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