Collections: deletea collection move objects to master collection if users=0
The mental model is that a scene collection is a small wrap on top of the master collection, so all objects are in the master collection at all times. When we remove a collection there is no reason to remove an object. So if the object was not linked to any other collection, we add link it to the master one.
This commit is contained in:
parent
8ed1c61642
commit
fe1e2c2f89
Notes:
blender-bot
2023-02-14 06:18:26 +01:00
Referenced by issue #53633, Grease Pencil scaling issues through multiple editors. Referenced by issue #53636, Workspaces: Changing active view layer doesn't update viewport visibility
|
@ -175,6 +175,8 @@ static void layer_collection_remove(ViewLayer *view_layer, ListBase *lb, const S
|
|||
|
||||
/**
|
||||
* Remove a collection from the scene, and syncronize all render layers
|
||||
*
|
||||
* If an object is in any other collection, link the object to the master collection.
|
||||
*/
|
||||
bool BKE_collection_remove(ID *owner_id, SceneCollection *sc)
|
||||
{
|
||||
|
@ -190,6 +192,36 @@ bool BKE_collection_remove(ID *owner_id, SceneCollection *sc)
|
|||
BLI_assert(false);
|
||||
}
|
||||
|
||||
/* If an object is no longer in any collection, we add it to the master collection. */
|
||||
ListBase collection_objects;
|
||||
BLI_duplicatelist(&collection_objects, &sc->objects);
|
||||
|
||||
FOREACH_SCENE_COLLECTION(owner_id, scene_collection_iter)
|
||||
{
|
||||
if (scene_collection_iter == sc) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LinkData *link_next, *link = collection_objects.first;
|
||||
while (link) {
|
||||
link_next = link->next;
|
||||
|
||||
if (BLI_findptr(&scene_collection_iter->objects, link->data, offsetof(LinkData, data))) {
|
||||
BLI_remlink(&collection_objects, link);
|
||||
MEM_freeN(link);
|
||||
}
|
||||
|
||||
link = link_next;
|
||||
}
|
||||
}
|
||||
FOREACH_SCENE_COLLECTION_END
|
||||
|
||||
for (LinkData *link = collection_objects.first; link; link = link->next) {
|
||||
BKE_collection_object_add(owner_id, sc_master, link->data);
|
||||
}
|
||||
|
||||
BLI_freelistN(&collection_objects);
|
||||
|
||||
/* Clear the collection items. */
|
||||
collection_free(sc, true);
|
||||
|
||||
|
|
Loading…
Reference in New Issue