btTriangleIndexVertexMaterialArray.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. ///This file was created by Alex Silverman
  14. #ifndef BT_MULTIMATERIAL_TRIANGLE_INDEX_VERTEX_ARRAY_H
  15. #define BT_MULTIMATERIAL_TRIANGLE_INDEX_VERTEX_ARRAY_H
  16. #include "btTriangleIndexVertexArray.h"
  17. ATTRIBUTE_ALIGNED16( struct) btMaterialProperties
  18. {
  19. ///m_materialBase ==========> 2 btScalar values make up one material, friction then restitution
  20. int m_numMaterials;
  21. const unsigned char * m_materialBase;
  22. int m_materialStride;
  23. PHY_ScalarType m_materialType;
  24. ///m_numTriangles <=========== This exists in the btIndexedMesh object for the same subpart, but since we're
  25. /// padding the structure, it can be reproduced at no real cost
  26. ///m_triangleMaterials =====> 1 integer value makes up one entry
  27. /// eg: m_triangleMaterials[1] = 5; // This will set triangle 2 to use material 5
  28. int m_numTriangles;
  29. const unsigned char * m_triangleMaterialsBase;
  30. int m_triangleMaterialStride;
  31. ///m_triangleType <========== Automatically set in addMaterialProperties
  32. PHY_ScalarType m_triangleType;
  33. };
  34. typedef btAlignedObjectArray<btMaterialProperties> MaterialArray;
  35. ///Teh btTriangleIndexVertexMaterialArray is built on TriangleIndexVertexArray
  36. ///The addition of a material array allows for the utilization of the partID and
  37. ///triangleIndex that are returned in the ContactAddedCallback. As with
  38. ///TriangleIndexVertexArray, no duplicate is made of the material data, so it
  39. ///is the users responsibility to maintain the array during the lifetime of the
  40. ///TriangleIndexVertexMaterialArray.
  41. ATTRIBUTE_ALIGNED16(class) btTriangleIndexVertexMaterialArray : public btTriangleIndexVertexArray
  42. {
  43. protected:
  44. MaterialArray m_materials;
  45. public:
  46. BT_DECLARE_ALIGNED_ALLOCATOR();
  47. btTriangleIndexVertexMaterialArray()
  48. {
  49. }
  50. btTriangleIndexVertexMaterialArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,
  51. int numVertices,btScalar* vertexBase,int vertexStride,
  52. int numMaterials, unsigned char* materialBase, int materialStride,
  53. int* triangleMaterialsBase, int materialIndexStride);
  54. virtual ~btTriangleIndexVertexMaterialArray() {}
  55. void addMaterialProperties(const btMaterialProperties& mat, PHY_ScalarType triangleType = PHY_INTEGER)
  56. {
  57. m_materials.push_back(mat);
  58. m_materials[m_materials.size()-1].m_triangleType = triangleType;
  59. }
  60. virtual void getLockedMaterialBase(unsigned char **materialBase, int& numMaterials, PHY_ScalarType& materialType, int& materialStride,
  61. unsigned char ** triangleMaterialBase, int& numTriangles, int& triangleMaterialStride, PHY_ScalarType& triangleType ,int subpart = 0);
  62. virtual void getLockedReadOnlyMaterialBase(const unsigned char **materialBase, int& numMaterials, PHY_ScalarType& materialType, int& materialStride,
  63. const unsigned char ** triangleMaterialBase, int& numTriangles, int& triangleMaterialStride, PHY_ScalarType& triangleType, int subpart = 0);
  64. }
  65. ;
  66. #endif //BT_MULTIMATERIAL_TRIANGLE_INDEX_VERTEX_ARRAY_H