btStridingMeshInterface.h 5.2 KB

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