Collision problems in compound body, Impostor debug and blender workflow

Hello !

I’m trying to allow collisions with two or more complex meshes. I use primitives like Boxes, spheres, cylinders to cover the mesh for the collision. I do everything in blender and it seemed to work well.

But I noticed some problems with my way doing it. Sometimes, collision is done without “touch” between colliders like the impostor was bigger or with another rotation. Sometimes it just pass through, specially at corners.
The physics debug panel show the impostors with strange sizes. Always smaller but with correct rotations.
It seems to be correlated when I parent colliders to an empty compound object. If I do a simple box with impostor, the impostor size is correct. When parenting to a compound body, it’s smaller. It’s still working (strangely) but if I rotate it following quaternion advice from the docs, it behaves like not rotated (but the impostor is in good rotation).

https://www.babylonjs-playground.com/#RPJWFT#17

My actual blender workflow is like that:
-the actual visual mesh with scale(1,1,1), rotation (0,0,0),position(0,0,0). Origin as center of mass and snap the object to center of grid.
-creating colliders in object mode so the scale can be (2,6,1), rotation(x,y,z) and a position. Origin as center of mass.

If I rotate the mesh in edit mode so manipulating the vertices, the rotation in babylon for the impostor will be wrong.

Thanks for help :slight_smile:

Hi Spyrou… thanks for the detailed trouble-report and supporting playground. Nice work!

https://www.babylonjs-playground.com/#RPJWFT#20

Wingnut experimenting. (also in #18 and #19). I set main model slightly visible. There’s some seriously-desperate hacking in there… mostly me… wandering-around blindly in the dark. heh. I’m no pro and I’m behind “the curve”. These days, @trevordev is primary physics custodian, I think… so he stands pinged. :slight_smile: (thx t-dev)

Back in the “old days”, @RaananW was physics custodian, and he discovered that it was a BIG pain… to scale a mesh with an impostor “affected” (already added). He coded a new thing… mesh.physicsImpostor.setScalingUpdated(). You can see a remarked-out version in line 108 of the #20 PG. It is to be called AFTER a scaling adjustment on a p-mesh (physics-active mesh). As far as I know, it removes old impostor and adds a new one of same type.

I have some boundingBox.extends testing on boxes[1] in some places… to watch-for children being scaled… when parent is scaled. I would expect… that after a compoundBody.physicsImpostor.setScalingUpdated()… the children’s impostors would all need setScalingUpdated(), as well. I’m not sure that compoundBody.physicsImpostor.setScalingUpdated() is doing any (automatic) updating of the children.

Another rumor… and warning seen in #20 console: You must affect impostors to children before affecting impostor to parent. Briefly, I THINK this means… for compounds… we should add impostors to children FIRST, and then add (no)Impostor to parent… later. PG #20 does it that way. Lines 79-81 add the child impostors, and line 84 does the parent. Still, I get the warning at console. Not sure why.

I dunno much about noImpostor, but I think it might be wise to do tests… with a standard (invisible or micro-tiny) box with boxImpostor… as a master parent for the compound. Just an idea to test. Currently, setScalingUpdated() on the blankMesh… acts strange. Perhaps that would change… when parent is a full mesh with boxImpostor. Worth some tests. I don’'t think a blank mesh has a boundingBox, so it is difficult to check ITS .extends measurements (after a scaling).

You might wish to remove lines 92-93 of #20 PG… SOON… before any further experimenting on that PG. Changing the childrens’ Quats… back to Eulers… is likely “a desperate reach” on my part. heh.

Ok, that’s all I have. Not much help, huh? Sorry. But, maybe now you have some more “toys” to experiment-with, anyway. Stay tuned for more (and likely better) info/wisdom from others.

Thanks for all the testing Wingnut :).

I followed the docs for the compound body: Create Compound Bodies - Babylon.js Documentation where they insist on adding child impostor before parent impostor ^^.

https://www.babylonjs-playground.com/#RPJWFT#22

In PG22 I tried to simulate my blender colliders. From my blender file, I have a visual_mesh and somme colliders. Each collider has a position, scale and a rotation.
For now, the position and the scale works fine if added before impostor.
But the rotation act strangely. If I change the rotation before impostor, even with rotationQuaternion (Positioning, Rotating, Scaling - Babylon.js Documentation) it rotates the object but also the noImpostor object(??). So I have to reset the position of the compound body in the end. The rotation seems to break the physics because the impostor debug display an impostor(very small by the way) with a good rotation but the collisions are completly false.

I already had this strange behaviour of rotations with my meshes where a rotation has been applied on creation (without my consent ^^).

If I don’t set a compound, I remove the NoImpostor et remove the parenting, each cube has a normal sized and rotated impostor in the inspector debug and the physics works fine.

So I guess the problem is in the rotation of childs within the compound or in my way doing them.

EDIT: it seems to work fine with AmmoJSPlugin (https://www.babylonjs-playground.com/#RPJWFT#23). The rotation of the boxes before parenting doesn’t rotate the futur parent and the physics works fine.

1 Like

Glad it sounds like AmmoJS is working. It is a known issue that this only works with Ammo (Use a Physics Engine - Babylon.js Documentation which says " Currently works with AmmoJS plugin only")

Are you dependent on using an engine that isn’t Ammo or are there any other issues you are hitting with Ammo?

No I think ammo will be fine. I want to simulate ligaments and muscles (so basically springs), I think ammo can do that but I didn’t test it yet.
Yeah I saw the warning on the docs (that’s why I tested with Ammo) but the exemples on the playground uses Cannon and seems to work fine so I thought the doc was out of date ^^ (Create Compound Bodies - Babylon.js Documentation).

Thanks for the answer :).

Finally I’ve got some issues. It’s how to use it correctly.
I can only create a Babylon.SpringJoint with Cannon.
For Oimo, I saw some PG using nativParams:{spring[200,2]} and I’ve also found this nativParam in the OimoPlugin file so I gues I can do i also in Oimo.
But I didn’t see any line with nativParams for Ammo in the plugin file.Do I have to use directly Ammo with stuff like Bullet Collision Detection & Physics Library: btGeneric6DofSpring2Constraint Class Reference ?
I’m kinda lost.

This is not really my area of expertise, but just pointing out that the Blender exporter does transfer imposters shapes from Blender. It appears your picture is using a bunch of meshes for that. There is a mesh type shape imposter type, which I think uses the actual mesh itself. If this is not the conversation I think it, just disregard.

1 Like

Ow I did’nt saw that I can export rigidbodies from blender ! Thanks.
But doesn’t 24 vertebrae with mesh impostors put too much stress on the physics engine ?

@Spyrou for the using ammo specific features, take a look at physicsImpostor.physicsBody this object is marked as any type because it is the native physics object for the physics body.

If you look at Babylon.js/ammoJSPlugin.ts at master · BabylonJS/Babylon.js · GitHub in generateJoint, you could try to implement much of what is done there in your own app code for a specific constraint that is not exposed.

1 Like

Thanks !
I already did it. I even posted a New topic in question ( Spring joint with AmmoJS ) I solved myself. Everything si fine :slight_smile:.

1 Like