Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-12-16 03:05:45 +0300
committerHans Goudey <h.goudey@me.com>2021-12-16 03:05:45 +0300
commitb265b447b639601ab53d1dc3cae0c3a95020cd64 (patch)
tree76bda73cece22524358a78fab7f593584406a09f
parent36a830b4d36d31ae29166e0defa6ed62a9a7a321 (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.
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc13
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc11
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc36
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc53
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_raycast.cc2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc10
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_math.cc11
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vector_math.cc11
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 &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);
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 &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"),
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 &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});
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 &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)
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 &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");
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<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;
});
}
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 &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");
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 &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
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 &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