A CSG library for doing boolean operations with ofMesh

I was searching for a CSG library and it seems hard. There’s https://github.com/paulobala/ofxCarveCSG, with 2 commits and not compiling at the moment, and https://github.com/Larsberg/ofxCSG, labeled WIP. None have been updated recently.

Researching I found this list from the Openscad people: https://github.com/openscad/openscad/wiki/Project%3A-Survey-of-CSG-algorithms

Cork, the library they mention first (https://github.com/gilbo/cork) is written by

a computer scientist who has worked on robust geometric intersections in various projects since 2007

The code is LGPL, and compiles in a few seconds. It comes with a command line tool to test the boolean operations. I think it would be easy to create an OpenFrameworks addon based on this library (for someone who’s created a library before).
It would require converting ofMesh into their mesh format, which is also based on vertices and triangles.

I hope someone feels tempted enough :wink:

:slight_smile:

1 Like

So happy :slight_smile:

Cork is dependent on the GMP library and at the moment only the OSX version is included here.

I tried making it work on linux by deleting the libs/gmp folder that comes with the addon and adding cpp.dynamicLibraries: ['gmp'] to my qbs file in QtCreator. I do have gmp installed in my OS (sudo pacman -S gmp).

gmp is found, but I get this error:

ofxCorkCsg.cpp:58: undefined reference to 
`ofxCorkCsg::resolveIntersections(ofxCorkCsg::MeshWrapper const&, 
ofxCorkCsg::MeshWrapper const&, ofMesh_<glm::tvec3<float, (glm::precision)0>, 
glm::tvec3<float, (glm::precision)0>, ofColor_<float>, glm::tvec2<float, 
(glm::precision)0> >&)'

My OF is recent, but not from git. I’ll try from git next. If my approach to adding gmp is wrong I’ll be happy to hear suggestions :slight_smile: