refactor constraint serialization, so that double precision is maintained,

changes are backwards compatible (btBulletWorldImporter can load old .bullet files)
but not forwards compatible (constraints in new .bullet files are ignored/unrecognized by old Bullet SDK)
This commit is for Issue 734. Some more work needs to be done for btGImpactMeshShapeDoubleData and thus btStridingMeshInterfaceDoubleData and btMeshPartDoubleData
This commit is contained in:
erwin.coumans 2013-09-14 06:08:50 +00:00
parent e94a2137b0
commit 1aac33f6b6
16 changed files with 1523 additions and 665 deletions

View File

@ -266,6 +266,49 @@ void ConstraintDemo::initPhysics()
}
#endif
#if ENABLE_ALL_DEMOS
{
btTransform trans;
trans.setIdentity();
btVector3 worldPos(-20,0,30);
trans.setOrigin(worldPos);
btTransform frameInA, frameInB;
frameInA = btTransform::getIdentity();
frameInB = btTransform::getIdentity();
btRigidBody* pRbA1 = localCreateRigidBody(mass, trans, shape);
// btRigidBody* pRbA1 = localCreateRigidBody(0.f, trans, shape);
pRbA1->setActivationState(DISABLE_DEACTIVATION);
// add dynamic rigid body B1
worldPos.setValue(-30,0,30);
trans.setOrigin(worldPos);
btRigidBody* pRbB1 = localCreateRigidBody(mass, trans, shape);
// btRigidBody* pRbB1 = localCreateRigidBody(0.f, trans, shape);
pRbB1->setActivationState(DISABLE_DEACTIVATION);
// create slider constraint between A1 and B1 and add it to world
btSliderConstraint* spSlider1 = new btSliderConstraint(*pRbA1, *pRbB1, frameInA, frameInB, true);
// spSlider1 = new btSliderConstraint(*pRbA1, *pRbB1, frameInA, frameInB, false);
spSlider1->setLowerLinLimit(-15.0F);
spSlider1->setUpperLinLimit(-5.0F);
// spSlider1->setLowerLinLimit(5.0F);
// spSlider1->setUpperLinLimit(15.0F);
// spSlider1->setLowerLinLimit(-10.0F);
// spSlider1->setUpperLinLimit(-10.0F);
spSlider1->setLowerAngLimit(-SIMD_PI / 3.0F);
spSlider1->setUpperAngLimit( SIMD_PI / 3.0F);
m_dynamicsWorld->addConstraint(spSlider1, true);
spSlider1->setDbgDrawSize(btScalar(5.f));
}
#endif
#if ENABLE_ALL_DEMOS
//create a slider, using the generic D6 constraint
{

View File

@ -898,9 +898,17 @@ void SerializeDemo::exitPhysics()
{
//cleanup in the reverse order of creation/initialization
//removed/delete constraints
int i;
for (i=m_dynamicsWorld->getNumConstraints()-1; i>=0 ;i--)
{
btTypedConstraint* constraint = m_dynamicsWorld->getConstraint(i);
m_dynamicsWorld->removeConstraint(constraint);
delete constraint;
}
//remove the rigidbodies from the dynamics world and delete them
int i;
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
{
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];

View File

@ -52,6 +52,7 @@ bool btBulletWorldImporter::loadFile( const char* fileName, const char* preSwapF
bulletFile2->preSwap();
bulletFile2->writeFile(preSwapFilenameOut);
}
}
delete bulletFile2;
@ -304,7 +305,10 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
for (i=0;i<bulletFile2->m_constraints.size();i++)
{
btTypedConstraintData* constraintData = (btTypedConstraintData*)bulletFile2->m_constraints[i];
btTypedConstraintData2* constraintData = (btTypedConstraintData2*)bulletFile2->m_constraints[i];
btTypedConstraintFloatData* singleC = (btTypedConstraintFloatData*)bulletFile2->m_constraints[i];
btTypedConstraintDoubleData* doubleC = (btTypedConstraintDoubleData*)bulletFile2->m_constraints[i];
btCollisionObject** colAptr = m_bodyMap.find(constraintData->m_rbA);
btCollisionObject** colBptr = m_bodyMap.find(constraintData->m_rbB);
@ -327,7 +331,29 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
continue;
bool isDoublePrecisionData = (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)!=0;
convertConstraint(constraintData, rbA,rbB,isDoublePrecisionData, bulletFile2->getVersion());
if (isDoublePrecisionData)
{
if (bulletFile2->getVersion()>=282)
{
btTypedConstraintDoubleData* dc = (btTypedConstraintDoubleData*)constraintData;
convertConstraintDouble(dc, rbA,rbB, bulletFile2->getVersion());
} else
{
//double-precision constraints were messed up until 2.82, try to recover data...
btTypedConstraintData* oldData = (btTypedConstraintData*)constraintData;
convertConstraintBackwardsCompatible281(oldData, rbA,rbB, bulletFile2->getVersion());
}
}
else
{
btTypedConstraintFloatData* dc = (btTypedConstraintFloatData*)constraintData;
convertConstraintFloat(dc, rbA,rbB, bulletFile2->getVersion());
}
}

View File

@ -518,99 +518,53 @@ char* btWorldImporter::duplicateName(const char* name)
return 0;
}
void btWorldImporter::convertConstraint(btTypedConstraintData* constraintData,btRigidBody* rbA, btRigidBody* rbB ,bool isDoublePrecisionData, int fileVersion)
void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion)
{
btTypedConstraint* constraint = 0;
switch (constraintData->m_objectType)
{
case POINT2POINT_CONSTRAINT_TYPE:
{
if (isDoublePrecisionData)
{
btPoint2PointConstraintDoubleData* p2pData = (btPoint2PointConstraintDoubleData*)constraintData;
if (rbA && rbB)
{
btVector3 pivotInA,pivotInB;
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
pivotInB.deSerializeDouble(p2pData->m_pivotInB);
constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
} else
{
btVector3 pivotInA;
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
constraint = createPoint2PointConstraint(*rbA,pivotInA);
}
btPoint2PointConstraintDoubleData* p2pData = (btPoint2PointConstraintDoubleData*)constraintData;
if (rbA && rbB)
{
btVector3 pivotInA,pivotInB;
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
pivotInB.deSerializeDouble(p2pData->m_pivotInB);
constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
} else
{
btPoint2PointConstraintFloatData* p2pData = (btPoint2PointConstraintFloatData*)constraintData;
if (rbA&& rbB)
{
btVector3 pivotInA,pivotInB;
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
pivotInB.deSerializeFloat(p2pData->m_pivotInB);
constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
} else
{
btVector3 pivotInA;
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
constraint = createPoint2PointConstraint(*rbA,pivotInA);
}
btVector3 pivotInA;
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
constraint = createPoint2PointConstraint(*rbA,pivotInA);
}
break;
}
case HINGE_CONSTRAINT_TYPE:
{
btHingeConstraint* hinge = 0;
if (isDoublePrecisionData)
btHingeConstraintDoubleData* hingeData = (btHingeConstraintDoubleData*)constraintData;
if (rbA&& rbB)
{
btHingeConstraintDoubleData* hingeData = (btHingeConstraintDoubleData*)constraintData;
if (rbA&& rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
} else
{
btTransform rbAFrame;
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
}
if (hingeData->m_enableAngularMotor)
{
hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse);
}
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));
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
} else
{
btHingeConstraintFloatData* hingeData = (btHingeConstraintFloatData*)constraintData;
if (rbA&& rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
rbBFrame.deSerializeFloat(hingeData->m_rbBFrame);
hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
} else
{
btTransform rbAFrame;
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
}
if (hingeData->m_enableAngularMotor)
{
hinge->enableAngularMotor(true,hingeData->m_motorTargetVelocity,hingeData->m_maxMotorImpulse);
}
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));
btTransform rbAFrame;
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
}
if (hingeData->m_enableAngularMotor)
{
hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse);
}
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));
constraint = hinge;
break;
@ -621,6 +575,226 @@ void btWorldImporter::convertConstraint(btTypedConstraintData* constraintData,bt
btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData;
btConeTwistConstraint* coneTwist = 0;
if (rbA&& rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
} else
{
btTransform rbAFrame;
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
}
coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness,
(btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor);
coneTwist->setDamping((btScalar)coneData->m_damping);
constraint = coneTwist;
break;
}
case D6_SPRING_CONSTRAINT_TYPE:
{
btGeneric6DofSpringConstraintData* dofData = (btGeneric6DofSpringConstraintData*)constraintData;
// int sz = sizeof(btGeneric6DofSpringConstraintData);
btGeneric6DofSpringConstraint* dof = 0;
if (rbA && rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame);
rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame);
dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
} else
{
printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
}
if (dof)
{
btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit);
angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit);
linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit);
linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit);
angLowerLimit.setW(0.f);
dof->setAngularLowerLimit(angLowerLimit);
dof->setAngularUpperLimit(angUpperLimit);
dof->setLinearLowerLimit(linLowerLimit);
dof->setLinearUpperLimit(linUpperlimit);
int i;
if (fileVersion>280)
{
for (i=0;i<6;i++)
{
dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]);
dof->setEquilibriumPoint(i,(btScalar)dofData->m_equilibriumPoint[i]);
dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
dof->setDamping(i,(btScalar)dofData->m_springDamping[i]);
}
}
}
constraint = dof;
break;
}
case D6_CONSTRAINT_TYPE:
{
btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData;
btGeneric6DofConstraint* dof = 0;
if (rbA&& rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
} else
{
if (rbB)
{
btTransform rbBFrame;
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
} else
{
printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
}
}
if (dof)
{
btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit);
linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit);
linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit);
dof->setAngularLowerLimit(angLowerLimit);
dof->setAngularUpperLimit(angUpperLimit);
dof->setLinearLowerLimit(linLowerLimit);
dof->setLinearUpperLimit(linUpperlimit);
}
constraint = dof;
break;
}
case SLIDER_CONSTRAINT_TYPE:
{
btSliderConstraintDoubleData* sliderData = (btSliderConstraintDoubleData*)constraintData;
btSliderConstraint* slider = 0;
if (rbA&& rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeDouble(sliderData->m_rbAFrame);
rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
} else
{
btTransform rbBFrame;
rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
}
slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit);
slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit);
slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit);
slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit);
slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
constraint = slider;
break;
}
default:
{
printf("unknown constraint type\n");
}
};
if (constraint)
{
constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize);
///those fields didn't exist and set to zero for pre-280 versions, so do a check here
if (fileVersion>=280)
{
constraint->setBreakingImpulseThreshold((btScalar)constraintData->m_breakingImpulseThreshold);
constraint->setEnabled(constraintData->m_isEnabled!=0);
constraint->setOverrideNumSolverIterations(constraintData->m_overrideNumSolverIterations);
}
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);
}
}
void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion)
{
btTypedConstraint* constraint = 0;
switch (constraintData->m_objectType)
{
case POINT2POINT_CONSTRAINT_TYPE:
{
btPoint2PointConstraintFloatData2* p2pData = (btPoint2PointConstraintFloatData2*)constraintData;
if (rbA&& rbB)
{
btVector3 pivotInA,pivotInB;
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
pivotInB.deSerializeFloat(p2pData->m_pivotInB);
constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
} else
{
btVector3 pivotInA;
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
constraint = createPoint2PointConstraint(*rbA,pivotInA);
}
break;
}
case HINGE_CONSTRAINT_TYPE:
{
btHingeConstraint* hinge = 0;
btHingeConstraintFloatData* hingeData = (btHingeConstraintFloatData*)constraintData;
if (rbA&& rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
rbBFrame.deSerializeFloat(hingeData->m_rbBFrame);
hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
} else
{
btTransform rbAFrame;
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
}
if (hingeData->m_enableAngularMotor)
{
hinge->enableAngularMotor(true,hingeData->m_motorTargetVelocity,hingeData->m_maxMotorImpulse);
}
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));
constraint = hinge;
break;
}
case CONETWIST_CONSTRAINT_TYPE:
{
btConeTwistConstraintFloatData* coneData = (btConeTwistConstraintFloatData*)constraintData;
btConeTwistConstraint* coneTwist = 0;
if (rbA&& rbB)
{
btTransform rbAFrame,rbBFrame;
@ -643,7 +817,7 @@ void btWorldImporter::convertConstraint(btTypedConstraintData* constraintData,bt
case D6_SPRING_CONSTRAINT_TYPE:
{
btGeneric6DofSpringConstraintData* dofData = (btGeneric6DofSpringConstraintData*)constraintData;
btGeneric6DofSpringConstraintFloatData2* dofData = (btGeneric6DofSpringConstraintFloatData2*)constraintData;
// int sz = sizeof(btGeneric6DofSpringConstraintData);
btGeneric6DofSpringConstraint* dof = 0;
@ -690,7 +864,7 @@ void btWorldImporter::convertConstraint(btTypedConstraintData* constraintData,bt
}
case D6_CONSTRAINT_TYPE:
{
btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData;
btGeneric6DofConstraintFloatData2* dofData = (btGeneric6DofConstraintFloatData2*)constraintData;
btGeneric6DofConstraint* dof = 0;
if (rbA&& rbB)
@ -786,6 +960,227 @@ void btWorldImporter::convertConstraint(btTypedConstraintData* constraintData,bt
void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion)
{
btTypedConstraint* constraint = 0;
switch (constraintData->m_objectType)
{
case POINT2POINT_CONSTRAINT_TYPE:
{
btPoint2PointConstraintDoubleData2* p2pData = (btPoint2PointConstraintDoubleData2*)constraintData;
if (rbA && rbB)
{
btVector3 pivotInA,pivotInB;
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
pivotInB.deSerializeDouble(p2pData->m_pivotInB);
constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
} else
{
btVector3 pivotInA;
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
constraint = createPoint2PointConstraint(*rbA,pivotInA);
}
break;
}
case HINGE_CONSTRAINT_TYPE:
{
btHingeConstraint* hinge = 0;
btHingeConstraintDoubleData2* hingeData = (btHingeConstraintDoubleData2*)constraintData;
if (rbA&& rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
} else
{
btTransform rbAFrame;
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
}
if (hingeData->m_enableAngularMotor)
{
hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse);
}
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));
constraint = hinge;
break;
}
case CONETWIST_CONSTRAINT_TYPE:
{
btConeTwistConstraintDoubleData* coneData = (btConeTwistConstraintDoubleData*)constraintData;
btConeTwistConstraint* coneTwist = 0;
if (rbA&& rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeDouble(coneData->m_rbAFrame);
rbBFrame.deSerializeDouble(coneData->m_rbBFrame);
coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
} else
{
btTransform rbAFrame;
rbAFrame.deSerializeDouble(coneData->m_rbAFrame);
coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
}
coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness,
(btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor);
coneTwist->setDamping((btScalar)coneData->m_damping);
constraint = coneTwist;
break;
}
case D6_SPRING_CONSTRAINT_TYPE:
{
btGeneric6DofSpringConstraintDoubleData2* dofData = (btGeneric6DofSpringConstraintDoubleData2*)constraintData;
// int sz = sizeof(btGeneric6DofSpringConstraintData);
btGeneric6DofSpringConstraint* dof = 0;
if (rbA && rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeDouble(dofData->m_6dofData.m_rbAFrame);
rbBFrame.deSerializeDouble(dofData->m_6dofData.m_rbBFrame);
dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
} else
{
printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
}
if (dof)
{
btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
angLowerLimit.deSerializeDouble(dofData->m_6dofData.m_angularLowerLimit);
angUpperLimit.deSerializeDouble(dofData->m_6dofData.m_angularUpperLimit);
linLowerLimit.deSerializeDouble(dofData->m_6dofData.m_linearLowerLimit);
linUpperlimit.deSerializeDouble(dofData->m_6dofData.m_linearUpperLimit);
angLowerLimit.setW(0.f);
dof->setAngularLowerLimit(angLowerLimit);
dof->setAngularUpperLimit(angUpperLimit);
dof->setLinearLowerLimit(linLowerLimit);
dof->setLinearUpperLimit(linUpperlimit);
int i;
if (fileVersion>280)
{
for (i=0;i<6;i++)
{
dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]);
dof->setEquilibriumPoint(i,(btScalar)dofData->m_equilibriumPoint[i]);
dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
dof->setDamping(i,(btScalar)dofData->m_springDamping[i]);
}
}
}
constraint = dof;
break;
}
case D6_CONSTRAINT_TYPE:
{
btGeneric6DofConstraintDoubleData2* dofData = (btGeneric6DofConstraintDoubleData2*)constraintData;
btGeneric6DofConstraint* dof = 0;
if (rbA&& rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeDouble(dofData->m_rbAFrame);
rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
} else
{
if (rbB)
{
btTransform rbBFrame;
rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
} else
{
printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
}
}
if (dof)
{
btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
angLowerLimit.deSerializeDouble(dofData->m_angularLowerLimit);
angUpperLimit.deSerializeDouble(dofData->m_angularUpperLimit);
linLowerLimit.deSerializeDouble(dofData->m_linearLowerLimit);
linUpperlimit.deSerializeDouble(dofData->m_linearUpperLimit);
dof->setAngularLowerLimit(angLowerLimit);
dof->setAngularUpperLimit(angUpperLimit);
dof->setLinearLowerLimit(linLowerLimit);
dof->setLinearUpperLimit(linUpperlimit);
}
constraint = dof;
break;
}
case SLIDER_CONSTRAINT_TYPE:
{
btSliderConstraintDoubleData* sliderData = (btSliderConstraintDoubleData*)constraintData;
btSliderConstraint* slider = 0;
if (rbA&& rbB)
{
btTransform rbAFrame,rbBFrame;
rbAFrame.deSerializeDouble(sliderData->m_rbAFrame);
rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
} else
{
btTransform rbBFrame;
rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
}
slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit);
slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit);
slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit);
slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit);
slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
constraint = slider;
break;
}
default:
{
printf("unknown constraint type\n");
}
};
if (constraint)
{
constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize);
///those fields didn't exist and set to zero for pre-280 versions, so do a check here
if (fileVersion>=280)
{
constraint->setBreakingImpulseThreshold((btScalar)constraintData->m_breakingImpulseThreshold);
constraint->setEnabled(constraintData->m_isEnabled!=0);
constraint->setOverrideNumSolverIterations(constraintData->m_overrideNumSolverIterations);
}
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);
}
}

View File

@ -45,6 +45,8 @@ class btGeneric6DofSpringConstraint;
class btSliderConstraint;
struct btContactSolverInfo;
struct btTypedConstraintData;
struct btTypedConstraintFloatData;
struct btTypedConstraintDoubleData;
struct btRigidBodyDoubleData;
struct btRigidBodyFloatData;
@ -100,7 +102,10 @@ protected:
char* duplicateName(const char* name);
btCollisionShape* convertCollisionShape( btCollisionShapeData* shapeData );
void convertConstraint(btTypedConstraintData* constraintData, btRigidBody* rbA, btRigidBody* rbB, bool isDoublePrecisionData, int fileVersion);
void convertConstraintBackwardsCompatible281(btTypedConstraintData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion);
void convertConstraintFloat(btTypedConstraintFloatData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion);
void convertConstraintDouble(btTypedConstraintDoubleData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion);
void convertRigidBodyFloat(btRigidBodyFloatData* colObjData);
void convertRigidBodyDouble( btRigidBodyDoubleData* colObjData);

View File

@ -407,7 +407,7 @@ void btBulletXmlWorldImporter::deSerializeGeneric6DofConstraintData(TiXmlNode* p
int ptr=0;
get_int_attribute_by_name(pParent->ToElement(),"pointer",&ptr);
btGeneric6DofConstraintData* dof6Data = (btGeneric6DofConstraintData*)btAlignedAlloc(sizeof(btGeneric6DofConstraintData),16);
btGeneric6DofConstraintData2* dof6Data = (btGeneric6DofConstraintData2*)btAlignedAlloc(sizeof(btGeneric6DofConstraintData2),16);
TiXmlNode* n = pParent->FirstChild("m_typeConstraintData");
@ -438,7 +438,7 @@ void btBulletXmlWorldImporter::deSerializeGeneric6DofConstraintData(TiXmlNode* p
SET_INT_VALUE(pParent, dof6Data,m_useLinearReferenceFrameA);
SET_INT_VALUE(pParent, dof6Data,m_useOffsetForConstraintFrame);
m_constraintData.push_back((btTypedConstraintData*)dof6Data);
m_constraintData.push_back((btTypedConstraintData2*)dof6Data);
m_pointerLookup.insert((void*)ptr,dof6Data);
}
@ -560,7 +560,7 @@ CONCAVE_SHAPES_END_HERE,
MAX_BROADPHASE_COLLISION_TYPES
*/
void btBulletXmlWorldImporter::fixupConstraintData(btTypedConstraintData* tcd)
void btBulletXmlWorldImporter::fixupConstraintData(btTypedConstraintData2* tcd)
{
if (tcd->m_rbA)
{
@ -754,7 +754,7 @@ void btBulletXmlWorldImporter::auto_serialize_root_level_children(TiXmlNode* pPa
for (int i=0;i<m_constraintData.size();i++)
{
btTypedConstraintData* tcd = m_constraintData[i];
btTypedConstraintData2* tcd = m_constraintData[i];
fixupConstraintData(tcd);
}
@ -789,7 +789,7 @@ void btBulletXmlWorldImporter::auto_serialize_root_level_children(TiXmlNode* pPa
for (int i=0;i<m_constraintData.size();i++)
{
btTypedConstraintData* tcd = m_constraintData[i];
btTypedConstraintData2* tcd = m_constraintData[i];
bool isDoublePrecision = false;
btRigidBody* rbA = 0;
btRigidBody* rbB = 0;
@ -809,7 +809,8 @@ void btBulletXmlWorldImporter::auto_serialize_root_level_children(TiXmlNode* pPa
}
if (rbA || rbB)
{
convertConstraint(tcd,rbA,rbB,isDoublePrecision, m_fileVersion);
btAssert(0);//todo
//convertConstraint(tcd,rbA,rbB,isDoublePrecision, m_fileVersion);
}
}

View File

@ -24,12 +24,17 @@ struct btConvexInternalShapeData;
struct btCollisionShapeData;
#ifdef BT_USE_DOUBLE_PRECISION
struct btRigidBodyDoubleData;
struct btTypedConstraintDoubleData;
#define btRigidBodyData btRigidBodyDoubleData
#define btTypedConstraintData2 btTypedConstraintDoubleData
#else
struct btRigidBodyFloatData;
struct btTypedConstraintFloatData;
#define btTypedConstraintData2 btTypedConstraintFloatData
#define btRigidBodyData btRigidBodyFloatData
#endif//BT_USE_DOUBLE_PRECISION
struct btTypedConstraintData;
struct btCompoundShapeChildData;
#include "LinearMath/btAlignedObjectArray.h"
@ -42,7 +47,7 @@ protected:
btAlignedObjectArray<btCollisionShapeData*> m_collisionShapeData;
btAlignedObjectArray<btAlignedObjectArray<btCompoundShapeChildData>* > m_compoundShapeChildDataArrays;
btAlignedObjectArray<btRigidBodyData*> m_rigidBodyData;
btAlignedObjectArray<btTypedConstraintData*> m_constraintData;
btAlignedObjectArray<btTypedConstraintData2*> m_constraintData;
btHashMap<btHashPtr,void*> m_pointerLookup;
int m_fileVersion;
bool m_fileOk;
@ -53,7 +58,7 @@ protected:
void deSerializeVector3FloatData(TiXmlNode* pParent,btAlignedObjectArray<btVector3FloatData>& vectors);
void fixupCollisionDataPointers(btCollisionShapeData* shapeData);
void fixupConstraintData(btTypedConstraintData* tcd);
void fixupConstraintData(btTypedConstraintData2* tcd);
//collision shapes data
void deSerializeCollisionShapeData(TiXmlNode* pParent,btCollisionShapeData* colShapeData);

View File

@ -40,6 +40,15 @@ and swing 1 and 2 are along the z and y axes respectively.
#include "btJacobianEntry.h"
#include "btTypedConstraint.h"
#ifdef BT_USE_DOUBLE_PRECISION
#define btConeTwistConstraintData2 btConeTwistConstraintDoubleData
#define btConeTwistConstraintDataName "btConeTwistConstraintDoubleData"
#else
#define btConeTwistConstraintData2 btConeTwistConstraintFloatData
#define btConeTwistConstraintDataName "btConeTwistConstraintFloatData"
#endif //BT_USE_DOUBLE_PRECISION
class btRigidBody;
enum btConeTwistFlags
@ -296,6 +305,48 @@ public:
};
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
struct btConeTwistConstraintFloatData
{
btTypedConstraintFloatData m_typeConstraintData;
btTransformFloatData m_rbAFrame;
btTransformFloatData m_rbBFrame;
//limits
float m_swingSpan1;
float m_swingSpan2;
float m_twistSpan;
float m_limitSoftness;
float m_biasFactor;
float m_relaxationFactor;
float m_damping;
char m_pad[4];
};
struct btConeTwistConstraintDoubleData
{
btTypedConstraintDoubleData m_typeConstraintData;
btTransformDoubleData m_rbAFrame;
btTransformDoubleData m_rbBFrame;
//limits
double m_swingSpan1;
double m_swingSpan2;
double m_twistSpan;
double m_limitSoftness;
double m_biasFactor;
double m_relaxationFactor;
double m_damping;
};
#ifdef BT_BACKWARDS_COMPATIBLE_SERIALIZATION
///this structure is not used, except for loading pre-2.82 .bullet files
struct btConeTwistConstraintData
{
btTypedConstraintData m_typeConstraintData;
@ -315,12 +366,12 @@ struct btConeTwistConstraintData
char m_pad[4];
};
#endif //BT_BACKWARDS_COMPATIBLE_SERIALIZATION
//
SIMD_FORCE_INLINE int btConeTwistConstraint::calculateSerializeBufferSize() const
{
return sizeof(btConeTwistConstraintData);
return sizeof(btConeTwistConstraintData2);
}
@ -328,21 +379,21 @@ SIMD_FORCE_INLINE int btConeTwistConstraint::calculateSerializeBufferSize() cons
///fills the dataBuffer and returns the struct name (and 0 on failure)
SIMD_FORCE_INLINE const char* btConeTwistConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
{
btConeTwistConstraintData* cone = (btConeTwistConstraintData*) dataBuffer;
btConeTwistConstraintData2* cone = (btConeTwistConstraintData2*) dataBuffer;
btTypedConstraint::serialize(&cone->m_typeConstraintData,serializer);
m_rbAFrame.serializeFloat(cone->m_rbAFrame);
m_rbBFrame.serializeFloat(cone->m_rbBFrame);
m_rbAFrame.serialize(cone->m_rbAFrame);
m_rbBFrame.serialize(cone->m_rbBFrame);
cone->m_swingSpan1 = float(m_swingSpan1);
cone->m_swingSpan2 = float(m_swingSpan2);
cone->m_twistSpan = float(m_twistSpan);
cone->m_limitSoftness = float(m_limitSoftness);
cone->m_biasFactor = float(m_biasFactor);
cone->m_relaxationFactor = float(m_relaxationFactor);
cone->m_damping = float(m_damping);
cone->m_swingSpan1 = m_swingSpan1;
cone->m_swingSpan2 = m_swingSpan2;
cone->m_twistSpan = m_twistSpan;
cone->m_limitSoftness = m_limitSoftness;
cone->m_biasFactor = m_biasFactor;
cone->m_relaxationFactor = m_relaxationFactor;
cone->m_damping = m_damping;
return "btConeTwistConstraintData";
return btConeTwistConstraintDataName;
}

View File

@ -35,6 +35,14 @@ class btRigidBody;
#ifdef BT_USE_DOUBLE_PRECISION
#define btGeneric6DofConstraintData2 btGeneric6DofConstraintDoubleData2
#define btGeneric6DofConstraintDataName "btGeneric6DofConstraintDoubleData2"
#else
#define btGeneric6DofConstraintData2 btGeneric6DofConstraintFloatData2
#define btGeneric6DofConstraintDataName "btGeneric6DofConstraintFloatData2"
#endif //BT_USE_DOUBLE_PRECISION
//! Rotation Limit structure for generic joints
class btRotationalLimitMotor
@ -562,6 +570,25 @@ public:
};
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
struct btGeneric6DofConstraintFloatData2
{
btTypedConstraintFloatData m_typeConstraintData;
btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
btTransformFloatData m_rbBFrame;
btVector3FloatData m_linearUpperLimit;
btVector3FloatData m_linearLowerLimit;
btVector3FloatData m_angularUpperLimit;
btVector3FloatData m_angularLowerLimit;
int m_useLinearReferenceFrameA;
int m_useOffsetForConstraintFrame;
};
#ifdef BT_BACKWARDS_COMPATIBLE_SERIALIZATION
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
///this structure is not used, except for loading pre-2.82 .bullet files
struct btGeneric6DofConstraintData
{
btTypedConstraintData m_typeConstraintData;
@ -577,36 +604,53 @@ struct btGeneric6DofConstraintData
int m_useLinearReferenceFrameA;
int m_useOffsetForConstraintFrame;
};
#endif //BT_BACKWARDS_COMPATIBLE_SERIALIZATION
struct btGeneric6DofConstraintDoubleData2
{
btTypedConstraintDoubleData m_typeConstraintData;
btTransformDoubleData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
btTransformDoubleData m_rbBFrame;
btVector3DoubleData m_linearUpperLimit;
btVector3DoubleData m_linearLowerLimit;
btVector3DoubleData m_angularUpperLimit;
btVector3DoubleData m_angularLowerLimit;
int m_useLinearReferenceFrameA;
int m_useOffsetForConstraintFrame;
};
SIMD_FORCE_INLINE int btGeneric6DofConstraint::calculateSerializeBufferSize() const
{
return sizeof(btGeneric6DofConstraintData);
return sizeof(btGeneric6DofConstraintData2);
}
///fills the dataBuffer and returns the struct name (and 0 on failure)
SIMD_FORCE_INLINE const char* btGeneric6DofConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
{
btGeneric6DofConstraintData* dof = (btGeneric6DofConstraintData*)dataBuffer;
btGeneric6DofConstraintData2* dof = (btGeneric6DofConstraintData2*)dataBuffer;
btTypedConstraint::serialize(&dof->m_typeConstraintData,serializer);
m_frameInA.serializeFloat(dof->m_rbAFrame);
m_frameInB.serializeFloat(dof->m_rbBFrame);
m_frameInA.serialize(dof->m_rbAFrame);
m_frameInB.serialize(dof->m_rbBFrame);
int i;
for (i=0;i<3;i++)
{
dof->m_angularLowerLimit.m_floats[i] = float(m_angularLimits[i].m_loLimit);
dof->m_angularUpperLimit.m_floats[i] = float(m_angularLimits[i].m_hiLimit);
dof->m_linearLowerLimit.m_floats[i] = float(m_linearLimits.m_lowerLimit[i]);
dof->m_linearUpperLimit.m_floats[i] = float(m_linearLimits.m_upperLimit[i]);
dof->m_angularLowerLimit.m_floats[i] = m_angularLimits[i].m_loLimit;
dof->m_angularUpperLimit.m_floats[i] = m_angularLimits[i].m_hiLimit;
dof->m_linearLowerLimit.m_floats[i] = m_linearLimits.m_lowerLimit[i];
dof->m_linearUpperLimit.m_floats[i] = m_linearLimits.m_upperLimit[i];
}
dof->m_useLinearReferenceFrameA = m_useLinearReferenceFrameA? 1 : 0;
dof->m_useOffsetForConstraintFrame = m_useOffsetForConstraintFrame ? 1 : 0;
return "btGeneric6DofConstraintData";
return btGeneric6DofConstraintDataName;
}

View File

@ -21,6 +21,15 @@ subject to the following restrictions:
#include "btTypedConstraint.h"
#include "btGeneric6DofConstraint.h"
#ifdef BT_USE_DOUBLE_PRECISION
#define btGeneric6DofSpringConstraintData2 btGeneric6DofSpringConstraintDoubleData2
#define btGeneric6DofSpringConstraintDataName "btGeneric6DofSpringConstraintDoubleData2"
#else
#define btGeneric6DofSpringConstraintData2 btGeneric6DofSpringConstraintFloatData2
#define btGeneric6DofSpringConstraintDataName "btGeneric6DofSpringConstraintFloatData2"
#endif //BT_USE_DOUBLE_PRECISION
/// Generic 6 DOF constraint that allows to set spring motors to any translational and rotational DOF
@ -66,6 +75,19 @@ public:
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
struct btGeneric6DofSpringConstraintFloatData2
{
btGeneric6DofConstraintFloatData2 m_6dofData;
int m_springEnabled[6];
float m_equilibriumPoint[6];
float m_springStiffness[6];
float m_springDamping[6];
};
#ifdef BT_BACKWARDS_COMPATIBLE_SERIALIZATION
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
///this structure is not used, except for loading pre-2.82 .bullet files
struct btGeneric6DofSpringConstraintData
{
btGeneric6DofConstraintData m_6dofData;
@ -75,27 +97,39 @@ struct btGeneric6DofSpringConstraintData
float m_springStiffness[6];
float m_springDamping[6];
};
#endif //BT_BACKWARDS_COMPATIBLE_SERIALIZATION
struct btGeneric6DofSpringConstraintDoubleData2
{
btGeneric6DofConstraintDoubleData2 m_6dofData;
int m_springEnabled[6];
double m_equilibriumPoint[6];
double m_springStiffness[6];
double m_springDamping[6];
};
SIMD_FORCE_INLINE int btGeneric6DofSpringConstraint::calculateSerializeBufferSize() const
{
return sizeof(btGeneric6DofSpringConstraintData);
return sizeof(btGeneric6DofSpringConstraintData2);
}
///fills the dataBuffer and returns the struct name (and 0 on failure)
SIMD_FORCE_INLINE const char* btGeneric6DofSpringConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
{
btGeneric6DofSpringConstraintData* dof = (btGeneric6DofSpringConstraintData*)dataBuffer;
btGeneric6DofSpringConstraintData2* dof = (btGeneric6DofSpringConstraintData2*)dataBuffer;
btGeneric6DofConstraint::serialize(&dof->m_6dofData,serializer);
int i;
for (i=0;i<6;i++)
{
dof->m_equilibriumPoint[i] = (float)m_equilibriumPoint[i];
dof->m_springDamping[i] = (float)m_springDamping[i];
dof->m_equilibriumPoint[i] = m_equilibriumPoint[i];
dof->m_springDamping[i] = m_springDamping[i];
dof->m_springEnabled[i] = m_springEnabled[i]? 1 : 0;
dof->m_springStiffness[i] = (float)m_springStiffness[i];
dof->m_springStiffness[i] = m_springStiffness[i];
}
return "btGeneric6DofSpringConstraintData";
return btGeneric6DofSpringConstraintDataName;
}
#endif // BT_GENERIC_6DOF_SPRING_CONSTRAINT_H

View File

@ -28,11 +28,11 @@ subject to the following restrictions:
class btRigidBody;
#ifdef BT_USE_DOUBLE_PRECISION
#define btHingeConstraintData btHingeConstraintDoubleData
#define btHingeConstraintDataName "btHingeConstraintDoubleData"
#define btHingeConstraintData btHingeConstraintDoubleData2 //rename to 2 for backwards compatibility, so we can still load the 'btHingeConstraintDoubleData' version
#define btHingeConstraintDataName "btHingeConstraintDoubleData2"
#else
#define btHingeConstraintData btHingeConstraintFloatData
#define btHingeConstraintDataName "btHingeConstraintFloatData"
#define btHingeConstraintData btHingeConstraintFloatData2
#define btHingeConstraintDataName "btHingeConstraintFloatData2"
#endif //BT_USE_DOUBLE_PRECISION
@ -302,10 +302,11 @@ public:
};
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
struct btHingeConstraintDoubleData
struct btHingeConstraintDoubleData2
{
btTypedConstraintData m_typeConstraintData;
btTypedConstraintDoubleData m_typeConstraintData;
btTransformDoubleData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
btTransformDoubleData m_rbBFrame;
int m_useReferenceFrameA;
@ -322,7 +323,52 @@ struct btHingeConstraintDoubleData
char m_padding1[4];
};
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
struct btHingeConstraintFloatData2
{
btTypedConstraintFloatData m_typeConstraintData;
btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
btTransformFloatData m_rbBFrame;
int m_useReferenceFrameA;
int m_angularOnly;
int m_enableAngularMotor;
float m_motorTargetVelocity;
float m_maxMotorImpulse;
float m_lowerLimit;
float m_upperLimit;
float m_limitSoftness;
float m_biasFactor;
float m_relaxationFactor;
};
//only for backward compatibility
#ifdef BT_BACKWARDS_COMPATIBLE_SERIALIZATION
///this structure is not used, except for loading pre-2.82 .bullet files
struct btHingeConstraintDoubleData
{
btTypedConstraintData m_typeConstraintData;
btTransformDoubleData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
btTransformDoubleData m_rbBFrame;
int m_useReferenceFrameA;
int m_angularOnly;
int m_enableAngularMotor;
float m_motorTargetVelocity;
float m_maxMotorImpulse;
float m_lowerLimit;
float m_upperLimit;
float m_limitSoftness;
float m_biasFactor;
float m_relaxationFactor;
};
///this structure is not used, except for loading pre-2.82 .bullet files
struct btHingeConstraintFloatData
{
btTypedConstraintData m_typeConstraintData;
@ -342,7 +388,7 @@ struct btHingeConstraintFloatData
float m_relaxationFactor;
};
#endif //BT_BACKWARDS_COMPATIBLE_SERIALIZATION
SIMD_FORCE_INLINE int btHingeConstraint::calculateSerializeBufferSize() const

View File

@ -24,11 +24,11 @@ class btRigidBody;
#ifdef BT_USE_DOUBLE_PRECISION
#define btPoint2PointConstraintData btPoint2PointConstraintDoubleData
#define btPoint2PointConstraintDataName "btPoint2PointConstraintDoubleData"
#define btPoint2PointConstraintData2 btPoint2PointConstraintDoubleData2
#define btPoint2PointConstraintDataName "btPoint2PointConstraintDoubleData2"
#else
#define btPoint2PointConstraintData btPoint2PointConstraintFloatData
#define btPoint2PointConstraintDataName "btPoint2PointConstraintFloatData"
#define btPoint2PointConstraintData2 btPoint2PointConstraintFloatData2
#define btPoint2PointConstraintDataName "btPoint2PointConstraintFloatData2"
#endif //BT_USE_DOUBLE_PRECISION
struct btConstraintSetting
@ -126,6 +126,24 @@ public:
};
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
struct btPoint2PointConstraintFloatData2
{
btTypedConstraintFloatData m_typeConstraintData;
btVector3FloatData m_pivotInA;
btVector3FloatData m_pivotInB;
};
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
struct btPoint2PointConstraintDoubleData2
{
btTypedConstraintDoubleData m_typeConstraintData;
btVector3DoubleData m_pivotInA;
btVector3DoubleData m_pivotInB;
};
#ifdef BT_BACKWARDS_COMPATIBLE_SERIALIZATION
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
///this structure is not used, except for loading pre-2.82 .bullet files
struct btPoint2PointConstraintFloatData
{
btTypedConstraintData m_typeConstraintData;
@ -140,18 +158,19 @@ struct btPoint2PointConstraintDoubleData
btVector3DoubleData m_pivotInA;
btVector3DoubleData m_pivotInB;
};
#endif //BT_BACKWARDS_COMPATIBLE_SERIALIZATION
SIMD_FORCE_INLINE int btPoint2PointConstraint::calculateSerializeBufferSize() const
{
return sizeof(btPoint2PointConstraintData);
return sizeof(btPoint2PointConstraintData2);
}
///fills the dataBuffer and returns the struct name (and 0 on failure)
SIMD_FORCE_INLINE const char* btPoint2PointConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
{
btPoint2PointConstraintData* p2pData = (btPoint2PointConstraintData*)dataBuffer;
btPoint2PointConstraintData2* p2pData = (btPoint2PointConstraintData2*)dataBuffer;
btTypedConstraint::serialize(&p2pData->m_typeConstraintData,serializer);
m_pivotInA.serialize(p2pData->m_pivotInA);

View File

@ -25,7 +25,13 @@ TODO:
#ifndef BT_SLIDER_CONSTRAINT_H
#define BT_SLIDER_CONSTRAINT_H
#ifdef BT_USE_DOUBLE_PRECISION
#define btSliderConstraintData2 btSliderConstraintDoubleData
#define btSliderConstraintDataName "btSliderConstraintDoubleData"
#else
#define btSliderConstraintData2 btSliderConstraintData //not btSliderConstraintFloatData for backward compatibility
#define btSliderConstraintDataName "btSliderConstraintData" //not "btSliderConstraintFloatData" for backward compatibility
#endif //BT_USE_DOUBLE_PRECISION
#include "LinearMath/btVector3.h"
#include "btJacobianEntry.h"
@ -286,7 +292,7 @@ public:
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
struct btSliderConstraintData
{
btTypedConstraintData m_typeConstraintData;
btTypedConstraintFloatData m_typeConstraintData;
btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
btTransformFloatData m_rbBFrame;
@ -301,32 +307,48 @@ struct btSliderConstraintData
};
struct btSliderConstraintDoubleData
{
btTypedConstraintDoubleData m_typeConstraintData;
btTransformDoubleData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
btTransformDoubleData m_rbBFrame;
double m_linearUpperLimit;
double m_linearLowerLimit;
double m_angularUpperLimit;
double m_angularLowerLimit;
int m_useLinearReferenceFrameA;
int m_useOffsetForConstraintFrame;
};
SIMD_FORCE_INLINE int btSliderConstraint::calculateSerializeBufferSize() const
{
return sizeof(btSliderConstraintData);
return sizeof(btSliderConstraintData2);
}
///fills the dataBuffer and returns the struct name (and 0 on failure)
SIMD_FORCE_INLINE const char* btSliderConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
{
btSliderConstraintData* sliderData = (btSliderConstraintData*) dataBuffer;
btSliderConstraintData2* sliderData = (btSliderConstraintData2*) dataBuffer;
btTypedConstraint::serialize(&sliderData->m_typeConstraintData,serializer);
m_frameInA.serializeFloat(sliderData->m_rbAFrame);
m_frameInB.serializeFloat(sliderData->m_rbBFrame);
m_frameInA.serialize(sliderData->m_rbAFrame);
m_frameInB.serialize(sliderData->m_rbBFrame);
sliderData->m_linearUpperLimit = float(m_upperLinLimit);
sliderData->m_linearLowerLimit = float(m_lowerLinLimit);
sliderData->m_linearUpperLimit = m_upperLinLimit;
sliderData->m_linearLowerLimit = m_lowerLinLimit;
sliderData->m_angularUpperLimit = float(m_upperAngLimit);
sliderData->m_angularLowerLimit = float(m_lowerAngLimit);
sliderData->m_angularUpperLimit = m_upperAngLimit;
sliderData->m_angularLowerLimit = m_lowerAngLimit;
sliderData->m_useLinearReferenceFrameA = m_useLinearReferenceFrameA;
sliderData->m_useOffsetForConstraintFrame = m_useOffsetForConstraintFrame;
return "btSliderConstraintData";
return btSliderConstraintDataName;
}

View File

@ -109,7 +109,7 @@ btScalar btTypedConstraint::getMotorFactor(btScalar pos, btScalar lowLim, btScal
///fills the dataBuffer and returns the struct name (and 0 on failure)
const char* btTypedConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
{
btTypedConstraintData* tcd = (btTypedConstraintData*) dataBuffer;
btTypedConstraintData2* tcd = (btTypedConstraintData2*) dataBuffer;
tcd->m_rbA = (btRigidBodyData*)serializer->getUniquePointer(&m_rbA);
tcd->m_rbB = (btRigidBodyData*)serializer->getUniquePointer(&m_rbB);
@ -123,14 +123,14 @@ const char* btTypedConstraint::serialize(void* dataBuffer, btSerializer* seriali
tcd->m_objectType = m_objectType;
tcd->m_needsFeedback = m_needsFeedback;
tcd->m_overrideNumSolverIterations = m_overrideNumSolverIterations;
tcd->m_breakingImpulseThreshold = float(m_breakingImpulseThreshold);
tcd->m_breakingImpulseThreshold = m_breakingImpulseThreshold;
tcd->m_isEnabled = m_isEnabled? 1: 0;
tcd->m_userConstraintId =m_userConstraintId;
tcd->m_userConstraintType =m_userConstraintType;
tcd->m_appliedImpulse = float(m_appliedImpulse);
tcd->m_dbgDrawSize = float(m_dbgDrawSize );
tcd->m_appliedImpulse = m_appliedImpulse;
tcd->m_dbgDrawSize = m_dbgDrawSize;
tcd->m_disableCollisionsBetweenLinkedBodies = false;
@ -142,7 +142,7 @@ const char* btTypedConstraint::serialize(void* dataBuffer, btSerializer* seriali
if (m_rbB.getConstraintRef(i) == this)
tcd->m_disableCollisionsBetweenLinkedBodies = true;
return "btTypedConstraintData";
return btTypedConstraintDataName;
}
btRigidBody& btTypedConstraint::getFixedBody()

View File

@ -21,6 +21,15 @@ subject to the following restrictions:
#include "btSolverConstraint.h"
#include "BulletDynamics/Dynamics/btRigidBody.h"
#ifdef BT_USE_DOUBLE_PRECISION
#define btTypedConstraintData2 btTypedConstraintDoubleData
#define btTypedConstraintDataName "btTypedConstraintDoubleData"
#else
#define btTypedConstraintData2 btTypedConstraintFloatData
#define btTypedConstraintDataName "btTypedConstraintFloatData"
#endif //BT_USE_DOUBLE_PRECISION
class btSerializer;
//Don't change any of the existing enum values, so add enum types at the end for serialization compatibility
@ -356,6 +365,33 @@ SIMD_FORCE_INLINE btScalar btAdjustAngleToLimits(btScalar angleInRadians, btScal
}
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
struct btTypedConstraintFloatData
{
btRigidBodyFloatData *m_rbA;
btRigidBodyFloatData *m_rbB;
char *m_name;
int m_objectType;
int m_userConstraintType;
int m_userConstraintId;
int m_needsFeedback;
float m_appliedImpulse;
float m_dbgDrawSize;
int m_disableCollisionsBetweenLinkedBodies;
int m_overrideNumSolverIterations;
float m_breakingImpulseThreshold;
int m_isEnabled;
};
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
#define BT_BACKWARDS_COMPATIBLE_SERIALIZATION
#ifdef BT_BACKWARDS_COMPATIBLE_SERIALIZATION
///this structure is not used, except for loading pre-2.82 .bullet files
struct btTypedConstraintData
{
btRigidBodyData *m_rbA;
@ -377,10 +413,35 @@ struct btTypedConstraintData
int m_isEnabled;
};
#endif BACKWARDS_COMPATIBLE
struct btTypedConstraintDoubleData
{
btRigidBodyDoubleData *m_rbA;
btRigidBodyDoubleData *m_rbB;
char *m_name;
int m_objectType;
int m_userConstraintType;
int m_userConstraintId;
int m_needsFeedback;
double m_appliedImpulse;
double m_dbgDrawSize;
int m_disableCollisionsBetweenLinkedBodies;
int m_overrideNumSolverIterations;
double m_breakingImpulseThreshold;
int m_isEnabled;
char padding[4];
};
SIMD_FORCE_INLINE int btTypedConstraint::calculateSerializeBufferSize() const
{
return sizeof(btTypedConstraintData);
return sizeof(btTypedConstraintData2);
}

File diff suppressed because it is too large Load Diff