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 */
108 /* Physics Parameters */
109 float mass; /* how much object 'weighs' (i.e. absolute 'amount of stuff' it holds) */
111 float friction; /* resistance of object to movement */
112 float restitution; /* how 'bouncy' object is when it collides */
114 float margin; /* tolerance for detecting collisions */
116 float lin_damping; /* damping for linear velocities */
117 float ang_damping; /* damping for angular velocities */
119 float lin_sleep_thresh; /* deactivation threshold for linear velocities */
120 float ang_sleep_thresh; /* deactivation threshold for angular velocities */
122 float orn[4]; /* rigid body orientation */
123 float pos[3]; /* rigid body position */
128 /* Participation types for RigidBodyOb */
129 typedef enum eRigidBodyOb_Type {
130 /* active geometry participant in simulation. is directly controlled by sim */
132 /* passive geometry participant in simulation. is directly controlled by animsys */
136 /* Flags for RigidBodyOb */
137 typedef enum eRigidBodyOb_Flag {
138 /* rigidbody is kinematic (controlled by the animation system) */
139 RBO_FLAG_KINEMATIC = (1 << 0),
140 /* rigidbody needs to be validated (usually set after duplicating and not hooked up yet) */
141 RBO_FLAG_NEEDS_VALIDATE = (1 << 1),
142 /* rigidbody shape needs refreshing (usually after exiting editmode) */
143 RBO_FLAG_NEEDS_RESHAPE = (1 << 2),
144 /* rigidbody can be deactivated */
145 RBO_FLAG_USE_DEACTIVATION = (1 << 3),
146 /* rigidbody is deactivated at the beginning of simulation */
147 RBO_FLAG_START_DEACTIVATED = (1 << 4),
148 /* rigidbody is not dynamically simulated */
149 RBO_FLAG_DISABLED = (1 << 5),
150 /* collision margin is not embedded (only used by convex hull shapes for now) */
151 RBO_FLAG_USE_MARGIN = (1 << 6)
154 /* RigidBody Collision Shape */
155 typedef enum eRigidBody_Shape {
156 /* simple box (i.e. bounding box) */
160 /* rounded "pill" shape (i.e. calcium tablets) */
162 /* cylinder (i.e. pringles can) */
164 /* cone (i.e. party hat) */
167 /* convex hull (minimal shrinkwrap encompassing all verts) */
169 /* triangulated mesh */
172 /* concave mesh approximated using primitives */
176 /* ******************************** */
177 /* RigidBody Constraint */
179 /* RigidBodyConstraint (rbc)
181 * Represents an constraint connecting two rigid bodies.
183 typedef struct RigidBodyCon {
184 struct Object *ob1; /* First object influenced by the constraint */
185 struct Object *ob2; /* Second object influenced by the constraint */
187 /* General Settings for this RigidBodyCon */
188 short type; /* (eRigidBodyCon_Type) role of RigidBody in sim */
189 short num_solver_iterations;/* number of constraint solver iterations made per simulation step */
191 int flag; /* (eRigidBodyCon_Flag) */
193 float breaking_threshold; /* breaking impulse threshold */
197 float limit_lin_x_lower; /* lower limit for x axis translation */
198 float limit_lin_x_upper; /* upper limit for x axis translation */
199 float limit_lin_y_lower; /* lower limit for y axis translation */
200 float limit_lin_y_upper; /* upper limit for y axis translation */
201 float limit_lin_z_lower; /* lower limit for z axis translation */
202 float limit_lin_z_upper; /* upper limit for z axis translation */
203 float limit_ang_x_lower; /* lower limit for x axis rotation */
204 float limit_ang_x_upper; /* upper limit for x axis rotation */
205 float limit_ang_y_lower; /* lower limit for y axis rotation */
206 float limit_ang_y_upper; /* upper limit for y axis rotation */
207 float limit_ang_z_lower; /* lower limit for z axis rotation */
208 float limit_ang_z_upper; /* upper limit for z axis rotation */
210 /* spring settings */
211 /* RB_TODO document spring properties */
212 float spring_stiffness_x;
213 float spring_stiffness_y;
214 float spring_stiffness_z;
215 float spring_damping_x;
216 float spring_damping_y;
217 float spring_damping_z;
219 /* References to Physics Sim object. Exist at runtime only */
220 void *physics_constraint; /* Physics object representation (i.e. btTypedConstraint) */
224 /* Participation types for RigidBodyOb */
225 typedef enum eRigidBodyCon_Type {
226 /* lets bodies rotate around a specified point */
228 /* lets bodies rotate around a specified axis */
230 /* simulates wheel suspension */
232 /* restricts movent to a specified axis */
234 /* lets object rotate within a cpecified cone */
236 /* allows user to specify constraint axes */
238 /* like 6DOF but has springs */
239 RBC_TYPE_6DOF_SPRING,
240 /* simulates a universal joint */
242 /* glues two bodies together */
244 /* similar to slider but also allows rotation around slider axis */
246 /* Simplified spring constraint with only once axis that's automatically placed between the connected bodies */
248 } eRigidBodyCon_Type;
250 /* Flags for RigidBodyCon */
251 typedef enum eRigidBodyCon_Flag {
252 /* constraint influences rigid body motion */
253 RBC_FLAG_ENABLED = (1 << 0),
254 /* constraint needs to be validated */
255 RBC_FLAG_NEEDS_VALIDATE = (1 << 1),
256 /* allow constrained bodies to collide */
257 RBC_FLAG_DISABLE_COLLISIONS = (1 << 2),
258 /* constraint can break */
259 RBC_FLAG_USE_BREAKING = (1 << 3),
260 /* constraint use custom number of constraint solver iterations */
261 RBC_FLAG_OVERRIDE_SOLVER_ITERATIONS = (1 << 4),
263 RBC_FLAG_USE_LIMIT_LIN_X = (1 << 5),
264 RBC_FLAG_USE_LIMIT_LIN_Y = (1 << 6),
265 RBC_FLAG_USE_LIMIT_LIN_Z = (1 << 7),
266 RBC_FLAG_USE_LIMIT_ANG_X = (1 << 8),
267 RBC_FLAG_USE_LIMIT_ANG_Y = (1 << 9),
268 RBC_FLAG_USE_LIMIT_ANG_Z = (1 << 10),
270 RBC_FLAG_USE_SPRING_X = (1 << 11),
271 RBC_FLAG_USE_SPRING_Y = (1 << 12),
272 RBC_FLAG_USE_SPRING_Z = (1 << 13)
273 } eRigidBodyCon_Flag;
275 /* ******************************** */
277 #endif /* __DNA_RIGIDBODY_TYPES_H__ */