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.
This commit is contained in:
Hans Goudey 2021-12-15 18:05:45 -06:00
parent 36a830b4d3
commit b265b447b6
9 changed files with 74 additions and 75 deletions

View File

@ -96,17 +96,14 @@ static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
const bNodeType &node_type = params.node_type();
if (params.other_socket().type == SOCK_GEOMETRY) {
params.add_item(IFACE_("Geometry"), [node_type](LinkSearchOpParams &params) {
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<CustomDataType> 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 &params) {
bNode &node = params.add_node(node_type);

View File

@ -159,15 +159,12 @@ class SocketSearchOp {
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
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 &params) {
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<eNodeSocketDatatype>(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"),

View File

@ -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 &params)
{
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 &params)
{
class SocketSearchOp {
public:
StringRef socket_name;
GeometryNodeCurveSampleMode mode;
void operator()(LinkSearchOpParams &params)
{
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<eNodeSocketDatatype>(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});

View File

@ -109,31 +109,34 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
search_link_ops_for_declarations(params, declaration.outputs());
return;
}
params.add_item(IFACE_("Count"), [](LinkSearchOpParams &params) {
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 &params) {
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 &params) {
bNode &node = params.add_node("GeometryNodeMeshLine");
params.connect_available_socket(node, "Start Location");
});
params.add_item(IFACE_("Offset"), [](LinkSearchOpParams &params) {
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 &params) {
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<eNodeSocketDatatype>(params.other_socket().type), SOCK_FLOAT)) {
params.add_item(IFACE_("Count"), [](LinkSearchOpParams &params) {
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 &params) {
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 &params) {
bNode &node = params.add_node("GeometryNodeMeshLine");
params.connect_available_socket(node, "Start Location");
});
params.add_item(IFACE_("Offset"), [](LinkSearchOpParams &params) {
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 &params) {
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)

View File

@ -121,7 +121,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
const std::optional<CustomDataType> 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 &params) {
bNode &node = params.add_node("GeometryNodeRaycast");

View File

@ -63,7 +63,7 @@ static void node_declare(NodeDeclarationBuilder &b)
});
b.add_output<decl::Geometry>(N_("Curves"));
b.add_output<decl::String>(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;
});
}

View File

@ -136,19 +136,13 @@ static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
{
if (params.other_socket().type == SOCK_GEOMETRY) {
params.add_item(IFACE_("Target"), [](LinkSearchOpParams &params) {
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<CustomDataType> 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 &params) {
bNode &node = params.add_node("GeometryNodeAttributeTransfer");

View File

@ -48,10 +48,13 @@ static void sh_node_math_declare(NodeDeclarationBuilder &b)
static void sh_node_math_gather_link_searches(GatherLinkSearchOpParams &params)
{
/* For now, do something very basic (only exposing "Add", and a single "Value" socket). */
params.add_item(IFACE_("Value"), [](LinkSearchOpParams &params) {
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 &params) {
bNode &node = params.add_node("ShaderNodeMath");
params.update_and_connect_available_socket(node, "Value");
});
}
}
} // namespace blender::nodes

View File

@ -42,10 +42,13 @@ static void sh_node_vector_math_declare(NodeDeclarationBuilder &b)
static void sh_node_vector_math_gather_link_searches(GatherLinkSearchOpParams &params)
{
/* For now, do something very basic (only exposing "Add", and a single "Vector" socket). */
params.add_item(IFACE_("Vector"), [](LinkSearchOpParams &params) {
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 &params) {
bNode &node = params.add_node("ShaderNodeVectorMath");
params.update_and_connect_available_socket(node, "Vector");
});
}
}
} // namespace blender::nodes