Hi I've created an object with
btSoftBody* psb = btSoftBodyHelpers::CreateFromTriMesh(softBodyWorldInfo, o->vertices, o->indexes, o->num_triangles);
I then perform a step of the physics engine and want to read the triangles data back from the physics engine.
btSoftBody::tFaceArray& faces(psb->_faces);
for (int i = 0; i < object->num_triangles; ++i) {
object->triangles.vertex[0].set( faces.m_n[0]->m_x.getX(), faces.m_n[0]->m_x.getY(), faces.m_n[0]->m_x.getZ());
object->triangles.vertex[1].set( faces.m_n[1]->m_x.getX(), faces.m_n[1]->m_x.getY(), faces.m_n[1]->m_x.getZ());
object->triangles.vertex[2].set( faces.m_n[2]->m_x.getX(), faces[i].m_n[2]->m_x.getY(), faces[i].m_n[2]->m_x.getZ());
}
The triangles are not however coming back in the same order the were in the data I sent to CreateFromTriMesh. Am I doing this wrong? How do I read them back in the correct order? Any help much appreciated!
Triangles reading back in wrong order from btSoftBody?
-
elethiomel
- Posts: 10
- Joined: Wed Oct 27, 2010 11:05 pm
-
Mr.Orange
- Posts: 11
- Joined: Mon Apr 18, 2011 10:03 am
Re: Triangles reading back in wrong order from btSoftBody?
Hi elethiomel!
After taking a look at the bullet source code for btSoftBodyHelpers::CreateFromTriMesh
(http://bulletphysics.com/Bullet/BulletF ... tml#l00819), I got the idea that the switching of faces is caused by the very last parameter of
=>bool randomizeConstraints. By default the parameter is set to "true", which causes bullet to randomly switch faces and links within the mesh (http://bulletphysics.com/Bullet/BulletF ... tml#l00908). Maybe you should try to set it on "false".
Another way would be to completely delete your mesh from the renderer at every simulation step (or during your "load" procedure) and build it up from scratch with your bullet faces array. But that depends on the capabilities of your renderer.
Greets,
Mr.Orange
After taking a look at the bullet source code for btSoftBodyHelpers::CreateFromTriMesh
(http://bulletphysics.com/Bullet/BulletF ... tml#l00819), I got the idea that the switching of faces is caused by the very last parameter of
Code: Select all
btSoftBodyHelpers::CreateFromTriMeshCreateFromTriMesh ( btSoftBodyWorldInfo & worldInfo,
const btScalar * vertices,
const int * triangles,
int ntriangles,
bool randomizeConstraints = true
) Another way would be to completely delete your mesh from the renderer at every simulation step (or during your "load" procedure) and build it up from scratch with your bullet faces array. But that depends on the capabilities of your renderer.
Greets,
Mr.Orange
-
elethiomel
- Posts: 10
- Joined: Wed Oct 27, 2010 11:05 pm
Re: Triangles reading back in wrong order from btSoftBody?
Thank you so much for the tip! I'm at work right now, but I'll be able to try this in 5 hours.
Colin
Colin