Blender V5.3
node_geo_evaluate_at_index.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include "NOD_rna_define.hh"
8
10#include "UI_resources.hh"
11
12#include "RNA_enum_types.hh"
13
15
17
19{
20 b.use_custom_socket_order();
21 b.allow_any_socket_order();
22 b.add_default_layout();
23 const bNode *node = b.node_or_null();
24 if (node != nullptr) {
25 const eCustomDataType data_type = eCustomDataType(node->custom2);
26 b.add_input(data_type, "Value"_ustr).hide_value().structure_type(StructureType::Field);
27 b.add_output(data_type, "Value"_ustr)
28 .structure_type(StructureType::Field)
29 .propagate_references()
30 .align_with_previous();
31 }
32 b.add_input<decl::Int>("Index"_ustr).min(0).structure_type(StructureType::Field);
33}
34
35static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
36{
37 layout.prop(ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
38 layout.prop(ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
39}
40
41static void node_init(bNodeTree * /*tree*/, bNode *node)
42{
43 node->custom1 = int(AttrDomain::Point);
44 node->custom2 = CD_PROP_FLOAT;
45}
46
48{
49 const bke::bNodeType &node_type = params.node_type();
50 const std::optional<eCustomDataType> type = bke::socket_type_to_custom_data_type(
51 params.other_socket().type);
52 if (type && *type != CD_PROP_STRING) {
53 params.add_item(IFACE_("Value"), [node_type, type](LinkSearchOpParams &params) {
54 bNode &node = params.add_node(node_type);
55 node.custom2 = *type;
56 params.update_and_connect_available_socket(node, "Value"_ustr);
57 });
58 if (params.in_out() == SOCK_IN) {
59 params.add_item(
60 IFACE_("Index"),
61 [node_type, type](LinkSearchOpParams &params) {
62 bNode &node = params.add_node(node_type);
63 node.custom2 = *type;
64 params.update_and_connect_available_socket(node, "Index"_ustr);
65 },
66 -1);
67 }
68 }
69}
70
72{
73 const bNode &node = params.node();
74 const AttrDomain domain = AttrDomain(node.custom1);
75
77 params.extract_input<Field<int>>("Index"_ustr),
78 params.extract_input<GField>("Value"_ustr),
79 domain);
80 params.set_output<GField>("Value"_ustr, std::move(output_field));
81}
82
83static void node_rna(StructRNA *srna)
84{
86 "domain",
87 "Domain",
88 "Domain the field is evaluated in",
91 int(AttrDomain::Point));
92
94 "data_type",
95 "Data Type",
96 "",
101}
102
103static void node_register()
104{
105 static bke::bNodeType ntype;
106
107 geo_node_type_base(&ntype, "GeometryNodeFieldAtIndex"_ustr, GEO_NODE_EVALUATE_AT_INDEX);
108 ntype.ui_name = "Evaluate at Index";
109 ntype.ui_description = "Retrieve data of other elements in the context's geometry";
110 ntype.enum_name_legacy = "FIELD_AT_INDEX";
114 ntype.initfunc = node_init;
115 ntype.declare = node_declare;
118
119 node_rna(ntype.rna_ext.srna);
120}
122
123} // namespace blender::nodes::node_geo_evaluate_at_index_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define GEO_NODE_EVALUATE_AT_INDEX
#define IFACE_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define UI_ITEM_NONE
static GField from_input(Args &&...args)
Definition FN_field.hh:482
const bke::bNodeType & node_type() const
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void update_and_connect_available_socket(bNode &new_node, UString socket_name)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
std::optional< eCustomDataType > socket_type_to_custom_data_type(eNodeSocketDatatype type)
Definition node.cc:5911
const EnumPropertyItem * attribute_type_type_with_socket_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
const EnumPropertyItem rna_enum_attribute_type_items[]
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
const EnumPropertyItem rna_enum_attribute_domain_items[]
#define min(a, b)
Definition sort.cc:38
eNodeSocketDatatype type
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:409
NodeDeclareFunction declare
Definition BKE_node.hh:393
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)