-
-
Save ochafik/cb45164b84c01a33ad3934a21c826b24 to your computer and use it in GitHub Desktop.
Draft ideas re/ pluggable CSG engines in OpenSCAD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| /* | |
| To coexist peacefully, 3D CSG engines must: | |
| - Generate Geometry convertible to a PolySet with ->toPolySet()) | |
| - Be able to consume any Geometry to convert it to whatever it needs (fallback to ->toPolySet()) | |
| The exact Geometry subclass (if not PolySet) needs not be known by anyone else than the engine itself, but *can* be (for instance, to provide better specialized rendering). | |
| PolySets in the wild are not assumed to be triangular (for instance could have complex faces with holes, which is useful for rendering). | |
| toPolySet() does however triangulate them. | |
| */ | |
| class Geometry { | |
| ... | |
| shared_ptr<PolySet> toPolySet(bool triangulate = true) const = 0; | |
| }; | |
| class CsgEngine { | |
| virtual shared_ptr<const Geometry> applyOperator3D(const Geometry::Geometries& children, OpenSCADOperator op) = 0; | |
| virtual shared_ptr<const Geometry> applyTransform3D(const shared_ptr<const Geometry>& geom, const Transform3d& tr) = 0; | |
| }; | |
| // Implementation of these is just copy pasted from cgalutils-applyops.cc | |
| class CGALNefCsgEngine : public CsgEngine { | |
| public: | |
| virtual shared_ptr<const Geometry> applyOperator3D(const Geometry::Geometries& children, OpenSCADOperator op) const override; | |
| ... | |
| private: | |
| bool applyHull(const Geometry::Geometries& children, PolySet& result); | |
| shared_ptr<const Geometry> applyUnion3D(Geometry::Geometries::iterator chbegin, Geometry::Geometries::iterator chend); | |
| shared_ptr<const Geometry> applyMinkowski(const Geometry::Geometries& children); | |
| }; | |
| class CGALHybridCsgEngine : public CsgEngine { | |
| // cgalutils-applyops-hybrid.cc | |
| }; | |
| class ManifoldGeometry : public Geometry {}; | |
| class ManifoldCsgEngine : public CsgEngine {}; | |
| // A helper that does the facet-based queuing of operands so as to assemble smaller bodies first | |
| // Currently only used for union but should really be used for intersection too. | |
| template <class Children, class Child> | |
| shared_ptr<const Geometry> applyCommutativeOpInPlace( | |
| const Children& children, | |
| const std::function<void(Child& lhs, const Child& rhs)>& opFn) const; | |
| /* | |
| class ParallelLazyGeomBase : public CsgEngine { | |
| std::shared_ptr<CsgEngine> underlyingEngine_; | |
| }; | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment