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