# CSG alternatives

**URL:** <https://forum.babylonjs.com/t/csg-alternatives/28137>\
**Category:** Questions\
**Tags:** csg\
**Created:** [March 3, 2022, 9:37pm UTC](https://forum.babylonjs.com/t/csg-alternatives/28137 "2022-03-03T21:37:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffpennal](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jeffpennal/32/13577_2.png) [@jeffpennal](https://forum.babylonjs.com/u/jeffpennal)\
**Post date:** [March 3, 2022, 9:37pm UTC](https://forum.babylonjs.com/t/csg-alternatives/28137/1 "2022-03-03T21:37:36Z")

</div>

We are using CSG successfully here to cut meshes but the time it takes to perform these cuts depends greatly on the complexity of the meshes. Given that we can’t control for the mesh complexity (the meshes are coming from an external source), I’m exploring different options for how we can perform the CSG operations.

We have currently offloaded the cutting to our NodeJS server and are using a NullEngine, but the process isn’t any faster, it’s just non-blocking at that point.

What I’d like to do is to offload the CSG cutting to a stand-alone service and not use Javascript for the CSG operation.

So my question to the forum is, what technologies are out there for performing CSG operations that ARENT javascript based and are fast.

Any help is appreciated!

Thanks,  
Jeff

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [March 4, 2022, 12:04pm UTC](https://forum.babylonjs.com/t/csg-alternatives/28137/2 "2022-03-04T12:04:21Z")

</div>

Hello! CSG is certainly a pretty heavy operation 🙂 I think CGAL ( [The Computational Geometry Algorithms Library (cgal.org)](https://www.cgal.org/)) which is C++ based, might be a good option.

---

<div class="post-metadata">

**Author:** ![webgrid](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/webgrid/32/24940_2.png) [@webgrid](https://forum.babylonjs.com/u/webgrid)\
**Post date:** [March 4, 2022, 2:44pm UTC](https://forum.babylonjs.com/t/csg-alternatives/28137/3 "2022-03-04T14:44:25Z")

</div>

You should consider a web worker for that, I offload compute work like retargeting matrices, mesh computation, game minimap, and various assets loading.

Using web workers has been a (literally) game changer for me.

---

<div class="post-metadata">

**Author:** ![jeffpennal](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jeffpennal/32/13577_2.png) [@jeffpennal](https://forum.babylonjs.com/u/jeffpennal)\
**Post date:** [March 5, 2022, 1:02am UTC](https://forum.babylonjs.com/t/csg-alternatives/28137/4 "2022-03-05T01:02:22Z")

</div>

We looked into web workers, but that only solved the problem of doing the boolean operations off thread, the performance was still terrible.

---

<div class="post-metadata">

**Author:** ![jeffpennal](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jeffpennal/32/13577_2.png) [@jeffpennal](https://forum.babylonjs.com/u/jeffpennal)\
**Post date:** [March 5, 2022, 1:07am UTC](https://forum.babylonjs.com/t/csg-alternatives/28137/5 "2022-03-05T01:07:00Z")

</div>

Thanks for the suggestion, I ended up finding JSCAD ([https://github.com/jscad/OpenJSCAD.org](https://github.com/jscad/OpenJSCAD.org)) which has boolean operations that are “insanely” fast.

For comparison, a cut that would take 20+ minutes in BabylonJS, takes 23 seconds using JSCAD.

It was relatively easy to integrate the 2 systems as well. I used the `STLExport.CreateSTL` function to get the methods as STL, turn them into a `Buffer` that I loaded into JSCAD to perform the operations (boolean subtract and turning that back into an STL).

The “hard” part is getting the resulting cut STL back into BabylonJS. There is no easy “load this ArrayBuffer into a BabylonJS scene” like ThreeJS has. Its either Base64 (which is broken for STLs), or what I ended up doing, uploading the STL to a server a loading it into the scene from the resulting URL.

Anyhow, thanks again for the suggestion!

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 5, 2022, 1:27am UTC](https://forum.babylonjs.com/t/csg-alternatives/28137/6 "2022-03-05T01:27:09Z")

</div>

@bghgary were the base64 improvments you did not available for all loaders ?

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [March 5, 2022, 7:07pm UTC](https://forum.babylonjs.com/t/csg-alternatives/28137/7 "2022-03-05T19:07:31Z")

</div>

I do remember when I was making the STL exporter supporting binary was skipped cause screw that noise, so I assume the importer is the same its been so long now I don’t remember though.

_update_ Actually I am mistaken looks like I did add binary support to the serializer at some point. Assumingly because Gary had/has the support for the import working.

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [March 7, 2022, 4:53pm UTC](https://forum.babylonjs.com/t/csg-alternatives/28137/8 "2022-03-07T16:53:32Z")

</div>

> [@sebavan](#):
>
> @bghgary were the base64 improvments you did not available for all loaders ?

Wasn’t my changes, but it is glTF only.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [April 6, 2022, 1:46pm UTC](https://forum.babylonjs.com/t/csg-alternatives/28137/9 "2022-04-06T13:46:43Z")

</div>

Hello @jeffpennal just checking in, was your question answered? 🙂

---

<div class="post-metadata">

**Author:** ![jeffpennal](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jeffpennal/32/13577_2.png) [@jeffpennal](https://forum.babylonjs.com/u/jeffpennal)\
**Post date:** [April 6, 2022, 3:11pm UTC](https://forum.babylonjs.com/t/csg-alternatives/28137/10 "2022-04-06T15:11:23Z")

</div>

Yes it was thanks!
