btBulletWorldImporter support for loading of btCollisionObject from a .bullet file.
minor compilation fix on PS3 Yippie, revision 2000!
This commit is contained in:
@@ -12,11 +12,17 @@ subject to the following restrictions:
|
|||||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
#include <memory.h>
|
|
||||||
#include "bChunk.h"
|
#include "bChunk.h"
|
||||||
#include "bDefines.h"
|
#include "bDefines.h"
|
||||||
#include "bFile.h"
|
#include "bFile.h"
|
||||||
|
|
||||||
|
#if !defined( __CELLOS_LV2__) && !defined(__MWERKS__)
|
||||||
|
#include <memory.h>
|
||||||
|
#endif
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace bParse;
|
using namespace bParse;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -353,7 +353,8 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
|
|||||||
shapeMap.insert(shapeData,shape);
|
shapeMap.insert(shapeData,shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
btHashMap<btHashPtr,btRigidBody*> bodyMap;
|
btHashMap<btHashPtr,btCollisionObject*> bodyMap;
|
||||||
|
|
||||||
|
|
||||||
for (i=0;i<bulletFile2->m_rigidBodies.size();i++)
|
for (i=0;i<bulletFile2->m_rigidBodies.size();i++)
|
||||||
{
|
{
|
||||||
@@ -409,18 +410,66 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (i=0;i<bulletFile2->m_collisionObjects.size();i++)
|
for (i=0;i<bulletFile2->m_collisionObjects.size();i++)
|
||||||
// {
|
{
|
||||||
// btCollisionObjectData* colObjData = (btCollisionObjectData*)bulletFile2->m_collisionObjects[i];
|
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
|
||||||
// printf("bla");
|
{
|
||||||
// }
|
btCollisionObjectDoubleData* colObjData = (btCollisionObjectDoubleData*)bulletFile2->m_collisionObjects[i];
|
||||||
|
btCollisionShape** shapePtr = shapeMap.find(colObjData->m_collisionShape);
|
||||||
|
if (shapePtr && *shapePtr)
|
||||||
|
{
|
||||||
|
btTransform startTransform;
|
||||||
|
startTransform.deSerializeDouble(colObjData->m_worldTransform);
|
||||||
|
btCollisionShape* shape = (btCollisionShape*)*shapePtr;
|
||||||
|
btCollisionObject* body = createCollisionObject(startTransform,shape);
|
||||||
|
bodyMap.insert(colObjData,body);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
printf("error: no shape found\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
btCollisionObjectFloatData* colObjData = (btCollisionObjectFloatData*)bulletFile2->m_collisionObjects[i];
|
||||||
|
btCollisionShape** shapePtr = shapeMap.find(colObjData->m_collisionShape);
|
||||||
|
if (shapePtr && *shapePtr)
|
||||||
|
{
|
||||||
|
btTransform startTransform;
|
||||||
|
startTransform.deSerializeFloat(colObjData->m_worldTransform);
|
||||||
|
btCollisionShape* shape = (btCollisionShape*)*shapePtr;
|
||||||
|
btCollisionObject* body = createCollisionObject(startTransform,shape);
|
||||||
|
bodyMap.insert(colObjData,body);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
printf("error: no shape found\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("bla");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for (i=0;i<bulletFile2->m_constraints.size();i++)
|
for (i=0;i<bulletFile2->m_constraints.size();i++)
|
||||||
{
|
{
|
||||||
btTypedConstraintData* constraintData = (btTypedConstraintData*)bulletFile2->m_constraints[i];
|
btTypedConstraintData* constraintData = (btTypedConstraintData*)bulletFile2->m_constraints[i];
|
||||||
btRigidBody** rbAptr = bodyMap.find(constraintData->m_rbA);
|
btCollisionObject** colAptr = bodyMap.find(constraintData->m_rbA);
|
||||||
btRigidBody** rbBptr = bodyMap.find(constraintData->m_rbB);
|
btCollisionObject** colBptr = bodyMap.find(constraintData->m_rbB);
|
||||||
|
|
||||||
|
btRigidBody* rbA = 0;
|
||||||
|
btRigidBody* rbB = 0;
|
||||||
|
|
||||||
|
if (colAptr)
|
||||||
|
{
|
||||||
|
rbA = btRigidBody::upcast(*colAptr);
|
||||||
|
if (!rbA)
|
||||||
|
rbA = &getFixedBody();
|
||||||
|
}
|
||||||
|
if (colBptr)
|
||||||
|
{
|
||||||
|
rbB = btRigidBody::upcast(*colBptr);
|
||||||
|
if (!rbB)
|
||||||
|
rbB = &getFixedBody();
|
||||||
|
}
|
||||||
|
|
||||||
switch (constraintData->m_objectType)
|
switch (constraintData->m_objectType)
|
||||||
{
|
{
|
||||||
@@ -431,33 +480,33 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
|
|||||||
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
|
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
|
||||||
{
|
{
|
||||||
btPoint2PointConstraintDoubleData* p2pData = (btPoint2PointConstraintDoubleData*)constraintData;
|
btPoint2PointConstraintDoubleData* p2pData = (btPoint2PointConstraintDoubleData*)constraintData;
|
||||||
if (rbAptr && rbBptr)
|
if (rbA && rbB)
|
||||||
{
|
{
|
||||||
btVector3 pivotInA,pivotInB;
|
btVector3 pivotInA,pivotInB;
|
||||||
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
|
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
|
||||||
pivotInB.deSerializeDouble(p2pData->m_pivotInB);
|
pivotInB.deSerializeDouble(p2pData->m_pivotInB);
|
||||||
constraint = new btPoint2PointConstraint(**rbAptr,**rbBptr,pivotInA,pivotInB);
|
constraint = new btPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
btVector3 pivotInA;
|
btVector3 pivotInA;
|
||||||
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
|
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
|
||||||
constraint = new btPoint2PointConstraint(**rbAptr,pivotInA);
|
constraint = new btPoint2PointConstraint(*rbA,pivotInA);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
btPoint2PointConstraintFloatData* p2pData = (btPoint2PointConstraintFloatData*)constraintData;
|
btPoint2PointConstraintFloatData* p2pData = (btPoint2PointConstraintFloatData*)constraintData;
|
||||||
if (rbAptr && rbBptr)
|
if (rbA&& rbB)
|
||||||
{
|
{
|
||||||
btVector3 pivotInA,pivotInB;
|
btVector3 pivotInA,pivotInB;
|
||||||
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
|
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
|
||||||
pivotInB.deSerializeFloat(p2pData->m_pivotInB);
|
pivotInB.deSerializeFloat(p2pData->m_pivotInB);
|
||||||
constraint = new btPoint2PointConstraint(**rbAptr,**rbBptr,pivotInA,pivotInB);
|
constraint = new btPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
btVector3 pivotInA;
|
btVector3 pivotInA;
|
||||||
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
|
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
|
||||||
constraint = new btPoint2PointConstraint(**rbAptr,pivotInA);
|
constraint = new btPoint2PointConstraint(*rbA,pivotInA);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -473,17 +522,17 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
|
|||||||
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
|
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
|
||||||
{
|
{
|
||||||
btHingeConstraintDoubleData* hingeData = (btHingeConstraintDoubleData*)constraintData;
|
btHingeConstraintDoubleData* hingeData = (btHingeConstraintDoubleData*)constraintData;
|
||||||
if (rbAptr && rbBptr)
|
if (rbA&& rbB)
|
||||||
{
|
{
|
||||||
btTransform rbAFrame,rbBFrame;
|
btTransform rbAFrame,rbBFrame;
|
||||||
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
|
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
|
||||||
rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
|
rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
|
||||||
hinge = new btHingeConstraint(**rbAptr,**rbBptr,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
|
hinge = new btHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
btTransform rbAFrame;
|
btTransform rbAFrame;
|
||||||
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
|
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
|
||||||
hinge = new btHingeConstraint(**rbAptr,rbAFrame,hingeData->m_useReferenceFrameA!=0);
|
hinge = new btHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
|
||||||
}
|
}
|
||||||
if (hingeData->m_enableAngularMotor)
|
if (hingeData->m_enableAngularMotor)
|
||||||
{
|
{
|
||||||
@@ -494,17 +543,17 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
|
|||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
btHingeConstraintFloatData* hingeData = (btHingeConstraintFloatData*)constraintData;
|
btHingeConstraintFloatData* hingeData = (btHingeConstraintFloatData*)constraintData;
|
||||||
if (rbAptr && rbBptr)
|
if (rbA&& rbB)
|
||||||
{
|
{
|
||||||
btTransform rbAFrame,rbBFrame;
|
btTransform rbAFrame,rbBFrame;
|
||||||
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
|
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
|
||||||
rbBFrame.deSerializeFloat(hingeData->m_rbBFrame);
|
rbBFrame.deSerializeFloat(hingeData->m_rbBFrame);
|
||||||
hinge = new btHingeConstraint(**rbAptr,**rbBptr,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
|
hinge = new btHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
btTransform rbAFrame;
|
btTransform rbAFrame;
|
||||||
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
|
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
|
||||||
hinge = new btHingeConstraint(**rbAptr,rbAFrame,hingeData->m_useReferenceFrameA!=0);
|
hinge = new btHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
|
||||||
}
|
}
|
||||||
if (hingeData->m_enableAngularMotor)
|
if (hingeData->m_enableAngularMotor)
|
||||||
{
|
{
|
||||||
@@ -525,17 +574,17 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
|
|||||||
btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData;
|
btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData;
|
||||||
btConeTwistConstraint* coneTwist = 0;
|
btConeTwistConstraint* coneTwist = 0;
|
||||||
|
|
||||||
if (rbAptr && rbBptr)
|
if (rbA&& rbB)
|
||||||
{
|
{
|
||||||
btTransform rbAFrame,rbBFrame;
|
btTransform rbAFrame,rbBFrame;
|
||||||
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
|
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
|
||||||
rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
|
rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
|
||||||
coneTwist = new btConeTwistConstraint(**rbAptr,**rbBptr,rbAFrame,rbBFrame);
|
coneTwist = new btConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
btTransform rbAFrame;
|
btTransform rbAFrame;
|
||||||
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
|
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
|
||||||
coneTwist = new btConeTwistConstraint(**rbAptr,rbAFrame);
|
coneTwist = new btConeTwistConstraint(*rbA,rbAFrame);
|
||||||
}
|
}
|
||||||
coneTwist->setLimit(coneData->m_swingSpan1,coneData->m_swingSpan2,coneData->m_twistSpan,coneData->m_limitSoftness,coneData->m_biasFactor,coneData->m_relaxationFactor);
|
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);
|
coneTwist->setDamping(coneData->m_damping);
|
||||||
@@ -551,17 +600,17 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
|
|||||||
btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData;
|
btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData;
|
||||||
btGeneric6DofConstraint* dof = 0;
|
btGeneric6DofConstraint* dof = 0;
|
||||||
|
|
||||||
if (rbAptr && rbBptr)
|
if (rbA&& rbB)
|
||||||
{
|
{
|
||||||
btTransform rbAFrame,rbBFrame;
|
btTransform rbAFrame,rbBFrame;
|
||||||
rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
|
rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
|
||||||
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
|
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
|
||||||
dof = new btGeneric6DofConstraint(**rbAptr,**rbBptr,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
|
dof = new btGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
btTransform rbBFrame;
|
btTransform rbBFrame;
|
||||||
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
|
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
|
||||||
dof = new btGeneric6DofConstraint(**rbBptr,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
|
dof = new btGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
|
||||||
}
|
}
|
||||||
btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
|
btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
|
||||||
angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
|
angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
|
||||||
@@ -582,17 +631,17 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
|
|||||||
{
|
{
|
||||||
btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData;
|
btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData;
|
||||||
btSliderConstraint* slider = 0;
|
btSliderConstraint* slider = 0;
|
||||||
if (rbAptr && rbBptr)
|
if (rbA&& rbB)
|
||||||
{
|
{
|
||||||
btTransform rbAFrame,rbBFrame;
|
btTransform rbAFrame,rbBFrame;
|
||||||
rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
|
rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
|
||||||
rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
|
rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
|
||||||
slider = new btSliderConstraint(**rbAptr,**rbBptr,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
|
slider = new btSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
btTransform rbBFrame;
|
btTransform rbBFrame;
|
||||||
rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
|
rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
|
||||||
slider = new btSliderConstraint(**rbBptr,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
|
slider = new btSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
|
||||||
}
|
}
|
||||||
slider->setLowerLinLimit(sliderData->m_linearLowerLimit);
|
slider->setLowerLinLimit(sliderData->m_linearLowerLimit);
|
||||||
slider->setUpperLinLimit(sliderData->m_linearUpperLimit);
|
slider->setUpperLinLimit(sliderData->m_linearUpperLimit);
|
||||||
@@ -629,6 +678,13 @@ btTypedConstraint* btBulletWorldImporter::createUniversalD6Constraint(class bt
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btCollisionObject* btBulletWorldImporter::createCollisionObject(const btTransform& startTransform,btCollisionShape* shape)
|
||||||
|
{
|
||||||
|
return createRigidBody(false,0,startTransform,shape);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
btRigidBody* btBulletWorldImporter::createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform,btCollisionShape* shape)
|
btRigidBody* btBulletWorldImporter::createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform,btCollisionShape* shape)
|
||||||
{
|
{
|
||||||
btVector3 localInertia;
|
btVector3 localInertia;
|
||||||
@@ -715,3 +771,10 @@ btCompoundShape* btBulletWorldImporter::createCompoundShape()
|
|||||||
return new btCompoundShape();
|
return new btCompoundShape();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btRigidBody& btBulletWorldImporter::getFixedBody()
|
||||||
|
{
|
||||||
|
static btRigidBody s_fixed(0, 0,0);
|
||||||
|
s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));
|
||||||
|
return s_fixed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
class btBulletFile;
|
class btBulletFile;
|
||||||
class btCollisionShape;
|
class btCollisionShape;
|
||||||
|
class btCollisionObject;
|
||||||
class btRigidBody;
|
class btRigidBody;
|
||||||
class btTypedConstraint;
|
class btTypedConstraint;
|
||||||
class btDynamicsWorld;
|
class btDynamicsWorld;
|
||||||
@@ -56,6 +57,8 @@ protected:
|
|||||||
|
|
||||||
btTriangleIndexVertexArray* createMeshInterface(btStridingMeshInterfaceData& meshData);
|
btTriangleIndexVertexArray* createMeshInterface(btStridingMeshInterfaceData& meshData);
|
||||||
|
|
||||||
|
static btRigidBody& getFixedBody();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
btBulletWorldImporter(btDynamicsWorld* world);
|
btBulletWorldImporter(btDynamicsWorld* world);
|
||||||
@@ -96,6 +99,9 @@ public:
|
|||||||
const btTransform& startTransform,
|
const btTransform& startTransform,
|
||||||
btCollisionShape* shape);
|
btCollisionShape* shape);
|
||||||
|
|
||||||
|
virtual btCollisionObject* createCollisionObject( const btTransform& startTransform, btCollisionShape* shape);
|
||||||
|
|
||||||
|
|
||||||
virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal,btScalar planeConstant);
|
virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal,btScalar planeConstant);
|
||||||
virtual btCollisionShape* createBoxShape(const btVector3& halfExtents);
|
virtual btCollisionShape* createBoxShape(const btVector3& halfExtents);
|
||||||
virtual btCollisionShape* createSphereShape(btScalar radius);
|
virtual btCollisionShape* createSphereShape(btScalar radius);
|
||||||
|
|||||||
Reference in New Issue
Block a user