[Bf-blender-cvs] [92736a7b759] master: Per-Viewport Collection Visibility
Dalai Felinto
noreply at git.blender.org
Fri Sep 13 17:48:49 CEST 2019
Commit: 92736a7b75920ffe4b8016a2d097ff8e36687c70
Author: Dalai Felinto
Date: Mon Aug 19 14:25:29 2019 -0300
Branches: master
https://developer.blender.org/rB92736a7b75920ffe4b8016a2d097ff8e36687c70
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
===================================================================
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/blenkernel/BKE_layer.h
M source/blender/blenkernel/intern/layer.c
M source/blender/blenkernel/intern/object_update.c
M source/blender/blenloader/intern/versioning_280.c
M source/blender/draw/intern/draw_manager.c
M source/blender/editors/include/ED_view3d.h
M source/blender/editors/object/object_edit.c
M source/blender/editors/space_view3d/view3d_view.c
M source/blender/makesdna/DNA_layer_types.h
M source/blender/makesdna/DNA_object_types.h
M source/blender/makesdna/DNA_scene_types.h
M source/blender/makesdna/DNA_view3d_types.h
M source/blender/makesrna/intern/rna_layer.c
M source/blender/makesrna/intern/rna_space.c
M source/blender/windowmanager/intern/wm_files.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index e98a3684ddc..acb42e0545b 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4997,7 +4997,7 @@ class VIEW3D_PT_collections(Panel):
bl_label = "Collections"
bl_options = {'DEFAULT_CLOSED'}
- def _draw_collection(self, layout, view_layer, collection, index):
+ def _draw_collection(self, layout, view_layer, use_local_collections, collection, index):
need_separator = index
for child in collection.children:
index += 1
@@ -5023,6 +5023,7 @@ class VIEW3D_PT_collections(Panel):
pass
row = layout.row()
+ row.use_property_decorate = False
sub = row.split(factor=0.98)
subrow = sub.row()
subrow.alignment = 'LEFT'
@@ -5033,11 +5034,21 @@ class VIEW3D_PT_collections(Panel):
sub = row.split()
subrow = sub.row(align=True)
subrow.alignment = 'RIGHT'
- subrow.active = collection.is_visible # Parent collection runtime visibility
- subrow.prop(child, "hide_viewport", text="", emboss=False)
+ if not use_local_collections:
+ subrow.active = collection.is_visible # Parent collection runtime visibility
+ subrow.prop(child, "hide_viewport", text="", emboss=False)
+ elif not child.is_visible:
+ subrow.active = False
+ subrow.label(text="", icon='REMOVE')
+ else:
+ subrow.active = collection.visible_get() # Parent collection runtime visibility
+ icon = 'HIDE_OFF' if child.visible_get() else 'HIDE_ON'
+ props = subrow.operator("object.hide_collection", text="", icon=icon, emboss=False)
+ props.collection_index = index
+ props.toggle = True
for child in collection.children:
- index = self._draw_collection(layout, view_layer, child, index)
+ index = self._draw_collection(layout, view_layer, use_local_collections, child, index)
return index
@@ -5045,11 +5056,17 @@ class VIEW3D_PT_collections(Panel):
layout = self.layout
layout.use_property_split = False
+ view = context.space_data
view_layer = context.view_layer
+
+ layout.use_property_split = True
+ layout.prop(view, "use_local_collections")
+ layout.separator()
+
# We pass index 0 here because the index is increased
# so the first real index is 1
# And we start with index as 1 because we skip the master collection
- self._draw_collection(layout, view_layer, view_layer.layer_collection, 0)
+ self._draw_collection(layout, view_layer, view.use_local_collections, view_layer.layer_collection, 0)
class VIEW3D_PT_object_type_visibility(Panel):
diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
index eb65b7641e1..535980840c1 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -90,6 +90,7 @@ int BKE_layer_collection_findindex(struct ViewLayer *view_layer, const struct La
void BKE_main_collection_sync(const struct Main *bmain);
void BKE_scene_collection_sync(const struct Scene *scene);
void BKE_layer_collection_sync(const struct Scene *scene, struct ViewLayer *view_layer);
+void BKE_layer_collection_local_sync(struct ViewLayer *view_layer, struct View3D *v3d);
void BKE_main_collection_sync_remap(const struct Main *bmain);
@@ -117,6 +118,10 @@ void BKE_layer_collection_isolate(struct Scene *scene,
struct ViewLayer *view_layer,
struct LayerCollection *lc,
bool extend);
+void BKE_layer_collection_local_isolate(struct ViewLayer *view_layer,
+ struct View3D *v3d,
+ struct LayerCollection *lc,
+ bool extend);
void BKE_layer_collection_set_visible(struct ViewLayer *view_layer,
struct LayerCollection *lc,
const bool visible,
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) {
diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index 3a330ea0d5a..01f3f2e309b 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -453,6 +453,7 @@ void BKE_object_eval_eval_base_flags(Depsgraph *depsgraph,
object->base_flag &= ~(BASE_SELECTED | BASE_SELECTABLE);
}
object->base_local_view_bits = base->local_view_bits;
+ object->runtime.local_collections_bits = base->local_collections_bits;
if (object->mode == OB_MODE_PARTICLE_EDIT) {
for (ParticleSystem *psys = object->particlesystem.first; psys != NULL; psys = psys->next) {
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index e9b4650d7d6..6d21d9c1490 100644
--- a/source/blend
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list