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