btStridingMeshInterface.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef BT_STRIDING_MESHINTERFACE_H
  14. #define BT_STRIDING_MESHINTERFACE_H
  15. #include "bullet/LinearMath/btVector3.h"
  16. #include "btTriangleCallback.h"
  17. #include "btConcaveShape.h"
  18. /// The btStridingMeshInterface is the interface class for high performance generic access to triangle meshes, used in combination with btBvhTriangleMeshShape and some other collision shapes.
  19. /// Using index striding of 3*sizeof(integer) it can use triangle arrays, using index striding of 1*sizeof(integer) it can handle triangle strips.
  20. /// It allows for sharing graphics and collision meshes. Also it provides locking/unlocking of graphics meshes that are in gpu memory.
  21. ATTRIBUTE_ALIGNED16(class ) btStridingMeshInterface
  22. {
  23. protected:
  24. btVector3 m_scaling;
  25. public:
  26. BT_DECLARE_ALIGNED_ALLOCATOR();
  27. btStridingMeshInterface() :m_scaling(btScalar(1.),btScalar(1.),btScalar(1.))
  28. {
  29. }
  30. virtual ~btStridingMeshInterface();
  31. virtual void InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
  32. ///brute force method to calculate aabb
  33. void calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax);
  34. /// get read and write access to a subpart of a triangle mesh
  35. /// this subpart has a continuous array of vertices and indices
  36. /// in this way the mesh can be handled as chunks of memory with striding
  37. /// very similar to OpenGL vertexarray support
  38. /// make a call to unLockVertexBase when the read and write access is finished
  39. virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0)=0;
  40. virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const=0;
  41. /// unLockVertexBase finishes the access to a subpart of the triangle mesh
  42. /// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished
  43. virtual void unLockVertexBase(int subpart)=0;
  44. virtual void unLockReadOnlyVertexBase(int subpart) const=0;
  45. /// getNumSubParts returns the number of seperate subparts
  46. /// each subpart has a continuous array of vertices and indices
  47. virtual int getNumSubParts() const=0;
  48. virtual void preallocateVertices(int numverts)=0;
  49. virtual void preallocateIndices(int numindices)=0;
  50. virtual bool hasPremadeAabb() const { return false; }
  51. virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const
  52. {
  53. (void) aabbMin;
  54. (void) aabbMax;
  55. }
  56. virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const
  57. {
  58. (void) aabbMin;
  59. (void) aabbMax;
  60. }
  61. const btVector3& getScaling() const {
  62. return m_scaling;
  63. }
  64. void setScaling(const btVector3& scaling)
  65. {
  66. m_scaling = scaling;
  67. }
  68. virtual int calculateSerializeBufferSize() const;
  69. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  70. virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
  71. };
  72. struct btIntIndexData
  73. {
  74. int m_value;
  75. };
  76. struct btShortIntIndexData
  77. {
  78. short m_value;
  79. char m_pad[2];
  80. };
  81. struct btShortIntIndexTripletData
  82. {
  83. short m_values[3];
  84. char m_pad[2];
  85. };
  86. struct btCharIndexTripletData
  87. {
  88. unsigned char m_values[3];
  89. char m_pad;
  90. };
  91. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  92. struct btMeshPartData
  93. {
  94. btVector3FloatData *m_vertices3f;
  95. btVector3DoubleData *m_vertices3d;
  96. btIntIndexData *m_indices32;
  97. btShortIntIndexTripletData *m_3indices16;
  98. btCharIndexTripletData *m_3indices8;
  99. btShortIntIndexData *m_indices16;//backwards compatibility
  100. int m_numTriangles;//length of m_indices = m_numTriangles
  101. int m_numVertices;
  102. };
  103. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  104. struct btStridingMeshInterfaceData
  105. {
  106. btMeshPartData *m_meshPartsPtr;
  107. btVector3FloatData m_scaling;
  108. int m_numMeshParts;
  109. char m_padding[4];
  110. };
  111. SIMD_FORCE_INLINE int btStridingMeshInterface::calculateSerializeBufferSize() const
  112. {
  113. return sizeof(btStridingMeshInterfaceData);
  114. }
  115. #endif //BT_STRIDING_MESHINTERFACE_H