[Bf-blender-cvs] [b0d9e6797fb] master: Fix T87173: wrong Auto-Snap in animation editors

Germano Cavalcante noreply at git.blender.org
Thu Aug 19 15:34:28 CEST 2021


Commit: b0d9e6797fb866e7a58876c7977c98a190070310
Author: Germano Cavalcante
Date:   Thu Aug 19 10:28:43 2021 -0300
Branches: master
https://developer.blender.org/rBb0d9e6797fb866e7a58876c7977c98a190070310

Fix T87173: wrong Auto-Snap in animation editors

This was partially broken with {rBde9ea94fc6f}.

The `Frame Step` and `Second Step` snapping options were working as if
they were `Nearest Frame` and `Nearest Second` respectively in the
`Dope Sheet` and `NLA` editors.

In the `Graph Editor` the problem was more serious:
"Second Step: ... The keyframe itself moves along as though in snapping
were active at all, while its handles 'stay behind' until it reaches
the next second boundary, at which point the teleport handles to
'catch up'".

The snapping code for these modes was spread across the transform
mode code and `recalcData` of each data type. Therefore, create a
unified snapping code for these options so that all issues are fixed in
one place.

Differetial Revision: https://developer.blender.org/D12241

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

M	source/blender/editors/transform/transform_convert.c
M	source/blender/editors/transform/transform_convert.h
M	source/blender/editors/transform/transform_convert_action.c
M	source/blender/editors/transform/transform_convert_graph.c
M	source/blender/editors/transform/transform_convert_nla.c
M	source/blender/editors/transform/transform_mode_timescale.c
M	source/blender/editors/transform/transform_mode_timetranslate.c
M	source/blender/editors/transform/transform_snap.h
M	source/blender/editors/transform/transform_snap_animation.c

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

diff --git a/source/blender/editors/transform/transform_convert.c b/source/blender/editors/transform/transform_convert.c
index 3f730956dd0..094ae080de0 100644
--- a/source/blender/editors/transform/transform_convert.c
+++ b/source/blender/editors/transform/transform_convert.c
@@ -1662,6 +1662,23 @@ void animrecord_check_state(TransInfo *t, struct Object *ob)
   }
 }
 
+void transform_convert_flush_handle2D(TransData *td, TransData2D *td2d, const float inv_unit_scale)
+{
+  /* If the handles are to be moved too
+   * (as side-effect of keyframes moving, to keep the general effect)
+   * offset them by the same amount so that the general angles are maintained
+   * (i.e. won't change while handles are free-to-roam and keyframes are snap-locked).
+   */
+  if ((td->flag & TD_MOVEHANDLE1) && td2d->h1) {
+    td2d->h1[0] = td2d->ih1[0] + td->loc[0] - td->iloc[0];
+    td2d->h1[1] = td2d->ih1[1] + (td->loc[1] - td->iloc[1]) * inv_unit_scale;
+  }
+  if ((td->flag & TD_MOVEHANDLE2) && td2d->h2) {
+    td2d->h2[0] = td2d->ih2[0] + td->loc[0] - td->iloc[0];
+    td2d->h2[1] = td2d->ih2[1] + (td->loc[1] - td->iloc[1]) * inv_unit_scale;
+  }
+}
+
 /* called for updating while transform acts, once per redraw */
 void recalcData(TransInfo *t)
 {
diff --git a/source/blender/editors/transform/transform_convert.h b/source/blender/editors/transform/transform_convert.h
index 55731bfa321..fa34e2555d6 100644
--- a/source/blender/editors/transform/transform_convert.h
+++ b/source/blender/editors/transform/transform_convert.h
@@ -43,6 +43,9 @@ void sort_trans_data_dist(TransInfo *t);
 void createTransData(struct bContext *C, TransInfo *t);
 bool clipUVTransform(TransInfo *t, float vec[2], const bool resize);
 void clipUVData(TransInfo *t);
+void transform_convert_flush_handle2D(TransData *td,
+                                      TransData2D *td2d,
+                                      const float inv_unit_scale);
 void recalcData(TransInfo *t);
 
 /* transform_convert_mesh.c */
diff --git a/source/blender/editors/transform/transform_convert_action.c b/source/blender/editors/transform/transform_convert_action.c
index 30cb9fa20e5..8a3b254be5c 100644
--- a/source/blender/editors/transform/transform_convert_action.c
+++ b/source/blender/editors/transform/transform_convert_action.c
@@ -45,6 +45,8 @@
 #include "WM_types.h"
 
 #include "transform.h"
+#include "transform_snap.h"
+
 #include "transform_convert.h"
 
 /* helper struct for gp-frame transforms */
@@ -604,6 +606,19 @@ void recalcData_actedit(TransInfo *t)
     flushTransIntFrameActionData(t);
   }
 
+  /* Flush 2d vector. */
+  TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+  const short autosnap = getAnimEdit_SnapMode(t);
+  TransData *td;
+  TransData2D *td2d;
+  int i = 0;
+  for (td = tc->data, td2d = tc->data_2d; i < tc->data_len; i++, td++, td2d++) {
+    if ((autosnap != SACTSNAP_OFF) && (t->state != TRANS_CANCEL) && !(td->flag & TD_NOTIMESNAP)) {
+      transform_snap_anim_flush_data(t, td, autosnap, td->loc);
+    }
+    transform_convert_flush_handle2D(td, td2d, 1.0f);
+  }
+
   if (ac.datatype != ANIMCONT_MASK) {
     /* Get animdata blocks visible in editor,
      * assuming that these will be the ones where things changed. */
diff --git a/source/blender/editors/transform/transform_convert_graph.c b/source/blender/editors/transform/transform_convert_graph.c
index c0acdd89b02..d22277f9d91 100644
--- a/source/blender/editors/transform/transform_convert_graph.c
+++ b/source/blender/editors/transform/transform_convert_graph.c
@@ -40,6 +40,8 @@
 #include "UI_view2d.h"
 
 #include "transform.h"
+#include "transform_snap.h"
+
 #include "transform_convert.h"
 #include "transform_snap.h"
 
@@ -662,10 +664,9 @@ static void flushTransGraphData(TransInfo *t)
   TransData *td;
   TransData2D *td2d;
   TransDataGraph *tdg;
-  Scene *scene = t->scene;
-  double secf = FPS;
   int a;
 
+  const short autosnap = getAnimEdit_SnapMode(t);
   TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
 
   /* flush to 2d vector from internally used 3d vector */
@@ -681,22 +682,8 @@ static void flushTransGraphData(TransInfo *t)
      * - Only apply to keyframes (but never to handles).
      * - Don't do this when canceling, or else these changes won't go away.
      */
-    if ((t->state != TRANS_CANCEL) && (td->flag & TD_NOTIMESNAP) == 0) {
-      const short autosnap = getAnimEdit_SnapMode(t);
-      switch (autosnap) {
-        case SACTSNAP_FRAME: /* snap to nearest frame */
-          td2d->loc[0] = floor((double)td2d->loc[0] + 0.5);
-          break;
-
-        case SACTSNAP_SECOND: /* snap to nearest second */
-          td2d->loc[0] = floor(((double)td2d->loc[0] / secf) + 0.5) * secf;
-          break;
-
-        case SACTSNAP_MARKER: /* snap to nearest marker */
-          td2d->loc[0] = (float)ED_markers_find_nearest_marker_time(&t->scene->markers,
-                                                                    td2d->loc[0]);
-          break;
-      }
+    if ((autosnap != SACTSNAP_OFF) && (t->state != TRANS_CANCEL) && !(td->flag & TD_NOTIMESNAP)) {
+      transform_snap_anim_flush_data(t, td, autosnap, td->loc);
     }
 
     /* we need to unapply the nla-mapping from the time in some situations */
@@ -707,32 +694,6 @@ static void flushTransGraphData(TransInfo *t)
       td2d->loc2d[0] = td2d->loc[0];
     }
 
-    /** Time-stepping auto-snapping modes don't get applied for Graph Editor transforms,
-     * as these use the generic transform modes which don't account for this sort of thing.
-     * These ones aren't affected by NLA mapping, so we do this after the conversion...
-     *
-     * \note We also have to apply to td->loc,
-     * as that's what the handle-adjustment step below looks to,
-     * otherwise we get "swimming handles".
-     *
-     * \note We don't do this when canceling transforms, or else these changes don't go away.
-     */
-    if ((t->state != TRANS_CANCEL) && (td->flag & TD_NOTIMESNAP) == 0) {
-      const short autosnap = getAnimEdit_SnapMode(t);
-      switch (autosnap) {
-        case SACTSNAP_STEP: /* frame step */
-          td2d->loc2d[0] = floor((double)td2d->loc[0] + 0.5);
-          td->loc[0] = floor((double)td->loc[0] + 0.5);
-          break;
-
-        case SACTSNAP_TSTEP: /* second step */
-          /* XXX: the handle behavior in this case is still not quite right... */
-          td2d->loc[0] = floor(((double)td2d->loc[0] / secf) + 0.5) * secf;
-          td->loc[0] = floor(((double)td->loc[0] / secf) + 0.5) * secf;
-          break;
-      }
-    }
-
     /* if int-values only, truncate to integers */
     if (td->flag & TD_INTVALUES) {
       td2d->loc2d[1] = floorf(td2d->loc[1] * inv_unit_scale - tdg->offset + 0.5f);
@@ -741,15 +702,7 @@ static void flushTransGraphData(TransInfo *t)
       td2d->loc2d[1] = td2d->loc[1] * inv_unit_scale - tdg->offset;
     }
 
-    if ((td->flag & TD_MOVEHANDLE1) && td2d->h1) {
-      td2d->h1[0] = td2d->ih1[0] + td->loc[0] - td->iloc[0];
-      td2d->h1[1] = td2d->ih1[1] + (td->loc[1] - td->iloc[1]) * inv_unit_scale;
-    }
-
-    if ((td->flag & TD_MOVEHANDLE2) && td2d->h2) {
-      td2d->h2[0] = td2d->ih2[0] + td->loc[0] - td->iloc[0];
-      td2d->h2[1] = td2d->ih2[1] + (td->loc[1] - td->iloc[1]) * inv_unit_scale;
-    }
+    transform_convert_flush_handle2D(td, td2d, inv_unit_scale);
   }
 }
 
diff --git a/source/blender/editors/transform/transform_convert_nla.c b/source/blender/editors/transform/transform_convert_nla.c
index 4d98b7a489f..7e5b80c2453 100644
--- a/source/blender/editors/transform/transform_convert_nla.c
+++ b/source/blender/editors/transform/transform_convert_nla.c
@@ -41,6 +41,8 @@
 #include "RNA_access.h"
 
 #include "transform.h"
+#include "transform_snap.h"
+
 #include "transform_convert.h"
 #include "transform_snap.h"
 
@@ -292,21 +294,30 @@ void createTransNlaData(bContext *C, TransInfo *t)
 void recalcData_nla(TransInfo *t)
 {
   SpaceNla *snla = (SpaceNla *)t->area->spacedata.first;
-  Scene *scene = t->scene;
-  double secf = FPS;
-  int i;
 
   TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
-  TransDataNla *tdn = tc->custom.type.data;
+
+  /* handle auto-snapping
+   * NOTE: only do this when transform is still running, or we can't restore
+   */
+  if (t->state != TRANS_CANCEL) {
+    const short autosnap = getAnimEdit_SnapMode(t);
+    if (autosnap != SACTSNAP_OFF) {
+      TransData *td = tc->data;
+      for (int i = 0; i < tc->data_len; i++, td++) {
+        transform_snap_anim_flush_data(t, td, autosnap, td->loc);
+      }
+    }
+  }
 
   /* For each strip we've got, perform some additional validation of the values
    * that got set before using RNA to set the value (which does some special
    * operations when setting these values to make sure that everything works ok).
    */
-  for (i = 0; i < tc->data_len; i++, tdn++) {
+  TransDataNla *tdn = tc->custom.type.data;
+  for (int i = 0; i < tc->data_len; i++, tdn++) {
     NlaStrip *strip = tdn->strip;
     PointerRNA strip_ptr;
-    short iter;
     int delta_y1, delta_y2;
 
     /* if this tdn has no handles, that means it is just a dummy that should be skipped */
@@ -370,8 +381,7 @@ void recalcData_nla(TransInfo *t)
       next = next->next;
     }
 
-    for (iter = 0; iter < 5; iter++) {
-
+    for (short iter = 0; iter < 5; iter++) {
       const bool pExceeded = (prev != NULL) && (tdn->h1[0] < prev->end);
       const bool nExceeded = (next != NULL) && (tdn->h2[0] > next->start);
 
@@ -410,51 +420,6 @@ void recalcData_nla(TransInfo *t)
       }
     }
 
-    /* handle auto-snapping
-     * NOTE: only do this when transform is still running, or we can't restore
-     */
-    if (t->state != TRANS_CANCEL) {
-      const short autosnap = getAnimEdit_SnapMode(t);
-      switch (autosnap) {
-        case SACTSNAP_FRAME: /* snap to nearest frame */
-        case SACTSNAP_STEP:  /* frame step - this is basically the same,
-                              * since we don't have any remapping going on */
-        {
-          tdn->h1[0] = floorf(tdn->h1[0] + 0.5f);
-          tdn->h2[0] = floorf(tdn->h2[0] + 0.5f);
-          break;
-        }
-
-        case SACTSNAP_SECOND: /* snap to nearest second 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list