Fix (unreported) redo of 'bone envelope distance resize' transform op not working
authorBastien Montagne <montagne29@wanadoo.fr>
Wed, 17 Jun 2015 10:30:30 +0000 (12:30 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Wed, 17 Jun 2015 10:30:30 +0000 (12:30 +0200)
(it would behave like 'bone envelope resize' instead).

Issue comes from the fact this transform op shares some common points with both BoneResize
and BoneEnvelope operations. However, trying to re-use `TFM_BONE_ENVELOPE` itself in this case
is bad idea, since this mode gets stored in transform op and is directly re-used for redo,
by-passing the whole init phase that shall be done in `TFM_BONESIZE` mode... So now,
we add a real new mode, `TFM_BONE_ENVELOPE_DIST`, while keeping most of existing code
and all existing behavior.

This is slightly hackish - but was already anyway, and avoids creating a full new set of
function for pretty much the same thing. As a side note, also makes it possible to
resize envelope distance outside of envelope viewing mode (from py or by adding a custom
shortcut).

source/blender/editors/include/ED_transform.h
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_ops.c

index 478cb927011070037641ebef5031cd8fcd094358..732e67a341d56787f42c8f81aab7e5159255caae 100644 (file)
@@ -83,7 +83,8 @@ enum TfmMode {
        TFM_ALIGN,
        TFM_EDGE_SLIDE,
        TFM_VERT_SLIDE,
-       TFM_SEQ_SLIDE
+       TFM_SEQ_SLIDE,
+       TFM_BONE_ENVELOPE_DIST,
 };
 
 /* TRANSFORM CONTEXTS */
index 193969ffb722390d6cf0e18121e89469c91fcbfb..3a8e7cfa91a45987b8315c8bcb665298932bfc5a 100644 (file)
@@ -2220,15 +2220,22 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
                case TFM_BONESIZE:
                {   /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
                        bArmature *arm = t->poseobj->data;
-                       if (arm->drawtype == ARM_ENVELOPE)
+                       if (arm->drawtype == ARM_ENVELOPE) {
                                initBoneEnvelope(t);
-                       else
+                               t->mode = TFM_BONE_ENVELOPE_DIST;
+                       }
+                       else {
                                initBoneSize(t);
+                       }
                        break;
                }
                case TFM_BONE_ENVELOPE:
                        initBoneEnvelope(t);
                        break;
+               case TFM_BONE_ENVELOPE_DIST:
+                       initBoneEnvelope(t);
+                       t->mode = TFM_BONE_ENVELOPE_DIST;
+                       break;
                case TFM_EDGE_SLIDE:
                {
                        const bool use_double_side = (op ? !RNA_boolean_get(op->ptr, "single_side") : true);
index cd893a4cdbcf16d13124ebc39820c597a68a2a3d..cbe24c0f578f866541582aa4d6ff366d1d8d8ec5 100644 (file)
@@ -629,10 +629,10 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr
        mul_m3_m3m3(td->axismtx, omat, pmat);
        normalize_m3(td->axismtx);
 
-       if (t->mode == TFM_BONESIZE) {
+       if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
                bArmature *arm = t->poseobj->data;
 
-               if (arm->drawtype == ARM_ENVELOPE) {
+               if ((t->mode == TFM_BONE_ENVELOPE_DIST) || (arm->drawtype == ARM_ENVELOPE)) {
                        td->loc = NULL;
                        td->val = &bone->dist;
                        td->ival = bone->dist;
@@ -719,7 +719,7 @@ int count_set_pose_transflags(int *out_mode, short around, Object *ob)
 
        /* make sure no bone can be transformed when a parent is transformed */
        /* since pchans are depsgraph sorted, the parents are in beginning of list */
-       if (mode != TFM_BONESIZE) {
+       if (!ELEM(mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
                for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
                        bone = pchan->bone;
                        if (bone->flag & BONE_TRANSFORM)
@@ -1126,7 +1126,7 @@ static void createTransArmatureVerts(TransInfo *t)
                oldtot = t->total;
 
                if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) {
-                       if (t->mode == TFM_BONESIZE) {
+                       if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
                                if (ebo->flag & BONE_SELECTED)
                                        t->total++;
                        }
@@ -1204,9 +1204,9 @@ static void createTransArmatureVerts(TransInfo *t)
                                }
 
                        }
-                       else if (t->mode == TFM_BONESIZE) {
+                       else if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
                                if (ebo->flag & BONE_SELECTED) {
-                                       if (arm->drawtype == ARM_ENVELOPE) {
+                                       if ((t->mode == TFM_BONE_ENVELOPE_DIST) || (arm->drawtype == ARM_ENVELOPE)) {
                                                td->loc = NULL;
                                                td->val = &ebo->dist;
                                                td->ival = ebo->dist;
index f943ac5ee424cd3d1beeec0a89a63119ca6812c2..637b6c7c24840eaf6eab68e8919fb3d0cbcbc258 100644 (file)
@@ -816,7 +816,7 @@ static void recalcData_objects(TransInfo *t)
                                }
                        }
                        
-                       if (!ELEM(t->mode, TFM_BONE_ROLL, TFM_BONE_ENVELOPE, TFM_BONESIZE)) {
+                       if (!ELEM(t->mode, TFM_BONE_ROLL, TFM_BONE_ENVELOPE, TFM_BONE_ENVELOPE_DIST, TFM_BONESIZE)) {
                                /* fix roll */
                                for (i = 0; i < t->total; i++, td++) {
                                        if (td->extra) {
index e119ec6632106c3cb77d345d420050a465dc78ea..013e47886ebe190c11200b2ab2df723735413fac 100644 (file)
@@ -141,6 +141,7 @@ EnumPropertyItem transform_mode_types[] =
        {TFM_MIRROR, "MIRROR", 0, "Mirror", ""},
        {TFM_BONESIZE, "BONE_SIZE", 0, "Bonesize", ""},
        {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""},
+       {TFM_BONE_ENVELOPE_DIST, "BONE_ENVELOPE_DIST", 0, "Bone_Envelope_Distance", ""},
        {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""},
        {TFM_MASK_SHRINKFATTEN, "MASK_SHRINKFATTEN", 0, "Mask_Shrinkfatten", ""},
        {TFM_GPENCIL_SHRINKFATTEN, "GPENCIL_SHRINKFATTEN", 0, "GPencil_Shrinkfatten", ""},