Fix T42334: x-mirror fails in armature with a partially mirrored chain.
authorLukas Tönne <lukas.toenne@gmail.com>
Wed, 22 Oct 2014 09:11:52 +0000 (11:11 +0200)
committerLukas Tönne <lukas.toenne@gmail.com>
Wed, 22 Oct 2014 09:11:52 +0000 (11:11 +0200)
When resetting edit bones on cancel, they also have to reset connected
parent and child bone tips and heads respectively, since these can be
modified during the transform.

source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c

index 3b92e018d4919c4319f9d6fc939408fc44f292c7..6d6a1eace734c9e1cd8742815a6191eea72b2cf8 100644 (file)
@@ -1056,11 +1056,13 @@ static void createTransPose(TransInfo *t, Object *ob)
 
 void restoreBones(TransInfo *t)
 {
+       bArmature *arm = t->obedit->data;
        BoneInitData *bid = t->customData;
-       EditBone *ebo;
+       EditBone *ebo, *children;
 
        while (bid->bone) {
                ebo = bid->bone;
+               
                ebo->dist = bid->dist;
                ebo->rad_tail = bid->rad_tail;
                ebo->roll = bid->roll;
@@ -1068,7 +1070,22 @@ void restoreBones(TransInfo *t)
                ebo->zwidth = bid->zwidth;
                copy_v3_v3(ebo->head, bid->head);
                copy_v3_v3(ebo->tail, bid->tail);
-
+               
+               /* Also move connected children, in case children's name aren't mirrored properly */
+               for (children = arm->edbo->first; children; children = children->next) {
+                       if (children->parent == ebo && children->flag & BONE_CONNECTED) {
+                               copy_v3_v3(children->head, ebo->tail);
+                               children->rad_head = ebo->rad_tail;
+                       }
+               }
+               
+               /* Also move connected parent, in case parent's name isn't mirrored properly */
+               if (ebo->parent && ebo->flag & BONE_CONNECTED) {
+                       EditBone *parent = ebo->parent;
+                       copy_v3_v3(parent->tail, ebo->head);
+                       parent->rad_tail = ebo->rad_head;
+               }
+               
                bid++;
        }
 }
index b02671e18d859bdedeaed386899ffcef997fab79..2f035949edc60c16968c831753602212e7801075 100644 (file)
@@ -779,7 +779,7 @@ static void recalcData_objects(TransInfo *t)
                else if (t->obedit->type == OB_ARMATURE) { /* no recalc flag, does pose */
                        bArmature *arm = t->obedit->data;
                        ListBase *edbo = arm->edbo;
-                       EditBone *ebo;
+                       EditBone *ebo, *ebo_parent;
                        TransData *td = t->data;
                        int i;
                        
@@ -789,17 +789,18 @@ static void recalcData_objects(TransInfo *t)
                        
                        /* Ensure all bones are correctly adjusted */
                        for (ebo = edbo->first; ebo; ebo = ebo->next) {
+                               ebo_parent = (ebo->flag & BONE_CONNECTED) ? ebo->parent : NULL;
                                
-                               if ((ebo->flag & BONE_CONNECTED) && ebo->parent) {
+                               if (ebo_parent) {
                                        /* If this bone has a parent tip that has been moved */
-                                       if (ebo->parent->flag & BONE_TIPSEL) {
-                                               copy_v3_v3(ebo->head, ebo->parent->tail);
-                                               if (t->mode == TFM_BONE_ENVELOPE) ebo->rad_head = ebo->parent->rad_tail;
+                                       if (ebo_parent->flag & BONE_TIPSEL) {
+                                               copy_v3_v3(ebo->head, ebo_parent->tail);
+                                               if (t->mode == TFM_BONE_ENVELOPE) ebo->rad_head = ebo_parent->rad_tail;
                                        }
                                        /* If this bone has a parent tip that has NOT been moved */
                                        else {
-                                               copy_v3_v3(ebo->parent->tail, ebo->head);
-                                               if (t->mode == TFM_BONE_ENVELOPE) ebo->parent->rad_tail = ebo->rad_head;
+                                               copy_v3_v3(ebo_parent->tail, ebo->head);
+                                               if (t->mode == TFM_BONE_ENVELOPE) ebo_parent->rad_tail = ebo->rad_head;
                                        }
                                }