Blender V5.0
NOD_geo_bundle.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "DNA_node_types.h"
8
9#include "NOD_socket_items.hh"
10
11namespace blender::nodes {
12
14 const int ntree_type)
15{
16 switch (ntree_type) {
17 case NTREE_GEOMETRY:
18 return ELEM(socket_type,
34 case NTREE_SHADER:
35 return ELEM(socket_type,
42 SOCK_INT);
43 default:
44 return false;
45 }
46}
47
51 static int node_type;
52 static constexpr StringRefNull node_idname = "NodeCombineBundle";
53 static constexpr bool has_type = true;
54 static constexpr bool has_name = true;
55 static constexpr bool has_name_validation = true;
56 static constexpr char unique_name_separator = '_';
58 static constexpr StringRefNull add_item = "NODE_OT_combine_bundle_item_add";
59 static constexpr StringRefNull remove_item = "NODE_OT_combine_bundle_item_remove";
60 static constexpr StringRefNull move_item = "NODE_OT_combine_bundle_item_move";
61 };
62 struct ui_idnames {
63 static constexpr StringRefNull list = "DATA_UL_combine_bundle_items";
64 };
65 struct rna_names {
66 static constexpr StringRefNull items = "bundle_items";
67 static constexpr StringRefNull active_index = "active_index";
68 };
69
71 {
72 auto *storage = static_cast<NodeCombineBundle *>(node.storage);
73 return {&storage->items, &storage->items_num, &storage->active_index};
74 }
75
76 static void copy_item(const ItemT &src, ItemT &dst)
77 {
78 dst = src;
79 dst.name = BLI_strdup_null(dst.name);
80 }
81
82 static void destruct_item(ItemT *item)
83 {
84 MEM_SAFE_FREE(item->name);
85 }
86
87 static void blend_write_item(BlendWriter *writer, const ItemT &item);
88 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
89
91 {
93 }
94
95 static char **get_name(ItemT &item)
96 {
97 return &item.name;
98 }
99
100 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
101 {
102 return socket_type_supported_in_bundle(socket_type, ntree_type);
103 }
104
106 ItemT &item,
107 const eNodeSocketDatatype socket_type,
108 const char *name)
109 {
110 auto *storage = static_cast<NodeCombineBundle *>(node.storage);
111 item.socket_type = socket_type;
112 item.identifier = storage->next_identifier++;
114 }
115
116 static std::string socket_identifier_for_item(const ItemT &item)
117 {
118 return "Item_" + std::to_string(item.identifier);
119 }
120
121 static std::string validate_name(const StringRef name);
122};
123
127 static int node_type;
128 static constexpr StringRefNull node_idname = "NodeSeparateBundle";
129 static constexpr bool has_type = true;
130 static constexpr bool has_name = true;
131 static constexpr bool has_name_validation = true;
132 static constexpr char unique_name_separator = '_';
134 static constexpr StringRefNull add_item = "NODE_OT_separate_bundle_item_add";
135 static constexpr StringRefNull remove_item = "NODE_OT_separate_bundle_item_remove";
136 static constexpr StringRefNull move_item = "NODE_OT_separate_bundle_item_move";
137 };
138 struct ui_idnames {
139 static constexpr StringRefNull list = "DATA_UL_separate_bundle_items";
140 };
141 struct rna_names {
142 static constexpr StringRefNull items = "bundle_items";
143 static constexpr StringRefNull active_index = "active_index";
144 };
145
147 {
148 auto *storage = static_cast<NodeSeparateBundle *>(node.storage);
149 return {&storage->items, &storage->items_num, &storage->active_index};
150 }
151
152 static void copy_item(const ItemT &src, ItemT &dst)
153 {
154 dst = src;
155 dst.name = BLI_strdup_null(dst.name);
156 }
157
158 static void destruct_item(ItemT *item)
159 {
160 MEM_SAFE_FREE(item->name);
161 }
162
163 static void blend_write_item(BlendWriter *writer, const ItemT &item);
164 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
165
167 {
168 return eNodeSocketDatatype(item.socket_type);
169 }
170
171 static char **get_name(ItemT &item)
172 {
173 return &item.name;
174 }
175
176 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
177 {
178 return socket_type_supported_in_bundle(socket_type, ntree_type);
179 }
180
182 ItemT &item,
183 const eNodeSocketDatatype socket_type,
184 const char *name)
185 {
186 auto *storage = static_cast<NodeSeparateBundle *>(node.storage);
187 item.socket_type = socket_type;
188 item.identifier = storage->next_identifier++;
190 }
191
192 static std::string socket_identifier_for_item(const ItemT &item)
193 {
194 return "Item_" + std::to_string(item.identifier);
195 }
196
197 static std::string validate_name(const StringRef name)
198 {
200 }
201};
202
203} // namespace blender::nodes
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
Definition string.cc:46
#define ELEM(...)
@ NTREE_SHADER
@ NTREE_GEOMETRY
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_VECTOR
@ SOCK_CLOSURE
@ SOCK_BOOLEAN
@ SOCK_MATERIAL
@ SOCK_SHADER
@ SOCK_MATRIX
@ SOCK_FLOAT
@ SOCK_IMAGE
@ SOCK_COLLECTION
@ SOCK_BUNDLE
@ SOCK_GEOMETRY
@ SOCK_ROTATION
@ SOCK_OBJECT
@ SOCK_STRING
@ SOCK_RGBA
#define MEM_SAFE_FREE(v)
void set_item_name_and_make_unique(bNode &node, typename Accessor::ItemT &item, const char *value)
bool socket_type_supported_in_bundle(const eNodeSocketDatatype socket_type, const int ntree_type)
const char * name
void * storage
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static eNodeSocketDatatype get_socket_type(const ItemT &item)
static void copy_item(const ItemT &src, ItemT &dst)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
static std::string validate_name(const StringRef name)
static constexpr StringRefNull node_idname
static socket_items::SocketItemsRef< ItemT > get_items_from_node(bNode &node)
static std::string socket_identifier_for_item(const ItemT &item)
static void init_with_socket_type_and_name(bNode &node, ItemT &item, const eNodeSocketDatatype socket_type, const char *name)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
static eNodeSocketDatatype get_socket_type(const ItemT &item)
static constexpr StringRefNull node_idname
static void copy_item(const ItemT &src, ItemT &dst)
static socket_items::SocketItemsRef< ItemT > get_items_from_node(bNode &node)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static std::string validate_name(const StringRef name)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static void init_with_socket_type_and_name(bNode &node, ItemT &item, const eNodeSocketDatatype socket_type, const char *name)
static std::string socket_identifier_for_item(const ItemT &item)