[Bf-blender-cvs] [e00a47ffd61] master: Geometry Nodes: store domain and data type in attribute hints

Jacques Lucke noreply at git.blender.org
Wed Mar 17 11:16:00 CET 2021


Commit: e00a47ffd611b0ab06dba2a4933ab15871d576e6
Author: Jacques Lucke
Date:   Wed Mar 17 11:15:39 2021 +0100
Branches: master
https://developer.blender.org/rBe00a47ffd611b0ab06dba2a4933ab15871d576e6

Geometry Nodes: store domain and data type in attribute hints

The information is not exposed in the attribute search yet.

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

M	source/blender/blenkernel/BKE_node_ui_storage.hh
M	source/blender/blenkernel/intern/node_ui_storage.cc
M	source/blender/editors/space_node/node_geometry_attribute_search.cc
M	source/blender/modifiers/intern/MOD_nodes.cc

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

diff --git a/source/blender/blenkernel/BKE_node_ui_storage.hh b/source/blender/blenkernel/BKE_node_ui_storage.hh
index a49ff988272..be9510179c3 100644
--- a/source/blender/blenkernel/BKE_node_ui_storage.hh
+++ b/source/blender/blenkernel/BKE_node_ui_storage.hh
@@ -20,13 +20,17 @@
 
 #include "BLI_hash.hh"
 #include "BLI_map.hh"
+#include "BLI_multi_value_map.hh"
 #include "BLI_session_uuid.h"
 #include "BLI_set.hh"
 
 #include "DNA_ID.h"
+#include "DNA_customdata_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_session_uuid_types.h"
 
+#include "BKE_attribute.h"
+
 struct ModifierData;
 struct Object;
 struct bNode;
@@ -77,9 +81,26 @@ struct NodeWarning {
   std::string message;
 };
 
+struct AvailableAttributeInfo {
+  AttributeDomain domain;
+  CustomDataType data_type;
+
+  uint64_t hash() const
+  {
+    uint64_t domain_hash = (uint64_t)domain;
+    uint64_t data_type_hash = (uint64_t)data_type;
+    return (domain_hash * 33) ^ (data_type_hash * 89);
+  }
+
+  friend bool operator==(const AvailableAttributeInfo &a, const AvailableAttributeInfo &b)
+  {
+    return a.domain == b.domain && a.data_type == b.data_type;
+  }
+};
+
 struct NodeUIStorage {
   blender::Vector<NodeWarning> warnings;
-  blender::Set<std::string> attribute_name_hints;
+  blender::MultiValueMap<std::string, AvailableAttributeInfo> attribute_hints;
 };
 
 struct NodeTreeUIStorage {
@@ -103,4 +124,6 @@ void BKE_nodetree_error_message_add(bNodeTree &ntree,
 void BKE_nodetree_attribute_hint_add(bNodeTree &ntree,
                                      const NodeTreeEvaluationContext &context,
                                      const bNode &node,
-                                     const blender::StringRef attribute_name);
+                                     const blender::StringRef attribute_name,
+                                     const AttributeDomain domain,
+                                     const CustomDataType data_type);
diff --git a/source/blender/blenkernel/intern/node_ui_storage.cc b/source/blender/blenkernel/intern/node_ui_storage.cc
index 97f52dd3727..f2a152ac00d 100644
--- a/source/blender/blenkernel/intern/node_ui_storage.cc
+++ b/source/blender/blenkernel/intern/node_ui_storage.cc
@@ -158,8 +158,11 @@ void BKE_nodetree_error_message_add(bNodeTree &ntree,
 void BKE_nodetree_attribute_hint_add(bNodeTree &ntree,
                                      const NodeTreeEvaluationContext &context,
                                      const bNode &node,
-                                     const StringRef attribute_name)
+                                     const StringRef attribute_name,
+                                     const AttributeDomain domain,
+                                     const CustomDataType data_type)
 {
   NodeUIStorage &node_ui_storage = node_ui_storage_ensure(ntree, context, node);
-  node_ui_storage.attribute_name_hints.add_as(attribute_name);
+  node_ui_storage.attribute_hints.add_as(attribute_name,
+                                         AvailableAttributeInfo{domain, data_type});
 }
diff --git a/source/blender/editors/space_node/node_geometry_attribute_search.cc b/source/blender/editors/space_node/node_geometry_attribute_search.cc
index b03346577a8..6d0cd254505 100644
--- a/source/blender/editors/space_node/node_geometry_attribute_search.cc
+++ b/source/blender/editors/space_node/node_geometry_attribute_search.cc
@@ -37,6 +37,7 @@
 
 using blender::IndexRange;
 using blender::Map;
+using blender::MultiValueMap;
 using blender::Set;
 using blender::StringRef;
 
@@ -62,9 +63,10 @@ static void attribute_search_update_fn(
     return;
   }
 
-  const Set<std::string> &attribute_name_hints = ui_storage->attribute_name_hints;
+  const MultiValueMap<std::string, AvailableAttributeInfo> &attribute_hints =
+      ui_storage->attribute_hints;
 
-  if (str[0] != '\0' && !attribute_name_hints.contains_as(StringRef(str))) {
+  if (str[0] != '\0' && attribute_hints.lookup_as(StringRef(str)).is_empty()) {
     /* Any string may be valid, so add the current search string with the hints. */
     UI_search_item_add(items, str, (void *)str, ICON_ADD, 0, 0);
   }
@@ -80,7 +82,7 @@ static void attribute_search_update_fn(
   const char *string = is_first ? "" : str;
 
   StringSearch *search = BLI_string_search_new();
-  for (const std::string &attribute_name : attribute_name_hints) {
+  for (const std::string &attribute_name : attribute_hints.keys()) {
     BLI_string_search_add(search, attribute_name.c_str(), (void *)&attribute_name);
   }
 
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 504dd434b1b..003002e5fac 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -456,9 +456,13 @@ class GeometryNodesEvaluator {
 
       for (const GeometryComponent *component : components) {
         component->attribute_foreach(
-            [&](StringRefNull attribute_name, const AttributeMetaData &UNUSED(meta_data)) {
-              BKE_nodetree_attribute_hint_add(
-                  *btree_original, context, *node->bnode(), attribute_name);
+            [&](StringRefNull attribute_name, const AttributeMetaData &meta_data) {
+              BKE_nodetree_attribute_hint_add(*btree_original,
+                                              context,
+                                              *node->bnode(),
+                                              attribute_name,
+                                              meta_data.domain,
+                                              meta_data.data_type);
               return true;
             });
       }



More information about the Bf-blender-cvs mailing list