Move EEVEE properties into scene
[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_view_layer_visibility(ViewLayer *view_layer)
693 {
694         LayerCollection *layer_collection;
695         for (layer_collection = view_layer->layer_collections.first;
696              layer_collection;
697              layer_collection = layer_collection->next)
698         {
699                 if (layer_collection->flag & COLLECTION_DISABLED) {
700                         BKE_collection_enable(view_layer, layer_collection);
701                         layer_collection->flag &= ~COLLECTION_DISABLED;
702                 }
703
704                 if ((layer_collection->flag & (1 << 0)) == 0) { /* !COLLECTION_VISIBLE */
705                         layer_collection->flag |= COLLECTION_DISABLED;
706                 }
707                 layer_collection->flag |= COLLECTION_VIEWPORT | COLLECTION_RENDER;
708         }
709 }
710
711 void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
712 {
713
714         if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
715                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers")) {
716                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
717                                 /* Master Collection */
718                                 scene->collection = MEM_callocN(sizeof(SceneCollection), "Master Collection");
719                                 BLI_strncpy(scene->collection->name, "Master Collection", sizeof(scene->collection->name));
720                         }
721                 }
722
723                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
724                         scene->r.gauss = 1.5f;
725                 }
726         }
727
728         if (!MAIN_VERSION_ATLEAST(main, 280, 1)) {
729                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "bleedexp")) {
730                         for (Lamp *la = main->lamp.first; la; la = la->id.next) {
731                                 la->bleedexp = 2.5f;
732                         }
733                 }
734
735                 if (!DNA_struct_elem_find(fd->filesdna, "GPUDOFSettings", "float", "ratio")) {
736                         for (Camera *ca = main->camera.first; ca; ca = ca->id.next) {
737                                 ca->gpu_dof.ratio = 1.0f;
738                         }
739                 }
740
741                 /* MTexPoly now removed. */
742                 if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
743                         const int cd_mtexpoly = 15;  /* CD_MTEXPOLY, deprecated */
744                         for (Mesh *me = main->mesh.first; me; me = me->id.next) {
745                                 /* If we have UV's, so this file will have MTexPoly layers too! */
746                                 if (me->mloopuv != NULL) {
747                                         CustomData_update_typemap(&me->pdata);
748                                         CustomData_free_layers(&me->pdata, cd_mtexpoly, me->totpoly);
749                                         BKE_mesh_update_customdata_pointers(me, false);
750                                 }
751                         }
752                 }
753         }
754
755         if (!MAIN_VERSION_ATLEAST(main, 280, 2)) {
756                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "cascade_max_dist")) {
757                         for (Lamp *la = main->lamp.first; la; la = la->id.next) {
758                                 la->cascade_max_dist = 1000.0f;
759                                 la->cascade_count = 4;
760                                 la->cascade_exponent = 0.8f;
761                                 la->cascade_fade = 0.1f;
762                         }
763                 }
764
765                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "contact_dist")) {
766                         for (Lamp *la = main->lamp.first; la; la = la->id.next) {
767                                 la->contact_dist = 1.0f;
768                                 la->contact_bias = 0.03f;
769                                 la->contact_spread = 0.2f;
770                                 la->contact_thickness = 0.5f;
771                         }
772                 }
773
774                 if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "vis_bias")) {
775                         for (LightProbe *probe = main->lightprobe.first; probe; probe = probe->id.next) {
776                                 probe->vis_bias = 1.0f;
777                                 probe->vis_blur = 0.2f;
778                         }
779                 }
780
781                 typedef enum eNTreeDoVersionErrors {
782                         NTREE_DOVERSION_NO_ERROR = 0,
783                         NTREE_DOVERSION_NEED_OUTPUT = (1 << 0),
784                         NTREE_DOVERSION_TRANSPARENCY_EMISSION = (1 << 1),
785                 } eNTreeDoVersionErrors;
786
787                 /* Eevee shader nodes renamed because of the output node system.
788                  * Note that a new output node is not being added here, because it would be overkill
789                  * to handle this case in lib_verify_nodetree.
790                  *
791                  * Also, metallic node is now unified into the principled node. */
792                 eNTreeDoVersionErrors error = NTREE_DOVERSION_NO_ERROR;
793
794                 FOREACH_NODETREE(main, ntree, id) {
795                         if (ntree->type == NTREE_SHADER) {
796                                 for (bNode *node = ntree->nodes.first; node; node = node->next) {
797                                         if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
798                                             STREQ(node->idname, "ShaderNodeOutputMetallic"))
799                                         {
800                                                 BLI_strncpy(node->idname, "ShaderNodeEeveeMetallic", sizeof(node->idname));
801                                                 error |= NTREE_DOVERSION_NEED_OUTPUT;
802                                         }
803
804                                         else if (node->type == SH_NODE_EEVEE_SPECULAR && STREQ(node->idname, "ShaderNodeOutputSpecular")) {
805                                                 BLI_strncpy(node->idname, "ShaderNodeEeveeSpecular", sizeof(node->idname));
806                                                 error |= NTREE_DOVERSION_NEED_OUTPUT;
807                                         }
808
809                                         else if (node->type == 196 /* SH_NODE_OUTPUT_EEVEE_MATERIAL */ &&
810                                                  STREQ(node->idname, "ShaderNodeOutputEeveeMaterial"))
811                                         {
812                                                 node->type = SH_NODE_OUTPUT_MATERIAL;
813                                                 BLI_strncpy(node->idname, "ShaderNodeOutputMaterial", sizeof(node->idname));
814                                         }
815
816                                         else if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
817                                                  STREQ(node->idname, "ShaderNodeEeveeMetallic"))
818                                         {
819                                                 node->type = SH_NODE_BSDF_PRINCIPLED;
820                                                 BLI_strncpy(node->idname, "ShaderNodeBsdfPrincipled", sizeof(node->idname));
821                                                 node->custom1 = SHD_GLOSSY_MULTI_GGX;
822                                                 error |= NTREE_DOVERSION_TRANSPARENCY_EMISSION;
823                                         }
824                                 }
825                         }
826                 } FOREACH_NODETREE_END
827
828                 if (error & NTREE_DOVERSION_NEED_OUTPUT) {
829                         BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
830                         printf("You need to connect Principled and Eevee Specular shader nodes to new material output nodes.\n");
831                 }
832
833                 if (error & NTREE_DOVERSION_TRANSPARENCY_EMISSION) {
834                         BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
835                         printf("You need to combine transparency and emission shaders to the converted Principled shader nodes.\n");
836                 }
837
838                 if ((DNA_struct_elem_find(fd->filesdna, "ViewLayer", "FreestyleConfig", "freestyle_config") == false) &&
839                     DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers"))
840                 {
841                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
842                                 ViewLayer *view_layer;
843                                 for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
844                                         view_layer->flag |= VIEW_LAYER_FREESTYLE;
845                                         view_layer->layflag = 0x7FFF;   /* solid ztra halo edge strand */
846                                         view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
847                                         view_layer->pass_alpha_threshold = 0.5f;
848                                         BKE_freestyle_config_init(&view_layer->freestyle_config);
849                                 }
850                         }
851                 }
852         }
853
854         if (!MAIN_VERSION_ATLEAST(main, 280, 3)) {
855                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
856                         ViewLayer *view_layer;
857                         for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
858                                 do_version_view_layer_visibility(view_layer);
859                         }
860                 }
861
862                 for (Group *group = main->group.first; group; group = group->id.next) {
863                         if (group->view_layer != NULL) {
864                                 do_version_view_layer_visibility(group->view_layer);
865                         }
866                 }
867         }
868
869         if (!MAIN_VERSION_ATLEAST(main, 280, 6)) {
870                 if (DNA_struct_elem_find(fd->filesdna, "SpaceOops", "int", "filter") == false) {
871                         bScreen *sc;
872                         ScrArea *sa;
873                         SpaceLink *sl;
874
875                         /* Update files using invalid (outdated) outlinevis Outliner values. */
876                         for (sc = main->screen.first; sc; sc = sc->id.next) {
877                                 for (sa = sc->areabase.first; sa; sa = sa->next) {
878                                         for (sl = sa->spacedata.first; sl; sl = sl->next) {
879                                                 if (sl->spacetype == SPACE_OUTLINER) {
880                                                         SpaceOops *so = (SpaceOops *)sl;
881
882                                                         if (!ELEM(so->outlinevis,
883                                                                   SO_SCENES,
884                                                                   SO_GROUPS,
885                                                                   SO_LIBRARIES,
886                                                                   SO_SEQUENCE,
887                                                                   SO_DATABLOCKS,
888                                                                   SO_ID_ORPHANS,
889                                                                   SO_COLLECTIONS))
890                                                         {
891                                                                 so->outlinevis = SO_COLLECTIONS;
892                                                         }
893                                                 }
894                                         }
895                                 }
896                         }
897                 }
898
899                 if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "intensity")) {
900                         for (LightProbe *probe = main->lightprobe.first; probe; probe = probe->id.next) {
901                                 probe->intensity = 1.0f;
902                         }
903                 }
904
905                 for (Object *ob = main->object.first; ob; ob = ob->id.next) {
906                         bConstraint *con, *con_next;
907                         con = ob->constraints.first;
908                         while (con) {
909                                 con_next = con->next;
910                                 if (con->type == 17) { /* CONSTRAINT_TYPE_RIGIDBODYJOINT */
911                                         BLI_remlink(&ob->constraints, con);
912                                         BKE_constraint_free_data(con);
913                                         MEM_freeN(con);
914                                 }
915                                 con = con_next;
916                         }
917                 }
918
919                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "int", "orientation_index_custom")) {
920                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
921                                 scene->orientation_index_custom = -1;
922                         }
923                 }
924
925                 for (bScreen *sc = main->screen.first; sc; sc = sc->id.next) {
926                         for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
927                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
928                                         if (sl->spacetype == SPACE_VIEW3D) {
929                                                 View3D *v3d = (View3D *)sl;
930                                                 v3d->shading.light = V3D_LIGHTING_STUDIO;
931                                                 v3d->shading.flag |= V3D_SHADING_OBJECT_OUTLINE;
932
933                                                 /* Assume (demo) files written with 2.8 want to show
934                                                  * Eevee renders in the viewport. */
935                                                 if (MAIN_VERSION_ATLEAST(main, 280, 0)) {
936                                                         v3d->drawtype = OB_MATERIAL;
937                                                 }
938                                         }
939                                 }
940                         }
941                 }
942         }
943
944         if (!MAIN_VERSION_ATLEAST(main, 280, 7)) {
945                 /* Render engine storage moved elsewhere and back during 2.8
946                  * development, we assume any files saved in 2.8 had Eevee set
947                  * as scene render engine. */
948                 if (MAIN_VERSION_ATLEAST(main, 280, 0)) {
949                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
950                                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
951                         }
952                 }
953         }
954
955         if (!MAIN_VERSION_ATLEAST(main, 280, 8)) {
956                 /* Blender Internal removal */
957                 for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
958                         if (STREQ(scene->r.engine, "BLENDER_RENDER") ||
959                             STREQ(scene->r.engine, "BLENDER_GAME"))
960                         {
961                                 BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
962                         }
963
964                         scene->r.bake_mode = 0;
965                 }
966
967                 for (Tex *tex = main->tex.first; tex; tex = tex->id.next) {
968                         /* Removed envmap, pointdensity, voxeldata, ocean textures. */
969                         if (ELEM(tex->type, 10, 14, 15, 16)) {
970                                 tex->type = 0;
971                         }
972                 }
973         }
974
975         if (!MAIN_VERSION_ATLEAST(main, 280, 11)) {
976
977                 /* Remove info editor, but only if at the top of the window. */
978                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
979                         /* Calculate window width/height from screen vertices */
980                         int win_width = 0, win_height = 0;
981                         for (ScrVert *vert = screen->vertbase.first; vert; vert = vert->next) {
982                                 win_width  = MAX2(win_width, vert->vec.x);
983                                 win_height = MAX2(win_height, vert->vec.y);
984                         }
985
986                         for (ScrArea *area = screen->areabase.first, *area_next; area; area = area_next) {
987                                 area_next = area->next;
988
989                                 if (area->spacetype == SPACE_INFO) {
990                                         if ((area->v2->vec.y == win_height) && (area->v1->vec.x == 0) && (area->v4->vec.x == win_width)) {
991                                                 BKE_screen_area_free(area);
992
993                                                 BLI_remlink(&screen->areabase, area);
994
995                                                 BKE_screen_remove_double_scredges(screen);
996                                                 BKE_screen_remove_unused_scredges(screen);
997                                                 BKE_screen_remove_unused_scrverts(screen);
998
999                                                 MEM_freeN(area);
1000                                         }
1001                                 }
1002                                 /* AREA_TEMP_INFO is deprecated from now on, it should only be set for info areas
1003                                  * which are deleted above, so don't need to unset it. Its slot/bit can be reused */
1004                         }
1005                 }
1006         }
1007
1008         if (!MAIN_VERSION_ATLEAST(main, 280, 11)) {
1009                 for (Lamp *lamp = main->lamp.first; lamp; lamp = lamp->id.next) {
1010                         if (lamp->mode & (1 << 13)) { /* LA_SHAD_RAY */
1011                                 lamp->mode |= LA_SHADOW;
1012                                 lamp->mode &= ~(1 << 13);
1013                         }
1014                 }
1015         }
1016
1017         if (!MAIN_VERSION_ATLEAST(main, 280, 12)) {
1018                 /* Remove tool property regions. */
1019                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1020                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1021                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1022                                         if (ELEM(sl->spacetype, SPACE_VIEW3D, SPACE_CLIP)) {
1023                                                 ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
1024
1025                                                 for (ARegion *region = regionbase->first, *region_next; region; region = region_next) {
1026                                                         region_next = region->next;
1027
1028                                                         if (region->regiontype == RGN_TYPE_TOOL_PROPS) {
1029                                                                 BKE_area_region_free(NULL, region);
1030                                                                 BLI_freelinkN(regionbase, region);
1031                                                         }
1032                                                 }
1033                                         }
1034                                 }
1035                         }
1036                 }
1037         }
1038
1039         if (!MAIN_VERSION_ATLEAST(main, 280, 13)) {
1040                 /* Initialize specular factor. */
1041                 if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "spec_fac")) {
1042                         for (Lamp *la = main->lamp.first; la; la = la->id.next) {
1043                                 la->spec_fac = 1.0f;
1044                         }
1045                 }
1046
1047                 /* Initialize new view3D options. */
1048                 for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1049                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1050                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1051                                         if (sl->spacetype == SPACE_VIEW3D) {
1052                                                 View3D *v3d = (View3D *)sl;
1053                                                 v3d->shading.light = V3D_LIGHTING_STUDIO;
1054                                                 v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR;
1055                                                 copy_v3_fl(v3d->shading.single_color, 0.8f);
1056                                                 v3d->shading.shadow_intensity = 0.5;
1057
1058                                                 v3d->overlay.backwire_opacity = 0.5f;
1059                                                 v3d->overlay.normals_length = 0.1f;
1060                                         }
1061                                 }
1062                         }
1063                 }
1064
1065                 if (!DNA_struct_find(fd->filesdna, "View3DCursor")) {
1066                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1067                                 unit_qt(scene->cursor.rotation);
1068                         }
1069                         for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
1070                                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
1071                                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
1072                                                 if (sl->spacetype == SPACE_VIEW3D) {
1073                                                         View3D *v3d = (View3D *)sl;
1074                                                         unit_qt(v3d->cursor.rotation);
1075                                                 }
1076                                         }
1077                                 }
1078                         }
1079                 }
1080         }
1081
1082         {
1083                 if (!DNA_struct_elem_find(fd->filesdna, "Scene", "SceneDisplay", "display")) {
1084                         /* Initialize new scene.SceneDisplay */
1085                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1086                                 copy_v3_v3(scene->display.light_direction, (float[3]){-M_SQRT1_3, -M_SQRT1_3, M_SQRT1_3});
1087                         }
1088                 }
1089                 if (!DNA_struct_elem_find(fd->filesdna, "SceneDisplay", "float", "shadow_shift")) {
1090                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1091                                 scene->display.shadow_shift = 0.1;
1092                         }
1093                 }
1094
1095                 if (!DNA_struct_elem_find(fd->filesdna, "Object", "ObjectDisplay", "display")) {
1096                         /* Initialize new object.ObjectDisplay */
1097                         for (Object *ob = main->object.first; ob; ob = ob->id.next) {
1098                                 ob->display.flag = OB_SHOW_SHADOW;
1099                         }
1100                 }
1101
1102                 if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "transform_pivot_point")) {
1103                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1104                                 scene->toolsettings->transform_pivot_point = V3D_AROUND_CENTER_MEAN;
1105                         }
1106                 }
1107
1108                 if (!DNA_struct_find(fd->filesdna, "SceneEEVEE")) {
1109                         for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
1110                                         /* First set the default for all the properties. */
1111
1112                                         scene->eevee.gi_diffuse_bounces = 3;
1113                                         scene->eevee.gi_cubemap_resolution = 512;
1114                                         scene->eevee.gi_visibility_resolution = 32;
1115
1116                                         scene->eevee.taa_samples = 16;
1117                                         scene->eevee.taa_render_samples = 64;
1118
1119                                         scene->eevee.sss_samples = 7;
1120                                         scene->eevee.sss_jitter_threshold = 0.3f;
1121
1122                                         scene->eevee.ssr_quality = 0.25f;
1123                                         scene->eevee.ssr_max_roughness = 0.5f;
1124                                         scene->eevee.ssr_thickness = 0.2f;
1125                                         scene->eevee.ssr_border_fade = 0.075f;
1126                                         scene->eevee.ssr_firefly_fac = 10.0f;
1127
1128                                         scene->eevee.volumetric_start = 0.1f;
1129                                         scene->eevee.volumetric_end = 100.0f;
1130                                         scene->eevee.volumetric_tile_size = 8;
1131                                         scene->eevee.volumetric_samples = 64;
1132                                         scene->eevee.volumetric_sample_distribution = 0.8f;
1133                                         scene->eevee.volumetric_light_clamp = 0.0f;
1134                                         scene->eevee.volumetric_shadow_samples = 16;
1135
1136                                         scene->eevee.gtao_distance = 0.2f;
1137                                         scene->eevee.gtao_factor = 1.0f;
1138                                         scene->eevee.gtao_quality = 0.25f;
1139
1140                                         scene->eevee.bokeh_max_size = 100.0f;
1141                                         scene->eevee.bokeh_threshold = 1.0f;
1142
1143                                         copy_v3_fl(scene->eevee.bloom_color, 1.0f);
1144                                         scene->eevee.bloom_threshold = 0.8f;
1145                                         scene->eevee.bloom_knee = 0.5f;
1146                                         scene->eevee.bloom_intensity = 0.8f;
1147                                         scene->eevee.bloom_radius = 6.5f;
1148                                         scene->eevee.bloom_clamp = 1.0f;
1149
1150                                         scene->eevee.motion_blur_samples = 8;
1151                                         scene->eevee.motion_blur_shutter = 1.0f;
1152
1153                                         scene->eevee.shadow_method = SHADOW_ESM;
1154                                         scene->eevee.shadow_cube_size = 512;
1155                                         scene->eevee.shadow_cascade_size = 1024;
1156
1157                                         scene->eevee.flag =
1158                                                 SCE_EEVEE_VOLUMETRIC_LIGHTS |
1159                                                 SCE_EEVEE_VOLUMETRIC_COLORED |
1160                                                 SCE_EEVEE_GTAO_BENT_NORMALS |
1161                                                 SCE_EEVEE_GTAO_BOUNCE |
1162                                                 SCE_EEVEE_TAA_REPROJECTION |
1163                                                 SCE_EEVEE_SSR_HALF_RESOLUTION;
1164
1165
1166                                 /* If the file is pre-2.80 move on. */
1167                                 if (scene->layer_properties == NULL) {
1168                                         continue;
1169                                 }
1170
1171                                 /* Now we handle eventual properties that may be set in the file. */
1172 #define EEVEE_GET_BOOL(_props, _name, _flag) \
1173                                 { \
1174                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1175                                         if (_idprop != NULL) { \
1176                                                 const int _value = IDP_Int(_idprop); \
1177                                                 if (_value) { \
1178                                                         scene->eevee.flag |= _flag; \
1179                                                 } \
1180                                                 else { \
1181                                                         scene->eevee.flag &= ~_flag; \
1182                                                 } \
1183                                         } \
1184                                 }
1185
1186 #define EEVEE_GET_INT(_props, _name) \
1187                                 { \
1188                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1189                                         if (_idprop != NULL) { \
1190                                                 scene->eevee._name = IDP_Int(_idprop); \
1191                                         } \
1192                                 }
1193
1194 #define EEVEE_GET_FLOAT(_props, _name) \
1195                                 { \
1196                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1197                                         if (_idprop != NULL) { \
1198                                                 scene->eevee._name = IDP_Float(_idprop); \
1199                                         } \
1200                                 }
1201
1202 #define EEVEE_GET_FLOAT_ARRAY(_props, _name, _length) \
1203                                 { \
1204                                         IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
1205                                         if (_idprop != NULL) { \
1206                                                 const float *_values = IDP_Array(_idprop); \
1207                                                 for (int _i = 0; _i < _length; _i++) { \
1208                                                         scene->eevee._name [_i] = _values[_i]; \
1209                                                 } \
1210                                         } \
1211                                 }
1212
1213                                 IDProperty *props = IDP_GetPropertyFromGroup(scene->layer_properties, RE_engine_id_BLENDER_EEVEE);
1214                                 EEVEE_GET_BOOL(props, volumetric_enable, SCE_EEVEE_VOLUMETRIC_ENABLED);
1215                                 EEVEE_GET_BOOL(props, volumetric_lights, SCE_EEVEE_VOLUMETRIC_LIGHTS);
1216                                 EEVEE_GET_BOOL(props, volumetric_shadows, SCE_EEVEE_VOLUMETRIC_SHADOWS);
1217                                 EEVEE_GET_BOOL(props, volumetric_colored_transmittance, SCE_EEVEE_VOLUMETRIC_COLORED);
1218                                 EEVEE_GET_BOOL(props, gtao_enable, SCE_EEVEE_GTAO_ENABLED);
1219                                 EEVEE_GET_BOOL(props, gtao_use_bent_normals, SCE_EEVEE_GTAO_BENT_NORMALS);
1220                                 EEVEE_GET_BOOL(props, gtao_bounce, SCE_EEVEE_GTAO_BOUNCE);
1221                                 EEVEE_GET_BOOL(props, dof_enable, SCE_EEVEE_DOF_ENABLED);
1222                                 EEVEE_GET_BOOL(props, bloom_enable, SCE_EEVEE_BLOOM_ENABLED);
1223                                 EEVEE_GET_BOOL(props, motion_blur_enable, SCE_EEVEE_MOTION_BLUR_ENABLED);
1224                                 EEVEE_GET_BOOL(props, shadow_high_bitdepth, SCE_EEVEE_SHADOW_HIGH_BITDEPTH);
1225                                 EEVEE_GET_BOOL(props, taa_reprojection, SCE_EEVEE_TAA_REPROJECTION);
1226                                 EEVEE_GET_BOOL(props, sss_enable, SCE_EEVEE_SSS_ENABLED);
1227                                 EEVEE_GET_BOOL(props, sss_separate_albedo, SCE_EEVEE_SSS_SEPARATE_ALBEDO);
1228                                 EEVEE_GET_BOOL(props, ssr_enable, SCE_EEVEE_SSR_ENABLED);
1229                                 EEVEE_GET_BOOL(props, ssr_refraction, SCE_EEVEE_SSR_REFRACTION);
1230                                 EEVEE_GET_BOOL(props, ssr_halfres, SCE_EEVEE_SSR_HALF_RESOLUTION);
1231
1232                                 EEVEE_GET_INT(props, gi_diffuse_bounces);
1233                                 EEVEE_GET_INT(props, gi_diffuse_bounces);
1234                                 EEVEE_GET_INT(props, gi_cubemap_resolution);
1235                                 EEVEE_GET_INT(props, gi_visibility_resolution);
1236
1237                                 EEVEE_GET_INT(props, taa_samples);
1238                                 EEVEE_GET_INT(props, taa_render_samples);
1239
1240                                 EEVEE_GET_INT(props, sss_samples);
1241                                 EEVEE_GET_FLOAT(props, sss_jitter_threshold);
1242
1243                                 EEVEE_GET_FLOAT(props, ssr_quality);
1244                                 EEVEE_GET_FLOAT(props, ssr_max_roughness);
1245                                 EEVEE_GET_FLOAT(props, ssr_thickness);
1246                                 EEVEE_GET_FLOAT(props, ssr_border_fade);
1247                                 EEVEE_GET_FLOAT(props, ssr_firefly_fac);
1248
1249                                 EEVEE_GET_FLOAT(props, volumetric_start);
1250                                 EEVEE_GET_FLOAT(props, volumetric_end);
1251                                 EEVEE_GET_INT(props, volumetric_tile_size);
1252                                 EEVEE_GET_INT(props, volumetric_samples);
1253                                 EEVEE_GET_FLOAT(props, volumetric_sample_distribution);
1254                                 EEVEE_GET_FLOAT(props, volumetric_light_clamp);
1255                                 EEVEE_GET_INT(props, volumetric_shadow_samples);
1256
1257                                 EEVEE_GET_FLOAT(props, gtao_distance);
1258                                 EEVEE_GET_FLOAT(props, gtao_factor);
1259                                 EEVEE_GET_FLOAT(props, gtao_quality);
1260
1261                                 EEVEE_GET_FLOAT(props, bokeh_max_size);
1262                                 EEVEE_GET_FLOAT(props, bokeh_threshold);
1263
1264                                 EEVEE_GET_FLOAT_ARRAY(props, bloom_color, 3);
1265                                 EEVEE_GET_FLOAT(props, bloom_threshold);
1266                                 EEVEE_GET_FLOAT(props, bloom_knee);
1267                                 EEVEE_GET_FLOAT(props, bloom_intensity);
1268                                 EEVEE_GET_FLOAT(props, bloom_radius);
1269                                 EEVEE_GET_FLOAT(props, bloom_clamp);
1270
1271                                 EEVEE_GET_INT(props, motion_blur_samples);
1272                                 EEVEE_GET_FLOAT(props, motion_blur_shutter);
1273
1274                                 EEVEE_GET_INT(props, shadow_method);
1275                                 EEVEE_GET_INT(props, shadow_cube_size);
1276                                 EEVEE_GET_INT(props, shadow_cascade_size);
1277
1278                                 /* Cleanup. */
1279                                 IDP_FreeProperty(scene->layer_properties);
1280                                 MEM_freeN(scene->layer_properties);
1281                                 scene->layer_properties = NULL;
1282
1283 #undef EEVEE_GET_FLOAT_ARRAY
1284 #undef EEVEE_GET_FLOAT
1285 #undef EEVEE_GET_INT
1286 #undef EEVEE_GET_BOOL
1287                         }
1288                 }
1289         }
1290 }