Changeset View
Changeset View
Standalone View
Standalone View
extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.h
| Show All 11 Lines | |||||
| 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | ||||
| 3. This notice may not be removed or altered from any source distribution. | 3. This notice may not be removed or altered from any source distribution. | ||||
| */ | */ | ||||
| #ifndef BT_SOFT_BODY_HELPERS_H | #ifndef BT_SOFT_BODY_HELPERS_H | ||||
| #define BT_SOFT_BODY_HELPERS_H | #define BT_SOFT_BODY_HELPERS_H | ||||
| #include "btSoftBody.h" | #include "btSoftBody.h" | ||||
| #include <fstream> | |||||
| #include <string> | |||||
| // | // | ||||
| // Helpers | // Helpers | ||||
| // | // | ||||
| /* fDrawFlags */ | /* fDrawFlags */ | ||||
| struct fDrawFlags { enum _ { | struct fDrawFlags | ||||
| { | |||||
| enum _ | |||||
| { | |||||
| Nodes = 0x0001, | Nodes = 0x0001, | ||||
| Links = 0x0002, | Links = 0x0002, | ||||
| Faces = 0x0004, | Faces = 0x0004, | ||||
| Tetras = 0x0008, | Tetras = 0x0008, | ||||
| Normals = 0x0010, | Normals = 0x0010, | ||||
| Contacts = 0x0020, | Contacts = 0x0020, | ||||
| Anchors = 0x0040, | Anchors = 0x0040, | ||||
| Notes = 0x0080, | Notes = 0x0080, | ||||
| Clusters = 0x0100, | Clusters = 0x0100, | ||||
| NodeTree = 0x0200, | NodeTree = 0x0200, | ||||
| FaceTree = 0x0400, | FaceTree = 0x0400, | ||||
| ClusterTree = 0x0800, | ClusterTree = 0x0800, | ||||
| Joints = 0x1000, | Joints = 0x1000, | ||||
| /* presets */ | /* presets */ | ||||
| Std = Links+Faces+Tetras+Anchors+Notes+Joints, | Std = Links + Faces + Tetras + Anchors + Notes + Joints, | ||||
| StdTetra = Std-Faces+Tetras | StdTetra = Std - Faces + Tetras | ||||
| };}; | }; | ||||
| }; | |||||
| struct btSoftBodyHelpers | struct btSoftBodyHelpers | ||||
| { | { | ||||
| /* Draw body */ | /* Draw body */ | ||||
| static void Draw( btSoftBody* psb, | static void Draw(btSoftBody* psb, | ||||
| btIDebugDraw* idraw, | btIDebugDraw* idraw, | ||||
| int drawflags=fDrawFlags::Std); | int drawflags = fDrawFlags::Std); | ||||
| /* Draw body infos */ | /* Draw body infos */ | ||||
| static void DrawInfos( btSoftBody* psb, | static void DrawInfos(btSoftBody* psb, | ||||
| btIDebugDraw* idraw, | btIDebugDraw* idraw, | ||||
| bool masses, | bool masses, | ||||
| bool areas, | bool areas, | ||||
| bool stress); | bool stress); | ||||
| /* Draw node tree */ | /* Draw node tree */ | ||||
| static void DrawNodeTree( btSoftBody* psb, | static void DrawNodeTree(btSoftBody* psb, | ||||
| btIDebugDraw* idraw, | btIDebugDraw* idraw, | ||||
| int mindepth=0, | int mindepth = 0, | ||||
| int maxdepth=-1); | int maxdepth = -1); | ||||
| /* Draw face tree */ | /* Draw face tree */ | ||||
| static void DrawFaceTree( btSoftBody* psb, | static void DrawFaceTree(btSoftBody* psb, | ||||
| btIDebugDraw* idraw, | btIDebugDraw* idraw, | ||||
| int mindepth=0, | int mindepth = 0, | ||||
| int maxdepth=-1); | int maxdepth = -1); | ||||
| /* Draw cluster tree */ | /* Draw cluster tree */ | ||||
| static void DrawClusterTree(btSoftBody* psb, | static void DrawClusterTree(btSoftBody* psb, | ||||
| btIDebugDraw* idraw, | btIDebugDraw* idraw, | ||||
| int mindepth=0, | int mindepth = 0, | ||||
| int maxdepth=-1); | int maxdepth = -1); | ||||
| /* Draw rigid frame */ | /* Draw rigid frame */ | ||||
| static void DrawFrame( btSoftBody* psb, | static void DrawFrame(btSoftBody* psb, | ||||
| btIDebugDraw* idraw); | btIDebugDraw* idraw); | ||||
| /* Create a rope */ | /* Create a rope */ | ||||
| static btSoftBody* CreateRope( btSoftBodyWorldInfo& worldInfo, | static btSoftBody* CreateRope(btSoftBodyWorldInfo& worldInfo, | ||||
| const btVector3& from, | const btVector3& from, | ||||
| const btVector3& to, | const btVector3& to, | ||||
| int res, | int res, | ||||
| int fixeds); | int fixeds); | ||||
| /* Create a patch */ | /* Create a patch */ | ||||
| static btSoftBody* CreatePatch(btSoftBodyWorldInfo& worldInfo, | static btSoftBody* CreatePatch(btSoftBodyWorldInfo& worldInfo, | ||||
| const btVector3& corner00, | const btVector3& corner00, | ||||
| const btVector3& corner10, | const btVector3& corner10, | ||||
| const btVector3& corner01, | const btVector3& corner01, | ||||
| const btVector3& corner11, | const btVector3& corner11, | ||||
| int resx, | int resx, | ||||
| int resy, | int resy, | ||||
| int fixeds, | int fixeds, | ||||
| bool gendiags); | bool gendiags, | ||||
| btScalar perturbation = 0.); | |||||
| /* Create a patch with UV Texture Coordinates */ | /* Create a patch with UV Texture Coordinates */ | ||||
| static btSoftBody* CreatePatchUV(btSoftBodyWorldInfo& worldInfo, | static btSoftBody* CreatePatchUV(btSoftBodyWorldInfo& worldInfo, | ||||
| const btVector3& corner00, | const btVector3& corner00, | ||||
| const btVector3& corner10, | const btVector3& corner10, | ||||
| const btVector3& corner01, | const btVector3& corner01, | ||||
| const btVector3& corner11, | const btVector3& corner11, | ||||
| int resx, | int resx, | ||||
| int resy, | int resy, | ||||
| int fixeds, | int fixeds, | ||||
| bool gendiags, | bool gendiags, | ||||
| float* tex_coords=0); | float* tex_coords = 0); | ||||
| static float CalculateUV(int resx,int resy,int ix,int iy,int id); | static float CalculateUV(int resx, int resy, int ix, int iy, int id); | ||||
| /* Create an ellipsoid */ | /* Create an ellipsoid */ | ||||
| static btSoftBody* CreateEllipsoid(btSoftBodyWorldInfo& worldInfo, | static btSoftBody* CreateEllipsoid(btSoftBodyWorldInfo& worldInfo, | ||||
| const btVector3& center, | const btVector3& center, | ||||
| const btVector3& radius, | const btVector3& radius, | ||||
| int res); | int res); | ||||
| /* Create from trimesh */ | /* Create from trimesh */ | ||||
| static btSoftBody* CreateFromTriMesh( btSoftBodyWorldInfo& worldInfo, | static btSoftBody* CreateFromTriMesh(btSoftBodyWorldInfo& worldInfo, | ||||
| const btScalar* vertices, | const btScalar* vertices, | ||||
| const int* triangles, | const int* triangles, | ||||
| int ntriangles, | int ntriangles, | ||||
| bool randomizeConstraints = true); | bool randomizeConstraints = true); | ||||
| /* Create from convex-hull */ | /* Create from convex-hull */ | ||||
| static btSoftBody* CreateFromConvexHull( btSoftBodyWorldInfo& worldInfo, | static btSoftBody* CreateFromConvexHull(btSoftBodyWorldInfo& worldInfo, | ||||
| const btVector3* vertices, | const btVector3* vertices, | ||||
| int nvertices, | int nvertices, | ||||
| bool randomizeConstraints = true); | bool randomizeConstraints = true); | ||||
| /* Export TetGen compatible .smesh file */ | /* Export TetGen compatible .smesh file */ | ||||
| // static void ExportAsSMeshFile( btSoftBody* psb, | // static void ExportAsSMeshFile( btSoftBody* psb, | ||||
| // const char* filename); | // const char* filename); | ||||
| /* Create from TetGen .ele, .face, .node files */ | /* Create from TetGen .ele, .face, .node files */ | ||||
| // static btSoftBody* CreateFromTetGenFile( btSoftBodyWorldInfo& worldInfo, | // static btSoftBody* CreateFromTetGenFile( btSoftBodyWorldInfo& worldInfo, | ||||
| // const char* ele, | // const char* ele, | ||||
| // const char* face, | // const char* face, | ||||
| // const char* node, | // const char* node, | ||||
| // bool bfacelinks, | // bool bfacelinks, | ||||
| // bool btetralinks, | // bool btetralinks, | ||||
| // bool bfacesfromtetras); | // bool bfacesfromtetras); | ||||
| /* Create from TetGen .ele, .face, .node data */ | /* Create from TetGen .ele, .face, .node data */ | ||||
| static btSoftBody* CreateFromTetGenData( btSoftBodyWorldInfo& worldInfo, | static btSoftBody* CreateFromTetGenData(btSoftBodyWorldInfo& worldInfo, | ||||
| const char* ele, | const char* ele, | ||||
| const char* face, | const char* face, | ||||
| const char* node, | const char* node, | ||||
| bool bfacelinks, | bool bfacelinks, | ||||
| bool btetralinks, | bool btetralinks, | ||||
| bool bfacesfromtetras); | bool bfacesfromtetras); | ||||
| static btSoftBody* CreateFromVtkFile(btSoftBodyWorldInfo& worldInfo, const char* vtk_file); | |||||
| static void writeObj(const char* file, const btSoftBody* psb); | |||||
| static void getBarycentricWeights(const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d, const btVector3& p, btVector4& bary); | |||||
| static void getBarycentricWeights(const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& p, btVector4& bary); | |||||
| static void interpolateBarycentricWeights(btSoftBody* psb); | |||||
| static void extrapolateBarycentricWeights(btSoftBody* psb); | |||||
| static void generateBoundaryFaces(btSoftBody* psb); | |||||
| static void duplicateFaces(const char* filename, const btSoftBody* psb); | |||||
| /// Sort the list of links to move link calculations that are dependent upon earlier | /// Sort the list of links to move link calculations that are dependent upon earlier | ||||
| /// ones as far as possible away from the calculation of those values | /// ones as far as possible away from the calculation of those values | ||||
| /// This tends to make adjacent loop iterations not dependent upon one another, | /// This tends to make adjacent loop iterations not dependent upon one another, | ||||
| /// so out-of-order processors can execute instructions from multiple iterations at once | /// so out-of-order processors can execute instructions from multiple iterations at once | ||||
| static void ReoptimizeLinkOrder(btSoftBody *psb ); | static void ReoptimizeLinkOrder(btSoftBody* psb); | ||||
| }; | }; | ||||
| #endif //BT_SOFT_BODY_HELPERS_H | #endif //BT_SOFT_BODY_HELPERS_H | ||||