[Bf-blender-cvs] [8d55fe9] render-layers: Start of versioning and more work

Dalai Felinto noreply at git.blender.org
Wed Nov 30 15:25:14 CET 2016


Commit: 8d55fe98991c313db2ff49a8cdf211d484bae4d4
Author: Dalai Felinto
Date:   Tue Nov 29 18:24:00 2016 +0100
Branches: render-layers
https://developer.blender.org/rB8d55fe98991c313db2ff49a8cdf211d484bae4d4

Start of versioning and more work

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

M	source/blender/blenkernel/BKE_collection.h
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/versioning_280.c
M	source/blender/makesdna/DNA_layer_types.h

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

diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index b8c1d1b..892799c 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -27,5 +27,23 @@
  *  \ingroup bke
  */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Collection;
+struct ListBase;
+struct Object;
+struct Scene;
+
+struct Collection *BKE_collection_add(struct Scene *scene, struct ListBase *lb, const char *name);
+void BKE_collection_remove(struct Scene *scene, struct Collection *collection);
+struct Collection *BKE_collection_master(struct Scene *scene);
+void BKE_collection_object_add(struct Scene *scene, struct Collection *collection, struct Object *object);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* __BKE_COLLECTION_H__ */
 
diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
index 0d5c38f..2489a62 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -27,5 +27,20 @@
  *  \ingroup bke
  */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define TODO_LAYER_SYNC
+
+struct RenderLayer;
+struct Scene;
+
+struct RenderLayer *BKE_render_layer_add(struct Scene *scene, const char *name);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* __BKE_LAYER_H__ */
 
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 0ad7933..f753747 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -23,3 +23,98 @@
 /** \file blender/blenkernel/intern/collection.c
  *  \ingroup bke
  */
+
+#include "BLI_blenlib.h"
+#include "BLI_listbase.h"
+#include "BLT_translation.h"
+
+#include "BKE_collection.h"
+#include "BKE_layer.h"
+#include "BKE_library.h"
+
+#include "DNA_layer_types.h"
+#include "DNA_scene_types.h"
+
+#include "MEM_guardedalloc.h"
+
+Collection *BKE_collection_add(Scene *scene, ListBase *lb, const char *name)
+{
+	Collection *collection = MEM_callocN(sizeof(Collection), "New Collection");
+	BLI_strncpy(collection->name, name, sizeof(collection->name));
+	BLI_uniquename(&scene->collections, collection, DATA_("Collection"), '.', offsetof(Collection, name), sizeof(collection->name));
+
+	if (lb) {
+		BLI_addtail(lb, collection);
+	}
+	else {
+		Collection *collection_master = BKE_collection_master(scene);
+		BLI_addtail(&collection_master->collections, collection);
+	}
+
+	TODO_LAYER_SYNC;
+	return collection;
+}
+
+/* free the collection items recursively */
+static void collection_free(Collection *collection)
+{
+	for (LinkData *link = collection->objects.first; link; link = link->next) {
+		id_us_min(link->data);
+	}
+
+	for (LinkData *link = collection->filter_objects.first; link; link = link->next) {
+		id_us_min(link->data);
+	}
+
+	for (Collection *cl = collection->collections.first; cl; cl = cl->next) {
+		collection_free(cl);
+	}
+	BLI_freelistN(&collection->collections);
+}
+
+/* unlink the collection recursively
+ * return true if unlinked */
+static bool collection_unlink(Collection *collection, Collection *gone)
+{
+	for (Collection *nc = collection->collections.first; nc; nc = nc->next)
+	{
+		if (nc == gone) {
+			BLI_remlink(&collection->collections, gone);
+			return true;
+		}
+
+		if (collection_unlink(nc, gone)) {
+			return true;
+		}
+	}
+	return false;
+}
+
+void BKE_collection_remove(Scene *scene, Collection *collection)
+{
+	Collection *master = BKE_collection_master(scene);
+
+	/* unlink from the main collection tree */
+	collection_unlink(master, collection);
+
+	/* clear the collection items */
+	collection_free(collection);
+
+	/* TODO: check all layers that use this collection and clear them */
+	TODO_LAYER_SYNC;
+
+	MEM_freeN(collection);
+}
+
+Collection *BKE_collection_master(Scene *scene)
+{
+	return scene->collections.first;
+}
+
+void BKE_collection_object_add(struct Scene *scene, struct Collection *collection, struct Object *object)
+{
+	BLI_addtail(&collection->objects, BLI_genericNodeN(object));
+	id_us_plus((ID *)object);
+	TODO_LAYER_SYNC;
+}
+
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index 8f7a13d..a638248 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -23,3 +23,41 @@
 /** \file blender/blenkernel/intern/layer.c
  *  \ingroup bke
  */
+
+#include "BKE_collection.h"
+#include "BKE_layer.h"
+
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_layer_types.h"
+#include "DNA_scene_types.h"
+
+/* prototype */
+CollectionBase *collection_base_add(RenderLayer *rl, Collection *collection);
+
+RenderLayer *BKE_render_layer_add(Scene *scene, const char *name)
+{
+	RenderLayer *rl = MEM_callocN(sizeof(RenderLayer), "Render Layer");
+	BLI_strncpy(rl->name, name, sizeof(rl->name));
+
+	Collection *collection = BKE_collection_master(scene);
+	CollectionBase *collection_base = collection_base_add(rl, collection);
+	return rl;
+}
+
+CollectionBase *collection_base_add(RenderLayer *rl, Collection *collection)
+{
+	CollectionBase *base = MEM_callocN(sizeof(CollectionBase), "Collection Base");
+	BLI_addhead(&rl->collection_bases, base);
+
+	base->collection = collection;
+	base->flag = COLLECTION_VISIBLE + COLLECTION_SELECTABLE + COLLECTION_FOLDED;
+
+	TODO_LAYER_SYNC;
+	/* TODO: add objects and collections to sl->object_bases, and sl->collection_bases */
+	return base;
+}
+
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 25fbc2f..63a8aa3 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -29,9 +29,12 @@
 #define DNA_DEPRECATED_ALLOW
 
 #include "DNA_object_types.h"
+#include "DNA_layer_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_genfile.h"
 
+#include "BKE_collection.h"
+#include "BKE_layer.h"
 #include "BKE_main.h"
 #include "BKE_scene.h"
 
@@ -45,5 +48,55 @@
 
 void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
 {
+	if (!DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "render_layers")) {
+		for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+
+			BKE_collection_add(scene, &scene->collections, "Master Collection");
+			RenderLayer *rl = BKE_render_layer_add(scene, "Render Layer");
+
+			rl->active_collection = 0;
+			rl->actbase = NULL;
+
+			Collection *collections[20] = {NULL};
+			bool is_visible[20];
+
+			int lay_used = 0;
+			for (int i = 0; i < 20; i++) {
+				char name[MAX_NAME];
+
+				BLI_snprintf(name, sizeof(collections[i]->name), "%d", i + 1);
+				collections[i] = BKE_collection_add(scene, NULL, name);
+
+				is_visible[i] = (scene->lay & (1 << i));
+			}
+
+			for (Base *base = scene->base.first; base; base = base->next) {
+				lay_used |= base->lay & ((1 << 20) - 1); /* ignore localview */
+
+				for (int i = 0; i < 20; i++) {
+					if ((base->lay & (1 << i)) != 0) {
+						BKE_collection_object_add(scene, collections[i], base->object);
+					}
+				}
+			}
+
+			/* TODO
+			 * we need to go over all the CollectionBases created for this rl, and the original rls,
+			 * and set visibility of collections accordingly
+			 * */
+
+			/* TODO
+			 * handle existing SceneRenderLayer
+			 * for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next);
+			 */
+
+			/* Cleanup */
+			for (int i = 0; i < 20; i++) {
+				if ((lay_used & (1 << i)) == 0) {
+					BKE_collection_remove(scene, collections[i]);
+				}
+			}
+		}
+	}
 }
 
diff --git a/source/blender/makesdna/DNA_layer_types.h b/source/blender/makesdna/DNA_layer_types.h
index 7023110..d303bc0 100644
--- a/source/blender/makesdna/DNA_layer_types.h
+++ b/source/blender/makesdna/DNA_layer_types.h
@@ -49,9 +49,9 @@ typedef struct CollectionBase {
 	struct CollectionBase *next, *prev;
 	struct Collection *collection;
 	short flag;
-	short pad[3];
+	short pad[2];
 	ListBase collection_bases; /* synced with collection->collections */
-	ListBase object_bases; /* synced with collection->objects */
+	ListBase object_bases; /* synced with collection->objects and collection->filter_objects */
 	ListBase overrides;
 } CollectionBase;
 
@@ -61,14 +61,16 @@ typedef struct Collection {
 	char filter[64]; /* MAX_NAME */
 	ListBase collections; /* nested collections */
 	ListBase objects;
+	ListBase filter_objects;
 } Collection;
 
-typedef struct Layer {
-	struct Layer *next, prev;
+typedef struct RenderLayer {
+	struct RenderLayer *next, *prev;
 	char name[64]; /* MAX_NAME */
 	char engine[32]; /* render engine */
 	short active_collection;
 	struct Base *actbase;
+	ListBase collection_bases;
 	ListBase object_bases;
 } RenderLayer;




More information about the Bf-blender-cvs mailing list