[Bf-blender-cvs] [227d8299799] temp-soc-2019-outliner-sync: Collections: change active if hidden or excluded

Nathan Craddock noreply at git.blender.org
Fri Aug 9 06:01:49 CEST 2019


Commit: 227d82997994ffdc2540afe3703a27ac6cb49310
Author: Nathan Craddock
Date:   Thu Aug 8 13:27:19 2019 -0600
Branches: temp-soc-2019-outliner-sync
https://developer.blender.org/rB227d82997994ffdc2540afe3703a27ac6cb49310

Collections: change active if hidden or excluded

When the active collection is hidden or excluded, change the active
collection to the first visible parent collection. This behavior existed
previously for excluding collections, and is now expanded to also
switch the active collection when viewport hidden or restricted.

This does not prevent viewport hidden or restricted collections from
being reactivated later. This could be added as a separate commit.
Excluded collections cannot be activated, so it may make sense to
extend this behavior to hiding collections.

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

M	source/blender/blenkernel/intern/layer.c

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

diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index 40608285785..de105b9b62a 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -493,6 +493,36 @@ static LayerCollection *collection_from_index(ListBase *lb, const int number, in
   return NULL;
 }
 
+/**
+ * Determine if a collection is hidden, viewport visibility restricted, or excluded
+ */
+static bool layer_collection_hidden(ViewLayer *view_layer, LayerCollection *lc)
+{
+  if (lc->flag & LAYER_COLLECTION_EXCLUDE) {
+    return true;
+  }
+
+  /* Check visiblilty restriction flags */
+  if (lc->flag & LAYER_COLLECTION_HIDE || lc->collection->flag & COLLECTION_RESTRICT_VIEWPORT) {
+    return true;
+  }
+  else {
+    /* Restriction flags stay set, so we need to check parents */
+    CollectionParent *parent = lc->collection->parents.first;
+
+    if (parent) {
+      lc = BKE_layer_collection_first_from_scene_collection(view_layer, parent->collection);
+
+      return lc && layer_collection_hidden(view_layer, lc);
+    }
+    else {
+      return false;
+    }
+  }
+
+  return false;
+}
+
 /**
  * Get the collection for a given index
  */
@@ -537,8 +567,9 @@ LayerCollection *BKE_layer_collection_activate_parent(ViewLayer *view_layer, Lay
     lc = NULL;
   }
 
-  if (lc && (lc->flag & LAYER_COLLECTION_EXCLUDE)) {
-    /* Don't activate excluded collections. */
+  /* Don't activate excluded or hidden collections to prevent creating objects in a hidden
+   * collection from the UI */
+  if (lc && layer_collection_hidden(view_layer, lc)) {
     return BKE_layer_collection_activate_parent(view_layer, lc);
   }
 
@@ -817,8 +848,7 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer)
 
   /* Always set a valid active collection. */
   LayerCollection *active = view_layer->active_collection;
-
-  if (active && (active->flag & LAYER_COLLECTION_EXCLUDE)) {
+  if (active && layer_collection_hidden(view_layer, active)) {
     BKE_layer_collection_activate_parent(view_layer, active);
   }
   else if (active == NULL) {



More information about the Bf-blender-cvs mailing list