Merging submeshes with same slope on csg mesh

Hi All-

Here’s a playground where I define submeshes on a csg mesh by scanning the vertices/normals for changes in slope and creating a new submesh whenever the slope changes or or merging with an existing one if a submesh with the same slope has already been created.

By merging I mean creating a submesh with a previously used index.

The merged shape is on the right. You can see the front face that is in common for both boxes is the same submesh.

Since the vertices are ordered by the order in which a mesh was added to the csg the submeshes are not contiguous and the facets overlap.

Is there a better way to do this?

Welcoming any thoughts.

Flex

I’m not sure to understand where the facets overlap in the CSG mesh? Given the start index / length info logged in the console there’s no overlaps.

However, you are creating a submesh per quad, which seems inefficient (there’s one drawcall per submesh). You should instead create a submesh for each slope and add all the faces with the same slope to the same submesh. You will have to reorganize/recreate the vertices/indices for that.

Last thing, I would not recreate a plane from a vertex+normal, I would instead work with the triangles of the mesh directly: take the slope of each of these triangles (using BABYLON.Plane.FromPoints) instead of the slope of the normal created from each vertex+normal.

1 Like

Thank you for your suggestions, Evgeni. I meant faces overlap, not facets.

I will try the approach of using the triangles and let the thread know what I come up with.

I am also working on code to simplify meshes produced by CSGs into more generic polyhedrons and will share with the forum if/when I have something that works well.

Flex