Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorRobin Allen <roblovski@gmail.com>2009-08-17 22:37:58 +0400
committerRobin Allen <roblovski@gmail.com>2009-08-17 22:37:58 +0400
commit55b6230464a140c62ec4cea4e11a4a05c8910d13 (patch)
tree54c9b5dff1a1f20388275f9e450969406f2af864 /source
parent6aeb2f687ae1d41715351ef265a0e0a9af06121a (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/makesrna/intern/rna_texture.c77
-rw-r--r--source/blender/nodes/intern/TEX_nodes/TEX_output.c63
-rw-r--r--source/blender/nodes/intern/TEX_util.c15
3 files changed, 147 insertions, 8 deletions
diff --git a/source/blender/makesrna/intern/rna_texture.c b/source/blender/makesrna/intern/rna_texture.c
index ccb5e5b2f95..76cb9986306 100644
--- a/source/blender/makesrna/intern/rna_texture.c
+++ b/source/blender/makesrna/intern/rna_texture.c
@@ -36,6 +36,9 @@
#include "DNA_material_types.h"
#include "DNA_texture_types.h"
#include "DNA_world_types.h"
+#include "DNA_node_types.h"
+
+#include "BKE_node.h"
#include "WM_types.h"
@@ -107,6 +110,43 @@ static void rna_TextureSlot_name_get(PointerRNA *ptr, char *str)
strcpy(str, "");
}
+static EnumPropertyItem *rna_TextureSlot_output_node_itemf(bContext *C, PointerRNA *ptr, int *free)
+{
+ MTex *mtex= ptr->data;
+ Tex *tex= mtex->tex;
+ EnumPropertyItem *item= NULL;
+ int totitem= 0;
+
+ if(tex)
+ {
+ bNodeTree *ntree= tex->nodetree;
+ if(ntree)
+ {
+ EnumPropertyItem tmp= {0, "", 0, "", ""};
+ bNode *node;
+
+ tmp.value = 0;
+ tmp.name = "Not Specified";
+ tmp.identifier = "NOT_SPECIFIED";
+ RNA_enum_item_add(&item, &totitem, &tmp);
+
+ for(node= ntree->nodes.first; node; node= node->next) {
+ if(node->type == TEX_NODE_OUTPUT) {
+ tmp.value= node->custom1;
+ tmp.name= ((TexNodeOutput*)node->storage)->name;
+ tmp.identifier = tmp.name;
+ RNA_enum_item_add(&item, &totitem, &tmp);
+ }
+ }
+ }
+ }
+
+ RNA_enum_item_end(&item, &totitem);
+
+ *free = 1;
+ return item;
+}
+
static void rna_Texture_use_color_ramp_set(PointerRNA *ptr, int value)
{
Tex *tex= (Tex*)ptr->data;
@@ -118,6 +158,18 @@ static void rna_Texture_use_color_ramp_set(PointerRNA *ptr, int value)
tex->coba= add_colorband(0);
}
+void rna_Texture_use_nodes_set(PointerRNA *ptr, int v)
+{
+ Tex *tex= (Tex*)ptr->data;
+
+ tex->use_nodes = v;
+ tex->type = 0;
+
+ if(v && tex->nodetree==NULL) {
+ node_texture_default(tex);
+ }
+}
+
static void rna_ImageTexture_mipmap_set(PointerRNA *ptr, int value)
{
Tex *tex= (Tex*)ptr->data;
@@ -287,6 +339,10 @@ static void rna_def_mtex(BlenderRNA *brna)
{MTEX_MAP_MODE_3D, "3D", 0, "3D", ""},
{0, NULL, 0, NULL, NULL}};
+ static EnumPropertyItem output_node_items[] = {
+ {0, "DUMMY", 0, "Dummy", ""},
+ {0, NULL, 0, NULL, NULL}};
+
srna= RNA_def_struct(brna, "TextureSlot", NULL);
RNA_def_struct_sdna(srna, "MTex");
RNA_def_struct_ui_text(srna, "Texture Slot", "Texture slot defining the mapping and influence of a texture.");
@@ -373,6 +429,13 @@ static void rna_def_mtex(BlenderRNA *brna)
RNA_def_property_ui_range(prop, 0, 5, 10, 3);
RNA_def_property_ui_text(prop, "Normal Factor", "Amount texture affects normal values.");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
+
+ prop= RNA_def_property(srna, "output_node", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "which_output");
+ RNA_def_property_enum_items(prop, output_node_items);
+ RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_TextureSlot_output_node_itemf");
+ RNA_def_property_ui_text(prop, "Output Node", "Which output node to use, for node-based textures.");
+ RNA_def_property_update(prop, NC_TEXTURE, NULL);
}
static void rna_def_filter_size_common(StructRNA *srna)
@@ -1285,7 +1348,19 @@ static void rna_def_texture(BlenderRNA *brna)
RNA_def_property_range(prop, 0, 2);
RNA_def_property_ui_text(prop, "RGB Factor", "");
RNA_def_property_update(prop, NC_TEXTURE, NULL);
-
+
+ /* nodetree */
+ prop= RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "use_nodes", 1);
+ RNA_def_property_boolean_funcs(prop, NULL, "rna_Texture_use_nodes_set");
+ RNA_def_property_ui_text(prop, "Use Nodes", "Make this a node-based texture");
+ RNA_def_property_update(prop, NC_TEXTURE, NULL);
+
+ prop= RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
+ RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node-based textures");
+ RNA_def_property_update(prop, NC_TEXTURE, NULL);
+
rna_def_animdata_common(srna);
/* specific types */
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 ++;