diff options
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/intern/TEX_nodes/TEX_output.c | 63 | ||||
-rw-r--r-- | source/blender/nodes/intern/TEX_util.c | 15 |
2 files changed, 71 insertions, 7 deletions
diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_output.c b/source/blender/nodes/intern/TEX_nodes/TEX_output.c index 060ea8d7e67..d0538d11900 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_output.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_output.c @@ -64,11 +64,64 @@ static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) } } -static void init(bNode* node) +static void unique_name(bNode *node) { - TexNodeOutput *tno = MEM_callocN(sizeof(TexNodeOutput), "TEX_output"); - strcpy(tno->name, "Default"); - node->storage= tno; + TexNodeOutput *tno = (TexNodeOutput *)node->storage; + char *new_name = 0; + int new_len; + int suffix; + bNode *i; + char *name = tno->name; + + i = node; + while(i->prev) i = i->prev; + for(; i; i=i->next) { + if( + i == node || + i->type != TEX_NODE_OUTPUT || + strcmp(name, ((TexNodeOutput*)(i->storage))->name) + ) + continue; + + if(!new_name) { + int len = strlen(name); + if(len >= 4 && sscanf(name + len - 4, ".%03d", &suffix) == 1) { + new_len = len; + } else { + suffix = 0; + new_len = len + 4; + if(new_len > 31) + new_len = 31; + } + + new_name = malloc(new_len + 1); + strcpy(new_name, name); + name = new_name; + } + sprintf(new_name + new_len - 4, ".%03d", ++suffix); + } + + if(new_name) { + strcpy(tno->name, new_name); + free(new_name); + } +} + +static void init(bNode *node) +{ + TexNodeOutput *tno = MEM_callocN(sizeof(TexNodeOutput), "TEX_output"); + node->storage= tno; + + strcpy(tno->name, "Default"); + unique_name(node); + ntreeTexAssignIndex(0, node); +} + +static void copy(bNode *orig, bNode *new) +{ + node_copy_standard_storage(orig, new); + unique_name(new); + ntreeTexAssignIndex(0, new); } @@ -85,6 +138,6 @@ bNodeType tex_node_output= { /* butfunc */ NULL, /* initfunc */ init, /* freestoragefunc */ node_free_standard_storage, - /* copystoragefunc */ node_copy_standard_storage, + /* copystoragefunc */ copy, /* id */ NULL }; diff --git a/source/blender/nodes/intern/TEX_util.c b/source/blender/nodes/intern/TEX_util.c index 867e754f960..d25decd4111 100644 --- a/source/blender/nodes/intern/TEX_util.c +++ b/source/blender/nodes/intern/TEX_util.c @@ -197,6 +197,10 @@ void ntreeTexExecTree(bNodeTree *nodes, TexResult *texres, float *coord, char do TexResult dummy_texres; TexCallData data; + /* 0 means don't care, so just use first */ + if(which_output == 0) + which_output = 1; + if(!texres) texres = &dummy_texres; data.coord = coord; data.target = texres; @@ -270,10 +274,17 @@ char* ntreeTexOutputMenu(bNodeTree *ntree) void ntreeTexAssignIndex(struct bNodeTree *ntree, struct bNode *node) { bNode *tnode; - int index = 0; + int index = 1; + + if(ntree) + tnode = ntree->nodes.first; + else { + tnode = node; + while(tnode->prev) tnode = tnode->prev; + } check_index: - for(tnode= ntree->nodes.first; tnode; tnode= tnode->next) + for(; tnode; tnode= tnode->next) if(tnode->type == TEX_NODE_OUTPUT && tnode != node) if(tnode->custom1 == index) { index ++; |