From 4669178fc3786e1aebb117892d8dc6a2ce4dc955 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 31 May 2022 13:20:16 +0200 Subject: [PATCH] Attributes: Hide internal UI attributes and disallow procedural access This commit hides "UI attributes" described in T97452 from the UI lists in mesh, curve, and point cloud properties, and disallow accessing them in geometry nodes. Internal UI attributes like selection and hiding values should use the attribute system for simplicity and performance, but we don't want to expose those attributes in the attribute panel, which is meant for regular user interaction. Procedural access may be misleading or cause problems, as described in the design task above. These attributes are added by two upcoming patches: D14934, D14685 Differential Revision: https://developer.blender.org/D15069 --- .../startup/bl_ui/properties_data_curves.py | 10 ++++++++++ .../scripts/startup/bl_ui/properties_data_mesh.py | 15 +++++++++++++-- .../startup/bl_ui/properties_data_pointcloud.py | 10 ++++++++++ source/blender/blenkernel/BKE_attribute.h | 1 + source/blender/blenkernel/BKE_attribute_access.hh | 3 +++ source/blender/blenkernel/intern/attribute.cc | 6 ++++++ .../blender/blenkernel/intern/attribute_access.cc | 8 ++++++++ .../interface_template_attribute_search.cc | 3 +++ .../spreadsheet_data_source_geometry.cc | 3 +++ source/blender/makesrna/intern/rna_attribute.c | 14 +++++++++++++- .../nodes/node_geo_input_named_attribute.cc | 5 +++++ .../geometry/nodes/node_geo_remove_attribute.cc | 5 +++++ .../nodes/node_geo_store_named_attribute.cc | 5 +++++ 13 files changed, 85 insertions(+), 3 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_data_curves.py b/release/scripts/startup/bl_ui/properties_data_curves.py index 4eefd5a0e0c..cf7117f2c85 100644 --- a/release/scripts/startup/bl_ui/properties_data_curves.py +++ b/release/scripts/startup/bl_ui/properties_data_curves.py @@ -78,6 +78,16 @@ class CURVES_MT_add_attribute(Menu): class CURVES_UL_attributes(UIList): + def filter_items(self, context, data, property): + attributes = getattr(data, property) + flags = [] + indices = [i for i in range(len(attributes))] + + for index, item in enumerate(attributes): + flags.append(self.bitflag_filter_item if item.is_internal else 0) + + return flags, indices + def draw_item(self, _context, layout, _data, attribute, _icon, _active_data, _active_propname, _index): data_type = attribute.bl_rna.properties['data_type'].enum_items[attribute.data_type] domain = attribute.bl_rna.properties['domain'].enum_items[attribute.domain] diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index 050bf56966f..d46ba31c960 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -497,6 +497,16 @@ class MESH_UL_attributes(UIList): 'CORNER': "Face Corner", } + def filter_items(self, context, data, property): + attributes = getattr(data, property) + flags = [] + indices = [i for i in range(len(attributes))] + + for index, item in enumerate(attributes): + flags.append(self.bitflag_filter_item if item.is_internal else 0) + + return flags, indices + def draw_item(self, _context, layout, _data, attribute, _icon, _active_data, _active_propname, _index): data_type = attribute.bl_rna.properties['data_type'].enum_items[attribute.data_type] @@ -576,7 +586,7 @@ class ColorAttributesListBase(): 'CORNER': "Face Corner", } - def filter_items(self, _context, data, property): + def filter_items(self, context, data, property): attrs = getattr(data, property) ret = [] idxs = [] @@ -584,7 +594,8 @@ class ColorAttributesListBase(): for idx, item in enumerate(attrs): skip = ( (item.domain not in {"POINT", "CORNER"}) or - (item.data_type not in {"FLOAT_COLOR", "BYTE_COLOR"}) + (item.data_type not in {"FLOAT_COLOR", "BYTE_COLOR"}) or + (not item.is_internal) ) ret.append(self.bitflag_filter_item if not skip else 0) idxs.append(idx) diff --git a/release/scripts/startup/bl_ui/properties_data_pointcloud.py b/release/scripts/startup/bl_ui/properties_data_pointcloud.py index 4f065a9ecfb..88d686b32f9 100644 --- a/release/scripts/startup/bl_ui/properties_data_pointcloud.py +++ b/release/scripts/startup/bl_ui/properties_data_pointcloud.py @@ -67,6 +67,16 @@ class POINTCLOUD_MT_add_attribute(Menu): class POINTCLOUD_UL_attributes(UIList): + def filter_items(self, context, data, property): + attributes = getattr(data, property) + flags = [] + indices = [i for i in range(len(attributes))] + + for index, item in enumerate(attributes): + flags.append(self.bitflag_filter_item if item.is_internal else 0) + + return flags, indices + def draw_item(self, _context, layout, _data, attribute, _icon, _active_data, _active_propname, _index): data_type = attribute.bl_rna.properties['data_type'].enum_items[attribute.data_type] diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h index cc50076e964..ebc95c4247c 100644 --- a/source/blender/blenkernel/BKE_attribute.h +++ b/source/blender/blenkernel/BKE_attribute.h @@ -49,6 +49,7 @@ typedef enum AttributeDomainMask { /* Attributes. */ bool BKE_id_attributes_supported(struct ID *id); +bool BKE_attribute_allow_procedural_access(const char *attribute_name); /** * Create a new attribute layer. diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh index 8d449a124ec..c8c7c4c6808 100644 --- a/source/blender/blenkernel/BKE_attribute_access.hh +++ b/source/blender/blenkernel/BKE_attribute_access.hh @@ -77,6 +77,9 @@ class AttributeIDRef { friend std::ostream &operator<<(std::ostream &stream, const AttributeIDRef &attribute_id); }; +bool allow_procedural_attribute_access(StringRef attribute_name); +extern const char *no_procedural_access_message; + } // namespace blender::bke /** diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc index 0007fea62cb..cfddae7721b 100644 --- a/source/blender/blenkernel/intern/attribute.cc +++ b/source/blender/blenkernel/intern/attribute.cc @@ -23,6 +23,7 @@ #include "BLI_string_utils.h" #include "BKE_attribute.h" +#include "BKE_attribute_access.hh" #include "BKE_curves.h" #include "BKE_customdata.h" #include "BKE_editmesh.h" @@ -116,6 +117,11 @@ bool BKE_id_attributes_supported(ID *id) return false; } +bool BKE_attribute_allow_procedural_access(const char *attribute_name) +{ + return blender::bke::allow_procedural_attribute_access(attribute_name); +} + bool BKE_id_attribute_rename(ID *id, CustomDataLayer *layer, const char *new_name, diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index e86bac21084..e487bf4acf6 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -55,6 +55,14 @@ std::ostream &operator<<(std::ostream &stream, const AttributeIDRef &attribute_i return stream; } +const char *no_procedural_access_message = + "This attribute can not be accessed in a procedural context"; + +bool allow_procedural_attribute_access(StringRef attribute_name) +{ + return !attribute_name.startswith(".selection"); +} + static int attribute_data_type_complexity(const CustomDataType data_type) { switch (data_type) { diff --git a/source/blender/editors/interface/interface_template_attribute_search.cc b/source/blender/editors/interface/interface_template_attribute_search.cc index dc8f568d025..65764e31ec8 100644 --- a/source/blender/editors/interface/interface_template_attribute_search.cc +++ b/source/blender/editors/interface/interface_template_attribute_search.cc @@ -91,6 +91,9 @@ void attribute_search_add_items(StringRefNull str, if (item->name == "normal" && item->domain == ATTR_DOMAIN_FACE) { continue; } + if (!bke::allow_procedural_attribute_access(item->name)) { + continue; + } BLI_string_search_add(search, item->name.c_str(), (void *)item, 0); } diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc index 7f696efabf7..ac15b77fde0 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc @@ -81,6 +81,9 @@ void GeometryDataSource::foreach_default_column_ids( if (attribute_id.is_anonymous()) { return true; } + if (!bke::allow_procedural_attribute_access(attribute_id.name())) { + return true; + } SpreadsheetColumnID column_id; column_id.name = (char *)attribute_id.name().data(); fn(column_id, false); diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c index 36706c82366..0cea693cd2a 100644 --- a/source/blender/makesrna/intern/rna_attribute.c +++ b/source/blender/makesrna/intern/rna_attribute.c @@ -232,6 +232,12 @@ static int rna_Attribute_domain_get(PointerRNA *ptr) return BKE_id_attribute_domain(ptr->owner_id, ptr->data); } +static bool rna_Attribute_is_internal_get(PointerRNA *ptr) +{ + const CustomDataLayer *layer = (const CustomDataLayer *)ptr->data; + return BKE_attribute_allow_procedural_access(layer->name); +} + static void rna_Attribute_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { ID *id = ptr->owner_id; @@ -930,6 +936,12 @@ static void rna_def_attribute(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Domain", "Domain of the Attribute"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); + prop = RNA_def_property(srna, "is_internal", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_Attribute_is_internal_get", NULL); + RNA_def_property_ui_text( + prop, "Is Internal", "The attribute is meant for internal use by Blender"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + /* types */ rna_def_attribute_float(brna); rna_def_attribute_float_vector(brna); @@ -942,7 +954,7 @@ static void rna_def_attribute(BlenderRNA *brna) rna_def_attribute_int8(brna); } -/* Mesh/PointCloud/Hair.attributes */ +/* Mesh/PointCloud/Curves.attributes */ static void rna_def_attribute_group(BlenderRNA *brna) { StructRNA *srna; diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc index 72dfff7cb39..553ea6cfcf0 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc @@ -82,6 +82,11 @@ static void node_geo_exec(GeoNodeExecParams params) params.set_default_remaining_outputs(); return; } + if (!bke::allow_procedural_attribute_access(name)) { + params.error_message_add(NodeWarningType::Info, TIP_(bke::no_procedural_access_message)); + params.set_default_remaining_outputs(); + return; + } params.used_named_attribute(name, NamedAttributeUsage::Read); diff --git a/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc index effeac5a37f..ecda35f6363 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc @@ -21,6 +21,11 @@ static void node_geo_exec(GeoNodeExecParams params) params.set_output("Geometry", std::move(geometry_set)); return; } + if (!bke::allow_procedural_attribute_access(name)) { + params.error_message_add(NodeWarningType::Info, TIP_(bke::no_procedural_access_message)); + params.set_output("Geometry", std::move(geometry_set)); + return; + } std::atomic attribute_exists = false; std::atomic cannot_delete = false; diff --git a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc index 3b348dd0136..669740f27cb 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc @@ -131,6 +131,11 @@ static void node_geo_exec(GeoNodeExecParams params) params.set_output("Geometry", std::move(geometry_set)); return; } + if (!bke::allow_procedural_attribute_access(name)) { + params.error_message_add(NodeWarningType::Info, TIP_(bke::no_procedural_access_message)); + params.set_output("Geometry", std::move(geometry_set)); + return; + } params.used_named_attribute(name, NamedAttributeUsage::Write);