[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54026] trunk/blender: rigidbody: Add generic spring constraint

Sergej Reich sergej.reich at googlemail.com
Wed Jan 23 06:57:01 CET 2013


Revision: 54026
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54026
Author:   sergof
Date:     2013-01-23 05:57:01 +0000 (Wed, 23 Jan 2013)
Log Message:
-----------
rigidbody: Add generic spring constraint

Behaves like the generic constraint but has optional spring on each axis.

TODO: Add option to set rest length.

Patch by Markus Kasten (markus111), thanks!

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/rigidbody.py
    trunk/blender/source/blender/blenkernel/intern/rigidbody.c
    trunk/blender/source/blender/makesdna/DNA_rigidbody_types.h
    trunk/blender/source/blender/makesrna/intern/rna_rigidbody.c

Modified: trunk/blender/release/scripts/startup/bl_operators/rigidbody.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/rigidbody.py	2013-01-23 05:56:56 UTC (rev 54025)
+++ trunk/blender/release/scripts/startup/bl_operators/rigidbody.py	2013-01-23 05:57:01 UTC (rev 54026)
@@ -206,6 +206,7 @@
                ('SLIDER', "Slider", "Restricts rigid boddy translation to one axis"),
                ('PISTON', "Piston", "Restricts rigid boddy translation and rotation to one axis"),
                ('GENERIC', "Generic", "Restricts translation and rotation to specified axes"),
+               ('GENERIC_SPRING', "Generic Spring", "Restricts translation and rotation to specified axes with springs")),
         default='FIXED',)
 
     pivot_type = EnumProperty(

Modified: trunk/blender/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/rigidbody.c	2013-01-23 05:56:56 UTC (rev 54025)
+++ trunk/blender/source/blender/blenkernel/intern/rigidbody.c	2013-01-23 05:57:01 UTC (rev 54026)
@@ -569,8 +569,26 @@
 					}
 					RB_constraint_set_limits_piston(rbc->physics_constraint, lin_lower, lin_upper, ang_lower, ang_upper);
 					break;
+				case RBC_TYPE_6DOF_SPRING:
+					rbc->physics_constraint = RB_constraint_new_6dof_spring(loc, rot, rb1, rb2);
+
+					RB_constraint_set_spring_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_X, rbc->flag & RBC_FLAG_USE_SPRING_X);
+					RB_constraint_set_stiffness_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_X, rbc->spring_stiffness_x);
+					RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_X, rbc->spring_damping_x);
+
+					RB_constraint_set_spring_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Y, rbc->flag & RBC_FLAG_USE_SPRING_Y);
+					RB_constraint_set_stiffness_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Y, rbc->spring_stiffness_y);
+					RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Y, rbc->spring_damping_y);
+
+					RB_constraint_set_spring_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Z, rbc->flag & RBC_FLAG_USE_SPRING_Z);
+					RB_constraint_set_stiffness_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Z, rbc->spring_stiffness_z);
+					RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Z, rbc->spring_damping_z);
+
+					RB_constraint_set_equilibrium_6dof_spring(rbc->physics_constraint);
+				/* fall through */
 				case RBC_TYPE_6DOF:
-					rbc->physics_constraint = RB_constraint_new_6dof(loc, rot, rb1, rb2);
+					if (rbc->type == RBC_TYPE_6DOF) /* a litte awkward but avoids duplicate code for limits */
+						rbc->physics_constraint = RB_constraint_new_6dof(loc, rot, rb1, rb2);
 
 					if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_X)
 						RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_X, rbc->limit_lin_x_lower, rbc->limit_lin_x_upper);
@@ -775,6 +793,13 @@
 	rbc->limit_ang_z_lower = -M_PI_4;
 	rbc->limit_ang_z_upper = M_PI_4;
 
+	rbc->spring_damping_x = 0.5f;
+	rbc->spring_damping_y = 0.5f;
+	rbc->spring_damping_z = 0.5f;
+	rbc->spring_stiffness_x = 10.0f;
+	rbc->spring_stiffness_y = 10.0f;
+	rbc->spring_stiffness_z = 10.0f;
+
 	/* flag cache as outdated */
 	BKE_rigidbody_cache_reset(rbw);
 

Modified: trunk/blender/source/blender/makesdna/DNA_rigidbody_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_rigidbody_types.h	2013-01-23 05:56:56 UTC (rev 54025)
+++ trunk/blender/source/blender/makesdna/DNA_rigidbody_types.h	2013-01-23 05:57:01 UTC (rev 54026)
@@ -207,6 +207,15 @@
 	float limit_ang_z_lower;	/* lower limit for z axis rotation */
 	float limit_ang_z_upper;	/* upper limit for z axis rotation */
 
+	/* spring settings */
+	/* RB_TODO document spring properties */
+	float spring_stiffness_x;
+	float spring_stiffness_y;
+	float spring_stiffness_z;
+	float spring_damping_x;
+	float spring_damping_y;
+	float spring_damping_z;
+
 	/* References to Physics Sim object. Exist at runtime only */
 	void *physics_constraint;	/* Physics object representation (i.e. btTypedConstraint) */
 } RigidBodyCon;
@@ -257,6 +266,10 @@
 	RBC_FLAG_USE_LIMIT_ANG_X			= (1<<8),
 	RBC_FLAG_USE_LIMIT_ANG_Y			= (1<<9),
 	RBC_FLAG_USE_LIMIT_ANG_Z			= (1<<10),
+	/* springs */
+	RBC_FLAG_USE_SPRING_X				= (1<<11),
+	RBC_FLAG_USE_SPRING_Y				= (1<<12),
+	RBC_FLAG_USE_SPRING_Z				= (1<<13)
 } eRigidBodyCon_Flag;
 
 /* ******************************** */

Modified: trunk/blender/source/blender/makesrna/intern/rna_rigidbody.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_rigidbody.c	2013-01-23 05:56:56 UTC (rev 54025)
+++ trunk/blender/source/blender/makesrna/intern/rna_rigidbody.c	2013-01-23 05:57:01 UTC (rev 54026)
@@ -67,6 +67,7 @@
 	{RBC_TYPE_SLIDER, "SLIDER", ICON_FORCE_FORCE, "Slider", "Restricts rigid boddy translation to one axis"},
 	{RBC_TYPE_PISTON, "PISTON", ICON_FORCE_FORCE, "Piston", "Restricts rigid boddy translation and rotation to one axis"},
 	{RBC_TYPE_6DOF, "GENERIC", ICON_FORCE_FORCE, "Generic", "Restricts translation and rotation to specified axes"},
+	{RBC_TYPE_6DOF_SPRING, "GENERIC_SPRING", ICON_FORCE_FORCE, "Generic Spring", "Restricts translation and rotation to specified axes with springs"},
 	{0, NULL, 0, NULL, NULL}};
 
 
@@ -381,6 +382,66 @@
 		RB_constraint_set_solver_iterations(rbc->physics_constraint, value);
 }
 
+static void rna_RigidBodyCon_spring_stiffness_x_set(PointerRNA *ptr, float value)
+{
+	RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
+
+	rbc->spring_stiffness_x = value;
+
+	if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_X))
+		RB_constraint_set_stiffness_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_X, value);
+}
+
+static void rna_RigidBodyCon_spring_stiffness_y_set(PointerRNA *ptr, float value)
+{
+	RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
+
+	rbc->spring_stiffness_y = value;
+
+	if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_Y))
+		RB_constraint_set_stiffness_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Y, value);
+}
+
+static void rna_RigidBodyCon_spring_stiffness_z_set(PointerRNA *ptr, float value)
+{
+	RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
+
+	rbc->spring_stiffness_z = value;
+
+	if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_Z))
+		RB_constraint_set_stiffness_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Z, value);
+}
+
+static void rna_RigidBodyCon_spring_damping_x_set(PointerRNA *ptr, float value)
+{
+	RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
+
+	rbc->spring_damping_x = value;
+
+	if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_X))
+		RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_X, value);
+}
+
+static void rna_RigidBodyCon_spring_damping_y_set(PointerRNA *ptr, float value)
+{
+	RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
+
+	rbc->spring_damping_y = value;
+
+	if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_Y))
+		RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Y, value);
+}
+
+static void rna_RigidBodyCon_spring_damping_z_set(PointerRNA *ptr, float value)
+{
+	RigidBodyCon *rbc = (RigidBodyCon *)ptr->data;
+
+	rbc->spring_damping_z = value;
+
+	if (rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING && (rbc->flag & RBC_FLAG_USE_SPRING_Z))
+		RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_Z, value);
+}
+
 #else
 
 static void rna_def_rigidbody_world(BlenderRNA *brna)
@@ -710,6 +771,21 @@
 	RNA_def_property_ui_text(prop, "Z Angle", "Limits rotation around z axis");
 	RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
 
+	prop = RNA_def_property(srna, "use_spring_x", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_SPRING_X);
+	RNA_def_property_ui_text(prop, "X Spring", "Enables spring on X axis");
+	RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
+
+	prop = RNA_def_property(srna, "use_spring_y", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_SPRING_Y);
+	RNA_def_property_ui_text(prop, "Y Spring", "Enables spring on Y axis");
+	RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
+
+	prop = RNA_def_property(srna, "use_spring_z", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_SPRING_Z);
+	RNA_def_property_ui_text(prop, "Z Spring", "Enables spring on Z axis");
+	RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
+
 	prop = RNA_def_property(srna, "limit_lin_x_lower", PROP_FLOAT, PROP_UNIT_LENGTH);
 	RNA_def_property_float_sdna(prop, NULL, "limit_lin_x_lower");
 	RNA_def_property_float_default(prop, -1.0f);
@@ -787,6 +863,57 @@
 	RNA_def_property_float_default(prop, M_PI_4);
 	RNA_def_property_ui_text(prop, "Upper Z Angle Limit", "Upper limit of z axis rotation");
 	RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_RigidBodyOb_reset");
+
+	prop = RNA_def_property(srna, "spring_stiffness_x", PROP_FLOAT, PROP_UNIT_LENGTH);
+	RNA_def_property_float_sdna(prop, NULL, "spring_stiffness_x");
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
+	RNA_def_property_float_default(prop, 10.0f);
+	RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_stiffness_x_set", NULL);
+	RNA_def_property_ui_text(prop, "X Axis Stiffness", "Stiffness on the X axis");
+	RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset");
+
+	prop = RNA_def_property(srna, "spring_stiffness_y", PROP_FLOAT, PROP_UNIT_LENGTH);
+	RNA_def_property_float_sdna(prop, NULL, "spring_stiffness_y");
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
+	RNA_def_property_float_default(prop, 10.0f);
+	RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_stiffness_y_set", NULL);
+	RNA_def_property_ui_text(prop, "Y Axis Stiffness", "Stiffness on the Y axis");

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list