Ammo.js Convex Hull Collider Position Not Correct

Yo @Cedric, @Deltakosh i guess any ammo guys out there

I have this funny issue ConvexHullImpostor. I loaded a test scene with a sample convex hull mesh called testHull from an external gltf file. I set a box and a sphere with mass of 1 WAY up top of the convex hull mesh… After 2 seconds i create the physics imposter and watch for where the box and sphere collide with the testHull… It looks like the actual physics representation of where that collider is does not match the actual mesh object. It is colliding to high.

Please check out: https://playground.babylonjs.com/#FD65RR#141

But if i use a simple BOX it is placed correctly. I read some forum post (which i cant find again) it was talking about the POSITION ORDER of how the addPoint function is called. Dunno… Does anybox have any troubles using the ConvexHullImposter on an actual convexed hull geometry and a simple box shaped mesh.

Note: I created that convex hull geometry in Unity using MIConvexHull (MIConvexHull/MIConvexHull at master · DesignEngrLab/MIConvexHull · GitHub)

This is odd. No transform hiearchy that might break. Nothing obvious here. Let me try to debug and see what I can find.

Thank you sir :slight_smile:

1 Like

Yo @Cedric … I think its the pivot point of the convex hull mesh. It looks like Bullet/Ammo.js will re-center the convexshapes around the center of the mesh. Its expecting the pivot point of the mesh to be in the center. The mesh that was the source of the convex null looks like the pivot point is at the BOTTOM of the mesh (Even in Unity). When use the inspector with the transform gizmo visible the gizmo also shows at the bottom of the convex hull mesh.

Screen Shot 2022-07-29 at 12.45.53 AM

So yeah… how would we compensate when the pivot point of the convex hull mesh is NOT in the center ?

Can you please test to call setDeltaPosition PhysicsImpostor | Babylon.js Documentation
The value would be the difference between the center (bbox center?) and the origin( 0,0,0 I guess)
If it fixes it, I’ll do a PR to do it automatically

Not sure how to get this

maybe something like this

this._tmpPositionVector.addInPlace(impostor.mesh.getBoundingInfo().boundingBox.center);
impostor.setDeltaPosition(this._tmpPositionVector);

Maybe not sure…Also… What about Delta Rotation… if the mesh is rotated, should we also do something ?

Yo @Cedric so i used Blender to SetOrigin to center and resaved as FixedHull.glb

and it works better… I think btConvexHullShape should be setMargin(0)… as per MANY posts on the gap. But centering the pivot fixed that… But i cant always use blender to recenter all the convex hull meshes, so any help in the DeltaPosition offset approach you are talking about would be great. I am not sure how to do it myself. May you can fix up the playground to do it:

Please :slight_smile:

I’m testing now

Actually, there is a delta position but it should not happen.
Add this:

convexHull.physicsImpostor.setDeltaPosition(new BABYLON.Vector3(0,0,0));

That seemed to work so far… thanks man :slight_smile:

Yo @Cedric
Edit… except for rotation… if i rotate the source mesh the collider is off as well

Can you try with

convexHull.physicsImpostor.setDeltaRotation(BABYLON.Quaternion.Identity(0));

if it doesn’t work, can you update the PG with the rotated convex hull?

Thanks so much @Cedric … the Zero Out The Delta Position and Rotation seems to be working ok now.

Thanks again :slight_smile:

1 Like