diff --git a/src/CGALRenderer.cc b/src/CGALRenderer.cc index c9b816c5..a3505856 100644 --- a/src/CGALRenderer.cc +++ b/src/CGALRenderer.cc @@ -32,6 +32,7 @@ // dxfdata.h must come first for Eigen SIMD alignment issues #include "dxfdata.h" #include "polyset.h" +#include "polyset-utils.h" #include "printutils.h" #include "CGALRenderer.h" @@ -44,7 +45,13 @@ CGALRenderer::CGALRenderer(shared_ptr geom) { if (shared_ptr ps = dynamic_pointer_cast(geom)) { - this->polyset = ps; + assert(ps->getDimension() == 3); + // We need to tessellate here, in case the generated PolySet contains concave polygons + // See testdata/scad/3D/features/polyhedron-concave-test.scad + PolySet *ps_tri = new PolySet(3, ps->convexValue()); + ps_tri->setConvexity(ps->getConvexity()); + PolysetUtils::tessellate_faces(*ps, *ps_tri); + this->polyset.reset(ps_tri); } else if (shared_ptr poly = dynamic_pointer_cast(geom)) { this->polyset.reset(poly->tessellate()); diff --git a/src/CSGTermEvaluator.cc b/src/CSGTermEvaluator.cc index 4adfa62d..bae72d4a 100644 --- a/src/CSGTermEvaluator.cc +++ b/src/CSGTermEvaluator.cc @@ -11,6 +11,7 @@ #include "printutils.h" #include "GeometryEvaluator.h" #include "polyset.h" +#include "polyset-utils.h" #include #include @@ -99,7 +100,20 @@ static shared_ptr evaluate_csg_term_from_geometry(const State &state, // We cannot render Polygon2d directly, so we preprocess (tessellate) it here shared_ptr g = geom; shared_ptr p2d = dynamic_pointer_cast(geom); - if (p2d) g.reset(p2d->tessellate()); + if (p2d) { + g.reset(p2d->tessellate()); + } + else { + // We cannot render concave polygons, so tessellate any 3D PolySets + shared_ptr ps = dynamic_pointer_cast(geom); + if (ps) { + assert(ps->getDimension() == 3); + PolySet *ps_tri = new PolySet(3, ps->convexValue()); + ps_tri->setConvexity(ps->getConvexity()); + PolysetUtils::tessellate_faces(*ps, *ps_tri); + g.reset(ps_tri); + } + } shared_ptr t(new CSGTerm(g, state.matrix(), state.color(), stream.str())); if (modinst->isHighlight()) { diff --git a/tests/regression/cgalpngtest/issue1061-expected.png b/tests/regression/cgalpngtest/issue1061-expected.png index 78bd8525..ef40d783 100644 Binary files a/tests/regression/cgalpngtest/issue1061-expected.png and b/tests/regression/cgalpngtest/issue1061-expected.png differ diff --git a/tests/regression/opencsgtest/issue1061-expected.png b/tests/regression/opencsgtest/issue1061-expected.png index fc626374..ca886ff2 100644 Binary files a/tests/regression/opencsgtest/issue1061-expected.png and b/tests/regression/opencsgtest/issue1061-expected.png differ diff --git a/tests/regression/opencsgtest/polyhedron-concave-test-expected.png b/tests/regression/opencsgtest/polyhedron-concave-test-expected.png index c45cc11c..8e3dd762 100644 Binary files a/tests/regression/opencsgtest/polyhedron-concave-test-expected.png and b/tests/regression/opencsgtest/polyhedron-concave-test-expected.png differ diff --git a/tests/regression/throwntogethertest/issue1061-expected.png b/tests/regression/throwntogethertest/issue1061-expected.png index fc626374..ca886ff2 100644 Binary files a/tests/regression/throwntogethertest/issue1061-expected.png and b/tests/regression/throwntogethertest/issue1061-expected.png differ diff --git a/tests/regression/throwntogethertest/polyhedron-concave-test-expected.png b/tests/regression/throwntogethertest/polyhedron-concave-test-expected.png index c45cc11c..8e3dd762 100644 Binary files a/tests/regression/throwntogethertest/polyhedron-concave-test-expected.png and b/tests/regression/throwntogethertest/polyhedron-concave-test-expected.png differ