Search code examples
wpfcollision-detectionmeshbulletbulletphysics

Mesh-mesh Bullet collision detection


I am using BulletSharp to integrate Bullet into a WPF application. My scene includes 2 instances of CollisionObject whose CollisionShape is a BvhTriangleMeshShape(), and a sphere.

 DefaultCollisionConfiguration collisionConf = new DefaultCollisionConfiguration();
        CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConf);
        CollisionWorld world;
        world = new CollisionWorld(dispatcher, broadphase, collisionConf);

        CollisionFilterGroups myGroup = (CollisionFilterGroups) 1;
        CollisionFilterGroups collideMask = (CollisionFilterGroups) 4; 

        foreach(var ob in obstacles)
            world.AddCollisionObject(ob.BulletObj.ColObj);

        CollisionObject sphere_A = new CollisionObject();
        double radius_A = 700;
        Point3D ptA = new Point3D(3000, -200, 2800);
        BulletSharp.Matrix tr_A = new BulletSharp.Matrix();
        tr_A.set_Rows(0, new Vector4(1, 0, 0, 0));
        tr_A.set_Rows(1, new Vector4(0, 1, 0, 0));
        tr_A.set_Rows(2, new Vector4(0, 0, 1, 0));
        tr_A.set_Rows(3, new Vector4((float)ptA.X, (float)ptA.Y, (float)ptA.Z, 1));
        sphere_A.WorldTransform = tr_A;

        SphereShape sphere_shape_A = new SphereShape((float)radius_A);

        //Set the shape of the sphere
        sphere_A.CollisionShape = sphere_shape_A;
        world.AddCollisionObject(sphere_A);


        world.PerformDiscreteCollisionDetection();

Sphere-mesh collision works properly on both models. However, when I try to check mesh-mesh collision detection it doesn't work. I see this might be more a Bullet problem rather than a BulletSharp problem.

QUESTION: Do sphere objects default to a different mask group? Is there a different configuration to enable mesh-mesh collision detection? enter image description here


Solution

  • The problem is BvhTriangleMeshShape only supports static objects. There is no proper collision handling for triangle meshes. Instead Bullet advises users to use convex decomposition for dynamic objects and use a btCompoundShape composed of btConvexHullShapes.