Bullet Collision Detection & Physics Library
btSoftBodyHelpers.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
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 */
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 */
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 */
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 getBarycentricWeights(const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d, const btVector3& p, btVector4& bary);
150 
151  static void interpolateBarycentricWeights(btSoftBody* psb);
152 
153  static void generateBoundaryFaces(btSoftBody* psb);
154 
155  static void duplicateFaces(const char* filename, const btSoftBody* psb);
160  static void ReoptimizeLinkOrder(btSoftBody* psb);
161 };
162 
163 #endif //BT_SOFT_BODY_HELPERS_H
btSoftBodyHelpers::DrawClusterTree
static void DrawClusterTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
Definition: btSoftBodyHelpers.cpp:483
fDrawFlags::FaceTree
Definition: btSoftBodyHelpers.h:41
btSoftBodyHelpers::CreatePatch
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.)
Definition: btSoftBodyHelpers.cpp:722
btSoftBodyHelpers::CreateFromVtkFile
static btSoftBody * CreateFromVtkFile(btSoftBodyWorldInfo &worldInfo, const char *vtk_file)
Definition: btSoftBodyHelpers.cpp:1246
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btSoftBodyHelpers::CreateFromTriMesh
static btSoftBody * CreateFromTriMesh(btSoftBodyWorldInfo &worldInfo, const btScalar *vertices, const int *triangles, int ntriangles, bool randomizeConstraints=true)
Definition: btSoftBodyHelpers.cpp:1046
btSoftBodyHelpers::DrawNodeTree
static void DrawNodeTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
Definition: btSoftBodyHelpers.cpp:465
btSoftBodyHelpers::interpolateBarycentricWeights
static void interpolateBarycentricWeights(btSoftBody *psb)
Definition: btSoftBodyHelpers.cpp:1505
btSoftBodyHelpers::CreateRope
static btSoftBody * CreateRope(btSoftBodyWorldInfo &worldInfo, const btVector3 &from, const btVector3 &to, int res, int fixeds)
Definition: btSoftBodyHelpers.cpp:690
fDrawFlags::StdTetra
Definition: btSoftBodyHelpers.h:46
btSoftBodyHelpers::DrawFrame
static void DrawFrame(btSoftBody *psb, btIDebugDraw *idraw)
Definition: btSoftBodyHelpers.cpp:666
fDrawFlags::Notes
Definition: btSoftBodyHelpers.h:38
btSoftBodyWorldInfo
Definition: btSoftBody.h:45
btSoftBodyHelpers::CreatePatchUV
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)
Definition: btSoftBodyHelpers.cpp:806
btVector4
Definition: btVector3.h:1073
fDrawFlags::Anchors
Definition: btSoftBodyHelpers.h:37
fDrawFlags::Links
Definition: btSoftBodyHelpers.h:32
btSoftBodyHelpers::getBarycentricWeights
static void getBarycentricWeights(const btVector3 &a, const btVector3 &b, const btVector3 &c, const btVector3 &d, const btVector3 &p, btVector4 &bary)
Definition: btSoftBodyHelpers.cpp:1484
btSoftBodyHelpers::CreateEllipsoid
static btSoftBody * CreateEllipsoid(btSoftBodyWorldInfo &worldInfo, const btVector3 &center, const btVector3 &radius, int res)
Definition: btSoftBodyHelpers.cpp:1015
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:26
btSoftBodyHelpers::CreateFromTetGenData
static btSoftBody * CreateFromTetGenData(btSoftBodyWorldInfo &worldInfo, const char *ele, const char *face, const char *node, bool bfacelinks, bool btetralinks, bool bfacesfromtetras)
Definition: btSoftBodyHelpers.cpp:1140
fDrawFlags::Normals
Definition: btSoftBodyHelpers.h:35
fDrawFlags::_
_
Definition: btSoftBodyHelpers.h:29
fDrawFlags::Contacts
Definition: btSoftBodyHelpers.h:36
fDrawFlags::Clusters
Definition: btSoftBodyHelpers.h:39
fDrawFlags::Faces
Definition: btSoftBodyHelpers.h:33
fDrawFlags::Joints
Definition: btSoftBodyHelpers.h:43
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:80
btSoftBodyHelpers::DrawInfos
static void DrawInfos(btSoftBody *psb, btIDebugDraw *idraw, bool masses, bool areas, bool stress)
Definition: btSoftBodyHelpers.cpp:439
btSoftBodyHelpers::writeObj
static void writeObj(const char *file, const btSoftBody *psb)
Definition: btSoftBodyHelpers.cpp:1413
btSoftBodyHelpers::ReoptimizeLinkOrder
static void ReoptimizeLinkOrder(btSoftBody *psb)
Sort the list of links to move link calculations that are dependent upon earlier ones as far as possi...
Definition: btSoftBodyHelpers.cpp:542
btSoftBody
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:72
fDrawFlags::NodeTree
Definition: btSoftBodyHelpers.h:40
btSoftBodyHelpers::Draw
static void Draw(btSoftBody *psb, btIDebugDraw *idraw, int drawflags=fDrawFlags::Std)
Definition: btSoftBodyHelpers.cpp:171
fDrawFlags::ClusterTree
Definition: btSoftBodyHelpers.h:42
btSoftBodyHelpers::generateBoundaryFaces
static void generateBoundaryFaces(btSoftBody *psb)
Definition: btSoftBodyHelpers.cpp:1343
fDrawFlags::Std
Definition: btSoftBodyHelpers.h:45
btSoftBodyHelpers::CalculateUV
static float CalculateUV(int resx, int resy, int ix, int iy, int id)
Definition: btSoftBodyHelpers.cpp:968
btSoftBodyHelpers::DrawFaceTree
static void DrawFaceTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
Definition: btSoftBodyHelpers.cpp:474
btSoftBodyHelpers
Definition: btSoftBodyHelpers.h:50
btSoftBodyHelpers::CreateFromConvexHull
static btSoftBody * CreateFromConvexHull(btSoftBodyWorldInfo &worldInfo, const btVector3 *vertices, int nvertices, bool randomizeConstraints=true)
Definition: btSoftBodyHelpers.cpp:1093
fDrawFlags::Tetras
Definition: btSoftBodyHelpers.h:34
fDrawFlags::Nodes
Definition: btSoftBodyHelpers.h:31
btSoftBody.h
fDrawFlags
Definition: btSoftBodyHelpers.h:27
btSoftBodyHelpers::duplicateFaces
static void duplicateFaces(const char *filename, const btSoftBody *psb)
Definition: btSoftBodyHelpers.cpp:1440