CSG on a non-closed mesh

Hello everybody !

I want to use CSG.intersect function on an imported mesh.

The imported mesh is supposed to represent something very thin, so it is built like a ground : only the “surface” is built, it has no thickness.
PG : Imported mesh

The trick was to duplicate, inverse, and merge the mesh
PG : the trick to have the two sides

My problem is : when CSG is used, the “front” face (the face where the vertices normals point at) is well made, but the other side (the void :scream:) is bugged.
PG : my CSG problem :cry:

We can see that if we delete the cloned mesh, the problem is still here
PG : CSG without the clone

How can I deal with this ?

I think the problem is because the shape is “opened”

  • how can I put some volume on it ?
  • how could I close it ?

Hello! Indeed, big planar surfaces like that usually don’t work well with CSG. To get some volume of this surface, you’d have to extrude it, but that’s not the simplest task :sweat_smile: Babylon has a method to create extruded meshes, but it requires all the points to be on the XY plane (so Z=0) Extruding Shapes | Babylon.js Documentation (babylonjs.com) which isn’t the case of this mesh’s outer edges. If you have access to Blender, it would be easier to use the Solidify modifier Solidify Modifier — Blender Manual, save the solidified mesh, and then use that for CSG. This is the result I got after doing just that in your mesh and applying CSG:

Thanks for the reply !

But I don’t have access to Blender. My app is intended to use what the server gives it…

How (or when ?) a shape is “closed” ?
And why would the clone-inverse-merge method didn’t do the job ?

We’ll have to veer into computational geometry territory here, but that’s unavoidable when dealing with a bit more complex CSG. The definition of “closed” I like to go with for practical purposes is a “watertight” shape, meaning that, if I were to submerge the object in water, nothing would get in. I like this definition here too: A Formal Definition of Watertight Meshes • David Stutz. It also talks about “manifolds”, which has to do with the connectivity between the vertices and edges. Having manifold and watertight meshes is highly desirable in some areas, like 3D printing. There are many different CSG algorithms, and some of them don’t work well in “open” meshes. It’s really a limitation of the algorithm.

The clone-inverse-merge method looks fine visually at first, but it doesn’t help much with the underlying topology. I tried to sketch an example to explain this:


Before the method, we have a planar surface with some vertices and normals pointing in a direction, and after the method, we have a copy of all the vertices, but with the opposite order. However, the initial vertices and the cloned vertices aren’t connected to each other, so this new mesh is still open - even through the vertices share the same position, they don’t share any connection, and that’s the thing that determines closedness. Even worse, meshes with vertices on the same position but connected to different faces is usually a sign of bad geometry and also worsens the CSG performance.

Really, talking about mesh geometry is definitely a biig area so I’m trying to keep it simple :sweat_smile: but the gist of it would be that open shells don’t work well in CSG unless you make them properly solid.

Okay, that’s what I was afraid of…
I’ll see this with the backend team.

Thanks for your time, @carolhmj !

1 Like