[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31135] branches/soc-2010-aligorith-2: Bullet SoC - Exposing some new simulation parameters

Joshua Leung aligorith at gmail.com
Sat Aug 7 07:48:29 CEST 2010


Revision: 31135
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31135
Author:   aligorith
Date:     2010-08-07 07:48:28 +0200 (Sat, 07 Aug 2010)

Log Message:
-----------
Bullet SoC - Exposing some new simulation parameters

Linear/Angular Damping and Deactivation Thresholds. 
- Damping is what you use to make things move around less vigorously 
- Deactivation Thresholds are the velocities at which if the corresponding velocity dips below that value, Bullet will stop evaluating that object.
I've added these to their own panel, which is closed by default as most people should not need to open it.

I was going to test this on an earlier example where there was a problem with this, but it looks like that's no longer necessary (which means that I now have a nice demo of force fields). Will need to find a new test case now though ;)

Modified Paths:
--------------
    branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
    branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
    branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c

Modified: branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
===================================================================
--- branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py	2010-08-07 04:48:09 UTC (rev 31134)
+++ branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py	2010-08-07 05:48:28 UTC (rev 31135)
@@ -62,12 +62,6 @@
             if rbo.type == 'ACTIVE':
                 col = layout.column()
                 col.prop(rbo, "mass")
-                
-                col = layout.column(align=1)
-                col.label(text="Simulation Influence:")
-                col.prop(rbo, "follow_simulation", text="")
-                col.prop(rbo, "influence")
-            
 
 class PHYSICS_PT_rigid_body_collisions(PHYSICS_PT_rigidbody_panel):
     bl_label = "Rigid Body Collisions"
@@ -101,14 +95,50 @@
         col.prop(rbo, "bounciness")
         
         col = split.column()
-        col.label(text="Sensitivity")
+        col.label(text="Sensitivity:")
         col.prop(rbo, "collision_margin", text="Margin")
+
+class PHYSICS_PT_rigid_body_dynamics(PHYSICS_PT_rigidbody_panel):
+    bl_label = "Rigid Body Dynamics"
+    bl_default_closed = True
+
+    def poll(self, context):
+        return (context.object and context.object.rigid_body and
+                context.object.rigid_body.type == 'ACTIVE')
         
+    def draw(self, context):
+        layout = self.layout
+
+        ob = context.object
+        rbo = ob.rigid_body
+        wide_ui = context.region.width > narrowui
+        
+        #col = layout.column(align=1)
+        #col.label(text="Activation:")
+        # XXX: settings such as activate on collison/etc. 
+        
+        col = layout.column(align=1)
+        col.label(text="Deactivation:")
+        col.prop(rbo, "deactivate_linear_velocity", text="Linear Vel")
+        col.prop(rbo, "deactivate_angular_velocity", text="Angular Vel")
+        # TODO: other params such as time?
+        
+        col = layout.column(align=1)
+        col.label(text="Damping:")
+        col.prop(rbo, "linear_damping", text="Linear Vel")
+        col.prop(rbo, "angular_damping", text="Angular Vel")
+        
+        col = layout.column(align=1)
+        col.label(text="Simulation Influence:")
+        col.prop(rbo, "follow_simulation", text="")
+        col.prop(rbo, "influence") 
+
 ##########################
 
 classes = [
     PHYSICS_PT_rigid_body,
-    PHYSICS_PT_rigid_body_collisions
+    PHYSICS_PT_rigid_body_collisions,
+    PHYSICS_PT_rigid_body_dynamics
 ]
 
 def register():

Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c	2010-08-07 04:48:09 UTC (rev 31134)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c	2010-08-07 05:48:28 UTC (rev 31135)
@@ -365,6 +365,9 @@
 		// at once... that will need further work later...
 		rbDWorldAddBody(rbw->physics_world, rbo->physics_object);
 	}
+	
+	// FIXME: flush every setting to the object, just so that we can make sure that all settings have been set?
+	// Doing this should fix problems with changing some settings having no effect (esp after restarting sims)
 }	
 
 /* --------------------- */

Modified: branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h	2010-08-07 04:48:09 UTC (rev 31134)
+++ branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h	2010-08-07 05:48:28 UTC (rev 31135)
@@ -116,6 +116,12 @@
 	float bounciness;		/* how 'bouncy' object is when it collides. also known as restitution */
 	
 	float margin;			/* tolerance for detecting collisions */ 
+	
+	float linDamping;		/* damping for linear velocities */
+	float angDamping;		/* damping for angular velocities */
+	
+	float linSleepThresh;	/* deactivation threshold for linear velocities */
+	float angSleepThresh;	/* deactivation threshold for angular velocities */
 } RigidBodyOb;
 
 

Modified: branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c	2010-08-07 04:48:09 UTC (rev 31134)
+++ branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c	2010-08-07 05:48:28 UTC (rev 31135)
@@ -192,6 +192,54 @@
 		rbShapeSetMargin(rbo->physics_shape, value);
 }
 
+static void rna_RigidBodyOb_linear_sleepThresh_set(PointerRNA *ptr, float value)
+{
+	RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+	
+	/* store new sleep threshold */
+	rbo->linSleepThresh = value;
+	
+	/* update mass if necessary - only active bodies need the mass */
+	if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE))
+		rbBodySetLinearSleepThresh(rbo->physics_object, value);
+}
+
+static void rna_RigidBodyOb_angular_sleepThresh_set(PointerRNA *ptr, float value)
+{
+	RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+	
+	/* store new sleep threshold */
+	rbo->angSleepThresh = value;
+	
+	/* update mass if necessary - only active bodies need the mass */
+	if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE))
+		rbBodySetAngularSleepThresh(rbo->physics_object, value);
+}
+
+static void rna_RigidBodyOb_linear_damping_set(PointerRNA *ptr, float value)
+{
+	RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+	
+	/* store new damping amount */
+	rbo->linDamping = value;
+	
+	/* update mass if necessary - only active bodies need the mass */
+	if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE))
+		rbBodySetLinearDamping(rbo->physics_object, value);
+}
+
+static void rna_RigidBodyOb_angular_damping_set(PointerRNA *ptr, float value)
+{
+	RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+	
+	/* store new damping amount */
+	rbo->angDamping = value;
+	
+	/* update mass if necessary - only active bodies need the mass */
+	if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE))
+		rbBodySetAngularDamping(rbo->physics_object, value);
+}
+
 #else
 
 static void rna_def_rigidbody_world(BlenderRNA *brna)
@@ -306,7 +354,36 @@
 	RNA_def_property_ui_text(prop, "Mass", "How much the object 'weighs' irrespective of gravity");
 	// TODO: setup necessary updates for this setting
 	
-	/* Collision Parameters */
+	/* Dynamics Parameters - Activation */
+	// TODO: define and figure out how to implement these
+	
+	/* Dynamics Parameters - Deactivation Thresholds */
+	prop= RNA_def_property(srna, "deactivate_linear_velocity", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "linSleepThresh");
+	RNA_def_property_range(prop, FLT_MIN, FLT_MAX); // range must always be positive (and non-zero)
+	RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_linear_sleepThresh_set", NULL);
+	RNA_def_property_ui_text(prop, "Linear Velocity Deactivation Threshold", "Linear Velocity below which simulation stops simulating object");
+	
+	prop= RNA_def_property(srna, "deactivate_angular_velocity", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "angSleepThresh");
+	RNA_def_property_range(prop, FLT_MIN, FLT_MAX); // range must always be positive (and non-zero)
+	RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_angular_sleepThresh_set", NULL);
+	RNA_def_property_ui_text(prop, "Angular Velocity Deactivation Threshold", "Angular Velocity below which simulation stops simulating object");
+	
+	/* Dynamics Parameters - Damping Parameters */
+	prop= RNA_def_property(srna, "linear_damping", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "linDamping");
+	RNA_def_property_range(prop, FLT_MIN, FLT_MAX); // XXX?
+	RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_linear_damping_set", NULL);
+	RNA_def_property_ui_text(prop, "Linear Damping", "Amount of linear velocity is lost on collisions");
+	
+	prop= RNA_def_property(srna, "angular_damping", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "angDamping");
+	RNA_def_property_range(prop, FLT_MIN, FLT_MAX); // XXX?
+	RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_angular_damping_set", NULL);
+	RNA_def_property_ui_text(prop, "Angular Damping", "Amount of angular velocity is lost on collisions");
+	
+	/* Collision Parameters - Surface Parameters */
 	prop= RNA_def_property(srna, "friction", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "friction");
 	RNA_def_property_range(prop, FLT_MIN, FLT_MAX); // XXX: this needs checking
@@ -321,6 +398,7 @@
 	RNA_def_property_ui_text(prop, "Bounciness", "Tendency of object to bounce after colliding with another (0 = stays still, 1 = perfectly elastic)");
 	// TODO: setup necessary updates for this setting
 	
+	/* Collision Parameters - Sensitivity */
 	prop= RNA_def_property(srna, "collision_margin", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "margin");
 	//RNA_def_property_range(prop, FLT_MIN, FLT_MAX); // XXX: this needs checking





More information about the Bf-blender-cvs mailing list