[Bf-blender-cvs] [8bdd996cd0d] master: Geometry Nodes: Add helper function to check if attribute exists

Hans Goudey noreply at git.blender.org
Thu Dec 10 17:50:44 CET 2020


Commit: 8bdd996cd0de794f21d5f201a3af0a9cca9e8e5e
Author: Hans Goudey
Date:   Thu Dec 10 10:50:37 2020 -0600
Branches: master
https://developer.blender.org/rB8bdd996cd0de794f21d5f201a3af0a9cca9e8e5e

Geometry Nodes: Add helper function to check if attribute exists

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

M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/blenkernel/intern/attribute_access.cc

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

diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index 3398da9896b..b7cb9320086 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -88,6 +88,9 @@ class GeometryComponent {
 
   GeometryComponentType type() const;
 
+  /* Return true when any attribute with this name exists, including built in attributes. */
+  bool attribute_exists(const blender::StringRef attribute_name) const;
+
   /* Returns true when the geometry component supports this attribute domain. */
   virtual bool attribute_domain_supported(const AttributeDomain domain) const;
   /* Returns true when the given data type is supported in the given domain. */
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index d79168d5443..282e9bc2962 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -590,6 +590,15 @@ Set<std::string> GeometryComponent::attribute_names() const
   return {};
 }
 
+bool GeometryComponent::attribute_exists(const blender::StringRef attribute_name) const
+{
+  ReadAttributePtr attribute = this->attribute_try_get_for_read(attribute_name);
+  if (attribute) {
+    return true;
+  }
+  return false;
+}
+
 static ReadAttributePtr try_adapt_data_type(ReadAttributePtr attribute,
                                             const blender::fn::CPPType &to_type)
 {



More information about the Bf-blender-cvs mailing list