1
votes

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:

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.

EDIT: After hooking up the debug drawer here is what it displays (this is a shot from under the mesh): enter image description here And for clarification here is an above shot: enter image description here

I don't know if it's an issue with the mesh itself or with the code that iterates through the vertices to create the physics mesh

1
What stops the floor falling? Have you turned on a debug view to check that isn't happening?weston
Yeah, I went ahead and hooked up the debug view and the floor is there where it should be.KKlouzal
I guess the green are the triangles and red is the binding volume. So can you explain what the floor should look like, because it looks like it has loads of gaps, it's mostly gaps in fact. So I wouldn't be surprised that a lot falls through.weston

1 Answers

0
votes

When iterating through the triangles provided via the Irrlicht Mesh Buffer I needed to iterate through ALL the mesh buffers present on the model like so:

btTriangleMesh* tMesh = new btTriangleMesh();

irr::u32 MBCount = WorldMesh1->getMeshBufferCount();

for (irr::u32 m = 0; m < MBCount; m++)
{
    irr::scene::IMeshBuffer* MB = WorldNode1->getMesh()->getMeshBuffer(m);

    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));
    }
}