From 79f7ebd7eb21acad8827f028b72ae2d49345007f Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Mon, 5 Aug 2024 18:57:21 +0100 Subject: [PATCH] Re-add occlusion culling --- project/code/Mission.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/project/code/Mission.cs b/project/code/Mission.cs index 9ba5924..8b694eb 100644 --- a/project/code/Mission.cs +++ b/project/code/Mission.cs @@ -113,11 +113,11 @@ public partial class Mission : Node3D }; MeshInstance3D mesh = GenerateMesh(surfaceArrays, material); - // OccluderInstance3D occluderInstance = GenerateOccluder(vertices, indices); + OccluderInstance3D occluderInstance = GenerateOccluder(surfaceArrays); var cellNode = new Node3D(); cellNode.AddChild(mesh); - // cellNode.AddChild(occluderInstance); + cellNode.AddChild(occluderInstance); AddChild(cellNode); } @@ -228,8 +228,21 @@ public partial class Mission : Node3D return surfacesArrays; } - private static OccluderInstance3D GenerateOccluder(List vertices, List indices) + private static OccluderInstance3D GenerateOccluder(List surfaceArrays) { + var vertices = new List(); + var indices = new List(); + foreach (var array in surfaceArrays) + { + var count = vertices.Count; + vertices.AddRange(array[(int)Mesh.ArrayType.Vertex].As()); + var surfaceIndices = array[(int)Mesh.ArrayType.Index].As(); + foreach (var idx in surfaceIndices) + { + indices.Add(count + idx); + } + } + var occluder = new ArrayOccluder3D(); occluder.SetArrays(vertices.ToArray(), indices.ToArray()); var occluderInstance = new OccluderInstance3D