Compare commits
4 Commits
e213b3ea26
...
261d5fe399
Author | SHA1 | Date |
---|---|---|
Jarrod Doyle | 261d5fe399 | |
Jarrod Doyle | 42cc08363e | |
Jarrod Doyle | 20a0796410 | |
Jarrod Doyle | 326543c0f6 |
|
@ -221,7 +221,11 @@ public partial class Mission : Node3D
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var lightmapTexture = BuildLightmapTexture(cells, packingRects.ToArray(), rectDataMap, surfaceDataMap);
|
var lightmapTexture = Timing.TimeStage("Build Lightmap", () =>
|
||||||
|
{
|
||||||
|
return BuildLightmapTexture(cells, packingRects.ToArray(), rectDataMap, surfaceDataMap);
|
||||||
|
});
|
||||||
|
|
||||||
foreach (var (textureId, surface) in surfaceDataMap)
|
foreach (var (textureId, surface) in surfaceDataMap)
|
||||||
{
|
{
|
||||||
if (surface.Empty)
|
if (surface.Empty)
|
||||||
|
@ -273,7 +277,12 @@ public partial class Mission : Node3D
|
||||||
|
|
||||||
private static Texture BuildLightmapTexture(WorldRep.Cell[] cells, PackingRectangle[] packingRects, Dictionary<int, LightmapRectData> rectDataMap, Dictionary<int, MeshSurfaceData> surfaceDataMap)
|
private static Texture BuildLightmapTexture(WorldRep.Cell[] cells, PackingRectangle[] packingRects, Dictionary<int, LightmapRectData> rectDataMap, Dictionary<int, MeshSurfaceData> surfaceDataMap)
|
||||||
{
|
{
|
||||||
RectanglePacker.Pack(packingRects, out var bounds);
|
var bounds = Timing.TimeStage("RectPack", () =>
|
||||||
|
{
|
||||||
|
RectanglePacker.Pack(packingRects, out var bounds, PackingHints.FindBest, 0);
|
||||||
|
return bounds;
|
||||||
|
});
|
||||||
|
GD.Print($"Creating lightmap with bounds: ({bounds.Width}, {bounds.Height})");
|
||||||
var image = Image.CreateEmpty((int)bounds.Width, (int)bounds.Height, false, Image.Format.Rgba8);
|
var image = Image.CreateEmpty((int)bounds.Width, (int)bounds.Height, false, Image.Format.Rgba8);
|
||||||
foreach (var rect in packingRects)
|
foreach (var rect in packingRects)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,4 +12,13 @@ public static class Timing
|
||||||
watch.Stop();
|
watch.Stop();
|
||||||
Godot.GD.Print($"[{stagename}]: {watch.Elapsed:g}");
|
Godot.GD.Print($"[{stagename}]: {watch.Elapsed:g}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static T TimeStage<T>(string stagename, Func<T> action)
|
||||||
|
{
|
||||||
|
var watch = Stopwatch.StartNew();
|
||||||
|
var value = action();
|
||||||
|
watch.Stop();
|
||||||
|
Godot.GD.Print($"[{stagename}]: {watch.Elapsed:g}");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue