Bullet btBvhTriangleMeshShape Not Colliding

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Bullet btBvhTriangleMeshShape Not Colliding

Post by kklouzal »

I'm attempting to create a btBvhTriangleMeshShape out of a large mesh in my application and use it as a Rigid Body. This Rigid Body will make up the 'ground plane' which is static and never moves. The problem is everything falls straight through like it's not even there. Here's the current source:

Code: Select all

    btTriangleMesh* tMesh = new btTriangleMesh();
    irr::scene::IMeshBuffer* MB = WorldNode1->getMesh()->getMeshBuffer(1);
 
    irr::video::S3DVertex* Vertices = (irr::video::S3DVertex*)MB->getVertices();
    irr::u16* Indices = MB->getIndices();
 
    for (irr::u32 i = 0; i < MB->getIndexCount(); i+=3)
    {
        irr::core::vector3df Tri1Pos = Vertices[Indices[i]].Pos;
        irr::core::vector3df Tri2Pos = Vertices[Indices[i+1]].Pos;
        irr::core::vector3df Tri3Pos = Vertices[Indices[i+2]].Pos;
 
        tMesh->addTriangle(btVector3(Tri1Pos.X, Tri1Pos.Y, Tri1Pos.Z), btVector3(Tri2Pos.X, Tri2Pos.Y, Tri2Pos.Z), btVector3(Tri3Pos.X, Tri3Pos.Y, Tri3Pos.Z));
    }
 
    btCollisionShape* groundShape = new btBvhTriangleMeshShape(tMesh, false);
    btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -1, 0)));
    PH->CreateRigidBody(0, groundMotionState, groundShape);
PH->CreateRigidBody() is just a helper function to quickly create rigid bodies, I know this function works properly since other objects use it and collide just fine.

Any insight into the issue here would be greatly appreciated. Thank you all very much for your time.
Dream Big Or Go Home.
Help Me Help You.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Bullet btBvhTriangleMeshShape Not Colliding

Post by hendu »

Enable debug drawing and see where it is.
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Bullet btBvhTriangleMeshShape Not Colliding

Post by kklouzal »

Thank you very much hendu for the suggestion, I went ahead and got it setup and it appears to be in the correct location, here is a shot from the underneath of the mesh since you can't see the debug drawings from above it:
Image
The red outline conforms correctly to the outside of the mesh, however I'm not sure what the green boxes are. The spherical rigid bodies have a red box around them so I'm assuming the red is the collision hull?
Dream Big Or Go Home.
Help Me Help You.
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Bullet btBvhTriangleMeshShape Not Colliding

Post by kklouzal »

I hooked up an event receiver to spawn a rigid body sphere at the camera position and started flying around spamming spheres, it seems like they only collide with the green areas. So does that mean something's wrong with my mesh? Or something's wrong with the code I posted above to create the physics object out of the mesh?
Heres an above shot of the actual mesh for clarification:
Image
Dream Big Or Go Home.
Help Me Help You.
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Bullet btBvhTriangleMeshShape Not Colliding

Post by kklouzal »

I fixed it. The issue was that the mesh uses multiple materials so I need to also iterate through all the meshbufers, not just mesh buffer 0, whoops ^.^**
Dream Big Or Go Home.
Help Me Help You.
Post Reply