Hi,
I'm using Bullet for 1 year and i have developped a simulation software using Qt, Ogre & Bullet but for a while I am confronted to
a serious problem that is the strange reaction of the concave moving shape in my environment.
I am using a btCompoundShape which is defined for concave moving objects.
But I don't want to create my own CompoundShape by adding spheres, cubes or cylinders on it, I want to read a mesh file
and insert the triangle list into the Compound Shape.
Here it is the mesh file reader and CompoundShape creation:
m_TriMesh = new btTriangleMesh();
m_ShapeMoving = new btCompoundShape();
unsigned short subCount = ptr->getNumSubMeshes();
for (unsigned short i = 0 ; i < subCount; i++)
{
SubMesh *pSubMesh = ptr->getSubMesh(i);
uint16 *pVIndices16 = NULL;
uint32 *pVIndices32 = NULL;
IndexData *indexData = pSubMesh->indexData;
HardwareIndexBufferSharedPtr buffIndex = indexData->indexBuffer;
bool use32bit = false;
if (buffIndex->getType() == HardwareIndexBuffer::IT_32BIT)
{
pVIndices32 = static_cast<uint32*>(buffIndex->lock(HardwareBuffer::HBL_READ_ONLY));
use32bit = true;
}
else
{
pVIndices16 = static_cast<uint16*>(buffIndex->lock(HardwareBuffer::HBL_READ_ONLY));
}
buffIndex->unlock();
VertexData *usedVertexData;
usedVertexData = pSubMesh->vertexData;
VertexDeclaration *vDecl = usedVertexData->vertexDeclaration;
VertexBufferBinding *vBind = usedVertexData->vertexBufferBinding;
const VertexElement *elemVPos = vDecl->findElementBySemantic(VES_POSITION);
HardwareVertexBufferSharedPtr srcBuf = vBind->getBuffer(elemVPos->getSource());
unsigned char *pSrcBase = static_cast<unsigned char*>(srcBuf->lock(HardwareBuffer::HBL_READ_ONLY)); //HBL_NORMAL
size_t numFaces = indexData->indexCount / 3;
btVector3 vertexPos[3];
uint32 vertInd[3];
float *pVPos;
for (size_t n = 0; n < numFaces; ++n)
{
int i;
for (i = 0; i < 3; ++i)
{
// get indexes of vertices that form a polygon in the position buffer
if (use32bit)
{
vertInd = *pVIndices32++;
}
else
{
vertInd = *pVIndices16++;
}
// get the vertices positions from the position buffer
unsigned char* vBase = pSrcBase + (srcBuf->getVertexSize() * vertInd);
elemVPos->baseVertexPointerToElement(vBase, &pVPos);
vertexPos[0] = pVPos[0];
vertexPos[1] = pVPos[1];
vertexPos[2] = pVPos[2];
}
m_TriMesh->addTriangle(vertexPos[0], vertexPos[1], vertexPos[2]);
}
srcBuf->unlock();
m_Shape = new btBvhTriangleMeshShape(m_TriMesh, true);
m_ShapeMoving->addChildShape(btTransform::getIdentity(),m_Shape);
}
btVector3 localInertiaTensor = btVector3(0,0,0);
m_ShapeMoving->calculateLocalInertia(10,localInertiaTensor);
m_Body = new btRigidBody(DynamicBodyMass, m_State, m_ShapeMoving, localInertiaTensor);
m_Body->setRestitution(DynamicBodyRestitution);
m_Body->setFriction(DynamicBodyFriction);
world->addRigidBody(m_Body);
So I use a TriangleMesh to put all the mesh triangles in, then I create a BvhTriangleMeshShape with the TriMesh and I add this new BvhTriangleMeshShape into the CompoundShape.
And when I start the simulation, all the coumpoundShape bounce everywhere with a non realistic movement.
I don't know why?
If anybody has an idea it will be a great help.
Moving Concave Shape Problem
-
- Posts: 12
- Joined: Thu Oct 22, 2009 12:50 am
Re: Moving Concave Shape Problem
You can only use TriangleMesh shapes with static bodies. It's not supported for dynamic bodies.
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Moving Concave Shape Problem
You should not insert a btGimpactTriangleMesh or btBvhTriangleMeshShape into a btCompoundShape. So you can use a btGimpactTriangleMesh, but not as child of a btCompoundShape.
For static, non-moving triangle meshes you can use btBvhTriangleMeshShape, and there is no collision between static (non-moving) meshes.
If you want to use moving concave triangle meshes, it is best to either approximate them using convex decomposition, for example creating several btConvexHullShape and store them into a btCompoundShape. See Bullet/Demos/ConvexDecompositionDemo.
Thanks,
Erwin
For static, non-moving triangle meshes you can use btBvhTriangleMeshShape, and there is no collision between static (non-moving) meshes.
If you want to use moving concave triangle meshes, it is best to either approximate them using convex decomposition, for example creating several btConvexHullShape and store them into a btCompoundShape. See Bullet/Demos/ConvexDecompositionDemo.
Thanks,
Erwin