# Constructive Shape Geometry Implementation

Following progress from my posts on here: http://hub.jmonkeyengine.org/forum/topic/constructive-solid-geometry-code-for-jmonkey-give-away/

Here’s an outline of what’s been done:
Fully ported csg.js library (MIT license) to Java, using JMonkeyEngine’s Vector3f.
Added function to produce a Mesh from the CSG object.
Made CSG.shapeName( static functions into classes that extend CSG.
Created CSGNode class, which is used to sequentially add CSG brushes and output 1 geometry (Soon to be node)
Created a MeshBrush, which reads the TexCoord, Normal, Position and Index buffers of a Mesh to product a shape which can be used for CSG.

Still left to do:
Add Material support on a per-brush level.
Add UV calculations to standard shapes (Cube, Sphere, Cylinder)
LOD support? (Or polygon reduction)

This will be released once the last of the ‘to do’ are done.

Below are some screenshots of what it can produce:

And finally, in JME itself:

8 Likes

The bottom one was constructed using the following code:
CSGNode csg = new CSGNode();
csg.setMaterial(mat_csg);
CubeBrush base = new CubeBrush(new Vector3f(0f, 0f, 0f), new Vector3f(1f, 1f, 1f));
SphereBrush hole = new SphereBrush(new Vector3f(0f, 0f, 0f), 1.3f, 16, 8);
hole.setType(BrushType.SUBTRACTIVE);
csg.regenerate();
csg.move(0f, 1f, 0f);
this.app.getRootNode().attachChild(csg);[/java]

This is so very useful. You ought to share the source code someplace like github/bitbucket (unless you already did and I just missed it).

Are the Brushes actual meshes? Would it be possible to add a converter jmemesh to brush? or are they something special due to technical/algorithm reasons?

@Empire Phoenix said: Are the Brushes actual meshes? Would it be possible to add a converter jmemesh to brush? or are they something special due to technical/algorithm reasons?

I’ve already added support for MeshBrush, which is a JME mesh. However, It doesn’t seem to work with any type of intersection with planes. I’ll have to look into this.

3 Likes

Wow, this is really huge! You should really consider contributing the library to the contrib repo when you are finished.

I’ve fully added support for using a mesh as a brush. Here’s the construction code:

CSGNode csg = new CSGNode();
csg.setMaterial(mat_csg);

``````		Spatial s = assetManager.loadModel("Models/Characters/Goblin.j3o");
ArrayList&lt;Geometry&gt; g = new ArrayList&lt;&gt;();
GeometryBatchFactory.gatherGeoms(s, g);
Mesh m = new Mesh();
GeometryBatchFactory.mergeGeometries(g, m);
MeshBrush mb = new MeshBrush(m);
CubeBrush base = new CubeBrush(new Vector3f(0f, 0.5f, 0f), new Vector3f(1f, 0.1f, 1f));
base.setType(BrushType.SUBTRACTIVE);

csg.regenerate();
csg.move(0f, 1f, 0f);
this.app.getRootNode().attachChild(csg);[/java]``````
2 Likes

Please release the source code as soon as possible! Don’t hold it hostage since you seem to be one of the few doing any sort of work in this area for jme3.

Plus I want to be able to test, review, and send you patches!

If you post the source as a zip I can set up a permanent github repository for you.

Yep I would definitly like to take a look as well, and play around with it.

Hey,

Sorry, I haven’t made any progress on this and don’t currently have enough time on my hands to continue it, so here it is:
http://uppit.com/pedjp7s7nbeu/src.rar

I got most of the issues fixed (mesh brush working).

Alright here is the repo if anyone just wants to view the source code:

https://github.com/asperous/fabian-csg

Also Fabian, do you agree to release this code under the BSD License? Otherwise there won’t be any hope in integrating it into jme3.

4 Likes
@asperous said: Alright here is the repo if anyone just wants to view the source code:

https://github.com/asperous/fabian-csg

Also Fabian, do you agree to release this code under the BSD License? Otherwise there won’t be any hope in integrating it into jme3.

Well…
Originally, csg.js was licensed under the MIT license. However, considering this doesn’t have the “that part of your brain now belongs to us” clause, I believe that gives me the right to license this port (which does have quite a few changes). So sure, BSD would be fine.

You guys just wait and see what this leads on to cough [video]http://www.youtube.com/watch?v=vrEIQzUQ3DY[/video]

This is so very useful. You ought to share the source code someplace like github/bitbucket.

This post was flagged by the community and is temporarily hidden.