[Bf-blender-cvs] [c0bd240ad0a] master: LibOverride: Add initial support for adding new NLA tracks.

Bastien Montagne noreply at git.blender.org
Tue Dec 8 10:56:02 CET 2020


Commit: c0bd240ad0a17402db9d2e4799a433b81b62fca8
Author: Bastien Montagne
Date:   Mon Dec 7 16:58:18 2020 +0100
Branches: master
https://developer.blender.org/rBc0bd240ad0a17402db9d2e4799a433b81b62fca8

LibOverride: Add initial support for adding new NLA tracks.

Also makes NLA tracks and strips overridable.

User can either edit existing strips in existing NLA tracks (but not add or remove them), and/or add new NLA tracks after those comming from the linked data.

Most of the work was as usual checking operators and adding protections against illegal operations in override context.

Note that since we can only rely on indices to deal with local added tracks, we forbid any local track being before any linked/original track.

Maniphest Tasks: T72629

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

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

M	source/blender/blenkernel/BKE_nla.h
M	source/blender/blenkernel/intern/ipo.c
M	source/blender/blenkernel/intern/nla.c
M	source/blender/editors/animation/anim_channels_edit.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/space_action/action_data.c
M	source/blender/editors/space_nla/nla_channels.c
M	source/blender/editors/space_nla/nla_edit.c
M	source/blender/editors/transform/transform_convert.c
M	source/blender/editors/transform/transform_convert_nla.c
M	source/blender/makesdna/DNA_anim_types.h
M	source/blender/makesrna/intern/rna_access_compare_override.c
M	source/blender/makesrna/intern/rna_animation.c
M	source/blender/makesrna/intern/rna_nla.c
M	source/blender/makesrna/intern/rna_rna.c
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/source/blender/blenkernel/BKE_nla.h b/source/blender/blenkernel/BKE_nla.h
index 8671324fab1..16d48024d07 100644
--- a/source/blender/blenkernel/BKE_nla.h
+++ b/source/blender/blenkernel/BKE_nla.h
@@ -60,9 +60,13 @@ struct NlaTrack *BKE_nlatrack_copy(struct Main *bmain,
                                    const int flag);
 void BKE_nla_tracks_copy(struct Main *bmain, ListBase *dst, ListBase *src, const int flag);
 
-struct NlaTrack *BKE_nlatrack_add(struct AnimData *adt, struct NlaTrack *prev);
+struct NlaTrack *BKE_nlatrack_add(struct AnimData *adt,
+                                  struct NlaTrack *prev,
+                                  bool is_liboverride);
 struct NlaStrip *BKE_nlastrip_new(struct bAction *act);
-struct NlaStrip *BKE_nlastack_add_strip(struct AnimData *adt, struct bAction *act);
+struct NlaStrip *BKE_nlastack_add_strip(struct AnimData *adt,
+                                        struct bAction *act,
+                                        const bool is_liboverride);
 struct NlaStrip *BKE_nla_add_soundstrip(struct Main *bmain,
                                         struct Scene *scene,
                                         struct Speaker *speaker);
@@ -95,10 +99,14 @@ void BKE_nlatrack_solo_toggle(struct AnimData *adt, struct NlaTrack *nlt);
 bool BKE_nlatrack_has_space(struct NlaTrack *nlt, float start, float end);
 void BKE_nlatrack_sort_strips(struct NlaTrack *nlt);
 
-bool BKE_nlatrack_add_strip(struct NlaTrack *nlt, struct NlaStrip *strip);
+bool BKE_nlatrack_add_strip(struct NlaTrack *nlt,
+                            struct NlaStrip *strip,
+                            const bool is_liboverride);
 
 bool BKE_nlatrack_get_bounds(struct NlaTrack *nlt, float bounds[2]);
 
+bool BKE_nlatrack_is_nonlocal_in_liboverride(const struct ID *id, const struct NlaTrack *nlt);
+
 /* ............ */
 
 struct NlaStrip *BKE_nlastrip_find_active(struct NlaTrack *nlt);
@@ -124,11 +132,11 @@ void BKE_nla_validate_state(struct AnimData *adt);
 /* ............ */
 
 bool BKE_nla_action_is_stashed(struct AnimData *adt, struct bAction *act);
-bool BKE_nla_action_stash(struct AnimData *adt);
+bool BKE_nla_action_stash(struct AnimData *adt, const bool is_liboverride);
 
 /* ............ */
 
-void BKE_nla_action_pushdown(struct AnimData *adt);
+void BKE_nla_action_pushdown(struct AnimData *adt, const bool is_liboverride);
 
 bool BKE_nla_tweakmode_enter(struct AnimData *adt);
 void BKE_nla_tweakmode_exit(struct AnimData *adt);
diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c
index 9696d920640..6a852df95c6 100644
--- a/source/blender/blenkernel/intern/ipo.c
+++ b/source/blender/blenkernel/intern/ipo.c
@@ -1999,12 +1999,12 @@ static void nlastrips_to_animdata(ID *id, ListBase *strips)
       }
 
       /* try to add this strip to the current NLA-Track (i.e. the 'last' one on the stack atm) */
-      if (BKE_nlatrack_add_strip(nlt, strip) == 0) {
+      if (BKE_nlatrack_add_strip(nlt, strip, false) == 0) {
         /* trying to add to the current failed (no space),
          * so add a new track to the stack, and add to that...
          */
-        nlt = BKE_nlatrack_add(adt, NULL);
-        BKE_nlatrack_add_strip(nlt, strip);
+        nlt = BKE_nlatrack_add(adt, NULL, false);
+        BKE_nlatrack_add_strip(nlt, strip, false);
       }
 
       /* ensure that strip has a name */
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index 56bd83140bf..ebd9317fcf1 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -280,7 +280,7 @@ void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, ListBase *src, const int fl
 /* Add a NLA Track to the given AnimData
  * - prev: NLA-Track to add the new one after
  */
-NlaTrack *BKE_nlatrack_add(AnimData *adt, NlaTrack *prev)
+NlaTrack *BKE_nlatrack_add(AnimData *adt, NlaTrack *prev, const bool is_liboverride)
 {
   NlaTrack *nlt;
 
@@ -293,11 +293,15 @@ NlaTrack *BKE_nlatrack_add(AnimData *adt, NlaTrack *prev)
   nlt = MEM_callocN(sizeof(NlaTrack), "NlaTrack");
 
   /* set settings requiring the track to not be part of the stack yet */
-  nlt->flag = NLATRACK_SELECTED;
+  nlt->flag = NLATRACK_SELECTED | NLATRACK_OVERRIDELIBRARY_LOCAL;
   nlt->index = BLI_listbase_count(&adt->nla_tracks);
 
   /* add track to stack, and make it the active one */
-  if (prev) {
+  if (is_liboverride) {
+    for (; prev != NULL && (prev->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0; prev = prev->next) {
+    }
+  }
+  if (prev != NULL) {
     BLI_insertlinkafter(&adt->nla_tracks, prev, nlt);
   }
   else {
@@ -359,7 +363,7 @@ NlaStrip *BKE_nlastrip_new(bAction *act)
 
 /* Add new NLA-strip to the top of the NLA stack - i.e.
  * into the last track if space, or a new one otherwise. */
-NlaStrip *BKE_nlastack_add_strip(AnimData *adt, bAction *act)
+NlaStrip *BKE_nlastack_add_strip(AnimData *adt, bAction *act, const bool is_liboverride)
 {
   NlaStrip *strip;
   NlaTrack *nlt;
@@ -376,12 +380,12 @@ NlaStrip *BKE_nlastack_add_strip(AnimData *adt, bAction *act)
   }
 
   /* firstly try adding strip to last track, but if that fails, add to a new track */
-  if (BKE_nlatrack_add_strip(adt->nla_tracks.last, strip) == 0) {
+  if (BKE_nlatrack_add_strip(adt->nla_tracks.last, strip, is_liboverride) == 0) {
     /* trying to add to the last track failed (no track or no space),
      * so add a new track to the stack, and add to that...
      */
-    nlt = BKE_nlatrack_add(adt, NULL);
-    BKE_nlatrack_add_strip(nlt, strip);
+    nlt = BKE_nlatrack_add(adt, NULL, is_liboverride);
+    BKE_nlatrack_add_strip(nlt, strip, is_liboverride);
   }
 
   /* automatically name it too */
@@ -1138,15 +1142,16 @@ void BKE_nlatrack_sort_strips(NlaTrack *nlt)
 /* Add the given NLA-Strip to the given NLA-Track, assuming that it
  * isn't currently attached to another one
  */
-bool BKE_nlatrack_add_strip(NlaTrack *nlt, NlaStrip *strip)
+bool BKE_nlatrack_add_strip(NlaTrack *nlt, NlaStrip *strip, const bool is_liboverride)
 {
   /* sanity checks */
   if (ELEM(NULL, nlt, strip)) {
     return false;
   }
 
-  /* do not allow adding strips if this track is locked */
-  if (nlt->flag & NLATRACK_PROTECTED) {
+  /* Do not allow adding strips if this track is locked, or not a local one in liboverride case. */
+  if (nlt->flag & NLATRACK_PROTECTED ||
+      (is_liboverride && (nlt->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0)) {
     return false;
   }
 
@@ -1186,6 +1191,18 @@ bool BKE_nlatrack_get_bounds(NlaTrack *nlt, float bounds[2])
   return true;
 }
 
+/**
+ * Check whether given NLA track is not local (i.e. from linked data) when the object is a library
+ * override.
+ *
+ * \param nlt May be NULL, in which case we consider it as a non-local track case.
+ */
+bool BKE_nlatrack_is_nonlocal_in_liboverride(const ID *id, const NlaTrack *nlt)
+{
+  return (ID_IS_OVERRIDE_LIBRARY(id) &&
+          (nlt == NULL || (nlt->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0));
+}
+
 /* NLA Strips -------------------------------------- */
 
 /* Find the active NLA-strip within the given track */
@@ -1857,7 +1874,7 @@ bool BKE_nla_action_is_stashed(AnimData *adt, bAction *act)
 /* "Stash" an action (i.e. store it as a track/layer in the NLA, but non-contributing)
  * to retain it in the file for future uses
  */
-bool BKE_nla_action_stash(AnimData *adt)
+bool BKE_nla_action_stash(AnimData *adt, const bool is_liboverride)
 {
   NlaTrack *prev_track = NULL;
   NlaTrack *nlt;
@@ -1881,7 +1898,7 @@ bool BKE_nla_action_stash(AnimData *adt)
     }
   }
 
-  nlt = BKE_nlatrack_add(adt, prev_track);
+  nlt = BKE_nlatrack_add(adt, prev_track, is_liboverride);
   BLI_assert(nlt != NULL);
 
   /* We need to ensure that if there wasn't any previous instance,
@@ -1901,7 +1918,7 @@ bool BKE_nla_action_stash(AnimData *adt)
   strip = BKE_nlastrip_new(adt->action);
   BLI_assert(strip != NULL);
 
-  BKE_nlatrack_add_strip(nlt, strip);
+  BKE_nlatrack_add_strip(nlt, strip, is_liboverride);
   BKE_nlastrip_validate_name(adt, strip);
 
   /* mark the stash track and strip so that they doesn't disturb the stack animation,
@@ -1931,7 +1948,7 @@ bool BKE_nla_action_stash(AnimData *adt)
  * so no checks for this are performed.
  */
 /* TODO: maybe we should have checks for this too... */
-void BKE_nla_action_pushdown(AnimData *adt)
+void BKE_nla_action_pushdown(AnimData *adt, const bool is_liboverride)
 {
   NlaStrip *strip;
   const bool is_first = (adt) && (adt->nla_tracks.first == NULL);
@@ -1952,7 +1969,7 @@ void BKE_nla_action_pushdown(AnimData *adt)
   }
 
   /* add a new NLA strip to the track, which references the active action */
-  strip = BKE_nlastack_add_strip(adt, adt->action);
+  strip = BKE_nlastack_add_strip(adt, adt->action, is_liboverride);
   if (strip == NULL) {
     return;
   }
@@ -2273,6 +2290,11 @@ void BKE_nla_blend_read_lib(BlendLibReader *reader, ID *id, ListBase *tracks)
 {
   /* we only care about the NLA strips inside the tracks */
   LISTBASE_FOREACH (NlaTrack *, nlt, tracks) {
+    /* If linking from a library, clear 'local' library override flag. */
+    if (id->lib != NULL) {
+      nlt->flag &= ~NLATRACK_OVERRIDELIBRARY_LOCAL;
+    }
+
     blend_lib_read_nla_strips(reader, id, &nlt->strips);
   }
 }
diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c
index ba3796ad245..124992bed71 100644
--- a/source/blender/editors/animation/anim_channels_edit.c
+++ b/source/blender/editors/animation/anim_channels_edit.c
@@ -49,6 +49,7 @@
 #include "BKE_gpencil.h"
 #include "BKE_lib_id.h"
 #include "BKE_mask.h"
+#include "BKE_nla.h"
 #include "BKE_scene.h"
 
 #include "DEG_depsgraph.h"
@@ -1063,18 +1064,27 @@ static void rearrange_animchannels_filter_visible(ListBase *anim_data_visible,
                                                   eAnim_ChannelType type)
 {
   ListBase anim_data = {NULL, NULL};
-  bAnimListElem *ale, *ale_next;
-  int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
+  eAnimFilter_Flags filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE |
+                              ANIMFILTER_LIST_CHAN

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list