[Bf-blender-cvs] [d159161155] fracture_modifier: retain existing creases, added inner crease and interpolate edge data with carve now

Martin Felke noreply at git.blender.org
Sun Jan 8 14:31:28 CET 2017


Commit: d159161155ea19e0fd4a197a42824ad04d880e84
Author: Martin Felke
Date:   Sun Jan 8 14:31:01 2017 +0100
Branches: fracture_modifier
https://developer.blender.org/rBd159161155ea19e0fd4a197a42824ad04d880e84

retain existing creases, added inner crease and interpolate edge data with carve now

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

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_boolean_util_carve.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 95edcef75d..637cf4551c 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -683,7 +683,8 @@ class AddPresetFracture(AddPresetBase, Operator):
         "fracture.dynamic_percentage",
         "fracture.dynamic_new_constraints",
         "fracture.dynamic_min_size",
-        "fracture.use_constraint_collision"
+        "fracture.use_constraint_collision",
+        "fracture.inner_crease"
     ]
 
     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 b2c47d5007..c1217d0276 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -160,6 +160,7 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel):
             box.prop_search(md, "ground_vertex_group", ob, "vertex_groups", text = "")
             box.label("Inner Vertex Group:")
             box.prop_search(md, "inner_vertex_group", ob, "vertex_groups", text = "")
+            box.prop(md, "inner_crease")
 
         layout.context_pointer_set("modifier", md)
         row = layout.row()
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 0147f5b8af..a05c1d1d19 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -212,6 +212,7 @@ Shard *BKE_custom_data_to_shard(Shard *s, DerivedMesh *dm)
 	CustomData_copy(&dm->vertData, &s->vertData, CD_MASK_MDEFORMVERT, CD_DUPLICATE, s->totvert);
 	CustomData_copy(&dm->loopData, &s->loopData, CD_MASK_MLOOPUV, CD_DUPLICATE, s->totloop);
 	CustomData_copy(&dm->polyData, &s->polyData, CD_MASK_MTEXPOLY, CD_DUPLICATE, s->totpoly);
+	CustomData_copy(&dm->edgeData, &s->edgeData, CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_MEDGE, CD_DUPLICATE, s->totedge);
 
 	return s;
 }
@@ -1825,6 +1826,7 @@ static void do_marking(FractureModifierData *fmd, DerivedMesh *result)
 				MLoop ml;
 				ml = mloop[mp->loopstart + j];
 				medge[ml.e].flag |= ME_SHARP;
+				medge[ml.e].crease = fmd->inner_crease * 255.0f;
 				mvert[ml.v].flag |= ME_VERT_TMP_TAG;
 			}
 
@@ -1882,6 +1884,7 @@ static DerivedMesh* do_create(FractureModifierData *fmd, int num_verts, int num_
 			CustomData_merge(&s->vertData, &result->vertData, CD_MASK_MDEFORMVERT, CD_CALLOC, num_verts);
 			CustomData_merge(&s->polyData, &result->polyData, CD_MASK_MTEXPOLY, CD_CALLOC, num_polys);
 			CustomData_merge(&s->loopData, &result->loopData, CD_MASK_MLOOPUV, CD_CALLOC, num_loops);
+			CustomData_merge(&s->edgeData, &result->edgeData, CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_MEDGE, CD_CALLOC, num_edges);
 		}
 		else
 		{
@@ -1889,6 +1892,8 @@ static DerivedMesh* do_create(FractureModifierData *fmd, int num_verts, int num_
 			CustomData_add_layer(&result->vertData, CD_MDEFORMVERT, CD_CALLOC, NULL, num_verts);
 			CustomData_add_layer(&result->polyData, CD_MTEXPOLY, CD_CALLOC, NULL, num_polys);
 			CustomData_add_layer(&result->loopData, CD_MLOOPUV, CD_CALLOC, NULL, num_loops);
+			CustomData_add_layer(&result->edgeData, CD_CREASE, CD_CALLOC, NULL, num_edges);
+			CustomData_add_layer(&result->edgeData, CD_BWEIGHT, CD_CALLOC, NULL, num_edges);
 		}
 	}
 
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 8a4fc609bd..f8c40407d2 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1738,6 +1738,7 @@ typedef struct FractureModifierData {
 	float mass_threshold_factor;
 	float boolean_double_threshold;
 	float dynamic_min_size;
+	float inner_crease;
 
 	/* flags */
 	int refresh;
@@ -1785,7 +1786,7 @@ typedef struct FractureModifierData {
 
 	int keep_cutter_shards;
 
-	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 ebe959f947..855c123bd1 100644
--- a/source/blender/makesrna/intern/rna_fracture.c
+++ b/source/blender/makesrna/intern/rna_fracture.c
@@ -1215,5 +1215,12 @@ 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, "inner_crease", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "inner_crease");
+	RNA_def_property_range(prop, 0.0f, 1.0f);
+	RNA_def_property_float_default(prop, 0.0f);
+	RNA_def_property_ui_text(prop, "Inner Crease",  "Crease at edges of inner faces");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	RNA_api_fracture(brna, srna);
 }
diff --git a/source/blender/modifiers/intern/MOD_boolean_util_carve.c b/source/blender/modifiers/intern/MOD_boolean_util_carve.c
index 5fc0d569cd..efe8e84cc1 100644
--- a/source/blender/modifiers/intern/MOD_boolean_util_carve.c
+++ b/source/blender/modifiers/intern/MOD_boolean_util_carve.c
@@ -66,9 +66,13 @@ static void DM_loop_interp_from_poly(DerivedMesh *source_dm,
 	float (*cos_3d)[3] = BLI_array_alloca(cos_3d, source_poly->totloop);
 	int *source_indices = BLI_array_alloca(source_indices, source_poly->totloop);
 	int *source_vert_indices = BLI_array_alloca(source_vert_indices, source_poly->totloop);
+	int *source_edge_indices = BLI_array_alloca(source_edge_indices, source_poly->totloop);
 	float *weights = BLI_array_alloca(weights, source_poly->totloop);
+	EdgeVertWeight *vweights = BLI_array_alloca(vweights, source_poly->totloop);
+
 	int i;
 	int target_vert_index = target_mloop[target_loop_index].v;
+	int target_edge_index = target_mloop[target_loop_index].e;
 	float coord[3];
 
 	for (i = 0; i < source_poly->totloop; ++i) {
@@ -93,6 +97,9 @@ static void DM_loop_interp_from_poly(DerivedMesh *source_dm,
 	/* interpolate vertex data as well, for painted weights interpolation on fracture modifier */
 	DM_interp_vert_data(source_dm, target_dm, source_vert_indices ,weights,
 	                    source_poly->totloop, target_vert_index);
+
+	/*interpolate edge data as well, to keep creases and bweights hopefully */
+	DM_interp_edge_data(source_dm, target_dm, source_edge_indices, weights, vweights, source_poly->totloop, target_edge_index);
 }
 
 typedef struct DMArrays {
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index d6d1f4bb8c..bc50cadf17 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -228,6 +228,7 @@ static void initData(ModifierData *md)
 	fmd->dynamic_min_size = 1.0f;
 	fmd->keep_cutter_shards = MOD_FRACTURE_KEEP_BOTH;
 	fmd->use_constraint_collision = false;
+	fmd->inner_crease = 0.0f;
 }
 
 //XXX TODO, freeing functionality should be in BKE too
@@ -1798,6 +1799,7 @@ static void copyData(ModifierData *md, ModifierData *target)
 	trmd->dynamic_min_size = rmd->dynamic_min_size;
 	trmd->keep_cutter_shards = rmd->keep_cutter_shards;
 	trmd->use_constraint_collision = rmd->use_constraint_collision;
+	trmd->inner_crease = rmd->inner_crease;
 }
 
 //XXXX TODO, is BB really useds still ? aint there exact volume calc now ?
@@ -3985,7 +3987,7 @@ static void foreachIDLink(ModifierData *md, Object *ob,
 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(md))
 {
 	CustomDataMask dataMask = 0;
-	dataMask |= CD_MASK_MDEFORMVERT;
+	dataMask |= CD_MASK_MDEFORMVERT | CD_MASK_MLOOPUV | CD_MASK_MTEXPOLY | CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_MEDGE;
 	return dataMask;
 }
 
@@ -4426,6 +4428,7 @@ static Shard* copy_shard(Shard *s)
 	CustomData_copy(&s->vertData, &t->vertData, CD_MASK_MDEFORMVERT, CD_DUPLICATE, s->totvert);
 	CustomData_copy(&s->loopData, &t->loopData, CD_MASK_MLOOPUV, CD_DUPLICATE, s->totloop);
 	CustomData_copy(&s->polyData, &t->polyData, CD_MASK_MTEXPOLY, CD_DUPLICATE, s->totpoly);
+	CustomData_copy(&s->edgeData, &t->edgeData, CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_MEDGE, CD_DUPLICATE, s->totedge);
 
 	t->neighbor_count = t->neighbor_count;
 	t->neighbor_ids = MEM_mallocN(sizeof(int) * s->neighbor_count, __func__);
@@ -4484,6 +4487,12 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 			return CDDM_copy(fmd->visible_mesh_cached);
 	}
 
+	if (final_dm != derivedData)
+	{
+		//dont forget to create customdatalayers for crease and bevel weights (else they wont be drawn in editmode)
+		final_dm->cd_flag |= (ME_CDFLAG_EDGE_CREASE | ME_CDFLAG_VERT_BWEIGHT | ME_CDFLAG_EDGE_BWEIGHT);
+	}
+
 	return final_dm;
 }




More information about the Bf-blender-cvs mailing list