[Bf-blender-cvs] [4eb44b86100] fracture_modifier: another implementation attempt for external constraints

Martin Felke noreply at git.blender.org
Tue Feb 13 18:08:07 CET 2018


Commit: 4eb44b86100be814ed2a21699435cf76cc5e1600
Author: Martin Felke
Date:   Tue Feb 13 18:07:41 2018 +0100
Branches: fracture_modifier
https://developer.blender.org/rB4eb44b86100be814ed2a21699435cf76cc5e1600

another implementation attempt for external constraints

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

M	release/scripts/startup/bl_operators/presets.py
M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/blenloader/intern/readfile.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 41e3a6f42c6..46821910176 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -712,6 +712,7 @@ class AddPresetFracture(AddPresetBase, Operator):
         "fracture.use_animated_mesh_rotation",
         "fracture.grid_offset",
         "fracture.grid_spacing",
+        "fracture.use_constraint_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 7be6be4b345..561a0f2d564 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -163,6 +163,7 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel):
                 col.prop(md, "cutter_axis")
             col.prop(md, "extra_group")
             col.prop(md, "dm_group")
+            col.prop(md, "use_constraint_group")
             col.prop(md, "cutter_group")
             if (md.cutter_group):
                 col.prop(md, "keep_cutter_shards")
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index e6a9e3f7a11..9012b236005 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -4119,6 +4119,11 @@ static bool check_constraint_island(FractureModifierData* fmd, MeshIsland *mi1,
 
 	}
 
+	if (fmd)
+	{
+		return !(fmd->dm_group && fmd->use_constraint_collision);
+	}
+
 	return true;
 }
 
@@ -4229,10 +4234,12 @@ static int filterCallback(void* world, void* island1, void* island2, void *blend
 		validOb = validOb || ((mi1 && (mi1->rigidbody->flag & RBO_FLAG_KINEMATIC) == 0)) || ((ob2->rigidbody_object->flag & RBO_FLAG_KINEMATIC) == 0);
 		validOb = validOb || ((mi1 && (mi1->rigidbody->flag & RBO_FLAG_KINEMATIC) == 0)) || ((mi2 && mi2->rigidbody->flag & RBO_FLAG_KINEMATIC) == 0);
 
-		validOb = validOb && (check_colgroup_ghost(ob1, ob2) && ((check_constraint_island(fmd1, mi1, mi2) && check_constraint_island(fmd2, mi2, mi1)) || (ob1 != ob2)));
+		validOb = validOb && (check_colgroup_ghost(ob1, ob2) && ((check_constraint_island(fmd1, mi1, mi2) &&
+		          check_constraint_island(fmd2, mi2, mi1)) || ((ob1 != ob2) && !(fmd1 && fmd2))));
 	}
 	else {
-		validOb = (check_colgroup_ghost(ob1, ob2) && ((check_constraint_island(fmd1, mi1, mi2) && check_constraint_island(fmd2, mi2, mi1)) || (ob1 != ob2)));
+		validOb = (check_colgroup_ghost(ob1, ob2) && ((check_constraint_island(fmd1, mi1, mi2) &&
+		          check_constraint_island(fmd2, mi2, mi1)) || ((ob1 != ob2) && !(fmd1 && fmd2))));
 	}
 
 	return activate ? validOb : check_activate || validOb;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 627aef36331..8a37e814ca1 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -9181,7 +9181,7 @@ static void fix_fracture_image_hack(Main* main)
 
 	for (ob = main->object.first; ob; ob = ob->id.next) {
 		FractureModifierData *fmd = (FractureModifierData*)modifiers_findByType(ob, eModifierType_Fracture);
-		if (fmd && fmd->dm_group) {
+		if (fmd && fmd->dm_group && !fmd->use_constraint_group) {
 			fmd->refresh_images = true;
 			fmd->refresh = true;
 		}
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 450ffa30ddf..5d8306ad26e 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1830,6 +1830,7 @@ typedef struct FractureModifierData {
 	int use_constraint_collision;
 	int use_self_collision;
 	int use_animated_mesh;
+	int use_constraint_group;
 
 	int shards_to_islands;
 	int execute_threaded;
@@ -1872,7 +1873,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 5a44f2d3c0e..f6d817f2b24 100644
--- a/source/blender/makesrna/intern/rna_fracture.c
+++ b/source/blender/makesrna/intern/rna_fracture.c
@@ -653,6 +653,14 @@ static void rna_FractureModifier_anim_mesh_ob_set(PointerRNA* ptr, PointerRNA va
 	rmd->anim_mesh_ob = value.data;
 }
 
+static void rna_FractureModifier_use_constraint_group_set(PointerRNA* ptr, int value)
+{
+	FractureModifierData *rmd = (FractureModifierData *)ptr->data;
+	rmd->use_constraint_group = value;
+	//rmd->refresh_constraints = true;
+}
+
+
 static void rna_Modifier_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
 	ModifierData* md = ptr->data;
@@ -1548,5 +1556,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, "use_constraint_group", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "use_constraint_group", false);
+	//RNA_def_property_boolean_funcs(prop, NULL, "rna_FractureModifier_use_constraint_group_set");
+	RNA_def_property_ui_text(prop, "Constraints Only", "Only manage the external constraints in this Fracture Modifier");
+	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 f5d5e3e627d..fa479b5772f 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -270,6 +270,7 @@ static void initData(ModifierData *md)
 	fmd->anim_bind_limit = 0.0f;
 	zero_v3(fmd->grid_offset);
 	zero_v3(fmd->grid_spacing);
+	fmd->use_constraint_group = false;
 }
 
 //XXX TODO, freeing functionality should be in BKE too
@@ -1923,6 +1924,8 @@ static void copyData(ModifierData *md, ModifierData *target)
 	trmd->anim_bind_limit = rmd->anim_bind_limit;
 	copy_v3_v3(trmd->grid_offset, rmd->grid_offset);
 	copy_v3_v3(trmd->grid_spacing, rmd->grid_spacing);
+
+	trmd->use_constraint_group = rmd->use_constraint_group;
 }
 
 //XXXX TODO, is BB really useds still ? aint there exact volume calc now ?
@@ -2631,7 +2634,72 @@ static void connect_meshislands(FractureModifierData *fmd, MeshIsland *mi1, Mesh
 	}
 
 	if (!con_found && ok) {
-		BKE_meshisland_constraint_create(fmd, mi1, mi2, con_type, thresh);
+
+		if (fmd->dm_group && fmd->use_constraint_group) {
+			//map back to "original" mesh islands and only create here if objects differ
+			int index1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(fmd->vert_index_map, SET_INT_IN_POINTER(mi1->vertex_indices[0])));
+			int index2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(fmd->vert_index_map, SET_INT_IN_POINTER(mi2->vertex_indices[0])));
+			bool error = false;
+
+			if (index1 != index2)
+			{
+				//different index in group, different objects
+				Object *ob1 = NULL, *ob2 = NULL;
+				FractureModifierData *fmd1 = NULL, *fmd2 = NULL;
+				MeshIsland *mi_1 = NULL, *mi_2 = NULL;
+				int i = 0;
+				int v = 0, v1 = 0, v2 = 0;
+
+				GroupObject *go;
+				DerivedMesh *dm;
+
+				for (go = fmd->dm_group->gobject.first; go; go = go->next)
+				{
+					if (i == index1)
+					{
+						ob1 = go->ob;
+						v1 = v;
+					}
+
+					if (i == index2)
+					{
+						ob2 = go->ob;
+						v2 = v;
+					}
+
+					i++;
+
+					dm = get_object_dm(go->ob);
+					if (!dm) {
+						error = true;
+						break;
+					}
+
+					v += dm->getNumVerts(dm);
+				}
+
+				if (ob1 && ob2 && !error)
+				{
+					fmd1 = (FractureModifierData*)modifiers_findByType(ob1, eModifierType_Fracture);
+					fmd2 = (FractureModifierData*)modifiers_findByType(ob2, eModifierType_Fracture);
+
+					if (fmd1 && fmd2)
+					{
+						mi_1 = BLI_ghash_lookup(fmd1->vertex_island_map, SET_INT_IN_POINTER(mi1->vertex_indices[0] - v1));
+						mi_2 = BLI_ghash_lookup(fmd2->vertex_island_map, SET_INT_IN_POINTER(mi2->vertex_indices[0] - v2));
+
+						if (mi_1 && mi_2)
+						{
+							BKE_meshisland_constraint_create(fmd, mi_1, mi_2, con_type, thresh);
+						}
+					}
+				}
+			}
+		}
+		else
+		{
+			BKE_meshisland_constraint_create(fmd, mi1, mi2, con_type, thresh);
+		}
 	}
 }
 
@@ -5075,6 +5143,15 @@ static DerivedMesh *do_prefractured(FractureModifierData *fmd, Object *ob, Deriv
 		final_dm = doSimulate(fmd, ob, clean_dm, clean_dm, NULL, 0);
 	}
 
+	if (fmd->dm_group && fmd->use_constraint_group)
+	{
+		//remove collected mesh here
+		final_dm = derivedData;
+
+		//remove own, unnecessary meshislands and rigidbodies
+		free_meshislands(fmd, &fmd->meshIslands, true);
+	}
+
 	/* free newly created derivedmeshes only, but keep derivedData and final_dm*/
 	if ((clean_dm != group_dm) && (clean_dm != derivedData) && (clean_dm != final_dm))
 	{



More information about the Bf-blender-cvs mailing list