diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2017-12-01 16:24:21 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2017-12-01 19:15:54 +0300 |
commit | be9e469ead227aee8d4c29b98a125cf599c5c8bb (patch) | |
tree | 381ee3e58a94495a923c575bb8185899d84ab4bc /source/blender/makesrna | |
parent | e8c15e0ed15f8369d0d0f706b4953fb64e357902 (diff) |
Groups and collection: initial integration
Since we are ditching layers from Blender (2.8) we need a replacement to
control groups visibility. This commit introduces collections as the building
blocks for groups, allowing users to control visibility as well as overrides
for groups.
Features
========
* Groups now have collections
This way you can change the visibility of a collection inside a group, and add
overrides which are part of the group and are prioritized over other overrides.
* Outliner
Groups can inspect their collections, change visibility, and add/remove members.
To change an override of a group collection, you need to select an instance of
the group, and then you can choose "group" in the collection properties editor
to edit this group active collection instead of the view layer one.
* Dupli groups overrides
We can now have multiple instances of the same group with an original "override"
and different overrides depending on the collection the instanced object is part
of.
Technical
=========
* Layers
We use the same api for groups and scene as much as possible.
Reviewers: sergey (depsgraph), mont29 (read/write and user count)
Differential Revision: https://developer.blender.org/D2892
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/RNA_enum_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_group.c | 18 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_layer.c | 88 |
3 files changed, 65 insertions, 43 deletions
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index 155c82bbbc3..345c47ae1bf 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -61,6 +61,8 @@ extern const EnumPropertyItem rna_enum_object_modifier_type_items[]; extern const EnumPropertyItem rna_enum_constraint_type_items[]; extern const EnumPropertyItem rna_enum_boidrule_type_items[]; extern const EnumPropertyItem rna_enum_sequence_modifier_type_items[]; + +extern const EnumPropertyItem rna_enum_collection_type_items[]; extern const EnumPropertyItem rna_enum_layer_collection_mode_settings_type_items[]; extern const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[]; diff --git a/source/blender/makesrna/intern/rna_group.c b/source/blender/makesrna/intern/rna_group.c index 2a5a0011279..ec67370b14f 100644 --- a/source/blender/makesrna/intern/rna_group.c +++ b/source/blender/makesrna/intern/rna_group.c @@ -49,8 +49,9 @@ static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter) { ListBaseIterator *internal = &iter->internal.listbase; - /* we are actually iterating a GroupObject list, so override get */ - return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((GroupObject *)internal->link)->ob); + /* we are actually iterating a ObjectBase list, so override get */ + Base *base = (Base *)internal->link; + return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, base->object); } static void rna_Group_objects_link(Group *group, ReportList *reports, Object *object) @@ -124,20 +125,17 @@ void RNA_def_group(BlenderRNA *brna) RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, RNA_TRANSLATION_PREC_DEFAULT); RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL); - prop = RNA_def_property(srna, "layers", PROP_BOOLEAN, PROP_LAYER); - RNA_def_property_boolean_sdna(prop, NULL, "layer", 1); - RNA_def_property_array(prop, 20); - RNA_def_property_ui_text(prop, "Dupli Layers", "Layers visible when this group is instanced as a dupli"); - RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL); - prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "gobject", NULL); + RNA_def_property_collection_sdna(prop, NULL, "view_layer->object_bases", NULL); RNA_def_property_struct_type(prop, "Object"); RNA_def_property_ui_text(prop, "Objects", "A collection of this groups objects"); RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_Group_objects_get", NULL, NULL, NULL, NULL); - rna_def_group_objects(brna, prop); + prop = RNA_def_property(srna, "collections", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "view_layer->layer_collections", NULL); + RNA_def_property_struct_type(prop, "LayerCollection"); + RNA_def_property_ui_text(prop, "Layer Collections", ""); } #endif diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c index 2bdb3035073..df6c2188799 100644 --- a/source/blender/makesrna/intern/rna_layer.c +++ b/source/blender/makesrna/intern/rna_layer.c @@ -54,8 +54,15 @@ const EnumPropertyItem rna_enum_layer_collection_mode_settings_type_items[] = { {0, NULL, 0, NULL, NULL} }; +const EnumPropertyItem rna_enum_collection_type_items[] = { + {COLLECTION_TYPE_NONE, "NONE", 0, "Normal", ""}, + {COLLECTION_TYPE_GROUP_INTERNAL, "GROUP_INTERNAL", 0, "Group Internal", ""}, + {0, NULL, 0, NULL, NULL} +}; + #ifdef RNA_RUNTIME +#include "DNA_group_types.h" #include "DNA_object_types.h" #include "RNA_access.h" @@ -69,6 +76,20 @@ const EnumPropertyItem rna_enum_layer_collection_mode_settings_type_items[] = { #include "DEG_depsgraph_build.h" #include "DEG_depsgraph_query.h" +static StructRNA *rna_SceneCollection_refine(PointerRNA *ptr) +{ + SceneCollection *scene_collection = (SceneCollection *)ptr->data; + switch (scene_collection->type) { + case COLLECTION_TYPE_GROUP_INTERNAL: + case COLLECTION_TYPE_NONE: + return &RNA_SceneCollection; + default: + BLI_assert(!"Collection type not fully implemented"); + break; + } + return &RNA_SceneCollection; +} + static void rna_SceneCollection_name_set(PointerRNA *ptr, const char *value) { Scene *scene = (Scene *)ptr->id.data; @@ -96,9 +117,7 @@ static PointerRNA rna_SceneCollection_objects_get(CollectionPropertyIterator *it static int rna_SceneCollection_move_above(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst) { - Scene *scene = (Scene *)id; - - if (!BKE_collection_move_above(scene, sc_dst, sc_src)) { + if (!BKE_collection_move_above(id, sc_dst, sc_src)) { return 0; } @@ -110,9 +129,7 @@ static int rna_SceneCollection_move_above(ID *id, SceneCollection *sc_src, Main static int rna_SceneCollection_move_below(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst) { - Scene *scene = (Scene *)id; - - if (!BKE_collection_move_below(scene, sc_dst, sc_src)) { + if (!BKE_collection_move_below(id, sc_dst, sc_src)) { return 0; } @@ -124,9 +141,7 @@ static int rna_SceneCollection_move_below(ID *id, SceneCollection *sc_src, Main static int rna_SceneCollection_move_into(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst) { - Scene *scene = (Scene *)id; - - if (!BKE_collection_move_into(scene, sc_dst, sc_src)) { + if (!BKE_collection_move_into(id, sc_dst, sc_src)) { return 0; } @@ -139,8 +154,7 @@ static int rna_SceneCollection_move_into(ID *id, SceneCollection *sc_src, Main * static SceneCollection *rna_SceneCollection_new( ID *id, SceneCollection *sc_parent, Main *bmain, const char *name) { - Scene *scene = (Scene *)id; - SceneCollection *sc = BKE_collection_add(scene, sc_parent, name); + SceneCollection *sc = BKE_collection_add(id, sc_parent, COLLECTION_TYPE_NONE, name); DEG_relations_tag_update(bmain); WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL); @@ -151,7 +165,6 @@ static SceneCollection *rna_SceneCollection_new( static void rna_SceneCollection_remove( ID *id, SceneCollection *sc_parent, Main *bmain, ReportList *reports, PointerRNA *sc_ptr) { - Scene *scene = (Scene *)id; SceneCollection *sc = sc_ptr->data; const int index = BLI_findindex(&sc_parent->scene_collections, sc); @@ -161,7 +174,7 @@ static void rna_SceneCollection_remove( return; } - if (!BKE_collection_remove(scene, sc)) { + if (!BKE_collection_remove(id, sc)) { BKE_reportf(reports, RPT_ERROR, "Collection '%s' could not be removed from collection '%s'", sc->name, sc_parent->name); return; @@ -203,7 +216,7 @@ void rna_SceneCollection_object_link( return; } - BKE_collection_object_add(scene, sc, ob); + BKE_collection_object_add(&scene->id, sc, ob); /* TODO(sergey): Only update relations for the current scene. */ DEG_relations_tag_update(bmain); @@ -226,7 +239,7 @@ static void rna_SceneCollection_object_unlink( return; } - BKE_collection_object_remove(bmain, scene, sc, ob, false); + BKE_collection_object_remove(bmain, &scene->id, sc, ob, false); /* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */ DEG_relations_tag_update(bmain); @@ -417,11 +430,11 @@ static void rna_ViewLayerEngineSettings_update(bContext *C, PointerRNA *UNUSED(p DEG_id_tag_update(&scene->id, 0); } -static void rna_LayerCollectionEngineSettings_update(bContext *C, PointerRNA *UNUSED(ptr)) +static void rna_LayerCollectionEngineSettings_update(bContext *UNUSED(C), PointerRNA *ptr) { - Scene *scene = CTX_data_scene(C); + ID *id = ptr->id.data; /* TODO(sergey): Use proper flag for tagging here. */ - DEG_id_tag_update(&scene->id, 0); + DEG_id_tag_update(id, 0); } static void rna_LayerCollectionEngineSettings_wire_update(bContext *C, PointerRNA *UNUSED(ptr)) @@ -641,9 +654,7 @@ static PointerRNA rna_LayerCollection_objects_get(CollectionPropertyIterator *it static int rna_LayerCollection_move_above(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst) { - Scene *scene = (Scene *)id; - - if (!BKE_layer_collection_move_above(scene, lc_dst, lc_src)) { + if (!BKE_layer_collection_move_above(id, lc_dst, lc_src)) { return 0; } @@ -655,9 +666,7 @@ static int rna_LayerCollection_move_above(ID *id, LayerCollection *lc_src, Main static int rna_LayerCollection_move_below(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst) { - Scene *scene = (Scene *)id; - - if (!BKE_layer_collection_move_below(scene, lc_dst, lc_src)) { + if (!BKE_layer_collection_move_below(id, lc_dst, lc_src)) { return 0; } @@ -669,9 +678,7 @@ static int rna_LayerCollection_move_below(ID *id, LayerCollection *lc_src, Main static int rna_LayerCollection_move_into(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst) { - Scene *scene = (Scene *)id; - - if (!BKE_layer_collection_move_into(scene, lc_dst, lc_src)) { + if (!BKE_layer_collection_move_into(id, lc_dst, lc_src)) { return 0; } @@ -681,19 +688,27 @@ static int rna_LayerCollection_move_into(ID *id, LayerCollection *lc_src, Main * return 1; } -static void rna_LayerCollection_flag_update(bContext *C, PointerRNA *UNUSED(ptr)) +static void rna_LayerCollection_flag_update(bContext *C, PointerRNA *ptr) { - Scene *scene = CTX_data_scene(C); + ID *id = ptr->id.data; /* 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); + DEG_id_tag_update(id, 0); + WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C)); } static void rna_LayerCollection_enable_set( ID *id, LayerCollection *layer_collection, Main *bmain, bContext *C, ReportList *reports, int value) { - Scene *scene = (Scene *)id; - ViewLayer *view_layer = BKE_view_layer_find_from_collection(scene, layer_collection); + ViewLayer *view_layer; + if (GS(id->name) == ID_SCE) { + Scene *scene = (Scene *)id; + view_layer = BKE_view_layer_find_from_collection(&scene->id, layer_collection); + } + else { + BLI_assert(GS(id->name) == ID_GR); + Group *group = (Group *)id; + view_layer = group->view_layer; + } if (layer_collection->flag & COLLECTION_DISABLED) { if (value == 1) { @@ -715,6 +730,7 @@ static void rna_LayerCollection_enable_set( } } + Scene *scene = CTX_data_scene(C); DEG_relations_tag_update(bmain); /* TODO(sergey): Use proper flag for tagging here. */ DEG_id_tag_update(&scene->id, 0); @@ -1034,6 +1050,7 @@ static void rna_def_scene_collection(BlenderRNA *brna) srna = RNA_def_struct(brna, "SceneCollection", NULL); RNA_def_struct_ui_text(srna, "Scene Collection", "Collection"); + RNA_def_struct_refine_func(srna, "rna_SceneCollection_refine"); prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_string_funcs(prop, NULL, NULL, "rna_SceneCollection_name_set"); @@ -1041,6 +1058,11 @@ static void rna_def_scene_collection(BlenderRNA *brna) RNA_def_struct_name_property(srna, prop); RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, NULL); + prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, rna_enum_collection_type_items); + RNA_def_property_ui_text(prop, "Type", "Type of collection"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + prop = RNA_def_property(srna, "filter", PROP_STRING, PROP_NONE); RNA_def_property_string_funcs(prop, NULL, NULL, "rna_SceneCollection_filter_set"); RNA_def_property_ui_text(prop, "Filter", "Filter to dynamically include objects based on their names (e.g., CHAR_*)"); |