[Bf-blender-cvs] [c23dbcf37d9] master: Bones: implement a new Aligned Inherit Scale mode.

Alexander Gavrilov noreply at git.blender.org
Thu Nov 21 18:10:39 CET 2019


Commit: c23dbcf37d9ffed4d443e0f9ce36f14854a52009
Author: Alexander Gavrilov
Date:   Sat Oct 19 11:37:57 2019 +0300
Branches: master
https://developer.blender.org/rBc23dbcf37d9ffed4d443e0f9ce36f14854a52009

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

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

M	source/blender/blenkernel/BKE_armature.h
M	source/blender/blenkernel/intern/armature.c
M	source/blender/makesdna/DNA_armature_types.h
M	source/blender/makesrna/intern/rna_armature.c

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

diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index b255500272a..4012ff60b98 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -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 */
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 3215b3d7b40..4d9a92d3ead 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -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.
diff --git a/source/blender/makesdna/DNA_armature_types.h b/source/blender/makesdna/DNA_armature_types.h
index 3bad2a04a65..4ead3165715 100644
--- a/source/blender/makesdna/DNA_armature_types.h
+++ b/source/blender/makesdna/DNA_armature_types.h
@@ -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 */
diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c
index 4dc383a2460..b09a19bb39f 100644
--- a/source/blender/makesrna/intern/rna_armature.c
+++ b/source/blender/makesrna/intern/rna_armature.c
@@ -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,



More information about the Bf-blender-cvs mailing list