Merge branch 'master' into blender2.8
[blender.git] / source / blender / blenloader / intern / versioning_280.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Dalai Felinto
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  *
22  */
23
24 /** \file blender/blenloader/intern/versioning_280.c
25  *  \ingroup blenloader
26  */
27
28 /* allow readfile to use deprecated functionality */
29 #define DNA_DEPRECATED_ALLOW
30
31 #include <string.h>
32 #include <float.h>
33
34 #include "BLI_listbase.h"
35 #include "BLI_math.h"
36 #include "BLI_mempool.h"
37 #include "BLI_string.h"
38 #include "BLI_string_utf8.h"
39 #include "BLI_utildefines.h"
40
41 #include "DNA_object_types.h"
42 #include "DNA_camera_types.h"
43 #include "DNA_constraint_types.h"
44 #include "DNA_gpu_types.h"
45 #include "DNA_group_types.h"
46 #include "DNA_lamp_types.h"
47 #include "DNA_layer_types.h"
48 #include "DNA_lightprobe_types.h"
49 #include "DNA_material_types.h"
50 #include "DNA_mesh_types.h"
51 #include "DNA_particle_types.h"
52 #include "DNA_scene_types.h"
53 #include "DNA_screen_types.h"
54 #include "DNA_view3d_types.h"
55 #include "DNA_genfile.h"
56 #include "DNA_workspace_types.h"
57
58 #include "BKE_collection.h"
59 #include "BKE_constraint.h"
60 #include "BKE_customdata.h"
61 #include "BKE_freestyle.h"
62 #include "BKE_idprop.h"
63 #include "BKE_image.h"
64 #include "BKE_layer.h"
65 #include "BKE_main.h"
66 #include "BKE_mesh.h"
67 #include "BKE_node.h"
68 #include "BKE_report.h"
69 #include "BKE_scene.h"
70 #include "BKE_screen.h"
71 #include "BKE_studiolight.h"
72 #include "BKE_workspace.h"
73
74 #include "BLO_readfile.h"
75 #include "readfile.h"
76
77 #include "MEM_guardedalloc.h"
78
79 static bScreen *screen_parent_find(const bScreen *screen)
80 {
81         /* can avoid lookup if screen state isn't maximized/full (parent and child store the same state) */
82         if (ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL)) {
83                 for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
84                         if (sa->full && sa->full != screen) {
85                                 BLI_assert(sa->full->state == screen->state);
86                                 return sa->full;
87                         }
88                 }
89         }
90
91         return NULL;
92 }
93
94 static void do_version_workspaces_create_from_screens(Main *bmain)
95 {
96         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
97                 const bScreen *screen_parent = screen_parent_find(screen);
98                 Scene *scene = screen->scene;
99                 WorkSpace *workspace;
100                 ViewLayer *layer = BLI_findlink(&scene->view_layers, scene->r.actlay);
101                 if (screen->temp) {
102                         continue;
103                 }
104                 if (!layer) {
105                         layer = BKE_view_layer_default_view(scene);
106                 }
107
108                 if (screen_parent) {
109                         /* fullscreen with "Back to Previous" option, don't create
110                          * a new workspace, add layout workspace containing parent */
111                         workspace = BLI_findstring(
112                                 &bmain->workspaces, screen_parent->id.name + 2, offsetof(ID, name) + 2);
113                 }
114                 else {
115                         workspace = BKE_workspace_add(bmain, screen->id.name + 2);
116                 }
117                 BKE_workspace_layout_add(workspace, screen, screen->id.name + 2);
118                 BKE_workspace_view_layer_set(workspace, layer, scene);
119         }
120 }
121
122 static void do_version_area_change_space_to_space_action(ScrArea *area, const Scene *scene)
123 {
124         SpaceType *stype = BKE_spacetype_from_id(SPACE_ACTION);
125         SpaceAction *saction = (SpaceAction *)stype->new(area, scene);
126         ARegion *region_channels;
127
128         /* Properly free current regions */
129         for (ARegion *region = area->regionbase.first; region; region = region->next) {
130                 BKE_area_region_free(area->type, region);
131         }
132         BLI_freelistN(&area->regionbase);
133
134         area->type = stype;
135         area->spacetype = stype->spaceid;
136
137         BLI_addhead(&area->spacedata, saction);
138         area->regionbase = saction->regionbase;
139         BLI_listbase_clear(&saction->regionbase);
140
141         /* Different defaults for timeline */
142         region_channels = BKE_area_find_region_type(area, RGN_TYPE_CHANNELS);
143         region_channels->flag |= RGN_FLAG_HIDDEN;
144
145         saction->mode = SACTCONT_TIMELINE;
146         saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED;
147 }
148
149 /**
150  * \brief After lib-link versioning for new workspace design.
151  *
152  * - Adds a workspace for (almost) each screen of the old file
153  *   and adds the needed workspace-layout to wrap the screen.
154  * - Active screen isn't stored directly in window anymore, but in the active workspace.
155  * - Active scene isn't stored in screen anymore, but in window.
156  * - Create workspace instance hook for each window.
157  *
158  * \note Some of the created workspaces might be deleted again in case of reading the default startup.blend.
159  */
160 static void do_version_workspaces_after_lib_link(Main *bmain)
161 {
162         BLI_assert(BLI_listbase_is_empty(&bmain->workspaces));
163
164         do_version_workspaces_create_from_screens(bmain);
165
166         for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
167                 for (wmWindow *win = wm->windows.first; win; win = win->next) {
168                         bScreen *screen_parent = screen_parent_find(win->screen);
169                         bScreen *screen = screen_parent ? screen_parent : win->screen;
170                         WorkSpace *workspace = BLI_findstring(&bmain->workspaces, screen->id.name + 2, offsetof(ID, name) + 2);
171                         ListBase *layouts = BKE_workspace_layouts_get(workspace);
172
173                         win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
174
175                         BKE_workspace_active_set(win->workspace_hook, workspace);
176                         BKE_workspace_active_layout_set(win->workspace_hook, layouts->first);
177
178                         win->scene = screen->scene;
179                         /* Deprecated from now on! */
180                         win->screen = NULL;
181                 }
182         }
183
184         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
185                 /* Deprecated from now on! */
186                 BLI_freelistN(&screen->scene->transform_spaces);
187                 screen->scene = NULL;
188         }
189 }
190
191 #ifdef USE_COLLECTION_COMPAT_28
192 enum {
193         COLLECTION_DEPRECATED_VISIBLE    = (1 << 0),
194         COLLECTION_DEPRECATED_VIEWPORT   = (1 << 0),
195         COLLECTION_DEPRECATED_SELECTABLE = (1 << 1),
196         COLLECTION_DEPRECATED_DISABLED   = (1 << 2),
197         COLLECTION_DEPRECATED_RENDER     = (1 << 3),
198 };
199
200 static void do_version_view_layer_visibility(ViewLayer *view_layer)
201 {
202         /* Convert from deprecated VISIBLE flag to DISABLED */
203         LayerCollection *lc;
204         for (lc = view_layer->layer_collections.first;
205              lc;
206              lc = lc->next)
207         {
208                 if (lc->flag & COLLECTION_DEPRECATED_DISABLED) {
209                         lc->flag &= ~COLLECTION_DEPRECATED_DISABLED;
210                 }
211
212                 if ((lc->flag & COLLECTION_DEPRECATED_VISIBLE) == 0) {
213                         lc->flag |= COLLECTION_DEPRECATED_DISABLED;
214                 }
215
216                 lc->flag |= COLLECTION_DEPRECATED_VIEWPORT | COLLECTION_DEPRECATED_RENDER;
217         }
218 }
219
220 static void do_version_layer_collection_pre(
221         ViewLayer *view_layer,
222         ListBase *lb,
223         GSet *enabled_set,
224         GSet *selectable_set)
225 {
226         /* Convert from deprecated DISABLED to new layer collection and collection flags */
227         for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
228                 if (lc->scene_collection) {
229                         if (!(lc->flag & COLLECTION_DEPRECATED_DISABLED)) {
230                                 BLI_gset_insert(enabled_set, lc->scene_collection);
231                         }
232                         if (lc->flag & COLLECTION_DEPRECATED_SELECTABLE) {
233                                 BLI_gset_insert(selectable_set, lc->scene_collection);
234                         }
235                 }
236
237                 do_version_layer_collection_pre(view_layer, &lc->layer_collections, enabled_set, selectable_set);
238         }
239 }
240
241 static void do_version_layer_collection_post(
242         ViewLayer *view_layer,
243         ListBase *lb,
244         GSet *enabled_set,
245         GSet *selectable_set,
246         GHash *collection_map)
247 {
248         /* Apply layer collection exclude flags. */
249         for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
250                 if (!(lc->collection->flag & COLLECTION_IS_MASTER)) {
251                         SceneCollection *sc = BLI_ghash_lookup(collection_map, lc->collection);
252                         const bool enabled = (sc && BLI_gset_haskey(enabled_set, sc));
253                         const bool selectable = (sc && BLI_gset_haskey(selectable_set, sc));
254
255                         if (!enabled) {
256                                 lc->flag |= LAYER_COLLECTION_EXCLUDE;
257                         }
258                         if (enabled && !selectable) {
259                                 lc->collection->flag |= COLLECTION_RESTRICT_SELECT;
260                         }
261                 }
262
263                 do_version_layer_collection_post(
264                         view_layer, &lc->layer_collections, enabled_set, selectable_set, collection_map);
265         }
266 }
267
268 static void do_version_scene_collection_convert(
269         Main *bmain,
270         ID *id,
271         SceneCollection *sc,
272         Collection *collection,
273         GHash *collection_map)
274 {
275         if (collection_map) {
276                 BLI_ghash_insert(collection_map, collection, sc);
277         }
278
279         for (SceneCollection *nsc = sc->scene_collections.first; nsc;) {
280                 SceneCollection *nsc_next = nsc->next;
281                 Collection *ncollection = BKE_collection_add(bmain, collection, nsc->name);
282                 ncollection->id.lib = id->lib;
283                 do_version_scene_collection_convert(bmain, id, nsc, ncollection, collection_map);
284                 nsc = nsc_next;
285         }
286
287         for (LinkData *link = sc->objects.first; link; link = link->next) {
288                 Object *ob = link->data;
289                 if (ob) {
290                         BKE_collection_object_add(bmain, collection, ob);
291                         id_us_min(&ob->id);
292                 }
293         }
294
295         BLI_freelistN(&sc->objects);
296         MEM_freeN(sc);
297 }
298
299 static void do_version_group_collection_to_collection(Main *bmain, Collection *group)
300 {
301         /* Convert old 2.8 group collections to new unified collections. */
302         if (group->collection) {
303                 do_version_scene_collection_convert(bmain, &group->id, group->collection, group, NULL);
304         }
305
306         group->collection = NULL;
307         group->view_layer = NULL;
308         id_fake_user_set(&group->id);
309 }
310
311 static void do_version_scene_collection_to_collection(Main *bmain, Scene *scene)
312 {
313         /* Convert old 2.8 scene collections to new unified collections. */
314
315         /* Temporarily clear view layers so we don't do any layer collection syncing
316          * and destroy old flags that we want to restore. */
317         ListBase view_layers = scene->view_layers;
318         BLI_listbase_clear(&scene->view_layers);
319
320         if (!scene->master_collection) {
321                 scene->master_collection = BKE_collection_master_add();
322         }
323
324         /* Convert scene collections. */
325         GHash *collection_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
326         if (scene->collection) {
327                 do_version_scene_collection_convert(bmain, &scene->id, scene->collection, scene->master_collection, collection_map);
328                 scene->collection = NULL;
329         }
330
331         scene->view_layers = view_layers;
332
333         /* Convert layer collections. */
334         ViewLayer *view_layer;
335         for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
336                 GSet *enabled_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
337                 GSet *selectable_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
338
339                 do_version_layer_collection_pre(
340                         view_layer, &view_layer->layer_collections, enabled_set, selectable_set);
341
342                 BKE_layer_collection_sync(scene, view_layer);
343
344                 do_version_layer_collection_post(
345                         view_layer, &view_layer->layer_collections, enabled_set, selectable_set, collection_map);
346
347                 BLI_gset_free(enabled_set, NULL);
348                 BLI_gset_free(selectable_set, NULL);
349
350                 BKE_layer_collection_sync(scene, view_layer);
351         }
352
353         BLI_ghash_free(collection_map, NULL, NULL);
354 }
355 #endif
356
357
358 enum {
359         DO_VERSION_COLLECTION_VISIBLE     = 0,
360         DO_VERSION_COLLECTION_HIDE        = 1,
361         DO_VERSION_COLLECTION_HIDE_RENDER = 2,
362         DO_VERSION_COLLECTION_HIDE_ALL    = 3,
363 };
364
365 static void do_version_layers_to_collections(Main *bmain, Scene *scene)
366 {
367         /* Since we don't have access to FileData we check the (always valid) first
368          * render layer instead. */
369         if (!scene->master_collection) {
370                 scene->master_collection = BKE_collection_master_add();
371         }
372
373         if (scene->view_layers.first) {
374                 return;
375         }
376
377         /* Create collections from layers. */
378         Collection *collection_master = BKE_collection_master(scene);
379
380         struct DoVersionSceneCollections {
381                 Collection *collections[20];
382                 int created;
383                 const char *suffix;
384                 int flag;
385         } collections[] =
386         {
387                 {
388                         .collections = {NULL},
389                         .created = 0,
390                         .suffix = "",
391                         .flag = 0,
392                 },
393                 {
394                         .collections = {NULL},
395                         .created = 0,
396                         .suffix = " - Hide Viewport",
397                         .flag = COLLECTION_RESTRICT_VIEW,
398                 },
399                 {
400                         .collections = {NULL},
401                         .created = 0,
402                         .suffix = " - Hide Render",
403                         .flag = COLLECTION_RESTRICT_RENDER,
404                 },
405                 {
406                         .collections = {NULL},
407                         .created = 0,
408                         .suffix = " - Hide Render All",
409                         .flag = COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER,
410                 }
411         };
412
413         for (int layer = 0; layer < 20; layer++) {
414                 for (Base *base = scene->base.first; base; base = base->next) {
415                         if (base->lay & (1 << layer)) {
416                                 int collection_index = -1;
417                                 if ((base->object->restrictflag & OB_RESTRICT_VIEW) &&
418                                     (base->object->restrictflag & OB_RESTRICT_RENDER))
419                                 {
420                                         collection_index = DO_VERSION_COLLECTION_HIDE_ALL;
421                                 }
422                                 else if (base->object->restrictflag & OB_RESTRICT_VIEW) {
423                                         collection_index = DO_VERSION_COLLECTION_HIDE;
424                                 }
425                                 else if (base->object->restrictflag & OB_RESTRICT_RENDER) {
426                                         collection_index = DO_VERSION_COLLECTION_HIDE_RENDER;
427                                 }
428                                 else {
429                                         collection_index = DO_VERSION_COLLECTION_VISIBLE;
430                                 }
431
432                                 /* Create collections when needed only. */
433                                 if ((collections[collection_index].created & (1 << layer)) == 0) {
434                                         char name[MAX_NAME];
435
436                                         if ((collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) == 0) {
437                                                 BLI_snprintf(name,
438                                                              sizeof(collection_master->id.name),
439                                                              "Collection %d%s",
440                                                              layer + 1,
441                                                              collections[DO_VERSION_COLLECTION_VISIBLE].suffix);
442
443                                                 Collection *collection = BKE_collection_add(bmain, collection_master, name);
444                                                 collection->id.lib = scene->id.lib;
445                                                 collection->flag |= collections[DO_VERSION_COLLECTION_VISIBLE].flag;
446                                                 collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer] = collection;
447                                                 collections[DO_VERSION_COLLECTION_VISIBLE].created |= (1 << layer);
448
449                                                 if (!(scene->lay & (1 << layer))) {
450                                                         collection->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
451                                                 }
452                                         }
453
454                                         if (collection_index != DO_VERSION_COLLECTION_VISIBLE) {
455                                                 Collection *collection_parent;
456                                                 collection_parent = collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer];
457                                                 BLI_snprintf(name,
458                                                              sizeof(collection_master->id.name),
459                                                              "Collection %d%s",
460                                                              layer + 1,
461                                                              collections[collection_index].suffix);
462
463                                                 Collection *collection = BKE_collection_add(bmain, collection_parent, name);
464                                                 collection->id.lib = scene->id.lib;
465                                                 collection->flag |= collections[collection_index].flag;
466                                                 collections[collection_index].collections[layer] = collection;
467                                                 collections[collection_index].created |= (1 << layer);
468
469                                                 if (!(scene->lay & (1 << layer))) {
470                                                         collection->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
471                                                 }
472                                         }
473                                 }
474
475                                 /* Note usually this would do slow collection syncing for view layers,
476                                  * but since no view layers exists yet at this point it's fast. */
477                                 BKE_collection_object_add(
478                                         bmain,
479                                         collections[collection_index].collections[layer], base->object);
480                         }
481
482                         if (base->flag & SELECT) {
483                                 base->object->flag |= SELECT;
484                         }
485                         else {
486                                 base->object->flag &= ~SELECT;
487                         }
488                 }
489         }
490
491         /* Re-order the nested hidden collections. */
492         CollectionChild *child_parent = collection_master->children.first;
493         Collection *collection_parent = (child_parent) ? child_parent->collection : NULL;
494
495         for (int layer = 0; layer < 20; layer++) {
496                 if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
497                         CollectionChild *hide_child = BLI_findptr(
498                                 &collection_parent->children,
499                                 collections[DO_VERSION_COLLECTION_HIDE].collections[layer],
500                                 offsetof(CollectionChild, collection));
501
502                         if ((collections[DO_VERSION_COLLECTION_HIDE].created & (1 << layer)) &&
503                             (hide_child != collection_parent->children.first))
504                         {
505                                 BLI_listbase_swaplinks(
506                                         &collection_parent->children,
507                                         hide_child,
508                                         collection_parent->children.first);
509                         }
510
511                         CollectionChild *hide_all_child = BLI_findptr(
512                                 &collection_parent->children,
513                                 collections[DO_VERSION_COLLECTION_HIDE_ALL].collections[layer],
514                                 offsetof(CollectionChild, collection));
515
516                         if ((collections[DO_VERSION_COLLECTION_HIDE_ALL].created & (1 << layer)) &&
517                             (hide_all_child != collection_parent->children.last))
518                         {
519                                 BLI_listbase_swaplinks(
520                                         &collection_parent->children,
521                                         hide_all_child,
522                                         collection_parent->children.last);
523                         }
524
525                         child_parent = child_parent->next;
526                         collection_parent = (child_parent) ? child_parent->collection : NULL;
527                 }
528         }
529         BLI_assert(collection_parent == NULL);
530
531         /* Handle legacy render layers. */
532         bool have_override = false;
533
534         for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
535                 ViewLayer *view_layer = BKE_view_layer_add(scene, srl->name);
536
537                 if (srl->samples != 0) {
538                         have_override = true;
539
540                         /* It is up to the external engine to handle
541                          * its own doversion in this case. */
542                         BKE_override_view_layer_int_add(
543                                 view_layer,
544                                 ID_SCE,
545                                 "samples",
546                                 srl->samples);
547                 }
548
549                 if (srl->mat_override) {
550                         have_override = true;
551
552                         BKE_override_view_layer_datablock_add(
553                                 view_layer,
554                                 ID_MA,
555                                 "self",
556                                 (ID *)srl->mat_override);
557                 }
558
559                 if (srl->layflag & SCE_LAY_DISABLE) {
560                         view_layer->flag &= ~VIEW_LAYER_RENDER;
561                 }
562
563                 if ((srl->layflag & SCE_LAY_FRS) == 0) {
564                         view_layer->flag &= ~VIEW_LAYER_FREESTYLE;
565                 }
566
567                 /* XXX If we are to keep layflag it should be merged with flag (dfelinto). */
568                 view_layer->layflag = srl->layflag;
569                 /* XXX Not sure if we should keep the passes (dfelinto). */
570                 view_layer->passflag = srl->passflag;
571                 view_layer->pass_xor = srl->pass_xor;
572                 view_layer->pass_alpha_threshold = srl->pass_alpha_threshold;
573
574                 BKE_freestyle_config_free(&view_layer->freestyle_config, true);
575                 view_layer->freestyle_config = srl->freestyleConfig;
576                 view_layer->id_properties = srl->prop;
577
578                 /* Set exclusion and overrides. */
579                 for (int layer = 0; layer < 20; layer++) {
580                         if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
581                                 Collection *collection = collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer];
582                                 LayerCollection *lc = BKE_layer_collection_first_from_scene_collection(view_layer, collection);
583
584                                 if (srl->lay_exclude & (1 << layer)) {
585                                         /* Disable excluded layer. */
586                                         have_override = true;
587                                         lc->flag |= LAYER_COLLECTION_EXCLUDE;
588                                         for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) {
589                                                 nlc->flag |= LAYER_COLLECTION_EXCLUDE;
590                                         }
591                                 }
592                                 else if ((scene->lay & srl->lay & ~(srl->lay_exclude) & (1 << layer)) ||
593                                          (srl->lay_zmask & (scene->lay | srl->lay_exclude) & (1 << layer)))
594                                 {
595                                         if (srl->lay_zmask & (1 << layer)) {
596                                                 have_override = true;
597
598                                                 BKE_override_layer_collection_boolean_add(
599                                                         lc,
600                                                         ID_OB,
601                                                         "cycles.is_holdout",
602                                                         true);
603                                         }
604
605                                         if ((srl->lay & (1 << layer)) == 0) {
606                                                 have_override = true;
607
608                                                 BKE_override_layer_collection_boolean_add(
609                                                         lc,
610                                                         ID_OB,
611                                                         "cycles_visibility.camera",
612                                                         false);
613                                         }
614                                 }
615
616                                 LayerCollection *nlc = lc->layer_collections.first;
617                                 for (int j = 1; j < 4; j++) {
618                                         if (collections[j].created & (1 << layer)) {
619                                                 nlc = nlc->next;
620                                         }
621                                 }
622                                 BLI_assert(nlc == NULL);
623                         }
624                 }
625
626                 /* for convenience set the same active object in all the layers */
627                 if (scene->basact) {
628                         view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
629                 }
630
631                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
632                         if ((base->flag & BASE_SELECTABLED) && (base->object->flag & SELECT)) {
633                                 base->flag |= BASE_SELECTED;
634                         }
635                 }
636         }
637
638         BLI_freelistN(&scene->r.layers);
639
640         /* If render layers included overrides, we also create a vanilla
641          * viewport layer without them. */
642         if (have_override) {
643                 ViewLayer *view_layer = BKE_view_layer_add(scene, "Viewport");
644
645                 /* Make it first in the list. */
646                 BLI_remlink(&scene->view_layers, view_layer);
647                 BLI_addhead(&scene->view_layers, view_layer);
648
649                 /* If we ported all the original render layers, we don't need to make the viewport layer renderable. */
650                 if (!BLI_listbase_is_single(&scene->view_layers)) {
651                         view_layer->flag &= ~VIEW_LAYER_RENDER;
652                 }
653
654                 /* convert active base */
655                 if (scene->basact) {
656                         view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
657                 }
658
659                 /* convert selected bases */
660                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
661                         if ((base->flag & BASE_SELECTABLED) && (base->object->flag & SELECT)) {
662                                 base->flag |= BASE_SELECTED;
663                         }
664
665                         /* keep lay around for forward compatibility (open those files in 2.79) */
666                         base->lay = base->object->lay;
667                 }
668         }
669
670         /* remove bases once and for all */
671         for (Base *base = scene->base.first; base; base = base->next) {
672                 id_us_min(&base->object->id);
673         }
674
675         BLI_freelistN(&scene->base);
676         scene->basact = NULL;
677 }
678
679 void do_versions_after_linking_280(Main *bmain)
680 {
681         bool use_collection_compat_28 = true;
682
683         if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
684                 use_collection_compat_28 = false;
685
686                 /* Convert group layer visibility flags to hidden nested collection. */
687                 for (Collection *collection = bmain->collection.first; collection; collection = collection->id.next) {
688                         /* Add fake user for all existing groups. */
689                         id_fake_user_set(&collection->id);
690
691                         if (collection->flag & (COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER)) {
692                                 continue;
693                         }
694
695                         Collection *collection_hidden = NULL;
696                         for (CollectionObject *cob = collection->gobject.first, *cob_next = NULL; cob; cob = cob_next) {
697                                 cob_next = cob->next;
698                                 Object *ob = cob->ob;
699
700                                 if (!(ob->lay & collection->layer)) {
701                                         if (collection_hidden == NULL) {
702                                                 collection_hidden = BKE_collection_add(bmain, collection, "Hidden");
703                                                 collection_hidden->id.lib = collection->id.lib;
704                                                 collection_hidden->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
705                                         }
706
707                                         BKE_collection_object_add(bmain, collection_hidden, ob);
708                                         BKE_collection_object_remove(bmain, collection, ob, true);
709                                 }
710                         }
711                 }
712
713                 /* Convert layers to collections. */
714                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
715                         do_version_layers_to_collections(bmain, scene);
716                 }
717         }
718
719         if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
720                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
721                         /* same render-layer as do_version_workspaces_after_lib_link will activate,
722                          * so same layer as BKE_view_layer_from_workspace_get would return */
723                         ViewLayer *layer = screen->scene->view_layers.first;
724
725                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
726                                 for (SpaceLink *space = sa->spacedata.first; space; space = space->next) {
727                                         if (space->spacetype == SPACE_OUTLINER) {
728                                                 SpaceOops *soutliner = (SpaceOops *)space;
729
730                                                 soutliner->outlinevis = SO_VIEW_LAYER;
731
732                                                 if (BLI_listbase_count_at_most(&layer->layer_collections, 2) == 1) {
733                                                         if (soutliner->treestore == NULL) {
734                                                                 soutliner->treestore = BLI_mempool_create(
735                                                                         sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
736                                                         }
737
738                                                         /* Create a tree store element for the collection. This is normally
739                                                          * done in check_persistent (outliner_tree.c), but we need to access
740                                                          * it here :/ (expand element if it's the only one) */
741                                                         TreeStoreElem *tselem = BLI_mempool_calloc(soutliner->treestore);
742                                                         tselem->type = TSE_LAYER_COLLECTION;
743                                                         tselem->id = layer->layer_collections.first;
744                                                         tselem->nr = tselem->used = 0;
745                                                         tselem->flag &= ~TSE_CLOSED;
746                                                 }
747                                         }
748                                 }
749                         }
750                 }
751         }
752
753         /* New workspace design */
754         if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
755                 do_version_workspaces_after_lib_link(bmain);
756         }
757
758         if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) {
759                 /* Cleanup any remaining SceneRenderLayer data for files that were created
760                  * with Blender 2.8 before the SceneRenderLayer > RenderLayer refactor. */
761                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
762                         for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
763                                 if (srl->prop) {
764                                         IDP_FreeProperty(srl->prop);
765                                         MEM_freeN(srl->prop);
766                                 }
767                                 BKE_freestyle_config_free(&srl->freestyleConfig, true);
768                         }
769                         BLI_freelistN(&scene->r.layers);
770                 }
771         }
772
773         if (!MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
774                 /* Due to several changes to particle RNA and draw code particles from older files may no longer
775                  * be visible. Here we correct this by setting a default draw size for those files. */
776                 for (Object *object = bmain->object.first; object; object = object->id.next) {
777                         for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
778                                 if (psys->part->draw_size == 0.0f) {
779                                         psys->part->draw_size = 0.1f;
780                                 }
781                         }
782                 }
783         }
784
785         if (!MAIN_VERSION_ATLEAST(bmain, 280, 4)) {
786                 for (Object *object = bmain->object.first; object; object = object->id.next) {
787 #ifndef VERSION_280_SUBVERSION_4
788                         /* If any object already has an initialized value for
789                          * duplicator_visibility_flag it means we've already doversioned it.
790                          * TODO(all) remove the VERSION_280_SUBVERSION_4 code once the subversion was bumped. */
791                         if (object->duplicator_visibility_flag != 0) {
792                                 break;
793                         }
794 #endif
795                         if (object->particlesystem.first) {
796                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
797                                 for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
798                                         if (psys->part->draw & PART_DRAW_EMITTER) {
799                                                 object->duplicator_visibility_flag |= OB_DUPLI_FLAG_RENDER;
800 #ifndef VERSION_280_SUBVERSION_4
801                                                 psys->part->draw &= ~PART_DRAW_EMITTER;
802 #else
803                                                 break;
804 #endif
805                                         }
806                                 }
807                         }
808                         else if (object->transflag & OB_DUPLI) {
809                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
810                         }
811                         else {
812                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER;
813                         }
814                 }
815         }
816
817         /* SpaceTime & SpaceLogic removal/replacing */
818         if (!MAIN_VERSION_ATLEAST(bmain, 280, 9)) {
819                 const wmWindowManager *wm = bmain->wm.first;
820                 const Scene *scene = bmain->scene.first;
821
822                 if (wm != NULL) {
823                         /* Action editors need a scene for creation. First, update active
824                          * screens using the active scene of the window they're displayed in.
825                          * Next, update remaining screens using first scene in main listbase. */
826
827                         for (wmWindow *win = wm->windows.first; win; win = win->next) {
828                                 const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
829                                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
830                                         if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
831                                                 do_version_area_change_space_to_space_action(area, win->scene);
832
833                                                 /* Don't forget to unset! */
834                                                 area->butspacetype = SPACE_EMPTY;
835                                         }
836                                 }
837                         }
838                 }
839                 if (scene != NULL) {
840                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
841                                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
842                                         if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
843                                                 /* Areas that were already handled won't be handled again */
844                                                 do_version_area_change_space_to_space_action(area, scene);
845
846                                                 /* Don't forget to unset! */
847                                                 area->butspacetype = SPACE_EMPTY;
848                                         }
849                                 }
850                         }
851                 }
852         }
853
854 #ifdef USE_COLLECTION_COMPAT_28
855         if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 14)) {
856                 for (Collection *group = bmain->collection.first; group; group = group->id.next) {
857                         do_version_group_collection_to_collection(bmain, group);
858                 }
859
860                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
861                         do_version_scene_collection_to_collection(bmain, scene);
862                 }
863         }
864 #endif
865 }
866
867 void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
868 {
869         bool use_collection_compat_28 = true;
870
871         if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
872                 use_collection_compat_28 = false;
873
874                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
875                         scene->r.gauss = 1.5f;
876                 }
877         }
878
879         if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
880                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "bleedexp")) {
881                         for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
882                                 la->bleedexp = 2.5f;
883                         }
884                 }
885
886                 if (!DNA_struct_elem_find(fd->filesdna, "GPUDOFSettings", "float", "ratio")) {
887                         for (Camera *ca = bmain->camera.first; ca; ca = ca->id.next) {
888                                 ca->gpu_dof.ratio = 1.0f;
889                         }
890                 }
891
892                 /* MTexPoly now removed. */
893                 if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
894                         const int cd_mtexpoly = 15;  /* CD_MTEXPOLY, deprecated */
895                         for (Mesh *me = bmain->mesh.first; me; me = me->id.next) {
896                                 /* If we have UV's, so this file will have MTexPoly layers too! */
897                                 if (me->mloopuv != NULL) {
898                                         CustomData_update_typemap(&me->pdata);
899                                         CustomData_free_layers(&me->pdata, cd_mtexpoly, me->totpoly);
900                                         BKE_mesh_update_customdata_pointers(me, false);
901                                 }
902                         }
903                 }
904         }
905
906         if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) {
907                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "cascade_max_dist")) {
908                         for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
909                                 la->cascade_max_dist = 1000.0f;
910                                 la->cascade_count = 4;
911                                 la->cascade_exponent = 0.8f;
912                                 la->cascade_fade = 0.1f;
913                         }
914                 }
915
916                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "contact_dist")) {
917                         for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
918                                 la->contact_dist = 1.0f;
919                                 la->contact_bias = 0.03f;
920                                 la->contact_spread = 0.2f;
921                                 la->contact_thickness = 0.5f;
922                         }
923                 }
924
925                 if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "vis_bias")) {
926                         for (LightProbe *probe = bmain->lightprobe.first; probe; probe = probe->id.next) {
927                                 probe->vis_bias = 1.0f;
928                                 probe->vis_blur = 0.2f;
929                         }
930                 }
931
932                 typedef enum eNTreeDoVersionErrors {
933                         NTREE_DOVERSION_NO_ERROR = 0,
934                         NTREE_DOVERSION_NEED_OUTPUT = (1 << 0),
935                         NTREE_DOVERSION_TRANSPARENCY_EMISSION = (1 << 1),
936                 } eNTreeDoVersionErrors;
937
938                 /* Eevee shader nodes renamed because of the output node system.
939                  * Note that a new output node is not being added here, because it would be overkill
940                  * to handle this case in lib_verify_nodetree.
941                  *
942                  * Also, metallic node is now unified into the principled node. */
943                 eNTreeDoVersionErrors error = NTREE_DOVERSION_NO_ERROR;
944
945                 FOREACH_NODETREE(bmain, ntree, id) {
946                         if (ntree->type == NTREE_SHADER) {
947                                 for (bNode *node = ntree->nodes.first; node; node = node->next) {
948                                         if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
949                                             STREQ(node->idname, "ShaderNodeOutputMetallic"))
950                                         {
951                                                 BLI_strncpy(node->idname, "ShaderNodeEeveeMetallic", sizeof(node->idname));
952                                                 error |= NTREE_DOVERSION_NEED_OUTPUT;
953                                         }
954
955                                         else if (node->type == SH_NODE_EEVEE_SPECULAR && STREQ(node->idname, "ShaderNodeOutputSpecular")) {
956                                                 BLI_strncpy(node->idname, "ShaderNodeEeveeSpecular", sizeof(node->idname));
957                                                 error |= NTREE_DOVERSION_NEED_OUTPUT;
958                                         }
959
960                                         else if (node->type == 196 /* SH_NODE_OUTPUT_EEVEE_MATERIAL */ &&
961                                                  STREQ(node->idname, "ShaderNodeOutputEeveeMaterial"))
962                                         {
963                                                 node->type = SH_NODE_OUTPUT_MATERIAL;
964                                                 BLI_strncpy(node->idname, "ShaderNodeOutputMaterial", sizeof(node->idname));
965                                         }
966
967                                         else if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
968                                                  STREQ(node->idname, "ShaderNodeEeveeMetallic"))
969                                         {
970                                                 node->type = SH_NODE_BSDF_PRINCIPLED;
971                                                 BLI_strncpy(node->idname, "ShaderNodeBsdfPrincipled", sizeof(node->idname));
972                                                 node->custom1 = SHD_GLOSSY_MULTI_GGX;
973                                                 error |= NTREE_DOVERSION_TRANSPARENCY_EMISSION;
974                                         }
975                                 }
976                         }
977                 } FOREACH_NODETREE_END
978
979                 if (error & NTREE_DOVERSION_NEED_OUTPUT) {
980                         BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
981                         printf("You need to connect Principled and Eevee Specular shader nodes to new material output nodes.\n");
982                 }
983
984                 if (error & NTREE_DOVERSION_TRANSPARENCY_EMISSION) {
985                         BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
986                         printf("You need to combine transparency and emission shaders to the converted Principled shader nodes.\n");
987                 }
988
989 #ifdef USE_COLLECTION_COMPAT_28
990                 if (use_collection_compat_28 &&
991                     (DNA_struct_elem_find(fd->filesdna, "ViewLayer", "FreestyleConfig", "freestyle_config") == false) &&
992                     DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers"))
993                 {
994                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
995                                 ViewLayer *view_layer;
996                                 for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
997                                         view_layer->flag |= VIEW_LAYER_FREESTYLE;
998                                         view_layer->layflag = 0x7FFF;   /* solid ztra halo edge strand */
999                                         view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
1000                                         view_layer->pass_alpha_threshold = 0.5f;
1001                                         BKE_freestyle_config_init(&view_layer->freestyle_config);
1002                                 }
1003                         }
1004                 }
1005 #endif
1006         }
1007
1008 #ifdef USE_COLLECTION_COMPAT_28
1009         if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
1010                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1011                         ViewLayer *view_layer;
1012                         for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
1013                                 do_version_view_layer_visibility(view_layer);
1014                         }
1015                 }
1016
1017                 for (Collection *group = bmain->collection.first; group; group = group->id.next) {
1018                         if (group->view_layer != NULL) {
1019                                 do_version_view_layer_visibility(group->view_layer);
1020                         }
1021                 }
1022         }
1023 #endif
1024
1025         if (!MAIN_VERSION_ATLEAST(bmain, 280, 6)) {
1026                 if (DNA_struct_elem_find(fd->filesdna, "SpaceOops", "int", "filter") == false) {
1027                         bScreen *sc;
1028                         ScrArea *sa;
1029                         SpaceLink *sl;
1030
1031                         /* Update files using invalid (outdated) outlinevis Outliner values. */
1032                         for (sc = bmain->screen.first; sc; sc = sc->id.next) {
1033                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
1034                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1035                                                 if (sl->spacetype == SPACE_OUTLINER) {
1036                                                         SpaceOops *so = (SpaceOops *)sl;
1037
1038                                                         if (!ELEM(so->outlinevis,
1039                                                                   SO_SCENES,
1040                                                                   SO_LIBRARIES,
1041                                                                   SO_SEQUENCE,
1042                                                                   SO_DATA_API,
1043                                                                   SO_ID_ORPHANS))
1044                                                         {
1045                                                                 so->outlinevis = SO_VIEW_LAYER;
1046                                                         }
1047                                                 }
1048                                         }
1049                                 }
1050                         }
1051                 }
1052
1053                 if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "intensity")) {
1054                         for (LightProbe *probe = bmain->lightprobe.first; probe; probe = probe->id.next) {
1055                                 probe->intensity = 1.0f;
1056                         }
1057                 }
1058
1059                 for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
1060                         bConstraint *con, *con_next;
1061                         con = ob->constraints.first;
1062                         while (con) {
1063                                 con_next = con->next;
1064                                 if (con->type == 17) { /* CONSTRAINT_TYPE_RIGIDBODYJOINT */
1065                                         BLI_remlink(&ob->constraints, con);
1066                                         BKE_constraint_free_data(con);
1067                                         MEM_freeN(con);
1068                                 }
1069                                 con = con_next;
1070                         }
1071                 }
1072
1073                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "int", "orientation_index_custom")) {
1074                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1075                                 scene->orientation_index_custom = -1;
1076                         }
1077                 }
1078
1079                 for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
1080                         for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
1081                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1082                                         if (sl->spacetype == SPACE_VIEW3D) {
1083                                                 View3D *v3d = (View3D *)sl;
1084                                                 v3d->shading.light = V3D_LIGHTING_STUDIO;
1085                                                 v3d->shading.flag |= V3D_SHADING_OBJECT_OUTLINE;
1086
1087                                                 /* Assume (demo) files written with 2.8 want to show
1088                                                  * Eevee renders in the viewport. */
1089                                                 if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
1090                                                         v3d->drawtype = OB_MATERIAL;
1091                                                 }
1092                                         }
1093                                 }
1094                         }
1095                 }
1096         }
1097
1098         if (!MAIN_VERSION_ATLEAST(bmain, 280, 7)) {
1099                 /* Render engine storage moved elsewhere and back during 2.8
1100                  * development, we assume any files saved in 2.8 had Eevee set
1101                  * as scene render engine. */
1102                 if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
1103                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1104                                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
1105                         }
1106                 }
1107         }
1108
1109         if (!MAIN_VERSION_ATLEAST(bmain, 280, 8)) {
1110                 /* Blender Internal removal */
1111                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1112                         if (STREQ(scene->r.engine, "BLENDER_RENDER") ||
1113                             STREQ(scene->r.engine, "BLENDER_GAME"))
1114                         {
1115                                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
1116                         }
1117
1118                         scene->r.bake_mode = 0;
1119                 }
1120
1121                 for (Tex *tex = bmain->tex.first; tex; tex = tex->id.next) {
1122                         /* Removed envmap, pointdensity, voxeldata, ocean textures. */
1123                         if (ELEM(tex->type, 10, 14, 15, 16)) {
1124                                 tex->type = 0;
1125                         }
1126                 }
1127         }
1128
1129         if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) {
1130
1131                 /* Remove info editor, but only if at the top of the window. */
1132                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1133                         /* Calculate window width/height from screen vertices */
1134                         int win_width = 0, win_height = 0;
1135                         for (ScrVert *vert = screen->vertbase.first; vert; vert = vert->next) {
1136                                 win_width  = MAX2(win_width, vert->vec.x);
1137                                 win_height = MAX2(win_height, vert->vec.y);
1138                         }
1139
1140                         for (ScrArea *area = screen->areabase.first, *area_next; area; area = area_next) {
1141                                 area_next = area->next;
1142
1143                                 if (area->spacetype == SPACE_INFO) {
1144                                         if ((area->v2->vec.y == win_height) && (area->v1->vec.x == 0) && (area->v4->vec.x == win_width)) {
1145                                                 BKE_screen_area_free(area);
1146
1147                                                 BLI_remlink(&screen->areabase, area);
1148
1149                                                 BKE_screen_remove_double_scredges(screen);
1150                                                 BKE_screen_remove_unused_scredges(screen);
1151                                                 BKE_screen_remove_unused_scrverts(screen);
1152
1153                                                 MEM_freeN(area);
1154                                         }
1155                                 }
1156                                 /* AREA_TEMP_INFO is deprecated from now on, it should only be set for info areas
1157                                  * which are deleted above, so don't need to unset it. Its slot/bit can be reused */
1158                         }
1159                 }
1160         }
1161
1162         if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) {
1163                 for (Lamp *lamp = bmain->lamp.first; lamp; lamp = lamp->id.next) {
1164                         if (lamp->mode & (1 << 13)) { /* LA_SHAD_RAY */
1165                                 lamp->mode |= LA_SHADOW;
1166                                 lamp->mode &= ~(1 << 13);
1167                         }
1168                 }
1169         }
1170
1171         if (!MAIN_VERSION_ATLEAST(bmain, 280, 12)) {
1172                 /* Remove tool property regions. */
1173                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1174                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1175                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1176                                         if (ELEM(sl->spacetype, SPACE_VIEW3D, SPACE_CLIP)) {
1177                                                 ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1178
1179                                                 for (ARegion *region = regionbase->first, *region_next; region; region = region_next) {
1180                                                         region_next = region->next;
1181
1182                                                         if (region->regiontype == RGN_TYPE_TOOL_PROPS) {
1183                                                                 BKE_area_region_free(NULL, region);
1184                                                                 BLI_freelinkN(regionbase, region);
1185                                                         }
1186                                                 }
1187                                         }
1188                                 }
1189                         }
1190                 }
1191         }
1192
1193         if (!MAIN_VERSION_ATLEAST(bmain, 280, 13)) {
1194                 /* Initialize specular factor. */
1195                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "spec_fac")) {
1196                         for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
1197                                 la->spec_fac = 1.0f;
1198                         }
1199                 }
1200
1201                 /* Initialize new view3D options. */
1202                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1203                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1204                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1205                                         if (sl->spacetype == SPACE_VIEW3D) {
1206                                                 View3D *v3d = (View3D *)sl;
1207                                                 v3d->shading.light = V3D_LIGHTING_STUDIO;
1208                                                 v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR;
1209                                                 copy_v3_fl(v3d->shading.single_color, 0.8f);
1210                                                 v3d->shading.shadow_intensity = 0.5;
1211
1212                                                 v3d->overlay.backwire_opacity = 0.5f;
1213                                                 v3d->overlay.normals_length = 0.1f;
1214                                                 v3d->overlay.flag = V3D_OVERLAY_LOOK_DEV;
1215                                         }
1216                                 }
1217                         }
1218                 }
1219
1220                 if (!DNA_struct_find(fd->filesdna, "View3DCursor")) {
1221                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1222                                 unit_qt(scene->cursor.rotation);
1223                         }
1224                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1225                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1226                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1227                                                 if (sl->spacetype == SPACE_VIEW3D) {
1228                                                         View3D *v3d = (View3D *)sl;
1229                                                         unit_qt(v3d->cursor.rotation);
1230                                                 }
1231                                         }
1232                                 }
1233                         }
1234                 }
1235         }
1236
1237         if (!MAIN_VERSION_ATLEAST(bmain, 280, 14)) {
1238                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "SceneDisplay", "display")) {
1239                         /* Initialize new scene.SceneDisplay */
1240                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1241                                 copy_v3_v3(scene->display.light_direction, (float[3]){-M_SQRT1_3, -M_SQRT1_3, M_SQRT1_3});
1242                         }
1243                 }
1244                 if (!DNA_struct_elem_find(fd->filesdna, "SceneDisplay", "float", "shadow_shift")) {
1245                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1246                                 scene->display.shadow_shift = 0.1;
1247                         }
1248                 }
1249
1250                 if (!DNA_struct_elem_find(fd->filesdna, "Object", "ObjectDisplay", "display")) {
1251                         /* Initialize new object.ObjectDisplay */
1252                         for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
1253                                 ob->display.flag = OB_SHOW_SHADOW;
1254                         }
1255                 }
1256
1257                 if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "transform_pivot_point")) {
1258                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1259                                 scene->toolsettings->transform_pivot_point = V3D_AROUND_CENTER_MEAN;
1260                         }
1261                 }
1262
1263                 if (!DNA_struct_find(fd->filesdna, "SceneEEVEE")) {
1264                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1265                                 /* First set the default for all the properties. */
1266
1267                                 scene->eevee.gi_diffuse_bounces = 3;
1268                                 scene->eevee.gi_cubemap_resolution = 512;
1269                                 scene->eevee.gi_visibility_resolution = 32;
1270
1271                                 scene->eevee.taa_samples = 16;
1272                                 scene->eevee.taa_render_samples = 64;
1273
1274                                 scene->eevee.sss_samples = 7;
1275                                 scene->eevee.sss_jitter_threshold = 0.3f;
1276
1277                                 scene->eevee.ssr_quality = 0.25f;
1278                                 scene->eevee.ssr_max_roughness = 0.5f;
1279                                 scene->eevee.ssr_thickness = 0.2f;
1280                                 scene->eevee.ssr_border_fade = 0.075f;
1281                                 scene->eevee.ssr_firefly_fac = 10.0f;
1282
1283                                 scene->eevee.volumetric_start = 0.1f;
1284                                 scene->eevee.volumetric_end = 100.0f;
1285                                 scene->eevee.volumetric_tile_size = 8;
1286                                 scene->eevee.volumetric_samples = 64;
1287                                 scene->eevee.volumetric_sample_distribution = 0.8f;
1288                                 scene->eevee.volumetric_light_clamp = 0.0f;
1289                                 scene->eevee.volumetric_shadow_samples = 16;
1290
1291                                 scene->eevee.gtao_distance = 0.2f;
1292                                 scene->eevee.gtao_factor = 1.0f;
1293                                 scene->eevee.gtao_quality = 0.25f;
1294
1295                                 scene->eevee.bokeh_max_size = 100.0f;
1296                                 scene->eevee.bokeh_threshold = 1.0f;
1297
1298                                 copy_v3_fl(scene->eevee.bloom_color, 1.0f);
1299                                 scene->eevee.bloom_threshold = 0.8f;
1300                                 scene->eevee.bloom_knee = 0.5f;
1301                                 scene->eevee.bloom_intensity = 0.8f;
1302                                 scene->eevee.bloom_radius = 6.5f;
1303                                 scene->eevee.bloom_clamp = 1.0f;
1304
1305                                 scene->eevee.motion_blur_samples = 8;
1306                                 scene->eevee.motion_blur_shutter = 1.0f;
1307
1308                                 scene->eevee.shadow_method = SHADOW_ESM;
1309                                 scene->eevee.shadow_cube_size = 512;
1310                                 scene->eevee.shadow_cascade_size = 1024;
1311
1312                                 scene->eevee.flag =
1313                                         SCE_EEVEE_VOLUMETRIC_LIGHTS |
1314                                         SCE_EEVEE_VOLUMETRIC_COLORED |
1315                                         SCE_EEVEE_GTAO_BENT_NORMALS |
1316                                         SCE_EEVEE_GTAO_BOUNCE |
1317                                         SCE_EEVEE_TAA_REPROJECTION |
1318                                         SCE_EEVEE_SSR_HALF_RESOLUTION;
1319
1320
1321                                 /* If the file is pre-2.80 move on. */
1322                                 if (scene->layer_properties == NULL) {
1323                                         continue;
1324                                 }
1325
1326                                 /* Now we handle eventual properties that may be set in the file. */
1327 #define EEVEE_GET_BOOL(_props, _name, _flag) \
1328                                 { \
1329                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1330                                         if (_idprop != NULL) { \
1331                                                 const int _value = IDP_Int(_idprop); \
1332                                                 if (_value) { \
1333                                                         scene->eevee.flag |= _flag; \
1334                                                 } \
1335                                                 else { \
1336                                                         scene->eevee.flag &= ~_flag; \
1337                                                 } \
1338                                         } \
1339                                 }
1340
1341 #define EEVEE_GET_INT(_props, _name) \
1342                                 { \
1343                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1344                                         if (_idprop != NULL) { \
1345                                                 scene->eevee._name = IDP_Int(_idprop); \
1346                                         } \
1347                                 }
1348
1349 #define EEVEE_GET_FLOAT(_props, _name) \
1350                                 { \
1351                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1352                                         if (_idprop != NULL) { \
1353                                                 scene->eevee._name = IDP_Float(_idprop); \
1354                                         } \
1355                                 }
1356
1357 #define EEVEE_GET_FLOAT_ARRAY(_props, _name, _length) \
1358                                 { \
1359                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1360                                         if (_idprop != NULL) { \
1361                                                 const float *_values = IDP_Array(_idprop); \
1362                                                 for (int _i = 0; _i < _length; _i++) { \
1363                                                         scene->eevee._name [_i] = _values[_i]; \
1364                                                 } \
1365                                         } \
1366                                 }
1367
1368                                 IDProperty *props = IDP_GetPropertyFromGroup(scene->layer_properties, RE_engine_id_BLENDER_EEVEE);
1369                                 EEVEE_GET_BOOL(props, volumetric_enable, SCE_EEVEE_VOLUMETRIC_ENABLED);
1370                                 EEVEE_GET_BOOL(props, volumetric_lights, SCE_EEVEE_VOLUMETRIC_LIGHTS);
1371                                 EEVEE_GET_BOOL(props, volumetric_shadows, SCE_EEVEE_VOLUMETRIC_SHADOWS);
1372                                 EEVEE_GET_BOOL(props, volumetric_colored_transmittance, SCE_EEVEE_VOLUMETRIC_COLORED);
1373                                 EEVEE_GET_BOOL(props, gtao_enable, SCE_EEVEE_GTAO_ENABLED);
1374                                 EEVEE_GET_BOOL(props, gtao_use_bent_normals, SCE_EEVEE_GTAO_BENT_NORMALS);
1375                                 EEVEE_GET_BOOL(props, gtao_bounce, SCE_EEVEE_GTAO_BOUNCE);
1376                                 EEVEE_GET_BOOL(props, dof_enable, SCE_EEVEE_DOF_ENABLED);
1377                                 EEVEE_GET_BOOL(props, bloom_enable, SCE_EEVEE_BLOOM_ENABLED);
1378                                 EEVEE_GET_BOOL(props, motion_blur_enable, SCE_EEVEE_MOTION_BLUR_ENABLED);
1379                                 EEVEE_GET_BOOL(props, shadow_high_bitdepth, SCE_EEVEE_SHADOW_HIGH_BITDEPTH);
1380                                 EEVEE_GET_BOOL(props, taa_reprojection, SCE_EEVEE_TAA_REPROJECTION);
1381                                 EEVEE_GET_BOOL(props, sss_enable, SCE_EEVEE_SSS_ENABLED);
1382                                 EEVEE_GET_BOOL(props, sss_separate_albedo, SCE_EEVEE_SSS_SEPARATE_ALBEDO);
1383                                 EEVEE_GET_BOOL(props, ssr_enable, SCE_EEVEE_SSR_ENABLED);
1384                                 EEVEE_GET_BOOL(props, ssr_refraction, SCE_EEVEE_SSR_REFRACTION);
1385                                 EEVEE_GET_BOOL(props, ssr_halfres, SCE_EEVEE_SSR_HALF_RESOLUTION);
1386
1387                                 EEVEE_GET_INT(props, gi_diffuse_bounces);
1388                                 EEVEE_GET_INT(props, gi_diffuse_bounces);
1389                                 EEVEE_GET_INT(props, gi_cubemap_resolution);
1390                                 EEVEE_GET_INT(props, gi_visibility_resolution);
1391
1392                                 EEVEE_GET_INT(props, taa_samples);
1393                                 EEVEE_GET_INT(props, taa_render_samples);
1394
1395                                 EEVEE_GET_INT(props, sss_samples);
1396                                 EEVEE_GET_FLOAT(props, sss_jitter_threshold);
1397
1398                                 EEVEE_GET_FLOAT(props, ssr_quality);
1399                                 EEVEE_GET_FLOAT(props, ssr_max_roughness);
1400                                 EEVEE_GET_FLOAT(props, ssr_thickness);
1401                                 EEVEE_GET_FLOAT(props, ssr_border_fade);
1402                                 EEVEE_GET_FLOAT(props, ssr_firefly_fac);
1403
1404                                 EEVEE_GET_FLOAT(props, volumetric_start);
1405                                 EEVEE_GET_FLOAT(props, volumetric_end);
1406                                 EEVEE_GET_INT(props, volumetric_tile_size);
1407                                 EEVEE_GET_INT(props, volumetric_samples);
1408                                 EEVEE_GET_FLOAT(props, volumetric_sample_distribution);
1409                                 EEVEE_GET_FLOAT(props, volumetric_light_clamp);
1410                                 EEVEE_GET_INT(props, volumetric_shadow_samples);
1411
1412                                 EEVEE_GET_FLOAT(props, gtao_distance);
1413                                 EEVEE_GET_FLOAT(props, gtao_factor);
1414                                 EEVEE_GET_FLOAT(props, gtao_quality);
1415
1416                                 EEVEE_GET_FLOAT(props, bokeh_max_size);
1417                                 EEVEE_GET_FLOAT(props, bokeh_threshold);
1418
1419                                 EEVEE_GET_FLOAT_ARRAY(props, bloom_color, 3);
1420                                 EEVEE_GET_FLOAT(props, bloom_threshold);
1421                                 EEVEE_GET_FLOAT(props, bloom_knee);
1422                                 EEVEE_GET_FLOAT(props, bloom_intensity);
1423                                 EEVEE_GET_FLOAT(props, bloom_radius);
1424                                 EEVEE_GET_FLOAT(props, bloom_clamp);
1425
1426                                 EEVEE_GET_INT(props, motion_blur_samples);
1427                                 EEVEE_GET_FLOAT(props, motion_blur_shutter);
1428
1429                                 EEVEE_GET_INT(props, shadow_method);
1430                                 EEVEE_GET_INT(props, shadow_cube_size);
1431                                 EEVEE_GET_INT(props, shadow_cascade_size);
1432
1433                                 /* Cleanup. */
1434                                 IDP_FreeProperty(scene->layer_properties);
1435                                 MEM_freeN(scene->layer_properties);
1436                                 scene->layer_properties = NULL;
1437
1438 #undef EEVEE_GET_FLOAT_ARRAY
1439 #undef EEVEE_GET_FLOAT
1440 #undef EEVEE_GET_INT
1441 #undef EEVEE_GET_BOOL
1442                         }
1443                 }
1444
1445
1446                 if (!MAIN_VERSION_ATLEAST(bmain, 280, 15)) {
1447                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1448                                 scene->display.matcap_ssao_distance = 0.2f;
1449                                 scene->display.matcap_ssao_attenuation = 1.0f;
1450                                 scene->display.matcap_ssao_samples = 16;
1451                         }
1452
1453                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1454                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1455                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1456                                                 if (sl->spacetype == SPACE_OUTLINER) {
1457                                                         SpaceOops *soops = (SpaceOops *)sl;
1458                                                         soops->filter_id_type = ID_GR;
1459                                                         soops->outlinevis = SO_VIEW_LAYER;
1460                                                 }
1461                                         }
1462                                 }
1463                         }
1464
1465                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1466                                 switch (scene->toolsettings->snap_mode) {
1467                                         case 0: scene->toolsettings->snap_mode = SCE_SNAP_MODE_INCREMENT; break;
1468                                         case 1: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VERTEX   ; break;
1469                                         case 2: scene->toolsettings->snap_mode = SCE_SNAP_MODE_EDGE     ; break;
1470                                         case 3: scene->toolsettings->snap_mode = SCE_SNAP_MODE_FACE     ; break;
1471                                         case 4: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VOLUME   ; break;
1472                                 }
1473                                 switch (scene->toolsettings->snap_node_mode) {
1474                                         case 5: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X; break;
1475                                         case 6: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_Y; break;
1476                                         case 7: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X | SCE_SNAP_MODE_NODE_Y; break;
1477                                         case 8: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID  ; break;
1478                                 }
1479                                 switch (scene->toolsettings->snap_uv_mode) {
1480                                         case 0: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_INCREMENT; break;
1481                                         case 1: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_VERTEX   ; break;
1482                                 }
1483                         }
1484
1485                         ParticleSettings *part;
1486                         for (part = bmain->particle.first; part; part = part->id.next) {
1487                                 part->shape_flag = PART_SHAPE_CLOSE_TIP;
1488                                 part->shape = 0.0f;
1489                                 part->rad_root = 1.0f;
1490                                 part->rad_tip = 0.0f;
1491                                 part->rad_scale = 0.01f;
1492                         }
1493                 }
1494
1495         }
1496         {
1497                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "roughness")) {
1498                         for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) {
1499                                 if (mat->use_nodes) {
1500                                         if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
1501                                                 mat->roughness = mat->gloss_mir;
1502                                         }
1503                                         else {
1504                                                 mat->roughness = 0.25f;
1505                                         }
1506                                 }
1507                                 else {
1508                                         mat->roughness = 1.0f - mat->gloss_mir;
1509                                 }
1510                                 mat->metallic = mat->ray_mirror;
1511                         }
1512
1513                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1514                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1515                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1516                                                 if (sl->spacetype == SPACE_VIEW3D) {
1517                                                         View3D *v3d = (View3D *)sl;
1518                                                         v3d->shading.flag |= V3D_SHADING_SPECULAR_HIGHLIGHT;
1519                                                 }
1520                                         }
1521                                 }
1522                         }
1523                 }
1524
1525                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "xray_alpha")) {
1526                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1527                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1528                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1529                                                 if (sl->spacetype == SPACE_VIEW3D) {
1530                                                         View3D *v3d = (View3D *)sl;
1531                                                         v3d->shading.xray_alpha = 0.5f;
1532                                                 }
1533                                         }
1534                                 }
1535                         }
1536                 }
1537                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "char", "matcap[256]")) {
1538                         StudioLight *default_matcap = BKE_studiolight_find_first(STUDIOLIGHT_ORIENTATION_VIEWNORMAL);
1539                         /* when loading the internal file is loaded before the matcaps */
1540                         if (default_matcap) {
1541                                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1542                                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1543                                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1544                                                         if (sl->spacetype == SPACE_VIEW3D) {
1545                                                                 View3D *v3d = (View3D *)sl;
1546                                                                 BLI_strncpy(v3d->shading.matcap, default_matcap->name, FILE_MAXFILE);
1547                                                         }
1548                                                 }
1549                                         }
1550                                 }
1551                         }
1552                 }
1553                 if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "wireframe_threshold")) {
1554                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1555                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1556                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1557                                                 if (sl->spacetype == SPACE_VIEW3D) {
1558                                                         View3D *v3d = (View3D *)sl;
1559                                                         v3d->overlay.wireframe_threshold = 0.5f;
1560                                                 }
1561                                         }
1562                                 }
1563                         }
1564                 }
1565                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "cavity_valley_factor")) {
1566                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1567                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1568                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1569                                                 if (sl->spacetype == SPACE_VIEW3D) {
1570                                                         View3D *v3d = (View3D *)sl;
1571                                                         v3d->shading.cavity_valley_factor = 1.0f;
1572                                                         v3d->shading.cavity_ridge_factor = 1.0f;
1573                                                 }
1574                                         }
1575                                 }
1576                         }
1577                 }
1578                 if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "bone_selection_alpha")) {
1579                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1580                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1581                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1582                                                 if (sl->spacetype == SPACE_VIEW3D) {
1583                                                         View3D *v3d = (View3D *)sl;
1584                                                         v3d->overlay.bone_selection_alpha = 0.5f;
1585                                                 }
1586                                         }
1587                                 }
1588                         }
1589                 }
1590                 if (!DNA_struct_elem_find(fd->filesdna, "Image", "ListBase", "renderslot")) {
1591                         for (Image *ima = bmain->image.first; ima; ima = ima->id.next) {
1592                                 if (ima->type == IMA_TYPE_R_RESULT) {
1593                                         for (int i = 0; i < 8; i++) {
1594                                                 RenderSlot *slot = MEM_callocN(sizeof(RenderSlot), "Image Render Slot Init");
1595                                                 BLI_snprintf(slot->name, sizeof(slot->name), "Slot %d", i+1);
1596                                                 BLI_addtail(&ima->renderslots, slot);
1597                                         }
1598                                 }
1599                         }
1600                 }
1601         }
1602 }