[Bf-blender-cvs] [e2670b3] fracture_modifier: fixes for correct rotation calculation in prefractured and external mode

Martin Felke noreply at git.blender.org
Thu Jan 21 12:07:32 CET 2016


Commit: e2670b38140c71ff9409e157b8ffce3d4566b115
Author: Martin Felke
Date:   Thu Jan 21 12:02:00 2016 +0100
Branches: fracture_modifier
https://developer.blender.org/rBe2670b38140c71ff9409e157b8ffce3d4566b115

fixes for correct rotation calculation in prefractured and external mode

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

M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 0a61f98..983b24c 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -115,15 +115,19 @@ static void calc_dist_angle(RigidBodyShardCon *con, float *dist, float *angle, b
 	if (exact)
 	{
 		rotation_between_quats_to_quat(qdiff, q1, q2);
+		normalize_qt(qdiff);
+		*angle = 2.0f * saacos(qdiff[0]);
+		if (!finite(*angle)) {
+			*angle = 0.0f;
+		}
 	}
 	else
 	{
 		//XXX TODO probably very wrong here
 		invert_qt(q1);
 		mul_qt_qtqt(qdiff, q1, q2);
+		quat_to_axis_angle(axis, angle, qdiff);
 	}
-
-	quat_to_axis_angle(axis, &angle, qdiff);
 }
 
 void BKE_rigidbody_start_dist_angle(RigidBodyShardCon *con, bool exact)
@@ -1630,9 +1634,30 @@ static void rigidbody_create_shard_physics_constraint(FractureModifierData* fmd,
 		return;
 	}
 
-	mul_v3_m4v3(loc, ob->obmat, rbc->pos);
-	mat4_to_quat(rot, ob->obmat);
-	mul_qt_qtqt(rot, rot, rbc->orn);
+	if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL)
+	{
+		mul_v3_m4v3(loc, ob->obmat, rbc->pos);
+		mat4_to_quat(rot, ob->obmat);
+		mul_qt_qtqt(rot, rot, rbc->orn);
+	}
+	else
+	{
+		/* keep old constraint calculation for other fracture modes ! */
+		/* do this for all constraints */
+		/* location for fixed constraints doesnt matter, so keep old setting */
+		if (rbc->type == RBC_TYPE_FIXED) {
+			copy_v3_v3(rbc->pos, rbc->mi1->rigidbody->pos);
+		}
+		else {
+			/* else set location to center */
+			add_v3_v3v3(rbc->pos, rbc->mi1->rigidbody->pos, rbc->mi2->rigidbody->pos);
+			mul_v3_fl(rbc->pos, 0.5f);
+		}
+
+		copy_qt_qt(rbc->orn, rbc->mi1->rigidbody->orn);
+		copy_v3_v3(loc, rbc->pos);
+		copy_qt_qt(rot, rbc->orn);
+	}
 
 	if (rb1 && rb2) {
 		switch (rbc->type) {
@@ -3134,6 +3159,8 @@ static void handle_plastic_breaking(RigidBodyShardCon *rbsc)
 	/* 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 (anglediff > 0.0f)
+		printf("Angles %f %f\n", anglediff, rbsc->breaking_angle);
 
 	exceededAngle = ((rbsc->breaking_angle >= 0.0f) && (anglediff > rbsc->breaking_angle));
 	exceededDist = ((rbsc->breaking_dist >= 0.0f) && (distdiff > (rbsc->breaking_dist + (anglediff / M_PI))));
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index f34c9f4..3f9463f 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -5603,29 +5603,29 @@ static void rna_def_mesh_constraint(BlenderRNA *brna)
 	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_range(prop, -1.0f, FLT_MAX);
+	RNA_def_property_ui_text(prop, "Breaking Distance", "Breaking Distance Tolerance of this constraint, -1 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_range(prop, -1.0f, DEG2RADF(360.0));
+	RNA_def_property_ui_text(prop, "Breaking Angle", "Breaking Angle Tolerance of this constraint, -1 disables");
 	//RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
 	prop = RNA_def_property(srna, "plastic_distance", PROP_FLOAT, PROP_DISTANCE);
 	RNA_def_property_float_sdna(prop, NULL, "plastic_dist");
 	RNA_def_property_float_default(prop, 0.0f);
-	RNA_def_property_range(prop, 0.0f, FLT_MAX);
-	RNA_def_property_ui_text(prop, "Plastic Distance", "Distance Tolerance of this constraint, when exceeded enter plastic mode, 0 disables");
+	RNA_def_property_range(prop, -1.0f, FLT_MAX);
+	RNA_def_property_ui_text(prop, "Plastic Distance", "Distance Tolerance of this constraint, when exceeded enter plastic mode, -1 disables");
 	//RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
 	prop = RNA_def_property(srna, "plastic_angle", PROP_FLOAT, PROP_ANGLE);
 	RNA_def_property_float_sdna(prop, NULL, "plastic_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, "Plastic Angle", "Angle Tolerance of this constraint, when exceeded enter plastic mode, 0 disables");
+	RNA_def_property_range(prop, -1.0f, DEG2RADF(360.0));
+	RNA_def_property_ui_text(prop, "Plastic Angle", "Angle Tolerance of this constraint, when exceeded enter plastic mode, -1 disables");
 	//RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 2f4e804..05d8ef8 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -1643,7 +1643,7 @@ static float do_setup_meshisland(FractureModifierData *fmd, Object *ob, int totv
 
 	copy_v3_v3(mi->centroid, centroid);
 	mat4_to_loc_quat(dummyloc, rot, ob->obmat);
-	copy_v3_v3(mi->rot, rot);
+	copy_qt_qt(mi->rot, rot);
 	mi->bb = BKE_boundbox_alloc_unit();
 	BKE_boundbox_init_from_minmax(mi->bb, min, max);
 	mi->participating_constraints = NULL;
@@ -3000,7 +3000,7 @@ static void do_island_from_shard(FractureModifierData *fmd, Object *ob, Shard* s
 	copy_v3_v3(mi->centroid, s->centroid);
 
 	mat4_to_loc_quat(dummyloc, rot, ob->obmat);
-	copy_v3_v3(mi->rot, rot);
+	copy_qt_qt(mi->rot, rot);
 	mi->id = s->shard_id;
 
 	if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)




More information about the Bf-blender-cvs mailing list