b3StridingMeshInterface.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 B3_STRIDING_MESHINTERFACE_H
  14. #define B3_STRIDING_MESHINTERFACE_H
  15. #include "Bullet3Common/b3Vector3.h"
  16. #include "b3TriangleCallback.h"
  17. //#include "b3ConcaveShape.h"
  18. enum PHY_ScalarType
  19. {
  20. PHY_FLOAT,
  21. PHY_DOUBLE,
  22. PHY_INTEGER,
  23. PHY_SHORT,
  24. PHY_FIXEDPOINT88,
  25. PHY_UCHAR
  26. };
  27. /// The b3StridingMeshInterface is the interface class for high performance generic access to triangle meshes, used in combination with b3BvhTriangleMeshShape and some other collision shapes.
  28. /// Using index striding of 3*sizeof(integer) it can use triangle arrays, using index striding of 1*sizeof(integer) it can handle triangle strips.
  29. /// It allows for sharing graphics and collision meshes. Also it provides locking/unlocking of graphics meshes that are in gpu memory.
  30. B3_ATTRIBUTE_ALIGNED16(class)
  31. b3StridingMeshInterface
  32. {
  33. protected:
  34. b3Vector3 m_scaling;
  35. public:
  36. B3_DECLARE_ALIGNED_ALLOCATOR();
  37. b3StridingMeshInterface() : m_scaling(b3MakeVector3(b3Scalar(1.), b3Scalar(1.), b3Scalar(1.)))
  38. {
  39. }
  40. virtual ~b3StridingMeshInterface();
  41. virtual void InternalProcessAllTriangles(b3InternalTriangleIndexCallback * callback, const b3Vector3& aabbMin, const b3Vector3& aabbMax) const;
  42. ///brute force method to calculate aabb
  43. void calculateAabbBruteForce(b3Vector3 & aabbMin, b3Vector3 & aabbMax);
  44. /// get read and write access to a subpart of a triangle mesh
  45. /// this subpart has a continuous array of vertices and indices
  46. /// in this way the mesh can be handled as chunks of memory with striding
  47. /// very similar to OpenGL vertexarray support
  48. /// make a call to unLockVertexBase when the read and write access is finished
  49. 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;
  50. 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;
  51. /// unLockVertexBase finishes the access to a subpart of the triangle mesh
  52. /// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished
  53. virtual void unLockVertexBase(int subpart) = 0;
  54. virtual void unLockReadOnlyVertexBase(int subpart) const = 0;
  55. /// getNumSubParts returns the number of separate subparts
  56. /// each subpart has a continuous array of vertices and indices
  57. virtual int getNumSubParts() const = 0;
  58. virtual void preallocateVertices(int numverts) = 0;
  59. virtual void preallocateIndices(int numindices) = 0;
  60. virtual bool hasPremadeAabb() const { return false; }
  61. virtual void setPremadeAabb(const b3Vector3& aabbMin, const b3Vector3& aabbMax) const
  62. {
  63. (void)aabbMin;
  64. (void)aabbMax;
  65. }
  66. virtual void getPremadeAabb(b3Vector3 * aabbMin, b3Vector3 * aabbMax) const
  67. {
  68. (void)aabbMin;
  69. (void)aabbMax;
  70. }
  71. const b3Vector3& getScaling() const
  72. {
  73. return m_scaling;
  74. }
  75. void setScaling(const b3Vector3& scaling)
  76. {
  77. m_scaling = scaling;
  78. }
  79. virtual int calculateSerializeBufferSize() const;
  80. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  81. //virtual const char* serialize(void* dataBuffer, b3Serializer* serializer) const;
  82. };
  83. struct b3IntIndexData
  84. {
  85. int m_value;
  86. };
  87. struct b3ShortIntIndexData
  88. {
  89. short m_value;
  90. char m_pad[2];
  91. };
  92. struct b3ShortIntIndexTripletData
  93. {
  94. short m_values[3];
  95. char m_pad[2];
  96. };
  97. struct b3CharIndexTripletData
  98. {
  99. unsigned char m_values[3];
  100. char m_pad;
  101. };
  102. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  103. struct b3MeshPartData
  104. {
  105. b3Vector3FloatData* m_vertices3f;
  106. b3Vector3DoubleData* m_vertices3d;
  107. b3IntIndexData* m_indices32;
  108. b3ShortIntIndexTripletData* m_3indices16;
  109. b3CharIndexTripletData* m_3indices8;
  110. b3ShortIntIndexData* m_indices16; //backwards compatibility
  111. int m_numTriangles; //length of m_indices = m_numTriangles
  112. int m_numVertices;
  113. };
  114. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  115. struct b3StridingMeshInterfaceData
  116. {
  117. b3MeshPartData* m_meshPartsPtr;
  118. b3Vector3FloatData m_scaling;
  119. int m_numMeshParts;
  120. char m_padding[4];
  121. };
  122. B3_FORCE_INLINE int b3StridingMeshInterface::calculateSerializeBufferSize() const
  123. {
  124. return sizeof(b3StridingMeshInterfaceData);
  125. }
  126. #endif //B3_STRIDING_MESHINTERFACE_H