1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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);
*/
}
}
}
|