LibOverride: When created from IDTemplate UI, ensure instanciation of hierarchy root.
When a new liboverride is created from the IDTemplate UI widget, in case its hierarchy root is different than the liboverride itself, ensure that it is also instanciated in the scene, if possible (i.e. if it's an object or collection). Should allow for better representation of liboverride hierarchies created that way, and reduce the risk of getting key liboverrides hidden from the scene's hierarchy (in the Outliner ViewLayer view e.g.).
This commit is contained in:
@@ -720,7 +720,8 @@ ID *ui_template_id_liboverride_hierarchy_make(
|
||||
}
|
||||
}
|
||||
|
||||
Collection *collection_active = CTX_data_collection(C);
|
||||
Collection *collection_active_context = CTX_data_collection(C);
|
||||
Collection *collection_active = collection_active_context;
|
||||
if (collection_active == nullptr && GS(owner_id->name) == ID_GR) {
|
||||
collection_active = (Collection *)owner_id;
|
||||
}
|
||||
@@ -902,6 +903,33 @@ ID *ui_template_id_liboverride_hierarchy_make(
|
||||
|
||||
if (id_override != nullptr) {
|
||||
id_override->override_library->flag &= ~LIBOVERRIDE_FLAG_SYSTEM_DEFINED;
|
||||
|
||||
/* Ensure that the hierarchy root of the newly overridden data is instanciated in the scene, in
|
||||
* case it's a collection or object. */
|
||||
ID *hierarchy_root = id_override->override_library->hierarchy_root;
|
||||
if (GS(hierarchy_root->name) == ID_OB) {
|
||||
Object *object_hierarchy_root = reinterpret_cast<Object *>(hierarchy_root);
|
||||
if (!BKE_scene_has_object(scene, object_hierarchy_root)) {
|
||||
if (!ID_IS_LINKED(collection_active_context)) {
|
||||
BKE_collection_object_add(bmain, collection_active_context, object_hierarchy_root);
|
||||
}
|
||||
else {
|
||||
BKE_collection_object_add(bmain, scene->master_collection, object_hierarchy_root);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (GS(hierarchy_root->name) == ID_GR) {
|
||||
Collection *collection_hierarchy_root = reinterpret_cast<Collection *>(hierarchy_root);
|
||||
if (!BKE_collection_has_collection(scene->master_collection, collection_hierarchy_root)) {
|
||||
if (!ID_IS_LINKED(collection_active_context)) {
|
||||
BKE_collection_child_add(bmain, collection_active_context, collection_hierarchy_root);
|
||||
}
|
||||
else {
|
||||
BKE_collection_child_add(bmain, scene->master_collection, collection_hierarchy_root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*r_undo_push_label = "Make Library Override Hierarchy";
|
||||
|
||||
/* In theory we could rely on setting/updating the RNA ID pointer property (as done by calling
|
||||
|
||||
Reference in New Issue
Block a user