[Bf-blender-cvs] [d1fcf93f039] master: Geometry Nodes: disable attribute search for non-attribute string sockets

Jacques Lucke noreply at git.blender.org
Fri Oct 22 11:56:42 CEST 2021


Commit: d1fcf93f039b0546dfd01c33daf50bd135e34344
Author: Jacques Lucke
Date:   Fri Oct 22 11:56:05 2021 +0200
Branches: master
https://developer.blender.org/rBd1fcf93f039b0546dfd01c33daf50bd135e34344

Geometry Nodes: disable attribute search for non-attribute string sockets

This is a simplified version of D12730 by @erik85.

I added attribute search only to one legacy node for testing purposes.

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

M	source/blender/editors/space_node/drawnode.cc
M	source/blender/nodes/NOD_node_declaration.hh
M	source/blender/nodes/geometry/nodes/legacy/node_geo_attribute_fill.cc

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

diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index 5117544aba8..8a63a1f3505 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -73,6 +73,7 @@
 
 #include "NOD_composite.h"
 #include "NOD_geometry.h"
+#include "NOD_node_declaration.hh"
 #include "NOD_shader.h"
 #include "NOD_texture.h"
 #include "node_intern.h" /* own include */
@@ -3535,6 +3536,18 @@ static void node_file_output_socket_draw(bContext *C,
   }
 }
 
+static bool socket_needs_attribute_search(bNode &node, bNodeSocket &socket)
+{
+  if (node.declaration == nullptr) {
+    return false;
+  }
+  if (socket.in_out == SOCK_OUT) {
+    return false;
+  }
+  const int socket_index = BLI_findindex(&node.inputs, &socket);
+  return node.declaration->inputs()[socket_index]->is_attribute_name();
+}
+
 static void std_node_socket_draw(
     bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *node_ptr, const char *text)
 {
@@ -3591,8 +3604,8 @@ static void std_node_socket_draw(
       uiLayout *row = uiLayoutSplit(layout, 0.4f, false);
       uiItemL(row, text, 0);
 
-      const bNodeTree *node_tree = (const bNodeTree *)node_ptr->owner_id;
-      if (node_tree->type == NTREE_GEOMETRY) {
+      if (socket_needs_attribute_search(*node, *sock)) {
+        const bNodeTree *node_tree = (const bNodeTree *)node_ptr->owner_id;
         node_geometry_add_attribute_search_button(C, node_tree, node, ptr, row);
       }
       else {
diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh
index da0ce6a3907..1481e69c00e 100644
--- a/source/blender/nodes/NOD_node_declaration.hh
+++ b/source/blender/nodes/NOD_node_declaration.hh
@@ -88,6 +88,7 @@ class SocketDeclaration {
   bool hide_value_ = false;
   bool is_multi_input_ = false;
   bool no_mute_links_ = false;
+  bool is_attribute_name_ = false;
 
   InputSocketFieldType input_field_type_ = InputSocketFieldType::None;
   OutputFieldDependency output_field_dependency_;
@@ -105,6 +106,7 @@ class SocketDeclaration {
   StringRefNull name() const;
   StringRefNull description() const;
   StringRefNull identifier() const;
+  bool is_attribute_name() const;
 
   InputSocketFieldType input_field_type() const;
   const OutputFieldDependency &output_field_dependency() const;
@@ -163,6 +165,12 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
     return *(Self *)this;
   }
 
+  Self &is_attribute_name(bool value = true)
+  {
+    decl_->is_attribute_name_ = value;
+    return *(Self *)this;
+  }
+
   /** The input socket allows passing in a field. */
   Self &supports_field()
   {
@@ -349,6 +357,12 @@ inline StringRefNull SocketDeclaration::description() const
 {
   return description_;
 }
+
+inline bool SocketDeclaration::is_attribute_name() const
+{
+  return is_attribute_name_;
+}
+
 inline InputSocketFieldType SocketDeclaration::input_field_type() const
 {
   return input_field_type_;
diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_attribute_fill.cc b/source/blender/nodes/geometry/nodes/legacy/node_geo_attribute_fill.cc
index 3c50ae5c837..1458b6df9ba 100644
--- a/source/blender/nodes/geometry/nodes/legacy/node_geo_attribute_fill.cc
+++ b/source/blender/nodes/geometry/nodes/legacy/node_geo_attribute_fill.cc
@@ -24,7 +24,7 @@ namespace blender::nodes {
 static void geo_node_attribute_fill_declare(NodeDeclarationBuilder &b)
 {
   b.add_input<decl::Geometry>("Geometry");
-  b.add_input<decl::String>("Attribute");
+  b.add_input<decl::String>("Attribute").is_attribute_name();
   b.add_input<decl::Vector>("Value", "Value");
   b.add_input<decl::Float>("Value", "Value_001");
   b.add_input<decl::Color>("Value", "Value_002");



More information about the Bf-blender-cvs mailing list