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