Bullet Collision Detection & Physics Library: btSoftBodyHelpers.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 */
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);
169 static void ReoptimizeLinkOrder(btSoftBody* psb);
170};
171
172#endif //BT_SOFT_BODY_HELPERS_H
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btSoftBody.h
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:27
btSoftBody
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:75
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btVector4
Definition: btVector3.h:1074
btSoftBodyHelpers
Definition: btSoftBodyHelpers.h:51
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:807
btSoftBodyHelpers::writeObj
static void writeObj(const char *file, const btSoftBody *psb)
Definition: btSoftBodyHelpers.cpp:1426
btSoftBodyHelpers::CreateFromTriMesh
static btSoftBody * CreateFromTriMesh(btSoftBodyWorldInfo &worldInfo, const btScalar *vertices, const int *triangles, int ntriangles, bool randomizeConstraints=true)
Definition: btSoftBodyHelpers.cpp:1047
btSoftBodyHelpers::extrapolateBarycentricWeights
static void extrapolateBarycentricWeights(btSoftBody *psb)
Definition: btSoftBodyHelpers.cpp:1647
btSoftBodyHelpers::DrawNodeTree
static void DrawNodeTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
Definition: btSoftBodyHelpers.cpp:466
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:1566
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:1141
btSoftBodyHelpers::CreateFromConvexHull
static btSoftBody * CreateFromConvexHull(btSoftBodyWorldInfo &worldInfo, const btVector3 *vertices, int nvertices, bool randomizeConstraints=true)
Definition: btSoftBodyHelpers.cpp:1094
btSoftBodyHelpers::CreateFromVtkFile
static btSoftBody * CreateFromVtkFile(btSoftBodyWorldInfo &worldInfo, const char *vtk_file)
Definition: btSoftBodyHelpers.cpp:1247
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:543
btSoftBodyHelpers::DrawFaceTree
static void DrawFaceTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
Definition: btSoftBodyHelpers.cpp:475
btSoftBodyHelpers::DrawInfos
static void DrawInfos(btSoftBody *psb, btIDebugDraw *idraw, bool masses, bool areas, bool stress)
Definition: btSoftBodyHelpers.cpp:440
btSoftBodyHelpers::CreateEllipsoid
static btSoftBody * CreateEllipsoid(btSoftBodyWorldInfo &worldInfo, const btVector3 &center, const btVector3 &radius, int res)
Definition: btSoftBodyHelpers.cpp:1016
btSoftBodyHelpers::DrawClusterTree
static void DrawClusterTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
Definition: btSoftBodyHelpers.cpp:484
btSoftBodyHelpers::CalculateUV
static float CalculateUV(int resx, int resy, int ix, int iy, int id)
Definition: btSoftBodyHelpers.cpp:969
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:723
btSoftBodyHelpers::generateBoundaryFaces
static void generateBoundaryFaces(btSoftBody *psb)
Definition: btSoftBodyHelpers.cpp:1354
btSoftBodyHelpers::Draw
static void Draw(btSoftBody *psb, btIDebugDraw *idraw, int drawflags=fDrawFlags::Std)
Definition: btSoftBodyHelpers.cpp:172
btSoftBodyHelpers::duplicateFaces
static void duplicateFaces(const char *filename, const btSoftBody *psb)
Definition: btSoftBodyHelpers.cpp:1522
btSoftBodyHelpers::DrawFrame
static void DrawFrame(btSoftBody *psb, btIDebugDraw *idraw)
Definition: btSoftBodyHelpers.cpp:667
btSoftBodyHelpers::writeState
static void writeState(const char *file, const btSoftBody *psb)
Definition: btSoftBodyHelpers.cpp:1492
btSoftBodyHelpers::CreateRope
static btSoftBody * CreateRope(btSoftBodyWorldInfo &worldInfo, const btVector3 &from, const btVector3 &to, int res, int fixeds)
Definition: btSoftBodyHelpers.cpp:691
btSoftBodyHelpers::interpolateBarycentricWeights
static void interpolateBarycentricWeights(btSoftBody *psb)
Definition: btSoftBodyHelpers.cpp:1603
btSoftBodyWorldInfo
Definition: btSoftBody.h:48
fDrawFlags
Definition: btSoftBodyHelpers.h:28
fDrawFlags::_
_
Definition: btSoftBodyHelpers.h:30
fDrawFlags::StdTetra
@ StdTetra
Definition: btSoftBodyHelpers.h:46
fDrawFlags::FaceTree
@ FaceTree
Definition: btSoftBodyHelpers.h:41
fDrawFlags::Faces
@ Faces
Definition: btSoftBodyHelpers.h:33
fDrawFlags::Links
@ Links
Definition: btSoftBodyHelpers.h:32
fDrawFlags::Clusters
@ Clusters
Definition: btSoftBodyHelpers.h:39
fDrawFlags::Anchors
@ Anchors
Definition: btSoftBodyHelpers.h:37
fDrawFlags::NodeTree
@ NodeTree
Definition: btSoftBodyHelpers.h:40
fDrawFlags::Tetras
@ Tetras
Definition: btSoftBodyHelpers.h:34
fDrawFlags::Normals
@ Normals
Definition: btSoftBodyHelpers.h:35
fDrawFlags::Contacts
@ Contacts
Definition: btSoftBodyHelpers.h:36
fDrawFlags::Notes
@ Notes
Definition: btSoftBodyHelpers.h:38
fDrawFlags::Std
@ Std
Definition: btSoftBodyHelpers.h:45
fDrawFlags::ClusterTree
@ ClusterTree
Definition: btSoftBodyHelpers.h:42
fDrawFlags::Joints
@ Joints
Definition: btSoftBodyHelpers.h:43
fDrawFlags::Nodes
@ Nodes
Definition: btSoftBodyHelpers.h:31