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