Hello everyone, let me start off by saying thank you very much for your time.
I have a vector of Vertices and Indices that describe my "World Geometry" and after looking through the provided tutorials can't seem to find one that deals with creating a ridged body shape out of the raw triangle data. The closest thing I've found is the Terrain Demo which deals with heightmap data. The only other information I think to add which is relevant would be that the triangle data describes a static mesh, so no "moving parts" and it will also make up my ground plane.
I appreciate your time, thank you.
Which btShape For Non-Heightfield Terrain?
Re: Which btShape For Non-Heightfield Terrain?
After some research I found btBvhTriangleMeshShape is what I need. After setting it up however my objects just fall through the mesh. Here's what I've done:
PH->CreateRigidBody() is just a helper function to quickly create Rigid Body's and I know that works fine because other objects use it and they collide just fine.
Have I missed anything here?
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);
Have I missed anything here?
Re: Which btShape For Non-Heightfield Terrain?
I went ahead and got the debug drawer setup and the physics mesh 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:
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?
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:
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?
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:
Re: Which btShape For Non-Heightfield Terrain?
Aren't the 'green boxes' just the values you added to the bvhTriangleMesh ? Pretty sure the red box is just the bounding box for the whole shape. maybe your mesh has some holes in it ? might be worth putting a simple plane collision object as a base level to stop things falling through?