public IEnumerator Cut(MPath path) { while (buildingGraph) { yield return(new WaitForSeconds(0.01f)); } DebugTime("Total Cut"); Vector3 normal = path.GetNormal(0); path.InsertPositionAt(0, path.dotFrom.transform.position); path.InsertNormalAt(0, normal); path.AddPosition(path.dotTo.transform.position); path.AddNormal(normal); DebugTime("Identify Cuts"); mesh = manifold.gameObject.GetComponent <MeshFilter> ().mesh; var vertices = mesh.vertices.ToList(); meshTriangles = mesh.triangles.ToList(); meshNormals = mesh.normals.ToList(); // Misc.DebugSphere (vertices[1299], Color.blue, "1299"); // Misc.DebugSphere (vertices[1334], Color.blue, "1334"); // Misc.DebugSphere (vertices[1335], Color.blue, "1335"); // DebugAtTriangle (2596, Color.white, "2596"); // DebugAtTriangle (2597, Color.white, "2597"); var cutPointIdentifier = new CutPointIdentifier(g, manifold); cutPointIdentifier.IdentifyCuts(path); var cutPoints = cutPointIdentifier.cutPoints; var cutEdges = cutPointIdentifier.cutEdges; var cutPointType = cutPointIdentifier.cutPointType; var cutTriangles = cutPointIdentifier.cutTriangles; var cutAlongEdges = cutPointIdentifier.cutAlongEdges; var cutNodes = cutPointIdentifier.cutNodes; DebugTime("Identify Cuts"); Debug.Log("Identification done, resulting in " + cutPoints.Count + " cut Points."); List <HashSet <int> > bounds; List <HashSet <int> > meshVertexPres; GetNewMeshVertices(vertices, cutNodes, cutAlongEdges, cutEdges, out bounds, out meshVertexPres); Debug.Log("GetBounds done, resulting in " + bounds.Count + " bounds."); int numComponents = meshVertexPres.Count; DebugTime("Set up Polygons"); var polyAtTriangle = new Dictionary <int, List <MPolygon> > (); foreach (var i in cutTriangles.Keys) { var index = cutTriangles[i]; polyAtTriangle[index] = new List <MPolygon> (); var list = new MPolygon(); list.Add(meshTriangles[index * 3]); list.Add(meshTriangles[index * 3 + 1]); list.Add(meshTriangles[index * 3 + 2]); polyAtTriangle[index].Add(list); } DebugTime("Set up Polygons"); // foreach (var item in cutTriangles.Keys) { // DebugAtTriangle (cutTriangles[item], Color.red, item + ""); // } DebugTime("Cut up Polygons"); oldVertexNumber = vertices.Count; var polygonCutter = new PolygonCutter(meshTriangles, meshNormals, vertices, polyAtTriangle); var sidesOfCut = polygonCutter.Cut(cutPoints, cutEdges, cutNodes, cutTriangles); List <Vector3> normals = polygonCutter.normals; var cutPointsToVertices = polygonCutter.cutPointVertices; DebugTime("Cut up Polygons"); // for (int i = 0; i < cutPoints.Count; i++) { // Vector3 cp = cutPoints[i]; // Misc.DebugSphere (cp, Color.red, i + "cp"); // } DebugTime("Triangulate"); var to = new TriangleOrdering(vertices, polyAtTriangle, bounds, cutNodes, cutPointsToVertices, sidesOfCut); Pair <HashSet <int> > sideBounds; var polygons = to.orderTriangles(out sideBounds); DebugTime("Triangulate"); Debug.Log("Triangulation done, resulting in " + polygons.Count + " lists of polygons."); // foreach (var item in sidesOfCut.left) { // DebugAtPolygon (vertices, item, Color.green); // } // foreach (var item in sidesOfCut.right) { // DebugAtPolygon (vertices, item, Color.red); // } var newMeshVertexPres = new List <HashSet <int> > (); newMeshVertexPres.Add(new HashSet <int> ()); newMeshVertexPres.Add(new HashSet <int> ()); foreach (var bound in sideBounds.left) { newMeshVertexPres[0].UnionWith(meshVertexPres[bound]); } foreach (var bound in sideBounds.right) { newMeshVertexPres[1].UnionWith(meshVertexPres[bound]); } numComponents = 2; if (newMeshVertexPres[0].SetEquals(newMeshVertexPres[1])) { numComponents = 1; polygons[0].AddRange(polygons[1]); } DebugTime("GetTriangles"); List <List <int> > meshts; List <List <Vector3> > meshvs, meshns; SetUpNewMeshes(vertices, cutTriangles, newMeshVertexPres, out meshts, out meshvs, out meshns); DebugTime("Set Normals and Triangles"); DebugTime("Set up manifolds"); SetUpManifolds(vertices, meshts, meshvs, meshns, normals, polygons, cutPoints, numComponents); SetSwitchedManifolds(); DebugTime("Set up manifolds"); //SLOW DebugTime("Total Cut"); }