Version patching fixes for F-Curves (as required for fixes for T48988 and T52009)
authorJoshua Leung <aligorith@gmail.com>
Tue, 5 Dec 2017 11:54:39 +0000 (00:54 +1300)
committerJoshua Leung <aligorith@gmail.com>
Tue, 5 Dec 2017 11:54:39 +0000 (00:54 +1300)
* For the T48988 fix (i.e. separate Ease In/Out properties for Bendy Bones
  in Edit vs Pose modes), old animation data needed to be patched to use
  the new property names. This is needed to partially fix some of the
  issues in T53356 (though the Rigify code itself still needs to be patched).

* For the T52009 fix, old files needed to have the frame_start and frame_end
  properties on the FModifier (base-class) updated to match that of the
  FMod_Stepped type-specific class. This wasn't done in the earlier commit
  since it wasn't worth going through all animation data just for the sake
  of updating these relatively-rare settings, but since we're doing it anyway
  now, it makes sense to include this here.

source/blender/blenkernel/intern/anim_sys.c
source/blender/blenloader/intern/versioning_270.c

index 5aa13cad61d5c08e88266760289cc3b8e645cbb6..6107bb1e32e75ef8d1c39f65447c489c7568537b 100644 (file)
@@ -1047,8 +1047,9 @@ static void nlastrips_apply_all_curves_cb(ID *id, ListBase *strips, AllFCurvesCb
 }
 
 /* Helper for BKE_fcurves_main_cb() - Dispatch wrapped operator to all F-Curves */
-static void adt_apply_all_fcurves_cb(ID *id, AnimData *adt, AllFCurvesCbWrapper *wrapper)
+static void adt_apply_all_fcurves_cb(ID *id, AnimData *adt, void *wrapper_data)
 {
+       AllFCurvesCbWrapper *wrapper = wrapper_data;
        NlaTrack *nlt;
        
        if (adt->action) {
index 095f21a5b06746f14967e1324147003aee856d5a..fa7bf0c7dee8c116dcc3bd1b449ce3d658349cf2 100644 (file)
@@ -62,6 +62,8 @@
 #include "BKE_animsys.h"
 #include "BKE_brush.h"
 #include "BKE_colortools.h"
+#include "BKE_fcurve.h"
+#include "BKE_gpencil.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_mask.h"
@@ -71,7 +73,6 @@
 #include "BKE_sequencer.h"
 #include "BKE_screen.h"
 #include "BKE_tracking.h"
-#include "BKE_gpencil.h"
 
 #include "BLI_math.h"
 #include "BLI_listbase.h"
@@ -285,6 +286,67 @@ static void do_versions_compositor_render_passes(bNodeTree *ntree)
        }
 }
 
+
+static char *replace_bbone_easing_rnapath(char *old_path)
+{
+       char *new_path = NULL;
+       
+       /* NOTE: This will break paths for any bones/custom-properties
+        * which happen be named after the bbone property id's
+        */
+       if (strstr(old_path, "bbone_in"))
+               new_path = BLI_str_replaceN(old_path, "bbone_in", "bbone_easein");
+       else if (strstr(old_path, "bbone_out"))
+               new_path = BLI_str_replaceN(old_path, "bbone_out", "bbone_easeout");
+       
+       if (new_path) {
+               MEM_freeN(old_path);
+               return new_path;
+       }
+       else {
+               return old_path;
+       }
+}
+
+static void do_version_bbone_easing_fcurve_fix(ID *UNUSED(id), FCurve *fcu, void *UNUSED(user_data))
+{
+       /* F-Curve's path (for bbone_in/out) */
+       if (fcu->rna_path) {
+               fcu->rna_path = replace_bbone_easing_rnapath(fcu->rna_path);
+       }
+       
+       /* Driver -> Driver Vars (for bbone_in/out) */
+       if (fcu->driver) {
+               for (DriverVar *dvar = fcu->driver->variables.first; dvar; dvar = dvar->next) {
+                       DRIVER_TARGETS_LOOPER(dvar)
+                       {
+                               if (dtar->rna_path) {
+                                       dtar->rna_path = replace_bbone_easing_rnapath(dtar->rna_path);
+                               }
+                       }
+                       DRIVER_TARGETS_LOOPER_END;
+               }
+       }
+       
+       /* FModifiers -> Stepped (for frame_start/end) */
+       if (fcu->modifiers.first) {
+               for (FModifier *fcm = fcu->modifiers.first; fcm; fcm = fcm->next) {
+                       if (fcm->type == FMODIFIER_TYPE_STEPPED) {
+                               FMod_Stepped *data = fcm->data;
+                               
+                               /* Modifier doesn't work if the modifier's copy of start/end frame are both 0
+                                * as those were only getting written to the fcm->data copy (T52009)
+                                */
+                               if ((fcm->sfra == fcm->efra) && (fcm->sfra == 0)) {
+                                       fcm->sfra = data->start_frame;
+                                       fcm->efra = data->end_frame;
+                               }
+                       }
+               }
+       }
+}
+
+
 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 {
        if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
@@ -1721,4 +1783,10 @@ void do_versions_after_linking_270(Main *main)
                        }
                } FOREACH_NODETREE_END
        }
+       
+       if (!MAIN_VERSION_ATLEAST(main, 279, 2)) {
+               /* B-Bones (bbone_in/out -> bbone_easein/out) + Stepped FMod Frame Start/End fix */
+               /* if (!DNA_struct_elem_find(fd->filesdna, "Bone", "float", "bbone_easein")) */
+               BKE_fcurves_main_cb(main, do_version_bbone_easing_fcurve_fix, NULL);
+       }
 }