[Bf-blender-cvs] [1ae8bcc] fracture_modifier: exposed per-constraint breaking angle and distance to python (for external mode only, for now)

Martin Felke noreply at git.blender.org
Mon Jan 18 19:55:17 CET 2016


Commit: 1ae8bcc8e6caeee2b102865d664c1bf30aeb0ad5
Author: Martin Felke
Date:   Mon Jan 18 19:55:10 2016 +0100
Branches: fracture_modifier
https://developer.blender.org/rB1ae8bcc8e6caeee2b102865d664c1bf30aeb0ad5

exposed per-constraint breaking angle and distance to python (for external mode only, for now)

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

M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/makesdna/DNA_rigidbody_types.h
M	source/blender/makesrna/intern/rna_modifier.c

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

diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 35b53e6..e98abbd 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -2424,6 +2424,8 @@ RigidBodyShardCon *BKE_rigidbody_create_shard_constraint(Scene *scene, short typ
 	rbc->id = -1;
 	zero_v3(rbc->pos);
 	unit_qt(rbc->orn);
+	rbc->breaking_angle = 0.0f;
+	rbc->breaking_dist = 0.0f;
 
 	/* flag cache as outdated */
 	BKE_rigidbody_cache_reset(rbw);
@@ -3081,7 +3083,17 @@ static bool can_next(RigidBodyShardCon *rbsc, MeshIsland *mi1, MeshIsland *mi2)
 
 static void handle_plastic_breaking_participants(RigidBodyShardCon *rbsc)
 {
-	if (rbsc->physics_constraint && !(RB_constraint_is_enabled(rbsc->physics_constraint)))
+	float dist, angle, distdiff, anglediff;
+	bool exceeded = false;
+	calc_dist_angle(rbsc, &dist, &angle);
+
+	anglediff = fabs(angle - rbsc->start_angle);
+	distdiff = fabs(dist - rbsc->start_dist);
+
+	exceeded = (rbsc->breaking_angle > 0.0f && anglediff > rbsc->breaking_angle);
+	exceeded = exceeded || (rbsc->breaking_dist > 0.0f && distdiff > rbsc->breaking_dist);
+
+	if (rbsc->physics_constraint && (!(RB_constraint_is_enabled(rbsc->physics_constraint)) || exceeded))
 	{
 		//go back until pair changes, break all
 		MeshIsland *mi1 = rbsc->mi1;
@@ -3099,7 +3111,7 @@ static void handle_plastic_breaking_participants(RigidBodyShardCon *rbsc)
 				}
 				else {
 					RB_constraint_set_enabled(con->physics_constraint, false);
-
+#if 0
 					RB_constraint_set_breaking_threshold(con->physics_constraint, 0);
 					if (con->type == RBC_TYPE_6DOF_SPRING)
 					{
@@ -3118,6 +3130,7 @@ static void handle_plastic_breaking_participants(RigidBodyShardCon *rbsc)
 
 						RB_constraint_set_equilibrium_6dof_spring(rbc->physics_constraint);
 					}
+#endif
 				}
 			}
 		}
@@ -3134,6 +3147,7 @@ static void handle_plastic_breaking_participants(RigidBodyShardCon *rbsc)
 				else {
 					RB_constraint_set_enabled(con->physics_constraint, false);
 
+#if 0
 					RB_constraint_set_breaking_threshold(con->physics_constraint, 0);
 
 					if (con->type == RBC_TYPE_6DOF_SPRING)
@@ -3153,6 +3167,7 @@ static void handle_plastic_breaking_participants(RigidBodyShardCon *rbsc)
 
 						RB_constraint_set_equilibrium_6dof_spring(rbc->physics_constraint);
 					}
+#endif
 				}
 			}
 		}
@@ -3343,7 +3358,7 @@ static bool do_update_modifier(Scene* scene, Object* ob, RigidBodyWorld *rbw, bo
 				rbsc->mi2->rigidbody->flag & RBO_FLAG_KINEMATIC_REBUILD) {
 				/* World has been rebuilt so rebuild constraint */
 				BKE_rigidbody_validate_sim_shard_constraint(rbw, fmd,  ob,  rbsc, true);
-				BKE_rigidbody_start_dist_angle(rbsc);
+				BKE_rigidbody_start_dist_angle(rbsc); //TODO ensure evaluation on transform change too
 			}
 
 			else if (rbsc->flag & RBC_FLAG_NEEDS_VALIDATE) {
diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index f628085..484dbae 100644
--- a/source/blender/makesdna/DNA_rigidbody_types.h
+++ b/source/blender/makesdna/DNA_rigidbody_types.h
@@ -285,6 +285,8 @@ typedef struct RigidBodyShardCon {
 	float breaking_threshold;	/* breaking impulse threshold */
 	float start_angle;			//needed for breaking by angle and dist
 	float start_dist;
+	float breaking_angle;
+	float breaking_dist;
 
 	float orn[4];
 	float pos[3];
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index d48e8fc..e8b757a 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -5599,6 +5599,20 @@ static void rna_def_mesh_constraint(BlenderRNA *brna)
 	RNA_def_property_float_funcs(prop, NULL, "rna_MeshCon_motor_ang_max_impulse_set", NULL);
 	RNA_def_property_ui_text(prop, "Max Impulse", "Maximum angular motor impulse");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "breaking_distance", PROP_FLOAT, PROP_DISTANCE);
+	RNA_def_property_float_sdna(prop, NULL, "breaking_dist");
+	RNA_def_property_float_default(prop, 0.0f);
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_text(prop, "Breaking Distance", "Breaking Distance Tolerance of this constraint, 0 disables");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "breaking_angle", PROP_FLOAT, PROP_ANGLE);
+	RNA_def_property_float_sdna(prop, NULL, "breaking_angle");
+	RNA_def_property_float_default(prop, 0.0f);
+	RNA_def_property_range(prop, DEG2RADF(-360.0), DEG2RADF(360.0));
+	RNA_def_property_ui_text(prop, "Breaking Angle", "Breaking Angle Tolerance of this constraint, 0 disables");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
 static void rna_def_fracture_meshislands(BlenderRNA *brna, PropertyRNA *cprop)




More information about the Bf-blender-cvs mailing list