remove Extras/obsolete/quickstep

improve serialization based on feedback: make it easier to serialize a single object, or single shape, or single bvh.
Modified Bullet/Demos/ConcaveDemo to use btSerializer to serialize the btOptimizedBvh (or optionally the trimesh+bvh)

You can also serialize trimesh without BVH, use:
serializer->setSerializationFlags(BT_SERIALIZE_NO_BVH);//	or BT_SERIALIZE_NO_TRIANGLEINFOMAP
This commit is contained in:
erwin.coumans
2010-02-25 20:12:40 +00:00
parent 44503b20a9
commit 40dc18f604
272 changed files with 561 additions and 44611 deletions

View File

@@ -18,13 +18,54 @@ m_verboseDumpAllTypes(false)
btBulletWorldImporter::~btBulletWorldImporter()
{
for (int i=0;i<m_allocatedCollisionShapes.size();i++)
}
void btBulletWorldImporter::deleteAllData()
{
int i;
for (i=0;i<m_allocatedCollisionShapes.size();i++)
{
delete m_allocatedCollisionShapes[i];
}
m_allocatedCollisionShapes.clear();
for (i=0;i<m_allocatedRigidBodies.size();i++)
{
delete m_allocatedRigidBodies[i];
}
m_allocatedRigidBodies.clear();
for (i=0;i<m_allocatedConstraints.size();i++)
{
delete m_allocatedConstraints[i];
}
m_allocatedConstraints.clear();
for (i=0;i<m_allocatedBvhs.size();i++)
{
delete m_allocatedBvhs[i];
}
m_allocatedBvhs.clear();
for (i=0;i<m_allocatedTriangleInfoMaps.size();i++)
{
delete m_allocatedTriangleInfoMaps[i];
}
m_allocatedTriangleInfoMaps.clear();
for (i=0;i<m_allocatedTriangleIndexArrays.size();i++)
{
delete m_allocatedTriangleIndexArrays[i];
}
m_allocatedTriangleIndexArrays.clear();
for (i=0;i<m_allocatedNames.size();i++)
{
delete m_allocatedNames[i];
}
m_allocatedNames.clear();
}
bool btBulletWorldImporter::loadFile( const char* fileName)
{
bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(fileName);
@@ -114,7 +155,7 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
btVector3 planeNormal,localScaling;
planeNormal.deSerializeFloat(planeData->m_planeNormal);
localScaling.deSerializeFloat(planeData->m_localScaling);
shape = new btStaticPlaneShape(planeNormal,btScalar(planeData->m_planeConstant));
shape = createPlaneShape(planeNormal,planeData->m_planeConstant);
shape->setLocalScaling(localScaling);
break;
@@ -305,13 +346,27 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
if (trimesh->m_quantizedFloatBvh)
{
bvh = createOptimizedBvh();
bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh);
btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedFloatBvh);
if (bvhPtr && *bvhPtr)
{
bvh = *bvhPtr;
} else
{
bvh = createOptimizedBvh();
bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh);
}
}
if (trimesh->m_quantizedDoubleBvh)
{
bvh = createOptimizedBvh();
bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh);
btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedDoubleBvh);
if (bvhPtr && *bvhPtr)
{
bvh = *bvhPtr;
} else
{
bvh = createOptimizedBvh();
bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh);
}
}
@@ -369,12 +424,25 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
}
char* btBulletWorldImporter::duplicateName(const char* name)
{
if (name)
{
int l = strlen(name);
char* newName = new char[l+1];
memcpy(newName,name,l);
newName[l] = 0;
m_allocatedNames.push_back(newName);
return newName;
}
return 0;
}
bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFile2)
{
int i;
bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0;
if (ok)
@@ -387,7 +455,24 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
bulletFile2->dumpChunks(bulletFile2->getFileDNA());
}
int i;
for (i=0;i<bulletFile2->m_bvhs.size();i++)
{
btOptimizedBvh* bvh = createOptimizedBvh();
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
{
btQuantizedBvhDoubleData* bvhData = (btQuantizedBvhDoubleData*)bulletFile2->m_bvhs[i];
bvh->deSerializeDouble(*bvhData);
} else
{
btQuantizedBvhFloatData* bvhData = (btQuantizedBvhFloatData*)bulletFile2->m_bvhs[i];
bvh->deSerializeFloat(*bvhData);
}
m_bvhMap.insert(bulletFile2->m_bvhs[i],bvh);
}
btHashMap<btHashPtr,btCollisionShape*> shapeMap;
for (i=0;i<bulletFile2->m_collisionShapes.size();i++)
@@ -396,11 +481,17 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
btCollisionShape* shape = convertCollisionShape(shapeData);
if (shape)
shapeMap.insert(shapeData,shape);
if (shape&& shapeData->m_name)
{
char* newname = duplicateName(shapeData->m_name);
m_objectNameMap.insert(shape,newname);
m_nameShapeMap.insert(newname,shape);
}
}
btHashMap<btHashPtr,btCollisionObject*> bodyMap;
for (i=0;i<bulletFile2->m_rigidBodies.size();i++)
{
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
@@ -559,12 +650,12 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
rbB = &getFixedBody();
}
btTypedConstraint* constraint = 0;
switch (constraintData->m_objectType)
{
case POINT2POINT_CONSTRAINT_TYPE:
{
btPoint2PointConstraint* constraint = 0;
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
{
btPoint2PointConstraintDoubleData* p2pData = (btPoint2PointConstraintDoubleData*)constraintData;
@@ -573,12 +664,12 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
btVector3 pivotInA,pivotInB;
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
pivotInB.deSerializeDouble(p2pData->m_pivotInB);
constraint = new btPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
} else
{
btVector3 pivotInA;
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
constraint = new btPoint2PointConstraint(*rbA,pivotInA);
constraint = createPoint2PointConstraint(*rbA,pivotInA);
}
} else
{
@@ -588,19 +679,17 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
btVector3 pivotInA,pivotInB;
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
pivotInB.deSerializeFloat(p2pData->m_pivotInB);
constraint = new btPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
} else
{
btVector3 pivotInA;
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
constraint = new btPoint2PointConstraint(*rbA,pivotInA);
constraint = createPoint2PointConstraint(*rbA,pivotInA);
}
}
m_dynamicsWorld->addConstraint(constraint,constraintData->m_disableCollisionsBetweenLinkedBodies!=0);
constraint->setDbgDrawSize(constraintData->m_dbgDrawSize);
break;
}
case HINGE_CONSTRAINT_TYPE:
@@ -615,12 +704,12 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
hinge = new btHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
} else
{
btTransform rbAFrame;
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
hinge = new btHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
}
if (hingeData->m_enableAngularMotor)
{
@@ -636,12 +725,12 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
rbBFrame.deSerializeFloat(hingeData->m_rbBFrame);
hinge = new btHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
} else
{
btTransform rbAFrame;
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
hinge = new btHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
}
if (hingeData->m_enableAngularMotor)
{
@@ -650,10 +739,8 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
hinge->setAngularOnly(hingeData->m_angularOnly!=0);
hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
}
m_dynamicsWorld->addConstraint(hinge,constraintData->m_disableCollisionsBetweenLinkedBodies!=0);
hinge->setDbgDrawSize(constraintData->m_dbgDrawSize);
constraint = hinge;
break;
}
@@ -667,19 +754,17 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
coneTwist = new btConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
} else
{
btTransform rbAFrame;
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
coneTwist = new btConeTwistConstraint(*rbA,rbAFrame);
coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
}
coneTwist->setLimit(coneData->m_swingSpan1,coneData->m_swingSpan2,coneData->m_twistSpan,coneData->m_limitSoftness,coneData->m_biasFactor,coneData->m_relaxationFactor);
coneTwist->setDamping(coneData->m_damping);
m_dynamicsWorld->addConstraint(coneTwist,constraintData->m_disableCollisionsBetweenLinkedBodies!=0);
coneTwist->setDbgDrawSize(constraintData->m_dbgDrawSize);
constraint = coneTwist;
break;
}
@@ -693,12 +778,12 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
dof = new btGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
} else
{
btTransform rbBFrame;
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
dof = new btGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
}
btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
@@ -711,8 +796,7 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
dof->setLinearLowerLimit(linLowerLimit);
dof->setLinearUpperLimit(linUpperlimit);
m_dynamicsWorld->addConstraint(dof,constraintData->m_disableCollisionsBetweenLinkedBodies!=0);
dof->setDbgDrawSize(constraintData->m_dbgDrawSize);
constraint = dof;
break;
}
case SLIDER_CONSTRAINT_TYPE:
@@ -724,22 +808,19 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
slider = new btSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
} else
{
btTransform rbBFrame;
rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
slider = new btSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
}
slider->setLowerLinLimit(sliderData->m_linearLowerLimit);
slider->setUpperLinLimit(sliderData->m_linearUpperLimit);
slider->setLowerAngLimit(sliderData->m_angularLowerLimit);
slider->setUpperAngLimit(sliderData->m_angularUpperLimit);
slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
m_dynamicsWorld->addConstraint(slider,constraintData->m_disableCollisionsBetweenLinkedBodies!=0);
slider->setDbgDrawSize(constraintData->m_dbgDrawSize);
constraint = slider;
break;
}
@@ -748,23 +829,26 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
printf("unknown constraint type\n");
}
};
if (constraint)
{
constraint->setDbgDrawSize(constraintData->m_dbgDrawSize);
if (constraintData->m_name)
{
char* newname = duplicateName(constraintData->m_name);
m_nameConstraintMap.insert(newname,constraint);
m_objectNameMap.insert(constraint,newname);
}
if(m_dynamicsWorld)
m_dynamicsWorld->addConstraint(constraint,constraintData->m_disableCollisionsBetweenLinkedBodies!=0);
}
}
return true;
}
btTypedConstraint* btBulletWorldImporter::createUniversalD6Constraint(class btRigidBody* body0,class btRigidBody* otherBody,
btTransform& localAttachmentFrameRef,
btTransform& localAttachmentOther,
const btVector3& linearMinLimits,
const btVector3& linearMaxLimits,
const btVector3& angularMinLimits,
const btVector3& angularMaxLimits,
bool disableCollisionsBetweenLinkedBodies)
{
return 0;
}
btCollisionObject* btBulletWorldImporter::createCollisionObject(const btTransform& startTransform,btCollisionShape* shape, const char* bodyName)
{
@@ -784,69 +868,102 @@ btRigidBody* btBulletWorldImporter::createRigidBody(bool isDynamic, btScalar ma
btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
body->setWorldTransform(startTransform);
m_dynamicsWorld->addRigidBody(body);
if (m_dynamicsWorld)
m_dynamicsWorld->addRigidBody(body);
if (bodyName)
{
char* newname = duplicateName(bodyName);
m_objectNameMap.insert(body,newname);
m_nameBodyMap.insert(newname,body);
}
m_allocatedRigidBodies.push_back(body);
return body;
}
btCollisionShape* btBulletWorldImporter::createPlaneShape(const btVector3& planeNormal,btScalar planeConstant)
{
return 0;
btStaticPlaneShape* shape = new btStaticPlaneShape(planeNormal,planeConstant);
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btCollisionShape* btBulletWorldImporter::createBoxShape(const btVector3& halfExtents)
{
return new btBoxShape(halfExtents);
btBoxShape* shape = new btBoxShape(halfExtents);
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btCollisionShape* btBulletWorldImporter::createSphereShape(btScalar radius)
{
return new btSphereShape(radius);
btSphereShape* shape = new btSphereShape(radius);
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btCollisionShape* btBulletWorldImporter::createCapsuleShapeX(btScalar radius, btScalar height)
{
return new btCapsuleShapeX(radius,height);
btCapsuleShapeX* shape = new btCapsuleShapeX(radius,height);
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btCollisionShape* btBulletWorldImporter::createCapsuleShapeY(btScalar radius, btScalar height)
{
return new btCapsuleShape(radius,height);
btCapsuleShape* shape = new btCapsuleShape(radius,height);
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btCollisionShape* btBulletWorldImporter::createCapsuleShapeZ(btScalar radius, btScalar height)
{
return new btCapsuleShapeZ(radius,height);
btCapsuleShapeZ* shape = new btCapsuleShapeZ(radius,height);
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btCollisionShape* btBulletWorldImporter::createCylinderShapeX(btScalar radius,btScalar height)
{
return new btCylinderShapeX(btVector3(height,radius,radius));
btCylinderShapeX* shape = new btCylinderShapeX(btVector3(height,radius,radius));
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btCollisionShape* btBulletWorldImporter::createCylinderShapeY(btScalar radius,btScalar height)
{
return new btCylinderShape(btVector3(radius,height,radius));
btCylinderShape* shape = new btCylinderShape(btVector3(radius,height,radius));
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btCollisionShape* btBulletWorldImporter::createCylinderShapeZ(btScalar radius,btScalar height)
{
return new btCylinderShapeZ(btVector3(radius,radius,height));
btCylinderShapeZ* shape = new btCylinderShapeZ(btVector3(radius,radius,height));
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btTriangleIndexVertexArray* btBulletWorldImporter::createTriangleMeshContainer()
{
return new btTriangleIndexVertexArray();
btTriangleIndexVertexArray* in = new btTriangleIndexVertexArray();
m_allocatedTriangleIndexArrays.push_back(in);
return in;
}
btOptimizedBvh* btBulletWorldImporter::createOptimizedBvh()
{
return new btOptimizedBvh();
btOptimizedBvh* bvh = new btOptimizedBvh();
m_allocatedBvhs.push_back(bvh);
return bvh;
}
btTriangleInfoMap* btBulletWorldImporter::createTriangleInfoMap()
{
return new btTriangleInfoMap();
btTriangleInfoMap* tim = new btTriangleInfoMap();
m_allocatedTriangleInfoMaps.push_back(tim);
return tim;
}
btBvhTriangleMeshShape* btBulletWorldImporter::createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh)
@@ -855,9 +972,14 @@ btBvhTriangleMeshShape* btBulletWorldImporter::createBvhTriangleMeshShape(btStri
{
btBvhTriangleMeshShape* bvhTriMesh = new btBvhTriangleMeshShape(trimesh,bvh->isQuantized(), false);
bvhTriMesh->setOptimizedBvh(bvh);
m_allocatedCollisionShapes.push_back(bvhTriMesh);
return bvhTriMesh;
}
return new btBvhTriangleMeshShape(trimesh,true);
btBvhTriangleMeshShape* ts = new btBvhTriangleMeshShape(trimesh,true);
m_allocatedCollisionShapes.push_back(ts);
return ts;
}
btCollisionShape* btBulletWorldImporter::createConvexTriangleMeshShape(btStridingMeshInterface* trimesh)
{
@@ -865,16 +987,23 @@ btCollisionShape* btBulletWorldImporter::createConvexTriangleMeshShape(btStridin
}
btGImpactMeshShape* btBulletWorldImporter::createGimpactShape(btStridingMeshInterface* trimesh)
{
return new btGImpactMeshShape(trimesh);
btGImpactMeshShape* shape = new btGImpactMeshShape(trimesh);
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btConvexHullShape* btBulletWorldImporter::createConvexHullShape()
{
return new btConvexHullShape();
btConvexHullShape* shape = new btConvexHullShape();
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btCompoundShape* btBulletWorldImporter::createCompoundShape()
{
return new btCompoundShape();
btCompoundShape* shape = new btCompoundShape();
m_allocatedCollisionShapes.push_back(shape);
return shape;
}
btRigidBody& btBulletWorldImporter::getFixedBody()
@@ -884,3 +1013,163 @@ btRigidBody& btBulletWorldImporter::getFixedBody()
return s_fixed;
}
btPoint2PointConstraint* btBulletWorldImporter::createPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB)
{
btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,rbB,pivotInA,pivotInB);
m_allocatedConstraints.push_back(p2p);
return p2p;
}
btPoint2PointConstraint* btBulletWorldImporter::createPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA)
{
btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,pivotInA);
m_allocatedConstraints.push_back(p2p);
return p2p;
}
btHingeConstraint* btBulletWorldImporter::createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA)
{
btHingeConstraint* hinge = new btHingeConstraint(rbA,rbB,rbAFrame,rbBFrame,useReferenceFrameA);
m_allocatedConstraints.push_back(hinge);
return hinge;
}
btHingeConstraint* btBulletWorldImporter::createHingeConstraint(btRigidBody& rbA,const btTransform& rbAFrame, bool useReferenceFrameA)
{
btHingeConstraint* hinge = new btHingeConstraint(rbA,rbAFrame,useReferenceFrameA);
m_allocatedConstraints.push_back(hinge);
return hinge;
}
btConeTwistConstraint* btBulletWorldImporter::createConeTwistConstraint(btRigidBody& rbA,btRigidBody& rbB,const btTransform& rbAFrame, const btTransform& rbBFrame)
{
btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbB,rbAFrame,rbBFrame);
m_allocatedConstraints.push_back(cone);
return cone;
}
btConeTwistConstraint* btBulletWorldImporter::createConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame)
{
btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbAFrame);
m_allocatedConstraints.push_back(cone);
return cone;
}
btGeneric6DofConstraint* btBulletWorldImporter::createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA)
{
btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
m_allocatedConstraints.push_back(dof);
return dof;
}
btGeneric6DofConstraint* btBulletWorldImporter::createGeneric6DofConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB)
{
btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbB,frameInB,useLinearReferenceFrameB);
m_allocatedConstraints.push_back(dof);
return dof;
}
btSliderConstraint* btBulletWorldImporter::createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA)
{
btSliderConstraint* slider = new btSliderConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
m_allocatedConstraints.push_back(slider);
return slider;
}
btSliderConstraint* btBulletWorldImporter::createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA)
{
btSliderConstraint* slider = new btSliderConstraint(rbB,frameInB,useLinearReferenceFrameA);
m_allocatedConstraints.push_back(slider);
return slider;
}
// query for data
int btBulletWorldImporter::getNumCollisionShapes() const
{
return m_allocatedCollisionShapes.size();
}
btCollisionShape* btBulletWorldImporter::getCollisionShapeByIndex(int index)
{
return m_allocatedCollisionShapes[index];
}
btCollisionShape* btBulletWorldImporter::getCollisionShapeByName(const char* name)
{
btCollisionShape** shapePtr = m_nameShapeMap.find(name);
if (shapePtr&& *shapePtr)
{
return *shapePtr;
}
return 0;
}
btRigidBody* btBulletWorldImporter::getRigidBodyByName(const char* name)
{
btRigidBody** bodyPtr = m_nameBodyMap.find(name);
if (bodyPtr && *bodyPtr)
{
*bodyPtr;
}
return 0;
}
btTypedConstraint* btBulletWorldImporter::getConstraintByName(const char* name)
{
btTypedConstraint** constraintPtr = m_nameConstraintMap.find(name);
if (constraintPtr && *constraintPtr)
{
return *constraintPtr;
}
return 0;
}
const char* btBulletWorldImporter::getNameForPointer(const void* ptr) const
{
const char*const * namePtr = m_objectNameMap.find(ptr);
if (namePtr && *namePtr)
return *namePtr;
return 0;
}
int btBulletWorldImporter::getNumRigidBodies() const
{
return m_allocatedRigidBodies.size();
}
btCollisionObject* btBulletWorldImporter::getRigidBodyByIndex(int index) const
{
return m_allocatedRigidBodies[index];
}
int btBulletWorldImporter::getNumConstraints() const
{
return m_allocatedConstraints.size();
}
btTypedConstraint* btBulletWorldImporter::getConstraintByIndex(int index) const
{
return m_allocatedConstraints[index];
}
int btBulletWorldImporter::getNumBvhs() const
{
return m_allocatedBvhs.size();
}
btOptimizedBvh* btBulletWorldImporter::getBvhByIndex(int index) const
{
return m_allocatedBvhs[index];
}
int btBulletWorldImporter::getNumTriangleInfoMaps() const
{
return m_allocatedTriangleInfoMaps.size();
}
btTriangleInfoMap* btBulletWorldImporter::getTriangleInfoMapByIndex(int index) const
{
return m_allocatedTriangleInfoMaps[index];
}

View File

@@ -39,6 +39,12 @@ class btGImpactMeshShape;
class btOptimizedBvh;
struct btTriangleInfoMap;
class btBvhTriangleMeshShape;
class btPoint2PointConstraint;
class btHingeConstraint;
class btConeTwistConstraint;
class btGeneric6DofConstraint;
class btSliderConstraint;
namespace bParse
@@ -58,18 +64,40 @@ protected:
btCollisionShape* convertCollisionShape( btCollisionShapeData* shapeData );
btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
btAlignedObjectArray<btCollisionObject*> m_allocatedRigidBodies;
btAlignedObjectArray<btTypedConstraint*> m_allocatedConstraints;
btAlignedObjectArray<btOptimizedBvh*> m_allocatedBvhs;
btAlignedObjectArray<btTriangleInfoMap*> m_allocatedTriangleInfoMaps;
btAlignedObjectArray<btTriangleIndexVertexArray*> m_allocatedTriangleIndexArrays;
btAlignedObjectArray<char*> m_allocatedNames;
btHashMap<btHashPtr,btOptimizedBvh*> m_bvhMap;
btHashMap<btHashPtr,btTriangleInfoMap*> m_timMap;
btHashMap<btHashString,btCollisionShape*> m_nameShapeMap;
btHashMap<btHashString,btRigidBody*> m_nameBodyMap;
btHashMap<btHashString,btTypedConstraint*> m_nameConstraintMap;
btHashMap<btHashPtr,const char*> m_objectNameMap;
//methods
btTriangleIndexVertexArray* createMeshInterface(btStridingMeshInterfaceData& meshData);
static btRigidBody& getFixedBody();
char* duplicateName(const char* name);
public:
btBulletWorldImporter(btDynamicsWorld* world);
btBulletWorldImporter(btDynamicsWorld* world=0);
virtual ~btBulletWorldImporter();
///delete all memory collision shapes, rigid bodies, constraints etc. allocated during the load.
///make sure you don't use the dynamics world containing objects after you call this method
void deleteAllData();
bool loadFile(const char* fileName);
///the memoryBuffer might be modified (for example if endian swaps are necessary)
@@ -86,26 +114,32 @@ public:
{
return m_verboseDumpAllTypes;
}
///those virtuals are called by load
virtual btTypedConstraint* createUniversalD6Constraint(
class btRigidBody* body0,class btRigidBody* otherBody,
btTransform& localAttachmentFrameRef,
btTransform& localAttachmentOther,
const btVector3& linearMinLimits,
const btVector3& linearMaxLimits,
const btVector3& angularMinLimits,
const btVector3& angularMaxLimits,
bool disableCollisionsBetweenLinkedBodies
);
virtual btRigidBody* createRigidBody(bool isDynamic,
btScalar mass,
const btTransform& startTransform,
btCollisionShape* shape,const char* bodyName);
// query for data
int getNumCollisionShapes() const;
btCollisionShape* getCollisionShapeByIndex(int index);
int getNumRigidBodies() const;
btCollisionObject* getRigidBodyByIndex(int index) const;
int getNumConstraints() const;
btTypedConstraint* getConstraintByIndex(int index) const;
int getNumBvhs() const;
btOptimizedBvh* getBvhByIndex(int index) const;
int getNumTriangleInfoMaps() const;
btTriangleInfoMap* getTriangleInfoMapByIndex(int index) const;
// queris involving named objects
btCollisionShape* getCollisionShapeByName(const char* name);
btRigidBody* getRigidBodyByName(const char* name);
btTypedConstraint* getConstraintByName(const char* name);
const char* getNameForPointer(const void* ptr) const;
///those virtuals are called by load and can be overridden by the user
//bodies
virtual btRigidBody* createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform, btCollisionShape* shape,const char* bodyName);
virtual btCollisionObject* createCollisionObject( const btTransform& startTransform, btCollisionShape* shape,const char* bodyName);
///shapes
virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal,btScalar planeConstant);
virtual btCollisionShape* createBoxShape(const btVector3& halfExtents);
@@ -119,13 +153,27 @@ public:
virtual btCollisionShape* createCylinderShapeZ(btScalar radius,btScalar height);
virtual class btTriangleIndexVertexArray* createTriangleMeshContainer();
virtual btBvhTriangleMeshShape* createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh);
virtual btOptimizedBvh* createOptimizedBvh();
virtual btTriangleInfoMap* createTriangleInfoMap();
virtual btCollisionShape* createConvexTriangleMeshShape(btStridingMeshInterface* trimesh);
virtual btGImpactMeshShape* createGimpactShape(btStridingMeshInterface* trimesh);
virtual class btConvexHullShape* createConvexHullShape();
virtual class btCompoundShape* createCompoundShape();
///acceleration and connectivity structures
virtual btOptimizedBvh* createOptimizedBvh();
virtual btTriangleInfoMap* createTriangleInfoMap();
///constraints
virtual btPoint2PointConstraint* createPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB);
virtual btPoint2PointConstraint* createPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA);
virtual btHingeConstraint* createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA=false);
virtual btHingeConstraint* createHingeConstraint(btRigidBody& rbA,const btTransform& rbAFrame, bool useReferenceFrameA=false);
virtual btConeTwistConstraint* createConeTwistConstraint(btRigidBody& rbA,btRigidBody& rbB,const btTransform& rbAFrame, const btTransform& rbBFrame);
virtual btConeTwistConstraint* createConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame);
virtual btGeneric6DofConstraint* createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA);
virtual btGeneric6DofConstraint* createGeneric6DofConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB);
virtual btSliderConstraint* createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA);
virtual btSliderConstraint* createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA);
};
#endif //BULLET_WORLD_IMPORTER_H

View File

@@ -1,8 +1,9 @@
IF (BUILD_BLEND_DEMO)
IF (BUILD_BLEND_DEMO OR INTERNAL_UPDATE_SERIALIZATION_STRUCTURES)
SUBDIRS(BlenderSerialize )
ENDIF()
IF(INTERNAL_UPDATE_SERIALIZATION_STRUCTURES)
# makesdna and HeaderGenerator are for advanced use only