Little bit of cleanup
This commit is contained in:
parent
0ce662733b
commit
2105ea7b24
|
@ -86,38 +86,34 @@ 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++)
|
||||
var cellIdxOffset = 0;
|
||||
|
||||
var maxPolyIdx = Math.Min(numRenderPolys, numPolys - numPortalPolys);
|
||||
for (int i = 0; i < maxPolyIdx; 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 normal = plane.Normal;
|
||||
var gNormal = normal.ToGodotVec3(4.0f);
|
||||
|
||||
var numPolyVertices = poly.VertexCount;
|
||||
var baseIdx = vertices.Count;
|
||||
var meshIdxOffset = vertices.Count;
|
||||
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));
|
||||
normals.Add(normal.ToGodotVec3(4.0f));
|
||||
normals.Add(gNormal);
|
||||
}
|
||||
|
||||
// Simple triangulation
|
||||
for (int j = 1; j < numPolyVertices - 1; j++)
|
||||
{
|
||||
foreach (var offset in new int[] { 0, j, j + 1 })
|
||||
{
|
||||
indices.Add(baseIdx + offset);
|
||||
}
|
||||
indices.Add(meshIdxOffset);
|
||||
indices.Add(meshIdxOffset + j);
|
||||
indices.Add(meshIdxOffset + j + 1);
|
||||
}
|
||||
|
||||
idxOffset += poly.VertexCount;
|
||||
cellIdxOffset += poly.VertexCount;
|
||||
}
|
||||
|
||||
var cellNode = new Node3D();
|
||||
|
@ -128,8 +124,8 @@ public partial class Mission : Node3D
|
|||
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
|
||||
{
|
||||
Mesh = arrMesh,
|
||||
|
@ -137,14 +133,15 @@ public partial class Mission : Node3D
|
|||
};
|
||||
cellNode.AddChild(meshInstance);
|
||||
|
||||
var occluderInstance = new OccluderInstance3D();
|
||||
var occluder = new ArrayOccluder3D();
|
||||
occluder.SetArrays(vertices.ToArray(), indices.ToArray());
|
||||
occluderInstance.Occluder = occluder;
|
||||
occluderInstance.BakeSimplificationDistance = 0.0f;
|
||||
var occluderInstance = new OccluderInstance3D
|
||||
{
|
||||
Occluder = occluder,
|
||||
BakeSimplificationDistance = 0.0f
|
||||
};
|
||||
cellNode.AddChild(occluderInstance);
|
||||
|
||||
|
||||
var r = new Random();
|
||||
if (r.NextSingle() > 0.9 && cell.SphereRadius > 5.0)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue