diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2019-08-19 20:25:29 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2019-09-13 18:37:35 +0300 |
commit | 92736a7b75920ffe4b8016a2d097ff8e36687c70 (patch) | |
tree | 33594ff97ce96124481ce9d898ea31158f91236c /source/blender/blenkernel/intern/layer.c | |
parent | ce34a6b0d727bbde6ae373afa8ec6c42bc8980ce (diff) |
Per-Viewport Collection Visibility
Support per-viewport collection visibility options.
Note 1: There is no way to show a collection that was not visible before
due to depsgraph. Otherwise we would risk having all the collections in
the depsgraph and I believe this is not the idea.
An alternative would be to have a new depsgraph for viewports that are
not local. Something to keep in mind if we do per-viewport current frame
in the future.
So for now what we do is to only allow collections visibility to be
disabled/hidden in this mode.
Note 2: hide_viewport (the eye icon) doesn't really matter for
depsgraph. So after the merge we can still ignore it to show the
collections locally in a viewport with no problems for the depsgraph.
Reviewers: brecht, sergey
Subscribers: billreynish
Related task: T61327
Differential Revision: https://developer.blender.org/D5611
Diffstat (limited to 'source/blender/blenkernel/intern/layer.c')
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index de105b9b62a..f3c0d5da6ee 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -68,6 +68,7 @@ static LayerCollection *layer_collection_add(ListBase *lb_parent, Collection *co { LayerCollection *lc = MEM_callocN(sizeof(LayerCollection), "Collection Base"); lc->collection = collection; + lc->local_collections_bits = ~(0); BLI_addtail(lb_parent, lc); return lc; @@ -1083,6 +1084,117 @@ void BKE_layer_collection_isolate(Scene *scene, BKE_layer_collection_sync(scene, view_layer); } +static void layer_collection_local_visibility_set_recursive(LayerCollection *layer_collection, + const int local_collections_uuid) +{ + layer_collection->local_collections_bits |= local_collections_uuid; + for (LayerCollection *child = layer_collection->layer_collections.first; child; + child = child->next) { + layer_collection_local_visibility_set_recursive(child, local_collections_uuid); + } +} + +static void layer_collection_local_visibility_unset_recursive(LayerCollection *layer_collection, + const int local_collections_uuid) +{ + layer_collection->local_collections_bits &= ~local_collections_uuid; + for (LayerCollection *child = layer_collection->layer_collections.first; child; + child = child->next) { + layer_collection_local_visibility_unset_recursive(child, local_collections_uuid); + } +} + +static void layer_collection_local_sync(ViewLayer *view_layer, + LayerCollection *layer_collection, + const unsigned short local_collections_uuid, + bool visible) +{ + if ((layer_collection->local_collections_bits & local_collections_uuid) == 0) { + visible = false; + } + + if (visible) { + for (CollectionObject *cob = layer_collection->collection->gobject.first; cob; + cob = cob->next) { + BLI_assert(cob->ob); + Base *base = BKE_view_layer_base_find(view_layer, cob->ob); + base->local_collections_bits |= local_collections_uuid; + } + } + + LISTBASE_FOREACH (LayerCollection *, child, &layer_collection->layer_collections) { + layer_collection_local_sync(view_layer, child, local_collections_uuid, visible); + } +} + +void BKE_layer_collection_local_sync(ViewLayer *view_layer, View3D *v3d) +{ + const unsigned short local_collections_uuid = v3d->local_collections_uuid; + + /* Reset flags and set the bases visible by default. */ + for (Base *base = view_layer->object_bases.first; base; base = base->next) { + base->local_collections_bits &= ~local_collections_uuid; + } + + LISTBASE_FOREACH (LayerCollection *, layer_collection, &view_layer->layer_collections) { + layer_collection_local_sync(view_layer, layer_collection, local_collections_uuid, true); + } +} + +/** + * Isolate the collection locally + * + * Same as BKE_layer_collection_local_isolate but for a viewport + */ +void BKE_layer_collection_local_isolate(ViewLayer *view_layer, + View3D *v3d, + LayerCollection *lc, + bool extend) +{ + LayerCollection *lc_master = view_layer->layer_collections.first; + bool hide_it = extend && ((v3d->local_collections_uuid & lc->local_collections_bits) != 0); + + if (!extend) { + /* Hide all collections. */ + for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; + lc_iter = lc_iter->next) { + layer_collection_local_visibility_unset_recursive(lc_iter, v3d->local_collections_uuid); + } + } + + /* Make all the direct parents visible. */ + if (hide_it) { + lc->local_collections_bits &= ~(v3d->local_collections_uuid); + } + else { + LayerCollection *lc_parent = lc; + for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; + lc_iter = lc_iter->next) { + if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) { + lc_parent = lc_iter; + break; + } + } + + while (lc_parent != lc) { + lc_parent->local_collections_bits |= v3d->local_collections_uuid; + + for (LayerCollection *lc_iter = lc_parent->layer_collections.first; lc_iter; + lc_iter = lc_iter->next) { + if (BKE_layer_collection_has_layer_collection(lc_iter, lc)) { + lc_parent = lc_iter; + break; + } + } + } + + /* Make all the children visible. */ + layer_collection_local_visibility_set_recursive(lc, v3d->local_collections_uuid); + } + + BKE_layer_collection_local_sync(view_layer, v3d); +} + static void layer_collection_bases_show_recursive(ViewLayer *view_layer, LayerCollection *lc) { if ((lc->flag & LAYER_COLLECTION_EXCLUDE) == 0) { |