[Bf-blender-cvs] [7b38df41ae8] blender2.8: Fix/cleanup RNA viewlayer API.

Bastien Montagne noreply at git.blender.org
Tue Nov 6 17:26:25 CET 2018


Commit: 7b38df41ae8b2903eb65dc72e506ba0b0c58453d
Author: Bastien Montagne
Date:   Tue Nov 6 17:20:49 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB7b38df41ae8b2903eb65dc72e506ba0b0c58453d

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.)...

===================================================================

M	doc/python_api/examples/bpy.types.Object.py
M	release/scripts/modules/bpy_extras/object_utils.py
M	release/scripts/startup/bl_operators/clip.py
M	source/blender/makesrna/intern/rna_layer.c

===================================================================

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);



More information about the Bf-blender-cvs mailing list