private Vertex[] BuildNextSection(MeshBuilder meshBuilder, Vector3 curvePt, Vector3 tangent, Quaternion quat, Vertex[] lastVerts) { Vector3 pt1 = quat * new Vector3(TRACK_RADIUS * X_SCALE_TOP, TRACK_RADIUS, 0) + curvePt; Vector3 pt2 = quat * new Vector3(TRACK_RADIUS * X_SCALE_BOTTOM, -TRACK_RADIUS, 0) + curvePt; Vector3 pt3 = quat * new Vector3(-TRACK_RADIUS * X_SCALE_BOTTOM, -TRACK_RADIUS, 0) + curvePt; Vector3 pt4 = quat * new Vector3(-TRACK_RADIUS * X_SCALE_TOP, TRACK_RADIUS, 0) + curvePt; Vertex[] verts = new Vertex[]{ meshBuilder.VertAutoNormal(pt1, new Vector2(), false), meshBuilder.VertAutoNormal(pt1, new Vector2(), false), meshBuilder.VertAutoNormal(pt2, new Vector2(), false), meshBuilder.VertAutoNormal(pt2, new Vector2(), false), meshBuilder.VertAutoNormal(pt3, new Vector2(), false), meshBuilder.VertAutoNormal(pt3, new Vector2(), false), meshBuilder.VertAutoNormal(pt4, new Vector2(), false), meshBuilder.VertAutoNormal(pt4, new Vector2(), false), }; if (lastVerts != null) { meshBuilder.AddTriangleStrip(false, new Vertex[]{ verts[2], lastVerts[2], verts[1], lastVerts[1], // right side verts[0], lastVerts[0], verts[7], lastVerts[7], // top side verts[6], lastVerts[6], verts[5], lastVerts[5], // left side verts[4], lastVerts[4], verts[3], lastVerts[3], // bottom side }); } else { AddCap(meshBuilder, new Vector3[]{pt1, pt2, pt3, pt4}, false); } return verts; }
private static void AddCap(MeshBuilder meshBuilder, Vector3[] verts, bool reverse) { meshBuilder.AddTriangleStrip(reverse, new Vertex[]{ meshBuilder.VertAutoNormal(verts[0], new Vector2(), false), meshBuilder.VertAutoNormal(verts[1], new Vector2(), false), meshBuilder.VertAutoNormal(verts[3], new Vector2(), false), meshBuilder.VertAutoNormal(verts[2], new Vector2(), false), }); }
public void BuildMesh(PartType partType, AdjacencyMatrix adjMatrix, MeshBuilder meshBuilder, BlockBounds clipBounds) { if (PartType.BlockFront == partType) { meshBuilder.AddTriangleStrip( false, meshBuilder.VertAutoNormal(new Vector3(1, 1, 0), new Vector2(1, 1), true), meshBuilder.VertAutoNormal(new Vector3(1, 0, 0), new Vector2(1, 0), true), meshBuilder.VertAutoNormal(new Vector3(0, 1, 0), new Vector2(0, 1), true), meshBuilder.VertAutoNormal(new Vector3(0, 0, 0), new Vector2(0, 0), true));; } else if (PartType.BlockBack == partType) { meshBuilder.AddTriangleStrip( false, meshBuilder.VertAutoNormal(new Vector3(0, 1, 1), new Vector2(1, 1), true), meshBuilder.VertAutoNormal(new Vector3(0, 0, 1), new Vector2(1, 0), true), meshBuilder.VertAutoNormal(new Vector3(1, 1, 1), new Vector2(0, 1), true), meshBuilder.VertAutoNormal(new Vector3(1, 0, 1), new Vector2(0, 0), true)); } else if (PartType.BlockRight == partType) { meshBuilder.AddTriangleStrip( false, meshBuilder.VertAutoNormal(new Vector3(1, 1, 1), new Vector2(1, 1), true), meshBuilder.VertAutoNormal(new Vector3(1, 0, 1), new Vector2(1, 0), true), meshBuilder.VertAutoNormal(new Vector3(1, 1, 0), new Vector2(0, 1), true), meshBuilder.VertAutoNormal(new Vector3(1, 0, 0), new Vector2(0, 0), true)); } else if (PartType.BlockLeft == partType) { meshBuilder.AddTriangleStrip( false, meshBuilder.VertAutoNormal(new Vector3(0, 1, 0), new Vector2(1, 1), true), meshBuilder.VertAutoNormal(new Vector3(0, 0, 0), new Vector2(1, 0), true), meshBuilder.VertAutoNormal(new Vector3(0, 1, 1), new Vector2(0, 1), true), meshBuilder.VertAutoNormal(new Vector3(0, 0, 1), new Vector2(0, 0), true)); } else if (PartType.BlockTop == partType) { meshBuilder.AddTriangleStrip( false, meshBuilder.VertAutoNormal(new Vector3(1, 1, 1), new Vector2(1, 1), true), meshBuilder.VertAutoNormal(new Vector3(1, 1, 0), new Vector2(1, 0), true), meshBuilder.VertAutoNormal(new Vector3(0, 1, 1), new Vector2(0, 1), true), meshBuilder.VertAutoNormal(new Vector3(0, 1, 0), new Vector2(0, 0), true)); } else if (PartType.BlockBottom == partType) { meshBuilder.AddTriangleStrip( false, meshBuilder.VertAutoNormal(new Vector3(1, 0, 0), new Vector2(1, 1), true), meshBuilder.VertAutoNormal(new Vector3(1, 0, 1), new Vector2(1, 0), true), meshBuilder.VertAutoNormal(new Vector3(0, 0, 0), new Vector2(0, 1), true), meshBuilder.VertAutoNormal(new Vector3(0, 0, 1), new Vector2(0, 0), true)); } }