diff options
-rw-r--r-- | release/scripts/startup/bl_ui/space_view3d.py | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_layer.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 83 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object_update.c | 3 | ||||
-rw-r--r-- | source/blender/editors/object/object_edit.c | 6 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_layer_types.h | 22 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_layer.c | 32 |
7 files changed, 58 insertions, 93 deletions
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index 3a8419ffe3e..cacf946b3b5 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -4370,13 +4370,10 @@ class VIEW3D_PT_collections(Panel): else: has_objects = False - has_visible_objects = has_objects and child.has_visible_objects(view_layer) - row = layout.row() sub = row.split(factor=0.98) subrow = sub.row() subrow.alignment = 'LEFT' - subrow.active = has_visible_objects subrow.operator( "object.hide_collection", text=child.name, icon=icon, emboss=False, ).collection_index = index diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h index e3a182f9ec1..f10f2f44706 100644 --- a/source/blender/blenkernel/BKE_layer.h +++ b/source/blender/blenkernel/BKE_layer.h @@ -114,6 +114,8 @@ bool BKE_layer_collection_set_visible(struct ViewLayer *view_layer, struct Layer /* evaluation */ +void BKE_base_eval_flags(struct Base *base); + void BKE_layer_eval_view_layer_indexed( struct Depsgraph *depsgraph, struct Scene *scene, diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index cf8f94abdae..2bbccec2cfe 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -54,6 +54,13 @@ #include "MEM_guardedalloc.h" +/* Set of flags which are dependent on a collection settings. */ +static short g_base_collection_flags = (BASE_VISIBLE | + BASE_SELECTABLE | + BASE_ENABLED_VIEWPORT | + BASE_ENABLED_RENDER | + BASE_HOLDOUT | + BASE_INDIRECT_ONLY); /* prototype */ static void object_bases_iterator_next(BLI_Iterator *iter, const int flag); @@ -700,53 +707,32 @@ static short layer_collection_sync( BLI_addtail(new_object_bases, base); } - int object_restrict = base->object->restrictflag; - - if (((child_restrict & COLLECTION_RESTRICT_VIEW) == 0) && - ((object_restrict & OB_RESTRICT_VIEW) == 0)) - { - base->flag |= BASE_ENABLED_VIEWPORT; - + if ((child_restrict & COLLECTION_RESTRICT_VIEW) == 0) { + base->flag_from_collection |= BASE_ENABLED_VIEWPORT; if ((child_layer_restrict & LAYER_COLLECTION_RESTRICT_VIEW) == 0) { - base->flag |= BASE_VISIBLE; - - if (((child_restrict & COLLECTION_RESTRICT_SELECT) == 0) && - ((object_restrict & OB_RESTRICT_SELECT) == 0)) - { - base->flag |= BASE_SELECTABLE; + base->flag_from_collection |= BASE_VISIBLE; + if (((child_restrict & COLLECTION_RESTRICT_SELECT) == 0)) { + base->flag_from_collection |= BASE_SELECTABLE; } } } - if (((child_restrict & COLLECTION_RESTRICT_RENDER) == 0) && - ((object_restrict & OB_RESTRICT_RENDER) == 0)) - { - base->flag |= BASE_ENABLED_RENDER; - } - - /* Update runtime flags used for display and tools. */ - if (base->flag & BASE_ENABLED_VIEWPORT) { - lc->runtime_flag |= LAYER_COLLECTION_HAS_ENABLED_OBJECTS; - } - - if (base->flag & BASE_HIDDEN) { - base->flag &= ~BASE_VISIBLE; - view_layer->runtime_flag |= VIEW_LAYER_HAS_HIDE; - lc->runtime_flag |= LAYER_COLLECTION_HAS_HIDDEN_OBJECTS; - } - else if (base->flag & BASE_VISIBLE) { - lc->runtime_flag |= LAYER_COLLECTION_HAS_VISIBLE_OBJECTS; + if ((child_restrict & COLLECTION_RESTRICT_RENDER) == 0) { + base->flag_from_collection |= BASE_ENABLED_RENDER; } /* Holdout and indirect only */ if (lc->flag & LAYER_COLLECTION_HOLDOUT) { - base->flag |= BASE_HOLDOUT; + base->flag_from_collection |= BASE_HOLDOUT; } if (lc->flag & LAYER_COLLECTION_INDIRECT_ONLY) { - base->flag |= BASE_INDIRECT_ONLY; + base->flag_from_collection |= BASE_INDIRECT_ONLY; } lc->runtime_flag |= LAYER_COLLECTION_HAS_OBJECTS; + + /* Make sure flags on base are usable right away. */ + BKE_base_eval_flags(base); } runtime_flag |= lc->runtime_flag; @@ -781,16 +767,10 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer) /* Clear visible and selectable flags to be reset. */ for (Base *base = view_layer->object_bases.first; base; base = base->next) { - base->flag &= ~(BASE_VISIBLE | - BASE_SELECTABLE | - BASE_ENABLED_VIEWPORT | - BASE_ENABLED_RENDER | - BASE_HOLDOUT | - BASE_INDIRECT_ONLY); + base->flag &= ~g_base_collection_flags; + base->flag_from_collection &= ~g_base_collection_flags; } - view_layer->runtime_flag = 0; - /* Generate new layer connections and object bases when collections changed. */ CollectionChild child = {NULL, NULL, scene->master_collection}; const ListBase collections = {&child, &child}; @@ -1461,6 +1441,27 @@ void BKE_view_layer_bases_in_mode_iterator_end(BLI_Iterator *UNUSED(iter)) /* Evaluation */ +/* Applies object's restrict flags on top of flags coming from the collection + * and stores those in base->flag. */ +void BKE_base_eval_flags(Base *base) +{ + const int object_restrict = base->object->restrictflag; + base->flag &= ~g_base_collection_flags; + base->flag |= (base->flag_from_collection & g_base_collection_flags); + if (object_restrict & OB_RESTRICT_VIEW) { + base->flag &= ~(BASE_ENABLED_VIEWPORT | BASE_SELECTABLE); + } + if (object_restrict & OB_RESTRICT_SELECT) { + base->flag &= ~BASE_SELECTABLE; + } + if (object_restrict & OB_RESTRICT_RENDER) { + base->flag &= ~BASE_ENABLED_RENDER; + } + if (base->flag & BASE_HIDDEN) { + base->flag &= ~BASE_VISIBLE; + } +} + static void layer_eval_view_layer( struct Depsgraph *depsgraph, struct Scene *UNUSED(scene), diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c index 7f66cfd5dc3..60cf4d1b1d4 100644 --- a/source/blender/blenkernel/intern/object_update.c +++ b/source/blender/blenkernel/intern/object_update.c @@ -44,6 +44,7 @@ #include "BKE_effect.h" #include "BKE_image.h" #include "BKE_key.h" +#include "BKE_layer.h" #include "BKE_light.h" #include "BKE_lattice.h" #include "BKE_material.h" @@ -428,6 +429,8 @@ void BKE_object_eval_eval_base_flags(Depsgraph *depsgraph, ? BASE_ENABLED_VIEWPORT : BASE_ENABLED_RENDER; + BKE_base_eval_flags(base); + /* Compute visibility for depsgraph evaluation mode. */ if (base->flag & base_enabled_flag) { /* When rendering, visibility is controlled by the enable/disable option. */ diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 4ade69f7c26..cd8eeba73d4 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -306,12 +306,6 @@ void ED_collection_hide_menu_draw(const bContext *C, uiLayout *layout) continue; } - if ((view_layer->runtime_flag & VIEW_LAYER_HAS_HIDE) && - !(lc->runtime_flag & LAYER_COLLECTION_HAS_VISIBLE_OBJECTS)) - { - uiLayoutSetActive(row, false); - } - int icon = ICON_NONE; if (BKE_layer_collection_has_selected_objects(view_layer, lc)) { icon = ICON_LAYER_ACTIVE; diff --git a/source/blender/makesdna/DNA_layer_types.h b/source/blender/makesdna/DNA_layer_types.h index ce51be0d620..aa7ca2ca987 100644 --- a/source/blender/makesdna/DNA_layer_types.h +++ b/source/blender/makesdna/DNA_layer_types.h @@ -30,9 +30,18 @@ extern "C" { typedef struct Base { struct Base *next, *prev; + + /* Flags which are based on the collections flags evaluation, does not + * include flags from object's restrictions. */ + short flag_from_collection; + + /* Final flags, including both accumulated collection flags and object's + * restriction flags. */ short flag; + unsigned short local_view_bits; short sx, sy; + char _pad1[6]; struct Object *object; unsigned int lay DNA_DEPRECATED; int flag_legacy; @@ -66,8 +75,7 @@ typedef struct ViewLayer { /** MAX_NAME. */ char name[64]; short flag; - short runtime_flag; - char _pad[4]; + char _pad[6]; /** ObjectBase. */ ListBase object_bases; /** Default allocated now. */ @@ -131,10 +139,7 @@ enum { /* Layer Collection->runtime_flag */ enum { LAYER_COLLECTION_HAS_OBJECTS = (1 << 0), - LAYER_COLLECTION_HAS_VISIBLE_OBJECTS = (1 << 1), - LAYER_COLLECTION_HAS_HIDDEN_OBJECTS = (1 << 2), - LAYER_COLLECTION_HAS_ENABLED_OBJECTS = (1 << 3), - LAYER_COLLECTION_VISIBLE = (1 << 4), + LAYER_COLLECTION_VISIBLE = (1 << 1), }; /* ViewLayer->flag */ @@ -144,11 +149,6 @@ enum { VIEW_LAYER_FREESTYLE = (1 << 2), }; -/* ViewLayer->runtime_flag */ -enum { - VIEW_LAYER_HAS_HIDE = (1 << 0), -}; - /****************************** Deprecated ******************************/ /* Compatibility with collections saved in early 2.8 versions, diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c index 808eb21b3fa..edd9054a6b6 100644 --- a/source/blender/makesrna/intern/rna_layer.c +++ b/source/blender/makesrna/intern/rna_layer.c @@ -227,26 +227,6 @@ static bool rna_LayerCollection_has_objects(LayerCollection *lc) return (lc->runtime_flag & LAYER_COLLECTION_HAS_OBJECTS) != 0; } -static bool rna_LayerCollection_has_visible_objects(LayerCollection *lc, ViewLayer *view_layer) -{ - if ((view_layer->runtime_flag & VIEW_LAYER_HAS_HIDE) && - !(lc->runtime_flag & LAYER_COLLECTION_HAS_VISIBLE_OBJECTS)) - { - return false; - } - return true; -} - -static bool rna_LayerCollection_has_hidden_objects(LayerCollection *lc, ViewLayer *view_layer) -{ - if ((view_layer->runtime_flag & VIEW_LAYER_HAS_HIDE) && - (lc->runtime_flag & LAYER_COLLECTION_HAS_HIDDEN_OBJECTS)) - { - return true; - } - return false; -} - static bool rna_LayerCollection_has_selected_objects(LayerCollection *lc, ViewLayer *view_layer) { return BKE_layer_collection_has_selected_objects(view_layer, lc); @@ -319,18 +299,6 @@ static void rna_def_layer_collection(BlenderRNA *brna) RNA_def_function_ui_description(func, ""); RNA_def_function_return(func, RNA_def_boolean(func, "result", 0, "", "")); - func = RNA_def_function(srna, "has_visible_objects", "rna_LayerCollection_has_visible_objects"); - RNA_def_function_ui_description(func, ""); - prop = RNA_def_pointer(func, "view_layer", "ViewLayer", "", "ViewLayer the layer collection belongs to"); - RNA_def_parameter_flags(prop, 0, PARM_REQUIRED); - RNA_def_function_return(func, RNA_def_boolean(func, "result", 0, "", "")); - - func = RNA_def_function(srna, "has_hidden_objects", "rna_LayerCollection_has_hidden_objects"); - RNA_def_function_ui_description(func, ""); - prop = RNA_def_pointer(func, "view_layer", "ViewLayer", "", "ViewLayer the layer collection belongs to"); - RNA_def_parameter_flags(prop, 0, PARM_REQUIRED); - RNA_def_function_return(func, RNA_def_boolean(func, "result", 0, "", "")); - func = RNA_def_function(srna, "has_selected_objects", "rna_LayerCollection_has_selected_objects"); RNA_def_function_ui_description(func, ""); prop = RNA_def_pointer(func, "view_layer", "ViewLayer", "", "ViewLayer the layer collection belongs to"); |