Performance problem with milling simulator

Hey everyone, I´m currently working on a project: a milling machine simulator. To make material to be able to continuously being “cut”, I made a cube made of thousands of other cubes, so when the “cutting object” touches a small cube it will be destroyed. The main problem is that I have around 24k cubes so the performance is affected.
I already made some changes that really help, like:

  • Batching, reduce like 20k batches to 73
  • Disable all kinds of shadows
  • Mark as Static all objects that don´t move.
  • Occlusion seems to not really helping because all the cubes are literally in the camera´s point of view. (Or if anyone knows a good setup with this will be helpful).
  • The cubes materials are GPU instancing

After all this, it goes around 25-30 fps but when the table is moving it drops to 10-15 fps.
Somebody knows how can i increase the performance?
I also see that the physics get really overwhelm, only have 1 rigidbody the rest is just meshes.

Some pictures and thanks in advanced :slight_smile:



8494955--1130588--upload_2022-10-6_17-20-59.png

I would recommend just using one mesh with a ton of vertices, then displacing those in the vertex shader. Similar to how it is done for snow on terrain in many games. Another option would be to do 2D polygon cutting using some kind of library like Clipper : Clipper2 - Polygon Clipping and Offsetting Library
Either of these would probably offer better performance.

If you are limited by the amount of geometry then perhaps think about dynamic subdivision (quadtree style) of the block where the drill bit is. Then only the region around the bit needs to be fully divided to the smallest grain size.
Also, as the bit cannot get to the bottom without cutting through the top, the subdivision can be done layer by layer.

some kind of marching cubes mesh could work also.

24k objects is not that much, if they get batched too,
do the boxes have colliders too? (that shouldn’t be needed, if check manually)

can you share part of the code that hits and removes boxes?

How can i check it manually?
Yes, they do have colliders.
8498987--1131515--upload_2022-10-8_12-43-0.png

things to experiment / look for:

  • not using colliders, but manually check if drill is inside 3d grid cell (since your blocks are not moving anyway)
  • have many tall cubes (for each position, instead of having many cubes on top of each other) and then make them shorter on hit (this might even work with colliders)
  • if the cutter doesn’t rotate, then basically all you need is a heightmap that you modify (make it lower based on drill tip)
  • use high resolution mesh cube, move vertices down based on drill tip (can try manually looping closest vertices to move, or use shader, or rendertexture, similar to heightmap)
  • voxel/marching cubes mesh (this might be best looking)

You need to use voxels for something like this and not cubes. Voxels are not cubes.

Also your cubes shouldn’t be actual objects but rather something rendered using DrawMeshInstancedIndirect.

Because that’s the way to render a huge number of objects.

Obviously you’ll need to implement your own collsiion with the milled objects too.

If the player can’t rotate the detail they work on, and can’t rotate the cutter, a single heightmap mesh will be enough.

1 Like