From b265b447b639601ab53d1dc3cae0c3a95020cd64 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 15 Dec 2021 18:05:45 -0600 Subject: 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. --- .../geometry/nodes/node_geo_attribute_capture.cc | 13 ++---- .../node_geo_curve_primitive_quadrilateral.cc | 11 ++--- .../nodes/geometry/nodes/node_geo_curve_trim.cc | 36 ++++++++------- .../geometry/nodes/node_geo_mesh_primitive_line.cc | 53 ++++++++++++---------- .../nodes/geometry/nodes/node_geo_raycast.cc | 2 +- .../geometry/nodes/node_geo_string_to_curves.cc | 2 +- .../geometry/nodes/node_geo_transfer_attribute.cc | 10 +--- .../blender/nodes/shader/nodes/node_shader_math.cc | 11 +++-- .../nodes/shader/nodes/node_shader_vector_math.cc | 11 +++-- 9 files changed, 74 insertions(+), 75 deletions(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc index 22a9e4a0c33..be0baa706af 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc @@ -96,17 +96,14 @@ static void node_update(bNodeTree *ntree, bNode *node) static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) { - const bNodeType &node_type = params.node_type(); - if (params.other_socket().type == SOCK_GEOMETRY) { - params.add_item(IFACE_("Geometry"), [node_type](LinkSearchOpParams ¶ms) { - bNode &node = params.add_node(node_type); - params.connect_available_socket(node, "Geometry"); - }); - } + const NodeDeclaration &declaration = *params.node_type().fixed_declaration; + search_link_ops_for_declarations(params, declaration.inputs().take_front(1)); + search_link_ops_for_declarations(params, declaration.outputs().take_front(1)); + const bNodeType &node_type = params.node_type(); const std::optional type = node_data_type_to_custom_data_type( (eNodeSocketDatatype)params.other_socket().type); - if (type) { + if (type && *type != CD_PROP_STRING) { if (params.in_out() == SOCK_OUT) { params.add_item(IFACE_("Attribute"), [node_type, type](LinkSearchOpParams ¶ms) { bNode &node = params.add_node(node_type); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc index 07bd7cec766..ff6294b9b6b 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc @@ -159,15 +159,12 @@ class SocketSearchOp { static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) { + const NodeDeclaration &declaration = *params.node_type().fixed_declaration; if (params.in_out() == SOCK_OUT) { - if (params.other_socket().type == SOCK_GEOMETRY) { - params.add_item(IFACE_("Curve"), [](LinkSearchOpParams ¶ms) { - bNode &node = params.add_node("GeometryNodeCurvePrimitiveQuadrilateral"); - params.connect_available_socket(node, "Curve"); - }); - } + search_link_ops_for_declarations(params, declaration.outputs()); } - else { + else if (params.node_tree().typeinfo->validate_link( + static_cast(params.other_socket().type), SOCK_FLOAT)) { params.add_item(IFACE_("Width"), SocketSearchOp{"Width", GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_RECTANGLE}); params.add_item(IFACE_("Height"), diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc index c6908cb8ed0..746392a66cc 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc @@ -90,26 +90,28 @@ static void node_update(bNodeTree *ntree, bNode *node) nodeSetSocketAvailability(ntree, end_len, mode == GEO_NODE_CURVE_SAMPLE_LENGTH); } +class SocketSearchOp { + public: + StringRef socket_name; + GeometryNodeCurveSampleMode mode; + void operator()(LinkSearchOpParams ¶ms) + { + bNode &node = params.add_node("GeometryNodeTrimCurve"); + node_storage(node).mode = mode; + params.update_and_connect_available_socket(node, socket_name); + } +}; + static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) { - class SocketSearchOp { - public: - StringRef socket_name; - GeometryNodeCurveSampleMode mode; - void operator()(LinkSearchOpParams ¶ms) - { - bNode &node = params.add_node("GeometryNodeTrimCurve"); - node_storage(node).mode = mode; - params.update_and_connect_available_socket(node, socket_name); - } - }; + const NodeDeclaration &declaration = *params.node_type().fixed_declaration; - if (params.in_out() == SOCK_OUT) { - params.add_item(IFACE_("Curve"), SocketSearchOp{"Curve", GEO_NODE_CURVE_SAMPLE_FACTOR}); - } - else { - params.add_item(IFACE_("Curve"), SocketSearchOp{"Curve", GEO_NODE_CURVE_SAMPLE_FACTOR}); - if (params.other_socket().type == SOCK_FLOAT) { + search_link_ops_for_declarations(params, declaration.outputs()); + search_link_ops_for_declarations(params, declaration.inputs().take_front(1)); + + if (params.in_out() == SOCK_IN) { + if (params.node_tree().typeinfo->validate_link( + static_cast(params.other_socket().type), SOCK_FLOAT)) { params.add_item(IFACE_("Start (Factor)"), SocketSearchOp{"Start", GEO_NODE_CURVE_SAMPLE_FACTOR}); params.add_item(IFACE_("End (Factor)"), SocketSearchOp{"End", GEO_NODE_CURVE_SAMPLE_FACTOR}); diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc index 389dc278197..41ad4d79f1e 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc @@ -109,31 +109,34 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) search_link_ops_for_declarations(params, declaration.outputs()); return; } - params.add_item(IFACE_("Count"), [](LinkSearchOpParams ¶ms) { - bNode &node = params.add_node("GeometryNodeMeshLine"); - node_storage(node).mode = GEO_NODE_MESH_LINE_MODE_OFFSET; - params.connect_available_socket(node, "Count"); - }); - params.add_item(IFACE_("Resolution"), [](LinkSearchOpParams ¶ms) { - bNode &node = params.add_node("GeometryNodeMeshLine"); - node_storage(node).mode = GEO_NODE_MESH_LINE_MODE_OFFSET; - node_storage(node).count_mode = GEO_NODE_MESH_LINE_COUNT_RESOLUTION; - params.connect_available_socket(node, "Resolution"); - }); - params.add_item(IFACE_("Start Location"), [](LinkSearchOpParams ¶ms) { - bNode &node = params.add_node("GeometryNodeMeshLine"); - params.connect_available_socket(node, "Start Location"); - }); - params.add_item(IFACE_("Offset"), [](LinkSearchOpParams ¶ms) { - bNode &node = params.add_node("GeometryNodeMeshLine"); - params.connect_available_socket(node, "Offset"); - }); - /* The last socket is reused in end points mode. */ - params.add_item(IFACE_("End Location"), [](LinkSearchOpParams ¶ms) { - bNode &node = params.add_node("GeometryNodeMeshLine"); - node_storage(node).mode = GEO_NODE_MESH_LINE_MODE_END_POINTS; - params.connect_available_socket(node, "Offset"); - }); + else if (params.node_tree().typeinfo->validate_link( + static_cast(params.other_socket().type), SOCK_FLOAT)) { + params.add_item(IFACE_("Count"), [](LinkSearchOpParams ¶ms) { + bNode &node = params.add_node("GeometryNodeMeshLine"); + node_storage(node).mode = GEO_NODE_MESH_LINE_MODE_OFFSET; + params.connect_available_socket(node, "Count"); + }); + params.add_item(IFACE_("Resolution"), [](LinkSearchOpParams ¶ms) { + bNode &node = params.add_node("GeometryNodeMeshLine"); + node_storage(node).mode = GEO_NODE_MESH_LINE_MODE_OFFSET; + node_storage(node).count_mode = GEO_NODE_MESH_LINE_COUNT_RESOLUTION; + params.connect_available_socket(node, "Resolution"); + }); + params.add_item(IFACE_("Start Location"), [](LinkSearchOpParams ¶ms) { + bNode &node = params.add_node("GeometryNodeMeshLine"); + params.connect_available_socket(node, "Start Location"); + }); + params.add_item(IFACE_("Offset"), [](LinkSearchOpParams ¶ms) { + bNode &node = params.add_node("GeometryNodeMeshLine"); + params.connect_available_socket(node, "Offset"); + }); + /* The last socket is reused in end points mode. */ + params.add_item(IFACE_("End Location"), [](LinkSearchOpParams ¶ms) { + bNode &node = params.add_node("GeometryNodeMeshLine"); + node_storage(node).mode = GEO_NODE_MESH_LINE_MODE_END_POINTS; + params.connect_available_socket(node, "Offset"); + }); + } } static void node_geo_exec(GeoNodeExecParams params) diff --git a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc index 8968675c1ed..d255fe482f6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc @@ -121,7 +121,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) const std::optional type = node_data_type_to_custom_data_type( (eNodeSocketDatatype)params.other_socket().type); - if (type) { + if (type && *type != CD_PROP_STRING) { /* The input and output sockets have the same name. */ params.add_item(IFACE_("Attribute"), [type](LinkSearchOpParams ¶ms) { bNode &node = params.add_node("GeometryNodeRaycast"); diff --git a/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc b/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc index e30b11907e8..33614eb3c46 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc @@ -63,7 +63,7 @@ static void node_declare(NodeDeclarationBuilder &b) }); b.add_output(N_("Curves")); b.add_output(N_("Remainder")).make_available([](bNode &node) { - node_storage(node).overflow = GEO_NODE_STRING_TO_CURVES_MODE_OVERFLOW; + node_storage(node).overflow = GEO_NODE_STRING_TO_CURVES_MODE_TRUNCATE; }); } diff --git a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc index 007373929f4..1f099dcd04d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc @@ -136,19 +136,13 @@ static void node_update(bNodeTree *ntree, bNode *node) static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms) { - if (params.other_socket().type == SOCK_GEOMETRY) { - params.add_item(IFACE_("Target"), [](LinkSearchOpParams ¶ms) { - bNode &node = params.add_node("GeometryNodeAttributeTransfer"); - params.connect_available_socket(node, "Target"); - }); - } - const NodeDeclaration &declaration = *params.node_type().fixed_declaration; search_link_ops_for_declarations(params, declaration.inputs().take_back(2)); + search_link_ops_for_declarations(params, declaration.inputs().take_front(1)); const std::optional type = node_data_type_to_custom_data_type( (eNodeSocketDatatype)params.other_socket().type); - if (type) { + if (type && *type != CD_PROP_STRING) { /* The input and output sockets have the same name. */ params.add_item(IFACE_("Attribute"), [type](LinkSearchOpParams ¶ms) { bNode &node = params.add_node("GeometryNodeAttributeTransfer"); 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(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(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 -- cgit v1.2.3