public static string RenderableToPlyFile(IRenderable mesh) { int vertCount = mesh.Verts.Vertices.Length; int triCount = mesh.Verts.Tris; PlyBuilder plyString = new PlyBuilder(); plyString.WriteHeader(vertCount, triCount); // Multply the transform matrix by -90 along x to Fix PLY Co-ord Space Matrix4 RotateX90 = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(-90)); // Vertex Elements foreach (var vert in mesh.Verts.Vertices) { plyString.BuildVertexElement( Vector3.TransformPosition(vert.Position, mesh.Transform.Matrix * RotateX90), vert.Normal, vert.TexCoord, vert.Color); } // Face Indices for (var i = 0; i < mesh.Verts.Indices.Length; i += 3) { int idx1 = mesh.Verts.Indices[i]; int idx2 = mesh.Verts.Indices[i + 1]; int idx3 = mesh.Verts.Indices[i + 2]; plyString.BuildFaceElement(idx1, idx2, idx3); } return(plyString.ToString()); }
public static string RenderableListToPlyFile(IEnumerable <IRenderable> meshes) { int vertCount = 0; int triCount = 0; IEnumerable <IRenderable> renderables = meshes as IRenderable[] ?? meshes.ToArray(); foreach (var mesh in renderables) { vertCount += mesh.Verts.Vertices.Length; triCount += mesh.Verts.Tris; } PlyBuilder plyString = new PlyBuilder(); plyString.WriteHeader(vertCount, triCount); // Multply the transform matrix by -90 along x to Fix PLY Co-ord Space Matrix4 rotateX90 = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(-90)); // Vertex Elements foreach (var mesh in renderables) { foreach (var vert in mesh.Verts.Vertices) { plyString.BuildVertexElement( Vector3.TransformPosition(vert.Position, mesh.Transform.Matrix * rotateX90), vert.Normal, vert.TexCoord, vert.Color); } } // Face Indices int faceBase = 0; foreach (var mesh in renderables) { for (var i = 0; i < mesh.Verts.Indices.Length; i += 3) { int idx1 = faceBase + mesh.Verts.Indices[i]; int idx2 = faceBase + mesh.Verts.Indices[i + 1]; int idx3 = faceBase + mesh.Verts.Indices[i + 2]; plyString.BuildFaceElement(idx1, idx2, idx3); } faceBase += mesh.Verts.Vertices.Length; } return(plyString.ToString()); }