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"
18 #ifdef USE_GIMPACT
20 #endif
22 :m_dynamicsWorld(world),
23 m_verboseMode(0),
24 m_importerFlags(0)
25 {
26 
27 }
28 
30 {
31 }
32 
34 {
35  int i;
36  for (i=0;i<m_allocatedConstraints.size();i++)
37  {
38  if(m_dynamicsWorld)
40  delete m_allocatedConstraints[i];
41  }
43 
44 
45  for (i=0;i<m_allocatedRigidBodies.size();i++)
46  {
47  if(m_dynamicsWorld)
49  delete m_allocatedRigidBodies[i];
50  }
51 
53 
54 
55  for (i=0;i<m_allocatedCollisionShapes.size();i++)
56  {
58  }
60 
61 
62  for (i=0;i<m_allocatedBvhs.size();i++)
63  {
64  delete m_allocatedBvhs[i];
65  }
67 
68  for (i=0;i<m_allocatedTriangleInfoMaps.size();i++)
69  {
71  }
73  for (i=0;i<m_allocatedTriangleIndexArrays.size();i++)
74  {
76  }
78  for (i=0;i<m_allocatedNames.size();i++)
79  {
80  delete[] m_allocatedNames[i];
81  }
83 
85  {
87 
88  for(int a = 0;a < curData->m_numMeshParts;a++)
89  {
90  btMeshPartData* curPart = &curData->m_meshPartsPtr[a];
91  if(curPart->m_vertices3f)
92  delete [] curPart->m_vertices3f;
93 
94  if(curPart->m_vertices3d)
95  delete [] curPart->m_vertices3d;
96 
97  if(curPart->m_indices32)
98  delete [] curPart->m_indices32;
99 
100  if(curPart->m_3indices16)
101  delete [] curPart->m_3indices16;
102 
103  if(curPart->m_indices16)
104  delete [] curPart->m_indices16;
105 
106  if (curPart->m_3indices8)
107  delete [] curPart->m_3indices8;
108 
109  }
110  delete [] curData->m_meshPartsPtr;
111  delete curData;
112  }
114 
115  for (i=0;i<m_indexArrays.size();i++)
116  {
118  }
120 
121  for (i=0;i<m_shortIndexArrays.size();i++)
122  {
124  }
126 
127  for (i=0;i<m_charIndexArrays.size();i++)
128  {
130  }
132 
133  for (i=0;i<m_floatVertexArrays.size();i++)
134  {
136  }
138 
139  for (i=0;i<m_doubleVertexArrays.size();i++)
140  {
142  }
144 
145 
146 }
147 
148 
149 
151 {
152  btCollisionShape* shape = 0;
153 
154  switch (shapeData->m_shapeType)
155  {
157  {
158  btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*)shapeData;
159  btVector3 planeNormal,localScaling;
160  planeNormal.deSerializeFloat(planeData->m_planeNormal);
161  localScaling.deSerializeFloat(planeData->m_localScaling);
162  shape = createPlaneShape(planeNormal,planeData->m_planeConstant);
163  shape->setLocalScaling(localScaling);
164 
165  break;
166  }
168  {
170  btCollisionShapeData* colShapeData = (btCollisionShapeData*) &scaledMesh->m_trimeshShapeData;
172  btCollisionShape* childShape = convertCollisionShape(colShapeData);
173  btBvhTriangleMeshShape* meshShape = (btBvhTriangleMeshShape*)childShape;
174  btVector3 localScaling;
175  localScaling.deSerializeFloat(scaledMesh->m_localScaling);
176 
177  shape = createScaledTrangleMeshShape(meshShape, localScaling);
178  break;
179  }
181  {
182 #ifdef USE_GIMPACT
183  btGImpactMeshShapeData* gimpactData = (btGImpactMeshShapeData*) shapeData;
184  if (gimpactData->m_gimpactSubType == CONST_GIMPACT_TRIMESH_SHAPE)
185  {
187  btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
188 
189 
190  btGImpactMeshShape* gimpactShape = createGimpactShape(meshInterface);
191  btVector3 localScaling;
192  localScaling.deSerializeFloat(gimpactData->m_localScaling);
193  gimpactShape->setLocalScaling(localScaling);
194  gimpactShape->setMargin(btScalar(gimpactData->m_collisionMargin));
195  gimpactShape->updateBound();
196  shape = gimpactShape;
197  } else
198  {
199  printf("unsupported gimpact sub type\n");
200  }
201 #endif//USE_GIMPACT
202  break;
203  }
204  //The btCapsuleShape* API has issue passing the margin/scaling/halfextents unmodified through the API
205  //so deal with this
207  {
208  btCapsuleShapeData* capData = (btCapsuleShapeData*)shapeData;
209 
210 
211  switch (capData->m_upAxis)
212  {
213  case 0:
214  {
215  shape = createCapsuleShapeX(1,1);
216  break;
217  }
218  case 1:
219  {
220  shape = createCapsuleShapeY(1,1);
221  break;
222  }
223  case 2:
224  {
225  shape = createCapsuleShapeZ(1,1);
226  break;
227  }
228  default:
229  {
230  printf("error: wrong up axis for btCapsuleShape\n");
231  }
232 
233 
234  };
235  if (shape)
236  {
237  btCapsuleShape* cap = (btCapsuleShape*) shape;
238  cap->deSerializeFloat(capData);
239  }
240  break;
241  }
244  case BOX_SHAPE_PROXYTYPE:
248  {
250  btVector3 implicitShapeDimensions;
251  implicitShapeDimensions.deSerializeFloat(bsd->m_implicitShapeDimensions);
252  btVector3 localScaling;
253  localScaling.deSerializeFloat(bsd->m_localScaling);
255  switch (shapeData->m_shapeType)
256  {
257  case BOX_SHAPE_PROXYTYPE:
258  {
259  btBoxShape* box= (btBoxShape*)createBoxShape(implicitShapeDimensions/localScaling+margin);
260  //box->initializePolyhedralFeatures();
261  shape = box;
262 
263  break;
264  }
266  {
267  shape = createSphereShape(implicitShapeDimensions.getX());
268  break;
269  }
270 
272  {
273  btCylinderShapeData* cylData = (btCylinderShapeData*) shapeData;
274  btVector3 halfExtents = implicitShapeDimensions+margin;
275  switch (cylData->m_upAxis)
276  {
277  case 0:
278  {
279  shape = createCylinderShapeX(halfExtents.getY(),halfExtents.getX());
280  break;
281  }
282  case 1:
283  {
284  shape = createCylinderShapeY(halfExtents.getX(),halfExtents.getY());
285  break;
286  }
287  case 2:
288  {
289  shape = createCylinderShapeZ(halfExtents.getX(),halfExtents.getZ());
290  break;
291  }
292  default:
293  {
294  printf("unknown Cylinder up axis\n");
295  }
296 
297  };
298 
299 
300 
301  break;
302  }
304  {
305  btConeShapeData* conData = (btConeShapeData*) shapeData;
306  btVector3 halfExtents = implicitShapeDimensions;//+margin;
307  switch (conData->m_upIndex)
308  {
309  case 0:
310  {
311  shape = createConeShapeX(halfExtents.getY(),halfExtents.getX());
312  break;
313  }
314  case 1:
315  {
316  shape = createConeShapeY(halfExtents.getX(),halfExtents.getY());
317  break;
318  }
319  case 2:
320  {
321  shape = createConeShapeZ(halfExtents.getX(),halfExtents.getZ());
322  break;
323  }
324  default:
325  {
326  printf("unknown Cone up axis\n");
327  }
328 
329  };
330 
331 
332 
333  break;
334  }
336  {
338  int numSpheres = mss->m_localPositionArraySize;
339 
342  radii.resize(numSpheres);
343  tmpPos.resize(numSpheres);
344  int i;
345  for ( i=0;i<numSpheres;i++)
346  {
347  tmpPos[i].deSerializeFloat(mss->m_localPositionArrayPtr[i].m_pos);
348  radii[i] = mss->m_localPositionArrayPtr[i].m_radius;
349  }
350  shape = createMultiSphereShape(&tmpPos[0],&radii[0],numSpheres);
351  break;
352  }
354  {
355  // int sz = sizeof(btConvexHullShapeData);
356  // int sz2 = sizeof(btConvexInternalShapeData);
357  // int sz3 = sizeof(btCollisionShapeData);
358  btConvexHullShapeData* convexData = (btConvexHullShapeData*)bsd;
359  int numPoints = convexData->m_numUnscaledPoints;
360 
362  tmpPoints.resize(numPoints);
363  int i;
364  for ( i=0;i<numPoints;i++)
365  {
366 #ifdef BT_USE_DOUBLE_PRECISION
367  if (convexData->m_unscaledPointsDoublePtr)
368  tmpPoints[i].deSerialize(convexData->m_unscaledPointsDoublePtr[i]);
369  if (convexData->m_unscaledPointsFloatPtr)
370  tmpPoints[i].deSerializeFloat(convexData->m_unscaledPointsFloatPtr[i]);
371 #else
372  if (convexData->m_unscaledPointsFloatPtr)
373  tmpPoints[i].deSerialize(convexData->m_unscaledPointsFloatPtr[i]);
374  if (convexData->m_unscaledPointsDoublePtr)
375  tmpPoints[i].deSerializeDouble(convexData->m_unscaledPointsDoublePtr[i]);
376 #endif //BT_USE_DOUBLE_PRECISION
377  }
379  for (i=0;i<numPoints;i++)
380  {
381  hullShape->addPoint(tmpPoints[i]);
382  }
383  hullShape->setMargin(bsd->m_collisionMargin);
384  //hullShape->initializePolyhedralFeatures();
385  shape = hullShape;
386  break;
387  }
388  default:
389  {
390  printf("error: cannot create shape type (%d)\n",shapeData->m_shapeType);
391  }
392  }
393 
394  if (shape)
395  {
396  shape->setMargin(bsd->m_collisionMargin);
397 
398  btVector3 localScaling;
399  localScaling.deSerializeFloat(bsd->m_localScaling);
400  shape->setLocalScaling(localScaling);
401 
402  }
403  break;
404  }
406  {
407  btTriangleMeshShapeData* trimesh = (btTriangleMeshShapeData*)shapeData;
409  btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
410  if (!meshInterface->getNumSubParts())
411  {
412  return 0;
413  }
414 
415  btVector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling);
416  meshInterface->setScaling(scaling);
417 
418 
419  btOptimizedBvh* bvh = 0;
420 #if 1
421  if (trimesh->m_quantizedFloatBvh)
422  {
423  btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedFloatBvh);
424  if (bvhPtr && *bvhPtr)
425  {
426  bvh = *bvhPtr;
427  } else
428  {
429  bvh = createOptimizedBvh();
430  bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh);
431  }
432  }
433  if (trimesh->m_quantizedDoubleBvh)
434  {
435  btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedDoubleBvh);
436  if (bvhPtr && *bvhPtr)
437  {
438  bvh = *bvhPtr;
439  } else
440  {
441  bvh = createOptimizedBvh();
442  bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh);
443  }
444  }
445 #endif
446 
447 
448  btBvhTriangleMeshShape* trimeshShape = createBvhTriangleMeshShape(meshInterface,bvh);
449  trimeshShape->setMargin(trimesh->m_collisionMargin);
450  shape = trimeshShape;
451 
452  if (trimesh->m_triangleInfoMap)
453  {
455  map->deSerialize(*trimesh->m_triangleInfoMap);
456  trimeshShape->setTriangleInfoMap(map);
457 
458 #ifdef USE_INTERNAL_EDGE_UTILITY
459  gContactAddedCallback = btAdjustInternalEdgeContactsCallback;
460 #endif //USE_INTERNAL_EDGE_UTILITY
461 
462  }
463 
464  //printf("trimesh->m_collisionMargin=%f\n",trimesh->m_collisionMargin);
465  break;
466  }
468  {
469  btCompoundShapeData* compoundData = (btCompoundShapeData*)shapeData;
470  btCompoundShape* compoundShape = createCompoundShape();
471 
472 
474  for (int i=0;i<compoundData->m_numChildShapes;i++)
475  {
476 
477  btCollisionShapeData* cd = compoundData->m_childShapePtr[i].m_childShape;
478 
479  btCollisionShape* childShape = convertCollisionShape(cd);
480  if (childShape)
481  {
482  btTransform localTransform;
483  localTransform.deSerializeFloat(compoundData->m_childShapePtr[i].m_transform);
484  compoundShape->addChildShape(localTransform,childShape);
485  } else
486  {
487 #ifdef _DEBUG
488  printf("error: couldn't create childShape for compoundShape\n");
489 #endif
490  }
491 
492  }
493  shape = compoundShape;
494 
495  break;
496  }
498  {
499  return 0;
500  }
501  default:
502  {
503 #ifdef _DEBUG
504  printf("unsupported shape type (%d)\n",shapeData->m_shapeType);
505 #endif
506  }
507  }
508 
509  return shape;
510 
511 }
512 
513 
514 
515 char* btWorldImporter::duplicateName(const char* name)
516 {
517  if (name)
518  {
519  int l = (int)strlen(name);
520  char* newName = new char[l+1];
521  memcpy(newName,name,l);
522  newName[l] = 0;
523  m_allocatedNames.push_back(newName);
524  return newName;
525  }
526  return 0;
527 }
528 
530 {
531 
532  btTypedConstraint* constraint = 0;
533 
534  switch (constraintData->m_objectType)
535  {
537  {
539  if (rbA && rbB)
540  {
541  btVector3 pivotInA,pivotInB;
542  pivotInA.deSerializeDouble(p2pData->m_pivotInA);
543  pivotInB.deSerializeDouble(p2pData->m_pivotInB);
544  constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
545  } else
546  {
547  btVector3 pivotInA;
548  pivotInA.deSerializeDouble(p2pData->m_pivotInA);
549  constraint = createPoint2PointConstraint(*rbA,pivotInA);
550  }
551  break;
552  }
554  {
555  btHingeConstraint* hinge = 0;
556 
557  btHingeConstraintDoubleData* hingeData = (btHingeConstraintDoubleData*)constraintData;
558  if (rbA&& rbB)
559  {
560  btTransform rbAFrame,rbBFrame;
561  rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
562  rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
563  hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
564  } else
565  {
566  btTransform rbAFrame;
567  rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
568  hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
569  }
570  if (hingeData->m_enableAngularMotor)
571  {
572  hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse);
573  }
574  hinge->setAngularOnly(hingeData->m_angularOnly!=0);
575  hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
576 
577  constraint = hinge;
578  break;
579 
580  }
582  {
583  btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData;
584  btConeTwistConstraint* coneTwist = 0;
585 
586  if (rbA&& rbB)
587  {
588  btTransform rbAFrame,rbBFrame;
589  rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
590  rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
591  coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
592  } else
593  {
594  btTransform rbAFrame;
595  rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
596  coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
597  }
598  coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness,
599  (btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor);
600  coneTwist->setDamping((btScalar)coneData->m_damping);
601 
602  constraint = coneTwist;
603  break;
604  }
605 
607  {
608 
610  // int sz = sizeof(btGeneric6DofSpringConstraintData);
612 
613  if (rbA && rbB)
614  {
615  btTransform rbAFrame,rbBFrame;
616  rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame);
617  rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame);
618  dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
619  } else
620  {
621  printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
622  }
623 
624  if (dof)
625  {
626  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
627  angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit);
628  angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit);
629  linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit);
630  linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit);
631 
632  angLowerLimit.setW(0.f);
633  dof->setAngularLowerLimit(angLowerLimit);
634  dof->setAngularUpperLimit(angUpperLimit);
635  dof->setLinearLowerLimit(linLowerLimit);
636  dof->setLinearUpperLimit(linUpperlimit);
637 
638  int i;
639  if (fileVersion>280)
640  {
641  for (i=0;i<6;i++)
642  {
643  dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]);
644  dof->setEquilibriumPoint(i,(btScalar)dofData->m_equilibriumPoint[i]);
645  dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
646  dof->setDamping(i,(btScalar)dofData->m_springDamping[i]);
647  }
648  }
649  }
650 
651  constraint = dof;
652  break;
653 
654  }
655  case D6_CONSTRAINT_TYPE:
656  {
657  btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData;
658  btGeneric6DofConstraint* dof = 0;
659 
660  if (rbA&& rbB)
661  {
662  btTransform rbAFrame,rbBFrame;
663  rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
664  rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
665  dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
666  } else
667  {
668  if (rbB)
669  {
670  btTransform rbBFrame;
671  rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
672  dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
673  } else
674  {
675  printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
676  }
677  }
678 
679  if (dof)
680  {
681  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
682  angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
683  angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit);
684  linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit);
685  linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit);
686 
687  dof->setAngularLowerLimit(angLowerLimit);
688  dof->setAngularUpperLimit(angUpperLimit);
689  dof->setLinearLowerLimit(linLowerLimit);
690  dof->setLinearUpperLimit(linUpperlimit);
691  }
692 
693  constraint = dof;
694  break;
695  }
697  {
698  btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData;
699  btSliderConstraint* slider = 0;
700  if (rbA&& rbB)
701  {
702  btTransform rbAFrame,rbBFrame;
703  rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
704  rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
705  slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
706  } else
707  {
708  btTransform rbBFrame;
709  rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
710  slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
711  }
712  slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit);
713  slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit);
714  slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit);
715  slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit);
716  slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
717  constraint = slider;
718  break;
719  }
720 
721  default:
722  {
723  printf("unknown constraint type\n");
724  }
725  };
726 
727  if (constraint)
728  {
729  constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize);
731  if (fileVersion>=280)
732  {
734  constraint->setEnabled(constraintData->m_isEnabled!=0);
736  }
737 
738  if (constraintData->m_name)
739  {
740  char* newname = duplicateName(constraintData->m_name);
741  m_nameConstraintMap.insert(newname,constraint);
742  m_objectNameMap.insert(constraint,newname);
743  }
744  if(m_dynamicsWorld)
746  }
747 
748 }
749 
751 {
752  btTypedConstraint* constraint = 0;
753 
754  switch (constraintData->m_objectType)
755  {
757  {
759  if (rbA&& rbB)
760  {
761  btVector3 pivotInA,pivotInB;
762  pivotInA.deSerializeFloat(p2pData->m_pivotInA);
763  pivotInB.deSerializeFloat(p2pData->m_pivotInB);
764  constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
765 
766  } else
767  {
768  btVector3 pivotInA;
769  pivotInA.deSerializeFloat(p2pData->m_pivotInA);
770  constraint = createPoint2PointConstraint(*rbA,pivotInA);
771  }
772  break;
773  }
775  {
776  btHingeConstraint* hinge = 0;
777  btHingeConstraintFloatData* hingeData = (btHingeConstraintFloatData*)constraintData;
778  if (rbA&& rbB)
779  {
780  btTransform rbAFrame,rbBFrame;
781  rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
782  rbBFrame.deSerializeFloat(hingeData->m_rbBFrame);
783  hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
784  } else
785  {
786  btTransform rbAFrame;
787  rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
788  hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
789  }
790  if (hingeData->m_enableAngularMotor)
791  {
792  hinge->enableAngularMotor(true,hingeData->m_motorTargetVelocity,hingeData->m_maxMotorImpulse);
793  }
794  hinge->setAngularOnly(hingeData->m_angularOnly!=0);
795  hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
796 
797  constraint = hinge;
798  break;
799 
800  }
802  {
803  btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData;
804  btConeTwistConstraint* coneTwist = 0;
805 
806  if (rbA&& rbB)
807  {
808  btTransform rbAFrame,rbBFrame;
809  rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
810  rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
811  coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
812  } else
813  {
814  btTransform rbAFrame;
815  rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
816  coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
817  }
818  coneTwist->setLimit(coneData->m_swingSpan1,coneData->m_swingSpan2,coneData->m_twistSpan,coneData->m_limitSoftness,coneData->m_biasFactor,coneData->m_relaxationFactor);
819  coneTwist->setDamping(coneData->m_damping);
820 
821  constraint = coneTwist;
822  break;
823  }
824 
826  {
827 
829  // int sz = sizeof(btGeneric6DofSpringConstraintData);
831 
832  if (rbA && rbB)
833  {
834  btTransform rbAFrame,rbBFrame;
835  rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame);
836  rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame);
837  dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
838  } else
839  {
840  printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
841  }
842 
843  if (dof)
844  {
845  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
846  angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit);
847  angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit);
848  linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit);
849  linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit);
850 
851  angLowerLimit.setW(0.f);
852  dof->setAngularLowerLimit(angLowerLimit);
853  dof->setAngularUpperLimit(angUpperLimit);
854  dof->setLinearLowerLimit(linLowerLimit);
855  dof->setLinearUpperLimit(linUpperlimit);
856 
857  int i;
858  if (fileVersion>280)
859  {
860  for (i=0;i<6;i++)
861  {
862  dof->setStiffness(i,dofData->m_springStiffness[i]);
863  dof->setEquilibriumPoint(i,dofData->m_equilibriumPoint[i]);
864  dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
865  dof->setDamping(i,dofData->m_springDamping[i]);
866  }
867  }
868  }
869 
870  constraint = dof;
871  break;
872  }
873  case D6_CONSTRAINT_TYPE:
874  {
875  btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData;
876  btGeneric6DofConstraint* dof = 0;
877 
878  if (rbA&& rbB)
879  {
880  btTransform rbAFrame,rbBFrame;
881  rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
882  rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
883  dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
884  } else
885  {
886  if (rbB)
887  {
888  btTransform rbBFrame;
889  rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
890  dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
891  } else
892  {
893  printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
894  }
895  }
896 
897  if (dof)
898  {
899  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
900  angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
901  angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit);
902  linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit);
903  linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit);
904 
905  dof->setAngularLowerLimit(angLowerLimit);
906  dof->setAngularUpperLimit(angUpperLimit);
907  dof->setLinearLowerLimit(linLowerLimit);
908  dof->setLinearUpperLimit(linUpperlimit);
909  }
910 
911  constraint = dof;
912  break;
913  }
915  {
916  btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData;
917  btSliderConstraint* slider = 0;
918  if (rbA&& rbB)
919  {
920  btTransform rbAFrame,rbBFrame;
921  rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
922  rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
923  slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
924  } else
925  {
926  btTransform rbBFrame;
927  rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
928  slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
929  }
930  slider->setLowerLinLimit(sliderData->m_linearLowerLimit);
931  slider->setUpperLinLimit(sliderData->m_linearUpperLimit);
932  slider->setLowerAngLimit(sliderData->m_angularLowerLimit);
933  slider->setUpperAngLimit(sliderData->m_angularUpperLimit);
934  slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
935  constraint = slider;
936  break;
937  }
939  {
940  btGearConstraintFloatData* gearData = (btGearConstraintFloatData*) constraintData;
941  btGearConstraint* gear = 0;
942  if (rbA&&rbB)
943  {
944  btVector3 axisInA,axisInB;
945  axisInA.deSerializeFloat(gearData->m_axisInA);
946  axisInB.deSerializeFloat(gearData->m_axisInB);
947  gear = createGearConstraint(*rbA, *rbB, axisInA,axisInB, gearData->m_ratio);
948  } else
949  {
950  btAssert(0);
951  //perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized?
952  //btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio=1.f);
953  }
954  constraint = gear;
955  break;
956  }
958  {
959 
961 
963 
964  if (rbA && rbB)
965  {
966  btTransform rbAFrame,rbBFrame;
967  rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
968  rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
969  dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, dofData->m_rotateOrder);
970  } else
971  {
972  printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
973  }
974 
975  if (dof)
976  {
977  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
978  angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
979  angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit);
980  linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit);
981  linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit);
982 
983  angLowerLimit.setW(0.f);
984  dof->setAngularLowerLimit(angLowerLimit);
985  dof->setAngularUpperLimit(angUpperLimit);
986  dof->setLinearLowerLimit(linLowerLimit);
987  dof->setLinearUpperLimit(linUpperlimit);
988 
989  int i;
990  if (fileVersion>280)
991  {
992  //6-dof: 3 linear followed by 3 angular
993  for (i=0;i<3;i++)
994  {
997  dof->enableSpring(i,dofData->m_linearEnableSpring[i]!=0);
998  dof->setDamping(i,dofData->m_linearSpringDamping.m_floats[i],(dofData->m_linearSpringDampingLimited[i]!=0));
999  }
1000  for (i=0;i<3;i++)
1001  {
1002  dof->setStiffness(i+3,dofData->m_angularSpringStiffness.m_floats[i],(dofData->m_angularSpringStiffnessLimited[i]!=0));
1004  dof->enableSpring(i+3,dofData->m_angularEnableSpring[i]!=0);
1005  dof->setDamping(i+3,dofData->m_angularSpringDamping.m_floats[i],dofData->m_angularSpringDampingLimited[i]);
1006  }
1007 
1008  }
1009  }
1010 
1011  constraint = dof;
1012  break;
1013 
1014  }
1015  case FIXED_CONSTRAINT_TYPE:
1016  {
1017 
1019  if (rbA && rbB)
1020  {
1021  btTransform rbAFrame,rbBFrame;
1022  //compute a shared world frame, and compute frameInA, frameInB relative to this
1023  btTransform sharedFrame;
1024  sharedFrame.setIdentity();
1025  btVector3 centerPos = btScalar(0.5)*(rbA->getWorldTransform().getOrigin()+
1026  rbB->getWorldTransform().getOrigin());
1027  sharedFrame.setOrigin(centerPos);
1028  rbAFrame = rbA->getWorldTransform().inverse()*sharedFrame;
1029  rbBFrame = rbB->getWorldTransform().inverse()*sharedFrame;
1030 
1031 
1032  dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, RO_XYZ);
1033  dof->setLinearUpperLimit(btVector3(0,0,0));
1034  dof->setLinearLowerLimit(btVector3(0,0,0));
1035  dof->setAngularUpperLimit(btVector3(0,0,0));
1036  dof->setAngularLowerLimit(btVector3(0,0,0));
1037 
1038  } else
1039  {
1040  printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
1041  }
1042 
1043  constraint = dof;
1044  break;
1045  }
1046  default:
1047  {
1048  printf("unknown constraint type\n");
1049  }
1050  };
1051 
1052  if (constraint)
1053  {
1054  constraint->setDbgDrawSize(constraintData->m_dbgDrawSize);
1056  if (fileVersion>=280)
1057  {
1058  constraint->setBreakingImpulseThreshold(constraintData->m_breakingImpulseThreshold);
1059  constraint->setEnabled(constraintData->m_isEnabled!=0);
1061  }
1062 
1063  if (constraintData->m_name)
1064  {
1065  char* newname = duplicateName(constraintData->m_name);
1066  m_nameConstraintMap.insert(newname,constraint);
1067  m_objectNameMap.insert(constraint,newname);
1068  }
1069  if(m_dynamicsWorld)
1071  }
1072 
1073 
1074 }
1075 
1076 
1077 
1079 {
1080  btTypedConstraint* constraint = 0;
1081 
1082  switch (constraintData->m_objectType)
1083  {
1085  {
1087  if (rbA && rbB)
1088  {
1089  btVector3 pivotInA,pivotInB;
1090  pivotInA.deSerializeDouble(p2pData->m_pivotInA);
1091  pivotInB.deSerializeDouble(p2pData->m_pivotInB);
1092  constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
1093  } else
1094  {
1095  btVector3 pivotInA;
1096  pivotInA.deSerializeDouble(p2pData->m_pivotInA);
1097  constraint = createPoint2PointConstraint(*rbA,pivotInA);
1098  }
1099  break;
1100  }
1101  case HINGE_CONSTRAINT_TYPE:
1102  {
1103  btHingeConstraint* hinge = 0;
1104 
1105  btHingeConstraintDoubleData2* hingeData = (btHingeConstraintDoubleData2*)constraintData;
1106  if (rbA&& rbB)
1107  {
1108  btTransform rbAFrame,rbBFrame;
1109  rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
1110  rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
1111  hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
1112  } else
1113  {
1114  btTransform rbAFrame;
1115  rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
1116  hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
1117  }
1118  if (hingeData->m_enableAngularMotor)
1119  {
1120  hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse);
1121  }
1122  hinge->setAngularOnly(hingeData->m_angularOnly!=0);
1123  hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
1124 
1125  constraint = hinge;
1126  break;
1127 
1128  }
1130  {
1132  btConeTwistConstraint* coneTwist = 0;
1133 
1134  if (rbA&& rbB)
1135  {
1136  btTransform rbAFrame,rbBFrame;
1137  rbAFrame.deSerializeDouble(coneData->m_rbAFrame);
1138  rbBFrame.deSerializeDouble(coneData->m_rbBFrame);
1139  coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
1140  } else
1141  {
1142  btTransform rbAFrame;
1143  rbAFrame.deSerializeDouble(coneData->m_rbAFrame);
1144  coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
1145  }
1146  coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness,
1147  (btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor);
1148  coneTwist->setDamping((btScalar)coneData->m_damping);
1149 
1150  constraint = coneTwist;
1151  break;
1152  }
1153 
1155  {
1156 
1158  // int sz = sizeof(btGeneric6DofSpringConstraintData);
1160 
1161  if (rbA && rbB)
1162  {
1163  btTransform rbAFrame,rbBFrame;
1164  rbAFrame.deSerializeDouble(dofData->m_6dofData.m_rbAFrame);
1165  rbBFrame.deSerializeDouble(dofData->m_6dofData.m_rbBFrame);
1166  dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
1167  } else
1168  {
1169  printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
1170  }
1171 
1172  if (dof)
1173  {
1174  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
1175  angLowerLimit.deSerializeDouble(dofData->m_6dofData.m_angularLowerLimit);
1176  angUpperLimit.deSerializeDouble(dofData->m_6dofData.m_angularUpperLimit);
1177  linLowerLimit.deSerializeDouble(dofData->m_6dofData.m_linearLowerLimit);
1178  linUpperlimit.deSerializeDouble(dofData->m_6dofData.m_linearUpperLimit);
1179 
1180  angLowerLimit.setW(0.f);
1181  dof->setAngularLowerLimit(angLowerLimit);
1182  dof->setAngularUpperLimit(angUpperLimit);
1183  dof->setLinearLowerLimit(linLowerLimit);
1184  dof->setLinearUpperLimit(linUpperlimit);
1185 
1186  int i;
1187  if (fileVersion>280)
1188  {
1189  for (i=0;i<6;i++)
1190  {
1191  dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]);
1192  dof->setEquilibriumPoint(i,(btScalar)dofData->m_equilibriumPoint[i]);
1193  dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
1194  dof->setDamping(i,(btScalar)dofData->m_springDamping[i]);
1195  }
1196  }
1197  }
1198 
1199  constraint = dof;
1200  break;
1201  }
1202  case D6_CONSTRAINT_TYPE:
1203  {
1205  btGeneric6DofConstraint* dof = 0;
1206 
1207  if (rbA&& rbB)
1208  {
1209  btTransform rbAFrame,rbBFrame;
1210  rbAFrame.deSerializeDouble(dofData->m_rbAFrame);
1211  rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
1212  dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
1213  } else
1214  {
1215  if (rbB)
1216  {
1217  btTransform rbBFrame;
1218  rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
1219  dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
1220  } else
1221  {
1222  printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
1223  }
1224  }
1225 
1226  if (dof)
1227  {
1228  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
1229  angLowerLimit.deSerializeDouble(dofData->m_angularLowerLimit);
1230  angUpperLimit.deSerializeDouble(dofData->m_angularUpperLimit);
1231  linLowerLimit.deSerializeDouble(dofData->m_linearLowerLimit);
1232  linUpperlimit.deSerializeDouble(dofData->m_linearUpperLimit);
1233 
1234  dof->setAngularLowerLimit(angLowerLimit);
1235  dof->setAngularUpperLimit(angUpperLimit);
1236  dof->setLinearLowerLimit(linLowerLimit);
1237  dof->setLinearUpperLimit(linUpperlimit);
1238  }
1239 
1240  constraint = dof;
1241  break;
1242  }
1244  {
1245  btSliderConstraintDoubleData* sliderData = (btSliderConstraintDoubleData*)constraintData;
1246  btSliderConstraint* slider = 0;
1247  if (rbA&& rbB)
1248  {
1249  btTransform rbAFrame,rbBFrame;
1250  rbAFrame.deSerializeDouble(sliderData->m_rbAFrame);
1251  rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
1252  slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
1253  } else
1254  {
1255  btTransform rbBFrame;
1256  rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
1257  slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
1258  }
1259  slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit);
1260  slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit);
1261  slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit);
1262  slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit);
1263  slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
1264  constraint = slider;
1265  break;
1266  }
1267  case GEAR_CONSTRAINT_TYPE:
1268  {
1269  btGearConstraintDoubleData* gearData = (btGearConstraintDoubleData*) constraintData;
1270  btGearConstraint* gear = 0;
1271  if (rbA&&rbB)
1272  {
1273  btVector3 axisInA,axisInB;
1274  axisInA.deSerializeDouble(gearData->m_axisInA);
1275  axisInB.deSerializeDouble(gearData->m_axisInB);
1276  gear = createGearConstraint(*rbA, *rbB, axisInA,axisInB, gearData->m_ratio);
1277  } else
1278  {
1279  btAssert(0);
1280  //perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized?
1281  //btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio=1.f);
1282  }
1283  constraint = gear;
1284  break;
1285  }
1286 
1288  {
1289 
1291 
1293 
1294  if (rbA && rbB)
1295  {
1296  btTransform rbAFrame,rbBFrame;
1297  rbAFrame.deSerializeDouble(dofData->m_rbAFrame);
1298  rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
1299  dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, dofData->m_rotateOrder);
1300  } else
1301  {
1302  printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
1303  }
1304 
1305  if (dof)
1306  {
1307  btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
1308  angLowerLimit.deSerializeDouble(dofData->m_angularLowerLimit);
1309  angUpperLimit.deSerializeDouble(dofData->m_angularUpperLimit);
1310  linLowerLimit.deSerializeDouble(dofData->m_linearLowerLimit);
1311  linUpperlimit.deSerializeDouble(dofData->m_linearUpperLimit);
1312 
1313  angLowerLimit.setW(0.f);
1314  dof->setAngularLowerLimit(angLowerLimit);
1315  dof->setAngularUpperLimit(angUpperLimit);
1316  dof->setLinearLowerLimit(linLowerLimit);
1317  dof->setLinearUpperLimit(linUpperlimit);
1318 
1319  int i;
1320  if (fileVersion>280)
1321  {
1322  //6-dof: 3 linear followed by 3 angular
1323  for (i=0;i<3;i++)
1324  {
1327  dof->enableSpring(i,dofData->m_linearEnableSpring[i]!=0);
1328  dof->setDamping(i,dofData->m_linearSpringDamping.m_floats[i],(dofData->m_linearSpringDampingLimited[i]!=0));
1329  }
1330  for (i=0;i<3;i++)
1331  {
1332  dof->setStiffness(i+3,dofData->m_angularSpringStiffness.m_floats[i],(dofData->m_angularSpringStiffnessLimited[i]!=0));
1334  dof->enableSpring(i+3,dofData->m_angularEnableSpring[i]!=0);
1335  dof->setDamping(i+3,dofData->m_angularSpringDamping.m_floats[i],(dofData->m_angularSpringDampingLimited[i]!=0));
1336  }
1337 
1338  }
1339  }
1340 
1341  constraint = dof;
1342  break;
1343 
1344  }
1345  case FIXED_CONSTRAINT_TYPE:
1346  {
1347 
1349  if (rbA && rbB)
1350  {
1351  btTransform rbAFrame,rbBFrame;
1352  //compute a shared world frame, and compute frameInA, frameInB relative to this
1353  btTransform sharedFrame;
1354  sharedFrame.setIdentity();
1355  btVector3 centerPos = btScalar(0.5)*(rbA->getWorldTransform().getOrigin()+
1356  rbB->getWorldTransform().getOrigin());
1357  sharedFrame.setOrigin(centerPos);
1358  rbAFrame = rbA->getWorldTransform().inverse()*sharedFrame;
1359  rbBFrame = rbB->getWorldTransform().inverse()*sharedFrame;
1360 
1361 
1362  dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, RO_XYZ);
1363  dof->setLinearUpperLimit(btVector3(0,0,0));
1364  dof->setLinearLowerLimit(btVector3(0,0,0));
1365  dof->setAngularUpperLimit(btVector3(0,0,0));
1366  dof->setAngularLowerLimit(btVector3(0,0,0));
1367 
1368  } else
1369  {
1370  printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
1371  }
1372 
1373  constraint = dof;
1374  break;
1375  }
1376 
1377  default:
1378  {
1379  printf("unknown constraint type\n");
1380  }
1381  };
1382 
1383  if (constraint)
1384  {
1385  constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize);
1387  if (fileVersion>=280)
1388  {
1389  constraint->setBreakingImpulseThreshold((btScalar)constraintData->m_breakingImpulseThreshold);
1390  constraint->setEnabled(constraintData->m_isEnabled!=0);
1392  }
1393 
1394  if (constraintData->m_name)
1395  {
1396  char* newname = duplicateName(constraintData->m_name);
1397  m_nameConstraintMap.insert(newname,constraint);
1398  m_objectNameMap.insert(constraint,newname);
1399  }
1400  if(m_dynamicsWorld)
1402  }
1403 
1404 
1405 }
1406 
1407 
1408 
1409 
1410 
1411 
1412 
1413 
1414 
1415 
1417 {
1419 
1420  for (int i=0;i<meshData.m_numMeshParts;i++)
1421  {
1422  btIndexedMesh meshPart;
1423  meshPart.m_numTriangles = meshData.m_meshPartsPtr[i].m_numTriangles;
1424  meshPart.m_numVertices = meshData.m_meshPartsPtr[i].m_numVertices;
1425 
1426 
1427  if (meshData.m_meshPartsPtr[i].m_indices32)
1428  {
1429  meshPart.m_indexType = PHY_INTEGER;
1430  meshPart.m_triangleIndexStride = 3*sizeof(int);
1431  int* indexArray = (int*)btAlignedAlloc(sizeof(int)*3*meshPart.m_numTriangles,16);
1432  m_indexArrays.push_back(indexArray);
1433  for (int j=0;j<3*meshPart.m_numTriangles;j++)
1434  {
1435  indexArray[j] = meshData.m_meshPartsPtr[i].m_indices32[j].m_value;
1436  }
1437  meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1438  } else
1439  {
1440  if (meshData.m_meshPartsPtr[i].m_3indices16)
1441  {
1442  meshPart.m_indexType = PHY_SHORT;
1443  meshPart.m_triangleIndexStride = sizeof(short int)*3;//sizeof(btShortIntIndexTripletData);
1444 
1445  short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
1446  m_shortIndexArrays.push_back(indexArray);
1447 
1448  for (int j=0;j<meshPart.m_numTriangles;j++)
1449  {
1450  indexArray[3*j] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[0];
1451  indexArray[3*j+1] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[1];
1452  indexArray[3*j+2] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[2];
1453  }
1454 
1455  meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1456  }
1457  if (meshData.m_meshPartsPtr[i].m_indices16)
1458  {
1459  meshPart.m_indexType = PHY_SHORT;
1460  meshPart.m_triangleIndexStride = 3*sizeof(short int);
1461  short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
1462  m_shortIndexArrays.push_back(indexArray);
1463  for (int j=0;j<3*meshPart.m_numTriangles;j++)
1464  {
1465  indexArray[j] = meshData.m_meshPartsPtr[i].m_indices16[j].m_value;
1466  }
1467 
1468  meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1469  }
1470 
1471  if (meshData.m_meshPartsPtr[i].m_3indices8)
1472  {
1473  meshPart.m_indexType = PHY_UCHAR;
1474  meshPart.m_triangleIndexStride = sizeof(unsigned char)*3;
1475 
1476  unsigned char* indexArray = (unsigned char*)btAlignedAlloc(sizeof(unsigned char)*3*meshPart.m_numTriangles,16);
1477  m_charIndexArrays.push_back(indexArray);
1478 
1479  for (int j=0;j<meshPart.m_numTriangles;j++)
1480  {
1481  indexArray[3*j] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[0];
1482  indexArray[3*j+1] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[1];
1483  indexArray[3*j+2] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[2];
1484  }
1485 
1486  meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1487  }
1488  }
1489 
1490  if (meshData.m_meshPartsPtr[i].m_vertices3f)
1491  {
1492  meshPart.m_vertexType = PHY_FLOAT;
1493  meshPart.m_vertexStride = sizeof(btVector3FloatData);
1495  m_floatVertexArrays.push_back(vertices);
1496 
1497  for (int j=0;j<meshPart.m_numVertices;j++)
1498  {
1499  vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[0];
1500  vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[1];
1501  vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[2];
1502  vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[3];
1503  }
1504  meshPart.m_vertexBase = (const unsigned char*)vertices;
1505  } else
1506  {
1507  meshPart.m_vertexType = PHY_DOUBLE;
1508  meshPart.m_vertexStride = sizeof(btVector3DoubleData);
1509 
1510 
1512  m_doubleVertexArrays.push_back(vertices);
1513 
1514  for (int j=0;j<meshPart.m_numVertices;j++)
1515  {
1516  vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[0];
1517  vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[1];
1518  vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[2];
1519  vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[3];
1520  }
1521  meshPart.m_vertexBase = (const unsigned char*)vertices;
1522  }
1523 
1524  if (meshPart.m_triangleIndexBase && meshPart.m_vertexBase)
1525  {
1526  meshInterface->addIndexedMesh(meshPart,meshPart.m_indexType);
1527  }
1528  }
1529 
1530  return meshInterface;
1531 }
1532 
1533 
1535 {
1536  //create a new btStridingMeshInterfaceData that is an exact copy of shapedata and store it in the WorldImporter
1538 
1539  newData->m_scaling = interfaceData->m_scaling;
1540  newData->m_numMeshParts = interfaceData->m_numMeshParts;
1541  newData->m_meshPartsPtr = new btMeshPartData[newData->m_numMeshParts];
1542 
1543  for(int i = 0;i < newData->m_numMeshParts;i++)
1544  {
1545  btMeshPartData* curPart = &interfaceData->m_meshPartsPtr[i];
1546  btMeshPartData* curNewPart = &newData->m_meshPartsPtr[i];
1547 
1548  curNewPart->m_numTriangles = curPart->m_numTriangles;
1549  curNewPart->m_numVertices = curPart->m_numVertices;
1550 
1551  if(curPart->m_vertices3f)
1552  {
1553  curNewPart->m_vertices3f = new btVector3FloatData[curNewPart->m_numVertices];
1554  memcpy(curNewPart->m_vertices3f,curPart->m_vertices3f,sizeof(btVector3FloatData) * curNewPart->m_numVertices);
1555  }
1556  else
1557  curNewPart->m_vertices3f = NULL;
1558 
1559  if(curPart->m_vertices3d)
1560  {
1561  curNewPart->m_vertices3d = new btVector3DoubleData[curNewPart->m_numVertices];
1562  memcpy(curNewPart->m_vertices3d,curPart->m_vertices3d,sizeof(btVector3DoubleData) * curNewPart->m_numVertices);
1563  }
1564  else
1565  curNewPart->m_vertices3d = NULL;
1566 
1567  int numIndices = curNewPart->m_numTriangles * 3;
1570  bool uninitialized3indices8Workaround =false;
1571 
1572  if(curPart->m_indices32)
1573  {
1574  uninitialized3indices8Workaround=true;
1575  curNewPart->m_indices32 = new btIntIndexData[numIndices];
1576  memcpy(curNewPart->m_indices32,curPart->m_indices32,sizeof(btIntIndexData) * numIndices);
1577  }
1578  else
1579  curNewPart->m_indices32 = NULL;
1580 
1581  if(curPart->m_3indices16)
1582  {
1583  uninitialized3indices8Workaround=true;
1584  curNewPart->m_3indices16 = new btShortIntIndexTripletData[curNewPart->m_numTriangles];
1585  memcpy(curNewPart->m_3indices16,curPart->m_3indices16,sizeof(btShortIntIndexTripletData) * curNewPart->m_numTriangles);
1586  }
1587  else
1588  curNewPart->m_3indices16 = NULL;
1589 
1590  if(curPart->m_indices16)
1591  {
1592  uninitialized3indices8Workaround=true;
1593  curNewPart->m_indices16 = new btShortIntIndexData[numIndices];
1594  memcpy(curNewPart->m_indices16,curPart->m_indices16,sizeof(btShortIntIndexData) * numIndices);
1595  }
1596  else
1597  curNewPart->m_indices16 = NULL;
1598 
1599  if(!uninitialized3indices8Workaround && curPart->m_3indices8)
1600  {
1601  curNewPart->m_3indices8 = new btCharIndexTripletData[curNewPart->m_numTriangles];
1602  memcpy(curNewPart->m_3indices8,curPart->m_3indices8,sizeof(btCharIndexTripletData) * curNewPart->m_numTriangles);
1603  }
1604  else
1605  curNewPart->m_3indices8 = NULL;
1606 
1607  }
1608 
1610 
1611  return(newData);
1612 }
1613 
1614 #ifdef USE_INTERNAL_EDGE_UTILITY
1616 
1617 static bool btAdjustInternalEdgeContactsCallback(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
1618 {
1619 
1620  btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1);
1621  //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_BACKFACE_MODE);
1622  //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_DOUBLE_SIDED+BT_TRIANGLE_CONCAVE_DOUBLE_SIDED);
1623  return true;
1624 }
1625 #endif //USE_INTERNAL_EDGE_UTILITY
1626 
1627 
1628 
1629 
1630 btCollisionObject* btWorldImporter::createCollisionObject(const btTransform& startTransform,btCollisionShape* shape, const char* bodyName)
1631 {
1632  return createRigidBody(false,0,startTransform,shape,bodyName);
1633 }
1634 
1636 {
1637  if (m_dynamicsWorld)
1638  {
1639  m_dynamicsWorld->setGravity(gravity);
1640  m_dynamicsWorld->getSolverInfo() = solverInfo;
1641  }
1642 
1643 }
1644 
1645 btRigidBody* btWorldImporter::createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform,btCollisionShape* shape,const char* bodyName)
1646 {
1647  btVector3 localInertia;
1648  localInertia.setZero();
1649 
1650  if (mass)
1651  shape->calculateLocalInertia(mass,localInertia);
1652 
1653  btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
1654  body->setWorldTransform(startTransform);
1655 
1656  if (m_dynamicsWorld)
1658 
1659  if (bodyName)
1660  {
1661  char* newname = duplicateName(bodyName);
1662  m_objectNameMap.insert(body,newname);
1663  m_nameBodyMap.insert(newname,body);
1664  }
1666  return body;
1667 
1668 }
1669 
1671 {
1672  btStaticPlaneShape* shape = new btStaticPlaneShape(planeNormal,planeConstant);
1674  return shape;
1675 }
1677 {
1678  btBoxShape* shape = new btBoxShape(halfExtents);
1680  return shape;
1681 }
1683 {
1684  btSphereShape* shape = new btSphereShape(radius);
1686  return shape;
1687 }
1688 
1689 
1691 {
1692  btCapsuleShapeX* shape = new btCapsuleShapeX(radius,height);
1694  return shape;
1695 }
1696 
1698 {
1699  btCapsuleShape* shape = new btCapsuleShape(radius,height);
1701  return shape;
1702 }
1703 
1705 {
1706  btCapsuleShapeZ* shape = new btCapsuleShapeZ(radius,height);
1708  return shape;
1709 }
1710 
1712 {
1713  btCylinderShapeX* shape = new btCylinderShapeX(btVector3(height,radius,radius));
1715  return shape;
1716 }
1717 
1719 {
1720  btCylinderShape* shape = new btCylinderShape(btVector3(radius,height,radius));
1722  return shape;
1723 }
1724 
1726 {
1727  btCylinderShapeZ* shape = new btCylinderShapeZ(btVector3(radius,radius,height));
1729  return shape;
1730 }
1731 
1733 {
1734  btConeShapeX* shape = new btConeShapeX(radius,height);
1736  return shape;
1737 }
1738 
1740 {
1741  btConeShape* shape = new btConeShape(radius,height);
1743  return shape;
1744 }
1745 
1747 {
1748  btConeShapeZ* shape = new btConeShapeZ(radius,height);
1750  return shape;
1751 }
1752 
1754 {
1757  return in;
1758 }
1759 
1761 {
1762  btOptimizedBvh* bvh = new btOptimizedBvh();
1764  return bvh;
1765 }
1766 
1767 
1769 {
1770  btTriangleInfoMap* tim = new btTriangleInfoMap();
1772  return tim;
1773 }
1774 
1776 {
1777  if (bvh)
1778  {
1779  btBvhTriangleMeshShape* bvhTriMesh = new btBvhTriangleMeshShape(trimesh,bvh->isQuantized(), false);
1780  bvhTriMesh->setOptimizedBvh(bvh);
1782  return bvhTriMesh;
1783  }
1784 
1785  btBvhTriangleMeshShape* ts = new btBvhTriangleMeshShape(trimesh,true);
1787  return ts;
1788 
1789 }
1791 {
1792  return 0;
1793 }
1795 {
1796 #ifdef USE_GIMPACT
1797  btGImpactMeshShape* shape = new btGImpactMeshShape(trimesh);
1799  return shape;
1800 #else
1801  return 0;
1802 #endif
1803 
1804 }
1806 {
1807  btConvexHullShape* shape = new btConvexHullShape();
1809  return shape;
1810 }
1811 
1813 {
1814  btCompoundShape* shape = new btCompoundShape();
1816  return shape;
1817 }
1818 
1819 
1821 {
1822  btScaledBvhTriangleMeshShape* shape = new btScaledBvhTriangleMeshShape(meshShape,localScaling);
1824  return shape;
1825 }
1826 
1828 {
1829  btMultiSphereShape* shape = new btMultiSphereShape(positions, radi, numSpheres);
1831  return shape;
1832 }
1833 
1835 {
1836  static btRigidBody s_fixed(0, 0,0);
1837  s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));
1838  return s_fixed;
1839 }
1840 
1842 {
1843  btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,rbB,pivotInA,pivotInB);
1845  return p2p;
1846 }
1847 
1849 {
1850  btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,pivotInA);
1852  return p2p;
1853 }
1854 
1855 
1856 btHingeConstraint* btWorldImporter::createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA)
1857 {
1858  btHingeConstraint* hinge = new btHingeConstraint(rbA,rbB,rbAFrame,rbBFrame,useReferenceFrameA);
1860  return hinge;
1861 }
1862 
1864 {
1865  btHingeConstraint* hinge = new btHingeConstraint(rbA,rbAFrame,useReferenceFrameA);
1867  return hinge;
1868 }
1869 
1871 {
1872  btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbB,rbAFrame,rbBFrame);
1874  return cone;
1875 }
1876 
1878 {
1879  btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbAFrame);
1881  return cone;
1882 }
1883 
1884 
1885 btGeneric6DofConstraint* btWorldImporter::createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA)
1886 {
1887  btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
1889  return dof;
1890 }
1891 
1893 {
1894  btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbB,frameInB,useLinearReferenceFrameB);
1896  return dof;
1897 }
1898 
1900 {
1901  btGeneric6DofSpring2Constraint* dof = new btGeneric6DofSpring2Constraint(rbA,rbB,frameInA,frameInB, (RotateOrder)rotateOrder);
1903  return dof;
1904 }
1905 
1906 
1907 
1909 {
1910  btGeneric6DofSpringConstraint* dof = new btGeneric6DofSpringConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
1912  return dof;
1913 }
1914 
1915 
1916 btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA)
1917 {
1918  btSliderConstraint* slider = new btSliderConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
1920  return slider;
1921 }
1922 
1923 btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA)
1924 {
1925  btSliderConstraint* slider = new btSliderConstraint(rbB,frameInB,useLinearReferenceFrameA);
1927  return slider;
1928 }
1929 
1931 {
1932  btGearConstraint* gear = new btGearConstraint(rbA,rbB,axisInA,axisInB,ratio);
1934  return gear;
1935 }
1936 
1937  // query for data
1939 {
1941 }
1942 
1944 {
1945  return m_allocatedCollisionShapes[index];
1946 }
1947 
1949 {
1950  btCollisionShape** shapePtr = m_nameShapeMap.find(name);
1951  if (shapePtr&& *shapePtr)
1952  {
1953  return *shapePtr;
1954  }
1955  return 0;
1956 }
1957 
1959 {
1960  btRigidBody** bodyPtr = m_nameBodyMap.find(name);
1961  if (bodyPtr && *bodyPtr)
1962  {
1963  return *bodyPtr;
1964  }
1965  return 0;
1966 }
1967 
1969 {
1970  btTypedConstraint** constraintPtr = m_nameConstraintMap.find(name);
1971  if (constraintPtr && *constraintPtr)
1972  {
1973  return *constraintPtr;
1974  }
1975  return 0;
1976 }
1977 
1978 const char* btWorldImporter::getNameForPointer(const void* ptr) const
1979 {
1980  const char*const * namePtr = m_objectNameMap.find(ptr);
1981  if (namePtr && *namePtr)
1982  return *namePtr;
1983  return 0;
1984 }
1985 
1986 
1988 {
1989  return m_allocatedRigidBodies.size();
1990 }
1991 
1993 {
1994  return m_allocatedRigidBodies[index];
1995 }
1997 {
1998  return m_allocatedConstraints.size();
1999 }
2000 
2002 {
2003  return m_allocatedConstraints[index];
2004 }
2005 
2007 {
2008  return m_allocatedBvhs.size();
2009 }
2011 {
2012  return m_allocatedBvhs[index];
2013 }
2014 
2016 {
2018 }
2019 
2021 {
2022  return m_allocatedTriangleInfoMaps[index];
2023 }
2024 
2025 
2027 {
2028  btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f);
2029  btVector3 localInertia;
2030  localInertia.setZero();
2032  if (shapePtr && *shapePtr)
2033  {
2034  btTransform startTransform;
2036  startTransform.deSerializeFloat(colObjData->m_collisionObjectData.m_worldTransform);
2037 
2038  // startTransform.setBasis(btMatrix3x3::getIdentity());
2039  btCollisionShape* shape = (btCollisionShape*)*shapePtr;
2040  if (shape->isNonMoving())
2041  {
2042  mass = 0.f;
2043  }
2044  if (mass)
2045  {
2046  shape->calculateLocalInertia(mass,localInertia);
2047  }
2048  bool isDynamic = mass!=0.f;
2049  btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name);
2050  body->setFriction(colObjData->m_collisionObjectData.m_friction);
2052  btVector3 linearFactor,angularFactor;
2053  linearFactor.deSerializeFloat(colObjData->m_linearFactor);
2054  angularFactor.deSerializeFloat(colObjData->m_angularFactor);
2055  body->setLinearFactor(linearFactor);
2056  body->setAngularFactor(angularFactor);
2057 
2058 #ifdef USE_INTERNAL_EDGE_UTILITY
2060  {
2062  if (trimesh->getTriangleInfoMap())
2063  {
2065  }
2066  }
2067 #endif //USE_INTERNAL_EDGE_UTILITY
2068  m_bodyMap.insert(colObjData,body);
2069  } else
2070  {
2071  printf("error: no shape found\n");
2072  }
2073 }
2074 
2076 {
2077  btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f);
2078  btVector3 localInertia;
2079  localInertia.setZero();
2081  if (shapePtr && *shapePtr)
2082  {
2083  btTransform startTransform;
2085  startTransform.deSerializeDouble(colObjData->m_collisionObjectData.m_worldTransform);
2086 
2087  // startTransform.setBasis(btMatrix3x3::getIdentity());
2088  btCollisionShape* shape = (btCollisionShape*)*shapePtr;
2089  if (shape->isNonMoving())
2090  {
2091  mass = 0.f;
2092  }
2093  if (mass)
2094  {
2095  shape->calculateLocalInertia(mass,localInertia);
2096  }
2097  bool isDynamic = mass!=0.f;
2098  btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name);
2101  btVector3 linearFactor,angularFactor;
2102  linearFactor.deSerializeDouble(colObjData->m_linearFactor);
2103  angularFactor.deSerializeDouble(colObjData->m_angularFactor);
2104  body->setLinearFactor(linearFactor);
2105  body->setAngularFactor(angularFactor);
2106 
2107 
2108 #ifdef USE_INTERNAL_EDGE_UTILITY
2110  {
2112  if (trimesh->getTriangleInfoMap())
2113  {
2115  }
2116  }
2117 #endif //USE_INTERNAL_EDGE_UTILITY
2118  m_bodyMap.insert(colObjData,body);
2119  } else
2120  {
2121  printf("error: no shape found\n");
2122  }
2123 }
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:203
btTransformDoubleData m_rbBFrame
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)
int getShapeType() 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:1345
virtual btCollisionShape * createSphereShape(btScalar radius)
const btTriangleInfoMap * getTriangleInfoMap() const
void setLowerLinLimit(btScalar lowerLimit)
int getNumCollisionShapes() const
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.
const char * getNameForPointer(const void *ptr) const
void convertRigidBodyFloat(btRigidBodyFloatData *colObjData)
void setLowerAngLimit(btScalar lowerLimit)
btVector3FloatData m_angularFactor
Definition: btRigidBody.h:570
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:1320
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btOptimizedBvh * getBvhByIndex(int index) const
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
int getNumTriangleInfoMaps() const
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:131
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...
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:113
btHashMap< btHashString, btCollisionShape * > m_nameShapeMap
btAlignedObjectArray< short int * > m_shortIndexArrays
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.
int getCollisionFlags() const
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:268
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:566
btVector3DoubleData m_linearFactor
Definition: btRigidBody.h:597
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
const btScalar & getZ() const
Return the z value.
Definition: btVector3.h:577
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)
virtual class btCompoundShape * createCompoundShape()
The btBvhTriangleMeshShape is a static-triangle mesh shape, it can only be used for fixed/non-moving ...
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
int size() const
return the number of elements in the array
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)
btTypedConstraint * getConstraintByIndex(int index) const
bool isNonMoving() const
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:153
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btRigidBody.h:590
int getNumConstraints() const
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:585
virtual void removeRigidBody(btRigidBody *body)=0
btTransformFloatData m_transform
void setUpperAngLimit(btScalar upperLimit)
const btScalar & getY() const
Return the y value.
Definition: btVector3.h:575
char * duplicateName(const char *name)
#define btAlignedFree(ptr)
btVector3FloatData m_pos
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))
const btScalar & getX() const
Return the x value.
Definition: btVector3.h:573
void insert(const Key &key, const Value &value)
Definition: btHashMap.h:262
btAlignedObjectArray< btTypedConstraint * > m_allocatedConstraints
virtual class btScaledBvhTriangleMeshShape * createScaledTrangleMeshShape(btBvhTriangleMeshShape *meshShape, const btVector3 &localScalingbtBvhTriangleMeshShape)
void setZero()
Definition: btVector3.h:683
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
btTransform inverse() const
Return the inverse of this transform.
Definition: btTransform.h:188
void setLinearUpperLimit(const btVector3 &linearUpper)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btRigidBody.h:564
this structure is not used, except for loading pre-2.82 .bullet files
void setLinearLowerLimit(const btVector3 &linearLower)
btVector3DoubleData m_angularFactor
Definition: btRigidBody.h:596
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
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
btTriangleInfoMap * getTriangleInfoMapByIndex(int index) const
const Value * find(const Key &key) const
Definition: btHashMap.h:422
bool(* ContactAddedCallback)(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1)
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:133
btAlignedObjectArray< char * > m_allocatedNames
void setCollisionFlags(int flags)
btCollisionObjectDoubleData m_collisionObjectData
Definition: btRigidBody.h:592
btTransformDoubleData m_rbAFrame
btTransformDoubleData m_worldTransform
virtual void deSerializeFloat(struct btQuantizedBvhFloatData &quantizedBvhFloatData)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
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)
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 setStiffness(int index, btScalar stiffness, bool limitIfNeeded=true)
void setEnabled(bool enabled)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
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...
virtual int getNumSubParts() const
getNumSubParts returns the number of seperate subparts each subpart has a continuous array of vertice...
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
int getNumBvhs() const
void addPoint(const btVector3 &point, bool recalculateLocalAabb=true)
virtual btSliderConstraint * createSliderConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, bool useLinearReferenceFrameA)
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. ...
void setAngularUpperLimit(const btVector3 &angularUpper)
The btTriangleInfoMap stores edge angle information for some triangles. You can compute this informat...
int getNumRigidBodies() const
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:1331
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 ...
void setDamping(int index, btScalar damping, bool limitIfNeeded=true)
btAlignedObjectArray< btVector3FloatData * > m_floatVertexArrays
void setAngularFactor(const btVector3 &angFac)
Definition: btRigidBody.h:493
btHashMap< btHashPtr, const char * > m_objectNameMap
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)
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:292
PHY_ScalarType m_vertexType
btVector3FloatData m_linearFactor
Definition: btRigidBody.h:571
const unsigned char * m_vertexBase
void enableAngularMotor(bool enableMotor, btScalar targetVelocity, btScalar maxMotorImpulse)
btCollisionObject * getRigidBodyByIndex(int index) const
btTransformFloatData m_rbBFrame
virtual void setMargin(btScalar margin)
btVector3DoubleData * m_vertices3d