Merge branch 'master' into blender2.8
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 5 Jun 2018 15:02:50 +0000 (17:02 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 5 Jun 2018 15:02:50 +0000 (17:02 +0200)
Conflicts:
source/blender/blenkernel/intern/blendfile.c
source/blender/blenloader/intern/readfile.h
source/blender/blenloader/intern/versioning_250.c
source/blender/blenloader/intern/versioning_260.c
source/blender/blenloader/intern/versioning_270.c
source/blender/blenloader/intern/versioning_legacy.c
source/blender/editors/render/render_shading.c
source/blender/makesrna/intern/rna_movieclip.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/voxeldata.c

60 files changed:
1  2 
source/blender/blenkernel/BKE_library.h
source/blender/blenkernel/BKE_movieclip.h
source/blender/blenkernel/intern/blender_undo.c
source/blender/blenkernel/intern/blendfile.c
source/blender/blenkernel/intern/bpath.c
source/blender/blenkernel/intern/dynamicpaint.c
source/blender/blenkernel/intern/font.c
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/pointcache.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/sequencer.c
source/blender/blenkernel/intern/sound.c
source/blender/blenkernel/intern/text.c
source/blender/blenkernel/intern/writeavi.c
source/blender/blenkernel/intern/writeffmpeg.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/readfile.h
source/blender/blenloader/intern/versioning_250.c
source/blender/blenloader/intern/versioning_260.c
source/blender/blenloader/intern/versioning_270.c
source/blender/blenloader/intern/versioning_280.c
source/blender/blenloader/intern/versioning_legacy.c
source/blender/blenloader/intern/writefile.c
source/blender/collada/ImageExporter.cpp
source/blender/editors/interface/interface_ops.c
source/blender/editors/io/io_alembic.c
source/blender/editors/io/io_collada.c
source/blender/editors/object/object_bake_api.c
source/blender/editors/object/object_modifier.c
source/blender/editors/render/render_opengl.c
source/blender/editors/render/render_preview.c
source/blender/editors/screen/screendump.c
source/blender/editors/sound/sound_ops.c
source/blender/editors/space_clip/clip_ops.c
source/blender/editors/space_file/file_draw.c
source/blender/editors/space_file/filesel.c
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_outliner/outliner_draw.c
source/blender/editors/space_sequencer/sequencer_add.c
source/blender/editors/space_sequencer/sequencer_edit.c
source/blender/editors/space_text/text_ops.c
source/blender/editors/util/ed_util.c
source/blender/makesdna/DNA_ID.h
source/blender/makesrna/intern/rna_color.c
source/blender/makesrna/intern/rna_image_api.c
source/blender/makesrna/intern/rna_main_api.c
source/blender/makesrna/intern/rna_movieclip.c
source/blender/makesrna/intern/rna_nodetree.c
source/blender/makesrna/intern/rna_scene_api.c
source/blender/python/intern/bpy_interface.c
source/blender/python/intern/bpy_library_load.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/render_result.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_files_link.c
source/blender/windowmanager/intern/wm_init_exit.c
source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/intern/wm_window.c

@@@ -172,16 -168,13 +173,16 @@@ static void setup_app_data
                bool track_undo_scene;
  
                /* comes from readfile.c */
-               SWAP(ListBase, G.main->wm, bfd->main->wm);
-               SWAP(ListBase, G.main->workspaces, bfd->main->workspaces);
-               SWAP(ListBase, G.main->screen, bfd->main->screen);
+               SWAP(ListBase, bmain->wm, bfd->main->wm);
++              SWAP(ListBase, bmain->workspaces, bfd->main->workspaces);
+               SWAP(ListBase, bmain->screen, bfd->main->screen);
  
 -              /* we re-use current screen */
 +              /* we re-use current window and screen */
 +              win = CTX_wm_window(C);
                curscreen = CTX_wm_screen(C);
 -              /* but use new Scene pointer */
 +              /* but use Scene pointer from new file */
                curscene = bfd->curscene;
 +              cur_view_layer = bfd->cur_view_layer;
  
                track_undo_scene = (mode == LOAD_UNDO && curscreen && curscene && bfd->main->wm.first);
  
        /* clear old property update cache, in case some old references are left dangling */
        RNA_property_update_cache_free();
  
-       G.main = bfd->main;
+       bmain = G.main = bfd->main;
  
-       CTX_data_main_set(C, G.main);
+       CTX_data_main_set(C, bmain);
  
        if (bfd->user) {
 +
                /* only here free userdef themes... */
                BKE_blender_userdef_data_set_and_free(bfd->user);
                bfd->user = NULL;
  
        /* this can happen when active scene was lib-linked, and doesn't exist anymore */
        if (CTX_data_scene(C) == NULL) {
 +              wmWindow *win = CTX_wm_window(C);
 +
                /* in case we don't even have a local scene, add one */
-               if (!G.main->scene.first)
-                       BKE_scene_add(G.main, "Empty");
+               if (!bmain->scene.first)
+                       BKE_scene_add(bmain, "Empty");
  
-               CTX_data_scene_set(C, G.main->scene.first);
+               CTX_data_scene_set(C, bmain->scene.first);
 -              CTX_wm_screen(C)->scene = CTX_data_scene(C);
 +              win->scene = CTX_data_scene(C);
                curscene = CTX_data_scene(C);
        }
  
        /* baseflags, groups, make depsgraph, etc */
        /* first handle case if other windows have different scenes visible */
        if (mode == LOAD_UI) {
-               wmWindowManager *wm = G.main->wm.first;
+               wmWindowManager *wm = bmain->wm.first;
  
                if (wm) {
 -                      wmWindow *win;
 -
 -                      for (win = wm->windows.first; win; win = win->next) {
 -                              if (win->screen && win->screen->scene) /* zealous check... */
 -                                      if (win->screen->scene != curscene)
 -                                              BKE_scene_set_background(bmain, win->screen->scene);
 +                      for (wmWindow *win = wm->windows.first; win; win = win->next) {
 +                              if (win->scene && win->scene != curscene) {
-                                       BKE_scene_set_background(G.main, win->scene);
++                                      BKE_scene_set_background(bmain, win->scene);
 +                              }
                        }
                }
        }
-               IMB_colormanagement_check_file_config(G.main);
 +
 +      /* Setting scene might require having a dependency graph, with copy on write
 +       * we need to make sure we ensure scene has correct color management before
 +       * constructing dependency graph.
 +       */
 +      if (mode != LOAD_UNDO) {
-       BKE_scene_set_background(G.main, curscene);
++              IMB_colormanagement_check_file_config(bmain);
 +      }
 +
+       BKE_scene_set_background(bmain, curscene);
  
        if (mode != LOAD_UNDO) {
 +              /* TODO(sergey): Can this be also move above? */
                RE_FreeAllPersistentData();
 -              IMB_colormanagement_check_file_config(bmain);
        }
  
        MEM_freeN(bfd);
@@@ -10424,14 -10412,17 +10424,14 @@@ static void library_link_end(Main *main
        BKE_main_id_tag_all(mainvar, LIB_TAG_NEW, false);
  
        lib_verify_nodetree(mainvar, false);
-       fix_relpaths_library(G.main->name, mainvar); /* make all relative paths, relative to the open blend file */
+       fix_relpaths_library(BKE_main_blendfile_path(mainvar), mainvar); /* make all relative paths, relative to the open blend file */
  
 -      /* Give a base to loose objects. If group append, do it for objects too.
 -       * Only directly linked objects & groups are instantiated by `BLO_library_link_named_part_ex()` & co,
 +      /* Give a base to loose objects and collections.
 +       * Only directly linked objects & collections are instantiated by `BLO_library_link_named_part_ex()` & co,
         * here we handle indirect ones and other possible edge-cases. */
        if (scene) {
 -              give_base_to_objects(mainvar, scene, v3d, curlib, flag);
 -
 -              if (flag & FILE_GROUP_INSTANCE) {
 -                      give_base_to_groups(mainvar, scene, v3d, curlib, flag);
 -              }
 +              add_collections_to_scene(mainvar, bmain, scene, view_layer, curlib, flag);
 +              add_loose_objects_to_scene(mainvar, bmain, scene, view_layer, curlib, flag);
        }
        else {
                /* printf("library_append_end, scene is NULL (objects wont get bases)\n"); */
@@@ -169,14 -167,12 +169,14 @@@ void blo_do_version_old_trackto_to_cons
  void blo_do_versions_view3d_split_250(struct View3D *v3d, struct ListBase *regions);
  void blo_do_versions_key_uidgen(struct Key *key);
  
- void blo_do_versions_pre250(struct FileData *fd, struct Library *lib, struct Main *main);
- void blo_do_versions_250(struct FileData *fd, struct Library *lib, struct Main *main);
- void blo_do_versions_260(struct FileData *fd, struct Library *lib, struct Main *main);
- void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *main);
- void blo_do_versions_280(struct FileData *fd, struct Library *lib, struct Main *main);
- void do_versions_after_linking_270(struct Main *main);
- void do_versions_after_linking_280(struct Main *main);
+ void blo_do_versions_pre250(struct FileData *fd, struct Library *lib, struct Main *bmain);
+ void blo_do_versions_250(struct FileData *fd, struct Library *lib, struct Main *bmain);
+ void blo_do_versions_260(struct FileData *fd, struct Library *lib, struct Main *bmain);
+ void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *bmain);
++void blo_do_versions_280(struct FileData *fd, struct Library *lib, struct Main *bmain);
+ void do_versions_after_linking_270(struct Main *bmain);
++void do_versions_after_linking_280(struct Main *bmain);
  
  #endif
  
@@@ -662,15 -750,44 +662,15 @@@ void blo_do_versions_250(FileData *fd, 
  
                bSound *sound;
                Sequence *seq;
 -              bActuator *act;
 -              int a;
  
-               for (sound = main->sound.first; sound; sound = sound->id.next) {
+               for (sound = bmain->sound.first; sound; sound = sound->id.next) {
                        if (sound->newpackedfile) {
                                sound->packedfile = sound->newpackedfile;
                                sound->newpackedfile = NULL;
                        }
                }
  
-               for (scene = main->scene.first; scene; scene = scene->id.next) {
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      for (act = ob->actuators.first; act; act = act->next) {
 -                              if (act->type == ACT_SOUND) {
 -                                      bSoundActuator *sAct = (bSoundActuator*) act->data;
 -                                      if (sAct->sound) {
 -                                              sound = blo_do_versions_newlibadr(fd, lib, sAct->sound);
 -                                              sAct->flag = (sound->flags & SOUND_FLAGS_3D) ? ACT_SND_3D_SOUND : 0;
 -                                              sAct->pitch = sound->pitch;
 -                                              sAct->volume = sound->volume;
 -                                              sAct->sound3D.reference_distance = sound->distance;
 -                                              sAct->sound3D.max_gain = sound->max_gain;
 -                                              sAct->sound3D.min_gain = sound->min_gain;
 -                                              sAct->sound3D.rolloff_factor = sound->attenuation;
 -                                      }
 -                                      else {
 -                                              sAct->sound3D.reference_distance = 1.0f;
 -                                              sAct->volume = 1.0f;
 -                                              sAct->sound3D.max_gain = 1.0f;
 -                                              sAct->sound3D.rolloff_factor = 1.0f;
 -                                      }
 -                                      sAct->sound3D.cone_inner_angle = 360.0f;
 -                                      sAct->sound3D.cone_outer_angle = 360.0f;
 -                                      sAct->sound3D.max_distance = FLT_MAX;
 -                              }
 -                      }
 -              }
 -
+               for (scene = bmain->scene.first; scene; scene = scene->id.next) {
                        if (scene->ed && scene->ed->seqbasep) {
                                SEQ_BEGIN (scene->ed, seq)
                                {
                /* shader, composite and texture node trees have id.name empty, put something in
                 * to have them show in RNA viewer and accessible otherwise.
                 */
-               for (ma = main->mat.first; ma; ma = ma->id.next) {
+               for (ma = bmain->mat.first; ma; ma = ma->id.next) {
                        if (ma->nodetree && ma->nodetree->id.name[0] == '\0')
                                strcpy(ma->nodetree->id.name, "NTShader Nodetree");
 -
 -                      /* which_output 0 is now "not specified" */
 -                      for (a = 0; a < MAX_MTEX; a++) {
 -                              if (ma->mtex[a]) {
 -                                      tx = blo_do_versions_newlibadr(fd, lib, ma->mtex[a]->tex);
 -                                      if (tx && tx->use_nodes)
 -                                              ma->mtex[a]->which_output++;
 -                              }
 -                      }
                }
  
                /* and composite trees */
                }
        }
  
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 1)) {
+       if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 1)) {
                Object *ob;
 -              Material *ma;
                Tex *tex;
                Scene *sce;
                ToolSettings *ts;
                                tex->afmax = 8;
                }
  
-               for (sce = main->scene.first; sce; sce = sce->id.next) {
 -              for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 -                      int a;
 -
 -                      if (ma->mode & MA_WIRE) {
 -                              ma->material_type = MA_TYPE_WIRE;
 -                              ma->mode &= ~MA_WIRE;
 -                      }
 -
 -                      if (ma->mode & MA_HALO) {
 -                              ma->material_type = MA_TYPE_HALO;
 -                              ma->mode &= ~MA_HALO;
 -                      }
 -
 -                      if (ma->mode & (MA_ZTRANSP|MA_RAYTRANSP)) {
 -                              ma->mode |= MA_TRANSP;
 -                      }
 -                      else {
 -                              /* ma->mode |= MA_ZTRANSP; */ /* leave ztransp as is even if its not used [#28113] */
 -                              ma->mode &= ~MA_TRANSP;
 -                      }
 -
 -                      /* set new bump for unused slots */
 -                      for (a = 0; a < MAX_MTEX; a++) {
 -                              if (ma->mtex[a]) {
 -                                      tex = ma->mtex[a]->tex;
 -                                      if (!tex) {
 -                                              ma->mtex[a]->texflag |= MTEX_3TAP_BUMP;
 -                                              ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE;
 -                                      }
 -                                      else {
 -                                              tex = (Tex*) blo_do_versions_newlibadr(fd, ma->id.lib, tex);
 -                                              if (tex && tex->type == 0) { /* invalid type */
 -                                                      ma->mtex[a]->texflag |= MTEX_3TAP_BUMP;
 -                                                      ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE;
 -                                              }
 -                                      }
 -                              }
 -                      }
 -
 -                      /* volume rendering settings */
 -                      if (ma->vol.stepsize < 0.0001f) {
 -                              ma->vol.density = 1.0f;
 -                              ma->vol.emission = 0.0f;
 -                              ma->vol.scattering = 1.0f;
 -                              ma->vol.emission_col[0] = ma->vol.emission_col[1] = ma->vol.emission_col[2] = 1.0f;
 -                              ma->vol.density_scale = 1.0f;
 -                              ma->vol.depth_cutoff = 0.01f;
 -                              ma->vol.stepsize_type = MA_VOL_STEP_RANDOMIZED;
 -                              ma->vol.stepsize = 0.2f;
 -                              ma->vol.shade_type = MA_VOL_SHADE_SHADED;
 -                              ma->vol.shadeflag |= MA_VOL_PRECACHESHADING;
 -                              ma->vol.precache_resolution = 50;
 -                      }
 -              }
 -
+               for (sce = bmain->scene.first; sce; sce = sce->id.next) {
                        ts = sce->toolsettings;
 -                      if (ts->normalsize == 0.0f || !ts->uv_selectmode || ts->vgroup_weight == 0.0f) {
 -                              ts->normalsize = 0.1f;
 +                      if (!ts->uv_selectmode || ts->vgroup_weight == 0.0f) {
                                ts->selectmode = SCE_SELECT_VERTEX;
  
                                /* autokeying - setting should be taken from the user-prefs
                }
        }
  
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 2)) {
+       if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 2)) {
 -              Scene *sce;
                Object *ob;
  
-               for (ob = main->object.first; ob; ob = ob->id.next) {
 -              for (sce = bmain->scene.first; sce; sce = sce->id.next) {
 -                      if (fd->fileflags & G_FILE_ENABLE_ALL_FRAMES)
 -                              sce->gm.flag |= GAME_ENABLE_ALL_FRAMES;
 -                      if (fd->fileflags & G_FILE_SHOW_DEBUG_PROPS)
 -                              sce->gm.flag |= GAME_SHOW_DEBUG_PROPS;
 -                      if (fd->fileflags & G_FILE_SHOW_FRAMERATE)
 -                              sce->gm.flag |= GAME_SHOW_FRAMERATE;
 -                      if (fd->fileflags & G_FILE_SHOW_PHYSICS)
 -                              sce->gm.flag |= GAME_SHOW_PHYSICS;
 -                      if (fd->fileflags & G_FILE_GLSL_NO_SHADOWS)
 -                              sce->gm.flag |= GAME_GLSL_NO_SHADOWS;
 -                      if (fd->fileflags & G_FILE_GLSL_NO_SHADERS)
 -                              sce->gm.flag |= GAME_GLSL_NO_SHADERS;
 -                      if (fd->fileflags & G_FILE_GLSL_NO_RAMPS)
 -                              sce->gm.flag |= GAME_GLSL_NO_RAMPS;
 -                      if (fd->fileflags & G_FILE_GLSL_NO_NODES)
 -                              sce->gm.flag |= GAME_GLSL_NO_NODES;
 -                      if (fd->fileflags & G_FILE_GLSL_NO_EXTRA_TEX)
 -                              sce->gm.flag |= GAME_GLSL_NO_EXTRA_TEX;
 -                      if (fd->fileflags & G_FILE_GLSL_NO_ENV_LIGHTING)
 -                              sce->gm.flag |= GAME_GLSL_NO_ENV_LIGHTING;
 -                      if (fd->fileflags & G_FILE_IGNORE_DEPRECATION_WARNINGS)
 -                              sce->gm.flag |= GAME_IGNORE_DEPRECATION_WARNINGS;
 -
 -                      if (fd->fileflags & G_FILE_GAME_MAT_GLSL)
 -                              sce->gm.matmode = GAME_MAT_GLSL;
 -                      else if (fd->fileflags & G_FILE_GAME_MAT)
 -                              sce->gm.matmode = GAME_MAT_MULTITEX;
 -                      else
 -                              sce->gm.matmode = GAME_MAT_TEXFACE;
 -
 -                      sce->gm.flag |= GAME_DISPLAY_LISTS;
 -              }
 -
+               for (ob = bmain->object.first; ob; ob = ob->id.next) {
                        if (ob->flag & 8192) // OB_POSEMODE = 8192
                                ob->mode |= OB_MODE_POSE;
                }
        }
  
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 4)) {
+       if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 4)) {
                Scene *sce;
                Object *ob;
 -              Material *ma;
 -              Lamp *la;
 -              World *wo;
 -              Tex *tex;
                ParticleSettings *part;
                bool do_gravity = false;
  
                        ob->rotmode = ROT_MODE_EUL;
                }
  
-               for (sce = main->scene.first; sce; sce = sce->id.next) {
 -              for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 -                      if (ma->vol.reflection == 0.f) {
 -                              ma->vol.reflection = 1.f;
 -                              ma->vol.transmission_col[0] = ma->vol.transmission_col[1] = ma->vol.transmission_col[2] = 1.0f;
 -                              ma->vol.reflection_col[0] = ma->vol.reflection_col[1] = ma->vol.reflection_col[2] = 1.0f;
 -                      }
 -
 -                      do_version_mtex_factor_2_50(ma->mtex, ID_MA);
 -              }
 -
 -              for (la = bmain->lamp.first; la; la = la->id.next)
 -                      do_version_mtex_factor_2_50(la->mtex, ID_LA);
 -
 -              for (wo = bmain->world.first; wo; wo = wo->id.next)
 -                      do_version_mtex_factor_2_50(wo->mtex, ID_WO);
 -
 -              for (tex = bmain->tex.first; tex; tex = tex->id.next)
 -                      if (tex->vd)
 -                              if (tex->vd->extend == 0)
 -                                      tex->vd->extend = TEX_CLIP;
 -
+               for (sce = bmain->scene.first; sce; sce = sce->id.next) {
                        if (sce->audio.main == 0.0f)
                                sce->audio.main = 1.0f;
  
                }
        }
  
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 6)) {
+       if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 6)) {
                Object *ob;
 -              Lamp *la;
  
                /* New variables for axis-angle rotations and/or quaternion rotations were added, and need proper initialization */
-               for (ob = main->object.first; ob; ob = ob->id.next) {
+               for (ob = bmain->object.first; ob; ob = ob->id.next) {
                        /* new variables for all objects */
                        ob->quat[0] = 1.0f;
                        ob->rotAxis[1] = 1.0f;
                                }
                        }
                }
 -
 -              for (la = bmain->lamp.first; la; la = la->id.next)
 -                      la->compressthresh = 0.05f;
        }
  
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 7)) {
+       if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 7)) {
                Mesh *me;
                Nurb *nu;
                Lattice *lt;
                }
  
                /* only convert old 2.50 files with color management */
-               if (main->versionfile == 250) {
-                       Scene *sce = main->scene.first;
-                       Material *ma = main->mat.first;
-                       Tex *tex = main->tex.first;
+               if (bmain->versionfile == 250) {
+                       Scene *sce = bmain->scene.first;
+                       Material *ma = bmain->mat.first;
 -                      World *wo = bmain->world.first;
+                       Tex *tex = bmain->tex.first;
                        int i, convert = 0;
  
                        /* convert to new color management system:
                }
        }
  
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 12)) {
+       if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 12)) {
 -              Scene *sce;
                Object *ob;
                Brush *brush;
 -              Material *ma;
 -
 -              /* game engine changes */
 -              for (sce = bmain->scene.first; sce; sce = sce->id.next) {
 -                      sce->gm.eyeseparation = 0.10f;
 -              }
  
                /* anim viz changes */
-               for (ob = main->object.first; ob; ob = ob->id.next) {
+               for (ob = bmain->object.first; ob; ob = ob->id.next) {
                        /* initialize object defaults */
                        animviz_settings_init(&ob->avs);
  
                        BKE_texture_mtex_default(&brush->mtex);
                        BKE_texture_mtex_default(&brush->mask_mtex);
                }
 -
 -              for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 -                      if (ma->vol.ms_spread < 0.0001f) {
 -                              ma->vol.ms_spread = 0.2f;
 -                              ma->vol.ms_diff = 1.f;
 -                              ma->vol.ms_intensity = 1.f;
 -                      }
 -              }
        }
  
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 13)) {
+       if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 13)) {
                /* NOTE: if you do more conversion, be sure to do it outside of this and
                 * increase subversion again, otherwise it will not be correct */
                Object *ob;
                }
        }
  
-       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 17)) {
 -      if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 15)) {
 -              World *wo;
 -              Material *ma;
 -
 -              /* ambient default from 0.5f to 1.0f */
 -              for (ma = bmain->mat.first; ma; ma = ma->id.next)
 -                      ma->amb *= 2.0f;
 -
 -              for (wo = bmain->world.first; wo; wo = wo->id.next) {
 -                      /* ao splitting into ao/env/indirect */
 -                      wo->ao_env_energy = wo->aoenergy;
 -                      wo->aoenergy = 1.0f;
 -
 -                      if (wo->ao_indirect_bounces == 0)
 -                              wo->ao_indirect_bounces = 1;
 -                      else
 -                              wo->mode |= WO_INDIRECT_LIGHT;
 -
 -                      if (wo->aomix == WO_AOSUB)
 -                              wo->ao_env_energy = -wo->ao_env_energy;
 -                      else if (wo->aomix == WO_AOADDSUB)
 -                              wo->mode |= WO_AMB_OCC;
 -
 -                      wo->aomix = WO_AOMUL;
 -
 -                      /* ambient default from 0.5f to 1.0f */
 -                      mul_v3_fl(&wo->ambr, 0.5f);
 -                      wo->ao_env_energy *= 0.5f;
 -              }
 -      }
 -
+       if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 17)) {
                Scene *sce;
                Sequence *seq;
 -              Material *ma;
  
                /* initialize to sane default so toggling on border shows something */
-               for (sce = main->scene.first; sce; sce = sce->id.next) {
+               for (sce = bmain->scene.first; sce; sce = sce->id.next) {
                        if (sce->r.border.xmin == 0.0f && sce->r.border.ymin == 0.0f &&
                            sce->r.border.xmax == 0.0f && sce->r.border.ymax == 0.0f)
                        {
                Brush *br;
                ParticleSettings *part;
                bScreen *sc;
 -              Object *ob;
  
-               for (br = main->brush.first; br; br = br->id.next) {
+               for (br = bmain->brush.first; br; br = br->id.next) {
                        if (br->ob_mode == 0)
                                br->ob_mode = OB_MODE_ALL_PAINT;
                }
                                }
                        }
                }
 -
 -              /* fix rotation actuators for objects so they use real angles (radians)
 -               * since before blender went opensource this strange scalar was used: (1 / 0.02) * 2 * math.pi/360 */
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      bActuator *act = ob->actuators.first;
 -                      while (act) {
 -                              if (act->type == ACT_OBJECT) {
 -                                      /* multiply velocity with 50 in old files */
 -                                      bObjectActuator *oa = act->data;
 -                                      mul_v3_fl(oa->drot, 0.8726646259971648f);
 -                              }
 -                              act = act->next;
 -                      }
 -              }
 -      }
 -
 -      /* init facing axis property of steering actuators */
 -      {
 -              Object *ob;
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      bActuator *act;
 -                      for (act = ob->actuators.first; act; act = act->next) {
 -                              if (act->type == ACT_STEERING) {
 -                                      bSteeringActuator *stact = act->data;
 -                                      if (stact == NULL) {//HG1
 -                                              init_actuator(act);
 -                                      }
 -                                      else {
 -                                              if (stact->facingaxis == 0) {
 -                                                      stact->facingaxis = 1;
 -                                              }
 -                                      }
 -                              }
 -                      }
 -              }
        }
  
-       if (main->versionfile < 255 || (main->versionfile == 255 && main->subversionfile < 3)) {
+       if (bmain->versionfile < 255 || (bmain->versionfile == 255 && bmain->subversionfile < 3)) {
                Object *ob;
  
                /* ocean res is now squared, reset old ones - will be massive */
                Brush *brush;
                Object *ob;
                ParticleSettings *part;
 -              Material *mat;
 -              int tex_nr, transp_tex;
 -
 -              for (mat = bmain->mat.first; mat; mat = mat->id.next) {
 -                      if (!(mat->mode & MA_TRANSP) && !(mat->material_type & MA_TYPE_VOLUME)) {
 -                              transp_tex = 0;
 -
 -                              for (tex_nr = 0; tex_nr < MAX_MTEX; tex_nr++) {
 -                                      if (!mat->mtex[tex_nr])
 -                                              continue;
 -                                      if (mat->mtex[tex_nr]->mapto & MAP_ALPHA)
 -                                              transp_tex = 1;
 -                              }
 -
 -                              /* weak! material alpha could be animated */
 -                              if (mat->alpha < 1.0f || mat->fresnel_tra > 0.0f || transp_tex) {
 -                                      mat->mode |= MA_TRANSP;
 -                                      mat->mode &= ~(MA_ZTRANSP|MA_RAYTRANSP);
 -                              }
 -                      }
 -              }
  
                /* redraws flag in SpaceTime has been moved to Screen level */
-               for (sc = main->screen.first; sc; sc = sc->id.next) {
+               for (sc = bmain->screen.first; sc; sc = sc->id.next) {
                        if (sc->redraws_flag == 0) {
                                /* just initialize to default? */
                                /* XXX: we could also have iterated through areas, and taken them from the first timeline available... */
                        }
                }
  
 -              {
 -                      /* Initialize texture point density curve falloff */
 -                      Tex *tex;
 -                      for (tex = bmain->tex.first; tex; tex = tex->id.next) {
 -                              if (tex->pd) {
 -                                      if (tex->pd->falloff_speed_scale == 0.0f)
 -                                              tex->pd->falloff_speed_scale = 100.0f;
 -
 -                                      if (!tex->pd->falloff_curve) {
 -                                              tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1);
 -
 -                                              tex->pd->falloff_curve->preset = CURVE_PRESET_LINE;
 -                                              tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
 -                                              curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
 -                                              curvemapping_changed(tex->pd->falloff_curve, false);
 -                                      }
 -                              }
 -                      }
 -              }
 -
 -              {
 -                      /* add default value for behind strength of camera actuator */
 -                      Object *ob;
 -                      bActuator *act;
 -                      for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                              for (act = ob->actuators.first; act; act = act->next) {
 -                                      if (act->type == ACT_CAMERA) {
 -                                              bCameraActuator *ba = act->data;
 -
 -                                              ba->damping = 1.0/32.0;
 -                                      }
 -                              }
 -                      }
 -              }
 -
                {
                        ParticleSettings *part;
-                       for (part = main->particle.first; part; part = part->id.next) {
+                       for (part = bmain->particle.first; part; part = part->id.next) {
                                /* Initialize particle billboard scale */
                                part->bb_size[0] = part->bb_size[1] = 1.0f;
                        }
                                }
                        }
                }
 -
 -              {
 -                      /* convert fcurve and shape action actuators to action actuators */
 -                      Object *ob;
 -                      bActuator *act;
 -                      bIpoActuator *ia;
 -                      bActionActuator *aa;
 -
 -                      for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                              for (act = ob->actuators.first; act; act = act->next) {
 -                                      if (act->type == ACT_IPO) {
 -                                              /* Create the new actuator */
 -                                              ia = act->data;
 -                                              aa = MEM_callocN(sizeof(bActionActuator), "fcurve -> action actuator do_version");
 -
 -                                              /* Copy values */
 -                                              aa->type = ia->type;
 -                                              aa->flag = ia->flag;
 -                                              aa->sta = ia->sta;
 -                                              aa->end = ia->end;
 -                                              BLI_strncpy(aa->name, ia->name, sizeof(aa->name));
 -                                              BLI_strncpy(aa->frameProp, ia->frameProp, sizeof(aa->frameProp));
 -                                              if (ob->adt)
 -                                                      aa->act = ob->adt->action;
 -
 -                                              /* Get rid of the old actuator */
 -                                              MEM_freeN(ia);
 -
 -                                              /* Assign the new actuator */
 -                                              act->data = aa;
 -                                              act->type = act->otype = ACT_ACTION;
 -
 -                                              /* Fix for converting 2.4x files: if we don't have an action, but we have an
 -                                               * object IPO, then leave the actuator as an IPO actuator for now and let the
 -                                               * IPO conversion code handle it */
 -                                              if (ob->ipo && !aa->act)
 -                                                      act->type = ACT_IPO;
 -                                      }
 -                                      else if (act->type == ACT_SHAPEACTION) {
 -                                              act->type = act->otype = ACT_ACTION;
 -                                      }
 -                              }
 -                      }
 -              }
        }
  
-       if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 2)) {
+       if (bmain->versionfile < 259 || (bmain->versionfile == 259 && bmain->subversionfile < 2)) {
                {
                        /* Convert default socket values from bNodeStack */
-                       FOREACH_NODETREE(main, ntree, id) {
+                       FOREACH_NODETREE(bmain, ntree, id) {
                                bNode *node;
                                bNodeSocket *sock;
                                
@@@ -912,9 -943,44 +912,9 @@@ void blo_do_versions_260(FileData *fd, 
                                }
                        }
                }
 -              {
 -                      /* Warn the user if he is using ["Text"] properties for Font objects */
 -                      Object *ob;
 -                      bProperty *prop;
 -
 -                      for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                              if (ob->type == OB_FONT) {
 -                                      prop = BKE_bproperty_object_get(ob, "Text");
 -                                      if (prop) {
 -                                              blo_reportf_wrap(fd->reports, RPT_WARNING,
 -                                                               TIP_("Game property name conflict in object '%s': text objects reserve the "
 -                                                                    "['Text'] game property to change their content through logic bricks"),
 -                                                               ob->id.name + 2);
 -                                      }
 -                              }
 -                      }
 -              }
        }
  
-       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 2)) {
+       if (bmain->versionfile < 261 || (bmain->versionfile == 261 && bmain->subversionfile < 2)) {
 -              {
 -                      /* convert Camera Actuator values to defines */
 -                      Object *ob;
 -                      bActuator *act;
 -                      for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                              for (act = ob->actuators.first; act; act = act->next) {
 -                                      if (act->type == ACT_CAMERA) {
 -                                              bCameraActuator *ba = act->data;
 -
 -                                              if (ba->axis == (float) 'x') ba->axis = OB_POSX;
 -                                              else if (ba->axis == (float)'y') ba->axis = OB_POSY;
 -                                              /* don't do an if/else to avoid imediate subversion bump*/
 -//                                            ba->axis=((ba->axis == (float)'x') ? OB_POSX_X : OB_POSY);
 -                                      }
 -                              }
 -                      }
 -              }
 -
                {
                        /* convert deprecated sculpt_paint_unified_* fields to
                         * UnifiedPaintSettings */
                }
        }
  
-       if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 4)) {
+       if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 4)) {
 -              Lamp *la;
                Camera *cam;
                Curve *cu;
  
-               for (cam = main->camera.first; cam; cam = cam->id.next) {
 -              for (la = bmain->lamp.first; la; la = la->id.next) {
 -                      if (la->shadow_frustum_size == 0.0f)
 -                              la->shadow_frustum_size = 10.0f;
 -              }
 -
+               for (cam = bmain->camera.first; cam; cam = cam->id.next) {
                        if (cam->flag & CAM_PANORAMA) {
                                cam->type = CAM_PANO;
                                cam->flag &= ~CAM_PANORAMA;
                }
        }
  
-       if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 9)) {
-               FOREACH_NODETREE(main, ntree, id) {
 -
 -      if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 8)) {
 -              /* set new deactivation values for game settings */
 -              Scene *sce;
 -
 -              for (sce = bmain->scene.first; sce; sce = sce->id.next) {
 -                      /* Game Settings */
 -                      sce->gm.lineardeactthreshold = 0.8f;
 -                      sce->gm.angulardeactthreshold = 1.0f;
 -                      sce->gm.deactivationtime = 2.0f;
 -              }
 -      }
 -
+       if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 9)) {
+               FOREACH_NODETREE(bmain, ntree, id) {
                        if (ntree->type == NTREE_SHADER) {
                                bNode *node;
                                for (node = ntree->nodes.first; node; node = node->next) {
                }
        }
  
-       if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 13)) {
-               FOREACH_NODETREE(main, ntree, id) {
 -      if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 12)) {
 -              Material *ma;
 -
 -              for (ma = bmain->mat.first; ma; ma = ma->id.next)
 -                      if (ma->strand_widthfade == 2.0f)
 -                              ma->strand_widthfade = 0.0f;
 -      }
 -
+       if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 13)) {
+               FOREACH_NODETREE(bmain, ntree, id) {
                        if (ntree->type == NTREE_COMPOSIT) {
                                bNode *node;
                                for (node = ntree->nodes.first; node; node = node->next) {
                }
        }
  
-       if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 21)) {
 -      /* remove texco */
+       if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 21)) {
 -              Material *ma;
 -              for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 -                      int a;
 -                      for (a = 0; a < MAX_MTEX; a++) {
 -                              if (ma->mtex[a]) {
 -                                      if (ma->mtex[a]->texco == TEXCO_STICKY_) {
 -                                              ma->mtex[a]->texco = TEXCO_UV;
 -                                      }
 -                              }
 -                      }
 -              }
 -
                {
                        Mesh *me;
-                       for (me = main->mesh.first; me; me = me->id.next) {
+                       for (me = bmain->mesh.first; me; me = me->id.next) {
                                CustomData_update_typemap(&me->vdata);
                                CustomData_free_layers(&me->vdata, CD_MSTICKY, me->totvert);
                        }
                } FOREACH_NODETREE_END
        }
  
-       if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 7)) {
 -      if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 6)) {
 -              bScreen *sc;
 -
 -              for (sc = bmain->screen.first; sc; sc = sc->id.next) {
 -                      ScrArea *sa;
 -                      for (sa = sc->areabase.first; sa; sa = sa->next) {
 -                              SpaceLink *sl;
 -                              if ( sa->spacetype == SPACE_LOGIC)
 -                                      do_version_logic_264(&sa->regionbase);
 -
 -                              for (sl = sa->spacedata.first; sl; sl = sl->next) {
 -                                      if (sl->spacetype == SPACE_LOGIC)
 -                                              do_version_logic_264(&sl->regionbase);
 -                              }
 -                      }
 -              }
 -      }
 -
+       if (bmain->versionfile < 264 || (bmain->versionfile == 264 && bmain->subversionfile < 7)) {
                /* convert tiles size from resolution and number of tiles */
                {
                        Scene *scene;
  
-                       for (scene = main->scene.first; scene; scene = scene->id.next) {
+                       for (scene = bmain->scene.first; scene; scene = scene->id.next) {
                                if (scene->r.tilex == 0 || scene->r.tiley == 1) {
 -                                      if (scene->r.xparts && scene->r.yparts) {
 -                                              /* scene could be set for panoramic rendering, so clamp with the
 -                                               * lowest possible tile size value
 -                                               */
 -                                              scene->r.tilex = max_ii(scene->r.xsch * scene->r.size / scene->r.xparts / 100, 8);
 -                                              scene->r.tiley = max_ii(scene->r.ysch * scene->r.size / scene->r.yparts / 100, 8);
 -                                      }
 -                                      else {
 -                                              /* happens when mixing using current trunk and previous release */
 -                                              scene->r.tilex = scene->r.tiley = 64;
 -                                      }
 +                                      scene->r.tilex = scene->r.tiley = 64;
                                }
                        }
                }
                }
        }
  
-       if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 3)) {
 -      if (bmain->versionfile < 265) {
 -              Object *ob;
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      if (ob->step_height == 0.0f) {
 -                              ob->step_height = 0.15f;
 -                              ob->jump_speed = 10.0f;
 -                              ob->fall_speed = 55.0f;
 -                      }
 -              }
 -      }
 -
+       if (bmain->versionfile < 265 || (bmain->versionfile == 265 && bmain->subversionfile < 3)) {
                bScreen *sc;
-               for (sc = main->screen.first; sc; sc = sc->id.next) {
+               for (sc = bmain->screen.first; sc; sc = sc->id.next) {
                        ScrArea *sa;
                        for (sa = sc->areabase.first; sa; sa = sa->next) {
                                SpaceLink *sl;
                Scene *scene;
                Tex *tex;
  
-               for (scene = main->scene.first; scene; scene = scene->id.next) {
+               for (scene = bmain->scene.first; scene; scene = scene->id.next) {
                        Sequence *seq;
 -                      bool set_premul = false;
  
                        SEQ_BEGIN (scene->ed, seq)
                        {
  
                        if (scene->r.bake_samples == 0)
                                scene->r.bake_samples = 256;
 -
 -                      if (scene->world) {
 -                              World *world = blo_do_versions_newlibadr(fd, scene->id.lib, scene->world);
 -
 -                              if (world && is_zero_v3(&world->horr)) {
 -                                      if ((world->skytype & WO_SKYBLEND) == 0 || is_zero_v3(&world->zenr)) {
 -                                              set_premul = true;
 -                                      }
 -                              }
 -                      }
 -                      else
 -                              set_premul = true;
 -
 -                      if (set_premul) {
 -                              printf("2.66 versioning fix: replacing black sky with premultiplied alpha for scene %s\n",
 -                                     scene->id.name + 2);
 -                              scene->r.alphamode = R_ALPHAPREMUL;
 -                      }
                }
  
-               for (Image *image = main->image.first; image; image = image->id.next) {
+               for (Image *image = bmain->image.first; image; image = image->id.next) {
                        if (image->flag & IMA_DO_PREMUL) {
                                image->alpha_mode = IMA_ALPHA_STRAIGHT;
                        }
                                }
                        }
                }
 -
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      bSensor *sens;
 -                      bTouchSensor *ts;
 -                      bCollisionSensor *cs;
 -                      Material *ma;
 -
 -                      for (sens = ob->sensors.first; sens; sens = sens->next) {
 -                              if (sens->type == SENS_TOUCH) {
 -                                      ts = sens->data;
 -                                      cs = MEM_callocN(sizeof(bCollisionSensor), "touch -> collision sensor do_version");
 -
 -                                      if (ts->ma) {
 -                                              ma = blo_do_versions_newlibadr(fd, ob->id.lib, ts->ma);
 -                                              BLI_strncpy(cs->materialName, ma->id.name + 2, sizeof(cs->materialName));
 -                                      }
 -
 -                                      cs->mode = SENS_COLLISION_MATERIAL;
 -
 -                                      MEM_freeN(ts);
 -
 -                                      sens->data = cs;
 -                                      sens->type = sens->otype = SENS_COLLISION;
 -                              }
 -                      }
 -              }
        }
  
-       if (!MAIN_VERSION_ATLEAST(main, 268, 5)) {
+       if (!MAIN_VERSION_ATLEAST(bmain, 268, 5)) {
                bScreen *sc;
                ScrArea *sa;
  
                        Object *ob;
                        Lamp *lamp;
  
-                       for (lamp = main->lamp.first; lamp; lamp = lamp->id.next)
+                       for (lamp = bmain->lamp.first; lamp; lamp = lamp->id.next)
                                lamp->spotsize = DEG2RADF(lamp->spotsize);
  
-                       for (ob = main->object.first; ob; ob = ob->id.next) {
+                       for (ob = bmain->object.first; ob; ob = ob->id.next) {
                                ModifierData *md;
 -                              bSensor *bs;
 -                              bActuator *ba;
  
                                for (md = ob->modifiers.first; md; md = md->next) {
                                        if (md->type == eModifierType_EdgeSplit) {
                                                bmd->bevel_angle = DEG2RADF(bmd->bevel_angle);
                                        }
                                }
 -
 -                              for (bs = ob->sensors.first; bs; bs = bs->next) {
 -                                      if (bs->type == SENS_RADAR) {
 -                                              bRadarSensor *brs = bs->data;
 -                                              brs->angle = DEG2RADF(brs->angle);
 -                                      }
 -                              }
 -
 -                              for (ba = ob->actuators.first; ba; ba = ba->next) {
 -                                      if (ba->type == ACT_CONSTRAINT) {
 -                                              bConstraintActuator *bca = ba->data;
 -                                              if (bca->type == ACT_CONST_TYPE_ORI) {
 -                                                      bca->minloc[0] = DEG2RADF(bca->minloc[0]);
 -                                                      bca->maxloc[0] = DEG2RADF(bca->maxloc[0]);
 -                                              }
 -                                      }
 -                                      else if (ba->type == ACT_SOUND) {
 -                                              bSoundActuator *bsa = ba->data;
 -                                              bsa->sound3D.cone_outer_angle = DEG2RADF(bsa->sound3D.cone_outer_angle);
 -                                              bsa->sound3D.cone_inner_angle = DEG2RADF(bsa->sound3D.cone_inner_angle);
 -                                      }
 -                              }
                        }
  
-                       for (scene = main->scene.first; scene; scene = scene->id.next) {
+                       for (scene = bmain->scene.first; scene; scene = scene->id.next) {
                                Sequence *seq;
                                SEQ_BEGIN (scene->ed, seq)
                                {
@@@ -404,7 -405,8 +404,7 @@@ void blo_do_versions_270(FileData *fd, 
                }
        }
  
-       if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
+       if (!MAIN_VERSION_ATLEAST(bmain, 270, 1)) {
 -              Scene *sce;
                Object *ob;
  
                /* Update Transform constraint (another deg -> rad stuff). */
                                }
                        }
                }
 -
 -              for (sce = bmain->scene.first; sce; sce = sce->id.next) {
 -                      if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
 -                              sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
 -                      }
 -              }
        }
  
-       if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
+       if (!MAIN_VERSION_ATLEAST(bmain, 270, 2)) {
                Mesh *me;
  
                /* Mesh smoothresh deg->rad. */
                }
        }
  
-       if (!MAIN_VERSION_ATLEAST(main, 271, 0)) {
+       if (!MAIN_VERSION_ATLEAST(bmain, 271, 0)) {
 -              if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) {
 -                      Material *ma;
 -
 -                      for (ma = bmain->mat.first; ma; ma = ma->id.next)
 -                              ma->mode2 = MA_CASTSHADOW;
 -              }
 -
                if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) {
                        Scene *sce;
  
                }
        }
  
-       if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
 -      if (!MAIN_VERSION_ATLEAST(bmain, 271, 2)) {
 -              /* init up & track axis property of trackto actuators */
 -              Object *ob;
 -
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      bActuator *act;
 -                      for (act = ob->actuators.first; act; act = act->next) {
 -                              if (act->type == ACT_EDIT_OBJECT) {
 -                                      bEditObjectActuator *eoact = act->data;
 -                                      eoact->trackflag = ob->trackflag;
 -                                      /* if trackflag is pointing +-Z axis then upflag should point Y axis.
 -                                       * Rest of trackflag cases, upflag should be point z axis */
 -                                      if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
 -                                              eoact->upflag = 1;
 -                                      }
 -                                      else {
 -                                              eoact->upflag = 2;
 -                                      }
 -                              }
 -                      }
 -              }
 -      }
 -
+       if (!MAIN_VERSION_ATLEAST(bmain, 271, 3)) {
                Brush *br;
  
-               for (br = main->brush.first; br; br = br->id.next) {
+               for (br = bmain->brush.first; br; br = br->id.next) {
                        br->fill_threshold = 0.2f;
                }
  
                                }
                        }
                }
 -
 -              if (!DNA_struct_elem_find(fd->filesdna, "GameData", "int", "scehysteresis")) {
 -                      Scene *scene;
 -                      for (scene = bmain->scene.first; scene; scene = scene->id.next) {
 -                              scene->gm.scehysteresis = 10;
 -                      }
 -              }
 -      }
 -
 -      if (!MAIN_VERSION_ATLEAST(bmain, 274, 2)) {
 -              FOREACH_NODETREE(bmain, ntree, id) {
 -                      bNode *node;
 -                      bNodeSocket *sock;
 -
 -                      for (node = ntree->nodes.first; node; node = node->next) {
 -                              if (node->type == SH_NODE_MATERIAL) {
 -                                      for (sock = node->inputs.first; sock; sock = sock->next) {
 -                                              if (STREQ(sock->name, "Refl")) {
 -                                                      BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
 -                                              }
 -                                      }
 -                              }
 -                              else if (node->type == SH_NODE_MATERIAL_EXT) {
 -                                      for (sock = node->outputs.first; sock; sock = sock->next) {
 -                                              if (STREQ(sock->name, "Refl")) {
 -                                                      BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
 -                                              }
 -                                              else if (STREQ(sock->name, "Ray Mirror")) {
 -                                                      BLI_strncpy(sock->name, "Reflectivity", sizeof(sock->name));
 -                                              }
 -                                      }
 -                              }
 -                      }
 -              } FOREACH_NODETREE_END
        }
  
-       if (!MAIN_VERSION_ATLEAST(main, 274, 4)) {
+       if (!MAIN_VERSION_ATLEAST(bmain, 274, 4)) {
                SceneRenderView *srv;
                wmWindowManager *wm;
                bScreen *screen;
                        }
  #undef LA_YF_PHOTON
                }
 -
 -              {
 -                      Object *ob;
 -                      for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                              if (ob->body_type == OB_BODY_TYPE_CHARACTER && (ob->gameflag & OB_BOUNDS) && ob->collision_boundtype == OB_BOUND_TRIANGLE_MESH) {
 -                                      ob->boundtype = ob->collision_boundtype = OB_BOUND_BOX;
 -                              }
 -                      }
 -              }
 -
        }
  
-       if (!MAIN_VERSION_ATLEAST(main, 276, 3)) {
+       if (!MAIN_VERSION_ATLEAST(bmain, 276, 3)) {
                if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "CurveMapping", "mblur_shutter_curve")) {
                        Scene *scene;
-                       for (scene = main->scene.first; scene != NULL; scene = scene->id.next) {
+                       for (scene = bmain->scene.first; scene != NULL; scene = scene->id.next) {
                                CurveMapping *curve_mapping = &scene->r.mblur_shutter_curve;
                                curvemapping_set_defaults(curve_mapping, 1, 0.0f, 0.0f, 1.0f, 1.0f);
                                curvemapping_initialize(curve_mapping);
                        else
                                gpd->flag &= ~GP_DATA_SHOW_ONIONSKINS;
                }
 -
 -              if (!DNA_struct_elem_find(fd->filesdna, "Object", "unsigned char", "max_jumps")) {
 -                      for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
 -                              ob->max_jumps = 1;
 -                      }
 -              }
        }
-       if (!MAIN_VERSION_ATLEAST(main, 276, 5)) {
+       if (!MAIN_VERSION_ATLEAST(bmain, 276, 5)) {
                ListBase *lbarray[MAX_LIBARRAY];
                int a;
  
index f73df9a,0000000..37f308d
mode 100644,000000..100644
--- /dev/null
@@@ -1,1557 -1,0 +1,1557 @@@
- void do_versions_after_linking_280(Main *main)
 +/*
 + * ***** BEGIN GPL LICENSE BLOCK *****
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * Contributor(s): Dalai Felinto
 + *
 + * ***** END GPL LICENSE BLOCK *****
 + *
 + */
 +
 +/** \file blender/blenloader/intern/versioning_280.c
 + *  \ingroup blenloader
 + */
 +
 +/* allow readfile to use deprecated functionality */
 +#define DNA_DEPRECATED_ALLOW
 +
 +#include <string.h>
 +#include <float.h>
 +
 +#include "BLI_listbase.h"
 +#include "BLI_math.h"
 +#include "BLI_mempool.h"
 +#include "BLI_string.h"
 +#include "BLI_string_utf8.h"
 +#include "BLI_utildefines.h"
 +
 +#include "DNA_object_types.h"
 +#include "DNA_camera_types.h"
 +#include "DNA_constraint_types.h"
 +#include "DNA_gpu_types.h"
 +#include "DNA_group_types.h"
 +#include "DNA_lamp_types.h"
 +#include "DNA_layer_types.h"
 +#include "DNA_lightprobe_types.h"
 +#include "DNA_material_types.h"
 +#include "DNA_mesh_types.h"
 +#include "DNA_particle_types.h"
 +#include "DNA_scene_types.h"
 +#include "DNA_screen_types.h"
 +#include "DNA_view3d_types.h"
 +#include "DNA_genfile.h"
 +#include "DNA_workspace_types.h"
 +
 +#include "BKE_collection.h"
 +#include "BKE_constraint.h"
 +#include "BKE_customdata.h"
 +#include "BKE_freestyle.h"
 +#include "BKE_idprop.h"
 +#include "BKE_layer.h"
 +#include "BKE_main.h"
 +#include "BKE_mesh.h"
 +#include "BKE_node.h"
 +#include "BKE_report.h"
 +#include "BKE_scene.h"
 +#include "BKE_screen.h"
 +#include "BKE_studiolight.h"
 +#include "BKE_workspace.h"
 +
 +#include "BLO_readfile.h"
 +#include "readfile.h"
 +
 +#include "MEM_guardedalloc.h"
 +
 +static bScreen *screen_parent_find(const bScreen *screen)
 +{
 +      /* can avoid lookup if screen state isn't maximized/full (parent and child store the same state) */
 +      if (ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL)) {
 +              for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                      if (sa->full && sa->full != screen) {
 +                              BLI_assert(sa->full->state == screen->state);
 +                              return sa->full;
 +                      }
 +              }
 +      }
 +
 +      return NULL;
 +}
 +
 +static void do_version_workspaces_create_from_screens(Main *bmain)
 +{
 +      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +              const bScreen *screen_parent = screen_parent_find(screen);
 +              Scene *scene = screen->scene;
 +              WorkSpace *workspace;
 +              ViewLayer *layer = BLI_findlink(&scene->view_layers, scene->r.actlay);
 +              if (!layer) {
 +                      layer = BKE_view_layer_default_view(scene);
 +              }
 +
 +              if (screen_parent) {
 +                      /* fullscreen with "Back to Previous" option, don't create
 +                       * a new workspace, add layout workspace containing parent */
 +                      workspace = BLI_findstring(
 +                              &bmain->workspaces, screen_parent->id.name + 2, offsetof(ID, name) + 2);
 +              }
 +              else {
 +                      workspace = BKE_workspace_add(bmain, screen->id.name + 2);
 +              }
 +              BKE_workspace_layout_add(workspace, screen, screen->id.name + 2);
 +              BKE_workspace_view_layer_set(workspace, layer, scene);
 +      }
 +}
 +
 +static void do_version_area_change_space_to_space_action(ScrArea *area, const Scene *scene)
 +{
 +      SpaceType *stype = BKE_spacetype_from_id(SPACE_ACTION);
 +      SpaceAction *saction = (SpaceAction *)stype->new(area, scene);
 +      ARegion *region_channels;
 +
 +      /* Properly free current regions */
 +      for (ARegion *region = area->regionbase.first; region; region = region->next) {
 +              BKE_area_region_free(area->type, region);
 +      }
 +      BLI_freelistN(&area->regionbase);
 +
 +      area->type = stype;
 +      area->spacetype = stype->spaceid;
 +
 +      BLI_addhead(&area->spacedata, saction);
 +      area->regionbase = saction->regionbase;
 +      BLI_listbase_clear(&saction->regionbase);
 +
 +      /* Different defaults for timeline */
 +      region_channels = BKE_area_find_region_type(area, RGN_TYPE_CHANNELS);
 +      region_channels->flag |= RGN_FLAG_HIDDEN;
 +
 +      saction->mode = SACTCONT_TIMELINE;
 +      saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED;
 +}
 +
 +/**
 + * \brief After lib-link versioning for new workspace design.
 + *
 + * - Adds a workspace for (almost) each screen of the old file
 + *   and adds the needed workspace-layout to wrap the screen.
 + * - Active screen isn't stored directly in window anymore, but in the active workspace.
 + * - Active scene isn't stored in screen anymore, but in window.
 + * - Create workspace instance hook for each window.
 + *
 + * \note Some of the created workspaces might be deleted again in case of reading the default startup.blend.
 + */
 +static void do_version_workspaces_after_lib_link(Main *bmain)
 +{
 +      BLI_assert(BLI_listbase_is_empty(&bmain->workspaces));
 +
 +      do_version_workspaces_create_from_screens(bmain);
 +
 +      for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
 +              for (wmWindow *win = wm->windows.first; win; win = win->next) {
 +                      bScreen *screen_parent = screen_parent_find(win->screen);
 +                      bScreen *screen = screen_parent ? screen_parent : win->screen;
 +                      WorkSpace *workspace = BLI_findstring(&bmain->workspaces, screen->id.name + 2, offsetof(ID, name) + 2);
 +                      ListBase *layouts = BKE_workspace_layouts_get(workspace);
 +
 +                      win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
 +
 +                      BKE_workspace_active_set(win->workspace_hook, workspace);
 +                      BKE_workspace_active_layout_set(win->workspace_hook, layouts->first);
 +
 +                      win->scene = screen->scene;
 +                      /* Deprecated from now on! */
 +                      win->screen = NULL;
 +              }
 +      }
 +
 +      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +              /* Deprecated from now on! */
 +              BLI_freelistN(&screen->scene->transform_spaces);
 +              screen->scene = NULL;
 +      }
 +}
 +
 +#ifdef USE_COLLECTION_COMPAT_28
 +enum {
 +      COLLECTION_DEPRECATED_VISIBLE    = (1 << 0),
 +      COLLECTION_DEPRECATED_VIEWPORT   = (1 << 0),
 +      COLLECTION_DEPRECATED_SELECTABLE = (1 << 1),
 +      COLLECTION_DEPRECATED_DISABLED   = (1 << 2),
 +      COLLECTION_DEPRECATED_RENDER     = (1 << 3),
 +};
 +
 +static void do_version_view_layer_visibility(ViewLayer *view_layer)
 +{
 +      /* Convert from deprecated VISIBLE flag to DISABLED */
 +      LayerCollection *lc;
 +      for (lc = view_layer->layer_collections.first;
 +           lc;
 +           lc = lc->next)
 +      {
 +              if (lc->flag & COLLECTION_DEPRECATED_DISABLED) {
 +                      lc->flag &= ~COLLECTION_DEPRECATED_DISABLED;
 +              }
 +
 +              if ((lc->flag & COLLECTION_DEPRECATED_VISIBLE) == 0) {
 +                      lc->flag |= COLLECTION_DEPRECATED_DISABLED;
 +              }
 +
 +              lc->flag |= COLLECTION_DEPRECATED_VIEWPORT | COLLECTION_DEPRECATED_RENDER;
 +      }
 +}
 +
 +static void do_version_layer_collection_pre(
 +        ViewLayer *view_layer,
 +        ListBase *lb,
 +        GSet *enabled_set,
 +        GSet *selectable_set)
 +{
 +      /* Convert from deprecated DISABLED to new layer collection and collection flags */
 +      for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
 +              if (lc->scene_collection) {
 +                      if (!(lc->flag & COLLECTION_DEPRECATED_DISABLED)) {
 +                              BLI_gset_insert(enabled_set, lc->scene_collection);
 +                      }
 +                      if (lc->flag & COLLECTION_DEPRECATED_SELECTABLE) {
 +                              BLI_gset_insert(selectable_set, lc->scene_collection);
 +                      }
 +              }
 +
 +              do_version_layer_collection_pre(view_layer, &lc->layer_collections, enabled_set, selectable_set);
 +      }
 +}
 +
 +static void do_version_layer_collection_post(
 +        ViewLayer *view_layer,
 +        ListBase *lb,
 +        GSet *enabled_set,
 +        GSet *selectable_set,
 +        GHash *collection_map)
 +{
 +      /* Apply layer collection exclude flags. */
 +      for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
 +              if (!(lc->collection->flag & COLLECTION_IS_MASTER)) {
 +                      SceneCollection *sc = BLI_ghash_lookup(collection_map, lc->collection);
 +                      const bool enabled = (sc && BLI_gset_haskey(enabled_set, sc));
 +                      const bool selectable = (sc && BLI_gset_haskey(selectable_set, sc));
 +
 +                      if (!enabled) {
 +                              lc->flag |= LAYER_COLLECTION_EXCLUDE;
 +                      }
 +                      if (enabled && !selectable) {
 +                              lc->collection->flag |= COLLECTION_RESTRICT_SELECT;
 +                      }
 +              }
 +
 +              do_version_layer_collection_post(
 +                      view_layer, &lc->layer_collections, enabled_set, selectable_set, collection_map);
 +      }
 +}
 +
 +static void do_version_scene_collection_convert(
 +        Main *bmain,
 +        ID *id,
 +        SceneCollection *sc,
 +        Collection *collection,
 +        GHash *collection_map)
 +{
 +      if (collection_map) {
 +              BLI_ghash_insert(collection_map, collection, sc);
 +      }
 +
 +      for (SceneCollection *nsc = sc->scene_collections.first; nsc;) {
 +              SceneCollection *nsc_next = nsc->next;
 +              Collection *ncollection = BKE_collection_add(bmain, collection, nsc->name);
 +              ncollection->id.lib = id->lib;
 +              do_version_scene_collection_convert(bmain, id, nsc, ncollection, collection_map);
 +              nsc = nsc_next;
 +      }
 +
 +      for (LinkData *link = sc->objects.first; link; link = link->next) {
 +              Object *ob = link->data;
 +              if (ob) {
 +                      BKE_collection_object_add(bmain, collection, ob);
 +                      id_us_min(&ob->id);
 +              }
 +      }
 +
 +      BLI_freelistN(&sc->objects);
 +      MEM_freeN(sc);
 +}
 +
 +static void do_version_group_collection_to_collection(Main *bmain, Collection *group)
 +{
 +      /* Convert old 2.8 group collections to new unified collections. */
 +      if (group->collection) {
 +              do_version_scene_collection_convert(bmain, &group->id, group->collection, group, NULL);
 +      }
 +
 +      group->collection = NULL;
 +      group->view_layer = NULL;
 +      id_fake_user_set(&group->id);
 +}
 +
 +static void do_version_scene_collection_to_collection(Main *bmain, Scene *scene)
 +{
 +      /* Convert old 2.8 scene collections to new unified collections. */
 +
 +      /* Temporarily clear view layers so we don't do any layer collection syncing
 +       * and destroy old flags that we want to restore. */
 +      ListBase view_layers = scene->view_layers;
 +      BLI_listbase_clear(&scene->view_layers);
 +
 +      if (!scene->master_collection) {
 +              scene->master_collection = BKE_collection_master_add();
 +      }
 +
 +      /* Convert scene collections. */
 +      GHash *collection_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
 +      if (scene->collection) {
 +              do_version_scene_collection_convert(bmain, &scene->id, scene->collection, scene->master_collection, collection_map);
 +              scene->collection = NULL;
 +      }
 +
 +      scene->view_layers = view_layers;
 +
 +      /* Convert layer collections. */
 +      ViewLayer *view_layer;
 +      for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
 +              GSet *enabled_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
 +              GSet *selectable_set = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
 +
 +              do_version_layer_collection_pre(
 +                      view_layer, &view_layer->layer_collections, enabled_set, selectable_set);
 +
 +              BKE_layer_collection_sync(scene, view_layer);
 +
 +              do_version_layer_collection_post(
 +                      view_layer, &view_layer->layer_collections, enabled_set, selectable_set, collection_map);
 +
 +              BLI_gset_free(enabled_set, NULL);
 +              BLI_gset_free(selectable_set, NULL);
 +
 +              BKE_layer_collection_sync(scene, view_layer);
 +      }
 +
 +      BLI_ghash_free(collection_map, NULL, NULL);
 +}
 +#endif
 +
 +
 +enum {
 +      DO_VERSION_COLLECTION_VISIBLE     = 0,
 +      DO_VERSION_COLLECTION_HIDE        = 1,
 +      DO_VERSION_COLLECTION_HIDE_RENDER = 2,
 +      DO_VERSION_COLLECTION_HIDE_ALL    = 3,
 +};
 +
 +static void do_version_layers_to_collections(Main *bmain, Scene *scene)
 +{
 +      /* Since we don't have access to FileData we check the (always valid) first
 +       * render layer instead. */
 +      if (!scene->master_collection) {
 +              scene->master_collection = BKE_collection_master_add();
 +      }
 +
 +      if (scene->view_layers.first) {
 +              return;
 +      }
 +
 +      /* Create collections from layers. */
 +      Collection *collection_master = BKE_collection_master(scene);
 +
 +      struct DoVersionSceneCollections {
 +              Collection *collections[20];
 +              int created;
 +              const char *suffix;
 +              int flag;
 +      } collections[] =
 +      {
 +              {
 +                      .collections = {NULL},
 +                      .created = 0,
 +                      .suffix = "",
 +                      .flag = 0,
 +              },
 +              {
 +                      .collections = {NULL},
 +                      .created = 0,
 +                      .suffix = " - Hide Viewport",
 +                      .flag = COLLECTION_RESTRICT_VIEW,
 +              },
 +              {
 +                      .collections = {NULL},
 +                      .created = 0,
 +                      .suffix = " - Hide Render",
 +                      .flag = COLLECTION_RESTRICT_RENDER,
 +              },
 +              {
 +                      .collections = {NULL},
 +                      .created = 0,
 +                      .suffix = " - Hide Render All",
 +                      .flag = COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER,
 +              }
 +      };
 +
 +      for (int layer = 0; layer < 20; layer++) {
 +              for (Base *base = scene->base.first; base; base = base->next) {
 +                      if (base->lay & (1 << layer)) {
 +                              int collection_index = -1;
 +                              if ((base->object->restrictflag & OB_RESTRICT_VIEW) &&
 +                                  (base->object->restrictflag & OB_RESTRICT_RENDER))
 +                              {
 +                                      collection_index = DO_VERSION_COLLECTION_HIDE_ALL;
 +                              }
 +                              else if (base->object->restrictflag & OB_RESTRICT_VIEW) {
 +                                      collection_index = DO_VERSION_COLLECTION_HIDE;
 +                              }
 +                              else if (base->object->restrictflag & OB_RESTRICT_RENDER) {
 +                                      collection_index = DO_VERSION_COLLECTION_HIDE_RENDER;
 +                              }
 +                              else {
 +                                      collection_index = DO_VERSION_COLLECTION_VISIBLE;
 +                              }
 +
 +                              /* Create collections when needed only. */
 +                              if ((collections[collection_index].created & (1 << layer)) == 0) {
 +                                      char name[MAX_NAME];
 +
 +                                      if ((collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) == 0) {
 +                                              BLI_snprintf(name,
 +                                                           sizeof(collection_master->id.name),
 +                                                           "Collection %d%s",
 +                                                           layer + 1,
 +                                                           collections[DO_VERSION_COLLECTION_VISIBLE].suffix);
 +
 +                                              Collection *collection = BKE_collection_add(bmain, collection_master, name);
 +                                              collection->id.lib = scene->id.lib;
 +                                              collection->flag |= collections[DO_VERSION_COLLECTION_VISIBLE].flag;
 +                                              collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer] = collection;
 +                                              collections[DO_VERSION_COLLECTION_VISIBLE].created |= (1 << layer);
 +
 +                                              if (!(scene->lay & (1 << layer))) {
 +                                                      collection->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
 +                                              }
 +                                      }
 +
 +                                      if (collection_index != DO_VERSION_COLLECTION_VISIBLE) {
 +                                              Collection *collection_parent;
 +                                              collection_parent = collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer];
 +                                              BLI_snprintf(name,
 +                                                           sizeof(collection_master->id.name),
 +                                                           "Collection %d%s",
 +                                                           layer + 1,
 +                                                           collections[collection_index].suffix);
 +
 +                                              Collection *collection = BKE_collection_add(bmain, collection_parent, name);
 +                                              collection->id.lib = scene->id.lib;
 +                                              collection->flag |= collections[collection_index].flag;
 +                                              collections[collection_index].collections[layer] = collection;
 +                                              collections[collection_index].created |= (1 << layer);
 +
 +                                              if (!(scene->lay & (1 << layer))) {
 +                                                      collection->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
 +                                              }
 +                                      }
 +                              }
 +
 +                              /* Note usually this would do slow collection syncing for view layers,
 +                               * but since no view layers exists yet at this point it's fast. */
 +                              BKE_collection_object_add(
 +                                      bmain,
 +                                      collections[collection_index].collections[layer], base->object);
 +                      }
 +
 +                      if (base->flag & SELECT) {
 +                              base->object->flag |= SELECT;
 +                      }
 +                      else {
 +                              base->object->flag &= ~SELECT;
 +                      }
 +              }
 +      }
 +
 +      /* Re-order the nested hidden collections. */
 +      CollectionChild *child_parent = collection_master->children.first;
 +      Collection *collection_parent = (child_parent) ? child_parent->collection : NULL;
 +
 +      for (int layer = 0; layer < 20; layer++) {
 +              if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
 +                      CollectionChild *hide_child = BLI_findptr(
 +                              &collection_parent->children,
 +                              collections[DO_VERSION_COLLECTION_HIDE].collections[layer],
 +                              offsetof(CollectionChild, collection));
 +
 +                      if ((collections[DO_VERSION_COLLECTION_HIDE].created & (1 << layer)) &&
 +                          (hide_child != collection_parent->children.first))
 +                      {
 +                              BLI_listbase_swaplinks(
 +                                      &collection_parent->children,
 +                                      hide_child,
 +                                      collection_parent->children.first);
 +                      }
 +
 +                      CollectionChild *hide_all_child = BLI_findptr(
 +                              &collection_parent->children,
 +                              collections[DO_VERSION_COLLECTION_HIDE_ALL].collections[layer],
 +                              offsetof(CollectionChild, collection));
 +
 +                      if ((collections[DO_VERSION_COLLECTION_HIDE_ALL].created & (1 << layer)) &&
 +                          (hide_all_child != collection_parent->children.last))
 +                      {
 +                              BLI_listbase_swaplinks(
 +                                      &collection_parent->children,
 +                                      hide_all_child,
 +                                      collection_parent->children.last);
 +                      }
 +
 +                      child_parent = child_parent->next;
 +                      collection_parent = (child_parent) ? child_parent->collection : NULL;
 +              }
 +      }
 +      BLI_assert(collection_parent == NULL);
 +
 +      /* Handle legacy render layers. */
 +      bool have_override = false;
 +
 +      for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
 +              ViewLayer *view_layer = BKE_view_layer_add(scene, srl->name);
 +
 +              if (srl->samples != 0) {
 +                      have_override = true;
 +
 +                      /* It is up to the external engine to handle
 +                       * its own doversion in this case. */
 +                      BKE_override_view_layer_int_add(
 +                              view_layer,
 +                              ID_SCE,
 +                              "samples",
 +                              srl->samples);
 +              }
 +
 +              if (srl->mat_override) {
 +                      have_override = true;
 +
 +                      BKE_override_view_layer_datablock_add(
 +                              view_layer,
 +                              ID_MA,
 +                              "self",
 +                              (ID *)srl->mat_override);
 +              }
 +
 +              if (srl->layflag & SCE_LAY_DISABLE) {
 +                      view_layer->flag &= ~VIEW_LAYER_RENDER;
 +              }
 +
 +              if ((srl->layflag & SCE_LAY_FRS) == 0) {
 +                      view_layer->flag &= ~VIEW_LAYER_FREESTYLE;
 +              }
 +
 +              /* XXX If we are to keep layflag it should be merged with flag (dfelinto). */
 +              view_layer->layflag = srl->layflag;
 +              /* XXX Not sure if we should keep the passes (dfelinto). */
 +              view_layer->passflag = srl->passflag;
 +              view_layer->pass_xor = srl->pass_xor;
 +              view_layer->pass_alpha_threshold = srl->pass_alpha_threshold;
 +
 +              BKE_freestyle_config_free(&view_layer->freestyle_config, true);
 +              view_layer->freestyle_config = srl->freestyleConfig;
 +              view_layer->id_properties = srl->prop;
 +
 +              /* Set exclusion and overrides. */
 +              for (int layer = 0; layer < 20; layer++) {
 +                      if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
 +                              Collection *collection = collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer];
 +                              LayerCollection *lc = BKE_layer_collection_first_from_scene_collection(view_layer, collection);
 +
 +                              if (srl->lay_exclude & (1 << layer)) {
 +                                      /* Disable excluded layer. */
 +                                      have_override = true;
 +                                      lc->flag |= LAYER_COLLECTION_EXCLUDE;
 +                                      for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) {
 +                                              nlc->flag |= LAYER_COLLECTION_EXCLUDE;
 +                                      }
 +                              }
 +                              else if ((scene->lay & srl->lay & ~(srl->lay_exclude) & (1 << layer)) ||
 +                                       (srl->lay_zmask & (scene->lay | srl->lay_exclude) & (1 << layer)))
 +                              {
 +                                      if (srl->lay_zmask & (1 << layer)) {
 +                                              have_override = true;
 +
 +                                              BKE_override_layer_collection_boolean_add(
 +                                                      lc,
 +                                                      ID_OB,
 +                                                      "cycles.is_holdout",
 +                                                      true);
 +                                      }
 +
 +                                      if ((srl->lay & (1 << layer)) == 0) {
 +                                              have_override = true;
 +
 +                                              BKE_override_layer_collection_boolean_add(
 +                                                      lc,
 +                                                      ID_OB,
 +                                                      "cycles_visibility.camera",
 +                                                      false);
 +                                      }
 +                              }
 +
 +                              LayerCollection *nlc = lc->layer_collections.first;
 +                              for (int j = 1; j < 4; j++) {
 +                                      if (collections[j].created & (1 << layer)) {
 +                                              nlc = nlc->next;
 +                                      }
 +                              }
 +                              BLI_assert(nlc == NULL);
 +                      }
 +              }
 +
 +              /* for convenience set the same active object in all the layers */
 +              if (scene->basact) {
 +                      view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
 +              }
 +
 +              for (Base *base = view_layer->object_bases.first; base; base = base->next) {
 +                      if ((base->flag & BASE_SELECTABLED) && (base->object->flag & SELECT)) {
 +                              base->flag |= BASE_SELECTED;
 +                      }
 +              }
 +      }
 +
 +      BLI_freelistN(&scene->r.layers);
 +
 +      /* If render layers included overrides, we also create a vanilla
 +       * viewport layer without them. */
 +      if (have_override) {
 +              ViewLayer *view_layer = BKE_view_layer_add(scene, "Viewport");
 +
 +              /* Make it first in the list. */
 +              BLI_remlink(&scene->view_layers, view_layer);
 +              BLI_addhead(&scene->view_layers, view_layer);
 +
 +              /* If we ported all the original render layers, we don't need to make the viewport layer renderable. */
 +              if (!BLI_listbase_is_single(&scene->view_layers)) {
 +                      view_layer->flag &= ~VIEW_LAYER_RENDER;
 +              }
 +
 +              /* convert active base */
 +              if (scene->basact) {
 +                      view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
 +              }
 +
 +              /* convert selected bases */
 +              for (Base *base = view_layer->object_bases.first; base; base = base->next) {
 +                      if ((base->flag & BASE_SELECTABLED) && (base->object->flag & SELECT)) {
 +                              base->flag |= BASE_SELECTED;
 +                      }
 +
 +                      /* keep lay around for forward compatibility (open those files in 2.79) */
 +                      base->lay = base->object->lay;
 +              }
 +      }
 +
 +      /* remove bases once and for all */
 +      for (Base *base = scene->base.first; base; base = base->next) {
 +              id_us_min(&base->object->id);
 +      }
 +
 +      BLI_freelistN(&scene->base);
 +      scene->basact = NULL;
 +}
 +
-       if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
++void do_versions_after_linking_280(Main *bmain)
 +{
 +      bool use_collection_compat_28 = true;
 +
-               for (Collection *collection = main->collection.first; collection; collection = collection->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
 +              use_collection_compat_28 = false;
 +
 +              /* Convert group layer visibility flags to hidden nested collection. */
-                                               collection_hidden = BKE_collection_add(main, collection, "Hidden");
++              for (Collection *collection = bmain->collection.first; collection; collection = collection->id.next) {
 +                      /* Add fake user for all existing groups. */
 +                      id_fake_user_set(&collection->id);
 +
 +                      if (collection->flag & (COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER)) {
 +                              continue;
 +                      }
 +
 +                      Collection *collection_hidden = NULL;
 +                      for (CollectionObject *cob = collection->gobject.first, *cob_next = NULL; cob; cob = cob_next) {
 +                              cob_next = cob->next;
 +                              Object *ob = cob->ob;
 +
 +                              if (!(ob->lay & collection->layer)) {
 +                                      if (collection_hidden == NULL) {
-                                       BKE_collection_object_add(main, collection_hidden, ob);
-                                       BKE_collection_object_remove(main, collection, ob, true);
++                                              collection_hidden = BKE_collection_add(bmain, collection, "Hidden");
 +                                              collection_hidden->id.lib = collection->id.lib;
 +                                              collection_hidden->flag |= COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
 +                                      }
 +
-               for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
-                       do_version_layers_to_collections(main, scene);
++                                      BKE_collection_object_add(bmain, collection_hidden, ob);
++                                      BKE_collection_object_remove(bmain, collection, ob, true);
 +                              }
 +                      }
 +              }
 +
 +              /* Convert layers to collections. */
-       if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
-               for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
++              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
++                      do_version_layers_to_collections(bmain, scene);
 +              }
 +      }
 +
-       if (!MAIN_VERSION_ATLEAST(main, 280, 1)) {
-               do_version_workspaces_after_lib_link(main);
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
++              for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                      /* same render-layer as do_version_workspaces_after_lib_link will activate,
 +                       * so same layer as BKE_view_layer_from_workspace_get would return */
 +                      ViewLayer *layer = screen->scene->view_layers.first;
 +
 +                      for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                              for (SpaceLink *space = sa->spacedata.first; space; space = space->next) {
 +                                      if (space->spacetype == SPACE_OUTLINER) {
 +                                              SpaceOops *soutliner = (SpaceOops *)space;
 +
 +                                              soutliner->outlinevis = SO_VIEW_LAYER;
 +
 +                                              if (BLI_listbase_count_at_most(&layer->layer_collections, 2) == 1) {
 +                                                      if (soutliner->treestore == NULL) {
 +                                                              soutliner->treestore = BLI_mempool_create(
 +                                                                      sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
 +                                                      }
 +
 +                                                      /* Create a tree store element for the collection. This is normally
 +                                                       * done in check_persistent (outliner_tree.c), but we need to access
 +                                                       * it here :/ (expand element if it's the only one) */
 +                                                      TreeStoreElem *tselem = BLI_mempool_calloc(soutliner->treestore);
 +                                                      tselem->type = TSE_LAYER_COLLECTION;
 +                                                      tselem->id = layer->layer_collections.first;
 +                                                      tselem->nr = tselem->used = 0;
 +                                                      tselem->flag &= ~TSE_CLOSED;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +
 +      /* New workspace design */
-       if (!MAIN_VERSION_ATLEAST(main, 280, 2)) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
++              do_version_workspaces_after_lib_link(bmain);
 +      }
 +
-               for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) {
 +              /* Cleanup any remaining SceneRenderLayer data for files that were created
 +               * with Blender 2.8 before the SceneRenderLayer > RenderLayer refactor. */
-       if (!MAIN_VERSION_ATLEAST(main, 280, 3)) {
++              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                      for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
 +                              if (srl->prop) {
 +                                      IDP_FreeProperty(srl->prop);
 +                                      MEM_freeN(srl->prop);
 +                              }
 +                              BKE_freestyle_config_free(&srl->freestyleConfig, true);
 +                      }
 +                      BLI_freelistN(&scene->r.layers);
 +              }
 +      }
 +
-               for (Object *object = main->object.first; object; object = object->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
 +              /* Due to several changes to particle RNA and draw code particles from older files may no longer
 +               * be visible. Here we correct this by setting a default draw size for those files. */
-       if (!MAIN_VERSION_ATLEAST(main, 280, 4)) {
-               for (Object *object = main->object.first; object; object = object->id.next) {
++              for (Object *object = bmain->object.first; object; object = object->id.next) {
 +                      for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
 +                              if (psys->part->draw_size == 0.0f) {
 +                                      psys->part->draw_size = 0.1f;
 +                              }
 +                      }
 +              }
 +      }
 +
-       if (!MAIN_VERSION_ATLEAST(main, 280, 9)) {
-               const wmWindowManager *wm = main->wm.first;
-               const Scene *scene = main->scene.first;
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 4)) {
++              for (Object *object = bmain->object.first; object; object = object->id.next) {
 +#ifndef VERSION_280_SUBVERSION_4
 +                      /* If any object already has an initialized value for
 +                       * duplicator_visibility_flag it means we've already doversioned it.
 +                       * TODO(all) remove the VERSION_280_SUBVERSION_4 code once the subversion was bumped. */
 +                      if (object->duplicator_visibility_flag != 0) {
 +                              break;
 +                      }
 +#endif
 +                      if (object->particlesystem.first) {
 +                              object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
 +                              for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
 +                                      if (psys->part->draw & PART_DRAW_EMITTER) {
 +                                              object->duplicator_visibility_flag |= OB_DUPLI_FLAG_RENDER;
 +#ifndef VERSION_280_SUBVERSION_4
 +                                              psys->part->draw &= ~PART_DRAW_EMITTER;
 +#else
 +                                              break;
 +#endif
 +                                      }
 +                              }
 +                      }
 +                      else if (object->transflag & OB_DUPLI) {
 +                              object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
 +                      }
 +                      else {
 +                              object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER;
 +                      }
 +              }
 +      }
 +
 +      /* SpaceTime & SpaceLogic removal/replacing */
-                       for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 9)) {
++              const wmWindowManager *wm = bmain->wm.first;
++              const Scene *scene = bmain->scene.first;
 +
 +              if (wm != NULL) {
 +                      /* Action editors need a scene for creation. First, update active
 +                       * screens using the active scene of the window they're displayed in.
 +                       * Next, update remaining screens using first scene in main listbase. */
 +
 +                      for (wmWindow *win = wm->windows.first; win; win = win->next) {
 +                              const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
 +                              for (ScrArea *area = screen->areabase.first; area; area = area->next) {
 +                                      if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
 +                                              do_version_area_change_space_to_space_action(area, win->scene);
 +
 +                                              /* Don't forget to unset! */
 +                                              area->butspacetype = SPACE_EMPTY;
 +                                      }
 +                              }
 +                      }
 +              }
 +              if (scene != NULL) {
-       if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(main, 280, 14)) {
-               for (Collection *group = main->collection.first; group; group = group->id.next) {
-                       do_version_group_collection_to_collection(main, group);
++                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *area = screen->areabase.first; area; area = area->next) {
 +                                      if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
 +                                              /* Areas that were already handled won't be handled again */
 +                                              do_version_area_change_space_to_space_action(area, scene);
 +
 +                                              /* Don't forget to unset! */
 +                                              area->butspacetype = SPACE_EMPTY;
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +
 +#ifdef USE_COLLECTION_COMPAT_28
-               for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
-                       do_version_scene_collection_to_collection(main, scene);
++      if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 14)) {
++              for (Collection *group = bmain->collection.first; group; group = group->id.next) {
++                      do_version_group_collection_to_collection(bmain, group);
 +              }
 +
- void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
++              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
++                      do_version_scene_collection_to_collection(bmain, scene);
 +              }
 +      }
 +#endif
 +}
 +
-       if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
++void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 +{
 +      bool use_collection_compat_28 = true;
 +
-               for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
 +              use_collection_compat_28 = false;
 +
-       if (!MAIN_VERSION_ATLEAST(main, 280, 1)) {
++              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                      scene->r.gauss = 1.5f;
 +              }
 +      }
 +
-                       for (Lamp *la = main->lamp.first; la; la = la->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
 +              if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "bleedexp")) {
-                       for (Camera *ca = main->camera.first; ca; ca = ca->id.next) {
++                      for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
 +                              la->bleedexp = 2.5f;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "GPUDOFSettings", "float", "ratio")) {
-                       for (Mesh *me = main->mesh.first; me; me = me->id.next) {
++                      for (Camera *ca = bmain->camera.first; ca; ca = ca->id.next) {
 +                              ca->gpu_dof.ratio = 1.0f;
 +                      }
 +              }
 +
 +              /* MTexPoly now removed. */
 +              if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
 +                      const int cd_mtexpoly = 15;  /* CD_MTEXPOLY, deprecated */
-       if (!MAIN_VERSION_ATLEAST(main, 280, 2)) {
++                      for (Mesh *me = bmain->mesh.first; me; me = me->id.next) {
 +                              /* If we have UV's, so this file will have MTexPoly layers too! */
 +                              if (me->mloopuv != NULL) {
 +                                      CustomData_update_typemap(&me->pdata);
 +                                      CustomData_free_layers(&me->pdata, cd_mtexpoly, me->totpoly);
 +                                      BKE_mesh_update_customdata_pointers(me, false);
 +                              }
 +                      }
 +              }
 +      }
 +
-                       for (Lamp *la = main->lamp.first; la; la = la->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 2)) {
 +              if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "cascade_max_dist")) {
-                       for (Lamp *la = main->lamp.first; la; la = la->id.next) {
++                      for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
 +                              la->cascade_max_dist = 1000.0f;
 +                              la->cascade_count = 4;
 +                              la->cascade_exponent = 0.8f;
 +                              la->cascade_fade = 0.1f;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "contact_dist")) {
-                       for (LightProbe *probe = main->lightprobe.first; probe; probe = probe->id.next) {
++                      for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
 +                              la->contact_dist = 1.0f;
 +                              la->contact_bias = 0.03f;
 +                              la->contact_spread = 0.2f;
 +                              la->contact_thickness = 0.5f;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "vis_bias")) {
-               FOREACH_NODETREE(main, ntree, id) {
++                      for (LightProbe *probe = bmain->lightprobe.first; probe; probe = probe->id.next) {
 +                              probe->vis_bias = 1.0f;
 +                              probe->vis_blur = 0.2f;
 +                      }
 +              }
 +
 +              typedef enum eNTreeDoVersionErrors {
 +                      NTREE_DOVERSION_NO_ERROR = 0,
 +                      NTREE_DOVERSION_NEED_OUTPUT = (1 << 0),
 +                      NTREE_DOVERSION_TRANSPARENCY_EMISSION = (1 << 1),
 +              } eNTreeDoVersionErrors;
 +
 +              /* Eevee shader nodes renamed because of the output node system.
 +               * Note that a new output node is not being added here, because it would be overkill
 +               * to handle this case in lib_verify_nodetree.
 +               *
 +               * Also, metallic node is now unified into the principled node. */
 +              eNTreeDoVersionErrors error = NTREE_DOVERSION_NO_ERROR;
 +
-                       for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++              FOREACH_NODETREE(bmain, ntree, id) {
 +                      if (ntree->type == NTREE_SHADER) {
 +                              for (bNode *node = ntree->nodes.first; node; node = node->next) {
 +                                      if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
 +                                          STREQ(node->idname, "ShaderNodeOutputMetallic"))
 +                                      {
 +                                              BLI_strncpy(node->idname, "ShaderNodeEeveeMetallic", sizeof(node->idname));
 +                                              error |= NTREE_DOVERSION_NEED_OUTPUT;
 +                                      }
 +
 +                                      else if (node->type == SH_NODE_EEVEE_SPECULAR && STREQ(node->idname, "ShaderNodeOutputSpecular")) {
 +                                              BLI_strncpy(node->idname, "ShaderNodeEeveeSpecular", sizeof(node->idname));
 +                                              error |= NTREE_DOVERSION_NEED_OUTPUT;
 +                                      }
 +
 +                                      else if (node->type == 196 /* SH_NODE_OUTPUT_EEVEE_MATERIAL */ &&
 +                                               STREQ(node->idname, "ShaderNodeOutputEeveeMaterial"))
 +                                      {
 +                                              node->type = SH_NODE_OUTPUT_MATERIAL;
 +                                              BLI_strncpy(node->idname, "ShaderNodeOutputMaterial", sizeof(node->idname));
 +                                      }
 +
 +                                      else if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
 +                                               STREQ(node->idname, "ShaderNodeEeveeMetallic"))
 +                                      {
 +                                              node->type = SH_NODE_BSDF_PRINCIPLED;
 +                                              BLI_strncpy(node->idname, "ShaderNodeBsdfPrincipled", sizeof(node->idname));
 +                                              node->custom1 = SHD_GLOSSY_MULTI_GGX;
 +                                              error |= NTREE_DOVERSION_TRANSPARENCY_EMISSION;
 +                                      }
 +                              }
 +                      }
 +              } FOREACH_NODETREE_END
 +
 +              if (error & NTREE_DOVERSION_NEED_OUTPUT) {
 +                      BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
 +                      printf("You need to connect Principled and Eevee Specular shader nodes to new material output nodes.\n");
 +              }
 +
 +              if (error & NTREE_DOVERSION_TRANSPARENCY_EMISSION) {
 +                      BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
 +                      printf("You need to combine transparency and emission shaders to the converted Principled shader nodes.\n");
 +              }
 +
 +#ifdef USE_COLLECTION_COMPAT_28
 +              if (use_collection_compat_28 &&
 +                  (DNA_struct_elem_find(fd->filesdna, "ViewLayer", "FreestyleConfig", "freestyle_config") == false) &&
 +                  DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers"))
 +              {
-       if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(main, 280, 3)) {
-               for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              ViewLayer *view_layer;
 +                              for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
 +                                      view_layer->flag |= VIEW_LAYER_FREESTYLE;
 +                                      view_layer->layflag = 0x7FFF;   /* solid ztra halo edge strand */
 +                                      view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
 +                                      view_layer->pass_alpha_threshold = 0.5f;
 +                                      BKE_freestyle_config_init(&view_layer->freestyle_config);
 +                              }
 +                      }
 +              }
 +#endif
 +      }
 +
 +#ifdef USE_COLLECTION_COMPAT_28
-               for (Collection *group = main->collection.first; group; group = group->id.next) {
++      if (use_collection_compat_28 && !MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
++              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                      ViewLayer *view_layer;
 +                      for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
 +                              do_version_view_layer_visibility(view_layer);
 +                      }
 +              }
 +
-       if (!MAIN_VERSION_ATLEAST(main, 280, 6)) {
++              for (Collection *group = bmain->collection.first; group; group = group->id.next) {
 +                      if (group->view_layer != NULL) {
 +                              do_version_view_layer_visibility(group->view_layer);
 +                      }
 +              }
 +      }
 +#endif
 +
-                       for (sc = main->screen.first; sc; sc = sc->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 6)) {
 +              if (DNA_struct_elem_find(fd->filesdna, "SpaceOops", "int", "filter") == false) {
 +                      bScreen *sc;
 +                      ScrArea *sa;
 +                      SpaceLink *sl;
 +
 +                      /* Update files using invalid (outdated) outlinevis Outliner values. */
-                       for (LightProbe *probe = main->lightprobe.first; probe; probe = probe->id.next) {
++                      for (sc = bmain->screen.first; sc; sc = sc->id.next) {
 +                              for (sa = sc->areabase.first; sa; sa = sa->next) {
 +                                      for (sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_OUTLINER) {
 +                                                      SpaceOops *so = (SpaceOops *)sl;
 +
 +                                                      if (!ELEM(so->outlinevis,
 +                                                                SO_SCENES,
 +                                                                SO_LIBRARIES,
 +                                                                SO_SEQUENCE,
 +                                                                SO_DATA_API,
 +                                                                SO_ID_ORPHANS))
 +                                                      {
 +                                                              so->outlinevis = SO_VIEW_LAYER;
 +                                                      }
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "intensity")) {
-               for (Object *ob = main->object.first; ob; ob = ob->id.next) {
++                      for (LightProbe *probe = bmain->lightprobe.first; probe; probe = probe->id.next) {
 +                              probe->intensity = 1.0f;
 +                      }
 +              }
 +
-                       for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++              for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
 +                      bConstraint *con, *con_next;
 +                      con = ob->constraints.first;
 +                      while (con) {
 +                              con_next = con->next;
 +                              if (con->type == 17) { /* CONSTRAINT_TYPE_RIGIDBODYJOINT */
 +                                      BLI_remlink(&ob->constraints, con);
 +                                      BKE_constraint_free_data(con);
 +                                      MEM_freeN(con);
 +                              }
 +                              con = con_next;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "Scene", "int", "orientation_index_custom")) {
-               for (bScreen *sc = main->screen.first; sc; sc = sc->id.next) {
++                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              scene->orientation_index_custom = -1;
 +                      }
 +              }
 +
-                                               if (MAIN_VERSION_ATLEAST(main, 280, 0)) {
++              for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
 +                      for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
 +                              for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                      if (sl->spacetype == SPACE_VIEW3D) {
 +                                              View3D *v3d = (View3D *)sl;
 +                                              v3d->shading.light = V3D_LIGHTING_STUDIO;
 +                                              v3d->shading.flag |= V3D_SHADING_OBJECT_OUTLINE;
 +
 +                                              /* Assume (demo) files written with 2.8 want to show
 +                                               * Eevee renders in the viewport. */
-       if (!MAIN_VERSION_ATLEAST(main, 280, 7)) {
++                                              if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
 +                                                      v3d->drawtype = OB_MATERIAL;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +
-               if (MAIN_VERSION_ATLEAST(main, 280, 0)) {
-                       for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 7)) {
 +              /* Render engine storage moved elsewhere and back during 2.8
 +               * development, we assume any files saved in 2.8 had Eevee set
 +               * as scene render engine. */
-       if (!MAIN_VERSION_ATLEAST(main, 280, 8)) {
++              if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
++                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
 +                      }
 +              }
 +      }
 +
-               for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 8)) {
 +              /* Blender Internal removal */
-               for (Tex *tex = main->tex.first; tex; tex = tex->id.next) {
++              for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                      if (STREQ(scene->r.engine, "BLENDER_RENDER") ||
 +                          STREQ(scene->r.engine, "BLENDER_GAME"))
 +                      {
 +                              BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
 +                      }
 +
 +                      scene->r.bake_mode = 0;
 +              }
 +
-       if (!MAIN_VERSION_ATLEAST(main, 280, 11)) {
++              for (Tex *tex = bmain->tex.first; tex; tex = tex->id.next) {
 +                      /* Removed envmap, pointdensity, voxeldata, ocean textures. */
 +                      if (ELEM(tex->type, 10, 14, 15, 16)) {
 +                              tex->type = 0;
 +                      }
 +              }
 +      }
 +
-               for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) {
 +
 +              /* Remove info editor, but only if at the top of the window. */
-       if (!MAIN_VERSION_ATLEAST(main, 280, 11)) {
-               for (Lamp *lamp = main->lamp.first; lamp; lamp = lamp->id.next) {
++              for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                      /* Calculate window width/height from screen vertices */
 +                      int win_width = 0, win_height = 0;
 +                      for (ScrVert *vert = screen->vertbase.first; vert; vert = vert->next) {
 +                              win_width  = MAX2(win_width, vert->vec.x);
 +                              win_height = MAX2(win_height, vert->vec.y);
 +                      }
 +
 +                      for (ScrArea *area = screen->areabase.first, *area_next; area; area = area_next) {
 +                              area_next = area->next;
 +
 +                              if (area->spacetype == SPACE_INFO) {
 +                                      if ((area->v2->vec.y == win_height) && (area->v1->vec.x == 0) && (area->v4->vec.x == win_width)) {
 +                                              BKE_screen_area_free(area);
 +
 +                                              BLI_remlink(&screen->areabase, area);
 +
 +                                              BKE_screen_remove_double_scredges(screen);
 +                                              BKE_screen_remove_unused_scredges(screen);
 +                                              BKE_screen_remove_unused_scrverts(screen);
 +
 +                                              MEM_freeN(area);
 +                                      }
 +                              }
 +                              /* AREA_TEMP_INFO is deprecated from now on, it should only be set for info areas
 +                               * which are deleted above, so don't need to unset it. Its slot/bit can be reused */
 +                      }
 +              }
 +      }
 +
-       if (!MAIN_VERSION_ATLEAST(main, 280, 12)) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 11)) {
++              for (Lamp *lamp = bmain->lamp.first; lamp; lamp = lamp->id.next) {
 +                      if (lamp->mode & (1 << 13)) { /* LA_SHAD_RAY */
 +                              lamp->mode |= LA_SHADOW;
 +                              lamp->mode &= ~(1 << 13);
 +                      }
 +              }
 +      }
 +
-               for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 12)) {
 +              /* Remove tool property regions. */
-       if (!MAIN_VERSION_ATLEAST(main, 280, 13)) {
++              for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                      for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                              for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                      if (ELEM(sl->spacetype, SPACE_VIEW3D, SPACE_CLIP)) {
 +                                              ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
 +
 +                                              for (ARegion *region = regionbase->first, *region_next; region; region = region_next) {
 +                                                      region_next = region->next;
 +
 +                                                      if (region->regiontype == RGN_TYPE_TOOL_PROPS) {
 +                                                              BKE_area_region_free(NULL, region);
 +                                                              BLI_freelinkN(regionbase, region);
 +                                                      }
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +
-                       for (Lamp *la = main->lamp.first; la; la = la->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 13)) {
 +              /* Initialize specular factor. */
 +              if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "spec_fac")) {
-               for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
++                      for (Lamp *la = bmain->lamp.first; la; la = la->id.next) {
 +                              la->spec_fac = 1.0f;
 +                      }
 +              }
 +
 +              /* Initialize new view3D options. */
-                       for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++              for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                      for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                              for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                      if (sl->spacetype == SPACE_VIEW3D) {
 +                                              View3D *v3d = (View3D *)sl;
 +                                              v3d->shading.light = V3D_LIGHTING_STUDIO;
 +                                              v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR;
 +                                              copy_v3_fl(v3d->shading.single_color, 0.8f);
 +                                              v3d->shading.shadow_intensity = 0.5;
 +
 +                                              v3d->overlay.backwire_opacity = 0.5f;
 +                                              v3d->overlay.normals_length = 0.1f;
 +                                              v3d->overlay.flag = V3D_OVERLAY_LOOK_DEV;
 +                                      }
 +                              }
 +                      }
 +              }
 +
 +              if (!DNA_struct_find(fd->filesdna, "View3DCursor")) {
-                       for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
++                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              unit_qt(scene->cursor.rotation);
 +                      }
-       if (!MAIN_VERSION_ATLEAST(main, 280, 14)) {
++                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_VIEW3D) {
 +                                                      View3D *v3d = (View3D *)sl;
 +                                                      unit_qt(v3d->cursor.rotation);
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +
-                       for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++      if (!MAIN_VERSION_ATLEAST(bmain, 280, 14)) {
 +              if (!DNA_struct_elem_find(fd->filesdna, "Scene", "SceneDisplay", "display")) {
 +                      /* Initialize new scene.SceneDisplay */
-                       for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              copy_v3_v3(scene->display.light_direction, (float[3]){-M_SQRT1_3, -M_SQRT1_3, M_SQRT1_3});
 +                      }
 +              }
 +              if (!DNA_struct_elem_find(fd->filesdna, "SceneDisplay", "float", "shadow_shift")) {
-                       for (Object *ob = main->object.first; ob; ob = ob->id.next) {
++                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              scene->display.shadow_shift = 0.1;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "Object", "ObjectDisplay", "display")) {
 +                      /* Initialize new object.ObjectDisplay */
-                       for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++                      for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
 +                              ob->display.flag = OB_SHOW_SHADOW;
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "transform_pivot_point")) {
-                       for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              scene->toolsettings->transform_pivot_point = V3D_AROUND_CENTER_MEAN;
 +                      }
 +              }
 +
 +              if (!DNA_struct_find(fd->filesdna, "SceneEEVEE")) {
-               if (!MAIN_VERSION_ATLEAST(main, 280, 15)) {
-                       for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              /* First set the default for all the properties. */
 +
 +                              scene->eevee.gi_diffuse_bounces = 3;
 +                              scene->eevee.gi_cubemap_resolution = 512;
 +                              scene->eevee.gi_visibility_resolution = 32;
 +
 +                              scene->eevee.taa_samples = 16;
 +                              scene->eevee.taa_render_samples = 64;
 +
 +                              scene->eevee.sss_samples = 7;
 +                              scene->eevee.sss_jitter_threshold = 0.3f;
 +
 +                              scene->eevee.ssr_quality = 0.25f;
 +                              scene->eevee.ssr_max_roughness = 0.5f;
 +                              scene->eevee.ssr_thickness = 0.2f;
 +                              scene->eevee.ssr_border_fade = 0.075f;
 +                              scene->eevee.ssr_firefly_fac = 10.0f;
 +
 +                              scene->eevee.volumetric_start = 0.1f;
 +                              scene->eevee.volumetric_end = 100.0f;
 +                              scene->eevee.volumetric_tile_size = 8;
 +                              scene->eevee.volumetric_samples = 64;
 +                              scene->eevee.volumetric_sample_distribution = 0.8f;
 +                              scene->eevee.volumetric_light_clamp = 0.0f;
 +                              scene->eevee.volumetric_shadow_samples = 16;
 +
 +                              scene->eevee.gtao_distance = 0.2f;
 +                              scene->eevee.gtao_factor = 1.0f;
 +                              scene->eevee.gtao_quality = 0.25f;
 +
 +                              scene->eevee.bokeh_max_size = 100.0f;
 +                              scene->eevee.bokeh_threshold = 1.0f;
 +
 +                              copy_v3_fl(scene->eevee.bloom_color, 1.0f);
 +                              scene->eevee.bloom_threshold = 0.8f;
 +                              scene->eevee.bloom_knee = 0.5f;
 +                              scene->eevee.bloom_intensity = 0.8f;
 +                              scene->eevee.bloom_radius = 6.5f;
 +                              scene->eevee.bloom_clamp = 1.0f;
 +
 +                              scene->eevee.motion_blur_samples = 8;
 +                              scene->eevee.motion_blur_shutter = 1.0f;
 +
 +                              scene->eevee.shadow_method = SHADOW_ESM;
 +                              scene->eevee.shadow_cube_size = 512;
 +                              scene->eevee.shadow_cascade_size = 1024;
 +
 +                              scene->eevee.flag =
 +                                      SCE_EEVEE_VOLUMETRIC_LIGHTS |
 +                                      SCE_EEVEE_VOLUMETRIC_COLORED |
 +                                      SCE_EEVEE_GTAO_BENT_NORMALS |
 +                                      SCE_EEVEE_GTAO_BOUNCE |
 +                                      SCE_EEVEE_TAA_REPROJECTION |
 +                                      SCE_EEVEE_SSR_HALF_RESOLUTION;
 +
 +
 +                              /* If the file is pre-2.80 move on. */
 +                              if (scene->layer_properties == NULL) {
 +                                      continue;
 +                              }
 +
 +                              /* Now we handle eventual properties that may be set in the file. */
 +#define EEVEE_GET_BOOL(_props, _name, _flag) \
 +                              { \
 +                                      IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
 +                                      if (_idprop != NULL) { \
 +                                              const int _value = IDP_Int(_idprop); \
 +                                              if (_value) { \
 +                                                      scene->eevee.flag |= _flag; \
 +                                              } \
 +                                              else { \
 +                                                      scene->eevee.flag &= ~_flag; \
 +                                              } \
 +                                      } \
 +                              }
 +
 +#define EEVEE_GET_INT(_props, _name) \
 +                              { \
 +                                      IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
 +                                      if (_idprop != NULL) { \
 +                                              scene->eevee._name = IDP_Int(_idprop); \
 +                                      } \
 +                              }
 +
 +#define EEVEE_GET_FLOAT(_props, _name) \
 +                              { \
 +                                      IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
 +                                      if (_idprop != NULL) { \
 +                                              scene->eevee._name = IDP_Float(_idprop); \
 +                                      } \
 +                              }
 +
 +#define EEVEE_GET_FLOAT_ARRAY(_props, _name, _length) \
 +                              { \
 +                                      IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
 +                                      if (_idprop != NULL) { \
 +                                              const float *_values = IDP_Array(_idprop); \
 +                                              for (int _i = 0; _i < _length; _i++) { \
 +                                                      scene->eevee._name [_i] = _values[_i]; \
 +                                              } \
 +                                      } \
 +                              }
 +
 +                              IDProperty *props = IDP_GetPropertyFromGroup(scene->layer_properties, RE_engine_id_BLENDER_EEVEE);
 +                              EEVEE_GET_BOOL(props, volumetric_enable, SCE_EEVEE_VOLUMETRIC_ENABLED);
 +                              EEVEE_GET_BOOL(props, volumetric_lights, SCE_EEVEE_VOLUMETRIC_LIGHTS);
 +                              EEVEE_GET_BOOL(props, volumetric_shadows, SCE_EEVEE_VOLUMETRIC_SHADOWS);
 +                              EEVEE_GET_BOOL(props, volumetric_colored_transmittance, SCE_EEVEE_VOLUMETRIC_COLORED);
 +                              EEVEE_GET_BOOL(props, gtao_enable, SCE_EEVEE_GTAO_ENABLED);
 +                              EEVEE_GET_BOOL(props, gtao_use_bent_normals, SCE_EEVEE_GTAO_BENT_NORMALS);
 +                              EEVEE_GET_BOOL(props, gtao_bounce, SCE_EEVEE_GTAO_BOUNCE);
 +                              EEVEE_GET_BOOL(props, dof_enable, SCE_EEVEE_DOF_ENABLED);
 +                              EEVEE_GET_BOOL(props, bloom_enable, SCE_EEVEE_BLOOM_ENABLED);
 +                              EEVEE_GET_BOOL(props, motion_blur_enable, SCE_EEVEE_MOTION_BLUR_ENABLED);
 +                              EEVEE_GET_BOOL(props, shadow_high_bitdepth, SCE_EEVEE_SHADOW_HIGH_BITDEPTH);
 +                              EEVEE_GET_BOOL(props, taa_reprojection, SCE_EEVEE_TAA_REPROJECTION);
 +                              EEVEE_GET_BOOL(props, sss_enable, SCE_EEVEE_SSS_ENABLED);
 +                              EEVEE_GET_BOOL(props, sss_separate_albedo, SCE_EEVEE_SSS_SEPARATE_ALBEDO);
 +                              EEVEE_GET_BOOL(props, ssr_enable, SCE_EEVEE_SSR_ENABLED);
 +                              EEVEE_GET_BOOL(props, ssr_refraction, SCE_EEVEE_SSR_REFRACTION);
 +                              EEVEE_GET_BOOL(props, ssr_halfres, SCE_EEVEE_SSR_HALF_RESOLUTION);
 +
 +                              EEVEE_GET_INT(props, gi_diffuse_bounces);
 +                              EEVEE_GET_INT(props, gi_diffuse_bounces);
 +                              EEVEE_GET_INT(props, gi_cubemap_resolution);
 +                              EEVEE_GET_INT(props, gi_visibility_resolution);
 +
 +                              EEVEE_GET_INT(props, taa_samples);
 +                              EEVEE_GET_INT(props, taa_render_samples);
 +
 +                              EEVEE_GET_INT(props, sss_samples);
 +                              EEVEE_GET_FLOAT(props, sss_jitter_threshold);
 +
 +                              EEVEE_GET_FLOAT(props, ssr_quality);
 +                              EEVEE_GET_FLOAT(props, ssr_max_roughness);
 +                              EEVEE_GET_FLOAT(props, ssr_thickness);
 +                              EEVEE_GET_FLOAT(props, ssr_border_fade);
 +                              EEVEE_GET_FLOAT(props, ssr_firefly_fac);
 +
 +                              EEVEE_GET_FLOAT(props, volumetric_start);
 +                              EEVEE_GET_FLOAT(props, volumetric_end);
 +                              EEVEE_GET_INT(props, volumetric_tile_size);
 +                              EEVEE_GET_INT(props, volumetric_samples);
 +                              EEVEE_GET_FLOAT(props, volumetric_sample_distribution);
 +                              EEVEE_GET_FLOAT(props, volumetric_light_clamp);
 +                              EEVEE_GET_INT(props, volumetric_shadow_samples);
 +
 +                              EEVEE_GET_FLOAT(props, gtao_distance);
 +                              EEVEE_GET_FLOAT(props, gtao_factor);
 +                              EEVEE_GET_FLOAT(props, gtao_quality);
 +
 +                              EEVEE_GET_FLOAT(props, bokeh_max_size);
 +                              EEVEE_GET_FLOAT(props, bokeh_threshold);
 +
 +                              EEVEE_GET_FLOAT_ARRAY(props, bloom_color, 3);
 +                              EEVEE_GET_FLOAT(props, bloom_threshold);
 +                              EEVEE_GET_FLOAT(props, bloom_knee);
 +                              EEVEE_GET_FLOAT(props, bloom_intensity);
 +                              EEVEE_GET_FLOAT(props, bloom_radius);
 +                              EEVEE_GET_FLOAT(props, bloom_clamp);
 +
 +                              EEVEE_GET_INT(props, motion_blur_samples);
 +                              EEVEE_GET_FLOAT(props, motion_blur_shutter);
 +
 +                              EEVEE_GET_INT(props, shadow_method);
 +                              EEVEE_GET_INT(props, shadow_cube_size);
 +                              EEVEE_GET_INT(props, shadow_cascade_size);
 +
 +                              /* Cleanup. */
 +                              IDP_FreeProperty(scene->layer_properties);
 +                              MEM_freeN(scene->layer_properties);
 +                              scene->layer_properties = NULL;
 +
 +#undef EEVEE_GET_FLOAT_ARRAY
 +#undef EEVEE_GET_FLOAT
 +#undef EEVEE_GET_INT
 +#undef EEVEE_GET_BOOL
 +                      }
 +              }
 +
 +
-                       for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
++              if (!MAIN_VERSION_ATLEAST(bmain, 280, 15)) {
++                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              scene->display.matcap_icon = 1;
 +                              scene->display.matcap_type = CLAY_MATCAP_NONE;
 +                              scene->display.matcap_hue = 0.5f;
 +                              scene->display.matcap_saturation = 0.5f;
 +                              scene->display.matcap_value = 0.5f;
 +                              scene->display.matcap_ssao_distance = 0.2f;
 +                              scene->display.matcap_ssao_attenuation = 1.0f;
 +                              scene->display.matcap_ssao_factor_cavity = 1.0f;
 +                              scene->display.matcap_ssao_factor_edge = 1.0f;
 +                              scene->display.matcap_ssao_samples = 16;
 +                      }
 +
-                       for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
++                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_OUTLINER) {
 +                                                      SpaceOops *soops = (SpaceOops *)sl;
 +                                                      soops->filter_id_type = ID_GR;
 +                                                      soops->outlinevis = SO_VIEW_LAYER;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +
-                       for (part = main->particle.first; part; part = part->id.next) {
++                      for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
 +                              switch (scene->toolsettings->snap_mode) {
 +                                      case 0: scene->toolsettings->snap_mode = SCE_SNAP_MODE_INCREMENT; break;
 +                                      case 1: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VERTEX   ; break;
 +                                      case 2: scene->toolsettings->snap_mode = SCE_SNAP_MODE_EDGE     ; break;
 +                                      case 3: scene->toolsettings->snap_mode = SCE_SNAP_MODE_FACE     ; break;
 +                                      case 4: scene->toolsettings->snap_mode = SCE_SNAP_MODE_VOLUME   ; break;
 +                              }
 +                              switch (scene->toolsettings->snap_node_mode) {
 +                                      case 5: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X; break;
 +                                      case 6: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_Y; break;
 +                                      case 7: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_NODE_X | SCE_SNAP_MODE_NODE_Y; break;
 +                                      case 8: scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID  ; break;
 +                              }
 +                              switch (scene->toolsettings->snap_uv_mode) {
 +                                      case 0: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_INCREMENT; break;
 +                                      case 1: scene->toolsettings->snap_uv_mode = SCE_SNAP_MODE_VERTEX   ; break;
 +                              }
 +                      }
 +
 +                      ParticleSettings *part;
-                       for (Material *mat = main->mat.first; mat; mat = mat->id.next) {
++                      for (part = bmain->particle.first; part; part = part->id.next) {
 +                              part->shape_flag = PART_SHAPE_CLOSE_TIP;
 +                              part->shape = 0.0f;
 +                              part->rad_root = 1.0f;
 +                              part->rad_tip = 0.0f;
 +                              part->rad_scale = 0.01f;
 +                      }
 +              }
 +
 +      }
 +      {
 +              if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "roughness")) {
-                                       if (MAIN_VERSION_ATLEAST(main, 280, 0)) {
++                      for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) {
 +                              if (mat->use_nodes) {
-                       for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
++                                      if (MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
 +                                              mat->roughness = mat->gloss_mir;
 +                                      }
 +                                      else {
 +                                              mat->roughness = 0.25f;
 +                                      }
 +                              }
 +                              else {
 +                                      mat->roughness = 1.0f - mat->gloss_mir;
 +                              }
 +                              mat->metallic = mat->ray_mirror;
 +                      }
 +
-                       for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
++                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_VIEW3D) {
 +                                                      View3D *v3d = (View3D *)sl;
 +                                                      v3d->shading.flag |= V3D_SHADING_SPECULAR_HIGHLIGHT;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +
 +              if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "xray_alpha")) {
-                               for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
++                      for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                              if (sl->spacetype == SPACE_VIEW3D) {
 +                                                      View3D *v3d = (View3D *)sl;
 +                                                      v3d->shading.xray_alpha = 0.5f;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +              if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "char", "matcap[256]")) {
 +                      StudioLight *default_matcap = BKE_studiolight_find_first(STUDIOLIGHT_ORIENTATION_VIEWNORMAL);
 +                      /* when loading the internal file is loaded before the matcaps */
 +                      if (default_matcap) {
++                              for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
 +                                      for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                                              for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
 +                                                      if (sl->spacetype == SPACE_VIEW3D) {
 +                                                              View3D *v3d = (View3D *)sl;
 +                                                              BLI_strncpy(v3d->shading.matcap, default_matcap->name, FILE_MAXFILE);
 +                                                      }
 +                                              }
 +                                      }
 +                              }
 +                      }
 +              }
 +      }
 +}
@@@ -519,9 -617,18 +519,9 @@@ void blo_do_versions_pre250(FileData *f
                }
        }
  
-       if (main->versionfile <= 103) {
 -      if (bmain->versionfile <= 102) {
 -              /* init halo's at 1.0 */
 -              Material *ma = bmain->mat.first;
 -              while (ma) {
 -                      ma->add = 1.0;
 -                      ma = ma->id.next;
 -              }
 -      }
 -
+       if (bmain->versionfile <= 103) {
                /* new variable in object: colbits */
-               Object *ob = main->object.first;
+               Object *ob = bmain->object.first;
                int a;
                while (ob) {
                        ob->colbits = 0;
  
        }
  
-       if (main->versionfile <= 107) {
+       if (bmain->versionfile <= 107) {
                Object *ob;
-               ob = main->object.first;
 -              Scene *sce = bmain->scene.first;
 -              while (sce) {
 -                      sce->r.mode |= R_GAMMA;
 -                      sce = sce->id.next;
 -              }
+               ob = bmain->object.first;
                while (ob) {
                        if (ob->dt == 0)
                                ob->dt = OB_SOLID;
                }
        }
  
-       if (main->versionfile <= 134) {
-               Tex *tex = main->tex.first;
 -      if (bmain->versionfile <= 113) {
 -              Material *ma = bmain->mat.first;
 -              while (ma) {
 -                      if (ma->flaresize == 0.0f)
 -                              ma->flaresize = 1.0f;
 -                      ma->subsize = 1.0f;
 -                      ma->flareboost = 1.0f;
 -                      ma = ma->id.next;
 -              }
 -      }
 -
+       if (bmain->versionfile <= 134) {
+               Tex *tex = bmain->tex.first;
                while (tex) {
                        if ((tex->rfac == 0.0f) &&
                                (tex->gfac == 0.0f) &&
                }
        }
  
-       if (main->versionfile <= 204) {
 -      if (bmain->versionfile <= 191) {
 -              Object *ob = bmain->object.first;
 -              Material *ma = bmain->mat.first;
 -
 -              /* let faces have default add factor of 0.0 */
 -              while (ma) {
 -                      if (!(ma->mode & MA_HALO))
 -                              ma->add = 0.0;
 -                      ma = ma->id.next;
 -              }
 -
 -              while (ob) {
 -                      ob->mass = 1.0f;
 -                      ob->damping = 0.1f;
 -                      /*ob->quat[1] = 1.0f;*/ /* quats arnt used yet */
 -                      ob = ob->id.next;
 -              }
 -      }
 -
 -      if (bmain->versionfile <= 193) {
 -              Object *ob = bmain->object.first;
 -              while (ob) {
 -                      ob->inertia = 1.0f;
 -                      ob->rdamping = 0.1f;
 -                      ob = ob->id.next;
 -              }
 -      }
 -
 -      if (bmain->versionfile <= 196) {
 -              Mesh *me = bmain->mesh.first;
 -              int a, b;
 -              while (me) {
 -                      if (me->tface) {
 -                              TFace *tface = me->tface;
 -                              for (a = 0; a < me->totface; a++, tface++) {
 -                                      for (b = 0; b < 4; b++) {
 -                                              tface->mode |= TF_DYNAMIC;
 -                                              tface->mode &= ~TF_INVISIBLE;
 -                                      }
 -                              }
 -                      }
 -                      me = me->id.next;
 -              }
 -      }
 -
 -      if (bmain->versionfile <= 200) {
 -              Object *ob = bmain->object.first;
 -              while (ob) {
 -                      ob->scaflag = ob->gameflag & (OB_DO_FH|OB_ROT_FH|OB_ANISOTROPIC_FRICTION|OB_GHOST|OB_RIGID_BODY|OB_BOUNDS);
 -                              /* 64 is do_fh */
 -                      ob->gameflag &= ~(OB_ROT_FH|OB_ANISOTROPIC_FRICTION|OB_GHOST|OB_RIGID_BODY|OB_BOUNDS);
 -                      ob = ob->id.next;
 -              }
 -      }
 -
 -      if (bmain->versionfile <= 201) {
 -              /* add-object + end-object are joined to edit-object actuator */
 -              Object *ob  = bmain->object.first;
 -              bProperty *prop;
 -              bActuator *act;
 -              bIpoActuator *ia;
 -              bEditObjectActuator *eoa;
 -              bAddObjectActuator *aoa;
 -              while (ob) {
 -                      act = ob->actuators.first;
 -                      while (act) {
 -                              if (act->type == ACT_IPO) {
 -                                      ia = act->data;
 -                                      prop = BKE_bproperty_object_get(ob, ia->name);
 -                                      if (prop) {
 -                                              ia->type = ACT_IPO_FROM_PROP;
 -                                      }
 -                              }
 -                              else if (act->type == ACT_ADD_OBJECT) {
 -                                      aoa = act->data;
 -                                      eoa = MEM_callocN(sizeof(bEditObjectActuator), "edit ob act");
 -                                      eoa->type = ACT_EDOB_ADD_OBJECT;
 -                                      eoa->ob = aoa->ob;
 -                                      eoa->time = aoa->time;
 -                                      MEM_freeN(aoa);
 -                                      act->data = eoa;
 -                                      act->type = act->otype = ACT_EDIT_OBJECT;
 -                              }
 -                              else if (act->type == ACT_END_OBJECT) {
 -                                      eoa = MEM_callocN(sizeof(bEditObjectActuator), "edit ob act");
 -                                      eoa->type = ACT_EDOB_END_OBJECT;
 -                                      act->data = eoa;
 -                                      act->type = act->otype = ACT_EDIT_OBJECT;
 -                              }
 -                              act = act->next;
 -                      }
 -                      ob = ob->id.next;
 -              }
 -      }
 -
 -      if (bmain->versionfile <= 202) {
 -              /* add-object and end-object are joined to edit-object
 -               * actuator */
 -              Object *ob = bmain->object.first;
 -              bActuator *act;
 -              bObjectActuator *oa;
 -              while (ob) {
 -                      act = ob->actuators.first;
 -                      while (act) {
 -                              if (act->type == ACT_OBJECT) {
 -                                      oa = act->data;
 -                                      oa->flag &= ~(ACT_TORQUE_LOCAL|ACT_DROT_LOCAL);         /* this actuator didn't do local/glob rot before */
 -                              }
 -                              act = act->next;
 -                      }
 -                      ob = ob->id.next;
 -              }
 -      }
 -
+       if (bmain->versionfile <= 204) {
 -              /* patches for new physics */
 -              Object *ob = bmain->object.first;
 -              bActuator *act;
 -              bObjectActuator *oa;
                bSound *sound;
 -              while (ob) {
 -
 -                      /* please check this for demo20 files like
 -                       * original Egypt levels etc.  converted
 -                       * rotation factor of 50 is not workable */
 -                      act = ob->actuators.first;
 -                      while (act) {
 -                              if (act->type == ACT_OBJECT) {
 -                                      oa = act->data;
 -
 -                                      oa->forceloc[0] *= 25.0f;
 -                                      oa->forceloc[1] *= 25.0f;
 -                                      oa->forceloc[2] *= 25.0f;
 -
 -                                      oa->forcerot[0] *= 10.0f;
 -                                      oa->forcerot[1] *= 10.0f;
 -                                      oa->forcerot[2] *= 10.0f;
 -                              }
 -                              act = act->next;
 -                      }
 -                      ob = ob->id.next;
 -              }
  
-               sound = main->sound.first;
+               sound = bmain->sound.first;
                while (sound) {
                        if (sound->volume < 0.01f) {
                                sound->volume = 1.0f;
                }
        }
  
-       if (main->versionfile <= 212) {
 -      if (bmain->versionfile <= 205) {
 -              /* patches for new physics */
 -              Object *ob = bmain->object.first;
 -              bActuator *act;
 -              bSensor *sens;
 -              bEditObjectActuator *oa;
 -              bRaySensor *rs;
 -              bCollisionSensor *cs;
 -              while (ob) {
 -                      /* Set anisotropic friction off for old objects,
 -                       * values to 1.0.  */
 -                      ob->gameflag &= ~OB_ANISOTROPIC_FRICTION;
 -                      ob->anisotropicFriction[0] = 1.0;
 -                      ob->anisotropicFriction[1] = 1.0;
 -                      ob->anisotropicFriction[2] = 1.0;
 -
 -                      act = ob->actuators.first;
 -                      while (act) {
 -                              if (act->type == ACT_EDIT_OBJECT) {
 -                                      /* Zero initial velocity for newly
 -                                       * added objects */
 -                                      oa = act->data;
 -                                      oa->linVelocity[0] = 0.0;
 -                                      oa->linVelocity[1] = 0.0;
 -                                      oa->linVelocity[2] = 0.0;
 -                                      oa->localflag = 0;
 -                              }
 -                              act = act->next;
 -                      }
 -
 -                      sens = ob->sensors.first;
 -                      while (sens) {
 -                              /* Extra fields for radar sensors. */
 -                              if (sens->type == SENS_RADAR) {
 -                                      bRadarSensor *s = sens->data;
 -                                      s->range = 10000.0;
 -                              }
 -
 -                              /* Pulsing: defaults for new sensors. */
 -                              if (sens->type != SENS_ALWAYS) {
 -                                      sens->pulse = 0;
 -                                      sens->freq = 0;
 -                              }
 -                              else {
 -                                      sens->pulse = 1;
 -                              }
 -
 -                              /* Invert: off. */
 -                              sens->invert = 0;
 -
 -                              /* Collision and ray: default = trigger
 -                               * on property. The material field can
 -                               * remain empty. */
 -                              if (sens->type == SENS_COLLISION) {
 -                                      cs = (bCollisionSensor*) sens->data;
 -                                      cs->mode = 0;
 -                              }
 -                              if (sens->type == SENS_RAY) {
 -                                      rs = (bRaySensor*) sens->data;
 -                                      rs->mode = 0;
 -                              }
 -                              sens = sens->next;
 -                      }
 -                      ob = ob->id.next;
 -              }
 -              /* have to check the exact multiplier */
 -      }
 -
 -      if (bmain->versionfile <= 211) {
 -              /* Render setting: per scene, the applicable gamma value
 -               * can be set. Default is 1.0, which means no
 -               * correction.  */
 -              bActuator *act;
 -              bObjectActuator *oa;
 -              Object *ob;
 -
 -              /* added alpha in obcolor */
 -              ob = bmain->object.first;
 -              while (ob) {
 -                      ob->col[3] = 1.0;
 -                      ob = ob->id.next;
 -              }
 -
 -              /* added alpha in obcolor */
 -              ob = bmain->object.first;
 -              while (ob) {
 -                      act = ob->actuators.first;
 -                      while (act) {
 -                              if (act->type == ACT_OBJECT) {
 -                                      /* multiply velocity with 50 in old files */
 -                                      oa = act->data;
 -                                      if (fabsf(oa->linearvelocity[0]) >= 0.01f)
 -                                              oa->linearvelocity[0] *= 50.0f;
 -                                      if (fabsf(oa->linearvelocity[1]) >= 0.01f)
 -                                              oa->linearvelocity[1] *= 50.0f;
 -                                      if (fabsf(oa->linearvelocity[2]) >= 0.01f)
 -                                              oa->linearvelocity[2] *= 50.0f;
 -                                      if (fabsf(oa->angularvelocity[0]) >= 0.01f)
 -                                              oa->angularvelocity[0] *= 50.0f;
 -                                      if (fabsf(oa->angularvelocity[1]) >= 0.01f)
 -                                              oa->angularvelocity[1] *= 50.0f;
 -                                      if (fabsf(oa->angularvelocity[2]) >= 0.01f)
 -                                              oa->angularvelocity[2] *= 50.0f;
 -                              }
 -                              act = act->next;
 -                      }
 -                      ob = ob->id.next;
 -              }
 -      }
 -
+       if (bmain->versionfile <= 212) {
                bSound *sound;
 -              bProperty *prop;
 -              Object *ob;
                Mesh *me;
  
-               sound = main->sound.first;
+               sound = bmain->sound.first;
                while (sound) {
                        sound->max_gain = 1.0;
                        sound->min_gain = 0.0;
                }
        }
  
-       if (main->versionfile <= 220) {
+       if (bmain->versionfile <= 220) {
 -              Object *ob;
                Mesh *me;
  
 -              ob = bmain->object.first;
 -
 -              /* adapt form factor in order to get the 'old' physics
 -               * behavior back...
 -               */
 -
 -              while (ob) {
 -                      /* in future, distinguish between different
 -                       * object bounding shapes
 -                       */
 -                      ob->formfactor = 0.4f;
 -                      /* patch form factor, note that inertia equiv radius
 -                       * of a rotation symmetrical obj
 -                       */
 -                      if (ob->inertia != 1.0f) {
 -                              ob->formfactor /= ob->inertia * ob->inertia;
 -                      }
 -                      ob = ob->id.next;
 -              }
 -
                /* Began using alpha component of vertex colors, but
                 * old file vertex colors are undefined, reset them
                 * to be fully opaque. -zr
                }
        }
  
-       if (main->versionfile <= 223) {
 -      if (bmain->versionfile <= 221) {
 -              Scene *sce = bmain->scene.first;
 -
 -              /* new variables for std-alone player and runtime */
 -              while (sce) {
 -                      sce->r.xplay = 640;
 -                      sce->r.yplay = 480;
 -                      sce->r.freqplay = 60;
 -
 -                      sce = sce->id.next;
 -              }
 -
 -      }
 -
 -      if (bmain->versionfile <= 222) {
 -              Scene *sce = bmain->scene.first;
 -
 -              /* new variables for std-alone player and runtime */
 -              while (sce) {
 -                      sce->r.depth = 32;
 -
 -                      sce = sce->id.next;
 -              }
 -      }
 -
+       if (bmain->versionfile <= 223) {
                VFont *vf;
-               for (vf = main->vfont.first; vf; vf = vf->id.next) {
 -              Image *ima;
 -              Object *ob;
 -
+               for (vf = bmain->vfont.first; vf; vf = vf->id.next) {
                        if (STREQ(vf->name + strlen(vf->name) - 6, ".Bfont")) {
                                strcpy(vf->name, FO_BUILTIN_NAME);
                        }
                }
 -
 -              /* Old textures animate at 25 FPS */
 -              for (ima = bmain->image.first; ima; ima = ima->id.next) {
 -                      ima->animspeed = 25;
 -              }
 -
 -              /* Zr remapped some keyboard codes to be linear (stupid zr) */
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      bSensor *sens;
 -
 -                      for (sens = ob->sensors.first; sens; sens = sens->next) {
 -                              if (sens->type == SENS_KEYBOARD) {
 -                                      bKeyboardSensor *ks = sens->data;
 -
 -                                      ks->key = map_223_keybd_code_to_224_keybd_code(ks->key);
 -                                      ks->qual = map_223_keybd_code_to_224_keybd_code(ks->qual);
 -                                      ks->qual2 = map_223_keybd_code_to_224_keybd_code(ks->qual2);
 -                              }
 -                      }
 -              }
        }
  
-       if (main->versionfile <= 224) {
+       if (bmain->versionfile <= 224) {
                bSound *sound;
                Scene *sce;
                Mesh *me;
                }
        }
  
-       if (main->versionfile <= 227) {
 -      if (bmain->versionfile <= 225) {
 -              World *wo;
 -              /* Use Sumo for old games */
 -              for (wo = bmain->world.first; wo; wo = wo->id.next) {
 -                      wo->physicsEngine = 2;
 -              }
 -      }
 -
+       if (bmain->versionfile <= 227) {
                Scene *sce;
 -              Material *ma;
                bScreen *sc;
                Object *ob;
  
                        ob = ob->id.next;
                }
  
-               for (sce = main->scene.first; sce; sce = sce->id.next) {
+               for (sce = bmain->scene.first; sce; sce = sce->id.next) {
                        sce->audio.mixrate = 48000;
                        sce->audio.flag |= AUDIO_SCRUB;
 -                      sce->r.mode |= R_ENVMAP;
 -              }
 -
 -              /* init new shader vars */
 -              for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 -                      ma->refrac = 4.0f;
 -                      ma->roughness = 0.5f;
 -                      ma->param[0] = 0.5f;
 -                      ma->param[1] = 0.1f;
 -                      ma->param[2] = 0.1f;
 -                      ma->param[3] = 0.05f;
                }
  
                /* patch for old wrong max view2d settings, allows zooming out more */
                }
        }
  
-       if (main->versionfile <= 228) {
+       if (bmain->versionfile <= 228) {
 -              Scene *sce;
                bScreen *sc;
                Object *ob;
  
                        ob = ob->id.next;
                }
  
 -              for (sce = bmain->scene.first; sce; sce = sce->id.next) {
 -                      sce->r.mode |= R_ENVMAP;
 -              }
 -
                /* convert old mainb values for new button panels */
-               for (sc = main->screen.first; sc; sc = sc->id.next) {
+               for (sc = bmain->screen.first; sc; sc = sc->id.next) {
                        ScrArea *sa;
  
                        for (sa = sc->areabase.first; sa; sa = sa->next) {
                }
        }
  
-       if (main->versionfile <= 231) {
-               bScreen *sc = main->screen.first;
+       if (bmain->versionfile <= 231) {
 -              Material *ma = bmain->mat.first;
+               bScreen *sc = bmain->screen.first;
 -              Scene *sce;
 -              Lamp *la;
 -              World *wrld;
 -
 -              /* introduction of raytrace */
 -              while (ma) {
 -                      if (ma->fresnel_tra_i == 0.0f)
 -                              ma->fresnel_tra_i = 1.25f;
 -                      if (ma->fresnel_mir_i == 0.0f)
 -                              ma->fresnel_mir_i = 1.25f;
 -
 -                      ma->ang = 1.0;
 -                      ma->ray_depth = 2;
 -                      ma->ray_depth_tra = 2;
 -                      ma->fresnel_tra = 0.0;
 -                      ma->fresnel_mir = 0.0;
 -
 -                      ma = ma->id.next;
 -              }
 -              sce = bmain->scene.first;
 -              while (sce) {
 -                      if (sce->r.gauss == 0.0f)
 -                              sce->r.gauss = 1.0f;
 -                      sce = sce->id.next;
 -              }
 -              la = bmain->lamp.first;
 -              while (la) {
 -                      if (la->k == 0.0f) la->k = 1.0;
 -                      if (la->ray_samp == 0)
 -                              la->ray_samp = 1;
 -                      if (la->ray_sampy == 0)
 -                              la->ray_sampy = 1;
 -                      if (la->ray_sampz == 0)
 -                              la->ray_sampz = 1;
 -                      if (la->area_size == 0.0f)
 -                              la->area_size = 1.0f;
 -                      if (la->area_sizey == 0.0f)
 -                              la->area_sizey = 1.0f;
 -                      if (la->area_sizez == 0.0f)
 -                              la->area_sizez = 1.0f;
 -                      la = la->id.next;
 -              }
 -              wrld = bmain->world.first;
 -              while (wrld) {
 -                      if (wrld->range == 0.0f) {
 -                              wrld->range = 1.0f / wrld->exposure;
 -                      }
 -                      wrld = wrld->id.next;
 -              }
  
                /* new bit flags for showing/hiding grid floor and axes */
  
                }
        }
  
-       if (main->versionfile <= 232) {
-               Tex *tex = main->tex.first;
-               World *wrld = main->world.first;
+       if (bmain->versionfile <= 232) {
+               Tex *tex = bmain->tex.first;
+               World *wrld = bmain->world.first;
                bScreen *sc;
 -              Scene *sce;
  
                while (tex) {
                        if ((tex->flag & (TEX_CHECKER_ODD+TEX_CHECKER_EVEN))==0) {
                                }
                        }
                }
 -              sce = bmain->scene.first;
 -              while (sce) {
 -                      if (sce->r.ocres == 0)
 -                              sce->r.ocres = 64;
 -                      sce = sce->id.next;
 -              }
 -
        }
  
-       if (main->versionfile <= 233) {
+       if (bmain->versionfile <= 233) {
                bScreen *sc;
-               Material *ma = main->mat.first;
-               /* Object *ob = main->object.first; */
+               Material *ma = bmain->mat.first;
+               /* Object *ob = bmain->object.first; */
  
                while (ma) {
 -                      if (ma->rampfac_col == 0.0f)
 -                              ma->rampfac_col = 1.0;
 -                      if (ma->rampfac_spec == 0.0f)
 -                              ma->rampfac_spec = 1.0;
                        if (ma->pr_lamp == 0)
                                ma->pr_lamp = 3;
                        ma = ma->id.next;
                }
        }
  
-       if (main->versionfile <= 234) {
+       if (bmain->versionfile <= 234) {
 -              World *wo;
                bScreen *sc;
  
-               for (sc = main->screen.first; sc; sc = sc->id.next) {
 -              /* force sumo engine to be active */
 -              for (wo = bmain->world.first; wo; wo = wo->id.next) {
 -                      if (wo->physicsEngine == 0)
 -                              wo->physicsEngine = 2;
 -              }
 -
+               for (sc = bmain->screen.first; sc; sc = sc->id.next) {
                        ScrArea *sa;
                        for (sa = sc->areabase.first; sa; sa = sa->next) {
                                SpaceLink *sl;
                }
        }
  
-       if (main->versionfile <= 236) {
+       if (bmain->versionfile <= 236) {
                Object *ob;
-               Camera *cam = main->camera.first;
+               Camera *cam = bmain->camera.first;
 -              Material *ma;
 -              bScreen *sc;
  
                while (cam) {
                        if (cam->ortho_scale == 0.0f) {
                        }
                        cam = cam->id.next;
                }
 -              /* set manipulator type */
                /* force oops draw if depgraph was set*/
                /* set time line var */
 -              for (sc = bmain->screen.first; sc; sc = sc->id.next) {
 -                      ScrArea *sa;
 -                      for (sa = sc->areabase.first; sa; sa = sa->next) {
 -                              SpaceLink *sl;
 -                              for (sl = sa->spacedata.first; sl; sl = sl->next) {
 -                                      if (sl->spacetype == SPACE_VIEW3D) {
 -                                              View3D *v3d = (View3D *) sl;
 -                                              if (v3d->twtype == 0)
 -                                                      v3d->twtype = V3D_MANIP_TRANSLATE;
 -                                      }
 -                              }
 -                      }
 -              }
 -              /* init new shader vars */
 -              for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 -                      if (ma->darkness == 0.0f) {
 -                              ma->rms = 0.1f;
 -                              ma->darkness = 1.0f;
 -                      }
 -              }
  
                /* softbody init new vars */
-               for (ob = main->object.first; ob; ob = ob->id.next) {
+               for (ob = bmain->object.first; ob; ob = ob->id.next) {
                        if (ob->soft) {
                                if (ob->soft->defgoal == 0.0f)
                                        ob->soft->defgoal = 0.7f;
                        /* btw. armature_rebuild_pose is further only called on leave editmode */
                        if (ob->type == OB_ARMATURE) {
                                if (ob->pose)
-                                       BKE_pose_tag_recalc(main, ob->pose);
+                                       BKE_pose_tag_recalc(bmain, ob->pose);
  
                                /* cannot call stuff now (pointers!), done in setup_app_data */
 -                              ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
 +                              ob->id.recalc |= ID_RECALC_ALL;
  
                                /* new generic xray option */
                                arm = blo_do_versions_newlibadr(fd, lib, ob->data);
                }
        }
  
-       if (main->versionfile <= 239) {
+       if (bmain->versionfile <= 239) {
                bArmature *arm;
                Object *ob;
-               Scene *sce = main->scene.first;
-               Camera *cam = main->camera.first;
+               Scene *sce = bmain->scene.first;
+               Camera *cam = bmain->camera.first;
 -              Material *ma = bmain->mat.first;
                int set_passepartout = 0;
  
                /* deformflag is local in modifier now */
                        if (!(cam->passepartalpha))
                                cam->passepartalpha = 0.2f;
                }
 -
 -              for (; ma; ma = ma->id.next) {
 -                      if (ma->strand_sta == 0.0f) {
 -                              ma->strand_sta = ma->strand_end = 1.0f;
 -                              ma->mode |= MA_TANGENT_STR;
 -                      }
 -                      if (ma->mode & MA_TRACEBLE)
 -                              ma->mode |= MA_SHADBUF;
 -              }
        }
  
-       if (main->versionfile <= 241) {
+       if (bmain->versionfile <= 241) {
                Object *ob;
 -              Tex *tex;
                Scene *sce;
 -              World *wo;
                Lamp *la;
 -              Material *ma;
                bArmature *arm;
                bNodeTree *ntree;
  
 -              for (wo = bmain->world.first; wo; wo = wo->id.next) {
 -                      /* Migrate to Bullet for games, except for the NaN versions */
 -                      /* People can still explicitly choose for Sumo (after 2.42 is out) */
 -                      if (bmain->versionfile > 225)
 -                              wo->physicsEngine = WOPHY_BULLET;
 -                      if (WO_AODIST == wo->aomode)
 -                              wo->aocolor = WO_AOPLAIN;
 -              }
 -
                /* updating layers still */
-               for (arm = main->armature.first; arm; arm = arm->id.next) {
+               for (arm = bmain->armature.first; arm; arm = arm->id.next) {
                        bone_version_239(&arm->bonebase);
                        if (arm->layer == 0)
                                arm->layer = 1;
                                sce->toolsettings->uvcalc_flag = UVCALC_FILLHOLES;
                                sce->toolsettings->unwrapper = 1;
                        }
 -
 -                      if (sce->r.mode & R_PANORAMA) {
 -                              /* all these checks to ensure saved files between released versions keep working... */
 -                              if (sce->r.xsch < sce->r.ysch) {
 -                                      Object *obc = blo_do_versions_newlibadr(fd, lib, sce->camera);
 -                                      if (obc && obc->type == OB_CAMERA) {
 -                                              Camera *cam = blo_do_versions_newlibadr(fd, lib, obc->data);
 -                                              if (cam->lens >= 10.0f) {
 -                                                      sce->r.xsch *= sce->r.xparts;
 -                                                      cam->lens *= (float)sce->r.ysch / (float)sce->r.xsch;
 -                                              }
 -                                      }
 -                              }
 -                      }
                }
  
-               for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
+               for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next)
                        ntree_version_241(ntree);
  
-               for (la = main->lamp.first; la; la = la->id.next)
+               for (la = bmain->lamp.first; la; la = la->id.next)
                        if (la->buffers == 0)
                                la->buffers = 1;
  
 -              for (tex = bmain->tex.first; tex; tex = tex->id.next) {
 -                      if (tex->env && tex->env->viewscale == 0.0f)
 -                              tex->env->viewscale = 1.0f;
 -                      //tex->imaflag |= TEX_GAUSS_MIP;
 -              }
 -
                /* for empty drawsize and drawtype */
-               for (ob = main->object.first; ob; ob = ob->id.next) {
+               for (ob = bmain->object.first; ob; ob = ob->id.next) {
                        if (ob->empty_drawsize == 0.0f) {
                                ob->empty_drawtype = OB_ARROWS;
                                ob->empty_drawsize = 1.0;
                        }
                }
  
 -              for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 -                      /* stucci returns intensity from now on */
 -                      int a;
 -                      for (a = 0; a < MAX_MTEX; a++) {
 -                              if (ma->mtex[a] && ma->mtex[a]->tex) {
 -                                      tex = blo_do_versions_newlibadr(fd, lib, ma->mtex[a]->tex);
 -                                      if (tex && tex->type == TEX_STUCCI)
 -                                              ma->mtex[a]->mapto &= ~(MAP_COL|MAP_SPEC|MAP_REF);
 -                              }
 -                      }
 -                      /* transmissivity defaults */
 -                      if (ma->tx_falloff == 0.0f)
 -                              ma->tx_falloff = 1.0f;
 -              }
 -
                /* during 2.41 images with this name were used for viewer node output, lets fix that */
-               if (main->versionfile == 241) {
+               if (bmain->versionfile == 241) {
                        Image *ima;
-                       for (ima = main->image.first; ima; ima = ima->id.next) {
+                       for (ima = bmain->image.first; ima; ima = ima->id.next) {
                                if (STREQ(ima->name, "Compositor")) {
                                        strcpy(ima->id.name + 2, "Viewer Node");
                                        strcpy(ima->name, "Viewer Node");
  
                }
  
-               for (ma = main->mat.first; ma; ma = ma->id.next) {
+               for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 -                      if (ma->shad_alpha == 0.0f)
 -                              ma->shad_alpha = 1.0f;
                        if (ma->nodetree)
                                ntree_version_242(ma->nodetree);
                }
  
-               for (me = main->mesh.first; me; me = me->id.next)
+               for (me = bmain->mesh.first; me; me = me->id.next)
                        customdata_version_242(me);
  
-               for (collection = main->collection.first; collection; collection = collection->id.next)
 -              for (group = bmain->group.first; group; group = group->id.next)
 -                      if (group->layer == 0)
 -                              group->layer = (1 << 20) - 1;
++              for (collection = bmain->collection.first; collection; collection = collection->id.next)
 +                      if (collection->layer == 0)
 +                              collection->layer = (1 << 20) - 1;
  
                /* now, subversion control! */
-               if (main->subversionfile < 3) {
+               if (bmain->subversionfile < 3) {
                        Image *ima;
                        Tex *tex;
  
                        }
                }
  
-               if (main->subversionfile < 4) {
-                       for (sce = main->scene.first; sce; sce = sce->id.next) {
+               if (bmain->subversionfile < 4) {
+                       for (sce = bmain->scene.first; sce; sce = sce->id.next) {
                                sce->r.bake_mode = 1;   /* prevent to include render stuff here */
                                sce->r.bake_filter = 16;
 -                              sce->r.bake_osa = 5;
                                sce->r.bake_flag = R_BAKE_CLEAR;
                        }
                }
        }
  
-       if (main->versionfile <= 243) {
-               Object *ob = main->object.first;
+       if (bmain->versionfile <= 243) {
+               Object *ob = bmain->object.first;
 -              Material *ma;
 -
 -              for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 -                      if (ma->sss_scale == 0.0f) {
 -                              ma->sss_radius[0] = 1.0f;
 -                              ma->sss_radius[1] = 1.0f;
 -                              ma->sss_radius[2] = 1.0f;
 -                              ma->sss_col[0] = 0.8f;
 -                              ma->sss_col[1] = 0.8f;
 -                              ma->sss_col[2] = 0.8f;
 -                              ma->sss_error = 0.05f;
 -                              ma->sss_scale = 0.1f;
 -                              ma->sss_ior = 1.3f;
 -                              ma->sss_colfac = 1.0f;
 -                              ma->sss_texfac = 0.0f;
 -                      }
 -                      if (ma->sss_front == 0 && ma->sss_back == 0) {
 -                              ma->sss_front = 1.0f;
 -                              ma->sss_back = 1.0f;
 -                      }
 -                      if (ma->sss_col[0] == 0 && ma->sss_col[1] == 0 && ma->sss_col[2] == 0) {
 -                              ma->sss_col[0] = ma->r;
 -                              ma->sss_col[1] = ma->g;
 -                              ma->sss_col[2] = ma->b;
 -                      }
 -              }
  
                for (; ob; ob = ob->id.next) {
                        bDeformGroup *curdef;
  
        }
  
-       if (main->versionfile <= 244) {
+       if (bmain->versionfile <= 244) {
 -              Scene *sce;
                bScreen *sc;
 -              Lamp *la;
 -              World *wrld;
  
-               if (main->versionfile != 244 || main->subversionfile < 2) {
+               if (bmain->versionfile != 244 || bmain->subversionfile < 2) {
 -                      for (sce = bmain->scene.first; sce; sce = sce->id.next)
 -                              sce->r.mode |= R_SSS;
 -
                        /* correct older action editors - incorrect scrolling */
-                       for (sc = main->screen.first; sc; sc = sc->id.next) {
+                       for (sc = bmain->screen.first; sc; sc = sc->id.next) {
                                ScrArea *sa;
                                sa = sc->areabase.first;
                                while (sa) {
                                }
                        }
                }
 -
 -              if (bmain->versionfile != 244 || bmain->subversionfile < 3) {
 -                      /* constraints recode version patch used to be here. Moved to 245 now... */
 -
 -                      for (wrld = bmain->world.first; wrld; wrld = wrld->id.next) {
 -                              if (wrld->mode & WO_AMB_OCC)
 -                                      wrld->ao_samp_method = WO_AOSAMP_CONSTANT;
 -                              else
 -                                      wrld->ao_samp_method = WO_AOSAMP_HAMMERSLEY;
 -
 -                              wrld->ao_adapt_thresh = 0.005f;
 -                      }
 -
 -                      for (la = bmain->lamp.first; la; la = la->id.next) {
 -                              if (la->type == LA_AREA)
 -                                      la->ray_samp_method = LA_SAMP_CONSTANT;
 -                              else
 -                                      la->ray_samp_method = LA_SAMP_HALTON;
 -
 -                              la->adapt_thresh = 0.001f;
 -                      }
 -              }
        }
  
-       if (main->versionfile <= 245) {
+       if (bmain->versionfile <= 245) {
                Scene *sce;
                Object *ob;
                Image *ima;
                        }
                }
  
-               if (main->versionfile != 245 || main->subversionfile < 1) {
-                       for (la = main->lamp.first; la; la = la->id.next) {
+               if (bmain->versionfile != 245 || bmain->subversionfile < 1) {
+                       for (la = bmain->lamp.first; la; la = la->id.next) {
 -                              if (la->mode & LA_QUAD)
 -                                      la->falloff_type = LA_FALLOFF_SLIDERS;
 -                              else
 -                                      la->falloff_type = LA_FALLOFF_INVLINEAR;
 +                              la->falloff_type = LA_FALLOFF_INVLINEAR;
  
                                if (la->curfalloff == NULL) {
                                        la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
                        }
                }
  
-               for (ma = main->mat.first; ma; ma = ma->id.next) {
+               for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 -                      if (ma->samp_gloss_mir == 0) {
 -                              ma->gloss_mir = ma->gloss_tra = 1.0f;
 -                              ma->aniso_gloss_mir = 1.0f;
 -                              ma->samp_gloss_mir = ma->samp_gloss_tra = 18;
 -                              ma->adapt_thresh_mir = ma->adapt_thresh_tra = 0.005f;
 -                              ma->dist_mir = 0.0f;
 -                              ma->fadeto_mir = MA_RAYMIR_FADETOSKY;
 +                      if (ma->gloss_mir == 0.0f) {
 +                              ma->gloss_mir = 1.0f;
                        }
 -
 -                      if (ma->strand_min == 0.0f)
 -                              ma->strand_min = 1.0f;
                }
  
-               for (part = main->particle.first; part; part = part->id.next) {
+               for (part = bmain->particle.first; part; part = part->id.next) {
                        if (part->ren_child_nbr == 0)
                                part->ren_child_nbr = part->child_nbr;
 -
 -                      if (part->simplify_refsize == 0) {
 -                              part->simplify_refsize = 1920;
 -                              part->simplify_rate = 1.0f;
 -                              part->simplify_transition = 0.1f;
 -                              part->simplify_viewport = 0.8f;
 -                      }
 -              }
 -
 -              for (wrld = bmain->world.first; wrld; wrld = wrld->id.next) {
 -                      if (wrld->ao_approx_error == 0.0f)
 -                              wrld->ao_approx_error = 0.25f;
                }
  
-               for (sce = main->scene.first; sce; sce = sce->id.next) {
+               for (sce = bmain->scene.first; sce; sce = sce->id.next) {
                        if (sce->nodetree)
                                ntree_version_245(fd, lib, sce->nodetree);
  
                }
        }
  
-       if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 2)) {
 -      /* sanity check for skgen */
 -      {
 -              Scene *sce;
 -              for (sce = bmain->scene.first; sce; sce = sce->id.next) {
 -                      if (sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[1] ||
 -                          sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[2] ||
 -                          sce->toolsettings->skgen_subdivisions[1] == sce->toolsettings->skgen_subdivisions[2])
 -                      {
 -                              sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
 -                              sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
 -                              sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
 -                      }
 -              }
 -      }
 -
 -
+       if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 2)) {
                Image *ima;
  
                /* initialize 1:1 Aspect */
                        }
                }
        }
 -      if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 9)) {
 -              Material *ma;
 -              int a;
 -
 -              for (ma = bmain->mat.first; ma; ma = ma->id.next)
 -                      if (ma->mode & MA_NORMAP_TANG)
 -                              for (a = 0; a < MAX_MTEX; a++)
 -                                      if (ma->mtex[a] && ma->mtex[a]->tex)
 -                                              ma->mtex[a]->normapspace = MTEX_NSPACE_TANGENT;
 -      }
  
-       if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 10)) {
+       if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 10)) {
                Object *ob;
  
                /* dupliface scale */
        }
  
        /* fix broken group lengths in id properties */
-       if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 15)) {
-               idproperties_fix_group_lengths(main->scene);
-               idproperties_fix_group_lengths(main->library);
-               idproperties_fix_group_lengths(main->object);
-               idproperties_fix_group_lengths(main->mesh);
-               idproperties_fix_group_lengths(main->curve);
-               idproperties_fix_group_lengths(main->mball);
-               idproperties_fix_group_lengths(main->mat);
-               idproperties_fix_group_lengths(main->tex);
-               idproperties_fix_group_lengths(main->image);
-               idproperties_fix_group_lengths(main->latt);
-               idproperties_fix_group_lengths(main->lamp);
-               idproperties_fix_group_lengths(main->camera);
-               idproperties_fix_group_lengths(main->ipo);
-               idproperties_fix_group_lengths(main->key);
-               idproperties_fix_group_lengths(main->world);
-               idproperties_fix_group_lengths(main->screen);
-               idproperties_fix_group_lengths(main->vfont);
-               idproperties_fix_group_lengths(main->text);
-               idproperties_fix_group_lengths(main->sound);
-               idproperties_fix_group_lengths(main->collection);
-               idproperties_fix_group_lengths(main->armature);
-               idproperties_fix_group_lengths(main->action);
-               idproperties_fix_group_lengths(main->nodetree);
-               idproperties_fix_group_lengths(main->brush);
-               idproperties_fix_group_lengths(main->particle);
+       if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 15)) {
+               idproperties_fix_group_lengths(bmain->scene);
+               idproperties_fix_group_lengths(bmain->library);
+               idproperties_fix_group_lengths(bmain->object);
+               idproperties_fix_group_lengths(bmain->mesh);
+               idproperties_fix_group_lengths(bmain->curve);
+               idproperties_fix_group_lengths(bmain->mball);
+               idproperties_fix_group_lengths(bmain->mat);
+               idproperties_fix_group_lengths(bmain->tex);
+               idproperties_fix_group_lengths(bmain->image);
+               idproperties_fix_group_lengths(bmain->latt);
+               idproperties_fix_group_lengths(bmain->lamp);
+               idproperties_fix_group_lengths(bmain->camera);
+               idproperties_fix_group_lengths(bmain->ipo);
+               idproperties_fix_group_lengths(bmain->key);
+               idproperties_fix_group_lengths(bmain->world);
+               idproperties_fix_group_lengths(bmain->screen);
+               idproperties_fix_group_lengths(bmain->vfont);
+               idproperties_fix_group_lengths(bmain->text);
+               idproperties_fix_group_lengths(bmain->sound);
 -              idproperties_fix_group_lengths(bmain->group);
++              idproperties_fix_group_lengths(bmain->collection);
+               idproperties_fix_group_lengths(bmain->armature);
+               idproperties_fix_group_lengths(bmain->action);
+               idproperties_fix_group_lengths(bmain->nodetree);
+               idproperties_fix_group_lengths(bmain->brush);
+               idproperties_fix_group_lengths(bmain->particle);
        }
  
 -      /* sun/sky */
 -      if (bmain->versionfile < 246) {
 -              Object *ob;
 -              bActuator *act;
 -
 -              /* dRot actuator change direction in 2.46 */
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      for (act = ob->actuators.first; act; act = act->next) {
 -                              if (act->type == ACT_OBJECT) {
 -                                      bObjectActuator *ba = act->data;
 -
 -                                      ba->drot[0] = -ba->drot[0];
 -                                      ba->drot[1] = -ba->drot[1];
 -                                      ba->drot[2] = -ba->drot[2];
 -                              }
 -                      }
 -              }
 -      }
 -
        /* convert fluids to modifier */
-       if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) {
+       if (bmain->versionfile < 246 || (bmain->versionfile == 246 && bmain->subversionfile < 1)) {
                Object *ob;
  
-               for (ob = main->object.first; ob; ob = ob->id.next) {
+               for (ob = bmain->object.first; ob; ob = ob->id.next) {
                        if (ob->fluidsimSettings) {
                                FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifier_new(eModifierType_Fluidsim);
                                BLI_addhead(&ob->modifiers, (ModifierData *)fluidmd);
                }
        }
  
-       if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) {
 -
 -      if (bmain->versionfile < 246 || (bmain->versionfile == 246 && bmain->subversionfile < 1)) {
 -              Mesh *me;
 -
 -              for (me = bmain->mesh.first; me; me = me->id.next)
 -                      alphasort_version_246(fd, lib, me);
 -      }
 -
+       if (bmain->versionfile < 246 || (bmain->versionfile == 246 && bmain->subversionfile < 1)) {
                Object *ob;
-               for (ob = main->object.first; ob; ob = ob->id.next) {
+               for (ob = bmain->object.first; ob; ob = ob->id.next) {
                        if (ob->pd && (ob->pd->forcefield == PFIELD_WIND))
                                ob->pd->f_noise = 0.0f;
                }
        }
  
 -      if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 2)) {
 -              Object *ob;
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      ob->gameflag |= OB_COLLISION;
 -                      ob->margin = 0.06f;
 -              }
 -      }
 -
 -      if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 3)) {
 -              Object *ob;
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      /* Starting from subversion 3, ACTOR is a separate feature.
 -                       * Before it was conditioning all the other dynamic flags */
 -                      if (!(ob->gameflag & OB_ACTOR))
 -                              ob->gameflag &= ~(OB_GHOST|OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_COLLISION_RESPONSE);
 -                      /* suitable default for older files */
 -              }
 -      }
 -
 -      if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 5)) {
 -              Lamp *la = bmain->lamp.first;
 -              for (; la; la = la->id.next) {
 -                      la->skyblendtype = MA_RAMP_ADD;
 -                      la->skyblendfac = 1.0f;
 -              }
 -      }
 -
        /* set the curve radius interpolation to 2.47 default - easy */
-       if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 6)) {
+       if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 6)) {
                Curve *cu;
                Nurb *nu;
  
                }
        }
  
-       if (main->versionfile < 248 || (main->versionfile == 248 && main->subversionfile < 2)) {
 -      /* direction constraint actuators were always local in previous version */
 -      if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 7)) {
 -              bActuator *act;
 -              Object *ob;
 -
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      for (act = ob->actuators.first; act; act = act->next) {
 -                              if (act->type == ACT_CONSTRAINT) {
 -                                      bConstraintActuator *coa = act->data;
 -                                      if (coa->type == ACT_CONST_TYPE_DIST) {
 -                                              coa->flag |= ACT_CONST_LOCAL;
 -                                      }
 -                              }
 -                      }
 -              }
 -      }
 -
 -      if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 9)) {
 -              Lamp *la = bmain->lamp.first;
 -              for (; la; la = la->id.next) {
 -                      la->sky_exposure = 1.0f;
 -              }
 -      }
 -
 -      /* BGE message actuators needed OB prefix, very confusing */
 -      if (bmain->versionfile < 247 || (bmain->versionfile == 247 && bmain->subversionfile < 10)) {
 -              bActuator *act;
 -              Object *ob;
 -
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      for (act = ob->actuators.first; act; act = act->next) {
 -                              if (act->type == ACT_MESSAGE) {
 -                                      bMessageActuator *msgAct = (bMessageActuator *) act->data;
 -
 -                                      if (BLI_strnlen(msgAct->toPropName, 3) > 2) {
 -                                              /* strip first 2 chars, would have only worked if these were OB anyway */
 -                                              memmove(msgAct->toPropName, msgAct->toPropName + 2, sizeof(msgAct->toPropName) - 2);
 -                                      }
 -                                      else {
 -                                              msgAct->toPropName[0] = '\0';
 -                                      }
 -                              }
 -                      }
 -              }
 -      }
 -
 -      if (bmain->versionfile < 248) {
 -              Lamp *la;
 -
 -              for (la = bmain->lamp.first; la; la = la->id.next) {
 -                      if (la->atm_turbidity == 0.0f) {
 -                              la->sun_effect_type = 0;
 -                              la->horizon_brightness = 1.0f;
 -                              la->spread = 1.0f;
 -                              la->sun_brightness = 1.0f;
 -                              la->sun_size = 1.0f;
 -                              la->backscattered_light = 1.0f;
 -                              la->atm_turbidity = 2.0f;
 -                              la->atm_inscattering_factor = 1.0f;
 -                              la->atm_extinction_factor = 1.0f;
 -                              la->atm_distance_factor = 1.0f;
 -                              la->sun_intensity = 1.0f;
 -                      }
 -              }
 -      }
 -
+       if (bmain->versionfile < 248 || (bmain->versionfile == 248 && bmain->subversionfile < 2)) {
                Scene *sce;
  
                /* Note, these will need to be added for painting */
-               for (sce = main->scene.first; sce; sce = sce->id.next) {
+               for (sce = bmain->scene.first; sce; sce = sce->id.next) {
                        sce->toolsettings->imapaint.seam_bleed = 2;
                        sce->toolsettings->imapaint.normal_angle = 80;
 -
 -                      /* initialize skeleton generation toolsettings */
 -                      sce->toolsettings->skgen_resolution = 250;
 -                      sce->toolsettings->skgen_threshold_internal     = 0.1f;
 -                      sce->toolsettings->skgen_threshold_external     = 0.1f;
 -                      sce->toolsettings->skgen_angle_limit                    = 30.0f;
 -                      sce->toolsettings->skgen_length_ratio                   = 1.3f;
 -                      sce->toolsettings->skgen_length_limit                   = 1.5f;
 -                      sce->toolsettings->skgen_correlation_limit              = 0.98f;
 -                      sce->toolsettings->skgen_symmetry_limit                 = 0.1f;
 -                      sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
 -                      sce->toolsettings->skgen_postpro_passes = 3;
 -                      sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_FILTER_SMART|SKGEN_SUB_CORRELATION|SKGEN_HARMONIC;
 -                      sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
 -                      sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
 -                      sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
 -
 -
 -                      sce->toolsettings->skgen_retarget_angle_weight = 1.0f;
 -                      sce->toolsettings->skgen_retarget_length_weight = 1.0f;
 -                      sce->toolsettings->skgen_retarget_distance_weight = 1.0f;
 -
 -                      /* Skeleton Sketching */
 -                      sce->toolsettings->bone_sketching = 0;
 -                      sce->toolsettings->skgen_retarget_roll = SK_RETARGET_ROLL_VIEW;
                }
        }
  
                }
        }
  
 -      if (bmain->versionfile < 248 || (bmain->versionfile == 248 && bmain->subversionfile < 3)) {
 -              Object *ob;
 -
 -              /* Adjustments needed after Bullets update */
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      ob->damping *= 0.635f;
 -                      ob->rdamping = 0.1f + (0.8f * ob->rdamping);
 -              }
 -      }
 -
 -      if (bmain->versionfile < 248 || (bmain->versionfile == 248 && bmain->subversionfile < 4)) {
 -              Scene *sce;
 -              World *wrld;
 -
 -              /*  Dome (Fisheye) default parameters  */
 -              for (sce = bmain->scene.first; sce; sce = sce->id.next) {
 -                      sce->r.domeangle = 180;
 -                      sce->r.domemode = 1;
 -                      sce->r.domeres = 4;
 -                      sce->r.domeresbuf = 1.0f;
 -                      sce->r.dometilt = 0;
 -              }
 -              /* DBVT culling by default */
 -              for (wrld = bmain->world.first; wrld; wrld = wrld->id.next) {
 -                      wrld->mode |= WO_DBVT_CULLING;
 -                      wrld->occlusionRes = 128;
 -              }
 -      }
 -
 -      if (bmain->versionfile < 248 || (bmain->versionfile == 248 && bmain->subversionfile < 5)) {
 -              Object *ob;
 -              World *wrld;
 -              for (ob = bmain->object.first; ob; ob = ob->id.next) {
 -                      if (ob->parent) {
 -                              /* check if top parent has compound shape set and if yes, set this object
 -                               * to compound shaper as well (was the behavior before, now it's optional) */
 -                              Object *parent = blo_do_versions_newlibadr(fd, lib, ob->parent);
 -                              while (parent && parent != ob && parent->parent != NULL) {
 -                                      parent = blo_do_versions_newlibadr(fd, lib, parent->parent);
 -                              }
 -                              if (parent) {
 -                                      if (parent->gameflag & OB_CHILD)
 -                                              ob->gameflag |= OB_CHILD;
 -                              }
 -                      }
 -              }
 -              for (wrld = bmain->world.first; wrld; wrld = wrld->id.next) {
 -                      wrld->ticrate = 60;
 -                      wrld->maxlogicstep = 5;
 -                      wrld->physubstep = 1;
 -                      wrld->maxphystep = 5;
 -              }
 -      }
 -
        /* correct introduce of seed for wind force */
-       if (main->versionfile < 249 && main->subversionfile < 1) {
+       if (bmain->versionfile < 249 && bmain->subversionfile < 1) {
                Object *ob;
-               for (ob = main->object.first; ob; ob = ob->id.next) {
+               for (ob = bmain->object.first; ob; ob = ob->id.next) {
                        if (ob->pd)
                                ob->pd->seed = ((unsigned int)(ceil(PIL_check_seconds_timer())) + 1) % 128;
                }
@@@ -317,9 -275,10 +317,9 @@@ static World *preview_get_localized_wor
  static Scene *preview_prepare_scene(Main *bmain, Scene *scene, ID *id, int id_type, ShaderPreview *sp)
  {
        Scene *sce;
 -      Base *base;
        Main *pr_main = sp->pr_main;
  
-       memcpy(pr_main->name, bmain->name, sizeof(pr_main->name));
+       memcpy(pr_main->name, BKE_main_blendfile_path(bmain), sizeof(pr_main->name));
  
        sce = preview_get_scene(pr_main);
        if (sce) {
Simple merge
@@@ -379,9 -280,9 +379,9 @@@ typedef enum ID_Type 
  #define ID_REAL_USERS(id) (((ID *)id)->us - ID_FAKE_USERS(id))
  #define ID_EXTRA_USERS(id) (((ID *)id)->tag & LIB_TAG_EXTRAUSER ? 1 : 0)
  
 -#define ID_CHECK_UNDO(id) ((GS((id)->name) != ID_SCR) && (GS((id)->name) != ID_WM))
 +#define ID_CHECK_UNDO(id) ((GS((id)->name) != ID_SCR) && (GS((id)->name) != ID_WM) && (GS((id)->name) != ID_WS))
  
- #define ID_BLEND_PATH(_bmain, _id) ((_id)->lib ? (_id)->lib->filepath : (_bmain)->name)
+ #define ID_BLEND_PATH(_bmain, _id) ((_id)->lib ? (_id)->lib->filepath : BKE_main_blendfile_path((_bmain)))
  
  #define ID_MISSING(_id) (((_id)->tag & LIB_TAG_MISSING) != 0)
  
@@@ -60,8 -60,8 +60,8 @@@ static void rna_MovieClip_reload_update
  {
        MovieClip *clip = (MovieClip *)ptr->id.data;
  
-       BKE_movieclip_reload(clip);
+       BKE_movieclip_reload(bmain, clip);
 -      DAG_id_tag_update(&clip->id, 0);
 +      DEG_id_tag_update(&clip->id, 0);
  }
  
  static void rna_MovieClip_size_get(PointerRNA *ptr, int *values)
@@@ -869,13 -854,22 +871,13 @@@ int wm_homefile_read
        }
        
        /* match the read WM with current WM */
 -      wm_window_match_do(C, &wmbase); 
 +      wm_window_match_do(C, &wmbase, &G.main->wm, &G.main->wm);
        WM_check(C); /* opens window(s), checks keymaps */
  
-       G.main->name[0] = '\0';
+       bmain->name[0] = '\0';
  
 -      if (use_userdef) {
 -              /* When loading factory settings, the reset solid OpenGL lights need to be applied. */
 -              if (!G.background) {
 -                      GPU_default_lights();
 -              }
 -      }
 -
        /* start with save preference untitled.blend */
        G.save_over = 0;
 -      /* disable auto-play in startup.blend... */
 -      G.fileflags &= ~G_FILE_AUTOPLAY;
  
        wm_file_read_post(C, true, use_userdef);