Construct/Modify Models Programmatically! Constructive solid geometry (CSG) code inside

Hello everyone!

Wouldn’t it be cool to be able to generate objects using shapes =D? Check out this image: [PovRay: Villarceau Circles CSG]. This was constructed entirely from basic shapes. Imagine being able to build/modify objects/shapes
within jMonkeyEngine.

Awhile back @fabian did the hard work of porting csg.js to jMonkeyEngine.

The code is here: github: andychase/fabian-csg

The project is seeking people to help us test its functionality, clean up the codebase, align it to jMonkeyEngine standards/best practices, etc. If you are interested please dive in and send pull requests or link stuff in this thread. Thanks!


I actually made some progress on this front.
I added a system of assigning values to vertices. This was done through an interface - Lerpable. Lerpable:
[java]package org.fabian.csg;

public interface Lerpable<T> {
public T lerp(T destination, float progression);
public T clone();
public T get();
public void set(T val);

You would make a class to implement this. I had LerpableVec2f, LerpableVec3f and LerpableFloat.

Then, you can assign each vertex an arbitrary number of vertex values.
public void setValue(int idx, Lerpable value)

It was really quite an eloquent system. This way, I could have UV, Temperature (for predator vision etc) and more with very little effort.

The issue with textures that I encountered was that I was unable to apply textures on a per-face basis. I think what might need to be done is the CSGNode will have to produce an atlas of textures, and then the texture index for each face is stored in an unused mesh buffer OR you could use 3-Dimensional textures + coordinates.

For my own edification and entertainment, I have been re-implementing the CSG code provided by fabsterpal. In particular, a Material assigned to a primitive will carry into the surface it generates in the final shape. Of course, it all remains open source and is available from the jMonkeyCSG SourceForge project.

Hey @wcomohundro!

Thanks for your interest in this project and for making your efforts open source. Your documentation about your project is quite thorough and I’m grateful for the shoutout.

The reason why CSG interests me personally is because of the potential of being able to dynamically change or build geometry during gameplay.

  • Imagine a racing game where the terrain is slightly modified while driving, like jeeps going through soft dirt. You could have a wheel shape continually boolean difference-ing with the ground (creating shallow grooves) and that could effect the physics calculations of the other cars (creating more bumps, slowing them down etc).

  • Another example would be a networked game where terrain comes from mesh tiles unioned together (to prevent extra non-rendered edges from slowing things down).

  • Or like in an rpg when you enter a house you could do a difference between house and a large square to create a nice looking cut out, and then union with random props to populate the house.

My point is CSG is important and so I’m glad you are really glad you are making efforts towards this. I’m definately going to be watching your project. Good luck and have fun!

Replying to @fabsterpal

Those changes look cool! If you send me them I can look over them and possibly integrate them into the repository.

As for the textures, I think texture atlas is an optimization, possibly you’d have to calculate the exact position of the face on the texture and overwrite it, but I’m not 100% sure how I would know how to do that. csg.js kinda cheated since they can just change the color per vertex which is easier than texture math.

This is a very cool project. And I hope it goes ahead to become a valuable jME tool.

Refining the Texturing ability / method would be a big plus; and Vertex painting would be a nice addition (if its possible).

A Wiki page should probably be started, so that people can see a full example along with screen shots.

I can definitely see me using this in my projects, since most of my geometries are built up out of primatives, but currently, I just put them together in blender and import them. But doing that, there is little ability to change a model once loaded. This API could give us this feature.

I can see me integrating this into the world editor as a brush tool :smile:
Just to be sure, the wrapper is also bsd license?

@Empire_Phoenix Yeah it’s all freely licensed. Fabian has released his work under BSD and it was ported from csg.js which is MIT.

Using CSG as a brush tools would be really cool! I think that’s how Adobe Flash implements their vector tools.