diff options
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 88 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 37 |
2 files changed, 114 insertions, 11 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index bf6928b7b20..295ebc15a68 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -76,6 +76,7 @@ #include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" #include "DNA_nla_types.h" +#include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_object_force.h" #include "DNA_object_fluidsim.h" // NT @@ -1205,6 +1206,61 @@ static void test_pointer_array(FileData *fd, void **mat) } } +/* ************ READ NODE TREE *************** */ + +/* ntree is not NULL */ +static void lib_link_nodetree(FileData *fd, ID *id, bNodeTree *ntree) +{ + bNode *node; + + for(node= ntree->nodes.first; node; node= node->next) + node->id= newlibadr_us(fd, id->lib, node->id); +} + +static bNodeTree *direct_link_nodetree(FileData *fd, bNodeTree *ntree) +{ + /* note: writing and reading goes in sync, for speed */ + if(ntree) { + ntree= newdataadr(fd, ntree); + + if(ntree) { + bNode *node; + bNodeSocket *sock; + bNodeLink *link; + + ntree->init= 0; /* to set callbacks */ + ntree->data= NULL; /* safety only */ + + link_list(fd, &ntree->nodes); + for(node= ntree->nodes.first; node; node= node->next) { + node->storage= newdataadr(fd, node->storage); + link_list(fd, &node->inputs); + link_list(fd, &node->outputs); + } + link_list(fd, &ntree->links); + + /* and we connect the rest */ + for(node= ntree->nodes.first; node; node= node->next) { + node->preview= NULL; + node->lasty= 0; + for(sock= node->inputs.first; sock; sock= sock->next) + sock->link= newdataadr(fd, sock->link); + } + for(link= ntree->links.first; link; link= link->next) { + link->fromnode= newdataadr(fd, link->fromnode); + link->tonode= newdataadr(fd, link->tonode); + link->fromsock= newdataadr(fd, link->fromsock); + link->tosock= newdataadr(fd, link->tosock); + } + /* right after read file, the save-undo will need it */ + /* verify also does a full type checking. This is relative slow... so we + might move this later to the do_versions, and put ntreeInitTypes() only here */ + ntreeVerifyTypes(ntree); + } + } + return ntree; +} + /* ************ READ PACKEDFILE *************** */ static PackedFile *direct_link_packedfile(FileData *fd, PackedFile *oldpf) @@ -1993,7 +2049,7 @@ static void lib_link_material(FileData *fd, Main *main) ma->ipo= newlibadr_us(fd, ma->id.lib, ma->ipo); ma->group= newlibadr_us(fd, ma->id.lib, ma->group); - + for(a=0; a<MAX_MTEX; a++) { mtex= ma->mtex[a]; if(mtex) { @@ -2005,7 +2061,10 @@ static void lib_link_material(FileData *fd, Main *main) for (ml=ma->layers.first; ml; ml=ml->next) ml->mat= newlibadr_us(fd, ma->id.lib, ml->mat); - + + if(ma->nodetree) + lib_link_nodetree(fd, &ma->id, ma->nodetree); + ma->id.flag -= LIB_NEEDLINK; } ma= ma->id.next; @@ -2026,7 +2085,8 @@ static void direct_link_material(FileData *fd, Material *ma) direct_link_scriptlink(fd, &ma->scriptlink); link_list(fd, &ma->layers); - + + ma->nodetree= direct_link_nodetree(fd, ma->nodetree); } /* ************ READ MESH ***************** */ @@ -2994,6 +3054,13 @@ void lib_link_screen_restore(Main *newmain, Scene *curscene) ssound->sound= restore_pointer_by_name(newmain, (ID *)ssound->sound, 1); } + else if(sl->spacetype==SPACE_NODE) { + SpaceNode *snode= (SpaceNode *)sl; + + snode->nodetree= NULL; + snode->block= NULL; + snode->flag |= SNODE_DO_PREVIEW; + } } sa= sa->next; } @@ -3088,6 +3155,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc) SpaceNode *snode= (SpaceNode *)sl; snode->nodetree= NULL; snode->block= NULL; + snode->flag |= SNODE_DO_PREVIEW; } } @@ -5115,11 +5183,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main) ma->strand_sta= ma->strand_end= 1.0f; ma->mode |= MA_TANGENT_STR; } - /* remove this test before 2.40 too! pad is set to denote check was done */ - if(ma->pad==0) { - if(ma->mode & MA_TRACEBLE) ma->mode |= MA_SHADBUF; - ma->pad= 1; - } + if(ma->mode & MA_TRACEBLE) ma->mode |= MA_SHADBUF; + /* orange stuff, so should be done for 2.40 too */ if(ma->layers.first==NULL) { ma->ml_flag= ML_RENDER; @@ -5379,6 +5444,13 @@ static void expand_material(FileData *fd, Main *mainvar, Material *ma) if(ml->mat) expand_doit(fd, mainvar, ml->mat); } + + if(ma->nodetree) { + bNode *node; + for(node= ma->nodetree->nodes.first; node; node= node->next) + if(node->id) + expand_doit(fd, mainvar, node->id); + } } static void expand_lamp(FileData *fd, Main *mainvar, Lamp *la) diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 23d9d04ce3b..704215aaa7e 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -124,6 +124,7 @@ Important to know is that 'streaming' has been added to files, for Blender Publi #include "DNA_material_types.h" #include "DNA_modifier_types.h" #include "DNA_nla_types.h" +#include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_object_force.h" #include "DNA_oops_types.h" @@ -153,6 +154,7 @@ Important to know is that 'streaming' has been added to files, for Blender Publi #include "BKE_global.h" // for G #include "BKE_library.h" // for set_listbasepointers #include "BKE_main.h" // G.main +#include "BKE_node.h" #include "BKE_packedFile.h" // for packAll #include "BKE_screen.h" // for waitcursor #include "BKE_scene.h" // for do_seq @@ -317,7 +319,7 @@ static void writestruct(WriteData *wd, int filecode, char *structname, int nr, v BHead bh; short *sp; - if(adr==0 || nr==0) return; + if(adr==NULL || nr==0) return; /* init BHead */ bh.code= filecode; @@ -326,7 +328,7 @@ static void writestruct(WriteData *wd, int filecode, char *structname, int nr, v bh.SDNAnr= dna_findstruct_nr(wd->sdna, structname); if(bh.SDNAnr== -1) { - printf("error: can't find SDNA code %s\n", structname); + printf("error: can't find SDNA code <%s>\n", structname); return; } sp= wd->sdna->structs[bh.SDNAnr]; @@ -360,6 +362,33 @@ static void writedata(WriteData *wd, int filecode, int len, void *adr) /* do not if(len) mywrite(wd, adr, len); } +/* this is only direct data */ +static void write_nodetree(WriteData *wd, bNodeTree *ntree) +{ + bNode *node; + bNodeSocket *sock; + bNodeLink *link; + + writestruct(wd, DATA, "bNodeTree", 1, ntree); + + /* for link_list() speed, we write per list */ + + for(node= ntree->nodes.first; node; node= node->next) + writestruct(wd, DATA, "bNode", 1, node); + + for(node= ntree->nodes.first; node; node= node->next) { + if(node->storage) + writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage); + for(sock= node->inputs.first; sock; sock= sock->next) + writestruct(wd, DATA, "bNodeSocket", 1, sock); + for(sock= node->outputs.first; sock; sock= sock->next) + writestruct(wd, DATA, "bNodeSocket", 1, sock); + } + + for(link= ntree->links.first; link; link= link->next) + writestruct(wd, DATA, "bNodeLink", 1, link); +} + static void write_scriptlink(WriteData *wd, ScriptLink *slink) { writedata(wd, DATA, sizeof(void *)*slink->totscript, slink->scripts); @@ -1014,7 +1043,9 @@ static void write_materials(WriteData *wd, ListBase *idbase) for (ml=ma->layers.first; ml; ml=ml->next) writestruct(wd, DATA, "MaterialLayer", 1, ml); - + + if(ma->nodetree) + write_nodetree(wd, ma->nodetree); } ma= ma->id.next; } |