diff options
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 147 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.h | 4 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_250.c | 2 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_280.c | 181 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 41 |
5 files changed, 350 insertions, 25 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 060d290df32..e669bf3b4a6 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -72,6 +72,7 @@ #include "DNA_ipo_types.h" #include "DNA_key_types.h" #include "DNA_lattice_types.h" +#include "DNA_layer_types.h" #include "DNA_lamp_types.h" #include "DNA_linestyle_types.h" #include "DNA_meta_types.h" @@ -102,6 +103,8 @@ #include "DNA_movieclip_types.h" #include "DNA_mask_types.h" +#include "RNA_access.h" + #include "MEM_guardedalloc.h" #include "BLI_endian_switch.h" @@ -5630,11 +5633,29 @@ static bool scene_validate_setscene__liblink(Scene *sce, const int totscene) } #endif +static void lib_link_scene_collection(FileData *fd, Library *lib, SceneCollection *sc) +{ + for (LinkData *link = sc->objects.first; link; link = link->next) { + link->data = newlibadr_us(fd, lib, link->data); + BLI_assert(link->data); + } + + for (LinkData *link = sc->filter_objects.first; link; link = link->next) { + link->data = newlibadr_us(fd, lib, link->data); + BLI_assert(link->data); + } + + for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) { + lib_link_scene_collection(fd, lib, nsc); + } +} + static void lib_link_scene(FileData *fd, Main *main) { Scene *sce; - Base *base, *next; + BaseLegacy *base_legacy, *base_legacy_next; Sequence *seq; + SceneLayer *sl; SceneRenderLayer *srl; FreestyleModuleConfig *fmc; FreestyleLineSet *fls; @@ -5684,17 +5705,17 @@ static void lib_link_scene(FileData *fd, Main *main) sce->toolsettings->particle.shape_object = newlibadr(fd, sce->id.lib, sce->toolsettings->particle.shape_object); - for (base = sce->base.first; base; base = next) { - next = base->next; + for (base_legacy = sce->base.first; base_legacy; base_legacy = base_legacy_next) { + base_legacy_next = base_legacy->next; - base->object = newlibadr_us(fd, sce->id.lib, base->object); + base_legacy->object = newlibadr_us(fd, sce->id.lib, base_legacy->object); - if (base->object == NULL) { + if (base_legacy->object == NULL) { blo_reportf_wrap(fd->reports, RPT_WARNING, TIP_("LIB: object lost from scene: '%s'"), sce->id.name + 2); - BLI_remlink(&sce->base, base); - if (base == sce->basact) sce->basact = NULL; - MEM_freeN(base); + BLI_remlink(&sce->base, base_legacy); + if (base_legacy == sce->basact) sce->basact = NULL; + MEM_freeN(base_legacy); } } @@ -5780,6 +5801,15 @@ static void lib_link_scene(FileData *fd, Main *main) /* Motion Tracking */ sce->clip = newlibadr_us(fd, sce->id.lib, sce->clip); + lib_link_scene_collection(fd, sce->id.lib, sce->collection); + + for (sl = sce->render_layers.first; sl; sl = sl->next) { + for (Base *base = sl->object_bases.first; base; base = base->next) { + /* we only bump the use count for the collection objects */ + base->object = newlibadr(fd, sce->id.lib, base->object); + } + } + #ifdef USE_SETSCENE_CHECK if (sce->set != NULL) { /* link flag for scenes with set would be reset later, @@ -5883,12 +5913,42 @@ static void direct_link_view_settings(FileData *fd, ColorManagedViewSettings *vi direct_link_curvemapping(fd, view_settings->curve_mapping); } +static void direct_link_scene_collection(FileData *fd, SceneCollection *sc) +{ + link_list(fd, &sc->objects); + link_list(fd, &sc->filter_objects); + link_list(fd, &sc->scene_collections); + + for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) { + direct_link_scene_collection(fd, nsc); + } +} + +static void direct_link_layer_collections(FileData *fd, ListBase *lb) +{ + link_list(fd, lb); + for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + lc->scene_collection = newdataadr(fd, lc->scene_collection); + + link_list(fd, &lc->object_bases); + + for (LinkData *link = lc->object_bases.first; link; link = link->next) { + link->data = newdataadr(fd, link->data); + } + + link_list(fd, &lc->overrides); + + direct_link_layer_collections(fd, &lc->layer_collections); + } +} + static void direct_link_scene(FileData *fd, Scene *sce) { Editing *ed; Sequence *seq; MetaStack *ms; RigidBodyWorld *rbw; + SceneLayer *sl; SceneRenderLayer *srl; sce->theDag = NULL; @@ -6139,6 +6199,19 @@ static void direct_link_scene(FileData *fd, Scene *sce) sce->preview = direct_link_preview_image(fd, sce->preview); direct_link_curvemapping(fd, &sce->r.mblur_shutter_curve); + + /* this runs before the very first doversion */ + if (sce->collection) { + sce->collection = newdataadr(fd, sce->collection); + direct_link_scene_collection(fd, sce->collection); + } + + link_list(fd, &sce->render_layers); + for (sl = sce->render_layers.first; sl; sl = sl->next) { + link_list(fd, &sl->object_bases); + sl->basact = newdataadr(fd, sl->basact); + direct_link_layer_collections(fd, &sl->layer_collections); + } } /* ************ READ WM ***************** */ @@ -6482,6 +6555,10 @@ static void lib_link_screen(FileData *fd, Main *main) slogic->gpd = newlibadr_us(fd, sc->id.lib, slogic->gpd); } + else if (sl->spacetype == SPACE_COLLECTIONS) { + SpaceCollections *slayer = (SpaceCollections *)sl; + slayer->flag |= SC_COLLECTION_DATA_REFRESH; + } } } sc->id.tag &= ~LIB_TAG_NEED_LINK; @@ -6867,6 +6944,10 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc slogic->gpd = restore_pointer_by_name(id_map, (ID *)slogic->gpd, USER_REAL); } + else if (sl->spacetype == SPACE_COLLECTIONS) { + SpaceCollections *slayer = (SpaceCollections *)sl; + slayer->flag |= SC_COLLECTION_DATA_REFRESH; + } } } } @@ -7261,6 +7342,10 @@ static bool direct_link_screen(FileData *fd, bScreen *sc) sclip->scopes.track_preview = NULL; sclip->scopes.ok = 0; } + else if (sl->spacetype == SPACE_COLLECTIONS) { + SpaceCollections *slayer = (SpaceCollections *)sl; + slayer->flag |= SC_COLLECTION_DATA_REFRESH; + } } BLI_listbase_clear(&sa->actionzones); @@ -7457,7 +7542,7 @@ static void lib_link_group(FileData *fd, Main *main) if (add_us) { id_us_ensure_real(&group->id); } - BKE_group_object_unlink(group, NULL, NULL, NULL); /* removes NULL entries */ + BKE_group_object_unlink(group, NULL); /* removes NULL entries */ } } } @@ -8389,6 +8474,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) blo_do_versions_250(fd, lib, main); blo_do_versions_260(fd, lib, main); blo_do_versions_270(fd, lib, main); + blo_do_versions_280(fd, lib, main); /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ /* WATCH IT 2!: Userdef struct init see do_versions_userdef() above! */ @@ -8400,8 +8486,8 @@ static void do_versions_after_linking(Main *main) { // printf("%s for %s (%s), %d.%d\n", __func__, main->curlib ? main->curlib->name : main->name, // main->curlib ? "LIB" : "MAIN", main->versionfile, main->subversionfile); - do_versions_after_linking_270(main); + do_versions_after_linking_280(main); } static void lib_link_all(FileData *fd, Main *main) @@ -9484,9 +9570,24 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob) } } +static void expand_scene_collection(FileData *fd, Main *mainvar, SceneCollection *sc) +{ + for (LinkData *link = sc->objects.first; link; link = link->next) { + expand_doit(fd, mainvar, link->data); + } + + for (LinkData *link = sc->filter_objects.first; link; link = link->next) { + expand_doit(fd, mainvar, link->data); + } + + for (SceneCollection *nsc= sc->scene_collections.first; nsc; nsc = nsc->next) { + expand_scene_collection(fd, mainvar, nsc); + } +} + static void expand_scene(FileData *fd, Main *mainvar, Scene *sce) { - Base *base; + BaseLegacy *base; SceneRenderLayer *srl; FreestyleModuleConfig *module; FreestyleLineSet *lineset; @@ -9553,6 +9654,8 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce) } expand_doit(fd, mainvar, sce->clip); + + expand_scene_collection(fd, mainvar, sce->collection); } static void expand_camera(FileData *fd, Main *mainvar, Camera *ca) @@ -9799,7 +9902,7 @@ static bool object_in_any_scene(Main *mainvar, Object *ob) static void give_base_to_objects(Main *mainvar, Scene *scene, View3D *v3d, Library *lib, const short flag) { Object *ob; - Base *base; + BaseLegacy *base; const unsigned int active_lay = (flag & FILE_ACTIVELAY) ? BKE_screen_view3d_layer_active(v3d, scene) : 0; const bool is_link = (flag & FILE_LINK) != 0; @@ -9820,7 +9923,7 @@ static void give_base_to_objects(Main *mainvar, Scene *scene, View3D *v3d, Libra } if (do_it) { - base = MEM_callocN(sizeof(Base), __func__); + base = MEM_callocN(sizeof(BaseLegacy), __func__); BLI_addtail(&scene->base, base); if (active_lay) { @@ -9835,7 +9938,7 @@ static void give_base_to_objects(Main *mainvar, Scene *scene, View3D *v3d, Libra base->object = ob; base->lay = ob->lay; - base->flag = ob->flag; + BKE_scene_base_flag_sync_from_object(base); CLAMP_MIN(ob->id.us, 0); id_us_plus_no_lib((ID *)ob); @@ -9851,7 +9954,7 @@ static void give_base_to_groups( Main *mainvar, Scene *scene, View3D *v3d, Library *UNUSED(lib), const short UNUSED(flag)) { Group *group; - Base *base; + BaseLegacy *base; Object *ob; const unsigned int active_lay = BKE_screen_view3d_layer_active(v3d, scene); @@ -9868,8 +9971,8 @@ static void give_base_to_groups( /* assign the base */ base = BKE_scene_base_add(scene, ob); - base->flag |= SELECT; - base->object->flag = base->flag; + base->flag_legacy |= SELECT; + BKE_scene_base_flag_sync_from_base(base); DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); scene->basact = base; @@ -9951,10 +10054,10 @@ static ID *link_named_part( static void link_object_postprocess(ID *id, Scene *scene, View3D *v3d, const short flag) { if (scene) { - Base *base; + BaseLegacy *base; Object *ob; - base = MEM_callocN(sizeof(Base), "app_nam_part"); + base = MEM_callocN(sizeof(BaseLegacy), "app_nam_part"); BLI_addtail(&scene->base, base); ob = (Object *)id; @@ -9967,12 +10070,12 @@ static void link_object_postprocess(ID *id, Scene *scene, View3D *v3d, const sho ob->mode = OB_MODE_OBJECT; base->lay = ob->lay; base->object = ob; - base->flag = ob->flag; + base->flag_legacy = ob->flag; id_us_plus_no_lib((ID *)ob); if (flag & FILE_AUTOSELECT) { - base->flag |= SELECT; - base->object->flag = base->flag; + base->flag_legacy |= SELECT; + BKE_scene_base_flag_sync_from_base(base); /* do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level */ } } diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h index d97bef13a78..50cdeca16b5 100644 --- a/source/blender/blenloader/intern/readfile.h +++ b/source/blender/blenloader/intern/readfile.h @@ -34,6 +34,8 @@ #define __READFILE_H__ #include "zlib.h" +#include "DNA_sdna_types.h" +#include "DNA_space_types.h" #include "DNA_windowmanager_types.h" /* for ReportType */ struct OldNewMap; @@ -169,8 +171,10 @@ void blo_do_versions_pre250(struct FileData *fd, struct Library *lib, struct Mai 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); #endif diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 1956a17d57b..943e5479d9a 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -736,7 +736,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main) if (main->versionfile < 250) { bScreen *screen; Scene *scene; - Base *base; + BaseLegacy *base; Material *ma; Camera *cam; Mesh *me; diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c new file mode 100644 index 00000000000..a4e69c9d514 --- /dev/null +++ b/source/blender/blenloader/intern/versioning_280.c @@ -0,0 +1,181 @@ +/* + * ***** 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 "DNA_object_types.h" +#include "DNA_layer_types.h" +#include "DNA_scene_types.h" +#include "DNA_genfile.h" + +#include "BKE_collection.h" +#include "BKE_layer.h" +#include "BKE_main.h" +#include "BKE_scene.h" + +#include "BLI_listbase.h" +#include "BLI_string.h" + +#include "BLO_readfile.h" +#include "readfile.h" + +#include "MEM_guardedalloc.h" + +void do_versions_after_linking_280(Main *main) +{ + if (!MAIN_VERSION_ATLEAST(main, 280, 0)) { + for (Scene *scene = main->scene.first; scene; scene = scene->id.next) { + /* since we don't have access to FileData we check the (always valid) first render layer instead */ + if (scene->render_layers.first == NULL) { + SceneCollection *sc_master = BKE_collection_master(scene); + BLI_strncpy(sc_master->name, "Master Collection", sizeof(sc_master->name)); + + SceneCollection *collections[20] = {NULL}; + bool is_visible[20]; + + int lay_used = 0; + for (int i = 0; i < 20; i++) { + char name[MAX_NAME]; + + BLI_snprintf(name, sizeof(collections[i]->name), "%d", i + 1); + collections[i] = BKE_collection_add(scene, sc_master, name); + + is_visible[i] = (scene->lay & (1 << i)); + } + + for (BaseLegacy *base = scene->base.first; base; base = base->next) { + lay_used |= base->lay & ((1 << 20) - 1); /* ignore localview */ + + for (int i = 0; i < 20; i++) { + if ((base->lay & (1 << i)) != 0) { + BKE_collection_object_add(scene, collections[i], base->object); + } + } + } + + scene->active_layer = 0; + + if (!BKE_scene_uses_blender_game(scene)) { + for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) { + + SceneLayer *sl = BKE_scene_layer_add(scene, srl->name); + BKE_scene_layer_engine_set(sl, scene->r.engine); + + if (srl->mat_override) { + BKE_collection_override_datablock_add((LayerCollection *)sl->layer_collections.first, "material", (ID *)srl->mat_override); + } + + if (srl->light_override && BKE_scene_uses_blender_internal(scene)) { + /* not sure how we handle this, pending until we design the override system */ + TODO_LAYER_OVERRIDE; + } + + if (srl->lay != scene->lay) { + /* unlink master collection */ + BKE_collection_unlink(sl, sl->layer_collections.first); + + /* add new collection bases */ + for (int i = 0; i < 20; i++) { + if ((srl->lay & (1 << i)) != 0) { + BKE_collection_link(sl, collections[i]); + } + } + } + + /* TODO: passes, samples, mask_layesr, exclude, ... */ + } + + if (BLI_findlink(&scene->render_layers, scene->r.actlay)) { + scene->active_layer = scene->r.actlay; + } + } + + SceneLayer *sl = BKE_scene_layer_add(scene, "Render Layer"); + + /* In this particular case we can safely assume the data struct */ + LayerCollection *lc = ((LayerCollection *)sl->layer_collections.first)->layer_collections.first; + for (int i = 0; i < 20; i++) { + if (!is_visible[i]) { + lc->flag &= ~COLLECTION_VISIBLE; + } + lc = lc->next; + } + + /* but we still need to make the flags synced */ + BKE_scene_layer_base_flag_recalculate(sl); + + /* convert active base */ + if (scene->basact) { + sl->basact = BKE_scene_layer_base_find(sl, scene->basact->object); + } + + /* convert selected bases */ + for (BaseLegacy *base = scene->base.first; base; base = base->next) { + Base *ob_base = BKE_scene_layer_base_find(sl, base->object); + if ((base->flag_legacy & SELECT) != 0) { + if ((ob_base->flag & BASE_SELECTABLED) != 0) { + ob_base->flag |= BASE_SELECTED; + } + } + else { + ob_base->flag &= ~BASE_SELECTED; + } + } + + /* TODO: copy scene render data to layer */ + + /* Cleanup */ + for (int i = 0; i < 20; i++) { + if ((lay_used & (1 << i)) == 0) { + BKE_collection_remove(scene, collections[i]); + } + } + + /* remove bases once and for all */ + for (BaseLegacy *base = scene->base.first; base; base = base->next) { + id_us_min(&base->object->id); + } + BLI_freelistN(&scene->base); + scene->basact = NULL; + } + } + } +} + +void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main) +{ + if (!MAIN_VERSION_ATLEAST(main, 280, 0)) { + if (!DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "render_layers")) { + for (Scene *scene = main->scene.first; scene; scene = scene->id.next) { + /* Master Collection */ + scene->collection = MEM_callocN(sizeof(SceneCollection), "Master Collection"); + BLI_strncpy(scene->collection->name, "Master Collection", sizeof(scene->collection->name)); + } + } + } +} diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 5011f9836b7..4ddf83d306b 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -120,6 +120,7 @@ #include "DNA_key_types.h" #include "DNA_lattice_types.h" #include "DNA_lamp_types.h" +#include "DNA_layer_types.h" #include "DNA_linestyle_types.h" #include "DNA_meta_types.h" #include "DNA_mesh_types.h" @@ -2626,10 +2627,34 @@ static void write_paint(WriteData *wd, Paint *p) } } +static void write_scene_collection(WriteData *wd, SceneCollection *sc) +{ + writestruct(wd, DATA, SceneCollection, 1, sc); + + writelist(wd, DATA, LinkData, &sc->objects); + writelist(wd, DATA, LinkData, &sc->filter_objects); + + for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) { + write_scene_collection(wd, nsc); + } +} + +static void write_layer_collections(WriteData *wd, ListBase *lb) +{ + for (LayerCollection *lc = lb->first; lc; lc = lc->next) { + writestruct(wd, DATA, LayerCollection, 1, lc); + + writelist(wd, DATA, LinkData, &lc->object_bases); + writelist(wd, DATA, CollectionOverride, &lc->overrides); + + write_layer_collections(wd, &lc->layer_collections); + } +} + static void write_scenes(WriteData *wd, ListBase *scebase) { Scene *sce; - Base *base; + BaseLegacy *base; Editing *ed; Sequence *seq; MetaStack *ms; @@ -2641,6 +2666,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase) ToolSettings *tos; FreestyleModuleConfig *fmc; FreestyleLineSet *fls; + SceneLayer *sl; sce = scebase->first; while (sce) { @@ -2656,7 +2682,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase) /* direct data */ base = sce->base.first; while (base) { - writestruct(wd, DATA, Base, 1, base); + writestruct(wd, DATA, BaseLegacy, 1, base); base = base->next; } @@ -2846,6 +2872,14 @@ static void write_scenes(WriteData *wd, ListBase *scebase) write_previews(wd, sce->preview); write_curvemapping_curves(wd, &sce->r.mblur_shutter_curve); + write_scene_collection(wd, sce->collection); + + for (sl = sce->render_layers.first; sl; sl = sl->next) { + writestruct(wd, DATA, SceneLayer, 1, sl); + writelist(wd, DATA, Base, &sl->object_bases); + write_layer_collections(wd, &sl->layer_collections); + } + sce = sce->id.next; } @@ -3167,6 +3201,9 @@ static void write_screens(WriteData *wd, ListBase *scrbase) else if (sl->spacetype == SPACE_INFO) { writestruct(wd, DATA, SpaceInfo, 1, sl); } + else if (sl->spacetype == SPACE_COLLECTIONS) { + writestruct(wd, DATA, SpaceCollections, 1, sl); + } sl = sl->next; } |