Box jumpin' on triangle edges

Sussch
Posts: 2
Joined: Fri Jan 14, 2011 10:55 am

Box jumpin' on triangle edges

Post by Sussch »

Hi,

I think I have the typical problem of a rigid body with btBoxShape sliding across multiple static btBvhTriangleMeshShapes.

So, I took an attempt at using btInternalEdgeUtility to solve the problem. Well, it got better and the box jumps a lot less on triangle edges, but it still jumps. Played around with btTriangleInfoMap coefficients, but didn't manage to get things any better.

My guess is that I might be using too small collision shapes or something. Perhaps with bigger shapes, these anomalies at the edges would become insignificant?

Anyway, here's what I do with the triangle meshes:

Code: Select all

                // Let's assume that this works ok
                shape = converter.createTrimesh();

                btTriangleInfoMap* triangleInfoMap = new btTriangleInfoMap();

                // btGenerateInternalEdgeInfo fills in the btTriangleInfoMap and stores it as a user 
                // pointer of trimeshShape (trimeshShape->setUserPointer(triangleInfoMap))
                btGenerateInternalEdgeInfo( ( btBvhTriangleMeshShape * ) shape, triangleInfoMap );
And after creating a rigid body of the mesh in ground state:

Code: Select all

                // Let's assume that creating rigid body works well
                // and 'body' is a pointer to btRigidBody
                body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK );
Then the ContactAddedCallback:

Code: Select all

// Let's assume that the assignment of contact_added_callback to ContactAddedCallback works well
// because fiddling around with the arguments of btAdjustInternalEdgeContacts changed the
// behavior of the jumping
static bool contact_added_callback( 
    btManifoldPoint& cp, const btCollisionObject* colObj0, 
    int partId0, int index0, const btCollisionObject* colObj1, int partId1, int index1 )
{

    // Find the triangle mesh object and the other object
    const btCollisionObject *trimesh = colObj0, *other = colObj1;
    int trimesh_pid = partId0, other_pid = partId1;
    int trimesh_id = index0, other_id = index1;
    // Make sure we're giving btAdjustInternalEdgeContacts the right arguments 
    if ( colObj1->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE ) {
        trimesh = colObj1;
        trimesh_pid = partId1;
        trimesh_id = index1;

        other = colObj0;
        other_pid = partId0;
        other_id = index0;
    }

    btAdjustInternalEdgeContacts( cp, trimesh, other, trimesh_pid, trimesh_id );

    return false;
}
Any ideas?

Thanks
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Box jumpin' on triangle edges

Post by Erwin Coumans »

Please try reproducing it in the Bullet/Demos/InternalEdgeDemo so someone can have a look at it.

It is best if shape dimensions are larger than say 0.4 units.
Thanks,
Erwin
Sussch
Posts: 2
Joined: Fri Jan 14, 2011 10:55 am

Re: Box jumpin' on triangle edges

Post by Sussch »

Ok, thanks.

Updated bullet from repository and it all went unstable. So, chances are that my problem lies somewhere else and it would still all be working nicely without jumps. :)

Edit: Nope, the instability came from using setContactProcessingThreshold( 0.0f ) for character capsule (using simple rigid body for this). The problem still remains.

btTriangleInfoMap only contains connectivity info for a specific triangle mesh. But when there is a transition between multiple triangle meshes, then these jumps are still there. I wonder if it were possible to somehow merge and unmerge triangle meshes with certain coefficients for snapping vertexes together.

Another idea that popped into mind would be to temporarily offset the trimesh from which objects are moved so that things would always be moving like downstairs instead of stopping at sharp edges.

InternalEdgeDemo.cpp with 2 triangle meshes: http://pastebin.com/zXzy1hg6

Slightly out-of-topic: It would be convenient if attaching .cpp files were allowed..