Geometry Nodes: add conversion warnings for closures and bundles

This adds warnings to inform the user when potentially unexpected implicit
conversions happen in the Separate Bundle and Evaluate closure node.

Pull Request: https://projects.blender.org/blender/blender/pulls/143645
This commit is contained in:
Jacques Lucke
2025-07-30 18:03:52 +02:00
parent 78c161585b
commit 7186ab7e86
2 changed files with 69 additions and 8 deletions

View File

@@ -137,10 +137,31 @@ static void node_geo_exec(GeoNodeExecParams params)
continue;
}
void *output_ptr = lf_params.get_output_data_ptr(i);
if (!implicitly_convert_socket_value(
*socket_value->type, socket_value->value, *stype, output_ptr))
{
construct_socket_default_value(*stype, output_ptr);
if (socket_value->type->type == stype->type) {
socket_value->type->geometry_nodes_cpp_type->copy_construct(socket_value->value, output_ptr);
}
else {
if (implicitly_convert_socket_value(
*socket_value->type, socket_value->value, *stype, output_ptr))
{
params.error_message_add(
NodeWarningType::Info,
fmt::format("{}: \"{}\" ({} " BLI_STR_UTF8_BLACK_RIGHT_POINTING_SMALL_TRIANGLE " {})",
TIP_("Implicit type conversion"),
name,
TIP_(socket_value->type->label),
TIP_(stype->label)));
}
else {
params.error_message_add(
NodeWarningType::Error,
fmt::format("{}: \"{}\" ({} " BLI_STR_UTF8_BLACK_RIGHT_POINTING_SMALL_TRIANGLE " {})",
TIP_("Conversion not supported"),
name,
TIP_(socket_value->type->label),
TIP_(stype->label)));
construct_socket_default_value(*stype, output_ptr);
}
}
lf_params.output_set(i);
}

View File

@@ -21,6 +21,8 @@
#include "FN_lazy_function_execute.hh"
#include "BLI_string_utf8_symbols.h"
namespace blender::nodes {
using bke::node_tree_reference_lifetimes::ReferenceSetInfo;
@@ -430,6 +432,7 @@ class LazyFunctionForEvaluateClosureNode : public LazyFunction {
for (const NodeGeometryEvaluateClosureInputItem &item :
Span{node_storage.input_items.items, node_storage.input_items.items_num})
{
const bke::bNodeSocketType *item_type = bke::node_socket_type_find_static(item.socket_type);
if (const std::optional<int> i = signature.find_input_index(item.name)) {
const ClosureSignature::Item &closure_item = signature.inputs[*i];
if (!btree_.typeinfo->validate_link(eNodeSocketDatatype(item.socket_type),
@@ -439,8 +442,26 @@ class LazyFunctionForEvaluateClosureNode : public LazyFunction {
*tree_logger->allocator,
{bnode_.identifier,
{NodeWarningType::Error,
fmt::format(fmt::runtime(TIP_("Closure input has incompatible type: \"{}\"")),
item.name)}});
fmt::format("{}: {} \"{}\" ({} " BLI_STR_UTF8_BLACK_RIGHT_POINTING_SMALL_TRIANGLE
" {})",
TIP_("Conversion not supported"),
TIP_("Input"),
item.name,
TIP_(item_type->label),
TIP_(closure_item.type->label))}});
}
else if (item.socket_type != closure_item.type->type) {
tree_logger->node_warnings.append(
*tree_logger->allocator,
{bnode_.identifier,
{NodeWarningType::Info,
fmt::format("{}: {} \"{}\" ({} " BLI_STR_UTF8_BLACK_RIGHT_POINTING_SMALL_TRIANGLE
" {})",
TIP_("Implicit type conversion"),
TIP_("Input"),
item.name,
TIP_(item_type->label),
TIP_(closure_item.type->label))}});
}
}
else {
@@ -456,6 +477,7 @@ class LazyFunctionForEvaluateClosureNode : public LazyFunction {
for (const NodeGeometryEvaluateClosureOutputItem &item :
Span{node_storage.output_items.items, node_storage.output_items.items_num})
{
const bke::bNodeSocketType *item_type = bke::node_socket_type_find_static(item.socket_type);
if (const std::optional<int> i = signature.find_output_index(item.name)) {
const ClosureSignature::Item &closure_item = signature.outputs[*i];
if (!btree_.typeinfo->validate_link(eNodeSocketDatatype(closure_item.type->type),
@@ -465,8 +487,26 @@ class LazyFunctionForEvaluateClosureNode : public LazyFunction {
*tree_logger->allocator,
{bnode_.identifier,
{NodeWarningType::Error,
fmt::format(fmt::runtime(TIP_("Closure output has incompatible type: \"{}\"")),
item.name)}});
fmt::format("{}: {} \"{}\" ({} " BLI_STR_UTF8_BLACK_RIGHT_POINTING_SMALL_TRIANGLE
" {})",
TIP_("Conversion not supported"),
TIP_("Output"),
item.name,
TIP_(closure_item.type->label),
TIP_(item_type->label))}});
}
else if (item.socket_type != closure_item.type->type) {
tree_logger->node_warnings.append(
*tree_logger->allocator,
{bnode_.identifier,
{NodeWarningType::Info,
fmt::format("{}: {} \"{}\" ({} " BLI_STR_UTF8_BLACK_RIGHT_POINTING_SMALL_TRIANGLE
" {})",
TIP_("Implicit type conversion"),
TIP_("Output"),
item.name,
TIP_(closure_item.type->label),
TIP_(item_type->label))}});
}
}
else {