Hmm but at what point do we see this list of vertices/indices (and WHERE)? And can anyone else confirm that there is no way to extract this information AFTER the body has been created? That seems odd...
You wanted the code, you got it!
Here goes:
Include things
Create a cube
Code: Select all
const int NUM_TRIANGLES = 12;
const int NUM_VERTICES = 8;
const int NUM_INDICES = NUM_TRIANGLES * 3;
btScalar gVertices[NUM_VERTICES * 3] = {
// Front
btScalar(-0.5), btScalar(-0.5), btScalar(-0.5),
btScalar(0.5), btScalar(-0.5), btScalar(-0.5),
btScalar(0.5), btScalar(0.5), btScalar(-0.5),
btScalar(-0.5), btScalar(0.5), btScalar(-0.5),
//Back
btScalar(-0.5), btScalar(-0.5), btScalar(0.5),
btScalar(0.5), btScalar(-0.5), btScalar(0.5),
btScalar(0.5), btScalar(0.5), btScalar(0.5),
btScalar(-0.5), btScalar(0.5), btScalar(0.5)
};
int gIndices[NUM_INDICES][3] = {
//Front
{0,1,2},
{0,2,3},
//Back
{4,5,6},
{4,6,7},
//Bottom
{0,1,5},
{0,5,4},
//Top
{3,2,6},
{3,6,7},
//Left side
{4,0,3},
{4,3,7},
//Right side
{1,5,6},
{1,6,2}
};
Create the softbody
Code: Select all
btSoftBody* cubeSoftBody = btSoftBodyHelpers::CreateFromTriMesh(pdemo->m_softBodyWorldInfo, gVertices, &gIndices[0][0], NUM_TRIANGLES);
cubeSoftBody->m_cfg.kDF = 0.5;
cubeSoftBody->m_materials[0]->m_kLST = 0.1;
cubeSoftBody->m_cfg.kMT = 0.05;
cubeSoftBody->randomizeConstraints();
cubeSoftBody->scale(btVector3(6,6,6));
cubeSoftBody->setTotalMass(100,true);
cubeSoftBody->setPose(true,true);
Create placeholders for indices and vertices (this is the stuff you wanted, right?)
Code: Select all
//Vertices
std::map<int, btSoftBody::Node*> vertices;
//Indices
std::vector<int> indices;
Extract the vertex and index information from the btSoftBody (only needed when the softbody is created)
Code: Select all
//Temporary placeholder for nodes
std::map<btSoftBody::Node*, int> node_map;
for(int i = 0 ; i < cubeSoftBody->m_faces.size() ; i++) {
btSoftBody::Face face = cubeSoftBody->m_faces[i];
for(int j = 0 ; j < 3 ; j++) {
if(node_map.find(face.m_n[j]) == node_map.end()) {
node_map.insert(std::make_pair(face.m_n[j], node_map.size()));
}
}
for(int j = 0 ; j < 3 ; j++) {
indices.push_back(node_map.find(face.m_n[j])->second);
}
}
//Reverse node->index to index->node (should be unique on both sides)
std::map<btSoftBody::Node*, int>::const_iterator node_iter;
for(node_iter=node_map.begin(); node_iter != node_map.end(); ++node_iter) {
vertices.insert(std::make_pair(node_iter->second, node_iter->first));
}
//Add softbody
pdemo->getSoftDynamicsWorld()->addSoftBody(cubeSoftBody);
And now, all you need to do to sync your vertexbuffers every frame in Ogre is to iterate through the indices (vector) OR vertices (map).
Code: Select all
//Iterate through the indices
for(int i = 0 ; i < indices.size() ; i++) {
btSoftBody::Node* node = vertices.find(indices.at(i))->second;
std::cout << "update vertex with index: " << i << " [v](" << node->m_x.x() << " " << node->m_x.y() << " " << node->m_x.z() << ")" << std::endl;
}
//OR
//Iterate through the vertices
std::map<int, btSoftBody::Node*>::const_iterator it;
for(it=vertices.begin(); it != vertices.end(); ++it) {
int v_index = it->first;
btSoftBody::Node* node = it->second;
std::cout << "update vertex with index: " << v_index << " [v](" << node->m_x.x() << " " << node->m_x.y() << " " << node->m_x.z() << ")" << std::endl;
}
It may not be the best of code, but It works for me.. Let me know if things are still unclear.