Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Craddock <nzcraddock@gmail.com>2019-08-08 22:27:19 +0300
committerNathan Craddock <nzcraddock@gmail.com>2019-08-16 21:30:53 +0300
commit0a903e7ab101a27b4bba47dd12005311147e7b1a (patch)
treea5f0c867b2b5f9e6865e5c1aeacfdd51e1b19766 /source/blender/blenkernel/intern/layer.c
parent71eb65328078d3b3ca440a9a23a7aa08238a6710 (diff)
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.
Diffstat (limited to 'source/blender/blenkernel/intern/layer.c')
-rw-r--r--source/blender/blenkernel/intern/layer.c38
1 files changed, 34 insertions, 4 deletions
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
@@ -494,6 +494,36 @@ static LayerCollection *collection_from_index(ListBase *lb, const int number, in
}
/**
+ * 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
*/
LayerCollection *BKE_layer_collection_from_index(ViewLayer *view_layer, const int 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) {