Which physics engine is prefered in this case?

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.

  1. smooth physics implementation for hundreds of cubes.
  2. 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?

you can use cannon-es as physique engine and use ecsy as schema to store cube positions

this is code for ecsy schema :

import { Component, Types } from "three/examples/jsm/libs/ecsy.module.js";

export class ClassName extends Component {
    position: { type: Types.Ref },
    rotation: { type: Types.Ref },
    etc: { type: Types.Ref}
}

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.

Ammo, Jolt, Havok, PhysX, or Rapier. I would avoid cannon.

Cannon.js, oimo.js for small world.

Could you give me hint why you do not recommend cannon?

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…

Yeah, actually it’s not big one…
As I said, there are only hundreds of same cubes, and one cone shaped cup to put them all in.

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.

2 Likes

These ones have official examples with instancing of boxes and spheres.

2 Likes

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.

In cannon-es the method for this is World.step(…)

Yeah… but actually what we need is improving fps, isn’t it??
Or do I get you wrong?

Rapier 40fps (objects go through self), Jolt 20fps (objects go through self), Ammo 5fps (objects not go through self)

Huh?
For 300 cubes?

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.

2 Likes

For 400 cubes and 400 spheres. Total 800 objects.

400 boxes in Ammo 60fps, Jolt 30fps, Rapier 60fps

That’s so interesting!!
Could you share me any references or docs for that?