diff options
author | Ton Roosendaal <ton@blender.org> | 2006-12-06 00:33:56 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2006-12-06 00:33:56 +0300 |
commit | 09d3d15f45dfd2685253d5edd49566e2eab5ec4e (patch) | |
tree | a721f5784605f39362202f2ccccd95343f29263e /source/blender/src/editnode.c | |
parent | 5e52bee5a7ba17e31d5195ad59913429a05457d4 (diff) |
Node editor: when adding a new node, automatic links are created:
- from all selected nodes
- only connections between highest order socket types; so if there's RGBA
and Value sockets, only RGBA sockets are connected. This because in
these cases the Value sockets usually are for user input.
Example: Mix node.
Thanks Trip for the hint!
Diffstat (limited to 'source/blender/src/editnode.c')
-rw-r--r-- | source/blender/src/editnode.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/source/blender/src/editnode.c b/source/blender/src/editnode.c index 245a4a5339a..11c6cf83705 100644 --- a/source/blender/src/editnode.c +++ b/source/blender/src/editnode.c @@ -1380,6 +1380,58 @@ void node_border_select(SpaceNode *snode) /* ****************** Add *********************** */ +void snode_autoconnect(SpaceNode *snode, bNode *node_to, int flag) +{ + bNodeSocket *sock, *sockfrom[8]; + bNode *node, *nodefrom[8]; + int totsock= 0, socktype=0; + + if(node_to->inputs.first==NULL) + return; + + /* no inputs for node allowed (code it) */ + + /* connect first 1 socket type now */ + for(sock= node_to->inputs.first; sock; sock= sock->next) + if(socktype<sock->type) + socktype= sock->type; + + + /* find potential sockets, max 8 should work */ + for(node= snode->edittree->nodes.first; node; node= node->next) { + if((node->flag & flag) && node!=node_to) { + for(sock= node->outputs.first; sock; sock= sock->next) { + if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) { + sockfrom[totsock]= sock; + nodefrom[totsock]= node; + totsock++; + if(totsock>7) + break; + } + } + } + if(totsock>7) + break; + } + + /* now just get matching socket types and create links */ + for(sock= node_to->inputs.first; sock; sock= sock->next) { + int a; + + for(a=0; a<totsock; a++) { + if(sockfrom[a]) { + if(sock->type==sockfrom[a]->type && sock->type==socktype) { + nodeAddLink(snode->edittree, nodefrom[a], sockfrom[a], node_to, sock); + sockfrom[a]= NULL; + break; + } + } + } + } + + ntreeSolveOrder(snode->edittree); +} + /* can be called from menus too, but they should do own undopush and redraws */ bNode *node_add_node(SpaceNode *snode, int type, float locx, float locy) { @@ -1421,7 +1473,7 @@ bNode *node_add_node(SpaceNode *snode, int type, float locx, float locy) if(snode->nodetree->type==NTREE_COMPOSIT) ntreeCompositForceHidden(G.scene->nodetree); - + } return node; } |