Bones: implement a new Aligned Inherit Scale mode.

Implement one more way of inheriting scale from the parent
bone, as an addition to the choices introduced in D5588.

This new mode inherits parent scale as if the parent and child
were not rotated relative to each other, always applying parent
X scale to child X scale and so forth. It is quite natural for
connected bone chains with coherent roll, like limbs or tentacles,
falling roughly between Average and Fix Shear in how closely
the parent scaling is followed.

Currently this can be achieved by using Inherit Scale: None plus
a Copy Scale with Offset from parent on the child; however, this
is cumbersome, and loses the distinction between true local and
inherited scale in the child's Local space.

This new mode also matches how the Before/After Original mix
modes work in the Copy Transforms constraint.

On the technical side this mode requires adding a right side
scale matrix multiplication into the Local<->Pose conversion,
in addition to the existing two left side matrices used for
location and orientation.

Differential Revision: https://developer.blender.org/D6099
This commit is contained in:
Alexander Gavrilov 2019-10-19 11:37:57 +03:00
parent 6c9be3b27c
commit c23dbcf37d
4 changed files with 25 additions and 0 deletions

View File

@ -165,6 +165,7 @@ void BKE_bone_offset_matrix_get(const struct Bone *bone, float offs_bone[4][4]);
typedef struct BoneParentTransform {
float rotscale_mat[4][4]; /* parent effect on rotation & scale pose channels */
float loc_mat[4][4]; /* parent effect on location pose channel */
float post_scale[3]; /* additional scale to apply with post-multiply */
} BoneParentTransform;
/* Matrix-like algebra operations on the transform */

View File

@ -1893,6 +1893,8 @@ void BKE_bone_parent_transform_calc_from_matrices(int bone_flag,
const float parent_pose_mat[4][4],
BoneParentTransform *r_bpt)
{
copy_v3_fl(r_bpt->post_scale, 1.0f);
if (parent_pose_mat) {
const bool use_rotation = (bone_flag & BONE_HINGE) == 0;
const bool full_transform = use_rotation && inherit_scale_mode == BONE_INHERIT_SCALE_FULL;
@ -1922,6 +1924,12 @@ void BKE_bone_parent_transform_calc_from_matrices(int bone_flag,
orthogonalize_m4_stable(tmat, 1, true);
break;
case BONE_INHERIT_SCALE_ALIGNED:
/* Remove shear and extract scale. */
orthogonalize_m4_stable(tmat, 1, false);
normalize_m4_ex(tmat, r_bpt->post_scale);
break;
case BONE_INHERIT_SCALE_NONE_LEGACY:
/* Remove only scale - bad legacy way. */
normalize_m4(tmat);
@ -1949,6 +1957,10 @@ void BKE_bone_parent_transform_calc_from_matrices(int bone_flag,
rescale_m4(tmat, tscale);
break;
case BONE_INHERIT_SCALE_ALIGNED:
mat4_to_size_fix_shear(r_bpt->post_scale, parent_pose_mat);
break;
case BONE_INHERIT_SCALE_NONE:
case BONE_INHERIT_SCALE_AVERAGE:
case BONE_INHERIT_SCALE_NONE_LEGACY:
@ -2023,12 +2035,14 @@ void BKE_bone_parent_transform_clear(struct BoneParentTransform *bpt)
{
unit_m4(bpt->rotscale_mat);
unit_m4(bpt->loc_mat);
copy_v3_fl(bpt->post_scale, 1.0f);
}
void BKE_bone_parent_transform_invert(struct BoneParentTransform *bpt)
{
invert_m4(bpt->rotscale_mat);
invert_m4(bpt->loc_mat);
invert_v3(bpt->post_scale);
}
void BKE_bone_parent_transform_combine(const struct BoneParentTransform *in1,
@ -2037,6 +2051,7 @@ void BKE_bone_parent_transform_combine(const struct BoneParentTransform *in1,
{
mul_m4_m4m4(result->rotscale_mat, in1->rotscale_mat, in2->rotscale_mat);
mul_m4_m4m4(result->loc_mat, in1->loc_mat, in2->loc_mat);
mul_v3_v3v3(result->post_scale, in1->post_scale, in2->post_scale);
}
void BKE_bone_parent_transform_apply(const struct BoneParentTransform *bpt,
@ -2049,6 +2064,7 @@ void BKE_bone_parent_transform_apply(const struct BoneParentTransform *bpt,
mul_m4_m4m4(outmat, bpt->rotscale_mat, inmat);
mul_v3_m4v3(outmat[3], bpt->loc_mat, tmploc);
rescale_m4(outmat, bpt->post_scale);
}
/* Convert Pose-Space Matrix to Bone-Space Matrix.

View File

@ -267,6 +267,8 @@ typedef enum eBone_InheritScaleMode {
BONE_INHERIT_SCALE_NONE,
/* Inherit effects of shear on parent (same as old disabled Inherit Scale). */
BONE_INHERIT_SCALE_NONE_LEGACY,
/* Inherit parent X scale as child X scale etc. */
BONE_INHERIT_SCALE_ALIGNED,
} eBone_InheritScaleMode;
/* bone->bbone_prev_type, bbone_next_type */

View File

@ -832,6 +832,12 @@ static void rna_def_bone_common(StructRNA *srna, int editbone)
0,
"Fix Shear",
"Inherit scaling, but remove shearing of the child in the rest orientation"},
{BONE_INHERIT_SCALE_ALIGNED,
"ALIGNED",
0,
"Aligned",
"Rotate non-uniform parent scaling to align with the child, applying parent X "
"scale to child X axis, and so forth"},
{BONE_INHERIT_SCALE_AVERAGE,
"AVERAGE",
0,