0

Has anyone successfully compiled and used the Carve CSG library? I'm trying to use it in a project and I haven't been able to get it to work. Also, the documentation is pretty terrible. I've been looking at the Blender source and it appears to use Carve successfully, but I've been having trouble replicating it.

Here's the code I've been attempting to use, just to create a cube to use with Carve:

std::vector<carve::geom3d::Vector> vertices;

vertices.push_back(carve::geom::VECTOR(+1.0, +1.0, +1.0));
vertices.push_back(carve::geom::VECTOR(-1.0, +1.0, +1.0));
vertices.push_back(carve::geom::VECTOR(-1.0, -1.0, +1.0));
vertices.push_back(carve::geom::VECTOR(+1.0, -1.0, +1.0));
vertices.push_back(carve::geom::VECTOR(+1.0, +1.0, -1.0));
vertices.push_back(carve::geom::VECTOR(-1.0, +1.0, -1.0));
vertices.push_back(carve::geom::VECTOR(-1.0, -1.0, -1.0));
vertices.push_back(carve::geom::VECTOR(+1.0, -1.0, -1.0));

std::vector<int> f;
int numfaces = 6;

f.push_back(4);
f.push_back(0);
f.push_back(1);
f.push_back(2);
f.push_back(3);

f.push_back(4);
f.push_back(7);
f.push_back(6);
f.push_back(5);
f.push_back(4);

f.push_back(4);
f.push_back(0);
f.push_back(4);
f.push_back(5);
f.push_back(1);

f.push_back(4);
f.push_back(1);
f.push_back(5);
f.push_back(6);
f.push_back(2);

f.push_back(4);
f.push_back(2);
f.push_back(6);
f.push_back(7);
f.push_back(3);

f.push_back(4);
f.push_back(3);
f.push_back(7);
f.push_back(4);
f.push_back(0);

carve::mesh::MeshSet<3> *poly = new carve::mesh::MeshSet<3> (vertices, numfaces, f);

It seems to be getting stuck on the last line, falling into a long-running loop, then seg-faulting.

user1661773
  • 1
  • 1
  • 2

1 Answers1

0

Are you using the version from the blender source? I had some problems with that too, although I got a different kind of error. My issue was that I was not compiling using all of the same compiler flags that the blender carve library was compiled with. When I added them to my build, everything worked fine. Normally I would whine about secret compiler flags required for using a library, but it is internal to the blender project. If you are building the blender carve library via CMake, you can compile with "make VERBOSE=1" (or "ninja -v" if you are using ninja) to see exactly how everything is compiled and then modify your build appropriately. The flags I'm using (obviously these will probably change over time and across build environments; don't depend on them being correct) are:

-DCARVE_SYSTEM_BOOST -DDEBUG -DHAVE_BOOST_UNORDERED_COLLECTIONS -DHAVE_STDBOOL_H -DWITH_BOOL_COMPAT -D_DEBUG -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -D__LITTLE_ENDIAN__ -D__MMX__ -D__SSE2__ -D__SSE__

I have not tried to reduce these to a minimum required set; I just cut and pasted all the flags that seemed relevant into my exploratory/test code's build.

ejgottl
  • 2,809
  • 19
  • 18