I’ve been wanting to do some basic booleans with geometry for a project. Mostly just basic difference/union/intersect, and am wondering if anyone has recommendations for a CSG (constructive solid geometry) library they’ve used with cinder. CGAL seems great, but it’s so huge and I’ve heard a bit slow sometimes. I’m looking to go as lean as possible.
I’ve been using hg_sdf, obviously quite different to rendering triangles (unless you’ve got some sort of isosurface mesher) as you need a sphere tracing renderer or equivalent, but oh so powerful with not much code.
Just published a bare bones port of ofxCSG by Lars Berg. It works pretty well though it can get bogged down if there is a ton of geometry. Works with any ci::TriMeshRef and while there are some small anomalies, it’s great for the most part.
TriMeshRef mesh0 = TriMesh::create(geom::Cube());
TriMeshRef mesh1 = TriMesh::create(geom::Sphere());
TriMeshRef resultMesh = TriMesh::create();
ciCSG::meshUnion(m0, m1, resultMesh);
ciCSG::meshDifference(m0, m1, resultMesh);
ciCSG::meshIntersection(m0, m1, resultMesh);
If you’re a geometry whiz or you know lots about float precision errors, I would welcome a critical eye!
OpenVDB provides a lot of volumetric operations on their data structure. See the CSG Tools section of the tutorial to get an idea of whether it fits your needs.
I haven’t tried it myself, but it has won an Oscar.
VDB looks super cool, but also intimidatingly large! What it does seem to have going is that it’s all based on B+ trees and is incredibly quick at looking up positions.
The CSG block above does a linear search and could definitely benefit from some sort of tree structure as being O(n) doesn’t scale well.