mirror of https://github.com/vitalif/openscad
#337 Enabled conversion directly from Nef polyhedron to PolySets, making us able to deal with more manifold corner cases
parent
39fc1faee5
commit
51c43af4f4
Binary file not shown.
|
@ -53,6 +53,8 @@ size_t CGAL_Nef_polyhedron::memsize() const
|
|||
|
||||
Note: Can return NULL if an error occurred
|
||||
*/
|
||||
// FIXME: Deprecated by CGALUtils::createPolySetFromNefPolyhedron3
|
||||
#if 0
|
||||
PolySet *CGAL_Nef_polyhedron::convertToPolyset() const
|
||||
{
|
||||
if (this->isEmpty()) return new PolySet(3);
|
||||
|
@ -83,6 +85,7 @@ PolySet *CGAL_Nef_polyhedron::convertToPolyset() const
|
|||
CGAL::set_error_behaviour(old_behaviour);
|
||||
return ps;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CGAL_Nef_polyhedron::resize(Vector3d newsize,
|
||||
const Eigen::Matrix<bool,3,1> &autosize)
|
||||
|
|
|
@ -27,7 +27,8 @@ public:
|
|||
CGAL_Nef_polyhedron &operator*=(const CGAL_Nef_polyhedron &other);
|
||||
CGAL_Nef_polyhedron &operator-=(const CGAL_Nef_polyhedron &other);
|
||||
CGAL_Nef_polyhedron &minkowski(const CGAL_Nef_polyhedron &other);
|
||||
class PolySet *convertToPolyset() const;
|
||||
// FIXME: Deprecated by CGALUtils::createPolySetFromNefPolyhedron3
|
||||
// class PolySet *convertToPolyset() const;
|
||||
void transform( const Transform3d &matrix );
|
||||
void resize(Vector3d newsize, const Eigen::Matrix<bool,3,1> &autosize);
|
||||
|
||||
|
|
|
@ -60,8 +60,14 @@ shared_ptr<const Geometry> GeometryEvaluator::evaluateGeometry(const AbstractNod
|
|||
|
||||
if (!allownef) {
|
||||
if (shared_ptr<const CGAL_Nef_polyhedron> N = dynamic_pointer_cast<const CGAL_Nef_polyhedron>(this->root)) {
|
||||
|
||||
this->root.reset(N->convertToPolyset());
|
||||
PolySet *ps = new PolySet(3);
|
||||
ps->setConvexity(N->getConvexity());
|
||||
this->root.reset(ps);
|
||||
bool err = CGALUtils::createPolySetFromNefPolyhedron3(*N->p3, *ps);
|
||||
if (err) {
|
||||
PRINT("ERROR: Nef->PolySet failed");
|
||||
}
|
||||
|
||||
smartCacheInsert(node, this->root);
|
||||
}
|
||||
}
|
||||
|
@ -888,7 +894,14 @@ Response GeometryEvaluator::visit(State &state, const ProjectionNode &node)
|
|||
if (!chPS) {
|
||||
shared_ptr<const CGAL_Nef_polyhedron> chN = dynamic_pointer_cast<const CGAL_Nef_polyhedron>(chgeom);
|
||||
if (chN) {
|
||||
chPS.reset(chN->convertToPolyset());
|
||||
PolySet *ps = new PolySet(3);
|
||||
bool err = CGALUtils::createPolySetFromNefPolyhedron3(*chN->p3, *ps);
|
||||
if (err) {
|
||||
PRINT("ERROR: Nef->PolySet failed");
|
||||
}
|
||||
else {
|
||||
chPS.reset(ps);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (chPS) poly = PolysetUtils::project(*chPS);
|
||||
|
|
|
@ -302,7 +302,7 @@ static CGAL_Nef_polyhedron *createNefPolyhedronFromPolySet(const PolySet &ps)
|
|||
bool err = CGALUtils::createPolyhedronFromPolySet(ps, P);
|
||||
// if (!err) {
|
||||
// PRINTB("Polyhedron is closed: %d", P.is_closed());
|
||||
// PRINTB("Polyhedron is valid: %d", P.is_valid(true, 0));
|
||||
// PRINTB("Polyhedron is valid: %d", P.is_valid(false, 0));
|
||||
// }
|
||||
|
||||
if (!err) N = new CGAL_Nef_polyhedron3(P);
|
||||
|
@ -888,10 +888,13 @@ namespace CGALUtils {
|
|||
}
|
||||
// In projection mode all the triangles are projected manually into the XY plane
|
||||
else {
|
||||
PolySet *ps3 = N.convertToPolyset();
|
||||
if (!ps3) return poly;
|
||||
poly = PolysetUtils::project(*ps3);
|
||||
delete ps3;
|
||||
PolySet ps(3);
|
||||
bool err = CGALUtils::createPolySetFromNefPolyhedron3(*N.p3, ps);
|
||||
if (err) {
|
||||
PRINT("ERROR: Nef->PolySet failed");
|
||||
return poly;
|
||||
}
|
||||
poly = PolysetUtils::project(ps);
|
||||
}
|
||||
return poly;
|
||||
}
|
||||
|
|
|
@ -134,11 +134,14 @@ void export_stl(const PolySet &ps, std::ostream &output)
|
|||
setlocale(LC_NUMERIC, "C"); // Ensure radix is . (not ,) in output
|
||||
output << "solid OpenSCAD_Model\n";
|
||||
BOOST_FOREACH(const PolySet::Polygon &p, triangulated.polygons) {
|
||||
output << " facet normal 0 0 0\n";
|
||||
output << " outer loop\n";
|
||||
assert(p.size() == 3); // STL only allows triangles
|
||||
Vector3d normal = (p[1] - p[0]).cross(p[2] - p[0]);
|
||||
normal.normalize();
|
||||
output << " facet normal " << normal[0] << " " << normal[1] << " " << normal[2] << "\n";
|
||||
output << " outer loop\n";
|
||||
|
||||
BOOST_FOREACH(const Vector3d &v, p) {
|
||||
output << "vertex " << v[0] << " " << v[1] << " " << v[2] << "\n";
|
||||
output << " vertex " << v[0] << " " << v[1] << " " << v[2] << "\n";
|
||||
}
|
||||
output << " endloop\n";
|
||||
output << " endfacet\n";
|
||||
|
@ -230,7 +233,7 @@ void export_stl(const CGAL_Nef_polyhedron *root_N, std::ostream &output)
|
|||
PRINT("Object isn't a valid 2-manifold! Modify your design.\n");
|
||||
}
|
||||
|
||||
bool usePolySet = false;
|
||||
bool usePolySet = true;
|
||||
if (usePolySet) {
|
||||
PolySet ps(3);
|
||||
bool err = CGALUtils::createPolySetFromNefPolyhedron3(*(root_N->p3), ps);
|
||||
|
|
Loading…
Reference in New Issue