b3StridingMeshInterface.h 5.5 KB

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