Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2018-11-06 19:20:49 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2018-11-06 19:20:49 +0300
commit7b38df41ae8b2903eb65dc72e506ba0b0c58453d (patch)
tree61b841a5f634a1b6806688c1fb4b563b92b7e99a
parentaa9912ec045e3209bc87c48801fd955c59bd0908 (diff)
Fix/cleanup RNA viewlayer API.
RNA's ViewLayer would present 'first level' of layer collection as a list (collection property), when it is actually now only a single item, same as the scene's master collection. Note: did not try to update view_layer python tests, those are already fully broken for quiet some time I guess (they still assume view_layer.collections to be mutable e.g.)...
-rw-r--r--doc/python_api/examples/bpy.types.Object.py2
-rw-r--r--release/scripts/modules/bpy_extras/object_utils.py10
-rw-r--r--release/scripts/startup/bl_operators/clip.py4
-rw-r--r--source/blender/makesrna/intern/rna_layer.c53
4 files changed, 30 insertions, 39 deletions
diff --git a/doc/python_api/examples/bpy.types.Object.py b/doc/python_api/examples/bpy.types.Object.py
index f141ac7ce0f..46f42c828d7 100644
--- a/doc/python_api/examples/bpy.types.Object.py
+++ b/doc/python_api/examples/bpy.types.Object.py
@@ -19,7 +19,7 @@ light_object = bpy.data.objects.new(name="New Light", object_data=light_data)
# Link light object to the active collection of current view layer,
# so that it'll appear in the current scene.
-view_layer.collections.active.collection.objects.link(light_object)
+view_layer.active_layer_collection.collection.objects.link(light_object)
# Place light to a specified location.
light_object.location = (5.0, 5.0, 5.0)
diff --git a/release/scripts/modules/bpy_extras/object_utils.py b/release/scripts/modules/bpy_extras/object_utils.py
index ab32daa9d67..dbb4a376099 100644
--- a/release/scripts/modules/bpy_extras/object_utils.py
+++ b/release/scripts/modules/bpy_extras/object_utils.py
@@ -121,18 +121,12 @@ def object_data_add(context, obdata, operator=None, name=None):
"""
scene = context.scene
layer = context.view_layer
- layer_collection = context.layer_collection
+ layer_collection = context.layer_collection or layer.active_layer_collection
+ scene_collection = layer_collection.collection
for ob in layer.objects:
ob.select_set(action='DESELECT')
- if not layer_collection:
- # when there is no collection linked to this view_layer create one
- scene_collection = scene.master_collection.collections.new("")
- layer_collection = layer.collections.link(scene_collection)
- else:
- scene_collection = layer_collection.collection
-
if name is None:
name = "Object" if obdata is None else obdata.name
diff --git a/release/scripts/startup/bl_operators/clip.py b/release/scripts/startup/bl_operators/clip.py
index dfdfa845114..96aed07ecea 100644
--- a/release/scripts/startup/bl_operators/clip.py
+++ b/release/scripts/startup/bl_operators/clip.py
@@ -673,13 +673,13 @@ class CLIP_OT_setup_tracking_scene(Operator):
# rendersettings
setup_collection_recursively(
- vlayers["Foreground"].collections[0].children,
+ vlayers["Foreground"].layer_collection.children,
"background",
"holdout",
)
setup_collection_recursively(
- vlayers["Background"].collections[0].children,
+ vlayers["Background"].layer_collection.children,
"foreground",
"indirect_only",
)
diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c
index df86a45b1a9..727364a5bda 100644
--- a/source/blender/makesrna/intern/rna_layer.c
+++ b/source/blender/makesrna/intern/rna_layer.c
@@ -70,19 +70,21 @@
/***********************************/
-static PointerRNA rna_LayerCollections_active_collection_get(PointerRNA *ptr)
+static PointerRNA rna_ViewLayer_active_layer_collection_get(PointerRNA *ptr)
{
ViewLayer *view_layer = (ViewLayer *)ptr->data;
LayerCollection *lc = view_layer->active_collection;
return rna_pointer_inherit_refine(ptr, &RNA_LayerCollection, lc);
}
-static void rna_LayerCollections_active_collection_set(PointerRNA *ptr, PointerRNA value)
+static void rna_ViewLayer_active_layer_collection_set(PointerRNA *ptr, PointerRNA value)
{
ViewLayer *view_layer = (ViewLayer *)ptr->data;
LayerCollection *lc = (LayerCollection *)value.data;
const int index = BKE_layer_collection_findindex(view_layer, lc);
- if (index != -1) BKE_layer_collection_activate(view_layer, lc);
+ if (index != -1) {
+ BKE_layer_collection_activate(view_layer, lc);
+ }
}
static PointerRNA rna_LayerObjects_active_object_get(PointerRNA *ptr)
@@ -240,29 +242,12 @@ static void rna_def_layer_collection(BlenderRNA *brna)
prop = RNA_def_property(srna, "indirect_only", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", LAYER_COLLECTION_INDIRECT_ONLY);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
- RNA_def_property_ui_text(prop, "Indirect Only", "Objects in collection only contribute indirectly (through shadows and reflections) in the view layer");
+ RNA_def_property_ui_text(prop, "Indirect Only",
+ "Objects in collection only contribute indirectly (through shadows and reflections) "
+ "in the view layer");
RNA_def_property_update(prop, NC_SCENE | ND_LAYER, "rna_LayerCollection_use_update");
}
-static void rna_def_layer_collections(BlenderRNA *brna, PropertyRNA *cprop)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- RNA_def_property_srna(cprop, "LayerCollections");
- srna = RNA_def_struct(brna, "LayerCollections", NULL);
- RNA_def_struct_sdna(srna, "ViewLayer");
- RNA_def_struct_ui_text(srna, "Layer Collections", "Collections of render layer");
-
- prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "LayerCollection");
- RNA_def_property_pointer_funcs(prop, "rna_LayerCollections_active_collection_get",
- "rna_LayerCollections_active_collection_set", NULL, NULL);
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
- RNA_def_property_ui_text(prop, "Active Layer Collection", "Active Layer Collection");
- RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
-}
-
static void rna_def_layer_objects(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
@@ -275,7 +260,8 @@ static void rna_def_layer_objects(BlenderRNA *brna, PropertyRNA *cprop)
prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_funcs(prop, "rna_LayerObjects_active_object_get", "rna_LayerObjects_active_object_set", NULL, NULL);
+ RNA_def_property_pointer_funcs(prop, "rna_LayerObjects_active_object_get",
+ "rna_LayerObjects_active_object_set", NULL, NULL);
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
RNA_def_property_ui_text(prop, "Active Object", "Active object for this layer");
/* Could call: ED_object_base_activate(C, rl->basact);
@@ -329,11 +315,22 @@ void RNA_def_view_layer(BlenderRNA *brna)
RNA_def_function_ui_description(func, "Requery the enabled render passes from the render engine");
RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_NO_SELF);
- prop = RNA_def_property(srna, "collections", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "layer_collections", NULL);
+ prop = RNA_def_property(srna, "layer_collection", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "LayerCollection");
- RNA_def_property_ui_text(prop, "Layer Collections", "");
- rna_def_layer_collections(brna, prop);
+ RNA_def_property_pointer_sdna(prop, NULL, "layer_collections.first");
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_ui_text(prop, "Layer Collection",
+ "Root of collections hierarchy of this view layer,"
+ "its 'collection' pointer property is the same as the scene's master collection");
+
+ prop = RNA_def_property(srna, "active_layer_collection", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "LayerCollection");
+ RNA_def_property_pointer_funcs(prop, "rna_ViewLayer_active_layer_collection_get",
+ "rna_ViewLayer_active_layer_collection_set", NULL, NULL);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
+ RNA_def_property_ui_text(prop, "Active Layer Collection",
+ "Active layer collection in this view layer's hierarchy");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "object_bases", NULL);