From 9a8fb5fe98e4588bc9a3b3fcdbc64900b7b7b73d Mon Sep 17 00:00:00 2001 From: Brady Johnston Date: Wed, 8 Oct 2025 14:09:08 +0200 Subject: [PATCH] Fix: Geometry Nodes: Drag-to-search for Grid Info node This PR adds the drag-to-search for the **Grid Info** node. Pull Request: https://projects.blender.org/blender/blender/pulls/147547 --- .../geometry/nodes/node_geo_grid_info.cc | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/source/blender/nodes/geometry/nodes/node_geo_grid_info.cc b/source/blender/nodes/geometry/nodes/node_geo_grid_info.cc index d9179f82ca7..f016adae57d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_grid_info.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_grid_info.cc @@ -12,6 +12,7 @@ #include "NOD_rna_define.hh" #include "NOD_socket.hh" +#include "NOD_socket_search_link.hh" #include "UI_interface_layout.hh" #include "UI_resources.hh" @@ -43,6 +44,61 @@ static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr) layout->prop(ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE); } +static std::optional node_type_for_socket_type(const bNodeSocket &socket) +{ + switch (socket.type) { + case SOCK_FLOAT: + return SOCK_FLOAT; + case SOCK_BOOLEAN: + return SOCK_BOOLEAN; + case SOCK_INT: + return SOCK_INT; + case SOCK_VECTOR: + case SOCK_RGBA: + return SOCK_VECTOR; + default: + return std::nullopt; + } +} + +static void node_gather_link_search_ops(GatherLinkSearchOpParams ¶ms) +{ + const bNodeSocket &other_socket = params.other_socket(); + const StructureType structure_type = other_socket.runtime->inferred_structure_type; + const bool is_grid = structure_type == StructureType::Grid; + const bool is_dynamic = structure_type == StructureType::Dynamic; + const eNodeSocketDatatype other_type = eNodeSocketDatatype(other_socket.type); + + if (params.in_out() == SOCK_IN) { + if (is_grid || is_dynamic) { + const std::optional data_type = node_type_for_socket_type(other_socket); + if (data_type) { + params.add_item(IFACE_("Grid"), [data_type](LinkSearchOpParams ¶ms) { + bNode &node = params.add_node("GeometryNodeGridInfo"); + node.custom1 = *data_type; + params.update_and_connect_available_socket(node, "Grid"); + }); + } + } + } + else { + if (params.node_tree().typeinfo->validate_link(SOCK_MATRIX, other_type)) { + params.add_item(IFACE_("Transform"), [](LinkSearchOpParams ¶ms) { + bNode &node = params.add_node("GeometryNodeGridInfo"); + params.update_and_connect_available_socket(node, "Transform"); + }); + } + const std::optional data_type = node_type_for_socket_type(other_socket); + if (data_type) { + params.add_item(IFACE_("Background Value"), [data_type](LinkSearchOpParams ¶ms) { + bNode &node = params.add_node("GeometryNodeGridInfo"); + node.custom1 = *data_type; + params.update_and_connect_available_socket(node, "Background Value"); + }); + } + } +} + static void node_geo_exec(GeoNodeExecParams params) { #ifdef WITH_OPENVDB @@ -103,6 +159,7 @@ static void node_register() ntype.ui_description = "Retrieve information about a volume grid"; ntype.nclass = NODE_CLASS_INPUT; ntype.initfunc = node_init; + ntype.gather_link_search_ops = node_gather_link_search_ops; ntype.geometry_node_execute = node_geo_exec; ntype.draw_buttons = node_layout; ntype.declare = node_declare;