Using Bullet to test collision between triangle meshes

marcusl
Posts: 6
Joined: Fri Jan 15, 2010 8:57 am
Location: Gothenburg, Sweden

Using Bullet to test collision between triangle meshes

Post by marcusl »

Hi,

I want to check collision/penetration depth between 5 (convex & concave) triangle meshes that move a bit now and then, and have tried various ways to do this.
(It's mechanical system that needs collision protection, so I figured that using enlarged 3d-models and a physics engine/collision detection library would be a good thing. I only need discrete checks, not continous detection.)

What I do is to change the WorldTransform of these objects, step the simulation, then check for collision pairs from the CollisionDispatcher's manifold.
In my code I create either btGImpactMeshShape or btBvhTriangleMeshShape for each mesh, and they look ok in when viewed via the DebugDrawer, but I'm not getting any collisions. If I use btSphereShape:s, I get collisions.

Related, I just found http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=4359 which says that TriangleMeshes don't support dynamic objects.
Am I using the wrong approach, or is it something subtle that needs doing?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Using Bullet to test collision between triangle meshes

Post by Erwin Coumans »

There is no 'TriangleMesh' in Bullet, so we need to be more precise and use the class names.

If you want to detect collisions between concave triangle meshes, it is best to either approximate them using convex decomposition, for example creating several btConvexHullShape and store them into a btCompoundShape. See Bullet/Demos/ConvexDecompositionDemo. Alternatively, you can use a btGImpactMeshShape, but not as child of a btCompoundShape.

For static, non-moving triangle meshes you can use btBvhTriangleMeshShape, but there is no collision between static (non-moving) btBvhTriangleMeshShapes. Collisions are detected between a btBvhTriangleMeshShape and a btGImpactMeshShape..
marcusl
Posts: 6
Joined: Fri Jan 15, 2010 8:57 am
Location: Gothenburg, Sweden

Re: Using Bullet to test collision between triangle meshes

Post by marcusl »

Thanks for replying!

By "TriangleMesh" I was referring to any type of triangle-soup-supporting btCollisionShape (i.e. btBvhTriangleMeshShape and btGImpactMeshShape)-

Do I understand you right that there are no collisions between btBvhTriangleMeshShape:s and btBvhTriangleMeshShape:s, nor between btGImpactMeshShape:s and btGImpactMeshShape:s, but only between objects of different types, i.e. btGImpactMeshShape:s and btBvhTriangleMeshShape:s, where the bvh-shape is static?

If I can get this to work, I'll try to add a tutorial to the wiki, since it seems a basic yet non-trivial issue.(at least for new users, like myself).
marcusl
Posts: 6
Joined: Fri Jan 15, 2010 8:57 am
Location: Gothenburg, Sweden

Re: Using Bullet to test collision between triangle meshes

Post by marcusl »

I solved it by using btBoxShape for the boxy stuff. I won't need btGImpactMeshShape as much as I thought.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Using Bullet to test collision between triangle meshes

Post by Erwin Coumans »

marcusl wrote: Do I understand you right that there are no collisions between btBvhTriangleMeshShape:s and btBvhTriangleMeshShape:s, nor between btGImpactMeshShape:s and btGImpactMeshShape:s, but only between objects of different types, i.e. btGImpactMeshShape:s and btBvhTriangleMeshShape:s, where the bvh-shape is static?
This is not correct. Generally there are collision detection routines between all collision types, even if the types are the same, except for a few (static) exceptions such as btStaticPlaneShape and btBvhTriangleMeshShape. There is collision detection between btGImpactMeshShape and btGImpactMeshShape.

Thanks,
Erwin
marcusl
Posts: 6
Joined: Fri Jan 15, 2010 8:57 am
Location: Gothenburg, Sweden

Re: Using Bullet to test collision between triangle meshes

Post by marcusl »

Ok. Thanks! I just wanted to make things absolutely clear. :)
marcusl
Posts: 6
Joined: Fri Jan 15, 2010 8:57 am
Location: Gothenburg, Sweden

Re: Using Bullet to test collision between triangle meshes

Post by marcusl »

I solved this a few weeks ago (as we needed to fix mesh-mesh collisions). I had forgotten to register the GImpactCollisionAlgorithm:

Code: Select all

btGImpactCollisionAlgorithm::registerAlgorithm(&m_collision_dispatcher);
This is necessary or it won't work.