[Bf-blender-cvs] [d68f53a3f3f] fracture_modifier: added a limit / searchradius for animated mesh binding

Martin Felke noreply at git.blender.org
Tue Jan 23 18:05:38 CET 2018


Commit: d68f53a3f3f48a040d74aaf90bda3f6e63d6b9e5
Author: Martin Felke
Date:   Tue Jan 23 18:05:14 2018 +0100
Branches: fracture_modifier
https://developer.blender.org/rBd68f53a3f3f48a040d74aaf90bda3f6e63d6b9e5

added a limit / searchradius for animated mesh binding

bind operator now clears the simulation cache too

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

M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	source/blender/blenkernel/BKE_rigidbody.h
M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/editors/object/object_modifier.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_fracture.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py b/release/scripts/startup/bl_ui/properties_physics_fracture.py
index 3f7efb69e66..f1daf16ef66 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -60,6 +60,8 @@ class PHYSICS_PT_fracture_anim_mesh(PhysicButtonsPanel, Panel):
         row.prop(md, "use_animated_mesh")
         row.prop(md, "use_animated_mesh_rotation")
         row = layout.row()
+        row.prop(md, "animated_mesh_limit")
+        row = layout.row()
         row.prop(md, "animated_mesh_input")
         row = layout.row()
         row.operator("object.fracture_anim_bind", text="Bind", icon="UV_VERTEXSEL")
diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h
index 714a8bcfd0a..b8ce039011b 100644
--- a/source/blender/blenkernel/BKE_rigidbody.h
+++ b/source/blender/blenkernel/BKE_rigidbody.h
@@ -142,4 +142,6 @@ void BKE_rigidbody_object_sync_transforms(struct EvaluationContext *eval_ctx,
                                           struct Scene *scene,
                                           struct Object *ob);
 
+bool BKE_restoreKinematic(struct RigidBodyWorld *rbw, bool override_bind);
+
 #endif /* __BKE_RIGIDBODY_H__ */
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 50f7cee0d6a..df9765c8bbb 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -3845,6 +3845,24 @@ static DerivedMesh *eval_mod_stack_simple(Object *ob)
 	return dm;
 }
 
+void activate(MeshIsland *mi)
+{
+	if (mi->rigidbody->type == RBO_TYPE_ACTIVE)
+	{
+		RigidBodyOb* rbo = mi->rigidbody;
+
+		mi->rigidbody->flag &= ~RBO_FLAG_KINEMATIC;
+		mi->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
+
+		if (rbo->physics_object)
+		{
+			RB_body_set_mass(rbo->physics_object, rbo->mass);
+			RB_body_set_kinematic_state(rbo->physics_object, false);
+			RB_body_activate(rbo->physics_object);
+		}
+	}
+}
+
 void BKE_read_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool do_bind)
 {
 	//to be called after rigidbodies have been actually created... from MOD_fracture.c
@@ -3936,12 +3954,19 @@ void BKE_read_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool do_bi
 			mul_m4_v3(imat, co);
 			BLI_kdtree_find_nearest(tree, co, &n);
 
-			fmd->anim_bind[i].v = n.index;
-			fmd->anim_bind[i].mi = i;
-			sub_v3_v3v3(diff, n.co, co);
+			if (n.dist <= fmd->anim_bind_limit || fmd->anim_bind_limit == 0)
+			{
+				fmd->anim_bind[i].v = n.index;
+				fmd->anim_bind[i].mi = i;
+				sub_v3_v3v3(diff, n.co, co);
+				copy_v3_v3(fmd->anim_bind[i].offset, diff);
+				normal_short_to_float_v3(fmd->anim_bind[i].no, mvert[n.index].no);
+			}
+			else
+			{
+				activate(mi);
+			}
 
-			copy_v3_v3(fmd->anim_bind[i].offset, diff);
-			normal_short_to_float_v3(fmd->anim_bind[i].no, mvert[n.index].no);
 			i++;
 		}
 
@@ -3958,6 +3983,9 @@ void BKE_read_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool do_bi
 
 			index = fmd->anim_bind[i].mi;
 
+			if (index == -1)
+				continue;
+
 			//only let kinematic rbs do this, active ones are being taken care of by bullet
 			if (mi && mi->rigidbody && mi->rigidbody->flag & RBO_FLAG_KINEMATIC)
 			{
@@ -3976,14 +4004,7 @@ void BKE_read_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool do_bi
 					{
 						if (mi->rigidbody->physics_object && mi->rigidbody->type == RBO_TYPE_ACTIVE)
 						{
-							RigidBodyOb* rbo = mi->rigidbody;
-
-							mi->rigidbody->flag &= ~RBO_FLAG_KINEMATIC;
-							mi->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
-
-							RB_body_set_mass(rbo->physics_object, rbo->mass);
-							RB_body_set_kinematic_state(rbo->physics_object, false);
-							RB_body_activate(rbo->physics_object);
+							activate(mi);
 							continue;
 						}
 					}
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 44d6a64a737..f994247e264 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -101,7 +101,6 @@ static bool isModifierActive(FractureModifierData *rmd);
 static void activateRigidbody(RigidBodyOb* rbo, RigidBodyWorld *UNUSED_rbw, MeshIsland *mi, Object *ob);
 static bool do_update_modifier(Scene* scene, Object* ob, RigidBodyWorld *rbw, bool rebuild);
 static bool do_sync_modifier(ModifierData *md, Object *ob, RigidBodyWorld *rbw, float ctime);
-static bool restoreKinematic(RigidBodyWorld *rbw);
 static void DM_mesh_boundbox(DerivedMesh *bm, float r_loc[3], float r_size[3]);
 static void test_deactivate_rigidbody(RigidBodyOb *rbo);
 static float box_volume(float size[3]);
@@ -2387,7 +2386,7 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
 	}
 	else if (rbw->ltime == startframe)
 	{
-		/*bool did_it = */restoreKinematic(rbw);
+		/*bool did_it = */BKE_restoreKinematic(rbw, false);
 		//if (did_it)
 
 		//make 1st run like later runs... hack...
@@ -5489,7 +5488,7 @@ void rigidbody_passive_fake_parenting(FractureModifierData *fmd, Object *ob, Rig
 	}
 }
 
-static bool restoreKinematic(RigidBodyWorld *rbw)
+bool BKE_restoreKinematic(RigidBodyWorld *rbw, bool override_bind)
 {
 	GroupObject *go;
 	bool did_it = false;
@@ -5503,7 +5502,7 @@ static bool restoreKinematic(RigidBodyWorld *rbw)
 			triggered = go->ob->rigidbody_object->flag & RBO_FLAG_USE_KINEMATIC_DEACTIVATION;
 
 			FractureModifierData *fmd = (FractureModifierData*)modifiers_findByType(go->ob, eModifierType_Fracture);
-			if (fmd && triggered)
+			if (fmd && triggered && (!fmd->use_animated_mesh || (fmd->use_animated_mesh && override_bind)))
 			{
 				MeshIsland* mi;
 				for (mi = fmd->meshIslands.first; mi; mi = mi->next)
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 8a435f1942a..ef6cbe72743 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -2573,13 +2573,26 @@ static int fracture_refresh_invoke(bContext *C, wmOperator *op, const wmEvent *U
 static int fracture_anim_bind_exec(bContext *C, wmOperator *op)
 {
 	Object *obact = ED_object_active_context(C);
+	Scene* scene = CTX_data_scene(C);
 	FractureModifierData *rmd;
 
 	rmd = (FractureModifierData *)modifiers_findByType(obact, eModifierType_Fracture);
 	if (!rmd)
 		return OPERATOR_CANCELLED;
 
+	//restore kinematic here, before bind (and not afterwards !)
+	if (scene && scene->rigidbody_world)
+		BKE_restoreKinematic(scene->rigidbody_world, true);
 	BKE_read_animated_loc_rot(rmd, obact, true);
+
+	DAG_relations_tag_update(G.main);
+	WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+	WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
+	WM_event_add_notifier(C, NC_SCENE | ND_FRAME, NULL);
+
+	DAG_id_tag_update(&obact->id, OB_RECALC_DATA);
+	WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obact);
+
 	return OPERATOR_FINISHED;
 }
 
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index e47dce0c1aa..eb9cec877b8 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1807,6 +1807,7 @@ typedef struct FractureModifierData {
 	float min_acceleration;
 	float max_acceleration;
 	float acceleration_fade;
+	float anim_bind_limit;
 
 	/* flags */
 	int refresh;
@@ -1866,7 +1867,7 @@ typedef struct FractureModifierData {
 	short mat_ofs_intersect;
 	short mat_ofs_difference;
 
-	//char pad[4];
+	char pad[4];
 } FractureModifierData;
 
 typedef struct DataTransferModifierData {
diff --git a/source/blender/makesrna/intern/rna_fracture.c b/source/blender/makesrna/intern/rna_fracture.c
index 6e3b075f528..0fd2497fa24 100644
--- a/source/blender/makesrna/intern/rna_fracture.c
+++ b/source/blender/makesrna/intern/rna_fracture.c
@@ -1520,5 +1520,13 @@ void RNA_def_fracture(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Use Rotation", "Allow moving original vertices to rotate the shards as well");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+	prop = RNA_def_property(srna, "animated_mesh_limit", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "anim_bind_limit");
+	RNA_def_property_range(prop, 0, FLT_MAX);
+	RNA_def_property_ui_text(prop, "Limit", "Maximal distance between shards and verts to perform a bind between");
+	RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 0.1f, 4);
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	RNA_api_fracture(brna, srna);
 }
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index a8c289a12bf..829a00a5f63 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -267,6 +267,7 @@ static void initData(ModifierData *md)
 	fmd->anim_bind = NULL;
 	fmd->anim_bind_len = 0;
 	fmd->anim_mesh_rot = false;
+	fmd->anim_bind_limit = 0.0f;
 }
 
 //XXX TODO, freeing functionality should be in BKE too
@@ -1883,6 +1884,7 @@ static void copyData(ModifierData *md, ModifierData *target)
 	trmd->anim_bind = NULL;
 	//memcpy(trmd->anim_bind, rmd->anim_bind, sizeof(int) * trmd->anim_bind_len);
 	trmd->anim_mesh_rot = rmd->anim_mesh_rot;
+	trmd->anim_bind_limit = rmd->anim_bind_limit;
 }
 
 //XXXX TODO, is BB really useds still ? aint there exact volume calc now ?



More information about the Bf-blender-cvs mailing list