How to clip a 3D shape?

Suppose I have two boxes. They intersect each other. How can I make it so that one is clipped so it doesn’t intersect the second one? (Sort of like Ardor3D’s ClipState…?) Is there any code like:


Box b1=new Box(Vector3f.ZERO, 10, 10, 10);

Geometry geom1 = new Geometry(“Box1”, b1);

// apply material and stuff

geom1.setLocalTranslation(-5, 0, 2);

Box b2=new Box(Vector3f.ZERO, 10, 10, 10);

Geometry geom2 = new Geometry(“Box1”, b2);

// apply material and stuff

geom2.setLocalTranslation(5, 3, -1);

geom1.clipToOutsideShape(geom2); // anything like this?


i think your best bet is to use this as a jumping off point:

…as you can see, there is a known problem with normals. in my own attempted implementation i’m finding that after any of the boolean operations are applied, the new buffers seem to be way larger than they need to be. setting the geometry to render using lines instead of tris, it looks as though there is a lot of verts/indexes that are leftover after the CSG part is done (see below); these are being picked up by jme, but will only render if you choose line mode or point mode instead of tri mode. the problem isn’t jme, it’s unboolean, and it may not be a problem at all. it may be that the lines are just a result of a not-optimized-for-line-strip index buffer. i just haven’t had the time to look into it. here is an archive with all of the source files mentioned in the original post above, modified a little to work directly with jme geometry.

anyhow, this is using 2 boxes, one ‘cutting’ out a section of another:

and here is the very same result rendered using lines:

…notice how many more lines are there? i think before you or i, or anyone else attempts to use unboolean in jme for whatever end result they desire, we need to come up with a vertex/index cleanup procedure (assuming this is actually a problem) and get a handle on the normals.

also, the result you describe doesn’t sound possible using simple CSG; i think you can still get what you want by a crafty combination of operations, though.