Blender V5.3
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"_ustr).structure_type(StructureType::Field);
30 b.add_output(data_type, "Value"_ustr)
31 .structure_type(StructureType::Field)
32 .propagate_references()
33 .align_with_previous();
34 }
35}
36
37static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
38{
39 layout.prop(ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
40 layout.prop(ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
41}
42
43static void node_init(bNodeTree * /*tree*/, bNode *node)
44{
45 node->custom1 = int(AttrDomain::Point);
46 node->custom2 = CD_PROP_FLOAT;
47}
48
50{
51 const bke::bNodeType &node_type = params.node_type();
52 const std::optional<eCustomDataType> type = bke::socket_type_to_custom_data_type(
53 params.other_socket().type);
54 if (type && *type != CD_PROP_STRING) {
55 params.add_item(IFACE_("Value"), [node_type, type](LinkSearchOpParams &params) {
56 bNode &node = params.add_node(node_type);
57 node.custom2 = *type;
58 params.update_and_connect_available_socket(node, "Value"_ustr);
59 });
60 }
61}
62
64{
65 const bNode &node = params.node();
66 const AttrDomain domain = AttrDomain(node.custom1);
67
68 GField src_field = params.extract_input<GField>("Value"_ustr);
69 params.set_output<GField>(
70 "Value"_ustr, GField::from_input<bke::EvaluateOnDomainInput>(std::move(src_field), domain));
71}
72
73static void node_rna(StructRNA *srna)
74{
76 "domain",
77 "Domain",
78 "Domain the field is evaluated in",
81 int(AttrDomain::Point));
82
84 "data_type",
85 "Data Type",
86 "",
91}
92
93static void node_register()
94{
95 static bke::bNodeType ntype;
96
97 geo_node_type_base(&ntype, "GeometryNodeFieldOnDomain"_ustr, GEO_NODE_EVALUATE_ON_DOMAIN);
98 ntype.ui_name = "Evaluate on Domain";
99 ntype.ui_description =
100 "Retrieve values from a field on a different domain besides the domain from the context";
101 ntype.enum_name_legacy = "FIELD_ON_DOMAIN";
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_on_domain_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define GEO_NODE_EVALUATE_ON_DOMAIN
#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_layout(ui::Layout &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)
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[]
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)