[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / BulletSoftBody / btSoftBodyHelpers.h
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2008 Erwin Coumans  https://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 #ifndef BT_SOFT_BODY_HELPERS_H
17 #define BT_SOFT_BODY_HELPERS_H
18
19 #include "btSoftBody.h"
20 #include <fstream>
21 #include <string>
22 //
23 // Helpers
24 //
25
26 /* fDrawFlags                                                                                                                   */
27 struct fDrawFlags
28 {
29         enum _
30         {
31                 Nodes = 0x0001,
32                 Links = 0x0002,
33                 Faces = 0x0004,
34                 Tetras = 0x0008,
35                 Normals = 0x0010,
36                 Contacts = 0x0020,
37                 Anchors = 0x0040,
38                 Notes = 0x0080,
39                 Clusters = 0x0100,
40                 NodeTree = 0x0200,
41                 FaceTree = 0x0400,
42                 ClusterTree = 0x0800,
43                 Joints = 0x1000,
44                 /* presets      */
45                 Std = Links + Faces + Tetras + Anchors + Notes + Joints,
46                 StdTetra = Std - Faces + Tetras
47         };
48 };
49
50 struct btSoftBodyHelpers
51 {
52         /* Draw body                                                                                                                    */
53         static void Draw(btSoftBody* psb,
54                                          btIDebugDraw* idraw,
55                                          int drawflags = fDrawFlags::Std);
56         /* Draw body infos                                                                                                              */
57         static void DrawInfos(btSoftBody* psb,
58                                                   btIDebugDraw* idraw,
59                                                   bool masses,
60                                                   bool areas,
61                                                   bool stress);
62         /* Draw node tree                                                                                                               */
63         static void DrawNodeTree(btSoftBody* psb,
64                                                          btIDebugDraw* idraw,
65                                                          int mindepth = 0,
66                                                          int maxdepth = -1);
67         /* Draw face tree                                                                                                               */
68         static void DrawFaceTree(btSoftBody* psb,
69                                                          btIDebugDraw* idraw,
70                                                          int mindepth = 0,
71                                                          int maxdepth = -1);
72         /* Draw cluster tree                                                                                                    */
73         static void DrawClusterTree(btSoftBody* psb,
74                                                                 btIDebugDraw* idraw,
75                                                                 int mindepth = 0,
76                                                                 int maxdepth = -1);
77         /* Draw rigid frame                                                                                                             */
78         static void DrawFrame(btSoftBody* psb,
79                                                   btIDebugDraw* idraw);
80         /* Create a rope                                                                                                                */
81         static btSoftBody* CreateRope(btSoftBodyWorldInfo& worldInfo,
82                                                                   const btVector3& from,
83                                                                   const btVector3& to,
84                                                                   int res,
85                                                                   int fixeds);
86         /* Create a patch                                                                                                               */
87         static btSoftBody* CreatePatch(btSoftBodyWorldInfo& worldInfo,
88                                                                    const btVector3& corner00,
89                                                                    const btVector3& corner10,
90                                                                    const btVector3& corner01,
91                                                                    const btVector3& corner11,
92                                                                    int resx,
93                                                                    int resy,
94                                                                    int fixeds,
95                                                                    bool gendiags,
96                                                                    btScalar perturbation = 0.);
97         /* Create a patch with UV Texture Coordinates   */
98         static btSoftBody* CreatePatchUV(btSoftBodyWorldInfo& worldInfo,
99                                                                          const btVector3& corner00,
100                                                                          const btVector3& corner10,
101                                                                          const btVector3& corner01,
102                                                                          const btVector3& corner11,
103                                                                          int resx,
104                                                                          int resy,
105                                                                          int fixeds,
106                                                                          bool gendiags,
107                                                                          float* tex_coords = 0);
108         static float CalculateUV(int resx, int resy, int ix, int iy, int id);
109         /* Create an ellipsoid                                                                                                  */
110         static btSoftBody* CreateEllipsoid(btSoftBodyWorldInfo& worldInfo,
111                                                                            const btVector3& center,
112                                                                            const btVector3& radius,
113                                                                            int res);
114         /* Create from trimesh                                                                                                  */
115         static btSoftBody* CreateFromTriMesh(btSoftBodyWorldInfo& worldInfo,
116                                                                                  const btScalar* vertices,
117                                                                                  const int* triangles,
118                                                                                  int ntriangles,
119                                                                                  bool randomizeConstraints = true);
120         /* Create from convex-hull                                                                                              */
121         static btSoftBody* CreateFromConvexHull(btSoftBodyWorldInfo& worldInfo,
122                                                                                         const btVector3* vertices,
123                                                                                         int nvertices,
124                                                                                         bool randomizeConstraints = true);
125
126         /* Export TetGen compatible .smesh file                                                                 */
127         //      static void                             ExportAsSMeshFile(      btSoftBody* psb,
128         //                                                                                              const char* filename);
129         /* Create from TetGen .ele, .face, .node files                                                  */
130         //      static btSoftBody*              CreateFromTetGenFile(   btSoftBodyWorldInfo& worldInfo,
131         //                                                                                                      const char* ele,
132         //                                                                                                      const char* face,
133         //                                                                                                      const char* node,
134         //                                                                                                      bool bfacelinks,
135         //                                                                                                      bool btetralinks,
136         //                                                                                                      bool bfacesfromtetras);
137         /* Create from TetGen .ele, .face, .node data                                                   */
138         static btSoftBody* CreateFromTetGenData(btSoftBodyWorldInfo& worldInfo,
139                                                                                         const char* ele,
140                                                                                         const char* face,
141                                                                                         const char* node,
142                                                                                         bool bfacelinks,
143                                                                                         bool btetralinks,
144                                                                                         bool bfacesfromtetras);
145         static btSoftBody* CreateFromVtkFile(btSoftBodyWorldInfo& worldInfo, const char* vtk_file);
146
147         static void writeObj(const char* file, const btSoftBody* psb);
148
149         static void writeState(const char* file, const btSoftBody* psb);
150
151   //this code cannot be here, dependency on example code are not allowed
152         //static std::string loadDeformableState(btAlignedObjectArray<btVector3>& qs, btAlignedObjectArray<btVector3>& vs, const char* filename, CommonFileIOInterface* fileIO);
153
154         static void getBarycentricWeights(const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d, const btVector3& p, btVector4& bary);
155
156         static void getBarycentricWeights(const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& p, btVector4& bary);
157
158         static void interpolateBarycentricWeights(btSoftBody* psb);
159
160         static void extrapolateBarycentricWeights(btSoftBody* psb);
161
162         static void generateBoundaryFaces(btSoftBody* psb);
163
164         static void duplicateFaces(const char* filename, const btSoftBody* psb);
165         /// Sort the list of links to move link calculations that are dependent upon earlier
166         /// ones as far as possible away from the calculation of those values
167         /// This tends to make adjacent loop iterations not dependent upon one another,
168         /// so out-of-order processors can execute instructions from multiple iterations at once
169         static void ReoptimizeLinkOrder(btSoftBody* psb);
170 };
171
172 #endif  //BT_SOFT_BODY_HELPERS_H