[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / 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)
26 btMultimaterialTriangleMeshShape : public btBvhTriangleMeshShape
27 {
28         btAlignedObjectArray<btMaterial *> m_materialList;
29
30 public:
31         BT_DECLARE_ALIGNED_ALLOCATOR();
32
33         btMultimaterialTriangleMeshShape(btStridingMeshInterface * meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true) : btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh)
34         {
35                 m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
36
37                 const unsigned char *vertexbase;
38                 int numverts;
39                 PHY_ScalarType type;
40                 int stride;
41                 const unsigned char *indexbase;
42                 int indexstride;
43                 int numfaces;
44                 PHY_ScalarType indicestype;
45
46                 //m_materialLookup = (int**)(btAlignedAlloc(sizeof(int*) * meshInterface->getNumSubParts(), 16));
47
48                 for (int i = 0; i < meshInterface->getNumSubParts(); i++)
49                 {
50                         m_meshInterface->getLockedReadOnlyVertexIndexBase(
51                                 &vertexbase,
52                                 numverts,
53                                 type,
54                                 stride,
55                                 &indexbase,
56                                 indexstride,
57                                 numfaces,
58                                 indicestype,
59                                 i);
60                         //m_materialLookup[i] = (int*)(btAlignedAlloc(sizeof(int) * numfaces, 16));
61                 }
62         }
63
64         ///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb
65         btMultimaterialTriangleMeshShape(btStridingMeshInterface * meshInterface, bool useQuantizedAabbCompression, const btVector3 &bvhAabbMin, const btVector3 &bvhAabbMax, bool buildBvh = true) : btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh)
66         {
67                 m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
68
69                 const unsigned char *vertexbase;
70                 int numverts;
71                 PHY_ScalarType type;
72                 int stride;
73                 const unsigned char *indexbase;
74                 int indexstride;
75                 int numfaces;
76                 PHY_ScalarType indicestype;
77
78                 //m_materialLookup = (int**)(btAlignedAlloc(sizeof(int*) * meshInterface->getNumSubParts(), 16));
79
80                 for (int i = 0; i < meshInterface->getNumSubParts(); i++)
81                 {
82                         m_meshInterface->getLockedReadOnlyVertexIndexBase(
83                                 &vertexbase,
84                                 numverts,
85                                 type,
86                                 stride,
87                                 &indexbase,
88                                 indexstride,
89                                 numfaces,
90                                 indicestype,
91                                 i);
92                         //m_materialLookup[i] = (int*)(btAlignedAlloc(sizeof(int) * numfaces * 2, 16));
93                 }
94         }
95
96         virtual ~btMultimaterialTriangleMeshShape()
97         {
98                 /*
99         for(int i = 0; i < m_meshInterface->getNumSubParts(); i++)
100         {
101             btAlignedFree(m_materialValues[i]);
102             m_materialLookup[i] = NULL;
103         }
104         btAlignedFree(m_materialValues);
105         m_materialLookup = NULL;
106 */
107         }
108         //debugging
109         virtual const char *getName() const { return "MULTIMATERIALTRIANGLEMESH"; }
110
111         ///Obtains the material for a specific triangle
112         const btMaterial *getMaterialProperties(int partID, int triIndex);
113 };
114
115 #endif  //BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H