[Bf-blender-cvs] [b1c3782] fracture_modifier: added activation by force, if force exceeds an adjustable threshold, kinematic rigidbodies get activated / triggered by a force field

Martin Felke noreply at git.blender.org
Thu Jan 14 13:04:39 CET 2016


Commit: b1c3782c4649059845627ca5e58762ccb984dbc3
Author: Martin Felke
Date:   Thu Jan 14 13:04:10 2016 +0100
Branches: fracture_modifier
https://developer.blender.org/rBb1c3782c4649059845627ca5e58762ccb984dbc3

added activation by force, if force exceeds an adjustable threshold, kinematic rigidbodies get activated / triggered by a force field

===================================================================

M	release/scripts/startup/bl_ui/properties_physics_rigidbody.py
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/makesdna/DNA_rigidbody_types.h
M	source/blender/makesrna/intern/rna_rigidbody.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
index 4f4fcaf..a9a7715 100644
--- a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
+++ b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
@@ -134,6 +134,8 @@ class PHYSICS_PT_rigid_body_dynamics(PHYSICS_PT_rigidbody_panel, Panel):
         sub.prop(rbo, "deactivate_linear_velocity", text="Linear Vel")
         sub.prop(rbo, "deactivate_angular_velocity", text="Angular Vel")
         # TODO: other params such as time?
+        col.label(text="Activation:")
+        col.prop(rbo, "force_threshold", text="Force Thresh")
 
         col = split.column()
         col.label(text="Damping:")
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 43181f1..3034300 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -84,12 +84,12 @@ static void activateRigidbody(RigidBodyOb* rbo, RigidBodyWorld *UNUSED(rbw), Mes
 	if (rbo->flag & RBO_FLAG_KINEMATIC && rbo->type == RBO_TYPE_ACTIVE)
 	{
 		rbo->flag &= ~RBO_FLAG_KINEMATIC;
+		rbo->flag |= RBO_FLAG_NEEDS_VALIDATE;
 		//RB_dworld_remove_body(rbw->physics_world, rbo->physics_object);
 		RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
 		RB_body_set_kinematic_state(rbo->physics_object, false);
 		//RB_dworld_add_body(rbw->physics_world, rbo->physics_object, rbo->col_groups, mi, ob);
-		//RB_body_activate(rbo->physics_object);
-		rbo->flag |= RBO_FLAG_NEEDS_VALIDATE;
+		RB_body_activate(rbo->physics_object);
 	}
 }
 
@@ -2270,6 +2270,7 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type)
 
 	rbo->lin_sleep_thresh = 0.4f; /* 0.4 is half of Bullet default */
 	rbo->ang_sleep_thresh = 0.5f; /* 0.5 is half of Bullet default */
+	rbo->force_thresh = 0.0f; /*dont activate by force by default */
 
 	rbo->lin_damping = 0.04f; /* 0.04 is game engine default */
 	rbo->ang_damping = 0.1f; /* 0.1 is game engine default */
@@ -2813,7 +2814,7 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
 	}
 
 	/* update rigid body location and rotation for kinematic bodies */
-	if (rbo->flag & RBO_FLAG_KINEMATIC || (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ)) {
+	if ((rbo->flag & RBO_FLAG_KINEMATIC && rbo->force_thresh == 0.0f) || (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ)) {
 		mul_v3_v3(centr, scale);
 		mul_qt_v3(rot, centr);
 		add_v3_v3(loc, centr);
@@ -2832,6 +2833,7 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
 		if (effectors) {
 			float eff_force[3] = {0.0f, 0.0f, 0.0f};
 			float eff_loc[3], eff_vel[3];
+			float thresh = rbo->force_thresh * rbo->force_thresh; /*use this to compare against squared length of vector */
 
 			/* create dummy 'point' which represents last known position of object as result of sim */
 			// XXX: this can create some inaccuracies with sim position, but is probably better than using unsimulated vals?
@@ -2847,12 +2849,29 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
 			 *	- 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);
-			if (G.f & G_DEBUG)
-				printf("\tapplying force (%f,%f,%f) to '%s'\n", eff_force[0], eff_force[1], eff_force[2], ob->id.name + 2);
-			/* activate object in case it is deactivated */
-			if (!is_zero_v3(eff_force))
+			if ((rbo->flag & RBO_FLAG_KINEMATIC) && (thresh < len_squared_v3(eff_force)))
+			{
+				activateRigidbody(rbo, NULL, NULL, NULL);
+				RB_body_apply_central_force(rbo->physics_object, eff_force);
+			}
+			else if (rbo->flag & RBO_FLAG_KINEMATIC)
+			{
+				/* do the same here as above, but here we needed the eff_force value to compare against threshold */
+				mul_v3_v3(centr, scale);
+				mul_qt_v3(rot, centr);
+				add_v3_v3(loc, centr);
 				RB_body_activate(rbo->physics_object);
-			RB_body_apply_central_force(rbo->physics_object, eff_force);
+				RB_body_set_loc_rot(rbo->physics_object, loc, rot);
+			}
+			else
+			{
+				if (G.f & G_DEBUG)
+					printf("\tapplying force (%f,%f,%f) to '%s'\n", eff_force[0], eff_force[1], eff_force[2], ob->id.name + 2);
+				/* activate object in case it is deactivated */
+				if (!is_zero_v3(eff_force))
+					RB_body_activate(rbo->physics_object);
+				RB_body_apply_central_force(rbo->physics_object, eff_force);
+			}
 		}
 		else if (G.f & G_DEBUG)
 			printf("\tno forces to apply to '%s'\n", ob->id.name + 2);
diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index bf24dac..ebaacd0 100644
--- a/source/blender/makesdna/DNA_rigidbody_types.h
+++ b/source/blender/makesdna/DNA_rigidbody_types.h
@@ -132,12 +132,13 @@ typedef struct RigidBodyOb {
 	
 	float lin_sleep_thresh;	/* deactivation threshold for linear velocities */
 	float ang_sleep_thresh;	/* deactivation threshold for angular velocities */
+	float force_thresh;		/* activation threshold for activation by force */
 	
 	float orn[4];			/* rigid body orientation */
 	float pos[3];			/* rigid body position */
 	float lin_vel[3];		/* rigid body linear velocity, important for dynamic fracture*/
 	float ang_vel[3];		/* rigid body angular velocity, important for dynamic fracture*/
-	float pad1;
+	//float pad1;
 } RigidBodyOb;
 
 
diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c
index 129895a..d9b6f71 100644
--- a/source/blender/makesrna/intern/rna_rigidbody.c
+++ b/source/blender/makesrna/intern/rna_rigidbody.c
@@ -543,6 +543,19 @@ static void rna_RigidBodyOb_angular_damping_set(PointerRNA *ptr, float value)
 	foreach_shard_float(ob, value, set_angular_damping);
 }
 
+void set_force_threshold(RigidBodyOb *rbo, float value)
+{
+	rbo->force_thresh = value;
+}
+
+static void rna_RigidBodyOb_force_threshold_set(PointerRNA *ptr, float value)
+{
+	RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+	Object *ob = ptr->id.data;
+	rbo->force_thresh = value;
+	foreach_shard_float(ob, value, set_force_threshold);
+}
+
 static char *rna_RigidBodyCon_path(PointerRNA *UNUSED(ptr))
 {
 	/* NOTE: this hardcoded path should work as long as only Objects have this */
@@ -1125,6 +1138,14 @@ static void rna_def_rigidbody_object(BlenderRNA *brna)
 	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);
+
+	prop = RNA_def_property(srna, "force_threshold", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "force_thresh");
+	RNA_def_property_range(prop, 0.0f, 100000.0f);
+	RNA_def_property_float_default(prop, 0.1f);
+	RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_force_threshold_set", NULL);
+	RNA_def_property_ui_text(prop, "Activation Force Threshold", "Strength of force necessary to activate this kinematic object");
+	RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
 }
 
 static void rna_def_rigidbody_constraint(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list