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!
This commit is contained in:
2006-12-05 21:33:56 +00:00
parent 5e52bee5a7
commit 09d3d15f45
4 changed files with 68 additions and 2 deletions

View File

@@ -79,6 +79,8 @@ int node_has_hidden_sockets(struct bNode *node);
struct bNode *node_add_node(struct SpaceNode *snode, int type, float locx, float locy);
void node_adduplicate(struct SpaceNode *snode);
void snode_autoconnect(struct SpaceNode *snode, struct bNode *node_to, int flag);
/* ************* drawnode.c *************** */
struct SpaceNode;
struct bNodeLink;

View File

@@ -140,6 +140,8 @@ typedef struct bNode {
#define NODE_ACTIVE_ID 32
#define NODE_DO_OUTPUT 64
#define NODE_GROUP_EDIT 128
/* free test flag, undefined */
#define NODE_TEST 256
typedef struct bNodeLink {
struct bNodeLink *next, *prev;

View File

@@ -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;
}

View File

@@ -198,13 +198,23 @@ static uiBlock *node_selectmenu(void *arg_unused)
void do_node_addmenu(void *arg, int event)
{
SpaceNode *snode= curarea->spacedata.first;
bNode *node;
float locx, locy;
short mval[2];
/* store selection in temp test flag */
for(node= snode->edittree->nodes.first; node; node= node->next) {
if(node->flag & NODE_SELECT) node->flag |= NODE_TEST;
else node->flag &= ~NODE_TEST;
}
getmouseco_areawin(mval);
areamouseco_to_ipoco(G.v2d, mval, &locx, &locy);
node_add_node(snode, event, locx, locy);
node= node_add_node(snode, event, locx, locy);
/* uses test flag */
snode_autoconnect(snode, node, NODE_TEST);
addqueue(curarea->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
BIF_undo_push("Add Node");