[Bf-blender-cvs] [266cd7bb82c] master: Nodes: Add support to mute node wires
Charlie Jolly
noreply at git.blender.org
Wed Mar 17 12:56:05 CET 2021
Commit: 266cd7bb82ce4bfed20a3d61a84f25e2bacfca2b
Author: Charlie Jolly
Date: Tue Mar 16 19:11:54 2021 +0000
Branches: master
https://developer.blender.org/rB266cd7bb82ce4bfed20a3d61a84f25e2bacfca2b
Nodes: Add support to mute node wires
This patch adds the ability to mute individual wires in the node editor.
This is invoked like the cut links operator but with a new shortcut.
Mute = Ctrl + Alt
Cut = Ctrl
Dragging over wires will toggle the mute state for that wire.
The muted wires are drawn in red with a bar across the center.
Red is used in the nodes context to indicate invalid links, muted links and internal links.
When a wire is muted it exposes the original node buttons which are normally hidden when a wire is connected.
Downstream and upstream links connected using reroute nodes are also muted.
Outside scope of patch:
- Add support for pynodes e.g. Animation Nodes
- Requires minor change to check for muted links using the `is_muted` link property or the `is_linked` socket property.
Maniphest Tasks: T52659
Differential Revision: https://developer.blender.org/D2807
===================================================================
M intern/cycles/blender/blender_shader.cpp
M release/scripts/presets/keyconfig/keymap_data/blender_default.py
M release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
M release/scripts/startup/bl_ui/space_node.py
M source/blender/blenkernel/BKE_node.h
M source/blender/blenkernel/intern/node.cc
M source/blender/compositor/intern/COM_NodeGraph.cc
M source/blender/editors/space_node/drawnode.c
M source/blender/editors/space_node/node_intern.h
M source/blender/editors/space_node/node_ops.c
M source/blender/editors/space_node/node_relationships.c
M source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl
M source/blender/makesdna/DNA_node_types.h
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/intern/node_exec.c
M source/blender/nodes/intern/node_tree_ref.cc
M source/blender/nodes/shader/node_shader_tree.c
M source/blender/windowmanager/intern/wm_cursors.c
M source/blender/windowmanager/wm_cursors.h
===================================================================
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index a1ab5277744..72328333732 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -1234,7 +1234,8 @@ static void add_nodes(Scene *scene,
for (BL::NodeLink &b_link : b_ntree.links) {
/* Ignore invalid links to avoid unwanted cycles created in graph.
* Also ignore links with unavailable sockets. */
- if (!(b_link.is_valid() && b_link.from_socket().enabled() && b_link.to_socket().enabled())) {
+ if (!(b_link.is_valid() && b_link.from_socket().enabled() && b_link.to_socket().enabled()) ||
+ b_link.is_muted()) {
continue;
}
/* get blender link data */
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 3471a8d0db0..feba4e3bd09 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -1844,6 +1844,7 @@ def km_node_editor(params):
("node.resize", {"type": 'EVT_TWEAK_L', "value": 'ANY'}, None),
("node.add_reroute", {"type": 'EVT_TWEAK_L' if params.legacy else 'EVT_TWEAK_R', "value": 'ANY', "shift": True}, None),
("node.links_cut", {"type": 'EVT_TWEAK_L' if params.legacy else 'EVT_TWEAK_R', "value": 'ANY', "ctrl": True}, None),
+ ("node.links_mute", {"type": 'EVT_TWEAK_R', "value": 'ANY', "ctrl": True, "alt": True}, None),
("node.select_link_viewer", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True, "ctrl": True}, None),
("node.backimage_move", {"type": 'MIDDLEMOUSE', "value": 'PRESS', "alt": True}, None),
("node.backimage_zoom", {"type": 'V', "value": 'PRESS', "repeat": True},
diff --git a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
index c8fc6abe10a..91f153a0f42 100644
--- a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
+++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
@@ -1113,6 +1113,7 @@ def km_node_editor(params):
("node.resize", {"type": 'EVT_TWEAK_L', "value": 'ANY'}, None),
("node.add_reroute", {"type": params.action_tweak, "value": 'ANY', "shift": True}, None),
("node.links_cut", {"type": params.action_tweak, "value": 'ANY', "ctrl": True}, None),
+ ("node.links_mute", {"type": params.action_tweak, "value": 'ANY', "ctrl": True, "alt": True}, None),
("node.select_link_viewer", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True, "ctrl": True}, None),
("node.backimage_fit", {"type": 'A', "value": 'PRESS', "alt": True}, None),
("node.backimage_sample", {"type": 'LEFTMOUSE', "value": 'PRESS', "alt": True}, None),
diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py
index a9934850acd..7f66cdd3d74 100644
--- a/release/scripts/startup/bl_ui/space_node.py
+++ b/release/scripts/startup/bl_ui/space_node.py
@@ -331,6 +331,7 @@ class NODE_MT_node(Menu):
layout.operator("node.link_make", text="Make and Replace Links").replace = True
layout.operator("node.links_cut")
layout.operator("node.links_detach")
+ layout.operator("node.links_mute")
layout.separator()
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index ced76e65ada..04a9855de68 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -627,6 +627,7 @@ struct bNodeLink *nodeAddLink(struct bNodeTree *ntree,
struct bNodeSocket *tosock);
void nodeRemLink(struct bNodeTree *ntree, struct bNodeLink *link);
void nodeRemSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock);
+void nodeMuteLinkToggle(struct bNodeTree *ntree, struct bNodeLink *link);
bool nodeLinkIsHidden(const struct bNodeLink *link);
void nodeInternalRelink(struct bNodeTree *ntree, struct bNode *node);
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index bbc655d7fc8..ca973bd9d65 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -107,6 +107,9 @@ static void node_free_node(bNodeTree *ntree, bNode *node);
static void node_socket_interface_free(bNodeTree *UNUSED(ntree),
bNodeSocket *sock,
const bool do_id_user);
+static void nodeMuteRerouteOutputLinks(struct bNodeTree *ntree,
+ struct bNode *node,
+ const bool mute);
static void ntree_init_data(ID *id)
{
@@ -2215,6 +2218,106 @@ void nodeRemLink(bNodeTree *ntree, bNodeLink *link)
}
}
+/* Check if all output links are muted or not. */
+static bool nodeMuteFromSocketLinks(const bNodeTree *ntree, const bNodeSocket *sock)
+{
+ int tot = 0;
+ int muted = 0;
+ LISTBASE_FOREACH (const bNodeLink *, link, &ntree->links) {
+ if (link->fromsock == sock) {
+ tot++;
+ if (link->flag & NODE_LINK_MUTED) {
+ muted++;
+ }
+ }
+ }
+ return tot == muted;
+}
+
+static void nodeMuteLink(bNodeLink *link)
+{
+ link->flag |= NODE_LINK_MUTED;
+ link->flag |= NODE_LINK_TEST;
+ if (!(link->tosock->flag & SOCK_MULTI_INPUT)) {
+ link->tosock->flag &= ~SOCK_IN_USE;
+ }
+}
+
+static void nodeUnMuteLink(bNodeLink *link)
+{
+ link->flag &= ~NODE_LINK_MUTED;
+ link->flag |= NODE_LINK_TEST;
+ link->tosock->flag |= SOCK_IN_USE;
+}
+
+/* Upstream muting. Always happens when unmuting but checks when muting. O(n^2) algorithm.*/
+static void nodeMuteRerouteInputLinks(bNodeTree *ntree, bNode *node, const bool mute)
+{
+ if (node->type != NODE_REROUTE) {
+ return;
+ }
+ if (!mute || nodeMuteFromSocketLinks(ntree, (bNodeSocket *)node->outputs.first)) {
+ bNodeSocket *sock = (bNodeSocket *)node->inputs.first;
+ LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
+ if (!(link->flag & NODE_LINK_VALID) || (link->tosock != sock)) {
+ continue;
+ }
+ if (mute) {
+ nodeMuteLink(link);
+ }
+ else {
+ nodeUnMuteLink(link);
+ }
+ nodeMuteRerouteInputLinks(ntree, link->fromnode, mute);
+ }
+ }
+}
+
+/* Downstream muting propagates when reaching reroute nodes. O(n^2) algorithm.*/
+static void nodeMuteRerouteOutputLinks(bNodeTree *ntree, bNode *node, const bool mute)
+{
+ if (node->type != NODE_REROUTE) {
+ return;
+ }
+ bNodeSocket *sock;
+ sock = (bNodeSocket *)node->outputs.first;
+ LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
+ if (!(link->flag & NODE_LINK_VALID) || (link->fromsock != sock)) {
+ continue;
+ }
+ if (mute) {
+ nodeMuteLink(link);
+ }
+ else {
+ nodeUnMuteLink(link);
+ }
+ nodeMuteRerouteOutputLinks(ntree, link->tonode, mute);
+ }
+}
+
+void nodeMuteLinkToggle(bNodeTree *ntree, bNodeLink *link)
+{
+ if (link->tosock) {
+ bool mute = !(link->flag & NODE_LINK_MUTED);
+ if (mute) {
+ nodeMuteLink(link);
+ }
+ else {
+ nodeUnMuteLink(link);
+ }
+ if (link->tonode->type == NODE_REROUTE) {
+ nodeMuteRerouteOutputLinks(ntree, link->tonode, mute);
+ }
+ if (link->fromnode->type == NODE_REROUTE) {
+ nodeMuteRerouteInputLinks(ntree, link->fromnode, mute);
+ }
+ }
+
+ if (ntree) {
+ ntree->update |= NTREE_UPDATE_LINKS;
+ }
+}
+
void nodeRemSocketLinks(bNodeTree *ntree, bNodeSocket *sock)
{
LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) {
@@ -2257,6 +2360,10 @@ void nodeInternalRelink(bNodeTree *ntree, bNode *node)
link->flag &= ~NODE_LINK_VALID;
}
+ if (fromlink->flag & NODE_LINK_MUTED) {
+ link->flag |= NODE_LINK_MUTED;
+ }
+
ntree->update |= NTREE_UPDATE_LINKS;
}
else {
@@ -4014,7 +4121,9 @@ void ntreeTagUsedSockets(bNodeTree *ntree)
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
link->fromsock->flag |= SOCK_IN_USE;
- link->tosock->flag |= SOCK_IN_USE;
+ if (!(link->flag & NODE_LINK_MUTED)) {
+ link->tosock->flag |= SOCK_IN_USE;
+ }
}
}
diff --git a/source/blender/compositor/intern/COM_NodeGraph.cc b/source/blender/compositor/intern/COM_NodeGraph.cc
index f932acfa49e..d8220099f1f 100644
--- a/source/blender/compositor/intern/COM_NodeGraph.cc
+++ b/source/blender/compositor/intern/COM_NodeGraph.cc
@@ -188,7 +188,8 @@ void NodeGraph::add_bNodeLink(const NodeRange &node_range, bNodeLink *b_nodelink
if (!(b_nodelink->flag & NODE_LINK_VALID)) {
return;
}
- if ((b_nodelink->fromsock->flag & SOCK_UNAVAIL) || (b_nodelink->tosock->flag & SOCK_UNAVAIL)) {
+ if ((b_nodelink->fromsock->flag & SOCK_UNAVAIL) || (b_nodelink->tosock->flag & SOCK_UNAVAIL) ||
+ (b_nodelink->flag & NODE_LINK_MUTED)) {
return;
}
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 0f2b2b435bc..1354c06305c 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3751,17 +3751,21 @@ bool node_link_bezier_points(const View2D *v2d,
#define LINK_WIDTH (2.5f * UI_DPI_FAC)
#define ARROW_SIZE (7 * UI_DPI_FAC)
+/* Reroute arrow shape and mute bar. These are expanded here and shrunk in the glsl code.
+ * See: gpu_shader_2D_nodelink_vert.glsl */
static float arrow_verts[3][2] = {{-1.0f, 1.0f}, {0.0f, 0.0f}, {-1.0f, -1.0f}};
static float arrow_expand_axis[3][2] = {{0.7071f, 0.7071f}, {M_SQRT2, 0.0f}, {0.7071f, -0.7071f}};
+static float mute_verts[3][2] = {{0.7071f, 1.0f}, {0.7071f, 0.0f}, {0.7071f, -1.0f}};
+static float mute_expand_axis[3][2] = {{1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, -0.0f}};
static struct {
GPUBatch *batch; /* for batching line together */
GPUBatch *batch_single; /* for single line */
GPUVertBuf *inst_vbo;
uint p0_id, p1_id, p2_id, p3_id;
- uint colid_id;
+ uint colid_id, muted_id;
GPUVertBufRaw p0
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list