[Bf-blender-cvs] [d90b320444d] master: Fix T97533: Extrapolation of NLA strips outside current view are not rendered

Colin Basnett noreply at git.blender.org
Tue Jun 21 15:41:12 CEST 2022


Commit: d90b320444d5addf6dc5473dc0b94c975a2f9479
Author: Colin Basnett
Date:   Tue Jun 21 14:43:19 2022 +0200
Branches: master
https://developer.blender.org/rBd90b320444d5addf6dc5473dc0b94c975a2f9479

Fix T97533: Extrapolation of NLA strips outside current view are not rendered

Do a more thorough search for strips that are not visible themselves,
but still influence the viewed time range.

The problem before was that tracks not immediately visible would not be
drawn at all. The strategy for fixing this was to simply include strips
that are visible only because of their extrapolation mode.

To do this, there is now a new function `get_visible_nla_strips` which
gives a first and last `NlaTrack` that needs to  be drawn.

Tagging along with this is the removal of the strip index indicator from
the name on meta tracks. Because of the new structure of the code, it
would incur a performance penalty to restore the previous behavior
(requiring a linear search for the index). Since this number is of
virtually no utility to the user anyways (it has the look & feel of
developer debugging information), this is something I think we can
safely remove without regret.

Reviewed By: sybren

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

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

M	source/blender/editors/space_nla/nla_draw.c

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

diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c
index 6c631f46069..bb9e201d94a 100644
--- a/source/blender/editors/space_nla/nla_draw.c
+++ b/source/blender/editors/space_nla/nla_draw.c
@@ -621,7 +621,6 @@ static void nla_draw_strip(SpaceNla *snla,
 static void nla_draw_strip_text(AnimData *adt,
                                 NlaTrack *nlt,
                                 NlaStrip *strip,
-                                int index,
                                 View2D *v2d,
                                 float xminc,
                                 float xmaxc,
@@ -636,7 +635,7 @@ static void nla_draw_strip_text(AnimData *adt,
 
   /* just print the name and the range */
   if (strip->flag & NLASTRIP_FLAG_TEMP_META) {
-    str_len = BLI_snprintf_rlen(str, sizeof(str), "%d) Temp-Meta", index);
+    str_len = BLI_snprintf_rlen(str, sizeof(str), "Temp-Meta");
   }
   else {
     str_len = BLI_strncpy_rlen(str, strip->name, sizeof(str));
@@ -702,6 +701,89 @@ static void nla_draw_strip_frames_text(
 
 /* ---------------------- */
 
+/**
+ * Gets the first and last visible NLA strips on a track.
+ * Note that this also includes tracks that might only be
+ * visible because of their extendmode.
+ */
+static ListBase get_visible_nla_strips(NlaTrack *nlt, View2D *v2d)
+{
+  if (BLI_listbase_is_empty(&nlt->strips)) {
+    ListBase empty = {NULL, NULL};
+    return empty;
+  }
+
+  NlaStrip *first = NULL;
+  NlaStrip *last = NULL;
+
+  /* Find the first strip that is within the bounds of the view. */
+  LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) {
+    if (BKE_nlastrip_within_bounds(strip, v2d->cur.xmin, v2d->cur.xmax)) {
+      first = last = strip;
+      break;
+    }
+  }
+
+  const bool has_strips_within_bounds = first != NULL;
+
+  if (has_strips_within_bounds) {
+    /* Find the last visible strip. */
+    for (NlaStrip *strip = first->next; strip; strip = strip->next) {
+      if (!BKE_nlastrip_within_bounds(strip, v2d->cur.xmin, v2d->cur.xmax)) {
+        break;
+      }
+      last = strip;
+    }
+    /* Check if the first strip is adjacent to a strip outside the view to the left
+     * that has an extendmode region that should be drawn.
+     * If so, adjust the first strip to include drawing that strip as well.
+     */
+    NlaStrip *prev = first->prev;
+    if (prev && prev->extendmode != NLASTRIP_EXTEND_NOTHING) {
+      first = prev;
+    }
+  }
+  else {
+    /* No immediately visible strips.
+     * Figure out where our view is relative to the strips, then determine
+     * if the view is adjacent to a strip that should have its extendmode
+     * rendered.
+     */
+    NlaStrip *first_strip = nlt->strips.first;
+    NlaStrip *last_strip = nlt->strips.last;
+    if (first_strip && v2d->cur.xmax < first_strip->start &&
+        first_strip->extendmode == NLASTRIP_EXTEND_HOLD) {
+      /* The view is to the left of all strips and the first strip has an
+       * extendmode that should be drawn.
+       */
+      first = last = first_strip;
+    }
+    else if (last_strip && v2d->cur.xmin > last_strip->end &&
+             last_strip->extendmode != NLASTRIP_EXTEND_NOTHING) {
+      /* The view is to the right of all strips and the last strip has an
+       * extendmode that should be drawn.
+       */
+      first = last = last_strip;
+    }
+    else {
+      /* The view is in the middle of two strips. */
+      LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) {
+        /* Find the strip to the left by finding the strip to the right and getting its prev. */
+        if (v2d->cur.xmax < strip->start) {
+          /* If the strip to the left has an extendmode, set that as the only visible strip. */
+          if (strip->prev && strip->prev->extendmode != NLASTRIP_EXTEND_NOTHING) {
+            first = last = strip->prev;
+          }
+          break;
+        }
+      }
+    }
+  }
+
+  ListBase visible_strips = {first, last};
+  return visible_strips;
+}
+
 void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *region)
 {
   View2D *v2d = &region->v2d;
@@ -737,29 +819,26 @@ void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *region)
         case ANIMTYPE_NLATRACK: {
           AnimData *adt = ale->adt;
           NlaTrack *nlt = (NlaTrack *)ale->data;
-          NlaStrip *strip;
-          int index;
-
-          /* draw each strip in the track (if visible) */
-          for (strip = nlt->strips.first, index = 1; strip; strip = strip->next, index++) {
-            if (BKE_nlastrip_within_bounds(strip, v2d->cur.xmin, v2d->cur.xmax)) {
-              const float xminc = strip->start + text_margin_x;
-              const float xmaxc = strip->end - text_margin_x;
-
-              /* draw the visualization of the strip */
-              nla_draw_strip(snla, adt, nlt, strip, v2d, ymin, ymax);
-
-              /* add the text for this strip to the cache */
-              if (xminc < xmaxc) {
-                nla_draw_strip_text(adt, nlt, strip, index, v2d, xminc, xmaxc, ymin, ymax);
-              }
-
-              /* if transforming strips (only real reason for temp-metas currently),
-               * add to the cache the frame numbers of the strip's extents
-               */
-              if (strip->flag & NLASTRIP_FLAG_TEMP_META) {
-                nla_draw_strip_frames_text(nlt, strip, v2d, ymin, ymax);
-              }
+          ListBase visible_nla_strips = get_visible_nla_strips(nlt, v2d);
+
+          /* Draw each visible strip in the track. */
+          LISTBASE_FOREACH (NlaStrip *, strip, &visible_nla_strips) {
+            const float xminc = strip->start + text_margin_x;
+            const float xmaxc = strip->end - text_margin_x;
+
+            /* draw the visualization of the strip */
+            nla_draw_strip(snla, adt, nlt, strip, v2d, ymin, ymax);
+
+            /* add the text for this strip to the cache */
+            if (xminc < xmaxc) {
+              nla_draw_strip_text(adt, nlt, strip, v2d, xminc, xmaxc, ymin, ymax);
+            }
+
+            /* if transforming strips (only real reason for temp-metas currently),
+             * add to the cache the frame numbers of the strip's extents
+             */
+            if (strip->flag & NLASTRIP_FLAG_TEMP_META) {
+              nla_draw_strip_frames_text(nlt, strip, v2d, ymin, ymax);
             }
           }
           break;



More information about the Bf-blender-cvs mailing list