17#ifndef _BT_SOFT_BODY_H
18#define _BT_SOFT_BODY_H
36#define btSoftBodyData btSoftBodyFloatData
37#define btSoftBodyDataName "btSoftBodyFloatData"
39static unsigned long seed = 243703;
535 static const btMatrix3x3 iwi(0, 0, 0, 0, 0, 0, 0, 0, 0);
899 const Node* node1)
const;
926 void appendLink(
int model = -1, Material* mat = 0);
930 bool bcheckexist =
false);
934 bool bcheckexist =
false);
936 void appendFace(
int model = -1, Material* mat = 0);
953 btRigidBody* body,
bool disableCollisionBetweenLinkedBodies =
false,
btScalar influence = 1);
993 bool fromfaces =
false);
1052 static void clusterAImpulse(Cluster* cluster,
const Impulse& impulse);
1073 bool cutLink(
const Node* node0,
const Node* node1,
btScalar position);
1224#define SAFE_EPSILON SIMD_EPSILON * 100.0
1263 template <
class DBVTNODE>
1292 updateFace(node->childs[0], use_velocity, margin);
1293 updateFace(node->childs[1], use_velocity, margin);
1296 Merge(node->childs[0]->volume, node->childs[1]->volume, vol);
1308 template <
typename T>
1314 return (a * coord.
x() + b * coord.
y() + c * coord.
z());
1325#define NEXTRAND (seed = (1664525L * seed + 1013904223L) & 0xffffffff)
1328 for (i = 0, ni = indices.
size(); i < ni; ++i)
1335 int idx = indices[k];
1354 if (applySpringForce)
1357 I += 0.5 * mass * vn;
1358 int face_penetration = 0, node_penetration = node->
m_constrained;
1359 for (
int i = 0; i < 3; ++i)
1364 if (face_penetration > 0 || node_penetration > 0)
1368 if (face_penetration <= 0)
1370 for (
int j = 0; j < 3; ++j)
1371 face->
m_n[j]->
m_v += w[j] * n * I_tilde * node->
m_im;
1373 if (node_penetration <= 0)
1375 node->
m_v -= I_tilde * node->
m_im * n;
1385 I = 0.5 * mass * (vt_norm - vt_new);
1387 I_tilde = 2.0 * I / (1.0 + w.
length2());
1389 if (face_penetration > 0 || node_penetration > 0)
1391 if (face_penetration <= 0)
1393 for (
int j = 0; j < 3; ++j)
1394 face->
m_n[j]->
m_v += w[j] * vt * I_tilde * (face->
m_n[j])->m_im;
1396 if (node_penetration <= 0)
1398 node->
m_v -= I_tilde * node->
m_im * vt;
DBVT_INLINE void Merge(const btDbvtAabbMm &a, const btDbvtAabbMm &b, btDbvtAabbMm &r)
const T & btMax(const T &a, const T &b)
const T & btMin(const T &a, const T &b)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
#define ATTRIBUTE_ALIGNED16(a)
static unsigned long seed
static const btScalar OVERLAP_REDUCTION_FACTOR
btScalar btDot(const btVector3 &v1, const btVector3 &v2)
Return the dot product between two vectors.
btVector3 btCross(const btVector3 &v1, const btVector3 &v2)
Return the cross product of two vectors.
int size() const
return the number of elements in the array
void resize(int newsize, const T &fillData=T())
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs.
btCollisionObject can be used to manage collision detection objects.
btTransform & getWorldTransform()
int getInternalType() const
reserved for Bullet internal usage
void activate(bool forceActivation=false) const
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
void setIdentity()
Set the matrix to the identity.
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
The btRigidBody is the main class for rigid body objects.
void applyTorqueImpulse(const btVector3 &torque)
btScalar getInvMass() const
void applyImpulse(const btVector3 &impulse, const btVector3 &rel_pos)
void applyCentralImpulse(const btVector3 &impulse)
const btVector3 & getAngularVelocity() const
static const btRigidBody * upcast(const btCollisionObject *colObj)
to keep collision detection and dynamics separate we don't store a rigidbody pointer but a rigidbody ...
const btMatrix3x3 & getInvInertiaTensorWorld() const
const btVector3 & getLinearVelocity() const
btMultiBodyJacobianData jacobianData_t1
btMultiBodyJacobianData jacobianData_normal
btMultiBodyJacobianData jacobianData_t2
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
static void PSolve_Links(btSoftBody *psb, btScalar kst, btScalar ti)
static void PSolve_SContacts(btSoftBody *psb, btScalar, btScalar ti)
bool checkLink(int node0, int node1) const
btScalar m_sleepingThreshold
virtual void transformTo(const btTransform &trs)
btVector3 getLinearVelocity()
bool checkFace(int node0, int node1, int node2) const
void advanceDeformation()
btAlignedObjectArray< eVSolver::_ > tVSolverArray
void setGravityFactor(btScalar gravFactor)
void setPose(bool bvolume, bool bframe)
bool cutLink(int node0, int node1, btScalar position)
void appendFace(int model=-1, Material *mat=0)
void setMass(int node, btScalar mass)
void interpolateRenderMesh()
btScalar m_dampingCoefficient
void updateNode(btDbvtNode *node, bool use_velocity, bool margin)
btAlignedObjectArray< TetraScratch > m_tetraScratchesTn
btAlignedObjectArray< Tetra > tTetraArray
bool rayFaceTest(const btVector3 &rayFrom, const btVector3 &rayTo, sRayCast &results)
void appendLinearJoint(const LJoint::Specs &specs, Cluster *body0, Body body1)
tRenderFaceArray m_renderFaces
btAlignedObjectArray< SContact > tSContactArray
virtual void scale(const btVector3 &scl)
btAlignedObjectArray< bool > m_clusterConnectivity
void updateFaceTree(bool use_velocity, bool margin)
void defaultCollisionHandler(const btCollisionObjectWrapper *pcoWrap)
btScalar getVolume() const
bool rayTest(const btVector3 &rayFrom, const btVector3 &rayTo, sRayCast &results)
Ray casting using rayFrom and rayTo in worldspace, (not direction!)
void addVelocity(const btVector3 &velocity)
btAlignedObjectArray< RContact > tRContactArray
void setDampingCoefficient(btScalar damping_coeff)
void predictMotion(btScalar dt)
void setSelfCollision(bool useSelfCollision)
void setLinearVelocity(const btVector3 &linVel)
btAlignedObjectArray< int > m_userIndexMapping
btAlignedObjectArray< Face > tFaceArray
void appendTetra(int model, Material *mat)
void setRestLengthScale(btScalar restLength)
void updateNodeTree(bool use_velocity, bool margin)
virtual void rotate(const btQuaternion &rot)
void updateFace(DBVTNODE *node, bool use_velocity, bool margin)
void applyClusters(bool drift)
static void PSolve_Anchors(btSoftBody *psb, btScalar kst, btScalar ti)
btAlignedObjectArray< DeformableFaceNodeContact > m_faceNodeContactsCCD
btSoftBodyWorldInfo * m_worldInfo
void setSoftBodySolver(btSoftBodySolver *softBodySolver)
btAlignedObjectArray< btAlignedObjectArray< btScalar > > tDenseMatrix
void updateArea(bool averageArea=true)
void addForce(const btVector3 &force)
void prepareClusters(int iterations)
void setCollisionQuadrature(int N)
static void clusterVImpulse(Cluster *cluster, const btVector3 &rpos, const btVector3 &impulse)
virtual const char * serialize(void *dataBuffer, class btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
btAlignedObjectArray< DeformableFaceNodeContact > m_faceNodeContacts
static void VSolve_Links(btSoftBody *psb, btScalar kst)
btVector3 evaluateCom() const
void setTotalDensity(btScalar density)
btAlignedObjectArray< const class btCollisionObject * > m_collisionDisabledObjects
btAlignedObjectArray< Link > tLinkArray
static void clusterDAImpulse(Cluster *cluster, const btVector3 &impulse)
void appendNode(const btVector3 &x, btScalar m)
void staticSolve(int iterations)
void setVolumeMass(btScalar mass)
btScalar m_restLengthScale
bool checkDeformableContact(const btCollisionObjectWrapper *colObjWrap, const btVector3 &x, btScalar margin, btSoftBody::sCti &cti, bool predict=false) const
void updateDeactivation(btScalar timeStep)
btAlignedObjectArray< TetraScratch > m_tetraScratches
const btVector3 & getWindVelocity()
Return the wind velocity for interaction with the air.
void addAeroForceToFace(const btVector3 &windVelocity, int faceIndex)
btAlignedObjectArray< btVector4 > m_renderNodesInterpolationWeights
void appendAngularJoint(const AJoint::Specs &specs, Cluster *body0, Body body1)
void setAngularVelocity(const btVector3 &angVel)
void setVolumeDensity(btScalar density)
static void clusterDCImpulse(Cluster *cluster, const btVector3 &impulse)
virtual void transform(const btTransform &trs)
static void clusterVAImpulse(Cluster *cluster, const btVector3 &impulse)
btScalar getMass(int node) const
tMaterialArray m_materials
void setMaxStress(btScalar maxStress)
btSoftBody(btSoftBodyWorldInfo *worldInfo, int node_count, const btVector3 *x, const btScalar *m)
btAlignedObjectArray< btScalar > m_z
void addAeroForceToNode(const btVector3 &windVelocity, int nodeIndex)
void applyRepulsionForce(btScalar timeStep, bool applySpringForce)
btAlignedObjectArray< btVector3 > tVector3Array
static btVector3 clusterCom(const Cluster *cluster)
tRContactArray m_rcontacts
void appendAnchor(int node, btRigidBody *body, bool disableCollisionBetweenLinkedBodies=false, btScalar influence=1)
btAlignedObjectArray< Node > tNodeArray
btScalar m_maxSpeedSquared
void releaseCluster(int index)
btAlignedObjectArray< RenderNode > tRenderNodeArray
btScalar m_repulsionStiffness
void setVelocity(const btVector3 &velocity)
btAlignedObjectArray< Joint * > tJointArray
btAlignedObjectArray< DeformableFaceRigidContact > m_faceRigidContacts
int generateClusters(int k, int maxiterations=8192)
generateClusters with k=0 will create a convex cluster for each tetrahedron or triangle otherwise an ...
void geometricCollisionHandler(btSoftBody *psb)
void refine(ImplicitFn *ifn, btScalar accurary, bool cut)
void setSolver(eSolverPresets::_ preset)
static T BaryEval(const T &a, const T &b, const T &c, const btVector3 &coord)
Material * appendMaterial()
void removeAnchor(int node)
btAlignedObjectArray< DeformableNodeRigidAnchor > m_deformableAnchors
void setCacheBarycenter(bool cacheBarycenter)
btAlignedObjectArray< Material * > tMaterialArray
btAlignedObjectArray< Anchor > tAnchorArray
static void solveClusters(const btAlignedObjectArray< btSoftBody * > &bodies)
void appendNote(const char *text, const btVector3 &o, const btVector4 &c=btVector4(1, 0, 0, 0), Node *n0=0, Node *n1=0, Node *n2=0, Node *n3=0)
bool checkDeformableFaceContact(const btCollisionObjectWrapper *colObjWrap, Face &f, btVector3 &contact_point, btVector3 &bary, btScalar margin, btSoftBody::sCti &cti, bool predict=false) const
virtual int calculateSerializeBufferSize() const
btAlignedObjectArray< DeformableNodeRigidContact > m_nodeRigidContacts
btAlignedObjectArray< btSoftBody * > tSoftBodyArray
static void PSolve_RContacts(btSoftBody *psb, btScalar kst, btScalar ti)
virtual btMatrix3x3 getImpulseFactor(int n_node)
static void clusterImpulse(Cluster *cluster, const btVector3 &rpos, const Impulse &impulse)
btAlignedObjectArray< btAlignedObjectArray< const btSoftBody::Node * > > m_renderNodesParents
tRenderNodeArray m_renderNodes
static void clusterDImpulse(Cluster *cluster, const btVector3 &rpos, const btVector3 &impulse)
static btVector3 clusterVelocity(const Cluster *cluster, const btVector3 &rpos)
btTransform getRigidTransform()
tSContactArray m_scontacts
btAlignedObjectArray< btDbvtNode * > tLeafArray
void(* psolver_t)(btSoftBody *, btScalar, btScalar)
void initializeClusters()
btSoftBodyWorldInfo * getWorldInfo()
btScalar getRestLengthScale()
btAlignedObjectArray< Note > tNoteArray
void updateState(const btAlignedObjectArray< btVector3 > &qs, const btAlignedObjectArray< btVector3 > &vs)
void randomizeConstraints()
virtual void setCollisionShape(btCollisionShape *collisionShape)
btScalar getTotalMass() const
btAlignedObjectArray< ePSolver::_ > tPSolverArray
void appendLink(int model=-1, Material *mat=0)
void setSpringStiffness(btScalar k)
void initializeDmInverse()
static const btSoftBody * upcast(const btCollisionObject *colObj)
void setTotalMass(btScalar mass, bool fromfaces=false)
btSoftBodySolver * getSoftBodySolver()
void appendDeformableAnchor(int node, btRigidBody *body)
btAlignedObjectArray< RenderFace > tRenderFaceArray
void updateLinkConstants()
virtual void getAabb(btVector3 &aabbMin, btVector3 &aabbMax) const
void(* vsolver_t)(btSoftBody *, btScalar)
btAlignedObjectArray< btVector3 > m_quads
static psolver_t getSolver(ePSolver::_ solver)
bool checkContact(const btCollisionObjectWrapper *colObjWrap, const btVector3 &x, btScalar margin, btSoftBody::sCti &cti) const
void indicesToPointers(const int *map=0)
static void solveCommonConstraints(btSoftBody **bodies, int count, int iterations)
btAlignedObjectArray< Cluster * > tClusterArray
void setWindVelocity(const btVector3 &velocity)
Set a wind velocity for interaction with the air.
btSoftBodySolver * getSoftBodySolver() const
int generateBendingConstraints(int distance, Material *mat=0)
btAlignedObjectArray< btVector3 > m_X
virtual void translate(const btVector3 &trs)
btVector3 getCenterOfMass() const
void initializeFaceTree()
btSoftBodySolver * m_softBodySolver
void resetLinkRestLengths()
btAlignedObjectArray< btScalar > tScalarArray
static void clusterAImpulse(Cluster *cluster, const Impulse &impulse)
static btSoftBody * upcast(btCollisionObject *colObj)
btVector3 can be used to represent 3D points and vectors.
btScalar safeNorm() const
Return the norm (length) of the vector.
const btScalar & z() const
Return the z value.
btVector3 & safeNormalize()
btScalar dot(const btVector3 &v) const
Return the dot product.
btScalar length2() const
Return the length of the vector squared.
const btScalar & x() const
Return the x value.
const btScalar & y() const
Return the y value.
static btDbvtAabbMm FromCR(const btVector3 &c, btScalar r)
static btDbvtAabbMm FromPoints(const btVector3 *pts, int n)
DBVT_INLINE bool isleaf() const
The btDbvt class implements a fast dynamic bounding volume tree based on axis aligned bounding boxes ...
btDispatcher * m_dispatcher
btSparseSdf< 3 > m_sparsesdf
btScalar m_maxDisplacement
btBroadphaseInterface * m_broadphase
static IControl * Default()
virtual btScalar Speed(AJoint *, btScalar current)
virtual void Prepare(AJoint *)
void Prepare(btScalar dt, int iterations)
void Solve(btScalar dt, btScalar sor)
void Terminate(btScalar dt)
const btMatrix3x3 & invWorldInertia() const
void applyVImpulse(const btVector3 &impulse, const btVector3 &rpos) const
btVector3 angularVelocity() const
btVector3 linearVelocity() const
btVector3 angularVelocity(const btVector3 &rpos) const
void applyDImpulse(const btVector3 &impulse, const btVector3 &rpos) const
Body(const btCollisionObject *colObj)
btVector3 velocity(const btVector3 &rpos) const
void applyDCImpulse(const btVector3 &impulse) const
void applyDAImpulse(const btVector3 &impulse) const
const btTransform & xform() const
void applyVAImpulse(const btVector3 &impulse) const
void applyAImpulse(const Impulse &impulse) const
void applyImpulse(const Impulse &impulse, const btVector3 &rpos) const
const btCollisionObject * m_collisionObject
void Terminate(btScalar dt)
void Prepare(btScalar dt, int iterations)
void Solve(btScalar dt, btScalar sor)
tVector3Array m_framerefs
btScalar m_maxSelfCollisionImpulse
btAlignedObjectArray< Node * > m_nodes
btScalar m_selfCollisionImpulseFactor
tPSolverArray m_psequence
tPSolverArray m_dsequence
tVSolverArray m_vsequence
const btCollisionObject * m_colObj
virtual btScalar Eval(const btVector3 &x)=0
Impulse operator*(btScalar x) const
Impulse operator-() const
virtual void Solve(btScalar dt, btScalar sor)=0
virtual void Terminate(btScalar dt)=0
virtual void Prepare(btScalar dt, int iterations)
virtual eType::_ Type() const =0
void Solve(btScalar dt, btScalar sor)
void Prepare(btScalar dt, int iterations)
void Terminate(btScalar dt)
BT_DECLARE_ALIGNED_ALLOCATOR()
btMatrix3x3 m_effectiveMass_inv
btMatrix3x3 m_effectiveMass
btMultiBodyJacobianData jacobianData_t2
btMultiBodyJacobianData jacobianData_t1
btMultiBodyJacobianData jacobianData_normal
RayFromToCaster takes a ray from, ray to (instead of direction!)
RayFromToCaster(const btVector3 &rayFrom, const btVector3 &rayTo, btScalar mxt)
void Process(const btDbvtNode *leaf)
static btScalar rayFromToTriangle(const btVector3 &rayFrom, const btVector3 &rayTo, const btVector3 &rayNormalizedDirection, const btVector3 &a, const btVector3 &b, const btVector3 &c, btScalar maxt=SIMD_INFINITY)
btVector3 m_rayNormalizedDirection
btScalar m_element_measure
@ V_TwoSided
Vertex normals are oriented toward velocity.
@ V_OneSided
Vertex normals are flipped to match velocity and lift and drag forces are applied.
@ END
Face normals are taken as it is.
@ V_TwoSidedLiftDrag
Vertex normals are flipped to match velocity.
@ F_OneSided
Face normals are flipped to match velocity and lift and drag forces are applied.
@ F_TwoSided
Vertex normals are taken as it is.
@ F_TwoSidedLiftDrag
Face normals are flipped to match velocity.
ePSolver : positions solvers
@ RContacts
Anchor solver.
@ SContacts
Rigid contacts solver.
@ END
Soft contacts solver.
eVSolver : velocities solvers
@ SDF_RDN
GJK based Multibody vs. deformable face.
@ VF_SS
Rigid versus soft mask.
@ Default
SDF based Rigid vs. deformable node.
@ RVDFmask
Vertex vs face soft vs soft handling.
@ VF_DD
Cluster soft body self collision.
@ CL_SS
Vertex vs face soft vs soft handling.
@ CL_SELF
Cluster vs cluster soft vs soft handling.
@ SVSmask
rigid vs deformable
@ SDF_RS
Rigid versus soft mask.
@ SDF_RD
Cluster vs convex rigid vs soft.
@ SDF_RDF
Rigid versus deformable face mask.
@ SDF_MDF
GJK based Rigid vs. deformable face.
@ CL_RS
SDF based rigid vs soft.
@ Default
Enable debug draw.
const btCollisionObject * m_colObj
eFeature::_ feature
soft body
btScalar fraction
feature index