1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
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_SOFTBODY_FLOAT_DATA
17 #define BT_SOFTBODY_FLOAT_DATA
18 
19 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
20 #include "BulletDynamics/Dynamics/btRigidBody.h"
21 
22 
23 struct	SoftBodyMaterialData
24 {
25 	float	m_linearStiffness;
26 	float	m_angularStiffness;
27 	float	m_volumeStiffness;
28 	int		m_flags;
29 };
30 
31 struct	SoftBodyNodeData
32 {
33 	SoftBodyMaterialData		*m_material;
34 	btVector3FloatData			m_position;
35 	btVector3FloatData			m_previousPosition;
36 	btVector3FloatData			m_velocity;
37 	btVector3FloatData			m_accumulatedForce;
38 	btVector3FloatData			m_normal;
39 	float						m_inverseMass;
40 	float						m_area;
41 	int							m_attach;
42 	int							m_pad;
43 };
44 
45 struct	SoftBodyLinkData
46 {
47 	SoftBodyMaterialData	*m_material;
48 	int						m_nodeIndices[2];			// Node pointers
49 	float					m_restLength;			// Rest length
50 	int						m_bbending;		// Bending link
51 };
52 
53 struct	SoftBodyFaceData
54 {
55 	btVector3FloatData		m_normal;		// Normal
56 	SoftBodyMaterialData	*m_material;
57 	int						m_nodeIndices[3];			// Node pointers
58 	float					m_restArea;			// Rest area
59 };
60 
61 struct	SoftBodyTetraData
62 {
63 	btVector3FloatData		m_c0[4];		// gradients
64 	SoftBodyMaterialData	*m_material;
65 	int						m_nodeIndices[4];			// Node pointers
66 	float					m_restVolume;			// Rest volume
67 	float					m_c1;			// (4*kVST)/(im0+im1+im2+im3)
68 	float					m_c2;			// m_c1/sum(|g0..3|^2)
69 	int						m_pad;
70 };
71 
72 struct	SoftRigidAnchorData
73 {
74 	btMatrix3x3FloatData	m_c0;			// Impulse matrix
75 	btVector3FloatData		m_c1;			// Relative anchor
76 	btVector3FloatData		m_localFrame;		// Anchor position in body space
77 	btRigidBodyData			*m_rigidBody;
78 	int						m_nodeIndex;			// Node pointer
79 	float					m_c2;			// ima*dt
80 };
81 
82 
83 
84 struct	SoftBodyConfigData
85 {
86 	int					m_aeroModel;		// Aerodynamic model (default: V_Point)
87 	float				m_baumgarte;			// Velocities correction factor (Baumgarte)
88 	float				m_damping;			// Damping coefficient [0,1]
89 	float				m_drag;			// Drag coefficient [0,+inf]
90 	float				m_lift;			// Lift coefficient [0,+inf]
91 	float				m_pressure;			// Pressure coefficient [-inf,+inf]
92 	float				m_volume;			// Volume conversation coefficient [0,+inf]
93 	float				m_dynamicFriction;			// Dynamic friction coefficient [0,1]
94 	float				m_poseMatch;			// Pose matching coefficient [0,1]
95 	float				m_rigidContactHardness;			// Rigid contacts hardness [0,1]
96 	float				m_kineticContactHardness;			// Kinetic contacts hardness [0,1]
97 	float				m_softContactHardness;			// Soft contacts hardness [0,1]
98 	float				m_anchorHardness;			// Anchors hardness [0,1]
99 	float				m_softRigidClusterHardness;		// Soft vs rigid hardness [0,1] (cluster only)
100 	float				m_softKineticClusterHardness;		// Soft vs kinetic hardness [0,1] (cluster only)
101 	float				m_softSoftClusterHardness;		// Soft vs soft hardness [0,1] (cluster only)
102 	float				m_softRigidClusterImpulseSplit;	// Soft vs rigid impulse split [0,1] (cluster only)
103 	float				m_softKineticClusterImpulseSplit;	// Soft vs rigid impulse split [0,1] (cluster only)
104 	float				m_softSoftClusterImpulseSplit;	// Soft vs rigid impulse split [0,1] (cluster only)
105 	float				m_maxVolume;		// Maximum volume ratio for pose
106 	float				m_timeScale;		// Time scale
107 	int					m_velocityIterations;	// Velocities solver iterations
108 	int					m_positionIterations;	// Positions solver iterations
109 	int					m_driftIterations;	// Drift solver iterations
110 	int					m_clusterIterations;	// Cluster solver iterations
111 	int					m_collisionFlags;	// Collisions flags
112 };
113 
114 struct	SoftBodyPoseData
115 {
116 	btMatrix3x3FloatData	m_rot;			// Rotation
117 	btMatrix3x3FloatData	m_scale;			// Scale
118 	btMatrix3x3FloatData	m_aqq;			// Base scaling
119 	btVector3FloatData		m_com;			// COM
120 
121 	btVector3FloatData		*m_positions;			// Reference positions
122 	float					*m_weights;	// Weights
123 	int						m_numPositions;
124 	int						m_numWeigts;
125 
126 	int						m_bvolume;		// Is valid
127 	int						m_bframe;		// Is frame
128 	float					m_restVolume;		// Rest volume
129 	int						m_pad;
130 };
131 
132 struct	SoftBodyClusterData
133 {
134 		btTransformFloatData		m_framexform;
135 		btMatrix3x3FloatData		m_locii;
136 		btMatrix3x3FloatData		m_invwi;
137 		btVector3FloatData			m_com;
138 		btVector3FloatData			m_vimpulses[2];
139 		btVector3FloatData			m_dimpulses[2];
140 		btVector3FloatData			m_lv;
141 		btVector3FloatData			m_av;
142 
143 		btVector3FloatData			*m_framerefs;
144 		int							*m_nodeIndices;
145 		float						*m_masses;
146 
147 		int							m_numFrameRefs;
148 		int							m_numNodes;
149 		int							m_numMasses;
150 
151 		float						m_idmass;
152 		float						m_imass;
153 		int							m_nvimpulses;
154 		int							m_ndimpulses;
155 		float						m_ndamping;
156 		float						m_ldamping;
157 		float						m_adamping;
158 		float						m_matching;
159 		float						m_maxSelfCollisionImpulse;
160 		float						m_selfCollisionImpulseFactor;
161 		int							m_containsAnchor;
162 		int							m_collide;
163 		int							m_clusterIndex;
164 };
165 
166 
167 enum	btSoftJointBodyType
168 {
169 	BT_JOINT_SOFT_BODY_CLUSTER=1,
170 	BT_JOINT_RIGID_BODY,
171 	BT_JOINT_COLLISION_OBJECT
172 };
173 
174 struct	btSoftBodyJointData
175 {
176 	void						*m_bodyA;
177 	void						*m_bodyB;
178 	btVector3FloatData			m_refs[2];
179 	float						m_cfm;
180 	float						m_erp;
181 	float						m_split;
182 	int							m_delete;
183 	btVector3FloatData			m_relPosition[2];//linear
184 	int							m_bodyAtype;
185 	int							m_bodyBtype;
186 	int							m_jointType;
187 	int							m_pad;
188 };
189 
190 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
191 struct	btSoftBodyFloatData
192 {
193 	btCollisionObjectFloatData	m_collisionObjectData;
194 
195 	SoftBodyPoseData		*m_pose;
196 	SoftBodyMaterialData	**m_materials;
197 	SoftBodyNodeData		*m_nodes;
198 	SoftBodyLinkData		*m_links;
199 	SoftBodyFaceData		*m_faces;
200 	SoftBodyTetraData		*m_tetrahedra;
201 	SoftRigidAnchorData		*m_anchors;
202 	SoftBodyClusterData		*m_clusters;
203 	btSoftBodyJointData		*m_joints;
204 
205 	int						m_numMaterials;
206 	int						m_numNodes;
207 	int						m_numLinks;
208 	int						m_numFaces;
209 	int						m_numTetrahedra;
210 	int						m_numAnchors;
211 	int						m_numClusters;
212 	int						m_numJoints;
213 	SoftBodyConfigData		m_config;
214 };
215 
216 #endif //BT_SOFTBODY_FLOAT_DATA
217 
218