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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
/*
* ***** 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): Dalai Felinto
*
* ***** END GPL LICENSE BLOCK *****
*
*/
/** \file blender/blenloader/intern/versioning_280.c
* \ingroup blenloader
*/
/* allow readfile to use deprecated functionality */
#define DNA_DEPRECATED_ALLOW
#include "DNA_object_types.h"
#include "DNA_camera_types.h"
#include "DNA_gpu_types.h"
#include "DNA_lamp_types.h"
#include "DNA_layer_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_view3d_types.h"
#include "DNA_genfile.h"
#include "BKE_collection.h"
#include "BKE_customdata.h"
#include "BKE_idprop.h"
#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_scene.h"
#include "BKE_workspace.h"
#include "BLI_listbase.h"
#include "BLI_mempool.h"
#include "BLI_string.h"
#include "BLO_readfile.h"
#include "readfile.h"
#include "MEM_guardedalloc.h"
static bScreen *screen_parent_find(const bScreen *screen)
{
/* can avoid lookup if screen state isn't maximized/full (parent and child store the same state) */
if (ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL)) {
for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
if (sa->full && sa->full != screen) {
BLI_assert(sa->full->state == screen->state);
return sa->full;
}
}
}
return NULL;
}
static void do_version_workspaces_create_from_screens(Main *bmain)
{
for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
const bScreen *screen_parent = screen_parent_find(screen);
WorkSpace *workspace;
SceneLayer *layer = BKE_scene_layer_render_active(screen->scene);
ListBase *transform_orientations;
if (screen_parent) {
/* fullscreen with "Back to Previous" option, don't create
* a new workspace, add layout workspace containing parent */
workspace = BLI_findstring(
&bmain->workspaces, screen_parent->id.name + 2, offsetof(ID, name) + 2);
}
else {
workspace = BKE_workspace_add(bmain, screen->id.name + 2);
}
BKE_workspace_layout_add(workspace, screen, screen->id.name + 2);
BKE_workspace_render_layer_set(workspace, layer);
transform_orientations = BKE_workspace_transform_orientations_get(workspace);
BLI_duplicatelist(transform_orientations, &screen->scene->transform_spaces);
}
}
/**
* \brief After lib-link versioning for new workspace design.
*
* * Adds a workspace for (almost) each screen of the old file
* and adds the needed workspace-layout to wrap the screen.
* * Active screen isn't stored directly in window anymore, but in the active workspace.
* * Active scene isn't stored in screen anymore, but in window.
* * Create workspace instance hook for each window.
*
* \note Some of the created workspaces might be deleted again in case of reading the default startup.blend.
*/
static void do_version_workspaces_after_lib_link(Main *bmain)
{
BLI_assert(BLI_listbase_is_empty(&bmain->workspaces));
do_version_workspaces_create_from_screens(bmain);
for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
for (wmWindow *win = wm->windows.first; win; win = win->next) {
bScreen *screen_parent = screen_parent_find(win->screen);
bScreen *screen = screen_parent ? screen_parent : win->screen;
WorkSpace *workspace = BLI_findstring(&bmain->workspaces, screen->id.name + 2, offsetof(ID, name) + 2);
ListBase *layouts = BKE_workspace_layouts_get(workspace);
win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
BKE_workspace_active_set(win->workspace_hook, workspace);
BKE_workspace_active_layout_set(win->workspace_hook, layouts->first);
win->scene = screen->scene;
/* Deprecated from now on! */
win->screen = NULL;
}
}
for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
/* Deprecated from now on! */
BLI_freelistN(&screen->scene->transform_spaces);
screen->scene = NULL;
}
}
void do_versions_after_linking_280(Main *main)
{
if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
/* since we don't have access to FileData we check the (always valid) first render layer instead */
if (scene->render_layers.first == NULL) {
SceneCollection *sc_master = BKE_collection_master(scene);
BLI_strncpy(sc_master->name, "Master Collection", sizeof(sc_master->name));
SceneCollection *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), "Collection %d", i + 1);
collections[i] = BKE_collection_add(scene, sc_master, 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);
}
}
}
scene->active_layer = 0;
if (!BKE_scene_uses_blender_game(scene)) {
for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
SceneLayer *sl = BKE_scene_layer_add(scene, srl->name);
BKE_scene_layer_engine_set(sl, scene->r.engine);
if (srl->mat_override) {
BKE_collection_override_datablock_add((LayerCollection *)sl->layer_collections.first, "material", (ID *)srl->mat_override);
}
if (srl->light_override && BKE_scene_uses_blender_internal(scene)) {
/* not sure how we handle this, pending until we design the override system */
TODO_LAYER_OVERRIDE;
}
if (srl->lay != scene->lay) {
/* unlink master collection */
BKE_collection_unlink(sl, sl->layer_collections.first);
/* add new collection bases */
for (int i = 0; i < 20; i++) {
if ((srl->lay & (1 << i)) != 0) {
BKE_collection_link(sl, collections[i]);
}
}
}
/* for convenience set the same active object in all the layers */
if (scene->basact) {
sl->basact = BKE_scene_layer_base_find(sl, scene->basact->object);
}
/* TODO: passes, samples, mask_layesr, exclude, ... */
}
if (BLI_findlink(&scene->render_layers, scene->r.actlay)) {
scene->active_layer = scene->r.actlay;
}
}
SceneLayer *sl = BKE_scene_layer_add(scene, "Viewport");
/* In this particular case we can safely assume the data struct */
LayerCollection *lc = ((LayerCollection *)sl->layer_collections.first)->layer_collections.first;
for (int i = 0; i < 20; i++) {
if (!is_visible[i]) {
lc->flag &= ~COLLECTION_VISIBLE;
}
lc = lc->next;
}
/* convert active base */
if (scene->basact) {
sl->basact = BKE_scene_layer_base_find(sl, scene->basact->object);
}
/* convert selected bases */
for (Base *base = scene->base.first; base; base = base->next) {
Base *ob_base = BKE_scene_layer_base_find(sl, base->object);
if ((base->flag & SELECT) != 0) {
if ((ob_base->flag & BASE_SELECTABLED) != 0) {
ob_base->flag |= BASE_SELECTED;
}
}
else {
ob_base->flag &= ~BASE_SELECTED;
}
/* keep lay around for forward compatibility (open those files in 2.79) */
ob_base->lay = base->lay;
}
/* TODO: copy scene render data to layer */
/* Cleanup */
for (int i = 0; i < 20; i++) {
if ((lay_used & (1 << i)) == 0) {
BKE_collection_remove(scene, collections[i]);
}
}
/* Fallback name if only one layer was found in the original file */
if (BLI_listbase_count_ex(&sc_master->scene_collections, 2) == 1) {
BKE_collection_rename(scene, sc_master->scene_collections.first, "Default Collection");
}
/* remove bases once and for all */
for (Base *base = scene->base.first; base; base = base->next) {
id_us_min(&base->object->id);
}
BLI_freelistN(&scene->base);
scene->basact = NULL;
}
}
}
if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
/* same render-layer as do_version_workspaces_after_lib_link will activate,
* so same layer as BKE_scene_layer_context_active would return */
SceneLayer *layer = screen->scene->render_layers.first;
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_OUTLINER) {
SpaceOops *soutliner = (SpaceOops *)sl;
soutliner->outlinevis = SO_ACT_LAYER;
if (BLI_listbase_count_ex(&layer->layer_collections, 2) == 1) {
if (soutliner->treestore == NULL) {
soutliner->treestore = BLI_mempool_create(
sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
}
/* Create a tree store element for the collection. This is normally
* done in check_persistent (outliner_tree.c), but we need to access
* it here :/ (expand element if it's the only one) */
TreeStoreElem *tselem = BLI_mempool_calloc(soutliner->treestore);
tselem->type = TSE_LAYER_COLLECTION;
tselem->id = layer->layer_collections.first;
tselem->nr = tselem->used = 0;
tselem->flag &= ~TSE_CLOSED;
}
}
}
}
}
}
/* New workspace design */
if (!MAIN_VERSION_ATLEAST(main, 280, 1)) {
do_version_workspaces_after_lib_link(main);
}
}
static void do_version_layer_collections_idproperties(ListBase *lb)
{
IDPropertyTemplate val = {0};
for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
lc->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
BKE_layer_collection_engine_settings_create(lc->properties);
/* No overrides at first */
for (IDProperty *prop = lc->properties->data.group.first; prop; prop = prop->next) {
while (prop->data.group.first) {
IDP_FreeFromGroup(prop, prop->data.group.first);
}
}
/* Do it recursively */
do_version_layer_collections_idproperties(&lc->layer_collections);
}
}
void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
{
if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
if (!DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "render_layers")) {
for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
/* Master Collection */
scene->collection = MEM_callocN(sizeof(SceneCollection), "Master Collection");
BLI_strncpy(scene->collection->name, "Master Collection", sizeof(scene->collection->name));
}
}
if (DNA_struct_elem_find(fd->filesdna, "LayerCollection", "ListBase", "engine_settings") &&
!DNA_struct_elem_find(fd->filesdna, "LayerCollection", "IDProperty", "properties"))
{
for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) {
do_version_layer_collections_idproperties(&sl->layer_collections);
}
}
}
}
if (!MAIN_VERSION_ATLEAST(main, 280, 1)) {
if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "bleedexp")) {
for (Lamp *la = main->lamp.first; la; la = la->id.next) {
la->bleedexp = 120.0f;
}
}
if (!DNA_struct_elem_find(fd->filesdna, "GPUDOFSettings", "float", "ratio")) {
for (Camera *ca = main->camera.first; ca; ca = ca->id.next) {
ca->gpu_dof.ratio = 1.0f;
}
}
if (!DNA_struct_elem_find(fd->filesdna, "SceneLayer", "IDProperty", "*properties")) {
for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) {
IDPropertyTemplate val = {0};
sl->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
BKE_scene_layer_engine_settings_create(sl->properties);
}
}
}
/* MTexPoly now removed. */
if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
const int cd_mtexpoly = 15; /* CD_MTEXPOLY, deprecated */
for (Mesh *me = main->mesh.first; me; me = me->id.next) {
/* If we have UV's, so this file will have MTexPoly layers too! */
if (me->mloopuv != NULL) {
CustomData_update_typemap(&me->pdata);
CustomData_free_layers(&me->pdata, cd_mtexpoly, me->totpoly);
BKE_mesh_update_customdata_pointers(me, false);
}
}
}
if (!DNA_struct_elem_find(fd->filesdna, "View3D", "short", "custom_orientation_index")) {
for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
for (ScrArea *area = screen->areabase.first; area; area = area->next) {
for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
if (v3d->twmode >= V3D_MANIP_CUSTOM) {
v3d->custom_orientation_index = v3d->twmode - V3D_MANIP_CUSTOM;
v3d->twmode = V3D_MANIP_CUSTOM;
}
else {
v3d->custom_orientation_index = -1;
}
}
}
}
}
}
}
}
|