public Mesh Unfold(Mesh mesh) { List <face> Faces = new List <face>(); List <edge> Edges = new List <edge>(); mesh.Faces.ConvertQuadsToTriangles(); mesh.UnifyNormals(); mesh.Compact(); Rhino.Geometry.Collections.MeshTopologyEdgeList el = mesh.TopologyEdges; Rhino.Geometry.Collections.MeshTopologyVertexList vs = mesh.TopologyVertices; mesh.FaceNormals.ComputeFaceNormals(); //Print(mesh.FaceNormals.Count.ToString()); // Print(mesh.Vertices.Count.ToString()); for (int i = 0; i < mesh.Faces.Count; i++) { face f1 = new face( new Point3d(mesh.Vertices[mesh.Faces[i].A]), new Point3d(mesh.Vertices[mesh.Faces[i].B]), new Point3d(mesh.Vertices[mesh.Faces[i].C]), mesh.FaceNormals[i] ); Faces.Add(f1); } for (int i = 0; i < el.Count; i++) { int[] faceid = el.GetConnectedFaces(i); edge e1 = new edge(vs[el.GetTopologyVertices(i).I], vs[el.GetTopologyVertices(i).J]); if (faceid.Length == 1) { e1.Faces = new face[1]; e1.Faces[0] = Faces[faceid[0]]; } else if (faceid.Length > 1) { e1.Faces = new face[2]; e1.Faces[0] = Faces[faceid[0]]; e1.Faces[1] = Faces[faceid[1]]; } e1.ID = i; Edges.Add(e1); } for (int i = 0; i < mesh.Faces.Count; i++) { int[] edgeid = el.GetEdgesForFace(i); face f1 = Faces[i]; f1.edges[0] = Edges[edgeid[0]]; f1.edges[1] = Edges[edgeid[1]]; f1.edges[2] = Edges[edgeid[2]]; f1.ID = i; } /* List< Mesh> output2 = new List< Mesh>(); * for (int i = 0; i < Faces.Count; i++) * { * output2.Add(Faces[i].DrawFace()); * } * B = output2; */ face f = Faces[0]; f.AddTransform(Transform.PlaneToPlane(new Plane(f.Center(), -f.Normal), Plane.WorldXY)); FaceLoop(f); //Print(f.Pts[0].X.ToString() + "/" + f.Pts[0].Y.ToString() + "/" + f.Pts[0].Z.ToString()); Mesh output = new Mesh(); for (int i = 0; i < Faces.Count; i++) { output.Append(Faces[i].DrawFace()); } return(output); }