diff options
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 255 |
1 files changed, 184 insertions, 71 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 54b3bca1111..3a5bcc405d3 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -136,6 +136,8 @@ #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND #include "BKE_sound.h" +#include "NOD_socket.h" + //XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes //XXX #include "BIF_filelist.h" // badlevel too, where to move this? - elubie //XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo @@ -2054,10 +2056,21 @@ static void lib_link_nodetree(FileData *fd, Main *main) } } +static void lib_nodetree_init_types_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree) +{ + bNode *node; + + ntreeInitTypes(ntree); + + /* XXX could be replaced by do_versions for new nodes */ + for (node=ntree->nodes.first; node; node=node->next) + node_verify_socket_templates(ntree, node); +} + /* updates group node socket own_index so that * external links to/from the group node are preserved. */ -static void lib_node_do_versions_group(bNode *gnode) +static void lib_node_do_versions_group_indices(bNode *gnode) { bNodeTree *ngroup= (bNodeTree*)gnode->id; bNode *intnode; @@ -2090,92 +2103,101 @@ static void lib_node_do_versions_group(bNode *gnode) } /* updates external links for all group nodes in a tree */ -static void lib_nodetree_do_versions_group(bNodeTree *ntree) +static void lib_nodetree_do_versions_group_indices_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree) { bNode *node; for (node=ntree->nodes.first; node; node=node->next) { if (node->type==NODE_GROUP) { bNodeTree *ngroup= (bNodeTree*)node->id; - if (ngroup && (ngroup->flag & NTREE_DO_VERSIONS)) - lib_node_do_versions_group(node); + if (ngroup && (ngroup->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE)) + lib_node_do_versions_group_indices(node); } } } +/* make an update call for the tree */ +static void lib_nodetree_do_versions_update_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree) +{ + if (ntree->update) + ntreeUpdateTree(ntree); +} + /* verify types for nodes and groups, all data has to be read */ /* open = 0: appending/linking, open = 1: open new file (need to clean out dynamic * typedefs*/ static void lib_verify_nodetree(Main *main, int UNUSED(open)) { - Scene *sce; - Material *ma; - Tex *tx; bNodeTree *ntree; - + int i; + bNodeTreeType *ntreetype; + /* this crashes blender on undo/redo if(open==1) { reinit_nodesystem(); }*/ - /* now create the own typeinfo structs an verify nodes */ - /* here we still assume no groups in groups */ - for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) { - ntreeVerifyTypes(ntree); /* internal nodes, no groups! */ + /* set node->typeinfo pointers */ + for (i=0; i < NUM_NTREE_TYPES; ++i) { + ntreetype= ntreeGetType(i); + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, lib_nodetree_init_types_cb); } + for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) + ntreeInitTypes(ntree); { - /*int has_old_groups=0;*/ /*UNUSED*/ + int has_old_groups=0; /* XXX this should actually be part of do_versions, but since we need * finished library linking, it is not possible there. Instead in do_versions * we have set the NTREE_DO_VERSIONS flag, so at this point we can do the * actual group node updates. */ for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) { - if (ntree->flag & NTREE_DO_VERSIONS) { + if (ntree->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE) { /* this adds copies and links from all unlinked internal sockets to group inputs/outputs. */ - nodeGroupExposeAllSockets(ntree); - /*has_old_groups = 1;*/ /*UNUSED*/ + node_group_expose_all_sockets(ntree); + has_old_groups = 1; } } - /* now verify all types in material trees, groups are set OK now */ - for(ma= main->mat.first; ma; ma= ma->id.next) { - if(ma->nodetree) - lib_nodetree_do_versions_group(ma->nodetree); - } - /* and scene trees */ - for(sce= main->scene.first; sce; sce= sce->id.next) { - if(sce->nodetree) - lib_nodetree_do_versions_group(sce->nodetree); - } - /* and texture trees */ - for(tx= main->tex.first; tx; tx= tx->id.next) { - if(tx->nodetree) - lib_nodetree_do_versions_group(tx->nodetree); + + if (has_old_groups) { + for (i=0; i < NUM_NTREE_TYPES; ++i) { + ntreetype= ntreeGetType(i); + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_group_indices_cb); + } } for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) - ntree->flag &= ~NTREE_DO_VERSIONS; + ntree->flag &= ~NTREE_DO_VERSIONS_GROUP_EXPOSE; } - - /* now verify all types in material trees, groups are set OK now */ - for(ma= main->mat.first; ma; ma= ma->id.next) { - if(ma->nodetree) - ntreeVerifyTypes(ma->nodetree); - } - /* and scene trees */ - for(sce= main->scene.first; sce; sce= sce->id.next) { - if(sce->nodetree) - ntreeVerifyTypes(sce->nodetree); + + /* verify all group user nodes */ + for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) { + ntreeVerifyNodes(main, &ntree->id); } - /* and texture trees */ - for(tx= main->tex.first; tx; tx= tx->id.next) { - if(tx->nodetree) - ntreeVerifyTypes(tx->nodetree); + + /* make update calls where necessary */ + { + for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) + if (ntree->update) + ntreeUpdateTree(ntree); + for (i=0; i < NUM_NTREE_TYPES; ++i) { + ntreetype= ntreeGetType(i); + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_update_cb); + } } } - +static void direct_link_node_socket(FileData *fd, bNodeSocket *sock) +{ + sock->link= newdataadr(fd, sock->link); + sock->storage= newdataadr(fd, sock->storage); + sock->default_value= newdataadr(fd, sock->default_value); + sock->cache= NULL; +} /* ntree itself has been read! */ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) @@ -2187,6 +2209,7 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) ntree->init= 0; /* to set callbacks and force setting types */ ntree->progress= NULL; + ntree->execdata= NULL; ntree->adt= newdataadr(fd, ntree->adt); direct_link_animdata(fd, ntree->adt); @@ -2199,9 +2222,11 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) node->typeinfo= NULL; } + link_list(fd, &node->inputs); + link_list(fd, &node->outputs); + node->storage= newdataadr(fd, node->storage); if(node->storage) { - /* could be handlerized at some point */ if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB)) direct_link_curvemapping(fd, node->storage); @@ -2218,8 +2243,6 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) ((ImageUser *)node->storage)->ok= 1; } } - link_list(fd, &node->inputs); - link_list(fd, &node->outputs); } link_list(fd, &ntree->links); @@ -2229,15 +2252,19 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) /* and we connect the rest */ for(node= ntree->nodes.first; node; node= node->next) { + node->parent = newdataadr(fd, node->parent); node->preview= newimaadr(fd, node->preview); node->lasty= 0; + for(sock= node->inputs.first; sock; sock= sock->next) - sock->link= newdataadr(fd, sock->link); + direct_link_node_socket(fd, sock); for(sock= node->outputs.first; sock; sock= sock->next) - sock->ns.data= NULL; + direct_link_node_socket(fd, sock); } + for(sock= ntree->inputs.first; sock; sock= sock->next) + direct_link_node_socket(fd, sock); for(sock= ntree->outputs.first; sock; sock= sock->next) - sock->link= newdataadr(fd, sock->link); + direct_link_node_socket(fd, sock); for(link= ntree->links.first; link; link= link->next) { link->fromnode= newdataadr(fd, link->fromnode); @@ -5023,15 +5050,22 @@ static void lib_link_screen(FileData *fd, Main *main) SpaceNode *snode= (SpaceNode *)sl; snode->id= newlibadr(fd, sc->id.lib, snode->id); + snode->edittree= NULL; - /* internal data, a bit patchy */ - if(snode->id) { - if(GS(snode->id->name)==ID_MA) - snode->nodetree= ((Material *)snode->id)->nodetree; - else if(GS(snode->id->name)==ID_SCE) - snode->nodetree= ((Scene *)snode->id)->nodetree; - else if(GS(snode->id->name)==ID_TE) - snode->nodetree= ((Tex *)snode->id)->nodetree; + if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) { + /* internal data, a bit patchy */ + snode->nodetree= NULL; + if(snode->id) { + if(GS(snode->id->name)==ID_MA) + snode->nodetree= ((Material *)snode->id)->nodetree; + else if(GS(snode->id->name)==ID_SCE) + snode->nodetree= ((Scene *)snode->id)->nodetree; + else if(GS(snode->id->name)==ID_TE) + snode->nodetree= ((Tex *)snode->id)->nodetree; + } + } + else { + snode->nodetree= newlibadr_us(fd, sc->id.lib, snode->nodetree); } snode->linkdrag.first = snode->linkdrag.last = NULL; @@ -5251,15 +5285,19 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene) snode->id= restore_pointer_by_name(newmain, snode->id, 1); snode->edittree= NULL; - if(snode->id==NULL) + if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) { snode->nodetree= NULL; + if(snode->id) { + if(GS(snode->id->name)==ID_MA) + snode->nodetree= ((Material *)snode->id)->nodetree; + else if(GS(snode->id->name)==ID_SCE) + snode->nodetree= ((Scene *)snode->id)->nodetree; + else if(GS(snode->id->name)==ID_TE) + snode->nodetree= ((Tex *)snode->id)->nodetree; + } + } else { - if(GS(snode->id->name)==ID_MA) - snode->nodetree= ((Material *)snode->id)->nodetree; - else if(GS(snode->id->name)==ID_SCE) - snode->nodetree= ((Scene *)snode->id)->nodetree; - else if(GS(snode->id->name)==ID_TE) - snode->nodetree= ((Tex *)snode->id)->nodetree; + snode->nodetree= restore_pointer_by_name(newmain, &snode->nodetree->id, 1); } } } @@ -5488,7 +5526,6 @@ static void direct_link_screen(FileData *fd, bScreen *sc) snode->gpd= newdataadr(fd, snode->gpd); direct_link_gpencil(fd, snode->gpd); } - snode->nodetree= snode->edittree= NULL; } else if(sl->spacetype==SPACE_TIME) { SpaceTime *stime= (SpaceTime *)sl; @@ -6997,6 +7034,53 @@ static void do_version_bone_roll_256(Bone *bone) do_version_bone_roll_256(child); } +static void do_versions_socket_default_value(bNodeSocket *sock) +{ + bNodeSocketValueFloat *valfloat; + bNodeSocketValueVector *valvector; + bNodeSocketValueRGBA *valrgba; + + if (sock->default_value) + return; + + switch (sock->type) { + case SOCK_FLOAT: + valfloat = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueFloat), "default socket value"); + valfloat->value = sock->ns.vec[0]; + valfloat->min = sock->ns.min; + valfloat->max = sock->ns.max; + valfloat->subtype = PROP_NONE; + break; + case SOCK_VECTOR: + valvector = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueVector), "default socket value"); + copy_v3_v3(valvector->value, sock->ns.vec); + valvector->min = sock->ns.min; + valvector->max = sock->ns.max; + valvector->subtype = PROP_NONE; + break; + case SOCK_RGBA: + valrgba = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueRGBA), "default socket value"); + copy_v4_v4(valrgba->value, sock->ns.vec); + break; + } +} + +static void do_versions_nodetree_default_value(bNodeTree *ntree) +{ + bNode *node; + bNodeSocket *sock; + for (node=ntree->nodes.first; node; node=node->next) { + for (sock=node->inputs.first; sock; sock=sock->next) + do_versions_socket_default_value(sock); + for (sock=node->outputs.first; sock; sock=sock->next) + do_versions_socket_default_value(sock); + } + for (sock=ntree->inputs.first; sock; sock=sock->next) + do_versions_socket_default_value(sock); + for (sock=ntree->outputs.first; sock; sock=sock->next) + do_versions_socket_default_value(sock); +} + static void do_versions(FileData *fd, Library *lib, Main *main) { /* WATCH IT!!!: pointers from libdata have not been converted */ @@ -11648,7 +11732,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) * is done in lib_verify_nodetree, because at this point the internal * nodes may not be up-to-date! (missing lib-link) */ - ntree->flag |= NTREE_DO_VERSIONS; + ntree->flag |= NTREE_DO_VERSIONS_GROUP_EXPOSE; } } @@ -11773,10 +11857,10 @@ static void do_versions(FileData *fd, Library *lib, Main *main) if(tex->pd) { if (tex->pd->falloff_speed_scale == 0.0f) tex->pd->falloff_speed_scale = 100.0f; - + if (!tex->pd->falloff_curve) { tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1); - + tex->pd->falloff_curve->preset = CURVE_PRESET_LINE; tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE; curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE); @@ -11927,6 +12011,35 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } + if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 2)){ + { + /* Convert default socket values from bNodeStack */ + Scene *sce; + Material *mat; + Tex *tex; + bNodeTree *ntree; + for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) { + do_versions_nodetree_default_value(ntree); + ntree->update |= NTREE_UPDATE; + } + for (sce=main->scene.first; sce; sce=sce->id.next) + if (sce->nodetree) { + do_versions_nodetree_default_value(sce->nodetree); + sce->nodetree->update |= NTREE_UPDATE; + } + for (mat=main->mat.first; mat; mat=mat->id.next) + if (mat->nodetree) { + do_versions_nodetree_default_value(mat->nodetree); + mat->nodetree->update |= NTREE_UPDATE; + } + for (tex=main->tex.first; tex; tex=tex->id.next) + if (tex->nodetree) { + do_versions_nodetree_default_value(tex->nodetree); + tex->nodetree->update |= NTREE_UPDATE; + } + } + } + /* put compatibility code here until next subversion bump */ { |