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:
@@ -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);
|
struct bNode *node_add_node(struct SpaceNode *snode, int type, float locx, float locy);
|
||||||
void node_adduplicate(struct SpaceNode *snode);
|
void node_adduplicate(struct SpaceNode *snode);
|
||||||
|
|
||||||
|
void snode_autoconnect(struct SpaceNode *snode, struct bNode *node_to, int flag);
|
||||||
|
|
||||||
/* ************* drawnode.c *************** */
|
/* ************* drawnode.c *************** */
|
||||||
struct SpaceNode;
|
struct SpaceNode;
|
||||||
struct bNodeLink;
|
struct bNodeLink;
|
||||||
|
|||||||
@@ -140,6 +140,8 @@ typedef struct bNode {
|
|||||||
#define NODE_ACTIVE_ID 32
|
#define NODE_ACTIVE_ID 32
|
||||||
#define NODE_DO_OUTPUT 64
|
#define NODE_DO_OUTPUT 64
|
||||||
#define NODE_GROUP_EDIT 128
|
#define NODE_GROUP_EDIT 128
|
||||||
|
/* free test flag, undefined */
|
||||||
|
#define NODE_TEST 256
|
||||||
|
|
||||||
typedef struct bNodeLink {
|
typedef struct bNodeLink {
|
||||||
struct bNodeLink *next, *prev;
|
struct bNodeLink *next, *prev;
|
||||||
|
|||||||
@@ -1380,6 +1380,58 @@ void node_border_select(SpaceNode *snode)
|
|||||||
|
|
||||||
/* ****************** Add *********************** */
|
/* ****************** 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 */
|
/* 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)
|
bNode *node_add_node(SpaceNode *snode, int type, float locx, float locy)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -198,12 +198,22 @@ static uiBlock *node_selectmenu(void *arg_unused)
|
|||||||
void do_node_addmenu(void *arg, int event)
|
void do_node_addmenu(void *arg, int event)
|
||||||
{
|
{
|
||||||
SpaceNode *snode= curarea->spacedata.first;
|
SpaceNode *snode= curarea->spacedata.first;
|
||||||
|
bNode *node;
|
||||||
float locx, locy;
|
float locx, locy;
|
||||||
short mval[2];
|
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);
|
getmouseco_areawin(mval);
|
||||||
areamouseco_to_ipoco(G.v2d, mval, &locx, &locy);
|
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);
|
addqueue(curarea->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user