My setup: Debian 8.8, compiling with g++, using Bullet 2.87. I use the ExampleBrowser app to debug draw everything and therefore use a CommonExampleInterface (CommonMultiBodyBase) to setup and simulate my bodies and world.
I am desperately writing this post after a long time spent looking for answers... Basically, my project is very similar to this: https://pybullet.org/Bullet/phpBB3/viewtopic.php?t=6108. I am modelling a robot (with a btMultyBody instance) and try to study possible collision between its parts. I first tried to represent the different collision shapes (loaded from STL files) with btBvhTriangleMeshShapes, but of course it did'nt work since this representation is made for static objects.
After my research, I basically found to answers :
--> Use btGImpactMeshShapes
--> Use convex decomposition in order to build btCompoundShape
I tried using btGImpactMeshShape:
Code: Select all
#include "../Importers/ImportSTLDemo/LoadMeshFromSTL.h"
#include "../OpenGLWindow/GLInstanceGraphicsShape.h"
...
void MyRobotSim::initPhysics(){
...
GLInstanceGraphicsShape* glmesh = LoadMeshFromSTL(myStLFilePath);
if (!glmesh){
throw BCImportError(component->getFileName());
}
const GLInstanceVertex& v = glmesh->m_vertices->at(0);
btAlignedObjectArray<btVector3> convertedVerts;
convertedVerts.reserve(glmesh->m_numvertices);
for (int i=0; i<glmesh->m_numvertices; i++)
{
convertedVerts.push_back(btVector3(
glmesh->m_vertices->at(i).xyzw[0],
glmesh->m_vertices->at(i).xyzw[1],
glmesh->m_vertices->at(i).xyzw[2]));
}
btTriangleMesh* meshInterface = new btTriangleMesh();
for (int i=0; i<glmesh->m_numIndices/3; i++)
{
const btVector3& v0 = convertedVerts[glmesh->m_indices->at(i*3)];
const btVector3& v1 = convertedVerts[glmesh->m_indices->at(i*3+1)];
const btVector3& v2 = convertedVerts[glmesh->m_indices->at(i*3+2)];
meshInterface->addTriangle(v0,v1,v2);
}
btCollisionShape* shape = new btGImpactMeshShape(meshInterface);
Code: Select all
btCollisionDispatcher *dispatcher = static_cast<btCollisionDispatcher *>(m_dynamicsWorld->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
I'm quiet sure that the meshInterface built here is accurate, since when I replace
Code: Select all
btCollisionShape* shape = new btGImpactMeshShape(meshInterface);
Code: Select all
btCollisionShape* shape = new btBvhTriangleMesh(meshInterface, true, true);
Should there be a difference in the btStridingMeshInterface* that both constructor get in argument? Which one?
I also tried to build directly a btTriangleIndexVertexArray instead of a btTriangleMesh, without success.
Did anyone already face these issue? Does anyone has a working demo using btGImpactMeshShapes? (since there are none in Bullet 2.87)
Regarding the convex decomposition, does anyone have an approach / demo that would help me getting started?
Thank you in advance for your answers!