Split mesh with 2 solids into 2 meshes

Hi All-

I am using CSGs to split a mesh into 2 pieces. The result is a single mesh with 2 solid areas:

https://playground.babylonjs.com/#0ZUCZB#1

Is there a simple way to break this into 2 meshes? I tried getting the indices and vertices and grouping the facets by whether or not they share a common corner but I was not able to make that work.

Thanks for any thoughts.

-flex

I think it’s possible that a face has its own 3 vertices that are not shared by other faces, so relying on indices to group faces won’t work. You will need to use the vertex positions instead, and consider that you can group two faces if at least one of their vertex are close enough (each x/y/z coordinates are less than a small epsilon apart).

Thanks, Evgeni-

if at least one of their vertex are close enough (each x/y/z coordinates are less than a small epsilon apart).

Yes. I figured that out by trial and error. Like:
if (v1.subtract(v2).length() < smallEpsilon) v1 = v2.clone()

Also seeing if approach in this playground might work:

There is an alternative involving using CSG twice. A bit more involved but, I think, it gives you want you need

https://playground.babylonjs.com/#0ZUCZB#3

1 Like

@flex The approach in this PG is what @JohnK essentially did: applying two times a CSG operation, one to extract the left part and another to extract the right part.