// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #pragma once #include "Builder.h" #include "Engine/Utilities/RectPack.h" #if COMPILE_WITH_GI_BAKING namespace ShadowsOfMordor { class AtlasChartsPacker { public: struct Node : RectPackNode { Builder::LightmapUVsChart* Chart = nullptr; Node(Size x, Size y, Size width, Size height) : RectPackNode(x, y, width, height) { } void OnInsert(Builder::LightmapUVsChart* chart, const LightmapSettings* settings) { Chart = chart; const float invSize = 1.0f / (int32)settings->AtlasSize; chart->Result.UVsArea = Rectangle(X * invSize, Y * invSize, chart->Width * invSize, chart->Height * invSize); } }; private: RectPackAtlas _root; const LightmapSettings* _settings; public: /// /// Initializes a new instance of the class. /// /// The settings. AtlasChartsPacker(const LightmapSettings* settings) : _settings(settings) { _root.Init((int32)settings->AtlasSize, (int32)settings->AtlasSize, settings->ChartsPadding); } /// /// Finalizes an instance of the class. /// ~AtlasChartsPacker() { } public: /// /// Inserts the specified chart into atlas . /// /// The chart. /// Node* Insert(Builder::LightmapUVsChart* chart) { return _root.Insert(chart->Width, chart->Height, chart, _settings); } }; }; #endif