From 6844304dda497b245f63934b3c5d8c52f4f6bb19 Mon Sep 17 00:00:00 2001 From: Charlie Jolly Date: Fri, 31 Dec 2021 13:07:35 +0000 Subject: 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 --- .../nodes/function/nodes/node_fn_compare.cc | 42 ++++++++++++++-------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'source/blender/nodes/function') diff --git a/source/blender/nodes/function/nodes/node_fn_compare.cc b/source/blender/nodes/function/nodes/node_fn_compare.cc index e1c15ac2be1..0607acc95f2 100644 --- a/source/blender/nodes/function/nodes/node_fn_compare.cc +++ b/source/blender/nodes/function/nodes/node_fn_compare.cc @@ -130,21 +130,33 @@ static void node_compare_gather_link_searches(GatherLinkSearchOpParams ¶ms) const eNodeSocketDatatype type = static_cast(params.other_socket().type); - if (ELEM(type, SOCK_FLOAT, SOCK_BOOLEAN, SOCK_RGBA, SOCK_VECTOR, SOCK_INT)) { - params.add_item(IFACE_("A"), SocketSearchOp{"A", type, NODE_COMPARE_GREATER_THAN}); - params.add_item(IFACE_("B"), SocketSearchOp{"B", type, NODE_COMPARE_GREATER_THAN}); - params.add_item( - IFACE_("C"), - SocketSearchOp{ - "C", SOCK_VECTOR, NODE_COMPARE_GREATER_THAN, NODE_COMPARE_MODE_DOT_PRODUCT}); - params.add_item( - IFACE_("Angle"), - SocketSearchOp{ - "Angle", SOCK_VECTOR, NODE_COMPARE_GREATER_THAN, NODE_COMPARE_MODE_DIRECTION}); - } - else if (type == SOCK_STRING) { - params.add_item(IFACE_("A"), SocketSearchOp{"A", type, NODE_COMPARE_EQUAL}); - params.add_item(IFACE_("B"), SocketSearchOp{"B", type, NODE_COMPARE_EQUAL}); + if (ELEM(type, SOCK_BOOLEAN, SOCK_FLOAT, SOCK_RGBA, SOCK_VECTOR, SOCK_INT, SOCK_STRING)) { + const eNodeSocketDatatype mode_type = (type == SOCK_BOOLEAN) ? SOCK_FLOAT : type; + const bool string_type = (type == SOCK_STRING); + /* Add socket A compare operations. */ + for (const EnumPropertyItem *item = rna_enum_node_compare_operation_items; + item->identifier != nullptr; + item++) { + if (item->name != nullptr && item->identifier[0] != '\0') { + if (!string_type && + ELEM(item->value, NODE_COMPARE_COLOR_BRIGHTER, NODE_COMPARE_COLOR_DARKER)) { + params.add_item(IFACE_(item->name), + SocketSearchOp{"A", SOCK_RGBA, (NodeCompareOperation)item->value}); + } + else if ((!string_type) || + (string_type && ELEM(item->value, NODE_COMPARE_EQUAL, NODE_COMPARE_NOT_EQUAL))) { + params.add_item(IFACE_(item->name), + SocketSearchOp{"A", mode_type, (NodeCompareOperation)item->value}); + } + } + } + /* Add Angle socket. */ + if (!string_type) { + params.add_item( + IFACE_("Angle"), + SocketSearchOp{ + "Angle", SOCK_VECTOR, NODE_COMPARE_GREATER_THAN, NODE_COMPARE_MODE_DIRECTION}); + } } } -- cgit v1.2.3