"Better" CSG Operations/Mesh Booleans

Hi everyone,

I programmed Mesh Boolean operations, which are very similar to CSG operations (like Union, Intersect, and Difference) but can work on any type of mesh input. For example this is the intersection (union and difference do both work as well, but for examples sake) between a torus and a box:

For reference, this is how they are intersecting at the start

Here is the cube being manually moved with real time updates:

Here is the cube automatically rotating with real time updates:

There are two main issues for now, how to get rid of the artifacts and how to make the performance faster. I haven’t really optimized it at all, so I think there is a lot of room for improvement on that regard (spatial datastructures, mesh-connectivity caching, general caching stuff more, cleaning up code). The artifacts only happen here and there, so I’ve been having a hard time debugging it. But I’ll update when I do either of the two above ^^^

Sorry for the visual clutter in the background, I was working on a few different projects at once

Lmk if anyone has a suggestion for a project to use this on, I was thinking of something to do with maybe blacksmithing or procedurally fracturing an object along a pattern

Edit: Here is an example for difference

18 Likes

how did u do this ?
‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

4 Likes

This is incredible! When the part is rotating it creates an interesting visual.

Great job for real!

3 Likes

This is awesome! It would be a great concept for something like a 4D platformer

3 Likes

I based the mesh boolean algorithm off of a simplified model of this paper: Interactive and Robust Mesh Booleans https://arxiv.org/pdf/2205.14151 (simplified in that it doesnt use intermediate representations of intersections)

In brief

  1. The algorithm finds the intersections of every triangle pair within the two input meshes (Detect intersections step)
  2. From those intersection points, I insert them into a mesh connectivity structure that has references between elements (like triangles, vertices, edges). (Insert point step)
  3. I then constrain the edges from those intersection points, updating the mesh as I go. (insert segments)
  4. When both shapes do not intersect at any point, then I fire a ray upwards from every single new triangle to see whether it should be kept or destroyed (Jordan Curve theorem)

Sorry that it is a bad explanation that doesn’t get into the technical side, but once I clear up the code and fix some of the edge cases I’d be happy to go FOSS or explain in more detail

:tada:

3 Likes

Ooh thats a really cool idea! Maybe I could have a slider at the bottom of the screen to represent the 4th axis :thinking:

Once I get this up and running (faster, since if the entire environment uses this mesh boolean my PC might explode) I’ll be sure to give this a try :head_shaking_vertically:

2 Likes

Are you planning on releasing this? It would be so useful to CSG with editable meshes

Thanks for the interest! I was planning on releasing it, but around a month after I posted Roblox uploaded their Creator Roadmap: 2025 End of Year Recap that included

that should release early 2026. So its probably best just to wait for that to upload, rather than taking my design for it.

3 Likes

Actually I would prefer your version, there’s some limitations in GeometryService API and I would like to start where you ended

If you want to start this project back up, id be happy to help you. But I’m not going to share the code since there are some architectural liberties I took that I should not have taken (my method is an approximation since it uses floating point numbers, so not robust. If I were to redo it, I’d use exact predicates & floating point filters)

1 Like