Nodes: Consistent link drag search for math and vector math nodes

Previously operations for the math node when connecting to
outputs weren't added. It also used a different method to
check whether the link would be valid.
This commit is contained in:
Hans Goudey 2022-01-04 23:18:54 -06:00
parent 5336fdc6e3
commit 458be2ecc4
2 changed files with 16 additions and 28 deletions

View File

@ -61,32 +61,24 @@ class SocketSearchOp {
static void sh_node_math_gather_link_searches(GatherLinkSearchOpParams &params)
{
const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
if (params.in_out() == SOCK_OUT) {
search_link_ops_for_declarations(params, declaration.outputs());
if (!params.node_tree().typeinfo->validate_link(
static_cast<eNodeSocketDatatype>(params.other_socket().type), SOCK_FLOAT)) {
return;
}
/* Expose first Value socket. */
if (params.node_tree().typeinfo->validate_link(
static_cast<eNodeSocketDatatype>(params.other_socket().type), SOCK_FLOAT)) {
const bool is_geometry_node_tree = params.node_tree().type == NTREE_GEOMETRY;
const int weight = ELEM(params.other_socket().type, SOCK_FLOAT, SOCK_BOOLEAN, SOCK_INT) ? 0 : -1;
const bool is_geometry_node_tree = params.node_tree().type == NTREE_GEOMETRY;
const int weight = ELEM(params.other_socket().type, SOCK_FLOAT, SOCK_BOOLEAN, SOCK_INT) ? 0 :
-1;
for (const EnumPropertyItem *item = rna_enum_node_math_items; item->identifier != nullptr;
item++) {
if (item->name != nullptr && item->identifier[0] != '\0') {
const int gn_weight =
(is_geometry_node_tree &&
ELEM(item->value, NODE_MATH_COMPARE, NODE_MATH_GREATER_THAN, NODE_MATH_LESS_THAN)) ?
-1 :
weight;
params.add_item(IFACE_(item->name),
SocketSearchOp{"Value", (NodeMathOperation)item->value},
gn_weight);
}
for (const EnumPropertyItem *item = rna_enum_node_math_items; item->identifier != nullptr;
item++) {
if (item->name != nullptr && item->identifier[0] != '\0') {
const int gn_weight =
(is_geometry_node_tree &&
ELEM(item->value, NODE_MATH_COMPARE, NODE_MATH_GREATER_THAN, NODE_MATH_LESS_THAN)) ?
-1 :
weight;
params.add_item(
IFACE_(item->name), SocketSearchOp{"Value", (NodeMathOperation)item->value}, gn_weight);
}
}
}

View File

@ -55,12 +55,8 @@ class SocketSearchOp {
static void sh_node_vector_math_gather_link_searches(GatherLinkSearchOpParams &params)
{
if (!ELEM(params.other_socket().type,
SOCK_FLOAT,
SOCK_BOOLEAN,
SOCK_INT,
SOCK_VECTOR,
SOCK_RGBA)) {
if (!params.node_tree().typeinfo->validate_link(
static_cast<eNodeSocketDatatype>(params.other_socket().type), SOCK_VECTOR)) {
return;
}