Bullet Collision Detection & Physics Library
btCollisionWorldImporter.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2014 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
18#include "LinearMath/btSerializer.h" //for btBulletSerializedArrays definition
19
20#ifdef SUPPORT_GIMPACT_SHAPE_IMPORT
22#endif //SUPPORT_GIMPACT_SHAPE_IMPORT
23
25 : m_collisionWorld(world),
26 m_verboseMode(0)
27{
28}
29
31{
32}
33
35{
38
39 int i;
40
41 for (i = 0; i < arrays->m_bvhsDouble.size(); i++)
42 {
44 btQuantizedBvhDoubleData* bvhData = arrays->m_bvhsDouble[i];
45 bvh->deSerializeDouble(*bvhData);
46 m_bvhMap.insert(arrays->m_bvhsDouble[i], bvh);
47 }
48 for (i = 0; i < arrays->m_bvhsFloat.size(); i++)
49 {
51 btQuantizedBvhFloatData* bvhData = arrays->m_bvhsFloat[i];
52 bvh->deSerializeFloat(*bvhData);
53 m_bvhMap.insert(arrays->m_bvhsFloat[i], bvh);
54 }
55
56 for (i = 0; i < arrays->m_colShapeData.size(); i++)
57 {
58 btCollisionShapeData* shapeData = arrays->m_colShapeData[i];
59 btCollisionShape* shape = convertCollisionShape(shapeData);
60 if (shape)
61 {
62 // printf("shapeMap.insert(%x,%x)\n",shapeData,shape);
63 m_shapeMap.insert(shapeData, shape);
64 }
65
66 if (shape && shapeData->m_name)
67 {
68 char* newname = duplicateName(shapeData->m_name);
69 m_objectNameMap.insert(shape, newname);
70 m_nameShapeMap.insert(newname, shape);
71 }
72 }
73
74 for (i = 0; i < arrays->m_collisionObjectDataDouble.size(); i++)
75 {
77 btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionShape);
78 if (shapePtr && *shapePtr)
79 {
80 btTransform startTransform;
81 colObjData->m_worldTransform.m_origin.m_floats[3] = 0.f;
82 startTransform.deSerializeDouble(colObjData->m_worldTransform);
83
84 btCollisionShape* shape = (btCollisionShape*)*shapePtr;
85 btCollisionObject* body = createCollisionObject(startTransform, shape, colObjData->m_name);
86 body->setFriction(btScalar(colObjData->m_friction));
87 body->setRestitution(btScalar(colObjData->m_restitution));
88
89#ifdef USE_INTERNAL_EDGE_UTILITY
91 {
93 if (trimesh->getTriangleInfoMap())
94 {
96 }
97 }
98#endif //USE_INTERNAL_EDGE_UTILITY
99 m_bodyMap.insert(colObjData, body);
100 }
101 else
102 {
103 printf("error: no shape found\n");
104 }
105 }
106 for (i = 0; i < arrays->m_collisionObjectDataFloat.size(); i++)
107 {
109 btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionShape);
110 if (shapePtr && *shapePtr)
111 {
112 btTransform startTransform;
113 colObjData->m_worldTransform.m_origin.m_floats[3] = 0.f;
114 startTransform.deSerializeFloat(colObjData->m_worldTransform);
115
116 btCollisionShape* shape = (btCollisionShape*)*shapePtr;
117 btCollisionObject* body = createCollisionObject(startTransform, shape, colObjData->m_name);
118
119#ifdef USE_INTERNAL_EDGE_UTILITY
121 {
123 if (trimesh->getTriangleInfoMap())
124 {
126 }
127 }
128#endif //USE_INTERNAL_EDGE_UTILITY
129 m_bodyMap.insert(colObjData, body);
130 }
131 else
132 {
133 printf("error: no shape found\n");
134 }
135 }
136
137 return true;
138}
139
141{
142 int i;
143
144 for (i = 0; i < m_allocatedCollisionObjects.size(); i++)
145 {
149 }
150
152
153 for (i = 0; i < m_allocatedCollisionShapes.size(); i++)
154 {
156 }
158
159 for (i = 0; i < m_allocatedBvhs.size(); i++)
160 {
161 delete m_allocatedBvhs[i];
162 }
164
165 for (i = 0; i < m_allocatedTriangleInfoMaps.size(); i++)
166 {
168 }
170 for (i = 0; i < m_allocatedTriangleIndexArrays.size(); i++)
171 {
173 }
175 for (i = 0; i < m_allocatedNames.size(); i++)
176 {
177 delete[] m_allocatedNames[i];
178 }
180
181 for (i = 0; i < m_allocatedbtStridingMeshInterfaceDatas.size(); i++)
182 {
184
185 for (int a = 0; a < curData->m_numMeshParts; a++)
186 {
187 btMeshPartData* curPart = &curData->m_meshPartsPtr[a];
188 if (curPart->m_vertices3f)
189 delete[] curPart->m_vertices3f;
190
191 if (curPart->m_vertices3d)
192 delete[] curPart->m_vertices3d;
193
194 if (curPart->m_indices32)
195 delete[] curPart->m_indices32;
196
197 if (curPart->m_3indices16)
198 delete[] curPart->m_3indices16;
199
200 if (curPart->m_indices16)
201 delete[] curPart->m_indices16;
202
203 if (curPart->m_3indices8)
204 delete[] curPart->m_3indices8;
205 }
206 delete[] curData->m_meshPartsPtr;
207 delete curData;
208 }
210
211 for (i = 0; i < m_indexArrays.size(); i++)
212 {
214 }
216
217 for (i = 0; i < m_shortIndexArrays.size(); i++)
218 {
220 }
222
223 for (i = 0; i < m_charIndexArrays.size(); i++)
224 {
226 }
228
229 for (i = 0; i < m_floatVertexArrays.size(); i++)
230 {
232 }
234
235 for (i = 0; i < m_doubleVertexArrays.size(); i++)
236 {
238 }
240}
241
243{
244 btCollisionShape* shape = 0;
245
246 switch (shapeData->m_shapeType)
247 {
249 {
250 btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*)shapeData;
251 btVector3 planeNormal, localScaling;
252 planeNormal.deSerializeFloat(planeData->m_planeNormal);
253 localScaling.deSerializeFloat(planeData->m_localScaling);
254 shape = createPlaneShape(planeNormal, planeData->m_planeConstant);
255 shape->setLocalScaling(localScaling);
256
257 break;
258 }
260 {
262 btCollisionShapeData* colShapeData = (btCollisionShapeData*)&scaledMesh->m_trimeshShapeData;
264 btCollisionShape* childShape = convertCollisionShape(colShapeData);
265 btBvhTriangleMeshShape* meshShape = (btBvhTriangleMeshShape*)childShape;
266 btVector3 localScaling;
267 localScaling.deSerializeFloat(scaledMesh->m_localScaling);
268
269 shape = createScaledTrangleMeshShape(meshShape, localScaling);
270 break;
271 }
272#ifdef SUPPORT_GIMPACT_SHAPE_IMPORT
274 {
275 btGImpactMeshShapeData* gimpactData = (btGImpactMeshShapeData*)shapeData;
277 {
279 btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
280
281 btGImpactMeshShape* gimpactShape = createGimpactShape(meshInterface);
282 btVector3 localScaling;
283 localScaling.deSerializeFloat(gimpactData->m_localScaling);
284 gimpactShape->setLocalScaling(localScaling);
285 gimpactShape->setMargin(btScalar(gimpactData->m_collisionMargin));
286 gimpactShape->updateBound();
287 shape = gimpactShape;
288 }
289 else
290 {
291 printf("unsupported gimpact sub type\n");
292 }
293 break;
294 }
295#endif //SUPPORT_GIMPACT_SHAPE_IMPORT
296 //The btCapsuleShape* API has issue passing the margin/scaling/halfextents unmodified through the API
297 //so deal with this
299 {
300 btCapsuleShapeData* capData = (btCapsuleShapeData*)shapeData;
301
302 switch (capData->m_upAxis)
303 {
304 case 0:
305 {
306 shape = createCapsuleShapeX(1, 1);
307 break;
308 }
309 case 1:
310 {
311 shape = createCapsuleShapeY(1, 1);
312 break;
313 }
314 case 2:
315 {
316 shape = createCapsuleShapeZ(1, 1);
317 break;
318 }
319 default:
320 {
321 printf("error: wrong up axis for btCapsuleShape\n");
322 }
323 };
324 if (shape)
325 {
326 btCapsuleShape* cap = (btCapsuleShape*)shape;
327 cap->deSerializeFloat(capData);
328 }
329 break;
330 }
337 {
339 btVector3 implicitShapeDimensions;
340 implicitShapeDimensions.deSerializeFloat(bsd->m_implicitShapeDimensions);
341 btVector3 localScaling;
342 localScaling.deSerializeFloat(bsd->m_localScaling);
344 switch (shapeData->m_shapeType)
345 {
347 {
348 btBoxShape* box = (btBoxShape*)createBoxShape(implicitShapeDimensions / localScaling + margin);
349 //box->initializePolyhedralFeatures();
350 shape = box;
351
352 break;
353 }
355 {
356 shape = createSphereShape(implicitShapeDimensions.getX());
357 break;
358 }
359
361 {
362 btCylinderShapeData* cylData = (btCylinderShapeData*)shapeData;
363 btVector3 halfExtents = implicitShapeDimensions + margin;
364 switch (cylData->m_upAxis)
365 {
366 case 0:
367 {
368 shape = createCylinderShapeX(halfExtents.getY(), halfExtents.getX());
369 break;
370 }
371 case 1:
372 {
373 shape = createCylinderShapeY(halfExtents.getX(), halfExtents.getY());
374 break;
375 }
376 case 2:
377 {
378 shape = createCylinderShapeZ(halfExtents.getX(), halfExtents.getZ());
379 break;
380 }
381 default:
382 {
383 printf("unknown Cylinder up axis\n");
384 }
385 };
386
387 break;
388 }
390 {
391 btConeShapeData* conData = (btConeShapeData*)shapeData;
392 btVector3 halfExtents = implicitShapeDimensions; //+margin;
393 switch (conData->m_upIndex)
394 {
395 case 0:
396 {
397 shape = createConeShapeX(halfExtents.getY(), halfExtents.getX());
398 break;
399 }
400 case 1:
401 {
402 shape = createConeShapeY(halfExtents.getX(), halfExtents.getY());
403 break;
404 }
405 case 2:
406 {
407 shape = createConeShapeZ(halfExtents.getX(), halfExtents.getZ());
408 break;
409 }
410 default:
411 {
412 printf("unknown Cone up axis\n");
413 }
414 };
415
416 break;
417 }
419 {
421 int numSpheres = mss->m_localPositionArraySize;
422
425 radii.resize(numSpheres);
426 tmpPos.resize(numSpheres);
427 int i;
428 for (i = 0; i < numSpheres; i++)
429 {
430 tmpPos[i].deSerializeFloat(mss->m_localPositionArrayPtr[i].m_pos);
431 radii[i] = mss->m_localPositionArrayPtr[i].m_radius;
432 }
433 shape = createMultiSphereShape(&tmpPos[0], &radii[0], numSpheres);
434 break;
435 }
437 {
438 // int sz = sizeof(btConvexHullShapeData);
439 // int sz2 = sizeof(btConvexInternalShapeData);
440 // int sz3 = sizeof(btCollisionShapeData);
442 int numPoints = convexData->m_numUnscaledPoints;
443
445 tmpPoints.resize(numPoints);
446 int i;
447 for (i = 0; i < numPoints; i++)
448 {
449#ifdef BT_USE_DOUBLE_PRECISION
450 if (convexData->m_unscaledPointsDoublePtr)
451 tmpPoints[i].deSerialize(convexData->m_unscaledPointsDoublePtr[i]);
452 if (convexData->m_unscaledPointsFloatPtr)
453 tmpPoints[i].deSerializeFloat(convexData->m_unscaledPointsFloatPtr[i]);
454#else
455 if (convexData->m_unscaledPointsFloatPtr)
456 tmpPoints[i].deSerialize(convexData->m_unscaledPointsFloatPtr[i]);
457 if (convexData->m_unscaledPointsDoublePtr)
458 tmpPoints[i].deSerializeDouble(convexData->m_unscaledPointsDoublePtr[i]);
459#endif //BT_USE_DOUBLE_PRECISION
460 }
462 for (i = 0; i < numPoints; i++)
463 {
464 hullShape->addPoint(tmpPoints[i]);
465 }
466 hullShape->setMargin(bsd->m_collisionMargin);
467 //hullShape->initializePolyhedralFeatures();
468 shape = hullShape;
469 break;
470 }
471 default:
472 {
473 printf("error: cannot create shape type (%d)\n", shapeData->m_shapeType);
474 }
475 }
476
477 if (shape)
478 {
479 shape->setMargin(bsd->m_collisionMargin);
480
481 btVector3 localScaling;
482 localScaling.deSerializeFloat(bsd->m_localScaling);
483 shape->setLocalScaling(localScaling);
484 }
485 break;
486 }
488 {
491 btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
492 if (!meshInterface->getNumSubParts())
493 {
494 return 0;
495 }
496
497 btVector3 scaling;
499 meshInterface->setScaling(scaling);
500
501 btOptimizedBvh* bvh = 0;
502#if 1
503 if (trimesh->m_quantizedFloatBvh)
504 {
505 btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedFloatBvh);
506 if (bvhPtr && *bvhPtr)
507 {
508 bvh = *bvhPtr;
509 }
510 else
511 {
512 bvh = createOptimizedBvh();
514 }
515 }
516 if (trimesh->m_quantizedDoubleBvh)
517 {
519 if (bvhPtr && *bvhPtr)
520 {
521 bvh = *bvhPtr;
522 }
523 else
524 {
525 bvh = createOptimizedBvh();
527 }
528 }
529#endif
530
531 btBvhTriangleMeshShape* trimeshShape = createBvhTriangleMeshShape(meshInterface, bvh);
532 trimeshShape->setMargin(trimesh->m_collisionMargin);
533 shape = trimeshShape;
534
535 if (trimesh->m_triangleInfoMap)
536 {
538 map->deSerialize(*trimesh->m_triangleInfoMap);
539 trimeshShape->setTriangleInfoMap(map);
540
541#ifdef USE_INTERNAL_EDGE_UTILITY
542 gContactAddedCallback = btAdjustInternalEdgeContactsCallback;
543#endif //USE_INTERNAL_EDGE_UTILITY
544 }
545
546 //printf("trimesh->m_collisionMargin=%f\n",trimesh->m_collisionMargin);
547 break;
548 }
550 {
551 btCompoundShapeData* compoundData = (btCompoundShapeData*)shapeData;
552 btCompoundShape* compoundShape = createCompoundShape();
553
554 //btCompoundShapeChildData* childShapeDataArray = &compoundData->m_childShapePtr[0];
555
557 for (int i = 0; i < compoundData->m_numChildShapes; i++)
558 {
559 //btCompoundShapeChildData* ptr = &compoundData->m_childShapePtr[i];
560
562
563 btCollisionShape* childShape = convertCollisionShape(cd);
564 if (childShape)
565 {
566 btTransform localTransform;
567 localTransform.deSerializeFloat(compoundData->m_childShapePtr[i].m_transform);
568 compoundShape->addChildShape(localTransform, childShape);
569 }
570 else
571 {
572#ifdef _DEBUG
573 printf("error: couldn't create childShape for compoundShape\n");
574#endif
575 }
576 }
577 shape = compoundShape;
578
579 break;
580 }
582 {
583 return 0;
584 }
585 default:
586 {
587#ifdef _DEBUG
588 printf("unsupported shape type (%d)\n", shapeData->m_shapeType);
589#endif
590 }
591 }
592
593 return shape;
594}
595
597{
598 if (name)
599 {
600 int l = (int)strlen(name);
601 char* newName = new char[l + 1];
602 memcpy(newName, name, l);
603 newName[l] = 0;
605 return newName;
606 }
607 return 0;
608}
609
611{
613
614 for (int i = 0; i < meshData.m_numMeshParts; i++)
615 {
616 btIndexedMesh meshPart;
617 meshPart.m_numTriangles = meshData.m_meshPartsPtr[i].m_numTriangles;
618 meshPart.m_numVertices = meshData.m_meshPartsPtr[i].m_numVertices;
619
620 if (meshData.m_meshPartsPtr[i].m_indices32)
621 {
622 meshPart.m_indexType = PHY_INTEGER;
623 meshPart.m_triangleIndexStride = 3 * sizeof(int);
624 int* indexArray = (int*)btAlignedAlloc(sizeof(int) * 3 * meshPart.m_numTriangles, 16);
625 m_indexArrays.push_back(indexArray);
626 for (int j = 0; j < 3 * meshPart.m_numTriangles; j++)
627 {
628 indexArray[j] = meshData.m_meshPartsPtr[i].m_indices32[j].m_value;
629 }
630 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
631 }
632 else
633 {
634 if (meshData.m_meshPartsPtr[i].m_3indices16)
635 {
636 meshPart.m_indexType = PHY_SHORT;
637 meshPart.m_triangleIndexStride = sizeof(short int) * 3; //sizeof(btShortIntIndexTripletData);
638
639 short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int) * 3 * meshPart.m_numTriangles, 16);
640 m_shortIndexArrays.push_back(indexArray);
641
642 for (int j = 0; j < meshPart.m_numTriangles; j++)
643 {
644 indexArray[3 * j] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[0];
645 indexArray[3 * j + 1] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[1];
646 indexArray[3 * j + 2] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[2];
647 }
648
649 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
650 }
651 if (meshData.m_meshPartsPtr[i].m_indices16)
652 {
653 meshPart.m_indexType = PHY_SHORT;
654 meshPart.m_triangleIndexStride = 3 * sizeof(short int);
655 short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int) * 3 * meshPart.m_numTriangles, 16);
656 m_shortIndexArrays.push_back(indexArray);
657 for (int j = 0; j < 3 * meshPart.m_numTriangles; j++)
658 {
659 indexArray[j] = meshData.m_meshPartsPtr[i].m_indices16[j].m_value;
660 }
661
662 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
663 }
664
665 if (meshData.m_meshPartsPtr[i].m_3indices8)
666 {
667 meshPart.m_indexType = PHY_UCHAR;
668 meshPart.m_triangleIndexStride = sizeof(unsigned char) * 3;
669
670 unsigned char* indexArray = (unsigned char*)btAlignedAlloc(sizeof(unsigned char) * 3 * meshPart.m_numTriangles, 16);
671 m_charIndexArrays.push_back(indexArray);
672
673 for (int j = 0; j < meshPart.m_numTriangles; j++)
674 {
675 indexArray[3 * j] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[0];
676 indexArray[3 * j + 1] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[1];
677 indexArray[3 * j + 2] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[2];
678 }
679
680 meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
681 }
682 }
683
684 if (meshData.m_meshPartsPtr[i].m_vertices3f)
685 {
686 meshPart.m_vertexType = PHY_FLOAT;
687 meshPart.m_vertexStride = sizeof(btVector3FloatData);
690
691 for (int j = 0; j < meshPart.m_numVertices; j++)
692 {
693 vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[0];
694 vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[1];
695 vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[2];
696 vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[3];
697 }
698 meshPart.m_vertexBase = (const unsigned char*)vertices;
699 }
700 else
701 {
702 meshPart.m_vertexType = PHY_DOUBLE;
703 meshPart.m_vertexStride = sizeof(btVector3DoubleData);
704
707
708 for (int j = 0; j < meshPart.m_numVertices; j++)
709 {
710 vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[0];
711 vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[1];
712 vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[2];
713 vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[3];
714 }
715 meshPart.m_vertexBase = (const unsigned char*)vertices;
716 }
717
718 if (meshPart.m_triangleIndexBase && meshPart.m_vertexBase)
719 {
720 meshInterface->addIndexedMesh(meshPart, meshPart.m_indexType);
721 }
722 }
723
724 return meshInterface;
725}
726
728{
729 //create a new btStridingMeshInterfaceData that is an exact copy of shapedata and store it in the WorldImporter
731
732 newData->m_scaling = interfaceData->m_scaling;
733 newData->m_numMeshParts = interfaceData->m_numMeshParts;
734 newData->m_meshPartsPtr = new btMeshPartData[newData->m_numMeshParts];
735
736 for (int i = 0; i < newData->m_numMeshParts; i++)
737 {
738 btMeshPartData* curPart = &interfaceData->m_meshPartsPtr[i];
739 btMeshPartData* curNewPart = &newData->m_meshPartsPtr[i];
740
741 curNewPart->m_numTriangles = curPart->m_numTriangles;
742 curNewPart->m_numVertices = curPart->m_numVertices;
743
744 if (curPart->m_vertices3f)
745 {
746 curNewPart->m_vertices3f = new btVector3FloatData[curNewPart->m_numVertices];
747 memcpy(curNewPart->m_vertices3f, curPart->m_vertices3f, sizeof(btVector3FloatData) * curNewPart->m_numVertices);
748 }
749 else
750 curNewPart->m_vertices3f = NULL;
751
752 if (curPart->m_vertices3d)
753 {
754 curNewPart->m_vertices3d = new btVector3DoubleData[curNewPart->m_numVertices];
755 memcpy(curNewPart->m_vertices3d, curPart->m_vertices3d, sizeof(btVector3DoubleData) * curNewPart->m_numVertices);
756 }
757 else
758 curNewPart->m_vertices3d = NULL;
759
760 int numIndices = curNewPart->m_numTriangles * 3;
763 bool uninitialized3indices8Workaround = false;
764
765 if (curPart->m_indices32)
766 {
767 uninitialized3indices8Workaround = true;
768 curNewPart->m_indices32 = new btIntIndexData[numIndices];
769 memcpy(curNewPart->m_indices32, curPart->m_indices32, sizeof(btIntIndexData) * numIndices);
770 }
771 else
772 curNewPart->m_indices32 = NULL;
773
774 if (curPart->m_3indices16)
775 {
776 uninitialized3indices8Workaround = true;
777 curNewPart->m_3indices16 = new btShortIntIndexTripletData[curNewPart->m_numTriangles];
778 memcpy(curNewPart->m_3indices16, curPart->m_3indices16, sizeof(btShortIntIndexTripletData) * curNewPart->m_numTriangles);
779 }
780 else
781 curNewPart->m_3indices16 = NULL;
782
783 if (curPart->m_indices16)
784 {
785 uninitialized3indices8Workaround = true;
786 curNewPart->m_indices16 = new btShortIntIndexData[numIndices];
787 memcpy(curNewPart->m_indices16, curPart->m_indices16, sizeof(btShortIntIndexData) * numIndices);
788 }
789 else
790 curNewPart->m_indices16 = NULL;
791
792 if (!uninitialized3indices8Workaround && curPart->m_3indices8)
793 {
794 curNewPart->m_3indices8 = new btCharIndexTripletData[curNewPart->m_numTriangles];
795 memcpy(curNewPart->m_3indices8, curPart->m_3indices8, sizeof(btCharIndexTripletData) * curNewPart->m_numTriangles);
796 }
797 else
798 curNewPart->m_3indices8 = NULL;
799 }
800
802
803 return (newData);
804}
805
806#ifdef USE_INTERNAL_EDGE_UTILITY
808
809static bool btAdjustInternalEdgeContactsCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, int index0, const btCollisionObject* colObj1, int partId1, int index1)
810{
811 btAdjustInternalEdgeContacts(cp, colObj1, colObj0, partId1, index1);
812 //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_BACKFACE_MODE);
813 //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_DOUBLE_SIDED+BT_TRIANGLE_CONCAVE_DOUBLE_SIDED);
814 return true;
815}
816#endif //USE_INTERNAL_EDGE_UTILITY
817
818/*
819btRigidBody* btWorldImporter::createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform,btCollisionShape* shape,const char* bodyName)
820{
821 btVector3 localInertia;
822 localInertia.setZero();
823
824 if (mass)
825 shape->calculateLocalInertia(mass,localInertia);
826
827 btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
828 body->setWorldTransform(startTransform);
829
830 if (m_dynamicsWorld)
831 m_dynamicsWorld->addRigidBody(body);
832
833 if (bodyName)
834 {
835 char* newname = duplicateName(bodyName);
836 m_objectNameMap.insert(body,newname);
837 m_nameBodyMap.insert(newname,body);
838 }
839 m_allocatedRigidBodies.push_back(body);
840 return body;
841
842}
843*/
844
846{
847 btCollisionObject** bodyPtr = m_nameColObjMap.find(name);
848 if (bodyPtr && *bodyPtr)
849 {
850 return *bodyPtr;
851 }
852 return 0;
853}
854
856{
857 btCollisionObject* colObj = new btCollisionObject();
858 colObj->setWorldTransform(startTransform);
859 colObj->setCollisionShape(shape);
860 m_collisionWorld->addCollisionObject(colObj); //todo: flags etc
861
862 if (bodyName)
863 {
864 char* newname = duplicateName(bodyName);
865 m_objectNameMap.insert(colObj, newname);
866 m_nameColObjMap.insert(newname, colObj);
867 }
869
870 return colObj;
871}
872
874{
875 btStaticPlaneShape* shape = new btStaticPlaneShape(planeNormal, planeConstant);
877 return shape;
878}
880{
881 btBoxShape* shape = new btBoxShape(halfExtents);
883 return shape;
884}
886{
887 btSphereShape* shape = new btSphereShape(radius);
889 return shape;
890}
891
893{
894 btCapsuleShapeX* shape = new btCapsuleShapeX(radius, height);
896 return shape;
897}
898
900{
901 btCapsuleShape* shape = new btCapsuleShape(radius, height);
903 return shape;
904}
905
907{
908 btCapsuleShapeZ* shape = new btCapsuleShapeZ(radius, height);
910 return shape;
911}
912
914{
915 btCylinderShapeX* shape = new btCylinderShapeX(btVector3(height, radius, radius));
917 return shape;
918}
919
921{
922 btCylinderShape* shape = new btCylinderShape(btVector3(radius, height, radius));
924 return shape;
925}
926
928{
929 btCylinderShapeZ* shape = new btCylinderShapeZ(btVector3(radius, radius, height));
931 return shape;
932}
933
935{
936 btConeShapeX* shape = new btConeShapeX(radius, height);
938 return shape;
939}
940
942{
943 btConeShape* shape = new btConeShape(radius, height);
945 return shape;
946}
947
949{
950 btConeShapeZ* shape = new btConeShapeZ(radius, height);
952 return shape;
953}
954
956{
959 return in;
960}
961
963{
964 btOptimizedBvh* bvh = new btOptimizedBvh();
966 return bvh;
967}
968
970{
973 return tim;
974}
975
977{
978 if (bvh)
979 {
980 btBvhTriangleMeshShape* bvhTriMesh = new btBvhTriangleMeshShape(trimesh, bvh->isQuantized(), false);
981 bvhTriMesh->setOptimizedBvh(bvh);
983 return bvhTriMesh;
984 }
985
986 btBvhTriangleMeshShape* ts = new btBvhTriangleMeshShape(trimesh, true);
988 return ts;
989}
991{
992 return 0;
993}
994#ifdef SUPPORT_GIMPACT_SHAPE_IMPORT
995btGImpactMeshShape* btCollisionWorldImporter::createGimpactShape(btStridingMeshInterface* trimesh)
996{
997 btGImpactMeshShape* shape = new btGImpactMeshShape(trimesh);
999 return shape;
1000}
1001#endif //SUPPORT_GIMPACT_SHAPE_IMPORT
1002
1004{
1005 btConvexHullShape* shape = new btConvexHullShape();
1007 return shape;
1008}
1009
1011{
1012 btCompoundShape* shape = new btCompoundShape();
1014 return shape;
1015}
1016
1018{
1019 btScaledBvhTriangleMeshShape* shape = new btScaledBvhTriangleMeshShape(meshShape, localScaling);
1021 return shape;
1022}
1023
1025{
1026 btMultiSphereShape* shape = new btMultiSphereShape(positions, radi, numSpheres);
1028 return shape;
1029}
1030
1031// query for data
1033{
1035}
1036
1038{
1039 return m_allocatedCollisionShapes[index];
1040}
1041
1043{
1044 btCollisionShape** shapePtr = m_nameShapeMap.find(name);
1045 if (shapePtr && *shapePtr)
1046 {
1047 return *shapePtr;
1048 }
1049 return 0;
1050}
1051
1052const char* btCollisionWorldImporter::getNameForPointer(const void* ptr) const
1053{
1054 const char* const* namePtr = m_objectNameMap.find(ptr);
1055 if (namePtr && *namePtr)
1056 return *namePtr;
1057 return 0;
1058}
1059
1061{
1063}
1064
1066{
1067 return m_allocatedRigidBodies[index];
1068}
1069
1071{
1072 return m_allocatedBvhs.size();
1073}
1075{
1076 return m_allocatedBvhs[index];
1077}
1078
1080{
1082}
1083
1085{
1086 return m_allocatedTriangleInfoMaps[index];
1087}
#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:314
int size() const
return the number of elements in the array
void resize(int newsize, const T &fillData=T())
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0),...
void push_back(const T &_Val)
The btBoxShape is a box primitive around the origin, its sides axis aligned with length specified by ...
Definition: btBoxShape.h:28
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)
virtual void setCollisionShape(btCollisionShape *collisionShape)
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 setLocalScaling(const btVector3 &scaling)=0
btAlignedObjectArray< btOptimizedBvh * > m_allocatedBvhs
virtual void deleteAllData()
delete all memory collision shapes, rigid bodies, constraints etc.
virtual btStridingMeshInterfaceData * createStridingMeshInterfaceData(btStridingMeshInterfaceData *interfaceData)
virtual btOptimizedBvh * createOptimizedBvh()
acceleration and connectivity structures
btAlignedObjectArray< btTriangleIndexVertexArray * > m_allocatedTriangleIndexArrays
virtual btCollisionShape * createCylinderShapeX(btScalar radius, btScalar height)
bool convertAllObjects(btBulletSerializedArrays *arrays)
btCollisionShape * getCollisionShapeByName(const char *name)
virtual btCollisionShape * createPlaneShape(const btVector3 &planeNormal, btScalar planeConstant)
shapes
char * duplicateName(const char *name)
virtual class btTriangleIndexVertexArray * createTriangleMeshContainer()
btCollisionShape * convertCollisionShape(btCollisionShapeData *shapeData)
virtual btCollisionShape * createConeShapeZ(btScalar radius, btScalar height)
btTriangleInfoMap * getTriangleInfoMapByIndex(int index) const
btAlignedObjectArray< btCollisionObject * > m_allocatedRigidBodies
virtual class btCompoundShape * createCompoundShape()
virtual class btMultiSphereShape * createMultiSphereShape(const btVector3 *positions, const btScalar *radi, int numSpheres)
btHashMap< btHashPtr, btCollisionShape * > m_shapeMap
virtual btCollisionShape * createConeShapeY(btScalar radius, btScalar height)
virtual btCollisionShape * createSphereShape(btScalar radius)
btCollisionShape * getCollisionShapeByIndex(int index)
virtual btCollisionShape * createBoxShape(const btVector3 &halfExtents)
btAlignedObjectArray< btVector3DoubleData * > m_doubleVertexArrays
virtual btCollisionShape * createCylinderShapeZ(btScalar radius, btScalar height)
virtual class btConvexHullShape * createConvexHullShape()
btAlignedObjectArray< int * > m_indexArrays
const char * getNameForPointer(const void *ptr) const
virtual btTriangleInfoMap * createTriangleInfoMap()
virtual btCollisionShape * createConeShapeX(btScalar radius, btScalar height)
btHashMap< btHashString, btCollisionShape * > m_nameShapeMap
btCollisionObject * getCollisionObjectByName(const char *name)
btAlignedObjectArray< char * > m_allocatedNames
virtual btBvhTriangleMeshShape * createBvhTriangleMeshShape(btStridingMeshInterface *trimesh, btOptimizedBvh *bvh)
btAlignedObjectArray< short int * > m_shortIndexArrays
btAlignedObjectArray< btStridingMeshInterfaceData * > m_allocatedbtStridingMeshInterfaceDatas
btOptimizedBvh * getBvhByIndex(int index) const
btHashMap< btHashString, btCollisionObject * > m_nameColObjMap
btCollisionObject * getRigidBodyByIndex(int index) const
btHashMap< btHashPtr, btOptimizedBvh * > m_bvhMap
btHashMap< btHashPtr, const char * > m_objectNameMap
btAlignedObjectArray< btCollisionObject * > m_allocatedCollisionObjects
virtual btCollisionShape * createConvexTriangleMeshShape(btStridingMeshInterface *trimesh)
virtual class btScaledBvhTriangleMeshShape * createScaledTrangleMeshShape(btBvhTriangleMeshShape *meshShape, const btVector3 &localScalingbtBvhTriangleMeshShape)
virtual btCollisionShape * createCylinderShapeY(btScalar radius, btScalar height)
virtual btCollisionShape * createCapsuleShapeY(btScalar radius, btScalar height)
virtual btCollisionShape * createCapsuleShapeZ(btScalar radius, btScalar height)
btAlignedObjectArray< btVector3FloatData * > m_floatVertexArrays
btAlignedObjectArray< btTriangleInfoMap * > m_allocatedTriangleInfoMaps
virtual btCollisionObject * createCollisionObject(const btTransform &startTransform, btCollisionShape *shape, const char *bodyName)
those virtuals are called by load and can be overridden by the user
virtual btTriangleIndexVertexArray * createMeshInterface(btStridingMeshInterfaceData &meshData)
btHashMap< btHashPtr, btCollisionObject * > m_bodyMap
btCollisionWorldImporter(btCollisionWorld *world)
btAlignedObjectArray< unsigned char * > m_charIndexArrays
btAlignedObjectArray< btCollisionShape * > m_allocatedCollisionShapes
virtual btCollisionShape * createCapsuleShapeX(btScalar radius, btScalar height)
CollisionWorld is interface and container for the collision detection.
virtual void removeCollisionObject(btCollisionObject *collisionObject)
virtual void addCollisionObject(btCollisionObject *collisionObject, int collisionFilterGroup=btBroadphaseProxy::DefaultFilter, int collisionFilterMask=btBroadphaseProxy::AllFilter)
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:108
btConeShapeZ implements a Cone shape, around the Z axis
Definition: btConeShape.h:126
The btConeShape implements a cone shape primitive, centered around the origin and aligned with the Y ...
Definition: btConeShape.h:26
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....
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
void insert(const Key &key, const Value &value)
Definition: btHashMap.h:264
void clear()
Definition: btHashMap.h:461
const Value * find(const Key &key) const
Definition: btHashMap.h:424
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,...
virtual void deSerializeFloat(struct btQuantizedBvhFloatData &quantizedBvhFloatData)
virtual void deSerializeDouble(struct btQuantizedBvhDoubleData &quantizedBvhDoubleData)
The btScaledBvhTriangleMeshShape allows to instance a scaled version of an existing btBvhTriangleMesh...
The btSphereShape implements an implicit sphere, centered around a local origin with radius.
Definition: btSphereShape.h:25
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:30
void deSerializeFloat(const struct btTransformFloatData &dataIn)
Definition: btTransform.h:275
void deSerializeDouble(const struct btTransformDoubleData &dataIn)
Definition: btTransform.h:281
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 separate subparts each subpart has a continuous array of vertice...
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
const btScalar & getZ() const
Return the z value.
Definition: btVector3.h:565
void deSerializeFloat(const struct btVector3FloatData &dataIn)
Definition: btVector3.h:1298
const btScalar & getY() const
Return the y value.
Definition: btVector3.h:563
const btScalar & getX() const
Return the x value.
Definition: btVector3.h:561
btAlignedObjectArray< struct btQuantizedBvhDoubleData * > m_bvhsDouble
Definition: btSerializer.h:138
btAlignedObjectArray< struct btCollisionObjectFloatData * > m_collisionObjectDataFloat
Definition: btSerializer.h:146
btAlignedObjectArray< struct btCollisionObjectDoubleData * > m_collisionObjectDataDouble
Definition: btSerializer.h:145
btAlignedObjectArray< struct btCollisionShapeData * > m_colShapeData
Definition: btSerializer.h:140
btAlignedObjectArray< struct btQuantizedBvhFloatData * > m_bvhsFloat
Definition: btSerializer.h:139
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btTransformDoubleData m_worldTransform
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
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:144
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
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
btVector3FloatData m_pos
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
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:254
btVector3FloatData m_origin
Definition: btTransform.h:248
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
double m_floats[4]
Definition: btVector3.h:1288