Can't get BvhTriangleMeshShape to collide with anything.

danharibo
Posts: 1
Joined: Thu Aug 11, 2011 8:07 am

Can't get BvhTriangleMeshShape to collide with anything.

Post by danharibo »

I'm having some difficulty getting bvh Triangle Meshes to work with anything ( I have tired Box shapes and Capsules ), I have studied the samples and I can't seem to find where I'm slipping up.

Here is the part of my code the generates the mesh:

Code: Select all

void WorldChunk::generatePhysics()
{
	if( mPhysicsBody != NULL ) {
		OpencraftCore::Singleton->getPhysicsWorld()->removeRigidBody( mPhysicsBody );
		delete mPhysicsState;
		delete mPhysicsBody;
		delete mPhysicsShape;
		delete mPhysicsMesh;
	}

	if( mGeometry->vertexCount > 5 && mGeometry->edgeCount > 5 ) {
		btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray;
		btIndexedMesh part;

		int vertSize = sizeof( GLvertex );
		int indexSize = sizeof( GLedge );

		part.m_vertexBase = (const unsigned char*)&mGeometry->vertexData[0].x;
		part.m_vertexStride = vertSize;
		part.m_numVertices = mGeometry->vertexCount;
		part.m_vertexType = PHY_FLOAT;
		part.m_triangleIndexBase = (const unsigned char*)&mGeometry->edgeData[0];
		part.m_triangleIndexStride = indexSize * 3;
		part.m_numTriangles = mGeometry->edgeCount/3;
		part.m_indexType = PHY_SHORT;

		meshInterface->addIndexedMesh( part, PHY_SHORT );

		mPhysicsShape = new btBvhTriangleMeshShape( meshInterface, true );
		btTransform t;
		t.setOrigin( btVector3( getX() * CHUNK_WIDTH, getY() * CHUNK_HEIGHT, getZ() * CHUNK_WIDTH ) );
		mPhysicsState = new btDefaultMotionState( t );
		btRigidBody::btRigidBodyConstructionInfo ci( 0.f, mPhysicsState, mPhysicsShape, btVector3(0,0,0) );
		mPhysicsBody = new btRigidBody( ci );
		mPhysicsBody->setCollisionFlags( mPhysicsBody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT );
		OpencraftCore::Singleton->getPhysicsWorld()->addRigidBody( mPhysicsBody );
	}

}
And here is the structures I have used (GLvertex / GLedge):

Code: Select all


struct GLvertex {
	float x, y, z;
	float nx, ny, nz;
	float u0, v0;
	float r, g, b;
	int padding[5];
};
typedef unsigned short GLedge;
I have tried doing things in the same way as the demo yet it refuses to collide. In case I'm hitting some sort of limit, each Geometry piece has some 6000 vertices and edges, is this just too much data for a Triangle Mesh to deal with?
rbgrn
Posts: 12
Joined: Wed Aug 24, 2011 6:16 am

Re: Can't get BvhTriangleMeshShape to collide with anything.

Post by rbgrn »

Are the triangles looking correct in the debug view?
Karrok
Posts: 65
Joined: Fri May 13, 2011 1:11 pm

Re: Can't get BvhTriangleMeshShape to collide with anything.

Post by Karrok »

bvhTriangleMeshes require the proper dispatcher used in your world creation.

I myself finally resorted to just using the gimpact one coupled with regular triangle meshes.

If you do not want to change your world creation, use convex triangle mesh, or create a compound shape.
See the chapter on collision shapes (page 18 manual) and the collision matrix (page 21).
bvh triangle mesh falls under trianglemesh category there, so it requires the proper dispatchers/collision algorithms.
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Can't get BvhTriangleMeshShape to collide with anything.

Post by mi076 »

Karrok wrote:bvhTriangleMeshes require the proper dispatcher used in your world creation.

I myself finally resorted to just using the gimpact one coupled with regular triangle meshes.

If you do not want to change your world creation, use convex triangle mesh, or create a compound shape.
See the chapter on collision shapes (page 18 manual) and the collision matrix (page 21).
bvh triangle mesh falls under trianglemesh category there, so it requires the proper dispatchers/collision algorithms.
:?
bvh mesh shape is for static objects only and works without changing/registering algorithms or special steps during world creation.