Nodes: Add Compare node operations to link drag search menu

Exposes compare operations via rna emums.
This uses the rna enum to build the search list using
named operations linked to socket A.
This also weights the Math Node comparison operations lower
for geometry node trees.

Differential Revision: https://developer.blender.org/D13695
This commit is contained in:
Charlie Jolly
2021-12-31 13:07:35 +00:00
committed by Charlie Jolly
parent e79b4523b4
commit 6844304dda
2 changed files with 36 additions and 17 deletions

View File

@@ -71,14 +71,21 @@ static void sh_node_math_gather_link_searches(GatherLinkSearchOpParams &params)
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;
for (const EnumPropertyItem *item = rna_enum_node_math_items; item->identifier != nullptr;
item++) {
if (item->name != nullptr && item->identifier[0] != '\0') {
params.add_item(
IFACE_(item->name), SocketSearchOp{"Value", (NodeMathOperation)item->value}, weight);
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);
}
}
}