Blender V5.0
node_geo_list.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6#include "NOD_rna_define.hh"
7#include "NOD_socket.hh"
9
10#include "RNA_enum_types.hh"
11
13#include "UI_resources.hh"
14
15#include "list_function_eval.hh"
16
17#include "node_geometry_util.hh"
18
20
22{
23 const bNode *node = b.node_or_null();
24
25 b.add_input<decl::Int>("Count").default_value(1).min(1).description(
26 "The number of elements in the list");
27
28 if (node != nullptr) {
30 b.add_input(type, "Value").field_on_all();
31 }
32
33 if (node != nullptr) {
35 b.add_output(type, "List").structure_type(StructureType::List);
36 }
37}
38
39static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
40{
41 layout->prop(ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
42}
43
45 public:
49 {
50 bNode &node = params.add_node("GeometryNodeList");
51 node.custom1 = socket_type;
52 params.update_and_connect_available_socket(node, socket_name);
53 }
54};
55
57{
58 if (!U.experimental.use_geometry_nodes_lists) {
59 return;
60 }
61 const eNodeSocketDatatype socket_type = eNodeSocketDatatype(params.other_socket().type);
62 if (params.in_out() == SOCK_IN) {
63 if (params.node_tree().typeinfo->validate_link(socket_type, SOCK_INT)) {
64 params.add_item(IFACE_("Count"), SocketSearchOp{"Count", SOCK_INT});
65 }
66 params.add_item(IFACE_("Value"), SocketSearchOp{"Value", socket_type});
67 }
68 else {
69 params.add_item(IFACE_("List"), SocketSearchOp{"List", socket_type});
70 }
71}
72
74{
75 const int count = params.extract_input<int>("Count");
76 if (count < 0) {
77 params.error_message_add(NodeWarningType::Error, "Count must not be negative");
78 params.set_default_remaining_outputs();
79 return;
80 }
81
82 GField field = params.extract_input<GField>("Value");
83 params.set_output("List", evaluate_field_to_list(std::move(field), count));
84}
85
86static void node_rna(StructRNA *srna)
87{
89 srna,
90 "data_type",
91 "Data Type",
92 "",
96 [](bContext * /*C*/, PointerRNA * /*ptr*/, PropertyRNA * /*prop*/, bool *r_free) {
97 *r_free = true;
98 return enum_items_filter(
101 });
102 });
103}
104
105static void node_register()
106{
107 static blender::bke::bNodeType ntype;
108 geo_node_type_base(&ntype, "GeometryNodeList");
109 ntype.ui_name = "List";
110 ntype.ui_description = "Create a list of values";
113 ntype.declare = node_declare;
117 node_rna(ntype.rna_ext.srna);
118}
120
121} // namespace blender::nodes::node_geo_list_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define IFACE_(msgid)
@ SOCK_IN
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_GEOMETRY
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define UI_ITEM_NONE
#define U
void operator()(LinkSearchOpParams &params)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
int count
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_geo_exec(GeoNodeExecParams params)
static void node_rna(StructRNA *srna)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
ListPtr evaluate_field_to_list(GField field, const int64_t count)
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)
bool socket_type_supports_fields(const eNodeSocketDatatype socket_type)
const EnumPropertyItem * enum_items_filter(const EnumPropertyItem *original_item_array, FunctionRef< bool(const EnumPropertyItem &item)> fn)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
StructRNA * srna
int16_t custom1
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
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