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);