diff --git a/src/geometry/manifold/manifoldutils.cc b/src/geometry/manifold/manifoldutils.cc index 3460d06ea8..210664e3ac 100644 --- a/src/geometry/manifold/manifoldutils.cc +++ b/src/geometry/manifold/manifoldutils.cc @@ -128,27 +128,29 @@ std::unique_ptr createManifoldFromTriangularPolySet(co std::shared_ptr createManifoldFromPolySet(const PolySet& ps) { - // FIXME: To create a Manifold object, we may need to first triangulate. - // The incoming PolySet could be severely broken if it originated from user or file input, so - // be prepared to repair it. - // 1. If it's not triangular, attempt to triangulate it directly - // 2. Try to create a Manifold object - // 3. If the Manifold object is broken (e.g. not a manifold), attempt repair - // 4. If successfully repaired, try to create Manifold again. - - std::unique_ptr ps_tri; + // 1. If the PolySet is already manifold, we should be able to build a Manifold object directly + // (through using manifold::Mesh). + // We need to make sure our PolySet is triangulated before doing that. + // Note: We currently don't have a way of directly checking if a PolySet is manifold, + // so we just try converting to a Manifold object and check its status. + std::unique_ptr triangulated; if (!ps.isTriangular()) { - ps_tri = PolySetUtils::tessellate_faces(ps); + triangulated = PolySetUtils::tessellate_faces(ps); } - const PolySet good_ps = ps.isTriangular() ? ps : *ps_tri; - auto mani = createManifoldFromTriangularPolySet(good_ps); + const PolySet triangle_set = ps.isTriangular() ? ps : *triangulated; + + auto mani = createManifoldFromTriangularPolySet(triangle_set); if (mani->Status() == Error::NoError) { return std::make_shared(std::shared_ptr(std::move(mani))); } - LOG("Warning: [manifold] PolySet -> Manifold conversion failed: %1$s\n" - "Trying to repair and reconstruct mesh", + // FIXME: Should we suppress this warning, as it may not be very actionable? + LOG(message_group::Warning,"PolySet -> Manifold conversion failed: %1$s\n" + "Trying to repair and reconstruct mesh..", ManifoldUtils::statusToString(mani->Status())); + + // 2. If the PolySet couldn't be converted into a Manifold object, let's try to repair it. + // We currently have to utilize some CGAL functions to do this. { #ifdef ENABLE_CGAL PolySet psq(ps); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5ebcf800e8..74f9d1df78 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1073,22 +1073,6 @@ add_cmdline_test(stlpngtest SCRIPT ${EX_IM_PNGTEST_PY} ARGS ${OPENSCAD_ARG} --fo set_tests_properties( # Manifold construction error. Probably due to polygon soup strategy - 3mfpngtest_polyhedron-self-touch-face-nonmanifold - 3mfpngtest_polyhedron-self-touch-face - objpngtest_polyhedron-self-touch-face-nonmanifold - objpngtest_polyhedron-self-touch-face - offpngtest_polyhedron-self-touch-face-nonmanifold - offpngtest_polyhedron-self-touch-face - stlpngtest_polyhedron-self-touch-face-nonmanifold - stlpngtest_polyhedron-self-touch-face - 3mfpngtest_polyhedrons-touch-face-nonmanifold - 3mfpngtest_polyhedrons-touch-face - objpngtest_polyhedrons-touch-face-nonmanifold - objpngtest_polyhedrons-touch-face - offpngtest_polyhedrons-touch-face-nonmanifold - offpngtest_polyhedrons-touch-face - stlpngtest_polyhedrons-touch-face-nonmanifold - stlpngtest_polyhedrons-touch-face PROPERTIES DISABLED TRUE ) diff --git a/tests/data/scad/3D/misc/polyhedron-self-touch-face.scad b/tests/data/scad/3D/misc/polyhedron-self-touch-face.scad index 064880ba29..db178df0cd 100644 --- a/tests/data/scad/3D/misc/polyhedron-self-touch-face.scad +++ b/tests/data/scad/3D/misc/polyhedron-self-touch-face.scad @@ -20,7 +20,7 @@ polyhedron( [0.5, 0.6, 0.5], ], faces=[ - [5,4,11],[5,11,12] + [5,4,11],[5,11,12], [4,6,11], [6,13,11], [6,7,13], @@ -39,5 +39,5 @@ polyhedron( [4,5,1],[4,1,0], [5,7,3],[5,3,1], [7,6,2],[7,2,3], - [6,4,0,2],[6,0,2], + [6,4,0],[6,0,2], ]); diff --git a/tests/regression/3mfpngtest/polyhedron-self-touch-face-expected.png b/tests/regression/3mfpngtest/polyhedron-self-touch-face-expected.png index e69de29bb2..5fc450a26f 100644 Binary files a/tests/regression/3mfpngtest/polyhedron-self-touch-face-expected.png and b/tests/regression/3mfpngtest/polyhedron-self-touch-face-expected.png differ diff --git a/tests/regression/3mfpngtest/polyhedron-self-touch-face-nonmanifold-expected.png b/tests/regression/3mfpngtest/polyhedron-self-touch-face-nonmanifold-expected.png index e69de29bb2..5fc450a26f 100644 Binary files a/tests/regression/3mfpngtest/polyhedron-self-touch-face-nonmanifold-expected.png and b/tests/regression/3mfpngtest/polyhedron-self-touch-face-nonmanifold-expected.png differ