2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2013 Blender Foundation
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): Joshua Leung, Sergej Reich
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file DNA_rigidbody_types.h
30 * \brief Types and defines for representing Rigid Body entities
33 #ifndef __DNA_RIGIDBODY_TYPES_H__
34 #define __DNA_RIGIDBODY_TYPES_H__
36 #include "DNA_listBase.h"
40 struct EffectorWeights;
42 /* ******************************** */
45 /* RigidBodyWorld (rbw)
47 * Represents a "simulation scene" existing within the parent scene.
49 typedef struct RigidBodyWorld {
50 /* Sim World Settings ------------------------------------------------------------- */
51 struct EffectorWeights *effector_weights; /* effectors info */
53 struct Group *group; /* Group containing objects to use for Rigid Bodies */
54 struct Object **objects; /* Array to access group objects by index, only used at runtime */
56 struct Group *constraints; /* Group containing objects to use for Rigid Body Constraints*/
59 float ltime; /* last frame world was evaluated for (internal) */
62 struct PointCache *pointcache;
63 struct ListBase ptcaches;
64 int numbodies; /* number of objects in rigid body group */
66 short steps_per_second; /* number of simulation steps thaken per second */
67 short num_solver_iterations;/* number of constraint solver iterations made per simulation step */
69 int flag; /* (eRigidBodyWorld_Flag) settings for this RigidBodyWorld */
70 float time_scale; /* used to speed up or slow down the simulation */
72 /* References to Physics Sim objects. Exist at runtime only ---------------------- */
73 void *physics_world; /* Physics sim world (i.e. btDiscreteDynamicsWorld) */
76 /* Flags for RigidBodyWorld */
77 typedef enum eRigidBodyWorld_Flag {
78 /* should sim world be skipped when evaluating (user setting) */
79 RBW_FLAG_MUTED = (1 << 0),
80 /* sim data needs to be rebuilt */
81 RBW_FLAG_NEEDS_REBUILD = (1 << 1),
82 /* usse split impulse when stepping the simulation */
83 RBW_FLAG_USE_SPLIT_IMPULSE = (1 << 2)
84 } eRigidBodyWorld_Flag;
86 /* ******************************** */
87 /* RigidBody Object */
89 /* RigidBodyObject (rbo)
91 * Represents an object participating in a RigidBody sim.
92 * This is attached to each object that is currently
93 * participating in a sim.
95 typedef struct RigidBodyOb {
96 /* References to Physics Sim objects. Exist at runtime only */
97 void *physics_object; /* Physics object representation (i.e. btRigidBody) */
98 void *physics_shape; /* Collision shape used by physics sim (i.e. btCollisionShape) */
100 /* General Settings for this RigidBodyOb */
101 short type; /* (eRigidBodyOb_Type) role of RigidBody in sim */
102 short shape; /* (eRigidBody_Shape) collision shape to use */
104 int flag; /* (eRigidBodyOb_Flag) */
105 int col_groups; /* Collision groups that determines wich rigid bodies can collide with each other */
106 short mesh_source; /* (eRigidBody_MeshSource) mesh source for mesh based collision shapes */
109 /* Physics Parameters */
110 float mass; /* how much object 'weighs' (i.e. absolute 'amount of stuff' it holds) */
112 float friction; /* resistance of object to movement */
113 float restitution; /* how 'bouncy' object is when it collides */
115 float margin; /* tolerance for detecting collisions */
117 float lin_damping; /* damping for linear velocities */
118 float ang_damping; /* damping for angular velocities */
120 float lin_sleep_thresh; /* deactivation threshold for linear velocities */
121 float ang_sleep_thresh; /* deactivation threshold for angular velocities */
123 float orn[4]; /* rigid body orientation */
124 float pos[3]; /* rigid body position */
129 /* Participation types for RigidBodyOb */
130 typedef enum eRigidBodyOb_Type {
131 /* active geometry participant in simulation. is directly controlled by sim */
133 /* passive geometry participant in simulation. is directly controlled by animsys */
137 /* Flags for RigidBodyOb */
138 typedef enum eRigidBodyOb_Flag {
139 /* rigidbody is kinematic (controlled by the animation system) */
140 RBO_FLAG_KINEMATIC = (1 << 0),
141 /* rigidbody needs to be validated (usually set after duplicating and not hooked up yet) */
142 RBO_FLAG_NEEDS_VALIDATE = (1 << 1),
143 /* rigidbody shape needs refreshing (usually after exiting editmode) */
144 RBO_FLAG_NEEDS_RESHAPE = (1 << 2),
145 /* rigidbody can be deactivated */
146 RBO_FLAG_USE_DEACTIVATION = (1 << 3),
147 /* rigidbody is deactivated at the beginning of simulation */
148 RBO_FLAG_START_DEACTIVATED = (1 << 4),
149 /* rigidbody is not dynamically simulated */
150 RBO_FLAG_DISABLED = (1 << 5),
151 /* collision margin is not embedded (only used by convex hull shapes for now) */
152 RBO_FLAG_USE_MARGIN = (1 << 6)
155 /* RigidBody Collision Shape */
156 typedef enum eRigidBody_Shape {
157 /* simple box (i.e. bounding box) */
161 /* rounded "pill" shape (i.e. calcium tablets) */
163 /* cylinder (i.e. pringles can) */
165 /* cone (i.e. party hat) */
168 /* convex hull (minimal shrinkwrap encompassing all verts) */
170 /* triangulated mesh */
173 /* concave mesh approximated using primitives */
177 typedef enum eRigidBody_MeshSource {
180 /* only deformations */
182 /* final derived mesh */
184 } eRigidBody_MeshSource;
186 /* ******************************** */
187 /* RigidBody Constraint */
189 /* RigidBodyConstraint (rbc)
191 * Represents an constraint connecting two rigid bodies.
193 typedef struct RigidBodyCon {
194 struct Object *ob1; /* First object influenced by the constraint */
195 struct Object *ob2; /* Second object influenced by the constraint */
197 /* General Settings for this RigidBodyCon */
198 short type; /* (eRigidBodyCon_Type) role of RigidBody in sim */
199 short num_solver_iterations;/* number of constraint solver iterations made per simulation step */
201 int flag; /* (eRigidBodyCon_Flag) */
203 float breaking_threshold; /* breaking impulse threshold */
207 /* translation limits */
208 float limit_lin_x_lower;
209 float limit_lin_x_upper;
210 float limit_lin_y_lower;
211 float limit_lin_y_upper;
212 float limit_lin_z_lower;
213 float limit_lin_z_upper;
214 /* rotation limits */
215 float limit_ang_x_lower;
216 float limit_ang_x_upper;
217 float limit_ang_y_lower;
218 float limit_ang_y_upper;
219 float limit_ang_z_lower;
220 float limit_ang_z_upper;
222 /* spring settings */
223 /* resistance to deformation */
224 float spring_stiffness_x;
225 float spring_stiffness_y;
226 float spring_stiffness_z;
227 /* amount of velocity lost over time */
228 float spring_damping_x;
229 float spring_damping_y;
230 float spring_damping_z;
233 float motor_lin_target_velocity; /* linear velocity the motor tries to hold */
234 float motor_ang_target_velocity; /* angular velocity the motor tries to hold */
235 float motor_lin_max_impulse; /* maximum force used to reach linear target velocity */
236 float motor_ang_max_impulse; /* maximum force used to reach angular target velocity */
238 /* References to Physics Sim object. Exist at runtime only */
239 void *physics_constraint; /* Physics object representation (i.e. btTypedConstraint) */
243 /* Participation types for RigidBodyOb */
244 typedef enum eRigidBodyCon_Type {
245 /* lets bodies rotate around a specified point */
247 /* lets bodies rotate around a specified axis */
249 /* simulates wheel suspension */
251 /* restricts movent to a specified axis */
253 /* lets object rotate within a cpecified cone */
255 /* allows user to specify constraint axes */
257 /* like 6DOF but has springs */
258 RBC_TYPE_6DOF_SPRING,
259 /* simulates a universal joint */
261 /* glues two bodies together */
263 /* similar to slider but also allows rotation around slider axis */
265 /* Simplified spring constraint with only once axis that's automatically placed between the connected bodies */
267 /* dirves bodies by applying linear and angular forces */
269 } eRigidBodyCon_Type;
271 /* Flags for RigidBodyCon */
272 typedef enum eRigidBodyCon_Flag {
273 /* constraint influences rigid body motion */
274 RBC_FLAG_ENABLED = (1 << 0),
275 /* constraint needs to be validated */
276 RBC_FLAG_NEEDS_VALIDATE = (1 << 1),
277 /* allow constrained bodies to collide */
278 RBC_FLAG_DISABLE_COLLISIONS = (1 << 2),
279 /* constraint can break */
280 RBC_FLAG_USE_BREAKING = (1 << 3),
281 /* constraint use custom number of constraint solver iterations */
282 RBC_FLAG_OVERRIDE_SOLVER_ITERATIONS = (1 << 4),
284 RBC_FLAG_USE_LIMIT_LIN_X = (1 << 5),
285 RBC_FLAG_USE_LIMIT_LIN_Y = (1 << 6),
286 RBC_FLAG_USE_LIMIT_LIN_Z = (1 << 7),
287 RBC_FLAG_USE_LIMIT_ANG_X = (1 << 8),
288 RBC_FLAG_USE_LIMIT_ANG_Y = (1 << 9),
289 RBC_FLAG_USE_LIMIT_ANG_Z = (1 << 10),
291 RBC_FLAG_USE_SPRING_X = (1 << 11),
292 RBC_FLAG_USE_SPRING_Y = (1 << 12),
293 RBC_FLAG_USE_SPRING_Z = (1 << 13),
295 RBC_FLAG_USE_MOTOR_LIN = (1 << 14),
296 RBC_FLAG_USE_MOTOR_ANG = (1 << 15)
297 } eRigidBodyCon_Flag;
299 /* ******************************** */
301 #endif /* __DNA_RIGIDBODY_TYPES_H__ */