btTriangleIndexVertexArray.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_TRIANGLE_INDEX_VERTEX_ARRAY_H
  14. #define BT_TRIANGLE_INDEX_VERTEX_ARRAY_H
  15. #include "btStridingMeshInterface.h"
  16. #include "bullet/LinearMath/btAlignedObjectArray.h"
  17. #include "bullet/LinearMath/btScalar.h"
  18. ///The btIndexedMesh indexes a single vertex and index array. Multiple btIndexedMesh objects can be passed into a btTriangleIndexVertexArray using addIndexedMesh.
  19. ///Instead of the number of indices, we pass the number of triangles.
  20. ATTRIBUTE_ALIGNED16( struct) btIndexedMesh
  21. {
  22. BT_DECLARE_ALIGNED_ALLOCATOR();
  23. int m_numTriangles;
  24. const unsigned char * m_triangleIndexBase;
  25. // Size in byte of the indices for one triangle (3*sizeof(index_type) if the indices are tightly packed)
  26. int m_triangleIndexStride;
  27. int m_numVertices;
  28. const unsigned char * m_vertexBase;
  29. // Size of a vertex, in bytes
  30. int m_vertexStride;
  31. // The index type is set when adding an indexed mesh to the
  32. // btTriangleIndexVertexArray, do not set it manually
  33. PHY_ScalarType m_indexType;
  34. // The vertex type has a default type similar to Bullet's precision mode (float or double)
  35. // but can be set manually if you for example run Bullet with double precision but have
  36. // mesh data in single precision..
  37. PHY_ScalarType m_vertexType;
  38. btIndexedMesh()
  39. :m_indexType(PHY_INTEGER),
  40. #ifdef BT_USE_DOUBLE_PRECISION
  41. m_vertexType(PHY_DOUBLE)
  42. #else // BT_USE_DOUBLE_PRECISION
  43. m_vertexType(PHY_FLOAT)
  44. #endif // BT_USE_DOUBLE_PRECISION
  45. {
  46. }
  47. }
  48. ;
  49. typedef btAlignedObjectArray<btIndexedMesh> IndexedMeshArray;
  50. ///The btTriangleIndexVertexArray allows to access multiple triangle meshes, by indexing into existing triangle/index arrays.
  51. ///Additional meshes can be added using addIndexedMesh
  52. ///No duplcate is made of the vertex/index data, it only indexes into external vertex/index arrays.
  53. ///So keep those arrays around during the lifetime of this btTriangleIndexVertexArray.
  54. ATTRIBUTE_ALIGNED16( class) btTriangleIndexVertexArray : public btStridingMeshInterface
  55. {
  56. protected:
  57. IndexedMeshArray m_indexedMeshes;
  58. int m_pad[2];
  59. mutable int m_hasAabb; // using int instead of bool to maintain alignment
  60. mutable btVector3 m_aabbMin;
  61. mutable btVector3 m_aabbMax;
  62. public:
  63. BT_DECLARE_ALIGNED_ALLOCATOR();
  64. btTriangleIndexVertexArray() : m_hasAabb(0)
  65. {
  66. }
  67. virtual ~btTriangleIndexVertexArray();
  68. //just to be backwards compatible
  69. btTriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,btScalar* vertexBase,int vertexStride);
  70. void addIndexedMesh(const btIndexedMesh& mesh, PHY_ScalarType indexType = PHY_INTEGER)
  71. {
  72. m_indexedMeshes.push_back(mesh);
  73. m_indexedMeshes[m_indexedMeshes.size()-1].m_indexType = indexType;
  74. }
  75. virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0);
  76. virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const;
  77. /// unLockVertexBase finishes the access to a subpart of the triangle mesh
  78. /// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished
  79. virtual void unLockVertexBase(int subpart) {(void)subpart;}
  80. virtual void unLockReadOnlyVertexBase(int subpart) const {(void)subpart;}
  81. /// getNumSubParts returns the number of seperate subparts
  82. /// each subpart has a continuous array of vertices and indices
  83. virtual int getNumSubParts() const {
  84. return (int)m_indexedMeshes.size();
  85. }
  86. IndexedMeshArray& getIndexedMeshArray()
  87. {
  88. return m_indexedMeshes;
  89. }
  90. const IndexedMeshArray& getIndexedMeshArray() const
  91. {
  92. return m_indexedMeshes;
  93. }
  94. virtual void preallocateVertices(int numverts){(void) numverts;}
  95. virtual void preallocateIndices(int numindices){(void) numindices;}
  96. virtual bool hasPremadeAabb() const;
  97. virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const;
  98. virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const;
  99. }
  100. ;
  101. #endif //BT_TRIANGLE_INDEX_VERTEX_ARRAY_H