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!
This commit is contained in:
Bastien Montagne 2014-05-21 15:22:31 +02:00
parent d203edfc93
commit ebbeb082d1
Notes: blender-bot 2023-02-14 10:37:42 +01:00
Referenced by issue #40271, recalculation of the bone roll does not work correctly.
Referenced by issue #40271, recalculation of the bone roll does not work correctly.
3 changed files with 12 additions and 12 deletions

View File

@ -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 */

View File

@ -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 */

View File

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