Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2017-12-23 00:15:06 +0300
committerDalai Felinto <dfelinto@gmail.com>2017-12-23 00:18:21 +0300
commitfe1e2c2f89b54302b213621f6ffd2b6089016155 (patch)
treebb074f01634b873f1b5f430d3297dfdb5beeea0b
parent8ed1c616424eb9c418f0b7fa438acb27fda2fdbf (diff)
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.
-rw-r--r--source/blender/blenkernel/intern/collection.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index f8934184928..ea8dbc64c9f 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -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);