//Convert to Unity mesh (if we know we have stored triangles in the data structure) //shareVertices means that we want a smooth surface where some vertices are shared between triangles public Mesh ConvertToUnityMesh(string name, bool shareVertices, bool generateNormals) { MyMesh myMesh = new MyMesh(); //Loop through each triangle foreach (HalfEdgeFace3 f in faces) { //These should have been stored clock-wise HalfEdgeVertex3 v1 = f.edge.v; HalfEdgeVertex3 v2 = f.edge.nextEdge.v; HalfEdgeVertex3 v3 = f.edge.nextEdge.nextEdge.v; //Standardize MyMeshVertex my_v1 = new MyMeshVertex(v1.position, v1.normal); MyMeshVertex my_v2 = new MyMeshVertex(v2.position, v2.normal); MyMeshVertex my_v3 = new MyMeshVertex(v3.position, v3.normal); myMesh.AddTriangle(my_v1, my_v2, my_v3, shareVertices: true); } Mesh unityMesh = myMesh.ConvertToUnityMesh(name); return(unityMesh); }
//We have just the faces (which we know are triangles) public static MyMesh ConvertToMyMesh(string meshName, HashSet <HalfEdgeFace3> faces, MyMesh.MeshStyle meshStyle) { MyMesh myMesh = new MyMesh(meshName); //Loop through each triangle foreach (HalfEdgeFace3 f in faces) { //These should have been stored clock-wise HalfEdgeVertex3 v1 = f.edge.v; HalfEdgeVertex3 v2 = f.edge.nextEdge.v; HalfEdgeVertex3 v3 = f.edge.nextEdge.nextEdge.v; //Standardize MyMeshVertex my_v1 = new MyMeshVertex(v1.position, v1.normal); MyMeshVertex my_v2 = new MyMeshVertex(v2.position, v2.normal); MyMeshVertex my_v3 = new MyMeshVertex(v3.position, v3.normal); myMesh.AddTriangle(my_v1, my_v2, my_v3, meshStyle); } return(myMesh); }