[Bf-blender-cvs] [5f562577132] fracture_modifier: added basic material handling and outputting vertexgroups for intersect/difference shards with cuttergroups

Martin Felke noreply at git.blender.org
Sun Mar 12 13:12:11 CET 2017


Commit: 5f562577132fb3a6c4e3d718846c182393576b74
Author: Martin Felke
Date:   Sun Mar 12 13:11:52 2017 +0100
Branches: fracture_modifier
https://developer.blender.org/rB5f562577132fb3a6c4e3d718846c182393576b74

added basic material handling and outputting vertexgroups for intersect/difference shards with cuttergroups

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

M	release/scripts/startup/bl_operators/presets.py
M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	source/blender/blenkernel/intern/fracture.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_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index 637cf4551c8..f521cb0b761 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -684,7 +684,9 @@ class AddPresetFracture(AddPresetBase, Operator):
         "fracture.dynamic_new_constraints",
         "fracture.dynamic_min_size",
         "fracture.use_constraint_collision",
-        "fracture.inner_crease"
+        "fracture.inner_crease",
+        "fracture.material_offset_difference",
+        "fracture.material_offset_intersect"
     ]
 
     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 c1217d02764..20d5e96dbca 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -151,6 +151,10 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel):
                 col.prop(md, "cutter_group")
                 if (md.cutter_group):
                    col.prop(md, "keep_cutter_shards")
+                   col.label("Material Index Offset")
+                   row = col.row(align=True)
+                   row.prop(md, "material_offset_intersect", text="Intersect")
+                   row.prop(md, "material_offset_difference", text="Difference")
             col.prop(md, "use_particle_birth_coordinates")
 
             box.prop(md, "percentage")
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index aa986e90647..3d267e662f1 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -1313,6 +1313,47 @@ static void stroke_to_faces(FractureModifierData *fmd, BMesh** bm, bGPDstroke *g
 	}
 }
 
+static void add_vgroup(Shard *s, Object *ob, const char* name)
+{
+	int index = 0, i = 0;
+	MDeformVert *dvert;
+	if (!defgroup_find_name(ob, name)) {
+		BKE_defgroup_new(ob, name);
+	}
+	index = defgroup_name_index(ob, name);
+	dvert = CustomData_get_layer(&s->vertData, CD_MDEFORMVERT);
+	if (dvert == NULL) {
+		dvert = CustomData_add_layer(&s->vertData, CD_MDEFORMVERT, CD_CALLOC, NULL, s->totvert);
+	}
+	for (i = 0; i < s->totvert; i++) {
+		MDeformVert* dv = dvert + i;
+		defvert_add_index_notest(dv, index, 1.0f);
+	}
+}
+
+static void add_material(Shard* s, Object *ob, short mat_ofs) {
+
+	/* only use material offsets if we have 3 or more materials; since FM material handling still is a bit odd  */
+	/* todo, use index for inner material too, then this hack here isnt necessary any more */
+
+	const short mat_nr_max = ob->totcol > 1 ? ob->totcol - 1 : 0;
+	mat_ofs = mat_nr_max ? mat_ofs : 0;
+
+	if (mat_ofs) {
+		MPoly *mp;
+		int i = 0;
+
+		for (i = 0; i < s->totpoly; i++)
+		{
+			mp = s->mpoly + i;
+			mp->mat_nr = mat_ofs;
+
+			//hrm first material and second (inner) should be untouched...
+			CLAMP(mp->mat_nr, 0, mat_nr_max);
+		}
+	}
+}
+
 static void do_intersect(FractureModifierData *fmd, Object* ob, Shard *t, short inner_mat_index,
                          bool is_zero, float mat[4][4], int **shard_counts, int* count,
                          int k, DerivedMesh **dm_parent, bool keep_other_shard, int solver, float thresh)
@@ -1349,6 +1390,8 @@ static void do_intersect(FractureModifierData *fmd, Object* ob, Shard *t, short
 
 	if (ELEM(fmd->keep_cutter_shards, MOD_FRACTURE_KEEP_BOTH, MOD_FRACTURE_KEEP_INTERSECT)) {
 		if (s != NULL) {
+			add_vgroup(s, ob, "Intersect");
+			add_material(s, ob, fmd->mat_ofs_intersect);
 			add_shard(fmd->frac_mesh, s, mat);
 			shards++;
 			s = NULL;
@@ -1357,6 +1400,8 @@ static void do_intersect(FractureModifierData *fmd, Object* ob, Shard *t, short
 
 	if (ELEM(fmd->keep_cutter_shards, MOD_FRACTURE_KEEP_BOTH, MOD_FRACTURE_KEEP_DIFFERENCE)) {
 		if (s2 != NULL) {
+			add_vgroup(s2, ob, "Difference");
+			add_material(s2, ob, fmd->mat_ofs_difference);
 			add_shard(fmd->frac_mesh, s2, mat);
 			shards++;
 			s2 = NULL;
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 2a726490783..0684abf41a6 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1786,8 +1786,10 @@ typedef struct FractureModifierData {
 	int defstart;
 
 	int keep_cutter_shards;
+	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 b8bdfe3712a..459b0b0fcd3 100644
--- a/source/blender/makesrna/intern/rna_fracture.c
+++ b/source/blender/makesrna/intern/rna_fracture.c
@@ -1228,5 +1228,17 @@ void RNA_def_fracture(BlenderRNA *brna)
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 	//RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+	prop = RNA_def_property(srna, "material_offset_intersect", PROP_INT, PROP_NONE);
+	RNA_def_property_int_sdna(prop, NULL, "mat_ofs_intersect");
+	RNA_def_property_range(prop, 0, SHRT_MAX);
+	RNA_def_property_ui_text(prop, "Intersect Material Offset", "Offset material index of intersected shards");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "material_offset_difference", PROP_INT, PROP_NONE);
+	RNA_def_property_int_sdna(prop, NULL, "mat_ofs_difference");
+	RNA_def_property_range(prop, 0, SHRT_MAX);
+	RNA_def_property_ui_text(prop, "Difference Material Offset", "Offset material index of difference shards");
+	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 7f0a66ea744..7e258e3587c 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -231,6 +231,9 @@ static void initData(ModifierData *md)
 	fmd->use_constraint_collision = false;
 	fmd->inner_crease = 0.0f;
 	fmd->is_dynamic_external = false;
+
+	fmd->mat_ofs_difference = 0;
+	fmd->mat_ofs_intersect = 0;
 }
 
 //XXX TODO, freeing functionality should be in BKE too
@@ -1661,8 +1664,9 @@ static void do_fracture(FractureModifierData *fmd, ShardID id, Object *obj, Deri
 		bool reset = fmd->reset_shards;
 
 		unit_m4(mat);
-		mat_index = do_materials(fmd, obj);
-		mat_index = mat_index > 0 ? mat_index - 1 : mat_index;
+		//mat_index = do_materials(fmd, obj);
+		//mat_index = mat_index > 0 ? mat_index - 1 : mat_index;
+
 
 		BKE_fracture_shard_by_planes(fmd, obj, mat_index, mat);
 
@@ -1812,6 +1816,9 @@ static void copyData(ModifierData *md, ModifierData *target)
 	trmd->use_constraint_collision = rmd->use_constraint_collision;
 	trmd->inner_crease = rmd->inner_crease;
 	trmd->is_dynamic_external = rmd->is_dynamic_external;
+
+	trmd->mat_ofs_difference = rmd->mat_ofs_difference;
+	trmd->mat_ofs_intersect = rmd->mat_ofs_intersect;
 }
 
 //XXXX TODO, is BB really useds still ? aint there exact volume calc now ?




More information about the Bf-blender-cvs mailing list