Physics: How to control rotational inertia of compound bodies?

Hi all!

I’d be interested in compound physical bodies and wonder how the rotational inertia tensor is actually determined. I was in hope that composing basic meshes (with child-parent relationship) giving each a mass would lead to an approximated inertia tensor. But obviously it isn’t.

Either do I get a runtime warning and strange physical behaviour or I need to have all children have mass=0 and only the top-level parent gets the overall mass (see below). This way I cannot model a compound e.g. of one heavy and one light sphere. The documentation about compounds is a bit contradictory as cited below.

So how to?

What comes to my mind is having multiple components connected by LockJoints (Cannon.js only)?

Hope for help,

. J

From https://doc.babylonjs.com/how_to/using_advanced_physics_features :

sphere2.physicsImpostor = new BABYLON.PhysicsImpostor(sphere2, BABYLON.PhysicsImpostor.SphereImpostor, {mass: 2, restitution: 0.8});
sphere.physicsImpostor = new BABYLON.PhysicsImpostor(sphere, BABYLON.PhysicsImpostor.SphereImpostor, {mass: 2, restitution: 0.8});

The mass will be accumulated. So this single physics body’s mass will be 4. sphere2 's physics impostor will be “disabled” and will be joined to sphere ‘s impostor, which is the main impostor. To apply impulses, set the liner velocity etc’, use sphere.physicsImpostor .

This might be true, but issues a warning at runtime:

A physics impostor has been created for an object which has a parent. Babylon physics currently works in local space so unexpected issues may occur.

In fact, the resp. samples don’t show the expected physical behavior (at least the child object has no mass or so).

Another place in the documentation (https://doc.babylonjs.com/how_to/compounds) states:

  1. Create an empty mesh to be used as a parent for the compound body;
  2. Create a range of appropriately shaped standard meshes to fit over the irregular mesh;
  3. Parent the standard meshes and the irregular mesh to the empty mesh;
  4. Calculate or estimate the mass for each standard mesh;
  5. Create physics imposters for each standard mesh with zero mass;
  6. Create a physics imposter for the empty mesh, using the NoImposter property, with the total mass of all the standard meshes.

This does not give me any control about mass distribution in the ensemble.

Pinging @Cedric and @RaananW the physics semi-gods

Hi @Joerg_Plewe

I only took a look at ammojs for now. It seems possible to have more control on inertia tensor. I’ll take closer look if I can find something useful.
If you can compute the inertia vectors yourself, I’m pretty sure to find entry points in the API quickly.

1 Like

Quick update.

Still with Ammojs, the compound shape inertia is computed this way:

The mass is distributed on the bounding box of the compound shape. That’s what is used in Babylon.
When a compound is created with ammojs, BJS use that function to compute inertia and it’s then passed as parameter infos to the body creation function.
But, there is another function in BulletPhysics that is not exposed (yet!):


Basically, if computes inertia from a transform and masses (1 per shape).
Is this what you need ?

I think I somehow get what bullet is doing there and that’s also the way I expected it to be … BUT, that requires each sub-body of a compound needs a mass, which is prohibited and forbidden by Babylon due to this runtime warning:

A physics impostor has been created for an object which has a parent. Babylon physics currently works in local space so unexpected issues may occur.

And if you try anyway … it does not work.
See the sample right from the documentation: https://playground.babylonjs.com/#PRHF00#6

And the other documentation I quoted also suggests they must have mass=0:

  1. Create physics imposters for each standard mesh with zero mass;

As done from here: https://www.babylonjs-playground.com/#492ZK0#12

And the other samples from that page. They behave as if the sub-body has mass=0, regardless what you assign and also issue the warning if you assign something !=0.

I can add some tests with Ammojs that checks if the mass is not 0. In that case, I’ll call the bulletphysics to compute an inertia that’s based on those weights distribution.
This will make the mass distribution work differently between ammo and the other physic engine.

1 Like

… and remove the runtime warning… :slight_smile:

Sounds reasonable. Unfortunately I’m tied to Cannon for I need the HeightmapImpostor (only available for Cannon?).

What about the idea to compose the body with the help of LockJoints (Cannon only) instead of parenting? Although this sounds like unneseccary computing overhead.

Like so: https://playground.babylonjs.com/#PRHF00#17

. J

You can try to use a meshimpostor with ammo. I don’t know about its memory footprint or cpu performance compare to cannon and HeightmapImpostor.

Yes, try with a lockJoints and Cannon. If it doesn’t behave how you expect it, drop me a few lines :slight_smile:

AFAIK MeshImpostor can only collide against spheres, so that will not work.

Any chance that same fix could also hold for Cannon?

I’m new to Babylon so I’d have some hard times finding out myself. But if you give me a hint on how and where the physicsBody is created, I’d do my very best…

MeshImpostor with Ammo should work with any shape (box, sphere, compounds…)

Hi @Cedric!

Sorry for coming back to this issue. Wasn’t this PG expected to work correctly with Ammo at least (without warning)? Seems it doesn’t.

Could the same fix also help with Cannon?

Thx again,

. J