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>2016-11-21 22:10:16 +0300
committerDalai Felinto <dfelinto@gmail.com>2016-11-21 22:10:19 +0300
commit3592c959e7563ad1a308a5d52d3bb261fc274153 (patch)
treeb3019905f8157741345ba42d65ddf64605c8f16e /source/blender/blenloader
parent559bd7576602e04b1895481561b054e67982351c (diff)
Layers - initial commit
This is mostly DNA + doversion and some util functions. I need to look at the layer-manager branch to see how Julian Eisel (Severin) managed to handle nested lists (required for collections). Also, since I think doversioning may get more complex as the project evolves, I started the vesioning_280.c file. And the changes in readfile.c were so that I could include into the versioning_280.c file only the DNA_* that were really needed. (if someone feels like doing a cleanup, I'm sure the other versioning_*.c files could use the same treatment)
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r--source/blender/blenloader/CMakeLists.txt1
-rw-r--r--source/blender/blenloader/intern/readfile.c40
-rw-r--r--source/blender/blenloader/intern/readfile.h3
-rw-r--r--source/blender/blenloader/intern/versioning_280.c116
-rw-r--r--source/blender/blenloader/intern/versioning_defaults.c3
-rw-r--r--source/blender/blenloader/intern/writefile.c25
6 files changed, 188 insertions, 0 deletions
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt
index 8cb9ef837b2..e40692f4a88 100644
--- a/source/blender/blenloader/CMakeLists.txt
+++ b/source/blender/blenloader/CMakeLists.txt
@@ -53,6 +53,7 @@ set(SRC
intern/versioning_250.c
intern/versioning_260.c
intern/versioning_270.c
+ intern/versioning_280.c
intern/versioning_defaults.c
intern/versioning_legacy.c
intern/writefile.c
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 677c90051f7..3831bf92d17 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5234,6 +5234,7 @@ static void lib_link_scene(FileData *fd, Main *main)
Scene *sce;
Base *base, *next;
Sequence *seq;
+ SceneLayer *sl;
SceneRenderLayer *srl;
FreestyleModuleConfig *fmc;
FreestyleLineSet *fls;
@@ -5359,6 +5360,22 @@ static void lib_link_scene(FileData *fd, Main *main)
sce->nodetree->id.lib = sce->id.lib;
composite_patch(sce->nodetree, sce);
}
+
+ for (sl = sce->layers.first; sl; sl = sl->next) {
+ for (base = sl->base.first; base; base = next) {
+ next = base->next;
+
+ base->object = newlibadr_us(fd, sce->id.lib, base->object);
+
+ if (base->object == NULL) {
+ blo_reportf_wrap(fd->reports, RPT_WARNING, TIP_("LIB: object lost from scene: '%s'"),
+ sce->id.name + 2);
+ BLI_remlink(&sl->base, base);
+ if (base == sl->basact) sl->basact = NULL;
+ MEM_freeN(base);
+ }
+ }
+ }
for (srl = sce->r.layers.first; srl; srl = srl->next) {
srl->mat_override = newlibadr_us(fd, sce->id.lib, srl->mat_override);
@@ -5486,6 +5503,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
Sequence *seq;
MetaStack *ms;
RigidBodyWorld *rbw;
+ SceneLayer *sl;
SceneRenderLayer *srl;
sce->theDag = NULL;
@@ -5719,6 +5737,20 @@ static void direct_link_scene(FileData *fd, Scene *sce)
sce->preview = direct_link_preview_image(fd, sce->preview);
direct_link_curvemapping(fd, &sce->r.mblur_shutter_curve);
+
+ link_list(fd, &(sce->layers));
+
+ for (sl = sce->layers.first; sl; sl = sl->next) {
+ sl->obedit = NULL;
+ link_list(fd, &(sl->base));
+ sl->basact = newdataadr(fd, sl->basact);
+ link_list(fd, &(sl->collections));
+
+ for (LayerCollection *lc = sl->collections.first; lc; lc = lc->next) {
+ link_list(fd, &(lc->elements));
+ link_list(fd, &(lc->overrides));
+ }
+ }
}
/* ************ READ WM ***************** */
@@ -7959,6 +7991,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
blo_do_versions_250(fd, lib, main);
blo_do_versions_260(fd, lib, main);
blo_do_versions_270(fd, lib, main);
+ blo_do_versions_280(fd, lib, main);
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
/* WATCH IT 2!: Userdef struct init see do_versions_userdef() above! */
@@ -8988,6 +9021,7 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob)
static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
{
Base *base;
+ SceneLayer *sl;
SceneRenderLayer *srl;
FreestyleModuleConfig *module;
FreestyleLineSet *lineset;
@@ -9054,6 +9088,12 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
}
expand_doit(fd, mainvar, sce->clip);
+
+ for (sl = sce->layers.first; sl; sl = sl->next) {
+ for (base = sl->base.first; base; base = base->next) {
+ expand_doit(fd, mainvar, base->object);
+ }
+ }
}
static void expand_camera(FileData *fd, Main *mainvar, Camera *ca)
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 7719aaa2b0d..06d4c903382 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -34,6 +34,8 @@
#define __READFILE_H__
#include "zlib.h"
+#include "DNA_sdna_types.h"
+#include "DNA_space_types.h"
#include "DNA_windowmanager_types.h" /* for ReportType */
struct OldNewMap;
@@ -169,6 +171,7 @@ void blo_do_versions_pre250(struct FileData *fd, struct Library *lib, struct Mai
void blo_do_versions_250(struct FileData *fd, struct Library *lib, struct Main *main);
void blo_do_versions_260(struct FileData *fd, struct Library *lib, struct Main *main);
void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *main);
+void blo_do_versions_280(struct FileData *fd, struct Library *lib, struct Main *main);
#endif
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
new file mode 100644
index 00000000000..3353a6df000
--- /dev/null
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -0,0 +1,116 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+/** \file blender/blenloader/intern/versioning_280.c
+ * \ingroup blenloader
+ */
+
+/* for MinGW32 definition of NULL, could use BLI_blenlib.h instead too */
+#include <stddef.h>
+
+/* allow readfile to use deprecated functionality */
+#define DNA_DEPRECATED_ALLOW
+
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_genfile.h"
+
+#include "BKE_main.h"
+#include "BKE_scene.h"
+
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+
+#include "BLO_readfile.h"
+
+#include "readfile.h"
+
+#include "MEM_guardedalloc.h"
+
+void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
+{
+ if (!DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "layers")) {
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ SceneLayer *layer = MEM_callocN(sizeof(SceneLayer), "initial scene layer");
+ LayerCollection *collections[20] = {NULL};
+ scene->active_layer = 0;
+
+ BLI_addhead(&scene->layers, layer);
+ int lay_used = 0;
+
+ for (int i = 0; i < 20; i++) {
+ LayerCollection *collection = MEM_callocN(sizeof(LayerCollection), "doversion layer collections");
+ collection->flag = COLLECTION_SELECTABLE;
+
+ if (scene->lay & (1 << i)) {
+ collection->flag |= COLLECTION_VISIBLE;
+ }
+
+ BLI_snprintf(collection->name, sizeof(collection->name), "%d", i);
+ collections[i] = collection;
+ }
+
+ Base *base = scene->base.first;
+ while (base) {
+ Base *base_new = MEM_dupallocN(base);
+ BLI_addtail(&layer->base, base_new);
+
+ if (base == scene->basact) {
+ layer->basact = base_new;
+ }
+
+ lay_used |= base->lay & ((1 << 20) - 1); /* ignore localview */
+
+ for (int i = 0; i < 20; i++) {
+ if ((base->lay & (1 << i)) != 0) {
+ LinkData *link = MEM_callocN(sizeof(LinkData), "doversion linkdata");
+ link->data = base_new;
+ BLI_addtail(&collections[i]->elements, link);
+ }
+ }
+ base = base->next;
+ }
+
+ /* We should always have at least one layer, and one collection at all times */
+ if (lay_used == 0) {
+ lay_used = (1 << 0);
+ }
+
+ /* Cleanup */
+ for (int i = 0; i < 20; i++) {
+ if ((lay_used & (1 << i)) != 0) {
+ BLI_addtail(&layer->collections, collections[i]);
+ }
+ else {
+ MEM_freeN(collections[i]);
+ }
+ }
+
+ /*
+ * TODO handle existing SceneRenderLayer
+ * for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next);
+ */
+ }
+ }
+
+}
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index 01ef5d6a606..0e74c3f6170 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -25,6 +25,9 @@
* \ingroup blenloader
*/
+/* allow readfile to use deprecated functionality */
+#define DNA_DEPRECATED_ALLOW
+
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index d8097f1a50a..31e81358a38 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2407,10 +2407,12 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
Base *base;
Editing *ed;
Sequence *seq;
+ LayerCollection *lc;
MetaStack *ms;
Strip *strip;
TimeMarker *marker;
TransformOrientation *ts;
+ SceneLayer *sl;
SceneRenderLayer *srl;
SceneRenderView *srv;
ToolSettings *tos;
@@ -2585,6 +2587,29 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
writestruct(wd, DATA, TransformOrientation, 1, ts);
}
+ /* writing scene layers to the blend file */
+ for (sl = sce->layers.first; sl; sl = sl->next) {
+ writestruct(wd, DATA, SceneLayer, 1, sl);
+
+ base = sl->base.first;
+ while (base) {
+ writestruct(wd, DATA, Base, 1, base);
+ base = base->next;
+ }
+
+ for (lc = sl->collections.first; lc; lc = lc->next) {
+ writestruct(wd, DATA, LayerCollection, 1, lc);
+
+ for (LinkData *link = lc->elements.first; link; link = link->next) {
+ writestruct(wd, DATA, LinkData, 1, link);
+ }
+
+ for (CollectionOverride *ov = lc->overrides.first; ov; ov = ov->next) {
+ writestruct(wd, DATA, CollectionOverride, 1, ov);
+ }
+ }
+ }
+
for (srl = sce->r.layers.first; srl; srl = srl->next) {
writestruct(wd, DATA, SceneRenderLayer, 1, srl);
for (fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {