[Bf-blender-cvs] [12fab532be2] temp-unified-collections: Collections: more work on unification with groups

Brecht Van Lommel noreply at git.blender.org
Tue May 15 19:34:09 CEST 2018


Commit: 12fab532be2f9b8d8e82f0286022947a6ebab37a
Author: Brecht Van Lommel
Date:   Tue May 15 19:31:37 2018 +0200
Branches: temp-unified-collections
https://developer.blender.org/rB12fab532be2f9b8d8e82f0286022947a6ebab37a

Collections: more work on unification with groups

* Better backwards compatibility for Hero files saved in previous 2.8 files,
  particularly preserving per view layer visibility.

* Various bugfixes.

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

M	source/blender/blenkernel/BKE_layer.h
M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenkernel/intern/layer.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/space_outliner/outliner_collections.c
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/makesdna/DNA_layer_types.h

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

diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
index 6dce7671e73..725ef65b511 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -84,6 +84,7 @@ void BKE_view_layer_copy_data(
         const int flag);
 
 struct LayerCollection *BKE_layer_collection_get_active(struct ViewLayer *view_layer);
+struct LayerCollection *BKE_layer_collection_activate_parent(struct ViewLayer *view_layer, struct LayerCollection *lc);
 
 int BKE_layer_collection_count(struct ViewLayer *view_layer);
 
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 026ab783753..a6a871eb97e 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -278,7 +278,10 @@ void BKE_collection_new_name_get(Collection *collection_parent, char *rname)
 {
 	char *name;
 
-	if (collection_parent->flag & COLLECTION_IS_MASTER) {
+	if (!collection_parent) {
+		name = BLI_sprintfN("Collection");
+	}
+	else if (collection_parent->flag & COLLECTION_IS_MASTER) {
 		name = BLI_sprintfN("Collection %d", BLI_listbase_count(&collection_parent->children) + 1);
 	}
 	else {
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index c36430ec2cd..45877558ad3 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -436,6 +436,27 @@ LayerCollection *BKE_layer_collection_get_active(ViewLayer *view_layer)
 	return view_layer->active_collection;
 }
 
+/**
+ * Active parent collection
+ */
+LayerCollection *BKE_layer_collection_activate_parent(ViewLayer *view_layer, LayerCollection *lc)
+{
+	CollectionParent *parent = lc->collection->parents.first;
+
+	if (parent) {
+		lc = BKE_layer_collection_first_from_scene_collection(view_layer, parent->collection);
+	}
+	else {
+		lc = NULL;
+	}
+
+	if (!lc) {
+		lc = view_layer->layer_collections.first;
+	}
+
+	view_layer->active_collection = lc;
+	return lc;
+}
 
 /**
  * Recursively get the count of collections
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 319a2b13e09..ccc3e2dea74 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5546,7 +5546,7 @@ static void direct_link_view_settings(FileData *fd, ColorManagedViewSettings *vi
 
 /* ***************** READ VIEW LAYER *************** */
 
-static void direct_link_layer_collections(FileData *fd, ListBase *lb)
+static void direct_link_layer_collections(FileData *fd, ListBase *lb, bool master)
 {
 	link_list(fd, lb);
 	for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
@@ -5554,7 +5554,12 @@ static void direct_link_layer_collections(FileData *fd, ListBase *lb)
 		lc->scene_collection = newdataadr(fd, lc->scene_collection);
 #endif
 
-		direct_link_layer_collections(fd, &lc->layer_collections);
+		/* Master collection is not a real datablock. */
+		if (master) {
+			lc->collection = newdataadr(fd, lc->collection);
+		}
+
+		direct_link_layer_collections(fd, &lc->layer_collections, false);
 	}
 }
 
@@ -5564,7 +5569,7 @@ static void direct_link_view_layer(FileData *fd, ViewLayer *view_layer)
 	link_list(fd, &view_layer->object_bases);
 	view_layer->basact = newdataadr(fd, view_layer->basact);
 
-	direct_link_layer_collections(fd, &view_layer->layer_collections);
+	direct_link_layer_collections(fd, &view_layer->layer_collections, true);
 	view_layer->active_collection = newdataadr(fd, view_layer->active_collection);
 
 	view_layer->id_properties = newdataadr(fd, view_layer->id_properties);
@@ -5580,15 +5585,18 @@ static void direct_link_view_layer(FileData *fd, ViewLayer *view_layer)
 	view_layer->object_bases_hash = NULL;
 }
 
-static void lib_link_layer_collection(FileData *fd, Library *lib, LayerCollection *layer_collection)
+static void lib_link_layer_collection(FileData *fd, Library *lib, LayerCollection *layer_collection, bool master)
 {
-	layer_collection->collection = newlibadr(fd, lib, layer_collection->collection);
+	/* Master collection is not a real datablock. */
+	if (!master) {
+		layer_collection->collection = newlibadr(fd, lib, layer_collection->collection);
+	}
 
 	for (LayerCollection *layer_collection_nested = layer_collection->layer_collections.first;
 	     layer_collection_nested != NULL;
 	     layer_collection_nested = layer_collection_nested->next)
 	{
-		lib_link_layer_collection(fd, lib, layer_collection_nested);
+		lib_link_layer_collection(fd, lib, layer_collection_nested, false);
 	}
 }
 
@@ -5623,7 +5631,7 @@ static void lib_link_view_layer(FileData *fd, Library *lib, ViewLayer *view_laye
 	     layer_collection != NULL;
 	     layer_collection = layer_collection->next)
 	{
-		lib_link_layer_collection(fd, lib, layer_collection);
+		lib_link_layer_collection(fd, lib, layer_collection, true);
 	}
 
 	IDP_LibLinkProperty(view_layer->id_properties, fd);
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index bf1b0e64b11..eda07e608f3 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -195,57 +195,79 @@ enum {
 static void do_version_view_layer_visibility(ViewLayer *view_layer)
 {
 	/* Convert from deprecated VISIBLE flag to DISABLED */
-	LayerCollection *layer_collection;
-	for (layer_collection = view_layer->layer_collections.first;
-	     layer_collection;
-	     layer_collection = layer_collection->next)
+	LayerCollection *lc;
+	for (lc = view_layer->layer_collections.first;
+	     lc;
+	     lc = lc->next)
 	{
-		if (layer_collection->flag & COLLECTION_DEPRECATED_DISABLED) {
-			layer_collection->flag &= ~COLLECTION_DEPRECATED_DISABLED;
+		if (lc->flag & COLLECTION_DEPRECATED_DISABLED) {
+			lc->flag &= ~COLLECTION_DEPRECATED_DISABLED;
 		}
 
-		if ((layer_collection->flag & COLLECTION_DEPRECATED_VISIBLE) == 0) {
-			layer_collection->flag |= COLLECTION_DEPRECATED_DISABLED;
+		if ((lc->flag & COLLECTION_DEPRECATED_VISIBLE) == 0) {
+			lc->flag |= COLLECTION_DEPRECATED_DISABLED;
 		}
 
-		layer_collection->flag |= COLLECTION_DEPRECATED_VIEWPORT | COLLECTION_DEPRECATED_RENDER;
+		lc->flag |= COLLECTION_DEPRECATED_VIEWPORT | COLLECTION_DEPRECATED_RENDER;
 	}
 }
 
-static void do_version_scene_collection_visibility(ViewLayer *view_layer, ListBase *lb)
+static void do_version_layer_collection_pre(ViewLayer *view_layer,
+                                            ListBase *lb,
+                                            GSet *enabled_set,
+                                            GSet *selectable_set)
 {
-	/* Convert from deprecated DISABLED in layer to VIEWPORT/RENDER in scene */
-	LayerCollection *layer_collection;
-	for (layer_collection = lb->first; layer_collection; layer_collection = layer_collection->next)
-	{
-		/* TODO: find a better heuristic? test on existing files */
-		if (layer_collection->collection) {
-			if (view_layer->flag & VIEW_LAYER_RENDER) {
-				if (layer_collection->flag & COLLECTION_DEPRECATED_DISABLED) {
-					layer_collection->collection->flag |= COLLECTION_RESTRICT_RENDER;
-				}
+	/* Convert from deprecated DISABLED to new layer collection and collection flags */
+	for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
+		if (lc->scene_collection) {
+			if (!(lc->flag & COLLECTION_DEPRECATED_DISABLED)) {
+				BLI_gset_insert(enabled_set, lc->scene_collection);
 			}
-			else {
-				if (layer_collection->flag & COLLECTION_DEPRECATED_DISABLED) {
-					layer_collection->collection->flag |= COLLECTION_RESTRICT_VIEW;
-				}
+			if (lc->flag & COLLECTION_DEPRECATED_SELECTABLE) {
+				BLI_gset_insert(selectable_set, lc->scene_collection);
 			}
+		}
 
-			if (!(layer_collection->flag & COLLECTION_DEPRECATED_SELECTABLE)) {
-				layer_collection->collection->flag |= COLLECTION_RESTRICT_SELECT;
-			}
+		do_version_layer_collection_pre(view_layer, &lc->layer_collections, enabled_set, selectable_set);
+	}
+}
+
+static void do_version_layer_collection_post(ViewLayer *view_layer,
+                                             ListBase *lb,
+                                             GSet *enabled_set,
+                                             GSet *selectable_set,
+                                             GHash *collection_map)
+{
+	/* Apply layer collection exclude flags. */
+	for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
+		SceneCollection *sc = BLI_ghash_lookup(collection_map, lc->collection);
+		const bool enabled = (sc && BLI_gset_haskey(enabled_set, sc));
+		const bool selectable = (sc && BLI_gset_haskey(selectable_set, sc));
+
+		if (!enabled) {
+			lc->flag |= LAYER_COLLECTION_EXCLUDE;
+		}
+		if (enabled && !selectable) {
+			lc->collection->flag |= COLLECTION_RESTRICT_SELECT;
 		}
 
-		do_version_scene_collection_visibility(view_layer, &layer_collection->layer_collections);
+		do_version_layer_collection_post(view_layer, &lc->layer_collections, enabled_set, selectable_set, collection_map);
 	}
 }
 
-static void do_version_scene_collection_convert(Main *bmain, SceneCollection *sc, Collection *collection)
+static void do_version_scene_collection_convert(Main *bmain,
+                                                SceneCollection *sc,
+                                                Collection *collection,
+                                                GHash *collection_map)
 {
+	if (collection_map) {
+		BLI_ghash_insert(collection_map, collection, sc);
+	}
+
 	for (SceneCollection *nsc = sc->scene_collections.first; nsc;) {
 		SceneCollection *nsc_next = nsc->next;
 		Collection *ncollection = BKE_collection_add(bmain, collection, nsc->name);
-		do_version_scene_collection_convert(bmain, nsc, ncollection);
+		do_version_scene_collection_convert(bmain, nsc, ncollection, collection_map);
 		nsc = nsc_next;
 	}
 
@@ -263,8 +285,9 @@ static void do_version_scene_collection_convert(Main *bmain, SceneCollection *sc
 
 static void do_version_group_collection_to_collection(Main *bmain, Collection *group)
 {
+	/* Convert old 2.8 group collections to new unified collections. */
 	if (group->collection) {
-	

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list