You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

163 line
5.3 KiB

  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 "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. class btStridingMeshInterface
  22. {
  23. protected:
  24. btVector3 m_scaling;
  25. public:
  26. btStridingMeshInterface() :m_scaling(btScalar(1.),btScalar(1.),btScalar(1.))
  27. {
  28. }
  29. virtual ~btStridingMeshInterface();
  30. virtual void InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
  31. ///brute force method to calculate aabb
  32. void calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax);
  33. /// get read and write access to a subpart of a triangle mesh
  34. /// this subpart has a continuous array of vertices and indices
  35. /// in this way the mesh can be handled as chunks of memory with striding
  36. /// very similar to OpenGL vertexarray support
  37. /// make a call to unLockVertexBase when the read and write access is finished
  38. 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;
  39. 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;
  40. /// unLockVertexBase finishes the access to a subpart of the triangle mesh
  41. /// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished
  42. virtual void unLockVertexBase(int subpart)=0;
  43. virtual void unLockReadOnlyVertexBase(int subpart) const=0;
  44. /// getNumSubParts returns the number of seperate subparts
  45. /// each subpart has a continuous array of vertices and indices
  46. virtual int getNumSubParts() const=0;
  47. virtual void preallocateVertices(int numverts)=0;
  48. virtual void preallocateIndices(int numindices)=0;
  49. virtual bool hasPremadeAabb() const { return false; }
  50. virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const
  51. {
  52. (void) aabbMin;
  53. (void) aabbMax;
  54. }
  55. virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const
  56. {
  57. (void) aabbMin;
  58. (void) aabbMax;
  59. }
  60. const btVector3& getScaling() const {
  61. return m_scaling;
  62. }
  63. void setScaling(const btVector3& scaling)
  64. {
  65. m_scaling = scaling;
  66. }
  67. virtual int calculateSerializeBufferSize() const;
  68. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  69. virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
  70. };
  71. struct btIntIndexData
  72. {
  73. int m_value;
  74. };
  75. struct btShortIntIndexData
  76. {
  77. short m_value;
  78. char m_pad[2];
  79. };
  80. struct btShortIntIndexTripletData
  81. {
  82. short m_values[3];
  83. char m_pad[2];
  84. };
  85. struct btCharIndexTripletData
  86. {
  87. unsigned char m_values[3];
  88. char m_pad;
  89. };
  90. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  91. struct btMeshPartData
  92. {
  93. btVector3FloatData *m_vertices3f;
  94. btVector3DoubleData *m_vertices3d;
  95. btIntIndexData *m_indices32;
  96. btShortIntIndexTripletData *m_3indices16;
  97. btCharIndexTripletData *m_3indices8;
  98. btShortIntIndexData *m_indices16;//backwards compatibility
  99. int m_numTriangles;//length of m_indices = m_numTriangles
  100. int m_numVertices;
  101. };
  102. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  103. struct btStridingMeshInterfaceData
  104. {
  105. btMeshPartData *m_meshPartsPtr;
  106. btVector3FloatData m_scaling;
  107. int m_numMeshParts;
  108. char m_padding[4];
  109. };
  110. SIMD_FORCE_INLINE int btStridingMeshInterface::calculateSerializeBufferSize() const
  111. {
  112. return sizeof(btStridingMeshInterfaceData);
  113. }
  114. #endif //BT_STRIDING_MESHINTERFACE_H