diff options
author | Jacques Lucke <jacques@blender.org> | 2022-05-31 19:52:27 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-05-31 19:58:54 +0300 |
commit | 96f20ddc1e84e0f5036ea1bdda8381f037069f77 (patch) | |
tree | 3491451249a3019e5b515da4549e6a16b5f65025 /source/blender/modifiers/intern | |
parent | 610619c2031056330f174bcee590c363cb6b45fc (diff) |
Geometry Nodes: Don't allow UI attributes as modifier field inputs
This is an extension of 4669178fc3786e1, 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
Diffstat (limited to 'source/blender/modifiers/intern')
-rw-r--r-- | source/blender/modifiers/intern/MOD_nodes.cc | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index e0105e4962d..c1e16e1b8e5 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -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, |