[Bf-blender-cvs] [a8510408b95] fracture_modifier: added deform weakening factor

Martin Felke noreply at git.blender.org
Sun Jun 18 19:26:06 CEST 2017


Commit: a8510408b958d8c12a1c6ddf08940448813ef65f
Author: Martin Felke
Date:   Sun Jun 18 19:25:57 2017 +0200
Branches: fracture_modifier
https://developer.blender.org/rBa8510408b958d8c12a1c6ddf08940448813ef65f

added deform weakening factor

the threshold is multiplied with 1.0-fac per deform iteration, so it can automatically break at some point.

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

M	intern/rigidbody/RBI_api.h
M	intern/rigidbody/rb_bullet_api.cpp
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/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_fracture.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index 765397f0a54..02447f8d1b8 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -346,6 +346,7 @@ void RB_constraint_set_solver_iterations(rbConstraint *con, int num_solver_itera
 
 /* Set breaking impulse threshold, if constraint shouldn't break it can be set to FLT_MAX */
 void RB_constraint_set_breaking_threshold(rbConstraint *con, float threshold);
+float RB_constraint_get_breaking_threshold(rbConstraint *con);
 
 void RB_constraint_set_id(rbConstraint *con, char id[64]);
 
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index ac81a362f08..337fc97ba8b 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -2058,4 +2058,11 @@ void RB_constraint_set_id(rbConstraint *con, char id[64])
 	strncpy(con->id, id, len);
 }
 
+float RB_constraint_get_breaking_threshold(rbConstraint *con)
+{
+	btTypedConstraint *constraint = reinterpret_cast<btTypedConstraint*>(con->con);
+
+	return constraint->getBreakingImpulseThreshold();
+}
+
 /* ********************************** */
diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index d917eaabcf1..fb9fe0e8b7d 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -697,7 +697,8 @@ class AddPresetFracture(AddPresetBase, Operator):
         "fracture.cluster_deform_distance",
         "fracture.deform_angle",
         "fracture.deform_angle_weighted",
-        "fracture.cluster_deform_angle"
+        "fracture.cluster_deform_angle",
+        "fracture.deform_weakening"
     ]
 
     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 ea155a7eefc..1fd6b1021e3 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -257,6 +257,8 @@ class PHYSICS_PT_fracture_simulation(PhysicButtonsPanel, Panel):
             row.prop(md, "deform_angle_weighted")
             row.prop(md, "deform_distance_weighted")
 
+            col.prop(md, "deform_weakening")
+
 
 
 
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index ac90857ccdf..16af2aca95f 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -3750,6 +3750,9 @@ static void deactivateRigidbody(RigidBodyOb *rbo)
 
 static void deform_constraint(FractureModifierData *fmd, Object *ob, RigidBodyShardCon* rbsc, RigidBodyWorld *rbw)
 {
+	float thresh;
+	float weakening = 1.0f - fmd->deform_weakening;
+
 	RB_dworld_remove_constraint(rbw->physics_world, rbsc->physics_constraint);
 
 	BKE_rigidbody_start_dist_angle(rbsc, true);
@@ -3757,6 +3760,9 @@ static void deform_constraint(FractureModifierData *fmd, Object *ob, RigidBodySh
 	BKE_rigidbody_validate_sim_shard_constraint(rbw, fmd, ob, rbsc, true);
 	//set_constraint_index(fmd, rbsc);
 
+	thresh = RB_constraint_get_breaking_threshold(rbsc->physics_constraint);
+	RB_constraint_set_breaking_threshold(rbsc->physics_constraint, thresh * weakening);
+
 	deactivateRigidbody(rbsc->mi1->rigidbody);
 	deactivateRigidbody(rbsc->mi2->rigidbody);
 }
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 2e61d5fa6f9..16bb460a44a 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 deform_distance;
 	float cluster_deform_angle;
 	float cluster_deform_distance;
+	float deform_weakening;
 
 	float impulse_dampening;
 	float minimum_impulse;
@@ -1801,7 +1802,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 0505c05861e..80ea94bada3 100644
--- a/source/blender/makesrna/intern/rna_fracture.c
+++ b/source/blender/makesrna/intern/rna_fracture.c
@@ -318,6 +318,13 @@ static void rna_FractureModifier_cluster_threshold_set(PointerRNA *ptr, float va
 	rmd->refresh_constraints = true;
 }
 
+static void rna_FractureModifier_deform_weakening_set(PointerRNA *ptr, float value)
+{
+	FractureModifierData *rmd = (FractureModifierData*)ptr->data;
+	rmd->deform_weakening = value;
+	rmd->refresh_constraints = true;
+}
+
 static void rna_FractureModifier_solver_iterations_override_set(PointerRNA *ptr, float value)
 {
 	FractureModifierData *rmd = (FractureModifierData*)ptr->data;
@@ -1344,5 +1351,15 @@ 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, "deform_weakening", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "deform_weakening");
+	RNA_def_property_range(prop, 0.0f, 1.0f);
+	RNA_def_property_float_funcs(prop, NULL, "rna_FractureModifier_deform_weakening_set", NULL);
+	RNA_def_property_ui_text(prop, "Deform Weakening Factor",
+	                         "Multiplies the breaking threshold in each iteration with 1.0 - factor in order to weaken it at deform, 0 to disable");
+	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.0001f, 6);
+	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 7823822b828..c65885d1867 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -263,6 +263,8 @@ static void initData(ModifierData *md)
 
 	fmd->pack_storage.first = NULL;
 	fmd->pack_storage.last = NULL;
+
+	fmd->deform_weakening = 0.0f;
 }
 
 //XXX TODO, freeing functionality should be in BKE too
@@ -1868,6 +1870,7 @@ static void copyData(ModifierData *md, ModifierData *target)
 	trmd->deform_distance = rmd->deform_distance;
 	trmd->deform_distance_weighted = rmd->deform_distance_weighted;
 	trmd->cluster_deform_distance = rmd->cluster_deform_distance;
+	trmd->deform_weakening = rmd->deform_weakening;
 }
 
 //XXXX TODO, is BB really useds still ? aint there exact volume calc now ?




More information about the Bf-blender-cvs mailing list