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 * Contributor(s): Blender Foundation 2013, Joshua Leung, Sergej Reich
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file rna_rigidbody.c
25 * \brief RNA property definitions for Rigid Body datatypes
31 #include "RNA_define.h"
32 #include "RNA_enum_types.h"
34 #include "rna_internal.h"
36 #include "DNA_group_types.h"
37 #include "DNA_object_types.h"
38 #include "DNA_rigidbody_types.h"
39 #include "DNA_scene_types.h"
41 #include "BLI_utildefines.h"
46 /* roles of objects in RigidBody Sims */
47 EnumPropertyItem rigidbody_object_type_items[] = {
48 {RBO_TYPE_ACTIVE, "ACTIVE", 0, "Active", "Object is directly controlled by simulation results"},
49 {RBO_TYPE_PASSIVE, "PASSIVE", 0, "Passive", "Object is directly controlled by animation system"},
50 {0, NULL, 0, NULL, NULL}};
52 /* collision shapes of objects in rigid body sim */
53 EnumPropertyItem rigidbody_object_shape_items[] = {
54 {RB_SHAPE_BOX, "BOX", ICON_MESH_CUBE, "Box", "Box-like shapes (i.e. cubes), including planes (i.e. ground planes)"},
55 {RB_SHAPE_SPHERE, "SPHERE", ICON_MESH_UVSPHERE, "Sphere", ""},
56 {RB_SHAPE_CAPSULE, "CAPSULE", ICON_OUTLINER_OB_META, "Capsule", ""},
57 {RB_SHAPE_CYLINDER, "CYLINDER", ICON_MESH_CYLINDER, "Cylinder", ""},
58 {RB_SHAPE_CONE, "CONE", ICON_MESH_CONE, "Cone", ""},
59 {RB_SHAPE_CONVEXH, "CONVEX_HULL", ICON_MESH_ICOSPHERE, "Convex Hull",
60 "A mesh-like surface encompassing (i.e. shrinkwrap over) all vertices (best results with "
62 {RB_SHAPE_TRIMESH, "MESH", ICON_MESH_MONKEY, "Mesh",
63 "Mesh consisting of triangles only, allowing for more detailed interactions than convex hulls"},
64 {0, NULL, 0, NULL, NULL}};
66 /* collision shapes of constraints in rigid body sim */
67 EnumPropertyItem rigidbody_constraint_type_items[] = {
68 {RBC_TYPE_FIXED, "FIXED", ICON_NONE, "Fixed", "Glue rigid bodies together"},
69 {RBC_TYPE_POINT, "POINT", ICON_NONE, "Point", "Constrain rigid bodies to move around common pivot point"},
70 {RBC_TYPE_HINGE, "HINGE", ICON_NONE, "Hinge", "Restrict rigid body rotation to one axis"},
71 {RBC_TYPE_SLIDER, "SLIDER", ICON_NONE, "Slider", "Restrict rigid body translation to one axis"},
72 {RBC_TYPE_PISTON, "PISTON", ICON_NONE, "Piston", "Restrict rigid body translation and rotation to one axis"},
73 {RBC_TYPE_6DOF, "GENERIC", ICON_NONE, "Generic", "Restrict translation and rotation to specified axes"},
74 {RBC_TYPE_6DOF_SPRING, "GENERIC_SPRING", ICON_NONE, "Generic Spring",
75 "Restrict translation and rotation to specified axes with springs"},
76 {RBC_TYPE_MOTOR, "MOTOR", ICON_NONE, "Motor", "Drive rigid body around or along an axis"},
77 {0, NULL, 0, NULL, NULL}};
79 /* mesh source for collision shape creation */
80 EnumPropertyItem rigidbody_mesh_source_items[] = {
81 {RBO_MESH_BASE, "BASE", 0, "Base", "Base mesh"},
82 {RBO_MESH_DEFORM, "DEFORM", 0, "Deform", "Deformations (shaps keys, deform modifiers"},
83 {RBO_MESH_FINAL, "FINAL", 0, "Final", "All modifiers"},
84 {0, NULL, 0, NULL, NULL}};
93 #include "BKE_depsgraph.h"
94 #include "BKE_rigidbody.h"
96 #define RB_FLAG_SET(dest, value, flag) { \
104 /* ******************************** */
106 static void rna_RigidBodyWorld_reset(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
108 RigidBodyWorld *rbw = (RigidBodyWorld *)ptr->data;
110 BKE_rigidbody_cache_reset(rbw);
113 static char *rna_RigidBodyWorld_path(PointerRNA *UNUSED(ptr))
115 return BLI_sprintfN("rigidbody_world");
118 static void rna_RigidBodyWorld_num_solver_iterations_set(PointerRNA *ptr, int value)
120 RigidBodyWorld *rbw = (RigidBodyWorld *)ptr->data;
122 rbw->num_solver_iterations = value;
125 if (rbw->physics_world) {
126 RB_dworld_set_solver_iterations(rbw->physics_world, value);
131 static void rna_RigidBodyWorld_split_impulse_set(PointerRNA *ptr, int value)
133 RigidBodyWorld *rbw = (RigidBodyWorld *)ptr->data;
135 RB_FLAG_SET(rbw->flag, value, RBW_FLAG_USE_SPLIT_IMPULSE);
138 if (rbw->physics_world) {
139 RB_dworld_set_split_impulse(rbw->physics_world, value);
144 /* ******************************** */
146 static void rna_RigidBodyOb_reset(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
148 RigidBodyWorld *rbw = scene->rigidbody_world;
150 BKE_rigidbody_cache_reset(rbw);
153 static void rna_RigidBodyOb_shape_reset(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
155 RigidBodyWorld *rbw = scene->rigidbody_world;
156 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
158 BKE_rigidbody_cache_reset(rbw);
159 if (rbo->physics_shape)
160 rbo->flag |= RBO_FLAG_NEEDS_RESHAPE;
163 static char *rna_RigidBodyOb_path(PointerRNA *UNUSED(ptr))
165 /* NOTE: this hardcoded path should work as long as only Objects have this */
166 return BLI_sprintfN("rigid_body");
169 static void rna_RigidBodyOb_type_set(PointerRNA *ptr, int value)
171 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
174 rbo->flag |= RBO_FLAG_NEEDS_VALIDATE;
177 static void rna_RigidBodyOb_shape_set(PointerRNA *ptr, int value)
179 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
182 rbo->flag |= RBO_FLAG_NEEDS_VALIDATE;
185 static void rna_RigidBodyOb_disabled_set(PointerRNA *ptr, int value)
187 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
189 RB_FLAG_SET(rbo->flag, !value, RBO_FLAG_DISABLED);
192 /* update kinematic state if necessary - only needed for active bodies */
193 if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE)) {
194 RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
195 RB_body_set_kinematic_state(rbo->physics_object, !value);
196 rbo->flag |= RBO_FLAG_NEEDS_VALIDATE;
201 static void rna_RigidBodyOb_mass_set(PointerRNA *ptr, float value)
203 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
208 /* only active bodies need mass update */
209 if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE)) {
210 RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
215 static void rna_RigidBodyOb_friction_set(PointerRNA *ptr, float value)
217 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
219 rbo->friction = value;
222 if (rbo->physics_object) {
223 RB_body_set_friction(rbo->physics_object, value);
228 static void rna_RigidBodyOb_restitution_set(PointerRNA *ptr, float value)
230 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
232 rbo->restitution = value;
234 if (rbo->physics_object) {
235 RB_body_set_restitution(rbo->physics_object, value);
240 static void rna_RigidBodyOb_collision_margin_set(PointerRNA *ptr, float value)
242 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
247 if (rbo->physics_shape) {
248 RB_shape_set_margin(rbo->physics_shape, RBO_GET_MARGIN(rbo));
253 static void rna_RigidBodyOb_collision_groups_set(PointerRNA *ptr, const int *values)
255 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
258 for (i = 0; i < 20; i++) {
260 rbo->col_groups |= (1 << i);
262 rbo->col_groups &= ~(1 << i);
264 rbo->flag |= RBO_FLAG_NEEDS_VALIDATE;
267 static void rna_RigidBodyOb_kinematic_state_set(PointerRNA *ptr, int value)
269 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
271 RB_FLAG_SET(rbo->flag, value, RBO_FLAG_KINEMATIC);
274 /* update kinematic state if necessary */
275 if (rbo->physics_object) {
276 RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
277 RB_body_set_kinematic_state(rbo->physics_object, value);
278 rbo->flag |= RBO_FLAG_NEEDS_VALIDATE;
283 static void rna_RigidBodyOb_activation_state_set(PointerRNA *ptr, int value)
285 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
287 RB_FLAG_SET(rbo->flag, value, RBO_FLAG_USE_DEACTIVATION);
290 /* update activation state if necessary - only active bodies can be deactivated */
291 if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE)) {
292 RB_body_set_activation_state(rbo->physics_object, value);
297 static void rna_RigidBodyOb_linear_sleepThresh_set(PointerRNA *ptr, float value)
299 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
301 rbo->lin_sleep_thresh = value;
304 /* only active bodies need sleep threshold update */
305 if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE)) {
306 RB_body_set_linear_sleep_thresh(rbo->physics_object, value);
311 static void rna_RigidBodyOb_angular_sleepThresh_set(PointerRNA *ptr, float value)
313 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
315 rbo->ang_sleep_thresh = value;
318 /* only active bodies need sleep threshold update */
319 if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE)) {
320 RB_body_set_angular_sleep_thresh(rbo->physics_object, value);
325 static void rna_RigidBodyOb_linear_damping_set(PointerRNA *ptr, float value)
327 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
329 rbo->lin_damping = value;
332 /* only active bodies need damping update */
333 if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE)) {
334 RB_body_set_linear_damping(rbo->physics_object, value);
339 static void rna_RigidBodyOb_angular_damping_set(PointerRNA *ptr, float value)
341 RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
343 rbo->ang_damping = value;
346 /* only active bodies need damping update */
347 if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE)) {
348 RB_body_set_angular_damping(rbo->physics_object, value);
353 static char *rna_RigidBodyCon_path(PointerRNA *UNUSED(ptr))
355 /* NOTE: this hardcoded path should work as long as only Objects have this */
356 return BLI_sprintfN("rigid_body_constraint");
359 static void rna_RigidBodyCon_type_set(PointerRNA *ptr, int value)
361 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
364 rbc->flag |= RBC_FLAG_NEEDS_VALIDATE;
367 static void rna_RigidBodyCon_enabled_set(PointerRNA *ptr, int value)
369 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
371 RB_FLAG_SET(rbc->flag, value, RBC_FLAG_ENABLED);
374 if (rbc->physics_constraint) {
375 RB_constraint_set_enabled(rbc->physics_constraint, value);
380 static void rna_RigidBodyCon_disable_collisions_set(PointerRNA *ptr, int value)
382 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
384 RB_FLAG_SET(rbc->flag, value, RBC_FLAG_DISABLE_COLLISIONS);
386 rbc->flag |= RBC_FLAG_NEEDS_VALIDATE;
389 static void rna_RigidBodyCon_use_breaking_set(PointerRNA *ptr, int value)
391 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
394 rbc->flag |= RBC_FLAG_USE_BREAKING;
396 if (rbc->physics_constraint) {
397 RB_constraint_set_breaking_threshold(rbc->physics_constraint, rbc->breaking_threshold);
402 rbc->flag &= ~RBC_FLAG_USE_BREAKING;
404 if (rbc->physics_constraint) {
405 RB_constraint_set_breaking_threshold(rbc->physics_constraint, FLT_MAX);
411 static void rna_RigidBodyCon_breaking_threshold_set(PointerRNA *ptr, float value)
413 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
415 rbc->breaking_threshold = value;
418 if (rbc->physics_constraint && (rbc->flag & RBC_FLAG_USE_BREAKING)) {
419 RB_constraint_set_breaking_threshold(rbc->physics_constraint, value);
424 static void rna_RigidBodyCon_override_solver_iterations_set(PointerRNA *ptr, int value)
426 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
429 rbc->flag |= RBC_FLAG_OVERRIDE_SOLVER_ITERATIONS;
431 if (rbc->physics_constraint) {
432 RB_constraint_set_solver_iterations(rbc->physics_constraint, rbc->num_solver_iterations);
437 rbc->flag &= ~RBC_FLAG_OVERRIDE_SOLVER_ITERATIONS;
439 if (rbc->physics_constraint) {
440 RB_constraint_set_solver_iterations(rbc->physics_constraint, -1);
446 static void rna_RigidBodyCon_num_solver_iterations_set(PointerRNA *ptr, int value)
448 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
450 rbc->num_solver_iterations = value;
453 if (rbc->physics_constraint && (rbc->flag & RBC_FLAG_OVERRIDE_SOLVER_ITERATIONS)) {
454 RB_constraint_set_solver_iterations(rbc->physics_constraint, value);
459 static void rna_RigidBodyCon_spring_stiffness_x_set(PointerRNA *ptr, float value)
461 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
463 rbc->spring_stiffness_x = value;
466 if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_X)) {
467 RB_constraint_set_stiffness_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_X, value);
472 static void rna_RigidBodyCon_spring_stiffness_y_set(PointerRNA *ptr, float value)
474 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
476 rbc->spring_stiffness_y = value;
479 if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_Y)) {
480 RB_constraint_set_stiffness_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Y, value);
485 static void rna_RigidBodyCon_spring_stiffness_z_set(PointerRNA *ptr, float value)
487 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
489 rbc->spring_stiffness_z = value;
492 if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_Z)) {
493 RB_constraint_set_stiffness_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Z, value);
498 static void rna_RigidBodyCon_spring_damping_x_set(PointerRNA *ptr, float value)
500 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
502 rbc->spring_damping_x = value;
505 if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_X)) {
506 RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_X, value);
511 static void rna_RigidBodyCon_spring_damping_y_set(PointerRNA *ptr, float value)
513 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
515 rbc->spring_damping_y = value;
517 if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_Y)) {
518 RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Y, value);
523 static void rna_RigidBodyCon_spring_damping_z_set(PointerRNA *ptr, float value)
525 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
527 rbc->spring_damping_z = value;
529 if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_Z)) {
530 RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Z, value);
535 static void rna_RigidBodyCon_motor_lin_max_impulse_set(PointerRNA *ptr, float value)
537 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
539 rbc->motor_lin_max_impulse = value;
542 if (rbc->physics_constraint && rbc->type == RBC_TYPE_MOTOR) {
543 RB_constraint_set_max_impulse_motor(rbc->physics_constraint, value, rbc->motor_ang_max_impulse);
548 static void rna_RigidBodyCon_use_motor_lin_set(PointerRNA *ptr, int value)
550 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
552 RB_FLAG_SET(rbc->flag, value, RBC_FLAG_USE_MOTOR_LIN);
555 if (rbc->physics_constraint) {
556 RB_constraint_set_enable_motor(rbc->physics_constraint, rbc->flag & RBC_FLAG_USE_MOTOR_LIN, rbc->flag & RBC_FLAG_USE_MOTOR_ANG);
561 static void rna_RigidBodyCon_use_motor_ang_set(PointerRNA *ptr, int value)
563 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
565 RB_FLAG_SET(rbc->flag, value, RBC_FLAG_USE_MOTOR_ANG);
568 if (rbc->physics_constraint) {
569 RB_constraint_set_enable_motor(rbc->physics_constraint, rbc->flag & RBC_FLAG_USE_MOTOR_LIN, rbc->flag & RBC_FLAG_USE_MOTOR_ANG);
574 static void rna_RigidBodyCon_motor_lin_target_velocity_set(PointerRNA *ptr, float value)
576 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
578 rbc->motor_lin_target_velocity = value;
581 if (rbc->physics_constraint && rbc->type == RBC_TYPE_MOTOR) {
582 RB_constraint_set_target_velocity_motor(rbc->physics_constraint, value, rbc->motor_ang_target_velocity);
587 static void rna_RigidBodyCon_motor_ang_max_impulse_set(PointerRNA *ptr, float value)
589 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
591 rbc->motor_ang_max_impulse = value;
594 if (rbc->physics_constraint && rbc->type == RBC_TYPE_MOTOR) {
595 RB_constraint_set_max_impulse_motor(rbc->physics_constraint, rbc->motor_lin_max_impulse, value);
600 static void rna_RigidBodyCon_motor_ang_target_velocity_set(PointerRNA *ptr, float value)
602 RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
604 rbc->motor_ang_target_velocity = value;
607 if (rbc->physics_constraint && rbc->type == RBC_TYPE_MOTOR) {
608 RB_constraint_set_target_velocity_motor(rbc->physics_constraint, rbc->motor_lin_target_velocity, value);
614 static void rna_RigidBodyWorld_convex_sweep_test(
615 RigidBodyWorld *rbw, ReportList *reports,
616 Object *object, float ray_start[3], float ray_end[3],
617 float r_location[3], float r_hitpoint[3], float r_normal[3], int *r_hit)
620 RigidBodyOb *rob = object->rigidbody_object;
622 if (rbw->physics_world != NULL && rob->physics_object != NULL) {
623 RB_world_convex_sweep_test(rbw->physics_world, rob->physics_object, ray_start, ray_end,
624 r_location, r_hitpoint, r_normal, r_hit);
626 BKE_report(reports, RPT_ERROR,
627 "A non convex collision shape was passed to the function, use only convex collision shapes");
632 BKE_report(reports, RPT_ERROR, "Rigidbody world was not properly initialized, need to step the simulation first");
635 (void)rbw, (void)reports, (void)object, (void)ray_start, (void)ray_end;
636 (void)r_location, (void)r_hitpoint, (void)r_normal, (void)r_hit;
642 static void rna_def_rigidbody_world(BlenderRNA *brna)
648 srna = RNA_def_struct(brna, "RigidBodyWorld", NULL);
649 RNA_def_struct_sdna(srna, "RigidBodyWorld");
650 RNA_def_struct_ui_text(srna, "Rigid Body World", "Self-contained rigid body simulation environment and settings");
651 RNA_def_struct_path_func(srna, "rna_RigidBodyWorld_path");
654 prop = RNA_def_property(srna, "group", PROP_POINTER, PROP_NONE);
655 RNA_def_property_struct_type(prop, "Group");
656 RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
657 RNA_def_property_ui_text(prop, "Group", "Group containing objects participating in this simulation");
658 RNA_def_property_update(prop, NC_SCENE, "rna_RigidBodyWorld_reset");
660 prop = RNA_def_property(srna, "constraints", PROP_POINTER, PROP_NONE);
661 RNA_def_property_struct_type(prop, "Group");
662 RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
663 RNA_def_property_ui_text(prop, "Constraints", "Group containing rigid body constraint objects");
664 RNA_def_property_update(prop, NC_SCENE, "rna_RigidBodyWorld_reset");
667 prop = RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
668 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", RBW_FLAG_MUTED);
669 RNA_def_property_ui_text(prop, "Enabled", "Simulation will be evaluated");
670 RNA_def_property_update(prop, NC_SCENE, NULL);
673 prop = RNA_def_property(srna, "time_scale", PROP_FLOAT, PROP_NONE);
674 RNA_def_property_float_sdna(prop, NULL, "time_scale");
675 RNA_def_property_range(prop, 0.0f, 100.0f);
676 RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
677 RNA_def_property_float_default(prop, 1.0f);
678 RNA_def_property_ui_text(prop, "Time Scale", "Change the speed of the simulation");
679 RNA_def_property_update(prop, NC_SCENE, "rna_RigidBodyWorld_reset");
682 prop = RNA_def_property(srna, "steps_per_second", PROP_INT, PROP_NONE);
683 RNA_def_property_int_sdna(prop, NULL, "steps_per_second");
684 RNA_def_property_range(prop, 1, SHRT_MAX);
685 RNA_def_property_ui_range(prop, 60, 1000, 1, -1);
686 RNA_def_property_int_default(prop, 60);
687 RNA_def_property_ui_text(prop, "Steps Per Second",
688 "Number of simulation steps taken per second (higher values are more accurate "
690 RNA_def_property_update(prop, NC_SCENE, "rna_RigidBodyWorld_reset");
692 /* constraint solver iterations */
693 prop = RNA_def_property(srna, "solver_iterations", PROP_INT, PROP_NONE);
694 RNA_def_property_int_sdna(prop, NULL, "num_solver_iterations");
695 RNA_def_property_range(prop, 1, 1000);
696 RNA_def_property_ui_range(prop, 10, 100, 1, -1);
697 RNA_def_property_int_default(prop, 10);
698 RNA_def_property_int_funcs(prop, NULL, "rna_RigidBodyWorld_num_solver_iterations_set", NULL);
699 RNA_def_property_ui_text(prop, "Solver Iterations",
700 "Number of constraint solver iterations made per simulation step (higher values are more "
701 "accurate but slower)");
702 RNA_def_property_update(prop, NC_SCENE, "rna_RigidBodyWorld_reset");
705 prop = RNA_def_property(srna, "use_split_impulse", PROP_BOOLEAN, PROP_NONE);
706 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBW_FLAG_USE_SPLIT_IMPULSE);
707 RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyWorld_split_impulse_set");
708 RNA_def_property_ui_text(prop, "Split Impulse",
709 "Reduce extra velocity that can build up when objects collide (lowers simulation "
710 "stability a little so use only when necessary)");
711 RNA_def_property_update(prop, NC_SCENE, "rna_RigidBodyWorld_reset");
714 prop = RNA_def_property(srna, "point_cache", PROP_POINTER, PROP_NONE);
715 RNA_def_property_flag(prop, PROP_NEVER_NULL);
716 RNA_def_property_pointer_sdna(prop, NULL, "pointcache");
717 RNA_def_property_ui_text(prop, "Point Cache", "");
719 /* effector weights */
720 prop = RNA_def_property(srna, "effector_weights", PROP_POINTER, PROP_NONE);
721 RNA_def_property_struct_type(prop, "EffectorWeights");
722 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
723 RNA_def_property_ui_text(prop, "Effector Weights", "");
726 func = RNA_def_function(srna, "convex_sweep_test", "rna_RigidBodyWorld_convex_sweep_test");
727 RNA_def_function_ui_description(func, "Sweep test convex rigidbody against the current rigidbody world");
728 RNA_def_function_flag(func, FUNC_USE_REPORTS);
730 prop = RNA_def_pointer(func, "object", "Object", "", "Rigidbody object with a convex collision shape");
731 RNA_def_property_flag(prop, PROP_REQUIRED | PROP_NEVER_NULL);
732 RNA_def_property_clear_flag(prop, PROP_THICK_WRAP);
734 /* ray start and end */
735 prop = RNA_def_float_vector(func, "start", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
736 RNA_def_property_flag(prop, PROP_REQUIRED);
737 prop = RNA_def_float_vector(func, "end", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
738 RNA_def_property_flag(prop, PROP_REQUIRED);
740 prop = RNA_def_float_vector(func, "object_location", 3, NULL, -FLT_MAX, FLT_MAX, "Location",
741 "The hit location of this sweep test", -1e4, 1e4);
742 RNA_def_property_flag(prop, PROP_THICK_WRAP);
743 RNA_def_function_output(func, prop);
745 prop = RNA_def_float_vector(func, "hitpoint", 3, NULL, -FLT_MAX, FLT_MAX, "Hitpoint",
746 "The hit location of this sweep test", -1e4, 1e4);
747 RNA_def_property_flag(prop, PROP_THICK_WRAP);
748 RNA_def_function_output(func, prop);
750 prop = RNA_def_float_vector(func, "normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal",
751 "The face normal at the sweep test hit location", -1e4, 1e4);
752 RNA_def_property_flag(prop, PROP_THICK_WRAP);
753 RNA_def_function_output(func, prop);
755 prop = RNA_def_int(func, "has_hit", 0, 0, 0, "", "If the function has found collision point, value is 1, otherwise 0", 0, 0);
756 RNA_def_function_output(func, prop);
759 static void rna_def_rigidbody_object(BlenderRNA *brna)
765 srna = RNA_def_struct(brna, "RigidBodyObject", NULL);
766 RNA_def_struct_sdna(srna, "RigidBodyOb");
767 RNA_def_struct_ui_text(srna, "Rigid Body Object", "Settings for object participating in Rigid Body Simulation");
768 RNA_def_struct_path_func(srna, "rna_RigidBodyOb_path");
771 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
772 RNA_def_property_enum_sdna(prop, NULL, "type");
773 RNA_def_property_enum_items(prop, rigidbody_object_type_items);
774 RNA_def_property_enum_funcs(prop, NULL, "rna_RigidBodyOb_type_set", NULL);
775 RNA_def_property_ui_text(prop, "Type", "Role of object in Rigid Body Simulations");
776 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
777 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
779 prop = RNA_def_property(srna, "mesh_source", PROP_ENUM, PROP_NONE);
780 RNA_def_property_enum_sdna(prop, NULL, "mesh_source");
781 RNA_def_property_enum_items(prop, rigidbody_mesh_source_items);
782 RNA_def_property_ui_text(prop, "Mesh Source", "Source of the mesh used to create collision shape");
783 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
784 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
787 prop = RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
788 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", RBO_FLAG_DISABLED);
789 RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyOb_disabled_set");
790 RNA_def_property_ui_text(prop, "Enabled", "Rigid Body actively participates to the simulation");
791 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
793 prop = RNA_def_property(srna, "collision_shape", PROP_ENUM, PROP_NONE);
794 RNA_def_property_enum_sdna(prop, NULL, "shape");
795 RNA_def_property_enum_items(prop, rigidbody_object_shape_items);
796 RNA_def_property_enum_funcs(prop, NULL, "rna_RigidBodyOb_shape_set", NULL);
797 RNA_def_property_ui_text(prop, "Collision Shape", "Collision Shape of object in Rigid Body Simulations");
798 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
799 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
801 prop = RNA_def_property(srna, "kinematic", PROP_BOOLEAN, PROP_NONE);
802 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBO_FLAG_KINEMATIC);
803 RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyOb_kinematic_state_set");
804 RNA_def_property_ui_text(prop, "Kinematic", "Allow rigid body to be controlled by the animation system");
805 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
807 prop = RNA_def_property(srna, "use_deform", PROP_BOOLEAN, PROP_NONE);
808 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBO_FLAG_USE_DEFORM);
809 RNA_def_property_ui_text(prop, "Deforming", "Rigid body deforms during simulation");
810 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
812 /* Physics Parameters */
813 prop = RNA_def_property(srna, "mass", PROP_FLOAT, PROP_UNIT_MASS);
814 RNA_def_property_float_sdna(prop, NULL, "mass");
815 RNA_def_property_range(prop, 0.001f, FLT_MAX); // range must always be positive (and non-zero)
816 RNA_def_property_float_default(prop, 1.0f);
817 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_mass_set", NULL);
818 RNA_def_property_ui_text(prop, "Mass", "How much the object 'weighs' irrespective of gravity");
819 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
821 /* Dynamics Parameters - Activation */
822 // TODO: define and figure out how to implement these
824 /* Dynamics Parameters - Deactivation */
825 prop = RNA_def_property(srna, "use_deactivation", PROP_BOOLEAN, PROP_NONE);
826 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBO_FLAG_USE_DEACTIVATION);
827 RNA_def_property_boolean_default(prop, TRUE);
828 RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyOb_activation_state_set");
829 RNA_def_property_ui_text(prop, "Enable Deactivation",
830 "Enable deactivation of resting rigid bodies (increases performance and stability "
831 "but can cause glitches)");
832 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
834 prop = RNA_def_property(srna, "use_start_deactivated", PROP_BOOLEAN, PROP_NONE);
835 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBO_FLAG_START_DEACTIVATED);
836 RNA_def_property_ui_text(prop, "Start Deactivated", "Deactivate rigid body at the start of the simulation");
837 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
838 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
840 prop = RNA_def_property(srna, "deactivate_linear_velocity", PROP_FLOAT, PROP_UNIT_VELOCITY);
841 RNA_def_property_float_sdna(prop, NULL, "lin_sleep_thresh");
842 RNA_def_property_range(prop, FLT_MIN, FLT_MAX); // range must always be positive (and non-zero)
843 RNA_def_property_float_default(prop, 0.4f);
844 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_linear_sleepThresh_set", NULL);
845 RNA_def_property_ui_text(prop, "Linear Velocity Deactivation Threshold",
846 "Linear Velocity below which simulation stops simulating object");
847 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
849 prop = RNA_def_property(srna, "deactivate_angular_velocity", PROP_FLOAT, PROP_UNIT_VELOCITY);
850 RNA_def_property_float_sdna(prop, NULL, "ang_sleep_thresh");
851 RNA_def_property_range(prop, FLT_MIN, FLT_MAX); // range must always be positive (and non-zero)
852 RNA_def_property_float_default(prop, 0.5f);
853 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_angular_sleepThresh_set", NULL);
854 RNA_def_property_ui_text(prop, "Angular Velocity Deactivation Threshold",
855 "Angular Velocity below which simulation stops simulating object");
856 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
858 /* Dynamics Parameters - Damping Parameters */
859 prop = RNA_def_property(srna, "linear_damping", PROP_FLOAT, PROP_FACTOR);
860 RNA_def_property_float_sdna(prop, NULL, "lin_damping");
861 RNA_def_property_range(prop, 0.0f, 1.0f);
862 RNA_def_property_float_default(prop, 0.04f);
863 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_linear_damping_set", NULL);
864 RNA_def_property_ui_text(prop, "Linear Damping", "Amount of linear velocity that is lost over time");
865 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
867 prop = RNA_def_property(srna, "angular_damping", PROP_FLOAT, PROP_FACTOR);
868 RNA_def_property_float_sdna(prop, NULL, "ang_damping");
869 RNA_def_property_range(prop, 0.0f, 1.0f);
870 RNA_def_property_float_default(prop, 0.1f);
871 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_angular_damping_set", NULL);
872 RNA_def_property_ui_text(prop, "Angular Damping", "Amount of angular velocity that is lost over time");
873 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
875 /* Collision Parameters - Surface Parameters */
876 prop = RNA_def_property(srna, "friction", PROP_FLOAT, PROP_FACTOR);
877 RNA_def_property_float_sdna(prop, NULL, "friction");
878 RNA_def_property_range(prop, 0.0f, FLT_MAX);
879 RNA_def_property_ui_range(prop, 0.0f, 1.0f, 1, 3);
880 RNA_def_property_float_default(prop, 0.5f);
881 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_friction_set", NULL);
882 RNA_def_property_ui_text(prop, "Friction", "Resistance of object to movement");
883 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
885 prop = RNA_def_property(srna, "restitution", PROP_FLOAT, PROP_FACTOR);
886 RNA_def_property_float_sdna(prop, NULL, "restitution");
887 RNA_def_property_range(prop, 0.0f, FLT_MAX);
888 RNA_def_property_ui_range(prop, 0.0f, 1.0f, 1, 3);
889 RNA_def_property_float_default(prop, 0.0f);
890 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_restitution_set", NULL);
891 RNA_def_property_ui_text(prop, "Restitution",
892 "Tendency of object to bounce after colliding with another "
893 "(0 = stays still, 1 = perfectly elastic)");
894 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
896 /* Collision Parameters - Sensitivity */
897 prop = RNA_def_property(srna, "use_margin", PROP_BOOLEAN, PROP_NONE);
898 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBO_FLAG_USE_MARGIN);
899 RNA_def_property_boolean_default(prop, FALSE);
900 RNA_def_property_ui_text(prop, "Collision Margin",
901 "Use custom collision margin (some shapes will have a visible gap around them)");
902 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_shape_reset");
904 prop = RNA_def_property(srna, "collision_margin", PROP_FLOAT, PROP_UNIT_LENGTH);
905 RNA_def_property_float_sdna(prop, NULL, "margin");
906 RNA_def_property_range(prop, 0.0f, 1.0f);
907 RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.01, 3);
908 RNA_def_property_float_default(prop, 0.04f);
909 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_collision_margin_set", NULL);
910 RNA_def_property_ui_text(prop, "Collision Margin",
911 "Threshold of distance near surface where collisions are still considered "
912 "(best results when non-zero)");
913 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_shape_reset");
915 prop = RNA_def_property(srna, "collision_groups", PROP_BOOLEAN, PROP_LAYER_MEMBER);
916 RNA_def_property_boolean_sdna(prop, NULL, "col_groups", 1);
917 RNA_def_property_array(prop, 20);
918 RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyOb_collision_groups_set");
919 RNA_def_property_ui_text(prop, "Collision Groups", "Collision Groups Rigid Body belongs to");
920 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
921 RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
924 static void rna_def_rigidbody_constraint(BlenderRNA *brna)
929 srna = RNA_def_struct(brna, "RigidBodyConstraint", NULL);
930 RNA_def_struct_sdna(srna, "RigidBodyCon");
931 RNA_def_struct_ui_text(srna, "Rigid Body Constraint",
932 "Constraint influencing Objects inside Rigid Body Simulation");
933 RNA_def_struct_path_func(srna, "rna_RigidBodyCon_path");
936 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
937 RNA_def_property_enum_sdna(prop, NULL, "type");
938 RNA_def_property_enum_items(prop, rigidbody_constraint_type_items);
939 RNA_def_property_enum_funcs(prop, NULL, "rna_RigidBodyCon_type_set", NULL);
940 RNA_def_property_ui_text(prop, "Type", "Type of Rigid Body Constraint");
941 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
942 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
944 prop = RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
945 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_ENABLED);
946 RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyCon_enabled_set");
947 RNA_def_property_ui_text(prop, "Enabled", "Enable this constraint");
948 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
950 prop = RNA_def_property(srna, "disable_collisions", PROP_BOOLEAN, PROP_NONE);
951 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_DISABLE_COLLISIONS);
952 RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyCon_disable_collisions_set");
953 RNA_def_property_ui_text(prop, "Disable Collisions", "Disable collisions between constrained rigid bodies");
954 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
956 prop = RNA_def_property(srna, "object1", PROP_POINTER, PROP_NONE);
957 RNA_def_property_pointer_sdna(prop, NULL, "ob1");
958 RNA_def_property_flag(prop, PROP_EDITABLE);
959 RNA_def_property_ui_text(prop, "Object 1", "First Rigid Body Object to be constrained");
960 RNA_def_property_flag(prop, PROP_EDITABLE);
961 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
963 prop = RNA_def_property(srna, "object2", PROP_POINTER, PROP_NONE);
964 RNA_def_property_pointer_sdna(prop, NULL, "ob2");
965 RNA_def_property_flag(prop, PROP_EDITABLE);
966 RNA_def_property_ui_text(prop, "Object 2", "Second Rigid Body Object to be constrained");
967 RNA_def_property_flag(prop, PROP_EDITABLE);
968 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
970 /* Breaking Threshold */
971 prop = RNA_def_property(srna, "use_breaking", PROP_BOOLEAN, PROP_NONE);
972 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_BREAKING);
973 RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyCon_use_breaking_set");
974 RNA_def_property_ui_text(prop, "Breakable",
975 "Constraint can be broken if it receives an impulse above the threshold");
976 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
978 prop = RNA_def_property(srna, "breaking_threshold", PROP_FLOAT, PROP_NONE);
979 RNA_def_property_float_sdna(prop, NULL, "breaking_threshold");
980 RNA_def_property_range(prop, 0.0f, FLT_MAX);
981 RNA_def_property_ui_range(prop, 0.0f, 1000.0f, 100.0, 2);
982 RNA_def_property_float_default(prop, 10.0f);
983 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_breaking_threshold_set", NULL);
984 RNA_def_property_ui_text(prop, "Breaking Threshold",
985 "Impulse threshold that must be reached for the constraint to break");
986 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
988 /* Solver Iterations */
989 prop = RNA_def_property(srna, "use_override_solver_iterations", PROP_BOOLEAN, PROP_NONE);
990 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_OVERRIDE_SOLVER_ITERATIONS);
991 RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyCon_override_solver_iterations_set");
992 RNA_def_property_ui_text(prop, "Override Solver Iterations",
993 "Override the number of solver iterations for this constraint");
994 RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
996 prop = RNA_def_property(srna, "solver_iterations", PROP_INT, PROP_NONE);
997 RNA_def_property_int_sdna(prop, NULL, "num_solver_iterations");
998 RNA_def_property_range(prop, 1, 1000);
999 RNA_def_property_ui_range(prop, 1, 100, 1, -1);
1000 RNA_def_property_int_default(prop, 10);
1001 RNA_def_property_int_funcs(prop, NULL, "rna_RigidBodyCon_num_solver_iterations_set", NULL);
1002 RNA_def_property_ui_text(prop, "Solver Iterations",
1003 "Number of constraint solver iterations made per simulation step (higher values are more "
1004 "accurate but slower)");
1005 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1008 prop = RNA_def_property(srna, "use_limit_lin_x", PROP_BOOLEAN, PROP_NONE);
1009 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_LIMIT_LIN_X);
1010 RNA_def_property_ui_text(prop, "X Axis", "Limit translation on X axis");
1011 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1013 prop = RNA_def_property(srna, "use_limit_lin_y", PROP_BOOLEAN, PROP_NONE);
1014 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_LIMIT_LIN_Y);
1015 RNA_def_property_ui_text(prop, "Y Axis", "Limit translation on Y axis");
1016 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1018 prop = RNA_def_property(srna, "use_limit_lin_z", PROP_BOOLEAN, PROP_NONE);
1019 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_LIMIT_LIN_Z);
1020 RNA_def_property_ui_text(prop, "Z Axis", "Limit translation on Z axis");
1021 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1023 prop = RNA_def_property(srna, "use_limit_ang_x", PROP_BOOLEAN, PROP_NONE);
1024 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_LIMIT_ANG_X);
1025 RNA_def_property_ui_text(prop, "X Angle", "Limit rotation around X axis");
1026 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1028 prop = RNA_def_property(srna, "use_limit_ang_y", PROP_BOOLEAN, PROP_NONE);
1029 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_LIMIT_ANG_Y);
1030 RNA_def_property_ui_text(prop, "Y Angle", "Limit rotation around Y axis");
1031 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1033 prop = RNA_def_property(srna, "use_limit_ang_z", PROP_BOOLEAN, PROP_NONE);
1034 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_LIMIT_ANG_Z);
1035 RNA_def_property_ui_text(prop, "Z Angle", "Limit rotation around Z axis");
1036 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1038 prop = RNA_def_property(srna, "use_spring_x", PROP_BOOLEAN, PROP_NONE);
1039 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_SPRING_X);
1040 RNA_def_property_ui_text(prop, "X Spring", "Enable spring on X axis");
1041 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1043 prop = RNA_def_property(srna, "use_spring_y", PROP_BOOLEAN, PROP_NONE);
1044 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_SPRING_Y);
1045 RNA_def_property_ui_text(prop, "Y Spring", "Enable spring on Y axis");
1046 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1048 prop = RNA_def_property(srna, "use_spring_z", PROP_BOOLEAN, PROP_NONE);
1049 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_SPRING_Z);
1050 RNA_def_property_ui_text(prop, "Z Spring", "Enable spring on Z axis");
1051 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1053 prop = RNA_def_property(srna, "use_motor_lin", PROP_BOOLEAN, PROP_NONE);
1054 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_MOTOR_LIN);
1055 RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyCon_use_motor_lin_set");
1056 RNA_def_property_ui_text(prop, "Linear Motor", "Enable linear motor");
1057 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1059 prop = RNA_def_property(srna, "use_motor_ang", PROP_BOOLEAN, PROP_NONE);
1060 RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_MOTOR_ANG);
1061 RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyCon_use_motor_ang_set");
1062 RNA_def_property_ui_text(prop, "Angular Motor", "Enable angular motor");
1063 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1065 prop = RNA_def_property(srna, "limit_lin_x_lower", PROP_FLOAT, PROP_UNIT_LENGTH);
1066 RNA_def_property_float_sdna(prop, NULL, "limit_lin_x_lower");
1067 RNA_def_property_float_default(prop, -1.0f);
1068 RNA_def_property_ui_text(prop, "Lower X Limit", "Lower limit of X axis translation");
1069 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1071 prop = RNA_def_property(srna, "limit_lin_x_upper", PROP_FLOAT, PROP_UNIT_LENGTH);
1072 RNA_def_property_float_sdna(prop, NULL, "limit_lin_x_upper");
1073 RNA_def_property_float_default(prop, 1.0f);
1074 RNA_def_property_ui_text(prop, "Upper X Limit", "Upper limit of X axis translation");
1075 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1077 prop = RNA_def_property(srna, "limit_lin_y_lower", PROP_FLOAT, PROP_UNIT_LENGTH);
1078 RNA_def_property_float_sdna(prop, NULL, "limit_lin_y_lower");
1079 RNA_def_property_float_default(prop, -1.0f);
1080 RNA_def_property_ui_text(prop, "Lower Y Limit", "Lower limit of Y axis translation");
1081 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1083 prop = RNA_def_property(srna, "limit_lin_y_upper", PROP_FLOAT, PROP_UNIT_LENGTH);
1084 RNA_def_property_float_sdna(prop, NULL, "limit_lin_y_upper");
1085 RNA_def_property_float_default(prop, 1.0f);
1086 RNA_def_property_ui_text(prop, "Upper Y Limit", "Upper limit of Y axis translation");
1087 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1089 prop = RNA_def_property(srna, "limit_lin_z_lower", PROP_FLOAT, PROP_UNIT_LENGTH);
1090 RNA_def_property_float_sdna(prop, NULL, "limit_lin_z_lower");
1091 RNA_def_property_float_default(prop, -1.0f);
1092 RNA_def_property_ui_text(prop, "Lower Z Limit", "Lower limit of Z axis translation");
1093 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1095 prop = RNA_def_property(srna, "limit_lin_z_upper", PROP_FLOAT, PROP_UNIT_LENGTH);
1096 RNA_def_property_float_sdna(prop, NULL, "limit_lin_z_upper");
1097 RNA_def_property_float_default(prop, 1.0f);
1098 RNA_def_property_ui_text(prop, "Upper Z Limit", "Upper limit of Z axis translation");
1099 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1101 prop = RNA_def_property(srna, "limit_ang_x_lower", PROP_FLOAT, PROP_ANGLE);
1102 RNA_def_property_float_sdna(prop, NULL, "limit_ang_x_lower");
1103 RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
1104 RNA_def_property_float_default(prop, -M_PI_4);
1105 RNA_def_property_ui_text(prop, "Lower X Angle Limit", "Lower limit of X axis rotation");
1106 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1108 prop = RNA_def_property(srna, "limit_ang_x_upper", PROP_FLOAT, PROP_ANGLE);
1109 RNA_def_property_float_sdna(prop, NULL, "limit_ang_x_upper");
1110 RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
1111 RNA_def_property_float_default(prop, M_PI_4);
1112 RNA_def_property_ui_text(prop, "Upper X Angle Limit", "Upper limit of X axis rotation");
1113 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1115 prop = RNA_def_property(srna, "limit_ang_y_lower", PROP_FLOAT, PROP_ANGLE);
1116 RNA_def_property_float_sdna(prop, NULL, "limit_ang_y_lower");
1117 RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
1118 RNA_def_property_float_default(prop, -M_PI_4);
1119 RNA_def_property_ui_text(prop, "Lower Y Angle Limit", "Lower limit of Y axis rotation");
1120 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1122 prop = RNA_def_property(srna, "limit_ang_y_upper", PROP_FLOAT, PROP_ANGLE);
1123 RNA_def_property_float_sdna(prop, NULL, "limit_ang_y_upper");
1124 RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
1125 RNA_def_property_float_default(prop, M_PI_4);
1126 RNA_def_property_ui_text(prop, "Upper Y Angle Limit", "Upper limit of Y axis rotation");
1127 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1129 prop = RNA_def_property(srna, "limit_ang_z_lower", PROP_FLOAT, PROP_ANGLE);
1130 RNA_def_property_float_sdna(prop, NULL, "limit_ang_z_lower");
1131 RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
1132 RNA_def_property_float_default(prop, -M_PI_4);
1133 RNA_def_property_ui_text(prop, "Lower Z Angle Limit", "Lower limit of Z axis rotation");
1134 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1136 prop = RNA_def_property(srna, "limit_ang_z_upper", PROP_FLOAT, PROP_ANGLE);
1137 RNA_def_property_float_sdna(prop, NULL, "limit_ang_z_upper");
1138 RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
1139 RNA_def_property_float_default(prop, M_PI_4);
1140 RNA_def_property_ui_text(prop, "Upper Z Angle Limit", "Upper limit of Z axis rotation");
1141 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
1143 prop = RNA_def_property(srna, "spring_stiffness_x", PROP_FLOAT, PROP_NONE);
1144 RNA_def_property_float_sdna(prop, NULL, "spring_stiffness_x");
1145 RNA_def_property_range(prop, 0.0f, FLT_MAX);
1146 RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
1147 RNA_def_property_float_default(prop, 10.0f);
1148 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_stiffness_x_set", NULL);
1149 RNA_def_property_ui_text(prop, "X Axis Stiffness", "Stiffness on the X axis");
1150 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1152 prop = RNA_def_property(srna, "spring_stiffness_y", PROP_FLOAT, PROP_NONE);
1153 RNA_def_property_float_sdna(prop, NULL, "spring_stiffness_y");
1154 RNA_def_property_range(prop, 0.0f, FLT_MAX);
1155 RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
1156 RNA_def_property_float_default(prop, 10.0f);
1157 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_stiffness_y_set", NULL);
1158 RNA_def_property_ui_text(prop, "Y Axis Stiffness", "Stiffness on the Y axis");
1159 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1161 prop = RNA_def_property(srna, "spring_stiffness_z", PROP_FLOAT, PROP_NONE);
1162 RNA_def_property_float_sdna(prop, NULL, "spring_stiffness_z");
1163 RNA_def_property_range(prop, 0.0f, FLT_MAX);
1164 RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
1165 RNA_def_property_float_default(prop, 10.0f);
1166 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_stiffness_z_set", NULL);
1167 RNA_def_property_ui_text(prop, "Z Axis Stiffness", "Stiffness on the Z axis");
1168 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1170 prop = RNA_def_property(srna, "spring_damping_x", PROP_FLOAT, PROP_FACTOR);
1171 RNA_def_property_float_sdna(prop, NULL, "spring_damping_x");
1172 RNA_def_property_range(prop, 0.0f, 1.0f);
1173 RNA_def_property_float_default(prop, 0.5f);
1174 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_damping_x_set", NULL);
1175 RNA_def_property_ui_text(prop, "Damping X", "Damping on the X axis");
1176 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1178 prop = RNA_def_property(srna, "spring_damping_y", PROP_FLOAT, PROP_FACTOR);
1179 RNA_def_property_float_sdna(prop, NULL, "spring_damping_y");
1180 RNA_def_property_range(prop, 0.0f, 1.0f);
1181 RNA_def_property_float_default(prop, 0.5f);
1182 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_damping_y_set", NULL);
1183 RNA_def_property_ui_text(prop, "Damping Y", "Damping on the Y axis");
1184 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1186 prop = RNA_def_property(srna, "spring_damping_z", PROP_FLOAT, PROP_FACTOR);
1187 RNA_def_property_float_sdna(prop, NULL, "spring_damping_z");
1188 RNA_def_property_range(prop, 0.0f, 1.0f);
1189 RNA_def_property_float_default(prop, 0.5f);
1190 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_damping_z_set", NULL);
1191 RNA_def_property_ui_text(prop, "Damping Z", "Damping on the Z axis");
1192 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1194 prop = RNA_def_property(srna, "motor_lin_target_velocity", PROP_FLOAT, PROP_UNIT_VELOCITY);
1195 RNA_def_property_float_sdna(prop, NULL, "motor_lin_target_velocity");
1196 RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
1197 RNA_def_property_ui_range(prop, -100.0f, 100.0f, 1, 3);
1198 RNA_def_property_float_default(prop, 1.0f);
1199 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_motor_lin_target_velocity_set", NULL);
1200 RNA_def_property_ui_text(prop, "Target Velocity", "Target linear motor velocity");
1201 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1203 prop = RNA_def_property(srna, "motor_lin_max_impulse", PROP_FLOAT, PROP_NONE);
1204 RNA_def_property_float_sdna(prop, NULL, "motor_lin_max_impulse");
1205 RNA_def_property_range(prop, 0.0f, FLT_MAX);
1206 RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
1207 RNA_def_property_float_default(prop, 1.0f);
1208 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_motor_lin_max_impulse_set", NULL);
1209 RNA_def_property_ui_text(prop, "Max Impulse", "Maximum linear motor impulse");
1210 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1212 prop = RNA_def_property(srna, "motor_ang_target_velocity", PROP_FLOAT, PROP_NONE);
1213 RNA_def_property_float_sdna(prop, NULL, "motor_ang_target_velocity");
1214 RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
1215 RNA_def_property_ui_range(prop, -100.0f, 100.0f, 1, 3);
1216 RNA_def_property_float_default(prop, 1.0f);
1217 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_motor_ang_target_velocity_set", NULL);
1218 RNA_def_property_ui_text(prop, "Target Velocity", "Target angular motor velocity");
1219 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1221 prop = RNA_def_property(srna, "motor_ang_max_impulse", PROP_FLOAT, PROP_NONE);
1222 RNA_def_property_float_sdna(prop, NULL, "motor_ang_max_impulse");
1223 RNA_def_property_range(prop, 0.0f, FLT_MAX);
1224 RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
1225 RNA_def_property_float_default(prop, 1.0f);
1226 RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_motor_ang_max_impulse_set", NULL);
1227 RNA_def_property_ui_text(prop, "Max Impulse", "Maximum angular motor impulse");
1228 RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
1231 void RNA_def_rigidbody(BlenderRNA *brna)
1233 rna_def_rigidbody_world(brna);
1234 rna_def_rigidbody_object(brna);
1235 rna_def_rigidbody_constraint(brna);