Bullet Collision Detection & Physics Library
btWorldImporter.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#include "btWorldImporter.h"
18#ifdef USE_GIMPACT
20#endif
22:m_dynamicsWorld(world),
23m_verboseMode(0)
24{
25
26}
27
29{
30}
31
33{
34 int i;
35 for (i=0;i<m_allocatedConstraints.size();i++)
36 {
39 delete m_allocatedConstraints[i];
40 }
42
43
44 for (i=0;i<m_allocatedRigidBodies.size();i++)
45 {
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 }
65 m_allocatedBvhs.clear();
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 }
81 m_allocatedNames.clear();
82
83 for (i=0;i<m_allocatedbtStridingMeshInterfaceDatas.size();i++)
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 }
118 m_indexArrays.clear();
119
120 for (i=0;i<m_shortIndexArrays.size();i++)
121 {
123 }
124 m_shortIndexArrays.clear();
125
126 for (i=0;i<m_charIndexArrays.size();i++)
127 {
129 }
130 m_charIndexArrays.clear();
131
132 for (i=0;i<m_floatVertexArrays.size();i++)
133 {
135 }
136 m_floatVertexArrays.clear();
137
138 for (i=0;i<m_doubleVertexArrays.size();i++)
139 {
141 }
142 m_doubleVertexArrays.clear();
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;
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 }
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 {
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);
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 {
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();
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();
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
473 for (int i=0;i<compoundData->m_numChildShapes;i++)
474 {
475
477
478 btCollisionShape* childShape = convertCollisionShape(cd);
479 if (childShape)
480 {
481 btTransform localTransform;
482 localTransform.deSerializeFloat(compoundData->m_childShapePtr[i].m_transform);
483 compoundShape->addChildShape(localTransform,childShape);
484 } else
485 {
486#ifdef _DEBUG
487 printf("error: couldn't create childShape for compoundShape\n");
488#endif
489 }
490
491 }
492 shape = compoundShape;
493
494 break;
495 }
497 {
498 return 0;
499 }
500 default:
501 {
502#ifdef _DEBUG
503 printf("unsupported shape type (%d)\n",shapeData->m_shapeType);
504#endif
505 }
506 }
507
508 return shape;
509
510}
511
512
513
514char* btWorldImporter::duplicateName(const char* name)
515{
516 if (name)
517 {
518 int l = (int)strlen(name);
519 char* newName = new char[l+1];
520 memcpy(newName,name,l);
521 newName[l] = 0;
522 m_allocatedNames.push_back(newName);
523 return newName;
524 }
525 return 0;
526}
527
529{
530
531 btTypedConstraint* constraint = 0;
532
533 switch (constraintData->m_objectType)
534 {
536 {
538 if (rbA && rbB)
539 {
540 btVector3 pivotInA,pivotInB;
541 pivotInA.deSerializeDouble(p2pData->m_pivotInA);
542 pivotInB.deSerializeDouble(p2pData->m_pivotInB);
543 constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
544 } else
545 {
546 btVector3 pivotInA;
547 pivotInA.deSerializeDouble(p2pData->m_pivotInA);
548 constraint = createPoint2PointConstraint(*rbA,pivotInA);
549 }
550 break;
551 }
553 {
554 btHingeConstraint* hinge = 0;
555
556 btHingeConstraintDoubleData* hingeData = (btHingeConstraintDoubleData*)constraintData;
557 if (rbA&& rbB)
558 {
559 btTransform rbAFrame,rbBFrame;
560 rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
561 rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
562 hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
563 } else
564 {
565 btTransform rbAFrame;
566 rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
567 hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
568 }
569 if (hingeData->m_enableAngularMotor)
570 {
572 }
573 hinge->setAngularOnly(hingeData->m_angularOnly!=0);
574 hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
575
576 constraint = hinge;
577 break;
578
579 }
581 {
582 btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData;
583 btConeTwistConstraint* coneTwist = 0;
584
585 if (rbA&& rbB)
586 {
587 btTransform rbAFrame,rbBFrame;
588 rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
589 rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
590 coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
591 } else
592 {
593 btTransform rbAFrame;
594 rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
595 coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
596 }
597 coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness,
598 (btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor);
599 coneTwist->setDamping((btScalar)coneData->m_damping);
600
601 constraint = coneTwist;
602 break;
603 }
604
606 {
607
609 // int sz = sizeof(btGeneric6DofSpringConstraintData);
611
612 if (rbA && rbB)
613 {
614 btTransform rbAFrame,rbBFrame;
615 rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame);
616 rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame);
617 dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
618 } else
619 {
620 printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
621 }
622
623 if (dof)
624 {
625 btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
626 angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit);
627 angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit);
628 linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit);
629 linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit);
630
631 angLowerLimit.setW(0.f);
632 dof->setAngularLowerLimit(angLowerLimit);
633 dof->setAngularUpperLimit(angUpperLimit);
634 dof->setLinearLowerLimit(linLowerLimit);
635 dof->setLinearUpperLimit(linUpperlimit);
636
637 int i;
638 if (fileVersion>280)
639 {
640 for (i=0;i<6;i++)
641 {
642 dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]);
644 dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
645 dof->setDamping(i,(btScalar)dofData->m_springDamping[i]);
646 }
647 }
648 }
649
650 constraint = dof;
651 break;
652
653 }
655 {
658
659 if (rbA&& rbB)
660 {
661 btTransform rbAFrame,rbBFrame;
662 rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
663 rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
664 dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
665 } else
666 {
667 if (rbB)
668 {
669 btTransform rbBFrame;
670 rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
671 dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
672 } else
673 {
674 printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
675 }
676 }
677
678 if (dof)
679 {
680 btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
681 angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
682 angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit);
683 linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit);
684 linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit);
685
686 dof->setAngularLowerLimit(angLowerLimit);
687 dof->setAngularUpperLimit(angUpperLimit);
688 dof->setLinearLowerLimit(linLowerLimit);
689 dof->setLinearUpperLimit(linUpperlimit);
690 }
691
692 constraint = dof;
693 break;
694 }
696 {
697 btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData;
698 btSliderConstraint* slider = 0;
699 if (rbA&& rbB)
700 {
701 btTransform rbAFrame,rbBFrame;
702 rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
703 rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
704 slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
705 } else
706 {
707 btTransform rbBFrame;
708 rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
709 slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
710 }
711 slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit);
712 slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit);
713 slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit);
714 slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit);
715 slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
716 constraint = slider;
717 break;
718 }
719
720 default:
721 {
722 printf("unknown constraint type\n");
723 }
724 };
725
726 if (constraint)
727 {
728 constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize);
730 if (fileVersion>=280)
731 {
733 constraint->setEnabled(constraintData->m_isEnabled!=0);
735 }
736
737 if (constraintData->m_name)
738 {
739 char* newname = duplicateName(constraintData->m_name);
740 m_nameConstraintMap.insert(newname,constraint);
741 m_objectNameMap.insert(constraint,newname);
742 }
745 }
746
747}
748
750{
751 btTypedConstraint* constraint = 0;
752
753 switch (constraintData->m_objectType)
754 {
756 {
758 if (rbA&& rbB)
759 {
760 btVector3 pivotInA,pivotInB;
761 pivotInA.deSerializeFloat(p2pData->m_pivotInA);
762 pivotInB.deSerializeFloat(p2pData->m_pivotInB);
763 constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
764
765 } else
766 {
767 btVector3 pivotInA;
768 pivotInA.deSerializeFloat(p2pData->m_pivotInA);
769 constraint = createPoint2PointConstraint(*rbA,pivotInA);
770 }
771 break;
772 }
774 {
775 btHingeConstraint* hinge = 0;
776 btHingeConstraintFloatData* hingeData = (btHingeConstraintFloatData*)constraintData;
777 if (rbA&& rbB)
778 {
779 btTransform rbAFrame,rbBFrame;
780 rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
781 rbBFrame.deSerializeFloat(hingeData->m_rbBFrame);
782 hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
783 } else
784 {
785 btTransform rbAFrame;
786 rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
787 hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
788 }
789 if (hingeData->m_enableAngularMotor)
790 {
791 hinge->enableAngularMotor(true,hingeData->m_motorTargetVelocity,hingeData->m_maxMotorImpulse);
792 }
793 hinge->setAngularOnly(hingeData->m_angularOnly!=0);
794 hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
795
796 constraint = hinge;
797 break;
798
799 }
801 {
802 btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData;
803 btConeTwistConstraint* coneTwist = 0;
804
805 if (rbA&& rbB)
806 {
807 btTransform rbAFrame,rbBFrame;
808 rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
809 rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
810 coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
811 } else
812 {
813 btTransform rbAFrame;
814 rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
815 coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
816 }
817 coneTwist->setLimit(coneData->m_swingSpan1,coneData->m_swingSpan2,coneData->m_twistSpan,coneData->m_limitSoftness,coneData->m_biasFactor,coneData->m_relaxationFactor);
818 coneTwist->setDamping(coneData->m_damping);
819
820 constraint = coneTwist;
821 break;
822 }
823
825 {
826
828 // int sz = sizeof(btGeneric6DofSpringConstraintData);
830
831 if (rbA && rbB)
832 {
833 btTransform rbAFrame,rbBFrame;
834 rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame);
835 rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame);
836 dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
837 } else
838 {
839 printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
840 }
841
842 if (dof)
843 {
844 btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
845 angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit);
846 angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit);
847 linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit);
848 linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit);
849
850 angLowerLimit.setW(0.f);
851 dof->setAngularLowerLimit(angLowerLimit);
852 dof->setAngularUpperLimit(angUpperLimit);
853 dof->setLinearLowerLimit(linLowerLimit);
854 dof->setLinearUpperLimit(linUpperlimit);
855
856 int i;
857 if (fileVersion>280)
858 {
859 for (i=0;i<6;i++)
860 {
861 dof->setStiffness(i,dofData->m_springStiffness[i]);
862 dof->setEquilibriumPoint(i,dofData->m_equilibriumPoint[i]);
863 dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
864 dof->setDamping(i,dofData->m_springDamping[i]);
865 }
866 }
867 }
868
869 constraint = dof;
870 break;
871 }
873 {
876
877 if (rbA&& rbB)
878 {
879 btTransform rbAFrame,rbBFrame;
880 rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
881 rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
882 dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
883 } else
884 {
885 if (rbB)
886 {
887 btTransform rbBFrame;
888 rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
889 dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
890 } else
891 {
892 printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
893 }
894 }
895
896 if (dof)
897 {
898 btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
899 angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
900 angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit);
901 linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit);
902 linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit);
903
904 dof->setAngularLowerLimit(angLowerLimit);
905 dof->setAngularUpperLimit(angUpperLimit);
906 dof->setLinearLowerLimit(linLowerLimit);
907 dof->setLinearUpperLimit(linUpperlimit);
908 }
909
910 constraint = dof;
911 break;
912 }
914 {
915 btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData;
916 btSliderConstraint* slider = 0;
917 if (rbA&& rbB)
918 {
919 btTransform rbAFrame,rbBFrame;
920 rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
921 rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
922 slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
923 } else
924 {
925 btTransform rbBFrame;
926 rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
927 slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
928 }
929 slider->setLowerLinLimit(sliderData->m_linearLowerLimit);
930 slider->setUpperLinLimit(sliderData->m_linearUpperLimit);
931 slider->setLowerAngLimit(sliderData->m_angularLowerLimit);
932 slider->setUpperAngLimit(sliderData->m_angularUpperLimit);
933 slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
934 constraint = slider;
935 break;
936 }
938 {
939 btGearConstraintFloatData* gearData = (btGearConstraintFloatData*) constraintData;
940 btGearConstraint* gear = 0;
941 if (rbA&&rbB)
942 {
943 btVector3 axisInA,axisInB;
944 axisInA.deSerializeFloat(gearData->m_axisInA);
945 axisInB.deSerializeFloat(gearData->m_axisInB);
946 gear = createGearConstraint(*rbA, *rbB, axisInA,axisInB, gearData->m_ratio);
947 } else
948 {
949 btAssert(0);
950 //perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized?
951 //btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio=1.f);
952 }
953 constraint = gear;
954 break;
955 }
957 {
958
960
962
963 if (rbA && rbB)
964 {
965 btTransform rbAFrame,rbBFrame;
966 rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
967 rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
968 dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, dofData->m_rotateOrder);
969 } else
970 {
971 printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
972 }
973
974 if (dof)
975 {
976 btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
977 angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit);
978 angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit);
979 linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit);
980 linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit);
981
982 angLowerLimit.setW(0.f);
983 dof->setAngularLowerLimit(angLowerLimit);
984 dof->setAngularUpperLimit(angUpperLimit);
985 dof->setLinearLowerLimit(linLowerLimit);
986 dof->setLinearUpperLimit(linUpperlimit);
987
988 int i;
989 if (fileVersion>280)
990 {
991 //6-dof: 3 linear followed by 3 angular
992 for (i=0;i<3;i++)
993 {
996 dof->enableSpring(i,dofData->m_linearEnableSpring[i]!=0);
997 dof->setDamping(i,dofData->m_linearSpringDamping.m_floats[i],(dofData->m_linearSpringDampingLimited[i]!=0));
998 }
999 for (i=0;i<3;i++)
1000 {
1003 dof->enableSpring(i+3,dofData->m_angularEnableSpring[i]!=0);
1005 }
1006
1007 }
1008 }
1009
1010 constraint = dof;
1011 break;
1012
1013 }
1015 {
1016
1018 if (rbA && rbB)
1019 {
1020 btTransform rbAFrame,rbBFrame;
1021 //compute a shared world frame, and compute frameInA, frameInB relative to this
1022 btTransform sharedFrame;
1023 sharedFrame.setIdentity();
1024 btVector3 centerPos = btScalar(0.5)*(rbA->getWorldTransform().getOrigin()+
1025 rbB->getWorldTransform().getOrigin());
1026 sharedFrame.setOrigin(centerPos);
1027 rbAFrame = rbA->getWorldTransform().inverse()*sharedFrame;
1028 rbBFrame = rbB->getWorldTransform().inverse()*sharedFrame;
1029
1030
1031 dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, RO_XYZ);
1032 dof->setLinearUpperLimit(btVector3(0,0,0));
1033 dof->setLinearLowerLimit(btVector3(0,0,0));
1034 dof->setAngularUpperLimit(btVector3(0,0,0));
1035 dof->setAngularLowerLimit(btVector3(0,0,0));
1036
1037 } else
1038 {
1039 printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
1040 }
1041
1042 constraint = dof;
1043 break;
1044 }
1045 default:
1046 {
1047 printf("unknown constraint type\n");
1048 }
1049 };
1050
1051 if (constraint)
1052 {
1053 constraint->setDbgDrawSize(constraintData->m_dbgDrawSize);
1055 if (fileVersion>=280)
1056 {
1057 constraint->setBreakingImpulseThreshold(constraintData->m_breakingImpulseThreshold);
1058 constraint->setEnabled(constraintData->m_isEnabled!=0);
1060 }
1061
1062 if (constraintData->m_name)
1063 {
1064 char* newname = duplicateName(constraintData->m_name);
1065 m_nameConstraintMap.insert(newname,constraint);
1066 m_objectNameMap.insert(constraint,newname);
1067 }
1068 if(m_dynamicsWorld)
1070 }
1071
1072
1073}
1074
1075
1076
1078{
1079 btTypedConstraint* constraint = 0;
1080
1081 switch (constraintData->m_objectType)
1082 {
1084 {
1086 if (rbA && rbB)
1087 {
1088 btVector3 pivotInA,pivotInB;
1089 pivotInA.deSerializeDouble(p2pData->m_pivotInA);
1090 pivotInB.deSerializeDouble(p2pData->m_pivotInB);
1091 constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB);
1092 } else
1093 {
1094 btVector3 pivotInA;
1095 pivotInA.deSerializeDouble(p2pData->m_pivotInA);
1096 constraint = createPoint2PointConstraint(*rbA,pivotInA);
1097 }
1098 break;
1099 }
1101 {
1102 btHingeConstraint* hinge = 0;
1103
1104 btHingeConstraintDoubleData2* hingeData = (btHingeConstraintDoubleData2*)constraintData;
1105 if (rbA&& rbB)
1106 {
1107 btTransform rbAFrame,rbBFrame;
1108 rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
1109 rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
1110 hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0);
1111 } else
1112 {
1113 btTransform rbAFrame;
1114 rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
1115 hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0);
1116 }
1117 if (hingeData->m_enableAngularMotor)
1118 {
1119 hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse);
1120 }
1121 hinge->setAngularOnly(hingeData->m_angularOnly!=0);
1122 hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));
1123
1124 constraint = hinge;
1125 break;
1126
1127 }
1129 {
1131 btConeTwistConstraint* coneTwist = 0;
1132
1133 if (rbA&& rbB)
1134 {
1135 btTransform rbAFrame,rbBFrame;
1136 rbAFrame.deSerializeDouble(coneData->m_rbAFrame);
1137 rbBFrame.deSerializeDouble(coneData->m_rbBFrame);
1138 coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame);
1139 } else
1140 {
1141 btTransform rbAFrame;
1142 rbAFrame.deSerializeDouble(coneData->m_rbAFrame);
1143 coneTwist = createConeTwistConstraint(*rbA,rbAFrame);
1144 }
1145 coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness,
1146 (btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor);
1147 coneTwist->setDamping((btScalar)coneData->m_damping);
1148
1149 constraint = coneTwist;
1150 break;
1151 }
1152
1154 {
1155
1157 // int sz = sizeof(btGeneric6DofSpringConstraintData);
1159
1160 if (rbA && rbB)
1161 {
1162 btTransform rbAFrame,rbBFrame;
1163 rbAFrame.deSerializeDouble(dofData->m_6dofData.m_rbAFrame);
1164 rbBFrame.deSerializeDouble(dofData->m_6dofData.m_rbBFrame);
1165 dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0);
1166 } else
1167 {
1168 printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
1169 }
1170
1171 if (dof)
1172 {
1173 btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
1174 angLowerLimit.deSerializeDouble(dofData->m_6dofData.m_angularLowerLimit);
1175 angUpperLimit.deSerializeDouble(dofData->m_6dofData.m_angularUpperLimit);
1176 linLowerLimit.deSerializeDouble(dofData->m_6dofData.m_linearLowerLimit);
1177 linUpperlimit.deSerializeDouble(dofData->m_6dofData.m_linearUpperLimit);
1178
1179 angLowerLimit.setW(0.f);
1180 dof->setAngularLowerLimit(angLowerLimit);
1181 dof->setAngularUpperLimit(angUpperLimit);
1182 dof->setLinearLowerLimit(linLowerLimit);
1183 dof->setLinearUpperLimit(linUpperlimit);
1184
1185 int i;
1186 if (fileVersion>280)
1187 {
1188 for (i=0;i<6;i++)
1189 {
1190 dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]);
1191 dof->setEquilibriumPoint(i,(btScalar)dofData->m_equilibriumPoint[i]);
1192 dof->enableSpring(i,dofData->m_springEnabled[i]!=0);
1193 dof->setDamping(i,(btScalar)dofData->m_springDamping[i]);
1194 }
1195 }
1196 }
1197
1198 constraint = dof;
1199 break;
1200 }
1201 case D6_CONSTRAINT_TYPE:
1202 {
1204 btGeneric6DofConstraint* dof = 0;
1205
1206 if (rbA&& rbB)
1207 {
1208 btTransform rbAFrame,rbBFrame;
1209 rbAFrame.deSerializeDouble(dofData->m_rbAFrame);
1210 rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
1211 dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
1212 } else
1213 {
1214 if (rbB)
1215 {
1216 btTransform rbBFrame;
1217 rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
1218 dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0);
1219 } else
1220 {
1221 printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
1222 }
1223 }
1224
1225 if (dof)
1226 {
1227 btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
1228 angLowerLimit.deSerializeDouble(dofData->m_angularLowerLimit);
1229 angUpperLimit.deSerializeDouble(dofData->m_angularUpperLimit);
1230 linLowerLimit.deSerializeDouble(dofData->m_linearLowerLimit);
1231 linUpperlimit.deSerializeDouble(dofData->m_linearUpperLimit);
1232
1233 dof->setAngularLowerLimit(angLowerLimit);
1234 dof->setAngularUpperLimit(angUpperLimit);
1235 dof->setLinearLowerLimit(linLowerLimit);
1236 dof->setLinearUpperLimit(linUpperlimit);
1237 }
1238
1239 constraint = dof;
1240 break;
1241 }
1243 {
1244 btSliderConstraintDoubleData* sliderData = (btSliderConstraintDoubleData*)constraintData;
1245 btSliderConstraint* slider = 0;
1246 if (rbA&& rbB)
1247 {
1248 btTransform rbAFrame,rbBFrame;
1249 rbAFrame.deSerializeDouble(sliderData->m_rbAFrame);
1250 rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
1251 slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
1252 } else
1253 {
1254 btTransform rbBFrame;
1255 rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
1256 slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0);
1257 }
1258 slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit);
1259 slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit);
1260 slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit);
1261 slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit);
1262 slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0);
1263 constraint = slider;
1264 break;
1265 }
1267 {
1268 btGearConstraintDoubleData* gearData = (btGearConstraintDoubleData*) constraintData;
1269 btGearConstraint* gear = 0;
1270 if (rbA&&rbB)
1271 {
1272 btVector3 axisInA,axisInB;
1273 axisInA.deSerializeDouble(gearData->m_axisInA);
1274 axisInB.deSerializeDouble(gearData->m_axisInB);
1275 gear = createGearConstraint(*rbA, *rbB, axisInA,axisInB, gearData->m_ratio);
1276 } else
1277 {
1278 btAssert(0);
1279 //perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized?
1280 //btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio=1.f);
1281 }
1282 constraint = gear;
1283 break;
1284 }
1285
1287 {
1288
1290
1292
1293 if (rbA && rbB)
1294 {
1295 btTransform rbAFrame,rbBFrame;
1296 rbAFrame.deSerializeDouble(dofData->m_rbAFrame);
1297 rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
1298 dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, dofData->m_rotateOrder);
1299 } else
1300 {
1301 printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
1302 }
1303
1304 if (dof)
1305 {
1306 btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit;
1307 angLowerLimit.deSerializeDouble(dofData->m_angularLowerLimit);
1308 angUpperLimit.deSerializeDouble(dofData->m_angularUpperLimit);
1309 linLowerLimit.deSerializeDouble(dofData->m_linearLowerLimit);
1310 linUpperlimit.deSerializeDouble(dofData->m_linearUpperLimit);
1311
1312 angLowerLimit.setW(0.f);
1313 dof->setAngularLowerLimit(angLowerLimit);
1314 dof->setAngularUpperLimit(angUpperLimit);
1315 dof->setLinearLowerLimit(linLowerLimit);
1316 dof->setLinearUpperLimit(linUpperlimit);
1317
1318 int i;
1319 if (fileVersion>280)
1320 {
1321 //6-dof: 3 linear followed by 3 angular
1322 for (i=0;i<3;i++)
1323 {
1326 dof->enableSpring(i,dofData->m_linearEnableSpring[i]!=0);
1327 dof->setDamping(i,dofData->m_linearSpringDamping.m_floats[i],(dofData->m_linearSpringDampingLimited[i]!=0));
1328 }
1329 for (i=0;i<3;i++)
1330 {
1333 dof->enableSpring(i+3,dofData->m_angularEnableSpring[i]!=0);
1334 dof->setDamping(i+3,dofData->m_angularSpringDamping.m_floats[i],(dofData->m_angularSpringDampingLimited[i]!=0));
1335 }
1336
1337 }
1338 }
1339
1340 constraint = dof;
1341 break;
1342
1343 }
1345 {
1346
1348 if (rbA && rbB)
1349 {
1350 btTransform rbAFrame,rbBFrame;
1351 //compute a shared world frame, and compute frameInA, frameInB relative to this
1352 btTransform sharedFrame;
1353 sharedFrame.setIdentity();
1354 btVector3 centerPos = btScalar(0.5)*(rbA->getWorldTransform().getOrigin()+
1355 rbB->getWorldTransform().getOrigin());
1356 sharedFrame.setOrigin(centerPos);
1357 rbAFrame = rbA->getWorldTransform().inverse()*sharedFrame;
1358 rbBFrame = rbB->getWorldTransform().inverse()*sharedFrame;
1359
1360
1361 dof = createGeneric6DofSpring2Constraint(*rbA,*rbB,rbAFrame,rbBFrame, RO_XYZ);
1362 dof->setLinearUpperLimit(btVector3(0,0,0));
1363 dof->setLinearLowerLimit(btVector3(0,0,0));
1364 dof->setAngularUpperLimit(btVector3(0,0,0));
1365 dof->setAngularLowerLimit(btVector3(0,0,0));
1366
1367 } else
1368 {
1369 printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
1370 }
1371
1372 constraint = dof;
1373 break;
1374 }
1375
1376 default:
1377 {
1378 printf("unknown constraint type\n");
1379 }
1380 };
1381
1382 if (constraint)
1383 {
1384 constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize);
1386 if (fileVersion>=280)
1387 {
1389 constraint->setEnabled(constraintData->m_isEnabled!=0);
1391 }
1392
1393 if (constraintData->m_name)
1394 {
1395 char* newname = duplicateName(constraintData->m_name);
1396 m_nameConstraintMap.insert(newname,constraint);
1397 m_objectNameMap.insert(constraint,newname);
1398 }
1399 if(m_dynamicsWorld)
1401 }
1402
1403
1404}
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1416{
1418
1419 for (int i=0;i<meshData.m_numMeshParts;i++)
1420 {
1421 btIndexedMesh meshPart;
1422 meshPart.m_numTriangles = meshData.m_meshPartsPtr[i].m_numTriangles;
1423 meshPart.m_numVertices = meshData.m_meshPartsPtr[i].m_numVertices;
1424
1425
1426 if (meshData.m_meshPartsPtr[i].m_indices32)
1427 {
1428 meshPart.m_indexType = PHY_INTEGER;
1429 meshPart.m_triangleIndexStride = 3*sizeof(int);
1430 int* indexArray = (int*)btAlignedAlloc(sizeof(int)*3*meshPart.m_numTriangles,16);
1431 m_indexArrays.push_back(indexArray);
1432 for (int j=0;j<3*meshPart.m_numTriangles;j++)
1433 {
1434 indexArray[j] = meshData.m_meshPartsPtr[i].m_indices32[j].m_value;
1435 }
1436 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1437 } else
1438 {
1439 if (meshData.m_meshPartsPtr[i].m_3indices16)
1440 {
1441 meshPart.m_indexType = PHY_SHORT;
1442 meshPart.m_triangleIndexStride = sizeof(short int)*3;//sizeof(btShortIntIndexTripletData);
1443
1444 short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
1445 m_shortIndexArrays.push_back(indexArray);
1446
1447 for (int j=0;j<meshPart.m_numTriangles;j++)
1448 {
1449 indexArray[3*j] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[0];
1450 indexArray[3*j+1] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[1];
1451 indexArray[3*j+2] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[2];
1452 }
1453
1454 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1455 }
1456 if (meshData.m_meshPartsPtr[i].m_indices16)
1457 {
1458 meshPart.m_indexType = PHY_SHORT;
1459 meshPart.m_triangleIndexStride = 3*sizeof(short int);
1460 short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
1461 m_shortIndexArrays.push_back(indexArray);
1462 for (int j=0;j<3*meshPart.m_numTriangles;j++)
1463 {
1464 indexArray[j] = meshData.m_meshPartsPtr[i].m_indices16[j].m_value;
1465 }
1466
1467 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1468 }
1469
1470 if (meshData.m_meshPartsPtr[i].m_3indices8)
1471 {
1472 meshPart.m_indexType = PHY_UCHAR;
1473 meshPart.m_triangleIndexStride = sizeof(unsigned char)*3;
1474
1475 unsigned char* indexArray = (unsigned char*)btAlignedAlloc(sizeof(unsigned char)*3*meshPart.m_numTriangles,16);
1476 m_charIndexArrays.push_back(indexArray);
1477
1478 for (int j=0;j<meshPart.m_numTriangles;j++)
1479 {
1480 indexArray[3*j] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[0];
1481 indexArray[3*j+1] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[1];
1482 indexArray[3*j+2] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[2];
1483 }
1484
1485 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
1486 }
1487 }
1488
1489 if (meshData.m_meshPartsPtr[i].m_vertices3f)
1490 {
1491 meshPart.m_vertexType = PHY_FLOAT;
1492 meshPart.m_vertexStride = sizeof(btVector3FloatData);
1494 m_floatVertexArrays.push_back(vertices);
1495
1496 for (int j=0;j<meshPart.m_numVertices;j++)
1497 {
1498 vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[0];
1499 vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[1];
1500 vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[2];
1501 vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[3];
1502 }
1503 meshPart.m_vertexBase = (const unsigned char*)vertices;
1504 } else
1505 {
1506 meshPart.m_vertexType = PHY_DOUBLE;
1507 meshPart.m_vertexStride = sizeof(btVector3DoubleData);
1508
1509
1511 m_doubleVertexArrays.push_back(vertices);
1512
1513 for (int j=0;j<meshPart.m_numVertices;j++)
1514 {
1515 vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[0];
1516 vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[1];
1517 vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[2];
1518 vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[3];
1519 }
1520 meshPart.m_vertexBase = (const unsigned char*)vertices;
1521 }
1522
1523 if (meshPart.m_triangleIndexBase && meshPart.m_vertexBase)
1524 {
1525 meshInterface->addIndexedMesh(meshPart,meshPart.m_indexType);
1526 }
1527 }
1528
1529 return meshInterface;
1530}
1531
1532
1534{
1535 //create a new btStridingMeshInterfaceData that is an exact copy of shapedata and store it in the WorldImporter
1537
1538 newData->m_scaling = interfaceData->m_scaling;
1539 newData->m_numMeshParts = interfaceData->m_numMeshParts;
1540 newData->m_meshPartsPtr = new btMeshPartData[newData->m_numMeshParts];
1541
1542 for(int i = 0;i < newData->m_numMeshParts;i++)
1543 {
1544 btMeshPartData* curPart = &interfaceData->m_meshPartsPtr[i];
1545 btMeshPartData* curNewPart = &newData->m_meshPartsPtr[i];
1546
1547 curNewPart->m_numTriangles = curPart->m_numTriangles;
1548 curNewPart->m_numVertices = curPart->m_numVertices;
1549
1550 if(curPart->m_vertices3f)
1551 {
1552 curNewPart->m_vertices3f = new btVector3FloatData[curNewPart->m_numVertices];
1553 memcpy(curNewPart->m_vertices3f,curPart->m_vertices3f,sizeof(btVector3FloatData) * curNewPart->m_numVertices);
1554 }
1555 else
1556 curNewPart->m_vertices3f = NULL;
1557
1558 if(curPart->m_vertices3d)
1559 {
1560 curNewPart->m_vertices3d = new btVector3DoubleData[curNewPart->m_numVertices];
1561 memcpy(curNewPart->m_vertices3d,curPart->m_vertices3d,sizeof(btVector3DoubleData) * curNewPart->m_numVertices);
1562 }
1563 else
1564 curNewPart->m_vertices3d = NULL;
1565
1566 int numIndices = curNewPart->m_numTriangles * 3;
1569 bool uninitialized3indices8Workaround =false;
1570
1571 if(curPart->m_indices32)
1572 {
1573 uninitialized3indices8Workaround=true;
1574 curNewPart->m_indices32 = new btIntIndexData[numIndices];
1575 memcpy(curNewPart->m_indices32,curPart->m_indices32,sizeof(btIntIndexData) * numIndices);
1576 }
1577 else
1578 curNewPart->m_indices32 = NULL;
1579
1580 if(curPart->m_3indices16)
1581 {
1582 uninitialized3indices8Workaround=true;
1583 curNewPart->m_3indices16 = new btShortIntIndexTripletData[curNewPart->m_numTriangles];
1584 memcpy(curNewPart->m_3indices16,curPart->m_3indices16,sizeof(btShortIntIndexTripletData) * curNewPart->m_numTriangles);
1585 }
1586 else
1587 curNewPart->m_3indices16 = NULL;
1588
1589 if(curPart->m_indices16)
1590 {
1591 uninitialized3indices8Workaround=true;
1592 curNewPart->m_indices16 = new btShortIntIndexData[numIndices];
1593 memcpy(curNewPart->m_indices16,curPart->m_indices16,sizeof(btShortIntIndexData) * numIndices);
1594 }
1595 else
1596 curNewPart->m_indices16 = NULL;
1597
1598 if(!uninitialized3indices8Workaround && curPart->m_3indices8)
1599 {
1600 curNewPart->m_3indices8 = new btCharIndexTripletData[curNewPart->m_numTriangles];
1601 memcpy(curNewPart->m_3indices8,curPart->m_3indices8,sizeof(btCharIndexTripletData) * curNewPart->m_numTriangles);
1602 }
1603 else
1604 curNewPart->m_3indices8 = NULL;
1605
1606 }
1607
1608 m_allocatedbtStridingMeshInterfaceDatas.push_back(newData);
1609
1610 return(newData);
1611}
1612
1613#ifdef USE_INTERNAL_EDGE_UTILITY
1615
1616static bool btAdjustInternalEdgeContactsCallback(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
1617{
1618
1619 btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1);
1620 //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_BACKFACE_MODE);
1621 //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_DOUBLE_SIDED+BT_TRIANGLE_CONCAVE_DOUBLE_SIDED);
1622 return true;
1623}
1624#endif //USE_INTERNAL_EDGE_UTILITY
1625
1626
1627
1628
1630{
1631 return createRigidBody(false,0,startTransform,shape,bodyName);
1632}
1633
1635{
1636 if (m_dynamicsWorld)
1637 {
1638 m_dynamicsWorld->setGravity(gravity);
1639 m_dynamicsWorld->getSolverInfo() = solverInfo;
1640 }
1641
1642}
1643
1644btRigidBody* btWorldImporter::createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform,btCollisionShape* shape,const char* bodyName)
1645{
1646 btVector3 localInertia;
1647 localInertia.setZero();
1648
1649 if (mass)
1650 shape->calculateLocalInertia(mass,localInertia);
1651
1652 btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
1653 body->setWorldTransform(startTransform);
1654
1655 if (m_dynamicsWorld)
1657
1658 if (bodyName)
1659 {
1660 char* newname = duplicateName(bodyName);
1661 m_objectNameMap.insert(body,newname);
1662 m_nameBodyMap.insert(newname,body);
1663 }
1664 m_allocatedRigidBodies.push_back(body);
1665 return body;
1666
1667}
1668
1670{
1671 btStaticPlaneShape* shape = new btStaticPlaneShape(planeNormal,planeConstant);
1672 m_allocatedCollisionShapes.push_back(shape);
1673 return shape;
1674}
1676{
1677 btBoxShape* shape = new btBoxShape(halfExtents);
1678 m_allocatedCollisionShapes.push_back(shape);
1679 return shape;
1680}
1682{
1683 btSphereShape* shape = new btSphereShape(radius);
1684 m_allocatedCollisionShapes.push_back(shape);
1685 return shape;
1686}
1687
1688
1690{
1691 btCapsuleShapeX* shape = new btCapsuleShapeX(radius,height);
1692 m_allocatedCollisionShapes.push_back(shape);
1693 return shape;
1694}
1695
1697{
1698 btCapsuleShape* shape = new btCapsuleShape(radius,height);
1699 m_allocatedCollisionShapes.push_back(shape);
1700 return shape;
1701}
1702
1704{
1705 btCapsuleShapeZ* shape = new btCapsuleShapeZ(radius,height);
1706 m_allocatedCollisionShapes.push_back(shape);
1707 return shape;
1708}
1709
1711{
1712 btCylinderShapeX* shape = new btCylinderShapeX(btVector3(height,radius,radius));
1713 m_allocatedCollisionShapes.push_back(shape);
1714 return shape;
1715}
1716
1718{
1719 btCylinderShape* shape = new btCylinderShape(btVector3(radius,height,radius));
1720 m_allocatedCollisionShapes.push_back(shape);
1721 return shape;
1722}
1723
1725{
1726 btCylinderShapeZ* shape = new btCylinderShapeZ(btVector3(radius,radius,height));
1727 m_allocatedCollisionShapes.push_back(shape);
1728 return shape;
1729}
1730
1732{
1733 btConeShapeX* shape = new btConeShapeX(radius,height);
1734 m_allocatedCollisionShapes.push_back(shape);
1735 return shape;
1736}
1737
1739{
1740 btConeShape* shape = new btConeShape(radius,height);
1741 m_allocatedCollisionShapes.push_back(shape);
1742 return shape;
1743}
1744
1746{
1747 btConeShapeZ* shape = new btConeShapeZ(radius,height);
1748 m_allocatedCollisionShapes.push_back(shape);
1749 return shape;
1750}
1751
1753{
1755 m_allocatedTriangleIndexArrays.push_back(in);
1756 return in;
1757}
1758
1760{
1761 btOptimizedBvh* bvh = new btOptimizedBvh();
1762 m_allocatedBvhs.push_back(bvh);
1763 return bvh;
1764}
1765
1766
1768{
1770 m_allocatedTriangleInfoMaps.push_back(tim);
1771 return tim;
1772}
1773
1775{
1776 if (bvh)
1777 {
1778 btBvhTriangleMeshShape* bvhTriMesh = new btBvhTriangleMeshShape(trimesh,bvh->isQuantized(), false);
1779 bvhTriMesh->setOptimizedBvh(bvh);
1780 m_allocatedCollisionShapes.push_back(bvhTriMesh);
1781 return bvhTriMesh;
1782 }
1783
1784 btBvhTriangleMeshShape* ts = new btBvhTriangleMeshShape(trimesh,true);
1785 m_allocatedCollisionShapes.push_back(ts);
1786 return ts;
1787
1788}
1790{
1791 return 0;
1792}
1794{
1795#ifdef USE_GIMPACT
1796 btGImpactMeshShape* shape = new btGImpactMeshShape(trimesh);
1797 m_allocatedCollisionShapes.push_back(shape);
1798 return shape;
1799#else
1800 return 0;
1801#endif
1802
1803}
1805{
1806 btConvexHullShape* shape = new btConvexHullShape();
1807 m_allocatedCollisionShapes.push_back(shape);
1808 return shape;
1809}
1810
1812{
1813 btCompoundShape* shape = new btCompoundShape();
1814 m_allocatedCollisionShapes.push_back(shape);
1815 return shape;
1816}
1817
1818
1820{
1821 btScaledBvhTriangleMeshShape* shape = new btScaledBvhTriangleMeshShape(meshShape,localScaling);
1822 m_allocatedCollisionShapes.push_back(shape);
1823 return shape;
1824}
1825
1827{
1828 btMultiSphereShape* shape = new btMultiSphereShape(positions, radi, numSpheres);
1829 m_allocatedCollisionShapes.push_back(shape);
1830 return shape;
1831}
1832
1834{
1835 static btRigidBody s_fixed(0, 0,0);
1836 s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));
1837 return s_fixed;
1838}
1839
1841{
1842 btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,rbB,pivotInA,pivotInB);
1843 m_allocatedConstraints.push_back(p2p);
1844 return p2p;
1845}
1846
1848{
1849 btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,pivotInA);
1850 m_allocatedConstraints.push_back(p2p);
1851 return p2p;
1852}
1853
1854
1855btHingeConstraint* btWorldImporter::createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA)
1856{
1857 btHingeConstraint* hinge = new btHingeConstraint(rbA,rbB,rbAFrame,rbBFrame,useReferenceFrameA);
1858 m_allocatedConstraints.push_back(hinge);
1859 return hinge;
1860}
1861
1863{
1864 btHingeConstraint* hinge = new btHingeConstraint(rbA,rbAFrame,useReferenceFrameA);
1865 m_allocatedConstraints.push_back(hinge);
1866 return hinge;
1867}
1868
1870{
1871 btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbB,rbAFrame,rbBFrame);
1872 m_allocatedConstraints.push_back(cone);
1873 return cone;
1874}
1875
1877{
1878 btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbAFrame);
1879 m_allocatedConstraints.push_back(cone);
1880 return cone;
1881}
1882
1883
1884btGeneric6DofConstraint* btWorldImporter::createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA)
1885{
1886 btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
1887 m_allocatedConstraints.push_back(dof);
1888 return dof;
1889}
1890
1892{
1893 btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbB,frameInB,useLinearReferenceFrameB);
1894 m_allocatedConstraints.push_back(dof);
1895 return dof;
1896}
1897
1899{
1900 btGeneric6DofSpring2Constraint* dof = new btGeneric6DofSpring2Constraint(rbA,rbB,frameInA,frameInB, (RotateOrder)rotateOrder);
1901 m_allocatedConstraints.push_back(dof);
1902 return dof;
1903}
1904
1905
1906
1908{
1909 btGeneric6DofSpringConstraint* dof = new btGeneric6DofSpringConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
1910 m_allocatedConstraints.push_back(dof);
1911 return dof;
1912}
1913
1914
1915btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA)
1916{
1917 btSliderConstraint* slider = new btSliderConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA);
1918 m_allocatedConstraints.push_back(slider);
1919 return slider;
1920}
1921
1922btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA)
1923{
1924 btSliderConstraint* slider = new btSliderConstraint(rbB,frameInB,useLinearReferenceFrameA);
1925 m_allocatedConstraints.push_back(slider);
1926 return slider;
1927}
1928
1930{
1931 btGearConstraint* gear = new btGearConstraint(rbA,rbB,axisInA,axisInB,ratio);
1932 m_allocatedConstraints.push_back(gear);
1933 return gear;
1934}
1935
1936 // query for data
1938{
1939 return m_allocatedCollisionShapes.size();
1940}
1941
1943{
1944 return m_allocatedCollisionShapes[index];
1945}
1946
1948{
1949 btCollisionShape** shapePtr = m_nameShapeMap.find(name);
1950 if (shapePtr&& *shapePtr)
1951 {
1952 return *shapePtr;
1953 }
1954 return 0;
1955}
1956
1958{
1959 btRigidBody** bodyPtr = m_nameBodyMap.find(name);
1960 if (bodyPtr && *bodyPtr)
1961 {
1962 return *bodyPtr;
1963 }
1964 return 0;
1965}
1966
1968{
1969 btTypedConstraint** constraintPtr = m_nameConstraintMap.find(name);
1970 if (constraintPtr && *constraintPtr)
1971 {
1972 return *constraintPtr;
1973 }
1974 return 0;
1975}
1976
1977const char* btWorldImporter::getNameForPointer(const void* ptr) const
1978{
1979 const char*const * namePtr = m_objectNameMap.find(ptr);
1980 if (namePtr && *namePtr)
1981 return *namePtr;
1982 return 0;
1983}
1984
1985
1987{
1988 return m_allocatedRigidBodies.size();
1989}
1990
1992{
1993 return m_allocatedRigidBodies[index];
1994}
1996{
1997 return m_allocatedConstraints.size();
1998}
1999
2001{
2002 return m_allocatedConstraints[index];
2003}
2004
2006{
2007 return m_allocatedBvhs.size();
2008}
2010{
2011 return m_allocatedBvhs[index];
2012}
2013
2015{
2016 return m_allocatedTriangleInfoMaps.size();
2017}
2018
2020{
2021 return m_allocatedTriangleInfoMaps[index];
2022}
2023
2024
2026{
2027 btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f);
2028 btVector3 localInertia;
2029 localInertia.setZero();
2031 if (shapePtr && *shapePtr)
2032 {
2033 btTransform startTransform;
2035 startTransform.deSerializeFloat(colObjData->m_collisionObjectData.m_worldTransform);
2036
2037 // startTransform.setBasis(btMatrix3x3::getIdentity());
2038 btCollisionShape* shape = (btCollisionShape*)*shapePtr;
2039 if (shape->isNonMoving())
2040 {
2041 mass = 0.f;
2042 }
2043 if (mass)
2044 {
2045 shape->calculateLocalInertia(mass,localInertia);
2046 }
2047 bool isDynamic = mass!=0.f;
2048 btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name);
2049 body->setFriction(colObjData->m_collisionObjectData.m_friction);
2051 btVector3 linearFactor,angularFactor;
2052 linearFactor.deSerializeFloat(colObjData->m_linearFactor);
2053 angularFactor.deSerializeFloat(colObjData->m_angularFactor);
2054 body->setLinearFactor(linearFactor);
2055 body->setAngularFactor(angularFactor);
2056
2057#ifdef USE_INTERNAL_EDGE_UTILITY
2059 {
2061 if (trimesh->getTriangleInfoMap())
2062 {
2064 }
2065 }
2066#endif //USE_INTERNAL_EDGE_UTILITY
2067 m_bodyMap.insert(colObjData,body);
2068 } else
2069 {
2070 printf("error: no shape found\n");
2071 }
2072}
2073
2075{
2076 btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f);
2077 btVector3 localInertia;
2078 localInertia.setZero();
2080 if (shapePtr && *shapePtr)
2081 {
2082 btTransform startTransform;
2084 startTransform.deSerializeDouble(colObjData->m_collisionObjectData.m_worldTransform);
2085
2086 // startTransform.setBasis(btMatrix3x3::getIdentity());
2087 btCollisionShape* shape = (btCollisionShape*)*shapePtr;
2088 if (shape->isNonMoving())
2089 {
2090 mass = 0.f;
2091 }
2092 if (mass)
2093 {
2094 shape->calculateLocalInertia(mass,localInertia);
2095 }
2096 bool isDynamic = mass!=0.f;
2097 btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name);
2100 btVector3 linearFactor,angularFactor;
2101 linearFactor.deSerializeDouble(colObjData->m_linearFactor);
2102 angularFactor.deSerializeDouble(colObjData->m_angularFactor);
2103 body->setLinearFactor(linearFactor);
2104 body->setAngularFactor(angularFactor);
2105
2106
2107#ifdef USE_INTERNAL_EDGE_UTILITY
2109 {
2111 if (trimesh->getTriangleInfoMap())
2112 {
2114 }
2115 }
2116#endif //USE_INTERNAL_EDGE_UTILITY
2117 m_bodyMap.insert(colObjData,body);
2118 } else
2119 {
2120 printf("error: no shape found\n");
2121 }
2122}
#define btAlignedFree(ptr)
#define btAlignedAlloc(size, alignment)
@ COMPOUND_SHAPE_PROXYTYPE
@ GIMPACT_SHAPE_PROXYTYPE
Used for GIMPACT Trimesh integration.
@ SOFTBODY_SHAPE_PROXYTYPE
@ SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE
@ TRIANGLE_MESH_SHAPE_PROXYTYPE
@ STATIC_PLANE_PROXYTYPE
@ SPHERE_SHAPE_PROXYTYPE
@ BOX_SHAPE_PROXYTYPE
@ MULTI_SPHERE_SHAPE_PROXYTYPE
@ CYLINDER_SHAPE_PROXYTYPE
@ CONE_SHAPE_PROXYTYPE
@ CAPSULE_SHAPE_PROXYTYPE
@ CONVEX_HULL_SHAPE_PROXYTYPE
@ PHY_FLOAT
@ PHY_UCHAR
@ PHY_DOUBLE
@ PHY_SHORT
@ PHY_INTEGER
@ CONST_GIMPACT_TRIMESH_SHAPE
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.
ContactAddedCallback gContactAddedCallback
This is to allow MaterialCombiner/Custom Friction/Restitution values.
bool(* ContactAddedCallback)(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
#define btAssert(x)
Definition: btScalar.h:131
@ SLIDER_CONSTRAINT_TYPE
@ GEAR_CONSTRAINT_TYPE
@ CONETWIST_CONSTRAINT_TYPE
@ FIXED_CONSTRAINT_TYPE
@ POINT2POINT_CONSTRAINT_TYPE
@ D6_SPRING_2_CONSTRAINT_TYPE
@ HINGE_CONSTRAINT_TYPE
@ D6_SPRING_CONSTRAINT_TYPE
@ D6_CONSTRAINT_TYPE
void resize(int newsize, const T &fillData=T())
The btBoxShape is a box primitive around the origin, its sides axis aligned with length specified by ...
Definition: btBoxShape.h:27
The btBvhTriangleMeshShape is a static-triangle mesh shape, it can only be used for fixed/non-moving ...
void setOptimizedBvh(btOptimizedBvh *bvh, const btVector3 &localScaling=btVector3(1, 1, 1))
const btTriangleInfoMap * getTriangleInfoMap() const
void setTriangleInfoMap(btTriangleInfoMap *triangleInfoMap)
btCapsuleShapeX represents a capsule around the Z axis the total height is height+2*radius,...
btCapsuleShapeZ represents a capsule around the Z axis the total height is height+2*radius,...
The btCapsuleShape represents a capsule around the Y axis, there is also the btCapsuleShapeX aligned ...
void deSerializeFloat(struct btCapsuleShapeData *dataBuffer)
btCollisionObject can be used to manage collision detection objects.
void setRestitution(btScalar rest)
void setCollisionFlags(int flags)
btTransform & getWorldTransform()
void setWorldTransform(const btTransform &worldTrans)
void setFriction(btScalar frict)
int getCollisionFlags() const
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
virtual void setMargin(btScalar margin)=0
int getShapeType() const
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const =0
bool isNonMoving() const
virtual void setLocalScaling(const btVector3 &scaling)=0
The btCompoundShape allows to store multiple other btCollisionShapes This allows for moving concave c...
void addChildShape(const btTransform &localTransform, btCollisionShape *shape)
virtual void setMargin(btScalar collisionMargin)
btConeShape implements a Cone shape, around the X axis
Definition: btConeShape.h:114
btConeShapeZ implements a Cone shape, around the Z axis
Definition: btConeShape.h:134
The btConeShape implements a cone shape primitive, centered around the origin and aligned with the Y ...
Definition: btConeShape.h:25
btConeTwistConstraint can be used to simulate ragdoll joints (upper arm, leg etc)
void setLimit(int limitIndex, btScalar limitValue)
void setDamping(btScalar damping)
The btConvexHullShape implements an implicit convex hull of an array of vertices.
void addPoint(const btVector3 &point, bool recalculateLocalAabb=true)
virtual void setMargin(btScalar margin)
The btCylinderShape class implements a cylinder shape primitive, centered around the origin....
The btDynamicsWorld is the interface class for several dynamics implementation, basic,...
virtual void removeRigidBody(btRigidBody *body)=0
btContactSolverInfo & getSolverInfo()
virtual void removeConstraint(btTypedConstraint *constraint)
virtual void addRigidBody(btRigidBody *body)=0
virtual void addConstraint(btTypedConstraint *constraint, bool disableCollisionsBetweenLinkedBodies=false)
virtual void setGravity(const btVector3 &gravity)=0
This class manages a mesh supplied by the btStridingMeshInterface interface.
virtual void setMargin(btScalar margin)
virtual void setLocalScaling(const btVector3 &scaling)
void updateBound()
performs refit operation
The btGeatConstraint will couple the angular velocity for two bodies around given local axis and rati...
btGeneric6DofConstraint between two rigidbodies each with a pivotpoint that descibes the axis locatio...
void setLinearLowerLimit(const btVector3 &linearLower)
void setAngularLowerLimit(const btVector3 &angularLower)
void setAngularUpperLimit(const btVector3 &angularUpper)
void setLinearUpperLimit(const btVector3 &linearUpper)
void setStiffness(int index, btScalar stiffness, bool limitIfNeeded=true)
void setDamping(int index, btScalar damping, bool limitIfNeeded=true)
void setLinearUpperLimit(const btVector3 &linearUpper)
void setAngularUpperLimit(const btVector3 &angularUpper)
void setAngularLowerLimit(const btVector3 &angularLower)
void setLinearLowerLimit(const btVector3 &linearLower)
Generic 6 DOF constraint that allows to set spring motors to any translational and rotational DOF.
void setDamping(int index, btScalar damping)
void setStiffness(int index, btScalar stiffness)
hinge constraint between two rigidbodies each with a pivotpoint that descibes the axis location in lo...
void setAngularOnly(bool angularOnly)
void setLimit(btScalar low, btScalar high, btScalar _softness=0.9f, btScalar _biasFactor=0.3f, btScalar _relaxationFactor=1.0f)
void enableAngularMotor(bool enableMotor, btScalar targetVelocity, btScalar maxMotorImpulse)
ManifoldContactPoint collects and maintains persistent contactpoints.
The btMultiSphereShape represents the convex hull of a collection of spheres.
The btOptimizedBvh extends the btQuantizedBvh to create AABB tree for triangle meshes,...
point to point constraint between two rigidbodies each with a pivotpoint that descibes the 'ballsocke...
virtual void deSerializeFloat(struct btQuantizedBvhFloatData &quantizedBvhFloatData)
virtual void deSerializeDouble(struct btQuantizedBvhDoubleData &quantizedBvhDoubleData)
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:63
void setLinearFactor(const btVector3 &linearFactor)
Definition: btRigidBody.h:268
void setMassProps(btScalar mass, const btVector3 &inertia)
void setAngularFactor(const btVector3 &angFac)
Definition: btRigidBody.h:493
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:203
The btScaledBvhTriangleMeshShape allows to instance a scaled version of an existing btBvhTriangleMesh...
void setUseFrameOffset(bool frameOffsetOnOff)
void setLowerLinLimit(btScalar lowerLimit)
void setUpperLinLimit(btScalar upperLimit)
void setUpperAngLimit(btScalar upperLimit)
void setLowerAngLimit(btScalar lowerLimit)
The btSphereShape implements an implicit sphere, centered around a local origin with radius.
Definition: btSphereShape.h:24
The btStaticPlaneShape simulates an infinite non-moving (static) collision plane.
The btStridingMeshInterface is the interface class for high performance generic access to triangle me...
void setScaling(const btVector3 &scaling)
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btTransform inverse() const
Return the inverse of this transform.
Definition: btTransform.h:188
void deSerializeFloat(const struct btTransformFloatData &dataIn)
Definition: btTransform.h:286
void deSerializeDouble(const struct btTransformDoubleData &dataIn)
Definition: btTransform.h:292
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:172
btVector3 & getOrigin()
Return the origin vector translation.
Definition: btTransform.h:117
void setOrigin(const btVector3 &origin)
Set the translational element.
Definition: btTransform.h:150
The btTriangleIndexVertexArray allows to access multiple triangle meshes, by indexing into existing t...
void addIndexedMesh(const btIndexedMesh &mesh, PHY_ScalarType indexType=PHY_INTEGER)
virtual int getNumSubParts() const
getNumSubParts returns the number of seperate subparts each subpart has a continuous array of vertice...
TypedConstraint is the baseclass for Bullet constraints and vehicles.
void setDbgDrawSize(btScalar dbgDrawSize)
void setEnabled(bool enabled)
void setOverrideNumSolverIterations(int overideNumIterations)
override the number of constraint solver iterations used to solve this constraint -1 will use the def...
void setBreakingImpulseThreshold(btScalar threshold)
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:84
const btScalar & getZ() const
Return the z value.
Definition: btVector3.h:577
void deSerializeFloat(const struct btVector3FloatData &dataIn)
Definition: btVector3.h:1330
void deSerializeDouble(const struct btVector3DoubleData &dataIn)
Definition: btVector3.h:1344
void setW(btScalar _w)
Set the w value.
Definition: btVector3.h:585
const btScalar & getY() const
Return the y value.
Definition: btVector3.h:575
void setZero()
Definition: btVector3.h:683
const btScalar & getX() const
Return the x value.
Definition: btVector3.h:573
char * duplicateName(const char *name)
btAlignedObjectArray< btTriangleIndexVertexArray * > m_allocatedTriangleIndexArrays
btAlignedObjectArray< char * > m_allocatedNames
virtual btCollisionObject * createCollisionObject(const btTransform &startTransform, btCollisionShape *shape, const char *bodyName)
btTypedConstraint * getConstraintByName(const char *name)
static btRigidBody & getFixedBody()
virtual btCollisionShape * createConeShapeY(btScalar radius, btScalar height)
btAlignedObjectArray< btCollisionObject * > m_allocatedRigidBodies
int getNumBvhs() const
virtual btCollisionShape * createCapsuleShapeY(btScalar radius, btScalar height)
btTypedConstraint * getConstraintByIndex(int index) const
virtual btOptimizedBvh * createOptimizedBvh()
acceleration and connectivity structures
virtual class btScaledBvhTriangleMeshShape * createScaledTrangleMeshShape(btBvhTriangleMeshShape *meshShape, const btVector3 &localScalingbtBvhTriangleMeshShape)
virtual btRigidBody * createRigidBody(bool isDynamic, btScalar mass, const btTransform &startTransform, btCollisionShape *shape, const char *bodyName)
void convertConstraintBackwardsCompatible281(btTypedConstraintData *constraintData, btRigidBody *rbA, btRigidBody *rbB, int fileVersion)
btRigidBody * getRigidBodyByName(const char *name)
virtual class btConvexHullShape * createConvexHullShape()
virtual btCollisionShape * createConvexTriangleMeshShape(btStridingMeshInterface *trimesh)
const char * getNameForPointer(const void *ptr) const
btHashMap< btHashPtr, btOptimizedBvh * > m_bvhMap
virtual btCollisionShape * createCapsuleShapeX(btScalar radius, btScalar height)
btHashMap< btHashPtr, btCollisionObject * > m_bodyMap
virtual btCollisionShape * createPlaneShape(const btVector3 &planeNormal, btScalar planeConstant)
shapes
btAlignedObjectArray< btOptimizedBvh * > m_allocatedBvhs
btCollisionObject * getRigidBodyByIndex(int index) const
btCollisionShape * getCollisionShapeByIndex(int index)
virtual btConeTwistConstraint * createConeTwistConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &rbAFrame, const btTransform &rbBFrame)
virtual class btMultiSphereShape * createMultiSphereShape(const btVector3 *positions, const btScalar *radi, int numSpheres)
virtual ~btWorldImporter()
virtual btStridingMeshInterfaceData * createStridingMeshInterfaceData(btStridingMeshInterfaceData *interfaceData)
btAlignedObjectArray< btTypedConstraint * > m_allocatedConstraints
btHashMap< btHashString, btRigidBody * > m_nameBodyMap
btHashMap< btHashPtr, const char * > m_objectNameMap
void convertConstraintDouble(btTypedConstraintDoubleData *constraintData, btRigidBody *rbA, btRigidBody *rbB, int fileVersion)
virtual btGeneric6DofSpring2Constraint * createGeneric6DofSpring2Constraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, int rotateOrder)
btAlignedObjectArray< unsigned char * > m_charIndexArrays
virtual btCollisionShape * createBoxShape(const btVector3 &halfExtents)
virtual void setDynamicsWorldInfo(const btVector3 &gravity, const btContactSolverInfo &solverInfo)
those virtuals are called by load and can be overridden by the user
int getNumRigidBodies() const
int getNumTriangleInfoMaps() const
virtual btTriangleIndexVertexArray * createMeshInterface(btStridingMeshInterfaceData &meshData)
btAlignedObjectArray< int * > m_indexArrays
virtual btGeneric6DofConstraint * createGeneric6DofConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, bool useLinearReferenceFrameA)
int getNumCollisionShapes() const
btAlignedObjectArray< btTriangleInfoMap * > m_allocatedTriangleInfoMaps
virtual btCollisionShape * createCylinderShapeY(btScalar radius, btScalar height)
virtual void deleteAllData()
delete all memory collision shapes, rigid bodies, constraints etc.
virtual btGeneric6DofSpringConstraint * createGeneric6DofSpringConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, bool useLinearReferenceFrameA)
virtual btCollisionShape * createConeShapeX(btScalar radius, btScalar height)
btDynamicsWorld * m_dynamicsWorld
virtual btCollisionShape * createCylinderShapeX(btScalar radius, btScalar height)
void convertConstraintFloat(btTypedConstraintFloatData *constraintData, btRigidBody *rbA, btRigidBody *rbB, int fileVersion)
virtual class btCompoundShape * createCompoundShape()
btWorldImporter(btDynamicsWorld *world)
btTriangleInfoMap * getTriangleInfoMapByIndex(int index) const
btAlignedObjectArray< btCollisionShape * > m_allocatedCollisionShapes
virtual btGearConstraint * createGearConstraint(btRigidBody &rbA, btRigidBody &rbB, const btVector3 &axisInA, const btVector3 &axisInB, btScalar ratio)
btHashMap< btHashString, btCollisionShape * > m_nameShapeMap
int getNumConstraints() const
virtual btCollisionShape * createConeShapeZ(btScalar radius, btScalar height)
virtual btHingeConstraint * createHingeConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &rbAFrame, const btTransform &rbBFrame, bool useReferenceFrameA=false)
btAlignedObjectArray< btVector3DoubleData * > m_doubleVertexArrays
btCollisionShape * convertCollisionShape(btCollisionShapeData *shapeData)
virtual btCollisionShape * createSphereShape(btScalar radius)
btCollisionShape * getCollisionShapeByName(const char *name)
btHashMap< btHashPtr, btCollisionShape * > m_shapeMap
void convertRigidBodyDouble(btRigidBodyDoubleData *colObjData)
btAlignedObjectArray< btVector3FloatData * > m_floatVertexArrays
btHashMap< btHashString, btTypedConstraint * > m_nameConstraintMap
virtual class btTriangleIndexVertexArray * createTriangleMeshContainer()
virtual btBvhTriangleMeshShape * createBvhTriangleMeshShape(btStridingMeshInterface *trimesh, btOptimizedBvh *bvh)
btAlignedObjectArray< btStridingMeshInterfaceData * > m_allocatedbtStridingMeshInterfaceDatas
virtual btGImpactMeshShape * createGimpactShape(btStridingMeshInterface *trimesh)
btOptimizedBvh * getBvhByIndex(int index) const
void convertRigidBodyFloat(btRigidBodyFloatData *colObjData)
virtual btPoint2PointConstraint * createPoint2PointConstraint(btRigidBody &rbA, btRigidBody &rbB, const btVector3 &pivotInA, const btVector3 &pivotInB)
constraints
virtual btCollisionShape * createCylinderShapeZ(btScalar radius, btScalar height)
virtual btTriangleInfoMap * createTriangleInfoMap()
virtual btCollisionShape * createCapsuleShapeZ(btScalar radius, btScalar height)
virtual btSliderConstraint * createSliderConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, bool useLinearReferenceFrameA)
btAlignedObjectArray< short int * > m_shortIndexArrays
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btTransformDoubleData m_worldTransform
btTransformFloatData m_worldTransform
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btTransformFloatData m_transform
btCollisionShapeData * m_childShape
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btCompoundShapeChildData * m_childShapePtr
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition: btConeShape.h:154
this structure is not used, except for loading pre-2.82 .bullet files
btTransformFloatData m_rbBFrame
btTransformFloatData m_rbAFrame
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btVector3DoubleData * m_unscaledPointsDoublePtr
btVector3FloatData * m_unscaledPointsFloatPtr
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btVector3FloatData m_implicitShapeDimensions
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btStridingMeshInterfaceData m_meshInterface
btVector3FloatData m_localScaling
btVector3DoubleData m_axisInA
btVector3DoubleData m_axisInB
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btVector3FloatData m_axisInB
btVector3FloatData m_axisInA
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btTransformDoubleData m_rbBFrame
btTransformDoubleData m_rbAFrame
this structure is not used, except for loading pre-2.82 .bullet files
btTransformDoubleData m_rbAFrame
btTransformDoubleData m_rbBFrame
btTransformFloatData m_rbAFrame
btTransformFloatData m_rbBFrame
The btIndexedMesh indexes a single vertex and index array.
PHY_ScalarType m_indexType
const unsigned char * m_vertexBase
const unsigned char * m_triangleIndexBase
PHY_ScalarType m_vertexType
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btShortIntIndexData * m_indices16
btCharIndexTripletData * m_3indices8
btVector3FloatData * m_vertices3f
btShortIntIndexTripletData * m_3indices16
btIntIndexData * m_indices32
btVector3DoubleData * m_vertices3d
btPositionAndRadius * m_localPositionArrayPtr
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 th...
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btVector3FloatData m_pos
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition: btRigidBody.h:591
btCollisionObjectDoubleData m_collisionObjectData
Definition: btRigidBody.h:592
btVector3DoubleData m_linearFactor
Definition: btRigidBody.h:597
btVector3DoubleData m_angularFactor
Definition: btRigidBody.h:596
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition: btRigidBody.h:565
btVector3FloatData m_linearFactor
Definition: btRigidBody.h:571
btVector3FloatData m_angularFactor
Definition: btRigidBody.h:570
btCollisionObjectFloatData m_collisionObjectData
Definition: btRigidBody.h:566
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btTransformFloatData m_rbBFrame
btTransformFloatData m_rbAFrame
btTransformDoubleData m_rbAFrame
btTransformDoubleData m_rbBFrame
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btVector3FloatData m_localScaling
btVector3FloatData m_planeNormal
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btVector3DoubleData m_origin
Definition: btTransform.h:262
btVector3FloatData m_origin
Definition: btTransform.h:256
The btTriangleInfoMap stores edge angle information for some triangles. You can compute this informat...
void deSerialize(struct btTriangleInfoMapData &data)
fills the dataBuffer and returns the struct name (and 0 on failure)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btStridingMeshInterfaceData m_meshInterface
btQuantizedBvhDoubleData * m_quantizedDoubleBvh
btQuantizedBvhFloatData * m_quantizedFloatBvh
btTriangleInfoMapData * m_triangleInfoMap
this structure is not used, except for loading pre-2.82 .bullet files
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
double m_floats[4]
Definition: btVector3.h:1319