#793 Tessellate PolySets before rendering to properly support concave polygons
|
@ -32,6 +32,7 @@
|
||||||
// dxfdata.h must come first for Eigen SIMD alignment issues
|
// dxfdata.h must come first for Eigen SIMD alignment issues
|
||||||
#include "dxfdata.h"
|
#include "dxfdata.h"
|
||||||
#include "polyset.h"
|
#include "polyset.h"
|
||||||
|
#include "polyset-utils.h"
|
||||||
#include "printutils.h"
|
#include "printutils.h"
|
||||||
|
|
||||||
#include "CGALRenderer.h"
|
#include "CGALRenderer.h"
|
||||||
|
@ -44,7 +45,13 @@
|
||||||
CGALRenderer::CGALRenderer(shared_ptr<const class Geometry> geom)
|
CGALRenderer::CGALRenderer(shared_ptr<const class Geometry> geom)
|
||||||
{
|
{
|
||||||
if (shared_ptr<const PolySet> ps = dynamic_pointer_cast<const PolySet>(geom)) {
|
if (shared_ptr<const PolySet> ps = dynamic_pointer_cast<const PolySet>(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<const Polygon2d> poly = dynamic_pointer_cast<const Polygon2d>(geom)) {
|
else if (shared_ptr<const Polygon2d> poly = dynamic_pointer_cast<const Polygon2d>(geom)) {
|
||||||
this->polyset.reset(poly->tessellate());
|
this->polyset.reset(poly->tessellate());
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "printutils.h"
|
#include "printutils.h"
|
||||||
#include "GeometryEvaluator.h"
|
#include "GeometryEvaluator.h"
|
||||||
#include "polyset.h"
|
#include "polyset.h"
|
||||||
|
#include "polyset-utils.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -99,7 +100,20 @@ static shared_ptr<CSGTerm> evaluate_csg_term_from_geometry(const State &state,
|
||||||
// We cannot render Polygon2d directly, so we preprocess (tessellate) it here
|
// We cannot render Polygon2d directly, so we preprocess (tessellate) it here
|
||||||
shared_ptr<const Geometry> g = geom;
|
shared_ptr<const Geometry> g = geom;
|
||||||
shared_ptr<const Polygon2d> p2d = dynamic_pointer_cast<const Polygon2d>(geom);
|
shared_ptr<const Polygon2d> p2d = dynamic_pointer_cast<const Polygon2d>(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<const PolySet> ps = dynamic_pointer_cast<const PolySet>(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<CSGTerm> t(new CSGTerm(g, state.matrix(), state.color(), stream.str()));
|
shared_ptr<CSGTerm> t(new CSGTerm(g, state.matrix(), state.color(), stream.str()));
|
||||||
if (modinst->isHighlight()) {
|
if (modinst->isHighlight()) {
|
||||||
|
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.3 KiB |