Why is mesh collision shape implemented as compound collision?

After fiddling around with ammo.js and creating my own bindings/extending bullet physics, I’ve found out that playcanvas implements the mesh collision shape as compound shape.

Is there any reason to do so, instead of using a btBvhTriangleMeshShape with multiple IndexedMeshes for each meshInstance?

I guess the convexHull shape wouldn’t work anymore, but that could be an extra collision type.

When selecting a type for the CollisionComponent I would expect the following:
compound → btCompoundShape
mesh → btBvhTriangleMeshShape

However mesh also results in a btCompoundShape with btBvhTriangleMeshShape as its children

It was done when I was not around, but I believe it was done so because models that are set as mesh collider could have multiple mesh instances.

With model you mean the old ModelComponent? Same should apply for the RenderComponent.

However this doesn’t rule out using a btBvhTriangleMeshShape as it’s MeshInterface can have multiple IndexedMeshes (I think this is the bullet counterpart of mesh instances).
btTriangleIndexVertexArray has addIndexedMesh which can add a IndexedMesh to the MeshInterface

I cannot comment, as it was ages ago. I don’t even know what Ammo supported at the time. Is there a use case that you are not able to do with the current implementation?

Doesn’t bother me too much, now that I know it.
It’s more of a general question as I was kind of confused when I logged the bullet physics shape type and it returned COMPOUND_SHAPE_PROXYTYPE instead of TRIANGLE_MESH_SHAPE_PROXYTYPE which I was expecting.

I thought it might be advantagous to change it, so playcanvas doesn’t differ from the bullet behaviour.
However I don’t think this is possible without a breaking change, because of the convex hull behaviour.
Might be a candidate for 2.0.0

1 Like

@will might have some thoughts here

@LucaHeft It appears the Bullet API you’re referring to is not exposed in the ammo.idl, as far as I can tell. However, there’s nothing to stop us from submitting a PR to the ammo repo to expose it. But unless there’s a major benefit from doing so (performance, lower memory requirements, better simulation behavior), I’m not sure why we’d do it. The compound shape approach has served us well for years. But feel free to make the case, and better yet, if anyone wanted to take a stab at submitting a PR that would improve the engine in this area, be my guest! :smile: