virtual public void CutMesh() { Frame3f frameL = SceneTransforms.SceneToObject(target, cut_plane); Action <DMesh3> editF = (mesh) => { MeshPlaneCut cut = new MeshPlaneCut(mesh, frameL.Origin, frameL.Y); cut.Cut(); PlaneProjectionTarget planeTarget = new PlaneProjectionTarget() { Origin = frameL.Origin, Normal = frameL.Y }; if (GenerateFillSurface) { double min, max, avg; MeshQueries.EdgeLengthStats(mesh, out min, out max, out avg); cut.FillHoles(); MeshFaceSelection selection = new MeshFaceSelection(mesh); foreach (var tris in cut.LoopFillTriangles) { selection.Select(tris); } RegionRemesher.QuickRemesh(mesh, selection.ToArray(), 2 * avg, 1.0f, 25, planeTarget); MeshNormals normals = new MeshNormals(mesh); normals.Compute(); normals.CopyTo(mesh); } }; target.EditAndUpdateMesh(editF, GeometryEditTypes.ArbitraryEdit); }
} // test_basic_fills public static void test_plane_cut() { List <int> tests = new List <int>() { 2 }; bool DO_EXHAUSTIVE_TESTS = false; foreach (int num_test in tests) { string name; DMesh3 orig_mesh = MakeEditTestMesh(num_test, out name); DMesh3 mesh = new DMesh3(orig_mesh); AxisAlignedBox3d bounds = mesh.CachedBounds; MeshPlaneCut cut = new MeshPlaneCut(mesh, bounds.Center, Vector3d.AxisY); Debug.Assert(cut.Validate() == ValidationStatus.Ok); bool bCutOK = cut.Cut(); bool bFillOK = cut.FillHoles(-1); System.Console.WriteLine("cut: {0} fill:D {1}", ((bCutOK) ? "Ok" : "Failed"), ((bFillOK) ? "Ok" : "Failed")); TestUtil.WriteTestOutputMesh(mesh, name + "_cut" + ".obj"); if (DO_EXHAUSTIVE_TESTS == false) { continue; } // grinder: cut through each vtx int VertexIncrement = 1; for (int vid = 0; vid < orig_mesh.MaxVertexID; vid += VertexIncrement) { if (orig_mesh.IsVertex(vid) == false) { continue; } if (vid % 100 == 0) { System.Console.WriteLine("{0} / {1}", vid, orig_mesh.MaxVertexID); } Vector3d v = orig_mesh.GetVertex(vid); mesh = new DMesh3(orig_mesh); cut = new MeshPlaneCut(mesh, bounds.Center, Vector3d.AxisY); bCutOK = cut.Cut(); Debug.Assert(bCutOK); } } // test_plane_cut }