Feature Request: Built-in CSG support

CSG is a very important feature… other 3D frameworks have support for CSG built-in ( Babylon.js ), the only CSG I can find is the 7 years outdated plugin ( https://github.com/chandlerprall/ThreeCSG )

The forum is to the best place for feature requests. It’s better to post them directly at github.

Is the library that you linked to not working? It was first published 7 years ago, but the commit history indicates that it was last updated 8 months ago.

There’s also this alternative, which I’ve heard good things about, but haven’t yet tried for myself: https://evanw.github.io/csg.js/

Also GitHub - jscad/OpenJSCAD.org: Code based parametric 2D/3D CAD in Javascript

This can export to STL file. If you locate the code that generates the STL string, you can pass the output of that to the parse method of a THREE.STLLoader() (from the examples). :slight_smile: EDIT: here it is io/packages/stl-serializer at master · jscad/io · GitHub

I need something that works with ThreeJS in real time.

We currently use Chandler Prall’s CSG plug in, but, according to Lewy B, we should convert everything to using BufferGeometry ( which I think is probably right. ) and to quote Lewy B:

"However, you are also using Chandler Prall’s CSG plugin. This hasn’t been updated in over 7 years and I don’t think BufferGeometry even existed back then.

First, I’d check to see whether there are any more up to date CSG libraries available. I’ve done a quick search and nothing obvious has come up but you may find something.

If not, then I would convert the library yourself. I’ve had a look through the library and this would be, well, not easy but certainly possible with some time and effort.

If neither of those works for you, then you may find it possible to just use Geometry at the CSG step. After that you can convert to geometry:

var geometry = new THREE.BufferGeometry().fromGeometry( legacyGeometry ); 


Legacy Geometry will never be removed from the library, just the ability to render it, so this last option will work in the long term at the cost of some efficiency."

Which is why I posted here…

Exporting to STL file is not an option. This has to work in real time as the user is moving their mouse.

OK. Are you planning to offer anything that is not offered here? https://openjscad.org/
Do you need any specific features of Three.js?

Hm, I just saw the previous post. Converting from Geometry to BufferGeometry live will cause lag, just like converting to and from STL representation.

But modifying an existing (and well-designed) solution to using BufferGeometry shouldn’t be very hard, if you understand how BufferGeometry works.

Alternatively, this could be a case for a proxygeometry that imitates (part of) the Geometry interface while being a BufferGeometry on the inside. @mrdoob had a “Geometry2” project once in the past, and I have done some experiments myself (in my own WebGL framework made for a university course), where Vector3’s can take a target parameter that takes the place of the internal elements array. When that parameter is a subarray of the BufferAttribute array, you can modify e.g. the vertex positions using a vector interface. (Just remember to somehow set needsUpdate=true on the BufferGeometry before rendering.)

This is my recommendation. I don’t think that converting Chandler Prall’s library to use BufferGeometry would be that hard, just time consuming.

1 Like