Use indices for meshes
This commit is contained in:
parent
1ba0c6ac27
commit
76b95bcf67
|
@ -85,6 +85,7 @@ public partial class Mission : Node3D
|
|||
|
||||
var vertices = new List<Vector3>();
|
||||
var normals = new List<Vector3>();
|
||||
var indices = new List<int>();
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue