public static void FindNewTriangles(MeshFilter _mf, ref SliceData _data, bool _showDebug) { CustomPlane secondPlane = new CustomPlane(); Vector3 pointOnSliceVec; Vector3 sliceDir; Vector3 finalPoint; for (int i = 0, FaceID = 0; i < _mf.mesh.triangles.Length; i += 3, FaceID += 2) { Vector3 V1 = _mf.transform.TransformPoint(_mf.mesh.vertices[_mf.mesh.triangles[i]]); Vector3 V2 = _mf.transform.TransformPoint(_mf.mesh.vertices[_mf.mesh.triangles[i + 1]]); Vector3 V3 = _mf.transform.TransformPoint(_mf.mesh.vertices[_mf.mesh.triangles[i + 2]]); if (_showDebug) { _data.AddNewSlVectorDebug(V1, Vector3.zero, Color.magenta, false, true); _data.AddNewSlVectorDebug(V2, Vector3.zero, Color.magenta, false, true); _data.AddNewSlVectorDebug(V3, Vector3.zero, Color.magenta, false, true); } secondPlane.Set3Points(V1, V2, V3); Face face1 = new Face(); Face face2 = new Face(); _data.AddFace(FaceID, face1); _data.AddFace(FaceID + 1, face2); Edge[] edges = { new Edge(V1, V2), new Edge(V2, V3), new Edge(V3, V1) }; if (!IntersectionPlanToPlan(out pointOnSliceVec, out sliceDir, _data.CtmPlane, secondPlane)) { foreach (Edge e in edges) { _data.AddEdge(FaceID, new Edge(e.Points[0])); } continue; } bool drawSlice = false; foreach (Edge e in edges) { if (IntersectionVectorToVector(out finalPoint, e.Points[0], e.Points[1], pointOnSliceVec, sliceDir)) { if (_showDebug) { drawSlice = true; _data.AddNewSlVectorDebug(finalPoint, Vector3.zero, Color.magenta, true, false); } _data.AddSeperateEdges(FaceID, e, finalPoint); } else { _data.AddEdge(FaceID, new Edge(e.Points[0])); } } if (drawSlice && _showDebug) { _data.AddNewSlVectorDebug(pointOnSliceVec, sliceDir, Color.green); } } if (_showDebug) { _data.CleanUnusedDebugIntersections(); } }