Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'extern/bullet2/src/BulletSoftBody/btSoftBody.h')
-rw-r--r--extern/bullet2/src/BulletSoftBody/btSoftBody.h159
1 files changed, 144 insertions, 15 deletions
diff --git a/extern/bullet2/src/BulletSoftBody/btSoftBody.h b/extern/bullet2/src/BulletSoftBody/btSoftBody.h
index a62c21883c8..ad8678f28b2 100644
--- a/extern/bullet2/src/BulletSoftBody/btSoftBody.h
+++ b/extern/bullet2/src/BulletSoftBody/btSoftBody.h
@@ -27,8 +27,17 @@ subject to the following restrictions:
#include "btSparseSDF.h"
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
+//#ifdef BT_USE_DOUBLE_PRECISION
+//#define btRigidBodyData btRigidBodyDoubleData
+//#define btRigidBodyDataName "btRigidBodyDoubleData"
+//#else
+#define btSoftBodyData btSoftBodyFloatData
+#define btSoftBodyDataName "btSoftBodyFloatData"
+//#endif //BT_USE_DOUBLE_PRECISION
+
class btBroadphaseInterface;
class btDispatcher;
+class btSoftBodySolver;
/* btSoftBodyWorldInfo */
struct btSoftBodyWorldInfo
@@ -41,6 +50,17 @@ struct btSoftBodyWorldInfo
btDispatcher* m_dispatcher;
btVector3 m_gravity;
btSparseSdf<3> m_sparsesdf;
+
+ btSoftBodyWorldInfo()
+ :air_density((btScalar)1.2),
+ water_density(0),
+ water_offset(0),
+ water_normal(0,0,0),
+ m_broadphase(0),
+ m_dispatcher(0),
+ m_gravity(0,-10,0)
+ {
+ }
};
@@ -51,6 +71,9 @@ class btSoftBody : public btCollisionObject
public:
btAlignedObjectArray<class btCollisionObject*> m_collisionDisabledObjects;
+ // The solver object that handles this soft body
+ btSoftBodySolver *m_softBodySolver;
+
//
// Enumerations
//
@@ -110,9 +133,10 @@ public:
SDF_RS = 0x0001, ///SDF based rigid vs soft
CL_RS = 0x0002, ///Cluster vs convex rigid vs soft
- SVSmask = 0x00f0, ///Rigid versus soft mask
+ SVSmask = 0x0030, ///Rigid versus soft mask
VF_SS = 0x0010, ///Vertex vs face soft vs soft handling
CL_SS = 0x0020, ///Cluster vs cluster soft vs soft handling
+ CL_SELF = 0x0040, ///Cluster soft body self collision
/* presets */
Default = SDF_RS,
END
@@ -220,6 +244,16 @@ public:
btScalar m_ra; // Rest area
btDbvtNode* m_leaf; // Leaf data
};
+ /* Tetra */
+ struct Tetra : Feature
+ {
+ Node* m_n[4]; // Node pointers
+ btScalar m_rv; // Rest volume
+ btDbvtNode* m_leaf; // Leaf data
+ btVector3 m_c0[4]; // gradients
+ btScalar m_c1; // (4*kVST)/(im0+im1+im2+im3)
+ btScalar m_c2; // m_c1/sum(|g0..3|^2)
+ };
/* RContact */
struct RContact
{
@@ -276,9 +310,9 @@ public:
};
/* Cluster */
struct Cluster
- {
- btAlignedObjectArray<Node*> m_nodes;
+ {
tScalarArray m_masses;
+ btAlignedObjectArray<Node*> m_nodes;
tVector3Array m_framerefs;
btTransform m_framexform;
btScalar m_idmass;
@@ -297,9 +331,16 @@ public:
btScalar m_ldamping; /* Linear damping */
btScalar m_adamping; /* Angular damping */
btScalar m_matching;
+ btScalar m_maxSelfCollisionImpulse;
+ btScalar m_selfCollisionImpulseFactor;
+ bool m_containsAnchor;
bool m_collide;
int m_clusterIndex;
- Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0) {}
+ Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0)
+ ,m_maxSelfCollisionImpulse(100.f),
+ m_selfCollisionImpulseFactor(0.01f),
+ m_containsAnchor(false)
+ {}
};
/* Impulse */
struct Impulse
@@ -340,7 +381,11 @@ public:
void activate() const
{
- if(m_rigid) m_rigid->activate();
+ if(m_rigid)
+ m_rigid->activate();
+ if (m_collisionObject)
+ m_collisionObject->activate();
+
}
const btMatrix3x3& invWorldInertia() const
{
@@ -358,7 +403,7 @@ public:
const btTransform& xform() const
{
static const btTransform identity=btTransform::getIdentity();
- if(m_collisionObject) return(m_collisionObject->getInterpolationWorldTransform());
+ if(m_collisionObject) return(m_collisionObject->getWorldTransform());
if(m_soft) return(m_soft->m_framexform);
return(identity);
}
@@ -370,8 +415,8 @@ public:
}
btVector3 angularVelocity(const btVector3& rpos) const
{
- if(m_rigid) return(cross(m_rigid->getAngularVelocity(),rpos));
- if(m_soft) return(cross(m_soft->m_av,rpos));
+ if(m_rigid) return(btCross(m_rigid->getAngularVelocity(),rpos));
+ if(m_soft) return(btCross(m_soft->m_av,rpos));
return(btVector3(0,0,0));
}
btVector3 angularVelocity() const
@@ -396,8 +441,16 @@ public:
}
void applyImpulse(const Impulse& impulse,const btVector3& rpos) const
{
- if(impulse.m_asVelocity) applyVImpulse(impulse.m_velocity,rpos);
- if(impulse.m_asDrift) applyDImpulse(impulse.m_drift,rpos);
+ if(impulse.m_asVelocity)
+ {
+// printf("impulse.m_velocity = %f,%f,%f\n",impulse.m_velocity.getX(),impulse.m_velocity.getY(),impulse.m_velocity.getZ());
+ applyVImpulse(impulse.m_velocity,rpos);
+ }
+ if(impulse.m_asDrift)
+ {
+// printf("impulse.m_drift = %f,%f,%f\n",impulse.m_drift.getX(),impulse.m_drift.getY(),impulse.m_drift.getZ());
+ applyDImpulse(impulse.m_drift,rpos);
+ }
}
void applyVAImpulse(const btVector3& impulse) const
{
@@ -424,7 +477,7 @@ public:
struct Joint
{
struct eType { enum _ {
- Linear,
+ Linear=0,
Angular,
Contact
};};
@@ -563,7 +616,7 @@ public:
};
//
- // Typedef's
+ // Typedefs
//
typedef void (*psolver_t)(btSoftBody*,btScalar,btScalar);
@@ -574,6 +627,7 @@ public:
typedef btAlignedObjectArray<btDbvtNode*> tLeafArray;
typedef btAlignedObjectArray<Link> tLinkArray;
typedef btAlignedObjectArray<Face> tFaceArray;
+ typedef btAlignedObjectArray<Tetra> tTetraArray;
typedef btAlignedObjectArray<Anchor> tAnchorArray;
typedef btAlignedObjectArray<RContact> tRContactArray;
typedef btAlignedObjectArray<SContact> tSContactArray;
@@ -594,6 +648,7 @@ public:
tNodeArray m_nodes; // Nodes
tLinkArray m_links; // Links
tFaceArray m_faces; // Faces
+ tTetraArray m_tetras; // Tetras
tAnchorArray m_anchors; // Anchors
tRContactArray m_rcontacts; // Rigid contacts
tSContactArray m_scontacts; // Soft contacts
@@ -611,14 +666,19 @@ public:
btTransform m_initialWorldTransform;
+ btVector3 m_windVelocity;
//
// Api
//
/* ctor */
- btSoftBody( btSoftBodyWorldInfo* worldInfo,int node_count,
- const btVector3* x,
- const btScalar* m);
+ btSoftBody( btSoftBodyWorldInfo* worldInfo,int node_count, const btVector3* x, const btScalar* m);
+
+ /* ctor */
+ btSoftBody( btSoftBodyWorldInfo* worldInfo);
+
+ void initDefaults();
+
/* dtor */
virtual ~btSoftBody();
/* Check for existing link */
@@ -681,9 +741,19 @@ public:
int node1,
int node2,
Material* mat=0);
+ void appendTetra(int model,Material* mat);
+ //
+ void appendTetra(int node0,
+ int node1,
+ int node2,
+ int node3,
+ Material* mat=0);
+
+
/* Append anchor */
void appendAnchor( int node,
btRigidBody* body, bool disableCollisionBetweenLinkedBodies=false);
+ void appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies=false);
/* Append linear joint */
void appendLinearJoint(const LJoint::Specs& specs,Cluster* body0,Body body1);
void appendLinearJoint(const LJoint::Specs& specs,Body body=Body());
@@ -718,6 +788,10 @@ public:
bool fromfaces=false);
/* Set total density */
void setTotalDensity(btScalar density);
+ /* Set volume mass (using tetrahedrons) */
+ void setVolumeMass( btScalar mass);
+ /* Set volume density (using tetrahedrons) */
+ void setVolumeDensity( btScalar density);
/* Transform */
void transform( const btTransform& trs);
/* Translate */
@@ -755,6 +829,8 @@ public:
void releaseCluster(int index);
void releaseClusters();
/* Generate clusters (K-mean) */
+ ///generateClusters with k=0 will create a convex cluster for each tetrahedron or triangle
+ ///otherwise an approximation will be used (better performance)
int generateClusters(int k,int maxiterations=8192);
/* Refine */
void refine(ImplicitFn* ifn,btScalar accurary,bool cut);
@@ -784,6 +860,49 @@ public:
void defaultCollisionHandler(btCollisionObject* pco);
void defaultCollisionHandler(btSoftBody* psb);
+
+
+ //
+ // Functionality to deal with new accelerated solvers.
+ //
+
+ /**
+ * Set a wind velocity for interaction with the air.
+ */
+ void setWindVelocity( const btVector3 &velocity );
+
+
+ /**
+ * Return the wind velocity for interaction with the air.
+ */
+ const btVector3& getWindVelocity();
+
+ //
+ // Set the solver that handles this soft body
+ // Should not be allowed to get out of sync with reality
+ // Currently called internally on addition to the world
+ void setSoftBodySolver( btSoftBodySolver *softBodySolver )
+ {
+ m_softBodySolver = softBodySolver;
+ }
+
+ //
+ // Return the solver that handles this soft body
+ //
+ btSoftBodySolver *getSoftBodySolver()
+ {
+ return m_softBodySolver;
+ }
+
+ //
+ // Return the solver that handles this soft body
+ //
+ btSoftBodySolver *getSoftBodySolver() const
+ {
+ return m_softBodySolver;
+ }
+
+
//
// Cast
//
@@ -841,8 +960,18 @@ public:
static psolver_t getSolver(ePSolver::_ solver);
static vsolver_t getSolver(eVSolver::_ solver);
+
+ virtual int calculateSerializeBufferSize() const;
+
+ ///fills the dataBuffer and returns the struct name (and 0 on failure)
+ virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
+
+ //virtual void serializeSingleObject(class btSerializer* serializer) const;
+
+
};
+
#endif //_BT_SOFT_BODY_H