Blender V4.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
9#include "UI_interface.hh"
10#include "UI_resources.hh"
11
12#include "BLI_task.hh"
13
14#include "RNA_enum_types.hh"
15
17
19
21{
22 const bNode *node = b.node_or_null();
23
24 b.add_input<decl::Int>("Index").min(0).supports_field();
25 if (node != nullptr) {
26 const eCustomDataType data_type = eCustomDataType(node->custom2);
27 b.add_input(data_type, "Value").hide_value().supports_field();
28
29 b.add_output(data_type, "Value").field_source_reference_all();
30 }
31}
32
33static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
34{
35 uiItemR(layout, ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
36 uiItemR(layout, ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
37}
38
39static void node_init(bNodeTree * /*tree*/, bNode *node)
40{
41 node->custom1 = int(AttrDomain::Point);
42 node->custom2 = CD_PROP_FLOAT;
43}
44
46{
47 const blender::bke::bNodeType &node_type = params.node_type();
48 const std::optional<eCustomDataType> type = bke::socket_type_to_custom_data_type(
49 eNodeSocketDatatype(params.other_socket().type));
50 if (type && *type != CD_PROP_STRING) {
51 params.add_item(IFACE_("Value"), [node_type, type](LinkSearchOpParams &params) {
52 bNode &node = params.add_node(node_type);
53 node.custom2 = *type;
54 params.update_and_connect_available_socket(node, "Value");
55 });
56 params.add_item(
57 IFACE_("Index"),
58 [node_type, type](LinkSearchOpParams &params) {
59 bNode &node = params.add_node(node_type);
60 node.custom2 = *type;
61 params.update_and_connect_available_socket(node, "Index");
62 },
63 -1);
64 }
65}
66
68{
69 const bNode &node = params.node();
70 const AttrDomain domain = AttrDomain(node.custom1);
71
72 GField output_field{std::make_shared<bke::EvaluateAtIndexInput>(
73 params.extract_input<Field<int>>("Index"), params.extract_input<GField>("Value"), domain)};
74 params.set_output<GField>("Value", std::move(output_field));
75}
76
77static void node_rna(StructRNA *srna)
78{
80 "domain",
81 "Domain",
82 "Domain the field is evaluated in",
85 int(AttrDomain::Point));
86
88 "data_type",
89 "Data Type",
90 "",
95}
96
97static void node_register()
98{
99 static blender::bke::bNodeType ntype;
100
102 &ntype, GEO_NODE_EVALUATE_AT_INDEX, "Evaluate at Index", NODE_CLASS_CONVERTER);
105 ntype.initfunc = node_init;
106 ntype.declare = node_declare;
109
110 node_rna(ntype.rna_ext.srna);
111}
113
114} // namespace blender::nodes::node_geo_evaluate_at_index_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
#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
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
std::optional< eCustomDataType > socket_type_to_custom_data_type(eNodeSocketDatatype type)
Definition node.cc:4379
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, int type, const char *name, short nclass)
const EnumPropertyItem rna_enum_attribute_domain_items[]
const EnumPropertyItem rna_enum_attribute_type_items[]
#define min(a, b)
Definition sort.c:32
StructRNA * srna
Definition RNA_types.hh:780
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:363
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126