Bug(?) with AmmoJS and ConvexHullImposter

Hi everyone,

I may have found a bug, but it’s possible I’m doing something wrong. However, I haven’t found any solutions by searching the forums.

The problem seems to be that when using the ammo.js plugin and creating a ConvexHullImposter, the imposter is the wrong size - that is, the collisions imply that the imposter is bigger than the mesh it’s attached to. This results in a gap between the mesh and the ground, when it’s colliding.

Here’s a sandbox reproduction, using an icosahedron, but it happens with other polyhedrons as well: https://playground.babylonjs.com/#64KNQR#1

If I replace the ConvexHullImposter with a BoxImposter, the issue goes away.

Thanks in advance!

cc @Cedric and @RaananW

Hi @plonq and welcom to the forum

I’m not surprised. There is Phsyics Engine specific code to compute Convex hull. It’s a trade off between performance and accuracy. I would suggest to see if you can improve precision a little by orienting the mesh a bit differently and baking the vertices.It’s just a guess and I’m not sure about the result. But as the convex hull is an approximation, it might help to have more faces oriented along world planes.

Thanks for the suggestion @Cedric! I will definitely try tweaking the mesh to see if that makes any difference.

However, is there a way to force Babylon to use the actual literal mesh data, instead of ‘approximating’ it? Even if I have to define the vertices manually. I’m using simple meshes for the colliders, and I want the physics imposter to exactly match it.

Well, I’ve found a simple, albeit imperfect and hacky, solution - scale the collider mesh. Since the problem is scale, not shape. With some trial and error it results in a good-enough result. Here’s the same playground with only one line change: https://playground.babylonjs.com/#64KNQR#2

That line is:

colliderInstance.scaling.scaleInPlace(0.87);

UPDATE: well, this actually resulted in some weirdness. When scaled down, the facet normals (via getFacetNormal(...) are different, which is no good for my use case. Maybe something I’m missing, but either way doesn’t seem like a good solution.

I also found AmmoJSPlugin.onCreateCustomConvexHullImpostor which sounds like it could be used to create custom imposters, but there’s no documentation and I couldn’t find any examples (and the any return type isn’t helping).

UPDATE2: Figure I’d put another update, in case it helps others. It seems as though ConvexHullImposter (at least with Ammo) creates a collider that is a fixed distance from the mesh. That is, if I scale up everything really big, then the distance between the mesh and the ground while it’s resting will be the same absolute distance, but relative to the size of the object it’ll be much smaller. So one possible ‘solution’ is to scale everything up until that distance is small enough relative to the object to not matter.

1 Like