d68f0fe5d2c36f10b282a0c61cdb5da3df0bcb11
[blender.git] / source / blender / blenloader / intern / versioning_280.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16
17 /** \file
18  * \ingroup blenloader
19  */
20
21 /* allow readfile to use deprecated functionality */
22 #define DNA_DEPRECATED_ALLOW
23
24 #include <string.h>
25 #include <float.h>
26
27 #include "BLI_listbase.h"
28 #include "BLI_math.h"
29 #include "BLI_mempool.h"
30 #include "BLI_string.h"
31 #include "BLI_utildefines.h"
32
33 #include "DNA_object_types.h"
34 #include "DNA_camera_types.h"
35 #include "DNA_cloth_types.h"
36 #include "DNA_collection_types.h"
37 #include "DNA_constraint_types.h"
38 #include "DNA_gpu_types.h"
39 #include "DNA_light_types.h"
40 #include "DNA_layer_types.h"
41 #include "DNA_lightprobe_types.h"
42 #include "DNA_material_types.h"
43 #include "DNA_mesh_types.h"
44 #include "DNA_modifier_types.h"
45 #include "DNA_particle_types.h"
46 #include "DNA_rigidbody_types.h"
47 #include "DNA_scene_types.h"
48 #include "DNA_screen_types.h"
49 #include "DNA_view3d_types.h"
50 #include "DNA_genfile.h"
51 #include "DNA_gpencil_types.h"
52 #include "DNA_workspace_types.h"
53 #include "DNA_key_types.h"
54 #include "DNA_curve_types.h"
55 #include "DNA_armature_types.h"
56 #include "DNA_text_types.h"
57
58 #include "BKE_action.h"
59 #include "BKE_cloth.h"
60 #include "BKE_collection.h"
61 #include "BKE_constraint.h"
62 #include "BKE_colortools.h"
63 #include "BKE_customdata.h"
64 #include "BKE_freestyle.h"
65 #include "BKE_gpencil.h"
66 #include "BKE_idprop.h"
67 #include "BKE_image.h"
68 #include "BKE_key.h"
69 #include "BKE_library.h"
70 #include "BKE_layer.h"
71 #include "BKE_main.h"
72 #include "BKE_material.h"
73 #include "BKE_mesh.h"
74 #include "BKE_node.h"
75 #include "BKE_object.h"
76 #include "BKE_paint.h"
77 #include "BKE_pointcache.h"
78 #include "BKE_report.h"
79 #include "BKE_rigidbody.h"
80 #include "BKE_scene.h"
81 #include "BKE_screen.h"
82 #include "BKE_sequencer.h"
83 #include "BKE_studiolight.h"
84 #include "BKE_unit.h"
85 #include "BKE_workspace.h"
86
87 /* Only for IMB_BlendMode */
88 #include "IMB_imbuf.h"
89
90 #include "DEG_depsgraph.h"
91
92 #include "BLT_translation.h"
93
94 #include "BLO_readfile.h"
95 #include "readfile.h"
96
97 #include "MEM_guardedalloc.h"
98
99 static bScreen *screen_parent_find(const bScreen *screen)
100 {
101         /* can avoid lookup if screen state isn't maximized/full (parent and child store the same state) */
102         if (ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL)) {
103                 for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
104                         if (sa->full && sa->full != screen) {
105                                 BLI_assert(sa->full->state == screen->state);
106                                 return sa->full;
107                         }
108                 }
109         }
110
111         return NULL;
112 }
113
114 static void do_version_workspaces_create_from_screens(Main *bmain)
115 {
116         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
117                 const bScreen *screen_parent = screen_parent_find(screen);
118                 WorkSpace *workspace;
119                 if (screen->temp) {
120                         continue;
121                 }
122
123                 if (screen_parent) {
124                         /* fullscreen with "Back to Previous" option, don't create
125                          * a new workspace, add layout workspace containing parent */
126                         workspace = BLI_findstring(
127                                 &bmain->workspaces, screen_parent->id.name + 2, offsetof(ID, name) + 2);
128                 }
129                 else {
130                         workspace = BKE_workspace_add(bmain, screen->id.name + 2);
131                 }
132                 if (workspace == NULL) {
133                         continue;  /* Not much we can do.. */
134                 }
135                 BKE_workspace_layout_add(bmain, workspace, screen, screen->id.name + 2);
136         }
137 }
138
139 static void do_version_area_change_space_to_space_action(ScrArea *area, const Scene *scene)
140 {
141         SpaceType *stype = BKE_spacetype_from_id(SPACE_ACTION);
142         SpaceAction *saction = (SpaceAction *)stype->new(area, scene);
143         ARegion *region_channels;
144
145         /* Properly free current regions */
146         for (ARegion *region = area->regionbase.first; region; region = region->next) {
147                 BKE_area_region_free(area->type, region);
148         }
149         BLI_freelistN(&area->regionbase);
150
151         area->type = stype;
152         area->spacetype = stype->spaceid;
153
154         BLI_addhead(&area->spacedata, saction);
155         area->regionbase = saction->regionbase;
156         BLI_listbase_clear(&saction->regionbase);
157
158         /* Different defaults for timeline */
159         region_channels = BKE_area_find_region_type(area, RGN_TYPE_CHANNELS);
160         region_channels->flag |= RGN_FLAG_HIDDEN;
161
162         saction->mode = SACTCONT_TIMELINE;
163         saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED;
164         saction->ads.filterflag |= ADS_FILTER_SUMMARY;
165 }
166
167 /**
168  * \brief After lib-link versioning for new workspace design.
169  *
170  * - Adds a workspace for (almost) each screen of the old file
171  *   and adds the needed workspace-layout to wrap the screen.
172  * - Active screen isn't stored directly in window anymore, but in the active workspace.
173  * - Active scene isn't stored in screen anymore, but in window.
174  * - Create workspace instance hook for each window.
175  *
176  * \note Some of the created workspaces might be deleted again in case of reading the default startup.blend.
177  */
178 static void do_version_workspaces_after_lib_link(Main *bmain)
179 {
180         BLI_assert(BLI_listbase_is_empty(&bmain->workspaces));
181
182         do_version_workspaces_create_from_screens(bmain);
183
184         for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
185                 for (wmWindow *win = wm->windows.first; win; win = win->next) {
186                         bScreen *screen_parent = screen_parent_find(win->screen);
187                         bScreen *screen = screen_parent ? screen_parent : win->screen;
188
189                         if (screen->temp) {
190                                 /* We do not generate a new workspace for those screens... still need to set some data in win. */
191                                 win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
192                                 win->scene = screen->scene;
193                                 /* Deprecated from now on! */
194                                 win->screen = NULL;
195                                 continue;
196                         }
197
198                         WorkSpace *workspace = BLI_findstring(&bmain->workspaces, screen->id.name + 2, offsetof(ID, name) + 2);
199                         BLI_assert(workspace != NULL);
200                         ListBase *layouts = BKE_workspace_layouts_get(workspace);
201
202                         win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
203
204                         BKE_workspace_active_set(win->workspace_hook, workspace);
205                         BKE_workspace_active_layout_set(win->workspace_hook, layouts->first);
206
207                         /* Move scene and view layer to window. */
208                         Scene *scene = screen->scene;
209                         ViewLayer *layer = BLI_findlink(&scene->view_layers, scene->r.actlay);
210                         if (!layer) {
211                                 layer = BKE_view_layer_default_view(scene);
212                         }
213
214                         win->scene = scene;
215                         STRNCPY(win->view_layer_name, layer->name);
216
217                         /* Deprecated from now on! */
218                         win->screen = NULL;
219                 }
220         }
221
222         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
223                 /* Deprecated from now on! */
224                 BLI_freelistN(&screen->scene->transform_spaces);
225                 screen->scene = NULL;
226         }
227 }
228
229 #ifdef USE_COLLECTION_COMPAT_28
230 enum {
231         COLLECTION_DEPRECATED_VISIBLE    = (1 << 0),
232         COLLECTION_DEPRECATED_VIEWPORT   = (1 << 0),
233         COLLECTION_DEPRECATED_SELECTABLE = (1 << 1),
234         COLLECTION_DEPRECATED_DISABLED   = (1 << 2),
235         COLLECTION_DEPRECATED_RENDER     = (1 << 3),
236 };
237
238 static void do_version_view_layer_visibility(ViewLayer *view_layer)
239 {
240         /* Convert from deprecated VISIBLE flag to DISABLED */
241         LayerCollection *lc;
242         for (lc = view_layer->layer_collections.first;
243              lc;
244              lc = lc->next)
245         {
246                 if (lc->flag & COLLECTION_DEPRECATED_DISABLED) {
247                         lc->flag &= ~COLLECTION_DEPRECATED_DISABLED;
248                 }
249
250                 if ((lc->flag & COLLECTION_DEPRECATED_VISIBLE) == 0) {
251                         lc->flag |= COLLECTION_DEPRECATED_DISABLED;
252                 }
253
254                 lc->flag |= COLLECTION_DEPRECATED_VIEWPORT | COLLECTION_DEPRECATED_RENDER;
255         }
256 }
257
258 static void do_version_layer_collection_pre(
259         ViewLayer *view_layer,
260         ListBase *lb,
261         GSet *enabled_set,
262         GSet *selectable_set)
263 {
264         /* Convert from deprecated DISABLED to new layer collection and collection flags */
265         for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
266                 if (lc->scene_collection) {
267                         if (!(lc->flag & COLLECTION_DEPRECATED_DISABLED)) {
268                                 BLI_gset_insert(enabled_set, lc->scene_collection);
269                         }
270                         if (lc->flag & COLLECTION_DEPRECATED_SELECTABLE) {
271                                 BLI_gset_insert(selectable_set, lc->scene_collection);
272                         }
273                 }
274
275                 do_version_layer_collection_pre(view_layer, &lc->layer_collections, enabled_set, selectable_set);
276         }
277 }
278
279 static void do_version_layer_collection_post(
280         ViewLayer *view_layer,
281         ListBase *lb,
282         GSet *enabled_set,
283         GSet *selectable_set,
284         GHash *collection_map)
285 {
286         /* Apply layer collection exclude flags. */
287         for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
288                 if (!(lc->collection->flag & COLLECTION_IS_MASTER)) {
289                         SceneCollection *sc = BLI_ghash_lookup(collection_map, lc->collection);
290                         const bool enabled = (sc && BLI_gset_haskey(enabled_set, sc));
291                         const bool selectable = (sc && BLI_gset_haskey(selectable_set, sc));
292
293                         if (!enabled) {
294                                 lc->flag |= LAYER_COLLECTION_EXCLUDE;
295                         }
296                         if (enabled && !selectable) {
297                                 lc->collection->flag |= COLLECTION_RESTRICT_SELECT;
298                         }
299                 }
300
301                 do_version_layer_collection_post(
302                         view_layer, &lc->layer_collections, enabled_set, selectable_set, collection_map);
303         }
304 }
305
306 static void do_version_scene_collection_convert(
307         Main *bmain,
308         ID *id,
309         SceneCollection *sc,
310         Collection *collection,
311         GHash *collection_map)
312 {
313         if (collection_map) {
314                 BLI_ghash_insert(collection_map, collection, sc);
315         }
316
317         for (SceneCollection *nsc = sc->scene_collections.first; nsc;) {
318                 SceneCollection *nsc_next = nsc->next;
319                 Collection *ncollection = BKE_collection_add(bmain, collection, nsc->name);
320                 ncollection->id.lib = id->lib;
321                 do_version_scene_collection_convert(bmain, id, nsc, ncollection, collection_map);
322                 nsc = nsc_next;
323         }
324
325         for (LinkData *link = sc->objects.first; link; link = link->next) {
326                 Object *ob = link->data;
327                 if (ob) {
328                         BKE_collection_object_add(bmain, collection, ob);
329                         id_us_min(&ob->id);
330                 }
331         }
332
333         BLI_freelistN(&sc->objects);
334         MEM_freeN(sc);
335 }
336
337 static void do_version_group_collection_to_collection(Main *bmain, Collection *group)
338 {
339         /* Convert old 2.8 group collections to new unified collections. */
340         if (group->collection) {
341                 do_version_scene_collection_convert(bmain, &group->id, group->collection, group, NULL);
342         }
343
344         group->collection = NULL;
345         group->view_layer = NULL;
346         id_fake_user_set(&group->id);
347 }
348
349 static void do_version_scene_collection_to_collection(Main *bmain, Scene *scene)
350 {
351         /* Convert old 2.8 scene collections to new unified collections. */
352
353         /* Temporarily clear view layers so we don't do any layer collection syncing
354          * and destroy old flags that we want to restore. */
355         ListBase view_layers = scene->view_layers;
356         BLI_listbase_clear(&scene->view_layers);
357
358         if (!scene->master_collection) {
359                 scene->master_collection = BKE_collection_master_add();
360         }
361
362         /* Convert scene collections. */
363         GHash *collection_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
364         if (scene->collection) {
365                 do_version_scene_collection_convert(bmain, &scene->id, scene->collection, scene->master_collection, collection_map);
366                 scene->collection = NULL;
367         }
368
369         scene->view_layers = view_layers;
370
371         /* Convert layer collections. */
372         ViewLayer *view_layer;
373         for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
374                 GSet *enabled_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
375                 GSet *selectable_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
376
377                 do_version_layer_collection_pre(
378                         view_layer, &view_layer->layer_collections, enabled_set, selectable_set);
379
380                 BKE_layer_collection_sync(scene, view_layer);
381
382                 do_version_layer_collection_post(
383                         view_layer, &view_layer->layer_collections, enabled_set, selectable_set, collection_map);
384
385                 BLI_gset_free(enabled_set, NULL);
386                 BLI_gset_free(selectable_set, NULL);
387
388                 BKE_layer_collection_sync(scene, view_layer);
389         }
390
391         BLI_ghash_free(collection_map, NULL, NULL);
392 }
393 #endif
394
395
396 static void do_version_layers_to_collections(Main *bmain, Scene *scene)
397 {
398         /* Since we don't have access to FileData we check the (always valid) first
399          * render layer instead. */
400         if (!scene->master_collection) {
401                 scene->master_collection = BKE_collection_master_add();
402         }
403
404         if (scene->view_layers.first) {
405                 return;
406         }
407
408         /* Create collections from layers. */
409         Collection *collection_master = BKE_collection_master(scene);
410         Collection *collections[20] = {NULL};
411
412         for (int layer = 0; layer < 20; layer++) {
413                 for (Base *base = scene->base.first; base; base = base->next) {
414                         if (base->lay & (1 << layer)) {
415                                 /* Create collections when needed only. */
416                                 if (collections[layer] == NULL) {
417                                         char name[MAX_NAME];
418
419                                         BLI_snprintf(name,
420                                                      sizeof(collection_master->id.name),
421                                                      DATA_("Collection %d"),
422                                                      layer + 1);
423
424                                         Collection *collection = BKE_collection_add(bmain, collection_master, name);
425                                         collection->id.lib = scene->id.lib;
426                                         collections[layer] = collection;
427
428                                         if (!(scene->lay & (1 << layer))) {
429                                                 collection->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
430                                         }
431                                 }
432
433                                 /* Note usually this would do slow collection syncing for view layers,
434                                  * but since no view layers exists yet at this point it's fast. */
435                                 BKE_collection_object_add(
436                                         bmain,
437                                         collections[layer], base->object);
438                         }
439
440                         if (base->flag & SELECT) {
441                                 base->object->flag |= SELECT;
442                         }
443                         else {
444                                 base->object->flag &= ~SELECT;
445                         }
446                 }
447         }
448
449         /* Handle legacy render layers. */
450         bool have_override = false;
451         const bool need_default_renderlayer = scene->r.layers.first == NULL;
452
453         for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
454                 ViewLayer *view_layer = BKE_view_layer_add(scene, srl->name);
455
456                 if (srl->layflag & SCE_LAY_DISABLE) {
457                         view_layer->flag &= ~VIEW_LAYER_RENDER;
458                 }
459
460                 if ((srl->layflag & SCE_LAY_FRS) == 0) {
461                         view_layer->flag &= ~VIEW_LAYER_FREESTYLE;
462                 }
463
464                 view_layer->layflag = srl->layflag;
465                 view_layer->passflag = srl->passflag;
466                 view_layer->pass_alpha_threshold = srl->pass_alpha_threshold;
467                 view_layer->samples = srl->samples;
468                 view_layer->mat_override = srl->mat_override;
469
470                 BKE_freestyle_config_free(&view_layer->freestyle_config, true);
471                 view_layer->freestyle_config = srl->freestyleConfig;
472                 view_layer->id_properties = srl->prop;
473
474                 /* Set exclusion and overrides. */
475                 for (int layer = 0; layer < 20; layer++) {
476                         Collection *collection = collections[layer];
477                         if (collection) {
478                                 LayerCollection *lc = BKE_layer_collection_first_from_scene_collection(view_layer, collection);
479
480                                 if (srl->lay_exclude & (1 << layer)) {
481                                         /* Disable excluded layer. */
482                                         have_override = true;
483                                         lc->flag |= LAYER_COLLECTION_EXCLUDE;
484                                         for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) {
485                                                 nlc->flag |= LAYER_COLLECTION_EXCLUDE;
486                                         }
487                                 }
488                                 else {
489                                         if (srl->lay_zmask & (1 << layer)) {
490                                                 have_override = true;
491                                                 lc->flag |= LAYER_COLLECTION_HOLDOUT;
492                                         }
493
494                                         if ((srl->lay & (1 << layer)) == 0) {
495                                                 have_override = true;
496                                                 lc->flag |= LAYER_COLLECTION_INDIRECT_ONLY;
497                                         }
498                                 }
499                         }
500                 }
501
502                 /* for convenience set the same active object in all the layers */
503                 if (scene->basact) {
504                         view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
505                 }
506
507                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
508                         if ((base->flag & BASE_SELECTABLE) && (base->object->flag & SELECT)) {
509                                 base->flag |= BASE_SELECTED;
510                         }
511                 }
512         }
513
514         BLI_freelistN(&scene->r.layers);
515
516         /* If render layers included overrides, or there are no render layers,
517          * we also create a vanilla viewport layer. */
518         if (have_override || need_default_renderlayer) {
519                 ViewLayer *view_layer = BKE_view_layer_add(scene, "Viewport");
520
521                 /* If we ported all the original render layers, we don't need to make the viewport layer renderable. */
522                 if (!BLI_listbase_is_single(&scene->view_layers)) {
523                         view_layer->flag &= ~VIEW_LAYER_RENDER;
524                 }
525
526                 /* convert active base */
527                 if (scene->basact) {
528                         view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
529                 }
530
531                 /* convert selected bases */
532                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
533                         if ((base->flag & BASE_SELECTABLE) && (base->object->flag & SELECT)) {
534                                 base->flag |= BASE_SELECTED;
535                         }
536
537                         /* keep lay around for forward compatibility (open those files in 2.79) */
538                         base->lay = base->object->lay;
539                 }
540         }
541
542         /* remove bases once and for all */
543         for (Base *base = scene->base.first; base; base = base->next) {
544                 id_us_min(&base->object->id);
545         }
546
547         BLI_freelistN(&scene->base);
548         scene->basact = NULL;
549 }
550
551 static void do_version_collection_propagate_lib_to_children(Collection *collection)
552 {
553         if (collection->id.lib != NULL) {
554                 for (CollectionChild *collection_child = collection->children.first;
555                      collection_child != NULL;
556                      collection_child = collection_child->next)
557                 {
558                         if (collection_child->collection->id.lib == NULL) {
559                                 collection_child->collection->id.lib = collection->id.lib;
560                         }
561                         do_version_collection_propagate_lib_to_children(collection_child->collection);
562                 }
563         }
564 }
565
566 void do_versions_after_linking_280(Main *bmain)
567 {
568         bool use_collection_compat_28 = true;
569
570         if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
571                 use_collection_compat_28 = false;
572
573                 /* Convert group layer visibility flags to hidden nested collection. */
574                 for (Collection *collection = bmain->collections.first; collection; collection = collection->id.next) {
575                         /* Add fake user for all existing groups. */
576                         id_fake_user_set(&collection->id);
577
578                         if (collection->flag & (COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER)) {
579                                 continue;
580                         }
581
582                         Collection *hidden_collection_array[20] = {NULL};
583                         for (CollectionObject *cob = collection->gobject.first, *cob_next = NULL; cob; cob = cob_next) {
584                                 cob_next = cob->next;
585                                 Object *ob = cob->ob;
586
587                                 if (!(ob->lay & collection->layer)) {
588                                         /* Find or create hidden collection matching object's first layer. */
589                                         Collection **collection_hidden = NULL;
590                                         int coll_idx = 0;
591                                         for (; coll_idx < 20; coll_idx++) {
592                                                 if (ob->lay & (1 << coll_idx)) {
593                                                         collection_hidden = &hidden_collection_array[coll_idx];
594                                                         break;
595                                                 }
596                                         }
597                                         BLI_assert(collection_hidden != NULL);
598
599                                         if (*collection_hidden == NULL) {
600                                                 char name[MAX_ID_NAME];
601                                                 BLI_snprintf(name, sizeof(name), DATA_("Hidden %d"), coll_idx + 1);
602                                                 *collection_hidden = BKE_collection_add(bmain, collection, name);
603                                                 (*collection_hidden)->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
604                                         }
605
606                                         BKE_collection_object_add(bmain, *collection_hidden, ob);
607                                         BKE_collection_object_remove(bmain, collection, ob, true);
608                                 }
609                         }
610                 }
611
612                 /* We need to assign lib pointer to generated hidden collections *after* all have been created, otherwise we'll
613                  * end up with several datablocks sharing same name/library, which is FORBIDDEN!
614                  * Note: we need this to be recursive, since a child collection may be sorted before its parent in bmain... */
615                 for (Collection *collection = bmain->collections.first; collection != NULL; collection = collection->id.next) {
616                         do_version_collection_propagate_lib_to_children(collection);
617                 }
618
619                 /* Convert layers to collections. */
620                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
621                         do_version_layers_to_collections(bmain, scene);
622                 }
623         }
624
625         if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
626                 for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
627                         /* same render-layer as do_version_workspaces_after_lib_link will activate,
628                          * so same layer as BKE_view_layer_default_view would return */
629                         ViewLayer *layer = screen->scene->view_layers.first;
630
631                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
632                                 for (SpaceLink *space = sa->spacedata.first; space; space = space->next) {
633                                         if (space->spacetype == SPACE_OUTLINER) {
634                                                 SpaceOutliner *soutliner = (SpaceOutliner *)space;
635
636                                                 soutliner->outlinevis = SO_VIEW_LAYER;
637
638                                                 if (BLI_listbase_count_at_most(&layer->layer_collections, 2) == 1) {
639                                                         if (soutliner->treestore == NULL) {
640                                                                 soutliner->treestore = BLI_mempool_create(
641                                                                         sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
642                                                         }
643
644                                                         /* Create a tree store element for the collection. This is normally
645                                                          * done in check_persistent (outliner_tree.c), but we need to access
646                                                          * it here :/ (expand element if it's the only one) */
647                                                         TreeStoreElem *tselem = BLI_mempool_calloc(soutliner->treestore);
648                                                         tselem->type = TSE_LAYER_COLLECTION;
649                                                         tselem->id = layer->layer_collections.first;
650                                                         tselem->nr = tselem->used = 0;
651                                                         tselem->flag &= ~TSE_CLOSED;
652                                                 }
653                                         }
654                                 }
655                         }
656                 }
657         }
658
659         /* New workspace design */
660         if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
661                 do_version_workspaces_after_lib_link(bmain);
662         }
663
664         if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) {
665                 /* Cleanup any remaining SceneRenderLayer data for files that were created
666                  * with Blender 2.8 before the SceneRenderLayer > RenderLayer refactor. */
667                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
668                         for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
669                                 if (srl->prop) {
670                                         IDP_FreeProperty(srl->prop);
671                                         MEM_freeN(srl->prop);
672                                 }
673                                 BKE_freestyle_config_free(&srl->freestyleConfig, true);
674                         }
675                         BLI_freelistN(&scene->r.layers);
676                 }
677         }
678
679         if (!MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
680                 /* Due to several changes to particle RNA and draw code particles from older files may no longer
681                  * be visible. Here we correct this by setting a default draw size for those files. */
682                 for (Object *object = bmain->objects.first; object; object = object->id.next) {
683                         for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
684                                 if (psys->part->draw_size == 0.0f) {
685                                         psys->part->draw_size = 0.1f;
686                                 }
687                         }
688                 }
689         }
690
691         if (!MAIN_VERSION_ATLEAST(bmain, 280, 4)) {
692                 for (Object *object = bmain->objects.first; object; object = object->id.next) {
693                         if (object->particlesystem.first) {
694                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
695                                 for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
696                                         if (psys->part->draw & PART_DRAW_EMITTER) {
697                                                 object->duplicator_visibility_flag |= OB_DUPLI_FLAG_RENDER;
698                                                 break;
699                                         }
700                                 }
701                         }
702                         else if (object->transflag & OB_DUPLI) {
703                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
704                         }
705                         else {
706                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER;
707                         }
708                 }
709
710                 /* Cleanup deprecated flag from particlesettings data-blocks. */
711                 for (ParticleSettings *part = bmain->particles.first; part; part = part->id.next) {
712                         part->draw &= ~PART_DRAW_EMITTER;
713                 }
714         }
715
716         /* SpaceTime & SpaceLogic removal/replacing */
717         if (!MAIN_VERSION_ATLEAST(bmain, 280, 9)) {
718                 const wmWindowManager *wm = bmain->wm.first;
719                 const Scene *scene = bmain->scenes.first;
720
721                 if (wm != NULL) {
722                         /* Action editors need a scene for creation. First, update active
723                          * screens using the active scene of the window they're displayed in.
724                          * Next, update remaining screens using first scene in main listbase. */
725
726                         for (wmWindow *win = wm->windows.first; win; win = win->next) {
727                                 const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
728                                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
729                                         if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
730                                                 do_version_area_change_space_to_space_action(area, win->scene);
731
732                                                 /* Don't forget to unset! */
733                                                 area->butspacetype = SPACE_EMPTY;
734                                         }
735                                 }
736                         }
737                 }
738                 if (scene != NULL) {
739                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
740                                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
741                                         if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
742                                                 /* Areas that were already handled won't be handled again */
743                                                 do_version_area_change_space_to_space_action(area, scene);
744
745                                                 /* Don't forget to unset! */
746                                                 area->butspacetype = SPACE_EMPTY;
747                                         }
748                                 }
749                         }
750                 }
751         }
752
753 #ifdef USE_COLLECTION_COMPAT_28
754         if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 14)) {
755                 for (Collection *group = bmain->collections.first; group; group = group->id.next) {
756                         do_version_group_collection_to_collection(bmain, group);
757                 }
758
759                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
760                         do_version_scene_collection_to_collection(bmain, scene);
761                 }
762         }
763 #endif
764
765         /* Update Curve object Shape Key data layout to include the Radius property */
766         if (!MAIN_VERSION_ATLEAST(bmain, 280, 23)) {
767                 for (Curve *cu = bmain->curves.first; cu; cu = cu->id.next) {
768                         if (!cu->key || cu->key->elemsize != sizeof(float[4]))
769                                 continue;
770
771                         cu->key->elemstr[0] = 3; /*KEYELEM_ELEM_SIZE_CURVE*/
772                         cu->key->elemsize = sizeof(float[3]);
773
774                         int new_count = BKE_keyblock_curve_element_count(&cu->nurb);
775
776                         for (KeyBlock *block = cu->key->block.first; block; block = block->next) {
777                                 int old_count = block->totelem;
778                                 void *old_data = block->data;
779
780                                 if (!old_data || old_count <= 0)
781                                         continue;
782
783                                 block->totelem = new_count;
784                                 block->data = MEM_callocN(sizeof(float[3]) * new_count, __func__);
785
786                                 float *oldptr = old_data;
787                                 float (*newptr)[3] = block->data;
788
789                                 for (Nurb *nu = cu->nurb.first; nu; nu = nu->next) {
790                                         if (nu->bezt) {
791                                                 BezTriple *bezt = nu->bezt;
792
793                                                 for (int a = 0; a < nu->pntsu; a++, bezt++) {
794                                                         if ((old_count -= 3) < 0) {
795                                                                 memcpy(newptr, bezt->vec, sizeof(float[3][3]));
796                                                                 newptr[3][0] = bezt->tilt;
797                                                         }
798                                                         else {
799                                                                 memcpy(newptr, oldptr, sizeof(float[3][4]));
800                                                         }
801
802                                                         newptr[3][1] = bezt->radius;
803
804                                                         oldptr += 3 * 4;
805                                                         newptr += 4; /*KEYELEM_ELEM_LEN_BEZTRIPLE*/
806                                                 }
807                                         }
808                                         else if (nu->bp) {
809                                                 BPoint *bp = nu->bp;
810
811                                                 for (int a = 0; a < nu->pntsu * nu->pntsv; a++, bp++) {
812                                                         if (--old_count < 0) {
813                                                                 copy_v3_v3(newptr[0], bp->vec);
814                                                                 newptr[1][0] = bp->tilt;
815                                                         }
816                                                         else {
817                                                                 memcpy(newptr, oldptr, sizeof(float[4]));
818                                                         }
819
820                                                         newptr[1][1] = bp->radius;
821
822                                                         oldptr += 4;
823                                                         newptr += 2; /*KEYELEM_ELEM_LEN_BPOINT*/
824                                                 }
825                                         }
826                                 }
827
828                                 MEM_freeN(old_data);
829                         }
830                 }
831         }
832
833         /* Move B-Bone custom handle settings from bPoseChannel to Bone. */
834         if (!MAIN_VERSION_ATLEAST(bmain, 280, 25)) {
835                 for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
836                         bArmature *arm = ob->data;
837
838                         /* If it is an armature from the same file. */
839                         if (ob->pose && arm && arm->id.lib == ob->id.lib) {
840                                 bool rebuild = false;
841
842                                 for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
843                                         /* If the 2.7 flag is enabled, processing is needed. */
844                                         if (pchan->bone && (pchan->bboneflag & PCHAN_BBONE_CUSTOM_HANDLES)) {
845                                                 /* If the settings in the Bone are not set, copy. */
846                                                 if (pchan->bone->bbone_prev_type == BBONE_HANDLE_AUTO &&
847                                                     pchan->bone->bbone_next_type == BBONE_HANDLE_AUTO &&
848                                                     pchan->bone->bbone_prev == NULL && pchan->bone->bbone_next == NULL)
849                                                 {
850                                                         pchan->bone->bbone_prev_type = (pchan->bboneflag & PCHAN_BBONE_CUSTOM_START_REL) ? BBONE_HANDLE_RELATIVE : BBONE_HANDLE_ABSOLUTE;
851                                                         pchan->bone->bbone_next_type = (pchan->bboneflag & PCHAN_BBONE_CUSTOM_END_REL) ? BBONE_HANDLE_RELATIVE : BBONE_HANDLE_ABSOLUTE;
852
853                                                         if (pchan->bbone_prev) {
854                                                                 pchan->bone->bbone_prev = pchan->bbone_prev->bone;
855                                                         }
856                                                         if (pchan->bbone_next) {
857                                                                 pchan->bone->bbone_next = pchan->bbone_next->bone;
858                                                         }
859                                                 }
860
861                                                 rebuild = true;
862                                                 pchan->bboneflag = 0;
863                                         }
864                                 }
865
866                                 /* Tag pose rebuild for all objects that use this armature. */
867                                 if (rebuild) {
868                                         for (Object *ob2 = bmain->objects.first; ob2; ob2 = ob2->id.next) {
869                                                 if (ob2->pose && ob2->data == arm) {
870                                                         ob2->pose->flag |= POSE_RECALC;
871                                                 }
872                                         }
873                                 }
874                         }
875                 }
876         }
877
878         if (!MAIN_VERSION_ATLEAST(bmain, 280, 30)) {
879                 for (Brush *brush = bmain->brushes.first; brush; brush = brush->id.next) {
880                         if (brush->gpencil_settings != NULL) {
881                                 brush->gpencil_tool = brush->gpencil_settings->brush_type;
882                         }
883                 }
884                 BKE_paint_toolslots_init_from_main(bmain);
885         }
886
887         if (!MAIN_VERSION_ATLEAST(bmain, 280, 38)) {
888                 /* Ensure we get valid rigidbody object/constraint data in relevant collections' objects. */
889                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
890                         RigidBodyWorld *rbw = scene->rigidbody_world;
891
892                         if (rbw == NULL) {
893                                 continue;
894                         }
895
896                         BKE_rigidbody_objects_collection_validate(scene, rbw);
897                         BKE_rigidbody_constraints_collection_validate(scene, rbw);
898                 }
899         }
900 }
901
902 /* NOTE: this version patch is intended for versions < 2.52.2, but was initially introduced in 2.27 already.
903  *       But in 2.79 another case generating non-unique names was discovered (see T55668, involving Meta strips)... */
904 static void do_versions_seq_unique_name_all_strips(Scene *sce, ListBase *seqbasep)
905 {
906         for (Sequence *seq = seqbasep->first; seq != NULL; seq = seq->next) {
907                 BKE_sequence_base_unique_name_recursive(&sce->ed->seqbase, seq);
908                 if (seq->seqbase.first != NULL) {
909                         do_versions_seq_unique_name_all_strips(sce, &seq->seqbase);
910                 }
911         }
912 }
913
914 void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
915 {
916         bool use_collection_compat_28 = true;
917
918         if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
919                 use_collection_compat_28 = false;
920
921                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
922                         scene->r.gauss = 1.5f;
923                 }
924         }
925
926         if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
927                 if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "bleedexp")) {
928                         for (Light *la = bmain->lights.first; la; la = la->id.next) {
929                                 la->bleedexp = 2.5f;
930                         }
931                 }
932
933                 if (!DNA_struct_elem_find(fd->filesdna, "GPUDOFSettings", "float", "ratio")) {
934                         for (Camera *ca = bmain->cameras.first; ca; ca = ca->id.next) {
935                                 ca->gpu_dof.ratio = 1.0f;
936                         }
937                 }
938
939                 /* MTexPoly now removed. */
940                 if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
941                         const int cd_mtexpoly = 15;  /* CD_MTEXPOLY, deprecated */
942                         for (Mesh *me = bmain->meshes.first; me; me = me->id.next) {
943                                 /* If we have UV's, so this file will have MTexPoly layers too! */
944                                 if (me->mloopuv != NULL) {
945                                         CustomData_update_typemap(&me->pdata);
946                                         CustomData_free_layers(&me->pdata, cd_mtexpoly, me->totpoly);
947                                         BKE_mesh_update_customdata_pointers(me, false);
948                                 }
949                         }
950                 }
951         }
952
953         if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) {
954                 if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "cascade_max_dist")) {
955                         for (Light *la = bmain->lights.first; la; la = la->id.next) {
956                                 la->cascade_max_dist = 1000.0f;
957                                 la->cascade_count = 4;
958                                 la->cascade_exponent = 0.8f;
959                                 la->cascade_fade = 0.1f;
960                         }
961                 }
962
963                 if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "contact_dist")) {
964                         for (Light *la = bmain->lights.first; la; la = la->id.next) {
965                                 la->contact_dist = 0.2f;
966                                 la->contact_bias = 0.03f;
967                                 la->contact_spread = 0.2f;
968                                 la->contact_thickness = 0.2f;
969                         }
970                 }
971
972                 if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "vis_bias")) {
973                         for (LightProbe *probe = bmain->lightprobes.first; probe; probe = probe->id.next) {
974                                 probe->vis_bias = 1.0f;
975                                 probe->vis_blur = 0.2f;
976                         }
977                 }
978
979                 typedef enum eNTreeDoVersionErrors {
980                         NTREE_DOVERSION_NO_ERROR = 0,
981                         NTREE_DOVERSION_NEED_OUTPUT = (1 << 0),
982                         NTREE_DOVERSION_TRANSPARENCY_EMISSION = (1 << 1),
983                 } eNTreeDoVersionErrors;
984
985                 /* Eevee shader nodes renamed because of the output node system.
986                  * Note that a new output node is not being added here, because it would be overkill
987                  * to handle this case in lib_verify_nodetree.
988                  *
989                  * Also, metallic node is now unified into the principled node. */
990                 eNTreeDoVersionErrors error = NTREE_DOVERSION_NO_ERROR;
991
992                 FOREACH_NODETREE_BEGIN(bmain, ntree, id) {
993                         if (ntree->type == NTREE_SHADER) {
994                                 for (bNode *node = ntree->nodes.first; node; node = node->next) {
995                                         if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
996                                             STREQ(node->idname, "ShaderNodeOutputMetallic"))
997                                         {
998                                                 BLI_strncpy(node->idname, "ShaderNodeEeveeMetallic", sizeof(node->idname));
999                                                 error |= NTREE_DOVERSION_NEED_OUTPUT;
1000                                         }
1001
1002                                         else if (node->type == SH_NODE_EEVEE_SPECULAR && STREQ(node->idname, "ShaderNodeOutputSpecular")) {
1003                                                 BLI_strncpy(node->idname, "ShaderNodeEeveeSpecular", sizeof(node->idname));
1004                                                 error |= NTREE_DOVERSION_NEED_OUTPUT;
1005                                         }
1006
1007                                         else if (node->type == 196 /* SH_NODE_OUTPUT_EEVEE_MATERIAL */ &&
1008                                                  STREQ(node->idname, "ShaderNodeOutputEeveeMaterial"))
1009                                         {
1010                                                 node->type = SH_NODE_OUTPUT_MATERIAL;
1011                                                 BLI_strncpy(node->idname, "ShaderNodeOutputMaterial", sizeof(node->idname));
1012                                         }
1013
1014                                         else if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
1015                                                  STREQ(node->idname, "ShaderNodeEeveeMetallic"))
1016                                         {
1017                                                 node->type = SH_NODE_BSDF_PRINCIPLED;
1018                                                 BLI_strncpy(node->idname, "ShaderNodeBsdfPrincipled", sizeof(node->idname));
1019                                                 node->custom1 = SHD_GLOSSY_MULTI_GGX;
1020                                                 error |= NTREE_DOVERSION_TRANSPARENCY_EMISSION;
1021                                         }
1022                                 }
1023                         }
1024                 } FOREACH_NODETREE_END;
1025
1026                 if (error & NTREE_DOVERSION_NEED_OUTPUT) {
1027                         BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
1028                         printf("You need to connect Principled and Eevee Specular shader nodes to new material output nodes.\n");
1029                 }
1030
1031                 if (error & NTREE_DOVERSION_TRANSPARENCY_EMISSION) {
1032                         BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
1033                         printf("You need to combine transparency and emission shaders to the converted Principled shader nodes.\n");
1034                 }
1035
1036 #ifdef USE_COLLECTION_COMPAT_28
1037                 if (use_collection_compat_28 &&
1038                     (DNA_struct_elem_find(fd->filesdna, "ViewLayer", "FreestyleConfig", "freestyle_config") == false) &&
1039                     DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers"))
1040                 {
1041                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1042                                 ViewLayer *view_layer;
1043                                 for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
1044                                         view_layer->flag |= VIEW_LAYER_FREESTYLE;
1045                                         view_layer->layflag = 0x7FFF;   /* solid ztra halo edge strand */
1046                                         view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
1047                                         view_layer->pass_alpha_threshold = 0.5f;
1048                                         BKE_freestyle_config_init(&view_layer->freestyle_config);
1049                                 }
1050                         }
1051                 }
1052 #endif
1053
1054                 {
1055                         /* Grease pencil sculpt and paint cursors */
1056                         if (!DNA_struct_elem_find(fd->filesdna, "GP_Sculpt_Settings", "int", "weighttype")) {
1057                                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1058                                         /* sculpt brushes */
1059                                         GP_Sculpt_Settings *gset = &scene->toolsettings->gp_sculpt;
1060                                         if (gset) {
1061                                                 gset->weighttype = GP_SCULPT_TYPE_WEIGHT;
1062                                         }
1063                                 }
1064                         }
1065
1066                         {
1067                                 float curcolor_add[3], curcolor_sub[3];
1068                                 ARRAY_SET_ITEMS(curcolor_add, 1.0f, 0.6f, 0.6f);
1069                                 ARRAY_SET_ITEMS(curcolor_sub, 0.6f, 0.6f, 1.0f);
1070                                 GP_Sculpt_Data *gp_brush;
1071
1072                                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1073                                         ToolSettings *ts = scene->toolsettings;
1074                                         /* sculpt brushes */
1075                                         GP_Sculpt_Settings *gset = &ts->gp_sculpt;
1076                                         for (int i = 0; i < GP_SCULPT_TYPE_MAX; ++i) {
1077                                                 gp_brush = &gset->brush[i];
1078                                                 gp_brush->flag |= GP_SCULPT_FLAG_ENABLE_CURSOR;
1079                                                 copy_v3_v3(gp_brush->curcolor_add, curcolor_add);
1080                                                 copy_v3_v3(gp_brush->curcolor_sub, curcolor_sub);
1081                                         }
1082                                 }
1083                         }
1084
1085                         /* Init grease pencil edit line color */
1086                         if (!DNA_struct_elem_find(fd->filesdna, "bGPdata", "float", "line_color[4]")) {
1087                                 for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
1088                                         ARRAY_SET_ITEMS(gpd->line_color, 0.6f, 0.6f, 0.6f, 0.5f);
1089                                 }
1090                         }
1091
1092                         /* Init grease pencil pixel size factor */
1093                         if (!DNA_struct_elem_find(fd->filesdna, "bGPdata", "int", "pixfactor")) {
1094                                 for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
1095                                         gpd->pixfactor = GP_DEFAULT_PIX_FACTOR;
1096                                 }
1097                         }
1098
1099                         /* Grease pencil multiframe falloff curve */
1100                         if (!DNA_struct_elem_find(fd->filesdna, "GP_Sculpt_Settings", "CurveMapping", "cur_falloff")) {
1101                                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1102                                         /* sculpt brushes */
1103                                         GP_Sculpt_Settings *gset = &scene->toolsettings->gp_sculpt;
1104                                         if ((gset) && (gset->cur_falloff == NULL)) {
1105                                                 gset->cur_falloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
1106                                                 curvemapping_initialize(gset->cur_falloff);
1107                                                 curvemap_reset(gset->cur_falloff->cm,
1108                                                                &gset->cur_falloff->clipr,
1109                                                                CURVE_PRESET_GAUSS,
1110                                                                CURVEMAP_SLOPE_POSITIVE);
1111                                         }
1112                                 }
1113                         }
1114                 }
1115         }
1116
1117 #ifdef USE_COLLECTION_COMPAT_28
1118         if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
1119                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1120                         ViewLayer *view_layer;
1121                         for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
1122                                 do_version_view_layer_visibility(view_layer);
1123                         }
1124                 }
1125
1126                 for (Collection *group = bmain->collections.first; group; group = group->id.next) {
1127                         if (group->view_layer != NULL) {
1128                                 do_version_view_layer_visibility(group->view_layer);
1129                         }
1130                 }
1131         }
1132 #endif
1133
1134         if (!MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
1135                 /* init grease pencil grids and paper */
1136                 if (!DNA_struct_elem_find(fd->filesdna, "gp_paper_opacity", "float", "gpencil_paper_color[3]")) {
1137                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1138                                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
1139                                         for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) {
1140                                                 if (sl->spacetype == SPACE_VIEW3D) {
1141                                                         View3D *v3d = (View3D *)sl;
1142                                                         v3d->overlay.gpencil_paper_opacity = 0.5f;
1143                                                         v3d->overlay.gpencil_grid_opacity = 0.9f;
1144                                                 }
1145                                         }
1146                                 }
1147                         }
1148                 }
1149         }
1150
1151         if (!MAIN_VERSION_ATLEAST(bmain, 280, 6)) {
1152                 if (DNA_struct_elem_find(fd->filesdna, "SpaceOutliner", "int", "filter") == false) {
1153                         bScreen *sc;
1154                         ScrArea *sa;
1155                         SpaceLink *sl;
1156
1157                         /* Update files using invalid (outdated) outlinevis Outliner values. */
1158                         for (sc = bmain->screens.first; sc; sc = sc->id.next) {
1159                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
1160                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
1161                                                 if (sl->spacetype == SPACE_OUTLINER) {
1162                                                         SpaceOutliner *so = (SpaceOutliner *)sl;
1163
1164                                                         if (!ELEM(so->outlinevis,
1165                                                                   SO_SCENES,
1166                                                                   SO_LIBRARIES,
1167                                                                   SO_SEQUENCE,
1168                                                                   SO_DATA_API,
1169                                                                   SO_ID_ORPHANS))
1170                                                         {
1171                                                                 so->outlinevis = SO_VIEW_LAYER;
1172                                                         }
1173                                                 }
1174                                         }
1175                                 }
1176                         }
1177                 }
1178
1179                 if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "intensity")) {
1180                         for (LightProbe *probe = bmain->lightprobes.first; probe; probe = probe->id.next) {
1181                                 probe->intensity = 1.0f;
1182                         }
1183                 }
1184
1185                 for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
1186                         bConstraint *con, *con_next;
1187                         con = ob->constraints.first;
1188                         while (con) {
1189                                 con_next = con->next;
1190                                 if (con->type == 17) { /* CONSTRAINT_TYPE_RIGIDBODYJOINT */
1191                                         BLI_remlink(&ob->constraints, con);
1192                                         BKE_constraint_free_data(con);
1193                                         MEM_freeN(con);
1194                                 }
1195                                 con = con_next;
1196                         }
1197                 }
1198
1199                 for (bScreen *sc = bmain->screens.first; sc; sc = sc->id.next) {
1200                         for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
1201                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1202                                         if (sl->spacetype == SPACE_VIEW3D) {
1203                                                 View3D *v3d = (View3D *)sl;
1204                                                 v3d->shading.light = V3D_LIGHTING_STUDIO;
1205                                                 v3d->shading.flag |= V3D_SHADING_OBJECT_OUTLINE;
1206
1207                                                 /* Assume (demo) files written with 2.8 want to show
1208                                                  * Eevee renders in the viewport. */
1209                                                 if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
1210                                                         v3d->drawtype = OB_MATERIAL;
1211                                                 }
1212                                         }
1213                                 }
1214                         }
1215                 }
1216         }
1217
1218         if (!MAIN_VERSION_ATLEAST(bmain, 280, 7)) {
1219                 /* Render engine storage moved elsewhere and back during 2.8
1220                  * development, we assume any files saved in 2.8 had Eevee set
1221                  * as scene render engine. */
1222                 if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
1223                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1224                                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
1225                         }
1226                 }
1227         }
1228
1229         if (!MAIN_VERSION_ATLEAST(bmain, 280, 8)) {
1230                 /* Blender Internal removal */
1231                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1232                         if (STREQ(scene->r.engine, "BLENDER_RENDER") ||
1233                             STREQ(scene->r.engine, "BLENDER_GAME"))
1234                         {
1235                                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
1236                         }
1237
1238                         scene->r.bake_mode = 0;
1239                 }
1240
1241                 for (Tex *tex = bmain->textures.first; tex; tex = tex->id.next) {
1242                         /* Removed envmap, pointdensity, voxeldata, ocean textures. */
1243                         if (ELEM(tex->type, 10, 14, 15, 16)) {
1244                                 tex->type = 0;
1245                         }
1246                 }
1247
1248         }
1249
1250         if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) {
1251
1252                 /* Remove info editor, but only if at the top of the window. */
1253                 for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1254                         /* Calculate window width/height from screen vertices */
1255                         int win_width = 0, win_height = 0;
1256                         for (ScrVert *vert = screen->vertbase.first; vert; vert = vert->next) {
1257                                 win_width  = MAX2(win_width, vert->vec.x);
1258                                 win_height = MAX2(win_height, vert->vec.y);
1259                         }
1260
1261                         for (ScrArea *area = screen->areabase.first, *area_next; area; area = area_next) {
1262                                 area_next = area->next;
1263
1264                                 if (area->spacetype == SPACE_INFO) {
1265                                         if ((area->v2->vec.y == win_height) && (area->v1->vec.x == 0) && (area->v4->vec.x == win_width)) {
1266                                                 BKE_screen_area_free(area);
1267
1268                                                 BLI_remlink(&screen->areabase, area);
1269
1270                                                 BKE_screen_remove_double_scredges(screen);
1271                                                 BKE_screen_remove_unused_scredges(screen);
1272                                                 BKE_screen_remove_unused_scrverts(screen);
1273
1274                                                 MEM_freeN(area);
1275                                         }
1276                                 }
1277                                 /* AREA_TEMP_INFO is deprecated from now on, it should only be set for info areas
1278                                  * which are deleted above, so don't need to unset it. Its slot/bit can be reused */
1279                         }
1280                 }
1281         }
1282
1283         if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) {
1284                 for (Light *la = bmain->lights.first; la; la = la->id.next) {
1285                         if (la->mode & (1 << 13)) { /* LA_SHAD_RAY */
1286                                 la->mode |= LA_SHADOW;
1287                                 la->mode &= ~(1 << 13);
1288                         }
1289                 }
1290         }
1291
1292         if (!MAIN_VERSION_ATLEAST(bmain, 280, 12)) {
1293                 /* Remove tool property regions. */
1294                 for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1295                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1296                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1297                                         if (ELEM(sl->spacetype, SPACE_VIEW3D, SPACE_CLIP)) {
1298                                                 ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1299
1300                                                 for (ARegion *region = regionbase->first, *region_next; region; region = region_next) {
1301                                                         region_next = region->next;
1302
1303                                                         if (region->regiontype == RGN_TYPE_TOOL_PROPS) {
1304                                                                 BKE_area_region_free(NULL, region);
1305                                                                 BLI_freelinkN(regionbase, region);
1306                                                         }
1307                                                 }
1308                                         }
1309                                 }
1310                         }
1311                 }
1312         }
1313
1314         if (!MAIN_VERSION_ATLEAST(bmain, 280, 13)) {
1315                 /* Initialize specular factor. */
1316                 if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "spec_fac")) {
1317                         for (Light *la = bmain->lights.first; la; la = la->id.next) {
1318                                 la->spec_fac = 1.0f;
1319                         }
1320                 }
1321
1322                 /* Initialize new view3D options. */
1323                 for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1324                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1325                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1326                                         if (sl->spacetype == SPACE_VIEW3D) {
1327                                                 View3D *v3d = (View3D *)sl;
1328                                                 v3d->shading.light = V3D_LIGHTING_STUDIO;
1329                                                 v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR;
1330                                                 copy_v3_fl(v3d->shading.single_color, 0.8f);
1331                                                 v3d->shading.shadow_intensity = 0.5;
1332
1333                                                 v3d->overlay.backwire_opacity = 0.5f;
1334                                                 v3d->overlay.normals_length = 0.1f;
1335                                                 v3d->overlay.flag = 0;
1336                                         }
1337                                 }
1338                         }
1339                 }
1340         }
1341
1342         if (!MAIN_VERSION_ATLEAST(bmain, 280, 14)) {
1343                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "SceneDisplay", "display")) {
1344                         /* Initialize new scene.SceneDisplay */
1345                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1346                                 copy_v3_v3(scene->display.light_direction, (float[3]){-M_SQRT1_3, -M_SQRT1_3, M_SQRT1_3});
1347                         }
1348                 }
1349                 if (!DNA_struct_elem_find(fd->filesdna, "SceneDisplay", "float", "shadow_shift")) {
1350                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1351                                 scene->display.shadow_shift = 0.1;
1352                         }
1353                 }
1354
1355                 if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "transform_pivot_point")) {
1356                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1357                                 scene->toolsettings->transform_pivot_point = V3D_AROUND_CENTER_MEDIAN;
1358                         }
1359                 }
1360
1361                 if (!DNA_struct_find(fd->filesdna, "SceneEEVEE")) {
1362                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1363                                 /* First set the default for all the properties. */
1364
1365                                 scene->eevee.gi_diffuse_bounces = 3;
1366                                 scene->eevee.gi_cubemap_resolution = 512;
1367                                 scene->eevee.gi_visibility_resolution = 32;
1368
1369                                 scene->eevee.taa_samples = 16;
1370                                 scene->eevee.taa_render_samples = 64;
1371
1372                                 scene->eevee.sss_samples = 7;
1373                                 scene->eevee.sss_jitter_threshold = 0.3f;
1374
1375                                 scene->eevee.ssr_quality = 0.25f;
1376                                 scene->eevee.ssr_max_roughness = 0.5f;
1377                                 scene->eevee.ssr_thickness = 0.2f;
1378                                 scene->eevee.ssr_border_fade = 0.075f;
1379                                 scene->eevee.ssr_firefly_fac = 10.0f;
1380
1381                                 scene->eevee.volumetric_start = 0.1f;
1382                                 scene->eevee.volumetric_end = 100.0f;
1383                                 scene->eevee.volumetric_tile_size = 8;
1384                                 scene->eevee.volumetric_samples = 64;
1385                                 scene->eevee.volumetric_sample_distribution = 0.8f;
1386                                 scene->eevee.volumetric_light_clamp = 0.0f;
1387                                 scene->eevee.volumetric_shadow_samples = 16;
1388
1389                                 scene->eevee.gtao_distance = 0.2f;
1390                                 scene->eevee.gtao_factor = 1.0f;
1391                                 scene->eevee.gtao_quality = 0.25f;
1392
1393                                 scene->eevee.bokeh_max_size = 100.0f;
1394                                 scene->eevee.bokeh_threshold = 1.0f;
1395
1396                                 copy_v3_fl(scene->eevee.bloom_color, 1.0f);
1397                                 scene->eevee.bloom_threshold = 0.8f;
1398                                 scene->eevee.bloom_knee = 0.5f;
1399                                 scene->eevee.bloom_intensity = 0.05f;
1400                                 scene->eevee.bloom_radius = 6.5f;
1401                                 scene->eevee.bloom_clamp = 0.0f;
1402
1403                                 scene->eevee.motion_blur_samples = 8;
1404                                 scene->eevee.motion_blur_shutter = 0.5f;
1405
1406                                 scene->eevee.shadow_method = SHADOW_ESM;
1407                                 scene->eevee.shadow_cube_size = 512;
1408                                 scene->eevee.shadow_cascade_size = 1024;
1409
1410                                 scene->eevee.flag =
1411                                         SCE_EEVEE_VOLUMETRIC_LIGHTS |
1412                                         SCE_EEVEE_GTAO_BENT_NORMALS |
1413                                         SCE_EEVEE_GTAO_BOUNCE |
1414                                         SCE_EEVEE_TAA_REPROJECTION |
1415                                         SCE_EEVEE_SSR_HALF_RESOLUTION;
1416
1417
1418                                 /* If the file is pre-2.80 move on. */
1419                                 if (scene->layer_properties == NULL) {
1420                                         continue;
1421                                 }
1422
1423                                 /* Now we handle eventual properties that may be set in the file. */
1424 #define EEVEE_GET_BOOL(_props, _name, _flag) \
1425                                 { \
1426                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1427                                         if (_idprop != NULL) { \
1428                                                 const int _value = IDP_Int(_idprop); \
1429                                                 if (_value) { \
1430                                                         scene->eevee.flag |= _flag; \
1431                                                 } \
1432                                                 else { \
1433                                                         scene->eevee.flag &= ~_flag; \
1434                                                 } \
1435                                         } \
1436                                 }
1437
1438 #define EEVEE_GET_INT(_props, _name) \
1439                                 { \
1440                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1441                                         if (_idprop != NULL) { \
1442                                                 scene->eevee._name = IDP_Int(_idprop); \
1443                                         } \
1444                                 }
1445
1446 #define EEVEE_GET_FLOAT(_props, _name) \
1447                                 { \
1448                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1449                                         if (_idprop != NULL) { \
1450                                                 scene->eevee._name = IDP_Float(_idprop); \
1451                                         } \
1452                                 }
1453
1454 #define EEVEE_GET_FLOAT_ARRAY(_props, _name, _length) \
1455                                 { \
1456                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1457                                         if (_idprop != NULL) { \
1458                                                 const float *_values = IDP_Array(_idprop); \
1459                                                 for (int _i = 0; _i < _length; _i++) { \
1460                                                         scene->eevee._name [_i] = _values[_i]; \
1461                                                 } \
1462                                         } \
1463                                 }
1464
1465                                 IDProperty *props = IDP_GetPropertyFromGroup(scene->layer_properties, RE_engine_id_BLENDER_EEVEE);
1466                                 EEVEE_GET_BOOL(props, volumetric_enable, SCE_EEVEE_VOLUMETRIC_ENABLED);
1467                                 EEVEE_GET_BOOL(props, volumetric_lights, SCE_EEVEE_VOLUMETRIC_LIGHTS);
1468                                 EEVEE_GET_BOOL(props, volumetric_shadows, SCE_EEVEE_VOLUMETRIC_SHADOWS);
1469                                 EEVEE_GET_BOOL(props, gtao_enable, SCE_EEVEE_GTAO_ENABLED);
1470                                 EEVEE_GET_BOOL(props, gtao_use_bent_normals, SCE_EEVEE_GTAO_BENT_NORMALS);
1471                                 EEVEE_GET_BOOL(props, gtao_bounce, SCE_EEVEE_GTAO_BOUNCE);
1472                                 EEVEE_GET_BOOL(props, dof_enable, SCE_EEVEE_DOF_ENABLED);
1473                                 EEVEE_GET_BOOL(props, bloom_enable, SCE_EEVEE_BLOOM_ENABLED);
1474                                 EEVEE_GET_BOOL(props, motion_blur_enable, SCE_EEVEE_MOTION_BLUR_ENABLED);
1475                                 EEVEE_GET_BOOL(props, shadow_high_bitdepth, SCE_EEVEE_SHADOW_HIGH_BITDEPTH);
1476                                 EEVEE_GET_BOOL(props, taa_reprojection, SCE_EEVEE_TAA_REPROJECTION);
1477                                 EEVEE_GET_BOOL(props, sss_enable, SCE_EEVEE_SSS_ENABLED);
1478                                 EEVEE_GET_BOOL(props, sss_separate_albedo, SCE_EEVEE_SSS_SEPARATE_ALBEDO);
1479                                 EEVEE_GET_BOOL(props, ssr_enable, SCE_EEVEE_SSR_ENABLED);
1480                                 EEVEE_GET_BOOL(props, ssr_refraction, SCE_EEVEE_SSR_REFRACTION);
1481                                 EEVEE_GET_BOOL(props, ssr_halfres, SCE_EEVEE_SSR_HALF_RESOLUTION);
1482
1483                                 EEVEE_GET_INT(props, gi_diffuse_bounces);
1484                                 EEVEE_GET_INT(props, gi_diffuse_bounces);
1485                                 EEVEE_GET_INT(props, gi_cubemap_resolution);
1486                                 EEVEE_GET_INT(props, gi_visibility_resolution);
1487
1488                                 EEVEE_GET_INT(props, taa_samples);
1489                                 EEVEE_GET_INT(props, taa_render_samples);
1490
1491                                 EEVEE_GET_INT(props, sss_samples);
1492                                 EEVEE_GET_FLOAT(props, sss_jitter_threshold);
1493
1494                                 EEVEE_GET_FLOAT(props, ssr_quality);
1495                                 EEVEE_GET_FLOAT(props, ssr_max_roughness);
1496                                 EEVEE_GET_FLOAT(props, ssr_thickness);
1497                                 EEVEE_GET_FLOAT(props, ssr_border_fade);
1498                                 EEVEE_GET_FLOAT(props, ssr_firefly_fac);
1499
1500                                 EEVEE_GET_FLOAT(props, volumetric_start);
1501                                 EEVEE_GET_FLOAT(props, volumetric_end);
1502                                 EEVEE_GET_INT(props, volumetric_tile_size);
1503                                 EEVEE_GET_INT(props, volumetric_samples);
1504                                 EEVEE_GET_FLOAT(props, volumetric_sample_distribution);
1505                                 EEVEE_GET_FLOAT(props, volumetric_light_clamp);
1506                                 EEVEE_GET_INT(props, volumetric_shadow_samples);
1507
1508                                 EEVEE_GET_FLOAT(props, gtao_distance);
1509                                 EEVEE_GET_FLOAT(props, gtao_factor);
1510                                 EEVEE_GET_FLOAT(props, gtao_quality);
1511
1512                                 EEVEE_GET_FLOAT(props, bokeh_max_size);
1513                                 EEVEE_GET_FLOAT(props, bokeh_threshold);
1514
1515                                 EEVEE_GET_FLOAT_ARRAY(props, bloom_color, 3);
1516                                 EEVEE_GET_FLOAT(props, bloom_threshold);
1517                                 EEVEE_GET_FLOAT(props, bloom_knee);
1518                                 EEVEE_GET_FLOAT(props, bloom_intensity);
1519                                 EEVEE_GET_FLOAT(props, bloom_radius);
1520                                 EEVEE_GET_FLOAT(props, bloom_clamp);
1521
1522                                 EEVEE_GET_INT(props, motion_blur_samples);
1523                                 EEVEE_GET_FLOAT(props, motion_blur_shutter);
1524
1525                                 EEVEE_GET_INT(props, shadow_method);
1526                                 EEVEE_GET_INT(props, shadow_cube_size);
1527                                 EEVEE_GET_INT(props, shadow_cascade_size);
1528
1529                                 /* Cleanup. */
1530                                 IDP_FreeProperty(scene->layer_properties);
1531                                 MEM_freeN(scene->layer_properties);
1532                                 scene->layer_properties = NULL;
1533
1534 #undef EEVEE_GET_FLOAT_ARRAY
1535 #undef EEVEE_GET_FLOAT
1536 #undef EEVEE_GET_INT
1537 #undef EEVEE_GET_BOOL
1538                         }
1539                 }
1540
1541
1542                 if (!MAIN_VERSION_ATLEAST(bmain, 280, 15)) {
1543                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1544                                 scene->display.matcap_ssao_distance = 0.2f;
1545                                 scene->display.matcap_ssao_attenuation = 1.0f;
1546                                 scene->display.matcap_ssao_samples = 16;
1547                         }
1548
1549                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1550                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1551                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1552                                                 if (sl->spacetype == SPACE_OUTLINER) {
1553                                                         SpaceOutliner *soops = (SpaceOutliner *)sl;
1554                                                         soops->filter_id_type = ID_GR;
1555                                                         soops->outlinevis = SO_VIEW_LAYER;
1556                                                 }
1557                                         }
1558                                 }
1559                         }
1560
1561                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1562                                 switch (scene->toolsettings->snap_mode) {
1563                                         case 0: scene->toolsettings->snap_mode = SCE_SNAP_MODE_INCREMENT; break;
1564                                         case 1: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VERTEX   ; break;
1565                                         case 2: scene->toolsettings->snap_mode = SCE_SNAP_MODE_EDGE     ; break;
1566                                         case 3: scene->toolsettings->snap_mode = SCE_SNAP_MODE_FACE     ; break;
1567                                         case 4: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VOLUME   ; break;
1568                                 }
1569                                 switch (scene->toolsettings->snap_node_mode) {
1570                                         case 5: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X; break;
1571                                         case 6: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_Y; break;
1572                                         case 7: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X | SCE_SNAP_MODE_NODE_Y; break;
1573                                         case 8: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID  ; break;
1574                                 }
1575                                 switch (scene->toolsettings->snap_uv_mode) {
1576                                         case 0: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_INCREMENT; break;
1577                                         case 1: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_VERTEX   ; break;
1578                                 }
1579                         }
1580
1581                         ParticleSettings *part;
1582                         for (part = bmain->particles.first; part; part = part->id.next) {
1583                                 part->shape_flag = PART_SHAPE_CLOSE_TIP;
1584                                 part->shape = 0.0f;
1585                                 part->rad_root = 1.0f;
1586                                 part->rad_tip = 0.0f;
1587                                 part->rad_scale = 0.01f;
1588                         }
1589                 }
1590
1591         }
1592
1593         if (!MAIN_VERSION_ATLEAST(bmain, 280, 18)) {
1594                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "roughness")) {
1595                         for (Material *mat = bmain->materials.first; mat; mat = mat->id.next) {
1596                                 if (mat->use_nodes) {
1597                                         if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
1598                                                 mat->roughness = mat->gloss_mir;
1599                                         }
1600                                         else {
1601                                                 mat->roughness = 0.25f;
1602                                         }
1603                                 }
1604                                 else {
1605                                         mat->roughness = 1.0f - mat->gloss_mir;
1606                                 }
1607                                 mat->metallic = mat->ray_mirror;
1608                         }
1609
1610                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1611                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1612                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1613                                                 if (sl->spacetype == SPACE_VIEW3D) {
1614                                                         View3D *v3d = (View3D *)sl;
1615                                                         v3d->shading.flag |= V3D_SHADING_SPECULAR_HIGHLIGHT;
1616                                                 }
1617                                         }
1618                                 }
1619                         }
1620                 }
1621
1622                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "xray_alpha")) {
1623                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1624                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1625                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1626                                                 if (sl->spacetype == SPACE_VIEW3D) {
1627                                                         View3D *v3d = (View3D *)sl;
1628                                                         v3d->shading.xray_alpha = 0.5f;
1629                                                 }
1630                                         }
1631                                 }
1632                         }
1633                 }
1634                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "char", "matcap[256]")) {
1635                         StudioLight *default_matcap = BKE_studiolight_find_default(STUDIOLIGHT_TYPE_MATCAP);
1636                         /* when loading the internal file is loaded before the matcaps */
1637                         if (default_matcap) {
1638                                 for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1639                                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1640                                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1641                                                         if (sl->spacetype == SPACE_VIEW3D) {
1642                                                                 View3D *v3d = (View3D *)sl;
1643                                                                 BLI_strncpy(v3d->shading.matcap, default_matcap->name, FILE_MAXFILE);
1644                                                         }
1645                                                 }
1646                                         }
1647                                 }
1648                         }
1649                 }
1650                 if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "wireframe_threshold")) {
1651                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1652                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1653                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1654                                                 if (sl->spacetype == SPACE_VIEW3D) {
1655                                                         View3D *v3d = (View3D *)sl;
1656                                                         v3d->overlay.wireframe_threshold = 0.5f;
1657                                                 }
1658                                         }
1659                                 }
1660                         }
1661                 }
1662                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "cavity_valley_factor")) {
1663                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1664                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1665                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1666                                                 if (sl->spacetype == SPACE_VIEW3D) {
1667                                                         View3D *v3d = (View3D *)sl;
1668                                                         v3d->shading.cavity_valley_factor = 1.0f;
1669                                                         v3d->shading.cavity_ridge_factor = 1.0f;
1670                                                 }
1671                                         }
1672                                 }
1673                         }
1674                 }
1675                 if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "xray_alpha_bone")) {
1676                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1677                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1678                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1679                                                 if (sl->spacetype == SPACE_VIEW3D) {
1680                                                         View3D *v3d = (View3D *)sl;
1681                                                         v3d->overlay.xray_alpha_bone = 0.5f;
1682                                                 }
1683                                         }
1684                                 }
1685                         }
1686                 }
1687         }
1688
1689         if (!MAIN_VERSION_ATLEAST(bmain, 280, 19)) {
1690                 if (!DNA_struct_elem_find(fd->filesdna, "Image", "ListBase", "renderslot")) {
1691                         for (Image *ima = bmain->images.first; ima; ima = ima->id.next) {
1692                                 if (ima->type == IMA_TYPE_R_RESULT) {
1693                                         for (int i = 0; i < 8; i++) {
1694                                                 RenderSlot *slot = MEM_callocN(sizeof(RenderSlot), "Image Render Slot Init");
1695                                                 BLI_snprintf(slot->name, sizeof(slot->name), "Slot %d", i + 1);
1696                                                 BLI_addtail(&ima->renderslots, slot);
1697                                         }
1698                                 }
1699                         }
1700                 }
1701                 if (!DNA_struct_elem_find(fd->filesdna, "SpaceAction", "char", "mode_prev")) {
1702                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1703                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1704                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1705                                                 if (sl->spacetype == SPACE_ACTION) {
1706                                                         SpaceAction *saction = (SpaceAction *)sl;
1707                                                         /* "Dopesheet" should be default here, unless it looks like the Action Editor was active instead */
1708                                                         if ((saction->mode_prev == 0) && (saction->action == NULL)) {
1709                                                                 saction->mode_prev = SACTCONT_DOPESHEET;
1710                                                         }
1711                                                 }
1712                                         }
1713                                 }
1714                         }
1715                 }
1716
1717                 for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1718                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1719                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1720                                         if (sl->spacetype == SPACE_VIEW3D) {
1721                                                 View3D *v3d = (View3D *)sl;
1722                                                 if (v3d->drawtype == OB_TEXTURE) {
1723                                                         v3d->drawtype = OB_SOLID;
1724                                                         v3d->shading.light = V3D_LIGHTING_STUDIO;
1725                                                         v3d->shading.color_type = V3D_SHADING_TEXTURE_COLOR;
1726                                                 }
1727                                         }
1728                                 }
1729                         }
1730                 }
1731
1732         }
1733
1734         if (!MAIN_VERSION_ATLEAST(bmain, 280, 21)) {
1735                 for (Scene *sce = bmain->scenes.first; sce != NULL; sce = sce->id.next) {
1736                         if (sce->ed != NULL && sce->ed->seqbase.first != NULL) {
1737                                 do_versions_seq_unique_name_all_strips(sce, &sce->ed->seqbase);
1738                         }
1739                 }
1740
1741                 if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "texture_paint_mode_opacity")) {
1742                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1743                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1744                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1745                                                 if (sl->spacetype == SPACE_VIEW3D) {
1746                                                         enum { V3D_SHOW_MODE_SHADE_OVERRIDE = (1 << 15), };
1747                                                         View3D *v3d = (View3D *)sl;
1748                                                         float alpha = v3d->flag2 & V3D_SHOW_MODE_SHADE_OVERRIDE ? 0.0f : 1.0f;
1749                                                         v3d->overlay.texture_paint_mode_opacity = alpha;
1750                                                         v3d->overlay.vertex_paint_mode_opacity = alpha;
1751                                                         v3d->overlay.weight_paint_mode_opacity = alpha;
1752                                                 }
1753                                         }
1754                                 }
1755                         }
1756                 }
1757
1758                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "char", "background_type")) {
1759                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1760                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1761                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1762                                                 if (sl->spacetype == SPACE_VIEW3D) {
1763                                                         View3D *v3d = (View3D *)sl;
1764                                                         copy_v3_fl(v3d->shading.background_color, 0.05f);
1765                                                 }
1766                                         }
1767                                 }
1768                         }
1769                 }
1770
1771                 if (!DNA_struct_elem_find(fd->filesdna, "SceneEEVEE", "float", "gi_cubemap_draw_size")) {
1772                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1773                                 scene->eevee.gi_irradiance_draw_size = 0.1f;
1774                                 scene->eevee.gi_cubemap_draw_size = 0.3f;
1775                         }
1776                 }
1777
1778                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1779                         if (scene->toolsettings->gizmo_flag == 0) {
1780                                 scene->toolsettings->gizmo_flag = SCE_GIZMO_SHOW_TRANSLATE | SCE_GIZMO_SHOW_ROTATE | SCE_GIZMO_SHOW_SCALE;
1781                         }
1782                 }
1783
1784                 if (!DNA_struct_elem_find(fd->filesdna, "RigidBodyWorld", "RigidBodyWorld_Shared", "*shared")) {
1785                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1786                                 RigidBodyWorld *rbw = scene->rigidbody_world;
1787
1788                                 if (rbw == NULL) {
1789                                         continue;
1790                                 }
1791
1792                                 if (rbw->shared == NULL) {
1793                                         rbw->shared = MEM_callocN(sizeof(*rbw->shared), "RigidBodyWorld_Shared");
1794                                 }
1795
1796                                 /* Move shared pointers from deprecated location to current location */
1797                                 rbw->shared->pointcache = rbw->pointcache;
1798                                 rbw->shared->ptcaches = rbw->ptcaches;
1799
1800                                 rbw->pointcache = NULL;
1801                                 BLI_listbase_clear(&rbw->ptcaches);
1802
1803                                 if (rbw->shared->pointcache == NULL) {
1804                                         rbw->shared->pointcache = BKE_ptcache_add(&(rbw->shared->ptcaches));
1805                                 }
1806
1807                         }
1808                 }
1809
1810                 if (!DNA_struct_elem_find(fd->filesdna, "SoftBody", "SoftBody_Shared", "*shared")) {
1811                         for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
1812                                 SoftBody *sb = ob->soft;
1813                                 if (sb == NULL) {
1814                                         continue;
1815                                 }
1816                                 if (sb->shared == NULL) {
1817                                         sb->shared = MEM_callocN(sizeof(*sb->shared), "SoftBody_Shared");
1818                                 }
1819
1820                                 /* Move shared pointers from deprecated location to current location */
1821                                 sb->shared->pointcache = sb->pointcache;
1822                                 sb->shared->ptcaches = sb->ptcaches;
1823
1824                                 sb->pointcache = NULL;
1825                                 BLI_listbase_clear(&sb->ptcaches);
1826                         }
1827                 }
1828
1829                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "short", "type")) {
1830                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1831                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1832                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1833                                                 if (sl->spacetype == SPACE_VIEW3D) {
1834                                                         View3D *v3d = (View3D *)sl;
1835                                                         if (v3d->drawtype == OB_RENDER) {
1836                                                                 v3d->drawtype = OB_SOLID;
1837                                                         }
1838                                                         v3d->shading.type = v3d->drawtype;
1839                                                         v3d->shading.prev_type = OB_SOLID;
1840                                                 }
1841                                         }
1842                                 }
1843                         }
1844                 }
1845
1846                 if (!DNA_struct_elem_find(fd->filesdna, "SceneDisplay", "View3DShading", "shading")) {
1847                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1848                                 BKE_screen_view3d_shading_init(&scene->display.shading);
1849                         }
1850                 }
1851                 /* initialize grease pencil view data */
1852                 if (!DNA_struct_elem_find(fd->filesdna, "SpaceView3D", "float", "vertex_opacity")) {
1853                         for (bScreen *sc = bmain->screens.first; sc; sc = sc->id.next) {
1854                                 for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
1855                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1856                                                 if (sl->spacetype == SPACE_VIEW3D) {
1857                                                         View3D *v3d = (View3D *)sl;
1858                                                         v3d->vertex_opacity = 1.0f;
1859                                                         v3d->gp_flag |= V3D_GP_SHOW_EDIT_LINES;
1860                                                 }
1861                                         }
1862                                 }
1863                         }
1864                 }
1865
1866         }
1867
1868         if (!MAIN_VERSION_ATLEAST(bmain, 280, 22)) {
1869                 if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "annotate_v3d_align")) {
1870                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1871                                 scene->toolsettings->annotate_v3d_align = GP_PROJECT_VIEWSPACE | GP_PROJECT_CURSOR;
1872                                 scene->toolsettings->annotate_thickness = 3;
1873                         }
1874                 }
1875                 if (!DNA_struct_elem_find(fd->filesdna, "bGPDlayer", "short", "line_change")) {
1876                         for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
1877                                 for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1878                                         gpl->line_change = gpl->thickness;
1879                                         if ((gpl->thickness < 1) || (gpl->thickness > 10)) {
1880                                                 gpl->thickness = 3;
1881                                         }
1882                                 }
1883                         }
1884                 }
1885                 if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "gpencil_paper_opacity")) {
1886                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1887                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1888                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1889                                                 if (sl->spacetype == SPACE_VIEW3D) {
1890                                                         View3D *v3d = (View3D *)sl;
1891                                                         v3d->overlay.gpencil_paper_opacity = 0.5f;
1892                                                 }
1893                                         }
1894                                 }
1895                         }
1896                 }
1897                 if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "gpencil_grid_opacity")) {
1898                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
1899                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1900                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1901                                                 if (sl->spacetype == SPACE_VIEW3D) {
1902                                                         View3D *v3d = (View3D *)sl;
1903                                                         v3d->overlay.gpencil_grid_opacity = 0.5f;
1904                                                 }
1905                                         }
1906                                 }
1907                         }
1908                 }
1909
1910                 /* default loc axis */
1911                 if (!DNA_struct_elem_find(fd->filesdna, "GP_Sculpt_Settings", "int", "lock_axis")) {
1912                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
1913                                 /* lock axis */
1914                                 GP_Sculpt_Settings *gset = &scene->toolsettings->gp_sculpt;
1915                                 if (gset) {
1916                                         gset->lock_axis = GP_LOCKAXIS_Y;
1917                                 }
1918                         }
1919                 }
1920
1921                 /* Versioning code for Subsurf modifier. */
1922                 if (!DNA_struct_elem_find(fd->filesdna, "SubsurfModifier", "short", "uv_smooth")) {
1923                         for (Object *object = bmain->objects.first; object != NULL; object = object->id.next) {
1924                                 for (ModifierData *md = object->modifiers.first; md; md = md->next) {
1925                                         if (md->type == eModifierType_Subsurf) {
1926                                                 SubsurfModifierData *smd = (SubsurfModifierData *)md;
1927                                                 if (smd->flags & eSubsurfModifierFlag_SubsurfUv_DEPRECATED) {
1928                                                         smd->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS;
1929                                                 }
1930                                                 else {
1931                                                         smd->uv_smooth = SUBSURF_UV_SMOOTH_NONE;
1932                                                 }
1933                                         }
1934                                 }
1935                         }
1936                 }
1937
1938                 if (!DNA_struct_elem_find(fd->filesdna, "SubsurfModifier", "short", "quality")) {
1939                         for (Object *object = bmain->objects.first; object != NULL; object = object->id.next) {
1940                                 for (ModifierData *md = object->modifiers.first; md; md = md->next) {
1941                                         if (md->type == eModifierType_Subsurf) {
1942                                                 SubsurfModifierData *smd = (SubsurfModifierData *)md;
1943                                                 smd->quality = min_ii(smd->renderLevels, 3);
1944                                         }
1945                                 }
1946                         }
1947                 }
1948                 /* Versioning code for Multires modifier. */
1949                 if (!DNA_struct_elem_find(fd->filesdna, "MultiresModifier", "short", "quality")) {
1950                         for (Object *object = bmain->objects.first; object != NULL; object = object->id.next) {
1951                                 for (ModifierData *md = object->modifiers.first; md; md = md->next) {
1952                                         if (md->type == eModifierType_Multires) {
1953                                                 MultiresModifierData *mmd = (MultiresModifierData *)md;
1954                                                 mmd->quality = 3;
1955                                                 if (mmd->flags & eMultiresModifierFlag_PlainUv_DEPRECATED) {
1956                                                         mmd->uv_smooth = SUBSURF_UV_SMOOTH_NONE;
1957                                                 }
1958                                                 else {
1959                                                         mmd->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS;
1960                                                 }
1961                                         }
1962                                 }
1963                         }
1964                 }
1965
1966                 if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "short", "bending_model")) {
1967                         for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
1968                                 for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
1969                                         ClothModifierData *clmd = NULL;
1970                                         if (md->type == eModifierType_Cloth) {
1971                                                 clmd = (ClothModifierData *)md;
1972                                         }
1973                                         else if (md->type == eModifierType_ParticleSystem) {
1974                                                 ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md;
1975                                                 ParticleSystem *psys = psmd->psys;
1976                                                 clmd = psys->clmd;
1977                                         }
1978                                         if (clmd != NULL) {
1979                                                 clmd->sim_parms->bending_model = CLOTH_BENDING_LINEAR;
1980                                                 clmd->sim_parms->tension = clmd->sim_parms->structural;
1981                                                 clmd->sim_parms->compression = clmd->sim_parms->structural;
1982                                                 clmd->sim_parms->shear = clmd->sim_parms->structural;
1983                                                 clmd->sim_parms->max_tension = clmd->sim_parms->max_struct;
1984                                                 clmd->sim_parms->max_compression = clmd->sim_parms->max_struct;
1985                                                 clmd->sim_parms->max_shear = clmd->sim_parms->max_struct;
1986                                                 clmd->sim_parms->vgroup_shear = clmd->sim_parms->vgroup_struct;
1987                                                 clmd->sim_parms->tension_damp = clmd->sim_parms->Cdis;
1988                                                 clmd->sim_parms->compression_damp = clmd->sim_parms->Cdis;
1989                                                 clmd->sim_parms->shear_damp = clmd->sim_parms->Cdis;
1990                                         }
1991                                 }
1992                         }
1993                 }
1994
1995                 if (!DNA_struct_elem_find(fd->filesdna, "BrushGpencilSettings", "float", "era_strength_f")) {
1996                         for (Brush *brush = bmain->brushes.first; brush; brush = brush->id.next) {
1997                                 if (brush->gpencil_settings != NULL) {
1998                                         BrushGpencilSettings *gp = brush->gpencil_settings;
1999                                         if (gp->brush_type == GPAINT_TOOL_ERASE) {
2000                                                 gp->era_strength_f = 100.0f;
2001                                                 gp->era_thickness_f = 10.0f;
2002                                         }
2003                                 }
2004                         }
2005                 }
2006
2007                 for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
2008                         for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
2009                                 if (md->type == eModifierType_Cloth) {
2010                                         ClothModifierData *clmd = (ClothModifierData *)md;
2011
2012                                         if (!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL)) {
2013                                                 clmd->sim_parms->vgroup_mass = 0;
2014                                         }
2015
2016                                         if (!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING)) {
2017                                                 clmd->sim_parms->vgroup_struct = 0;
2018                                                 clmd->sim_parms->vgroup_shear = 0;
2019                                                 clmd->sim_parms->vgroup_bend = 0;
2020                                         }
2021
2022                                         if (!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW)) {
2023                                                 clmd->sim_parms->shrink_min = 0.0f;
2024                                                 clmd->sim_parms->vgroup_shrink = 0;
2025                                         }
2026
2027                                         if (!(clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED)) {
2028                                                 clmd->coll_parms->flags &= ~CLOTH_COLLSETTINGS_FLAG_SELF;
2029                                         }
2030                                 }
2031                         }
2032                 }
2033         }
2034
2035         if (!MAIN_VERSION_ATLEAST(bmain, 280, 24)) {
2036                 for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
2037                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
2038                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
2039                                         if (sl->spacetype == SPACE_VIEW3D) {
2040                                                 View3D *v3d = (View3D *)sl;
2041                                                 v3d->overlay.edit_flag |= V3D_OVERLAY_EDIT_FACES |
2042                                                                           V3D_OVERLAY_EDIT_SEAMS |
2043                                                                           V3D_OVERLAY_EDIT_SHARP |
2044                                                                           V3D_OVERLAY_EDIT_FREESTYLE_EDGE |
2045                                                                           V3D_OVERLAY_EDIT_FREESTYLE_FACE |
2046                                                                           V3D_OVERLAY_EDIT_EDGES |
2047                                                                           V3D_OVERLAY_EDIT_CREASES |
2048                                                                           V3D_OVERLAY_EDIT_BWEIGHTS |
2049                                                                           V3D_OVERLAY_EDIT_CU_HANDLES |
2050                                                                           V3D_OVERLAY_EDIT_CU_NORMALS;
2051                                         }
2052                                 }
2053                         }
2054                 }
2055
2056                 if (!DNA_struct_elem_find(fd->filesdna, "ShrinkwrapModifierData", "char", "shrinkMode")) {
2057                         for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
2058                                 for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
2059                                         if (md->type == eModifierType_Shrinkwrap) {
2060                                                 ShrinkwrapModifierData *smd = (ShrinkwrapModifierData *)md;
2061                                                 if (smd->shrinkOpts & MOD_SHRINKWRAP_KEEP_ABOVE_SURFACE) {
2062                                                         smd->shrinkMode = MOD_SHRINKWRAP_ABOVE_SURFACE;
2063                                                         smd->shrinkOpts &= ~MOD_SHRINKWRAP_KEEP_ABOVE_SURFACE;
2064                                                 }
2065                                         }
2066                                 }
2067                         }
2068                 }
2069
2070                 if (!DNA_struct_elem_find(fd->filesdna, "PartDeflect", "float", "pdef_cfrict")) {
2071                         for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
2072                                 if (ob->pd) {
2073                                         ob->pd->pdef_cfrict = 5.0f;
2074                                 }
2075
2076                                 for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
2077                                         if (md->type == eModifierType_Cloth) {
2078                                                 ClothModifierData *clmd = (ClothModifierData *)md;
2079
2080                                                 clmd->coll_parms->selfepsilon = 0.015f;
2081                                         }
2082                                 }
2083                         }
2084                 }
2085
2086                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "xray_alpha_wire")) {
2087                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
2088                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
2089                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
2090                                                 if (sl->spacetype == SPACE_VIEW3D) {
2091                                                         View3D *v3d = (View3D *)sl;
2092                                                         v3d->shading.xray_alpha_wire = 0.5f;
2093                                                 }
2094                                         }
2095                                 }
2096                         }
2097
2098                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
2099                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
2100                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
2101                                                 if (sl->spacetype == SPACE_VIEW3D) {
2102                                                         View3D *v3d = (View3D *)sl;
2103                                                         v3d->shading.flag |= V3D_SHADING_XRAY_BONE;
2104                                                 }
2105                                         }
2106                                 }
2107                         }
2108                 }
2109         }
2110
2111         if (!MAIN_VERSION_ATLEAST(bmain, 280, 25)) {
2112                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
2113                         UnitSettings *unit = &scene->unit;
2114                         if (unit->system != USER_UNIT_NONE) {
2115                                 unit->length_unit = bUnit_GetBaseUnitOfType(scene->unit.system, B_UNIT_LENGTH);
2116                                 unit->mass_unit = bUnit_GetBaseUnitOfType(scene->unit.system, B_UNIT_MASS);
2117                         }
2118                         unit->time_unit = bUnit_GetBaseUnitOfType(USER_UNIT_NONE, B_UNIT_TIME);
2119                 }
2120
2121                 /* gpencil grid settings */
2122                 for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
2123                         ARRAY_SET_ITEMS(gpd->grid.color, 0.5f, 0.5f, 0.5f); // Color
2124                         ARRAY_SET_ITEMS(gpd->grid.scale, 1.0f, 1.0f); // Scale
2125                         gpd->grid.lines = GP_DEFAULT_GRID_LINES; // Number of lines
2126                 }
2127         }
2128
2129         if (!MAIN_VERSION_ATLEAST(bmain, 280, 29)) {
2130                 for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
2131                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
2132                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
2133                                         if (sl->spacetype == SPACE_VIEW3D) {
2134                                                 enum { V3D_OCCLUDE_WIRE = (1 << 14) };
2135                                                 View3D *v3d = (View3D *)sl;
2136                                                 if (v3d->flag2 & V3D_OCCLUDE_WIRE) {
2137                                                         v3d->overlay.edit_flag |= V3D_OVERLAY_EDIT_OCCLUDE_WIRE;
2138                                                         v3d->flag2 &= ~V3D_OCCLUDE_WIRE;
2139                                                 }
2140                                         }
2141                                 }
2142                         }
2143                 }
2144
2145                 for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
2146                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
2147                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
2148                                         if (sl->spacetype == SPACE_PROPERTIES) {
2149                                                 ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
2150                                                 ARegion *ar = MEM_callocN(sizeof(ARegion), "navigation bar for properties");
2151                                                 ARegion *ar_header = NULL;
2152
2153                                                 for (ar_header = regionbase->first; ar_header; ar_header = ar_header->next) {
2154                                                         if (ar_header->regiontype == RGN_TYPE_HEADER) {
2155                                                                 break;
2156                                                         }
2157                                                 }
2158                                                 BLI_assert(ar_header);
2159
2160                                                 BLI_insertlinkafter(regionbase, ar_header, ar);
2161
2162                                                 ar->regiontype = RGN_TYPE_NAV_BAR;
2163                                                 ar->alignment = RGN_ALIGN_LEFT;
2164                                         }
2165                                 }
2166                         }
2167                 }
2168
2169                 /* grease pencil fade layer opacity */
2170                 if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "gpencil_fade_layer")) {
2171                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
2172                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
2173                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
2174                                                 if (sl->spacetype == SPACE_VIEW3D) {
2175                                                         View3D *v3d = (View3D *)sl;
2176                                                         v3d->overlay.gpencil_fade_layer = 0.5f;
2177                                                 }
2178                                         }
2179                                 }
2180                         }
2181                 }
2182         }
2183
2184         if (!MAIN_VERSION_ATLEAST(bmain, 280, 30)) {
2185                 /* grease pencil main material show switches */
2186                 for (Material *mat = bmain->materials.first; mat; mat = mat->id.next) {
2187                         if (mat->gp_style) {
2188                                 mat->gp_style->flag |= GP_STYLE_STROKE_SHOW;
2189                                 mat->gp_style->flag |= GP_STYLE_FILL_SHOW;
2190                         }
2191                 }
2192         }
2193
2194         if (!MAIN_VERSION_ATLEAST(bmain, 280, 33)) {
2195                 /* Grease pencil reset sculpt brushes after struct rename  */
2196                 if (!DNA_struct_elem_find(fd->filesdna, "GP_Sculpt_Settings", "int", "weighttype")) {
2197                         float curcolor_add[3], curcolor_sub[3];
2198                         ARRAY_SET_ITEMS(curcolor_add, 1.0f, 0.6f, 0.6f);
2199                         ARRAY_SET_ITEMS(curcolor_sub, 0.6f, 0.6f, 1.0f);
2200
2201                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
2202                                 /* sculpt brushes */
2203                                 GP_Sculpt_Settings *gset = &scene->toolsettings->gp_sculpt;
2204                                 if (gset) {
2205                                         for (int i = 0; i < GP_SCULPT_TYPE_MAX; i++) {
2206                                                 GP_Sculpt_Data *gp_brush = &gset->brush[i];
2207                                                 gp_brush->size = 30;
2208                                                 gp_brush->strength = 0.5f;
2209                                                 gp_brush->flag = GP_SCULPT_FLAG_USE_FALLOFF | GP_SCULPT_FLAG_ENABLE_CURSOR;
2210                                                 copy_v3_v3(gp_brush->curcolor_add, curcolor_add);
2211                                                 copy_v3_v3(gp_brush->curcolor_sub, curcolor_sub);
2212                                         }
2213                                 }
2214                         }
2215                 }
2216
2217                 if (!DNA_struct_elem_find(fd->filesdna, "SceneEEVEE", "float", "overscan")) {
2218                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
2219                                 scene->eevee.overscan = 3.0f;
2220                         }
2221                 }
2222
2223                 for (Light *la = bmain->lights.first; la; la = la->id.next) {
2224                         /* Removed Hemi lights. */
2225                         if (!ELEM(la->type, LA_LOCAL, LA_SUN, LA_SPOT, LA_AREA)) {
2226                                 la->type = LA_SUN;
2227                         }
2228                 }
2229
2230                 if (!DNA_struct_elem_find(fd->filesdna, "SceneEEVEE", "float", "light_threshold")) {
2231                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
2232                                 scene->eevee.light_threshold = 0.01f;
2233                         }
2234                 }
2235
2236                 if (!DNA_struct_elem_find(fd->filesdna, "SceneEEVEE", "float", "gi_irradiance_smoothing")) {
2237                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
2238                                 scene->eevee.gi_irradiance_smoothing = 0.1f;
2239                         }
2240                 }
2241
2242                 if (!DNA_struct_elem_find(fd->filesdna, "SceneEEVEE", "float", "gi_filter_quality")) {
2243                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
2244                                 scene->eevee.gi_filter_quality = 1.0f;
2245                         }
2246                 }
2247
2248                 if (!DNA_struct_elem_find(fd->filesdna, "Light", "float", "att_dist")) {
2249                         for (Light *la = bmain->lights.first; la; la = la->id.next) {
2250                                 la->att_dist = la->clipend;
2251                         }
2252                 }
2253
2254                 if (!DNA_struct_elem_find(fd->filesdna, "Brush", "char", "weightpaint_tool")) {
2255                         /* Magic defines from old files (2.7x) */
2256
2257 #define PAINT_BLEND_MIX 0
2258 #define PAINT_BLEND_ADD 1
2259 #define PAINT_BLEND_SUB 2
2260 #define PAINT_BLEND_MUL 3
2261 #define PAINT_BLEND_BLUR 4
2262 #define PAINT_BLEND_LIGHTEN 5
2263 #define PAINT_BLEND_DARKEN 6
2264 #define PAINT_BLEND_AVERAGE 7
2265 #define PAINT_BLEND_SMEAR 8
2266 #define PAINT_BLEND_COLORDODGE 9
2267 #define PAINT_BLEND_DIFFERENCE 10
2268 #define PAINT_BLEND_SCREEN 11
2269 #define PAINT_BLEND_HARDLIGHT 12
2270 #define PAINT_BLEND_OVERLAY 13
2271 #define PAINT_BLEND_SOFTLIGHT 14
2272 #define PAINT_BLEND_EXCLUSION 15
2273 #define PAINT_BLEND_LUMINOSITY 16
2274 #define PAINT_BLEND_SATURATION 17
2275 #define PAINT_BLEND_HUE 18
2276 #define PAINT_BLEND_ALPHA_SUB 19
2277 #define PAINT_BLEND_ALPHA_ADD 20
2278
2279                         for (Brush *brush = bmain->brushes.first; brush; brush = brush->id.next) {
2280                                 if (brush->ob_mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) {
2281                                         const char tool_init = brush->vertexpaint_tool;
2282                                         bool is_blend = false;
2283
2284                                         {
2285                                                 char tool = tool_init;
2286                                                 switch (tool_init) {
2287                                                         case PAINT_BLEND_MIX: tool = VPAINT_TOOL_DRAW; break;
2288                                                         case PAINT_BLEND_BLUR: tool = VPAINT_TOOL_BLUR; break;
2289                                                         case PAINT_BLEND_AVERAGE: tool = VPAINT_TOOL_AVERAGE; break;
2290                                                         case PAINT_BLEND_SMEAR: tool = VPAINT_TOOL_SMEAR; break;
2291                                                         default:
2292                                                                 tool = VPAINT_TOOL_DRAW;
2293                                                                 is_blend = true;
2294                                                                 break;
2295                                                 }
2296                                                 brush->vertexpaint_tool = tool;
2297                                         }
2298
2299                                         if (is_blend == false) {
2300                                                 brush->blend = IMB_BLEND_MIX;
2301                                         }
2302                                         else {
2303                                                 short blend = IMB_BLEND_MIX;
2304                                                 switch (tool_init) {
2305                                                         case PAINT_BLEND_ADD: blend = IMB_BLEND_ADD; break;
2306                                                         case PAINT_BLEND_SUB: blend = IMB_BLEND_SUB; break;
2307                                                         case PAINT_BLEND_MUL: blend = IMB_BLEND_MUL; break;
2308                                                         case PAINT_BLEND_LIGHTEN: blend = IMB_BLEND_LIGHTEN; break;
2309                                                         case PAINT_BLEND_DARKEN: blend = IMB_BLEND_DARKEN; break;
2310                                                         case PAINT_BLEND_COLORDODGE: blend = IMB_BLEND_COLORDODGE; break;
2311                                                         case PAINT_BLEND_DIFFERENCE: blend = IMB_BLEND_DIFFERENCE; break;
2312                                                         case PAINT_BLEND_SCREEN: blend = IMB_BLEND_SCREEN; break;
2313                                                         case PAINT_BLEND_HARDLIGHT: blend = IMB_BLEND_HARDLIGHT; break;
2314                                                         case PAINT_BLEND_OVERLAY: blend = IMB_BLEND_OVERLAY; break;
2315                                                         case PAINT_BLEND_SOFTLIGHT: blend = IMB_BLEND_SOFTLIGHT; break;
2316                                                         case PAINT_BLEND_EXCLUSION: blend = IMB_BLEND_EXCLUSION; break;
2317                                                         case PAINT_BLEND_LUMINOSITY: blend = IMB_BLEND_LUMINOSITY; break;
2318                                                         case PAINT_BLEND_SATURATION: blend = IMB_BLEND_SATURATION; break;
2319                                                         case PAINT_BLEND_HUE: blend = IMB_BLEND_HUE; break;
2320                                                         case PAINT_BLEND_ALPHA_SUB: blend = IMB_BLEND_ERASE_ALPHA; break;
2321                                                         case PAINT_BLEND_ALPHA_ADD: blend = IMB_BLEND_ADD_ALPHA; break;
2322                                                 }
2323                                                 brush->blend = blend;
2324                                         }
2325                                 }
2326                                 /* For now these match, in the future new items may not. */
2327                                 brush->weightpaint_tool = brush->vertexpaint_tool;
2328                         }
2329
2330 #undef PAINT_BLEND_MIX
2331 #undef PAINT_BLEND_ADD
2332 #undef PAINT_BLEND_SUB
2333 #undef PAINT_BLEND_MUL
2334 #undef PAINT_BLEND_BLUR
2335 #undef PAINT_BLEND_LIGHTEN
2336 #undef PAINT_BLEND_DARKEN
2337 #undef PAINT_BLEND_AVERAGE
2338 #undef PAINT_BLEND_SMEAR
2339 #undef PAINT_BLEND_COLORDODGE
2340 #undef PAINT_BLEND_DIFFERENCE
2341 #undef PAINT_BLEND_SCREEN
2342 #undef PAINT_BLEND_HARDLIGHT
2343 #undef PAINT_BLEND_OVERLAY
2344 #undef PAINT_BLEND_SOFTLIGHT
2345 #undef PAINT_BLEND_EXCLUSION
2346 #undef PAINT_BLEND_LUMINOSITY
2347 #undef PAINT_BLEND_SATURATION
2348 #undef PAINT_BLEND_HUE
2349 #undef PAINT_BLEND_ALPHA_SUB
2350 #undef PAINT_BLEND_ALPHA_ADD
2351                 }
2352         }
2353
2354         if (!MAIN_VERSION_ATLEAST(bmain, 280, 34)) {
2355                 for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
2356                         for (ScrArea *area = screen->areabase.first; area; area = area->next) {
2357                                 for (SpaceLink *slink = area->spacedata.first; slink; slink = slink->next) {
2358                                         if (slink->spacetype == SPACE_USERPREF) {
2359                                                 ARegion *navigation_region = BKE_spacedata_find_region_type(slink, area, RGN_TYPE_NAV_BAR);
2360
2361                                                 if (!navigation_region) {
2362                                                         ARegion *main_region = BKE_spacedata_find_region_type(slink, area, RGN_TYPE_WINDOW);
2363                                                         ListBase *regionbase = (slink == area->spacedata.first) ?
2364                                                                                &area->regionbase : &slink->regionbase;
2365
2366                                                         navigation_region = MEM_callocN(sizeof(ARegion), "userpref navigation-region do_versions");
2367
2368                                                         BLI_insertlinkbefore(regionbase, main_region, navigation_region); /* order matters, addhead not addtail! */
2369                                                         navigation_region->regiontype = RGN_TYPE_NAV_BAR;
2370                                                         navigation_region->alignment = RGN_ALIGN_LEFT;
2371                                                 }
2372                                         }
2373                                 }
2374                         }
2375                 }
2376         }
2377
2378         if (!MAIN_VERSION_ATLEAST(bmain, 280, 36)) {
2379                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "curvature_ridge_factor")) {
2380                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
2381                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
2382                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
2383                                                 if (sl->spacetype == SPACE_VIEW3D) {
2384                                                         View3D *v3d = (View3D *)sl;
2385                                                         v3d->shading.curvature_ridge_factor = 1.0f;
2386                                                         v3d->shading.curvature_valley_factor = 1.0f;
2387                                                 }
2388                                         }
2389                                 }
2390                         }
2391                 }
2392
2393                 /* Rename OpenGL to Workbench. */
2394                 for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
2395                         if (STREQ(scene->r.engine, "BLENDER_OPENGL")) {
2396                                 STRNCPY(scene->r.engine, RE_engine_id_BLENDER_WORKBENCH);
2397                         }
2398                 }
2399
2400                 /* init Annotations onion skin */
2401                 if (!DNA_struct_elem_find(fd->filesdna, "bGPDlayer", "int", "gstep")) {
2402                         for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
2403                                 for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
2404                                         ARRAY_SET_ITEMS(gpl->gcolor_prev, 0.302f, 0.851f, 0.302f);
2405                                         ARRAY_SET_ITEMS(gpl->gcolor_next, 0.250f, 0.1f, 1.0f);
2406                                 }
2407                         }
2408                 }
2409
2410                 /* Move studio_light selection to lookdev_light. */
2411                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "char", "lookdev_light[256]")) {
2412                         for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
2413                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
2414                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
2415                                                 if (sl->spacetype == SPACE_VIEW3D) {
2416                                                         View3D *v3d = (View3D *)sl;
2417                                                         memcpy(v3d->shading.lookdev_light, v3d->shading.studio_light, sizeof(char) * 256);
2418                                                 }
2419                                         }
2420                                 }
2421                         }
2422                 }
2423
2424                 /* Change Solid mode shadow orientation. */
2425                 if (!DNA_struct_elem_find(fd->filesdna, "SceneDisplay", "float", "shadow_focus")) {
2426                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
2427                                 float *dir = scene->display.light_direction;
2428                                 SWAP(float, dir[2], dir[1]);
2429                                 dir[2] = -dir[2];
2430                                 dir[0] = -dir[0];
2431                         }
2432                 }
2433         }
2434
2435         if (!MAIN_VERSION_ATLEAST(bmain, 280, 37)) {
2436                 for (Camera *ca = bmain->cameras.first; ca; ca = ca->id.next) {
2437                         ca->drawsize *= 2.0f;
2438                 }
2439                 for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
2440                         if (ob->type != OB_EMPTY) {
2441                                 if (UNLIKELY(ob->transflag & OB_DUPLICOLLECTION)) {
2442                                         BKE_object_type_set_empty_for_versioning(ob);
2443                                 }
2444                         }
2445                 }
2446
2447                 /* Grease pencil primitive curve */
2448                 if (!DNA_struct_elem_find(fd->filesdna, "GP_Sculpt_Settings", "CurveMapping", "cur_primitive")) {
2449                         for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
2450                                 GP_Sculpt_Settings *gset = &scene->toolsettings->gp_sculpt;
2451                                 if ((gset) && (gset->cur_primitive == NULL)) {
2452                                         gset->cur_primitive = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
2453                                         curvemapping_initialize(gset->cur_primitive);
2454                                         curvemap_reset(
2455                                                 gset->cur_primitive->cm,
2456                                                 &gset->cur_primitive->clipr,
2457                                                 CURVE_PRESET_BELL,
2458                                                 CURVEMAP_SLOPE_POSITIVE);
2459                                 }
2460                         }
2461                 }
2462         }
2463
2464
2465         if (!MAIN_VERSION_ATLEAST(bmain, 280, 38)) {
2466                 if (DNA_struct_elem_find(fd->filesdna, "Object", "char", "empty_image_visibility_flag")) {
2467                         for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
2468                                 ob->empty_image_visibility_flag ^= (
2469                                         OB_EMPTY_IMAGE_HIDE_PERSPECTIVE |
2470                                         OB_EMPTY_IMAGE_HIDE_ORTHOGRAPHIC |
2471                                         OB_EMPTY_IMAGE_HIDE_BACK);
2472                         }
2473                 }
2474
2475                 for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
2476                         for (ScrArea *area = screen->areabase.first; area; area = area->next) {
2477                                 for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) {
2478                                         switch (sl->spacetype) {
2479                                                 case SPACE_IMAGE:
2480                                                 {
2481                                                         SpaceImage *sima = (SpaceImage *)sl;
2482                                                         sima->flag &= ~(
2483                                                                 SI_FLAG_DEPRECATED_0 |
2484                                                                 SI_FLAG_DEPRECATED_1 |
2485                                                                 SI_FLAG_DEPRECATED_3 |
2486                                                                 SI_FLAG_DEPRECATED_6 |
2487                                                                 SI_FLAG_DEPRECATED_7 |
2488                                                                 SI_FLAG_DEPRECATED_8 |
2489                                                                 SI_FLAG_DEPRECATED_17 |
2490                                                                 SI_FLAG_DEPRECATED_18 |
2491                                                                 SI_FLAG_DEPRECATED_23 |
2492                                                                 SI_FLAG_DEPRECATED_24);
2493                                                         break;
2494                                                 }
2495                                                 case SPACE_VIEW3D:
2496    &