Merged changes in the trunk up to revision 36757.
This commit is contained in:
@@ -138,7 +138,6 @@
|
||||
//XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo
|
||||
#include "BLO_readfile.h"
|
||||
#include "BLO_undofile.h"
|
||||
#include "BLO_readblenfile.h" // streaming read pipe, for BLO_readblenfile BLO_readblenfilememory
|
||||
|
||||
#include "readfile.h"
|
||||
|
||||
@@ -489,13 +488,13 @@ static void read_file_version(FileData *fd, Main *main)
|
||||
}
|
||||
|
||||
|
||||
static Main *blo_find_main(FileData *fd, ListBase *mainlist, const char *name, const char *relabase)
|
||||
static Main *blo_find_main(FileData *fd, ListBase *mainlist, const char *filepath, const char *relabase)
|
||||
{
|
||||
Main *m;
|
||||
Library *lib;
|
||||
char name1[FILE_MAXDIR+FILE_MAXFILE];
|
||||
|
||||
strncpy(name1, name, sizeof(name1)-1);
|
||||
BLI_strncpy(name1, filepath, sizeof(name1));
|
||||
cleanup_path(relabase, name1);
|
||||
// printf("blo_find_main: original in %s\n", name);
|
||||
// printf("blo_find_main: converted to %s\n", name1);
|
||||
@@ -513,14 +512,14 @@ static Main *blo_find_main(FileData *fd, ListBase *mainlist, const char *name, c
|
||||
BLI_addtail(mainlist, m);
|
||||
|
||||
lib= alloc_libblock(&m->library, ID_LI, "lib");
|
||||
strncpy(lib->name, name, sizeof(lib->name)-1);
|
||||
strncpy(lib->name, filepath, sizeof(lib->name)-1);
|
||||
BLI_strncpy(lib->filepath, name1, sizeof(lib->filepath));
|
||||
|
||||
m->curlib= lib;
|
||||
|
||||
read_file_version(fd, m);
|
||||
|
||||
if(G.f & G_DEBUG) printf("blo_find_main: added new lib %s\n", name);
|
||||
if(G.f & G_DEBUG) printf("blo_find_main: added new lib %s\n", filepath);
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -946,14 +945,14 @@ static FileData *blo_decode_and_check(FileData *fd, ReportList *reports)
|
||||
|
||||
/* cannot be called with relative paths anymore! */
|
||||
/* on each new library added, it now checks for the current FileData and expands relativeness */
|
||||
FileData *blo_openblenderfile(const char *name, ReportList *reports)
|
||||
FileData *blo_openblenderfile(const char *filepath, ReportList *reports)
|
||||
{
|
||||
gzFile gzfile;
|
||||
errno= 0;
|
||||
gzfile= gzopen(name, "rb");
|
||||
gzfile= gzopen(filepath, "rb");
|
||||
|
||||
if (gzfile == (gzFile)Z_NULL) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Unable to open \"%s\": %s.", name, errno ? strerror(errno) : "Unknown error reading file");
|
||||
BKE_reportf(reports, RPT_ERROR, "Unable to open \"%s\": %s.", filepath, errno ? strerror(errno) : "Unknown error reading file");
|
||||
return NULL;
|
||||
} else {
|
||||
FileData *fd = filedata_new();
|
||||
@@ -961,7 +960,7 @@ FileData *blo_openblenderfile(const char *name, ReportList *reports)
|
||||
fd->read = fd_read_gzip_from_file;
|
||||
|
||||
/* needed for library_append and read_libraries */
|
||||
BLI_strncpy(fd->relabase, name, sizeof(fd->relabase));
|
||||
BLI_strncpy(fd->relabase, filepath, sizeof(fd->relabase));
|
||||
|
||||
return blo_decode_and_check(fd, reports);
|
||||
}
|
||||
@@ -1585,7 +1584,7 @@ static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_p
|
||||
|
||||
if (prv) {
|
||||
int i;
|
||||
for (i=0; i < PREVIEW_MIPMAPS; ++i) {
|
||||
for (i=0; i < NUM_ICON_SIZES; ++i) {
|
||||
if (prv->rect[i]) {
|
||||
prv->rect[i] = newdataadr(fd, prv->rect[i]);
|
||||
}
|
||||
@@ -3969,7 +3968,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
|
||||
|
||||
fluidmd->fss= newdataadr(fd, fluidmd->fss);
|
||||
fluidmd->fss->fmd= fluidmd;
|
||||
fluidmd->fss->meshSurfNormals = NULL;
|
||||
fluidmd->fss->meshVelocities = NULL;
|
||||
}
|
||||
else if (md->type==eModifierType_Smoke) {
|
||||
SmokeModifierData *smd = (SmokeModifierData*) md;
|
||||
@@ -5526,20 +5525,31 @@ static void lib_link_library(FileData *UNUSED(fd), Main *main)
|
||||
}
|
||||
}
|
||||
|
||||
/* Always call this once you havbe loaded new library data to set the relative paths correctly in relation to the blend file */
|
||||
/* Always call this once you have loaded new library data to set the relative paths correctly in relation to the blend file */
|
||||
static void fix_relpaths_library(const char *basepath, Main *main)
|
||||
{
|
||||
Library *lib;
|
||||
/* BLO_read_from_memory uses a blank filename */
|
||||
if (basepath==NULL || basepath[0] == '\0')
|
||||
return;
|
||||
|
||||
for(lib= main->library.first; lib; lib= lib->id.next) {
|
||||
/* Libraries store both relative and abs paths, recreate relative paths,
|
||||
* relative to the blend file since indirectly linked libs will be relative to their direct linked library */
|
||||
if (strncmp(lib->name, "//", 2)==0) { /* if this is relative to begin with? */
|
||||
strncpy(lib->name, lib->filepath, sizeof(lib->name));
|
||||
BLI_path_rel(lib->name, basepath);
|
||||
if (basepath==NULL || basepath[0] == '\0') {
|
||||
for(lib= main->library.first; lib; lib= lib->id.next) {
|
||||
/* when loading a linked lib into a file which has not been saved,
|
||||
* there is nothing we can be relative to, so instead we need to make
|
||||
* it absolute. This can happen when appending an object with a relative
|
||||
* link into an unsaved blend file. See [#27405].
|
||||
* The remap relative option will make it relative again on save - campbell */
|
||||
if (strncmp(lib->name, "//", 2)==0) {
|
||||
strncpy(lib->name, lib->filepath, sizeof(lib->name));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(lib= main->library.first; lib; lib= lib->id.next) {
|
||||
/* Libraries store both relative and abs paths, recreate relative paths,
|
||||
* relative to the blend file since indirectly linked libs will be relative to their direct linked library */
|
||||
if (strncmp(lib->name, "//", 2)==0) { /* if this is relative to begin with? */
|
||||
strncpy(lib->name, lib->filepath, sizeof(lib->name));
|
||||
BLI_path_rel(lib->name, basepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9774,7 +9784,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
|
||||
|
||||
fluidmd->fss->lastgoodframe = INT_MAX;
|
||||
fluidmd->fss->flag = 0;
|
||||
fluidmd->fss->meshSurfNormals = NULL;
|
||||
fluidmd->fss->meshVelocities = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11891,7 +11901,7 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead)
|
||||
return bhead;
|
||||
}
|
||||
|
||||
BlendFileData *blo_read_file_internal(FileData *fd, const char *filename)
|
||||
BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
|
||||
{
|
||||
BHead *bhead= blo_firstbhead(fd);
|
||||
BlendFileData *bfd;
|
||||
@@ -11903,7 +11913,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filename)
|
||||
bfd->main->versionfile= fd->fileversion;
|
||||
|
||||
bfd->type= BLENFILETYPE_BLEND;
|
||||
strncpy(bfd->main->name, filename, sizeof(bfd->main->name)-1);
|
||||
strncpy(bfd->main->name, filepath, sizeof(bfd->main->name)-1);
|
||||
|
||||
while(bhead) {
|
||||
switch(bhead->code) {
|
||||
@@ -12954,7 +12964,7 @@ static void give_base_to_groups(Main *mainvar, Scene *scene)
|
||||
|
||||
/* returns true if the item was found
|
||||
* but it may already have already been appended/linked */
|
||||
static int append_named_part(const bContext *C, Main *mainl, FileData *fd, const char *name, int idcode, short flag)
|
||||
static int append_named_part(const bContext *C, Main *mainl, FileData *fd, const char *idname, int idcode, short flag)
|
||||
{
|
||||
Scene *scene= CTX_data_scene(C);
|
||||
Object *ob;
|
||||
@@ -12969,9 +12979,9 @@ static int append_named_part(const bContext *C, Main *mainl, FileData *fd, const
|
||||
|
||||
if(bhead->code==ENDB) endloop= 1;
|
||||
else if(bhead->code==idcode) {
|
||||
char *idname= bhead_id_name(fd, bhead);
|
||||
const char *idname_test= bhead_id_name(fd, bhead);
|
||||
|
||||
if(strcmp(idname+2, name)==0) {
|
||||
if(strcmp(idname_test + 2, idname)==0) {
|
||||
found= 1;
|
||||
id= is_yet_read(fd, mainl, bhead);
|
||||
if(id==NULL) {
|
||||
@@ -13023,10 +13033,10 @@ static int append_named_part(const bContext *C, Main *mainl, FileData *fd, const
|
||||
return found;
|
||||
}
|
||||
|
||||
int BLO_library_append_named_part(const bContext *C, Main *mainl, BlendHandle** bh, const char *name, int idcode, short flag)
|
||||
int BLO_library_append_named_part(const bContext *C, Main *mainl, BlendHandle** bh, const char *idname, int idcode, short flag)
|
||||
{
|
||||
FileData *fd= (FileData*)(*bh);
|
||||
return append_named_part(C, mainl, fd, name, idcode, flag);
|
||||
return append_named_part(C, mainl, fd, idname, idcode, flag);
|
||||
}
|
||||
|
||||
static void append_id_part(FileData *fd, Main *mainvar, ID *id, ID **id_r)
|
||||
@@ -13051,7 +13061,7 @@ 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, char *dir)
|
||||
static Main* library_append_begin(const bContext *C, FileData **fd, const char *filepath)
|
||||
{
|
||||
Main *mainvar= CTX_data_main(C);
|
||||
Main *mainl;
|
||||
@@ -13060,7 +13070,7 @@ static Main* library_append_begin(const bContext *C, FileData **fd, char *dir)
|
||||
blo_split_main(&(*fd)->mainlist, mainvar);
|
||||
|
||||
/* which one do we need? */
|
||||
mainl = blo_find_main(*fd, &(*fd)->mainlist, dir, G.main->name);
|
||||
mainl = blo_find_main(*fd, &(*fd)->mainlist, filepath, G.main->name);
|
||||
|
||||
/* needed for do_version */
|
||||
mainl->versionfile= (*fd)->fileversion;
|
||||
@@ -13069,10 +13079,10 @@ static Main* library_append_begin(const bContext *C, FileData **fd, char *dir)
|
||||
return mainl;
|
||||
}
|
||||
|
||||
Main* BLO_library_append_begin(const bContext *C, BlendHandle** bh, char *dir)
|
||||
Main* BLO_library_append_begin(const bContext *C, BlendHandle** bh, const char *filepath)
|
||||
{
|
||||
FileData *fd= (FileData*)(*bh);
|
||||
return library_append_begin(C, &fd, dir);
|
||||
return library_append_begin(C, &fd, filepath);
|
||||
}
|
||||
|
||||
static void append_do_cursor(Scene *scene, Library *curlib, short flag)
|
||||
@@ -13194,30 +13204,10 @@ void BLO_library_append_end(const bContext *C, struct Main *mainl, BlendHandle**
|
||||
*bh= (BlendHandle*)fd;
|
||||
}
|
||||
|
||||
/* this is a version of BLO_library_append needed by the BPython API, so
|
||||
* scripts can load data from .blend files -- see Blender.Library module.*/
|
||||
/* append to scene */
|
||||
/* this should probably be moved into the Python code anyway */
|
||||
/* tentatively removed, Python should be able to use the split functions too: */
|
||||
/* BLO_library_append_begin, BLO_library_append_end, BLO_library_append_named_part */
|
||||
#if 0
|
||||
void BLO_script_library_append(BlendHandle **bh, char *dir, const char *name,
|
||||
int idcode, short flag, Main *mainvar, Scene *scene, ReportList *reports)
|
||||
void *BLO_library_read_struct(FileData *fd, BHead *bh, const char *blockname)
|
||||
{
|
||||
FileData *fd= (FileData*)(*bh);
|
||||
|
||||
/* try to append the requested object */
|
||||
fd->reports= reports;
|
||||
library_append(mainvar, scene, name, dir, idcode, 0, &fd, NULL, 0, flag );
|
||||
if(fd) fd->reports= NULL;
|
||||
|
||||
/* do we need to do this? */
|
||||
if(scene)
|
||||
DAG_scene_sort(bmain, scene);
|
||||
|
||||
*bh= (BlendHandle*)fd;
|
||||
return read_struct(fd, bh, blockname);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ************* READ LIBRARY ************** */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user