diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-05-21 17:22:31 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-05-21 17:22:31 +0400 |
commit | ebbeb082d1bef78d1fa162822db2af44468e97cd (patch) | |
tree | 2f31fdc6ed9774e1969cc8ccf336255246afaf51 | |
parent | d203edfc9384f8632fce122dc8313a4745799a86 (diff) |
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!
-rw-r--r-- | source/blender/blenkernel/BKE_armature.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/armature.c | 12 | ||||
-rw-r--r-- | source/blender/editors/armature/armature_edit.c | 11 |
3 files changed, 12 insertions, 12 deletions
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 85329753844..fdf0795fe02 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 fda252e81fd..95f8426872d 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 fffdb2fe9c0..f71cfd52175 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); |