mirror of https://github.com/vitalif/openscad
Handle CgaladvNodes
parent
11b1966cfb
commit
afd4a6adb8
|
@ -9,6 +9,7 @@
|
||||||
#include "linearextrudenode.h"
|
#include "linearextrudenode.h"
|
||||||
#include "rotateextrudenode.h"
|
#include "rotateextrudenode.h"
|
||||||
#include "csgnode.h"
|
#include "csgnode.h"
|
||||||
|
#include "cgaladvnode.h"
|
||||||
#include "clipper-utils.h"
|
#include "clipper-utils.h"
|
||||||
#include "CGALEvaluator.h"
|
#include "CGALEvaluator.h"
|
||||||
#include "CGALCache.h"
|
#include "CGALCache.h"
|
||||||
|
@ -157,29 +158,51 @@ void GeometryEvaluator::addToParent(const State &state,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Fallback: If we don't know how to handle a node, send it to CGAL
|
Custom nodes are handled here => implicit union
|
||||||
*/
|
*/
|
||||||
Response GeometryEvaluator::visit(State &state, const AbstractNode &node)
|
Response GeometryEvaluator::visit(State &state, const AbstractNode &node)
|
||||||
{
|
{
|
||||||
if (state.isPrefix() && isCached(node)) return PruneTraversal;
|
if (state.isPrefix() && isCached(node)) return PruneTraversal;
|
||||||
if (state.isPostfix()) {
|
if (state.isPostfix()) {
|
||||||
shared_ptr<const Geometry> geom;
|
shared_ptr<const class Geometry> geom;
|
||||||
if (!isCached(node)) {
|
if (!isCached(node)) {
|
||||||
CGAL_Nef_polyhedron N = this->cgalevaluator->evaluateCGALMesh(node);
|
const Geometry *geometry = applyToChildren2D(node, OPENSCAD_UNION);
|
||||||
CGALCache::instance()->insert(this->tree.getIdString(node), N);
|
const Polygon2d *polygons = dynamic_cast<const Polygon2d*>(geometry);
|
||||||
|
assert(polygons);
|
||||||
PolySet *ps = NULL;
|
geom.reset(geometry);
|
||||||
if (!N.isNull()) ps = N.convertToPolyset();
|
|
||||||
geom.reset(ps);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
geom = GeometryCache::instance()->get(this->tree.getIdString(node));
|
geom = GeometryCache::instance()->get(this->tree.getIdString(node));
|
||||||
}
|
}
|
||||||
addToParent(state, node, geom);
|
addToParent(state, node, geom);
|
||||||
|
// FIXME: if 3d node, CGAL?
|
||||||
}
|
}
|
||||||
return ContinueTraversal;
|
return ContinueTraversal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
FIXME: Where do we handle nodes which should be sent to CGAL?
|
||||||
|
|
||||||
|
if (state.isPrefix() && isCached(node)) return PruneTraversal;
|
||||||
|
if (state.isPostfix()) {
|
||||||
|
shared_ptr<const Geometry> geom;
|
||||||
|
if (!isCached(node)) {
|
||||||
|
CGAL_Nef_polyhedron N = this->cgalevaluator->evaluateCGALMesh(node);
|
||||||
|
CGALCache::instance()->insert(this->tree.getIdString(node), N);
|
||||||
|
|
||||||
|
PolySet *ps = NULL;
|
||||||
|
if (!N.isNull()) ps = N.convertToPolyset();
|
||||||
|
geom.reset(ps);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
geom = GeometryCache::instance()->get(this->tree.getIdString(node));
|
||||||
|
}
|
||||||
|
addToParent(state, node, geom);
|
||||||
|
}
|
||||||
|
return ContinueTraversal;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Leaf nodes can create their own geometry, so let them do that
|
Leaf nodes can create their own geometry, so let them do that
|
||||||
*/
|
*/
|
||||||
|
@ -476,3 +499,29 @@ Response GeometryEvaluator::visit(State &state, const AbstractPolyNode &node)
|
||||||
return ContinueTraversal;
|
return ContinueTraversal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Response GeometryEvaluator::visit(State &state, const CgaladvNode &node)
|
||||||
|
{
|
||||||
|
if (state.isPrefix() && isCached(node)) return PruneTraversal;
|
||||||
|
if (state.isPostfix()) {
|
||||||
|
shared_ptr<const Geometry> geom;
|
||||||
|
if (!isCached(node)) {
|
||||||
|
// if (node.type == RESIZE) {
|
||||||
|
// const Geometry *geometry = applyToChildren2D(node, OPENSCAD_UNION);
|
||||||
|
// // FIXME: find size and transform
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
CGAL_Nef_polyhedron N = this->cgalevaluator->evaluateCGALMesh(node);
|
||||||
|
CGALCache::instance()->insert(this->tree.getIdString(node), N);
|
||||||
|
PolySet *ps = N.isNull() ? NULL : N.convertToPolyset();
|
||||||
|
geom.reset(ps);
|
||||||
|
// }
|
||||||
|
// FIXME: handle 3D
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
geom = GeometryCache::instance()->get(this->tree.getIdString(node));
|
||||||
|
}
|
||||||
|
addToParent(state, node, geom);
|
||||||
|
}
|
||||||
|
return ContinueTraversal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ public:
|
||||||
virtual Response visit(State &state, const LeafNode &node);
|
virtual Response visit(State &state, const LeafNode &node);
|
||||||
virtual Response visit(State &state, const TransformNode &node);
|
virtual Response visit(State &state, const TransformNode &node);
|
||||||
virtual Response visit(State &state, const CsgNode &node);
|
virtual Response visit(State &state, const CsgNode &node);
|
||||||
|
virtual Response visit(State &state, const CgaladvNode &node);
|
||||||
|
|
||||||
const Tree &getTree() const { return this->tree; }
|
const Tree &getTree() const { return this->tree; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue