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.
This commit is contained in:
Jacques Lucke 2021-10-22 11:56:05 +02:00
parent 675a22b341
commit d1fcf93f03
3 changed files with 30 additions and 3 deletions

@ -73,6 +73,7 @@
#include "NOD_composite.h" #include "NOD_composite.h"
#include "NOD_geometry.h" #include "NOD_geometry.h"
#include "NOD_node_declaration.hh"
#include "NOD_shader.h" #include "NOD_shader.h"
#include "NOD_texture.h" #include "NOD_texture.h"
#include "node_intern.h" /* own include */ #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( static void std_node_socket_draw(
bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *node_ptr, const char *text) 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); uiLayout *row = uiLayoutSplit(layout, 0.4f, false);
uiItemL(row, text, 0); uiItemL(row, text, 0);
const bNodeTree *node_tree = (const bNodeTree *)node_ptr->owner_id; if (socket_needs_attribute_search(*node, *sock)) {
if (node_tree->type == NTREE_GEOMETRY) { const bNodeTree *node_tree = (const bNodeTree *)node_ptr->owner_id;
node_geometry_add_attribute_search_button(C, node_tree, node, ptr, row); node_geometry_add_attribute_search_button(C, node_tree, node, ptr, row);
} }
else { else {

@ -88,6 +88,7 @@ class SocketDeclaration {
bool hide_value_ = false; bool hide_value_ = false;
bool is_multi_input_ = false; bool is_multi_input_ = false;
bool no_mute_links_ = false; bool no_mute_links_ = false;
bool is_attribute_name_ = false;
InputSocketFieldType input_field_type_ = InputSocketFieldType::None; InputSocketFieldType input_field_type_ = InputSocketFieldType::None;
OutputFieldDependency output_field_dependency_; OutputFieldDependency output_field_dependency_;
@ -105,6 +106,7 @@ class SocketDeclaration {
StringRefNull name() const; StringRefNull name() const;
StringRefNull description() const; StringRefNull description() const;
StringRefNull identifier() const; StringRefNull identifier() const;
bool is_attribute_name() const;
InputSocketFieldType input_field_type() const; InputSocketFieldType input_field_type() const;
const OutputFieldDependency &output_field_dependency() const; const OutputFieldDependency &output_field_dependency() const;
@ -163,6 +165,12 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
return *(Self *)this; 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. */ /** The input socket allows passing in a field. */
Self &supports_field() Self &supports_field()
{ {
@ -349,6 +357,12 @@ inline StringRefNull SocketDeclaration::description() const
{ {
return description_; return description_;
} }
inline bool SocketDeclaration::is_attribute_name() const
{
return is_attribute_name_;
}
inline InputSocketFieldType SocketDeclaration::input_field_type() const inline InputSocketFieldType SocketDeclaration::input_field_type() const
{ {
return input_field_type_; return input_field_type_;

@ -24,7 +24,7 @@ namespace blender::nodes {
static void geo_node_attribute_fill_declare(NodeDeclarationBuilder &b) static void geo_node_attribute_fill_declare(NodeDeclarationBuilder &b)
{ {
b.add_input<decl::Geometry>("Geometry"); 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::Vector>("Value", "Value");
b.add_input<decl::Float>("Value", "Value_001"); b.add_input<decl::Float>("Value", "Value_001");
b.add_input<decl::Color>("Value", "Value_002"); b.add_input<decl::Color>("Value", "Value_002");