[Bf-blender-cvs] [9bf8ba16c28] fracture_modifier: added an acceleration map (vgroup), some remesher fixes

Martin Felke noreply at git.blender.org
Mon Dec 25 16:45:48 CET 2017


Commit: 9bf8ba16c28fd9e058fc58fa03529f6a287644f9
Author: Martin Felke
Date:   Mon Dec 25 16:45:27 2017 +0100
Branches: fracture_modifier
https://developer.blender.org/rB9bf8ba16c28fd9e058fc58fa03529f6a287644f9

added an acceleration map (vgroup), some remesher fixes

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

M	release/scripts/startup/bl_operators/presets.py
M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	source/blender/blenkernel/intern/mball_tessellate.c
M	source/blender/blenkernel/intern/rigidbody.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
M	source/blender/modifiers/intern/MOD_remesh.c

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

diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index 87ae6fcfe71..3eec5077eef 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -703,6 +703,8 @@ class AddPresetFracture(AddPresetBase, Operator):
         "fracture.use_vertices",
         "fracture.use_self_collision",
         "fracture.grid_resolution"
+        "fracture.min_acceleration",
+        "fracture.max_acceleration",
     ]
 
     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 29c821d6228..95a4f88c047 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -167,6 +167,11 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel):
             box.label("Inner Vertex Group:")
             box.prop_search(md, "inner_vertex_group", ob, "vertex_groups", text = "")
             box.prop(md, "inner_crease")
+            box.label("Acceleration Map:")
+            box.prop_search(md, "acceleration_vertex_group", ob, "vertex_groups", text = "")
+            row = box.row(align=True)
+            row.prop(md, "min_acceleration")
+            row.prop(md, "max_acceleration")
             if (md.frac_algorithm in {'BISECT_FAST', 'BISECT_FAST_FILL'}):
                 box.prop(md, "orthogonality_factor", text="Rectangular Alignment")
 
diff --git a/source/blender/blenkernel/intern/mball_tessellate.c b/source/blender/blenkernel/intern/mball_tessellate.c
index c1e43264fa2..21f73d2d931 100644
--- a/source/blender/blenkernel/intern/mball_tessellate.c
+++ b/source/blender/blenkernel/intern/mball_tessellate.c
@@ -1485,6 +1485,9 @@ void BKE_dm_from_metaball(DispList *dl, DerivedMesh *dm)
 		allloop = mloop = dm->getLoopArray(dm);
 		mpoly = dm->getPolyArray(dm);
 
+		//this will be recalculated here
+		dm->numLoopData = 0;
+
 		a = dl->nr;
 		nors = dl->nors;
 		verts = dl->verts;
@@ -1520,6 +1523,9 @@ void BKE_dm_from_metaball(DispList *dl, DerivedMesh *dm)
 
 		CDDM_calc_normals(dm);
 		CDDM_calc_edges(dm);
+		//CDDM_recalc_tessellation(dm);
+		CDDM_recalc_looptri(dm);
+		dm->dirty |= DM_DIRTY_NORMALS;
 	}
 }
 
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 061c526c4f2..04d2592df19 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -63,6 +63,7 @@
 
 #include "BKE_cdderivedmesh.h"
 #include "BKE_depsgraph.h"
+#include "BKE_deform.h"
 #include "BKE_effect.h"
 #include "BKE_fracture.h"
 #include "BKE_global.h"
@@ -4316,6 +4317,52 @@ static bool check_constraints(FractureModifierData *fmd, MeshIsland *mi, RigidBo
 	return false;
 }
 
+static void updateAccelerationMap(FractureModifierData *fmd, RigidBodyOb* rbo, Object* ob, rbContactPoint* cp)
+{
+	const int acc_defgrp_index = defgroup_name_index(ob, fmd->acceleration_defgrp_name);
+	MeshIsland *mi = findMeshIsland(fmd, rbo->meshisland_index);
+	DerivedMesh *dm = fmd->visible_mesh_cached;
+	MDeformVert *dvert = NULL, *dv;
+	MDeformWeight *dw = NULL;
+	float weight = 0.0f, denom;
+	int i = 0, w = 0;
+	int totvert = dm->getNumVerts(dm);
+
+	dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
+
+	if (dvert == NULL)
+	{
+		dvert = CustomData_add_layer(&dm->vertData, CD_MDEFORMVERT, CD_CALLOC,
+	                             NULL, totvert);
+	}
+
+	//calculate weight from force...
+	denom = fmd->max_acceleration - fmd->min_acceleration;
+
+	//sanity check
+	if (denom == 0.0f)
+		denom = 1.0f;
+
+	weight = (cp->contact_force - fmd->min_acceleration) / denom;
+
+	for (i = 0; i < mi->vertex_count; i++)
+	{
+		dv = dvert + mi->vertex_indices[i];
+		if (dv) {
+			if (dv->dw == NULL) {
+				defvert_add_index_notest(dv, acc_defgrp_index, 0.0f);
+			}
+
+			for (dw = dv->dw, w = 0; w < dv->totweight; dw++, w++)
+			{
+				if (dw->def_nr == acc_defgrp_index) {
+					dw->weight = weight;
+				}
+			}
+		}
+	}
+}
+
 static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw, Object *obA, Object *obB)
 {
 	int linear_index1, linear_index2;
@@ -4354,6 +4401,11 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw, Object *obA,
 		ob1 = rbw->objects[ob_index1];
 		fmd1 = (FractureModifierData*)modifiers_findByType(ob1, eModifierType_Fracture);
 
+		if (fmd1)
+		{
+			updateAccelerationMap(fmd1, rbw->cache_index_map[linear_index1], ob1,  cp);
+		}
+
 		if (fmd1 && fmd1->fracture_mode == MOD_FRACTURE_DYNAMIC)
 		{
 			if (fmd1->current_shard_entry && fmd1->current_shard_entry->is_new)
@@ -4408,6 +4460,11 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw, Object *obA,
 		//ob2 = rbw->objects[ob_index2];
 		fmd2 = (FractureModifierData*)modifiers_findByType(ob2, eModifierType_Fracture);
 
+		if (fmd2)
+		{
+			updateAccelerationMap(fmd2, rbw->cache_index_map[linear_index2], ob2, cp);
+		}
+
 		if (fmd2 && fmd2->fracture_mode == MOD_FRACTURE_DYNAMIC)
 		{
 			if (fmd2->current_shard_entry && fmd2->current_shard_entry->is_new)
@@ -4454,10 +4511,14 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw, Object *obA,
 	cp = NULL;
 }
 
+static ThreadMutex acceleration_lock = BLI_MUTEX_INITIALIZER;
 static void contactCallback(rbContactPoint* cp, void* world)
 {
 	RigidBodyWorld *rbw = (RigidBodyWorld*)world;
+
+	BLI_mutex_lock(&acceleration_lock);
 	check_fracture(cp, rbw, NULL, NULL);
+	BLI_mutex_unlock(&acceleration_lock);
 }
 
 static void idCallback(void *world, void* island, int* objectId, int* islandId)
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index be9682ecd11..498ee71e018 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1694,6 +1694,7 @@ typedef struct FractureModifierData {
 	char thresh_defgrp_name[64];  /* MAX_VGROUP_NAME */
 	char ground_defgrp_name[64];  /* MAX_VGROUP_NAME */
 	char inner_defgrp_name[64];  /* MAX_VGROUP_NAME */
+	char acceleration_defgrp_name[64]; /* MAX_VGROUP_NAME */
 	char uvlayer_name[64];  /* MAX_CUSTOMDATA_LAYER_NAME */
 	struct KDTree *nor_tree; /* store original vertices here (coords), to find them later and reuse their normals */
 	struct Material *inner_material;
@@ -1771,6 +1772,8 @@ typedef struct FractureModifierData {
 	float dynamic_min_size;
 	float inner_crease;
 	float orthogonality_factor;
+	float min_acceleration;
+	float max_acceleration;
 
 	/* flags */
 	int refresh;
diff --git a/source/blender/makesrna/intern/rna_fracture.c b/source/blender/makesrna/intern/rna_fracture.c
index 9aaa1fbfeee..566ab9674d0 100644
--- a/source/blender/makesrna/intern/rna_fracture.c
+++ b/source/blender/makesrna/intern/rna_fracture.c
@@ -198,6 +198,7 @@ static void rna_##_type##Modifier_##_prop##_set(PointerRNA *ptr, const char *val
 RNA_MOD_VGROUP_NAME_SET(Fracture, thresh_defgrp_name);
 RNA_MOD_VGROUP_NAME_SET(Fracture, ground_defgrp_name);
 RNA_MOD_VGROUP_NAME_SET(Fracture, inner_defgrp_name);
+RNA_MOD_VGROUP_NAME_SET(Fracture, acceleration_defgrp_name);
 
 #undef RNA_MOD_VGROUP_NAME_SET
 
@@ -631,6 +632,21 @@ static void rna_FractureModifier_cluster_group_set(PointerRNA* ptr, PointerRNA v
 	rmd->refresh_constraints = true;
 }
 
+//cant really update outside sim, without live values
+static void rna_FractureModifier_max_acceleration_set(PointerRNA *ptr, float value)
+{
+	FractureModifierData *rmd = (FractureModifierData *)ptr->data;
+	rmd->max_acceleration = value;
+	//rmd->refresh_constraints = true;
+}
+
+static void rna_FractureModifier_min_acceleration_set(PointerRNA *ptr, float value)
+{
+	FractureModifierData *rmd = (FractureModifierData *)ptr->data;
+	rmd->min_acceleration = value;
+	//rmd->refresh_constraints = true;
+}
+
 static void rna_Modifier_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
 	ModifierData* md = ptr->data;
@@ -1446,5 +1462,30 @@ void RNA_def_fracture(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Self Collision", "Allow collisions between constraint islands");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+	prop = RNA_def_property(srna, "acceleration_vertex_group", PROP_STRING, PROP_NONE);
+	RNA_def_property_string_sdna(prop, NULL, "acceleration_defgrp_name");
+	RNA_def_property_ui_text(prop, "Acceleration Vertex Group", "Vertex group whose weights represent the forces affecting the meshislands");
+	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_FractureModifier_acceleration_defgrp_name_set");
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "min_acceleration", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "min_acceleration");
+	RNA_def_property_range(prop, 0, FLT_MAX);
+	RNA_def_property_float_funcs(prop, NULL, "rna_FractureModifier_min_acceleration_set", NULL);
+	RNA_def_property_ui_text(prop, "Min Acceleration", "The minimum against which the force will be normed against");
+	RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 0.1f, 2);
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "max_acceleration", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "max_acceleration");
+	RNA_def_property_range(prop, 0, FLT_MAX);
+	RNA_def_property_float_funcs(prop, NULL, "rna_FractureModifier_max_acceleration_set", NULL);
+	RNA_def_property_ui_text(prop, "Max Acceleration", "The maximum against which the force will be normed against");
+	RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 0.1f, 2);
+	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 c1934670ef5..e63b2956399 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -257,6 +257,9 @@ static void init

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list