Sign in to follow this  
JohnOram

GLMmodel to bullet shape btConvexTriangleMeshShape

Recommended Posts

JohnOram    100
Hey,

So I'm working on creating a physics model from an obj file.
I'm using the bullet physics engine, 2.77 and a GLMmodel to load the file.
I walk through the triangles in the GLMModel, and add them to the btTriangleMesh.
I'm pretty sure I need to do something else to the mesh, but can't figure out what.

[code]

btConvexTriangleMeshShape* objToCollissionShape(GLMmodel *model){

btTriangleMesh *trimesh = new btTriangleMesh();

for( GLuint i = 0; i <model->numtriangles; i++ ){
std::cout << "triangle " << i << ":\n";
GLMtriangle triangle = model->triangles[i];

GLuint index0 =triangle.vindices[0];
GLuint index1 =triangle.vindices[1];
GLuint index2 =triangle.vindices[2];
printf( "indeices: %i %i %i\n", index0, index1, index2 );

GLfloat* p0 = &model->vertices[index0];
GLfloat* p1 = &model->vertices[index1];
GLfloat* p2 = &model->vertices[index2];

btVector3* v0 = new btVector3( p0[0], p0[1], p0[2] );
btVector3* v1 = new btVector3( p1[0], p1[1], p1[2] );
btVector3* v2 = new btVector3( p2[0], p2[1], p2[2] );
std::cout << "vertex("<<index0<<"):"<<v0->x()<<", "<<v0->y()<<", "<<v0->z()<<"\n";
std::cout << "vertex("<<index1<<"):"<<v1->x()<<", "<<v1->y()<<", "<<v1->z()<<"\n";
std::cout << "vertex("<<index2<<"):"<<v2->x()<<", "<<v2->y()<<", "<<v2->z()<<"\n";
trimesh->addTriangle(*v0,*v1,*v2);
}
return new btConvexTriangleMeshShape(trimesh);
}
[/code]

I get this error:

[quote]

Overflow in AABB, object removed from simulation
If you can reproduce this, please email bugs@continuousphysics.com

Please include above information, your Platform, version of OS.

Thanks.
[/quote]



Any thoughts would be appreciated.

Share this post


Link to post
Share on other sites
JohnOram    100
I was able to get it to work.
I didn't realise that the vertex array was offset by three, for their x,y&z values.

[code]

btConvexShape* objToCollissionShape(GLMmodel *model){
btTriangleMesh *trimesh = new btTriangleMesh();

// populate triangle mesh
for (int i=0; i<model->numtriangles; i++){
GLMtriangle *triangle = &model->triangles[i];
float *vertexA =&model->vertices[3*triangle->vindices[0]];
float *vertexB =&model->vertices[3*triangle->vindices[1]];
float *vertexC =&model->vertices[3*triangle->vindices[2]];
btVector3 btVertexA(vertexA[0],vertexA[1],vertexA[2]);
btVector3 btVertexB(vertexB[0],vertexB[1],vertexB[2]);
btVector3 btVertexC(vertexC[0],vertexC[1],vertexC[2]);
trimesh->addTriangle(btVertexA, btVertexB, btVertexC);
}

// convert triangle mesh into convex shape
btConvexShape *tmpshape = new btConvexTriangleMeshShape(trimesh);
btShapeHull *hull = new btShapeHull(tmpshape);
btScalar margin = tmpshape->getMargin();
hull->buildHull(margin);
tmpshape->setUserPointer(hull);

return tmpshape;
}
[/code]

hopefully this will be helpful to someone.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this