[Bf-blender-cvs] [fe1e2c2f89b] blender2.8: Collections: deletea collection move objects to master collection if users=0

Dalai Felinto noreply at git.blender.org
Fri Dec 22 22:18:35 CET 2017


Commit: fe1e2c2f89b54302b213621f6ffd2b6089016155
Author: Dalai Felinto
Date:   Fri Dec 22 19:15:06 2017 -0200
Branches: blender2.8
https://developer.blender.org/rBfe1e2c2f89b54302b213621f6ffd2b6089016155

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.

===================================================================

M	source/blender/blenkernel/intern/collection.c

===================================================================

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



More information about the Bf-blender-cvs mailing list