00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef GIMPACT_SHAPE_H
00026 #define GIMPACT_SHAPE_H
00027
00028 #include "BulletCollision/CollisionShapes/btCollisionShape.h"
00029 #include "BulletCollision/CollisionShapes/btTriangleShape.h"
00030 #include "BulletCollision/CollisionShapes/btStridingMeshInterface.h"
00031 #include "BulletCollision/CollisionShapes/btCollisionMargin.h"
00032 #include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
00033 #include "BulletCollision/CollisionShapes/btConcaveShape.h"
00034 #include "BulletCollision/CollisionShapes/btTetrahedronShape.h"
00035 #include "LinearMath/btVector3.h"
00036 #include "LinearMath/btTransform.h"
00037 #include "LinearMath/btMatrix3x3.h"
00038 #include "LinearMath/btAlignedObjectArray.h"
00039
00040 #include "btGImpactQuantizedBvh.h"
00041
00042
00044 typedef btGImpactQuantizedBvh btGImpactBoxSet;
00045
00046 enum eGIMPACT_SHAPE_TYPE
00047 {
00048 CONST_GIMPACT_COMPOUND_SHAPE = 0,
00049 CONST_GIMPACT_TRIMESH_SHAPE_PART,
00050 CONST_GIMPACT_TRIMESH_SHAPE
00051 };
00052
00053
00055 class btTetrahedronShapeEx:public btBU_Simplex1to4
00056 {
00057 public:
00058 btTetrahedronShapeEx()
00059 {
00060 m_numVertices = 4;
00061 }
00062
00063
00064 SIMD_FORCE_INLINE void setVertices(
00065 const btVector3 & v0,const btVector3 & v1,
00066 const btVector3 & v2,const btVector3 & v3)
00067 {
00068 m_vertices[0] = v0;
00069 m_vertices[1] = v1;
00070 m_vertices[2] = v2;
00071 m_vertices[3] = v3;
00072 recalcLocalAabb();
00073 }
00074 };
00075
00076
00078 class btGImpactShapeInterface : public btConcaveShape
00079 {
00080 protected:
00081 btAABB m_localAABB;
00082 bool m_needs_update;
00083 btVector3 localScaling;
00084 btGImpactBoxSet m_box_set;
00085
00088 virtual void calcLocalAABB()
00089 {
00090 lockChildShapes();
00091 if(m_box_set.getNodeCount() == 0)
00092 {
00093 m_box_set.buildSet();
00094 }
00095 else
00096 {
00097 m_box_set.update();
00098 }
00099 unlockChildShapes();
00100
00101 m_localAABB = m_box_set.getGlobalBox();
00102 }
00103
00104
00105 public:
00106 btGImpactShapeInterface()
00107 {
00108 m_shapeType=GIMPACT_SHAPE_PROXYTYPE;
00109 m_localAABB.invalidate();
00110 m_needs_update = true;
00111 localScaling.setValue(1.f,1.f,1.f);
00112 }
00113
00114
00116
00122 SIMD_FORCE_INLINE void updateBound()
00123 {
00124 if(!m_needs_update) return;
00125 calcLocalAABB();
00126 m_needs_update = false;
00127 }
00128
00130
00133 void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
00134 {
00135 btAABB transformedbox = m_localAABB;
00136 transformedbox.appy_transform(t);
00137 aabbMin = transformedbox.m_min;
00138 aabbMax = transformedbox.m_max;
00139 }
00140
00142 virtual void postUpdate()
00143 {
00144 m_needs_update = true;
00145 }
00146
00148 SIMD_FORCE_INLINE const btAABB & getLocalBox()
00149 {
00150 return m_localAABB;
00151 }
00152
00153
00154 virtual int getShapeType() const
00155 {
00156 return GIMPACT_SHAPE_PROXYTYPE;
00157 }
00158
00162 virtual void setLocalScaling(const btVector3& scaling)
00163 {
00164 localScaling = scaling;
00165 postUpdate();
00166 }
00167
00168 virtual const btVector3& getLocalScaling() const
00169 {
00170 return localScaling;
00171 }
00172
00173
00174 virtual void setMargin(btScalar margin)
00175 {
00176 m_collisionMargin = margin;
00177 int i = getNumChildShapes();
00178 while(i--)
00179 {
00180 btCollisionShape* child = getChildShape(i);
00181 child->setMargin(margin);
00182 }
00183
00184 m_needs_update = true;
00185 }
00186
00187
00190
00192 virtual eGIMPACT_SHAPE_TYPE getGImpactShapeType() const = 0 ;
00193
00195 SIMD_FORCE_INLINE btGImpactBoxSet * getBoxSet()
00196 {
00197 return &m_box_set;
00198 }
00199
00201 SIMD_FORCE_INLINE bool hasBoxSet() const
00202 {
00203 if(m_box_set.getNodeCount() == 0) return false;
00204 return true;
00205 }
00206
00208 virtual const btPrimitiveManagerBase * getPrimitiveManager() const = 0;
00209
00210
00212 virtual int getNumChildShapes() const = 0;
00213
00215 virtual bool childrenHasTransform() const = 0;
00216
00218 virtual bool needsRetrieveTriangles() const = 0;
00219
00221 virtual bool needsRetrieveTetrahedrons() const = 0;
00222
00223 virtual void getBulletTriangle(int prim_index,btTriangleShapeEx & triangle) const = 0;
00224
00225 virtual void getBulletTetrahedron(int prim_index,btTetrahedronShapeEx & tetrahedron) const = 0;
00226
00227
00228
00230 virtual void lockChildShapes() const
00231 {
00232 }
00233
00234 virtual void unlockChildShapes() const
00235 {
00236 }
00237
00239 SIMD_FORCE_INLINE void getPrimitiveTriangle(int index,btPrimitiveTriangle & triangle) const
00240 {
00241 getPrimitiveManager()->get_primitive_triangle(index,triangle);
00242 }
00243
00244
00246
00248 virtual void getChildAabb(int child_index,const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
00249 {
00250 btAABB child_aabb;
00251 getPrimitiveManager()->get_primitive_box(child_index,child_aabb);
00252 child_aabb.appy_transform(t);
00253 aabbMin = child_aabb.m_min;
00254 aabbMax = child_aabb.m_max;
00255 }
00256
00258 virtual btCollisionShape* getChildShape(int index) = 0;
00259
00260
00262 virtual const btCollisionShape* getChildShape(int index) const = 0;
00263
00265 virtual btTransform getChildTransform(int index) const = 0;
00266
00268
00271 virtual void setChildTransform(int index, const btTransform & transform) = 0;
00272
00274
00275
00277 virtual void rayTest(const btVector3& rayFrom, const btVector3& rayTo, btCollisionWorld::RayResultCallback& resultCallback) const
00278 {
00279 (void) rayFrom; (void) rayTo; (void) resultCallback;
00280 }
00281
00283
00286 virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
00287 {
00288 (void) callback; (void) aabbMin; (void) aabbMax;
00289 }
00290
00292
00293 };
00294
00295
00297
00300 class btGImpactCompoundShape : public btGImpactShapeInterface
00301 {
00302 public:
00304 class CompoundPrimitiveManager:public btPrimitiveManagerBase
00305 {
00306 public:
00307 virtual ~CompoundPrimitiveManager() {}
00308 btGImpactCompoundShape * m_compoundShape;
00309
00310
00311 CompoundPrimitiveManager(const CompoundPrimitiveManager& compound)
00312 : btPrimitiveManagerBase()
00313 {
00314 m_compoundShape = compound.m_compoundShape;
00315 }
00316
00317 CompoundPrimitiveManager(btGImpactCompoundShape * compoundShape)
00318 {
00319 m_compoundShape = compoundShape;
00320 }
00321
00322 CompoundPrimitiveManager()
00323 {
00324 m_compoundShape = NULL;
00325 }
00326
00327 virtual bool is_trimesh() const
00328 {
00329 return false;
00330 }
00331
00332 virtual int get_primitive_count() const
00333 {
00334 return (int )m_compoundShape->getNumChildShapes();
00335 }
00336
00337 virtual void get_primitive_box(int prim_index ,btAABB & primbox) const
00338 {
00339 btTransform prim_trans;
00340 if(m_compoundShape->childrenHasTransform())
00341 {
00342 prim_trans = m_compoundShape->getChildTransform(prim_index);
00343 }
00344 else
00345 {
00346 prim_trans.setIdentity();
00347 }
00348 const btCollisionShape* shape = m_compoundShape->getChildShape(prim_index);
00349 shape->getAabb(prim_trans,primbox.m_min,primbox.m_max);
00350 }
00351
00352 virtual void get_primitive_triangle(int prim_index,btPrimitiveTriangle & triangle) const
00353 {
00354 btAssert(0);
00355 (void) prim_index; (void) triangle;
00356 }
00357
00358 };
00359
00360
00361
00362 protected:
00363 CompoundPrimitiveManager m_primitive_manager;
00364 btAlignedObjectArray<btTransform> m_childTransforms;
00365 btAlignedObjectArray<btCollisionShape*> m_childShapes;
00366
00367
00368 public:
00369
00370 btGImpactCompoundShape(bool children_has_transform = true)
00371 {
00372 (void) children_has_transform;
00373 m_primitive_manager.m_compoundShape = this;
00374 m_box_set.setPrimitiveManager(&m_primitive_manager);
00375 }
00376
00377 virtual ~btGImpactCompoundShape()
00378 {
00379 }
00380
00381
00383 virtual bool childrenHasTransform() const
00384 {
00385 if(m_childTransforms.size()==0) return false;
00386 return true;
00387 }
00388
00389
00391 virtual const btPrimitiveManagerBase * getPrimitiveManager() const
00392 {
00393 return &m_primitive_manager;
00394 }
00395
00397 SIMD_FORCE_INLINE CompoundPrimitiveManager * getCompoundPrimitiveManager()
00398 {
00399 return &m_primitive_manager;
00400 }
00401
00403 virtual int getNumChildShapes() const
00404 {
00405 return m_childShapes.size();
00406 }
00407
00408
00410 void addChildShape(const btTransform& localTransform,btCollisionShape* shape)
00411 {
00412 btAssert(shape->isConvex());
00413 m_childTransforms.push_back(localTransform);
00414 m_childShapes.push_back(shape);
00415 }
00416
00418 void addChildShape(btCollisionShape* shape)
00419 {
00420 btAssert(shape->isConvex());
00421 m_childShapes.push_back(shape);
00422 }
00423
00425 virtual btCollisionShape* getChildShape(int index)
00426 {
00427 return m_childShapes[index];
00428 }
00429
00431 virtual const btCollisionShape* getChildShape(int index) const
00432 {
00433 return m_childShapes[index];
00434 }
00435
00437
00439 virtual void getChildAabb(int child_index,const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
00440 {
00441
00442 if(childrenHasTransform())
00443 {
00444 m_childShapes[child_index]->getAabb(t*m_childTransforms[child_index],aabbMin,aabbMax);
00445 }
00446 else
00447 {
00448 m_childShapes[child_index]->getAabb(t,aabbMin,aabbMax);
00449 }
00450 }
00451
00452
00454 virtual btTransform getChildTransform(int index) const
00455 {
00456 btAssert(m_childTransforms.size() == m_childShapes.size());
00457 return m_childTransforms[index];
00458 }
00459
00461
00464 virtual void setChildTransform(int index, const btTransform & transform)
00465 {
00466 btAssert(m_childTransforms.size() == m_childShapes.size());
00467 m_childTransforms[index] = transform;
00468 postUpdate();
00469 }
00470
00472 virtual bool needsRetrieveTriangles() const
00473 {
00474 return false;
00475 }
00476
00478 virtual bool needsRetrieveTetrahedrons() const
00479 {
00480 return false;
00481 }
00482
00483
00484 virtual void getBulletTriangle(int prim_index,btTriangleShapeEx & triangle) const
00485 {
00486 (void) prim_index; (void) triangle;
00487 btAssert(0);
00488 }
00489
00490 virtual void getBulletTetrahedron(int prim_index,btTetrahedronShapeEx & tetrahedron) const
00491 {
00492 (void) prim_index; (void) tetrahedron;
00493 btAssert(0);
00494 }
00495
00496
00498 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
00499
00500 virtual const char* getName()const
00501 {
00502 return "GImpactCompound";
00503 }
00504
00505 virtual eGIMPACT_SHAPE_TYPE getGImpactShapeType() const
00506 {
00507 return CONST_GIMPACT_COMPOUND_SHAPE;
00508 }
00509
00510 };
00511
00512
00513
00515
00521 class btGImpactMeshShapePart : public btGImpactShapeInterface
00522 {
00523 public:
00525
00528 class TrimeshPrimitiveManager:public btPrimitiveManagerBase
00529 {
00530 public:
00531 btScalar m_margin;
00532 btStridingMeshInterface * m_meshInterface;
00533 btVector3 m_scale;
00534 int m_part;
00535 int m_lock_count;
00536 const unsigned char *vertexbase;
00537 int numverts;
00538 PHY_ScalarType type;
00539 int stride;
00540 const unsigned char *indexbase;
00541 int indexstride;
00542 int numfaces;
00543 PHY_ScalarType indicestype;
00544
00545 TrimeshPrimitiveManager()
00546 {
00547 m_meshInterface = NULL;
00548 m_part = 0;
00549 m_margin = 0.01f;
00550 m_scale = btVector3(1.f,1.f,1.f);
00551 m_lock_count = 0;
00552 vertexbase = 0;
00553 numverts = 0;
00554 stride = 0;
00555 indexbase = 0;
00556 indexstride = 0;
00557 numfaces = 0;
00558 }
00559
00560 TrimeshPrimitiveManager(const TrimeshPrimitiveManager & manager)
00561 : btPrimitiveManagerBase()
00562 {
00563 m_meshInterface = manager.m_meshInterface;
00564 m_part = manager.m_part;
00565 m_margin = manager.m_margin;
00566 m_scale = manager.m_scale;
00567 m_lock_count = 0;
00568 vertexbase = 0;
00569 numverts = 0;
00570 stride = 0;
00571 indexbase = 0;
00572 indexstride = 0;
00573 numfaces = 0;
00574
00575 }
00576
00577 TrimeshPrimitiveManager(
00578 btStridingMeshInterface * meshInterface, int part)
00579 {
00580 m_meshInterface = meshInterface;
00581 m_part = part;
00582 m_scale = m_meshInterface->getScaling();
00583 m_margin = 0.1f;
00584 m_lock_count = 0;
00585 vertexbase = 0;
00586 numverts = 0;
00587 stride = 0;
00588 indexbase = 0;
00589 indexstride = 0;
00590 numfaces = 0;
00591
00592 }
00593
00594 virtual ~TrimeshPrimitiveManager() {}
00595
00596 void lock()
00597 {
00598 if(m_lock_count>0)
00599 {
00600 m_lock_count++;
00601 return;
00602 }
00603 m_meshInterface->getLockedReadOnlyVertexIndexBase(
00604 &vertexbase,numverts,
00605 type, stride,&indexbase, indexstride, numfaces,indicestype,m_part);
00606
00607 m_lock_count = 1;
00608 }
00609
00610 void unlock()
00611 {
00612 if(m_lock_count == 0) return;
00613 if(m_lock_count>1)
00614 {
00615 --m_lock_count;
00616 return;
00617 }
00618 m_meshInterface->unLockReadOnlyVertexBase(m_part);
00619 vertexbase = NULL;
00620 m_lock_count = 0;
00621 }
00622
00623 virtual bool is_trimesh() const
00624 {
00625 return true;
00626 }
00627
00628 virtual int get_primitive_count() const
00629 {
00630 return (int )numfaces;
00631 }
00632
00633 SIMD_FORCE_INLINE int get_vertex_count() const
00634 {
00635 return (int )numverts;
00636 }
00637
00638 SIMD_FORCE_INLINE void get_indices(int face_index,int &i0,int &i1,int &i2) const
00639 {
00640 if(indicestype == PHY_SHORT)
00641 {
00642 short * s_indices = (short *)(indexbase + face_index*indexstride);
00643 i0 = s_indices[0];
00644 i1 = s_indices[1];
00645 i2 = s_indices[2];
00646 }
00647 else
00648 {
00649 int * i_indices = (int *)(indexbase + face_index*indexstride);
00650 i0 = i_indices[0];
00651 i1 = i_indices[1];
00652 i2 = i_indices[2];
00653 }
00654 }
00655
00656 SIMD_FORCE_INLINE void get_vertex(int vertex_index, btVector3 & vertex) const
00657 {
00658 if(type == PHY_DOUBLE)
00659 {
00660 double * dvertices = (double *)(vertexbase + vertex_index*stride);
00661 vertex[0] = btScalar(dvertices[0]*m_scale[0]);
00662 vertex[1] = btScalar(dvertices[1]*m_scale[1]);
00663 vertex[2] = btScalar(dvertices[2]*m_scale[2]);
00664 }
00665 else
00666 {
00667 float * svertices = (float *)(vertexbase + vertex_index*stride);
00668 vertex[0] = svertices[0]*m_scale[0];
00669 vertex[1] = svertices[1]*m_scale[1];
00670 vertex[2] = svertices[2]*m_scale[2];
00671 }
00672 }
00673
00674 virtual void get_primitive_box(int prim_index ,btAABB & primbox) const
00675 {
00676 btPrimitiveTriangle triangle;
00677 get_primitive_triangle(prim_index,triangle);
00678 primbox.calc_from_triangle_margin(
00679 triangle.m_vertices[0],
00680 triangle.m_vertices[1],triangle.m_vertices[2],triangle.m_margin);
00681 }
00682
00683 virtual void get_primitive_triangle(int prim_index,btPrimitiveTriangle & triangle) const
00684 {
00685 int indices[3];
00686 get_indices(prim_index,indices[0],indices[1],indices[2]);
00687 get_vertex(indices[0],triangle.m_vertices[0]);
00688 get_vertex(indices[1],triangle.m_vertices[1]);
00689 get_vertex(indices[2],triangle.m_vertices[2]);
00690 triangle.m_margin = m_margin;
00691 }
00692
00693 SIMD_FORCE_INLINE void get_bullet_triangle(int prim_index,btTriangleShapeEx & triangle) const
00694 {
00695 int indices[3];
00696 get_indices(prim_index,indices[0],indices[1],indices[2]);
00697 get_vertex(indices[0],triangle.m_vertices1[0]);
00698 get_vertex(indices[1],triangle.m_vertices1[1]);
00699 get_vertex(indices[2],triangle.m_vertices1[2]);
00700 triangle.setMargin(m_margin);
00701 }
00702
00703 };
00704
00705
00706 protected:
00707 TrimeshPrimitiveManager m_primitive_manager;
00708 public:
00709
00710 btGImpactMeshShapePart()
00711 {
00712 m_box_set.setPrimitiveManager(&m_primitive_manager);
00713 }
00714
00715
00716 btGImpactMeshShapePart(btStridingMeshInterface * meshInterface, int part)
00717 {
00718 m_primitive_manager.m_meshInterface = meshInterface;
00719 m_primitive_manager.m_part = part;
00720 m_box_set.setPrimitiveManager(&m_primitive_manager);
00721 }
00722
00723 virtual ~btGImpactMeshShapePart()
00724 {
00725 }
00726
00728 virtual bool childrenHasTransform() const
00729 {
00730 return false;
00731 }
00732
00733
00735 virtual void lockChildShapes() const
00736 {
00737 void * dummy = (void*)(m_box_set.getPrimitiveManager());
00738 TrimeshPrimitiveManager * dummymanager = static_cast<TrimeshPrimitiveManager *>(dummy);
00739 dummymanager->lock();
00740 }
00741
00742 virtual void unlockChildShapes() const
00743 {
00744 void * dummy = (void*)(m_box_set.getPrimitiveManager());
00745 TrimeshPrimitiveManager * dummymanager = static_cast<TrimeshPrimitiveManager *>(dummy);
00746 dummymanager->unlock();
00747 }
00748
00750 virtual int getNumChildShapes() const
00751 {
00752 return m_primitive_manager.get_primitive_count();
00753 }
00754
00755
00757 virtual btCollisionShape* getChildShape(int index)
00758 {
00759 (void) index;
00760 btAssert(0);
00761 return NULL;
00762 }
00763
00764
00765
00767 virtual const btCollisionShape* getChildShape(int index) const
00768 {
00769 (void) index;
00770 btAssert(0);
00771 return NULL;
00772 }
00773
00775 virtual btTransform getChildTransform(int index) const
00776 {
00777 (void) index;
00778 btAssert(0);
00779 return btTransform();
00780 }
00781
00783
00786 virtual void setChildTransform(int index, const btTransform & transform)
00787 {
00788 (void) index;
00789 (void) transform;
00790 btAssert(0);
00791 }
00792
00793
00795 virtual const btPrimitiveManagerBase * getPrimitiveManager() const
00796 {
00797 return &m_primitive_manager;
00798 }
00799
00800 SIMD_FORCE_INLINE TrimeshPrimitiveManager * getTrimeshPrimitiveManager()
00801 {
00802 return &m_primitive_manager;
00803 }
00804
00805
00806
00807
00808
00809 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
00810
00811
00812
00813
00814 virtual const char* getName()const
00815 {
00816 return "GImpactMeshShapePart";
00817 }
00818
00819 virtual eGIMPACT_SHAPE_TYPE getGImpactShapeType() const
00820 {
00821 return CONST_GIMPACT_TRIMESH_SHAPE_PART;
00822 }
00823
00825 virtual bool needsRetrieveTriangles() const
00826 {
00827 return true;
00828 }
00829
00831 virtual bool needsRetrieveTetrahedrons() const
00832 {
00833 return false;
00834 }
00835
00836 virtual void getBulletTriangle(int prim_index,btTriangleShapeEx & triangle) const
00837 {
00838 m_primitive_manager.get_bullet_triangle(prim_index,triangle);
00839 }
00840
00841 virtual void getBulletTetrahedron(int prim_index,btTetrahedronShapeEx & tetrahedron) const
00842 {
00843 (void) prim_index;
00844 (void) tetrahedron;
00845 btAssert(0);
00846 }
00847
00848
00849
00850 SIMD_FORCE_INLINE int getVertexCount() const
00851 {
00852 return m_primitive_manager.get_vertex_count();
00853 }
00854
00855 SIMD_FORCE_INLINE void getVertex(int vertex_index, btVector3 & vertex) const
00856 {
00857 m_primitive_manager.get_vertex(vertex_index,vertex);
00858 }
00859
00860 SIMD_FORCE_INLINE void setMargin(btScalar margin)
00861 {
00862 m_primitive_manager.m_margin = margin;
00863 postUpdate();
00864 }
00865
00866 SIMD_FORCE_INLINE btScalar getMargin() const
00867 {
00868 return m_primitive_manager.m_margin;
00869 }
00870
00871 virtual void setLocalScaling(const btVector3& scaling)
00872 {
00873 m_primitive_manager.m_scale = scaling;
00874 postUpdate();
00875 }
00876
00877 virtual const btVector3& getLocalScaling() const
00878 {
00879 return m_primitive_manager.m_scale;
00880 }
00881
00882 SIMD_FORCE_INLINE int getPart() const
00883 {
00884 return (int)m_primitive_manager.m_part;
00885 }
00886
00887 virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
00888 };
00889
00890
00892
00899 class btGImpactMeshShape : public btGImpactShapeInterface
00900 {
00901 btStridingMeshInterface* m_meshInterface;
00902
00903 protected:
00904 btAlignedObjectArray<btGImpactMeshShapePart*> m_mesh_parts;
00905 void buildMeshParts(btStridingMeshInterface * meshInterface)
00906 {
00907 for (int i=0;i<meshInterface->getNumSubParts() ;++i )
00908 {
00909 btGImpactMeshShapePart * newpart = new btGImpactMeshShapePart(meshInterface,i);
00910 m_mesh_parts.push_back(newpart);
00911 }
00912 }
00913
00915 virtual void calcLocalAABB()
00916 {
00917 m_localAABB.invalidate();
00918 int i = m_mesh_parts.size();
00919 while(i--)
00920 {
00921 m_mesh_parts[i]->updateBound();
00922 m_localAABB.merge(m_mesh_parts[i]->getLocalBox());
00923 }
00924 }
00925
00926 public:
00927 btGImpactMeshShape(btStridingMeshInterface * meshInterface)
00928 {
00929 m_meshInterface = meshInterface;
00930 buildMeshParts(meshInterface);
00931 }
00932
00933 virtual ~btGImpactMeshShape()
00934 {
00935 int i = m_mesh_parts.size();
00936 while(i--)
00937 {
00938 btGImpactMeshShapePart * part = m_mesh_parts[i];
00939 delete part;
00940 }
00941 m_mesh_parts.clear();
00942 }
00943
00944
00945 btStridingMeshInterface* getMeshInterface()
00946 {
00947 return m_meshInterface;
00948 }
00949
00950 const btStridingMeshInterface* getMeshInterface() const
00951 {
00952 return m_meshInterface;
00953 }
00954
00955 int getMeshPartCount() const
00956 {
00957 return m_mesh_parts.size();
00958 }
00959
00960 btGImpactMeshShapePart * getMeshPart(int index)
00961 {
00962 return m_mesh_parts[index];
00963 }
00964
00965
00966
00967 const btGImpactMeshShapePart * getMeshPart(int index) const
00968 {
00969 return m_mesh_parts[index];
00970 }
00971
00972
00973 virtual void setLocalScaling(const btVector3& scaling)
00974 {
00975 localScaling = scaling;
00976
00977 int i = m_mesh_parts.size();
00978 while(i--)
00979 {
00980 btGImpactMeshShapePart * part = m_mesh_parts[i];
00981 part->setLocalScaling(scaling);
00982 }
00983
00984 m_needs_update = true;
00985 }
00986
00987 virtual void setMargin(btScalar margin)
00988 {
00989 m_collisionMargin = margin;
00990
00991 int i = m_mesh_parts.size();
00992 while(i--)
00993 {
00994 btGImpactMeshShapePart * part = m_mesh_parts[i];
00995 part->setMargin(margin);
00996 }
00997
00998 m_needs_update = true;
00999 }
01000
01002 virtual void postUpdate()
01003 {
01004 int i = m_mesh_parts.size();
01005 while(i--)
01006 {
01007 btGImpactMeshShapePart * part = m_mesh_parts[i];
01008 part->postUpdate();
01009 }
01010
01011 m_needs_update = true;
01012 }
01013
01014 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
01015
01016
01018 virtual const btPrimitiveManagerBase * getPrimitiveManager() const
01019 {
01020 btAssert(0);
01021 return NULL;
01022 }
01023
01024
01026 virtual int getNumChildShapes() const
01027 {
01028 btAssert(0);
01029 return 0;
01030 }
01031
01032
01034 virtual bool childrenHasTransform() const
01035 {
01036 btAssert(0);
01037 return false;
01038 }
01039
01041 virtual bool needsRetrieveTriangles() const
01042 {
01043 btAssert(0);
01044 return false;
01045 }
01046
01048 virtual bool needsRetrieveTetrahedrons() const
01049 {
01050 btAssert(0);
01051 return false;
01052 }
01053
01054 virtual void getBulletTriangle(int prim_index,btTriangleShapeEx & triangle) const
01055 {
01056 (void) prim_index; (void) triangle;
01057 btAssert(0);
01058 }
01059
01060 virtual void getBulletTetrahedron(int prim_index,btTetrahedronShapeEx & tetrahedron) const
01061 {
01062 (void) prim_index; (void) tetrahedron;
01063 btAssert(0);
01064 }
01065
01067 virtual void lockChildShapes() const
01068 {
01069 btAssert(0);
01070 }
01071
01072 virtual void unlockChildShapes() const
01073 {
01074 btAssert(0);
01075 }
01076
01077
01078
01079
01081
01083 virtual void getChildAabb(int child_index,const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
01084 {
01085 (void) child_index; (void) t; (void) aabbMin; (void) aabbMax;
01086 btAssert(0);
01087 }
01088
01090 virtual btCollisionShape* getChildShape(int index)
01091 {
01092 (void) index;
01093 btAssert(0);
01094 return NULL;
01095 }
01096
01097
01099 virtual const btCollisionShape* getChildShape(int index) const
01100 {
01101 (void) index;
01102 btAssert(0);
01103 return NULL;
01104 }
01105
01107 virtual btTransform getChildTransform(int index) const
01108 {
01109 (void) index;
01110 btAssert(0);
01111 return btTransform();
01112 }
01113
01115
01118 virtual void setChildTransform(int index, const btTransform & transform)
01119 {
01120 (void) index; (void) transform;
01121 btAssert(0);
01122 }
01123
01124
01125 virtual eGIMPACT_SHAPE_TYPE getGImpactShapeType() const
01126 {
01127 return CONST_GIMPACT_TRIMESH_SHAPE;
01128 }
01129
01130
01131 virtual const char* getName()const
01132 {
01133 return "GImpactMesh";
01134 }
01135
01136 virtual void rayTest(const btVector3& rayFrom, const btVector3& rayTo, btCollisionWorld::RayResultCallback& resultCallback) const;
01137
01139
01142 virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
01143
01144 virtual int calculateSerializeBufferSize() const;
01145
01147 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
01148
01149 };
01150
01152 struct btGImpactMeshShapeData
01153 {
01154 btCollisionShapeData m_collisionShapeData;
01155
01156 btStridingMeshInterfaceData m_meshInterface;
01157
01158 btVector3FloatData m_localScaling;
01159
01160 float m_collisionMargin;
01161
01162 int m_gimpactSubType;
01163 };
01164
01165 SIMD_FORCE_INLINE int btGImpactMeshShape::calculateSerializeBufferSize() const
01166 {
01167 return sizeof(btGImpactMeshShapeData);
01168 }
01169
01170
01171 #endif //GIMPACT_MESH_SHAPE_H