2.5 PoseLib/KeyingSets bugfixes:
authorJoshua Leung <aligorith@gmail.com>
Thu, 16 Apr 2009 00:33:40 +0000 (00:33 +0000)
committerJoshua Leung <aligorith@gmail.com>
Thu, 16 Apr 2009 00:33:40 +0000 (00:33 +0000)
* Replaced a quicky hack needed to get PoseLib working with a proper new group-naming option for KeyingSets. Now, all builtin KeyingSets will use the name of the data (i.e. Object or PoseChannel) as the name of the group new channels are added to

* Fixed a bug with LocRotScale builtin KeyingSet, which meant that scale keyframes were not getting added.

* TAB key (toggle original pose) now works again. Previously, events were flying past too quickly.

source/blender/editors/animation/keyingsets.c
source/blender/editors/armature/poselib.c
source/blender/makesdna/DNA_anim_types.h
source/blender/makesrna/intern/rna_animation.c

index 973d953cd4bb186b6cf8b83db46e81dcc0ef75e7..02b7980f0c40e96e5e6bb94439bf804cfa76f654 100644 (file)
@@ -703,21 +703,21 @@ static bBuiltinKeyingSet def_builtin_keyingsets_v3d[] =
        /* Keying Set - "Location" ---------- */
        BI_KS_DEFINE_BEGIN("Location", 0)
                BI_KS_PATHS_BEGIN(1)
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "location", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "location", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM
                BI_KS_PATHS_END
        BI_KS_DEFINE_END,
 
        /* Keying Set - "Rotation" ---------- */
        BI_KS_DEFINE_BEGIN("Rotation", 0)
                BI_KS_PATHS_BEGIN(1)
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "rotation", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "rotation", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM
                BI_KS_PATHS_END
        BI_KS_DEFINE_END,
        
        /* Keying Set - "Scaling" ---------- */
        BI_KS_DEFINE_BEGIN("Scaling", 0)
                BI_KS_PATHS_BEGIN(1)
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "scale", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "scale", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM
                BI_KS_PATHS_END
        BI_KS_DEFINE_END,
        
@@ -725,17 +725,17 @@ static bBuiltinKeyingSet def_builtin_keyingsets_v3d[] =
        /* Keying Set - "LocRot" ---------- */
        BI_KS_DEFINE_BEGIN("LocRot", 0)
                BI_KS_PATHS_BEGIN(2)
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "location", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME), 
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "rotation", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "location", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM), 
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "rotation", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM
                BI_KS_PATHS_END
        BI_KS_DEFINE_END,
        
        /* Keying Set - "LocRotScale" ---------- */
        BI_KS_DEFINE_BEGIN("LocRotScale", 0)
-               BI_KS_PATHS_BEGIN(2)
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "location", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME), 
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "rotation", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME), 
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "scale", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME
+               BI_KS_PATHS_BEGIN(3)
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "location", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM), 
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "rotation", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM), 
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "scale", 0, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM
                BI_KS_PATHS_END
        BI_KS_DEFINE_END,
        
@@ -743,22 +743,22 @@ static bBuiltinKeyingSet def_builtin_keyingsets_v3d[] =
        /* Keying Set - "VisualLoc" ---------- */
        BI_KS_DEFINE_BEGIN("VisualLoc", 0)
                BI_KS_PATHS_BEGIN(1)
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "location", INSERTKEY_MATRIX, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "location", INSERTKEY_MATRIX, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM
                BI_KS_PATHS_END
        BI_KS_DEFINE_END,
 
        /* Keying Set - "Rotation" ---------- */
        BI_KS_DEFINE_BEGIN("VisualRot", 0)
                BI_KS_PATHS_BEGIN(1)
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "rotation", INSERTKEY_MATRIX, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "rotation", INSERTKEY_MATRIX, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM
                BI_KS_PATHS_END
        BI_KS_DEFINE_END,
        
        /* Keying Set - "VisualLocRot" ---------- */
        BI_KS_DEFINE_BEGIN("VisualLocRot", 0)
                BI_KS_PATHS_BEGIN(2)
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "location", INSERTKEY_MATRIX, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME), 
-                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "rotation", INSERTKEY_MATRIX, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_KSNAME
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "location", INSERTKEY_MATRIX, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM), 
+                       BI_KSP_DEFINE(ID_OB, KSP_TEMPLATE_OBJECT|KSP_TEMPLATE_PCHAN, "rotation", INSERTKEY_MATRIX, KSP_FLAG_WHOLE_ARRAY, KSP_GROUP_TEMPLATE_ITEM
                BI_KS_PATHS_END
        BI_KS_DEFINE_END
 };
@@ -1110,17 +1110,15 @@ int modify_keyframes (bContext *C, ListBase *dsources, bAction *act, KeyingSet *
                                        BLI_dynstr_free(pathds);
                                }
                                
-                               /* if the group name settings have not been overriden for the entire KeyingSet,
-                                * get pointer to name of group to add channels to 
+                               /* get pointer to name of group to add channels to 
+                                *      - KSP_GROUP_TEMPLATE_ITEM is handled above while constructing the paths 
                                 */
-                               if ((ks->flag & KEYINGSET_GROUPNAMES_OVERRIDE)==0) {
-                                       if (ksp->groupmode == KSP_GROUP_NONE)
-                                               groupname= NULL;
-                                       else if (ksp->groupmode == KSP_GROUP_KSNAME)
-                                               groupname= ks->name;
-                                       else
-                                               groupname= ksp->group;
-                               }
+                               if (ksp->groupmode == KSP_GROUP_NONE)
+                                       groupname= NULL;
+                               else if (ksp->groupmode == KSP_GROUP_KSNAME)
+                                       groupname= ks->name;
+                               else if (ksp->groupmode == KSP_GROUP_NAMED)
+                                       groupname= ksp->group;
                                
                                /* init arraylen and i - arraylen should be greater than i so that
                                 * normal non-array entries get keyframed correctly
index 50588a2a2581c5b11af41efcb26210beacb85802..0b5a89e823f6c78d685bda3438484914d2261fb8 100644 (file)
@@ -393,10 +393,6 @@ static int poselib_add_exec (bContext *C, wmOperator *op)
        /* make sure we've got KeyingSets to use */
        poselib_get_builtin_keyingsets();
        
-       /* turn on group-name overrides temporarily (only here) */
-       poselib_ks_locrotscale->flag |= KEYINGSET_GROUPNAMES_OVERRIDE;
-       poselib_ks_locrotscale2->flag |= KEYINGSET_GROUPNAMES_OVERRIDE;
-       
        /* init common-key-source for use by KeyingSets */
        memset(&cks, 0, sizeof(bCommonKeySrc));
        cks.id= &ob->id;
@@ -418,10 +414,6 @@ static int poselib_add_exec (bContext *C, wmOperator *op)
                }
        }
        
-       /* turn off group-name overrides so they don't affect the KeyingSets when used elsewhere */
-       poselib_ks_locrotscale->flag &= ~KEYINGSET_GROUPNAMES_OVERRIDE;
-       poselib_ks_locrotscale2->flag &= ~KEYINGSET_GROUPNAMES_OVERRIDE;
-       
        /* store new 'active' pose number */
        act->active_marker= BLI_countlist(&act->markers);
        
@@ -662,13 +654,13 @@ typedef struct tPoseLib_Backup {
 /* Makes a copy of the current pose for restoration purposes - doesn't do constraints currently */
 static void poselib_backup_posecopy (tPoseLib_PreviewData *pld)
 {
-       bActionChannel *achan;
+       bActionGroup *agrp;
        bPoseChannel *pchan;
        
        /* for each posechannel that has an actionchannel in */
-       for (achan= pld->act->chanbase.first; achan; achan= achan->next) {
+       for (agrp= pld->act->groups.first; agrp; agrp= agrp->next) {
                /* try to find posechannel */
-               pchan= get_pose_channel(pld->pose, achan->name);
+               pchan= get_pose_channel(pld->pose, agrp->name);
                
                /* backup data if available */
                if (pchan) {
@@ -1085,8 +1077,11 @@ static int poselib_preview_handle_event (bContext *C, wmOperator *op, wmEvent *e
                                
                        /* quicky compare to original */
                        case TABKEY:
-                               pld->flag &= ~PL_PREVIEW_SHOWORIGINAL;
-                               pld->redraw= PL_PREVIEW_REDRAWALL;
+                               /* only respond to one event */
+                               if (event->val == 0) {
+                                       pld->flag &= ~PL_PREVIEW_SHOWORIGINAL;
+                                       pld->redraw= PL_PREVIEW_REDRAWALL;
+                               }
                                break;
                }
                
@@ -1113,8 +1108,11 @@ static int poselib_preview_handle_event (bContext *C, wmOperator *op, wmEvent *e
                        
                /* toggle between original pose and poselib pose*/
                case TABKEY:
-                       pld->flag |= PL_PREVIEW_SHOWORIGINAL;
-                       pld->redraw= PL_PREVIEW_REDRAWALL;
+                       /* only respond to one event */
+                       if (event->val == 0) {
+                               pld->flag |= PL_PREVIEW_SHOWORIGINAL;
+                               pld->redraw= PL_PREVIEW_REDRAWALL;
+                       }
                        break;
                
                /* change to previous pose (cyclic) */
@@ -1349,7 +1347,6 @@ static void poselib_preview_cleanup (bContext *C, wmOperator *op)
                /* updates */
                if (IS_AUTOKEY_MODE(scene, NORMAL)) {
                        //remake_action_ipos(ob->action);
-                       
                }
                else {
                        /* need to trick depgraph, action is not allowed to execute on pose */
@@ -1440,6 +1437,28 @@ static int poselib_preview_invoke(bContext *C, wmOperator *op, wmEvent *event)
        return OPERATOR_RUNNING_MODAL;
 }
 
+/* Repeat operator */
+static int poselib_preview_exec (bContext *C, wmOperator *op)
+{
+       tPoseLib_PreviewData *pld;
+       
+       /* check if everything is ok, and init settings for modal operator */
+       poselib_preview_init_data(C, op);
+       pld= (tPoseLib_PreviewData *)op->customdata;
+       
+       if (pld->state == PL_PREVIEW_ERROR) {
+               /* an error occurred, so free temp mem used */
+               poselib_preview_cleanup(C, op);
+               return OPERATOR_CANCELLED;
+       }
+       
+       /* apply the active pose */
+       poselib_preview_apply(C, op);
+       
+       /* cleanup */
+       return poselib_preview_exit(C, op);
+}
+
 void POSELIB_OT_browse_interactive (wmOperatorType *ot)
 {
        /* identifiers */
@@ -1451,7 +1470,7 @@ void POSELIB_OT_browse_interactive (wmOperatorType *ot)
        ot->invoke= poselib_preview_invoke;
        ot->modal= poselib_preview_modal;
        ot->cancel= poselib_preview_cancel;
-       //ot->exec= poselib_preview_exec;
+       ot->exec= poselib_preview_exec;
        ot->poll= ED_operator_posemode;
        
        /* flags */
index af67b31554cf1286e0d6f72b72cd699fb8098a84..0c04d046fdaade99f9910d70d3f4b96cf5a72c50 100644 (file)
@@ -510,12 +510,16 @@ enum {
 
 /* KS_Path->groupmode */
 enum {
-               /* path should be grouped using its own group-name */
+               /* path should be grouped using group name stored in path */
        KSP_GROUP_NAMED = 0,
                /* path should not be grouped at all */
        KSP_GROUP_NONE,
-               /* path should be grouped under an ActionGroup KeyingSet's name */
+               /* path should be grouped using KeyingSet's name */
        KSP_GROUP_KSNAME,
+               /* path should be grouped using name of inner-most context item from templates 
+                *      - this is most useful for relative KeyingSets only
+                */
+       KSP_GROUP_TEMPLATE_ITEM,
 } eKSP_Grouping;
 
 /* KS_Path->templates  (Template Flags)
@@ -561,11 +565,6 @@ enum {
        KEYINGSET_BUILTIN               = (1<<0),
                /* keyingset does not depend on context info (i.e. paths are absolute) */
        KEYINGSET_ABSOLUTE              = (1<<1),
-       
-               /* override group name settings of paths in this Keying Set with context 
-                * info (internally used for relative paths only)
-                */
-       KEYINGSET_GROUPNAMES_OVERRIDE   = (1<<2),
 } eKS_Settings;
 
 /* Flags for use by keyframe creation/deletion calls */
index 1559144e9e5c9892d0febfac07aa0bf818ecccd3..702dc9fa65d2e3e7694ceccaa0b1ac91ddef827f 100644 (file)
@@ -82,6 +82,7 @@ void rna_def_keyingset_path(BlenderRNA *brna)
                {KSP_GROUP_NAMED, "NAMED", "Named Group", ""},
                {KSP_GROUP_NONE, "NONE", "None", ""},
                {KSP_GROUP_KSNAME, "KEYINGSET", "Keying Set Name", ""},
+               {KSP_GROUP_TEMPLATE_ITEM, "TEMPLATE", "Innermost Context-Item Name", ""},
                {0, NULL, NULL, NULL}};
        
        srna= RNA_def_struct(brna, "KeyingSetPath", NULL);