diff options
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r-- | source/blender/blenloader/BLO_readfile.h | 16 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 88 |
2 files changed, 31 insertions, 73 deletions
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index 85d4b936c51..47931477728 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -211,7 +211,16 @@ int BLO_has_bfile_extension(char *str); */ int BLO_is_a_library(const char *path, char *dir, char *group); -struct Main* BLO_library_append_begin(const struct bContext *C, BlendHandle** bh, const char *filepath); + +/** + * Initialize the BlendHandle for appending or linking library data. + * + * @param mainvar The current main database eg G.main or CTX_data_main(C). + * @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->name + * @return the library Main, to be passed to BLO_library_append_named_part as mainl. + */ +struct Main* BLO_library_append_begin(struct Main *mainvar, BlendHandle** bh, const char *filepath); /** @@ -243,11 +252,6 @@ void BLO_library_append_end(const struct bContext *C, struct Main *mainl, BlendH void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const char *blockname); -/* deprecated */ -#if 1 -void BLO_script_library_append(BlendHandle **bh, char *dir, char *name, int idcode, short flag, struct Main *mainvar, struct Scene *scene, struct ReportList *reports); -#endif - BlendFileData* blo_read_blendafterruntime(int file, char *name, int actualsize, struct ReportList *reports); #ifdef __cplusplus diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 2c287441f38..a76353fa0c7 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -13041,9 +13041,8 @@ static void append_id_part(FileData *fd, Main *mainvar, ID *id, ID **id_r) /* common routine to append/link something from a library */ -static Main* library_append_begin(const bContext *C, FileData **fd, const char *filepath) +static Main* library_append_begin(Main *mainvar, FileData **fd, const char *filepath) { - Main *mainvar= CTX_data_main(C); Main *mainl; /* make mains */ @@ -13059,64 +13058,17 @@ static Main* library_append_begin(const bContext *C, FileData **fd, const char * return mainl; } -Main* BLO_library_append_begin(const bContext *C, BlendHandle** bh, const char *filepath) +Main* BLO_library_append_begin(Main *mainvar, BlendHandle** bh, const char *filepath) { FileData *fd= (FileData*)(*bh); - return library_append_begin(C, &fd, filepath); + return library_append_begin(mainvar, &fd, filepath); } -static void append_do_cursor(Scene *scene, Library *curlib, short flag) -{ - Base *centerbase; - Object *ob; - float *curs, centerloc[3], vec[3], min[3], max[3]; - int count= 0; - - /* when not linking (appending)... */ - if(flag & FILE_LINK) - return; - - /* we're not appending at cursor */ - if((flag & FILE_ATCURSOR) == 0) - return; - - /* find the center of everything appended */ - INIT_MINMAX(min, max); - centerbase= (scene->base.first); - while(centerbase) { - if(centerbase->object->id.lib==curlib && centerbase->object->parent==NULL) { - VECCOPY(vec, centerbase->object->loc); - DO_MINMAX(vec, min, max); - count++; - } - centerbase= centerbase->next; - } - /* we haven't found any objects to move to cursor */ - if(!count) - return; - - /* move from the center of the appended objects to cursor */ - mid_v3_v3v3(centerloc, min, max); - curs = scene->cursor; - VECSUB(centerloc,curs,centerloc); - - /* now translate the center of the objects */ - centerbase= (scene->base.first); - while(centerbase) { - if(centerbase->object->id.lib==curlib && centerbase->object->parent==NULL) { - ob= centerbase->object; - ob->loc[0] += centerloc[0]; - ob->loc[1] += centerloc[1]; - ob->loc[2] += centerloc[2]; - } - centerbase= centerbase->next; - } -} +/* Context == NULL signifies not to do any scene manipulation */ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, int idcode, short flag) { Main *mainvar; - Scene *scene= CTX_data_scene(C); Library *curlib; /* make main consistent */ @@ -13145,22 +13097,26 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in lib_verify_nodetree(mainvar, FALSE); fix_relpaths_library(G.main->name, 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 */ - if(scene) { - const short is_link= (flag & FILE_LINK) != 0; - if(idcode==ID_SCE) { - /* dont instance anything when linking in scenes, assume the scene its self instances the data */ - } - else { - give_base_to_objects(mainvar, scene, curlib, idcode, is_link); + if(C) { + Scene *scene= CTX_data_scene(C); - if (flag & FILE_GROUP_INSTANCE) { - give_base_to_groups(mainvar, scene); + /* give a base to loose objects. If group append, do it for objects too */ + if(scene) { + const short is_link= (flag & FILE_LINK) != 0; + if(idcode==ID_SCE) { + /* dont instance anything when linking in scenes, assume the scene its self instances the data */ + } + else { + give_base_to_objects(mainvar, scene, curlib, idcode, is_link); + + if (flag & FILE_GROUP_INSTANCE) { + give_base_to_groups(mainvar, scene); + } } } - } - else { - printf("library_append_end, scene is NULL (objects wont get bases)\n"); + else { + printf("library_append_end, scene is NULL (objects wont get bases)\n"); + } } /* has been removed... erm, why? s..ton) */ /* 20040907: looks like they are give base already in append_named_part(); -Nathan L */ @@ -13171,8 +13127,6 @@ static void library_append_end(const bContext *C, Main *mainl, FileData **fd, in blo_freefiledata( *fd ); *fd = NULL; } - - append_do_cursor(scene, curlib, flag); } void BLO_library_append_end(const bContext *C, struct Main *mainl, BlendHandle** bh, int idcode, short flag) |