B-Bones improve handle calculation
authorCampbell Barton <ideasman42@gmail.com>
Mon, 23 May 2016 11:32:12 +0000 (21:32 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 23 May 2016 11:35:54 +0000 (21:35 +1000)
This changes the bezier handles b-bones to fit to a circle more closely.

source/blender/blenkernel/intern/armature.c

index 5c95cde4d8ddd5ac1b207de0ddf12687fe6b5b2d..04b4733fd440d781a1699bb53eddaadf27dad862 100644 (file)
@@ -475,7 +475,7 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB
 {
        bPoseChannel *next, *prev;
        Bone *bone = pchan->bone;
-       float h1[3], h2[3], scale[3], length, hlength1, hlength2, roll1 = 0.0f, roll2;
+       float h1[3], h2[3], scale[3], length, roll1 = 0.0f, roll2;
        float mat3[3][3], imat[4][4], posemat[4][4], scalemat[4][4], iscalemat[4][4];
        float data[MAX_BBONE_SUBDIV + 1][4], *fp;
        int a;
@@ -496,9 +496,6 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB
                }
        }
 
-       hlength1 = bone->ease1 * length * 0.390464f; /* 0.5f * sqrt(2) * kappa, the handle length for near-perfect circles */
-       hlength2 = bone->ease2 * length * 0.390464f;
-
        /* get "next" and "prev" bones - these are used for handle calculations */
        if (pchan->bboneflag & PCHAN_BBONE_CUSTOM_HANDLES) {
                /* use the provided bones as the next/prev - leave blank to eliminate this effect altogether */
@@ -563,7 +560,7 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB
                }
 
                normalize_v3(h1);
-               mul_v3_fl(h1, -hlength1);
+               negate_v3(h1);
 
                if (prev->bone->segments == 1) {
                        /* find the previous roll to interpolate */
@@ -582,7 +579,7 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB
                }
        }
        else {
-               h1[0] = 0.0f; h1[1] = hlength1; h1[2] = 0.0f;
+               h1[0] = 0.0f; h1[1] = 1.0; h1[2] = 0.0f;
                roll1 = 0.0f;
        }
        if (next) {
@@ -635,14 +632,22 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB
 
                roll2 = atan2f(mat3[2][0], mat3[2][2]);
 
-               /* and only now negate handle */
-               mul_v3_fl(h2, -hlength2);
        }
        else {
-               h2[0] = 0.0f; h2[1] = -hlength2; h2[2] = 0.0f;
+               h2[0] = 0.0f; h2[1] = 1.0f; h2[2] = 0.0f;
                roll2 = 0.0;
        }
 
+       {
+               const float circle_factor = length * (cubic_tangent_factor_circle_v3(h1, h2) / 0.75f);
+               const float hlength1 = bone->ease1 * circle_factor;
+               const float hlength2 = bone->ease2 * circle_factor;
+
+               /* and only now negate h2 */
+               mul_v3_fl(h1,  hlength1);
+               mul_v3_fl(h2, -hlength2);
+       }
+
        /* Add effects from bbone properties over the top
         * - These properties allow users to hand-animate the
         *   bone curve/shape, without having to resort to using