diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-06-12 12:28:25 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-06-12 12:28:25 +0400 |
commit | caa59446ab1da8fee812e82cc9fb1b2024d180df (patch) | |
tree | 43917085a52fca9fc07136a07b943ea53f3c4aad | |
parent | c9ddb96750e0fd8b9cc842c992dfeaa523d5a7f1 (diff) |
Reroute node socket types update automatically from connections when possible. This prevents unnecessary conversions and breaking connections when linking incompatible types to the reroute color sockets (point in case: cycles shaders).
-rw-r--r-- | source/blender/nodes/intern/node_common.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index 78d21e5d4e4..24d1bd70e5a 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -853,7 +853,7 @@ static bNodeSocketTemplate node_reroute_out[]= { }; /* simple, only a single input and output here */ -ListBase node_reroute_internal_connect(bNodeTree *ntree, bNode *node) +static ListBase node_reroute_internal_connect(bNodeTree *ntree, bNode *node) { bNodeLink *link; ListBase ret; @@ -876,6 +876,23 @@ ListBase node_reroute_internal_connect(bNodeTree *ntree, bNode *node) return ret; } +static void node_reroute_update(bNodeTree *UNUSED(ntree), bNode *node) +{ + bNodeSocket *input = node->inputs.first; + bNodeSocket *output = node->outputs.first; + int type = SOCK_FLOAT; + + /* determine socket type from unambiguous input/output connection if possible */ + if (input->limit==1 && input->link) + type = input->link->fromsock->type; + else if (output->limit==1 && output->link) + type = output->link->tosock->type; + + /* same type for input/output */ + nodeSocketSetType(input, type); + nodeSocketSetType(output, type); +} + void register_node_type_reroute(bNodeTreeType *ttype) { /* frame type is used for all tree types, needs dynamic allocation */ @@ -884,6 +901,7 @@ void register_node_type_reroute(bNodeTreeType *ttype) node_type_base(ttype, ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT, 0); node_type_socket_templates(ntype, node_reroute_in, node_reroute_out); node_type_internal_connect(ntype, node_reroute_internal_connect); + node_type_update(ntype, node_reroute_update, NULL); ntype->needs_free = 1; nodeRegisterType(ttype, ntype); |