Blender  V3.3
node_geo_input_named_attribute.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "UI_interface.h"
4 #include "UI_resources.h"
5 
7 
8 #include "node_geometry_util.hh"
9 
11 
13 
15 {
16  b.add_input<decl::String>(N_("Name")).is_attribute_name();
17 
18  b.add_output<decl::Vector>(N_("Attribute"), "Attribute_Vector").field_source();
19  b.add_output<decl::Float>(N_("Attribute"), "Attribute_Float").field_source();
20  b.add_output<decl::Color>(N_("Attribute"), "Attribute_Color").field_source();
21  b.add_output<decl::Bool>(N_("Attribute"), "Attribute_Bool").field_source();
22  b.add_output<decl::Int>(N_("Attribute"), "Attribute_Int").field_source();
23 }
24 
25 static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
26 {
27  uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
28 }
29 
31 {
32  NodeGeometryInputNamedAttribute *data = MEM_cnew<NodeGeometryInputNamedAttribute>(__func__);
33  data->data_type = CD_PROP_FLOAT;
34  node->storage = data;
35 }
36 
38 {
39  const NodeGeometryInputNamedAttribute &storage = node_storage(*node);
40  const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
41 
42  bNodeSocket *socket_vector = (bNodeSocket *)node->outputs.first;
43  bNodeSocket *socket_float = socket_vector->next;
44  bNodeSocket *socket_color4f = socket_float->next;
45  bNodeSocket *socket_boolean = socket_color4f->next;
46  bNodeSocket *socket_int32 = socket_boolean->next;
47 
48  nodeSetSocketAvailability(ntree, socket_vector, data_type == CD_PROP_FLOAT3);
49  nodeSetSocketAvailability(ntree, socket_float, data_type == CD_PROP_FLOAT);
50  nodeSetSocketAvailability(ntree, socket_color4f, data_type == CD_PROP_COLOR);
51  nodeSetSocketAvailability(ntree, socket_boolean, data_type == CD_PROP_BOOL);
52  nodeSetSocketAvailability(ntree, socket_int32, data_type == CD_PROP_INT32);
53 }
54 
56 {
57  const NodeDeclaration &declaration = *params.node_type().fixed_declaration;
59 
60  if (params.in_out() == SOCK_OUT) {
61  const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
62  static_cast<eNodeSocketDatatype>(params.other_socket().type));
63  if (type && *type != CD_PROP_STRING) {
64  /* The input and output sockets have the same name. */
65  params.add_item(IFACE_("Attribute"), [type](LinkSearchOpParams &params) {
66  bNode &node = params.add_node("GeometryNodeInputNamedAttribute");
67  node_storage(node).data_type = *type;
68  params.update_and_connect_available_socket(node, "Attribute");
69  });
70  }
71  }
72 }
73 
75 {
76  const NodeGeometryInputNamedAttribute &storage = node_storage(params.node());
77  const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
78 
79  const std::string name = params.extract_input<std::string>("Name");
80 
81  if (name.empty()) {
82  params.set_default_remaining_outputs();
83  return;
84  }
87  params.set_default_remaining_outputs();
88  return;
89  }
90 
91  params.used_named_attribute(name, eNamedAttrUsage::Read);
92 
93  switch (data_type) {
94  case CD_PROP_FLOAT:
95  params.set_output("Attribute_Float", AttributeFieldInput::Create<float>(std::move(name)));
96  break;
97  case CD_PROP_FLOAT3:
98  params.set_output("Attribute_Vector", AttributeFieldInput::Create<float3>(std::move(name)));
99  break;
100  case CD_PROP_COLOR:
101  params.set_output("Attribute_Color",
102  AttributeFieldInput::Create<ColorGeometry4f>(std::move(name)));
103  break;
104  case CD_PROP_BOOL:
105  params.set_output("Attribute_Bool", AttributeFieldInput::Create<bool>(std::move(name)));
106  break;
107  case CD_PROP_INT32:
108  params.set_output("Attribute_Int", AttributeFieldInput::Create<int>(std::move(name)));
109  break;
110  default:
111  break;
112  }
113 }
114 
115 } // namespace blender::nodes::node_geo_input_named_attribute_cc
116 
118 {
120 
121  static bNodeType ntype;
122 
130  node_type_storage(&ntype,
131  "NodeGeometryInputNamedAttribute",
134  nodeRegisterType(&ntype);
135 }
#define NODE_STORAGE_FUNCS(StorageT)
Definition: BKE_node.h:1563
void nodeSetSocketAvailability(struct bNodeTree *ntree, struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3664
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
#define GEO_NODE_INPUT_NAMED_ATTRIBUTE
Definition: BKE_node.h:1498
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4426
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define UNUSED(x)
#define TIP_(msgid)
#define IFACE_(msgid)
eCustomDataType
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ CD_PROP_COLOR
@ CD_PROP_INT32
@ CD_PROP_BOOL
@ CD_PROP_STRING
@ SOCK_OUT
eNodeSocketDatatype
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
in reality light always falls off quadratically Particle Info
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
Span< SocketDeclarationPtr > inputs() const
OperationNode * node
void * tree
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
bool allow_procedural_attribute_access(StringRef attribute_name)
const char * no_procedural_access_message
static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_update(bNodeTree *ntree, bNode *node)
std::optional< eCustomDataType > node_data_type_to_custom_data_type(const eNodeSocketDatatype type)
void search_link_ops_for_declarations(GatherLinkSearchOpParams &params, Span< SocketDeclarationPtr > declarations)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static void node_init(const struct bContext *C, bNodeTree *ntree, bNode *node)
Definition: node.cc:1082
void register_node_type_geo_input_named_attribute()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:55
void node_free_standard_storage(bNode *node)
Definition: node_util.c:43
struct bNodeSocket * next
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition: BKE_node.h:335
void(* updatefunc)(struct bNodeTree *ntree, struct bNode *node)
Definition: BKE_node.h:265
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480