Bullet Collision Detection & Physics Library
btSoftBody.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 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*/
16
17#ifndef _BT_SOFT_BODY_H
18#define _BT_SOFT_BODY_H
19
25
28#include "btSparseSDF.h"
32//#ifdef BT_USE_DOUBLE_PRECISION
33//#define btRigidBodyData btRigidBodyDoubleData
34//#define btRigidBodyDataName "btRigidBodyDoubleData"
35//#else
36#define btSoftBodyData btSoftBodyFloatData
37#define btSoftBodyDataName "btSoftBodyFloatData"
39static unsigned long seed = 243703;
40//#endif //BT_USE_DOUBLE_PRECISION
41
43class btDispatcher;
45
46/* btSoftBodyWorldInfo */
48{
58
60 : air_density((btScalar)1.2),
62 water_offset(0),
63 m_maxDisplacement(1000.f), //avoid soft body from 'exploding' so use some upper threshold of maximum motion that a node can travel per frame
64 water_normal(0, 0, 0),
65 m_broadphase(0),
66 m_dispatcher(0),
67 m_gravity(0, -10, 0)
68 {
69 }
70};
71
75{
76public:
78
79 // The solver object that handles this soft body
81
82 //
83 // Enumerations
84 //
85
88 {
89 enum _
90 {
98 END
99 };
100 };
101
103 struct eVSolver
104 {
105 enum _
106 {
108 END
109 };
110 };
111
113 struct ePSolver
114 {
115 enum _
116 {
121 END
122 };
123 };
124
127 {
128 enum _
129 {
133 END
134 };
135 };
136
138 struct eFeature
139 {
140 enum _
141 {
147 END
148 };
149 };
150
153
154 //
155 // Flags
156 //
157
160 {
161 enum _
162 {
163 RVSmask = 0x000f,
164 SDF_RS = 0x0001,
165 CL_RS = 0x0002,
166 SDF_RD = 0x0004,
167
168 SVSmask = 0x00f0,
169 VF_SS = 0x0010,
170 CL_SS = 0x0020,
171 CL_SELF = 0x0040,
172 VF_DD = 0x0080,
173
174 RVDFmask = 0x0f00,
175 SDF_RDF = 0x0100,
176 SDF_MDF = 0x0200,
177 SDF_RDN = 0x0400,
178 /* presets */
180 END
181 };
182 };
183
186 {
187 enum _
188 {
189 DebugDraw = 0x0001,
190 /* presets */
192 END
193 };
194 };
195
196 //
197 // API Types
198 //
199
200 /* sRayCast */
201 struct sRayCast
202 {
205 int index;
207 };
208
209 /* ImplicitFn */
211 {
212 virtual ~ImplicitFn() {}
213 virtual btScalar Eval(const btVector3& x) = 0;
214 };
215
216 //
217 // Internal types
218 //
219
222
223 /* sCti is Softbody contact info */
224 struct sCti
225 {
226 const btCollisionObject* m_colObj; /* Rigid body */
227 btVector3 m_normal; /* Outward normal */
228 mutable btVector3 m_impulse; /* Applied impulse */
229 btScalar m_offset; /* Offset from origin */
230 btVector3 m_bary; /* Barycentric weights for faces */
231 sCti() : m_impulse(0, 0, 0) {}
232 };
233
234 /* sMedium */
235 struct sMedium
236 {
237 btVector3 m_velocity; /* Velocity */
238 btScalar m_pressure; /* Pressure */
239 btScalar m_density; /* Density */
240 };
241
242 /* Base type */
243 struct Element
244 {
245 void* m_tag; // User data
246 Element() : m_tag(0) {}
247 };
248 /* Material */
250 {
251 btScalar m_kLST; // Linear stiffness coefficient [0,1]
252 btScalar m_kAST; // Area/Angular stiffness coefficient [0,1]
253 btScalar m_kVST; // Volume stiffness coefficient [0,1]
254 int m_flags; // Flags
255 };
256
257 /* Feature */
259 {
260 Material* m_material; // Material
261 };
262 /* Node */
264 {
268 };
269 struct Node : Feature
270 {
271 btVector3 m_x; // Position
272 btVector3 m_q; // Previous step position/Test position
273 btVector3 m_v; // Velocity
274 btVector3 m_vn; // Previous step velocity
275 btVector3 m_f; // Force accumulator
276 btVector3 m_n; // Normal
277 btScalar m_im; // 1/mass
279 btDbvtNode* m_leaf; // Leaf data
280 int m_constrained; // depth of penetration
281 int m_battach : 1; // Attached
282 int index;
283 btVector3 m_splitv; // velocity associated with split impulse
284 btMatrix3x3 m_effectiveMass; // effective mass in contact
285 btMatrix3x3 m_effectiveMass_inv; // inverse of effective mass
286 };
287 /* Link */
289 Link : Feature
290 {
291 btVector3 m_c3; // gradient
292 Node* m_n[2]; // Node pointers
293 btScalar m_rl; // Rest length
294 int m_bbending : 1; // Bending link
295 btScalar m_c0; // (ima+imb)*kLST
296 btScalar m_c1; // rl^2
297 btScalar m_c2; // |gradient|^2/c0
298
300 };
302 {
303 RenderNode* m_n[3]; // Node pointers
304 };
305
306 /* Face */
307 struct Face : Feature
308 {
309 Node* m_n[3]; // Node pointers
311 btScalar m_ra; // Rest area
312 btDbvtNode* m_leaf; // Leaf data
313 btVector4 m_pcontact; // barycentric weights of the persistent contact
316 };
317 /* Tetra */
318 struct Tetra : Feature
319 {
320 Node* m_n[4]; // Node pointers
321 btScalar m_rv; // Rest volume
322 btDbvtNode* m_leaf; // Leaf data
323 btVector3 m_c0[4]; // gradients
324 btScalar m_c1; // (4*kVST)/(im0+im1+im2+im3)
325 btScalar m_c2; // m_c1/sum(|g0..3|^2)
329 btVector4 m_P_inv[3]; // first three columns of P_inv matrix
330 };
331
332 /* TetraScratch */
334 {
335 btMatrix3x3 m_F; // deformation gradient F
336 btScalar m_trace; // trace of F^T * F
337 btScalar m_J; // det(F)
338 btMatrix3x3 m_cofF; // cofactor of F
339 btMatrix3x3 m_corotation; // corotatio of the tetra
340 };
341
342 /* RContact */
343 struct RContact
344 {
345 sCti m_cti; // Contact infos
346 Node* m_node; // Owner node
347 btMatrix3x3 m_c0; // Impulse matrix
348 btVector3 m_c1; // Relative anchor
349 btScalar m_c2; // ima*dt
350 btScalar m_c3; // Friction
351 btScalar m_c4; // Hardness
352
353 // jacobians and unit impulse responses for multibody
359 };
360
362 {
363 public:
364 sCti m_cti; // Contact infos
365 btMatrix3x3 m_c0; // Impulse matrix
366 btVector3 m_c1; // Relative anchor
367 btScalar m_c2; // inverse mass of node/face
368 btScalar m_c3; // Friction
369 btScalar m_c4; // Hardness
370 btMatrix3x3 m_c5; // inverse effective mass
371
372 // jacobians and unit impulse responses for multibody
378 };
379
381 {
382 public:
383 Node* m_node; // Owner node
384 };
385
387 {
388 public:
389 btVector3 m_local; // Anchor position in body space
390 };
391
393 {
394 public:
395 Face* m_face; // Owner face
396 btVector3 m_contactPoint; // Contact point
397 btVector3 m_bary; // Barycentric weights
398 btVector3 m_weights; // v_contactPoint * m_weights[i] = m_face->m_node[i]->m_v;
399 };
400
402 {
403 Node* m_node; // Node
404 Face* m_face; // Face
405 btVector3 m_bary; // Barycentric weights
406 btVector3 m_weights; // v_contactPoint * m_weights[i] = m_face->m_node[i]->m_v;
409 btScalar m_friction; // Friction
410 btScalar m_imf; // inverse mass of the face at contact point
411 btScalar m_c0; // scale of the impulse matrix;
412 };
413
414 /* SContact */
415 struct SContact
416 {
417 Node* m_node; // Node
418 Face* m_face; // Face
422 btScalar m_friction; // Friction
423 btScalar m_cfm[2]; // Constraint force mixing
424 };
425 /* Anchor */
426 struct Anchor
427 {
428 Node* m_node; // Node pointer
429 btVector3 m_local; // Anchor position in body space
432 btMatrix3x3 m_c0; // Impulse matrix
433 btVector3 m_c1; // Relative anchor
434 btScalar m_c2; // ima*dt
435 };
436 /* Note */
437 struct Note : Element
438 {
439 const char* m_text; // Text
441 int m_rank; // Rank
442 Node* m_nodes[4]; // Nodes
443 btScalar m_coords[4]; // Coordinates
444 };
445 /* Pose */
446 struct Pose
447 {
448 bool m_bvolume; // Is valid
449 bool m_bframe; // Is frame
450 btScalar m_volume; // Rest volume
451 tVector3Array m_pos; // Reference positions
452 tScalarArray m_wgh; // Weights
454 btMatrix3x3 m_rot; // Rotation
456 btMatrix3x3 m_aqq; // Base scaling
457 };
458 /* Cluster */
459 struct Cluster
460 {
477 btScalar m_ndamping; /* Node damping */
478 btScalar m_ldamping; /* Linear damping */
479 btScalar m_adamping; /* Angular damping */
487 {
488 }
489 };
490 /* Impulse */
491 struct Impulse
492 {
496 int m_asDrift : 1;
497 Impulse() : m_velocity(0, 0, 0), m_drift(0, 0, 0), m_asVelocity(0), m_asDrift(0) {}
499 {
500 Impulse i = *this;
501 i.m_velocity = -i.m_velocity;
502 i.m_drift = -i.m_drift;
503 return (i);
504 }
506 {
507 Impulse i = *this;
508 i.m_velocity *= x;
509 i.m_drift *= x;
510 return (i);
511 }
512 };
513 /* Body */
514 struct Body
515 {
519
522 Body(const btCollisionObject* colObj) : m_soft(0), m_collisionObject(colObj)
523 {
525 }
526
527 void activate() const
528 {
529 if (m_rigid)
530 m_rigid->activate();
533 }
535 {
536 static const btMatrix3x3 iwi(0, 0, 0, 0, 0, 0, 0, 0, 0);
538 if (m_soft) return (m_soft->m_invwi);
539 return (iwi);
540 }
542 {
543 if (m_rigid) return (m_rigid->getInvMass());
544 if (m_soft) return (m_soft->m_imass);
545 return (0);
546 }
547 const btTransform& xform() const
548 {
549 static const btTransform identity = btTransform::getIdentity();
551 if (m_soft) return (m_soft->m_framexform);
552 return (identity);
553 }
555 {
556 if (m_rigid) return (m_rigid->getLinearVelocity());
557 if (m_soft) return (m_soft->m_lv);
558 return (btVector3(0, 0, 0));
559 }
561 {
562 if (m_rigid) return (btCross(m_rigid->getAngularVelocity(), rpos));
563 if (m_soft) return (btCross(m_soft->m_av, rpos));
564 return (btVector3(0, 0, 0));
565 }
567 {
568 if (m_rigid) return (m_rigid->getAngularVelocity());
569 if (m_soft) return (m_soft->m_av);
570 return (btVector3(0, 0, 0));
571 }
572 btVector3 velocity(const btVector3& rpos) const
573 {
574 return (linearVelocity() + angularVelocity(rpos));
575 }
576 void applyVImpulse(const btVector3& impulse, const btVector3& rpos) const
577 {
578 if (m_rigid) m_rigid->applyImpulse(impulse, rpos);
579 if (m_soft) btSoftBody::clusterVImpulse(m_soft, rpos, impulse);
580 }
581 void applyDImpulse(const btVector3& impulse, const btVector3& rpos) const
582 {
583 if (m_rigid) m_rigid->applyImpulse(impulse, rpos);
584 if (m_soft) btSoftBody::clusterDImpulse(m_soft, rpos, impulse);
585 }
586 void applyImpulse(const Impulse& impulse, const btVector3& rpos) const
587 {
588 if (impulse.m_asVelocity)
589 {
590 // printf("impulse.m_velocity = %f,%f,%f\n",impulse.m_velocity.getX(),impulse.m_velocity.getY(),impulse.m_velocity.getZ());
591 applyVImpulse(impulse.m_velocity, rpos);
592 }
593 if (impulse.m_asDrift)
594 {
595 // printf("impulse.m_drift = %f,%f,%f\n",impulse.m_drift.getX(),impulse.m_drift.getY(),impulse.m_drift.getZ());
596 applyDImpulse(impulse.m_drift, rpos);
597 }
598 }
599 void applyVAImpulse(const btVector3& impulse) const
600 {
601 if (m_rigid) m_rigid->applyTorqueImpulse(impulse);
603 }
604 void applyDAImpulse(const btVector3& impulse) const
605 {
606 if (m_rigid) m_rigid->applyTorqueImpulse(impulse);
608 }
609 void applyAImpulse(const Impulse& impulse) const
610 {
611 if (impulse.m_asVelocity) applyVAImpulse(impulse.m_velocity);
612 if (impulse.m_asDrift) applyDAImpulse(impulse.m_drift);
613 }
614 void applyDCImpulse(const btVector3& impulse) const
615 {
616 if (m_rigid) m_rigid->applyCentralImpulse(impulse);
618 }
619 };
620 /* Joint */
621 struct Joint
622 {
623 struct eType
624 {
625 enum _
626 {
629 Contact
630 };
631 };
632 struct Specs
633 {
634 Specs() : erp(1), cfm(1), split(1) {}
638 };
648 virtual ~Joint() {}
649 Joint() : m_delete(false) {}
650 virtual void Prepare(btScalar dt, int iterations);
651 virtual void Solve(btScalar dt, btScalar sor) = 0;
652 virtual void Terminate(btScalar dt) = 0;
653 virtual eType::_ Type() const = 0;
654 };
655 /* LJoint */
656 struct LJoint : Joint
657 {
659 {
661 };
663 void Prepare(btScalar dt, int iterations);
664 void Solve(btScalar dt, btScalar sor);
665 void Terminate(btScalar dt);
666 eType::_ Type() const { return (eType::Linear); }
667 };
668 /* AJoint */
669 struct AJoint : Joint
670 {
671 struct IControl
672 {
673 virtual ~IControl() {}
674 virtual void Prepare(AJoint*) {}
675 virtual btScalar Speed(AJoint*, btScalar current) { return (current); }
677 {
678 static IControl def;
679 return (&def);
680 }
681 };
683 {
684 Specs() : icontrol(IControl::Default()) {}
687 };
690 void Prepare(btScalar dt, int iterations);
691 void Solve(btScalar dt, btScalar sor);
692 void Terminate(btScalar dt);
693 eType::_ Type() const { return (eType::Angular); }
694 };
695 /* CJoint */
696 struct CJoint : Joint
697 {
703 void Prepare(btScalar dt, int iterations);
704 void Solve(btScalar dt, btScalar sor);
705 void Terminate(btScalar dt);
706 eType::_ Type() const { return (eType::Contact); }
707 };
708 /* Config */
709 struct Config
710 {
711 eAeroModel::_ aeromodel; // Aerodynamic model (default: V_Point)
712 btScalar kVCF; // Velocities correction factor (Baumgarte)
713 btScalar kDP; // Damping coefficient [0,1]
714 btScalar kDG; // Drag coefficient [0,+inf]
715 btScalar kLF; // Lift coefficient [0,+inf]
716 btScalar kPR; // Pressure coefficient [-inf,+inf]
717 btScalar kVC; // Volume conversation coefficient [0,+inf]
718 btScalar kDF; // Dynamic friction coefficient [0,1]
719 btScalar kMT; // Pose matching coefficient [0,1]
720 btScalar kCHR; // Rigid contacts hardness [0,1]
721 btScalar kKHR; // Kinetic contacts hardness [0,1]
722 btScalar kSHR; // Soft contacts hardness [0,1]
723 btScalar kAHR; // Anchors hardness [0,1]
724 btScalar kSRHR_CL; // Soft vs rigid hardness [0,1] (cluster only)
725 btScalar kSKHR_CL; // Soft vs kinetic hardness [0,1] (cluster only)
726 btScalar kSSHR_CL; // Soft vs soft hardness [0,1] (cluster only)
727 btScalar kSR_SPLT_CL; // Soft vs rigid impulse split [0,1] (cluster only)
728 btScalar kSK_SPLT_CL; // Soft vs rigid impulse split [0,1] (cluster only)
729 btScalar kSS_SPLT_CL; // Soft vs rigid impulse split [0,1] (cluster only)
730 btScalar maxvolume; // Maximum volume ratio for pose
731 btScalar timescale; // Time scale
732 int viterations; // Velocities solver iterations
733 int piterations; // Positions solver iterations
734 int diterations; // Drift solver iterations
735 int citerations; // Cluster solver iterations
736 int collisions; // Collisions flags
737 tVSolverArray m_vsequence; // Velocity solvers sequence
738 tPSolverArray m_psequence; // Position solvers sequence
739 tPSolverArray m_dsequence; // Drift solvers sequence
740 btScalar drag; // deformable air drag
741 btScalar m_maxStress; // Maximum principle first Piola stress
742 };
743 /* SolverState */
745 {
746 //if you add new variables, always initialize them!
748 : sdt(0),
749 isdt(0),
750 velmrg(0),
751 radmrg(0),
752 updmrg(0)
753 {
754 }
755 btScalar sdt; // dt*timescale
756 btScalar isdt; // 1/sdt
757 btScalar velmrg; // velocity margin
758 btScalar radmrg; // radial margin
759 btScalar updmrg; // Update margin
760 };
763 {
770 RayFromToCaster(const btVector3& rayFrom, const btVector3& rayTo, btScalar mxt);
771 void Process(const btDbvtNode* leaf);
772
773 static /*inline*/ btScalar rayFromToTriangle(const btVector3& rayFrom,
774 const btVector3& rayTo,
775 const btVector3& rayNormalizedDirection,
776 const btVector3& a,
777 const btVector3& b,
778 const btVector3& c,
779 btScalar maxt = SIMD_INFINITY);
780 };
781
782 //
783 // Typedefs
784 //
785
787 typedef void (*vsolver_t)(btSoftBody*, btScalar);
803
804 //
805 // Fields
806 //
807
808 Config m_cfg; // Configuration
809 SolverState m_sst; // Solver state
810 Pose m_pose; // Pose
811 void* m_tag; // User data
824 tRContactArray m_rcontacts; // Rigid contacts
828 tSContactArray m_scontacts; // Soft contacts
831 btScalar m_timeacc; // Time accumulator
832 btVector3 m_bounds[2]; // Spatial bounds
833 bool m_bUpdateRtCst; // Update runtime constants
834 btDbvt m_ndbvt; // Nodes tree
835 btDbvt m_fdbvt; // Faces tree
836 btDbvntNode* m_fdbvnt; // Faces tree with normals
837 btDbvt m_cdbvt; // Clusters tree
839 btScalar m_dampingCoefficient; // Damping Coefficient
842 btAlignedObjectArray<btVector3> m_quads; // quadrature points for collision detection
847
850 btAlignedObjectArray<btScalar> m_z; // vertical distance used in extrapolation
853
854 btAlignedObjectArray<bool> m_clusterConnectivity; //cluster connectivity, for self-collision
855
857
859
860 //
861 // Api
862 //
863
864 /* ctor */
865 btSoftBody(btSoftBodyWorldInfo* worldInfo, int node_count, const btVector3* x, const btScalar* m);
866
867 /* ctor */
869
870 void initDefaults();
871
872 /* dtor */
873 virtual ~btSoftBody();
874 /* Check for existing link */
875
877
879 {
880 return m_worldInfo;
881 }
882
883 void setDampingCoefficient(btScalar damping_coeff)
884 {
885 m_dampingCoefficient = damping_coeff;
886 }
887
889 virtual void setCollisionShape(btCollisionShape* collisionShape)
890 {
891 }
892
893 bool checkLink(int node0,
894 int node1) const;
895 bool checkLink(const Node* node0,
896 const Node* node1) const;
897 /* Check for existing face */
898 bool checkFace(int node0,
899 int node1,
900 int node2) const;
901 /* Append material */
902 Material* appendMaterial();
903 /* Append note */
904 void appendNote(const char* text,
905 const btVector3& o,
906 const btVector4& c = btVector4(1, 0, 0, 0),
907 Node* n0 = 0,
908 Node* n1 = 0,
909 Node* n2 = 0,
910 Node* n3 = 0);
911 void appendNote(const char* text,
912 const btVector3& o,
913 Node* feature);
914 void appendNote(const char* text,
915 const btVector3& o,
916 Link* feature);
917 void appendNote(const char* text,
918 const btVector3& o,
919 Face* feature);
920 /* Append node */
921 void appendNode(const btVector3& x, btScalar m);
922 /* Append link */
923 void appendLink(int model = -1, Material* mat = 0);
924 void appendLink(int node0,
925 int node1,
926 Material* mat = 0,
927 bool bcheckexist = false);
928 void appendLink(Node* node0,
929 Node* node1,
930 Material* mat = 0,
931 bool bcheckexist = false);
932 /* Append face */
933 void appendFace(int model = -1, Material* mat = 0);
934 void appendFace(int node0,
935 int node1,
936 int node2,
937 Material* mat = 0);
938 void appendTetra(int model, Material* mat);
939 //
940 void appendTetra(int node0,
941 int node1,
942 int node2,
943 int node3,
944 Material* mat = 0);
945
946 /* Append anchor */
947 void appendDeformableAnchor(int node, btRigidBody* body);
949 void appendAnchor(int node,
950 btRigidBody* body, bool disableCollisionBetweenLinkedBodies = false, btScalar influence = 1);
951 void appendAnchor(int node, btRigidBody* body, const btVector3& localPivot, bool disableCollisionBetweenLinkedBodies = false, btScalar influence = 1);
952 void removeAnchor(int node);
953 /* Append linear joint */
954 void appendLinearJoint(const LJoint::Specs& specs, Cluster* body0, Body body1);
955 void appendLinearJoint(const LJoint::Specs& specs, Body body = Body());
956 void appendLinearJoint(const LJoint::Specs& specs, btSoftBody* body);
957 /* Append linear joint */
958 void appendAngularJoint(const AJoint::Specs& specs, Cluster* body0, Body body1);
959 void appendAngularJoint(const AJoint::Specs& specs, Body body = Body());
960 void appendAngularJoint(const AJoint::Specs& specs, btSoftBody* body);
961 /* Add force (or gravity) to the entire body */
962 void addForce(const btVector3& force);
963 /* Add force (or gravity) to a node of the body */
964 void addForce(const btVector3& force,
965 int node);
966 /* Add aero force to a node of the body */
967 void addAeroForceToNode(const btVector3& windVelocity, int nodeIndex);
968
969 /* Add aero force to a face of the body */
970 void addAeroForceToFace(const btVector3& windVelocity, int faceIndex);
971
972 /* Add velocity to the entire body */
973 void addVelocity(const btVector3& velocity);
974
975 /* Set velocity for the entire body */
976 void setVelocity(const btVector3& velocity);
977
978 /* Add velocity to a node of the body */
979 void addVelocity(const btVector3& velocity,
980 int node);
981 /* Set mass */
982 void setMass(int node,
983 btScalar mass);
984 /* Get mass */
985 btScalar getMass(int node) const;
986 /* Get total mass */
987 btScalar getTotalMass() const;
988 /* Set total mass (weighted by previous masses) */
989 void setTotalMass(btScalar mass,
990 bool fromfaces = false);
991 /* Set total density */
992 void setTotalDensity(btScalar density);
993 /* Set volume mass (using tetrahedrons) */
994 void setVolumeMass(btScalar mass);
995 /* Set volume density (using tetrahedrons) */
996 void setVolumeDensity(btScalar density);
997 /* Get the linear velocity of the center of mass */
999 /* Set the linear velocity of the center of mass */
1000 void setLinearVelocity(const btVector3& linVel);
1001 /* Set the angular velocity of the center of mass */
1002 void setAngularVelocity(const btVector3& angVel);
1003 /* Get best fit rigid transform */
1005 /* Transform to given pose */
1006 void transformTo(const btTransform& trs);
1007 /* Transform */
1008 void transform(const btTransform& trs);
1009 /* Translate */
1010 void translate(const btVector3& trs);
1011 /* Rotate */
1012 void rotate(const btQuaternion& rot);
1013 /* Scale */
1014 void scale(const btVector3& scl);
1015 /* Get link resting lengths scale */
1017 /* Scale resting length of all springs */
1018 void setRestLengthScale(btScalar restLength);
1019 /* Set current state as pose */
1020 void setPose(bool bvolume,
1021 bool bframe);
1022 /* Set current link lengths as resting lengths */
1023 void resetLinkRestLengths();
1024 /* Return the volume */
1025 btScalar getVolume() const;
1026 /* Cluster count */
1028 {
1029 btVector3 com(0, 0, 0);
1030 for (int i = 0; i < m_nodes.size(); i++)
1031 {
1032 com += (m_nodes[i].m_x * this->getMass(i));
1033 }
1034 com /= this->getTotalMass();
1035 return com;
1036 }
1037 int clusterCount() const;
1038 /* Cluster center of mass */
1039 static btVector3 clusterCom(const Cluster* cluster);
1040 btVector3 clusterCom(int cluster) const;
1041 /* Cluster velocity at rpos */
1042 static btVector3 clusterVelocity(const Cluster* cluster, const btVector3& rpos);
1043 /* Cluster impulse */
1044 static void clusterVImpulse(Cluster* cluster, const btVector3& rpos, const btVector3& impulse);
1045 static void clusterDImpulse(Cluster* cluster, const btVector3& rpos, const btVector3& impulse);
1046 static void clusterImpulse(Cluster* cluster, const btVector3& rpos, const Impulse& impulse);
1047 static void clusterVAImpulse(Cluster* cluster, const btVector3& impulse);
1048 static void clusterDAImpulse(Cluster* cluster, const btVector3& impulse);
1049 static void clusterAImpulse(Cluster* cluster, const Impulse& impulse);
1050 static void clusterDCImpulse(Cluster* cluster, const btVector3& impulse);
1051 /* Generate bending constraints based on distance in the adjency graph */
1052 int generateBendingConstraints(int distance,
1053 Material* mat = 0);
1054 /* Randomize constraints to reduce solver bias */
1055 void randomizeConstraints();
1056 /* Release clusters */
1057 void releaseCluster(int index);
1058 void releaseClusters();
1059 /* Generate clusters (K-mean) */
1062 int generateClusters(int k, int maxiterations = 8192);
1063 /* Refine */
1064 void refine(ImplicitFn* ifn, btScalar accurary, bool cut);
1065 /* CutLink */
1066 bool cutLink(int node0, int node1, btScalar position);
1067 bool cutLink(const Node* node0, const Node* node1, btScalar position);
1068
1070 bool rayTest(const btVector3& rayFrom,
1071 const btVector3& rayTo,
1072 sRayCast& results);
1073 bool rayFaceTest(const btVector3& rayFrom,
1074 const btVector3& rayTo,
1075 sRayCast& results);
1076 int rayFaceTest(const btVector3& rayFrom, const btVector3& rayTo,
1077 btScalar& mint, int& index) const;
1078 /* Solver presets */
1079 void setSolver(eSolverPresets::_ preset);
1080 /* predictMotion */
1081 void predictMotion(btScalar dt);
1082 /* solveConstraints */
1083 void solveConstraints();
1084 /* staticSolve */
1085 void staticSolve(int iterations);
1086 /* solveCommonConstraints */
1087 static void solveCommonConstraints(btSoftBody** bodies, int count, int iterations);
1088 /* solveClusters */
1089 static void solveClusters(const btAlignedObjectArray<btSoftBody*>& bodies);
1090 /* integrateMotion */
1091 void integrateMotion();
1092 /* defaultCollisionHandlers */
1096 bool useSelfCollision();
1097 void updateDeactivation(btScalar timeStep);
1098 void setZeroVelocity();
1099 bool wantsSleeping();
1100
1101 //
1102 // Functionality to deal with new accelerated solvers.
1103 //
1104
1108 void setWindVelocity(const btVector3& velocity);
1109
1113 const btVector3& getWindVelocity();
1114
1115 //
1116 // Set the solver that handles this soft body
1117 // Should not be allowed to get out of sync with reality
1118 // Currently called internally on addition to the world
1120 {
1121 m_softBodySolver = softBodySolver;
1122 }
1123
1124 //
1125 // Return the solver that handles this soft body
1126 //
1128 {
1129 return m_softBodySolver;
1130 }
1131
1132 //
1133 // Return the solver that handles this soft body
1134 //
1136 {
1137 return m_softBodySolver;
1138 }
1139
1140 //
1141 // Cast
1142 //
1143
1144 static const btSoftBody* upcast(const btCollisionObject* colObj)
1145 {
1146 if (colObj->getInternalType() == CO_SOFT_BODY)
1147 return (const btSoftBody*)colObj;
1148 return 0;
1149 }
1151 {
1152 if (colObj->getInternalType() == CO_SOFT_BODY)
1153 return (btSoftBody*)colObj;
1154 return 0;
1155 }
1156
1157 //
1158 // ::btCollisionObject
1159 //
1160
1161 virtual void getAabb(btVector3& aabbMin, btVector3& aabbMax) const
1162 {
1163 aabbMin = m_bounds[0];
1164 aabbMax = m_bounds[1];
1165 }
1166 //
1167 // Private
1168 //
1169 void pointersToIndices();
1170 void indicesToPointers(const int* map = 0);
1171
1172 int rayTest(const btVector3& rayFrom, const btVector3& rayTo,
1173 btScalar& mint, eFeature::_& feature, int& index, bool bcountonly) const;
1174 void initializeFaceTree();
1175 void rebuildNodeTree();
1176 btVector3 evaluateCom() const;
1177 bool checkDeformableContact(const btCollisionObjectWrapper* colObjWrap, const btVector3& x, btScalar margin, btSoftBody::sCti& cti, bool predict = false) const;
1178 bool checkDeformableFaceContact(const btCollisionObjectWrapper* colObjWrap, Face& f, btVector3& contact_point, btVector3& bary, btScalar margin, btSoftBody::sCti& cti, bool predict = false) const;
1179 bool checkContact(const btCollisionObjectWrapper* colObjWrap, const btVector3& x, btScalar margin, btSoftBody::sCti& cti) const;
1180 void updateNormals();
1181 void updateBounds();
1182 void updatePose();
1183 void updateConstants();
1184 void updateLinkConstants();
1185 void updateArea(bool averageArea = true);
1186 void initializeClusters();
1187 void updateClusters();
1188 void cleanupClusters();
1189 void prepareClusters(int iterations);
1190 void solveClusters(btScalar sor);
1191 void applyClusters(bool drift);
1192 void dampClusters();
1194 void setGravityFactor(btScalar gravFactor);
1195 void setCacheBarycenter(bool cacheBarycenter);
1196 void initializeDmInverse();
1197 void updateDeformation();
1198 void advanceDeformation();
1199 void applyForces();
1200 void setMaxStress(btScalar maxStress);
1201 void interpolateRenderMesh();
1202 void setCollisionQuadrature(int N);
1203 static void PSolve_Anchors(btSoftBody* psb, btScalar kst, btScalar ti);
1204 static void PSolve_RContacts(btSoftBody* psb, btScalar kst, btScalar ti);
1205 static void PSolve_SContacts(btSoftBody* psb, btScalar, btScalar ti);
1206 static void PSolve_Links(btSoftBody* psb, btScalar kst, btScalar ti);
1207 static void VSolve_Links(btSoftBody* psb, btScalar kst);
1208 static psolver_t getSolver(ePSolver::_ solver);
1209 static vsolver_t getSolver(eVSolver::_ solver);
1211#define SAFE_EPSILON SIMD_EPSILON * 100.0
1212 void updateNode(btDbvtNode* node, bool use_velocity, bool margin)
1213 {
1214 if (node->isleaf())
1215 {
1216 btSoftBody::Node* n = (btSoftBody::Node*)(node->data);
1218 vol;
1219 btScalar pad = margin ? m_sst.radmrg : SAFE_EPSILON; // use user defined margin or margin for floating point precision
1220 if (use_velocity)
1221 {
1222 btVector3 points[2] = {n->m_x, n->m_x + m_sst.sdt * n->m_v};
1223 vol = btDbvtVolume::FromPoints(points, 2);
1224 vol.Expand(btVector3(pad, pad, pad));
1225 }
1226 else
1227 {
1228 vol = btDbvtVolume::FromCR(n->m_x, pad);
1229 }
1230 node->volume = vol;
1231 return;
1232 }
1233 else
1234 {
1235 updateNode(node->childs[0], use_velocity, margin);
1236 updateNode(node->childs[1], use_velocity, margin);
1238 vol;
1239 Merge(node->childs[0]->volume, node->childs[1]->volume, vol);
1240 node->volume = vol;
1241 }
1242 }
1243
1244 void updateNodeTree(bool use_velocity, bool margin)
1245 {
1246 if (m_ndbvt.m_root)
1247 updateNode(m_ndbvt.m_root, use_velocity, margin);
1248 }
1249
1250 template <class DBVTNODE> // btDbvtNode or btDbvntNode
1251 void updateFace(DBVTNODE* node, bool use_velocity, bool margin)
1252 {
1253 if (node->isleaf())
1254 {
1255 btSoftBody::Face* f = (btSoftBody::Face*)(node->data);
1256 btScalar pad = margin ? m_sst.radmrg : SAFE_EPSILON; // use user defined margin or margin for floating point precision
1258 vol;
1259 if (use_velocity)
1260 {
1261 btVector3 points[6] = {f->m_n[0]->m_x, f->m_n[0]->m_x + m_sst.sdt * f->m_n[0]->m_v,
1262 f->m_n[1]->m_x, f->m_n[1]->m_x + m_sst.sdt * f->m_n[1]->m_v,
1263 f->m_n[2]->m_x, f->m_n[2]->m_x + m_sst.sdt * f->m_n[2]->m_v};
1264 vol = btDbvtVolume::FromPoints(points, 6);
1265 }
1266 else
1267 {
1268 btVector3 points[3] = {f->m_n[0]->m_x,
1269 f->m_n[1]->m_x,
1270 f->m_n[2]->m_x};
1271 vol = btDbvtVolume::FromPoints(points, 3);
1272 }
1273 vol.Expand(btVector3(pad, pad, pad));
1274 node->volume = vol;
1275 return;
1276 }
1277 else
1278 {
1279 updateFace(node->childs[0], use_velocity, margin);
1280 updateFace(node->childs[1], use_velocity, margin);
1282 vol;
1283 Merge(node->childs[0]->volume, node->childs[1]->volume, vol);
1284 node->volume = vol;
1285 }
1286 }
1287 void updateFaceTree(bool use_velocity, bool margin)
1288 {
1289 if (m_fdbvt.m_root)
1290 updateFace(m_fdbvt.m_root, use_velocity, margin);
1291 if (m_fdbvnt)
1292 updateFace(m_fdbvnt, use_velocity, margin);
1293 }
1294
1295 template <typename T>
1296 static inline T BaryEval(const T& a,
1297 const T& b,
1298 const T& c,
1299 const btVector3& coord)
1300 {
1301 return (a * coord.x() + b * coord.y() + c * coord.z());
1302 }
1303
1304 void applyRepulsionForce(btScalar timeStep, bool applySpringForce)
1305 {
1307 {
1308 // randomize the order of repulsive force
1309 indices.resize(m_faceNodeContacts.size());
1310 for (int i = 0; i < m_faceNodeContacts.size(); ++i)
1311 indices[i] = i;
1312#define NEXTRAND (seed = (1664525L * seed + 1013904223L) & 0xffffffff)
1313 int i, ni;
1314
1315 for (i = 0, ni = indices.size(); i < ni; ++i)
1316 {
1317 btSwap(indices[i], indices[NEXTRAND % ni]);
1318 }
1319 }
1320 for (int k = 0; k < m_faceNodeContacts.size(); ++k)
1321 {
1322 int idx = indices[k];
1324 btSoftBody::Node* node = c.m_node;
1325 btSoftBody::Face* face = c.m_face;
1326 const btVector3& w = c.m_bary;
1327 const btVector3& n = c.m_normal;
1328 btVector3 l = node->m_x - BaryEval(face->m_n[0]->m_x, face->m_n[1]->m_x, face->m_n[2]->m_x, w);
1329 btScalar d = c.m_margin - n.dot(l);
1330 d = btMax(btScalar(0), d);
1331
1332 const btVector3& va = node->m_v;
1333 btVector3 vb = BaryEval(face->m_n[0]->m_v, face->m_n[1]->m_v, face->m_n[2]->m_v, w);
1334 btVector3 vr = va - vb;
1335 const btScalar vn = btDot(vr, n); // dn < 0 <==> opposing
1336 if (vn > OVERLAP_REDUCTION_FACTOR * d / timeStep)
1337 continue;
1338 btVector3 vt = vr - vn * n;
1339 btScalar I = 0;
1340 btScalar mass = node->m_im == 0 ? 0 : btScalar(1) / node->m_im;
1341 if (applySpringForce)
1342 I = -btMin(m_repulsionStiffness * timeStep * d, mass * (OVERLAP_REDUCTION_FACTOR * d / timeStep - vn));
1343 if (vn < 0)
1344 I += 0.5 * mass * vn;
1345 int face_penetration = 0, node_penetration = node->m_constrained;
1346 for (int i = 0; i < 3; ++i)
1347 face_penetration |= face->m_n[i]->m_constrained;
1348 btScalar I_tilde = 2.0 * I / (1.0 + w.length2());
1349
1350 // double the impulse if node or face is constrained.
1351 if (face_penetration > 0 || node_penetration > 0)
1352 {
1353 I_tilde *= 2.0;
1354 }
1355 if (face_penetration <= 0)
1356 {
1357 for (int j = 0; j < 3; ++j)
1358 face->m_n[j]->m_v += w[j] * n * I_tilde * node->m_im;
1359 }
1360 if (node_penetration <= 0)
1361 {
1362 node->m_v -= I_tilde * node->m_im * n;
1363 }
1364
1365 // apply frictional impulse
1366 btScalar vt_norm = vt.safeNorm();
1367 if (vt_norm > SIMD_EPSILON)
1368 {
1369 btScalar delta_vn = -2 * I * node->m_im;
1370 btScalar mu = c.m_friction;
1371 btScalar vt_new = btMax(btScalar(1) - mu * delta_vn / (vt_norm + SIMD_EPSILON), btScalar(0)) * vt_norm;
1372 I = 0.5 * mass * (vt_norm - vt_new);
1373 vt.safeNormalize();
1374 I_tilde = 2.0 * I / (1.0 + w.length2());
1375 // double the impulse if node or face is constrained.
1376 if (face_penetration > 0 || node_penetration > 0)
1377 I_tilde *= 2.0;
1378 if (face_penetration <= 0)
1379 {
1380 for (int j = 0; j < 3; ++j)
1381 face->m_n[j]->m_v += w[j] * vt * I_tilde * (face->m_n[j])->m_im;
1382 }
1383 if (node_penetration <= 0)
1384 {
1385 node->m_v -= I_tilde * node->m_im * vt;
1386 }
1387 }
1388 }
1389 }
1390 virtual int calculateSerializeBufferSize() const;
1391
1393 virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
1394};
1395
1396#endif //_BT_SOFT_BODY_H
DBVT_INLINE void Merge(const btDbvtAabbMm &a, const btDbvtAabbMm &b, btDbvtAabbMm &r)
Definition: btDbvt.h:745
const T & btMax(const T &a, const T &b)
Definition: btMinMax.h:27
const T & btMin(const T &a, const T &b)
Definition: btMinMax.h:21
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:99
#define SIMD_INFINITY
Definition: btScalar.h:544
#define SIMD_EPSILON
Definition: btScalar.h:543
void btSwap(T &a, T &b)
Definition: btScalar.h:643
static unsigned long seed
Definition: btSoftBody.h:39
static const btScalar OVERLAP_REDUCTION_FACTOR
Definition: btSoftBody.h:38
#define NEXTRAND
#define SAFE_EPSILON
Definition: btSoftBody.h:1211
btScalar btDot(const btVector3 &v1, const btVector3 &v2)
Return the dot product between two vectors.
Definition: btVector3.h:890
btVector3 btCross(const btVector3 &v1, const btVector3 &v2)
Return the cross product of two vectors.
Definition: btVector3.h:918
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
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 ...
Definition: btDispatcher.h:77
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:50
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
Definition: btQuaternion.h:50
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:60
void applyTorqueImpulse(const btVector3 &torque)
Definition: btRigidBody.h:327
btScalar getInvMass() const
Definition: btRigidBody.h:263
void applyImpulse(const btVector3 &impulse, const btVector3 &rel_pos)
Definition: btRigidBody.h:335
void applyCentralImpulse(const btVector3 &impulse)
Definition: btRigidBody.h:319
const btVector3 & getAngularVelocity() const
Definition: btRigidBody.h:437
static const btRigidBody * upcast(const btCollisionObject *colObj)
to keep collision detection and dynamics separate we don't store a rigidbody pointer but a rigidbody ...
Definition: btRigidBody.h:189
const btMatrix3x3 & getInvInertiaTensorWorld() const
Definition: btRigidBody.h:265
const btVector3 & getLinearVelocity() const
Definition: btRigidBody.h:433
btMultiBodyJacobianData jacobianData_t1
Definition: btSoftBody.h:374
btMultiBodyJacobianData jacobianData_normal
Definition: btSoftBody.h:373
btMultiBodyJacobianData jacobianData_t2
Definition: btSoftBody.h:375
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:75
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
Definition: btSoftBody.cpp:253
bool m_bUpdateRtCst
Definition: btSoftBody.h:833
btScalar m_sleepingThreshold
Definition: btSoftBody.h:840
void transformTo(const btTransform &trs)
btVector3 getLinearVelocity()
bool checkFace(int node0, int node1, int node2) const
Definition: btSoftBody.cpp:275
void advanceDeformation()
btAlignedObjectArray< eVSolver::_ > tVSolverArray
Definition: btSoftBody.h:151
void setGravityFactor(btScalar gravFactor)
void updateClusters()
btDbvt m_cdbvt
Definition: btSoftBody.h:837
void setPose(bool bvolume, bool bframe)
btAlignedObjectArray< RenderNode > tRenderNodeArray
Definition: btSoftBody.h:791
bool cutLink(int node0, int node1, btScalar position)
void appendFace(int model=-1, Material *mat=0)
Definition: btSoftBody.cpp:429
void setMass(int node, btScalar mass)
Definition: btSoftBody.cpp:920
void interpolateRenderMesh()
tJointArray m_joints
Definition: btSoftBody.h:829
btScalar m_dampingCoefficient
Definition: btSoftBody.h:839
void updateNode(btDbvtNode *node, bool use_velocity, bool margin)
Definition: btSoftBody.h:1212
btAlignedObjectArray< TetraScratch > m_tetraScratchesTn
Definition: btSoftBody.h:821
void integrateMotion()
btAlignedObjectArray< Tetra > tTetraArray
Definition: btSoftBody.h:796
void rebuildNodeTree()
bool rayFaceTest(const btVector3 &rayFrom, const btVector3 &rayTo, sRayCast &results)
void appendLinearJoint(const LJoint::Specs &specs, Cluster *body0, Body body1)
Definition: btSoftBody.cpp:637
tRenderFaceArray m_renderFaces
Definition: btSoftBody.h:818
btAlignedObjectArray< SContact > tSContactArray
Definition: btSoftBody.h:799
void scale(const btVector3 &scl)
btAlignedObjectArray< bool > m_clusterConnectivity
Definition: btSoftBody.h:854
void updateFaceTree(bool use_velocity, bool margin)
Definition: btSoftBody.h:1287
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!)
SolverState m_sst
Definition: btSoftBody.h:809
void addVelocity(const btVector3 &velocity)
Definition: btSoftBody.cpp:890
btAlignedObjectArray< RContact > tRContactArray
Definition: btSoftBody.h:798
void setDampingCoefficient(btScalar damping_coeff)
Definition: btSoftBody.h:883
void predictMotion(btScalar dt)
void setSelfCollision(bool useSelfCollision)
void setLinearVelocity(const btVector3 &linVel)
btScalar m_timeacc
Definition: btSoftBody.h:831
Pose m_pose
Definition: btSoftBody.h:810
btAlignedObjectArray< int > m_userIndexMapping
Definition: btSoftBody.h:876
btAlignedObjectArray< Face > tFaceArray
Definition: btSoftBody.h:794
void appendTetra(int model, Material *mat)
Definition: btSoftBody.cpp:469
void setRestLengthScale(btScalar restLength)
btDbvntNode * m_fdbvnt
Definition: btSoftBody.h:836
void updateNodeTree(bool use_velocity, bool margin)
Definition: btSoftBody.h:1244
void rotate(const btQuaternion &rot)
void updateFace(DBVTNODE *node, bool use_velocity, bool margin)
Definition: btSoftBody.h:1251
void applyClusters(bool drift)
void setZeroVelocity()
static void PSolve_Anchors(btSoftBody *psb, btScalar kst, btScalar ti)
btSoftBodyWorldInfo * m_worldInfo
Definition: btSoftBody.h:812
void setSoftBodySolver(btSoftBodySolver *softBodySolver)
Definition: btSoftBody.h:1119
void updateArea(bool averageArea=true)
void addForce(const btVector3 &force)
Definition: btSoftBody.cpp:690
bool wantsSleeping()
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
Definition: btSoftBody.h:826
static void VSolve_Links(btSoftBody *psb, btScalar kst)
tTetraArray m_tetras
Definition: btSoftBody.h:819
bool useSelfCollision()
btVector3 evaluateCom() const
void setTotalDensity(btScalar density)
Definition: btSoftBody.cpp:980
btAlignedObjectArray< const class btCollisionObject * > m_collisionDisabledObjects
Definition: btSoftBody.h:77
btAlignedObjectArray< Link > tLinkArray
Definition: btSoftBody.h:793
static void clusterDAImpulse(Cluster *cluster, const btVector3 &impulse)
void appendNode(const btVector3 &x, btScalar m)
Definition: btSoftBody.cpp:369
void staticSolve(int iterations)
void setVolumeMass(btScalar mass)
Definition: btSoftBody.cpp:986
btScalar m_restLengthScale
Definition: btSoftBody.h:858
bool checkDeformableContact(const btCollisionObjectWrapper *colObjWrap, const btVector3 &x, btScalar margin, btSoftBody::sCti &cti, bool predict=false) const
void cleanupClusters()
Config m_cfg
Definition: btSoftBody.h:808
void updateDeactivation(btScalar timeStep)
btAlignedObjectArray< TetraScratch > m_tetraScratches
Definition: btSoftBody.h:820
const btVector3 & getWindVelocity()
Return the wind velocity for interaction with the air.
void addAeroForceToFace(const btVector3 &windVelocity, int faceIndex)
Definition: btSoftBody.cpp:794
btAlignedObjectArray< btVector4 > m_renderNodesInterpolationWeights
Definition: btSoftBody.h:848
void appendAngularJoint(const AJoint::Specs &specs, Cluster *body0, Body body1)
Definition: btSoftBody.cpp:663
tFaceArray m_faces
Definition: btSoftBody.h:817
void setAngularVelocity(const btVector3 &angVel)
void setVolumeDensity(btScalar density)
static void clusterDCImpulse(Cluster *cluster, const btVector3 &impulse)
void transform(const btTransform &trs)
bool m_softSoftCollision
Definition: btSoftBody.h:852
static void clusterVAImpulse(Cluster *cluster, const btVector3 &impulse)
btScalar getMass(int node) const
Definition: btSoftBody.cpp:927
tMaterialArray m_materials
Definition: btSoftBody.h:830
void setMaxStress(btScalar maxStress)
void dampClusters()
btSoftBody(btSoftBodyWorldInfo *worldInfo, int node_count, const btVector3 *x, const btScalar *m)
Definition: btSoftBody.cpp:130
void updateDeformation()
btAlignedObjectArray< btScalar > m_z
Definition: btSoftBody.h:850
void addAeroForceToNode(const btVector3 &windVelocity, int nodeIndex)
Definition: btSoftBody.cpp:705
void applyRepulsionForce(btScalar timeStep, bool applySpringForce)
Definition: btSoftBody.h:1304
btAlignedObjectArray< btVector3 > tVector3Array
Definition: btSoftBody.h:221
static btVector3 clusterCom(const Cluster *cluster)
tRContactArray m_rcontacts
Definition: btSoftBody.h:824
void appendAnchor(int node, btRigidBody *body, bool disableCollisionBetweenLinkedBodies=false, btScalar influence=1)
Definition: btSoftBody.cpp:501
btAlignedObjectArray< Node > tNodeArray
Definition: btSoftBody.h:790
btVector3 m_bounds[2]
Definition: btSoftBody.h:832
btScalar m_maxSpeedSquared
Definition: btSoftBody.h:841
void releaseCluster(int index)
btScalar m_repulsionStiffness
Definition: btSoftBody.h:843
void setVelocity(const btVector3 &velocity)
Definition: btSoftBody.cpp:896
tClusterArray m_clusters
Definition: btSoftBody.h:838
btAlignedObjectArray< Joint * > tJointArray
Definition: btSoftBody.h:801
void solveConstraints()
btAlignedObjectArray< DeformableFaceRigidContact > m_faceRigidContacts
Definition: btSoftBody.h:827
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 releaseClusters()
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)
Definition: btSoftBody.h:1296
Material * appendMaterial()
Definition: btSoftBody.cpp:299
void removeAnchor(int node)
Definition: btSoftBody.cpp:563
btAlignedObjectArray< DeformableNodeRigidAnchor > m_deformableAnchors
Definition: btSoftBody.h:823
void setCacheBarycenter(bool cacheBarycenter)
btAlignedObjectArray< Material * > tMaterialArray
Definition: btSoftBody.h:800
btAlignedObjectArray< Anchor > tAnchorArray
Definition: btSoftBody.h:797
btScalar m_gravityFactor
Definition: btSoftBody.h:844
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)
Definition: btSoftBody.cpp:311
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
Definition: btSoftBody.h:825
btAlignedObjectArray< btSoftBody * > tSoftBodyArray
Definition: btSoftBody.h:802
static void PSolve_RContacts(btSoftBody *psb, btScalar kst, btScalar ti)
static void clusterImpulse(Cluster *cluster, const btVector3 &rpos, const Impulse &impulse)
btAlignedObjectArray< btAlignedObjectArray< const btSoftBody::Node * > > m_renderNodesParents
Definition: btSoftBody.h:849
tRenderNodeArray m_renderNodes
Definition: btSoftBody.h:815
void pointersToIndices()
tNoteArray m_notes
Definition: btSoftBody.h:813
void updateNormals()
static void clusterDImpulse(Cluster *cluster, const btVector3 &rpos, const btVector3 &impulse)
btDbvt m_fdbvt
Definition: btSoftBody.h:835
tLinkArray m_links
Definition: btSoftBody.h:816
void applyForces()
static btVector3 clusterVelocity(const Cluster *cluster, const btVector3 &rpos)
btTransform getRigidTransform()
tSContactArray m_scontacts
Definition: btSoftBody.h:828
bool m_cacheBarycenter
Definition: btSoftBody.h:845
bool m_useSelfCollision
Definition: btSoftBody.h:851
void * m_tag
Definition: btSoftBody.h:811
void updatePose()
btAlignedObjectArray< btDbvtNode * > tLeafArray
Definition: btSoftBody.h:792
void(* psolver_t)(btSoftBody *, btScalar, btScalar)
Definition: btSoftBody.h:786
void initializeClusters()
btSoftBodyWorldInfo * getWorldInfo()
Definition: btSoftBody.h:878
tAnchorArray m_anchors
Definition: btSoftBody.h:822
btScalar getRestLengthScale()
btAlignedObjectArray< Note > tNoteArray
Definition: btSoftBody.h:789
void randomizeConstraints()
virtual void setCollisionShape(btCollisionShape *collisionShape)
Definition: btSoftBody.h:889
btVector3 m_windVelocity
Definition: btSoftBody.h:856
btScalar getTotalMass() const
Definition: btSoftBody.cpp:933
tNodeArray m_nodes
Definition: btSoftBody.h:814
btAlignedObjectArray< ePSolver::_ > tPSolverArray
Definition: btSoftBody.h:152
void appendLink(int model=-1, Material *mat=0)
Definition: btSoftBody.cpp:389
void setSpringStiffness(btScalar k)
void initializeDmInverse()
static const btSoftBody * upcast(const btCollisionObject *colObj)
Definition: btSoftBody.h:1144
void updateConstants()
void setTotalMass(btScalar mass, bool fromfaces=false)
Definition: btSoftBody.cpp:944
btSoftBodySolver * getSoftBodySolver()
Definition: btSoftBody.h:1127
virtual ~btSoftBody()
Definition: btSoftBody.cpp:237
void appendDeformableAnchor(int node, btRigidBody *body)
Definition: btSoftBody.cpp:528
btAlignedObjectArray< RenderFace > tRenderFaceArray
Definition: btSoftBody.h:795
void updateLinkConstants()
virtual void getAabb(btVector3 &aabbMin, btVector3 &aabbMax) const
Definition: btSoftBody.h:1161
void(* vsolver_t)(btSoftBody *, btScalar)
Definition: btSoftBody.h:787
void initDefaults()
Definition: btSoftBody.cpp:170
btAlignedObjectArray< btVector3 > m_quads
Definition: btSoftBody.h:842
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
Definition: btSoftBody.h:788
void updateBounds()
void setWindVelocity(const btVector3 &velocity)
Set a wind velocity for interaction with the air.
btSoftBodySolver * getSoftBodySolver() const
Definition: btSoftBody.h:1135
int generateBendingConstraints(int distance, Material *mat=0)
btAlignedObjectArray< btVector3 > m_X
Definition: btSoftBody.h:846
void translate(const btVector3 &trs)
btVector3 getCenterOfMass() const
Definition: btSoftBody.h:1027
void initializeFaceTree()
btSoftBodySolver * m_softBodySolver
Definition: btSoftBody.h:80
void resetLinkRestLengths()
int clusterCount() const
btAlignedObjectArray< btScalar > tScalarArray
Definition: btSoftBody.h:220
btDbvt m_ndbvt
Definition: btSoftBody.h:834
static void clusterAImpulse(Cluster *cluster, const Impulse &impulse)
static btSoftBody * upcast(btCollisionObject *colObj)
Definition: btSoftBody.h:1150
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
static const btTransform & getIdentity()
Return an identity transform.
Definition: btTransform.h:197
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btScalar safeNorm() const
Return the norm (length) of the vector.
Definition: btVector3.h:269
const btScalar & z() const
Return the z value.
Definition: btVector3.h:579
btVector3 & safeNormalize()
Definition: btVector3.h:286
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition: btVector3.h:229
btScalar length2() const
Return the length of the vector squared.
Definition: btVector3.h:251
const btScalar & x() const
Return the x value.
Definition: btVector3.h:575
const btScalar & y() const
Return the y value.
Definition: btVector3.h:577
static btDbvtAabbMm FromCR(const btVector3 &c, btScalar r)
Definition: btDbvt.h:473
static btDbvtAabbMm FromPoints(const btVector3 *pts, int n)
Definition: btDbvt.h:488
btDbvtNode * childs[2]
Definition: btDbvt.h:187
void * data
Definition: btDbvt.h:188
btDbvtVolume volume
Definition: btDbvt.h:182
DBVT_INLINE bool isleaf() const
Definition: btDbvt.h:184
The btDbvt class implements a fast dynamic bounding volume tree based on axis aligned bounding boxes ...
Definition: btDbvt.h:229
btDbvtNode * m_root
Definition: btDbvt.h:302
btScalar air_density
Definition: btSoftBody.h:49
btDispatcher * m_dispatcher
Definition: btSoftBody.h:55
btScalar water_density
Definition: btSoftBody.h:50
btSparseSdf< 3 > m_sparsesdf
Definition: btSoftBody.h:57
btVector3 m_gravity
Definition: btSoftBody.h:56
btVector3 water_normal
Definition: btSoftBody.h:53
btScalar m_maxDisplacement
Definition: btSoftBody.h:52
btScalar water_offset
Definition: btSoftBody.h:51
btBroadphaseInterface * m_broadphase
Definition: btSoftBody.h:54
static IControl * Default()
Definition: btSoftBody.h:676
virtual btScalar Speed(AJoint *, btScalar current)
Definition: btSoftBody.h:675
virtual void Prepare(AJoint *)
Definition: btSoftBody.h:674
btVector3 m_axis[2]
Definition: btSoftBody.h:688
void Prepare(btScalar dt, int iterations)
void Solve(btScalar dt, btScalar sor)
IControl * m_icontrol
Definition: btSoftBody.h:689
void Terminate(btScalar dt)
eType::_ Type() const
Definition: btSoftBody.h:693
btScalar m_influence
Definition: btSoftBody.h:431
btVector3 m_local
Definition: btSoftBody.h:429
btRigidBody * m_body
Definition: btSoftBody.h:430
btMatrix3x3 m_c0
Definition: btSoftBody.h:432
btScalar invMass() const
Definition: btSoftBody.h:541
Body(Cluster *p)
Definition: btSoftBody.h:521
const btMatrix3x3 & invWorldInertia() const
Definition: btSoftBody.h:534
void applyVImpulse(const btVector3 &impulse, const btVector3 &rpos) const
Definition: btSoftBody.h:576
btVector3 angularVelocity() const
Definition: btSoftBody.h:566
btRigidBody * m_rigid
Definition: btSoftBody.h:517
btVector3 linearVelocity() const
Definition: btSoftBody.h:554
btVector3 angularVelocity(const btVector3 &rpos) const
Definition: btSoftBody.h:560
void applyDImpulse(const btVector3 &impulse, const btVector3 &rpos) const
Definition: btSoftBody.h:581
Body(const btCollisionObject *colObj)
Definition: btSoftBody.h:522
btVector3 velocity(const btVector3 &rpos) const
Definition: btSoftBody.h:572
void applyDCImpulse(const btVector3 &impulse) const
Definition: btSoftBody.h:614
void applyDAImpulse(const btVector3 &impulse) const
Definition: btSoftBody.h:604
const btTransform & xform() const
Definition: btSoftBody.h:547
void activate() const
Definition: btSoftBody.h:527
void applyVAImpulse(const btVector3 &impulse) const
Definition: btSoftBody.h:599
Cluster * m_soft
Definition: btSoftBody.h:516
void applyAImpulse(const Impulse &impulse) const
Definition: btSoftBody.h:609
void applyImpulse(const Impulse &impulse, const btVector3 &rpos) const
Definition: btSoftBody.h:586
const btCollisionObject * m_collisionObject
Definition: btSoftBody.h:518
void Terminate(btScalar dt)
eType::_ Type() const
Definition: btSoftBody.h:706
btVector3 m_rpos[2]
Definition: btSoftBody.h:700
void Prepare(btScalar dt, int iterations)
btVector3 m_normal
Definition: btSoftBody.h:701
btScalar m_friction
Definition: btSoftBody.h:702
void Solve(btScalar dt, btScalar sor)
btVector3 m_dimpulses[2]
Definition: btSoftBody.h:471
tVector3Array m_framerefs
Definition: btSoftBody.h:463
btMatrix3x3 m_invwi
Definition: btSoftBody.h:468
btScalar m_maxSelfCollisionImpulse
Definition: btSoftBody.h:481
btMatrix3x3 m_locii
Definition: btSoftBody.h:467
btAlignedObjectArray< Node * > m_nodes
Definition: btSoftBody.h:462
btDbvtNode * m_leaf
Definition: btSoftBody.h:476
btVector3 m_vimpulses[2]
Definition: btSoftBody.h:470
tScalarArray m_masses
Definition: btSoftBody.h:461
btScalar m_selfCollisionImpulseFactor
Definition: btSoftBody.h:482
btTransform m_framexform
Definition: btSoftBody.h:464
btScalar maxvolume
Definition: btSoftBody.h:730
tPSolverArray m_psequence
Definition: btSoftBody.h:738
tPSolverArray m_dsequence
Definition: btSoftBody.h:739
btScalar kSK_SPLT_CL
Definition: btSoftBody.h:728
btScalar kSS_SPLT_CL
Definition: btSoftBody.h:729
btScalar m_maxStress
Definition: btSoftBody.h:741
eAeroModel::_ aeromodel
Definition: btSoftBody.h:711
btScalar kSR_SPLT_CL
Definition: btSoftBody.h:727
tVSolverArray m_vsequence
Definition: btSoftBody.h:737
btScalar timescale
Definition: btSoftBody.h:731
btVector4 m_pcontact
Definition: btSoftBody.h:313
btVector3 m_normal
Definition: btSoftBody.h:310
btVector3 m_n0
Definition: btSoftBody.h:314
btVector3 m_n1
Definition: btSoftBody.h:314
btVector3 m_vn
Definition: btSoftBody.h:314
Node * m_n[3]
Definition: btSoftBody.h:309
btDbvtNode * m_leaf
Definition: btSoftBody.h:312
Material * m_material
Definition: btSoftBody.h:260
virtual btScalar Eval(const btVector3 &x)=0
Impulse operator*(btScalar x) const
Definition: btSoftBody.h:505
Impulse operator-() const
Definition: btSoftBody.h:498
btVector3 m_velocity
Definition: btSoftBody.h:493
btVector3 m_drift
Definition: btSoftBody.h:644
btVector3 m_sdrift
Definition: btSoftBody.h:645
btScalar m_split
Definition: btSoftBody.h:643
virtual void Solve(btScalar dt, btScalar sor)=0
virtual void Terminate(btScalar dt)=0
btMatrix3x3 m_massmatrix
Definition: btSoftBody.h:646
virtual ~Joint()
Definition: btSoftBody.h:648
btVector3 m_refs[2]
Definition: btSoftBody.h:640
virtual void Prepare(btScalar dt, int iterations)
virtual eType::_ Type() const =0
void Solve(btScalar dt, btScalar sor)
btVector3 m_rpos[2]
Definition: btSoftBody.h:662
eType::_ Type() const
Definition: btSoftBody.h:666
void Prepare(btScalar dt, int iterations)
void Terminate(btScalar dt)
btScalar m_area
Definition: btSoftBody.h:278
btVector3 m_x
Definition: btSoftBody.h:271
btVector3 m_splitv
Definition: btSoftBody.h:283
btVector3 m_vn
Definition: btSoftBody.h:274
btVector3 m_v
Definition: btSoftBody.h:273
btVector3 m_q
Definition: btSoftBody.h:272
btDbvtNode * m_leaf
Definition: btSoftBody.h:279
btVector3 m_n
Definition: btSoftBody.h:276
btVector3 m_f
Definition: btSoftBody.h:275
btMatrix3x3 m_effectiveMass_inv
Definition: btSoftBody.h:285
btMatrix3x3 m_effectiveMass
Definition: btSoftBody.h:284
btScalar m_coords[4]
Definition: btSoftBody.h:443
btVector3 m_offset
Definition: btSoftBody.h:440
Node * m_nodes[4]
Definition: btSoftBody.h:442
const char * m_text
Definition: btSoftBody.h:439
btMatrix3x3 m_scl
Definition: btSoftBody.h:455
btScalar m_volume
Definition: btSoftBody.h:450
btVector3 m_com
Definition: btSoftBody.h:453
tVector3Array m_pos
Definition: btSoftBody.h:451
btMatrix3x3 m_aqq
Definition: btSoftBody.h:456
btMatrix3x3 m_rot
Definition: btSoftBody.h:454
tScalarArray m_wgh
Definition: btSoftBody.h:452
btMultiBodyJacobianData jacobianData_t2
Definition: btSoftBody.h:356
btMultiBodyJacobianData jacobianData_t1
Definition: btSoftBody.h:355
btMatrix3x3 m_c0
Definition: btSoftBody.h:347
btMultiBodyJacobianData jacobianData_normal
Definition: btSoftBody.h:354
RayFromToCaster takes a ray from, ray to (instead of direction!)
Definition: btSoftBody.h:763
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
Definition: btSoftBody.h:766
RenderNode * m_n[3]
Definition: btSoftBody.h:303
btScalar m_cfm[2]
Definition: btSoftBody.h:423
btMatrix3x3 m_corotation
Definition: btSoftBody.h:339
btScalar m_element_measure
Definition: btSoftBody.h:328
btMatrix3x3 m_Dm_inverse
Definition: btSoftBody.h:326
btMatrix3x3 m_F
Definition: btSoftBody.h:327
btVector4 m_P_inv[3]
Definition: btSoftBody.h:329
btVector3 m_c0[4]
Definition: btSoftBody.h:323
btDbvtNode * m_leaf
Definition: btSoftBody.h:322
@ V_TwoSided
Vertex normals are oriented toward velocity.
Definition: btSoftBody.h:92
@ V_OneSided
Vertex normals are flipped to match velocity and lift and drag forces are applied.
Definition: btSoftBody.h:94
@ END
Face normals are taken as it is.
Definition: btSoftBody.h:98
@ V_TwoSidedLiftDrag
Vertex normals are flipped to match velocity.
Definition: btSoftBody.h:93
@ F_OneSided
Face normals are flipped to match velocity and lift and drag forces are applied.
Definition: btSoftBody.h:97
@ F_TwoSided
Vertex normals are taken as it is.
Definition: btSoftBody.h:95
@ F_TwoSidedLiftDrag
Face normals are flipped to match velocity.
Definition: btSoftBody.h:96
ePSolver : positions solvers
Definition: btSoftBody.h:114
@ RContacts
Anchor solver.
Definition: btSoftBody.h:119
@ SContacts
Rigid contacts solver.
Definition: btSoftBody.h:120
@ Anchors
Linear solver.
Definition: btSoftBody.h:118
@ END
Soft contacts solver.
Definition: btSoftBody.h:121
eVSolver : velocities solvers
Definition: btSoftBody.h:104
@ END
Linear solver.
Definition: btSoftBody.h:108
@ SDF_RDN
GJK based Multibody vs. deformable face.
Definition: btSoftBody.h:177
@ VF_SS
Rigid versus soft mask.
Definition: btSoftBody.h:169
@ Default
SDF based Rigid vs. deformable node.
Definition: btSoftBody.h:179
@ RVDFmask
Vertex vs face soft vs soft handling.
Definition: btSoftBody.h:174
@ VF_DD
Cluster soft body self collision.
Definition: btSoftBody.h:172
@ CL_SS
Vertex vs face soft vs soft handling.
Definition: btSoftBody.h:170
@ CL_SELF
Cluster vs cluster soft vs soft handling.
Definition: btSoftBody.h:171
@ SVSmask
rigid vs deformable
Definition: btSoftBody.h:168
@ SDF_RS
Rigid versus soft mask.
Definition: btSoftBody.h:164
@ SDF_RD
Cluster vs convex rigid vs soft.
Definition: btSoftBody.h:166
@ SDF_RDF
Rigid versus deformable face mask.
Definition: btSoftBody.h:175
@ SDF_MDF
GJK based Rigid vs. deformable face.
Definition: btSoftBody.h:176
@ CL_RS
SDF based rigid vs soft.
Definition: btSoftBody.h:165
@ Default
Enable debug draw.
Definition: btSoftBody.h:191
btVector3 m_impulse
Definition: btSoftBody.h:228
const btCollisionObject * m_colObj
Definition: btSoftBody.h:226
btVector3 m_bary
Definition: btSoftBody.h:230
btScalar m_offset
Definition: btSoftBody.h:229
btVector3 m_normal
Definition: btSoftBody.h:227
btVector3 m_velocity
Definition: btSoftBody.h:237
eFeature::_ feature
soft body
Definition: btSoftBody.h:204
btScalar fraction
feature index
Definition: btSoftBody.h:206
int index
feature type
Definition: btSoftBody.h:205
btSoftBody * body
Definition: btSoftBody.h:203