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