| [1963] | 1 | /* | 
|---|
|  | 2 | Bullet Continuous Collision Detection and Physics Library | 
|---|
| [8351] | 3 | Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org | 
|---|
| [1963] | 4 |  | 
|---|
|  | 5 | This software is provided 'as-is', without any express or implied warranty. | 
|---|
|  | 6 | In no event will the authors be held liable for any damages arising from the use of this software. | 
|---|
|  | 7 | Permission is granted to anyone to use this software for any purpose, | 
|---|
|  | 8 | including commercial applications, and to alter it and redistribute it freely, | 
|---|
|  | 9 | subject to the following restrictions: | 
|---|
|  | 10 |  | 
|---|
|  | 11 | 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. | 
|---|
|  | 12 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | 
|---|
|  | 13 | 3. This notice may not be removed or altered from any source distribution. | 
|---|
|  | 14 | */ | 
|---|
|  | 15 |  | 
|---|
|  | 16 | /// This file was created by Alex Silverman | 
|---|
|  | 17 |  | 
|---|
| [8393] | 18 | #ifndef BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H | 
|---|
|  | 19 | #define BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H | 
|---|
| [1963] | 20 |  | 
|---|
|  | 21 | #include "btBvhTriangleMeshShape.h" | 
|---|
|  | 22 | #include "btMaterial.h" | 
|---|
|  | 23 |  | 
|---|
|  | 24 | ///The BvhTriangleMaterialMeshShape extends the btBvhTriangleMeshShape. Its main contribution is the interface into a material array, which allows per-triangle friction and restitution. | 
|---|
|  | 25 | ATTRIBUTE_ALIGNED16(class) btMultimaterialTriangleMeshShape : public btBvhTriangleMeshShape | 
|---|
|  | 26 | { | 
|---|
|  | 27 | btAlignedObjectArray <btMaterial*> m_materialList; | 
|---|
|  | 28 | int ** m_triangleMaterials; | 
|---|
|  | 29 |  | 
|---|
|  | 30 | public: | 
|---|
|  | 31 |  | 
|---|
|  | 32 | BT_DECLARE_ALIGNED_ALLOCATOR(); | 
|---|
|  | 33 |  | 
|---|
|  | 34 | btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true): | 
|---|
|  | 35 | btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh) | 
|---|
|  | 36 | { | 
|---|
| [2882] | 37 | m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE; | 
|---|
|  | 38 |  | 
|---|
| [1963] | 39 | const unsigned char *vertexbase; | 
|---|
|  | 40 | int numverts; | 
|---|
|  | 41 | PHY_ScalarType type; | 
|---|
|  | 42 | int stride; | 
|---|
|  | 43 | const unsigned char *indexbase; | 
|---|
|  | 44 | int indexstride; | 
|---|
|  | 45 | int numfaces; | 
|---|
|  | 46 | PHY_ScalarType indicestype; | 
|---|
|  | 47 |  | 
|---|
|  | 48 | //m_materialLookup = (int**)(btAlignedAlloc(sizeof(int*) * meshInterface->getNumSubParts(), 16)); | 
|---|
|  | 49 |  | 
|---|
|  | 50 | for(int i = 0; i < meshInterface->getNumSubParts(); i++) | 
|---|
|  | 51 | { | 
|---|
|  | 52 | m_meshInterface->getLockedReadOnlyVertexIndexBase( | 
|---|
|  | 53 | &vertexbase, | 
|---|
|  | 54 | numverts, | 
|---|
|  | 55 | type, | 
|---|
|  | 56 | stride, | 
|---|
|  | 57 | &indexbase, | 
|---|
|  | 58 | indexstride, | 
|---|
|  | 59 | numfaces, | 
|---|
|  | 60 | indicestype, | 
|---|
|  | 61 | i); | 
|---|
|  | 62 | //m_materialLookup[i] = (int*)(btAlignedAlloc(sizeof(int) * numfaces, 16)); | 
|---|
|  | 63 | } | 
|---|
|  | 64 | } | 
|---|
|  | 65 |  | 
|---|
|  | 66 | ///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb | 
|---|
|  | 67 | btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax, bool buildBvh = true): | 
|---|
|  | 68 | btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh) | 
|---|
|  | 69 | { | 
|---|
| [2882] | 70 | m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE; | 
|---|
|  | 71 |  | 
|---|
| [1963] | 72 | const unsigned char *vertexbase; | 
|---|
|  | 73 | int numverts; | 
|---|
|  | 74 | PHY_ScalarType type; | 
|---|
|  | 75 | int stride; | 
|---|
|  | 76 | const unsigned char *indexbase; | 
|---|
|  | 77 | int indexstride; | 
|---|
|  | 78 | int numfaces; | 
|---|
|  | 79 | PHY_ScalarType indicestype; | 
|---|
|  | 80 |  | 
|---|
|  | 81 | //m_materialLookup = (int**)(btAlignedAlloc(sizeof(int*) * meshInterface->getNumSubParts(), 16)); | 
|---|
|  | 82 |  | 
|---|
|  | 83 | for(int i = 0; i < meshInterface->getNumSubParts(); i++) | 
|---|
|  | 84 | { | 
|---|
|  | 85 | m_meshInterface->getLockedReadOnlyVertexIndexBase( | 
|---|
|  | 86 | &vertexbase, | 
|---|
|  | 87 | numverts, | 
|---|
|  | 88 | type, | 
|---|
|  | 89 | stride, | 
|---|
|  | 90 | &indexbase, | 
|---|
|  | 91 | indexstride, | 
|---|
|  | 92 | numfaces, | 
|---|
|  | 93 | indicestype, | 
|---|
|  | 94 | i); | 
|---|
|  | 95 | //m_materialLookup[i] = (int*)(btAlignedAlloc(sizeof(int) * numfaces * 2, 16)); | 
|---|
|  | 96 | } | 
|---|
|  | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 | virtual ~btMultimaterialTriangleMeshShape() | 
|---|
|  | 100 | { | 
|---|
|  | 101 | /* | 
|---|
|  | 102 | for(int i = 0; i < m_meshInterface->getNumSubParts(); i++) | 
|---|
|  | 103 | { | 
|---|
|  | 104 | btAlignedFree(m_materialValues[i]); | 
|---|
|  | 105 | m_materialLookup[i] = NULL; | 
|---|
|  | 106 | } | 
|---|
|  | 107 | btAlignedFree(m_materialValues); | 
|---|
|  | 108 | m_materialLookup = NULL; | 
|---|
|  | 109 | */ | 
|---|
|  | 110 | } | 
|---|
|  | 111 | //debugging | 
|---|
|  | 112 | virtual const char*     getName()const {return "MULTIMATERIALTRIANGLEMESH";} | 
|---|
|  | 113 |  | 
|---|
|  | 114 | ///Obtains the material for a specific triangle | 
|---|
|  | 115 | const btMaterial * getMaterialProperties(int partID, int triIndex); | 
|---|
|  | 116 |  | 
|---|
|  | 117 | } | 
|---|
|  | 118 | ; | 
|---|
|  | 119 |  | 
|---|
| [8393] | 120 | #endif //BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H | 
|---|