From f2db6cefa0869fe474b4fbbb467d63bff8c0935b Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Wed, 20 Sep 2017 14:15:35 +0200 Subject: Layer collection enable flag Right now this is exposed in the outliner, though all this (visible/selectable/enable) should be moved to a new panel soon. This removes objects from the depsgraph when the collection is disabled. It allows you to "hide" lamps but still having them lighting the scene. Same for light probes and other support objects. Pending tasks: * Have depsgraph to include invisible objects in the DEG_OBJECTS_ITER, and then have Eevee and other engines to make a distinction between an invisible and a visible object. (for example, we probably want invisible objects to not show in the viewport, but cast shadows and show up in light probes). * Change how we evaluate collection settings so that an invisible collection can force an object to be invisible. Reviewers: campbellbarton Subscribers: sergey Differential Revision: https://developer.blender.org/D2848 --- source/blender/makesrna/intern/rna_scene.c | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'source/blender/makesrna/intern/rna_scene.c') diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 119432f7ed3..9887da153e8 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -2899,6 +2899,39 @@ static void rna_LayerCollection_flag_update(bContext *C, PointerRNA *UNUSED(ptr) WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } +static void rna_LayerCollection_enable_set( + ID *id, LayerCollection *layer_collection, Main *bmain, bContext *C, ReportList *reports, int value) +{ + Scene *scene = (Scene *)id; + SceneLayer *scene_layer = BKE_scene_layer_find_from_collection(scene, layer_collection); + + if (layer_collection->flag & COLLECTION_DISABLED) { + if (value == 1) { + BKE_collection_enable(scene_layer, layer_collection); + } + else { + BKE_reportf(reports, RPT_ERROR, "Layer collection '%s' is already disabled", + layer_collection->scene_collection->name); + return; + } + } + else { + if (value == 0) { + BKE_collection_disable(scene_layer, layer_collection); + } + else { + BKE_reportf(reports, RPT_ERROR, "Layer collection '%s' is already enabled", + layer_collection->scene_collection->name); + } + } + + DEG_relations_tag_update(bmain); + /* TODO(sergey): Use proper flag for tagging here. */ + DEG_id_tag_update(&scene->id, 0); + WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); + WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene); +} + static int rna_LayerCollections_active_collection_index_get(PointerRNA *ptr) { SceneLayer *sl = (SceneLayer *)ptr->data; @@ -6991,7 +7024,17 @@ static void rna_def_layer_collection(BlenderRNA *brna) parm = RNA_def_boolean(func, "result", false, "Result", "Whether the operation succeded"); RNA_def_function_return(func, parm); + func = RNA_def_function(srna, "enable_set", "rna_LayerCollection_enable_set"); + RNA_def_function_ui_description(func, "Enable or disable a collection"); + parm = RNA_def_boolean(func, "value", 1, "Enable", ""); + RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_CONTEXT | FUNC_USE_REPORTS); + /* Flags */ + prop = RNA_def_property(srna, "is_enabled", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", COLLECTION_DISABLED); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Enabled", "Enable or disable collection from depsgraph"); + prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", COLLECTION_VISIBLE); RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE); -- cgit v1.2.3