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
This commit is contained in:
Brady Johnston
2025-10-08 14:09:08 +02:00
committed by Hans Goudey
parent 14966dfe0f
commit 9a8fb5fe98

View File

@@ -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<eNodeSocketDatatype> 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 &params)
{
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<eNodeSocketDatatype> data_type = node_type_for_socket_type(other_socket);
if (data_type) {
params.add_item(IFACE_("Grid"), [data_type](LinkSearchOpParams &params) {
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 &params) {
bNode &node = params.add_node("GeometryNodeGridInfo");
params.update_and_connect_available_socket(node, "Transform");
});
}
const std::optional<eNodeSocketDatatype> data_type = node_type_for_socket_type(other_socket);
if (data_type) {
params.add_item(IFACE_("Background Value"), [data_type](LinkSearchOpParams &params) {
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;