[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59901] branches/soc-2013-rigid_body_sim: rigidbody: Add effector weights for individual rigid bodies

Sergej Reich sergej.reich at googlemail.com
Fri Sep 6 19:59:09 CEST 2013


Revision: 59901
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59901
Author:   sergof
Date:     2013-09-06 17:59:09 +0000 (Fri, 06 Sep 2013)
Log Message:
-----------
rigidbody: Add effector weights for individual rigid bodies

There's a need for more fine grained control over how individual rigid
bodies are affected by force fields.
Having effector weights for both the world and bodies might be too much.
If so, we could drop it from the world and copy the world settings to
the body setting for old files.

Modified Paths:
--------------
    branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
    branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c
    branches/soc-2013-rigid_body_sim/source/blender/blenloader/intern/readfile.c
    branches/soc-2013-rigid_body_sim/source/blender/blenloader/intern/writefile.c
    branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h
    branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c

Modified: branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
===================================================================
--- branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py	2013-09-06 17:59:07 UTC (rev 59900)
+++ branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py	2013-09-06 17:59:09 UTC (rev 59901)
@@ -19,6 +19,7 @@
 # <pep8 compliant>
 import bpy
 from bpy.types import Panel
+from bl_ui.properties_physics_common import effector_weights_ui
 
 
 class PHYSICS_PT_rigidbody_panel():
@@ -136,5 +137,23 @@
         col.prop(rbo, "linear_damping", text="Translation")
         col.prop(rbo, "angular_damping", text="Rotation")
 
+class PHYSICS_PT_rigid_body_field_weights(PHYSICS_PT_rigidbody_panel, Panel):
+    bl_label = "Rigid Body Field Weights"
+    bl_options = {'DEFAULT_CLOSED'}
+    COMPAT_ENGINES = {'BLENDER_RENDER'}
+
+    @classmethod
+    def poll(cls, context):
+        obj = context.object
+        return (obj and obj.rigid_body and
+                obj.rigid_body.type == 'ACTIVE' and
+                (not context.scene.render.use_game_engine))
+
+    def draw(self, context):
+        ob = context.object
+        rbo = ob.rigid_body
+
+        effector_weights_ui(self, context, rbo.effector_weights, 'RIGID_BODY')
+
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)

Modified: branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c	2013-09-06 17:59:07 UTC (rev 59900)
+++ branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c	2013-09-06 17:59:09 UTC (rev 59901)
@@ -144,6 +144,10 @@
 		rbo->physics_shape = NULL;
 	}
 
+	/* free effector weights */
+	if (rbo->effector_weights)
+		MEM_freeN(rbo->effector_weights);
+
 	/* free data itself */
 	MEM_freeN(rbo);
 	ob->rigidbody_object = NULL;
@@ -178,12 +182,16 @@
 
 RigidBodyOb *BKE_rigidbody_copy_object(Object *ob)
 {
+	RigidBodyOb *rbo = ob->rigidbody_object;
 	RigidBodyOb *rboN = NULL;
 
-	if (ob->rigidbody_object) {
+	if (rbo) {
 		/* just duplicate the whole struct first (to catch all the settings) */
-		rboN = MEM_dupallocN(ob->rigidbody_object);
+		rboN = MEM_dupallocN(rbo);
 
+		if (rbo->effector_weights)
+			rboN->effector_weights = MEM_dupallocN(rbo->effector_weights);
+
 		/* tag object as needing to be verified */
 		rboN->flag |= RBO_FLAG_NEEDS_VALIDATE;
 
@@ -959,6 +967,8 @@
 	/* create new settings data, and link it up */
 	rbo = MEM_callocN(sizeof(RigidBodyOb), "RigidBodyOb");
 
+	rbo->effector_weights = BKE_add_effector_weights(NULL);
+
 	/* set default settings */
 	rbo->type = type;
 
@@ -1211,13 +1221,16 @@
 	/* update influence of effectors - but don't do it on an effector */
 	/* only dynamic bodies need effector update */
 	else if (rbo->type == RBO_TYPE_ACTIVE && ((ob->pd == NULL) || (ob->pd->forcefield == PFIELD_NULL))) {
-		EffectorWeights *effector_weights = rbw->effector_weights;
 		EffectedPoint epoint;
-		ListBase *effectors;
+		ListBase *effectors_local;
+		ListBase *effectors_global;
 
 		/* get effectors present in the group specified by effector_weights */
-		effectors = pdInitEffectors(scene, ob, NULL, effector_weights);
-		if (effectors) {
+		effectors_local = pdInitEffectors(scene, ob, NULL, rbo->effector_weights);
+		effectors_global = pdInitEffectors(scene, ob, NULL, rbw->effector_weights);
+		if (effectors_local && effectors_global) {
+			float eff_force_local[3] = {0.0f, 0.0f, 0.0f};
+			float eff_force_global[3] = {0.0f, 0.0f, 0.0f};
 			float eff_force[3] = {0.0f, 0.0f, 0.0f};
 			float eff_loc[3], eff_vel[3];
 
@@ -1231,7 +1244,10 @@
 			/* calculate net force of effectors, and apply to sim object
 			 *	- we use 'central force' since apply force requires a "relative position" which we don't have...
 			 */
-			pdDoEffectors(effectors, NULL, effector_weights, &epoint, eff_force, NULL);
+			pdDoEffectors(effectors_local, NULL, rbo->effector_weights, &epoint, eff_force_local, NULL);
+			pdDoEffectors(effectors_global, NULL, rbw->effector_weights, &epoint, eff_force_global, NULL);
+			add_v3_v3v3(eff_force, eff_force_global, eff_force_local);
+			mul_v3_fl(eff_force, 0.5f);
 			/* activate object in case it is deactivated */
 			if (!is_zero_v3(eff_force))
 				RB_body_activate(rbo->physics_object);
@@ -1239,7 +1255,8 @@
 		}
 
 		/* cleanup */
-		pdEndEffectors(&effectors);
+		pdEndEffectors(&effectors_global);
+		pdEndEffectors(&effectors_local);
 	}
 	/* NOTE: passive objects don't need to be updated since they don't move */
 

Modified: branches/soc-2013-rigid_body_sim/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/blenloader/intern/readfile.c	2013-09-06 17:59:07 UTC (rev 59900)
+++ branches/soc-2013-rigid_body_sim/source/blender/blenloader/intern/readfile.c	2013-09-06 17:59:09 UTC (rev 59901)
@@ -4926,6 +4926,12 @@
 	if (ob->rigidbody_object) {
 		RigidBodyOb *rbo = ob->rigidbody_object;
 		
+		rbo->effector_weights = newdataadr(fd, rbo->effector_weights);
+		if (rbo->effector_weights)
+			rbo->effector_weights->group = newlibadr(fd, ob->id.lib, rbo->effector_weights->group);
+		else
+			rbo->effector_weights = BKE_add_effector_weights(NULL);
+
 		/* must nullify the references to physics sim objects, since they no-longer exist 
 		 * (and will need to be recalculated) 
 		 */

Modified: branches/soc-2013-rigid_body_sim/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/blenloader/intern/writefile.c	2013-09-06 17:59:07 UTC (rev 59900)
+++ branches/soc-2013-rigid_body_sim/source/blender/blenloader/intern/writefile.c	2013-09-06 17:59:09 UTC (rev 59901)
@@ -1525,6 +1525,7 @@
 			if (ob->rigidbody_object) {
 				// TODO: if any extra data is added to handle duplis, will need separate function then
 				writestruct(wd, DATA, "RigidBodyOb", 1, ob->rigidbody_object);
+				writestruct(wd, DATA, "EffectorWeights", 1, ob->rigidbody_object->effector_weights);
 			}
 			if (ob->rigidbody_constraint) {
 				writestruct(wd, DATA, "RigidBodyCon", 1, ob->rigidbody_constraint);

Modified: branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h	2013-09-06 17:59:07 UTC (rev 59900)
+++ branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h	2013-09-06 17:59:09 UTC (rev 59901)
@@ -123,6 +123,7 @@
 	float orn[4];			/* rigid body orientation */
 	float pos[3];			/* rigid body position */
 	float pad1;
+	struct EffectorWeights *effector_weights;
 } RigidBodyOb;
 
 

Modified: branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c	2013-09-06 17:59:07 UTC (rev 59900)
+++ branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c	2013-09-06 17:59:09 UTC (rev 59901)
@@ -924,6 +924,12 @@
 	RNA_def_property_ui_text(prop, "Collision Groups", "Collision Groups Rigid Body belongs to");
 	RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
 	RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
+
+	/* effector weights */
+	prop = RNA_def_property(srna, "effector_weights", PROP_POINTER, PROP_NONE);
+	RNA_def_property_struct_type(prop, "EffectorWeights");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Effector Weights", "");
 }
 
 static void rna_def_rigidbody_constraint(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list