[Bf-blender-cvs] [ebbeb08] master: Fix T40271: recalculation of the bone roll does not work correctly.

Bastien Montagne noreply at git.blender.org
Wed May 21 15:28:26 CEST 2014


Commit: ebbeb082d1bef78d1fa162822db2af44468e97cd
Author: Bastien Montagne
Date:   Wed May 21 15:22:31 2014 +0200
https://developer.blender.org/rBebbeb082d1bef78d1fa162822db2af44468e97cd

Fix T40271: recalculation of the bone roll does not work correctly.

Check that up_axis is not aligned with bone was wrong in at least two aspects
(not working against negative alignement case, and since ages it seems,
using Z axis when bones are along Y axis...).

Also optimized a bit here, better to have a normalized version of vec_roll_to_mat3(),
since it needs normalized vector anyway, and we have to normalize it for the tests
before calling it anyway (so now, we only do that twice in Transform code, instead
of three times).

And we can perform aling test *before* calling vec_roll_to_mat3!

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

M	source/blender/blenkernel/BKE_armature.h
M	source/blender/blenkernel/intern/armature.c
M	source/blender/editors/armature/armature_edit.c

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

diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index 8532975..fdf0795 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -99,6 +99,7 @@ void BKE_pose_where_is_bone_tail(struct bPoseChannel *pchan);
 /* get_objectspace_bone_matrix has to be removed still */
 void get_objectspace_bone_matrix(struct Bone *bone, float M_accumulatedMatrix[4][4], int root, int posed);
 void vec_roll_to_mat3(const float vec[3], const float roll, float mat[3][3]);
+void vec_roll_to_mat3_normalized(const float nor[3], const float roll, float mat[3][3]);
 void mat3_to_vec_roll(float mat[3][3], float r_vec[3], float *r_roll);
 
 /* Common Conversions Between Co-ordinate Spaces */
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index fda252e..95f8426 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -1482,17 +1482,14 @@ void mat3_to_vec_roll(float mat[3][3], float r_vec[3], float *r_roll)
  * M* = 1 / (x^2 + z^2) * │                         │
  *                        └ -2 * x * z,   x^2 - z^2 ┘
  */
-void vec_roll_to_mat3(const float vec[3], const float roll, float mat[3][3])
+void vec_roll_to_mat3_normalized(const float nor[3], const float roll, float mat[3][3])
 {
 #define THETA_THRESHOLD_NEGY 1.0e-9f
 #define THETA_THRESHOLD_NEGY_CLOSE 1.0e-5f
 
-	float nor[3];
 	float theta;
 	float rMatrix[3][3], bMatrix[3][3];
 
-	normalize_v3_v3(nor, vec);
-
 	theta = 1.0f + nor[1];
 
 	/* With old algo, 1.0e-13f caused T23954 and T31333, 1.0e-6f caused T27675 and T30438,
@@ -1543,6 +1540,13 @@ void vec_roll_to_mat3(const float vec[3], const float roll, float mat[3][3])
 #undef THETA_THRESHOLD_NEGY_CLOSE
 }
 
+void vec_roll_to_mat3(const float vec[3], const float roll, float mat[3][3])
+{
+	float nor[3];
+
+	normalize_v3_v3(nor, vec);
+	vec_roll_to_mat3_normalized(nor, roll, mat);
+}
 
 /* recursive part, calculates restposition of entire tree of children */
 /* used by exiting editmode too */
diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c
index fffdb2f..f71cfd5 100644
--- a/source/blender/editors/armature/armature_edit.c
+++ b/source/blender/editors/armature/armature_edit.c
@@ -209,17 +209,12 @@ float ED_rollBoneToVector(EditBone *bone, const float align_axis[3], const bool
 
 	sub_v3_v3v3(nor, bone->tail, bone->head);
 
-	/* if tail == head! */
-	if (is_zero_v3(nor)) {
+	/* If tail == head or the bone is aligned with the axis... */
+	if (normalize_v3(nor) <= FLT_EPSILON || (fabsf(dot_v3v3(align_axis, nor)) >= (1.0f - FLT_EPSILON))) {
 		return roll;
 	}
 
-	vec_roll_to_mat3(nor, 0.0f, mat);
-
-	/* check the bone isn't aligned with the axis */
-	if (dot_v3v3(align_axis, mat[2]) >= (1.0f - FLT_EPSILON)) {
-		return roll;
-	}
+	vec_roll_to_mat3_normalized(nor, 0.0f, mat);
 
 	/* project the new_up_axis along the normal */
 	project_v3_v3v3(vec, align_axis, nor);




More information about the Bf-blender-cvs mailing list