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

Bullet Collision Detection & Physics Library

btDeformableMultiBodyDynamicsWorld.h
Go to the documentation of this file.
1 /*
2 Written by Xuchen Han <xuchenhan2015@u.northwestern.edu>
3
4 Bullet Continuous Collision Detection and Physics Library
5 Copyright (c) 2019 Google Inc. http://bulletphysics.org
6 This software is provided 'as-is', without any express or implied warranty.
7 In no event will the authors be held liable for any damages arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it freely,
10 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.
14 */
15
16 #ifndef BT_DEFORMABLE_MULTIBODY_DYNAMICS_WORLD_H
17 #define BT_DEFORMABLE_MULTIBODY_DYNAMICS_WORLD_H
18
19 #include "btSoftMultiBodyDynamicsWorld.h"
20 #include "btDeformableLagrangianForce.h"
21 #include "btDeformableMassSpringForce.h"
22 #include "btDeformableBodySolver.h"
23 #include "btDeformableMultiBodyConstraintSolver.h"
24 #include "btSoftBodyHelpers.h"
25 #include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h"
26 #include <functional>
27 typedef btAlignedObjectArray<btSoftBody*> btSoftBodyArray;
28
29 class btDeformableBodySolver;
30 class btDeformableLagrangianForce;
31 struct MultiBodyInplaceSolverIslandCallback;
32 struct DeformableBodyInplaceSolverIslandCallback;
33 class btDeformableMultiBodyConstraintSolver;
34
35 typedef btAlignedObjectArray<btSoftBody*> btSoftBodyArray;
36
37 class btDeformableMultiBodyDynamicsWorld : public btMultiBodyDynamicsWorld
38 {
39 typedef btAlignedObjectArray<btVector3> TVStack;
41 btDeformableBodySolver* m_deformableBodySolver;
42 btSoftBodyArray m_softBodies;
43 int m_drawFlags;
44 bool m_drawNodeTree;
45 bool m_drawFaceTree;
46 bool m_drawClusterTree;
47 btSoftBodyWorldInfo m_sbi;
48 btScalar m_internalTime;
49 int m_contact_iterations;
50 bool m_implicit;
51 bool m_lineSearch;
52 bool m_selfCollision;
53 DeformableBodyInplaceSolverIslandCallback* m_solverDeformableBodyIslandCallback;
54
55 typedef void (*btSolverCallback)(btScalar time, btDeformableMultiBodyDynamicsWorld* world);
56 btSolverCallback m_solverCallback;
57
58 protected:
59 virtual void internalSingleStepSimulation(btScalar timeStep);
60
61 virtual void integrateTransforms(btScalar timeStep);
62
63 void positionCorrection(btScalar timeStep);
64
65 void solveConstraints(btScalar timeStep);
66
67 void updateActivationState(btScalar timeStep);
68
69 void clearGravity();
70
71 public:
72 btDeformableMultiBodyDynamicsWorld(btDispatcher* dispatcher, btBroadphaseInterface* pairCache, btDeformableMultiBodyConstraintSolver* constraintSolver, btCollisionConfiguration* collisionConfiguration, btDeformableBodySolver* deformableBodySolver = 0);
73
74 virtual int stepSimulation(btScalar timeStep, int maxSubSteps = 1, btScalar fixedTimeStep = btScalar(1.) / btScalar(60.));
75
76 virtual void debugDrawWorld();
77
78 void setSolverCallback(btSolverCallback cb)
79 {
80 m_solverCallback = cb;
81 }
82
83 virtual ~btDeformableMultiBodyDynamicsWorld()
84 {
85 }
86
87 virtual btMultiBodyDynamicsWorld* getMultiBodyDynamicsWorld()
88 {
89 return (btMultiBodyDynamicsWorld*)(this);
90 }
91
92 virtual const btMultiBodyDynamicsWorld* getMultiBodyDynamicsWorld() const
93 {
94 return (const btMultiBodyDynamicsWorld*)(this);
95 }
96
97 virtual btDynamicsWorldType getWorldType() const
98 {
99 return BT_DEFORMABLE_MULTIBODY_DYNAMICS_WORLD;
100 }
101
102 virtual void predictUnconstraintMotion(btScalar timeStep);
103
104 virtual void addSoftBody(btSoftBody* body, int collisionFilterGroup = btBroadphaseProxy::DefaultFilter, int collisionFilterMask = btBroadphaseProxy::AllFilter);
105
106 btSoftBodyArray& getSoftBodyArray()
107 {
108 return m_softBodies;
109 }
110
111 const btSoftBodyArray& getSoftBodyArray() const
112 {
113 return m_softBodies;
114 }
115
116 btSoftBodyWorldInfo& getWorldInfo()
117 {
118 return m_sbi;
119 }
120
121 const btSoftBodyWorldInfo& getWorldInfo() const
122 {
123 return m_sbi;
124 }
125
126 void reinitialize(btScalar timeStep);
127
128 void applyRigidBodyGravity(btScalar timeStep);
129
130 void beforeSolverCallbacks(btScalar timeStep);
131
132 void afterSolverCallbacks(btScalar timeStep);
133
134 void addForce(btSoftBody* psb, btDeformableLagrangianForce* force);
135
136 void removeSoftBody(btSoftBody* body);
137
138 void removeCollisionObject(btCollisionObject* collisionObject);
139
140 int getDrawFlags() const { return (m_drawFlags); }
141 void setDrawFlags(int f) { m_drawFlags = f; }
142
143 void setupConstraints();
144
145 void solveMultiBodyConstraints();
146
147 void solveContactConstraints();
148
149 void sortConstraints();
150
151 void softBodySelfCollision();
152
153 void setImplicit(bool implicit)
154 {
155 m_implicit = implicit;
156 }
157
158 void setLineSearch(bool lineSearch)
159 {
160 m_lineSearch = lineSearch;
161 }
162
163 };
164
165 #endif //BT_DEFORMABLE_MULTIBODY_DYNAMICS_WORLD_H
btSimulationIslandManager.h
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:50
btDeformableMultiBodyDynamicsWorld::TVStack
btAlignedObjectArray< btVector3 > TVStack
Definition: btDeformableMultiBodyDynamicsWorld.h:39
btDeformableMultiBodyDynamicsWorld::getWorldType
virtual btDynamicsWorldType getWorldType() const
Definition: btDeformableMultiBodyDynamicsWorld.h:97
btDeformableMultiBodyDynamicsWorld::m_selfCollision
bool m_selfCollision
Definition: btDeformableMultiBodyDynamicsWorld.h:52
btDeformableMultiBodyDynamicsWorld::solveConstraints
void solveConstraints(btScalar timeStep)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:256
btDeformableMultiBodyDynamicsWorld::getDrawFlags
int getDrawFlags() const
Definition: btDeformableMultiBodyDynamicsWorld.h:140
btDeformableMassSpringForce.h
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btBroadphaseProxy::DefaultFilter
@ DefaultFilter
Definition: btBroadphaseProxy.h:92
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:77
btDeformableMultiBodyDynamicsWorld::m_implicit
bool m_implicit
Definition: btDeformableMultiBodyDynamicsWorld.h:50
btDeformableMultiBodyDynamicsWorld::getWorldInfo
btSoftBodyWorldInfo & getWorldInfo()
Definition: btDeformableMultiBodyDynamicsWorld.h:116
btDeformableMultiBodyDynamicsWorld::positionCorrection
void positionCorrection(btScalar timeStep)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:148
btDeformableMultiBodyDynamicsWorld::debugDrawWorld
virtual void debugDrawWorld()
Definition: btDeformableMultiBodyDynamicsWorld.cpp:409
BT_DEFORMABLE_MULTIBODY_DYNAMICS_WORLD
@ BT_DEFORMABLE_MULTIBODY_DYNAMICS_WORLD
Definition: btDynamicsWorld.h:38
btDeformableMultiBodyDynamicsWorld::softBodySelfCollision
void softBodySelfCollision()
Definition: btDeformableMultiBodyDynamicsWorld.cpp:135
btDeformableMultiBodyDynamicsWorld::solveMultiBodyConstraints
void solveMultiBodyConstraints()
btDeformableMultiBodyDynamicsWorld::m_drawClusterTree
bool m_drawClusterTree
Definition: btDeformableMultiBodyDynamicsWorld.h:46
btDeformableMultiBodyDynamicsWorld::setupConstraints
void setupConstraints()
Definition: btDeformableMultiBodyDynamicsWorld.cpp:280
btSoftBodyWorldInfo
Definition: btSoftBody.h:46
btDeformableMultiBodyDynamicsWorld::reinitialize
void reinitialize(btScalar timeStep)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:395
btDeformableMultiBodyDynamicsWorld::~btDeformableMultiBodyDynamicsWorld
virtual ~btDeformableMultiBodyDynamicsWorld()
Definition: btDeformableMultiBodyDynamicsWorld.h:83
btDeformableMultiBodyDynamicsWorld::m_softBodies
btSoftBodyArray m_softBodies
Definition: btDeformableMultiBodyDynamicsWorld.h:42
btDeformableMultiBodyDynamicsWorld::addSoftBody
virtual void addSoftBody(btSoftBody *body, int collisionFilterGroup=btBroadphaseProxy::DefaultFilter, int collisionFilterMask=btBroadphaseProxy::AllFilter)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:375
btDeformableMultiBodyDynamicsWorld::beforeSolverCallbacks
void beforeSolverCallbacks(btScalar timeStep)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:527
MultiBodyInplaceSolverIslandCallback
Definition: btMultiBodyInplaceSolverIslandCallback.h:66
btDeformableMultiBodyDynamicsWorld::setLineSearch
void setLineSearch(bool lineSearch)
Definition: btDeformableMultiBodyDynamicsWorld.h:158
btBroadphaseProxy::AllFilter
@ AllFilter
Definition: btBroadphaseProxy.h:98
btDynamicsWorldType
btDynamicsWorldType
Definition: btDynamicsWorld.h:31
btDeformableMultiBodyConstraintSolver.h
btDeformableMultiBodyDynamicsWorld::stepSimulation
virtual int stepSimulation(btScalar timeStep, int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.))
if maxSubSteps > 0, it will interpolate motion between fixedTimeStep's
Definition: btDeformableMultiBodyDynamicsWorld.cpp:587
btDeformableMultiBodyDynamicsWorld::internalSingleStepSimulation
virtual void internalSingleStepSimulation(btScalar timeStep)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:69
btDeformableLagrangianForce
Definition: btDeformableLagrangianForce.h:38
btDeformableMultiBodyDynamicsWorld::sortConstraints
void sortConstraints()
Definition: btDeformableMultiBodyDynamicsWorld.cpp:298
btDeformableMultiBodyDynamicsWorld::setSolverCallback
void setSolverCallback(btSolverCallback cb)
Definition: btDeformableMultiBodyDynamicsWorld.h:78
btDeformableMultiBodyDynamicsWorld::addForce
void addForce(btSoftBody *psb, btDeformableLagrangianForce *force)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:548
btDeformableMultiBodyDynamicsWorld::m_deformableBodySolver
btDeformableBodySolver * m_deformableBodySolver
Solver classes that encapsulate multiple deformable bodies for solving.
Definition: btDeformableMultiBodyDynamicsWorld.h:41
btDeformableMultiBodyDynamicsWorld::m_lineSearch
bool m_lineSearch
Definition: btDeformableMultiBodyDynamicsWorld.h:51
btDeformableMultiBodyDynamicsWorld::afterSolverCallbacks
void afterSolverCallbacks(btScalar timeStep)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:540
btDeformableMultiBodyDynamicsWorld::m_solverCallback
btSolverCallback m_solverCallback
Definition: btDeformableMultiBodyDynamicsWorld.h:56
btDeformableMultiBodyDynamicsWorld::m_sbi
btSoftBodyWorldInfo m_sbi
Definition: btDeformableMultiBodyDynamicsWorld.h:47
btDeformableMultiBodyDynamicsWorld::clearGravity
void clearGravity()
Definition: btDeformableMultiBodyDynamicsWorld.cpp:486
btDeformableMultiBodyDynamicsWorld::m_drawFlags
int m_drawFlags
Definition: btDeformableMultiBodyDynamicsWorld.h:43
btAlignedObjectArray< btSoftBody * >
btDeformableMultiBodyDynamicsWorld::solveContactConstraints
void solveContactConstraints()
Definition: btDeformableMultiBodyDynamicsWorld.cpp:317
btSoftBody
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:73
btDeformableBodySolver.h
btBroadphaseInterface
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs.
Definition: btBroadphaseInterface.h:50
btDeformableMultiBodyConstraintSolver
Definition: btDeformableMultiBodyConstraintSolver.h:34
btDeformableMultiBodyDynamicsWorld::m_contact_iterations
int m_contact_iterations
Definition: btDeformableMultiBodyDynamicsWorld.h:49
btDeformableMultiBodyDynamicsWorld::removeSoftBody
void removeSoftBody(btSoftBody *body)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:569
btDeformableMultiBodyDynamicsWorld::integrateTransforms
virtual void integrateTransforms(btScalar timeStep)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:170
btDeformableMultiBodyDynamicsWorld::getMultiBodyDynamicsWorld
virtual const btMultiBodyDynamicsWorld * getMultiBodyDynamicsWorld() const
Definition: btDeformableMultiBodyDynamicsWorld.h:92
btSoftBodyHelpers.h
btDeformableMultiBodyDynamicsWorld::getWorldInfo
const btSoftBodyWorldInfo & getWorldInfo() const
Definition: btDeformableMultiBodyDynamicsWorld.h:121
btDeformableMultiBodyDynamicsWorld::removeCollisionObject
void removeCollisionObject(btCollisionObject *collisionObject)
removeCollisionObject will first check if it is a rigid body, if so call removeRigidBody otherwise ca...
Definition: btDeformableMultiBodyDynamicsWorld.cpp:577
btDeformableMultiBodyDynamicsWorld::applyRigidBodyGravity
void applyRigidBodyGravity(btScalar timeStep)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:426
btDeformableMultiBodyDynamicsWorld::setDrawFlags
void setDrawFlags(int f)
Definition: btDeformableMultiBodyDynamicsWorld.h:141
btDeformableMultiBodyDynamicsWorld::m_drawNodeTree
bool m_drawNodeTree
Definition: btDeformableMultiBodyDynamicsWorld.h:44
btDeformableBodySolver
Definition: btDeformableBodySolver.h:31
btDeformableMultiBodyDynamicsWorld::getSoftBodyArray
btSoftBodyArray & getSoftBodyArray()
Definition: btDeformableMultiBodyDynamicsWorld.h:106
btDeformableMultiBodyDynamicsWorld::m_solverDeformableBodyIslandCallback
DeformableBodyInplaceSolverIslandCallback * m_solverDeformableBodyIslandCallback
Definition: btDeformableMultiBodyDynamicsWorld.h:53
btMultiBodyDynamicsWorld
The btMultiBodyDynamicsWorld adds Featherstone multi body dynamics to Bullet This implementation is s...
Definition: btMultiBodyDynamicsWorld.h:32
btDeformableMultiBodyDynamicsWorld::getSoftBodyArray
const btSoftBodyArray & getSoftBodyArray() const
Definition: btDeformableMultiBodyDynamicsWorld.h:111
DeformableBodyInplaceSolverIslandCallback
Definition: DeformableBodyInplaceSolverIslandCallback.h:12
btCollisionConfiguration
btCollisionConfiguration allows to configure Bullet collision detection stack allocator size,...
Definition: btCollisionConfiguration.h:27
btSoftBodyArray
btAlignedObjectArray< btSoftBody * > btSoftBodyArray
Definition: btDeformableMultiBodyDynamicsWorld.h:27
btDeformableLagrangianForce.h
btDeformableMultiBodyDynamicsWorld::btDeformableMultiBodyDynamicsWorld
btDeformableMultiBodyDynamicsWorld(btDispatcher *dispatcher, btBroadphaseInterface *pairCache, btDeformableMultiBodyConstraintSolver *constraintSolver, btCollisionConfiguration *collisionConfiguration, btDeformableBodySolver *deformableBodySolver=0)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:43
btDeformableMultiBodyDynamicsWorld::m_internalTime
btScalar m_internalTime
Definition: btDeformableMultiBodyDynamicsWorld.h:48
btDeformableMultiBodyDynamicsWorld::btSolverCallback
void(* btSolverCallback)(btScalar time, btDeformableMultiBodyDynamicsWorld *world)
Definition: btDeformableMultiBodyDynamicsWorld.h:55
btDeformableMultiBodyDynamicsWorld::getMultiBodyDynamicsWorld
virtual btMultiBodyDynamicsWorld * getMultiBodyDynamicsWorld()
Definition: btDeformableMultiBodyDynamicsWorld.h:87
btDeformableMultiBodyDynamicsWorld::updateActivationState
void updateActivationState(btScalar timeStep)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:110
btDeformableMultiBodyDynamicsWorld::predictUnconstraintMotion
virtual void predictUnconstraintMotion(btScalar timeStep)
Definition: btDeformableMultiBodyDynamicsWorld.cpp:388
btSoftMultiBodyDynamicsWorld.h
btDeformableMultiBodyDynamicsWorld::setImplicit
void setImplicit(bool implicit)
Definition: btDeformableMultiBodyDynamicsWorld.h:153
btDeformableMultiBodyDynamicsWorld::m_drawFaceTree
bool m_drawFaceTree
Definition: btDeformableMultiBodyDynamicsWorld.h:45
btDeformableMultiBodyDynamicsWorld
Definition: btDeformableMultiBodyDynamicsWorld.h:38