ofxCSG - Constructive Solid Geometry Addon

I recently found a great little library for doing boolean operations on 3D solids in Java:
http://unbboolean.sourceforge.net/

Greg Santucci made a port of this to C++ and I cleaned it up today and made an openFrameworks addon.

The good news is that it was relatively simple to plug into OF, the bad news is that it seems to be a little buggy. I am posting the first iteration of the addon here in hopes that someone will find it useful, and maybe pick apart some of the bugs - namely it seems to lock up with certain geometry.

Granted there are a number of other more robust libraries out there for doing this kind of thing, for example GTS, but they are overkill for what I am doing at the moment.

I know there are a bunch of people working on 3D geometry out there, so perhaps they can pick it up and offer suggestions.

Download-ofxCSG

very nice - your package was missing the box.txt file but I think I found it from the c++ port and attached it

-edit: can’t seem to attach so here are the contents:

  
8  
0 -5.00000000000000E-0001 -5.00000000000000E-0001 -5.00000000000000E-0001  
1  5.00000000000000E-0001 -5.00000000000000E-0001 -5.00000000000000E-0001  
2 -5.00000000000000E-0001  5.00000000000000E-0001 -5.00000000000000E-0001  
3  5.00000000000000E-0001  5.00000000000000E-0001 -5.00000000000000E-0001  
4 -5.00000000000000E-0001 -5.00000000000000E-0001  5.00000000000000E-0001  
5  5.00000000000000E-0001 -5.00000000000000E-0001  5.00000000000000E-0001  
6 -5.00000000000000E-0001  5.00000000000000E-0001  5.00000000000000E-0001  
7  5.00000000000000E-0001  5.00000000000000E-0001  5.00000000000000E-0001  
  
12  
0 0 2 3   
1 3 1 0   
2 4 5 7   
3 7 6 4   
4 0 1 5   
5 5 4 0   
6 1 3 7   
7 7 5 1   
8 3 2 6   
9 6 7 3   
10 2 0 4   
11 4 6 2   
  

I’m using the following for a polygon to test and try and sort out some of the bugs (note: for some reason I get an error saying “The extension txt is not allowed” when I try to attach the file.

  
  
12  
0 0.518821 -2.301279 0.75924  
1 2.907626 -0.476381 2.494788  
2 -0.393603 -0.476381 3.56744  
3 -2.434377 -0.476608 0.759241  
4 -0.396816 -0.481579 -2.058847  
5 2.907626 -0.476381 -0.976308  
6 1.466729 2.53378 3.676656  
7 -1.874369 2.479042 2.497929  
8 -1.883142 2.484513 -0.985858  
9 1.431245 2.476381 -2.04896  
10 3.471567 2.476381 0.75924  
11 0.518761 4.347496 0.758974  
20  
0  
2  
0  
1  
1  
1  
0  
5  
2  
3  
0  
2  
3  
4  
0  
3  
4  
5  
0  
4  
5  
1  
5  
10  
6  
2  
1  
6  
7  
3  
2  
7  
8  
4  
3  
8  
9  
5  
4  
9  
10  
10  
6  
1  
11  
6  
7  
2  
12  
7  
8  
3  
13  
8  
9  
4  
14  
9  
10  
5  
15  
6  
10  
11  
16  
7  
6  
11  
17  
8  
7  
11  
18  
9  
8  
11  
19  
10  
9  
11  
  
  

Sorry about that, it was kinda late last night when I uploaded it…
Anyway, I updated the download file with a full example including an xcode project and the following primitives that came with it:

box.txt
cone.txt
cylinder.txt
sphere.txt

If you want to see an example of the buggyness, here is a simple test case based on the example:

  
  
void testApp::draw(){  
  
	cout << "Framenum: " << ofGetFrameNum() << endl;  
	  
	// Rotate seems to be very buggy...  
	solid2.rotate(0, 1, 0, 1);  
	  
	// Must call setup again to define the new solids  
	model.setup(&solid1, &solid2);  
  
	// The resulting solid is allocated in memory so must be deleted when done  
	//ofxCSGSolid *result = model.getIntersection();  
	//ofxCSGSolid *result = model.getUnion();  
	ofxCSGSolid *result = model.getDifference();  
	  
	ofPushMatrix();  
	// The rest is the same as the test example  
  

This seems to run ok 21 times, then it freezes.
If you turn on ofSetLogLevel(OF_LOG_VERBOSE); the last log info printed is “OF_VERBOSE: Object2 - Classify faces of Object1”
Which tells us the issue is happening someplace inside:

  
void Object3D::classifyFaces(Object3D & object);  

I haven’t seen any explicit behavior like SIG errors, it just seems to be caught in an infinite loop or something…

Karl

Hello!

I cant get the example to run on xcode5.
First I had problems with #includes from boost lib.

Once I got over them I start to get semantic and parse issues on the file with this header:

//===-------------------------- exception ---------------------------------===//
//
// The LLVM Compiler Infrastructure

please help

thank you