Orientation for 3D cursor
[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_scene_types.h"
53 #include "DNA_screen_types.h"
54 #include "DNA_view3d_types.h"
55 #include "DNA_genfile.h"
56 #include "DNA_workspace_types.h"
57
58 #include "BKE_collection.h"
59 #include "BKE_constraint.h"
60 #include "BKE_customdata.h"
61 #include "BKE_freestyle.h"
62 #include "BKE_group.h"
63 #include "BKE_idprop.h"
64 #include "BKE_layer.h"
65 #include "BKE_main.h"
66 #include "BKE_mesh.h"
67 #include "BKE_node.h"
68 #include "BKE_report.h"
69 #include "BKE_scene.h"
70 #include "BKE_screen.h"
71 #include "BKE_workspace.h"
72
73 #include "BLO_readfile.h"
74 #include "readfile.h"
75
76 #include "MEM_guardedalloc.h"
77
78
79 static bScreen *screen_parent_find(const bScreen *screen)
80 {
81         /* can avoid lookup if screen state isn't maximized/full (parent and child store the same state) */
82         if (ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL)) {
83                 for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
84                         if (sa->full && sa->full != screen) {
85                                 BLI_assert(sa->full->state == screen->state);
86                                 return sa->full;
87                         }
88                 }
89         }
90
91         return NULL;
92 }
93
94 static void do_version_workspaces_create_from_screens(Main *bmain)
95 {
96         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
97                 const bScreen *screen_parent = screen_parent_find(screen);
98                 Scene *scene = screen->scene;
99                 WorkSpace *workspace;
100                 ViewLayer *layer = BLI_findlink(&scene->view_layers, scene->r.actlay);
101                 if (!layer) {
102                         layer = BKE_view_layer_default_view(scene);
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(workspace, screen, screen->id.name + 2);
115                 BKE_workspace_view_layer_set(workspace, layer, scene);
116         }
117 }
118
119 static void do_version_area_change_space_to_space_action(ScrArea *area, const Scene *scene)
120 {
121         SpaceType *stype = BKE_spacetype_from_id(SPACE_ACTION);
122         SpaceAction *saction = (SpaceAction *)stype->new(area, scene);
123         ARegion *region_channels;
124
125         /* Properly free current regions */
126         for (ARegion *region = area->regionbase.first; region; region = region->next) {
127                 BKE_area_region_free(area->type, region);
128         }
129         BLI_freelistN(&area->regionbase);
130
131         area->type = stype;
132         area->spacetype = stype->spaceid;
133
134         BLI_addhead(&area->spacedata, saction);
135         area->regionbase = saction->regionbase;
136         BLI_listbase_clear(&saction->regionbase);
137
138         /* Different defaults for timeline */
139         region_channels = BKE_area_find_region_type(area, RGN_TYPE_CHANNELS);
140         region_channels->flag |= RGN_FLAG_HIDDEN;
141
142         saction->mode = SACTCONT_TIMELINE;
143         saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED;
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                         WorkSpace *workspace = BLI_findstring(&bmain->workspaces, screen->id.name + 2, offsetof(ID, name) + 2);
168                         ListBase *layouts = BKE_workspace_layouts_get(workspace);
169
170                         win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
171
172                         BKE_workspace_active_set(win->workspace_hook, workspace);
173                         BKE_workspace_active_layout_set(win->workspace_hook, layouts->first);
174
175                         win->scene = screen->scene;
176                         /* Deprecated from now on! */
177                         win->screen = NULL;
178                 }
179         }
180
181         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
182                 /* Deprecated from now on! */
183                 BLI_freelistN(&screen->scene->transform_spaces);
184                 screen->scene = NULL;
185         }
186 }
187
188 enum {
189         DO_VERSION_COLLECTION_VISIBLE     = 0,
190         DO_VERSION_COLLECTION_HIDE        = 1,
191         DO_VERSION_COLLECTION_HIDE_RENDER = 2,
192         DO_VERSION_COLLECTION_HIDE_ALL    = 3,
193 };
194
195 void do_versions_after_linking_280(Main *main)
196 {
197         if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
198                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
199                         /* since we don't have access to FileData we check the (always valid) first render layer instead */
200                         if (scene->view_layers.first == NULL) {
201                                 SceneCollection *sc_master = BKE_collection_master(&scene->id);
202                                 BLI_strncpy(sc_master->name, "Master Collection", sizeof(sc_master->name));
203
204                                 struct DoVersionSceneCollections {
205                                         SceneCollection *collections[20];
206                                         int created;
207                                         const char *suffix;
208                                         int flag_viewport;
209                                         int flag_render;
210                                 } collections[] =
211                                 {
212                                         {
213                                                 .collections = {NULL},
214                                                 .created = 0,
215                                                 .suffix = "",
216                                                 .flag_viewport = COLLECTION_SELECTABLE,
217                                                 .flag_render = COLLECTION_SELECTABLE
218                                         },
219                                         {
220                                                 .collections = {NULL},
221                                                 .created = 0,
222                                                 .suffix = " - Hide Viewport",
223                                                 .flag_viewport = COLLECTION_SELECTABLE,
224                                                 .flag_render = COLLECTION_SELECTABLE
225                                         },
226                                         {
227                                                 .collections = {NULL},
228                                                 .created = 0,
229                                                 .suffix = " - Hide Render",
230                                                 .flag_viewport = COLLECTION_SELECTABLE,
231                                                 .flag_render = COLLECTION_SELECTABLE | COLLECTION_DISABLED
232                                         },
233                                         {
234                                                 .collections = {NULL},
235                                                 .created = 0,
236                                                 .suffix = " - Hide Render All",
237                                                 .flag_viewport = COLLECTION_SELECTABLE | COLLECTION_DISABLED,
238                                                 .flag_render = COLLECTION_SELECTABLE | COLLECTION_DISABLED
239                                         }
240                                 };
241
242                                 for (int layer = 0; layer < 20; layer++) {
243                                         for (Base *base = scene->base.first; base; base = base->next) {
244                                                 if (base->lay & (1 << layer)) {
245                                                         int collection_index = -1;
246                                                         if ((base->object->restrictflag & OB_RESTRICT_VIEW) &&
247                                                             (base->object->restrictflag & OB_RESTRICT_RENDER))
248                                                         {
249                                                                 collection_index = DO_VERSION_COLLECTION_HIDE_ALL;
250                                                         }
251                                                         else if (base->object->restrictflag & OB_RESTRICT_VIEW) {
252                                                                 collection_index = DO_VERSION_COLLECTION_HIDE;
253                                                         }
254                                                         else if (base->object->restrictflag & OB_RESTRICT_RENDER) {
255                                                                 collection_index = DO_VERSION_COLLECTION_HIDE_RENDER;
256                                                         }
257                                                         else {
258                                                                 collection_index = DO_VERSION_COLLECTION_VISIBLE;
259                                                         }
260
261                                                         /* Create collections when needed only. */
262                                                         if ((collections[collection_index].created & (1 << layer)) == 0) {
263                                                                 char name[MAX_NAME];
264
265                                                                 if ((collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) == 0) {
266                                                                         BLI_snprintf(name,
267                                                                                      sizeof(sc_master->name),
268                                                                                      "Collection %d%s",
269                                                                                      layer + 1,
270                                                                                      collections[DO_VERSION_COLLECTION_VISIBLE].suffix);
271                                                                         collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer] =
272                                                                                 BKE_collection_add(&scene->id, sc_master, COLLECTION_TYPE_NONE, name);
273                                                                         collections[DO_VERSION_COLLECTION_VISIBLE].created |= (1 << layer);
274                                                                 }
275
276                                                                 if (collection_index != DO_VERSION_COLLECTION_VISIBLE) {
277                                                                         SceneCollection *sc_parent;
278                                                                         sc_parent = collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer];
279                                                                         BLI_snprintf(name,
280                                                                                      sizeof(sc_master->name),
281                                                                                      "Collection %d%s",
282                                                                                      layer + 1,
283                                                                                      collections[collection_index].suffix);
284                                                                         collections[collection_index].collections[layer] = BKE_collection_add(
285                                                                                 &scene->id,
286                                                                                 sc_parent,
287                                                                                 COLLECTION_TYPE_NONE,
288                                                                                 name);
289                                                                         collections[collection_index].created |= (1 << layer);
290                                                                 }
291                                                         }
292
293                                                         BKE_collection_object_add(
294                                                                 &scene->id, collections[collection_index].collections[layer], base->object);
295                                                 }
296
297                                                 if (base->flag & SELECT) {
298                                                         base->object->flag |= SELECT;
299                                                 }
300                                                 else {
301                                                         base->object->flag &= ~SELECT;
302                                                 }
303                                         }
304                                 }
305
306                                 /* Re-order the nested hidden collections. */
307                                 SceneCollection *scene_collection_parent = sc_master->scene_collections.first;
308
309                                 for (int layer = 0; layer < 20; layer++) {
310                                         if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
311
312                                                 if ((collections[DO_VERSION_COLLECTION_HIDE].created & (1 << layer)) &&
313                                                     (collections[DO_VERSION_COLLECTION_HIDE].collections[layer] !=
314                                                      scene_collection_parent->scene_collections.first))
315                                                 {
316                                                         BLI_listbase_swaplinks(
317                                                                 &scene_collection_parent->scene_collections,
318                                                                 collections[DO_VERSION_COLLECTION_HIDE].collections[layer],
319                                                                 scene_collection_parent->scene_collections.first);
320                                                 }
321
322                                                 if ((collections[DO_VERSION_COLLECTION_HIDE_ALL].created & (1 << layer)) &&
323                                                     (collections[DO_VERSION_COLLECTION_HIDE_ALL].collections[layer] !=
324                                                      scene_collection_parent->scene_collections.last))
325                                                 {
326                                                         BLI_listbase_swaplinks(
327                                                                 &scene_collection_parent->scene_collections,
328                                                                 collections[DO_VERSION_COLLECTION_HIDE_ALL].collections[layer],
329                                                                 scene_collection_parent->scene_collections.last);
330                                                 }
331
332                                                 scene_collection_parent = scene_collection_parent->next;
333                                         }
334                                 }
335                                 BLI_assert(scene_collection_parent == NULL);
336
337                                 /* Handle legacy render layers. */
338                                 {
339                                         for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
340
341                                                 ViewLayer *view_layer = BKE_view_layer_add(scene, srl->name);
342
343                                                 if (srl->samples != 0) {
344                                                         /* It is up to the external engine to handle
345                                                          * its own doversion in this case. */
346                                                         BKE_override_view_layer_int_add(
347                                                                 view_layer,
348                                                                 ID_SCE,
349                                                                 "samples",
350                                                                 srl->samples);
351                                                 }
352
353                                                 if (srl->mat_override) {
354                                                         BKE_override_view_layer_datablock_add(
355                                                                 view_layer,
356                                                                 ID_MA,
357                                                                 "self",
358                                                                 (ID *)srl->mat_override);
359                                                 }
360
361                                                 if (srl->layflag & SCE_LAY_DISABLE) {
362                                                         view_layer->flag &= ~VIEW_LAYER_RENDER;
363                                                 }
364
365                                                 if ((srl->layflag & SCE_LAY_FRS) == 0) {
366                                                         view_layer->flag &= ~VIEW_LAYER_FREESTYLE;
367                                                 }
368
369                                                 /* XXX If we are to keep layflag it should be merged with flag (dfelinto). */
370                                                 view_layer->layflag = srl->layflag;
371                                                 /* XXX Not sure if we should keep the passes (dfelinto). */
372                                                 view_layer->passflag = srl->passflag;
373                                                 view_layer->pass_xor = srl->pass_xor;
374                                                 view_layer->pass_alpha_threshold = srl->pass_alpha_threshold;
375
376                                                 BKE_freestyle_config_free(&view_layer->freestyle_config, true);
377                                                 view_layer->freestyle_config = srl->freestyleConfig;
378                                                 view_layer->id_properties = srl->prop;
379
380                                                 /* unlink master collection  */
381                                                 BKE_collection_unlink(view_layer, view_layer->layer_collections.first);
382
383                                                 /* Add new collection bases. */
384                                                 for (int layer = 0; layer < 20; layer++) {
385                                                         if ((scene->lay & srl->lay & ~(srl->lay_exclude) & (1 << layer)) ||
386                                                             (srl->lay_zmask & (scene->lay | srl->lay_exclude) & (1 << layer)))
387                                                         {
388                                                                 if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
389
390                                                                         LayerCollection *layer_collection_parent;
391                                                                         layer_collection_parent = BKE_collection_link(
392                                                                                 view_layer,
393                                                                                 collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer]);
394
395                                                                         if (srl->lay_zmask & (1 << layer)) {
396                                                                                 BKE_override_layer_collection_boolean_add(
397                                                                                         layer_collection_parent,
398                                                                                         ID_OB,
399                                                                                         "cycles.is_holdout",
400                                                                                         true);
401                                                                         }
402
403                                                                         if ((srl->lay & (1 << layer)) == 0) {
404                                                                                 BKE_override_layer_collection_boolean_add(
405                                                                                         layer_collection_parent,
406                                                                                         ID_OB,
407                                                                                         "cycles_visibility.camera",
408                                                                                         false);
409                                                                         }
410
411                                                                         LayerCollection *layer_collection_child;
412                                                                         layer_collection_child = layer_collection_parent->layer_collections.first;
413
414                                                                         for (int j = 1; j < 4; j++) {
415                                                                                 if (collections[j].created & (1 << layer)) {
416                                                                                         layer_collection_child->flag = COLLECTION_VIEWPORT |
417                                                                                                                        COLLECTION_RENDER |
418                                                                                                                        collections[j].flag_render;
419                                                                                         layer_collection_child = layer_collection_child->next;
420                                                                                 }
421                                                                         }
422                                                                         BLI_assert(layer_collection_child == NULL);
423                                                                 }
424                                                         }
425                                                 }
426
427                                                 /* for convenience set the same active object in all the layers */
428                                                 if (scene->basact) {
429                                                         view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
430                                                 }
431
432                                                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
433                                                         if ((base->flag & BASE_SELECTABLED) && (base->object->flag & SELECT)) {
434                                                                 base->flag |= BASE_SELECTED;
435                                                         }
436                                                 }
437                                         }
438                                 }
439                                 BLI_freelistN(&scene->r.layers);
440
441                                 ViewLayer *view_layer = BKE_view_layer_add(scene, "Viewport");
442                                 /* If we ported all the original render layers, we don't need to make the viewport layer renderable. */
443                                 if (!BLI_listbase_is_single(&scene->view_layers)) {
444                                         view_layer->flag &= ~VIEW_LAYER_RENDER;
445                                 }
446
447                                 /* If layer was not set, disable it. */
448                                 LayerCollection *layer_collection_parent;
449                                 layer_collection_parent =
450                                         ((LayerCollection *)view_layer->layer_collections.first)->layer_collections.first;
451
452                                 for (int layer = 0; layer < 20; layer++) {
453                                         if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
454                                                 const bool is_disabled = (scene->lay & (1 << layer)) == 0;
455
456                                                 /* We only need to disable the parent collection. */
457                                                 if (is_disabled) {
458                                                         layer_collection_parent->flag |= COLLECTION_DISABLED;
459                                                 }
460
461                                                 LayerCollection *layer_collection_child;
462                                                 layer_collection_child = layer_collection_parent->layer_collections.first;
463
464                                                 for (int j = 1; j < 4; j++) {
465                                                         if (collections[j].created & (1 << layer)) {
466                                                                 layer_collection_child->flag = COLLECTION_VIEWPORT |
467                                                                                                COLLECTION_RENDER |
468                                                                                                collections[j].flag_viewport;
469                                                                 layer_collection_child = layer_collection_child->next;
470                                                         }
471                                                 }
472                                                 BLI_assert(layer_collection_child == NULL);
473                                                 layer_collection_parent = layer_collection_parent->next;
474                                         }
475                                 }
476                                 BLI_assert(layer_collection_parent == NULL);
477
478                                 /* convert active base */
479                                 if (scene->basact) {
480                                         view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
481                                 }
482
483                                 /* convert selected bases */
484                                 for (Base *base = view_layer->object_bases.first; base; base = base->next) {
485                                         if ((base->flag & BASE_SELECTABLED) && (base->object->flag & SELECT)) {
486                                                 base->flag |= BASE_SELECTED;
487                                         }
488
489                                         /* keep lay around for forward compatibility (open those files in 2.79) */
490                                         base->lay = base->object->lay;
491                                 }
492
493                                 /* remove bases once and for all */
494                                 for (Base *base = scene->base.first; base; base = base->next) {
495                                         id_us_min(&base->object->id);
496                                 }
497                                 BLI_freelistN(&scene->base);
498                                 scene->basact = NULL;
499                         }
500                 }
501         }
502
503         if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
504                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
505                         /* same render-layer as do_version_workspaces_after_lib_link will activate,
506                          * so same layer as BKE_view_layer_from_workspace_get would return */
507                         ViewLayer *layer = screen->scene->view_layers.first;
508
509                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
510                                 for (SpaceLink *view_layer = sa->spacedata.first; view_layer; view_layer = view_layer->next) {
511                                         if (view_layer->spacetype == SPACE_OUTLINER) {
512                                                 SpaceOops *soutliner = (SpaceOops *)view_layer;
513
514                                                 soutliner->outlinevis = SO_COLLECTIONS;
515
516                                                 if (BLI_listbase_count_at_most(&layer->layer_collections, 2) == 1) {
517                                                         if (soutliner->treestore == NULL) {
518                                                                 soutliner->treestore = BLI_mempool_create(
519                                                                         sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
520                                                         }
521
522                                                         /* Create a tree store element for the collection. This is normally
523                                                          * done in check_persistent (outliner_tree.c), but we need to access
524                                                          * it here :/ (expand element if it's the only one) */
525                                                         TreeStoreElem *tselem = BLI_mempool_calloc(soutliner->treestore);
526                                                         tselem->type = TSE_LAYER_COLLECTION;
527                                                         tselem->id = layer->layer_collections.first;
528                                                         tselem->nr = tselem->used = 0;
529                                                         tselem->flag &= ~TSE_CLOSED;
530                                                 }
531                                         }
532                                 }
533                         }
534                 }
535         }
536
537         /* New workspace design */
538         if (!MAIN_VERSION_ATLEAST(main, 280, 1)) {
539                 do_version_workspaces_after_lib_link(main);
540         }
541
542         if (!MAIN_VERSION_ATLEAST(main, 280, 2)) {
543                 /* Cleanup any remaining SceneRenderLayer data for files that were created
544                  * with Blender 2.8 before the SceneRenderLayer > RenderLayer refactor. */
545                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
546                         for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
547                                 if (srl->prop) {
548                                         IDP_FreeProperty(srl->prop);
549                                         MEM_freeN(srl->prop);
550                                 }
551                                 BKE_freestyle_config_free(&srl->freestyleConfig, true);
552                         }
553                         BLI_freelistN(&scene->r.layers);
554                 }
555         }
556
557         if (!MAIN_VERSION_ATLEAST(main, 280, 3)) {
558                 /* Due to several changes to particle RNA and draw code particles from older files may no longer
559                  * be visible. Here we correct this by setting a default draw size for those files. */
560                 for (Object *object = main->object.first; object; object = object->id.next) {
561                         for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
562                                 if (psys->part->draw_size == 0.0f) {
563                                         psys->part->draw_size = 0.1f;
564                                 }
565                         }
566                 }
567         }
568
569         {
570                 for (WorkSpace *workspace = main->workspaces.first; workspace; workspace = workspace->id.next) {
571                         if (workspace->view_layer) {
572                                 /* During 2.8 work we temporarly stored view-layer in the
573                                  * workspace directly, but should be stored there per-scene. */
574                                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
575                                         if (BLI_findindex(&scene->view_layers, workspace->view_layer) != -1) {
576                                                 BKE_workspace_view_layer_set(workspace, workspace->view_layer, scene);
577                                                 workspace->view_layer = NULL;
578                                         }
579                                 }
580                         }
581                         /* While this should apply to most cases, it fails when reading workspaces.blend
582                          * to get its list of workspaces without actually appending any of them. */
583 //                      BLI_assert(workspace->view_layer == NULL);
584                 }
585         }
586
587         {
588                 /* Since we don't have access to FileData we check the (always valid) master collection of the group. */
589                 for (Group *group = main->group.first; group; group = group->id.next) {
590                         if (group->collection == NULL) {
591                                 BKE_group_init(group);
592                                 SceneCollection *sc = GROUP_MASTER_COLLECTION(group);
593                                 SceneCollection *sc_hidden = NULL;
594
595                                 for (GroupObject *go = group->gobject.first; go; go = go->next) {
596                                         if (go->ob->lay & group->layer) {
597                                                 BKE_collection_object_add(&group->id, sc, go->ob);
598                                         }
599                                         else {
600                                                 if (sc_hidden == NULL) {
601                                                         sc_hidden = BKE_collection_add(&group->id, sc, COLLECTION_TYPE_GROUP_INTERNAL, "Hidden");
602                                                 }
603                                                 BKE_collection_object_add(&group->id, sc_hidden, go->ob);
604                                         }
605                                 }
606
607                                 if (sc_hidden != NULL) {
608                                         LayerCollection *layer_collection_master, *layer_collection_hidden;
609                                         layer_collection_master = group->view_layer->layer_collections.first;
610                                         layer_collection_hidden = layer_collection_master->layer_collections.first;
611                                         layer_collection_hidden->flag |= COLLECTION_DISABLED;
612                                 }
613                         }
614
615                         GroupObject *go;
616                         while ((go = BLI_pophead(&group->gobject))) {
617                                 MEM_freeN(go);
618                         }
619                 }
620         }
621
622         {
623                 for (Object *object = main->object.first; object; object = object->id.next) {
624 #ifndef VERSION_280_SUBVERSION_4
625                         /* If any object already has an initialized value for
626                          * duplicator_visibility_flag it means we've already doversioned it.
627                          * TODO(all) remove the VERSION_280_SUBVERSION_4 code once the subversion was bumped. */
628                         if (object->duplicator_visibility_flag != 0) {
629                                 break;
630                         }
631 #endif
632                         if (object->particlesystem.first) {
633                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
634                                 for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
635                                         if (psys->part->draw & PART_DRAW_EMITTER) {
636                                                 object->duplicator_visibility_flag |= OB_DUPLI_FLAG_RENDER;
637 #ifndef VERSION_280_SUBVERSION_4
638                                                 psys->part->draw &= ~PART_DRAW_EMITTER;
639 #else
640                                                 break;
641 #endif
642                                         }
643                                 }
644                         }
645                         else if (object->transflag & OB_DUPLI) {
646                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
647                         }
648                         else {
649                                 object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER;
650                         }
651                 }
652         }
653
654         /* SpaceTime & SpaceLogic removal/replacing */
655         if (!MAIN_VERSION_ATLEAST(main, 280, 9)) {
656                 const wmWindowManager *wm = main->wm.first;
657                 const Scene *scene = main->scene.first;
658
659                 if (wm != NULL) {
660                         /* Action editors need a scene for creation. First, update active
661                          * screens using the active scene of the window they're displayed in.
662                          * Next, update remaining screens using first scene in main listbase. */
663
664                         for (wmWindow *win = wm->windows.first; win; win = win->next) {
665                                 const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
666                                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
667                                         if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
668                                                 do_version_area_change_space_to_space_action(area, win->scene);
669
670                                                 /* Don't forget to unset! */
671                                                 area->butspacetype = SPACE_EMPTY;
672                                         }
673                                 }
674                         }
675                 }
676                 if (scene != NULL) {
677                         for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
678                                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
679                                         if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
680                                                 /* Areas that were already handled won't be handled again */
681                                                 do_version_area_change_space_to_space_action(area, scene);
682
683                                                 /* Don't forget to unset! */
684                                                 area->butspacetype = SPACE_EMPTY;
685                                         }
686                                 }
687                         }
688                 }
689         }
690 }
691
692 static void do_version_layer_collections_idproperties(ListBase *lb)
693 {
694         IDPropertyTemplate val = {0};
695         for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
696                 lc->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
697                 BKE_layer_collection_engine_settings_create(lc->properties);
698
699                 /* No overrides at first */
700                 for (IDProperty *prop = lc->properties->data.group.first; prop; prop = prop->next) {
701                         while (prop->data.group.first) {
702                                 IDP_FreeFromGroup(prop, prop->data.group.first);
703                         }
704                 }
705
706                 /* Do it recursively */
707                 do_version_layer_collections_idproperties(&lc->layer_collections);
708         }
709 }
710
711 static void do_version_view_layer_visibility(ViewLayer *view_layer)
712 {
713         LayerCollection *layer_collection;
714         for (layer_collection = view_layer->layer_collections.first;
715              layer_collection;
716              layer_collection = layer_collection->next)
717         {
718                 if (layer_collection->flag & COLLECTION_DISABLED) {
719                         BKE_collection_enable(view_layer, layer_collection);
720                         layer_collection->flag &= ~COLLECTION_DISABLED;
721                 }
722
723                 if ((layer_collection->flag & (1 << 0)) == 0) { /* !COLLECTION_VISIBLE */
724                         layer_collection->flag |= COLLECTION_DISABLED;
725                 }
726                 layer_collection->flag |= COLLECTION_VIEWPORT | COLLECTION_RENDER;
727         }
728 }
729
730 void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
731 {
732
733         if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
734                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers")) {
735                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
736                                 /* Master Collection */
737                                 scene->collection = MEM_callocN(sizeof(SceneCollection), "Master Collection");
738                                 BLI_strncpy(scene->collection->name, "Master Collection", sizeof(scene->collection->name));
739                         }
740                 }
741
742                 if (DNA_struct_elem_find(fd->filesdna, "LayerCollection", "ListBase", "engine_settings") &&
743                     !DNA_struct_elem_find(fd->filesdna, "LayerCollection", "IDProperty", "properties"))
744                 {
745                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
746                                 for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
747                                         do_version_layer_collections_idproperties(&view_layer->layer_collections);
748                                 }
749                         }
750                 }
751
752                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
753                         scene->r.gauss = 1.5f;
754                 }
755         }
756
757         if (!MAIN_VERSION_ATLEAST(main, 280, 1)) {
758                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "bleedexp")) {
759                         for (Lamp *la = main->lamp.first; la; la = la->id.next) {
760                                 la->bleedexp = 2.5f;
761                         }
762                 }
763
764                 if (!DNA_struct_elem_find(fd->filesdna, "GPUDOFSettings", "float", "ratio")) {
765                         for (Camera *ca = main->camera.first; ca; ca = ca->id.next) {
766                                 ca->gpu_dof.ratio = 1.0f;
767                         }
768                 }
769
770                 if (!DNA_struct_elem_find(fd->filesdna, "ViewLayer", "IDProperty", "*properties")) {
771                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
772                                 for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
773                                         IDPropertyTemplate val = {0};
774                                         view_layer->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
775                                         BKE_view_layer_engine_settings_create(view_layer->properties);
776                                 }
777                         }
778                 }
779
780                 /* MTexPoly now removed. */
781                 if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
782                         const int cd_mtexpoly = 15;  /* CD_MTEXPOLY, deprecated */
783                         for (Mesh *me = main->mesh.first; me; me = me->id.next) {
784                                 /* If we have UV's, so this file will have MTexPoly layers too! */
785                                 if (me->mloopuv != NULL) {
786                                         CustomData_update_typemap(&me->pdata);
787                                         CustomData_free_layers(&me->pdata, cd_mtexpoly, me->totpoly);
788                                         BKE_mesh_update_customdata_pointers(me, false);
789                                 }
790                         }
791                 }
792         }
793
794         if (!MAIN_VERSION_ATLEAST(main, 280, 2)) {
795                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "cascade_max_dist")) {
796                         for (Lamp *la = main->lamp.first; la; la = la->id.next) {
797                                 la->cascade_max_dist = 1000.0f;
798                                 la->cascade_count = 4;
799                                 la->cascade_exponent = 0.8f;
800                                 la->cascade_fade = 0.1f;
801                         }
802                 }
803
804                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "contact_dist")) {
805                         for (Lamp *la = main->lamp.first; la; la = la->id.next) {
806                                 la->contact_dist = 1.0f;
807                                 la->contact_bias = 0.03f;
808                                 la->contact_spread = 0.2f;
809                                 la->contact_thickness = 0.5f;
810                         }
811                 }
812
813                 if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "vis_bias")) {
814                         for (LightProbe *probe = main->lightprobe.first; probe; probe = probe->id.next) {
815                                 probe->vis_bias = 1.0f;
816                                 probe->vis_blur = 0.2f;
817                         }
818                 }
819
820                 typedef enum eNTreeDoVersionErrors {
821                         NTREE_DOVERSION_NO_ERROR = 0,
822                         NTREE_DOVERSION_NEED_OUTPUT = (1 << 0),
823                         NTREE_DOVERSION_TRANSPARENCY_EMISSION = (1 << 1),
824                 } eNTreeDoVersionErrors;
825
826                 /* Eevee shader nodes renamed because of the output node system.
827                  * Note that a new output node is not being added here, because it would be overkill
828                  * to handle this case in lib_verify_nodetree.
829                  *
830                  * Also, metallic node is now unified into the principled node. */
831                 eNTreeDoVersionErrors error = NTREE_DOVERSION_NO_ERROR;
832
833                 FOREACH_NODETREE(main, ntree, id) {
834                         if (ntree->type == NTREE_SHADER) {
835                                 for (bNode *node = ntree->nodes.first; node; node = node->next) {
836                                         if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
837                                             STREQ(node->idname, "ShaderNodeOutputMetallic"))
838                                         {
839                                                 BLI_strncpy(node->idname, "ShaderNodeEeveeMetallic", sizeof(node->idname));
840                                                 error |= NTREE_DOVERSION_NEED_OUTPUT;
841                                         }
842
843                                         else if (node->type == SH_NODE_EEVEE_SPECULAR && STREQ(node->idname, "ShaderNodeOutputSpecular")) {
844                                                 BLI_strncpy(node->idname, "ShaderNodeEeveeSpecular", sizeof(node->idname));
845                                                 error |= NTREE_DOVERSION_NEED_OUTPUT;
846                                         }
847
848                                         else if (node->type == 196 /* SH_NODE_OUTPUT_EEVEE_MATERIAL */ &&
849                                                  STREQ(node->idname, "ShaderNodeOutputEeveeMaterial"))
850                                         {
851                                                 node->type = SH_NODE_OUTPUT_MATERIAL;
852                                                 BLI_strncpy(node->idname, "ShaderNodeOutputMaterial", sizeof(node->idname));
853                                         }
854
855                                         else if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
856                                                  STREQ(node->idname, "ShaderNodeEeveeMetallic"))
857                                         {
858                                                 node->type = SH_NODE_BSDF_PRINCIPLED;
859                                                 BLI_strncpy(node->idname, "ShaderNodeBsdfPrincipled", sizeof(node->idname));
860                                                 node->custom1 = SHD_GLOSSY_MULTI_GGX;
861                                                 error |= NTREE_DOVERSION_TRANSPARENCY_EMISSION;
862                                         }
863                                 }
864                         }
865                 } FOREACH_NODETREE_END
866
867                 if (error & NTREE_DOVERSION_NEED_OUTPUT) {
868                         BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
869                         printf("You need to connect Principled and Eevee Specular shader nodes to new material output nodes.\n");
870                 }
871
872                 if (error & NTREE_DOVERSION_TRANSPARENCY_EMISSION) {
873                         BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
874                         printf("You need to combine transparency and emission shaders to the converted Principled shader nodes.\n");
875                 }
876
877                 if ((DNA_struct_elem_find(fd->filesdna, "ViewLayer", "FreestyleConfig", "freestyle_config") == false) &&
878                     DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers"))
879                 {
880                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
881                                 ViewLayer *view_layer;
882                                 for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
883                                         view_layer->flag |= VIEW_LAYER_FREESTYLE;
884                                         view_layer->layflag = 0x7FFF;   /* solid ztra halo edge strand */
885                                         view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
886                                         view_layer->pass_alpha_threshold = 0.5f;
887                                         BKE_freestyle_config_init(&view_layer->freestyle_config);
888                                 }
889                         }
890                 }
891         }
892
893         if (!MAIN_VERSION_ATLEAST(main, 280, 3)) {
894                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
895                         ViewLayer *view_layer;
896                         for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
897                                 do_version_view_layer_visibility(view_layer);
898                         }
899                 }
900
901                 for (Group *group = main->group.first; group; group = group->id.next) {
902                         if (group->view_layer != NULL) {
903                                 do_version_view_layer_visibility(group->view_layer);
904                         }
905                 }
906         }
907
908         if (!MAIN_VERSION_ATLEAST(main, 280, 6)) {
909                 if (DNA_struct_elem_find(fd->filesdna, "SpaceOops", "int", "filter") == false) {
910                         bScreen *sc;
911                         ScrArea *sa;
912                         SpaceLink *sl;
913
914                         /* Update files using invalid (outdated) outlinevis Outliner values. */
915                         for (sc = main->screen.first; sc; sc = sc->id.next) {
916                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
917                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
918                                                 if (sl->spacetype == SPACE_OUTLINER) {
919                                                         SpaceOops *so = (SpaceOops *)sl;
920
921                                                         if (!ELEM(so->outlinevis,
922                                                                   SO_SCENES,
923                                                                   SO_GROUPS,
924                                                                   SO_LIBRARIES,
925                                                                   SO_SEQUENCE,
926                                                                   SO_DATABLOCKS,
927                                                                   SO_ID_ORPHANS,
928                                                                   SO_COLLECTIONS))
929                                                         {
930                                                                 so->outlinevis = SO_COLLECTIONS;
931                                                         }
932                                                 }
933                                         }
934                                 }
935                         }
936                 }
937
938                 if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "intensity")) {
939                         for (LightProbe *probe = main->lightprobe.first; probe; probe = probe->id.next) {
940                                 probe->intensity = 1.0f;
941                         }
942                 }
943
944                 for (Object *ob = main->object.first; ob; ob = ob->id.next) {
945                         bConstraint *con, *con_next;
946                         con = ob->constraints.first;
947                         while (con) {
948                                 con_next = con->next;
949                                 if (con->type == 17) { /* CONSTRAINT_TYPE_RIGIDBODYJOINT */
950                                         BLI_remlink(&ob->constraints, con);
951                                         BKE_constraint_free_data(con);
952                                         MEM_freeN(con);
953                                 }
954                                 con = con_next;
955                         }
956                 }
957
958                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "int", "orientation_index_custom")) {
959                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
960                                 scene->orientation_index_custom = -1;
961                         }
962                 }
963
964                 for (bScreen *sc = main->screen.first; sc; sc = sc->id.next) {
965                         for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
966                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
967                                         if (sl->spacetype == SPACE_VIEW3D) {
968                                                 View3D *v3d = (View3D *)sl;
969                                                 v3d->shading.light = V3D_LIGHTING_STUDIO;
970
971                                                 /* Assume (demo) files written with 2.8 want to show
972                                                  * Eevee renders in the viewport. */
973                                                 if (MAIN_VERSION_ATLEAST(main, 280, 0)) {
974                                                         v3d->drawtype = OB_MATERIAL;
975                                                 }
976                                         }
977                                 }
978                         }
979                 }
980         }
981
982         if (!MAIN_VERSION_ATLEAST(main, 280, 7)) {
983                 /* Render engine storage moved elsewhere and back during 2.8
984                  * development, we assume any files saved in 2.8 had Eevee set
985                  * as scene render engine. */
986                 if (MAIN_VERSION_ATLEAST(main, 280, 0)) {
987                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
988                                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
989                         }
990                 }
991         }
992
993         if (!MAIN_VERSION_ATLEAST(main, 280, 8)) {
994                 /* Blender Internal removal */
995                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
996                         if (STREQ(scene->r.engine, "BLENDER_RENDER") ||
997                             STREQ(scene->r.engine, "BLENDER_GAME"))
998                         {
999                                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
1000                         }
1001
1002                         scene->r.bake_mode = 0;
1003                 }
1004
1005                 for (Tex *tex = main->tex.first; tex; tex = tex->id.next) {
1006                         /* Removed envmap, pointdensity, voxeldata, ocean textures. */
1007                         if (ELEM(tex->type, 10, 14, 15, 16)) {
1008                                 tex->type = 0;
1009                         }
1010                 }
1011         }
1012
1013         if (!MAIN_VERSION_ATLEAST(main, 280, 11)) {
1014
1015                 /* Remove info editor, but only if at the top of the window. */
1016                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1017                         /* Calculate window width/height from screen vertices */
1018                         int win_width = 0, win_height = 0;
1019                         for (ScrVert *vert = screen->vertbase.first; vert; vert = vert->next) {
1020                                 win_width  = MAX2(win_width, vert->vec.x);
1021                                 win_height = MAX2(win_height, vert->vec.y);
1022                         }
1023
1024                         for (ScrArea *area = screen->areabase.first, *area_next; area; area = area_next) {
1025                                 area_next = area->next;
1026
1027                                 if (area->spacetype == SPACE_INFO) {
1028                                         if ((area->v2->vec.y == win_height) && (area->v1->vec.x == 0) && (area->v4->vec.x == win_width)) {
1029                                                 BKE_screen_area_free(area);
1030
1031                                                 BLI_remlink(&screen->areabase, area);
1032
1033                                                 BKE_screen_remove_double_scredges(screen);
1034                                                 BKE_screen_remove_unused_scredges(screen);
1035                                                 BKE_screen_remove_unused_scrverts(screen);
1036
1037                                                 MEM_freeN(area);
1038                                         }
1039                                 }
1040                                 /* AREA_TEMP_INFO is deprecated from now on, it should only be set for info areas
1041                                  * which are deleted above, so don't need to unset it. Its slot/bit can be reused */
1042                         }
1043                 }
1044         }
1045
1046         if (!MAIN_VERSION_ATLEAST(main, 280, 11)) {
1047                 for (Lamp *lamp = main->lamp.first; lamp; lamp = lamp->id.next) {
1048                         if (lamp->mode & (1 << 13)) { /* LA_SHAD_RAY */
1049                                 lamp->mode |= LA_SHADOW;
1050                                 lamp->mode &= ~(1 << 13);
1051                         }
1052                 }
1053         }
1054
1055         if (!MAIN_VERSION_ATLEAST(main, 280, 12)) {
1056                 /* Remove tool property regions. */
1057                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1058                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1059                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1060                                         if (ELEM(sl->spacetype, SPACE_VIEW3D, SPACE_CLIP)) {
1061                                                 ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1062
1063                                                 for (ARegion *region = regionbase->first, *region_next; region; region = region_next) {
1064                                                         region_next = region->next;
1065
1066                                                         if (region->regiontype == RGN_TYPE_TOOL_PROPS) {
1067                                                                 BKE_area_region_free(NULL, region);
1068                                                                 BLI_freelinkN(regionbase, region);
1069                                                         }
1070                                                 }
1071                                         }
1072                                 }
1073                         }
1074                 }
1075         }
1076
1077         if (!MAIN_VERSION_ATLEAST(main, 280, 13)) {
1078                 /* Initialize specular factor. */
1079                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "spec_fac")) {
1080                         for (Lamp *la = main->lamp.first; la; la = la->id.next) {
1081                                 la->spec_fac = 1.0f;
1082                         }
1083                 }
1084
1085                 /* Initialize new view3D options. */
1086                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1087                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1088                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1089                                         if (sl->spacetype == SPACE_VIEW3D) {
1090                                                 View3D *v3d = (View3D *)sl;
1091                                                 v3d->shading.light = V3D_LIGHTING_STUDIO;
1092                                                 v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR;
1093                                                 copy_v3_fl(v3d->shading.single_color, 0.8f);
1094                                                 v3d->shading.shadow_intensity = 0.5;
1095
1096                                                 v3d->overlay.backwire_opacity = 0.5f;
1097                                                 v3d->overlay.normals_length = 0.1f;
1098                                         }
1099                                 }
1100                         }
1101                 }
1102
1103                 if (!DNA_struct_find(fd->filesdna, "View3DCursor")) {
1104                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1105                                 unit_qt(scene->cursor.rotation);
1106                         }
1107                         for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1108                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1109                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1110                                                 if (sl->spacetype == SPACE_VIEW3D) {
1111                                                         View3D *v3d = (View3D *)sl;
1112                                                         unit_qt(v3d->cursor.rotation);
1113                                                 }
1114                                         }
1115                                 }
1116                         }
1117                 }
1118         }
1119 }