diff options
author | Fabian Schempp <fabian_schempp> | 2021-02-03 20:02:01 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-02-03 20:03:00 +0300 |
commit | c5514d3a2a03242ddc43f83be4bb72df7f85469f (patch) | |
tree | b7db84dd1f3f8586d287486749b2a812acc9724e /source/blender/nodes | |
parent | 894cc9c91592041a47c33300d784eac4e6412162 (diff) |
Geometry Nodes: Multi-Input Sockets
Normally sockets only have one input link. This commit adds the back-end
changes needed to use multiple input links per socket.
Multi-input sockets can be defined with a new flag in `bNodeSocketType`.
The changes necessary to make the sockets work in the geometry nodes
evaluator are generalizing input socket values as a vector of values,
and supporting this in the derived node tree structure.
This patch should contain no functional changes. Two upcoming patches
will use this system for the "Join Geometry" node and expose link picking
and updated display in the UI: D10069 and D10181.
Reviewed By: Jacques Lucke, Hans Goudey
Differential Revision: https://developer.blender.org/D10067
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/NOD_derived_node_tree.hh | 7 | ||||
-rw-r--r-- | source/blender/nodes/NOD_geometry_exec.hh | 19 | ||||
-rw-r--r-- | source/blender/nodes/intern/derived_node_tree.cc | 2 | ||||
-rw-r--r-- | source/blender/nodes/intern/node_util.c | 26 |
4 files changed, 42 insertions, 12 deletions
diff --git a/source/blender/nodes/NOD_derived_node_tree.hh b/source/blender/nodes/NOD_derived_node_tree.hh index 4d594a77ebc..62affe43895 100644 --- a/source/blender/nodes/NOD_derived_node_tree.hh +++ b/source/blender/nodes/NOD_derived_node_tree.hh @@ -80,6 +80,7 @@ class DInputSocket : public DSocket { private: Vector<DOutputSocket *> linked_sockets_; Vector<DGroupInput *> linked_group_inputs_; + bool is_multi_input_socket_; friend DerivedNodeTree; @@ -90,6 +91,7 @@ class DInputSocket : public DSocket { Span<const DGroupInput *> linked_group_inputs() const; bool is_linked() const; + bool is_multi_input_socket() const; }; class DOutputSocket : public DSocket { @@ -362,6 +364,11 @@ inline bool DInputSocket::is_linked() const return linked_sockets_.size() > 0 || linked_group_inputs_.size() > 0; } +inline bool DInputSocket::is_multi_input_socket() const +{ + return is_multi_input_socket_; +} + /* -------------------------------------------------------------------- * DOutputSocket inline methods. */ diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh index 454c9e96246..91d46e3951f 100644 --- a/source/blender/nodes/NOD_geometry_exec.hh +++ b/source/blender/nodes/NOD_geometry_exec.hh @@ -104,6 +104,25 @@ class GeoNodeExecParams { } /** + * Get input as vector for multi input socket with the given identifier. + * + * This method can only be called once for each identifier. + */ + template<typename T> Vector<T> extract_multi_input(StringRef identifier) + { + Vector<T> values; + values.append(input_values_.extract<T>(identifier)); + int i = 1; + std::string sub_identifier = identifier + "[1]"; + while (input_values_.contains(sub_identifier)) { + values.append(input_values_.extract<T>(sub_identifier)); + i++; + sub_identifier = identifier + "[" + std::to_string(i) + "]"; + } + return values; + } + + /** * Get the input value for the input socket with the given identifier. * * This makes a copy of the value, which is fine for most types but should be avoided for diff --git a/source/blender/nodes/intern/derived_node_tree.cc b/source/blender/nodes/intern/derived_node_tree.cc index c693047ff40..f5a0e14f18b 100644 --- a/source/blender/nodes/intern/derived_node_tree.cc +++ b/source/blender/nodes/intern/derived_node_tree.cc @@ -91,7 +91,7 @@ DNode &DerivedNodeTree::create_node(const NodeRef &node_ref, for (int i : node.inputs_.index_range()) { const InputSocketRef &socket_ref = node_ref.input(i); DInputSocket &socket = *node.inputs_[i]; - + socket.is_multi_input_socket_ = socket_ref.bsocket()->flag & SOCK_MULTI_INPUT; socket.id_ = UNINITIALIZED_ID; socket.node_ = &node; socket.socket_ref_ = &socket_ref; diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index 9669dc6496b..c7c3ced4e56 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -281,25 +281,30 @@ static int node_count_links(bNodeTree *ntree, bNodeSocket *sock) return count; } -/* find an eligible socket for linking */ +/* Find an eligible socket for linking. */ static bNodeSocket *node_find_linkable_socket(bNodeTree *ntree, bNode *node, bNodeSocket *cur) { - /* link swapping: try to find a free slot with a matching name */ - bNodeSocket *first = cur->in_out == SOCK_IN ? node->inputs.first : node->outputs.first; bNodeSocket *sock; - sock = cur->next ? cur->next : first; /* wrap around the list end */ + /* Iterate over all sockets of the target node, to find one that matches the same socket type. + * The idea behind this is: When a user connects an input to a socket that is + * already linked (and if its not an Multi Input Socket), we try to find a replacement socket for + * the link that we try to overwrite and connect that previous link to the new socket. */ + sock = cur->next ? cur->next : first; /* Wrap around the list end. */ while (sock != cur) { if (!nodeSocketIsHidden(sock) && node_link_socket_match(sock, cur)) { - int link_count = node_count_links(ntree, sock); - /* take +1 into account since we would add a new link */ - if (link_count + 1 <= nodeSocketLinkLimit(sock)) { - return sock; /* found a valid free socket we can swap to */ - } + break; } + sock = sock->next ? sock->next : first; /* Wrap around the list end. */ + } - sock = sock->next ? sock->next : first; /* wrap around the list end */ + if (!nodeSocketIsHidden(sock) && node_link_socket_match(sock, cur)) { + int link_count = node_count_links(ntree, sock); + /* Take +1 into account since we would add a new link. */ + if (link_count + 1 <= nodeSocketLinkLimit(sock)) { + return sock; /* Found a valid free socket we can swap to. */ + } } return NULL; } @@ -309,7 +314,6 @@ void node_insert_link_default(bNodeTree *ntree, bNode *node, bNodeLink *link) bNodeSocket *sock = link->tosock; bNodeLink *tlink, *tlink_next; - /* inputs can have one link only, outputs can have unlimited links */ if (node != link->tonode) { return; } |