Bullet Collision Detection & Physics Library
btSoftBodyHelpers.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2008 Erwin Coumans https://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. 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 */
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 */
47 };
48};
49
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 */
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 */
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 */
111 const btVector3& center,
112 const btVector3& radius,
113 int res);
114 /* Create from trimesh */
116 const btScalar* vertices,
117 const int* triangles,
118 int ntriangles,
119 bool randomizeConstraints = true);
120 /* Create from convex-hull */
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 */
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
159
161
162 static void generateBoundaryFaces(btSoftBody* psb);
163
164 static void duplicateFaces(const char* filename, const btSoftBody* psb);
169 static void ReoptimizeLinkOrder(btSoftBody* psb);
170};
171
172#endif //BT_SOFT_BODY_HELPERS_H
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:27
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:75
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
static btSoftBody * CreatePatchUV(btSoftBodyWorldInfo &worldInfo, const btVector3 &corner00, const btVector3 &corner10, const btVector3 &corner01, const btVector3 &corner11, int resx, int resy, int fixeds, bool gendiags, float *tex_coords=0)
static void writeObj(const char *file, const btSoftBody *psb)
static btSoftBody * CreateFromTriMesh(btSoftBodyWorldInfo &worldInfo, const btScalar *vertices, const int *triangles, int ntriangles, bool randomizeConstraints=true)
static void extrapolateBarycentricWeights(btSoftBody *psb)
static void DrawNodeTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
static void getBarycentricWeights(const btVector3 &a, const btVector3 &b, const btVector3 &c, const btVector3 &d, const btVector3 &p, btVector4 &bary)
static btSoftBody * CreateFromTetGenData(btSoftBodyWorldInfo &worldInfo, const char *ele, const char *face, const char *node, bool bfacelinks, bool btetralinks, bool bfacesfromtetras)
static btSoftBody * CreateFromConvexHull(btSoftBodyWorldInfo &worldInfo, const btVector3 *vertices, int nvertices, bool randomizeConstraints=true)
static btSoftBody * CreateFromVtkFile(btSoftBodyWorldInfo &worldInfo, const char *vtk_file)
static void ReoptimizeLinkOrder(btSoftBody *psb)
Sort the list of links to move link calculations that are dependent upon earlier ones as far as possi...
static void DrawFaceTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
static void DrawInfos(btSoftBody *psb, btIDebugDraw *idraw, bool masses, bool areas, bool stress)
static btSoftBody * CreateEllipsoid(btSoftBodyWorldInfo &worldInfo, const btVector3 &center, const btVector3 &radius, int res)
static void DrawClusterTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
static float CalculateUV(int resx, int resy, int ix, int iy, int id)
static btSoftBody * CreatePatch(btSoftBodyWorldInfo &worldInfo, const btVector3 &corner00, const btVector3 &corner10, const btVector3 &corner01, const btVector3 &corner11, int resx, int resy, int fixeds, bool gendiags, btScalar perturbation=0.)
static void generateBoundaryFaces(btSoftBody *psb)
static void Draw(btSoftBody *psb, btIDebugDraw *idraw, int drawflags=fDrawFlags::Std)
static void duplicateFaces(const char *filename, const btSoftBody *psb)
static void DrawFrame(btSoftBody *psb, btIDebugDraw *idraw)
static void writeState(const char *file, const btSoftBody *psb)
static btSoftBody * CreateRope(btSoftBodyWorldInfo &worldInfo, const btVector3 &from, const btVector3 &to, int res, int fixeds)
static void interpolateBarycentricWeights(btSoftBody *psb)