Jump to content
  • Advertisement
Sign in to follow this  
JohnOram

GLMmodel to bullet shape btConvexTriangleMeshShape

This topic is 2607 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.



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;

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);
}


I get this error:



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
Advertisement
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.



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

// populate triangle mesh
for (int i=0; i<model->numtriangles; i++){
GLMtriangle *triangle = &model->triangles;
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;
}


hopefully this will be helpful to someone.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!