btMultimaterialTriangleMeshShape.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
  15. #define BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
  16. #include "btBvhTriangleMeshShape.h"
  17. #include "btMaterial.h"
  18. ///The BvhTriangleMaterialMeshShape extends the btBvhTriangleMeshShape. Its main contribution is the interface into a material array, which allows per-triangle friction and restitution.
  19. ATTRIBUTE_ALIGNED16(class) btMultimaterialTriangleMeshShape : public btBvhTriangleMeshShape
  20. {
  21. btAlignedObjectArray <btMaterial*> m_materialList;
  22. int ** m_triangleMaterials;
  23. public:
  24. BT_DECLARE_ALIGNED_ALLOCATOR();
  25. btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true):
  26. btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh)
  27. {
  28. m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
  29. const unsigned char *vertexbase;
  30. int numverts;
  31. PHY_ScalarType type;
  32. int stride;
  33. const unsigned char *indexbase;
  34. int indexstride;
  35. int numfaces;
  36. PHY_ScalarType indicestype;
  37. //m_materialLookup = (int**)(btAlignedAlloc(sizeof(int*) * meshInterface->getNumSubParts(), 16));
  38. for(int i = 0; i < meshInterface->getNumSubParts(); i++)
  39. {
  40. m_meshInterface->getLockedReadOnlyVertexIndexBase(
  41. &vertexbase,
  42. numverts,
  43. type,
  44. stride,
  45. &indexbase,
  46. indexstride,
  47. numfaces,
  48. indicestype,
  49. i);
  50. //m_materialLookup[i] = (int*)(btAlignedAlloc(sizeof(int) * numfaces, 16));
  51. }
  52. }
  53. ///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb
  54. btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax, bool buildBvh = true):
  55. btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh)
  56. {
  57. m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
  58. const unsigned char *vertexbase;
  59. int numverts;
  60. PHY_ScalarType type;
  61. int stride;
  62. const unsigned char *indexbase;
  63. int indexstride;
  64. int numfaces;
  65. PHY_ScalarType indicestype;
  66. //m_materialLookup = (int**)(btAlignedAlloc(sizeof(int*) * meshInterface->getNumSubParts(), 16));
  67. for(int i = 0; i < meshInterface->getNumSubParts(); i++)
  68. {
  69. m_meshInterface->getLockedReadOnlyVertexIndexBase(
  70. &vertexbase,
  71. numverts,
  72. type,
  73. stride,
  74. &indexbase,
  75. indexstride,
  76. numfaces,
  77. indicestype,
  78. i);
  79. //m_materialLookup[i] = (int*)(btAlignedAlloc(sizeof(int) * numfaces * 2, 16));
  80. }
  81. }
  82. virtual ~btMultimaterialTriangleMeshShape()
  83. {
  84. /*
  85. for(int i = 0; i < m_meshInterface->getNumSubParts(); i++)
  86. {
  87. btAlignedFree(m_materialValues[i]);
  88. m_materialLookup[i] = NULL;
  89. }
  90. btAlignedFree(m_materialValues);
  91. m_materialLookup = NULL;
  92. */
  93. }
  94. //debugging
  95. virtual const char* getName()const {return "MULTIMATERIALTRIANGLEMESH";}
  96. ///Obtains the material for a specific triangle
  97. const btMaterial * getMaterialProperties(int partID, int triIndex);
  98. }
  99. ;
  100. #endif //BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H