public static PolygonMesh.Mesh CreateCylinder(Cylinder.CylinderPrimitive cylinderToMeasure) { PolygonMesh.Mesh cylinder = new PolygonMesh.Mesh(); List <Vertex> bottomVerts = new List <Vertex>(); List <Vertex> topVerts = new List <Vertex>(); int count = 20; for (int i = 0; i < count; i++) { Vector2 bottomRadialPos = Vector2.Rotate(new Vector2(cylinderToMeasure.Radius1, 0), MathHelper.Tau * i / 20); Vertex bottomVertex = cylinder.CreateVertex(new Vector3(bottomRadialPos.x, bottomRadialPos.y, -cylinderToMeasure.Height / 2)); bottomVerts.Add(bottomVertex); Vector2 topRadialPos = Vector2.Rotate(new Vector2(cylinderToMeasure.Radius1, 0), MathHelper.Tau * i / 20); Vertex topVertex = cylinder.CreateVertex(new Vector3(topRadialPos.x, topRadialPos.y, cylinderToMeasure.Height / 2)); topVerts.Add(topVertex); } cylinder.ReverseFaceEdges(cylinder.CreateFace(bottomVerts.ToArray())); cylinder.CreateFace(topVerts.ToArray()); for (int i = 0; i < count - 1; i++) { cylinder.CreateFace(new Vertex[] { topVerts[i], bottomVerts[i], bottomVerts[i + 1], topVerts[i + 1] }); } cylinder.CreateFace(new Vertex[] { topVerts[count - 1], bottomVerts[count - 1], bottomVerts[0], topVerts[0] }); return(cylinder); }
public static PolygonMesh.Mesh CreateBox(AxisAlignedBoundingBox aabb) { PolygonMesh.Mesh cube = new PolygonMesh.Mesh(); Vertex[] verts = new Vertex[8]; //verts[0] = cube.CreateVertex(new Vector3(-1, -1, 1)); //verts[1] = cube.CreateVertex(new Vector3(1, -1, 1)); //verts[2] = cube.CreateVertex(new Vector3(1, 1, 1)); //verts[3] = cube.CreateVertex(new Vector3(-1, 1, 1)); //verts[4] = cube.CreateVertex(new Vector3(-1, -1, -1)); //verts[5] = cube.CreateVertex(new Vector3(1, -1, -1)); //verts[6] = cube.CreateVertex(new Vector3(1, 1, -1)); //verts[7] = cube.CreateVertex(new Vector3(-1, 1, -1)); verts[0] = cube.CreateVertex(new Vector3(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.z)); verts[1] = cube.CreateVertex(new Vector3(aabb.maxXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.z)); verts[2] = cube.CreateVertex(new Vector3(aabb.maxXYZ.x, aabb.maxXYZ.y, aabb.maxXYZ.z)); verts[3] = cube.CreateVertex(new Vector3(aabb.minXYZ.x, aabb.maxXYZ.y, aabb.maxXYZ.z)); verts[4] = cube.CreateVertex(new Vector3(aabb.minXYZ.x, aabb.minXYZ.y, aabb.minXYZ.z)); verts[5] = cube.CreateVertex(new Vector3(aabb.maxXYZ.x, aabb.minXYZ.y, aabb.minXYZ.z)); verts[6] = cube.CreateVertex(new Vector3(aabb.maxXYZ.x, aabb.maxXYZ.y, aabb.minXYZ.z)); verts[7] = cube.CreateVertex(new Vector3(aabb.minXYZ.x, aabb.maxXYZ.y, aabb.minXYZ.z)); // front cube.CreateFace(new Vertex[] { verts[0], verts[1], verts[2], verts[3] }); // left cube.CreateFace(new Vertex[] { verts[4], verts[0], verts[3], verts[7] }); // right cube.CreateFace(new Vertex[] { verts[1], verts[5], verts[6], verts[2] }); // back cube.CreateFace(new Vertex[] { verts[4], verts[7], verts[6], verts[5] }); // top cube.CreateFace(new Vertex[] { verts[3], verts[2], verts[6], verts[7] }); // bottom cube.CreateFace(new Vertex[] { verts[4], verts[5], verts[1], verts[0] }); return(cube); }
public static PolygonMesh.Mesh CreateBox(AxisAlignedBoundingBox aabb) { PolygonMesh.Mesh cube = new PolygonMesh.Mesh(); Vertex[] verts = new Vertex[8]; //verts[0] = cube.CreateVertex(new Vector3(-1, -1, 1)); //verts[1] = cube.CreateVertex(new Vector3(1, -1, 1)); //verts[2] = cube.CreateVertex(new Vector3(1, 1, 1)); //verts[3] = cube.CreateVertex(new Vector3(-1, 1, 1)); //verts[4] = cube.CreateVertex(new Vector3(-1, -1, -1)); //verts[5] = cube.CreateVertex(new Vector3(1, -1, -1)); //verts[6] = cube.CreateVertex(new Vector3(1, 1, -1)); //verts[7] = cube.CreateVertex(new Vector3(-1, 1, -1)); verts[0] = cube.CreateVertex(new Vector3(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.z)); verts[1] = cube.CreateVertex(new Vector3(aabb.maxXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.z)); verts[2] = cube.CreateVertex(new Vector3(aabb.maxXYZ.x, aabb.maxXYZ.y, aabb.maxXYZ.z)); verts[3] = cube.CreateVertex(new Vector3(aabb.minXYZ.x, aabb.maxXYZ.y, aabb.maxXYZ.z)); verts[4] = cube.CreateVertex(new Vector3(aabb.minXYZ.x, aabb.minXYZ.y, aabb.minXYZ.z)); verts[5] = cube.CreateVertex(new Vector3(aabb.maxXYZ.x, aabb.minXYZ.y, aabb.minXYZ.z)); verts[6] = cube.CreateVertex(new Vector3(aabb.maxXYZ.x, aabb.maxXYZ.y, aabb.minXYZ.z)); verts[7] = cube.CreateVertex(new Vector3(aabb.minXYZ.x, aabb.maxXYZ.y, aabb.minXYZ.z)); // front cube.CreateFace(new Vertex[] { verts[0], verts[1], verts[2], verts[3] }); // left cube.CreateFace(new Vertex[] { verts[4], verts[0], verts[3], verts[7] }); // right cube.CreateFace(new Vertex[] { verts[1], verts[5], verts[6], verts[2] }); // back cube.CreateFace(new Vertex[] { verts[4], verts[7], verts[6], verts[5] }); // top cube.CreateFace(new Vertex[] { verts[3], verts[2], verts[6], verts[7] }); // bottom cube.CreateFace(new Vertex[] { verts[4], verts[5], verts[1], verts[0] }); return cube; }
public static PolygonMesh.Mesh CreateCylinder(Cylinder.CylinderPrimitive cylinderToMeasure) { PolygonMesh.Mesh cylinder = new PolygonMesh.Mesh(); List<Vertex> bottomVerts = new List<Vertex>(); List<Vertex> topVerts = new List<Vertex>(); int count = 20; for (int i = 0; i < count; i++) { Vector2 bottomRadialPos = Vector2.Rotate(new Vector2(cylinderToMeasure.Radius1, 0), MathHelper.Tau * i / 20); Vertex bottomVertex = cylinder.CreateVertex(new Vector3(bottomRadialPos.x, bottomRadialPos.y, -cylinderToMeasure.Height / 2)); bottomVerts.Add(bottomVertex); Vector2 topRadialPos = Vector2.Rotate(new Vector2(cylinderToMeasure.Radius1, 0), MathHelper.Tau * i / 20); Vertex topVertex = cylinder.CreateVertex(new Vector3(topRadialPos.x, topRadialPos.y, cylinderToMeasure.Height / 2)); topVerts.Add(topVertex); } cylinder.ReverseFaceEdges(cylinder.CreateFace(bottomVerts.ToArray())); cylinder.CreateFace(topVerts.ToArray()); for (int i = 0; i < count - 1; i++) { cylinder.CreateFace(new Vertex[] { topVerts[i], bottomVerts[i], bottomVerts[i + 1], topVerts[i + 1] }); } cylinder.CreateFace(new Vertex[] { topVerts[count - 1], bottomVerts[count - 1], bottomVerts[0], topVerts[0] }); return cylinder; }