Commit: 5ad594dab90e3d202e0ee48ee3c45ec7c66dd6a5
Author: Alexander Gavrilov
Date:   Mon May 3 17:27:53 2021 +0300
Branches: temp-angavrilov
https://developer.blender.org/rB5ad594dab90e3d202e0ee48ee3c45ec7c66dd6a5

Animation: support filtering for curves that have cycle issues.

It is possible to have curves with cyclic extrapolation that
have a mismatch in their end keyframes, causing a jump.

Also, since the looping behavior is defined per curve rather than at
action level, it is possible for curve loop periods to get out of
sync with each other. This commit adds an option to compare curves
against the manual frame range specified in the action, and treat
any mismatches as errors for the purpose of F-Curve filtering.

When enabled, the check verifies that end values of cyclic curves
match, curves within a cyclic action have valid cyclic extrapolation,
and the action period evenly divides by the curve period (since
a curve looping at e.g. half of the action period length still
repeats in sync with the action).

Ref: D11803

Differential Revision: https://developer.blender.org/D13349

===================================================================

M       release/scripts/startup/bl_ui/space_dopesheet.py
M       source/blender/editors/animation/anim_filter.c
M       source/blender/makesdna/DNA_action_types.h
M       source/blender/makesrna/intern/rna_action.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_dopesheet.py 
b/release/scripts/startup/bl_ui/space_dopesheet.py
index 99b33840051..f2854440e2a 100644
--- a/release/scripts/startup/bl_ui/space_dopesheet.py
+++ b/release/scripts/startup/bl_ui/space_dopesheet.py
@@ -63,6 +63,12 @@ class DopesheetFilterPopoverBase:
         else:  # graph and dopesheet editors - F-Curves and drivers only
             col.prop(dopesheet, "show_only_errors", icon='NONE')
 
+            col.separator()
+
+            col2 = col.column(align=True)
+            col2.active = dopesheet.show_only_errors
+            col2.prop(dopesheet, "show_cycle_errors")
+
     # Name/Membership Filters
     # XXX: Perhaps these should just stay in the headers (exclusively)?
     @classmethod
diff --git a/source/blender/editors/animation/anim_filter.c 
b/source/blender/editors/animation/anim_filter.c
index f619837a3c5..4f5201a6665 100644
--- a/source/blender/editors/animation/anim_filter.c
+++ b/source/blender/editors/animation/anim_filter.c
@@ -63,6 +63,7 @@
 #include "BLI_alloca.h"
 #include "BLI_blenlib.h"
 #include "BLI_ghash.h"
+#include "BLI_math.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
@@ -1207,6 +1208,53 @@ static bool skip_fcurve_with_name(
   return true;
 }
 
+/* Check if the F-Curve doesn't cycle properly based on action settings. */
+static bool fcurve_has_cycle_errors(const FCurve *fcu, const bAction *act)
+{
+  /* Check if the curve is cyclic. */
+  const eFCU_Cycle_Type cycle_type = BKE_fcurve_get_cycle_type(fcu);
+
+  if (cycle_type == FCU_CYCLE_NONE) {
+    /* Curves in a cyclic action should be cyclic; in an ordinary action 
either way is fine. */
+    return BKE_action_is_cyclic(act);
+  }
+
+  /* Check if the curve has enough points. */
+  if (fcu->totvert < 2 || !fcu->bezt) {
+    return true;
+  }
+
+  const BezTriple *first = &fcu->bezt[0], *last = &fcu->bezt[fcu->totvert - 1];
+
+  if (BKE_action_is_cyclic(act)) {
+    /* Check that it has a nonzero period length. */
+    const float curve_period = last->vec[1][0] - first->vec[1][0];
+
+    if (curve_period < 0.1f) {
+      return true;
+    }
+
+    /* Check that the action period is divisible by the curve period. */
+    const float action_period = act->frame_end - act->frame_start;
+    const float gap = action_period - roundf(action_period / curve_period) * 
curve_period;
+
+    if (fabsf(gap) > 1e-3f) {
+      return true;
+    }
+  }
+
+  /* In case of a perfect cycle, check that the start and end values match. */
+  if (cycle_type == FCU_CYCLE_PERFECT) {
+    const float magnitude = max_fff(fabsf(first->vec[1][1]), 
fabsf(last->vec[1][1]), 0.01f);
+
+    if (fabsf(first->vec[1][1] - last->vec[1][1]) > magnitude * 1e-4f) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 /**
  * Check if F-Curve has errors and/or is disabled
  *
@@ -1253,6 +1301,7 @@ static FCurve *animfilter_fcurve_next(bDopeSheet *ads,
                                       FCurve *first,
                                       eAnim_ChannelType channel_type,
                                       int filter_mode,
+                                      bAction *act,
                                       void *owner,
                                       ID *owner_id)
 {
@@ -1304,7 +1353,9 @@ static FCurve *animfilter_fcurve_next(bDopeSheet *ads,
             /* error-based filtering... */
             if ((ads) && (ads->filterflag & ADS_FILTER_ONLY_ERRORS)) {
               /* skip if no errors... */
-              if (fcurve_has_errors(fcu) == false) {
+              if (fcurve_has_errors(fcu) == false &&
+                  !((ads->filterflag & ADS_FILTER_CYCLE_ERRORS) &&
+                    fcurve_has_cycle_errors(fcu, act))) {
                 continue;
               }
             }
@@ -1326,6 +1377,7 @@ static size_t animfilter_fcurves(ListBase *anim_data,
                                  FCurve *first,
                                  eAnim_ChannelType fcurve_type,
                                  int filter_mode,
+                                 bAction *act,
                                  void *owner,
                                  ID *owner_id,
                                  ID *fcurve_owner_id)
@@ -1346,7 +1398,7 @@ static size_t animfilter_fcurves(ListBase *anim_data,
    *    Back to step 2 :)
    */
   for (fcu = first;
-       (fcu = animfilter_fcurve_next(ads, fcu, fcurve_type, filter_mode, 
owner, owner_id));
+       (fcu = animfilter_fcurve_next(ads, fcu, fcurve_type, filter_mode, act, 
owner, owner_id));
        fcu = fcu->next) {
     if (UNLIKELY(fcurve_type == ANIMTYPE_NLACURVE)) {
       /* NLA Control Curve - Basically the same as normal F-Curves,
@@ -1421,11 +1473,18 @@ static size_t animfilter_act_group(bAnimContext *ac,
         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {
           /* get first F-Curve which can be used here */
           FCurve *first_fcu = animfilter_fcurve_next(
-              ads, agrp->channels.first, ANIMTYPE_FCURVE, filter_mode, agrp, 
owner_id);
+              ads, agrp->channels.first, ANIMTYPE_FCURVE, filter_mode, act, 
agrp, owner_id);
 
           /* filter list, starting from this F-Curve */
-          tmp_items += animfilter_fcurves(
-              &tmp_data, ads, first_fcu, ANIMTYPE_FCURVE, filter_mode, agrp, 
owner_id, &act->id);
+          tmp_items += animfilter_fcurves(&tmp_data,
+                                          ads,
+                                          first_fcu,
+                                          ANIMTYPE_FCURVE,
+                                          filter_mode,
+                                          act,
+                                          agrp,
+                                          owner_id,
+                                          &act->id);
         }
       }
     }
@@ -1490,7 +1549,7 @@ static size_t animfilter_action(bAnimContext *ac,
   if (!(filter_mode & ANIMFILTER_ACTGROUPED)) {
     FCurve *firstfcu = (lastchan) ? (lastchan->next) : (act->curves.first);
     items += animfilter_fcurves(
-        anim_data, ads, firstfcu, ANIMTYPE_FCURVE, filter_mode, NULL, 
owner_id, &act->id);
+        anim_data, ads, firstfcu, ANIMTYPE_FCURVE, filter_mode, act, NULL, 
owner_id, &act->id);
   }
 
   /* return the number of items added to the list */
@@ -1623,6 +1682,7 @@ static size_t animfilter_nla_controls(
                                         strip->fcurves.first,
                                         ANIMTYPE_NLACURVE,
                                         filter_mode,
+                                        NULL,
                                         strip,
                                         owner_id,
                                         owner_id);
@@ -1679,8 +1739,15 @@ static size_t animfilter_block_data(
           items += animfilter_nla(ac, anim_data, ads, adt, filter_mode, id);
         },
         { /* Drivers */
-          items += animfilter_fcurves(
-              anim_data, ads, adt->drivers.first, ANIMTYPE_FCURVE, 
filter_mode, NULL, id, id);
+          items += animfilter_fcurves(anim_data,
+                                      ads,
+                                      adt->drivers.first,
+                                      ANIMTYPE_FCURVE,
+                                      filter_mode,
+                                      NULL,
+                                      NULL,
+                                      id,
+                                      id);
         },
         { /* NLA Control Keyframes */
           items += animfilter_nla_controls(anim_data, ads, adt, filter_mode, 
id);
diff --git a/source/blender/makesdna/DNA_action_types.h 
b/source/blender/makesdna/DNA_action_types.h
index 481c9f5e673..c1ef9b7c523 100644
--- a/source/blender/makesdna/DNA_action_types.h
+++ b/source/blender/makesdna/DNA_action_types.h
@@ -777,6 +777,8 @@ typedef enum eDopeSheet_FilterFlag {
   ADS_FILTER_INCL_HIDDEN = (1 << 26),
   /** show only F-Curves which are disabled/have errors - for debugging 
drivers */
   ADS_FILTER_ONLY_ERRORS = (1 << 28),
+  /** treat cyclic extrapolation issues as errors for the previous option */
+  ADS_FILTER_CYCLE_ERRORS = (1 << 29),
 
 #if 0
   /** combination filters (some only used at runtime) */
diff --git a/source/blender/makesrna/intern/rna_action.c 
b/source/blender/makesrna/intern/rna_action.c
index 14f4a82c62b..981cc694e27 100644
--- a/source/blender/makesrna/intern/rna_action.c
+++ b/source/blender/makesrna/intern/rna_action.c
@@ -420,6 +420,17 @@ static void rna_def_dopesheet(BlenderRNA *brna)
   RNA_def_property_ui_icon(prop, ICON_ERROR, 0);
   RNA_def_property_update(prop, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
 
+  prop = RNA_def_property(srna, "show_cycle_errors", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "filterflag", 
ADS_FILTER_CYCLE_ERRORS);
+  RNA_def_property_ui_text(
+      prop,
+      "Cyclic Extrapolation Issues",
+      "Treat cyclic extrapolation issues as errors for the Only Show Errors 
option, detecting "
+      "cyclic curves with mismatch between the end keys, or curves that are 
non-cyclic or have "
+      "the wrong period in a cyclic action");
+  RNA_def_property_ui_icon(prop, ICON_RECOVER_LAST, 0);
+  RNA_def_property_update(prop, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
+
   /* Object Collection Filtering Settings */
   prop = RNA_def_property(srna, "filter_collection", PROP_POINTER, PROP_NONE);
   RNA_def_property_pointer_sdna(prop, NULL, "filter_grp");

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to