There are cases where I want to provide Bullet with a simplified mesh
rather than using btShapeHull, so I fed bullet with the exact same vertecies as the original model I rendered
as a starting point. (Just using btConvexTriangleMeshShape to btRigidBody instead)
btIDebugDraw show all the vertices in correct position, I dropped some Bullet collision primitives on top of my mesh,
and was surprised that the collision was more or less unchanged to when I had used btShapeHull, in other words, not very precise
for this detailed model.
Anyone know why this happens? Via the debugger I can verify that Bullet has the vertices, yet it simulates a simplified model..
Code: Select all
ConvexDecomposition::WavefrontObj obj;
if (obj.loadObj("ausfb.obj") > 0) {
if (m_physicsMesh) {
delete m_physicsMesh;
}
m_physicsMesh = new btTriangleMesh();
for (int i = 0; i<obj.mTriCount; i++) {
int index0 = obj.mIndices[i * 3];
int index1 = obj.mIndices[i * 3 + 1];
int index2 = obj.mIndices[i * 3 + 2];
btVector3 vertex0(obj.mVertices[index0 * 3], obj.mVertices[index0 * 3 + 1], obj.mVertices[index0 * 3 + 2]);
btVector3 vertex1(obj.mVertices[index1 * 3], obj.mVertices[index1 * 3 + 1], obj.mVertices[index1 * 3 + 2]);
btVector3 vertex2(obj.mVertices[index2 * 3], obj.mVertices[index2 * 3 + 1], obj.mVertices[index2 * 3 + 2]);
m_physicsMesh->addTriangle(vertex0, vertex1, vertex2);
}
m_physicsMeshShape = new btConvexTriangleMeshShape(m_physicsMesh);
m_physicsMeshShape->setMargin(0.0);
m_physicsMeshShape->setUserPointer(this);
}
...........
m_btTransform = new btTransform;
m_btTransform->setIdentity();
m_mass = 0.0f;
bool isDynamic = (m_mass != 0.f);
btVector3 localInertia(0, 0, 0);
if (isDynamic) {
m_btConvexHullShape->calculateLocalInertia(m_mass, localInertia);
}
if (m_btRigidBody) {
delete m_btRigidBody;
}
m_defaultMotionState = new btDefaultMotionState();
m_btRigidBody = new btRigidBody(m_mass, 0, m_physicsMeshShape, localInertia);
m_btRigidBody->setFriction(10.0);
m_btRigidBody->setUserPointer(this);
m_btRigidBody->setHitFraction(1000.1);
m_object->setRigitBody(m_btRigidBody);
static RendererBase *rb = (RendererBase *)RInstance.rendererInterface();
static PhysicsEngineBase *peb = rb->physicsEngineBase();
peb->addRigidBody(m_btRigidBody);
glm::vec3 scale = vec3(1.0);
physicsUpdateTransformation(m_object->pos(), scale, m_object->degree(), m_object->rotAxis());