Upgrade Bullet to version 2.83.
[blender.git] / extern / bullet2 / src / BulletCollision / CollisionShapes / btMultimaterialTriangleMeshShape.h
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
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
18 #ifndef BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
19 #define BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
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
29 public:
30
31         BT_DECLARE_ALIGNED_ALLOCATOR();
32
33     btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true):
34         btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh)
35         {
36             m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
37
38             const unsigned char *vertexbase;
39             int numverts;
40             PHY_ScalarType type;
41             int stride;
42             const unsigned char *indexbase;
43             int indexstride;
44             int numfaces;
45             PHY_ScalarType indicestype;
46
47             //m_materialLookup = (int**)(btAlignedAlloc(sizeof(int*) * meshInterface->getNumSubParts(), 16));
48
49             for(int i = 0; i < meshInterface->getNumSubParts(); i++)
50             {
51                 m_meshInterface->getLockedReadOnlyVertexIndexBase(
52                     &vertexbase,
53                     numverts,
54                     type,
55                     stride,
56                     &indexbase,
57                     indexstride,
58                     numfaces,
59                     indicestype,
60                     i);
61                 //m_materialLookup[i] = (int*)(btAlignedAlloc(sizeof(int) * numfaces, 16));
62             }
63         }
64
65         ///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb
66         btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax, bool buildBvh = true):
67         btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh)
68         {
69             m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
70
71             const unsigned char *vertexbase;
72             int numverts;
73             PHY_ScalarType type;
74             int stride;
75             const unsigned char *indexbase;
76             int indexstride;
77             int numfaces;
78             PHY_ScalarType indicestype;
79
80             //m_materialLookup = (int**)(btAlignedAlloc(sizeof(int*) * meshInterface->getNumSubParts(), 16));
81
82             for(int i = 0; i < meshInterface->getNumSubParts(); i++)
83             {
84                 m_meshInterface->getLockedReadOnlyVertexIndexBase(
85                     &vertexbase,
86                     numverts,
87                     type,
88                     stride,
89                     &indexbase,
90                     indexstride,
91                     numfaces,
92                     indicestype,
93                     i);
94                 //m_materialLookup[i] = (int*)(btAlignedAlloc(sizeof(int) * numfaces * 2, 16));
95             }
96         }
97         
98     virtual ~btMultimaterialTriangleMeshShape()
99     {
100 /*
101         for(int i = 0; i < m_meshInterface->getNumSubParts(); i++)
102         {
103             btAlignedFree(m_materialValues[i]);
104             m_materialLookup[i] = NULL;
105         }
106         btAlignedFree(m_materialValues);
107         m_materialLookup = NULL;
108 */
109     }
110         //debugging
111         virtual const char*     getName()const {return "MULTIMATERIALTRIANGLEMESH";}
112
113     ///Obtains the material for a specific triangle
114     const btMaterial * getMaterialProperties(int partID, int triIndex);
115
116 }
117 ;
118
119 #endif //BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H