[Bf-blender-cvs] [5bb9fce0cde] soc-2019-outliner: Collections: Update active collection after visibility restriction

Nathan Craddock noreply at git.blender.org
Mon Jul 15 21:34:54 CEST 2019


Commit: 5bb9fce0cdead9045506dc5dd87154a10f987a7d
Author: Nathan Craddock
Date:   Mon Jul 15 13:29:42 2019 -0600
Branches: soc-2019-outliner
https://developer.blender.org/rB5bb9fce0cdead9045506dc5dd87154a10f987a7d

Collections: Update active collection after visibility restriction

When changing viewport visiblity or restriction change the active
collection. This replicates the behavior of excluding the active
collection, which sets the first non-excluded parent as active.

This required a function to recursively check parents for the
visiblility restrictions.

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

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

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

diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index 2b064c6b2a7..0f1a02bc5ec 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -493,6 +493,38 @@ static LayerCollection *collection_from_index(ListBase *lb, const int number, in
   return NULL;
 }
 
+/**
+ * Return true if the elements in a collection are visible
+ * Used to set active collection after excluding or restricting
+ * collection visiblility
+ */
+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 layer_collection_hidden(view_layer, lc);
+    }
+    else {
+      return false;
+    }
+  }
+
+  return false;
+}
+
 /**
  * Get the collection for a given index
  */
@@ -537,7 +569,7 @@ LayerCollection *BKE_layer_collection_activate_parent(ViewLayer *view_layer, Lay
     lc = NULL;
   }
 
-  if (lc && (lc->flag & LAYER_COLLECTION_EXCLUDE)) {
+  if (lc && layer_collection_hidden(view_layer, lc)) {
     /* Don't activate excluded collections. */
     return BKE_layer_collection_activate_parent(view_layer, lc);
   }
@@ -816,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