Which btShape For Non-Heightfield Terrain?

Post Reply
User avatar
KKlouzal
Posts: 65
Joined: Thu Mar 06, 2014 5:56 am
Location: USA - Arizona

Which btShape For Non-Heightfield Terrain?

Post by KKlouzal »

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.
User avatar
KKlouzal
Posts: 65
Joined: Thu Mar 06, 2014 5:56 am
Location: USA - Arizona

Re: Which btShape For Non-Heightfield Terrain?

Post by KKlouzal »

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:

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 Body's and I know that works fine because other objects use it and they collide just fine.

Have I missed anything here?
User avatar
KKlouzal
Posts: 65
Joined: Thu Mar 06, 2014 5:56 am
Location: USA - Arizona

Re: Which btShape For Non-Heightfield Terrain?

Post by KKlouzal »

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:
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?

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
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Which btShape For Non-Heightfield Terrain?

Post by xexuxjy »

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?
Post Reply