Bullet Collision Detection & Physics Library
btWorldImporter.cpp
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #include "btWorldImporter.h"
17 #include "btBulletDynamicsCommon.h"
19 
21 :m_dynamicsWorld(world),
22 m_verboseMode(0)
23 {
24 
25 }
26 
28 {
29 }
30 
32 {
33  int i;
34  for (i=0;i<m_allocatedConstraints.size();i++)
35  {
36  if(m_dynamicsWorld)
38  delete m_allocatedConstraints[i];
39  }
41 
42 
43  for (i=0;i<m_allocatedRigidBodies.size();i++)
44  {
45  if(m_dynamicsWorld)
47  delete m_allocatedRigidBodies[i];
48  }
49 
51 
52 
53  for (i=0;i<m_allocatedCollisionShapes.size();i++)
54  {
56  }
58 
59 
60  for (i=0;i<m_allocatedBvhs.size();i++)
61  {
62  delete m_allocatedBvhs[i];
63  }
65 
66  for (i=0;i<m_allocatedTriangleInfoMaps.size();i++)
67  {
69  }
71  for (i=0;i<m_allocatedTriangleIndexArrays.size();i++)
72  {
74  }
76  for (i=0;i<m_allocatedNames.size();i++)
77  {
78  delete[] m_allocatedNames[i];
79  }
81 
83  {
85 
86  for(int a = 0;a < curData->m_numMeshParts;a++)
87  {
88  btMeshPartData* curPart = &curData->m_meshPartsPtr[a];
89  if(curPart->m_vertices3f)
90  delete [] curPart->m_vertices3f;
91 
92  if(curPart->m_vertices3d)
93  delete [] curPart->m_vertices3d;
94 
95  if(curPart->m_indices32)
96  delete [] curPart->m_indices32;
97 
98  if(curPart->m_3indices16)
99  delete [] curPart->m_3indices16;
100 
101  if(curPart->m_indices16)
102  delete [] curPart->m_indices16;
103 
104  if (curPart->m_3indices8)
105  delete [] curPart->m_3indices8;
106 
107  }
108  delete [] curData->m_meshPartsPtr;
109  delete curData;
110  }
112 
113  for (i=0;i<m_indexArrays.size();i++)
114  {
116  }
118 
119  for (i=0;i<m_shortIndexArrays.size();i++)
120  {
122  }
124 
125  for (i=0;i<m_charIndexArrays.size();i++)
126  {
128  }
130 
131  for (i=0;i<m_floatVertexArrays.size();i++)
132  {
134  }
136 
137  for (i=0;i<m_doubleVertexArrays.size();i++)
138  {
140  }
142 
143 
144 }
145 
146 
147 
149 {
150  btCollisionShape* shape = 0;
151 
152  switch (shapeData->m_shapeType)
153  {
155  {
156  btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*)shapeData;
157  btVector3 planeNormal,localScaling;
158  planeNormal.deSerializeFloat(planeData->m_planeNormal);
159  localScaling.deSerializeFloat(planeData->m_localScaling);
160  shape = createPlaneShape(planeNormal,planeData->m_planeConstant);
161  shape->setLocalScaling(localScaling);
162 
163  break;
164  }
166  {
168  btCollisionShapeData* colShapeData = (btCollisionShapeData*) &scaledMesh->m_trimeshShapeData;
170  btCollisionShape* childShape = convertCollisionShape(colShapeData);
171  btBvhTriangleMeshShape* meshShape = (btBvhTriangleMeshShape*)childShape;
172  btVector3 localScaling;
173  localScaling.deSerializeFloat(scaledMesh->m_localScaling);
174 
175  shape = createScaledTrangleMeshShape(meshShape, localScaling);
176  break;
177  }
179  {
180  btGImpactMeshShapeData* gimpactData = (btGImpactMeshShapeData*) shapeData;
181  if (gimpactData->m_gimpactSubType == CONST_GIMPACT_TRIMESH_SHAPE)
182  {
184  btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
185 
186 
187  btGImpactMeshShape* gimpactShape = createGimpactShape(meshInterface);
188  btVector3 localScaling;
189  localScaling.deSerializeFloat(gimpactData->m_localScaling);
190  gimpactShape->setLocalScaling(localScaling);
191  gimpactShape->setMargin(btScalar(gimpactData->m_collisionMargin));
192  gimpactShape->updateBound();
193  shape = gimpactShape;
194  } else
195  {
196  printf("unsupported gimpact sub type\n");
197  }
198  break;
199  }
200  //The btCapsuleShape* API has issue passing the margin/scaling/halfextents unmodified through the API
201  //so deal with this
203  {
204  btCapsuleShapeData* capData = (btCapsuleShapeData*)shapeData;
205 
206 
207  switch (capData->m_upAxis)
208  {
209  case 0:
210  {
211  shape = createCapsuleShapeX(1,1);
212  break;
213  }
214  case 1:
215  {
216  shape = createCapsuleShapeY(1,1);
217  break;
218  }
219  case 2:
220  {
221  shape = createCapsuleShapeZ(1,1);
222  break;
223  }
224  default:
225  {
226  printf("error: wrong up axis for btCapsuleShape\n");
227  }
228 
229 
230  };
231  if (shape)
232  {
233  btCapsuleShape* cap = (btCapsuleShape*) shape;
234  cap->deSerializeFloat(capData);
235  }
236  break;
237  }
240  case BOX_SHAPE_PROXYTYPE:
244  {
246  btVector3 implicitShapeDimensions;
247  implicitShapeDimensions.deSerializeFloat(bsd->m_implicitShapeDimensions);
248  btVector3 localScaling;
249  localScaling.deSerializeFloat(bsd->m_localScaling);
251  switch (shapeData->m_shapeType)
252  {
253  case BOX_SHAPE_PROXYTYPE:
254  {
255  btBoxShape* box= (btBoxShape*)createBoxShape(implicitShapeDimensions/localScaling+margin);
256  //box->initializePolyhedralFeatures();
257  shape = box;
258 
259  break;
260  }
262  {
263  shape = createSphereShape(implicitShapeDimensions.getX());
264  break;
265  }
266 
268  {
269  btCylinderShapeData* cylData = (btCylinderShapeData*) shapeData;
270  btVector3 halfExtents = implicitShapeDimensions+margin;
271  switch (cylData->m_upAxis)
272  {
273  case 0:
274  {
275  shape = createCylinderShapeX(halfExtents.getY(),halfExtents.getX());
276  break;
277  }
278  case 1:
279  {
280  shape = createCylinderShapeY(halfExtents.getX(),halfExtents.getY());
281  break;
282  }
283  case 2:
284  {
285  shape = createCylinderShapeZ(halfExtents.getX(),halfExtents.getZ());
286  break;
287  }
288  default:
289  {
290  printf("unknown Cylinder up axis\n");
291  }
292 
293  };
294 
295 
296 
297  break;
298  }
300  {
301  btConeShapeData* conData = (btConeShapeData*) shapeData;
302  btVector3 halfExtents = implicitShapeDimensions;//+margin;
303  switch (conData->m_upIndex)
304  {
305  case 0:
306  {
307  shape = createConeShapeX(halfExtents.getY(),halfExtents.getX());
308  break;
309  }
310  case 1:
311  {
312  shape = createConeShapeY(halfExtents.getX(),halfExtents.getY());
313  break;
314  }
315  case 2:
316  {
317  shape = createConeShapeZ(halfExtents.getX(),halfExtents.getZ());
318  break;
319  }
320  default:
321  {
322  printf("unknown Cone up axis\n");
323  }
324 
325  };
326 
327 
328 
329  break;
330  }
332  {
334  int numSpheres = mss->m_localPositionArraySize;
335 
338  radii.resize(numSpheres);
339  tmpPos.resize(numSpheres);
340  int i;
341  for ( i=0;i<numSpheres;i++)
342  {
343  tmpPos[i].deSerializeFloat(mss->m_localPositionArrayPtr[i].m_pos);
344  radii[i] = mss->m_localPositionArrayPtr[i].m_radius;
345  }
346  shape = createMultiSphereShape(&tmpPos[0],&radii[0],numSpheres);
347  break;
348  }
350  {
351  // int sz = sizeof(btConvexHullShapeData);
352  // int sz2 = sizeof(btConvexInternalShapeData);
353  // int sz3 = sizeof(btCollisionShapeData);
354  btConvexHullShapeData* convexData = (btConvexHullShapeData*)bsd;
355  int numPoints = convexData->m_numUnscaledPoints;
356 
358  tmpPoints.resize(numPoints);
359  int i;
360  for ( i=0;i<numPoints;i++)
361  {
362 #ifdef BT_USE_DOUBLE_PRECISION
363  if (convexData->m_unscaledPointsDoublePtr)
364  tmpPoints[i].deSerialize(convexData->m_unscaledPointsDoublePtr[i]);
365  if (convexData->m_unscaledPointsFloatPtr)
366  tmpPoints[i].deSerializeFloat(convexData->m_unscaledPointsFloatPtr[i]);
367 #else
368  if (convexData->m_unscaledPointsFloatPtr)
369  tmpPoints[i].deSerialize(convexData->m_unscaledPointsFloatPtr[i]);
370  if (convexData->m_unscaledPointsDoublePtr)
371  tmpPoints[i].deSerializeDouble(convexData->m_unscaledPointsDoublePtr[i]);
372 #endif //BT_USE_DOUBLE_PRECISION
373  }
375  for (i=0;i<numPoints;i++)
376  {
377  hullShape->addPoint(tmpPoints[i]);
378  }
379  hullShape->setMargin(bsd->m_collisionMargin);
380  //hullShape->initializePolyhedralFeatures();
381  shape = hullShape;
382  break;
383  }
384  default:
385  {
386  printf("error: cannot create shape type (%d)\n",shapeData->m_shapeType);
387  }
388  }
389 
390  if (shape)
391  {
392  shape->setMargin(bsd->m_collisionMargin);
393 
394  btVector3 localScaling;
395  localScaling.deSerializeFloat(bsd->m_localScaling);
396  shape->setLocalScaling(localScaling);
397 
398  }
399  break;
400  }
402  {
403  btTriangleMeshShapeData* trimesh = (btTriangleMeshShapeData*)shapeData;
405  btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
406  if (!meshInterface->getNumSubParts())
407  {
408  return 0;
409  }
410 
411  btVector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling);
412  meshInterface->setScaling(scaling);
413 
414 
415  btOptimizedBvh* bvh = 0;
416 #if 1
417  if (trimesh->m_quantizedFloatBvh)
418  {
419  btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedFloatBvh);
420  if (bvhPtr && *bvhPtr)
421  {
422  bvh = *bvhPtr;
423  } else
424  {
425  bvh = createOptimizedBvh();
426  bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh);
427  }
428  }
429  if (trimesh->m_quantizedDoubleBvh)
430  {
431  btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedDoubleBvh);
432  if (bvhPtr && *bvhPtr)
433  {
434  bvh = *bvhPtr;
435  } else
436  {
437  bvh = createOptimizedBvh();
438  bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh);
439  }
440  }
441 #endif
442 
443 
444  btBvhTriangleMeshShape* trimeshShape = createBvhTriangleMeshShape(meshInterface,bvh);
445  trimeshShape->setMargin(trimesh->m_collisionMargin);
446  shape = trimeshShape;
447 
448  if (trimesh->m_triangleInfoMap)
449  {
451  map->deSerialize(*trimesh->m_triangleInfoMap);
452  trimeshShape->setTriangleInfoMap(map);
453 
454 #ifdef USE_INTERNAL_EDGE_UTILITY
455  gContactAddedCallback = btAdjustInternalEdgeContactsCallback;
456 #endif //USE_INTERNAL_EDGE_UTILITY
457 
458  }
459 
460  //printf("trimesh->m_collisionMargin=%f\n",trimesh->m_collisionMargin);
461  break;
462  }
464  {
465  btCompoundShapeData* compoundData = (btCompoundShapeData*)shapeData;
466  btCompoundShape* compoundShape = createCompoundShape();
467 
468  btCompoundShapeChildData* childShapeDataArray = &compoundData->m_childShapePtr[0];
469 
470 
472  for (int i=0;i<compoundData->m_numChildShapes;i++)
473  {
474  btCompoundShapeChildData* ptr = &compoundData->m_childShapePtr[i];
475 
476  btCollisionShapeData* cd = compoundData->m_childShapePtr[i].m_childShape;
477 
478  btCollisionShape* childShape = convertCollisionShape(cd);
479  if (childShape)
480  {
481  btTransform localTransform;
482  localTransform.deSerializeFloat(compoundData->m_childShapePtr[i].m_transform);
483  compoundShape->addChildShape(localTransform,childShape);
484  } else
485  {
486 #ifdef _DEBUG
487  printf("error: couldn't create childShape for compoundShape\n");
488 #endif
489  }
490 
491  }
492  shape = compoundShape;
493 
494  break;
495  }
497  {
498  return 0;
499  }
500  default:
501  {
502 #ifdef _DEBUG
503  printf("unsupported shape type (%d)\n",shapeData->m_shapeType);
504 #endif
505  }
506  }
507 
508  return shape;
509 
510 }
511 
512 
513 
514 char* btWorldImporter::duplicateName(const char* name)
515 {
516  if (name)
517  {
518  int l = (int)strlen(name);
519  char* newName = new char[l+1];
520  memcpy(newName,name,l);
521  newName[l] = 0;
522  m_allocatedNames.push_back(newName);
523  return newName;
524  }
525  return 0;
526 }
527 
529 {
530 
531  btTypedConstraint* constraint = 0;
532 
533  switch (constraintData->m_objectType)
534  {
536  {
538  if (rbA && rbB)
539  {
540  btVector3 pivotInA,pivotInB;
541  pivotInA.deSerializeDouble(p2pData->m_pivotInA);
542  pivotInB.deSerializeDouble(p2pData->m_pivotInB);
543  constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
544  } else
545  {
546  btVector3 pivotInA;
547  pivotInA.deSerializeDouble(p2pData->m_pivotInA);
548  constraint = createPoint2PointConstraint(*rbA,pivotInA);
549  }
550  break;
551  }
553  {
554  btHingeConstraint* hinge = 0;
555 
556  btHingeConstraintDoubleData* hingeData = (btHingeConstraintDoubleData*)constraintData;
557  if (rbA&& rbB)
558  {
559  btTransform rbAFrame,rbBFrame;
560  rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
561  rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
562  hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
563  } else
564  {
565  btTransform rbAFrame;
566  rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
567  hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
568  }
569  if (hingeData->m_enableAngularMotor)
570  {
571  hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse);
572  }
573  hinge->setAngularOnly(hingeData->m_angularOnly!=0);
574  hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
575 
576  constraint = hinge;
577  break;
578 
579  }
581  {
582  btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData;
583  btConeTwistConstraint* coneTwist = 0;
584 
585  if (rbA&& rbB)
586  {
587  btTransform rbAFrame,rbBFrame;
588  rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
589  rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
590  coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
591  } else
592  {
593  btTransform rbAFrame;
594  rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
595  coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
596  }
597  coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness,
598  (btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor);
599  coneTwist->setDamping((btScalar)coneData->m_damping);
600 
601  constraint = coneTwist;
602  break;
603  }
604 
606  {
607 
609  // int sz = sizeof(btGeneric6DofSpringConstraintData);
611 
612  if (rbA && rbB)
613  {
614  btTransform rbAFrame,rbBFrame;
615  rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame);
616  rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame);
617  dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
618  } else
619  {
620  printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
621  }
622 
623  if (dof)
624  {
625  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
626  angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit);
627  angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit);
628  linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit);
629  linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit);
630 
631  angLowerLimit.setW(0.f);
632  dof->setAngularLowerLimit(angLowerLimit);
633  dof->setAngularUpperLimit(angUpperLimit);
634  dof->setLinearLowerLimit(linLowerLimit);
635  dof->setLinearUpperLimit(linUpperlimit);
636 
637  int i;
638  if (fileVersion>280)
639  {
640  for (i=0;i<6;i++)
641  {
642  dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]);
643  dof->setEquilibriumPoint(i,(btScalar)dofData->m_equilibriumPoint[i]);
644  dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
645  dof->setDamping(i,(btScalar)dofData->m_springDamping[i]);
646  }
647  }
648  }
649 
650  constraint = dof;
651  break;
652 
653  }
654  case D6_CONSTRAINT_TYPE:
655  {
656  btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData;
657  btGeneric6DofConstraint* dof = 0;
658 
659  if (rbA&& rbB)
660  {
661  btTransform rbAFrame,rbBFrame;
662  rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
663  rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
664  dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
665  } else
666  {
667  if (rbB)
668  {
669  btTransform rbBFrame;
670  rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
671  dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
672  } else
673  {
674  printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
675  }
676  }
677 
678  if (dof)
679  {
680  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
681  angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
682  angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit);
683  linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit);
684  linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit);
685 
686  dof->setAngularLowerLimit(angLowerLimit);
687  dof->setAngularUpperLimit(angUpperLimit);
688  dof->setLinearLowerLimit(linLowerLimit);
689  dof->setLinearUpperLimit(linUpperlimit);
690  }
691 
692  constraint = dof;
693  break;
694  }
696  {
697  btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData;
698  btSliderConstraint* slider = 0;
699  if (rbA&& rbB)
700  {
701  btTransform rbAFrame,rbBFrame;
702  rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
703  rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
704  slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
705  } else
706  {
707  btTransform rbBFrame;
708  rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
709  slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
710  }
711  slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit);
712  slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit);
713  slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit);
714  slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit);
715  slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
716  constraint = slider;
717  break;
718  }
719 
720  default:
721  {
722  printf("unknown constraint type\n");
723  }
724  };
725 
726  if (constraint)
727  {
728  constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize);
730  if (fileVersion>=280)
731  {
733  constraint->setEnabled(constraintData->m_isEnabled!=0);
735  }
736 
737  if (constraintData->m_name)
738  {
739  char* newname = duplicateName(constraintData->m_name);
740  m_nameConstraintMap.insert(newname,constraint);
741  m_objectNameMap.insert(constraint,newname);
742  }
743  if(m_dynamicsWorld)
745  }
746 
747 }
748 
750 {
751  btTypedConstraint* constraint = 0;
752 
753  switch (constraintData->m_objectType)
754  {
756  {
758  if (rbA&& rbB)
759  {
760  btVector3 pivotInA,pivotInB;
761  pivotInA.deSerializeFloat(p2pData->m_pivotInA);
762  pivotInB.deSerializeFloat(p2pData->m_pivotInB);
763  constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
764 
765  } else
766  {
767  btVector3 pivotInA;
768  pivotInA.deSerializeFloat(p2pData->m_pivotInA);
769  constraint = createPoint2PointConstraint(*rbA,pivotInA);
770  }
771  break;
772  }
774  {
775  btHingeConstraint* hinge = 0;
776  btHingeConstraintFloatData* hingeData = (btHingeConstraintFloatData*)constraintData;
777  if (rbA&& rbB)
778  {
779  btTransform rbAFrame,rbBFrame;
780  rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
781  rbBFrame.deSerializeFloat(hingeData->m_rbBFrame);
782  hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
783  } else
784  {
785  btTransform rbAFrame;
786  rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
787  hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
788  }
789  if (hingeData->m_enableAngularMotor)
790  {
791  hinge->enableAngularMotor(true,hingeData->m_motorTargetVelocity,hingeData->m_maxMotorImpulse);
792  }
793  hinge->setAngularOnly(hingeData->m_angularOnly!=0);
794  hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
795 
796  constraint = hinge;
797  break;
798 
799  }
801  {
802  btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData;
803  btConeTwistConstraint* coneTwist = 0;
804 
805  if (rbA&& rbB)
806  {
807  btTransform rbAFrame,rbBFrame;
808  rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
809  rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
810  coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
811  } else
812  {
813  btTransform rbAFrame;
814  rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
815  coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
816  }
817  coneTwist->setLimit(coneData->m_swingSpan1,coneData->m_swingSpan2,coneData->m_twistSpan,coneData->m_limitSoftness,coneData->m_biasFactor,coneData->m_relaxationFactor);
818  coneTwist->setDamping(coneData->m_damping);
819 
820  constraint = coneTwist;
821  break;
822  }
823 
825  {
826 
828  // int sz = sizeof(btGeneric6DofSpringConstraintData);
830 
831  if (rbA && rbB)
832  {
833  btTransform rbAFrame,rbBFrame;
834  rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame);
835  rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame);
836  dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
837  } else
838  {
839  printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
840  }
841 
842  if (dof)
843  {
844  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
845  angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit);
846  angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit);
847  linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit);
848  linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit);
849 
850  angLowerLimit.setW(0.f);
851  dof->setAngularLowerLimit(angLowerLimit);
852  dof->setAngularUpperLimit(angUpperLimit);
853  dof->setLinearLowerLimit(linLowerLimit);
854  dof->setLinearUpperLimit(linUpperlimit);
855 
856  int i;
857  if (fileVersion>280)
858  {
859  for (i=0;i<6;i++)
860  {
861  dof->setStiffness(i,dofData->m_springStiffness[i]);
862  dof->setEquilibriumPoint(i,dofData->m_equilibriumPoint[i]);
863  dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
864  dof->setDamping(i,dofData->m_springDamping[i]);
865  }
866  }
867  }
868 
869  constraint = dof;
870  break;
871  }
872  case D6_CONSTRAINT_TYPE:
873  {
874  btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData;
875  btGeneric6DofConstraint* dof = 0;
876 
877  if (rbA&& rbB)
878  {
879  btTransform rbAFrame,rbBFrame;
880  rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
881  rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
882  dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
883  } else
884  {
885  if (rbB)
886  {
887  btTransform rbBFrame;
888  rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
889  dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
890  } else
891  {
892  printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
893  }
894  }
895 
896  if (dof)
897  {
898  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
899  angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
900  angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit);
901  linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit);
902  linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit);
903 
904  dof->setAngularLowerLimit(angLowerLimit);
905  dof->setAngularUpperLimit(angUpperLimit);
906  dof->setLinearLowerLimit(linLowerLimit);
907  dof->setLinearUpperLimit(linUpperlimit);
908  }
909 
910  constraint = dof;
911  break;
912  }
914  {
915  btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData;
916  btSliderConstraint* slider = 0;
917  if (rbA&& rbB)
918  {
919  btTransform rbAFrame,rbBFrame;
920  rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
921  rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
922  slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
923  } else
924  {
925  btTransform rbBFrame;
926  rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
927  slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
928  }
929  slider->setLowerLinLimit(sliderData->m_linearLowerLimit);
930  slider->setUpperLinLimit(sliderData->m_linearUpperLimit);
931  slider->setLowerAngLimit(sliderData->m_angularLowerLimit);
932  slider->setUpperAngLimit(sliderData->m_angularUpperLimit);
933  slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
934  constraint = slider;
935  break;
936  }
938  {
939  btGearConstraintFloatData* gearData = (btGearConstraintFloatData*) constraintData;
940  btGearConstraint* gear = 0;
941  if (rbA&&rbB)
942  {
943  btVector3 axisInA,axisInB;
944  axisInA.deSerializeFloat(gearData->m_axisInA);
945  axisInB.deSerializeFloat(gearData->m_axisInB);
946  gear = createGearConstraint(*rbA, *rbB, axisInA,axisInB, gearData->m_ratio);
947  } else
948  {
949  btAssert(0);
950  //perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized?
951  //btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio=1.f);
952  }
953  constraint = gear;
954  break;
955  }
957  {
958 
960 
962 
963  if (rbA && rbB)
964  {
965  btTransform rbAFrame,rbBFrame;
966  rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
967  rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
968  dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, dofData->m_rotateOrder);
969  } else
970  {
971  printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
972  }
973 
974  if (dof)
975  {
976  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
977  angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
978  angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit);
979  linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit);
980  linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit);
981 
982  angLowerLimit.setW(0.f);
983  dof->setAngularLowerLimit(angLowerLimit);
984  dof->setAngularUpperLimit(angUpperLimit);
985  dof->setLinearLowerLimit(linLowerLimit);
986  dof->setLinearUpperLimit(linUpperlimit);
987 
988  int i;
989  if (fileVersion>280)
990  {
991  //6-dof: 3 linear followed by 3 angular
992  for (i=0;i<3;i++)
993  {
994  dof->setStiffness(i,dofData->m_linearSpringStiffness.m_floats[i]);
996  dof->enableSpring(i,dofData->m_linearEnableSpring[i]!=0);
997  dof->setDamping(i,dofData->m_linearSpringDamping.m_floats[i]);
998  }
999  for (i=0;i<3;i++)
1000  {
1001  dof->setStiffness(i+3,dofData->m_angularSpringStiffness.m_floats[i]);
1003  dof->enableSpring(i+3,dofData->m_angularEnableSpring[i]!=0);
1004  dof->setDamping(i+3,dofData->m_angularSpringDamping.m_floats[i]);
1005  }
1006 
1007  }
1008  }
1009 
1010  constraint = dof;
1011  break;
1012 
1013  }
1014  case FIXED_CONSTRAINT_TYPE:
1015  {
1016 
1018  if (rbA && rbB)
1019  {
1020  btTransform rbAFrame,rbBFrame;
1021  //compute a shared world frame, and compute frameInA, frameInB relative to this
1022  btTransform sharedFrame;
1023  sharedFrame.setIdentity();
1024  btVector3 centerPos = btScalar(0.5)*(rbA->getWorldTransform().getOrigin()+
1025  rbB->getWorldTransform().getOrigin());
1026  sharedFrame.setOrigin(centerPos);
1027  rbAFrame = rbA->getWorldTransform().inverse()*sharedFrame;
1028  rbBFrame = rbB->getWorldTransform().inverse()*sharedFrame;
1029 
1030 
1031  dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, RO_XYZ);
1032  dof->setLinearUpperLimit(btVector3(0,0,0));
1033  dof->setLinearLowerLimit(btVector3(0,0,0));
1034  dof->setAngularUpperLimit(btVector3(0,0,0));
1035  dof->setAngularLowerLimit(btVector3(0,0,0));
1036 
1037  } else
1038  {
1039  printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
1040  }
1041 
1042  constraint = dof;
1043  break;
1044  }
1045  default:
1046  {
1047  printf("unknown constraint type\n");
1048  }
1049  };
1050 
1051  if (constraint)
1052  {
1053  constraint->setDbgDrawSize(constraintData->m_dbgDrawSize);
1055  if (fileVersion>=280)
1056  {
1057  constraint->setBreakingImpulseThreshold(constraintData->m_breakingImpulseThreshold);
1058  constraint->setEnabled(constraintData->m_isEnabled!=0);
1060  }
1061 
1062  if (constraintData->m_name)
1063  {
1064  char* newname = duplicateName(constraintData->m_name);
1065  m_nameConstraintMap.insert(newname,constraint);
1066  m_objectNameMap.insert(constraint,newname);
1067  }
1068  if(m_dynamicsWorld)
1070  }
1071 
1072 
1073 }
1074 
1075 
1076 
1078 {
1079  btTypedConstraint* constraint = 0;
1080 
1081  switch (constraintData->m_objectType)
1082  {
1084  {
1086  if (rbA && rbB)
1087  {
1088  btVector3 pivotInA,pivotInB;
1089  pivotInA.deSerializeDouble(p2pData->m_pivotInA);
1090  pivotInB.deSerializeDouble(p2pData->m_pivotInB);
1091  constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
1092  } else
1093  {
1094  btVector3 pivotInA;
1095  pivotInA.deSerializeDouble(p2pData->m_pivotInA);
1096  constraint = createPoint2PointConstraint(*rbA,pivotInA);
1097  }
1098  break;
1099  }
1100  case HINGE_CONSTRAINT_TYPE:
1101  {
1102  btHingeConstraint* hinge = 0;
1103 
1104  btHingeConstraintDoubleData2* hingeData = (btHingeConstraintDoubleData2*)constraintData;
1105  if (rbA&& rbB)
1106  {
1107  btTransform rbAFrame,rbBFrame;
1108  rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
1109  rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
1110  hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
1111  } else
1112  {
1113  btTransform rbAFrame;
1114  rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
1115  hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
1116  }
1117  if (hingeData->m_enableAngularMotor)
1118  {
1119  hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse);
1120  }
1121  hinge->setAngularOnly(hingeData->m_angularOnly!=0);
1122  hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
1123 
1124  constraint = hinge;
1125  break;
1126 
1127  }
1129  {
1131  btConeTwistConstraint* coneTwist = 0;
1132 
1133  if (rbA&& rbB)
1134  {
1135  btTransform rbAFrame,rbBFrame;
1136  rbAFrame.deSerializeDouble(coneData->m_rbAFrame);
1137  rbBFrame.deSerializeDouble(coneData->m_rbBFrame);
1138  coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
1139  } else
1140  {
1141  btTransform rbAFrame;
1142  rbAFrame.deSerializeDouble(coneData->m_rbAFrame);
1143  coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
1144  }
1145  coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness,
1146  (btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor);
1147  coneTwist->setDamping((btScalar)coneData->m_damping);
1148 
1149  constraint = coneTwist;
1150  break;
1151  }
1152 
1154  {
1155 
1157  // int sz = sizeof(btGeneric6DofSpringConstraintData);
1159 
1160  if (rbA && rbB)
1161  {
1162  btTransform rbAFrame,rbBFrame;
1163  rbAFrame.deSerializeDouble(dofData->m_6dofData.m_rbAFrame);
1164  rbBFrame.deSerializeDouble(dofData->m_6dofData.m_rbBFrame);
1165  dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
1166  } else
1167  {
1168  printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
1169  }
1170 
1171  if (dof)
1172  {
1173  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
1174  angLowerLimit.deSerializeDouble(dofData->m_6dofData.m_angularLowerLimit);
1175  angUpperLimit.deSerializeDouble(dofData->m_6dofData.m_angularUpperLimit);
1176  linLowerLimit.deSerializeDouble(dofData->m_6dofData.m_linearLowerLimit);
1177  linUpperlimit.deSerializeDouble(dofData->m_6dofData.m_linearUpperLimit);
1178 
1179  angLowerLimit.setW(0.f);
1180  dof->setAngularLowerLimit(angLowerLimit);
1181  dof->setAngularUpperLimit(angUpperLimit);
1182  dof->setLinearLowerLimit(linLowerLimit);
1183  dof->setLinearUpperLimit(linUpperlimit);
1184 
1185  int i;
1186  if (fileVersion>280)
1187  {
1188  for (i=0;i<6;i++)
1189  {
1190  dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]);
1191  dof->setEquilibriumPoint(i,(btScalar)dofData->m_equilibriumPoint[i]);
1192  dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
1193  dof->setDamping(i,(btScalar)dofData->m_springDamping[i]);
1194  }
1195  }
1196  }
1197 
1198  constraint = dof;
1199  break;
1200  }
1201  case D6_CONSTRAINT_TYPE:
1202  {
1204  btGeneric6DofConstraint* dof = 0;
1205 
1206  if (rbA&& rbB)
1207  {
1208  btTransform rbAFrame,rbBFrame;
1209  rbAFrame.deSerializeDouble(dofData->m_rbAFrame);
1210  rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
1211  dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
1212  } else
1213  {
1214  if (rbB)
1215  {
1216  btTransform rbBFrame;
1217  rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
1218  dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
1219  } else
1220  {
1221  printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
1222  }
1223  }
1224 
1225  if (dof)
1226  {
1227  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
1228  angLowerLimit.deSerializeDouble(dofData->m_angularLowerLimit);
1229  angUpperLimit.deSerializeDouble(dofData->m_angularUpperLimit);
1230  linLowerLimit.deSerializeDouble(dofData->m_linearLowerLimit);
1231  linUpperlimit.deSerializeDouble(dofData->m_linearUpperLimit);
1232 
1233  dof->setAngularLowerLimit(angLowerLimit);
1234  dof->setAngularUpperLimit(angUpperLimit);
1235  dof->setLinearLowerLimit(linLowerLimit);
1236  dof->setLinearUpperLimit(linUpperlimit);
1237  }
1238 
1239  constraint = dof;
1240  break;
1241  }
1243  {
1244  btSliderConstraintDoubleData* sliderData = (btSliderConstraintDoubleData*)constraintData;
1245  btSliderConstraint* slider = 0;
1246  if (rbA&& rbB)
1247  {
1248  btTransform rbAFrame,rbBFrame;
1249  rbAFrame.deSerializeDouble(sliderData->m_rbAFrame);
1250  rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
1251  slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
1252  } else
1253  {
1254  btTransform rbBFrame;
1255  rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
1256  slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
1257  }
1258  slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit);
1259  slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit);
1260  slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit);
1261  slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit);
1262  slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
1263  constraint = slider;
1264  break;
1265  }
1266  case GEAR_CONSTRAINT_TYPE:
1267  {
1268  btGearConstraintDoubleData* gearData = (btGearConstraintDoubleData*) constraintData;
1269  btGearConstraint* gear = 0;
1270  if (rbA&&rbB)
1271  {
1272  btVector3 axisInA,axisInB;
1273  axisInA.deSerializeDouble(gearData->m_axisInA);
1274  axisInB.deSerializeDouble(gearData->m_axisInB);
1275  gear = createGearConstraint(*rbA, *rbB, axisInA,axisInB, gearData->m_ratio);
1276  } else
1277  {
1278  btAssert(0);
1279  //perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized?
1280  //btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio=1.f);
1281  }
1282  constraint = gear;
1283  break;
1284  }
1285 
1287  {
1288 
1290 
1292 
1293  if (rbA && rbB)
1294  {
1295  btTransform rbAFrame,rbBFrame;
1296  rbAFrame.deSerializeDouble(dofData->m_rbAFrame);
1297  rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
1298  dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, dofData->m_rotateOrder);
1299  } else
1300  {
1301  printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
1302  }
1303 
1304  if (dof)
1305  {
1306  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
1307  angLowerLimit.deSerializeDouble(dofData->m_angularLowerLimit);
1308  angUpperLimit.deSerializeDouble(dofData->m_angularUpperLimit);
1309  linLowerLimit.deSerializeDouble(dofData->m_linearLowerLimit);
1310  linUpperlimit.deSerializeDouble(dofData->m_linearUpperLimit);
1311 
1312  angLowerLimit.setW(0.f);
1313  dof->setAngularLowerLimit(angLowerLimit);
1314  dof->setAngularUpperLimit(angUpperLimit);
1315  dof->setLinearLowerLimit(linLowerLimit);
1316  dof->setLinearUpperLimit(linUpperlimit);
1317 
1318  int i;
1319  if (fileVersion>280)
1320  {
1321  //6-dof: 3 linear followed by 3 angular
1322  for (i=0;i<3;i++)
1323  {
1324  dof->setStiffness(i,dofData->m_linearSpringStiffness.m_floats[i]);
1326  dof->enableSpring(i,dofData->m_linearEnableSpring[i]!=0);
1327  dof->setDamping(i,dofData->m_linearSpringDamping.m_floats[i]);
1328  }
1329  for (i=0;i<3;i++)
1330  {
1331  dof->setStiffness(i+3,dofData->m_angularSpringStiffness.m_floats[i]);
1333  dof->enableSpring(i+3,dofData->m_angularEnableSpring[i]!=0);
1334  dof->setDamping(i+3,dofData->m_angularSpringDamping.m_floats[i]);
1335  }
1336 
1337  }
1338  }
1339 
1340  constraint = dof;
1341  break;
1342 
1343  }
1344  case FIXED_CONSTRAINT_TYPE:
1345  {
1346 
1348  if (rbA && rbB)
1349  {
1350  btTransform rbAFrame,rbBFrame;
1351  //compute a shared world frame, and compute frameInA, frameInB relative to this
1352  btTransform sharedFrame;
1353  sharedFrame.setIdentity();
1354  btVector3 centerPos = btScalar(0.5)*(rbA->getWorldTransform().getOrigin()+
1355  rbB->getWorldTransform().getOrigin());
1356  sharedFrame.setOrigin(centerPos);
1357  rbAFrame = rbA->getWorldTransform().inverse()*sharedFrame;
1358  rbBFrame = rbB->getWorldTransform().inverse()*sharedFrame;
1359 
1360 
1361  dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, RO_XYZ);
1362  dof->setLinearUpperLimit(btVector3(0,0,0));
1363  dof->setLinearLowerLimit(btVector3(0,0,0));
1364  dof->setAngularUpperLimit(btVector3(0,0,0));
1365  dof->setAngularLowerLimit(btVector3(0,0,0));
1366 
1367  } else
1368  {
1369  printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
1370  }
1371 
1372  constraint = dof;
1373  break;
1374  }
1375 
1376  default:
1377  {
1378  printf("unknown constraint type\n");
1379  }
1380  };
1381 
1382  if (constraint)
1383  {
1384  constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize);
1386  if (fileVersion>=280)
1387  {
1388  constraint->setBreakingImpulseThreshold((btScalar)constraintData->m_breakingImpulseThreshold);
1389  constraint->setEnabled(constraintData->m_isEnabled!=0);
1391  }
1392 
1393  if (constraintData->m_name)
1394  {
1395  char* newname = duplicateName(constraintData->m_name);
1396  m_nameConstraintMap.insert(newname,constraint);
1397  m_objectNameMap.insert(constraint,newname);
1398  }
1399  if(m_dynamicsWorld)
1401  }
1402 
1403 
1404 }
1405 
1406 
1407 
1408 
1409 
1410 
1411 
1412 
1413 
1414 
1416 {
1418 
1419  for (int i=0;i<meshData.m_numMeshParts;i++)
1420  {
1421  btIndexedMesh meshPart;
1422  meshPart.m_numTriangles = meshData.m_meshPartsPtr[i].m_numTriangles;
1423  meshPart.m_numVertices = meshData.m_meshPartsPtr[i].m_numVertices;
1424 
1425 
1426  if (meshData.m_meshPartsPtr[i].m_indices32)
1427  {
1428  meshPart.m_indexType = PHY_INTEGER;
1429  meshPart.m_triangleIndexStride = 3*sizeof(int);
1430  int* indexArray = (int*)btAlignedAlloc(sizeof(int)*3*meshPart.m_numTriangles,16);
1431  m_indexArrays.push_back(indexArray);
1432  for (int j=0;j<3*meshPart.m_numTriangles;j++)
1433  {
1434  indexArray[j] = meshData.m_meshPartsPtr[i].m_indices32[j].m_value;
1435  }
1436  meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1437  } else
1438  {
1439  if (meshData.m_meshPartsPtr[i].m_3indices16)
1440  {
1441  meshPart.m_indexType = PHY_SHORT;
1442  meshPart.m_triangleIndexStride = sizeof(short int)*3;//sizeof(btShortIntIndexTripletData);
1443 
1444  short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
1445  m_shortIndexArrays.push_back(indexArray);
1446 
1447  for (int j=0;j<meshPart.m_numTriangles;j++)
1448  {
1449  indexArray[3*j] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[0];
1450  indexArray[3*j+1] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[1];
1451  indexArray[3*j+2] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[2];
1452  }
1453 
1454  meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1455  }
1456  if (meshData.m_meshPartsPtr[i].m_indices16)
1457  {
1458  meshPart.m_indexType = PHY_SHORT;
1459  meshPart.m_triangleIndexStride = 3*sizeof(short int);
1460  short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
1461  m_shortIndexArrays.push_back(indexArray);
1462  for (int j=0;j<3*meshPart.m_numTriangles;j++)
1463  {
1464  indexArray[j] = meshData.m_meshPartsPtr[i].m_indices16[j].m_value;
1465  }
1466 
1467  meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1468  }
1469 
1470  if (meshData.m_meshPartsPtr[i].m_3indices8)
1471  {
1472  meshPart.m_indexType = PHY_UCHAR;
1473  meshPart.m_triangleIndexStride = sizeof(unsigned char)*3;
1474 
1475  unsigned char* indexArray = (unsigned char*)btAlignedAlloc(sizeof(unsigned char)*3*meshPart.m_numTriangles,16);
1476  m_charIndexArrays.push_back(indexArray);
1477 
1478  for (int j=0;j<meshPart.m_numTriangles;j++)
1479  {
1480  indexArray[3*j] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[0];
1481  indexArray[3*j+1] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[1];
1482  indexArray[3*j+2] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[2];
1483  }
1484 
1485  meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1486  }
1487  }
1488 
1489  if (meshData.m_meshPartsPtr[i].m_vertices3f)
1490  {
1491  meshPart.m_vertexType = PHY_FLOAT;
1492  meshPart.m_vertexStride = sizeof(btVector3FloatData);
1494  m_floatVertexArrays.push_back(vertices);
1495 
1496  for (int j=0;j<meshPart.m_numVertices;j++)
1497  {
1498  vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[0];
1499  vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[1];
1500  vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[2];
1501  vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[3];
1502  }
1503  meshPart.m_vertexBase = (const unsigned char*)vertices;
1504  } else
1505  {
1506  meshPart.m_vertexType = PHY_DOUBLE;
1507  meshPart.m_vertexStride = sizeof(btVector3DoubleData);
1508 
1509 
1511  m_doubleVertexArrays.push_back(vertices);
1512 
1513  for (int j=0;j<meshPart.m_numVertices;j++)
1514  {
1515  vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[0];
1516  vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[1];
1517  vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[2];
1518  vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[3];
1519  }
1520  meshPart.m_vertexBase = (const unsigned char*)vertices;
1521  }
1522 
1523  if (meshPart.m_triangleIndexBase && meshPart.m_vertexBase)
1524  {
1525  meshInterface->addIndexedMesh(meshPart,meshPart.m_indexType);
1526  }
1527  }
1528 
1529  return meshInterface;
1530 }
1531 
1532 
1534 {
1535  //create a new btStridingMeshInterfaceData that is an exact copy of shapedata and store it in the WorldImporter
1537 
1538  newData->m_scaling = interfaceData->m_scaling;
1539  newData->m_numMeshParts = interfaceData->m_numMeshParts;
1540  newData->m_meshPartsPtr = new btMeshPartData[newData->m_numMeshParts];
1541 
1542  for(int i = 0;i < newData->m_numMeshParts;i++)
1543  {
1544  btMeshPartData* curPart = &interfaceData->m_meshPartsPtr[i];
1545  btMeshPartData* curNewPart = &newData->m_meshPartsPtr[i];
1546 
1547  curNewPart->m_numTriangles = curPart->m_numTriangles;
1548  curNewPart->m_numVertices = curPart->m_numVertices;
1549 
1550  if(curPart->m_vertices3f)
1551  {
1552  curNewPart->m_vertices3f = new btVector3FloatData[curNewPart->m_numVertices];
1553  memcpy(curNewPart->m_vertices3f,curPart->m_vertices3f,sizeof(btVector3FloatData) * curNewPart->m_numVertices);
1554  }
1555  else
1556  curNewPart->m_vertices3f = NULL;
1557 
1558  if(curPart->m_vertices3d)
1559  {
1560  curNewPart->m_vertices3d = new btVector3DoubleData[curNewPart->m_numVertices];
1561  memcpy(curNewPart->m_vertices3d,curPart->m_vertices3d,sizeof(btVector3DoubleData) * curNewPart->m_numVertices);
1562  }
1563  else
1564  curNewPart->m_vertices3d = NULL;
1565 
1566  int numIndices = curNewPart->m_numTriangles * 3;
1569  bool uninitialized3indices8Workaround =false;
1570 
1571  if(curPart->m_indices32)
1572  {
1573  uninitialized3indices8Workaround=true;
1574  curNewPart->m_indices32 = new btIntIndexData[numIndices];
1575  memcpy(curNewPart->m_indices32,curPart->m_indices32,sizeof(btIntIndexData) * numIndices);
1576  }
1577  else
1578  curNewPart->m_indices32 = NULL;
1579 
1580  if(curPart->m_3indices16)
1581  {
1582  uninitialized3indices8Workaround=true;
1583  curNewPart->m_3indices16 = new btShortIntIndexTripletData[curNewPart->m_numTriangles];
1584  memcpy(curNewPart->m_3indices16,curPart->m_3indices16,sizeof(btShortIntIndexTripletData) * curNewPart->m_numTriangles);
1585  }
1586  else
1587  curNewPart->m_3indices16 = NULL;
1588 
1589  if(curPart->m_indices16)
1590  {
1591  uninitialized3indices8Workaround=true;
1592  curNewPart->m_indices16 = new btShortIntIndexData[numIndices];
1593  memcpy(curNewPart->m_indices16,curPart->m_indices16,sizeof(btShortIntIndexData) * numIndices);
1594  }
1595  else
1596  curNewPart->m_indices16 = NULL;
1597 
1598  if(!uninitialized3indices8Workaround && curPart->m_3indices8)
1599  {
1600  curNewPart->m_3indices8 = new btCharIndexTripletData[curNewPart->m_numTriangles];
1601  memcpy(curNewPart->m_3indices8,curPart->m_3indices8,sizeof(btCharIndexTripletData) * curNewPart->m_numTriangles);
1602  }
1603  else
1604  curNewPart->m_3indices8 = NULL;
1605 
1606  }
1607 
1609 
1610  return(newData);
1611 }
1612 
1613 #ifdef USE_INTERNAL_EDGE_UTILITY
1615 
1616 static bool btAdjustInternalEdgeContactsCallback(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
1617 {
1618 
1619  btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1);
1620  //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_BACKFACE_MODE);
1621  //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_DOUBLE_SIDED+BT_TRIANGLE_CONCAVE_DOUBLE_SIDED);
1622  return true;
1623 }
1624 #endif //USE_INTERNAL_EDGE_UTILITY
1625 
1626 
1627 
1628 
1629 btCollisionObject* btWorldImporter::createCollisionObject(const btTransform& startTransform,btCollisionShape* shape, const char* bodyName)
1630 {
1631  return createRigidBody(false,0,startTransform,shape,bodyName);
1632 }
1633 
1635 {
1636  if (m_dynamicsWorld)
1637  {
1638  m_dynamicsWorld->setGravity(gravity);
1639  m_dynamicsWorld->getSolverInfo() = solverInfo;
1640  }
1641 
1642 }
1643 
1644 btRigidBody* btWorldImporter::createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform,btCollisionShape* shape,const char* bodyName)
1645 {
1646  btVector3 localInertia;
1647  localInertia.setZero();
1648 
1649  if (mass)
1650  shape->calculateLocalInertia(mass,localInertia);
1651 
1652  btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
1653  body->setWorldTransform(startTransform);
1654 
1655  if (m_dynamicsWorld)
1657 
1658  if (bodyName)
1659  {
1660  char* newname = duplicateName(bodyName);
1661  m_objectNameMap.insert(body,newname);
1662  m_nameBodyMap.insert(newname,body);
1663  }
1665  return body;
1666 
1667 }
1668 
1670 {
1671  btStaticPlaneShape* shape = new btStaticPlaneShape(planeNormal,planeConstant);
1673  return shape;
1674 }
1676 {
1677  btBoxShape* shape = new btBoxShape(halfExtents);
1679  return shape;
1680 }
1682 {
1683  btSphereShape* shape = new btSphereShape(radius);
1685  return shape;
1686 }
1687 
1688 
1690 {
1691  btCapsuleShapeX* shape = new btCapsuleShapeX(radius,height);
1693  return shape;
1694 }
1695 
1697 {
1698  btCapsuleShape* shape = new btCapsuleShape(radius,height);
1700  return shape;
1701 }
1702 
1704 {
1705  btCapsuleShapeZ* shape = new btCapsuleShapeZ(radius,height);
1707  return shape;
1708 }
1709 
1711 {
1712  btCylinderShapeX* shape = new btCylinderShapeX(btVector3(height,radius,radius));
1714  return shape;
1715 }
1716 
1718 {
1719  btCylinderShape* shape = new btCylinderShape(btVector3(radius,height,radius));
1721  return shape;
1722 }
1723 
1725 {
1726  btCylinderShapeZ* shape = new btCylinderShapeZ(btVector3(radius,radius,height));
1728  return shape;
1729 }
1730 
1732 {
1733  btConeShapeX* shape = new btConeShapeX(radius,height);
1735  return shape;
1736 }
1737 
1739 {
1740  btConeShape* shape = new btConeShape(radius,height);
1742  return shape;
1743 }
1744 
1746 {
1747  btConeShapeZ* shape = new btConeShapeZ(radius,height);
1749  return shape;
1750 }
1751 
1753 {
1756  return in;
1757 }
1758 
1760 {
1761  btOptimizedBvh* bvh = new btOptimizedBvh();
1763  return bvh;
1764 }
1765 
1766 
1768 {
1769  btTriangleInfoMap* tim = new btTriangleInfoMap();
1771  return tim;
1772 }
1773 
1775 {
1776  if (bvh)
1777  {
1778  btBvhTriangleMeshShape* bvhTriMesh = new btBvhTriangleMeshShape(trimesh,bvh->isQuantized(), false);
1779  bvhTriMesh->setOptimizedBvh(bvh);
1781  return bvhTriMesh;
1782  }
1783 
1784  btBvhTriangleMeshShape* ts = new btBvhTriangleMeshShape(trimesh,true);
1786  return ts;
1787 
1788 }
1790 {
1791  return 0;
1792 }
1794 {
1795  btGImpactMeshShape* shape = new btGImpactMeshShape(trimesh);
1797  return shape;
1798 
1799 }
1801 {
1802  btConvexHullShape* shape = new btConvexHullShape();
1804  return shape;
1805 }
1806 
1808 {
1809  btCompoundShape* shape = new btCompoundShape();
1811  return shape;
1812 }
1813 
1814 
1816 {
1817  btScaledBvhTriangleMeshShape* shape = new btScaledBvhTriangleMeshShape(meshShape,localScaling);
1819  return shape;
1820 }
1821 
1823 {
1824  btMultiSphereShape* shape = new btMultiSphereShape(positions, radi, numSpheres);
1826  return shape;
1827 }
1828 
1830 {
1831  static btRigidBody s_fixed(0, 0,0);
1832  s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));
1833  return s_fixed;
1834 }
1835 
1837 {
1838  btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,rbB,pivotInA,pivotInB);
1840  return p2p;
1841 }
1842 
1844 {
1845  btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,pivotInA);
1847  return p2p;
1848 }
1849 
1850 
1851 btHingeConstraint* btWorldImporter::createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA)
1852 {
1853  btHingeConstraint* hinge = new btHingeConstraint(rbA,rbB,rbAFrame,rbBFrame,useReferenceFrameA);
1855  return hinge;
1856 }
1857 
1859 {
1860  btHingeConstraint* hinge = new btHingeConstraint(rbA,rbAFrame,useReferenceFrameA);
1862  return hinge;
1863 }
1864 
1866 {
1867  btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbB,rbAFrame,rbBFrame);
1869  return cone;
1870 }
1871 
1873 {
1874  btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbAFrame);
1876  return cone;
1877 }
1878 
1879 
1880 btGeneric6DofConstraint* btWorldImporter::createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA)
1881 {
1882  btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
1884  return dof;
1885 }
1886 
1888 {
1889  btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbB,frameInB,useLinearReferenceFrameB);
1891  return dof;
1892 }
1893 
1895 {
1896  btGeneric6DofSpring2Constraint* dof = new btGeneric6DofSpring2Constraint(rbA,rbB,frameInA,frameInB, (RotateOrder)rotateOrder);
1898  return dof;
1899 }
1900 
1901 
1902 
1904 {
1905  btGeneric6DofSpringConstraint* dof = new btGeneric6DofSpringConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
1907  return dof;
1908 }
1909 
1910 
1911 btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA)
1912 {
1913  btSliderConstraint* slider = new btSliderConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
1915  return slider;
1916 }
1917 
1918 btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA)
1919 {
1920  btSliderConstraint* slider = new btSliderConstraint(rbB,frameInB,useLinearReferenceFrameA);
1922  return slider;
1923 }
1924 
1926 {
1927  btGearConstraint* gear = new btGearConstraint(rbA,rbB,axisInA,axisInB,ratio);
1929  return gear;
1930 }
1931 
1932  // query for data
1934 {
1936 }
1937 
1939 {
1940  return m_allocatedCollisionShapes[index];
1941 }
1942 
1944 {
1945  btCollisionShape** shapePtr = m_nameShapeMap.find(name);
1946  if (shapePtr&& *shapePtr)
1947  {
1948  return *shapePtr;
1949  }
1950  return 0;
1951 }
1952 
1954 {
1955  btRigidBody** bodyPtr = m_nameBodyMap.find(name);
1956  if (bodyPtr && *bodyPtr)
1957  {
1958  return *bodyPtr;
1959  }
1960  return 0;
1961 }
1962 
1964 {
1965  btTypedConstraint** constraintPtr = m_nameConstraintMap.find(name);
1966  if (constraintPtr && *constraintPtr)
1967  {
1968  return *constraintPtr;
1969  }
1970  return 0;
1971 }
1972 
1973 const char* btWorldImporter::getNameForPointer(const void* ptr) const
1974 {
1975  const char*const * namePtr = m_objectNameMap.find(ptr);
1976  if (namePtr && *namePtr)
1977  return *namePtr;
1978  return 0;
1979 }
1980 
1981 
1983 {
1984  return m_allocatedRigidBodies.size();
1985 }
1986 
1988 {
1989  return m_allocatedRigidBodies[index];
1990 }
1992 {
1993  return m_allocatedConstraints.size();
1994 }
1995 
1997 {
1998  return m_allocatedConstraints[index];
1999 }
2000 
2002 {
2003  return m_allocatedBvhs.size();
2004 }
2006 {
2007  return m_allocatedBvhs[index];
2008 }
2009 
2011 {
2013 }
2014 
2016 {
2017  return m_allocatedTriangleInfoMaps[index];
2018 }
2019 
2020 
2022 {
2023  btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f);
2024  btVector3 localInertia;
2025  localInertia.setZero();
2027  if (shapePtr && *shapePtr)
2028  {
2029  btTransform startTransform;
2031  startTransform.deSerializeFloat(colObjData->m_collisionObjectData.m_worldTransform);
2032 
2033  // startTransform.setBasis(btMatrix3x3::getIdentity());
2034  btCollisionShape* shape = (btCollisionShape*)*shapePtr;
2035  if (shape->isNonMoving())
2036  {
2037  mass = 0.f;
2038  }
2039  if (mass)
2040  {
2041  shape->calculateLocalInertia(mass,localInertia);
2042  }
2043  bool isDynamic = mass!=0.f;
2044  btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name);
2045  body->setFriction(colObjData->m_collisionObjectData.m_friction);
2047  btVector3 linearFactor,angularFactor;
2048  linearFactor.deSerializeFloat(colObjData->m_linearFactor);
2049  angularFactor.deSerializeFloat(colObjData->m_angularFactor);
2050  body->setLinearFactor(linearFactor);
2051  body->setAngularFactor(angularFactor);
2052 
2053 #ifdef USE_INTERNAL_EDGE_UTILITY
2055  {
2057  if (trimesh->getTriangleInfoMap())
2058  {
2060  }
2061  }
2062 #endif //USE_INTERNAL_EDGE_UTILITY
2063  m_bodyMap.insert(colObjData,body);
2064  } else
2065  {
2066  printf("error: no shape found\n");
2067  }
2068 }
2069 
2071 {
2072  btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f);
2073  btVector3 localInertia;
2074  localInertia.setZero();
2076  if (shapePtr && *shapePtr)
2077  {
2078  btTransform startTransform;
2080  startTransform.deSerializeDouble(colObjData->m_collisionObjectData.m_worldTransform);
2081 
2082  // startTransform.setBasis(btMatrix3x3::getIdentity());
2083  btCollisionShape* shape = (btCollisionShape*)*shapePtr;
2084  if (shape->isNonMoving())
2085  {
2086  mass = 0.f;
2087  }
2088  if (mass)
2089  {
2090  shape->calculateLocalInertia(mass,localInertia);
2091  }
2092  bool isDynamic = mass!=0.f;
2093  btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name);
2096  btVector3 linearFactor,angularFactor;
2097  linearFactor.deSerializeDouble(colObjData->m_linearFactor);
2098  angularFactor.deSerializeDouble(colObjData->m_angularFactor);
2099  body->setLinearFactor(linearFactor);
2100  body->setAngularFactor(angularFactor);
2101 
2102 
2103 #ifdef USE_INTERNAL_EDGE_UTILITY
2105  {
2107  if (trimesh->getTriangleInfoMap())
2108  {
2110  }
2111  }
2112 #endif //USE_INTERNAL_EDGE_UTILITY
2113  m_bodyMap.insert(colObjData,body);
2114  } else
2115  {
2116  printf("error: no shape found\n");
2117  }
2118 }
void setOrigin(const btVector3 &origin)
Set the translational element.
Definition: btTransform.h:150
btTransformFloatData m_worldTransform
static const btRigidBody * upcast(const btCollisionObject *colObj)
to keep collision detection and dynamics separate we don&#39;t store a rigidbody pointer but a rigidbody ...
Definition: btRigidBody.h:200
btTransformDoubleData m_rbBFrame
const btTriangleInfoMap * getTriangleInfoMap() const
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
virtual btGeneric6DofSpringConstraint * createGeneric6DofSpringConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, bool useLinearReferenceFrameA)
void setLimit(int limitIndex, btScalar limitValue)
btTransformFloatData m_rbAFrame
virtual btGeneric6DofConstraint * createGeneric6DofConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, bool useLinearReferenceFrameA)
void push_back(const T &_Val)
void setUpperLinLimit(btScalar upperLimit)
void convertConstraintBackwardsCompatible281(btTypedConstraintData *constraintData, btRigidBody *rbA, btRigidBody *rbB, int fileVersion)
btCompoundShapeChildData * m_childShapePtr
btCollisionShape * convertCollisionShape(btCollisionShapeData *shapeData)
btTriangleInfoMap * getTriangleInfoMapByIndex(int index) const
virtual btStridingMeshInterfaceData * createStridingMeshInterfaceData(btStridingMeshInterfaceData *interfaceData)
point to point constraint between two rigidbodies each with a pivotpoint that descibes the &#39;ballsocke...
btTransformFloatData m_rbAFrame
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
void deSerializeFloat(const struct btTransformFloatData &dataIn)
Definition: btTransform.h:286
virtual class btTriangleIndexVertexArray * createTriangleMeshContainer()
void convertRigidBodyDouble(btRigidBodyDoubleData *colObjData)
virtual btBvhTriangleMeshShape * createBvhTriangleMeshShape(btStridingMeshInterface *trimesh, btOptimizedBvh *bvh)
void deSerializeDouble(const struct btVector3DoubleData &dataIn)
Definition: btVector3.h:1333
virtual btCollisionShape * createSphereShape(btScalar radius)
void setLowerLinLimit(btScalar lowerLimit)
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const =0
virtual btConeTwistConstraint * createConeTwistConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &rbAFrame, const btTransform &rbBFrame)
virtual btTriangleInfoMap * createTriangleInfoMap()
The btIndexedMesh indexes a single vertex and index array.
void convertRigidBodyFloat(btRigidBodyFloatData *colObjData)
void setLowerAngLimit(btScalar lowerLimit)
btVector3FloatData m_angularFactor
Definition: btRigidBody.h:567
virtual btCollisionShape * createCylinderShapeZ(btScalar radius, btScalar height)
virtual void setLocalScaling(const btVector3 &scaling)
btAlignedObjectArray< unsigned char * > m_charIndexArrays
double m_floats[4]
Definition: btVector3.h:1308
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
const Value * find(const Key &key) const
Definition: btHashMap.h:402
void setDamping(int index, btScalar damping)
The btGeatConstraint will couple the angular velocity for two bodies around given local axis and rati...
The btMultiSphereShape represents the convex hull of a collection of spheres.
virtual btRigidBody * createRigidBody(bool isDynamic, btScalar mass, const btTransform &startTransform, btCollisionShape *shape, const char *bodyName)
btGeneric6DofConstraint between two rigidbodies each with a pivotpoint that descibes the axis locatio...
btWorldImporter(btDynamicsWorld *world)
The btCapsuleShape represents a capsule around the Y axis, there is also the btCapsuleShapeX aligned ...
btVector3DoubleData * m_unscaledPointsDoublePtr
this structure is not used, except for loading pre-2.82 .bullet files
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:172
#define btAssert(x)
Definition: btScalar.h:113
The btDynamicsWorld is the interface class for several dynamics implementation, basic, discrete, parallel, and continuous etc.
virtual class btConvexHullShape * createConvexHullShape()
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
int getNumCollisionShapes() const
btCapsuleShapeX represents a capsule around the Z axis the total height is height+2*radius, so the height is just the height between the center of each &#39;sphere&#39; of the capsule caps.
btConeShape implements a Cone shape, around the X axis
Definition: btConeShape.h:104
btHashMap< btHashString, btCollisionShape * > m_nameShapeMap
btAlignedObjectArray< short int * > m_shortIndexArrays
const btScalar & getY() const
Return the y value.
Definition: btVector3.h:563
void setDamping(btScalar damping)
virtual btCollisionShape * createConvexTriangleMeshShape(btStridingMeshInterface *trimesh)
The btSphereShape implements an implicit sphere, centered around a local origin with radius...
Definition: btSphereShape.h:22
void setScaling(const btVector3 &scaling)
virtual btCollisionShape * createCapsuleShapeY(btScalar radius, btScalar height)
virtual btCollisionShape * createCylinderShapeX(btScalar radius, btScalar height)
btCollisionShape * getCollisionShapeByName(const char *name)
btTransformFloatData m_rbBFrame
void setAngularUpperLimit(const btVector3 &angularUpper)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
ManifoldContactPoint collects and maintains persistent contactpoints.
void setUseFrameOffset(bool frameOffsetOnOff)
btStridingMeshInterfaceData m_meshInterface
virtual void setGravity(const btVector3 &gravity)=0
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btVector3DoubleData m_axisInB
btVector3FloatData * m_vertices3f
void setLinearFactor(const btVector3 &linearFactor)
Definition: btRigidBody.h:265
virtual btCollisionShape * createCylinderShapeY(btScalar radius, btScalar height)
btAlignedObjectArray< btOptimizedBvh * > m_allocatedBvhs
btVector3FloatData m_axisInB
virtual btCollisionShape * createConeShapeX(btScalar radius, btScalar height)
void addChildShape(const btTransform &localTransform, btCollisionShape *shape)
This class manages a mesh supplied by the btStridingMeshInterface interface.
void setStiffness(int index, btScalar stiffness)
Used for GIMPACT Trimesh integration.
btTriangleInfoMapData * m_triangleInfoMap
virtual void setMargin(btScalar collisionMargin)
virtual btCollisionShape * createCapsuleShapeZ(btScalar radius, btScalar height)
btTransformFloatData m_rbBFrame
hinge constraint between two rigidbodies each with a pivotpoint that descibes the axis location in lo...
void setRestitution(btScalar rest)
btCollisionObjectFloatData m_collisionObjectData
Definition: btRigidBody.h:563
btVector3DoubleData m_linearFactor
Definition: btRigidBody.h:594
virtual btCollisionShape * createPlaneShape(const btVector3 &planeNormal, btScalar planeConstant)
shapes
btAlignedObjectArray< btTriangleInfoMap * > m_allocatedTriangleInfoMaps
virtual void deleteAllData()
delete all memory collision shapes, rigid bodies, constraints etc.
PHY_ScalarType m_indexType
btShortIntIndexData * m_indices16
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0), to reduce performance overhead of run-time memory (de)allocations.
btTypedConstraint * getConstraintByName(const char *name)
virtual void addRigidBody(btRigidBody *body)=0
btCharIndexTripletData * m_3indices8
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
void setBreakingImpulseThreshold(btScalar threshold)
const btScalar & getZ() const
Return the z value.
Definition: btVector3.h:565
int getNumRigidBodies() const
virtual class btCompoundShape * createCompoundShape()
The btBvhTriangleMeshShape is a static-triangle mesh shape, it can only be used for fixed/non-moving ...
btCollisionObject * getRigidBodyByIndex(int index) const
void setDbgDrawSize(btScalar dbgDrawSize)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
void btAdjustInternalEdgeContacts(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, const btCollisionObjectWrapper *colObj1Wrap, int partId0, int index0, int normalAdjustFlags)
Changes a btManifoldPoint collision normal to the normal from the mesh.
The btTriangleIndexVertexArray allows to access multiple triangle meshes, by indexing into existing t...
btTransform & getWorldTransform()
virtual void setMargin(btScalar margin)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btHashMap< btHashPtr, btOptimizedBvh * > m_bvhMap
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
virtual void removeConstraint(btTypedConstraint *constraint)
btShortIntIndexTripletData * m_3indices16
btVector3 & getOrigin()
Return the origin vector translation.
Definition: btTransform.h:117
btAlignedObjectArray< btVector3DoubleData * > m_doubleVertexArrays
btAlignedObjectArray< btStridingMeshInterfaceData * > m_allocatedbtStridingMeshInterfaceDatas
void addIndexedMesh(const btIndexedMesh &mesh, PHY_ScalarType indexType=PHY_INTEGER)
virtual btGImpactMeshShape * createGimpactShape(btStridingMeshInterface *trimesh)
btHashMap< btHashString, btTypedConstraint * > m_nameConstraintMap
btVector3FloatData m_origin
Definition: btTransform.h:256
void setFriction(btScalar frict)
virtual btGearConstraint * createGearConstraint(btRigidBody &rbA, btRigidBody &rbB, const btVector3 &axisInA, const btVector3 &axisInB, btScalar ratio)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btConeShape.h:144
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btOptimizedBvh * getBvhByIndex(int index) const
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btRigidBody.h:587
virtual void deSerializeDouble(struct btQuantizedBvhDoubleData &quantizedBvhDoubleData)
The btConeShape implements a cone shape primitive, centered around the origin and aligned with the Y ...
Definition: btConeShape.h:23
virtual btCollisionShape * createConeShapeZ(btScalar radius, btScalar height)
void setOverrideNumSolverIterations(int overideNumIterations)
override the number of constraint solver iterations used to solve this constraint -1 will use the def...
virtual btOptimizedBvh * createOptimizedBvh()
acceleration and connectivity structures
void setDamping(int index, btScalar damping)
btHashMap< btHashPtr, btCollisionShape * > m_shapeMap
btPositionAndRadius * m_localPositionArrayPtr
btStridingMeshInterfaceData m_meshInterface
void setW(btScalar _w)
Set the w value.
Definition: btVector3.h:573
virtual void removeRigidBody(btRigidBody *body)=0
btTransformFloatData m_transform
void setUpperAngLimit(btScalar upperLimit)
char * duplicateName(const char *name)
#define btAlignedFree(ptr)
btVector3FloatData m_pos
void setStiffness(int index, btScalar stiffness)
btCollisionObject can be used to manage collision detection objects.
virtual btCollisionShape * createBoxShape(const btVector3 &halfExtents)
void setOptimizedBvh(btOptimizedBvh *bvh, const btVector3 &localScaling=btVector3(1, 1, 1))
void insert(const Key &key, const Value &value)
Definition: btHashMap.h:269
btAlignedObjectArray< btTypedConstraint * > m_allocatedConstraints
virtual class btScaledBvhTriangleMeshShape * createScaledTrangleMeshShape(btBvhTriangleMeshShape *meshShape, const btVector3 &localScalingbtBvhTriangleMeshShape)
void setZero()
Definition: btVector3.h:671
virtual btGeneric6DofSpring2Constraint * createGeneric6DofSpring2Constraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, int rotateOrder)
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:62
The btOptimizedBvh extends the btQuantizedBvh to create AABB tree for triangle meshes, through the btStridingMeshInterface.
virtual void setMargin(btScalar margin)=0
virtual btCollisionObject * createCollisionObject(const btTransform &startTransform, btCollisionShape *shape, const char *bodyName)
const unsigned char * m_triangleIndexBase
void setLinearUpperLimit(const btVector3 &linearUpper)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btRigidBody.h:561
this structure is not used, except for loading pre-2.82 .bullet files
void setLinearLowerLimit(const btVector3 &linearLower)
btVector3DoubleData m_angularFactor
Definition: btRigidBody.h:593
void setAngularLowerLimit(const btVector3 &angularLower)
void setWorldTransform(const btTransform &worldTrans)
btVector3FloatData m_implicitShapeDimensions
btVector3FloatData * m_unscaledPointsFloatPtr
btAlignedObjectArray< int * > m_indexArrays
virtual void setLocalScaling(const btVector3 &scaling)=0
void convertConstraintFloat(btTypedConstraintFloatData *constraintData, btRigidBody *rbA, btRigidBody *rbB, int fileVersion)
btQuantizedBvhDoubleData * m_quantizedDoubleBvh
btVector3DoubleData m_axisInA
int getCollisionFlags() const
btVector3FloatData m_axisInA
virtual void setDynamicsWorldInfo(const btVector3 &gravity, const btContactSolverInfo &solverInfo)
those virtuals are called by load and can be overridden by the user
The btBoxShape is a box primitive around the origin, its sides axis aligned with length specified by ...
Definition: btBoxShape.h:26
virtual btTriangleIndexVertexArray * createMeshInterface(btStridingMeshInterfaceData &meshData)
virtual btCollisionShape * createConeShapeY(btScalar radius, btScalar height)
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
int getNumConstraints() const
bool(* ContactAddedCallback)(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1)
int size() const
return the number of elements in the array
virtual btPoint2PointConstraint * createPoint2PointConstraint(btRigidBody &rbA, btRigidBody &rbB, const btVector3 &pivotInA, const btVector3 &pivotInB)
constraints
void setAngularOnly(bool angularOnly)
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btConeTwistConstraint can be used to simulate ragdoll joints (upper arm, leg etc) ...
void setMassProps(btScalar mass, const btVector3 &inertia)
The btStridingMeshInterface is the interface class for high performance generic access to triangle me...
btConeShapeZ implements a Cone shape, around the Z axis
Definition: btConeShape.h:124
bool isNonMoving() const
btAlignedObjectArray< char * > m_allocatedNames
void setCollisionFlags(int flags)
btCollisionObjectDoubleData m_collisionObjectData
Definition: btRigidBody.h:589
btTransformDoubleData m_rbAFrame
btTransformDoubleData m_worldTransform
virtual void deSerializeFloat(struct btQuantizedBvhFloatData &quantizedBvhFloatData)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btTypedConstraint * getConstraintByIndex(int index) const
TypedConstraint is the baseclass for Bullet constraints and vehicles.
void setLimit(btScalar low, btScalar high, btScalar _softness=0.9f, btScalar _biasFactor=0.3f, btScalar _relaxationFactor=1.0f)
virtual int getNumSubParts() const
getNumSubParts returns the number of seperate subparts each subpart has a continuous array of vertice...
const char * getNameForPointer(const void *ptr) const
void resize(int newsize, const T &fillData=T())
btTransformFloatData m_rbAFrame
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
static btRigidBody & getFixedBody()
virtual void addConstraint(btTypedConstraint *constraint, bool disableCollisionsBetweenLinkedBodies=false)
void setEnabled(bool enabled)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
int getNumTriangleInfoMaps() const
btAlignedObjectArray< btCollisionShape * > m_allocatedCollisionShapes
void deSerialize(struct btTriangleInfoMapData &data)
fills the dataBuffer and returns the struct name (and 0 on failure)
virtual btHingeConstraint * createHingeConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &rbAFrame, const btTransform &rbBFrame, bool useReferenceFrameA=false)
btVector3FloatData m_localScaling
The btCylinderShape class implements a cylinder shape primitive, centered around the origin...
ContactAddedCallback gContactAddedCallback
This is to allow MaterialCombiner/Custom Friction/Restitution values.
The btScaledBvhTriangleMeshShape allows to instance a scaled version of an existing btBvhTriangleMesh...
void setLinearLowerLimit(const btVector3 &linearLower)
btCollisionShape * getCollisionShapeByIndex(int index)
btRigidBody * getRigidBodyByName(const char *name)
btTransformDoubleData m_rbBFrame
#define btAlignedAlloc(size, alignment)
btHashMap< btHashPtr, btCollisionObject * > m_bodyMap
btCapsuleShapeZ represents a capsule around the Z axis the total height is height+2*radius, so the height is just the height between the center of each &#39;sphere&#39; of the capsule caps.
btIntIndexData * m_indices32
void deSerializeFloat(struct btCapsuleShapeData *dataBuffer)
void setTriangleInfoMap(btTriangleInfoMap *triangleInfoMap)
btVector3FloatData m_planeNormal
btTransformDoubleData m_rbBFrame
void addPoint(const btVector3 &point, bool recalculateLocalAabb=true)
virtual btSliderConstraint * createSliderConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, bool useLinearReferenceFrameA)
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
The btConvexHullShape implements an implicit convex hull of an array of vertices. ...
int getShapeType() const
void setAngularUpperLimit(const btVector3 &angularUpper)
The btTriangleInfoMap stores edge angle information for some triangles. You can compute this informat...
btQuantizedBvhFloatData * m_quantizedFloatBvh
btTransformDoubleData m_rbAFrame
The btCompoundShape allows to store multiple other btCollisionShapes This allows for moving concave c...
void updateBound()
performs refit operation
void deSerializeFloat(const struct btVector3FloatData &dataIn)
Definition: btVector3.h:1319
btCollisionShapeData * m_childShape
btAlignedObjectArray< btTriangleIndexVertexArray * > m_allocatedTriangleIndexArrays
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 th...
The btStaticPlaneShape simulates an infinite non-moving (static) collision plane. ...
void deSerializeDouble(const struct btTransformDoubleData &dataIn)
Definition: btTransform.h:292
btAlignedObjectArray< btCollisionObject * > m_allocatedRigidBodies
void setLinearUpperLimit(const btVector3 &linearUpper)
virtual ~btWorldImporter()
btTransformDoubleData m_rbAFrame
btVector3FloatData m_localScaling
btDynamicsWorld * m_dynamicsWorld
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btAlignedObjectArray< btVector3FloatData * > m_floatVertexArrays
void setAngularFactor(const btVector3 &angFac)
Definition: btRigidBody.h:490
btHashMap< btHashPtr, const char * > m_objectNameMap
btTransform inverse() const
Return the inverse of this transform.
Definition: btTransform.h:188
btContactSolverInfo & getSolverInfo()
btVector3DoubleData m_origin
Definition: btTransform.h:262
virtual btCollisionShape * createCapsuleShapeX(btScalar radius, btScalar height)
void setAngularLowerLimit(const btVector3 &angularLower)
Generic 6 DOF constraint that allows to set spring motors to any translational and rotational DOF...
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btHashMap< btHashString, btRigidBody * > m_nameBodyMap
virtual class btMultiSphereShape * createMultiSphereShape(const btVector3 *positions, const btScalar *radi, int numSpheres)
const btScalar & getX() const
Return the x value.
Definition: btVector3.h:561
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
void convertConstraintDouble(btTypedConstraintDoubleData *constraintData, btRigidBody *rbA, btRigidBody *rbB, int fileVersion)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278
PHY_ScalarType m_vertexType
btVector3FloatData m_linearFactor
Definition: btRigidBody.h:568
const unsigned char * m_vertexBase
void enableAngularMotor(bool enableMotor, btScalar targetVelocity, btScalar maxMotorImpulse)
int getNumBvhs() const
btTransformFloatData m_rbBFrame
virtual void setMargin(btScalar margin)
btVector3DoubleData * m_vertices3d