Merge branch 'master' into blender2.8
[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_constraint_types.h"
44 #include "DNA_gpu_types.h"
45 #include "DNA_group_types.h"
46 #include "DNA_lamp_types.h"
47 #include "DNA_layer_types.h"
48 #include "DNA_lightprobe_types.h"
49 #include "DNA_material_types.h"
50 #include "DNA_mesh_types.h"
51 #include "DNA_particle_types.h"
52 #include "DNA_rigidbody_types.h"
53 #include "DNA_scene_types.h"
54 #include "DNA_screen_types.h"
55 #include "DNA_view3d_types.h"
56 #include "DNA_genfile.h"
57 #include "DNA_workspace_types.h"
58
59 #include "BKE_collection.h"
60 #include "BKE_constraint.h"
61 #include "BKE_customdata.h"
62 #include "BKE_freestyle.h"
63 #include "BKE_idprop.h"
64 #include "BKE_image.h"
65 #include "BKE_layer.h"
66 #include "BKE_main.h"
67 #include "BKE_mesh.h"
68 #include "BKE_node.h"
69 #include "BKE_pointcache.h"
70 #include "BKE_report.h"
71 #include "BKE_scene.h"
72 #include "BKE_screen.h"
73 #include "BKE_studiolight.h"
74 #include "BKE_workspace.h"
75
76 #include "BLO_readfile.h"
77 #include "readfile.h"
78
79 #include "MEM_guardedalloc.h"
80
81 static bScreen *screen_parent_find(const bScreen *screen)
82 {
83         /* can avoid lookup if screen state isn't maximized/full (parent and child store the same state) */
84         if (ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL)) {
85                 for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
86                         if (sa->full && sa->full != screen) {
87                                 BLI_assert(sa->full->state == screen->state);
88                                 return sa->full;
89                         }
90                 }
91         }
92
93         return NULL;
94 }
95
96 static void do_version_workspaces_create_from_screens(Main *bmain)
97 {
98         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
99                 const bScreen *screen_parent = screen_parent_find(screen);
100                 WorkSpace *workspace;
101                 if (screen->temp) {
102                         continue;
103                 }
104
105                 if (screen_parent) {
106                         /* fullscreen with "Back to Previous" option, don't create
107                          * a new workspace, add layout workspace containing parent */
108                         workspace = BLI_findstring(
109                                 &bmain->workspaces, screen_parent->id.name + 2, offsetof(ID, name) + 2);
110                 }
111                 else {
112                         workspace = BKE_workspace_add(bmain, screen->id.name + 2);
113                 }
114                 BKE_workspace_layout_add(bmain, workspace, screen, screen->id.name + 2);
115         }
116 }
117
118 static void do_version_area_change_space_to_space_action(ScrArea *area, const Scene *scene)
119 {
120         SpaceType *stype = BKE_spacetype_from_id(SPACE_ACTION);
121         SpaceAction *saction = (SpaceAction *)stype->new(area, scene);
122         ARegion *region_channels;
123
124         /* Properly free current regions */
125         for (ARegion *region = area->regionbase.first; region; region = region->next) {
126                 BKE_area_region_free(area->type, region);
127         }
128         BLI_freelistN(&area->regionbase);
129
130         area->type = stype;
131         area->spacetype = stype->spaceid;
132
133         BLI_addhead(&area->spacedata, saction);
134         area->regionbase = saction->regionbase;
135         BLI_listbase_clear(&saction->regionbase);
136
137         /* Different defaults for timeline */
138         region_channels = BKE_area_find_region_type(area, RGN_TYPE_CHANNELS);
139         region_channels->flag |= RGN_FLAG_HIDDEN;
140
141         saction->mode = SACTCONT_TIMELINE;
142         saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED;
143         saction->ads.filterflag |= ADS_FILTER_SUMMARY;
144 }
145
146 /**
147  * \brief After lib-link versioning for new workspace design.
148  *
149  * - Adds a workspace for (almost) each screen of the old file
150  *   and adds the needed workspace-layout to wrap the screen.
151  * - Active screen isn't stored directly in window anymore, but in the active workspace.
152  * - Active scene isn't stored in screen anymore, but in window.
153  * - Create workspace instance hook for each window.
154  *
155  * \note Some of the created workspaces might be deleted again in case of reading the default startup.blend.
156  */
157 static void do_version_workspaces_after_lib_link(Main *bmain)
158 {
159         BLI_assert(BLI_listbase_is_empty(&bmain->workspaces));
160
161         do_version_workspaces_create_from_screens(bmain);
162
163         for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
164                 for (wmWindow *win = wm->windows.first; win; win = win->next) {
165                         bScreen *screen_parent = screen_parent_find(win->screen);
166                         bScreen *screen = screen_parent ? screen_parent : win->screen;
167
168                         if (screen->temp) {
169                                 /* We do not generate a new workspace for those screens... still need to set some data in win. */
170                                 win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
171                                 win->scene = screen->scene;
172                                 /* Deprecated from now on! */
173                                 win->screen = NULL;
174                                 continue;
175                         }
176
177                         WorkSpace *workspace = BLI_findstring(&bmain->workspaces, screen->id.name + 2, offsetof(ID, name) + 2);
178                         BLI_assert(workspace != NULL);
179                         ListBase *layouts = BKE_workspace_layouts_get(workspace);
180
181                         win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
182
183                         BKE_workspace_active_set(win->workspace_hook, workspace);
184                         BKE_workspace_active_layout_set(win->workspace_hook, layouts->first);
185
186                         /* Move scene and view layer to window. */
187                         Scene *scene = screen->scene;
188                         ViewLayer *layer = BLI_findlink(&scene->view_layers, scene->r.actlay);
189                         if (!layer) {
190                                 layer = BKE_view_layer_default_view(scene);
191                         }
192
193                         win->scene = scene;
194                         STRNCPY(win->view_layer_name, layer->name);
195
196                         /* Deprecated from now on! */
197                         win->screen = NULL;
198                 }
199         }
200
201         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
202                 /* Deprecated from now on! */
203                 BLI_freelistN(&screen->scene->transform_spaces);
204                 screen->scene = NULL;
205         }
206 }
207
208 #ifdef USE_COLLECTION_COMPAT_28
209 enum {
210         COLLECTION_DEPRECATED_VISIBLE    = (1 << 0),
211         COLLECTION_DEPRECATED_VIEWPORT   = (1 << 0),
212         COLLECTION_DEPRECATED_SELECTABLE = (1 << 1),
213         COLLECTION_DEPRECATED_DISABLED   = (1 << 2),
214         COLLECTION_DEPRECATED_RENDER     = (1 << 3),
215 };
216
217 static void do_version_view_layer_visibility(ViewLayer *view_layer)
218 {
219         /* Convert from deprecated VISIBLE flag to DISABLED */
220         LayerCollection *lc;
221         for (lc = view_layer->layer_collections.first;
222              lc;
223              lc = lc->next)
224         {
225                 if (lc->flag & COLLECTION_DEPRECATED_DISABLED) {
226                         lc->flag &= ~COLLECTION_DEPRECATED_DISABLED;
227                 }
228
229                 if ((lc->flag & COLLECTION_DEPRECATED_VISIBLE) == 0) {
230                         lc->flag |= COLLECTION_DEPRECATED_DISABLED;
231                 }
232
233                 lc->flag |= COLLECTION_DEPRECATED_VIEWPORT | COLLECTION_DEPRECATED_RENDER;
234         }
235 }
236
237 static void do_version_layer_collection_pre(
238         ViewLayer *view_layer,
239         ListBase *lb,
240         GSet *enabled_set,
241         GSet *selectable_set)
242 {
243         /* Convert from deprecated DISABLED to new layer collection and collection flags */
244         for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
245                 if (lc->scene_collection) {
246                         if (!(lc->flag & COLLECTION_DEPRECATED_DISABLED)) {
247                                 BLI_gset_insert(enabled_set, lc->scene_collection);
248                         }
249                         if (lc->flag & COLLECTION_DEPRECATED_SELECTABLE) {
250                                 BLI_gset_insert(selectable_set, lc->scene_collection);
251                         }
252                 }
253
254                 do_version_layer_collection_pre(view_layer, &lc->layer_collections, enabled_set, selectable_set);
255         }
256 }
257
258 static void do_version_layer_collection_post(
259         ViewLayer *view_layer,
260         ListBase *lb,
261         GSet *enabled_set,
262         GSet *selectable_set,
263         GHash *collection_map)
264 {
265         /* Apply layer collection exclude flags. */
266         for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
267                 if (!(lc->collection->flag & COLLECTION_IS_MASTER)) {
268                         SceneCollection *sc = BLI_ghash_lookup(collection_map, lc->collection);
269                         const bool enabled = (sc && BLI_gset_haskey(enabled_set, sc));
270                         const bool selectable = (sc && BLI_gset_haskey(selectable_set, sc));
271
272                         if (!enabled) {
273                                 lc->flag |= LAYER_COLLECTION_EXCLUDE;
274                         }
275                         if (enabled && !selectable) {
276                                 lc->collection->flag |= COLLECTION_RESTRICT_SELECT;
277                         }
278                 }
279
280                 do_version_layer_collection_post(
281                         view_layer, &lc->layer_collections, enabled_set, selectable_set, collection_map);
282         }
283 }
284
285 static void do_version_scene_collection_convert(
286         Main *bmain,
287         ID *id,
288         SceneCollection *sc,
289         Collection *collection,
290         GHash *collection_map)
291 {
292         if (collection_map) {
293                 BLI_ghash_insert(collection_map, collection, sc);
294         }
295
296         for (SceneCollection *nsc = sc->scene_collections.first; nsc;) {
297                 SceneCollection *nsc_next = nsc->next;
298                 Collection *ncollection = BKE_collection_add(bmain, collection, nsc->name);
299                 ncollection->id.lib = id->lib;
300                 do_version_scene_collection_convert(bmain, id, nsc, ncollection, collection_map);
301                 nsc = nsc_next;
302         }
303
304         for (LinkData *link = sc->objects.first; link; link = link->next) {
305                 Object *ob = link->data;
306                 if (ob) {
307                         BKE_collection_object_add(bmain, collection, ob);
308                         id_us_min(&ob->id);
309                 }
310         }
311
312         BLI_freelistN(&sc->objects);
313         MEM_freeN(sc);
314 }
315
316 static void do_version_group_collection_to_collection(Main *bmain, Collection *group)
317 {
318         /* Convert old 2.8 group collections to new unified collections. */
319         if (group->collection) {
320                 do_version_scene_collection_convert(bmain, &group->id, group->collection, group, NULL);
321         }
322
323         group->collection = NULL;
324         group->view_layer = NULL;
325         id_fake_user_set(&group->id);
326 }
327
328 static void do_version_scene_collection_to_collection(Main *bmain, Scene *scene)
329 {
330         /* Convert old 2.8 scene collections to new unified collections. */
331
332         /* Temporarily clear view layers so we don't do any layer collection syncing
333          * and destroy old flags that we want to restore. */
334         ListBase view_layers = scene->view_layers;
335         BLI_listbase_clear(&scene->view_layers);
336
337         if (!scene->master_collection) {
338                 scene->master_collection = BKE_collection_master_add();
339         }
340
341         /* Convert scene collections. */
342         GHash *collection_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
343         if (scene->collection) {
344                 do_version_scene_collection_convert(bmain, &scene->id, scene->collection, scene->master_collection, collection_map);
345                 scene->collection = NULL;
346         }
347
348         scene->view_layers = view_layers;
349
350         /* Convert layer collections. */
351         ViewLayer *view_layer;
352         for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
353                 GSet *enabled_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
354                 GSet *selectable_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
355
356                 do_version_layer_collection_pre(
357                         view_layer, &view_layer->layer_collections, enabled_set, selectable_set);
358
359                 BKE_layer_collection_sync(scene, view_layer);
360
361                 do_version_layer_collection_post(
362                         view_layer, &view_layer->layer_collections, enabled_set, selectable_set, collection_map);
363
364                 BLI_gset_free(enabled_set, NULL);
365                 BLI_gset_free(selectable_set, NULL);
366
367                 BKE_layer_collection_sync(scene, view_layer);
368         }
369
370         BLI_ghash_free(collection_map, NULL, NULL);
371 }
372 #endif
373
374
375 static void do_version_layers_to_collections(Main *bmain, Scene *scene)
376 {
377         /* Since we don't have access to FileData we check the (always valid) first
378          * render layer instead. */
379         if (!scene->master_collection) {
380                 scene->master_collection = BKE_collection_master_add();
381         }
382
383         if (scene->view_layers.first) {
384                 return;
385         }
386
387         /* Create collections from layers. */
388         Collection *collection_master = BKE_collection_master(scene);
389         Collection *collections[20] = {NULL};
390
391         for (int layer = 0; layer < 20; layer++) {
392                 for (Base *base = scene->base.first; base; base = base->next) {
393                         if (base->lay & (1 << layer)) {
394                                 /* Create collections when needed only. */
395                                 if (collections[layer] == NULL) {
396                                         char name[MAX_NAME];
397
398                                         BLI_snprintf(name,
399                                                      sizeof(collection_master->id.name),
400                                                      "Collection %d",
401                                                      layer + 1);
402
403                                         Collection *collection = BKE_collection_add(bmain, collection_master, name);
404                                         collection->id.lib = scene->id.lib;
405                                         collections[layer] = collection;
406
407                                         if (!(scene->lay & (1 << layer))) {
408                                                 collection->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
409                                         }
410                                 }
411
412                                 /* Note usually this would do slow collection syncing for view layers,
413                                  * but since no view layers exists yet at this point it's fast. */
414                                 BKE_collection_object_add(
415                                         bmain,
416                                         collections[layer], base->object);
417                         }
418
419                         if (base->flag & SELECT) {
420                                 base->object->flag |= SELECT;
421                         }
422                         else {
423                                 base->object->flag &= ~SELECT;
424                         }
425                 }
426         }
427
428         /* Handle legacy render layers. */
429         bool have_override = false;
430
431         for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
432                 ViewLayer *view_layer = BKE_view_layer_add(scene, srl->name);
433
434                 if (srl->samples != 0) {
435                         have_override = true;
436
437                         /* It is up to the external engine to handle
438                          * its own doversion in this case. */
439                         BKE_override_view_layer_int_add(
440                                 view_layer,
441                                 ID_SCE,
442                                 "samples",
443                                 srl->samples);
444                 }
445
446                 if (srl->mat_override) {
447                         have_override = true;
448
449                         BKE_override_view_layer_datablock_add(
450                                 view_layer,
451                                 ID_MA,
452                                 "self",
453                                 (ID *)srl->mat_override);
454                 }
455
456                 if (srl->layflag & SCE_LAY_DISABLE) {
457                         view_layer->flag &= ~VIEW_LAYER_RENDER;
458                 }
459
460                 if ((srl->layflag & SCE_LAY_FRS) == 0) {
461                         view_layer->flag &= ~VIEW_LAYER_FREESTYLE;
462                 }
463
464                 /* XXX If we are to keep layflag it should be merged with flag (dfelinto). */
465                 view_layer->layflag = srl->layflag;
466                 /* XXX Not sure if we should keep the passes (dfelinto). */
467                 view_layer->passflag = srl->passflag;
468                 view_layer->pass_xor = srl->pass_xor;
469                 view_layer->pass_alpha_threshold = srl->pass_alpha_threshold;
470
471                 BKE_freestyle_config_free(&view_layer->freestyle_config, true);
472                 view_layer->freestyle_config = srl->freestyleConfig;
473                 view_layer->id_properties = srl->prop;
474
475                 /* Set exclusion and overrides. */
476                 for (int layer = 0; layer < 20; layer++) {
477                         Collection *collection = collections[layer];
478                         if (collection) {
479                                 LayerCollection *lc = BKE_layer_collection_first_from_scene_collection(view_layer, collection);
480
481                                 if (srl->lay_exclude & (1 << layer)) {
482                                         /* Disable excluded layer. */
483                                         have_override = true;
484                                         lc->flag |= LAYER_COLLECTION_EXCLUDE;
485                                         for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) {
486                                                 nlc->flag |= LAYER_COLLECTION_EXCLUDE;
487                                         }
488                                 }
489                                 else if ((scene->lay & srl->lay & ~(srl->lay_exclude) & (1 << layer)) ||
490                                          (srl->lay_zmask & (scene->lay | srl->lay_exclude) & (1 << layer)))
491                                 {
492                                         if (srl->lay_zmask & (1 << layer)) {
493                                                 have_override = true;
494
495                                                 BKE_override_layer_collection_boolean_add(
496                                                         lc,
497                                                         ID_OB,
498                                                         "cycles.is_holdout",
499                                                         true);
500                                         }
501
502                                         if ((srl->lay & (1 << layer)) == 0) {
503                                                 have_override = true;
504
505                                                 BKE_override_layer_collection_boolean_add(
506                                                         lc,
507                                                         ID_OB,
508                                                         "cycles_visibility.camera",
509                                                         false);
510                                         }
511                                 }
512                         }
513                 }
514
515                 /* for convenience set the same active object in all the layers */
516                 if (scene->basact) {
517                         view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
518                 }
519
520                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
521                         if ((base->flag & BASE_SELECTABLE) && (base->object->flag & SELECT)) {
522                                 base->flag |= BASE_SELECTED;
523                         }
524                 }
525         }
526
527         BLI_freelistN(&scene->r.layers);
528
529         /* If render layers included overrides, we also create a vanilla
530          * viewport layer without them. */
531         if (have_override) {
532                 ViewLayer *view_layer = BKE_view_layer_add(scene, "Viewport");
533
534                 /* Make it first in the list. */
535                 BLI_remlink(&scene->view_layers, view_layer);
536                 BLI_addhead(&scene->view_layers, view_layer);
537
538                 /* If we ported all the original render layers, we don't need to make the viewport layer renderable. */
539                 if (!BLI_listbase_is_single(&scene->view_layers)) {
540                         view_layer->flag &= ~VIEW_LAYER_RENDER;
541                 }
542
543                 /* convert active base */
544                 if (scene->basact) {
545                         view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
546                 }
547
548                 /* convert selected bases */
549                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
550                         if ((base->flag & BASE_SELECTABLE) && (base->object->flag & SELECT)) {
551                                 base->flag |= BASE_SELECTED;
552                         }
553
554                         /* keep lay around for forward compatibility (open those files in 2.79) */
555                         base->lay = base->object->lay;
556                 }
557         }
558
559         /* remove bases once and for all */
560         for (Base *base = scene->base.first; base; base = base->next) {
561                 id_us_min(&base->object->id);
562         }
563
564         BLI_freelistN(&scene->base);
565         scene->basact = NULL;
566 }
567
568 void do_versions_after_linking_280(Main *bmain)
569 {
570         bool use_collection_compat_28 = true;
571
572         if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
573                 use_collection_compat_28 = false;
574
575                 /* Convert group layer visibility flags to hidden nested collection. */
576                 for (Collection *collection = bmain->collection.first; collection; collection = collection->id.next) {
577                         /* Add fake user for all existing groups. */
578                         id_fake_user_set(&collection->id);
579
580                         if (collection->flag & (COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER)) {
581                                 continue;
582                         }
583
584                         Collection *collection_hidden = NULL;
585                         for (CollectionObject *cob = collection->gobject.first, *cob_next = NULL; cob; cob = cob_next) {
586                                 cob_next = cob->next;
587                                 Object *ob = cob->ob;
588
589                                 if (!(ob->lay & collection->layer)) {
590                                         if (collection_hidden == NULL) {
591                                                 collection_hidden = BKE_collection_add(bmain, collection, "Hidden");
592                                                 collection_hidden->id.lib = collection->id.lib;
593                                                 collection_hidden->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
594                                         }
595
596                                         BKE_collection_object_add(bmain, collection_hidden, ob);
597                                         BKE_collection_object_remove(bmain, collection, ob, true);
598                                 }
599                         }
600                 }
601
602                 /* Convert layers to collections. */
603                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
604                         do_version_layers_to_collections(bmain, scene);
605                 }
606         }
607
608         if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
609                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
610                         /* same render-layer as do_version_workspaces_after_lib_link will activate,
611                          * so same layer as BKE_view_layer_default_view would return */
612                         ViewLayer *layer = screen->scene->view_layers.first;
613
614                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
615                                 for (SpaceLink *space = sa->spacedata.first; space; space = space->next) {
616                                         if (space->spacetype == SPACE_OUTLINER) {
617                                                 SpaceOops *soutliner = (SpaceOops *)space;
618
619                                                 soutliner->outlinevis = SO_VIEW_LAYER;
620
621                                                 if (BLI_listbase_count_at_most(&layer->layer_collections, 2) == 1) {
622                                                         if (soutliner->treestore == NULL) {
623                                                                 soutliner->treestore = BLI_mempool_create(
624                                                                         sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
625                                                         }
626
627                                                         /* Create a tree store element for the collection. This is normally
628                                                          * done in check_persistent (outliner_tree.c), but we need to access
629                                                          * it here :/ (expand element if it's the only one) */
630                                                         TreeStoreElem *tselem = BLI_mempool_calloc(soutliner->treestore);
631                                                         tselem->type = TSE_LAYER_COLLECTION;
632                                                         tselem->id = layer->layer_collections.first;
633                                                         tselem->nr = tselem->used = 0;
634                                                         tselem->flag &= ~TSE_CLOSED;
635                                                 }
636                                         }
637                                 }
638                         }
639                 }
640         }
641
642         /* New workspace design */
643         if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
644                 do_version_workspaces_after_lib_link(bmain);
645         }
646
647         if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) {
648                 /* Cleanup any remaining SceneRenderLayer data for files that were created
649                  * with Blender 2.8 before the SceneRenderLayer > RenderLayer refactor. */
650                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
651                         for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
652                                 if (srl->prop) {
653                                         IDP_FreeProperty(srl->prop);
654                                         MEM_freeN(srl->prop);
655                                 }
656                                 BKE_freestyle_config_free(&srl->freestyleConfig, true);
657                         }
658                         BLI_freelistN(&scene->r.layers);
659                 }
660         }
661
662         if (!MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
663                 /* Due to several changes to particle RNA and draw code particles from older files may no longer
664                  * be visible. Here we correct this by setting a default draw size for those files. */
665                 for (Object *object = bmain->object.first; object; object = object->id.next) {
666                         for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
667                                 if (psys->part->draw_size == 0.0f) {
668                                         psys->part->draw_size = 0.1f;
669                                 }
670                         }
671                 }
672         }
673
674         if (!MAIN_VERSION_ATLEAST(bmain, 280, 4)) {
675                 for (Object *object = bmain->object.first; object; object = object->id.next) {
676 #ifndef VERSION_280_SUBVERSION_4
677                         /* If any object already has an initialized value for
678                          * duplicator_visibility_flag it means we've already doversioned it.
679                          * TODO(all) remove the VERSION_280_SUBVERSION_4 code once the subversion was bumped. */
680                         if (object->duplicator_visibility_flag != 0) {
681                                 break;
682                         }
683 #endif
684                         if (object->particlesystem.first) {
685                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
686                                 for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
687                                         if (psys->part->draw & PART_DRAW_EMITTER) {
688                                                 object->duplicator_visibility_flag |= OB_DUPLI_FLAG_RENDER;
689 #ifndef VERSION_280_SUBVERSION_4
690                                                 psys->part->draw &= ~PART_DRAW_EMITTER;
691 #else
692                                                 break;
693 #endif
694                                         }
695                                 }
696                         }
697                         else if (object->transflag & OB_DUPLI) {
698                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
699                         }
700                         else {
701                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER;
702                         }
703                 }
704         }
705
706         /* SpaceTime & SpaceLogic removal/replacing */
707         if (!MAIN_VERSION_ATLEAST(bmain, 280, 9)) {
708                 const wmWindowManager *wm = bmain->wm.first;
709                 const Scene *scene = bmain->scene.first;
710
711                 if (wm != NULL) {
712                         /* Action editors need a scene for creation. First, update active
713                          * screens using the active scene of the window they're displayed in.
714                          * Next, update remaining screens using first scene in main listbase. */
715
716                         for (wmWindow *win = wm->windows.first; win; win = win->next) {
717                                 const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
718                                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
719                                         if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
720                                                 do_version_area_change_space_to_space_action(area, win->scene);
721
722                                                 /* Don't forget to unset! */
723                                                 area->butspacetype = SPACE_EMPTY;
724                                         }
725                                 }
726                         }
727                 }
728                 if (scene != NULL) {
729                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
730                                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
731                                         if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
732                                                 /* Areas that were already handled won't be handled again */
733                                                 do_version_area_change_space_to_space_action(area, scene);
734
735                                                 /* Don't forget to unset! */
736                                                 area->butspacetype = SPACE_EMPTY;
737                                         }
738                                 }
739                         }
740                 }
741         }
742
743 #ifdef USE_COLLECTION_COMPAT_28
744         if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 14)) {
745                 for (Collection *group = bmain->collection.first; group; group = group->id.next) {
746                         do_version_group_collection_to_collection(bmain, group);
747                 }
748
749                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
750                         do_version_scene_collection_to_collection(bmain, scene);
751                 }
752         }
753 #endif
754 }
755
756 /* NOTE: this version patch is intended for versions < 2.52.2, but was initially introduced in 2.27 already.
757  *       But in 2.79 another case generating non-unique names was discovered (see T55668, involving Meta strips)... */
758 static void do_versions_seq_unique_name_all_strips(Scene *sce, ListBase *seqbasep)
759 {
760         for (Sequence *seq = seqbasep->first; seq != NULL; seq = seq->next) {
761                 BKE_sequence_base_unique_name_recursive(&sce->ed->seqbase, seq);
762                 if (seq->seqbase.first != NULL) {
763                         do_versions_seq_unique_name_all_strips(sce, &seq->seqbase);
764                 }
765         }
766 }
767
768 void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
769 {
770         bool use_collection_compat_28 = true;
771
772         if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
773                 use_collection_compat_28 = false;
774
775                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
776                         scene->r.gauss = 1.5f;
777                 }
778         }
779
780         if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
781                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "bleedexp")) {
782                         for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
783                                 la->bleedexp = 2.5f;
784                         }
785                 }
786
787                 if (!DNA_struct_elem_find(fd->filesdna, "GPUDOFSettings", "float", "ratio")) {
788                         for (Camera *ca = bmain->camera.first; ca; ca = ca->id.next) {
789                                 ca->gpu_dof.ratio = 1.0f;
790                         }
791                 }
792
793                 /* MTexPoly now removed. */
794                 if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
795                         const int cd_mtexpoly = 15;  /* CD_MTEXPOLY, deprecated */
796                         for (Mesh *me = bmain->mesh.first; me; me = me->id.next) {
797                                 /* If we have UV's, so this file will have MTexPoly layers too! */
798                                 if (me->mloopuv != NULL) {
799                                         CustomData_update_typemap(&me->pdata);
800                                         CustomData_free_layers(&me->pdata, cd_mtexpoly, me->totpoly);
801                                         BKE_mesh_update_customdata_pointers(me, false);
802                                 }
803                         }
804                 }
805         }
806
807         if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) {
808                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "cascade_max_dist")) {
809                         for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
810                                 la->cascade_max_dist = 1000.0f;
811                                 la->cascade_count = 4;
812                                 la->cascade_exponent = 0.8f;
813                                 la->cascade_fade = 0.1f;
814                         }
815                 }
816
817                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "contact_dist")) {
818                         for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
819                                 la->contact_dist = 0.2f;
820                                 la->contact_bias = 0.03f;
821                                 la->contact_spread = 0.2f;
822                                 la->contact_thickness = 0.2f;
823                         }
824                 }
825
826                 if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "vis_bias")) {
827                         for (LightProbe *probe = bmain->lightprobe.first; probe; probe = probe->id.next) {
828                                 probe->vis_bias = 1.0f;
829                                 probe->vis_blur = 0.2f;
830                         }
831                 }
832
833                 typedef enum eNTreeDoVersionErrors {
834                         NTREE_DOVERSION_NO_ERROR = 0,
835                         NTREE_DOVERSION_NEED_OUTPUT = (1 << 0),
836                         NTREE_DOVERSION_TRANSPARENCY_EMISSION = (1 << 1),
837                 } eNTreeDoVersionErrors;
838
839                 /* Eevee shader nodes renamed because of the output node system.
840                  * Note that a new output node is not being added here, because it would be overkill
841                  * to handle this case in lib_verify_nodetree.
842                  *
843                  * Also, metallic node is now unified into the principled node. */
844                 eNTreeDoVersionErrors error = NTREE_DOVERSION_NO_ERROR;
845
846                 FOREACH_NODETREE(bmain, ntree, id) {
847                         if (ntree->type == NTREE_SHADER) {
848                                 for (bNode *node = ntree->nodes.first; node; node = node->next) {
849                                         if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
850                                             STREQ(node->idname, "ShaderNodeOutputMetallic"))
851                                         {
852                                                 BLI_strncpy(node->idname, "ShaderNodeEeveeMetallic", sizeof(node->idname));
853                                                 error |= NTREE_DOVERSION_NEED_OUTPUT;
854                                         }
855
856                                         else if (node->type == SH_NODE_EEVEE_SPECULAR && STREQ(node->idname, "ShaderNodeOutputSpecular")) {
857                                                 BLI_strncpy(node->idname, "ShaderNodeEeveeSpecular", sizeof(node->idname));
858                                                 error |= NTREE_DOVERSION_NEED_OUTPUT;
859                                         }
860
861                                         else if (node->type == 196 /* SH_NODE_OUTPUT_EEVEE_MATERIAL */ &&
862                                                  STREQ(node->idname, "ShaderNodeOutputEeveeMaterial"))
863                                         {
864                                                 node->type = SH_NODE_OUTPUT_MATERIAL;
865                                                 BLI_strncpy(node->idname, "ShaderNodeOutputMaterial", sizeof(node->idname));
866                                         }
867
868                                         else if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
869                                                  STREQ(node->idname, "ShaderNodeEeveeMetallic"))
870                                         {
871                                                 node->type = SH_NODE_BSDF_PRINCIPLED;
872                                                 BLI_strncpy(node->idname, "ShaderNodeBsdfPrincipled", sizeof(node->idname));
873                                                 node->custom1 = SHD_GLOSSY_MULTI_GGX;
874                                                 error |= NTREE_DOVERSION_TRANSPARENCY_EMISSION;
875                                         }
876                                 }
877                         }
878                 } FOREACH_NODETREE_END
879
880                 if (error & NTREE_DOVERSION_NEED_OUTPUT) {
881                         BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
882                         printf("You need to connect Principled and Eevee Specular shader nodes to new material output nodes.\n");
883                 }
884
885                 if (error & NTREE_DOVERSION_TRANSPARENCY_EMISSION) {
886                         BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
887                         printf("You need to combine transparency and emission shaders to the converted Principled shader nodes.\n");
888                 }
889
890 #ifdef USE_COLLECTION_COMPAT_28
891                 if (use_collection_compat_28 &&
892                     (DNA_struct_elem_find(fd->filesdna, "ViewLayer", "FreestyleConfig", "freestyle_config") == false) &&
893                     DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers"))
894                 {
895                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
896                                 ViewLayer *view_layer;
897                                 for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
898                                         view_layer->flag |= VIEW_LAYER_FREESTYLE;
899                                         view_layer->layflag = 0x7FFF;   /* solid ztra halo edge strand */
900                                         view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
901                                         view_layer->pass_alpha_threshold = 0.5f;
902                                         BKE_freestyle_config_init(&view_layer->freestyle_config);
903                                 }
904                         }
905                 }
906 #endif
907         }
908
909 #ifdef USE_COLLECTION_COMPAT_28
910         if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
911                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
912                         ViewLayer *view_layer;
913                         for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
914                                 do_version_view_layer_visibility(view_layer);
915                         }
916                 }
917
918                 for (Collection *group = bmain->collection.first; group; group = group->id.next) {
919                         if (group->view_layer != NULL) {
920                                 do_version_view_layer_visibility(group->view_layer);
921                         }
922                 }
923         }
924 #endif
925
926         if (!MAIN_VERSION_ATLEAST(bmain, 280, 6)) {
927                 if (DNA_struct_elem_find(fd->filesdna, "SpaceOops", "int", "filter") == false) {
928                         bScreen *sc;
929                         ScrArea *sa;
930                         SpaceLink *sl;
931
932                         /* Update files using invalid (outdated) outlinevis Outliner values. */
933                         for (sc = bmain->screen.first; sc; sc = sc->id.next) {
934                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
935                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
936                                                 if (sl->spacetype == SPACE_OUTLINER) {
937                                                         SpaceOops *so = (SpaceOops *)sl;
938
939                                                         if (!ELEM(so->outlinevis,
940                                                                   SO_SCENES,
941                                                                   SO_LIBRARIES,
942                                                                   SO_SEQUENCE,
943                                                                   SO_DATA_API,
944                                                                   SO_ID_ORPHANS))
945                                                         {
946                                                                 so->outlinevis = SO_VIEW_LAYER;
947                                                         }
948                                                 }
949                                         }
950                                 }
951                         }
952                 }
953
954                 if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "intensity")) {
955                         for (LightProbe *probe = bmain->lightprobe.first; probe; probe = probe->id.next) {
956                                 probe->intensity = 1.0f;
957                         }
958                 }
959
960                 for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
961                         bConstraint *con, *con_next;
962                         con = ob->constraints.first;
963                         while (con) {
964                                 con_next = con->next;
965                                 if (con->type == 17) { /* CONSTRAINT_TYPE_RIGIDBODYJOINT */
966                                         BLI_remlink(&ob->constraints, con);
967                                         BKE_constraint_free_data(con);
968                                         MEM_freeN(con);
969                                 }
970                                 con = con_next;
971                         }
972                 }
973
974                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "int", "orientation_index_custom")) {
975                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
976                                 scene->orientation_index_custom = -1;
977                         }
978                 }
979
980                 for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
981                         for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
982                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
983                                         if (sl->spacetype == SPACE_VIEW3D) {
984                                                 View3D *v3d = (View3D *)sl;
985                                                 v3d->shading.light = V3D_LIGHTING_STUDIO;
986                                                 v3d->shading.flag |= V3D_SHADING_OBJECT_OUTLINE;
987
988                                                 /* Assume (demo) files written with 2.8 want to show
989                                                  * Eevee renders in the viewport. */
990                                                 if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
991                                                         v3d->drawtype = OB_MATERIAL;
992                                                 }
993                                         }
994                                 }
995                         }
996                 }
997         }
998
999         if (!MAIN_VERSION_ATLEAST(bmain, 280, 7)) {
1000                 /* Render engine storage moved elsewhere and back during 2.8
1001                  * development, we assume any files saved in 2.8 had Eevee set
1002                  * as scene render engine. */
1003                 if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
1004                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1005                                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
1006                         }
1007                 }
1008         }
1009
1010         if (!MAIN_VERSION_ATLEAST(bmain, 280, 8)) {
1011                 /* Blender Internal removal */
1012                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1013                         if (STREQ(scene->r.engine, "BLENDER_RENDER") ||
1014                             STREQ(scene->r.engine, "BLENDER_GAME"))
1015                         {
1016                                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
1017                         }
1018
1019                         scene->r.bake_mode = 0;
1020                 }
1021
1022                 for (Tex *tex = bmain->tex.first; tex; tex = tex->id.next) {
1023                         /* Removed envmap, pointdensity, voxeldata, ocean textures. */
1024                         if (ELEM(tex->type, 10, 14, 15, 16)) {
1025                                 tex->type = 0;
1026                         }
1027                 }
1028         }
1029
1030         if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) {
1031
1032                 /* Remove info editor, but only if at the top of the window. */
1033                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1034                         /* Calculate window width/height from screen vertices */
1035                         int win_width = 0, win_height = 0;
1036                         for (ScrVert *vert = screen->vertbase.first; vert; vert = vert->next) {
1037                                 win_width  = MAX2(win_width, vert->vec.x);
1038                                 win_height = MAX2(win_height, vert->vec.y);
1039                         }
1040
1041                         for (ScrArea *area = screen->areabase.first, *area_next; area; area = area_next) {
1042                                 area_next = area->next;
1043
1044                                 if (area->spacetype == SPACE_INFO) {
1045                                         if ((area->v2->vec.y == win_height) && (area->v1->vec.x == 0) && (area->v4->vec.x == win_width)) {
1046                                                 BKE_screen_area_free(area);
1047
1048                                                 BLI_remlink(&screen->areabase, area);
1049
1050                                                 BKE_screen_remove_double_scredges(screen);
1051                                                 BKE_screen_remove_unused_scredges(screen);
1052                                                 BKE_screen_remove_unused_scrverts(screen);
1053
1054                                                 MEM_freeN(area);
1055                                         }
1056                                 }
1057                                 /* AREA_TEMP_INFO is deprecated from now on, it should only be set for info areas
1058                                  * which are deleted above, so don't need to unset it. Its slot/bit can be reused */
1059                         }
1060                 }
1061         }
1062
1063         if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) {
1064                 for (Lamp *lamp = bmain->lamp.first; lamp; lamp = lamp->id.next) {
1065                         if (lamp->mode & (1 << 13)) { /* LA_SHAD_RAY */
1066                                 lamp->mode |= LA_SHADOW;
1067                                 lamp->mode &= ~(1 << 13);
1068                         }
1069                 }
1070         }
1071
1072         if (!MAIN_VERSION_ATLEAST(bmain, 280, 12)) {
1073                 /* Remove tool property regions. */
1074                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1075                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1076                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1077                                         if (ELEM(sl->spacetype, SPACE_VIEW3D, SPACE_CLIP)) {
1078                                                 ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1079
1080                                                 for (ARegion *region = regionbase->first, *region_next; region; region = region_next) {
1081                                                         region_next = region->next;
1082
1083                                                         if (region->regiontype == RGN_TYPE_TOOL_PROPS) {
1084                                                                 BKE_area_region_free(NULL, region);
1085                                                                 BLI_freelinkN(regionbase, region);
1086                                                         }
1087                                                 }
1088                                         }
1089                                 }
1090                         }
1091                 }
1092         }
1093
1094         if (!MAIN_VERSION_ATLEAST(bmain, 280, 13)) {
1095                 /* Initialize specular factor. */
1096                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "spec_fac")) {
1097                         for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
1098                                 la->spec_fac = 1.0f;
1099                         }
1100                 }
1101
1102                 /* Initialize new view3D options. */
1103                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1104                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1105                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1106                                         if (sl->spacetype == SPACE_VIEW3D) {
1107                                                 View3D *v3d = (View3D *)sl;
1108                                                 v3d->shading.light = V3D_LIGHTING_STUDIO;
1109                                                 v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR;
1110                                                 copy_v3_fl(v3d->shading.single_color, 0.8f);
1111                                                 v3d->shading.shadow_intensity = 0.5;
1112
1113                                                 v3d->overlay.backwire_opacity = 0.5f;
1114                                                 v3d->overlay.normals_length = 0.1f;
1115                                                 v3d->overlay.flag = 0;
1116                                         }
1117                                 }
1118                         }
1119                 }
1120
1121                 if (!DNA_struct_find(fd->filesdna, "View3DCursor")) {
1122                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1123                                 unit_qt(scene->cursor.rotation);
1124                         }
1125                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1126                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1127                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1128                                                 if (sl->spacetype == SPACE_VIEW3D) {
1129                                                         View3D *v3d = (View3D *)sl;
1130                                                         unit_qt(v3d->cursor.rotation);
1131                                                 }
1132                                         }
1133                                 }
1134                         }
1135                 }
1136         }
1137
1138         if (!MAIN_VERSION_ATLEAST(bmain, 280, 14)) {
1139                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "SceneDisplay", "display")) {
1140                         /* Initialize new scene.SceneDisplay */
1141                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1142                                 copy_v3_v3(scene->display.light_direction, (float[3]){-M_SQRT1_3, -M_SQRT1_3, M_SQRT1_3});
1143                         }
1144                 }
1145                 if (!DNA_struct_elem_find(fd->filesdna, "SceneDisplay", "float", "shadow_shift")) {
1146                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1147                                 scene->display.shadow_shift = 0.1;
1148                         }
1149                 }
1150
1151                 if (!DNA_struct_elem_find(fd->filesdna, "Object", "ObjectDisplay", "display")) {
1152                         /* Initialize new object.ObjectDisplay */
1153                         for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
1154                                 ob->display.flag = OB_SHOW_SHADOW;
1155                         }
1156                 }
1157
1158                 if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "transform_pivot_point")) {
1159                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1160                                 scene->toolsettings->transform_pivot_point = V3D_AROUND_CENTER_MEAN;
1161                         }
1162                 }
1163
1164                 if (!DNA_struct_find(fd->filesdna, "SceneEEVEE")) {
1165                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1166                                 /* First set the default for all the properties. */
1167
1168                                 scene->eevee.gi_diffuse_bounces = 3;
1169                                 scene->eevee.gi_cubemap_resolution = 512;
1170                                 scene->eevee.gi_visibility_resolution = 32;
1171
1172                                 scene->eevee.taa_samples = 16;
1173                                 scene->eevee.taa_render_samples = 64;
1174
1175                                 scene->eevee.sss_samples = 7;
1176                                 scene->eevee.sss_jitter_threshold = 0.3f;
1177
1178                                 scene->eevee.ssr_quality = 0.25f;
1179                                 scene->eevee.ssr_max_roughness = 0.5f;
1180                                 scene->eevee.ssr_thickness = 0.2f;
1181                                 scene->eevee.ssr_border_fade = 0.075f;
1182                                 scene->eevee.ssr_firefly_fac = 10.0f;
1183
1184                                 scene->eevee.volumetric_start = 0.1f;
1185                                 scene->eevee.volumetric_end = 100.0f;
1186                                 scene->eevee.volumetric_tile_size = 8;
1187                                 scene->eevee.volumetric_samples = 64;
1188                                 scene->eevee.volumetric_sample_distribution = 0.8f;
1189                                 scene->eevee.volumetric_light_clamp = 0.0f;
1190                                 scene->eevee.volumetric_shadow_samples = 16;
1191
1192                                 scene->eevee.gtao_distance = 0.2f;
1193                                 scene->eevee.gtao_factor = 1.0f;
1194                                 scene->eevee.gtao_quality = 0.25f;
1195
1196                                 scene->eevee.bokeh_max_size = 100.0f;
1197                                 scene->eevee.bokeh_threshold = 1.0f;
1198
1199                                 copy_v3_fl(scene->eevee.bloom_color, 1.0f);
1200                                 scene->eevee.bloom_threshold = 0.8f;
1201                                 scene->eevee.bloom_knee = 0.5f;
1202                                 scene->eevee.bloom_intensity = 0.8f;
1203                                 scene->eevee.bloom_radius = 6.5f;
1204                                 scene->eevee.bloom_clamp = 1.0f;
1205
1206                                 scene->eevee.motion_blur_samples = 8;
1207                                 scene->eevee.motion_blur_shutter = 1.0f;
1208
1209                                 scene->eevee.shadow_method = SHADOW_ESM;
1210                                 scene->eevee.shadow_cube_size = 512;
1211                                 scene->eevee.shadow_cascade_size = 1024;
1212
1213                                 scene->eevee.flag =
1214                                         SCE_EEVEE_VOLUMETRIC_LIGHTS |
1215                                         SCE_EEVEE_VOLUMETRIC_COLORED |
1216                                         SCE_EEVEE_GTAO_BENT_NORMALS |
1217                                         SCE_EEVEE_GTAO_BOUNCE |
1218                                         SCE_EEVEE_TAA_REPROJECTION |
1219                                         SCE_EEVEE_SSR_HALF_RESOLUTION;
1220
1221
1222                                 /* If the file is pre-2.80 move on. */
1223                                 if (scene->layer_properties == NULL) {
1224                                         continue;
1225                                 }
1226
1227                                 /* Now we handle eventual properties that may be set in the file. */
1228 #define EEVEE_GET_BOOL(_props, _name, _flag) \
1229                                 { \
1230                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1231                                         if (_idprop != NULL) { \
1232                                                 const int _value = IDP_Int(_idprop); \
1233                                                 if (_value) { \
1234                                                         scene->eevee.flag |= _flag; \
1235                                                 } \
1236                                                 else { \
1237                                                         scene->eevee.flag &= ~_flag; \
1238                                                 } \
1239                                         } \
1240                                 }
1241
1242 #define EEVEE_GET_INT(_props, _name) \
1243                                 { \
1244                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1245                                         if (_idprop != NULL) { \
1246                                                 scene->eevee._name = IDP_Int(_idprop); \
1247                                         } \
1248                                 }
1249
1250 #define EEVEE_GET_FLOAT(_props, _name) \
1251                                 { \
1252                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1253                                         if (_idprop != NULL) { \
1254                                                 scene->eevee._name = IDP_Float(_idprop); \
1255                                         } \
1256                                 }
1257
1258 #define EEVEE_GET_FLOAT_ARRAY(_props, _name, _length) \
1259                                 { \
1260                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1261                                         if (_idprop != NULL) { \
1262                                                 const float *_values = IDP_Array(_idprop); \
1263                                                 for (int _i = 0; _i < _length; _i++) { \
1264                                                         scene->eevee._name [_i] = _values[_i]; \
1265                                                 } \
1266                                         } \
1267                                 }
1268
1269                                 IDProperty *props = IDP_GetPropertyFromGroup(scene->layer_properties, RE_engine_id_BLENDER_EEVEE);
1270                                 EEVEE_GET_BOOL(props, volumetric_enable, SCE_EEVEE_VOLUMETRIC_ENABLED);
1271                                 EEVEE_GET_BOOL(props, volumetric_lights, SCE_EEVEE_VOLUMETRIC_LIGHTS);
1272                                 EEVEE_GET_BOOL(props, volumetric_shadows, SCE_EEVEE_VOLUMETRIC_SHADOWS);
1273                                 EEVEE_GET_BOOL(props, volumetric_colored_transmittance, SCE_EEVEE_VOLUMETRIC_COLORED);
1274                                 EEVEE_GET_BOOL(props, gtao_enable, SCE_EEVEE_GTAO_ENABLED);
1275                                 EEVEE_GET_BOOL(props, gtao_use_bent_normals, SCE_EEVEE_GTAO_BENT_NORMALS);
1276                                 EEVEE_GET_BOOL(props, gtao_bounce, SCE_EEVEE_GTAO_BOUNCE);
1277                                 EEVEE_GET_BOOL(props, dof_enable, SCE_EEVEE_DOF_ENABLED);
1278                                 EEVEE_GET_BOOL(props, bloom_enable, SCE_EEVEE_BLOOM_ENABLED);
1279                                 EEVEE_GET_BOOL(props, motion_blur_enable, SCE_EEVEE_MOTION_BLUR_ENABLED);
1280                                 EEVEE_GET_BOOL(props, shadow_high_bitdepth, SCE_EEVEE_SHADOW_HIGH_BITDEPTH);
1281                                 EEVEE_GET_BOOL(props, taa_reprojection, SCE_EEVEE_TAA_REPROJECTION);
1282                                 EEVEE_GET_BOOL(props, sss_enable, SCE_EEVEE_SSS_ENABLED);
1283                                 EEVEE_GET_BOOL(props, sss_separate_albedo, SCE_EEVEE_SSS_SEPARATE_ALBEDO);
1284                                 EEVEE_GET_BOOL(props, ssr_enable, SCE_EEVEE_SSR_ENABLED);
1285                                 EEVEE_GET_BOOL(props, ssr_refraction, SCE_EEVEE_SSR_REFRACTION);
1286                                 EEVEE_GET_BOOL(props, ssr_halfres, SCE_EEVEE_SSR_HALF_RESOLUTION);
1287
1288                                 EEVEE_GET_INT(props, gi_diffuse_bounces);
1289                                 EEVEE_GET_INT(props, gi_diffuse_bounces);
1290                                 EEVEE_GET_INT(props, gi_cubemap_resolution);
1291                                 EEVEE_GET_INT(props, gi_visibility_resolution);
1292
1293                                 EEVEE_GET_INT(props, taa_samples);
1294                                 EEVEE_GET_INT(props, taa_render_samples);
1295
1296                                 EEVEE_GET_INT(props, sss_samples);
1297                                 EEVEE_GET_FLOAT(props, sss_jitter_threshold);
1298
1299                                 EEVEE_GET_FLOAT(props, ssr_quality);
1300                                 EEVEE_GET_FLOAT(props, ssr_max_roughness);
1301                                 EEVEE_GET_FLOAT(props, ssr_thickness);
1302                                 EEVEE_GET_FLOAT(props, ssr_border_fade);
1303                                 EEVEE_GET_FLOAT(props, ssr_firefly_fac);
1304
1305                                 EEVEE_GET_FLOAT(props, volumetric_start);
1306                                 EEVEE_GET_FLOAT(props, volumetric_end);
1307                                 EEVEE_GET_INT(props, volumetric_tile_size);
1308                                 EEVEE_GET_INT(props, volumetric_samples);
1309                                 EEVEE_GET_FLOAT(props, volumetric_sample_distribution);
1310                                 EEVEE_GET_FLOAT(props, volumetric_light_clamp);
1311                                 EEVEE_GET_INT(props, volumetric_shadow_samples);
1312
1313                                 EEVEE_GET_FLOAT(props, gtao_distance);
1314                                 EEVEE_GET_FLOAT(props, gtao_factor);
1315                                 EEVEE_GET_FLOAT(props, gtao_quality);
1316
1317                                 EEVEE_GET_FLOAT(props, bokeh_max_size);
1318                                 EEVEE_GET_FLOAT(props, bokeh_threshold);
1319
1320                                 EEVEE_GET_FLOAT_ARRAY(props, bloom_color, 3);
1321                                 EEVEE_GET_FLOAT(props, bloom_threshold);
1322                                 EEVEE_GET_FLOAT(props, bloom_knee);
1323                                 EEVEE_GET_FLOAT(props, bloom_intensity);
1324                                 EEVEE_GET_FLOAT(props, bloom_radius);
1325                                 EEVEE_GET_FLOAT(props, bloom_clamp);
1326
1327                                 EEVEE_GET_INT(props, motion_blur_samples);
1328                                 EEVEE_GET_FLOAT(props, motion_blur_shutter);
1329
1330                                 EEVEE_GET_INT(props, shadow_method);
1331                                 EEVEE_GET_INT(props, shadow_cube_size);
1332                                 EEVEE_GET_INT(props, shadow_cascade_size);
1333
1334                                 /* Cleanup. */
1335                                 IDP_FreeProperty(scene->layer_properties);
1336                                 MEM_freeN(scene->layer_properties);
1337                                 scene->layer_properties = NULL;
1338
1339 #undef EEVEE_GET_FLOAT_ARRAY
1340 #undef EEVEE_GET_FLOAT
1341 #undef EEVEE_GET_INT
1342 #undef EEVEE_GET_BOOL
1343                         }
1344                 }
1345
1346
1347                 if (!MAIN_VERSION_ATLEAST(bmain, 280, 15)) {
1348                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1349                                 scene->display.matcap_ssao_distance = 0.2f;
1350                                 scene->display.matcap_ssao_attenuation = 1.0f;
1351                                 scene->display.matcap_ssao_samples = 16;
1352                         }
1353
1354                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1355                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1356                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1357                                                 if (sl->spacetype == SPACE_OUTLINER) {
1358                                                         SpaceOops *soops = (SpaceOops *)sl;
1359                                                         soops->filter_id_type = ID_GR;
1360                                                         soops->outlinevis = SO_VIEW_LAYER;
1361                                                 }
1362                                         }
1363                                 }
1364                         }
1365
1366                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1367                                 switch (scene->toolsettings->snap_mode) {
1368                                         case 0: scene->toolsettings->snap_mode = SCE_SNAP_MODE_INCREMENT; break;
1369                                         case 1: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VERTEX   ; break;
1370                                         case 2: scene->toolsettings->snap_mode = SCE_SNAP_MODE_EDGE     ; break;
1371                                         case 3: scene->toolsettings->snap_mode = SCE_SNAP_MODE_FACE     ; break;
1372                                         case 4: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VOLUME   ; break;
1373                                 }
1374                                 switch (scene->toolsettings->snap_node_mode) {
1375                                         case 5: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X; break;
1376                                         case 6: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_Y; break;
1377                                         case 7: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X | SCE_SNAP_MODE_NODE_Y; break;
1378                                         case 8: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID  ; break;
1379                                 }
1380                                 switch (scene->toolsettings->snap_uv_mode) {
1381                                         case 0: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_INCREMENT; break;
1382                                         case 1: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_VERTEX   ; break;
1383                                 }
1384                         }
1385
1386                         ParticleSettings *part;
1387                         for (part = bmain->particle.first; part; part = part->id.next) {
1388                                 part->shape_flag = PART_SHAPE_CLOSE_TIP;
1389                                 part->shape = 0.0f;
1390                                 part->rad_root = 1.0f;
1391                                 part->rad_tip = 0.0f;
1392                                 part->rad_scale = 0.01f;
1393                         }
1394                 }
1395
1396         }
1397
1398         if (!MAIN_VERSION_ATLEAST(bmain, 280, 18)) {
1399                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "roughness")) {
1400                         for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) {
1401                                 if (mat->use_nodes) {
1402                                         if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
1403                                                 mat->roughness = mat->gloss_mir;
1404                                         }
1405                                         else {
1406                                                 mat->roughness = 0.25f;
1407                                         }
1408                                 }
1409                                 else {
1410                                         mat->roughness = 1.0f - mat->gloss_mir;
1411                                 }
1412                                 mat->metallic = mat->ray_mirror;
1413                         }
1414
1415                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1416                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1417                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1418                                                 if (sl->spacetype == SPACE_VIEW3D) {
1419                                                         View3D *v3d = (View3D *)sl;
1420                                                         v3d->shading.flag |= V3D_SHADING_SPECULAR_HIGHLIGHT;
1421                                                 }
1422                                         }
1423                                 }
1424                         }
1425                 }
1426
1427                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "xray_alpha")) {
1428                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1429                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1430                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1431                                                 if (sl->spacetype == SPACE_VIEW3D) {
1432                                                         View3D *v3d = (View3D *)sl;
1433                                                         v3d->shading.xray_alpha = 0.5f;
1434                                                 }
1435                                         }
1436                                 }
1437                         }
1438                 }
1439                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "char", "matcap[256]")) {
1440                         StudioLight *default_matcap = BKE_studiolight_find_first(STUDIOLIGHT_ORIENTATION_VIEWNORMAL);
1441                         /* when loading the internal file is loaded before the matcaps */
1442                         if (default_matcap) {
1443                                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1444                                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1445                                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1446                                                         if (sl->spacetype == SPACE_VIEW3D) {
1447                                                                 View3D *v3d = (View3D *)sl;
1448                                                                 BLI_strncpy(v3d->shading.matcap, default_matcap->name, FILE_MAXFILE);
1449                                                         }
1450                                                 }
1451                                         }
1452                                 }
1453                         }
1454                 }
1455                 if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "wireframe_threshold")) {
1456                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1457                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1458                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1459                                                 if (sl->spacetype == SPACE_VIEW3D) {
1460                                                         View3D *v3d = (View3D *)sl;
1461                                                         v3d->overlay.wireframe_threshold = 0.5f;
1462                                                 }
1463                                         }
1464                                 }
1465                         }
1466                 }
1467                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "cavity_valley_factor")) {
1468                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1469                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1470                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1471                                                 if (sl->spacetype == SPACE_VIEW3D) {
1472                                                         View3D *v3d = (View3D *)sl;
1473                                                         v3d->shading.cavity_valley_factor = 1.0f;
1474                                                         v3d->shading.cavity_ridge_factor = 1.0f;
1475                                                 }
1476                                         }
1477                                 }
1478                         }
1479                 }
1480                 if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "bone_select_alpha")) {
1481                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1482                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1483                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1484                                                 if (sl->spacetype == SPACE_VIEW3D) {
1485                                                         View3D *v3d = (View3D *)sl;
1486                                                         v3d->overlay.bone_select_alpha = 0.5f;
1487                                                 }
1488                                         }
1489                                 }
1490                         }
1491                 }
1492         }
1493
1494         if (!MAIN_VERSION_ATLEAST(bmain, 280, 19)) {
1495                 if (!DNA_struct_elem_find(fd->filesdna, "Image", "ListBase", "renderslot")) {
1496                         for (Image *ima = bmain->image.first; ima; ima = ima->id.next) {
1497                                 if (ima->type == IMA_TYPE_R_RESULT) {
1498                                         for (int i = 0; i < 8; i++) {
1499                                                 RenderSlot *slot = MEM_callocN(sizeof(RenderSlot), "Image Render Slot Init");
1500                                                 BLI_snprintf(slot->name, sizeof(slot->name), "Slot %d", i + 1);
1501                                                 BLI_addtail(&ima->renderslots, slot);
1502                                         }
1503                                 }
1504                         }
1505                 }
1506                 if (!DNA_struct_elem_find(fd->filesdna, "SpaceAction", "char", "mode_prev")) {
1507                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1508                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1509                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1510                                                 if (sl->spacetype == SPACE_ACTION) {
1511                                                         SpaceAction *saction = (SpaceAction *)sl;
1512                                                         /* "Dopesheet" should be default here, unless it looks like the Action Editor was active instead */
1513                                                         if ((saction->mode_prev == 0) && (saction->action == NULL)) {
1514                                                                 saction->mode_prev = SACTCONT_DOPESHEET;
1515                                                         }
1516                                                 }
1517                                         }
1518                                 }
1519                         }
1520                 }
1521
1522                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1523                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1524                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1525                                         if (sl->spacetype == SPACE_VIEW3D) {
1526                                                 View3D *v3d = (View3D *)sl;
1527                                                 if (v3d->drawtype == OB_TEXTURE) {
1528                                                         v3d->drawtype = OB_SOLID;
1529                                                         v3d->shading.light = V3D_LIGHTING_STUDIO;
1530                                                         v3d->shading.color_type = V3D_SHADING_TEXTURE_COLOR;
1531                                                 }
1532                                         }
1533                                 }
1534                         }
1535                 }
1536
1537         }
1538
1539         if (!MAIN_VERSION_ATLEAST(bmain, 280, 21)) {
1540                 for (Scene *sce = bmain->scene.first; sce != NULL; sce = sce->id.next) {
1541                         if (sce->ed != NULL && sce->ed->seqbase.first != NULL) {
1542                                 do_versions_seq_unique_name_all_strips(sce, &sce->ed->seqbase);
1543                         }
1544                 }
1545
1546                 if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "texture_paint_mode_opacity")) {
1547                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1548                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1549                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1550                                                 if (sl->spacetype == SPACE_VIEW3D) {
1551                                                         View3D *v3d = (View3D *)sl;
1552                                                         float alpha = v3d->flag2 & V3D_SHOW_MODE_SHADE_OVERRIDE ? 0.0f : 0.8f;
1553                                                         v3d->overlay.texture_paint_mode_opacity = alpha;
1554                                                         v3d->overlay.vertex_paint_mode_opacity = alpha;
1555                                                         v3d->overlay.weight_paint_mode_opacity = alpha;
1556                                                 }
1557                                         }
1558                                 }
1559                         }
1560                 }
1561
1562                 if (!DNA_struct_elem_find(fd->filesdna, "SceneEEVEE", "float", "gi_cubemap_draw_size")) {
1563                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1564                                 scene->eevee.gi_irradiance_draw_size = 0.1f;
1565                                 scene->eevee.gi_cubemap_draw_size = 0.3f;
1566                         }
1567                 }
1568
1569                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1570                         if (scene->toolsettings->gizmo_flag == 0) {
1571                                 scene->toolsettings->gizmo_flag = SCE_MANIP_TRANSLATE | SCE_MANIP_ROTATE | SCE_MANIP_SCALE;
1572                         }
1573                 }
1574
1575                 if (!DNA_struct_elem_find(fd->filesdna, "RigidBodyWorld", "RigidBodyWorld_Shared", "*shared")) {
1576                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1577                                 RigidBodyWorld *rbw = scene->rigidbody_world;
1578
1579                                 if (rbw == NULL) {
1580                                         continue;
1581                                 }
1582
1583                                 if (rbw->shared == NULL) {
1584                                         rbw->shared = MEM_callocN(sizeof(*rbw->shared), "RigidBodyWorld_Shared");
1585                                 }
1586
1587                                 /* Move shared pointers from deprecated location to current location */
1588                                 rbw->shared->pointcache = rbw->pointcache;
1589                                 rbw->shared->ptcaches = rbw->ptcaches;
1590
1591                                 rbw->pointcache = NULL;
1592                                 BLI_listbase_clear(&rbw->ptcaches);
1593
1594                                 if (rbw->shared->pointcache == NULL) {
1595                                         rbw->shared->pointcache = BKE_ptcache_add(&(rbw->shared->ptcaches));
1596                                 }
1597
1598                         }
1599                 }
1600
1601                 if (!DNA_struct_elem_find(fd->filesdna, "SoftBody", "SoftBody_Shared", "*shared")) {
1602                         for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
1603                                 SoftBody *sb = ob->soft;
1604                                 if (sb == NULL) {
1605                                         continue;
1606                                 }
1607                                 if (sb->shared == NULL) {
1608                                         sb->shared = MEM_callocN(sizeof(*sb->shared), "SoftBody_Shared");
1609                                 }
1610
1611                                 /* Move shared pointers from deprecated location to current location */
1612                                 sb->shared->pointcache = sb->pointcache;
1613                                 sb->shared->ptcaches = sb->ptcaches;
1614
1615                                 sb->pointcache = NULL;
1616                                 BLI_listbase_clear(&sb->ptcaches);
1617                         }
1618                 }
1619
1620                 if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "short", "type")) {
1621                         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
1622                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1623                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1624                                                 if (sl->spacetype == SPACE_VIEW3D) {
1625                                                         View3D *v3d = (View3D *)sl;
1626                                                         if (v3d->drawtype == OB_RENDER) {
1627                                                                 v3d->drawtype = OB_SOLID;
1628                                                         }
1629                                                         v3d->shading.type = v3d->drawtype;
1630                                                         v3d->shading.prev_type = OB_SOLID;
1631                                                 }
1632                                         }
1633                                 }
1634                         }
1635                 }
1636
1637                 if (!DNA_struct_elem_find(fd->filesdna, "SceneDisplay", "View3DShading", "shading")) {
1638                         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
1639                                 BKE_screen_view3d_shading_init(&scene->display.shading);
1640                         }
1641                 }
1642         }
1643
1644 }