[Bf-blender-cvs] [576c392241b] master: Nodes: Sortable Multi Input Sockets
Fabian Schempp
noreply at git.blender.org
Wed Mar 10 14:59:34 CET 2021
Commit: 576c392241bde1d6497b00490e97e104ac887132
Author: Fabian Schempp
Date: Wed Mar 10 14:57:57 2021 +0100
Branches: master
https://developer.blender.org/rB576c392241bde1d6497b00490e97e104ac887132
Nodes: Sortable Multi Input Sockets
This Patch removes the auto sorting from Multi-Input Sockets and allows
the links to be sorted by drag and drop instead.
As a minor related change, it fixes the drawing of the mute line to
connect to the first input instead of the socket's center.
===================================================================
M source/blender/editors/space_node/drawnode.c
M source/blender/editors/space_node/node_draw.cc
M source/blender/editors/space_node/node_edit.c
M source/blender/editors/space_node/node_group.c
M source/blender/editors/space_node/node_intern.h
M source/blender/editors/space_node/node_relationships.c
M source/blender/makesdna/DNA_node_types.h
M source/blender/nodes/NOD_node_tree_ref.hh
M source/blender/nodes/intern/node_tree_ref.cc
===================================================================
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index a9a7ef5a0a2..75ea5b9a1bf 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3593,6 +3593,13 @@ bool node_link_bezier_handles(const View2D *v2d,
if (link->fromsock) {
vec[0][0] = link->fromsock->locx;
vec[0][1] = link->fromsock->locy;
+ if (link->fromsock->flag & SOCK_MULTI_INPUT) {
+ node_link_calculate_multi_input_position(link->fromsock->locx,
+ link->fromsock->locy,
+ link->fromsock->total_inputs - 1,
+ link->fromsock->total_inputs,
+ vec[0]);
+ }
fromreroute = (link->fromnode && link->fromnode->type == NODE_REROUTE);
}
else {
@@ -3606,7 +3613,11 @@ bool node_link_bezier_handles(const View2D *v2d,
vec[3][0] = link->tosock->locx;
vec[3][1] = link->tosock->locy;
if (!(link->tonode->flag & NODE_HIDDEN) && link->tosock->flag & SOCK_MULTI_INPUT) {
- node_link_calculate_multi_input_position(link, vec[3]);
+ node_link_calculate_multi_input_position(link->tosock->locx,
+ link->tosock->locy,
+ link->multi_input_socket_index,
+ link->tosock->total_inputs,
+ vec[3]);
}
toreroute = (link->tonode && link->tonode->type == NODE_REROUTE);
}
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 5a0cacf070b..bb0cd754c7b 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -1780,25 +1780,6 @@ void node_update_nodetree(const bContext *C, bNodeTree *ntree)
}
}
-static bool compare_link_by_angle_to_node(const bNodeLink *link_a, const bNodeLink *link_b)
-{
- BLI_assert(link_a->tosock == link_b->tosock);
- const float socket_location[2] = {link_a->tosock->locx, link_a->tosock->locy};
- const float up_direction[2] = {0.0f, 1.0f};
-
- float delta_a[2] = {link_a->fromsock->locx - socket_location[0],
- link_a->fromsock->locy - socket_location[1]};
- normalize_v2(delta_a);
- const float angle_a = angle_normalized_v2v2(up_direction, delta_a);
-
- float delta_b[2] = {link_b->fromsock->locx - socket_location[0],
- link_b->fromsock->locy - socket_location[1]};
- normalize_v2(delta_b);
- const float angle_b = angle_normalized_v2v2(up_direction, delta_b);
-
- return angle_a > angle_b;
-}
-
static void node_draw(const bContext *C,
ARegion *region,
SpaceNode *snode,
@@ -1813,42 +1794,6 @@ static void node_draw(const bContext *C,
#define USE_DRAW_TOT_UPDATE
-/**
- * Automatically sort the input links to multi-input sockets to avoid crossing noodles.
- */
-static void sort_multi_input_socket_links(bNodeTree *ntree, SpaceNode *snode)
-{
- LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
- LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
- if (socket->flag & SOCK_MULTI_INPUT) {
- /* The total is calculated in #node_update_nodetree, which runs before this draw step. */
- const int total_inputs = socket->total_inputs;
- Vector<bNodeLink *> input_links;
- input_links.reserve(total_inputs);
-
- LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
- if (link->tosock == socket) {
- input_links.append(link);
- }
- }
- LISTBASE_FOREACH (bNodeLinkDrag *, nldrag, &snode->runtime->linkdrag) {
- LISTBASE_FOREACH (LinkData *, linkdata, &nldrag->links) {
- bNodeLink *link = (bNodeLink *)linkdata->data;
- if (link->tosock == socket) {
- input_links.append(link);
- }
- }
- }
-
- std::sort(input_links.begin(), input_links.end(), compare_link_by_angle_to_node);
- for (const int i : input_links.index_range()) {
- input_links[i]->multi_input_socket_index = i;
- }
- }
- }
- }
-}
-
void node_draw_nodetree(const bContext *C,
ARegion *region,
SpaceNode *snode,
@@ -1885,8 +1830,6 @@ void node_draw_nodetree(const bContext *C,
GPU_blend(GPU_BLEND_ALPHA);
nodelink_batch_start(snode);
- sort_multi_input_socket_links(ntree, snode);
-
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
if (!nodeLinkIsHidden(link)) {
node_draw_link(®ion->v2d, snode, link);
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index 5205e50b0bf..afdc9efb78b 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -107,14 +107,15 @@ float node_socket_calculate_height(const bNodeSocket *socket)
return sock_height;
}
-void node_link_calculate_multi_input_position(const bNodeLink *link, float r[2])
-{
- float offset = (link->tosock->total_inputs * NODE_MULTI_INPUT_LINK_GAP -
- NODE_MULTI_INPUT_LINK_GAP) *
- 0.5;
- r[0] = link->tosock->locx - NODE_SOCKSIZE * 0.5f;
- r[1] = link->tosock->locy - offset +
- (link->multi_input_socket_index * NODE_MULTI_INPUT_LINK_GAP);
+void node_link_calculate_multi_input_position(const float socket_x,
+ const float socket_y,
+ const int index,
+ const int total_inputs,
+ float r[2])
+{
+ float offset = (total_inputs * NODE_MULTI_INPUT_LINK_GAP - NODE_MULTI_INPUT_LINK_GAP) * 0.5;
+ r[0] = socket_x - NODE_SOCKSIZE * 0.5f;
+ r[1] = socket_y - offset + (index * NODE_MULTI_INPUT_LINK_GAP);
}
static void compo_tag_output_nodes(bNodeTree *nodetree, int recalc_flags)
diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c
index b3ae336aadf..e1de4bfc21e 100644
--- a/source/blender/editors/space_node/node_group.c
+++ b/source/blender/editors/space_node/node_group.c
@@ -1030,6 +1030,9 @@ static int node_group_make_exec(bContext *C, wmOperator *op)
nodeSetActive(ntree, gnode);
if (ngroup) {
ED_node_tree_push(snode, ngroup, gnode);
+ LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) {
+ sort_multi_input_socket_links(snode, node, NULL, NULL);
+ }
ntreeUpdateTree(bmain, ngroup);
}
}
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index 19700b258ae..241cbee00f0 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -77,6 +77,7 @@ typedef struct SpaceNode_Runtime {
/* XXX hack for translate_attach op-macros to pass data from transform op to insert_offset op */
/** Temporary data for node insert offset (in UI called Auto-offset). */
struct NodeInsertOfsData *iofsd;
+ struct bNode *last_node_hovered_while_dragging_a_link;
} SpaceNode_Runtime;
/* space_node.c */
@@ -86,7 +87,11 @@ void space_node_group_offset(struct SpaceNode *snode, float *x, float *y);
/* node_draw.cc */
float node_socket_calculate_height(const bNodeSocket *socket);
-void node_link_calculate_multi_input_position(const bNodeLink *link, float r[2]);
+void node_link_calculate_multi_input_position(const float socket_x,
+ const float socket_y,
+ const int index,
+ const int total_inputs,
+ float r[2]);
int node_get_colorid(struct bNode *node);
int node_get_resize_cursor(int directions);
@@ -215,6 +220,10 @@ void NODE_OT_group_separate(struct wmOperatorType *ot);
void NODE_OT_group_edit(struct wmOperatorType *ot);
/* node_relationships.c */
+void sort_multi_input_socket_links(struct SpaceNode *snode,
+ struct bNode *node,
+ struct bNodeLink *drag_link,
+ float cursor[2]);
bool node_connected_to_output(struct Main *bmain, struct bNodeTree *ntree, struct bNode *node);
void NODE_OT_link(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c
index 35dd865047e..963349f876b 100644
--- a/source/blender/editors/space_node/node_relationships.c
+++ b/source/blender/editors/space_node/node_relationships.c
@@ -434,6 +434,75 @@ static bool snode_autoconnect_input(SpaceNode *snode,
return true;
}
+typedef struct LinkAndPosition {
+ struct bNodeLink *link;
+ float multi_socket_position[2];
+} LinkAndPosition;
+
+static int compare_link_by_y_position(const void *a, const void *b)
+{
+ const LinkAndPosition *link_and_position_a = *(const LinkAndPosition **)a;
+ const LinkAndPosition *link_and_position_b = *(const LinkAndPosition **)b;
+
+ BLI_assert(link_and_position_a->link->tosock == link_and_position_b->link->tosock);
+ const float link_a_y = link_and_position_a->multi_socket_position[1];
+ const float link_b_y = link_and_position_b->multi_socket_position[1];
+ return link_a_y > link_b_y ? 1 : -1;
+}
+
+void sort_multi_input_socket_links(SpaceNode *snode,
+ bNode *node,
+ bNodeLink *drag_link,
+ float cursor[2])
+{
+ LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
+ if (!(socket->flag & SOCK_MULTI_INPUT)) {
+ continue;
+ }
+ /* The total is calculated in #node_update_nodetree, which runs before this draw step. */
+ int total_inputs = socket->total_inputs + 1;
+ struct LinkAndPosition **input_links = MEM_malloc_arrayN(
+ total_inputs, sizeof(Link
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list