diff options
author | Hans Goudey <h.goudey@me.com> | 2021-12-16 03:05:45 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-12-16 03:05:45 +0300 |
commit | b265b447b639601ab53d1dc3cae0c3a95020cd64 (patch) | |
tree | 76bda73cece22524358a78fab7f593584406a09f /source/blender/nodes/shader | |
parent | 36a830b4d36d31ae29166e0defa6ed62a9a7a321 (diff) |
Fix various cases of incorrect filtering in node link drag search
Some nodes didn't check the type of the link's socket for filtering.
Do this with a combination of manually calling the node tree's validate
links function and using the helper function for declarations.
Also clean up a few cases that added geometry sockets manually
when they can use the simpler helper function.
Diffstat (limited to 'source/blender/nodes/shader')
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_math.cc | 11 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_vector_math.cc | 11 |
2 files changed, 14 insertions, 8 deletions
diff --git a/source/blender/nodes/shader/nodes/node_shader_math.cc b/source/blender/nodes/shader/nodes/node_shader_math.cc index 51c94b10c8b..da237be273f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_math.cc +++ b/source/blender/nodes/shader/nodes/node_shader_math.cc @@ -48,10 +48,13 @@ static void sh_node_math_declare(NodeDeclarationBuilder &b) static void sh_node_math_gather_link_searches(GatherLinkSearchOpParams ¶ms) { /* For now, do something very basic (only exposing "Add", and a single "Value" socket). */ - params.add_item(IFACE_("Value"), [](LinkSearchOpParams ¶ms) { - bNode &node = params.add_node("ShaderNodeMath"); - params.update_and_connect_available_socket(node, "Value"); - }); + if (params.node_tree().typeinfo->validate_link( + static_cast<eNodeSocketDatatype>(params.other_socket().type), SOCK_FLOAT)) { + params.add_item(IFACE_("Value"), [](LinkSearchOpParams ¶ms) { + bNode &node = params.add_node("ShaderNodeMath"); + params.update_and_connect_available_socket(node, "Value"); + }); + } } } // namespace blender::nodes diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_math.cc b/source/blender/nodes/shader/nodes/node_shader_vector_math.cc index 70a0d47e1b9..5f5969de78c 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vector_math.cc +++ b/source/blender/nodes/shader/nodes/node_shader_vector_math.cc @@ -42,10 +42,13 @@ static void sh_node_vector_math_declare(NodeDeclarationBuilder &b) static void sh_node_vector_math_gather_link_searches(GatherLinkSearchOpParams ¶ms) { /* For now, do something very basic (only exposing "Add", and a single "Vector" socket). */ - params.add_item(IFACE_("Vector"), [](LinkSearchOpParams ¶ms) { - bNode &node = params.add_node("ShaderNodeVectorMath"); - params.update_and_connect_available_socket(node, "Vector"); - }); + if (params.node_tree().typeinfo->validate_link( + static_cast<eNodeSocketDatatype>(params.other_socket().type), SOCK_VECTOR)) { + params.add_item(IFACE_("Vector"), [](LinkSearchOpParams ¶ms) { + bNode &node = params.add_node("ShaderNodeVectorMath"); + params.update_and_connect_available_socket(node, "Vector"); + }); + } } } // namespace blender::nodes |