Re-add occlusion culling

This commit is contained in:
Jarrod Doyle 2024-08-05 18:57:21 +01:00
parent 770f4e22d5
commit 79f7ebd7eb
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 16 additions and 3 deletions

View File

@ -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<Vector3> vertices, List<int> indices)
private static OccluderInstance3D GenerateOccluder(List<Godot.Collections.Array> surfaceArrays)
{
var vertices = new List<Vector3>();
var indices = new List<int>();
foreach (var array in surfaceArrays)
{
var count = vertices.Count;
vertices.AddRange(array[(int)Mesh.ArrayType.Vertex].As<Vector3[]>());
var surfaceIndices = array[(int)Mesh.ArrayType.Index].As<int[]>();
foreach (var idx in surfaceIndices)
{
indices.Add(count + idx);
}
}
var occluder = new ArrayOccluder3D();
occluder.SetArrays(vertices.ToArray(), indices.ToArray());
var occluderInstance = new OccluderInstance3D