diff --git a/project/code/Mission.cs b/project/code/Mission.cs index 826a04c..c3eb83b 100644 --- a/project/code/Mission.cs +++ b/project/code/Mission.cs @@ -85,6 +85,7 @@ public partial class Mission : Node3D var vertices = new List(); var normals = new List(); + var indices = new List(); var idxOffset = 0; for (int i = 0; i < numPolys; i++) { @@ -100,13 +101,19 @@ public partial class Mission : Node3D var normal = plane.Normal; var numPolyVertices = poly.VertexCount; + var baseIdx = vertices.Count; + for (var j = 0; j < numPolyVertices; j++) + { + var vertex = cell.Vertices[cell.Indices[idxOffset + j]]; + vertices.Add(vertex.ToGodotVec3(4.0f)); + normals.Add(normal.ToGodotVec3(4.0f)); + } + for (int j = 1; j < numPolyVertices - 1; j++) { foreach (var offset in new int[] { 0, j, j + 1 }) { - var vertex = cell.Vertices[cell.Indices[idxOffset + offset]]; - vertices.Add(vertex.ToGodotVec3(4.0f)); - normals.Add(normal.ToGodotVec3(4.0f)); + indices.Add(baseIdx + offset); } } @@ -118,6 +125,7 @@ public partial class Mission : Node3D arrays.Resize((int)Mesh.ArrayType.Max); arrays[(int)Mesh.ArrayType.Vertex] = vertices.ToArray(); arrays[(int)Mesh.ArrayType.Normal] = normals.ToArray(); + arrays[(int)Mesh.ArrayType.Index] = indices.ToArray(); arrMesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, arrays); var meshInstance = new MeshInstance3D