Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concave collision detection in Bullet

I am a Bullet rookie, so I apologise in advance if my questions sound trivial to you.

I need to load a set of concave triangle meshes from .stl files and perform collision detection. Objects can be moved by the user. From the user manual, I read: "CONCAVE TRIANGLE MESHES: For static world environment, a very efficient way to represent static triangle meshes is to use a btBvhTriangleMeshShape."

Hence, my questions are: - can Bullet detect collisions between concave mesh objects modelled using the BvhTriangleMeshShape? - what is the real difference between contactTest and CollisionWorld::PerformDiscreteCollisionDetection() - do I need to specify a different collision algorithm for concave collision detection?

I am working with BulletSharp a maintained C# wrapper of Bullet. what I did, was set up my bullet environment:

CollisionConfiguration bt_collision_configuration;
CollisionDispatcher bt_dispatcher;
BroadphaseInterface bt_broadphase;
CollisionWorld bt_collision_world;

double scene_size = 500;
uint max_objects = 16000;

bt_collision_configuration = new DefaultCollisionConfiguration();
bt_dispatcher = new CollisionDispatcher(bt_collision_configuration);

float sscene_size = (float)scene_size;
Vector3 worldAabbMin = new Vector3(-sscene_size, -sscene_size, -sscene_size);
Vector3 worldAabbMax = new Vector3(sscene_size, sscene_size, sscene_size);
bt_broadphase = new AxisSweep3_32Bit(worldAabbMin, worldAabbMax, max_objects);
bt_collision_world = new CollisionWorld(bt_dispatcher, bt_broadphase, bt_collision_configuration);    [/code]

And load my CollisionObjects as BvhTriangleMeshShape.

To detect collisions, I used:

contactTest(object, callback)

The result with this code is that the ContactResultCallback::NeedsCollision function is called every time two bounding boxes intercept, but no manifolds are found if 2 meshes intersect.

And secondly:

    bt_collision_world.PerformDiscreteCollisionDetection();
    int numManifolds = bt_collision_world.Dispatcher.NumManifolds; 

Using this secondary code, no manifolds are found at all.

like image 613
Nic Avatar asked Sep 19 '15 12:09

Nic


1 Answers

As you've already read in manual, btBvhTriangleMeshShape can be used for static objects only. This means that there is no collision algorithm for two objects of this type (because if all of them are static, they cannot collide). As you tried, you can test the intersection of their bounding boxes, but no collision manifold will be ever created.

If you wonder what is the use of btBvhTriangleMeshShape, it is meant for detecting precise collision between convex dynamic objects and static concave environment.

The official solution suggested by Bullet is to perform convex decomposition of every concave model that is used for moving objects. The preferred method for convex decomposition is HACD (Hierarchical Approximate Convex Decomposition). An example can be found in Bullet Examples.

Another algorithm worth trying is V-HACD (Volumetric Hierarchical Approximate Convex Decomposition), which produces shapes with better topology than the previous one but convex hull is less precise - the result collision shape is bigger then the original mesh. The error rate can be controlled by the resolution but it slows down the process.

like image 62
Estiny Avatar answered Oct 04 '22 09:10

Estiny