Blender V5.0
node_geo_evaluate_on_domain.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
13
14#include "RNA_enum_types.hh"
15
17
19
21{
22 b.use_custom_socket_order();
23 b.allow_any_socket_order();
24 b.add_default_layout();
25 const bNode *node = b.node_or_null();
26
27 if (node != nullptr) {
28 const eCustomDataType data_type = eCustomDataType(node->custom2);
29 b.add_input(data_type, "Value").supports_field();
30 b.add_output(data_type, "Value").field_source_reference_all().align_with_previous();
31 }
32}
33
34static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
35{
36 layout->prop(ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
37 layout->prop(ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
38}
39
40static void node_init(bNodeTree * /*tree*/, bNode *node)
41{
42 node->custom1 = int(AttrDomain::Point);
43 node->custom2 = CD_PROP_FLOAT;
44}
45
47{
48 const blender::bke::bNodeType &node_type = params.node_type();
49 const std::optional<eCustomDataType> type = bke::socket_type_to_custom_data_type(
50 eNodeSocketDatatype(params.other_socket().type));
51 if (type && *type != CD_PROP_STRING) {
52 params.add_item(IFACE_("Value"), [node_type, type](LinkSearchOpParams &params) {
53 bNode &node = params.add_node(node_type);
54 node.custom2 = *type;
55 params.update_and_connect_available_socket(node, "Value");
56 });
57 }
58}
59
61{
62 const bNode &node = params.node();
63 const AttrDomain domain = AttrDomain(node.custom1);
64
65 GField src_field = params.extract_input<GField>("Value");
66 GField dst_field{std::make_shared<bke::EvaluateOnDomainInput>(std::move(src_field), domain)};
67 params.set_output<GField>("Value", std::move(dst_field));
68}
69
70static void node_rna(StructRNA *srna)
71{
73 "domain",
74 "Domain",
75 "Domain the field is evaluated in",
78 int(AttrDomain::Point));
79
81 "data_type",
82 "Data Type",
83 "",
88}
89
90static void node_register()
91{
92 static blender::bke::bNodeType ntype;
93
94 geo_node_type_base(&ntype, "GeometryNodeFieldOnDomain", GEO_NODE_EVALUATE_ON_DOMAIN);
95 ntype.ui_name = "Evaluate on Domain";
96 ntype.ui_description =
97 "Retrieve values from a field on a different domain besides the domain from the context";
98 ntype.enum_name_legacy = "FIELD_ON_DOMAIN";
102 ntype.initfunc = node_init;
103 ntype.declare = node_declare;
106
107 node_rna(ntype.rna_ext.srna);
108}
110
111} // namespace blender::nodes::node_geo_evaluate_on_domain_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define GEO_NODE_EVALUATE_ON_DOMAIN
#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_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
static void node_declare(NodeDeclarationBuilder &b)
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[]
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