[Bf-blender-cvs] [a448949f255] temp-geometry-nodes-fields--anonymous-attributes: more uses of attribute id

Jacques Lucke noreply at git.blender.org
Tue Aug 24 17:55:08 CEST 2021


Commit: a448949f255757ee74c9fb18215cebfd0afd76f2
Author: Jacques Lucke
Date:   Tue Aug 24 17:30:56 2021 +0200
Branches: temp-geometry-nodes-fields--anonymous-attributes
https://developer.blender.org/rBa448949f255757ee74c9fb18215cebfd0afd76f2

more uses of attribute id

===================================================================

M	source/blender/blenkernel/BKE_attribute_access.hh
M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/blenkernel/intern/attribute_access_intern.hh
M	source/blender/blenkernel/intern/geometry_component_curve.cc
M	source/blender/blenkernel/intern/geometry_component_mesh.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index f72b950d1a9..7d90fedd99d 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -337,24 +337,27 @@ class CustomDataAttributes {
   std::optional<blender::fn::GSpan> get_for_read(
       const blender::bke::AttributeIDRef &attribute_id) const;
 
-  blender::fn::GVArrayPtr get_for_read(const StringRef name,
+  blender::fn::GVArrayPtr get_for_read(const AttributeIDRef &attribute_id,
                                        const CustomDataType data_type,
                                        const void *default_value) const;
 
   template<typename T>
-  blender::fn::GVArray_Typed<T> get_for_read(const blender::StringRef name,
+  blender::fn::GVArray_Typed<T> get_for_read(const blender::bke::AttributeIDRef &attribute_id,
                                              const T &default_value) const
   {
     const blender::fn::CPPType &cpp_type = blender::fn::CPPType::get<T>();
     const CustomDataType type = blender::bke::cpp_type_to_custom_data_type(cpp_type);
-    GVArrayPtr varray = this->get_for_read(name, type, &default_value);
+    GVArrayPtr varray = this->get_for_read(attribute_id, type, &default_value);
     return blender::fn::GVArray_Typed<T>(std::move(varray));
   }
 
-  std::optional<blender::fn::GMutableSpan> get_for_write(const blender::StringRef name);
-  bool create(const blender::StringRef name, const CustomDataType data_type);
-  bool create_by_move(const blender::StringRef name, const CustomDataType data_type, void *buffer);
-  bool remove(const blender::StringRef name);
+  std::optional<blender::fn::GMutableSpan> get_for_write(
+      const blender::bke::AttributeIDRef &attribute_id);
+  bool create(const blender::bke::AttributeIDRef &attribute_id, const CustomDataType data_type);
+  bool create_by_move(const blender::bke::AttributeIDRef &attribute_id,
+                      const CustomDataType data_type,
+                      void *buffer);
+  bool remove(const blender::bke::AttributeIDRef &attribute_id);
 
   bool foreach_attribute(const AttributeForeachCallback callback,
                          const AttributeDomain domain) const;
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index c429161e38b..df237e17035 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -93,7 +93,7 @@ class GeometryComponent {
 
   /* Return the data type and domain of an attribute with the given name if it exists. */
   std::optional<AttributeMetaData> attribute_get_meta_data(
-      const blender::StringRef attribute_name) const;
+      const blender::bke::AttributeIDRef &attribute_id) const;
 
   /* Returns true when the geometry component supports this attribute domain. */
   bool attribute_domain_supported(const AttributeDomain domain) const;
@@ -110,7 +110,7 @@ class GeometryComponent {
   /* Get read and write access to the highest priority attribute with the given name.
    * Returns null if the attribute does not exist. */
   blender::bke::WriteAttributeLookup attribute_try_get_for_write(
-      const blender::StringRef attribute_name);
+      const blender::bke::AttributeIDRef &attribute_id);
 
   /* Get a read-only attribute for the domain based on the given attribute. This can be used to
    * interpolate from one domain to another.
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 7dfe6c18727..fec9c3db397 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -380,7 +380,7 @@ ReadAttributeLookup CustomDataAttributeProvider::try_get_for_read(
 }
 
 WriteAttributeLookup CustomDataAttributeProvider::try_get_for_write(
-    GeometryComponent &component, const StringRef attribute_name) const
+    GeometryComponent &component, const AttributeIDRef &attribute_id) const
 {
   CustomData *custom_data = custom_data_access_.get_custom_data(component);
   if (custom_data == nullptr) {
@@ -388,9 +388,10 @@ WriteAttributeLookup CustomDataAttributeProvider::try_get_for_write(
   }
   const int domain_size = component.attribute_domain_size(domain_);
   for (CustomDataLayer &layer : MutableSpan(custom_data->layers, custom_data->totlayer)) {
-    if (layer.name != attribute_name) {
+    if (!custom_data_layer_matches_attribute_id(layer, attribute_id)) {
       continue;
     }
+    /* TODO: Properly handle anonymous attribute. */
     CustomData_duplicate_referenced_layer_named(custom_data, layer.type, layer.name, domain_size);
     const CustomDataType data_type = (CustomDataType)layer.type;
     switch (data_type) {
@@ -414,7 +415,7 @@ WriteAttributeLookup CustomDataAttributeProvider::try_get_for_write(
 }
 
 bool CustomDataAttributeProvider::try_delete(GeometryComponent &component,
-                                             const StringRef attribute_name) const
+                                             const AttributeIDRef &attribute_id) const
 {
   CustomData *custom_data = custom_data_access_.get_custom_data(component);
   if (custom_data == nullptr) {
@@ -423,7 +424,8 @@ bool CustomDataAttributeProvider::try_delete(GeometryComponent &component,
   const int domain_size = component.attribute_domain_size(domain_);
   for (const int i : IndexRange(custom_data->totlayer)) {
     const CustomDataLayer &layer = custom_data->layers[i];
-    if (this->type_is_supported((CustomDataType)layer.type) && layer.name == attribute_name) {
+    if (this->type_is_supported((CustomDataType)layer.type) &&
+        custom_data_layer_matches_attribute_id(layer, attribute_id)) {
       CustomData_free_layer(custom_data, layer.type, domain_size, i);
       return true;
     }
@@ -473,7 +475,7 @@ static bool add_named_custom_data_layer_from_attribute_init(const StringRef attr
 }
 
 bool CustomDataAttributeProvider::try_create(GeometryComponent &component,
-                                             const StringRef attribute_name,
+                                             const AttributeIDRef &attribute_id,
                                              const AttributeDomain domain,
                                              const CustomDataType data_type,
                                              const AttributeInit &initializer) const
@@ -489,13 +491,17 @@ bool CustomDataAttributeProvider::try_create(GeometryComponent &component,
     return false;
   }
   for (const CustomDataLayer &layer : Span(custom_data->layers, custom_data->totlayer)) {
-    if (layer.name == attribute_name) {
+    if (custom_data_layer_matches_attribute_id(layer, attribute_id)) {
       return false;
     }
   }
   const int domain_size = component.attribute_domain_size(domain_);
+  /* TODO: Handle anonymous attribute. */
+  if (!attribute_id.is_named()) {
+    return false;
+  }
   add_named_custom_data_layer_from_attribute_init(
-      attribute_name, *custom_data, data_type, domain_size, initializer);
+      attribute_id.name(), *custom_data, data_type, domain_size, initializer);
   return true;
 }
 
@@ -537,7 +543,7 @@ ReadAttributeLookup NamedLegacyCustomDataProvider::try_get_for_read(
 }
 
 WriteAttributeLookup NamedLegacyCustomDataProvider::try_get_for_write(
-    GeometryComponent &component, const StringRef attribute_name) const
+    GeometryComponent &component, const AttributeIDRef &attribute_id) const
 {
   CustomData *custom_data = custom_data_access_.get_custom_data(component);
   if (custom_data == nullptr) {
@@ -545,7 +551,7 @@ WriteAttributeLookup NamedLegacyCustomDataProvider::try_get_for_write(
   }
   for (CustomDataLayer &layer : MutableSpan(custom_data->layers, custom_data->totlayer)) {
     if (layer.type == stored_type_) {
-      if (layer.name == attribute_name) {
+      if (custom_data_layer_matches_attribute_id(layer, attribute_id)) {
         const int domain_size = component.attribute_domain_size(domain_);
         void *data_old = layer.data;
         void *data_new = CustomData_duplicate_referenced_layer_named(
@@ -561,7 +567,7 @@ WriteAttributeLookup NamedLegacyCustomDataProvider::try_get_for_write(
 }
 
 bool NamedLegacyCustomDataProvider::try_delete(GeometryComponent &component,
-                                               const StringRef attribute_name) const
+                                               const AttributeIDRef &attribute_id) const
 {
   CustomData *custom_data = custom_data_access_.get_custom_data(component);
   if (custom_data == nullptr) {
@@ -570,7 +576,7 @@ bool NamedLegacyCustomDataProvider::try_delete(GeometryComponent &component,
   for (const int i : IndexRange(custom_data->totlayer)) {
     const CustomDataLayer &layer = custom_data->layers[i];
     if (layer.type == stored_type_) {
-      if (layer.name == attribute_name) {
+      if (custom_data_layer_matches_attribute_id(layer, attribute_id)) {
         const int domain_size = component.attribute_domain_size(domain_);
         CustomData_free_layer(custom_data, stored_type_, domain_size, i);
         custom_data_access_.update_custom_data_pointers(component);
@@ -657,13 +663,13 @@ std::optional<GSpan> CustomDataAttributes::get_for_read(const AttributeIDRef &at
  * value if the attribute doesn't exist. If no default value is provided, the default value for the
  * type will be used.
  */
-GVArrayPtr CustomDataAttributes::get_for_read(const StringRef name,
+GVArrayPtr CustomDataAttributes::get_for_read(const AttributeIDRef &attribute_id,
                                               const CustomDataType data_type,
                                               const void *default_value) const
 {
   const CPPType *type = blender::bke::custom_data_type_to_cpp_type(data_type);
 
-  std::optional<GSpan> attribute = this->get_for_read(name);
+  std::optional<GSpan> attribute = this->get_for_read(attribute_id);
   if (!attribute) {
     const int domain_size = this->size_;
     return std::make_unique<GVArray_For_SingleValue>(
@@ -678,12 +684,12 @@ GVArrayPtr CustomDataAttributes::get_for_read(const StringRef name,
   r

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list