2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2008 Erwin Coumans https://bulletphysics.org
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:
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.
16 #ifndef BT_SOFT_BODY_HELPERS_H
17 #define BT_SOFT_BODY_HELPERS_H
19 #include "btSoftBody.h"
45 Std = Links + Faces + Tetras + Anchors + Notes + Joints,
46 StdTetra = Std - Faces + Tetras
50 struct btSoftBodyHelpers
53 static void Draw(btSoftBody* psb,
55 int drawflags = fDrawFlags::Std);
57 static void DrawInfos(btSoftBody* psb,
63 static void DrawNodeTree(btSoftBody* psb,
68 static void DrawFaceTree(btSoftBody* psb,
72 /* Draw cluster tree */
73 static void DrawClusterTree(btSoftBody* psb,
77 /* Draw rigid frame */
78 static void DrawFrame(btSoftBody* psb,
81 static btSoftBody* CreateRope(btSoftBodyWorldInfo& worldInfo,
82 const btVector3& from,
87 static btSoftBody* CreatePatch(btSoftBodyWorldInfo& worldInfo,
88 const btVector3& corner00,
89 const btVector3& corner10,
90 const btVector3& corner01,
91 const btVector3& corner11,
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,
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,
114 /* Create from trimesh */
115 static btSoftBody* CreateFromTriMesh(btSoftBodyWorldInfo& worldInfo,
116 const btScalar* vertices,
117 const int* triangles,
119 bool randomizeConstraints = true);
120 /* Create from convex-hull */
121 static btSoftBody* CreateFromConvexHull(btSoftBodyWorldInfo& worldInfo,
122 const btVector3* vertices,
124 bool randomizeConstraints = true);
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,
136 // bool bfacesfromtetras);
137 /* Create from TetGen .ele, .face, .node data */
138 static btSoftBody* CreateFromTetGenData(btSoftBodyWorldInfo& worldInfo,
144 bool bfacesfromtetras);
145 static btSoftBody* CreateFromVtkFile(btSoftBodyWorldInfo& worldInfo, const char* vtk_file);
147 static void writeObj(const char* file, const btSoftBody* psb);
149 static void writeState(const char* file, const btSoftBody* psb);
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);
154 static void getBarycentricWeights(const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d, const btVector3& p, btVector4& bary);
156 static void getBarycentricWeights(const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& p, btVector4& bary);
158 static void interpolateBarycentricWeights(btSoftBody* psb);
160 static void extrapolateBarycentricWeights(btSoftBody* psb);
162 static void generateBoundaryFaces(btSoftBody* psb);
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);
172 #endif //BT_SOFT_BODY_HELPERS_H