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.)...
This commit is contained in:
Bastien Montagne 2018-11-06 17:20:49 +01:00
parent aa9912ec04
commit 7b38df41ae
Notes: blender-bot 2023-02-14 05:04:52 +01:00
Referenced by issue #57655, Crash after opening a v2.79 file saved with maximized area
4 changed files with 30 additions and 39 deletions

View File

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

View File

@ -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

View File

@ -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",
)

View File

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