Concave collision detection in Bullet
Asked Answered
M

1

6

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.

Moline answered 19/9, 2015 at 12:27 Comment(0)
A
6

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.

Armilda answered 19/9, 2015 at 18:17 Comment(2)
Thank you very much @Estiny. I will use convex decomposition then. Just another question. You mentioned: "btBvhTriangleMeshShape is meant for detecting precise collision between convex dynamic objects and static concave environment." For the sake of clarity, say ob1 is convex and ob2 is concave, I understand this will work: - import ob1 and ob2 into collision world - change ob1 transformation - 'contactTest(ob1, callback)' And this won't work: - import ob1 and ob2 into collision world - change ob2 transformation - 'contactTest(ob2, callback)' Am I mistaken?Moline
@Moline You understood it correctly. Assuming that ob1 is any convex shape and ob2 is btBvhTriangleMeshShape, the second case won't work properly because Bullet will think that ob2 is still in the same place, so it will collide with it's previous position instead of the new one.Armilda

© 2022 - 2024 — McMap. All rights reserved.