diff options
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 555 |
1 files changed, 23 insertions, 532 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index e4fe3e8da00..56047bb7f4f 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -195,7 +195,6 @@ static void read_libraries(FileData *basefd, ListBase *mainlist); static void *read_struct(FileData *fd, BHead *bh, const char *blockname); static BHead *find_bhead_from_code_name(FileData *fd, const short idcode, const char *name); static BHead *find_bhead_from_idname(FileData *fd, const char *idname); -static bool library_link_idcode_needs_tag_check(const short idcode, const int flag); typedef struct BHeadN { struct BHeadN *next, *prev; @@ -215,13 +214,6 @@ typedef struct BHeadN { * because ID names are used in lookup tables. */ #define BHEAD_USE_READ_ON_DEMAND(bhead) ((bhead)->code == DATA) -/** - * This function ensures that reports are printed, - * in the case of library linking errors this is important! - * - * bit kludge but better than doubling up on prints, - * we could alternatively have a versions of a report function which forces printing - campbell - */ void BLO_reportf_wrap(BlendFileReadReport *reports, eReportType type, const char *format, ...) { char fixed_buf[1024]; /* should be long enough */ @@ -639,7 +631,7 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab // printf("blo_find_main: converted to %s\n", name1); for (m = mainlist->first; m; m = m->next) { - const char *libname = (m->curlib) ? m->curlib->filepath_abs : m->name; + const char *libname = (m->curlib) ? m->curlib->filepath_abs : m->filepath; if (BLI_path_cmp(name1, libname) == 0) { if (G.debug & G_DEBUG) { @@ -998,13 +990,11 @@ static BHead *blo_bhead_read_full(FileData *fd, BHead *thisblock) } #endif /* USE_BHEAD_READ_ON_DEMAND */ -/* Warning! Caller's responsibility to ensure given bhead **is** an ID one! */ const char *blo_bhead_id_name(const FileData *fd, const BHead *bhead) { return (const char *)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_name_offset); } -/* Warning! Caller's responsibility to ensure given bhead **is** an ID one! */ AssetMetaData *blo_bhead_id_asset_data_address(const FileData *fd, const BHead *bhead) { BLI_assert(blo_bhead_is_id_valid_type(bhead)); @@ -1149,6 +1139,10 @@ static int *read_file_thumbnail(FileData *fd) /** \} */ +/* -------------------------------------------------------------------- */ +/** \name File Data API + * \{ */ + static FileData *filedata_new(BlendFileReadReport *reports) { BLI_assert(reports != NULL); @@ -1270,8 +1264,6 @@ static FileData *blo_filedata_from_file_open(const char *filepath, BlendFileRead return blo_filedata_from_file_descriptor(filepath, reports, file); } -/* cannot be called with relative paths anymore! */ -/* on each new library added, it now checks for the current FileData and expands relativeness */ FileData *blo_filedata_from_file(const char *filepath, BlendFileReadReport *reports) { FileData *fd = blo_filedata_from_file_open(filepath, reports); @@ -1412,30 +1404,12 @@ void blo_filedata_free(FileData *fd) /** \name Public Utilities * \{ */ -/** - * Check whether given path ends with a blend file compatible extension - * (`.blend`, `.ble` or `.blend.gz`). - * - * \param str: The path to check. - * \return true is this path ends with a blender file extension. - */ bool BLO_has_bfile_extension(const char *str) { const char *ext_test[4] = {".blend", ".ble", ".blend.gz", NULL}; return BLI_path_extension_check_array(str, ext_test); } -/** - * Try to explode given path into its 'library components' - * (i.e. a .blend file, id type/group, and data-block itself). - * - * \param path: the full path to explode. - * \param r_dir: the string that'll contain path up to blend file itself ('library' path). - * WARNING! Must be #FILE_MAX_LIBEXTRA long (it also stores group and name strings)! - * \param r_group: the string that'll contain 'group' part of the path, if any. May be NULL. - * \param r_name: the string that'll contain data's name part of the path, if any. May be NULL. - * \return true if path contains a blend file. - */ bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name) { /* We might get some data names with slashes, @@ -1496,14 +1470,6 @@ bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, cha return true; } -/** - * Does a very light reading of given .blend file to extract its stored thumbnail. - * - * \param filepath: The path of the file to extract thumbnail from. - * \return The raw thumbnail - * (MEM-allocated, as stored in file, use #BKE_main_thumbnail_to_imbuf() - * to convert it to ImBuf image). - */ BlendThumbnail *BLO_thumbnail_from_file(const char *filepath) { FileData *fd; @@ -1552,7 +1518,6 @@ static void *newdataadr_no_us(FileData *fd, const void *adr) return oldnewmap_lookup_and_inc(fd->datamap, adr, false); } -/* Direct datablocks with global linking. */ void *blo_read_get_new_globaldata_address(FileData *fd, const void *adr) { return oldnewmap_lookup_and_inc(fd->globmap, adr, true); @@ -1574,7 +1539,6 @@ static void *newlibadr(FileData *fd, const void *lib, const void *adr) return oldnewmap_liblookup(fd->libmap, adr, lib); } -/* only lib data */ void *blo_do_versions_newlibadr(FileData *fd, const void *lib, const void *adr) { return newlibadr(fd, lib, adr); @@ -1616,12 +1580,6 @@ static void change_link_placeholder_to_real_ID_pointer(ListBase *mainlist, } } -/* lib linked proxy objects point to our local data, we need - * to clear that pointer before reading the undo memfile since - * the object might be removed, it is set again in reading - * if the local object still exists. - * This is only valid for local proxy objects though, linked ones should not be affected here. - */ void blo_clear_proxy_pointers_from_lib(Main *oldmain) { LISTBASE_FOREACH (Object *, ob, &oldmain->objects) { @@ -1681,8 +1639,6 @@ void blo_make_packed_pointer_map(FileData *fd, Main *oldmain) } } -/* set old main packed data to zero if it has been restored */ -/* this works because freeing old main only happens after this call */ void blo_end_packed_pointer_map(FileData *fd, Main *oldmain) { OldNew *entry = fd->packedmap->entries; @@ -1719,7 +1675,6 @@ void blo_end_packed_pointer_map(FileData *fd, Main *oldmain) } } -/* undo file support: add all library pointers in lookup */ void blo_add_library_pointer_map(ListBase *old_mainlist, FileData *fd) { ListBase *lbarray[INDEX_ID_MAX]; @@ -1736,8 +1691,6 @@ void blo_add_library_pointer_map(ListBase *old_mainlist, FileData *fd) fd->old_mainlist = old_mainlist; } -/* Build a GSet of old main (we only care about local data here, so we can do that after - * split_main() call. */ void blo_make_old_idmap_from_main(FileData *fd, Main *bmain) { if (fd->old_idmap != NULL) { @@ -2771,10 +2724,6 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map, } } -/** - * Used to link a file (without UI) to the current UI. - * Note that it assumes the old pointers in UI are still valid, so old Main is not freed. - */ void blo_lib_link_restore(Main *oldmain, Main *newmain, wmWindowManager *curwm, @@ -2903,7 +2852,7 @@ static void lib_link_library(BlendLibReader *UNUSED(reader), Library *UNUSED(lib * in relation to the blend file. */ static void fix_relpaths_library(const char *basepath, Main *main) { - /* BLO_read_from_memory uses a blank filename */ + /* #BLO_read_from_memory uses a blank file-path. */ if (basepath == NULL || basepath[0] == '\0') { LISTBASE_FOREACH (Library *, lib, &main->libraries) { /* when loading a linked lib into a file which has not been saved, @@ -3557,25 +3506,25 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead) bfd->fileflags = fg->fileflags; bfd->globalf = fg->globalf; - BLI_strncpy(bfd->filename, fg->filename, sizeof(bfd->filename)); + STRNCPY(bfd->filepath, fg->filepath); - /* Error in 2.65 and older: main->name was not set if you save from startup + /* Error in 2.65 and older: `main->filepath` was not set if you save from startup * (not after loading file). */ - if (bfd->filename[0] == 0) { + if (bfd->filepath[0] == 0) { if (fd->fileversion < 265 || (fd->fileversion == 265 && fg->subversion < 1)) { if ((G.fileflags & G_FILE_RECOVER_READ) == 0) { - BLI_strncpy(bfd->filename, BKE_main_blendfile_path(bfd->main), sizeof(bfd->filename)); + STRNCPY(bfd->filepath, BKE_main_blendfile_path(bfd->main)); } } - /* early 2.50 version patch - filename not in FileGlobal struct at all */ + /* early 2.50 version patch - filepath not in FileGlobal struct at all */ if (fd->fileversion <= 250) { - BLI_strncpy(bfd->filename, BKE_main_blendfile_path(bfd->main), sizeof(bfd->filename)); + STRNCPY(bfd->filepath, BKE_main_blendfile_path(bfd->main)); } } if (G.fileflags & G_FILE_RECOVER_READ) { - BLI_strncpy(fd->relabase, fg->filename, sizeof(fd->relabase)); + BLI_strncpy(fd->relabase, fg->filepath, sizeof(fd->relabase)); } bfd->curscreen = fg->curscreen; @@ -3671,7 +3620,7 @@ static void do_versions_after_linking(Main *main, ReportList *reports) CLOG_INFO(&LOG, 2, "Processing %s (%s), %d.%d", - main->curlib ? main->curlib->filepath : main->name, + main->curlib ? main->curlib->filepath : main->filepath, main->curlib ? "LIB" : "MAIN", main->versionfile, main->subversionfile); @@ -3909,7 +3858,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath) if ((fd->skip_flags & BLO_READ_SKIP_DATA) == 0) { BLI_addtail(&mainlist, bfd->main); fd->mainlist = &mainlist; - BLI_strncpy(bfd->main->name, filepath, sizeof(bfd->main->name)); + STRNCPY(bfd->main->filepath, filepath); } if (G.background) { @@ -4384,23 +4333,11 @@ static void expand_id(BlendExpander *expander, ID *id) expand_id_embedded_id(expander, id); } -/** - * Set the callback func used over all ID data found by \a BLO_expand_main func. - * - * \param expand_doit_func: Called for each ID block it finds. - */ void BLO_main_expander(BLOExpandDoitCallback expand_doit_func) { expand_doit = expand_doit_func; } -/** - * Loop over all ID data in Main to mark relations. - * Set (id->tag & LIB_TAG_NEED_EXPAND) to mark expanding. Flags get cleared after expanding. - * - * \param fdhandle: usually filedata, or own handle. - * \param mainvar: the Main database to expand. - */ void BLO_expand_main(void *fdhandle, Main *mainvar) { ListBase *lbarray[INDEX_ID_MAX]; @@ -4441,290 +4378,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) /** \name Library Linking (helper functions) * \{ */ -static bool object_in_any_scene(Main *bmain, Object *ob) -{ - LISTBASE_FOREACH (Scene *, sce, &bmain->scenes) { - if (BKE_scene_object_find(sce, ob)) { - return true; - } - } - - return false; -} - -static bool object_in_any_collection(Main *bmain, Object *ob) -{ - LISTBASE_FOREACH (Collection *, collection, &bmain->collections) { - if (BKE_collection_has_object(collection, ob)) { - return true; - } - } - - LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { - if (scene->master_collection != NULL && - BKE_collection_has_object(scene->master_collection, ob)) { - return true; - } - } - - return false; -} - -/** - * Shared operations to perform on the object's base after adding it to the scene. - */ -static void object_base_instance_init( - Object *ob, ViewLayer *view_layer, const View3D *v3d, const int flag, bool set_active) -{ - Base *base = BKE_view_layer_base_find(view_layer, ob); - - if (v3d != NULL) { - base->local_view_bits |= v3d->local_view_uuid; - } - - if (flag & FILE_AUTOSELECT) { - /* All objects that use #FILE_AUTOSELECT must be selectable (unless linking data). */ - BLI_assert((base->flag & BASE_SELECTABLE) || (flag & FILE_LINK)); - if (base->flag & BASE_SELECTABLE) { - base->flag |= BASE_SELECTED; - } - } - - if (set_active) { - view_layer->basact = base; - } - - BKE_scene_object_base_flag_sync_from_base(base); -} - -/** - * Exported for link/append to create objects as well. - */ -void BLO_object_instantiate_object_base_instance_init(Main *bmain, - Collection *collection, - Object *ob, - ViewLayer *view_layer, - const View3D *v3d, - const int flag, - bool set_active) -{ - /* Auto-select and appending. */ - if ((flag & FILE_AUTOSELECT) && ((flag & FILE_LINK) == 0)) { - /* While in general the object should not be manipulated, - * when the user requests the object to be selected, ensure it's visible and selectable. */ - ob->visibility_flag &= ~(OB_HIDE_VIEWPORT | OB_HIDE_SELECT); - } - - BKE_collection_object_add(bmain, collection, ob); - - object_base_instance_init(ob, view_layer, v3d, flag, set_active); -} - -static void add_loose_objects_to_scene(Main *mainvar, - Main *bmain, - Scene *scene, - ViewLayer *view_layer, - const View3D *v3d, - Library *lib, - const int flag) -{ - Collection *active_collection = NULL; - const bool do_append = (flag & FILE_LINK) == 0; - - BLI_assert(scene); - - /* Give all objects which are LIB_TAG_INDIRECT a base, - * or for a collection when *lib has been set. */ - LISTBASE_FOREACH (Object *, ob, &mainvar->objects) { - /* NOTE: Even if this is a directly linked object and is tagged for instantiation, it might - * have already been instantiated through one of its owner collections, in which case we do not - * want to re-instantiate it in the active collection here. */ - bool do_it = (ob->id.tag & LIB_TAG_DOIT) != 0 && !BKE_scene_object_find(scene, ob); - if (do_it || - ((ob->id.tag & LIB_TAG_INDIRECT) != 0 && (ob->id.tag & LIB_TAG_PRE_EXISTING) == 0)) { - if (do_append) { - if (ob->id.us == 0) { - do_it = true; - } - else if ((ob->id.lib == lib) && !object_in_any_collection(bmain, ob)) { - /* When appending, make sure any indirectly loaded object gets a base, - * when they are not part of any collection yet. */ - do_it = true; - } - } - - if (do_it) { - /* Find or add collection as needed. */ - if (active_collection == NULL) { - if (flag & FILE_ACTIVE_COLLECTION) { - LayerCollection *lc = BKE_layer_collection_get_active(view_layer); - active_collection = lc->collection; - } - else { - active_collection = BKE_collection_add(bmain, scene->master_collection, NULL); - } - } - - CLAMP_MIN(ob->id.us, 0); - ob->mode = OB_MODE_OBJECT; - - /* Do NOT make base active here! screws up GUI stuff, - * if you want it do it at the editor level. */ - const bool set_active = false; - BLO_object_instantiate_object_base_instance_init( - bmain, active_collection, ob, view_layer, v3d, flag, set_active); - - ob->id.tag &= ~LIB_TAG_INDIRECT; - ob->id.flag &= ~LIB_INDIRECT_WEAK_LINK; - ob->id.tag |= LIB_TAG_EXTERN; - } - } - } -} - -static void add_loose_object_data_to_scene(Main *mainvar, - Main *bmain, - Scene *scene, - ViewLayer *view_layer, - const View3D *v3d, - const int flag) -{ - if ((flag & BLO_LIBLINK_OBDATA_INSTANCE) == 0) { - return; - } - - Collection *active_collection = scene->master_collection; - if (flag & FILE_ACTIVE_COLLECTION) { - LayerCollection *lc = BKE_layer_collection_get_active(view_layer); - active_collection = lc->collection; - } - - /* Do not re-instantiate obdata IDs that are already instantiated by an object. */ - LISTBASE_FOREACH (Object *, ob, &mainvar->objects) { - if ((ob->id.tag & LIB_TAG_PRE_EXISTING) == 0 && ob->data != NULL) { - ID *obdata = ob->data; - BLI_assert(ID_REAL_USERS(obdata) > 0); - if ((obdata->tag & LIB_TAG_PRE_EXISTING) == 0) { - obdata->tag &= ~LIB_TAG_DOIT; - } - } - } - - /* Loop over all ID types, instancing object-data for ID types that have support for it. */ - ListBase *lbarray[INDEX_ID_MAX]; - int i = set_listbasepointers(mainvar, lbarray); - while (i--) { - const short idcode = BKE_idtype_idcode_from_index(i); - if (!OB_DATA_SUPPORT_ID(idcode)) { - continue; - } - - LISTBASE_FOREACH (ID *, id, lbarray[i]) { - if (id->tag & LIB_TAG_DOIT) { - const int type = BKE_object_obdata_to_type(id); - BLI_assert(type != -1); - Object *ob = BKE_object_add_only_object(bmain, type, id->name + 2); - ob->data = id; - id_us_plus(id); - BKE_object_materials_test(bmain, ob, ob->data); - - /* Do NOT make base active here! screws up GUI stuff, - * if you want it do it at the editor level. */ - bool set_active = false; - BLO_object_instantiate_object_base_instance_init( - bmain, active_collection, ob, view_layer, v3d, flag, set_active); - - copy_v3_v3(ob->loc, scene->cursor.location); - } - } - } -} - -static void add_collections_to_scene(Main *mainvar, - Main *bmain, - Scene *scene, - ViewLayer *view_layer, - const View3D *v3d, - Library *lib, - const int flag) -{ - Collection *active_collection = scene->master_collection; - if (flag & FILE_ACTIVE_COLLECTION) { - LayerCollection *lc = BKE_layer_collection_get_active(view_layer); - active_collection = lc->collection; - } - - /* Give all objects which are tagged a base. */ - LISTBASE_FOREACH (Collection *, collection, &mainvar->collections) { - if ((flag & BLO_LIBLINK_COLLECTION_INSTANCE) && (collection->id.tag & LIB_TAG_DOIT)) { - /* Any indirect collection should not have been tagged. */ - BLI_assert((collection->id.tag & LIB_TAG_INDIRECT) == 0); - - /* BKE_object_add(...) messes with the selection. */ - Object *ob = BKE_object_add_only_object(bmain, OB_EMPTY, collection->id.name + 2); - ob->type = OB_EMPTY; - ob->empty_drawsize = U.collection_instance_empty_size; - - const bool set_selected = (flag & FILE_AUTOSELECT) != 0; - /* TODO: why is it OK to make this active here but not in other situations? - * See other callers of #object_base_instance_init */ - const bool set_active = set_selected; - BLO_object_instantiate_object_base_instance_init( - bmain, active_collection, ob, view_layer, v3d, flag, set_active); - - DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); - - /* Assign the collection. */ - ob->instance_collection = collection; - id_us_plus(&collection->id); - ob->transflag |= OB_DUPLICOLLECTION; - copy_v3_v3(ob->loc, scene->cursor.location); - } - /* We do not want to force instantiation of indirectly linked collections, - * not even when appending. Users can now easily instantiate collections (and their objects) - * as needed by themselves. See T67032. */ - else if ((collection->id.tag & LIB_TAG_INDIRECT) == 0) { - bool do_add_collection = (collection->id.tag & LIB_TAG_DOIT) != 0; - if (!do_add_collection) { - /* We need to check that objects in that collections are already instantiated in a scene. - * Otherwise, it's better to add the collection to the scene's active collection, than to - * instantiate its objects in active scene's collection directly. See T61141. - * Note that we only check object directly into that collection, - * not recursively into its children. - */ - LISTBASE_FOREACH (CollectionObject *, coll_ob, &collection->gobject) { - Object *ob = coll_ob->ob; - if ((ob->id.tag & (LIB_TAG_PRE_EXISTING | LIB_TAG_DOIT | LIB_TAG_INDIRECT)) == 0 && - (ob->id.lib == lib) && (object_in_any_scene(bmain, ob) == false)) { - do_add_collection = true; - break; - } - } - } - if (do_add_collection) { - /* Add collection as child of active collection. */ - BKE_collection_child_add(bmain, active_collection, collection); - - if (flag & FILE_AUTOSELECT) { - LISTBASE_FOREACH (CollectionObject *, coll_ob, &collection->gobject) { - Object *ob = coll_ob->ob; - Base *base = BKE_view_layer_base_find(view_layer, ob); - if (base) { - base->flag |= BASE_SELECTED; - BKE_scene_object_base_flag_sync_from_base(base); - } - } - } - - /* Those are kept for safety and consistency, but should not be needed anymore? */ - collection->id.tag &= ~LIB_TAG_INDIRECT; - collection->id.flag &= ~LIB_INDIRECT_WEAK_LINK; - collection->id.tag |= LIB_TAG_EXTERN; - } - } - } -} - /* returns true if the item was found * but it may already have already been appended/linked */ static ID *link_named_part( @@ -4774,75 +4427,9 @@ static ID *link_named_part( /* if we found the id but the id is NULL, this is really bad */ BLI_assert(!((bhead != NULL) && (id == NULL))); - /* Tag as loose object (or data associated with objects) - * needing to be instantiated in #LibraryLink_Params.scene. */ - if ((id != NULL) && (flag & BLO_LIBLINK_NEEDS_ID_TAG_DOIT)) { - if (library_link_idcode_needs_tag_check(idcode, flag)) { - id->tag |= LIB_TAG_DOIT; - } - } - return id; } -/** - * Simple reader for copy/paste buffers. - */ -int BLO_library_link_copypaste(Main *mainl, BlendHandle *bh, const uint64_t id_types_mask) -{ - FileData *fd = (FileData *)(bh); - BHead *bhead; - int num_directly_linked = 0; - - for (bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) { - ID *id = NULL; - - if (bhead->code == ENDB) { - break; - } - - if (blo_bhead_is_id_valid_type(bhead) && BKE_idtype_idcode_is_linkable((short)bhead->code) && - (id_types_mask == 0 || - (BKE_idtype_idcode_to_idfilter((short)bhead->code) & id_types_mask) != 0)) { - read_libblock(fd, mainl, bhead, LIB_TAG_NEED_EXPAND | LIB_TAG_EXTERN, false, &id); - num_directly_linked++; - } - - if (id) { - /* sort by name in list */ - ListBase *lb = which_libbase(mainl, GS(id->name)); - id_sort_by_name(lb, id, NULL); - - /* Tag as loose object (or data associated with objects) - * needing to be instantiated (see also #link_named_part and its usage of - * #BLO_LIBLINK_NEEDS_ID_TAG_DOIT above). */ - if (library_link_idcode_needs_tag_check(GS(id->name), BLO_LIBLINK_NEEDS_ID_TAG_DOIT)) { - id->tag |= LIB_TAG_DOIT; - } - - if (bhead->code == ID_OB) { - /* Instead of instancing Base's directly, postpone until after collections are loaded - * otherwise the base's flag is set incorrectly when collections are used */ - Object *ob = (Object *)id; - ob->mode = OB_MODE_OBJECT; - /* ensure add_loose_objects_to_scene runs on this object */ - BLI_assert(id->us == 0); - } - } - } - - return num_directly_linked; -} - -/** - * Link a named data-block from an external blend file. - * - * \param mainl: The main database to link from (not the active one). - * \param bh: The blender file handle. - * \param idcode: The kind of data-block to link. - * \param name: The name of the data-block (without the 2 char ID prefix). - * \return the linked ID when found. - */ ID *BLO_library_link_named_part(Main *mainl, BlendHandle **bh, const short idcode, @@ -4855,41 +4442,10 @@ ID *BLO_library_link_named_part(Main *mainl, /* common routine to append/link something from a library */ -/** - * Checks if the \a idcode needs to be tagged with #LIB_TAG_DOIT when linking/appending. - */ -static bool library_link_idcode_needs_tag_check(const short idcode, const int flag) -{ - if (flag & BLO_LIBLINK_NEEDS_ID_TAG_DOIT) { - /* Always true because of #add_loose_objects_to_scene & #add_collections_to_scene. */ - if (ELEM(idcode, ID_OB, ID_GR)) { - return true; - } - if (flag & BLO_LIBLINK_OBDATA_INSTANCE) { - if (OB_DATA_SUPPORT_ID(idcode)) { - return true; - } - } - } - return false; -} - -/** - * Clears #LIB_TAG_DOIT based on the result of #library_link_idcode_needs_tag_check. - */ -static void library_link_clear_tag(Main *mainvar, const int flag) -{ - for (int i = 0; i < INDEX_ID_MAX; i++) { - const short idcode = BKE_idtype_idcode_from_index(i); - BLI_assert(idcode != -1); - if (library_link_idcode_needs_tag_check(idcode, flag)) { - BKE_main_id_tag_idcode(mainvar, idcode, LIB_TAG_DOIT, false); - } - } -} - -static Main *library_link_begin( - Main *mainvar, FileData **fd, const char *filepath, const int flag, const int id_tag_extra) +static Main *library_link_begin(Main *mainvar, + FileData **fd, + const char *filepath, + const int id_tag_extra) { Main *mainl; @@ -4902,11 +4458,6 @@ static Main *library_link_begin( (*fd)->mainlist = MEM_callocN(sizeof(ListBase), "FileData.mainlist"); - if (flag & BLO_LIBLINK_NEEDS_ID_TAG_DOIT) { - /* Clear for objects and collections instantiating tag. */ - library_link_clear_tag(mainvar, flag); - } - /* make mains */ blo_split_main((*fd)->mainlist, mainvar); @@ -4945,30 +4496,18 @@ void BLO_library_link_params_init_with_context(struct LibraryLink_Params *params { BLO_library_link_params_init(params, bmain, flag, id_tag_extra); if (scene != NULL) { - /* Tagging is needed for instancing. */ - params->flag |= BLO_LIBLINK_NEEDS_ID_TAG_DOIT; - params->context.scene = scene; params->context.view_layer = view_layer; params->context.v3d = v3d; } } -/** - * Initialize the #BlendHandle for linking library data. - * - * \param bh: A blender file handle as returned by - * #BLO_blendhandle_from_file or #BLO_blendhandle_from_memory. - * \param filepath: Used for relative linking, copied to the `lib->filepath`. - * \param params: Settings for linking that don't change from beginning to end of linking. - * \return the library #Main, to be passed to #BLO_library_link_named_part as \a mainl. - */ Main *BLO_library_link_begin(BlendHandle **bh, const char *filepath, const struct LibraryLink_Params *params) { FileData *fd = (FileData *)(*bh); - return library_link_begin(params->bmain, &fd, filepath, params->flag, params->id_tag_extra); + return library_link_begin(params->bmain, &fd, filepath, params->id_tag_extra); } static void split_main_newid(Main *mainptr, Main *main_newid) @@ -4976,7 +4515,7 @@ static void split_main_newid(Main *mainptr, Main *main_newid) /* We only copy the necessary subset of data in this temp main. */ main_newid->versionfile = mainptr->versionfile; main_newid->subversionfile = mainptr->subversionfile; - BLI_strncpy(main_newid->name, mainptr->name, sizeof(main_newid->name)); + STRNCPY(main_newid->filepath, mainptr->filepath); main_newid->curlib = mainptr->curlib; ListBase *lbarray[INDEX_ID_MAX]; @@ -4995,19 +4534,7 @@ static void split_main_newid(Main *mainptr, Main *main_newid) } } -/** - * \param scene: The scene in which to instantiate objects/collections - * (if NULL, no instantiation is done). - * \param v3d: The active 3D viewport. - * (only to define active layers for instantiated objects & collections, can be NULL). - */ -static void library_link_end(Main *mainl, - FileData **fd, - Main *bmain, - const int flag, - Scene *scene, - ViewLayer *view_layer, - const View3D *v3d) +static void library_link_end(Main *mainl, FileData **fd, const int flag) { Main *mainvar; Library *curlib; @@ -5092,22 +4619,6 @@ static void library_link_end(Main *mainl, /* Make all relative paths, relative to the open blend file. */ fix_relpaths_library(BKE_main_blendfile_path(mainvar), mainvar); - /* Give a base to loose objects and collections. - * Only directly linked objects & collections are instantiated by - * #BLO_library_link_named_part & co, - * here we handle indirect ones and other possible edge-cases. */ - if (flag & BLO_LIBLINK_NEEDS_ID_TAG_DOIT) { - /* Should always be true. */ - if (scene != NULL) { - add_collections_to_scene(mainvar, bmain, scene, view_layer, v3d, curlib, flag); - add_loose_objects_to_scene(mainvar, bmain, scene, view_layer, v3d, curlib, flag); - add_loose_object_data_to_scene(mainvar, bmain, scene, view_layer, v3d, flag); - } - - /* Clear objects and collections instantiating tag. */ - library_link_clear_tag(mainvar, flag); - } - /* patch to prevent switch_endian happens twice */ if ((*fd)->flags & FD_FLAGS_SWITCH_ENDIAN) { blo_filedata_free(*fd); @@ -5115,25 +4626,10 @@ static void library_link_end(Main *mainl, } } -/** - * Finalize linking from a given .blend file (library). - * Optionally instance the indirect object/collection in the scene when the flags are set. - * \note Do not use \a bh after calling this function, it may frees it. - * - * \param mainl: The main database to link from (not the active one). - * \param bh: The blender file handle (WARNING! may be freed by this function!). - * \param params: Settings for linking that don't change from beginning to end of linking. - */ void BLO_library_link_end(Main *mainl, BlendHandle **bh, const struct LibraryLink_Params *params) { FileData *fd = (FileData *)(*bh); - library_link_end(mainl, - &fd, - params->bmain, - params->flag, - params->context.scene, - params->context.view_layer, - params->context.v3d); + library_link_end(mainl, &fd, params->flag); *bh = (BlendHandle *)fd; } @@ -5485,11 +4981,6 @@ bool BLO_read_requires_endian_switch(BlendDataReader *reader) return (reader->fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0; } -/** - * Updates all ->prev and ->next pointers of the list elements. - * Updates the list->first and list->last pointers. - * When not NULL, calls the callback on every element. - */ void BLO_read_list_cb(BlendDataReader *reader, ListBase *list, BlendReadListFn callback) { if (BLI_listbase_is_empty(list)) { |