Using CSG with MergeMeshes

Ver: 7.7.0
Playground:

Desc:
I’m building a scene that digs a hole when the button at the top right of the scene clicked, and when the wireframe mesh moved and the btn clicked again, it digs another hole.
Firstly I tried to use subtractInPlace again and again on the same csg, but it goes too much slower after 3 clicks.
Then I looked at MergeMeshes, expecting using it to get a merged mesh of all holes to dig, and subtract the csg with it being faster, but the result looks wrong.
Also, it’s also acceptable if a way is found making csg faster with multiple subtractInPlace.

Here are playgrounds tuned for faster reproduction of this:
Expected(but very slow):

Actual:

There’s unfortunately nothing that can be done (except maybe using another algorithm to compute CSG). CSG creates many faces very quickly, so after you’ve applied CSG a few times, your mesh can contain a lot of faces and it becomes exponentially slower to apply new CSG operations.

So, do it mean that the performance of csg can not be improved? What about the mergemeshes? Any ideas of making merged mesh work with csg?

I don’t know if the current CSG algorithm can be improved, it’s an external contribution I think, so it’s hard to know. But we already had this problem in the past with no good solution.

I’m not sure what you mean by having merge meshes work with CSG… Merge meshes simply merge the vertex buffers of multiple meshes into a single mesh, so in the end you end up with a regular mesh.

Even if it is just a single mesh, your poly count will go through the roof too quickly.

You need to look into “destructible environments” and see what approaches fit your project/purpose.

If you need e.g. dynamic caves, google for how “Red Faction 1” or “Deep Rock Galactic” did it. Or Minecraft.

I made a merged mesh from meshes in different positions, expecting that subtract a csg created from the merged mesh would result like running subtractInPlace multiple on csgs from meshes in different positions, but fails.

Perhaps check out the solution in a past thread with a related issue: