// Copyright (c) 2012-2023 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 : RectPack { Builder::LightmapUVsChart* Chart = nullptr; Node(uint32 x, uint32 y, uint32 width, uint32 height) : RectPack(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: Node _root; const LightmapSettings* _settings; public: /// /// Initializes a new instance of the class. /// /// The settings. AtlasChartsPacker(const LightmapSettings* settings) : _root(settings->ChartsPadding, settings->ChartsPadding, (int32)settings->AtlasSize - settings->ChartsPadding, (int32)settings->AtlasSize - settings->ChartsPadding) , _settings(settings) { } /// /// 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, _settings->ChartsPadding, chart, _settings); } }; }; #endif