[Bf-blender-cvs] [24ff36d] fracture_modifier: added an autohide filter group, its helpers can be used to animate revelation of cracks which are hidden otherwise. This is basic revelation functionality via object locations and sizes only.

Martin Felke noreply at git.blender.org
Mon Dec 28 15:05:02 CET 2015


Commit: 24ff36d84bf6de936f688d6fc38ce881aaffb4c7
Author: Martin Felke
Date:   Mon Dec 28 15:04:07 2015 +0100
Branches: fracture_modifier
https://developer.blender.org/rB24ff36d84bf6de936f688d6fc38ce881aaffb4c7

added an autohide filter group, its helpers can be used to animate revelation of cracks which are hidden otherwise. This is basic revelation functionality via object locations and sizes only.

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

M	release/scripts/startup/bl_operators/presets.py
M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index b1ca2df..b74b855 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -673,7 +673,8 @@ class AddPresetFracture(AddPresetBase, Operator):
        # "fracture.impulse_dampening",
        # "fracture.directional_factor",
         "fracture.minimum_impulse",
-        "fracture.mass_threshold_factor"
+        "fracture.mass_threshold_factor",
+        "fracture.autohide_filter_group"
     ]
 
     preset_subdir = "fracture"
diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py b/release/scripts/startup/bl_ui/properties_physics_fracture.py
index 0af4970..58dd87a 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -205,6 +205,7 @@ class PHYSICS_PT_fracture_utilities(PhysicButtonsPanel, Panel):
     def draw(self, context):
         layout = self.layout
         md = context.fracture
+        layout.prop(md, "autohide_filter_group", text = "Filter Group")
         col = layout.column(align=True)
         col.prop(md, "autohide_dist")
         col.prop(md, "automerge_dist")
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index c7d0fd2..f739e89 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1540,6 +1540,7 @@ typedef struct FractureID {
 	char pad[4];
 } FractureID;
 
+/* TODO, UNUSED currently !!!! */
 /* fracture settings for different mesh parts, applies to prefracture only */
 typedef struct FractureSetting {
 	struct FractureSetting *next, *prev;
@@ -1624,6 +1625,7 @@ typedef struct FractureModifierData {
 	struct Group *dm_group;
 	struct Group *cluster_group;
 	struct Group *cutter_group;
+	struct Group *autohide_filter_group;
 	struct BMesh *visible_mesh;
 	struct DerivedMesh *visible_mesh_cached;
 	ListBase meshIslands, meshConstraints;
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 095e8fb..ad89e24 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -1198,6 +1198,13 @@ static void rna_FractureModifier_mass_threshold_factor_set(PointerRNA *ptr, floa
 	rmd->refresh_constraints = true;
 }
 
+static void rna_FractureModifier_autohide_filter_group_set(PointerRNA* ptr, PointerRNA value)
+{
+	FractureModifierData *rmd = (FractureModifierData*)ptr->data;
+	rmd->autohide_filter_group = value.data;
+	//rmd->reset_shards = true;
+}
+
 /* NOTE: Curve and array modifiers requires curve path to be evaluated,
  * dependency graph will make sure that curve eval would create such a path,
  * but if curve was already evaluated we might miss path.
@@ -5264,6 +5271,13 @@ static void rna_def_modifier_fracture(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Inner UV Map", "Name of UV map for inner faces");
 	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_FractureModifier_uvlayer_name_set");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "autohide_filter_group", PROP_POINTER, PROP_NONE);
+	RNA_def_property_ui_text(prop, "Autohide Filter Group", "");
+	RNA_def_property_pointer_funcs(prop, NULL, "rna_FractureModifier_autohide_filter_group_set", NULL, NULL);
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
 static void rna_def_modifier_datatransfer(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index f711e8f..3b17649 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -211,6 +211,8 @@ static void initData(ModifierData *md)
 	fmd->directional_factor = 0.0f;
 	fmd->minimum_impulse = 0.1f;
 	fmd->mass_threshold_factor = 0.0f;
+
+	fmd->autohide_filter_group = NULL;
 }
 
 static void freeMeshIsland(FractureModifierData *rmd, MeshIsland *mi, bool remove_rigidbody)
@@ -1467,6 +1469,8 @@ static void copyData(ModifierData *md, ModifierData *target)
 	trmd->minimum_impulse = rmd->minimum_impulse;
 	trmd->mass_threshold_factor = rmd->mass_threshold_factor;
 	trmd->use_compounds = rmd->use_compounds;
+
+	trmd->autohide_filter_group = rmd->autohide_filter_group;
 }
 
 /* mi->bb, its for volume fraction calculation.... */
@@ -2674,7 +2678,7 @@ static void make_face_pairs(FractureModifierData *fmd, DerivedMesh *dm)
 	BLI_kdtree_free(tree);
 }
 
-static void find_other_face(FractureModifierData *fmd, int i, BMesh* bm, BMFace ***faces, int *del_faces)
+static void find_other_face(FractureModifierData *fmd, int i, BMesh* bm, Object* ob, BMFace ***faces, int *del_faces)
 {
 	float f_centr[3], f_centr_other[3];
 	BMFace *f1, *f2;
@@ -2710,15 +2714,48 @@ static void find_other_face(FractureModifierData *fmd, int i, BMesh* bm, BMFace
 	if ((len_squared_v3v3(f_centr, f_centr_other) < (fmd->autohide_dist)) && (f1 != f2) &&
 	    (f1->mat_nr == 1) && (f2->mat_nr == 1))
 	{
-		/*intact face pairs */
-		*faces = MEM_reallocN(*faces, sizeof(BMFace *) * ((*del_faces) + 2));
-		(*faces)[*del_faces] = f1;
-		(*faces)[(*del_faces) + 1] = f2;
-		(*del_faces) += 2;
+		bool in_filter = false;
+
+		/*filter out face pairs, if we have an autohide filter group */
+		if (fmd->autohide_filter_group){
+			GroupObject *go;
+			for (go = fmd->autohide_filter_group->gobject.first; go; go = go->next) {
+				/*check location and scale (maximum size if nonuniform) for now */
+				/*if not in any filter range, delete... else keep */
+				Object* obj = go->ob;
+				float f1_loc[3], f2_loc[3];
+				float radius = MAX3(obj->size[0], obj->size[1], obj->size[2]);
+
+				/* TODO XXX watch out if go->ob is parented to ob (Transformation error ?) */
+				mul_v3_m4v3(f1_loc, ob->obmat, f_centr);
+				mul_v3_m4v3(f2_loc, ob->obmat, f_centr_other);
+				radius = radius * radius;
+
+				if ((len_squared_v3v3(f1_loc, obj->loc) < radius) &&
+					(len_squared_v3v3(f2_loc, obj->loc) < radius))
+				{
+					in_filter = true;
+					break;
+				}
+				else
+				{
+					in_filter = false;
+				}
+			}
+		}
+
+		if (!fmd->autohide_filter_group || !in_filter)
+		{
+			/*intact face pairs */
+			*faces = MEM_reallocN(*faces, sizeof(BMFace *) * ((*del_faces) + 2));
+			(*faces)[*del_faces] = f1;
+			(*faces)[(*del_faces) + 1] = f2;
+			(*del_faces) += 2;
+		}
 	}
 }
 
-static DerivedMesh *do_autoHide(FractureModifierData *fmd, DerivedMesh *dm)
+static DerivedMesh *do_autoHide(FractureModifierData *fmd, DerivedMesh *dm, Object *ob)
 {
 	int totpoly = dm->getNumPolys(dm);
 	int i = 0;
@@ -2734,7 +2771,7 @@ static DerivedMesh *do_autoHide(FractureModifierData *fmd, DerivedMesh *dm)
 	BM_mesh_elem_hflag_disable_all(bm, BM_FACE | BM_EDGE | BM_VERT , BM_ELEM_SELECT, false);
 
 	for (i = 0; i < totpoly; i++) {
-		find_other_face(fmd, i, bm,  &faces, &del_faces);
+		find_other_face(fmd, i, bm, ob,  &faces, &del_faces);
 	}
 
 	for (i = 0; i < del_faces; i++) {
@@ -3123,14 +3160,14 @@ static MDeformVert* do_islands_from_shards(FractureModifierData* fmd, Object* ob
 	return ivert;
 }
 
-static DerivedMesh *output_dm(FractureModifierData* fmd, DerivedMesh *dm, bool exploOK)
+static DerivedMesh *output_dm(FractureModifierData* fmd, DerivedMesh *dm, Object* ob, bool exploOK)
 {
 	if ((fmd->visible_mesh_cached != NULL) && exploOK) {
 		DerivedMesh *dm_final;
 
 		if (fmd->autohide_dist > 0 && fmd->face_pairs) {
-			//printf("Autohide2 \n");
-			dm_final = do_autoHide(fmd, fmd->visible_mesh_cached);
+			//printf("Autohide \n");
+			dm_final = do_autoHide(fmd, fmd->visible_mesh_cached, ob);
 		}
 		else {
 			dm_final = CDDM_copy(fmd->visible_mesh_cached);
@@ -3418,7 +3455,7 @@ static DerivedMesh *doSimulate(FractureModifierData *fmd, Object *ob, DerivedMes
 		do_clear(fmd);
 	}
 
-	return output_dm(fmd, dm, exploOK);
+	return output_dm(fmd, dm, ob, exploOK);
 }
 
 static bool dependsOnTime(ModifierData *UNUSED(md))
@@ -3442,6 +3479,7 @@ static void foreachIDLink(ModifierData *md, Object *ob,
 	walk(userData, ob, (ID **)&fmd->dm_group);
 	walk(userData, ob, (ID **)&fmd->cluster_group);
 	walk(userData, ob, (ID **)&fmd->cutter_group);
+	walk(userData, ob, (ID **)&fmd->autohide_filter_group);
 
 	for (fs = fmd->fracture_settings.first; fs; fs = fs->next)
 	{
@@ -3474,7 +3512,19 @@ static void updateDepgraph(ModifierData *md, DagForest *forest,
 			{
 				DagNode *curNode = dag_get_node(forest, go->ob);
 				dag_add_relation(forest, curNode, obNode,
-				                 DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Fracture Modifier");
+				                 DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Fracture Modifier Extra Group");
+			}
+		}
+	}
+
+	if (fmd->autohide_filter_group) {
+		GroupObject *go;
+		for (go = fmd->autohide_filter_group->gobject.first; go; go = go->next) {
+			if (go->ob)
+			{
+				DagNode *curNode = dag_get_node(forest, go->ob);
+				dag_add_relation(forest, curNode, obNode,
+				                 DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Fracture Modifier Autohide Filter Group");
 			}
 		}
 	}
@@ -3506,6 +3556,15 @@ static void foreachObjectLink(
 	}
 
 	//TODO, walking over fracture settings, too ?
+
+	if (fmd->autohide_filter_group) {
+		GroupObject *go;
+		for (go = fmd->autohide_filter_group->gobject.first; go; go = go->next) {
+			if (go->ob) {
+				walk(userData, ob, &go->ob);
+			}
+		}
+	}
 }
 
 static ShardSequence* shard_sequence_add(FractureModifierData* fmd, float frame, DerivedMesh* dm)




More information about the Bf-blender-cvs mailing list