Skip to content

Commit

Permalink
Attempt a simple rebuild of PolySet on Manifold error (openscad#5183)
Browse files Browse the repository at this point in the history
  • Loading branch information
kintel authored Jun 23, 2024
1 parent 9eb0202 commit 9b9adab
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/geometry/manifold/manifoldutils.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Portions of this file are Copyright 2023 Google LLC, and licensed under GPL2+. See COPYING.
#include "manifoldutils.h"
#include "ManifoldGeometry.h"
#include "PolySetBuilder.h"
#include "manifold.h"
#include "printutils.h"
#ifdef ENABLE_CGAL
Expand Down Expand Up @@ -113,7 +114,23 @@ std::shared_ptr<ManifoldGeometry> createManifoldFromPolySet(const PolySet& ps)
return mani;
}

// FIXME: Should we suppress this warning, as it may not be very actionable?
// Before announcing that the conversion failed, let's try to fix the most common
// causes of a non-manifold topology:
// Polygon soup of manifold topology with co-incident vertices having identical vertex positions
//
// Note: This causes us to lose the ability to represent manifold topologies with duplicate
// vertex positions (touching cubes, donut with vertex in the center etc.)
PolySetBuilder builder(ps.vertices.size(), ps.indices.size(),
ps.getDimension(), ps.convexValue());
builder.appendPolySet(ps);
std::unique_ptr<PolySet> rebuilt_ps = builder.build();
rebuilt_ps->setTriangular(ps.isTriangular());
mani = createManifoldFromTriangularPolySet(*rebuilt_ps);
if (mani->getManifold().Status() == Error::NoError) {
return mani;
}

// FIXME: Should we attempt merging vertices within epsilon distance before issuing this warning?
LOG(message_group::Warning,"PolySet -> Manifold conversion failed: %1$s\n"
"Trying to repair and reconstruct mesh..",
ManifoldUtils::statusToString(mani->getManifold().Status()));
Expand Down
20 changes: 20 additions & 0 deletions tests/data/scad/3D/features/polyhedron-soup.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
polyhedron(points = [
[1,0,0], [0,0,1], [0,1,0],
[1,0,0], [0,1,0], [0,0,-1],
[1,0,0], [0,-1,0], [0,0,1],
[1,0,0], [0,0,-1], [0,-1,0],
[-1,0,0], [0,1,0], [0,0,1],
[-1,0,0], [0,0,-1], [0,1,0],
[-1,0,0], [0,0,1], [0,-1,0],
[-1,0,0], [0,-1,0], [0,0,-1],
],
faces = [
[0,1,2],
[3,4,5],
[6,7,8],
[9,10,11],
[12,13,14],
[15,16,17],
[18,19,20],
[21,22,23]
]);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions tests/regression/dumptest/polyhedron-soup-expected.csg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
polyhedron(points = [[1, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [0, 1, 0], [0, 0, -1], [1, 0, 0], [0, -1, 0], [0, 0, 1], [1, 0, 0], [0, 0, -1], [0, -1, 0], [-1, 0, 0], [0, 1, 0], [0, 0, 1], [-1, 0, 0], [0, 0, -1], [0, 1, 0], [-1, 0, 0], [0, 0, 1], [0, -1, 0], [-1, 0, 0], [0, -1, 0], [0, 0, -1]], faces = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14], [15, 16, 17], [18, 19, 20], [21, 22, 23]], convexity = 1);

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9b9adab

Please sign in to comment.