Library Overrides: Don't move collections to Scene Collection when overriding

When using the "Make Library Override" operator on instance collections, keep
the overriden collection in the parent collection of the instance empty.
Previoulsy the collection would be added to the scene collection, which was
confusing and not what users expected. It was placed there for a reason after
all.

Part of T76555.

Reviewed by: Andy Goralczyk, Bastien Montange.

Differential Revision: https://developer.blender.org/D7626
This commit is contained in:
Julian Eisel 2020-06-02 17:31:59 +02:00
parent 1743326889
commit bd3ab27410
Notes: blender-bot 2023-02-14 03:44:41 +01:00
Referenced by issue #73318, Library overrides
3 changed files with 39 additions and 11 deletions

View File

@ -50,6 +50,10 @@ typedef struct CollectionParent {
struct Collection *BKE_collection_add(struct Main *bmain,
struct Collection *parent,
const char *name);
void BKE_collection_add_from_object(struct Main *bmain,
struct Scene *scene,
const struct Object *ob_src,
struct Collection *collection_dst);
void BKE_collection_free(struct Collection *collection);
bool BKE_collection_delete(struct Main *bmain, struct Collection *collection, bool hierarchy);

View File

@ -210,6 +210,34 @@ Collection *BKE_collection_add(Main *bmain, Collection *collection_parent, const
return collection;
}
/**
* Add \a collection_dst to all scene collections that reference object \a ob_src is in.
* Used to replace an instance object with a collection (library override operator).
*
* Logic is very similar to #BKE_collection_object_add_from().
*/
void BKE_collection_add_from_object(Main *bmain,
Scene *scene,
const Object *ob_src,
Collection *collection_dst)
{
bool is_instantiated = false;
FOREACH_SCENE_COLLECTION_BEGIN (scene, collection) {
if (!ID_IS_LINKED(collection) && BKE_collection_has_object(collection, ob_src)) {
collection_child_add(collection, collection_dst, 0, true);
is_instantiated = true;
}
}
FOREACH_SCENE_COLLECTION_END;
if (!is_instantiated) {
collection_child_add(scene->master_collection, collection_dst, 0, true);
}
BKE_main_collection_sync(bmain);
}
/*********************** Free and Delete Collection ****************************/
/** Free (or release) any data used by this collection (does not free the collection itself). */
@ -758,8 +786,10 @@ bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
}
/**
* Add object to all scene collections that reference object is in
* (used to copy objects).
* Add \a ob_dst to all scene collections that reference object \a ob_src is in.
* Used for copying objects.
*
* Logic is very similar to #BKE_collection_add_from_object()
*/
void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst)
{

View File

@ -2516,7 +2516,8 @@ static int make_override_library_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
Collection *new_collection = (Collection *)collection->id.newid;
BKE_collection_child_add(bmain, scene->master_collection, new_collection);
BKE_collection_add_from_object(bmain, scene, obcollection, new_collection);
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (new_collection, new_ob) {
if (new_ob != NULL && new_ob->id.override_library != NULL) {
if ((base = BKE_view_layer_base_find(view_layer, new_ob)) == NULL) {
@ -2524,14 +2525,7 @@ static int make_override_library_exec(bContext *C, wmOperator *op)
base = BKE_view_layer_base_find(view_layer, new_ob);
DEG_id_tag_update_ex(bmain, &new_ob->id, ID_RECALC_TRANSFORM | ID_RECALC_BASE_FLAGS);
}
/* parent to 'collection' empty */
/* Disabled for now, according to some artist this is probably not really useful anyway.
* And it breaks things like objects parented to bones
* (most likely due to missing proper setting of inverse parent matrix?)... */
/* Note: we might even actually want to get rid of that instantiating empty... */
if (0 && new_ob->parent == NULL) {
new_ob->parent = obcollection;
}
if (new_ob == (Object *)obact->id.newid) {
/* TODO: is setting active needed? */
BKE_view_layer_base_select_and_set_active(view_layer, base);