(de)serialization of softbody joints working now. Resolving Issue 456.
This commit is contained in:
@@ -146,6 +146,9 @@ class MySoftBulletWorldImporter : public btBulletWorldImporter
|
|||||||
|
|
||||||
btHashMap<btHashPtr,btSoftBody::Material*> m_materialMap;
|
btHashMap<btHashPtr,btSoftBody::Material*> m_materialMap;
|
||||||
|
|
||||||
|
btHashMap<btHashPtr,btSoftBody*> m_clusterBodyMap;
|
||||||
|
btHashMap<btHashPtr,btSoftBody*> m_softBodyMap;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -181,6 +184,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
btSoftBody* psb=new btSoftBody(&m_softRigidWorld->getWorldInfo());
|
btSoftBody* psb=new btSoftBody(&m_softRigidWorld->getWorldInfo());
|
||||||
|
m_softBodyMap.insert(softBodyData,psb);
|
||||||
|
|
||||||
//materials
|
//materials
|
||||||
for (i=0;i<softBodyData->m_numMaterials;i++)
|
for (i=0;i<softBodyData->m_numMaterials;i++)
|
||||||
@@ -336,6 +340,7 @@ public:
|
|||||||
//clusters
|
//clusters
|
||||||
if (softBodyData->m_numClusters)
|
if (softBodyData->m_numClusters)
|
||||||
{
|
{
|
||||||
|
m_clusterBodyMap.insert(softBodyData->m_clusters,psb);
|
||||||
int j;
|
int j;
|
||||||
psb->m_clusters.resize(softBodyData->m_numClusters);
|
psb->m_clusters.resize(softBodyData->m_numClusters);
|
||||||
for (i=0;i<softBodyData->m_numClusters;i++)
|
for (i=0;i<softBodyData->m_numClusters;i++)
|
||||||
@@ -400,6 +405,8 @@ public:
|
|||||||
|
|
||||||
#endif //
|
#endif //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
psb->updateConstants();
|
psb->updateConstants();
|
||||||
m_softRigidWorld->getWorldInfo().m_dispatcher = m_softRigidWorld->getDispatcher();
|
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;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -433,6 +519,7 @@ void SerializeDemo::initPhysics()
|
|||||||
// fileLoader->setVerboseMode(true);
|
// fileLoader->setVerboseMode(true);
|
||||||
|
|
||||||
if (!fileLoader->loadFile("testFile.bullet"))
|
if (!fileLoader->loadFile("testFile.bullet"))
|
||||||
|
// if (!fileLoader->loadFile("../SoftDemo/testFile.bullet"))
|
||||||
{
|
{
|
||||||
///create a few basic rigid bodies and save them to 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.)));
|
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
|
||||||
|
|||||||
@@ -3068,7 +3068,7 @@ const char* btSoftBody::serialize(void* dataBuffer, class btSerializer* serializ
|
|||||||
|
|
||||||
|
|
||||||
sbd->m_numNodes = m_nodes.size();
|
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)
|
if (sbd->m_nodes)
|
||||||
{
|
{
|
||||||
int sz = sizeof(SoftBodyNodeData);
|
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_nodes[i].m_v.serializeFloat(memPtr->m_velocity);
|
||||||
m_nodeIndexMap.insert(&m_nodes[i],i);
|
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();
|
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
|
//clusters for convex-cluster collision detection
|
||||||
|
|
||||||
sbd->m_numClusters = m_clusters.size();
|
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)
|
if (sbd->m_numClusters)
|
||||||
{
|
{
|
||||||
int numElem = 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,"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]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -304,8 +304,8 @@ public:
|
|||||||
/* Cluster */
|
/* Cluster */
|
||||||
struct Cluster
|
struct Cluster
|
||||||
{
|
{
|
||||||
btAlignedObjectArray<Node*> m_nodes;
|
|
||||||
tScalarArray m_masses;
|
tScalarArray m_masses;
|
||||||
|
btAlignedObjectArray<Node*> m_nodes;
|
||||||
tVector3Array m_framerefs;
|
tVector3Array m_framerefs;
|
||||||
btTransform m_framexform;
|
btTransform m_framexform;
|
||||||
btScalar m_idmass;
|
btScalar m_idmass;
|
||||||
|
|||||||
Reference in New Issue
Block a user