Blender V5.0
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").hide_value().supports_field();
27 b.add_output(data_type, "Value").field_source_reference_all().align_with_previous();
28 }
29 b.add_input<decl::Int>("Index").min(0).supports_field();
30}
31
32static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
33{
34 layout->prop(ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
35 layout->prop(ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
36}
37
38static void node_init(bNodeTree * /*tree*/, bNode *node)
39{
40 node->custom1 = int(AttrDomain::Point);
41 node->custom2 = CD_PROP_FLOAT;
42}
43
45{
46 const blender::bke::bNodeType &node_type = params.node_type();
47 const std::optional<eCustomDataType> type = bke::socket_type_to_custom_data_type(
48 eNodeSocketDatatype(params.other_socket().type));
49 if (type && *type != CD_PROP_STRING) {
50 params.add_item(IFACE_("Value"), [node_type, type](LinkSearchOpParams &params) {
51 bNode &node = params.add_node(node_type);
52 node.custom2 = *type;
53 params.update_and_connect_available_socket(node, "Value");
54 });
55 params.add_item(
56 IFACE_("Index"),
57 [node_type, type](LinkSearchOpParams &params) {
58 bNode &node = params.add_node(node_type);
59 node.custom2 = *type;
60 params.update_and_connect_available_socket(node, "Index");
61 },
62 -1);
63 }
64}
65
67{
68 const bNode &node = params.node();
69 const AttrDomain domain = AttrDomain(node.custom1);
70
71 GField output_field{std::make_shared<bke::EvaluateAtIndexInput>(
72 params.extract_input<Field<int>>("Index"), params.extract_input<GField>("Value"), domain)};
73 params.set_output<GField>("Value", std::move(output_field));
74}
75
76static void node_rna(StructRNA *srna)
77{
79 "domain",
80 "Domain",
81 "Domain the field is evaluated in",
84 int(AttrDomain::Point));
85
87 "data_type",
88 "Data Type",
89 "",
94}
95
96static void node_register()
97{
98 static blender::bke::bNodeType ntype;
99
100 geo_node_type_base(&ntype, "GeometryNodeFieldAtIndex", GEO_NODE_EVALUATE_AT_INDEX);
101 ntype.ui_name = "Evaluate at Index";
102 ntype.ui_description = "Retrieve data of other elements in the context's geometry";
103 ntype.enum_name_legacy = "FIELD_AT_INDEX";
107 ntype.initfunc = node_init;
108 ntype.declare = node_declare;
111
112 node_rna(ntype.rna_ext.srna);
113}
115
116} // namespace blender::nodes::node_geo_evaluate_at_index_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define GEO_NODE_EVALUATE_AT_INDEX
#define IFACE_(msgid)
@ CD_PROP_FLOAT
@ CD_PROP_STRING
eNodeSocketDatatype
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define UI_ITEM_NONE
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
std::optional< eCustomDataType > socket_type_to_custom_data_type(eNodeSocketDatatype type)
Definition node.cc:5144
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(uiLayout *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)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
const EnumPropertyItem rna_enum_attribute_domain_items[]
const EnumPropertyItem rna_enum_attribute_type_items[]
#define min(a, b)
Definition sort.cc:36
StructRNA * srna
int16_t custom1
int16_t custom2
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:378
NodeDeclareFunction declare
Definition BKE_node.hh:362
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238