[Bf-blender-cvs] [7c3c6f8] fracture_modifier: used more exact angle calculation method for external mode, different formulae for tolerances, and some cleanup of obsolete stuff.

Martin Felke noreply at git.blender.org
Thu Jan 21 02:13:09 CET 2016


Commit: 7c3c6f83101403ec2140343dae56335a914e9c3f
Author: Martin Felke
Date:   Thu Jan 21 02:12:48 2016 +0100
Branches: fracture_modifier
https://developer.blender.org/rB7c3c6f83101403ec2140343dae56335a914e9c3f

used more exact angle calculation method for external mode, different formulae for tolerances, and some cleanup of obsolete stuff.

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

M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	source/blender/blenkernel/BKE_rigidbody.h
M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesdna/DNA_rigidbody_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py b/release/scripts/startup/bl_ui/properties_physics_fracture.py
index 03084d3..3ea1084 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -87,7 +87,6 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel):
         row.prop(md, "fracture_mode")
 
         if md.fracture_mode == 'EXTERNAL':
-           layout.prop(md, "use_special_breaking")
            return
 
         if md.fracture_mode == 'DYNAMIC':
diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h
index fa705b2..e4ea460 100644
--- a/source/blender/blenkernel/BKE_rigidbody.h
+++ b/source/blender/blenkernel/BKE_rigidbody.h
@@ -98,7 +98,7 @@ void BKE_rigidbody_calc_shard_mass(struct Object* ob, struct MeshIsland* mi, str
 void BKE_rigidbody_calc_threshold(float max_con_mass, struct FractureModifierData* rmd, struct RigidBodyShardCon *con);
 float BKE_rigidbody_calc_max_con_mass(struct Object* ob);
 float BKE_rigidbody_calc_min_con_dist(struct Object* ob);
-void BKE_rigidbody_start_dist_angle(struct RigidBodyShardCon* con);
+void BKE_rigidbody_start_dist_angle(struct RigidBodyShardCon* con, bool exact);
 void BKE_rigidbody_remove_shard_con(struct Scene* scene, struct RigidBodyShardCon* con);
 void BKE_rigidbody_remove_shard(struct Scene* scene, struct MeshIsland *mi);
 void BKE_rigidbody_update_ob_array(struct RigidBodyWorld *rbw);
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 41fc4f7..d923438 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -2444,13 +2444,16 @@ MeshIsland* BKE_fracture_mesh_island_add(FractureModifierData *fmd, Object* own,
 	mi = fracture_shard_to_island(fmd, s, vertstart);
 
 	mat4_to_loc_quat(loc, rot, target->obmat);
-	copy_v3_v3(mi->rot, rot);
+	copy_qt_qt(mi->rot, rot);
 
 	//lets see whether we need to add loc here too XXX TODO
 
 	mi->rigidbody = BKE_rigidbody_create_shard(fmd->modifier.scene, own, target, mi);
 	if (mi->rigidbody)
+	{
 		mi->rigidbody->meshisland_index = mi->id;
+		copy_qt_qt(mi->rigidbody->orn, rot);
+	}
 
 	//handle materials
 	if (!fmd->material_index_map)
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 61c28c3..0a61f98 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -97,7 +97,7 @@ static bool isModifierActive(FractureModifierData *rmd) {
 	return ((rmd != NULL) && (rmd->modifier.mode & (eModifierMode_Realtime | eModifierMode_Render)) && (rmd->refresh == false || rmd->fracture_mode == MOD_FRACTURE_DYNAMIC));
 }
 
-static void calc_dist_angle(RigidBodyShardCon *con, float *dist, float *angle)
+static void calc_dist_angle(RigidBodyShardCon *con, float *dist, float *angle, bool exact)
 {
 	float q1[4], q2[4], qdiff[4], axis[3];
 	if ((con->mi1->rigidbody == NULL) || (con->mi2->rigidbody == NULL)) {
@@ -105,21 +105,32 @@ static void calc_dist_angle(RigidBodyShardCon *con, float *dist, float *angle)
 		*angle = 0;
 		return;
 	}
-	
+
 	sub_v3_v3v3(axis, con->mi1->rigidbody->pos, con->mi2->rigidbody->pos);
 	*dist = len_v3(axis);
+
 	copy_qt_qt(q1, con->mi1->rigidbody->orn);
 	copy_qt_qt(q2, con->mi2->rigidbody->orn);
-	invert_qt(q1);
-	mul_qt_qtqt(qdiff, q1, q2);
-	quat_to_axis_angle(axis, angle, qdiff);
+	
+	if (exact)
+	{
+		rotation_between_quats_to_quat(qdiff, q1, q2);
+	}
+	else
+	{
+		//XXX TODO probably very wrong here
+		invert_qt(q1);
+		mul_qt_qtqt(qdiff, q1, q2);
+	}
+
+	quat_to_axis_angle(axis, &angle, qdiff);
 }
 
-void BKE_rigidbody_start_dist_angle(RigidBodyShardCon *con)
+void BKE_rigidbody_start_dist_angle(RigidBodyShardCon *con, bool exact)
 {
 	/* store starting angle and distance per constraint*/
 	float dist, angle;
-	calc_dist_angle(con, &dist, &angle);
+	calc_dist_angle(con, &dist, &angle, exact);
 	con->start_dist = dist;
 	con->start_angle = angle;
 }
@@ -1669,7 +1680,7 @@ static void rigidbody_create_shard_physics_constraint(FractureModifierData* fmd,
 			case RBC_TYPE_6DOF_SPRING:
 				rbc->physics_constraint = RB_constraint_new_6dof_spring(loc, rot, rb1, rb2);
 
-				if (rbc->flag & RBC_FLAG_USE_PLASTIC && !rbc->flag & RBC_FLAG_PLASTIC_ACTIVE)
+				if (rbc->flag & RBC_FLAG_USE_PLASTIC)
 				{	/* set to inactive plastic here, needs to be activated */
 					rigidbody_set_springs_active(rbc, false);
 				}
@@ -3110,171 +3121,50 @@ static void handle_breaking_distance(FractureModifierData *fmd, Object *ob, Rigi
 	}
 }
 
-static void handle_plastic_breaking_constraint(RigidBodyShardCon *rbsc, RigidBodyShardCon *con, bool broken, bool exceeded_plastic, bool exceeded)
-{
-	bool same = (((con->mi1 == rbsc->mi1 && con->mi2 == rbsc->mi2)) || ((con->mi1 == rbsc->mi2 && con->mi2 == rbsc->mi1)));
-	if (con->physics_constraint && same)
-	{
-		if (rbsc->type == RBC_TYPE_6DOF_SPRING)
-		{
-			if (rbsc->flag & RBC_FLAG_USE_PLASTIC)
-			{
-				/* I am plastic, the other is... */
-				/* doesnt matter, nothing should happen to the other con */
-			}
-			else
-			{	/* I am NOT plastic and a spring */
-				/* so the other needs to break */
-				if (broken || exceeded)
-					RB_constraint_set_enabled(con->physics_constraint, false);
-			}
-		}
-		else
-		{
-			/*I am no spring and the other is plastic*/
-			/*if i am broken, activate the other if inactive, else break it */
-			if (con->type == RBC_TYPE_6DOF_SPRING && con->flag & RBC_FLAG_USE_PLASTIC)
-			{
-				if (con->flag & RBC_FLAG_PLASTIC_ACTIVE)
-				{
-					/*Other is plastic active, break it*/
-					if (broken || exceeded)
-						RB_constraint_set_enabled(con->physics_constraint, false);
-				}
-				else
-				{
-					/* activate other plastic */
-					if (broken || exceeded_plastic)
-					{
-						con->flag |= RBC_FLAG_PLASTIC_ACTIVE;
-						rigidbody_set_springs_active(con, true);
-					}
-				}
-			}
-			else
-			{
-				/*other is not plastic, break it */
-				if (broken || exceeded)
-					RB_constraint_set_enabled(con->physics_constraint, false);
-			}
-		}
-	}
-}
-
-static void handle_plastic_breaking_participants(FractureModifierData *fmd, RigidBodyShardCon *rbsc)
+static void handle_plastic_breaking(RigidBodyShardCon *rbsc)
 {
 	float dist, angle, distdiff, anglediff;
-	bool exceeded = false, exceeded_plastic = false, broken = false;
-	calc_dist_angle(rbsc, &dist, &angle);
+	bool exceededAngle = false, exceededDist = false;
 
-	anglediff = fabs(angle - rbsc->start_angle);
-	distdiff = fabs(dist - rbsc->start_dist);
+	calc_dist_angle(rbsc, &dist, &angle, true);
 
-	if (fmd->use_special_breaking) {
-		//need distdiff in range 0...1, so norm it here
-		distdiff /= rbsc->start_dist;
-	}
+	/* note, relative change in percentage is expected, -1 disables */
+	distdiff = fabs(1 -(rbsc->start_dist/dist));
 
-	exceeded = (rbsc->breaking_angle > 0.0f && anglediff > rbsc->breaking_angle);
-	exceeded = exceeded || (rbsc->breaking_dist > 0.0f && distdiff > rbsc->breaking_dist);
+	/* TODO, ensure rigidbody orn is equal to quaternion of object !!! */
+	// The construct "asin(sin(x))" is a triangle function to achieve a seamless rotation loop from input
+	anglediff = asin(sin(abs(rbsc->start_angle - angle) * 0.5f));
 
-	if (exceeded && rbsc->physics_constraint)
-	{
-		RB_constraint_set_enabled(rbsc->physics_constraint, false);
-	}
-
-	if (!fmd->use_special_breaking)
-		return;
+	exceededAngle = ((rbsc->breaking_angle >= 0.0f) && (anglediff > rbsc->breaking_angle));
+	exceededDist = ((rbsc->breaking_dist >= 0.0f) && (distdiff > (rbsc->breaking_dist + (anglediff / M_PI))));
 
-	exceeded_plastic = (rbsc->plastic_angle > 0.0f && anglediff > rbsc->plastic_angle);
-	exceeded_plastic = exceeded_plastic || (rbsc->plastic_dist > 0.0f && distdiff > rbsc->plastic_dist);
-	broken = rbsc->physics_constraint && !(RB_constraint_is_enabled(rbsc->physics_constraint));
-
-	/* is there a break event on THIS constraint ? */
-	if (broken || exceeded_plastic || exceeded)
+	if (exceededDist || exceededAngle)
 	{
-		int i;
-		for (i = 0; i < rbsc->mi1->participating_constraint_count; i++)
+		if (rbsc->type == RBC_TYPE_6DOF_SPRING && rbsc->flag & RBC_FLAG_USE_PLASTIC)
 		{
-			RigidBodyShardCon *con = rbsc->mi1->participating_constraints[i];
-			handle_plastic_breaking_constraint(rbsc, con, broken, exceeded_plastic, exceeded);
+			rigidbody_set_springs_active(rbsc, true);
 		}
-
-		for (i = 0; i < rbsc->mi2->participating_constraint_count; i++)
+		else if (rbsc->physics_constraint)
 		{
-			RigidBodyShardCon *con = rbsc->mi2->participating_constraints[i];
-			handle_plastic_breaking_constraint(rbsc, con, broken, exceeded_plastic, exceeded);
+			RB_constraint_set_enabled(rbsc->physics_constraint, false);
 		}
 	}
-}
-
-#if 0
 
-static bool can_prev(RigidBodyShardCon *rbsc, MeshIsland *mi1, MeshIsland *mi2)
-{
-	return rbsc && rbsc->prev && rbsc->prev->mi1 == mi1 && rbsc->prev->mi2 == mi2;
-}
+	exceededAngle = ((rbsc->plastic_angle >= 0.0f) && (anglediff > rbsc->plastic_angle));
+	exceededDist = ((rbsc->plastic_dist >= 0.0f) && (distdiff > (rbsc->plastic_dist + (anglediff / M_PI))));
 
-static bool can_next(RigidBodyShardCon *rbsc, MeshIsland *mi1, MeshIsland *mi2)
-{
-	return rbsc && rbsc->next && rbsc->next->mi1 == mi1 && rbsc->next->mi2 == mi2;
-}
-
-static void handle_plastic_breaking(FractureModifierData *fmd, RigidBodyShardCon *rbsc)
-{
-	if (rbsc->physics_constraint && !(RB_constraint_is_enabled(rbsc->physics_constraint)))
+	/* break plastic connections */
+	if (exceededDist || exceededAngle)
 	{
-		//go back until pair changes, break all
-		RigidBodyShardCon *con = rbsc;
-		MeshIsland *mi1 = rbsc->mi1;
-		MeshIsland *mi2 = rbsc->mi2;
-
-		while (can_prev(con, mi1, mi2) && fmd->use_special_breaking)
-		{
-			if ((con->flag & RBC_FLAG_USE_PLASTIC))
-			{
-				if (con->physics_constraint) {
-					//con->flag |= RBC_FLAG_ENABLED;
-					RB_constraint_set_enabled(con->physics_constraint, true);
-					//con->flag |= RBC_FLAG_NEEDS_VALIDATE;
-				}
-			}
-			else
-			{
-				if (con->physics_constraint) {
-					//con->flag &= ~RBC_FLAG_ENABLED;
-					RB_constraint_set_

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list