Geometry Nodes: Don't allow UI attributes as modifier field inputs

This is an extension of 4669178fc3, applying the same changes to
attributes chosen in the field inputs of the geometry nodes modifier.
If a UI/internal attribute is used, the attribute name button will
have a red alert. Adding a disabled hint is currently a bit more complex.

Also hide UI attributes in attribute search for the named attribute node.

Part of D14934
This commit is contained in:
Jacques Lucke 2022-05-31 18:52:27 +02:00 committed by Hans Goudey
parent 610619c203
commit 96f20ddc1e
2 changed files with 23 additions and 8 deletions

View File

@ -82,8 +82,10 @@ static Vector<const GeometryAttributeInfo *> get_attribute_info_from_context(
if (const geo_log::GeometryValueLog *geo_value_log =
dynamic_cast<const geo_log::GeometryValueLog *>(value_log)) {
for (const GeometryAttributeInfo &attribute : geo_value_log->attributes()) {
if (names.add(attribute.name)) {
attributes.append(&attribute);
if (bke::allow_procedural_attribute_access(attribute.name)) {
if (names.add(attribute.name)) {
attributes.append(&attribute);
}
}
}
}

View File

@ -755,6 +755,7 @@ static void initialize_group_input(NodesModifierData &nmd,
{
const bNodeSocketType &socket_type = *socket.typeinfo();
const bNodeSocket &bsocket = *socket.bsocket();
const eNodeSocketDatatype socket_data_type = static_cast<eNodeSocketDatatype>(bsocket.type);
if (nmd.settings.properties == nullptr) {
socket_type.get_geometry_nodes_cpp_value(bsocket, r_value);
return;
@ -771,8 +772,7 @@ static void initialize_group_input(NodesModifierData &nmd,
}
if (!input_has_attribute_toggle(*nmd.node_group, socket.index())) {
init_socket_cpp_value_from_property(
*property, static_cast<eNodeSocketDatatype>(bsocket.type), r_value);
init_socket_cpp_value_from_property(*property, socket_data_type, r_value);
return;
}
@ -781,14 +781,17 @@ static void initialize_group_input(NodesModifierData &nmd,
const IDProperty *property_attribute_name = IDP_GetPropertyFromGroup(
nmd.settings.properties, (socket.identifier() + attribute_name_suffix).c_str());
if (property_use_attribute == nullptr || property_attribute_name == nullptr) {
init_socket_cpp_value_from_property(
*property, static_cast<eNodeSocketDatatype>(bsocket.type), r_value);
init_socket_cpp_value_from_property(*property, socket_data_type, r_value);
return;
}
const bool use_attribute = IDP_Int(property_use_attribute) != 0;
if (use_attribute) {
const StringRef attribute_name{IDP_String(property_attribute_name)};
if (!blender::bke::allow_procedural_attribute_access(attribute_name)) {
init_socket_cpp_value_from_property(*property, socket_data_type, r_value);
return;
}
auto attribute_input = std::make_shared<blender::bke::AttributeFieldInput>(
attribute_name, *socket_type.base_cpp_type);
GField attribute_field{std::move(attribute_input), 0};
@ -799,8 +802,7 @@ static void initialize_group_input(NodesModifierData &nmd,
cpp_type->construct_from_field(r_value, std::move(attribute_field));
}
else {
init_socket_cpp_value_from_property(
*property, static_cast<eNodeSocketDatatype>(bsocket.type), r_value);
init_socket_cpp_value_from_property(*property, socket_data_type, r_value);
}
}
@ -946,6 +948,9 @@ static MultiValueMap<AttributeDomain, OutputAttributeInfo> find_output_attribute
if (attribute_name.is_empty()) {
continue;
}
if (!blender::bke::allow_procedural_attribute_access(attribute_name)) {
continue;
}
const int index = socket->index();
const GPointer value = output_values[index];
@ -1431,6 +1436,14 @@ static void add_attribute_search_button(const bContext &C,
nullptr,
attribute_search_exec_fn,
nullptr);
char *attribute_name = RNA_string_get_alloc(
md_ptr, rna_path_attribute_name.c_str(), nullptr, 0, nullptr);
const bool access_allowed = blender::bke::allow_procedural_attribute_access(attribute_name);
MEM_freeN(attribute_name);
if (!access_allowed) {
UI_but_flag_enable(but, UI_BUT_REDALERT);
}
}
static void add_attribute_search_or_value_buttons(const bContext &C,