[Bf-blender-cvs] [fa67b84c348] master: NLA: Udating Blend-in and Blend-out values to clamp on NLA strip Transform

Nate Rupsis noreply at git.blender.org
Thu Jan 19 19:47:19 CET 2023


Commit: fa67b84c348b36fdc25da11c428738e9f1f8a860
Author: Nate Rupsis
Date:   Thu Jan 19 13:42:23 2023 -0500
Branches: master
https://developer.blender.org/rBfa67b84c348b36fdc25da11c428738e9f1f8a860

NLA: Udating Blend-in and Blend-out values to clamp on NLA strip Transform

Previously, transforming a clip (scaling, repeat, etc) wouldn't re-calculate the blend-in and blend-out values, leading to over / undershoot, and a visual clip artifact

Old:

{F14045003}

This patch adds re-calculation logic (new `BKE_nlastrip_recalculate_blend()`  method) to the blend-in/out on transformations to clamp values, and avoid over/under shoot.

The `BKE_nlastrip_recalculate_blend()`  encapsulates the existing logic for both the `rna_NlaStrip_blend_in_set()` and `rna_NlaStrip_blend_out_set()` methods into a single BKE method that we an execute as needed. The fact that blend-in is first decreased, is strictly on the order of calculation. My suspicion is that //if// the blend-in / blend-our values were working as intended, the RNA set methods would update in order, and we'd experience the same thing. In short, the choice here was t [...]

while talking things over with @sybren  and @RiggingDojo, they are fine with how this currently works, but there a desire to update how the two values interact with each (ratio scale, etc) in the future.

New:
{F14045024}

{F14045025}

Reviewed By: sybren

Maniphest Tasks: T101369

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

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

M	source/blender/blenkernel/BKE_nla.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/nla.c
A	source/blender/blenkernel/intern/nla_test.cc
M	source/blender/makesrna/intern/rna_nla.c

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

diff --git a/source/blender/blenkernel/BKE_nla.h b/source/blender/blenkernel/BKE_nla.h
index 41980999a18..3d304859e1b 100644
--- a/source/blender/blenkernel/BKE_nla.h
+++ b/source/blender/blenkernel/BKE_nla.h
@@ -10,6 +10,8 @@
 /** Temp constant defined for these functions only. */
 #define NLASTRIP_MIN_LEN_THRESH 0.1f
 
+#include "DNA_listBase.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -295,6 +297,11 @@ void BKE_nlastrip_recalculate_bounds(struct NlaStrip *strip);
  */
 void BKE_nlastrip_recalculate_bounds_sync_action(struct NlaStrip *strip);
 
+/**
+ * Recalculate the Blendin and Blendout values after a strip transform update.
+ */
+void BKE_nlastrip_recalculate_blend(struct NlaStrip *strip);
+
 /**
  * Find (and set) a unique name for a strip from the whole AnimData block
  * Uses a similar method to the BLI method, but is implemented differently
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 8a3c6877787..70da6b22672 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -837,6 +837,7 @@ if(WITH_GTESTS)
     intern/lib_id_remapper_test.cc
     intern/lib_id_test.cc
     intern/lib_remap_test.cc
+    intern/nla_test.cc
     intern/tracking_test.cc
   )
   set(TEST_INC
@@ -847,4 +848,4 @@ if(WITH_GTESTS)
 
   # RNA_prototypes.h
   add_dependencies(bf_blenkernel_tests bf_rna)
-endif()
+endif()
\ No newline at end of file
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index 5cdfe98f2e0..1ff7fc21b01 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -1521,6 +1521,30 @@ void BKE_nlastrip_recalculate_bounds(NlaStrip *strip)
   nlastrip_fix_resize_overlaps(strip);
 }
 
+void BKE_nlastrip_recalculate_blend(NlaStrip *strip)
+{
+
+  /* check if values need to be re-calculated. */
+  if (strip->blendin == 0 && strip->blendout == 0) {
+    return;
+  }
+
+  const double strip_len = strip->end - strip->start;
+  double blend_in = strip->blendin;
+  double blend_out = strip->blendout;
+
+  double blend_in_max = strip_len - blend_out;
+
+  CLAMP_MIN(blend_in_max, 0);
+
+  /* blend-out is limited to the length of the strip. */
+  CLAMP(blend_in, 0, blend_in_max);
+  CLAMP(blend_out, 0, strip_len - blend_in);
+
+  strip->blendin = blend_in;
+  strip->blendout = blend_out;
+}
+
 /* Animated Strips ------------------------------------------- */
 
 bool BKE_nlatrack_has_animated_strips(NlaTrack *nlt)
@@ -1854,6 +1878,7 @@ void BKE_nla_validate_state(AnimData *adt)
     for (strip = nlt->strips.first; strip; strip = strip->next) {
       /* auto-blending first */
       BKE_nlastrip_validate_autoblends(nlt, strip);
+      BKE_nlastrip_recalculate_blend(strip);
     }
   }
 }
diff --git a/source/blender/blenkernel/intern/nla_test.cc b/source/blender/blenkernel/intern/nla_test.cc
new file mode 100644
index 00000000000..e6875fff1ce
--- /dev/null
+++ b/source/blender/blenkernel/intern/nla_test.cc
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2023 Blender Foundation. All rights reserved. */
+
+#include "BKE_nla.h"
+
+#include "DNA_nla_types.h"
+#include "DNA_anim_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "testing/testing.h"
+
+
+namespace blender::bke::tests {
+
+TEST(nla_strip, BKE_nlastrip_recalculate_blend)
+{
+
+  NlaStrip strip = {
+    .blendin = 4.0,
+    .blendout = 5.0,
+    .start = 1,
+    .end = 10
+  };
+
+  /* Scaling a strip up doesn't affect the blend in/out value */
+    strip.end = 20;
+    BKE_nlastrip_recalculate_blend(&strip);
+    EXPECT_FLOAT_EQ(strip.blendin, 4.0);
+    EXPECT_FLOAT_EQ(strip.blendout, 5.0);
+
+  /* Scaling a strip down affects the blend-in value before the blend-out value  */
+    strip.end = 7;
+    BKE_nlastrip_recalculate_blend(&strip);
+    EXPECT_FLOAT_EQ(strip.blendin, 1.0);
+    EXPECT_FLOAT_EQ(strip.blendout, 5.0);
+
+    /* Scaling a strip down to nothing updates the blend in/out values accordingly  */
+    strip.end = 1.1;
+    BKE_nlastrip_recalculate_blend(&strip);
+    EXPECT_FLOAT_EQ(strip.blendin, 0.0);
+    EXPECT_FLOAT_EQ(strip.blendout, 0.1);
+}
+
+}  // namespace blender::bke::tests
diff --git a/source/blender/makesrna/intern/rna_nla.c b/source/blender/makesrna/intern/rna_nla.c
index a61f6fb8c2e..3d8b5159323 100644
--- a/source/blender/makesrna/intern/rna_nla.c
+++ b/source/blender/makesrna/intern/rna_nla.c
@@ -157,6 +157,8 @@ static void rna_NlaStrip_transform_update(Main *bmain, Scene *scene, PointerRNA
     }
   }
 
+  BKE_nlastrip_recalculate_blend(strip);
+
   rna_NlaStrip_update(bmain, scene, ptr);
 }



More information about the Bf-blender-cvs mailing list