From 55b6230464a140c62ec4cea4e11a4a05c8910d13 Mon Sep 17 00:00:00 2001 From: Robin Allen Date: Mon, 17 Aug 2009 18:37:58 +0000 Subject: Made texture nodes accessible in the interface. * Exposed Tex.use_nodes, Tex.nodetree, MTex.which_output in RNA * Added node controls to texture buttons (Use Nodes and Use Output) * Made new texture outputs have unique names by default, though unique names still aren't required. Note: The preview window in the texture buttons only takes which_output into account when in "material" mode, and in the material half of "both" mode; the plain texture display ignores the user's output choice. This is because ED_preview_draw draws a Tex* and not an MTex* -- still some work to do here. --- source/blender/nodes/intern/TEX_nodes/TEX_output.c | 63 ++++++++++++++++++++-- 1 file changed, 58 insertions(+), 5 deletions(-) (limited to 'source/blender/nodes/intern/TEX_nodes') 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 }; -- cgit v1.2.3