Little bit of cleanup

This commit is contained in:
Jarrod Doyle 2024-07-22 20:34:12 +01:00
parent 0ce662733b
commit 2105ea7b24
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 19 additions and 22 deletions

View File

@ -86,38 +86,34 @@ public partial class Mission : Node3D
var vertices = new List<Vector3>(); var vertices = new List<Vector3>();
var normals = new List<Vector3>(); var normals = new List<Vector3>();
var indices = new List<int>(); var indices = new List<int>();
var idxOffset = 0; var cellIdxOffset = 0;
for (int i = 0; i < numPolys; i++)
var maxPolyIdx = Math.Min(numRenderPolys, numPolys - numPortalPolys);
for (int i = 0; i < maxPolyIdx; i++)
{ {
var poly = cell.Polys[i]; var poly = cell.Polys[i];
// TODO: Make this break lol
if (i >= numRenderPolys || i >= numPolys - numPortalPolys)
{
idxOffset += poly.VertexCount;
continue;
}
var plane = cell.Planes[poly.PlaneId]; var plane = cell.Planes[poly.PlaneId];
var normal = plane.Normal; var normal = plane.Normal;
var gNormal = normal.ToGodotVec3(4.0f);
var numPolyVertices = poly.VertexCount; var numPolyVertices = poly.VertexCount;
var baseIdx = vertices.Count; var meshIdxOffset = vertices.Count;
for (var j = 0; j < numPolyVertices; j++) for (var j = 0; j < numPolyVertices; j++)
{ {
var vertex = cell.Vertices[cell.Indices[idxOffset + j]]; var vertex = cell.Vertices[cell.Indices[cellIdxOffset + j]];
vertices.Add(vertex.ToGodotVec3(4.0f)); vertices.Add(vertex.ToGodotVec3(4.0f));
normals.Add(normal.ToGodotVec3(4.0f)); normals.Add(gNormal);
} }
// Simple triangulation
for (int j = 1; j < numPolyVertices - 1; j++) for (int j = 1; j < numPolyVertices - 1; j++)
{ {
foreach (var offset in new int[] { 0, j, j + 1 }) indices.Add(meshIdxOffset);
{ indices.Add(meshIdxOffset + j);
indices.Add(baseIdx + offset); indices.Add(meshIdxOffset + j + 1);
}
} }
idxOffset += poly.VertexCount; cellIdxOffset += poly.VertexCount;
} }
var cellNode = new Node3D(); var cellNode = new Node3D();
@ -128,8 +124,8 @@ public partial class Mission : Node3D
arrays[(int)Mesh.ArrayType.Vertex] = vertices.ToArray(); arrays[(int)Mesh.ArrayType.Vertex] = vertices.ToArray();
arrays[(int)Mesh.ArrayType.Normal] = normals.ToArray(); arrays[(int)Mesh.ArrayType.Normal] = normals.ToArray();
arrays[(int)Mesh.ArrayType.Index] = indices.ToArray(); arrays[(int)Mesh.ArrayType.Index] = indices.ToArray();
arrMesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, arrays); arrMesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, arrays);
var meshInstance = new MeshInstance3D var meshInstance = new MeshInstance3D
{ {
Mesh = arrMesh, Mesh = arrMesh,
@ -137,14 +133,15 @@ public partial class Mission : Node3D
}; };
cellNode.AddChild(meshInstance); cellNode.AddChild(meshInstance);
var occluderInstance = new OccluderInstance3D();
var occluder = new ArrayOccluder3D(); var occluder = new ArrayOccluder3D();
occluder.SetArrays(vertices.ToArray(), indices.ToArray()); occluder.SetArrays(vertices.ToArray(), indices.ToArray());
occluderInstance.Occluder = occluder; var occluderInstance = new OccluderInstance3D
occluderInstance.BakeSimplificationDistance = 0.0f; {
Occluder = occluder,
BakeSimplificationDistance = 0.0f
};
cellNode.AddChild(occluderInstance); cellNode.AddChild(occluderInstance);
var r = new Random(); var r = new Random();
if (r.NextSingle() > 0.9 && cell.SphereRadius > 5.0) if (r.NextSingle() > 0.9 && cell.SphereRadius > 5.0)
{ {