Optimization of a scene with physical objects

I have about 1000 physical objects on stage, which greatly affects computer performance. It is necessary to optimize. I decided to divide the scene into chunks with physical objects. That is, immediately the objects will not be physical at all, they will be ordinary. If a player enters the chunk, I turn on physics objects. Can I make sure that those objects that don’t fall into the camera’s view freeze? That is, if the physical body fell - it will stop and freeze in the air

With ammojs, you can set threshold values for sleeping state:

If the body linear or angular value is below a threshold, it will be in sleep mode. It will not move until a new contact or an impulse.
So, I would try to set that value so newly created physics objects are in sleeping mode. When you leave the chunk and you want to remove the chunk’s physics objects, check that there are not moving. When an object is not moving anymore, if it’s not in the current chunk, then you can remove it.

Can you tell me how I can verify that the object is within the camera’s visibility?

Sure! you can try with this method : Camera - Babylon.js Documentation

1 Like