diff options
author | Sebastian Parborg <zeddb> | 2018-09-20 20:53:16 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-09-20 20:54:33 +0300 |
commit | d0eed5e50a80ef4df9ecb14772c87d4ede11e621 (patch) | |
tree | 2c59f9f4262f9309ca5e0130d6534ee71b543ad1 /source | |
parent | 09ea940e7ba8c4905e692134dfc14d0a6fbf909b (diff) |
Texture Paint: unify missing data and slots panels, better auto position nodes.
Differential Revision: https://developer.blender.org/D3694
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 48 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image_proj.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_templates.c | 11 |
4 files changed, 60 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 901822583cb..def0de54771 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -466,6 +466,10 @@ bool nodeAttachNodeCheck(struct bNode *node, struct bNode *parent); void nodeAttachNode(struct bNode *node, struct bNode *parent); void nodeDetachNode(struct bNode *node); +void nodePositionRelative(struct bNode *from_node, struct bNode *to_node, + struct bNodeSocket *from_sock, struct bNodeSocket *to_sock); +void nodePositionPropagate(struct bNode *node); + struct bNode *nodeFindNodebyName(struct bNodeTree *ntree, const char *name); int nodeFindNode(struct bNodeTree *ntree, struct bNodeSocket *sock, struct bNode **nodep, int *sockindex); struct bNode *nodeFindRootParent(bNode *node); diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index c81f5f425d8..1e17acdeada 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1213,6 +1213,54 @@ void nodeDetachNode(struct bNode *node) } } +void nodePositionRelative(bNode *from_node, bNode *to_node, bNodeSocket *from_sock, bNodeSocket *to_sock) +{ + float offset_x; + int tot_sock_idx; + + /* Socket to plug into. */ + if (SOCK_IN == to_sock->in_out) { + offset_x = - (from_node->typeinfo->width + 50); + tot_sock_idx = BLI_listbase_count(&to_node->outputs); + tot_sock_idx += BLI_findindex(&to_node->inputs, to_sock); + } + else { + offset_x = to_node->typeinfo->width + 50; + tot_sock_idx = BLI_findindex(&to_node->outputs, to_sock); + } + + BLI_assert(tot_sock_idx != -1); + + float offset_y = U.widget_unit * tot_sock_idx; + + /* Output socket. */ + if (SOCK_IN == from_sock->in_out) { + tot_sock_idx = BLI_listbase_count(&from_node->outputs); + tot_sock_idx += BLI_findindex(&from_node->inputs, from_sock); + } + else { + tot_sock_idx = BLI_findindex(&from_node->outputs, from_sock); + } + + BLI_assert(tot_sock_idx != -1); + + offset_y -= U.widget_unit * tot_sock_idx; + + from_node->locx = to_node->locx + offset_x; + from_node->locy = to_node->locy - offset_y; +} + +void nodePositionPropagate(bNode *node) +{ + for (bNodeSocket *nsock = node->inputs.first; nsock; nsock = nsock->next) { + if (nsock->link != NULL) { + bNodeLink *link = nsock->link; + nodePositionRelative(link->fromnode, link->tonode, link->fromsock, link->tosock); + nodePositionPropagate(link->fromnode); + } + } +} + void ntreeInitDefault(bNodeTree *ntree) { ntree_set_typeinfo(ntree, NULL); diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 805f51f008a..3ad373f4829 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -5696,10 +5696,10 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op) /* Connect to first available principled bsdf node. */ bNode *in_node; + bNode *out_node = imanode; in_node = ntreeFindType(ntree, SH_NODE_BSDF_PRINCIPLED); if (in_node != NULL) { - bNode *out_node = imanode; bNodeSocket *out_sock = nodeFindSocket(out_node, SOCK_OUT, "Color"); bNodeSocket *in_sock = NULL; @@ -5752,10 +5752,14 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op) bNodeLink *link = in_sock ? in_sock->link : NULL; if (in_sock != NULL && link == NULL) { nodeAddLink(ntree, out_node, out_sock, in_node, in_sock); + + nodePositionRelative(out_node, in_node, out_sock, in_sock); } } ntreeUpdateTree(CTX_data_main(C), ntree); + /* In case we added more than one node, position them too. */ + nodePositionPropagate(out_node); if (ima) { BKE_texpaint_slot_refresh_cache(scene, ma); diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c index 7b60963e082..64c898cb628 100644 --- a/source/blender/editors/space_node/node_templates.c +++ b/source/blender/editors/space_node/node_templates.c @@ -218,20 +218,15 @@ static void node_socket_add_replace(const bContext *C, bNodeTree *ntree, bNode * else if (!node_from) { node_from = nodeAddStaticNode(C, ntree, type); if (node_prev != NULL) { - /* If we're replacing existing node, use it's location. */ + /* If we're replacing existing node, use its location. */ node_from->locx = node_prev->locx; node_from->locy = node_prev->locy; node_from->offsetx = node_prev->offsetx; node_from->offsety = node_prev->offsety; } else { - /* Avoid exact intersection of nodes. - * TODO(sergey): Still not ideal, but better than nothing. - */ - int index = BLI_findindex(&node_to->inputs, sock_to); - BLI_assert(index != -1); - node_from->locx = node_to->locx - (node_from->typeinfo->width + 50); - node_from->locy = node_to->locy - (node_from->typeinfo->height * index); + sock_from_tmp = BLI_findlink(&node_from->outputs, item->socket_index); + nodePositionRelative(node_from, node_to, sock_from_tmp, sock_to); } node_link_item_apply(bmain, node_from, item); |