I want to create a soft body from an arbitrary mesh and for that I use the soft body helper:
Code: Select all
btVector3* btVerts = new btVector3[vertices.size()];
for(int i=0;i<vertices.size();++i)
btVerts[i] = (btVector3(vertices[i].pos.x,vertices[i].pos.y,vertices[i].pos.z));
const int iCount = indices.size();
const int tCount = iCount/3;
int* btInd = new int[iCount];
for(int i=0;i<iCount;++i){
btInd[i] = (int)indices[i];
}
btSoftBody* softBody = btSoftBodyHelpers::CreateFromTriMesh(
((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo()
,(btScalar*)btVerts
,&btInd[0],tCount
,false
);
I get the information from the softbody nodes by their tNodeArray m_nodes this way:
Code: Select all
btSoftBody::tNodeArray& nodes(softBody->m_nodes);
for(int j=0;j<nodes.size();++j)
{
verticesIn[j].pos=XMFLOAT3(nodes[j].m_x.getX(),nodes[j].m_x.getY(),nodes[j].m_x.getZ());
verticesIn[j].nor=XMFLOAT3(nodes[j].m_n.getX(),nodes[j].m_n.getY(),nodes[j].m_n.getZ());
}
But if I get values from the softbody's nodes after creation, but before stepping any physics I don't get back my original values from the nodes (the positions): { (-1,0,-1), (0,1,0), (-1,0,1), (0,1,0) }
I even noticed the node vertices kind of resemble the originals, just "overlapped" somehow or not sure how can I describe if it is even the case, but it is like the second vector has an extra zero at the beginning and the whole mesh got screwed up.
Could it be something is not right with my loading? Or do I miss something in the concept of soft body physics?
I have studied the bullet soft body sample which is quite informative and they sure load their meshes like I do (the bunny mesh for instance), at least it seems like it. I don't have any idea and got stuck here for a day now. Without connecting to the softbody, my mesh remains correct.