(de)serialization of softbody joints working now. Resolving Issue 456.

This commit is contained in:
erwin.coumans 2010-12-16 07:41:00 +00:00
parent 4ba9cfa5a4
commit 51dc372993
3 changed files with 94 additions and 7 deletions

View File

@ -145,6 +145,9 @@ class MySoftBulletWorldImporter : public btBulletWorldImporter
btSoftRigidDynamicsWorld* m_softRigidWorld;
btHashMap<btHashPtr,btSoftBody::Material*> m_materialMap;
btHashMap<btHashPtr,btSoftBody*> m_clusterBodyMap;
btHashMap<btHashPtr,btSoftBody*> m_softBodyMap;
@ -181,6 +184,7 @@ public:
btSoftBody* psb=new btSoftBody(&m_softRigidWorld->getWorldInfo());
m_softBodyMap.insert(softBodyData,psb);
//materials
for (i=0;i<softBodyData->m_numMaterials;i++)
@ -336,6 +340,7 @@ public:
//clusters
if (softBodyData->m_numClusters)
{
m_clusterBodyMap.insert(softBodyData->m_clusters,psb);
int j;
psb->m_clusters.resize(softBodyData->m_numClusters);
for (i=0;i<softBodyData->m_numClusters;i++)
@ -400,6 +405,8 @@ public:
#endif //
psb->updateConstants();
m_softRigidWorld->getWorldInfo().m_dispatcher = m_softRigidWorld->getDispatcher();
@ -409,6 +416,85 @@ public:
}
}
//now the soft body joints
for (i=0;i<bulletFile2->m_softBodies.size();i++)
{
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
{
btAssert(0); //not yet
//btSoftBodyFloatData* softBodyData = (btSoftBodyFloatData*)bulletFile2->m_softBodies[i];
} else
{
btSoftBodyFloatData* softBodyData = (btSoftBodyFloatData*)bulletFile2->m_softBodies[i];
btSoftBody** sbp = m_softBodyMap.find(softBodyData);
if (sbp && *sbp)
{
btSoftBody* sb = *sbp;
int i;
for (int i=0;i<softBodyData->m_numJoints;i++)
{
btSoftBodyJointData* sbjoint = &softBodyData->m_joints[i];
btSoftBody::Body bdyB;
btSoftBody* sbB = 0;
btTransform transA;
transA.setIdentity();
transA = sb->m_clusters[0]->m_framexform;
btCollisionObject** colBptr = m_bodyMap.find(sbjoint->m_bodyB);
if (colBptr && *colBptr)
{
btRigidBody* rbB = btRigidBody::upcast(*colBptr);
if (rbB)
{
bdyB = rbB;
} else
{
bdyB = *colBptr;
}
}
btSoftBody** bodyBptr = m_clusterBodyMap.find(sbjoint->m_bodyB);
if (bodyBptr && *bodyBptr )
{
sbB = *bodyBptr;
bdyB = sbB->m_clusters[0];
}
if (sbjoint->m_jointType==btSoftBody::Joint::eType::Linear)
{
btSoftBody::LJoint::Specs specs;
specs.cfm = sbjoint->m_cfm;
specs.erp = sbjoint->m_erp;
specs.split = sbjoint->m_split;
btVector3 relA;
relA.deSerializeFloat(sbjoint->m_refs[0]);
specs.position = transA*relA;
sb->appendLinearJoint(specs,sb->m_clusters[0],bdyB);
}
if (sbjoint->m_jointType==btSoftBody::Joint::eType::Angular)
{
btSoftBody::AJoint::Specs specs;
specs.cfm = sbjoint->m_cfm;
specs.erp = sbjoint->m_erp;
specs.split = sbjoint->m_split;
btVector3 relA;
relA.deSerializeFloat(sbjoint->m_refs[0]);
specs.axis = transA.getBasis()*relA;
sb->appendAngularJoint(specs,sb->m_clusters[0],bdyB);
}
}
}
}
}
return result;
}
@ -431,8 +517,9 @@ void SerializeDemo::initPhysics()
btBulletWorldImporter* fileLoader = new btBulletWorldImporter(m_dynamicsWorld);
#endif //DESERIALIZE_SOFT_BODIES
// fileLoader->setVerboseMode(true);
if (!fileLoader->loadFile("testFile.bullet"))
// if (!fileLoader->loadFile("../SoftDemo/testFile.bullet"))
{
///create a few basic rigid bodies and save them to testFile.bullet
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));

View File

@ -3068,7 +3068,7 @@ const char* btSoftBody::serialize(void* dataBuffer, class btSerializer* serializ
sbd->m_numNodes = m_nodes.size();
sbd->m_nodes = sbd->m_numNodes ? (SoftBodyNodeData*)serializer->getUniquePointer((void*)&m_nodes[0]): 0;
sbd->m_nodes = sbd->m_numNodes ? (SoftBodyNodeData*)serializer->getUniquePointer((void*)&m_nodes): 0;
if (sbd->m_nodes)
{
int sz = sizeof(SoftBodyNodeData);
@ -3088,7 +3088,7 @@ const char* btSoftBody::serialize(void* dataBuffer, class btSerializer* serializ
m_nodes[i].m_v.serializeFloat(memPtr->m_velocity);
m_nodeIndexMap.insert(&m_nodes[i],i);
}
serializer->finalizeChunk(chunk,"SoftBodyNodeData",BT_SBNODE_CODE,(void*) &m_nodes[0]);
serializer->finalizeChunk(chunk,"SoftBodyNodeData",BT_SBNODE_CODE,(void*) &m_nodes);
}
sbd->m_numLinks = m_links.size();
@ -3263,7 +3263,7 @@ const char* btSoftBody::serialize(void* dataBuffer, class btSerializer* serializ
//clusters for convex-cluster collision detection
sbd->m_numClusters = m_clusters.size();
sbd->m_clusters = sbd->m_numClusters? (SoftBodyClusterData*) serializer->getUniquePointer((void*)&m_clusters[0]) : 0;
sbd->m_clusters = sbd->m_numClusters? (SoftBodyClusterData*) serializer->getUniquePointer((void*)m_clusters[0]) : 0;
if (sbd->m_numClusters)
{
int numElem = sbd->m_numClusters;
@ -3349,7 +3349,7 @@ const char* btSoftBody::serialize(void* dataBuffer, class btSerializer* serializ
serializer->finalizeChunk(chunk,"int",BT_ARRAY_CODE,(void*)&m_clusters[i]->m_nodes);
}
}
serializer->finalizeChunk(chunk,"SoftBodyClusterData",BT_ARRAY_CODE,(void*)&m_clusters[0]);
serializer->finalizeChunk(chunk,"SoftBodyClusterData",BT_ARRAY_CODE,(void*)m_clusters[0]);
}

View File

@ -303,9 +303,9 @@ public:
};
/* Cluster */
struct Cluster
{
btAlignedObjectArray<Node*> m_nodes;
{
tScalarArray m_masses;
btAlignedObjectArray<Node*> m_nodes;
tVector3Array m_framerefs;
btTransform m_framexform;
btScalar m_idmass;