2 Bullet Continuous Collision Detection and Physics Library
\r
3 Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org
\r
5 This software is provided 'as-is', without any express or implied warranty.
\r
6 In no event will the authors be held liable for any damages arising from the use of this software.
\r
7 Permission is granted to anyone to use this software for any purpose,
\r
8 including commercial applications, and to alter it and redistribute it freely,
\r
9 subject to the following restrictions:
\r
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
\r
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
\r
13 3. This notice may not be removed or altered from any source distribution.
\r
16 #include "btWorldImporter.h"
\r
17 #include "btBulletDynamicsCommon.h"
\r
18 #include "BulletCollision/Gimpact/btGImpactShape.h"
\r
20 btWorldImporter::btWorldImporter(btDynamicsWorld* world)
\r
21 :m_dynamicsWorld(world),
\r
27 btWorldImporter::~btWorldImporter()
\r
31 void btWorldImporter::deleteAllData()
\r
34 for (i=0;i<m_allocatedConstraints.size();i++)
\r
37 m_dynamicsWorld->removeConstraint(m_allocatedConstraints[i]);
\r
38 delete m_allocatedConstraints[i];
\r
40 m_allocatedConstraints.clear();
\r
43 for (i=0;i<m_allocatedRigidBodies.size();i++)
\r
46 m_dynamicsWorld->removeRigidBody(btRigidBody::upcast(m_allocatedRigidBodies[i]));
\r
47 delete m_allocatedRigidBodies[i];
\r
50 m_allocatedRigidBodies.clear();
\r
53 for (i=0;i<m_allocatedCollisionShapes.size();i++)
\r
55 delete m_allocatedCollisionShapes[i];
\r
57 m_allocatedCollisionShapes.clear();
\r
60 for (i=0;i<m_allocatedBvhs.size();i++)
\r
62 delete m_allocatedBvhs[i];
\r
64 m_allocatedBvhs.clear();
\r
66 for (i=0;i<m_allocatedTriangleInfoMaps.size();i++)
\r
68 delete m_allocatedTriangleInfoMaps[i];
\r
70 m_allocatedTriangleInfoMaps.clear();
\r
71 for (i=0;i<m_allocatedTriangleIndexArrays.size();i++)
\r
73 delete m_allocatedTriangleIndexArrays[i];
\r
75 m_allocatedTriangleIndexArrays.clear();
\r
76 for (i=0;i<m_allocatedNames.size();i++)
\r
78 delete[] m_allocatedNames[i];
\r
80 m_allocatedNames.clear();
\r
82 for (i=0;i<m_allocatedbtStridingMeshInterfaceDatas.size();i++)
\r
84 btStridingMeshInterfaceData* curData = m_allocatedbtStridingMeshInterfaceDatas[i];
\r
86 for(int a = 0;a < curData->m_numMeshParts;a++)
\r
88 btMeshPartData* curPart = &curData->m_meshPartsPtr[a];
\r
89 if(curPart->m_vertices3f)
\r
90 delete [] curPart->m_vertices3f;
\r
92 if(curPart->m_vertices3d)
\r
93 delete [] curPart->m_vertices3d;
\r
95 if(curPart->m_indices32)
\r
96 delete [] curPart->m_indices32;
\r
98 if(curPart->m_3indices16)
\r
99 delete [] curPart->m_3indices16;
\r
101 if(curPart->m_indices16)
\r
102 delete [] curPart->m_indices16;
\r
104 if (curPart->m_3indices8)
\r
105 delete [] curPart->m_3indices8;
\r
108 delete [] curData->m_meshPartsPtr;
\r
111 m_allocatedbtStridingMeshInterfaceDatas.clear();
\r
113 for (i=0;i<m_indexArrays.size();i++)
\r
115 btAlignedFree(m_indexArrays[i]);
\r
117 m_indexArrays.clear();
\r
119 for (i=0;i<m_shortIndexArrays.size();i++)
\r
121 btAlignedFree(m_shortIndexArrays[i]);
\r
123 m_shortIndexArrays.clear();
\r
125 for (i=0;i<m_charIndexArrays.size();i++)
\r
127 btAlignedFree(m_charIndexArrays[i]);
\r
129 m_charIndexArrays.clear();
\r
131 for (i=0;i<m_floatVertexArrays.size();i++)
\r
133 btAlignedFree(m_floatVertexArrays[i]);
\r
135 m_floatVertexArrays.clear();
\r
137 for (i=0;i<m_doubleVertexArrays.size();i++)
\r
139 btAlignedFree(m_doubleVertexArrays[i]);
\r
141 m_doubleVertexArrays.clear();
\r
148 btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData* shapeData )
\r
150 btCollisionShape* shape = 0;
\r
152 switch (shapeData->m_shapeType)
\r
154 case STATIC_PLANE_PROXYTYPE:
\r
156 btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*)shapeData;
\r
157 btVector3 planeNormal,localScaling;
\r
158 planeNormal.deSerializeFloat(planeData->m_planeNormal);
\r
159 localScaling.deSerializeFloat(planeData->m_localScaling);
\r
160 shape = createPlaneShape(planeNormal,planeData->m_planeConstant);
\r
161 shape->setLocalScaling(localScaling);
\r
165 case SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE:
\r
167 btScaledTriangleMeshShapeData* scaledMesh = (btScaledTriangleMeshShapeData*) shapeData;
\r
168 btCollisionShapeData* colShapeData = (btCollisionShapeData*) &scaledMesh->m_trimeshShapeData;
\r
169 colShapeData->m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;
\r
170 btCollisionShape* childShape = convertCollisionShape(colShapeData);
\r
171 btBvhTriangleMeshShape* meshShape = (btBvhTriangleMeshShape*)childShape;
\r
172 btVector3 localScaling;
\r
173 localScaling.deSerializeFloat(scaledMesh->m_localScaling);
\r
175 shape = createScaledTrangleMeshShape(meshShape, localScaling);
\r
178 case GIMPACT_SHAPE_PROXYTYPE:
\r
180 btGImpactMeshShapeData* gimpactData = (btGImpactMeshShapeData*) shapeData;
\r
181 if (gimpactData->m_gimpactSubType == CONST_GIMPACT_TRIMESH_SHAPE)
\r
183 btStridingMeshInterfaceData* interfaceData = createStridingMeshInterfaceData(&gimpactData->m_meshInterface);
\r
184 btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
\r
187 btGImpactMeshShape* gimpactShape = createGimpactShape(meshInterface);
\r
188 btVector3 localScaling;
\r
189 localScaling.deSerializeFloat(gimpactData->m_localScaling);
\r
190 gimpactShape->setLocalScaling(localScaling);
\r
191 gimpactShape->setMargin(btScalar(gimpactData->m_collisionMargin));
\r
192 gimpactShape->updateBound();
\r
193 shape = gimpactShape;
\r
196 printf("unsupported gimpact sub type\n");
\r
201 case CYLINDER_SHAPE_PROXYTYPE:
\r
202 case CAPSULE_SHAPE_PROXYTYPE:
\r
203 case BOX_SHAPE_PROXYTYPE:
\r
204 case SPHERE_SHAPE_PROXYTYPE:
\r
205 case MULTI_SPHERE_SHAPE_PROXYTYPE:
\r
206 case CONVEX_HULL_SHAPE_PROXYTYPE:
\r
208 btConvexInternalShapeData* bsd = (btConvexInternalShapeData*)shapeData;
\r
209 btVector3 implicitShapeDimensions;
\r
210 implicitShapeDimensions.deSerializeFloat(bsd->m_implicitShapeDimensions);
\r
211 btVector3 localScaling;
\r
212 localScaling.deSerializeFloat(bsd->m_localScaling);
\r
213 btVector3 margin(bsd->m_collisionMargin,bsd->m_collisionMargin,bsd->m_collisionMargin);
\r
214 switch (shapeData->m_shapeType)
\r
216 case BOX_SHAPE_PROXYTYPE:
\r
218 btBoxShape* box= (btBoxShape*)createBoxShape(implicitShapeDimensions/localScaling+margin);
\r
219 //box->initializePolyhedralFeatures();
\r
224 case SPHERE_SHAPE_PROXYTYPE:
\r
226 shape = createSphereShape(implicitShapeDimensions.getX());
\r
229 case CAPSULE_SHAPE_PROXYTYPE:
\r
231 btCapsuleShapeData* capData = (btCapsuleShapeData*)shapeData;
\r
232 switch (capData->m_upAxis)
\r
236 shape = createCapsuleShapeX(implicitShapeDimensions.getY()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getX());
\r
241 shape = createCapsuleShapeY(implicitShapeDimensions.getX()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getY());
\r
246 shape = createCapsuleShapeZ(implicitShapeDimensions.getX()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getZ());
\r
251 printf("error: wrong up axis for btCapsuleShape\n");
\r
253 bsd->m_collisionMargin = 0.f;
\r
259 case CYLINDER_SHAPE_PROXYTYPE:
\r
261 btCylinderShapeData* cylData = (btCylinderShapeData*) shapeData;
\r
262 btVector3 halfExtents = implicitShapeDimensions+margin;
\r
263 switch (cylData->m_upAxis)
\r
267 shape = createCylinderShapeX(halfExtents.getY(),halfExtents.getX());
\r
272 shape = createCylinderShapeY(halfExtents.getX(),halfExtents.getY());
\r
277 shape = createCylinderShapeZ(halfExtents.getX(),halfExtents.getZ());
\r
282 printf("unknown Cylinder up axis\n");
\r
291 case MULTI_SPHERE_SHAPE_PROXYTYPE:
\r
293 btMultiSphereShapeData* mss = (btMultiSphereShapeData*)bsd;
\r
294 int numSpheres = mss->m_localPositionArraySize;
\r
296 btAlignedObjectArray<btVector3> tmpPos;
\r
297 btAlignedObjectArray<btScalar> radii;
\r
298 radii.resize(numSpheres);
\r
299 tmpPos.resize(numSpheres);
\r
301 for ( i=0;i<numSpheres;i++)
\r
303 tmpPos[i].deSerializeFloat(mss->m_localPositionArrayPtr[i].m_pos);
\r
304 radii[i] = mss->m_localPositionArrayPtr[i].m_radius;
\r
306 shape = createMultiSphereShape(&tmpPos[0],&radii[0],numSpheres);
\r
309 case CONVEX_HULL_SHAPE_PROXYTYPE:
\r
311 // int sz = sizeof(btConvexHullShapeData);
\r
312 // int sz2 = sizeof(btConvexInternalShapeData);
\r
313 // int sz3 = sizeof(btCollisionShapeData);
\r
314 btConvexHullShapeData* convexData = (btConvexHullShapeData*)bsd;
\r
315 int numPoints = convexData->m_numUnscaledPoints;
\r
317 btAlignedObjectArray<btVector3> tmpPoints;
\r
318 tmpPoints.resize(numPoints);
\r
320 for ( i=0;i<numPoints;i++)
\r
322 #ifdef BT_USE_DOUBLE_PRECISION
\r
323 if (convexData->m_unscaledPointsDoublePtr)
\r
324 tmpPoints[i].deSerialize(convexData->m_unscaledPointsDoublePtr[i]);
\r
325 if (convexData->m_unscaledPointsFloatPtr)
\r
326 tmpPoints[i].deSerializeFloat(convexData->m_unscaledPointsFloatPtr[i]);
\r
328 if (convexData->m_unscaledPointsFloatPtr)
\r
329 tmpPoints[i].deSerialize(convexData->m_unscaledPointsFloatPtr[i]);
\r
330 if (convexData->m_unscaledPointsDoublePtr)
\r
331 tmpPoints[i].deSerializeDouble(convexData->m_unscaledPointsDoublePtr[i]);
\r
332 #endif //BT_USE_DOUBLE_PRECISION
\r
334 btConvexHullShape* hullShape = createConvexHullShape();
\r
335 for (i=0;i<numPoints;i++)
\r
337 hullShape->addPoint(tmpPoints[i]);
\r
339 hullShape->setMargin(bsd->m_collisionMargin);
\r
340 //hullShape->initializePolyhedralFeatures();
\r
346 printf("error: cannot create shape type (%d)\n",shapeData->m_shapeType);
\r
352 shape->setMargin(bsd->m_collisionMargin);
\r
354 btVector3 localScaling;
\r
355 localScaling.deSerializeFloat(bsd->m_localScaling);
\r
356 shape->setLocalScaling(localScaling);
\r
361 case TRIANGLE_MESH_SHAPE_PROXYTYPE:
\r
363 btTriangleMeshShapeData* trimesh = (btTriangleMeshShapeData*)shapeData;
\r
364 btStridingMeshInterfaceData* interfaceData = createStridingMeshInterfaceData(&trimesh->m_meshInterface);
\r
365 btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
\r
366 if (!meshInterface->getNumSubParts())
\r
371 btVector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling);
\r
372 meshInterface->setScaling(scaling);
\r
375 btOptimizedBvh* bvh = 0;
\r
377 if (trimesh->m_quantizedFloatBvh)
\r
379 btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedFloatBvh);
\r
380 if (bvhPtr && *bvhPtr)
\r
385 bvh = createOptimizedBvh();
\r
386 bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh);
\r
389 if (trimesh->m_quantizedDoubleBvh)
\r
391 btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedDoubleBvh);
\r
392 if (bvhPtr && *bvhPtr)
\r
397 bvh = createOptimizedBvh();
\r
398 bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh);
\r
404 btBvhTriangleMeshShape* trimeshShape = createBvhTriangleMeshShape(meshInterface,bvh);
\r
405 trimeshShape->setMargin(trimesh->m_collisionMargin);
\r
406 shape = trimeshShape;
\r
408 if (trimesh->m_triangleInfoMap)
\r
410 btTriangleInfoMap* map = createTriangleInfoMap();
\r
411 map->deSerialize(*trimesh->m_triangleInfoMap);
\r
412 trimeshShape->setTriangleInfoMap(map);
\r
414 #ifdef USE_INTERNAL_EDGE_UTILITY
\r
415 gContactAddedCallback = btAdjustInternalEdgeContactsCallback;
\r
416 #endif //USE_INTERNAL_EDGE_UTILITY
\r
420 //printf("trimesh->m_collisionMargin=%f\n",trimesh->m_collisionMargin);
\r
423 case COMPOUND_SHAPE_PROXYTYPE:
\r
425 btCompoundShapeData* compoundData = (btCompoundShapeData*)shapeData;
\r
426 btCompoundShape* compoundShape = createCompoundShape();
\r
428 btCompoundShapeChildData* childShapeDataArray = &compoundData->m_childShapePtr[0];
\r
431 btAlignedObjectArray<btCollisionShape*> childShapes;
\r
432 for (int i=0;i<compoundData->m_numChildShapes;i++)
\r
434 btCompoundShapeChildData* ptr = &compoundData->m_childShapePtr[i];
\r
436 btCollisionShapeData* cd = compoundData->m_childShapePtr[i].m_childShape;
\r
438 btCollisionShape* childShape = convertCollisionShape(cd);
\r
441 btTransform localTransform;
\r
442 localTransform.deSerializeFloat(compoundData->m_childShapePtr[i].m_transform);
\r
443 compoundShape->addChildShape(localTransform,childShape);
\r
447 printf("error: couldn't create childShape for compoundShape\n");
\r
452 shape = compoundShape;
\r
456 case SOFTBODY_SHAPE_PROXYTYPE:
\r
463 printf("unsupported shape type (%d)\n",shapeData->m_shapeType);
\r
474 char* btWorldImporter::duplicateName(const char* name)
\r
478 int l = (int)strlen(name);
\r
479 char* newName = new char[l+1];
\r
480 memcpy(newName,name,l);
\r
482 m_allocatedNames.push_back(newName);
\r
490 void btWorldImporter::convertConstraint(btTypedConstraintData* constraintData,btRigidBody* rbA, btRigidBody* rbB ,bool isDoublePrecisionData, int fileVersion)
\r
492 btTypedConstraint* constraint = 0;
\r
494 switch (constraintData->m_objectType)
\r
496 case POINT2POINT_CONSTRAINT_TYPE:
\r
498 if (isDoublePrecisionData)
\r
500 btPoint2PointConstraintDoubleData* p2pData = (btPoint2PointConstraintDoubleData*)constraintData;
\r
503 btVector3 pivotInA,pivotInB;
\r
504 pivotInA.deSerializeDouble(p2pData->m_pivotInA);
\r
505 pivotInB.deSerializeDouble(p2pData->m_pivotInB);
\r
506 constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
\r
509 btVector3 pivotInA;
\r
510 pivotInA.deSerializeDouble(p2pData->m_pivotInA);
\r
511 constraint = createPoint2PointConstraint(*rbA,pivotInA);
\r
515 btPoint2PointConstraintFloatData* p2pData = (btPoint2PointConstraintFloatData*)constraintData;
\r
518 btVector3 pivotInA,pivotInB;
\r
519 pivotInA.deSerializeFloat(p2pData->m_pivotInA);
\r
520 pivotInB.deSerializeFloat(p2pData->m_pivotInB);
\r
521 constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
\r
525 btVector3 pivotInA;
\r
526 pivotInA.deSerializeFloat(p2pData->m_pivotInA);
\r
527 constraint = createPoint2PointConstraint(*rbA,pivotInA);
\r
534 case HINGE_CONSTRAINT_TYPE:
\r
536 btHingeConstraint* hinge = 0;
\r
538 if (isDoublePrecisionData)
\r
540 btHingeConstraintDoubleData* hingeData = (btHingeConstraintDoubleData*)constraintData;
\r
543 btTransform rbAFrame,rbBFrame;
\r
544 rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
\r
545 rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
\r
546 hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
\r
549 btTransform rbAFrame;
\r
550 rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
\r
551 hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
\r
553 if (hingeData->m_enableAngularMotor)
\r
555 hinge->enableAngularMotor(true,hingeData->m_motorTargetVelocity,hingeData->m_maxMotorImpulse);
\r
557 hinge->setAngularOnly(hingeData->m_angularOnly!=0);
\r
558 hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
\r
561 btHingeConstraintFloatData* hingeData = (btHingeConstraintFloatData*)constraintData;
\r
564 btTransform rbAFrame,rbBFrame;
\r
565 rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
\r
566 rbBFrame.deSerializeFloat(hingeData->m_rbBFrame);
\r
567 hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
\r
570 btTransform rbAFrame;
\r
571 rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
\r
572 hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
\r
574 if (hingeData->m_enableAngularMotor)
\r
576 hinge->enableAngularMotor(true,hingeData->m_motorTargetVelocity,hingeData->m_maxMotorImpulse);
\r
578 hinge->setAngularOnly(hingeData->m_angularOnly!=0);
\r
579 hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
\r
582 constraint = hinge;
\r
586 case CONETWIST_CONSTRAINT_TYPE:
\r
588 btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData;
\r
589 btConeTwistConstraint* coneTwist = 0;
\r
593 btTransform rbAFrame,rbBFrame;
\r
594 rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
\r
595 rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
\r
596 coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
\r
599 btTransform rbAFrame;
\r
600 rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
\r
601 coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
\r
603 coneTwist->setLimit(coneData->m_swingSpan1,coneData->m_swingSpan2,coneData->m_twistSpan,coneData->m_limitSoftness,coneData->m_biasFactor,coneData->m_relaxationFactor);
\r
604 coneTwist->setDamping(coneData->m_damping);
\r
606 constraint = coneTwist;
\r
610 case D6_SPRING_CONSTRAINT_TYPE:
\r
613 btGeneric6DofSpringConstraintData* dofData = (btGeneric6DofSpringConstraintData*)constraintData;
\r
614 // int sz = sizeof(btGeneric6DofSpringConstraintData);
\r
615 btGeneric6DofSpringConstraint* dof = 0;
\r
619 btTransform rbAFrame,rbBFrame;
\r
620 rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame);
\r
621 rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame);
\r
622 dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
\r
625 printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
\r
630 btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
\r
631 angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit);
\r
632 angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit);
\r
633 linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit);
\r
634 linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit);
\r
636 angLowerLimit.setW(0.f);
\r
637 dof->setAngularLowerLimit(angLowerLimit);
\r
638 dof->setAngularUpperLimit(angUpperLimit);
\r
639 dof->setLinearLowerLimit(linLowerLimit);
\r
640 dof->setLinearUpperLimit(linUpperlimit);
\r
643 if (fileVersion>280)
\r
647 dof->setStiffness(i,dofData->m_springStiffness[i]);
\r
648 dof->setEquilibriumPoint(i,dofData->m_equilibriumPoint[i]);
\r
649 dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
\r
650 dof->setDamping(i,dofData->m_springDamping[i]);
\r
658 case D6_CONSTRAINT_TYPE:
\r
660 btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData;
\r
661 btGeneric6DofConstraint* dof = 0;
\r
665 btTransform rbAFrame,rbBFrame;
\r
666 rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
\r
667 rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
\r
668 dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
\r
673 btTransform rbBFrame;
\r
674 rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
\r
675 dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
\r
678 printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
\r
684 btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
\r
685 angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
\r
686 angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit);
\r
687 linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit);
\r
688 linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit);
\r
690 dof->setAngularLowerLimit(angLowerLimit);
\r
691 dof->setAngularUpperLimit(angUpperLimit);
\r
692 dof->setLinearLowerLimit(linLowerLimit);
\r
693 dof->setLinearUpperLimit(linUpperlimit);
\r
699 case SLIDER_CONSTRAINT_TYPE:
\r
701 btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData;
\r
702 btSliderConstraint* slider = 0;
\r
705 btTransform rbAFrame,rbBFrame;
\r
706 rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
\r
707 rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
\r
708 slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
\r
711 btTransform rbBFrame;
\r
712 rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
\r
713 slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
\r
715 slider->setLowerLinLimit(sliderData->m_linearLowerLimit);
\r
716 slider->setUpperLinLimit(sliderData->m_linearUpperLimit);
\r
717 slider->setLowerAngLimit(sliderData->m_angularLowerLimit);
\r
718 slider->setUpperAngLimit(sliderData->m_angularUpperLimit);
\r
719 slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
\r
720 constraint = slider;
\r
726 printf("unknown constraint type\n");
\r
732 constraint->setDbgDrawSize(constraintData->m_dbgDrawSize);
\r
733 ///those fields didn't exist and set to zero for pre-280 versions, so do a check here
\r
734 if (fileVersion>=280)
\r
736 constraint->setBreakingImpulseThreshold(constraintData->m_breakingImpulseThreshold);
\r
737 constraint->setEnabled(constraintData->m_isEnabled!=0);
\r
738 constraint->setOverrideNumSolverIterations(constraintData->m_overrideNumSolverIterations);
\r
741 if (constraintData->m_name)
\r
743 char* newname = duplicateName(constraintData->m_name);
\r
744 m_nameConstraintMap.insert(newname,constraint);
\r
745 m_objectNameMap.insert(constraint,newname);
\r
747 if(m_dynamicsWorld)
\r
748 m_dynamicsWorld->addConstraint(constraint,constraintData->m_disableCollisionsBetweenLinkedBodies!=0);
\r
764 btTriangleIndexVertexArray* btWorldImporter::createMeshInterface(btStridingMeshInterfaceData& meshData)
\r
766 btTriangleIndexVertexArray* meshInterface = createTriangleMeshContainer();
\r
768 for (int i=0;i<meshData.m_numMeshParts;i++)
\r
770 btIndexedMesh meshPart;
\r
771 meshPart.m_numTriangles = meshData.m_meshPartsPtr[i].m_numTriangles;
\r
772 meshPart.m_numVertices = meshData.m_meshPartsPtr[i].m_numVertices;
\r
775 if (meshData.m_meshPartsPtr[i].m_indices32)
\r
777 meshPart.m_indexType = PHY_INTEGER;
\r
778 meshPart.m_triangleIndexStride = 3*sizeof(int);
\r
779 int* indexArray = (int*)btAlignedAlloc(sizeof(int)*3*meshPart.m_numTriangles,16);
\r
780 m_indexArrays.push_back(indexArray);
\r
781 for (int j=0;j<3*meshPart.m_numTriangles;j++)
\r
783 indexArray[j] = meshData.m_meshPartsPtr[i].m_indices32[j].m_value;
\r
785 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
\r
788 if (meshData.m_meshPartsPtr[i].m_3indices16)
\r
790 meshPart.m_indexType = PHY_SHORT;
\r
791 meshPart.m_triangleIndexStride = sizeof(short int)*3;//sizeof(btShortIntIndexTripletData);
\r
793 short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
\r
794 m_shortIndexArrays.push_back(indexArray);
\r
796 for (int j=0;j<meshPart.m_numTriangles;j++)
\r
798 indexArray[3*j] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[0];
\r
799 indexArray[3*j+1] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[1];
\r
800 indexArray[3*j+2] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[2];
\r
803 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
\r
805 if (meshData.m_meshPartsPtr[i].m_indices16)
\r
807 meshPart.m_indexType = PHY_SHORT;
\r
808 meshPart.m_triangleIndexStride = 3*sizeof(short int);
\r
809 short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
\r
810 m_shortIndexArrays.push_back(indexArray);
\r
811 for (int j=0;j<3*meshPart.m_numTriangles;j++)
\r
813 indexArray[j] = meshData.m_meshPartsPtr[i].m_indices16[j].m_value;
\r
816 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
\r
819 if (meshData.m_meshPartsPtr[i].m_3indices8)
\r
821 meshPart.m_indexType = PHY_UCHAR;
\r
822 meshPart.m_triangleIndexStride = sizeof(unsigned char)*3;
\r
824 unsigned char* indexArray = (unsigned char*)btAlignedAlloc(sizeof(unsigned char)*3*meshPart.m_numTriangles,16);
\r
825 m_charIndexArrays.push_back(indexArray);
\r
827 for (int j=0;j<meshPart.m_numTriangles;j++)
\r
829 indexArray[3*j] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[0];
\r
830 indexArray[3*j+1] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[1];
\r
831 indexArray[3*j+2] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[2];
\r
834 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
\r
838 if (meshData.m_meshPartsPtr[i].m_vertices3f)
\r
840 meshPart.m_vertexType = PHY_FLOAT;
\r
841 meshPart.m_vertexStride = sizeof(btVector3FloatData);
\r
842 btVector3FloatData* vertices = (btVector3FloatData*) btAlignedAlloc(sizeof(btVector3FloatData)*meshPart.m_numVertices,16);
\r
843 m_floatVertexArrays.push_back(vertices);
\r
845 for (int j=0;j<meshPart.m_numVertices;j++)
\r
847 vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[0];
\r
848 vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[1];
\r
849 vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[2];
\r
850 vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[3];
\r
852 meshPart.m_vertexBase = (const unsigned char*)vertices;
\r
855 meshPart.m_vertexType = PHY_DOUBLE;
\r
856 meshPart.m_vertexStride = sizeof(btVector3DoubleData);
\r
859 btVector3DoubleData* vertices = (btVector3DoubleData*) btAlignedAlloc(sizeof(btVector3DoubleData)*meshPart.m_numVertices,16);
\r
860 m_doubleVertexArrays.push_back(vertices);
\r
862 for (int j=0;j<meshPart.m_numVertices;j++)
\r
864 vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[0];
\r
865 vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[1];
\r
866 vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[2];
\r
867 vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[3];
\r
869 meshPart.m_vertexBase = (const unsigned char*)vertices;
\r
872 if (meshPart.m_triangleIndexBase && meshPart.m_vertexBase)
\r
874 meshInterface->addIndexedMesh(meshPart,meshPart.m_indexType);
\r
878 return meshInterface;
\r
882 btStridingMeshInterfaceData* btWorldImporter::createStridingMeshInterfaceData(btStridingMeshInterfaceData* interfaceData)
\r
884 //create a new btStridingMeshInterfaceData that is an exact copy of shapedata and store it in the WorldImporter
\r
885 btStridingMeshInterfaceData* newData = new btStridingMeshInterfaceData;
\r
887 newData->m_scaling = interfaceData->m_scaling;
\r
888 newData->m_numMeshParts = interfaceData->m_numMeshParts;
\r
889 newData->m_meshPartsPtr = new btMeshPartData[newData->m_numMeshParts];
\r
891 for(int i = 0;i < newData->m_numMeshParts;i++)
\r
893 btMeshPartData* curPart = &interfaceData->m_meshPartsPtr[i];
\r
894 btMeshPartData* curNewPart = &newData->m_meshPartsPtr[i];
\r
896 curNewPart->m_numTriangles = curPart->m_numTriangles;
\r
897 curNewPart->m_numVertices = curPart->m_numVertices;
\r
899 if(curPart->m_vertices3f)
\r
901 curNewPart->m_vertices3f = new btVector3FloatData[curNewPart->m_numVertices];
\r
902 memcpy(curNewPart->m_vertices3f,curPart->m_vertices3f,sizeof(btVector3FloatData) * curNewPart->m_numVertices);
\r
905 curNewPart->m_vertices3f = NULL;
\r
907 if(curPart->m_vertices3d)
\r
909 curNewPart->m_vertices3d = new btVector3DoubleData[curNewPart->m_numVertices];
\r
910 memcpy(curNewPart->m_vertices3d,curPart->m_vertices3d,sizeof(btVector3DoubleData) * curNewPart->m_numVertices);
\r
913 curNewPart->m_vertices3d = NULL;
\r
915 int numIndices = curNewPart->m_numTriangles * 3;
\r
916 ///the m_3indices8 was not initialized in some Bullet versions, this can cause crashes at loading time
\r
917 ///we catch it by only dealing with m_3indices8 if none of the other indices are initialized
\r
918 bool uninitialized3indices8Workaround =false;
\r
920 if(curPart->m_indices32)
\r
922 uninitialized3indices8Workaround=true;
\r
923 curNewPart->m_indices32 = new btIntIndexData[numIndices];
\r
924 memcpy(curNewPart->m_indices32,curPart->m_indices32,sizeof(btIntIndexData) * numIndices);
\r
927 curNewPart->m_indices32 = NULL;
\r
929 if(curPart->m_3indices16)
\r
931 uninitialized3indices8Workaround=true;
\r
932 curNewPart->m_3indices16 = new btShortIntIndexTripletData[curNewPart->m_numTriangles];
\r
933 memcpy(curNewPart->m_3indices16,curPart->m_3indices16,sizeof(btShortIntIndexTripletData) * curNewPart->m_numTriangles);
\r
936 curNewPart->m_3indices16 = NULL;
\r
938 if(curPart->m_indices16)
\r
940 uninitialized3indices8Workaround=true;
\r
941 curNewPart->m_indices16 = new btShortIntIndexData[numIndices];
\r
942 memcpy(curNewPart->m_indices16,curPart->m_indices16,sizeof(btShortIntIndexData) * numIndices);
\r
945 curNewPart->m_indices16 = NULL;
\r
947 if(!uninitialized3indices8Workaround && curPart->m_3indices8)
\r
949 curNewPart->m_3indices8 = new btCharIndexTripletData[curNewPart->m_numTriangles];
\r
950 memcpy(curNewPart->m_3indices8,curPart->m_3indices8,sizeof(btCharIndexTripletData) * curNewPart->m_numTriangles);
\r
953 curNewPart->m_3indices8 = NULL;
\r
957 m_allocatedbtStridingMeshInterfaceDatas.push_back(newData);
\r
962 #ifdef USE_INTERNAL_EDGE_UTILITY
\r
963 extern ContactAddedCallback gContactAddedCallback;
\r
965 static bool btAdjustInternalEdgeContactsCallback(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
\r
968 btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1);
\r
969 //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_BACKFACE_MODE);
\r
970 //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_DOUBLE_SIDED+BT_TRIANGLE_CONCAVE_DOUBLE_SIDED);
\r
973 #endif //USE_INTERNAL_EDGE_UTILITY
\r
978 btCollisionObject* btWorldImporter::createCollisionObject(const btTransform& startTransform,btCollisionShape* shape, const char* bodyName)
\r
980 return createRigidBody(false,0,startTransform,shape,bodyName);
\r
983 void btWorldImporter::setDynamicsWorldInfo(const btVector3& gravity, const btContactSolverInfo& solverInfo)
\r
985 if (m_dynamicsWorld)
\r
987 m_dynamicsWorld->setGravity(gravity);
\r
988 m_dynamicsWorld->getSolverInfo() = solverInfo;
\r
993 btRigidBody* btWorldImporter::createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform,btCollisionShape* shape,const char* bodyName)
\r
995 btVector3 localInertia;
\r
996 localInertia.setZero();
\r
999 shape->calculateLocalInertia(mass,localInertia);
\r
1001 btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
\r
1002 body->setWorldTransform(startTransform);
\r
1004 if (m_dynamicsWorld)
\r
1005 m_dynamicsWorld->addRigidBody(body);
\r
1009 char* newname = duplicateName(bodyName);
\r
1010 m_objectNameMap.insert(body,newname);
\r
1011 m_nameBodyMap.insert(newname,body);
\r
1013 m_allocatedRigidBodies.push_back(body);
\r
1018 btCollisionShape* btWorldImporter::createPlaneShape(const btVector3& planeNormal,btScalar planeConstant)
\r
1020 btStaticPlaneShape* shape = new btStaticPlaneShape(planeNormal,planeConstant);
\r
1021 m_allocatedCollisionShapes.push_back(shape);
\r
1024 btCollisionShape* btWorldImporter::createBoxShape(const btVector3& halfExtents)
\r
1026 btBoxShape* shape = new btBoxShape(halfExtents);
\r
1027 m_allocatedCollisionShapes.push_back(shape);
\r
1030 btCollisionShape* btWorldImporter::createSphereShape(btScalar radius)
\r
1032 btSphereShape* shape = new btSphereShape(radius);
\r
1033 m_allocatedCollisionShapes.push_back(shape);
\r
1038 btCollisionShape* btWorldImporter::createCapsuleShapeX(btScalar radius, btScalar height)
\r
1040 btCapsuleShapeX* shape = new btCapsuleShapeX(radius,height);
\r
1041 m_allocatedCollisionShapes.push_back(shape);
\r
1045 btCollisionShape* btWorldImporter::createCapsuleShapeY(btScalar radius, btScalar height)
\r
1047 btCapsuleShape* shape = new btCapsuleShape(radius,height);
\r
1048 m_allocatedCollisionShapes.push_back(shape);
\r
1052 btCollisionShape* btWorldImporter::createCapsuleShapeZ(btScalar radius, btScalar height)
\r
1054 btCapsuleShapeZ* shape = new btCapsuleShapeZ(radius,height);
\r
1055 m_allocatedCollisionShapes.push_back(shape);
\r
1059 btCollisionShape* btWorldImporter::createCylinderShapeX(btScalar radius,btScalar height)
\r
1061 btCylinderShapeX* shape = new btCylinderShapeX(btVector3(height,radius,radius));
\r
1062 m_allocatedCollisionShapes.push_back(shape);
\r
1066 btCollisionShape* btWorldImporter::createCylinderShapeY(btScalar radius,btScalar height)
\r
1068 btCylinderShape* shape = new btCylinderShape(btVector3(radius,height,radius));
\r
1069 m_allocatedCollisionShapes.push_back(shape);
\r
1073 btCollisionShape* btWorldImporter::createCylinderShapeZ(btScalar radius,btScalar height)
\r
1075 btCylinderShapeZ* shape = new btCylinderShapeZ(btVector3(radius,radius,height));
\r
1076 m_allocatedCollisionShapes.push_back(shape);
\r
1080 btTriangleIndexVertexArray* btWorldImporter::createTriangleMeshContainer()
\r
1082 btTriangleIndexVertexArray* in = new btTriangleIndexVertexArray();
\r
1083 m_allocatedTriangleIndexArrays.push_back(in);
\r
1087 btOptimizedBvh* btWorldImporter::createOptimizedBvh()
\r
1089 btOptimizedBvh* bvh = new btOptimizedBvh();
\r
1090 m_allocatedBvhs.push_back(bvh);
\r
1095 btTriangleInfoMap* btWorldImporter::createTriangleInfoMap()
\r
1097 btTriangleInfoMap* tim = new btTriangleInfoMap();
\r
1098 m_allocatedTriangleInfoMaps.push_back(tim);
\r
1102 btBvhTriangleMeshShape* btWorldImporter::createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh)
\r
1106 btBvhTriangleMeshShape* bvhTriMesh = new btBvhTriangleMeshShape(trimesh,bvh->isQuantized(), false);
\r
1107 bvhTriMesh->setOptimizedBvh(bvh);
\r
1108 m_allocatedCollisionShapes.push_back(bvhTriMesh);
\r
1109 return bvhTriMesh;
\r
1112 btBvhTriangleMeshShape* ts = new btBvhTriangleMeshShape(trimesh,true);
\r
1113 m_allocatedCollisionShapes.push_back(ts);
\r
1117 btCollisionShape* btWorldImporter::createConvexTriangleMeshShape(btStridingMeshInterface* trimesh)
\r
1121 btGImpactMeshShape* btWorldImporter::createGimpactShape(btStridingMeshInterface* trimesh)
\r
1123 btGImpactMeshShape* shape = new btGImpactMeshShape(trimesh);
\r
1124 m_allocatedCollisionShapes.push_back(shape);
\r
1128 btConvexHullShape* btWorldImporter::createConvexHullShape()
\r
1130 btConvexHullShape* shape = new btConvexHullShape();
\r
1131 m_allocatedCollisionShapes.push_back(shape);
\r
1135 btCompoundShape* btWorldImporter::createCompoundShape()
\r
1137 btCompoundShape* shape = new btCompoundShape();
\r
1138 m_allocatedCollisionShapes.push_back(shape);
\r
1143 btScaledBvhTriangleMeshShape* btWorldImporter::createScaledTrangleMeshShape(btBvhTriangleMeshShape* meshShape,const btVector3& localScaling)
\r
1145 btScaledBvhTriangleMeshShape* shape = new btScaledBvhTriangleMeshShape(meshShape,localScaling);
\r
1146 m_allocatedCollisionShapes.push_back(shape);
\r
1150 btMultiSphereShape* btWorldImporter::createMultiSphereShape(const btVector3* positions,const btScalar* radi,int numSpheres)
\r
1152 btMultiSphereShape* shape = new btMultiSphereShape(positions, radi, numSpheres);
\r
1153 m_allocatedCollisionShapes.push_back(shape);
\r
1157 btRigidBody& btWorldImporter::getFixedBody()
\r
1159 static btRigidBody s_fixed(0, 0,0);
\r
1160 s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));
\r
1164 btPoint2PointConstraint* btWorldImporter::createPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB)
\r
1166 btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,rbB,pivotInA,pivotInB);
\r
1167 m_allocatedConstraints.push_back(p2p);
\r
1171 btPoint2PointConstraint* btWorldImporter::createPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA)
\r
1173 btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,pivotInA);
\r
1174 m_allocatedConstraints.push_back(p2p);
\r
1179 btHingeConstraint* btWorldImporter::createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA)
\r
1181 btHingeConstraint* hinge = new btHingeConstraint(rbA,rbB,rbAFrame,rbBFrame,useReferenceFrameA);
\r
1182 m_allocatedConstraints.push_back(hinge);
\r
1186 btHingeConstraint* btWorldImporter::createHingeConstraint(btRigidBody& rbA,const btTransform& rbAFrame, bool useReferenceFrameA)
\r
1188 btHingeConstraint* hinge = new btHingeConstraint(rbA,rbAFrame,useReferenceFrameA);
\r
1189 m_allocatedConstraints.push_back(hinge);
\r
1193 btConeTwistConstraint* btWorldImporter::createConeTwistConstraint(btRigidBody& rbA,btRigidBody& rbB,const btTransform& rbAFrame, const btTransform& rbBFrame)
\r
1195 btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbB,rbAFrame,rbBFrame);
\r
1196 m_allocatedConstraints.push_back(cone);
\r
1200 btConeTwistConstraint* btWorldImporter::createConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame)
\r
1202 btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbAFrame);
\r
1203 m_allocatedConstraints.push_back(cone);
\r
1208 btGeneric6DofConstraint* btWorldImporter::createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA)
\r
1210 btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
\r
1211 m_allocatedConstraints.push_back(dof);
\r
1215 btGeneric6DofConstraint* btWorldImporter::createGeneric6DofConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB)
\r
1217 btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbB,frameInB,useLinearReferenceFrameB);
\r
1218 m_allocatedConstraints.push_back(dof);
\r
1222 btGeneric6DofSpringConstraint* btWorldImporter::createGeneric6DofSpringConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA)
\r
1224 btGeneric6DofSpringConstraint* dof = new btGeneric6DofSpringConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
\r
1225 m_allocatedConstraints.push_back(dof);
\r
1230 btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA)
\r
1232 btSliderConstraint* slider = new btSliderConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
\r
1233 m_allocatedConstraints.push_back(slider);
\r
1237 btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA)
\r
1239 btSliderConstraint* slider = new btSliderConstraint(rbB,frameInB,useLinearReferenceFrameA);
\r
1240 m_allocatedConstraints.push_back(slider);
\r
1246 int btWorldImporter::getNumCollisionShapes() const
\r
1248 return m_allocatedCollisionShapes.size();
\r
1251 btCollisionShape* btWorldImporter::getCollisionShapeByIndex(int index)
\r
1253 return m_allocatedCollisionShapes[index];
\r
1256 btCollisionShape* btWorldImporter::getCollisionShapeByName(const char* name)
\r
1258 btCollisionShape** shapePtr = m_nameShapeMap.find(name);
\r
1259 if (shapePtr&& *shapePtr)
\r
1266 btRigidBody* btWorldImporter::getRigidBodyByName(const char* name)
\r
1268 btRigidBody** bodyPtr = m_nameBodyMap.find(name);
\r
1269 if (bodyPtr && *bodyPtr)
\r
1276 btTypedConstraint* btWorldImporter::getConstraintByName(const char* name)
\r
1278 btTypedConstraint** constraintPtr = m_nameConstraintMap.find(name);
\r
1279 if (constraintPtr && *constraintPtr)
\r
1281 return *constraintPtr;
\r
1286 const char* btWorldImporter::getNameForPointer(const void* ptr) const
\r
1288 const char*const * namePtr = m_objectNameMap.find(ptr);
\r
1289 if (namePtr && *namePtr)
\r
1295 int btWorldImporter::getNumRigidBodies() const
\r
1297 return m_allocatedRigidBodies.size();
\r
1300 btCollisionObject* btWorldImporter::getRigidBodyByIndex(int index) const
\r
1302 return m_allocatedRigidBodies[index];
\r
1304 int btWorldImporter::getNumConstraints() const
\r
1306 return m_allocatedConstraints.size();
\r
1309 btTypedConstraint* btWorldImporter::getConstraintByIndex(int index) const
\r
1311 return m_allocatedConstraints[index];
\r
1314 int btWorldImporter::getNumBvhs() const
\r
1316 return m_allocatedBvhs.size();
\r
1318 btOptimizedBvh* btWorldImporter::getBvhByIndex(int index) const
\r
1320 return m_allocatedBvhs[index];
\r
1323 int btWorldImporter::getNumTriangleInfoMaps() const
\r
1325 return m_allocatedTriangleInfoMaps.size();
\r
1328 btTriangleInfoMap* btWorldImporter::getTriangleInfoMapByIndex(int index) const
\r
1330 return m_allocatedTriangleInfoMaps[index];
\r
1334 void btWorldImporter::convertRigidBodyFloat( btRigidBodyFloatData* colObjData)
\r
1336 btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f);
\r
1337 btVector3 localInertia;
\r
1338 localInertia.setZero();
\r
1339 btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionObjectData.m_collisionShape);
\r
1340 if (shapePtr && *shapePtr)
\r
1342 btTransform startTransform;
\r
1343 colObjData->m_collisionObjectData.m_worldTransform.m_origin.m_floats[3] = 0.f;
\r
1344 startTransform.deSerializeFloat(colObjData->m_collisionObjectData.m_worldTransform);
\r
1346 // startTransform.setBasis(btMatrix3x3::getIdentity());
\r
1347 btCollisionShape* shape = (btCollisionShape*)*shapePtr;
\r
1348 if (shape->isNonMoving())
\r
1354 shape->calculateLocalInertia(mass,localInertia);
\r
1356 bool isDynamic = mass!=0.f;
\r
1357 btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name);
\r
1358 body->setFriction(colObjData->m_collisionObjectData.m_friction);
\r
1359 body->setRestitution(colObjData->m_collisionObjectData.m_restitution);
\r
1362 #ifdef USE_INTERNAL_EDGE_UTILITY
\r
1363 if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
\r
1365 btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape;
\r
1366 if (trimesh->getTriangleInfoMap())
\r
1368 body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
\r
1371 #endif //USE_INTERNAL_EDGE_UTILITY
\r
1372 m_bodyMap.insert(colObjData,body);
\r
1375 printf("error: no shape found\n");
\r
1379 void btWorldImporter::convertRigidBodyDouble( btRigidBodyDoubleData* colObjData)
\r
1381 btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f);
\r
1382 btVector3 localInertia;
\r
1383 localInertia.setZero();
\r
1384 btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionObjectData.m_collisionShape);
\r
1385 if (shapePtr && *shapePtr)
\r
1387 btTransform startTransform;
\r
1388 colObjData->m_collisionObjectData.m_worldTransform.m_origin.m_floats[3] = 0.f;
\r
1389 startTransform.deSerializeDouble(colObjData->m_collisionObjectData.m_worldTransform);
\r
1391 // startTransform.setBasis(btMatrix3x3::getIdentity());
\r
1392 btCollisionShape* shape = (btCollisionShape*)*shapePtr;
\r
1393 if (shape->isNonMoving())
\r
1399 shape->calculateLocalInertia(mass,localInertia);
\r
1401 bool isDynamic = mass!=0.f;
\r
1402 btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name);
\r
1403 body->setFriction(colObjData->m_collisionObjectData.m_friction);
\r
1404 body->setRestitution(colObjData->m_collisionObjectData.m_restitution);
\r
1407 #ifdef USE_INTERNAL_EDGE_UTILITY
\r
1408 if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
\r
1410 btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape;
\r
1411 if (trimesh->getTriangleInfoMap())
\r
1413 body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
\r
1416 #endif //USE_INTERNAL_EDGE_UTILITY
\r
1417 m_bodyMap.insert(colObjData,body);
\r
1420 printf("error: no shape found\n");
\r