Let’s assume that there are 100 cubes on the floor, and 100 cubes are falling down on them. (Ofc physics effect)
And I need to save those positions and rotations, for next step.
At next step, there are 200 cubes on the floor(above cubes) and again 100 cubes are falling down.
and so on…
So for this purpose, I think at least I need to manage out 2 trickies.
smooth physics implementation for hundreds of cubes.
save and rerender positions and rotations (actually place objects there is no matter, but when it comes with physics, I think there could be an explosion issue)
So, I hope you understand what my idea is.
Could anybody suggest me the best physics library in this case?
Actually, saving position and rotation data is no problem.
But the problem is how to avoid explosion issue when place cannon bodies to saved position and rotation.
I’ve had issues with stability/stacking and exploding simulations… it’s also not as fast as some of the other/wasm’d libraries. It’s a nice library since it’s all JS but it isn’t as complex/fully featured, or battle tested as simulators like ammo(bullet)/havok/physx/jolt…
Stable stacking is one of the main “tests” of physics engines. Good engines can simulate large stacks, in a stable way. Less advanced ones will either slow down a lot, or explode.
All of them can handle small stacks reasonably well… but the bigger the stack, the more tricks are required to get stability.
If you’re just getting used to using physics engines, then cannon isn’t a bad choice… especially since you can see the source, but as you start to encounter problems with scaling it up, keep in mind that there are more advanced engines available.
Yeah, maybe…
Actually I have used only cannon yet.
It’s easy to use, but seems not efficient in some ways, as you said.
And also seems not maintained over 2 years now…
I am gonna try any other physics engine this time, but not all of them.
So, let me clarify requirement.
There is a cone shaped glass like this, and I need to drop hundreds of boxes there.
As I said at first, placing those boxes in the glass at the saved position/rotation is an other problem I have to solve.
So, hope you understand what I need to do with physics.
In this case, which library could you recommend?
Anyhow, since I know only cannon, I tried 300 cubes on plane simply.
Its fps varies between 45 to 60, maybe not bad…
But it will be worse on mobile…
I think I really need better engine.
You could monitor the performance and adjust the simulation step. Thus, when the animation is slow, you make bigger steps in the physics simulation and the cubes will appear as moving faster.
Note that bigger step makes motion faster, at the cost of less accuracy. Fps will not be improved.
You could also put some of the cubes to sleep (e.g. those that are not expected to move, at the bottom of the cup), so they do not waste simulation time.