12#include "RNA_prototypes.hh"
30#include "fmt/format.h"
40 bNode *current_node =
static_cast<bNode *
>(current_node_ptr->
data);
53 const bool is_zone_input_node = current_node->
type_legacy ==
60 if (is_zone_input_node) {
62 socket_items::ui::draw_items_list_with_operators<ForeachGeometryElementInputItemsAccessor>(
64 socket_items::ui::draw_active_item_props<ForeachGeometryElementInputItemsAccessor>(
66 panel->use_property_split_set(
true);
67 panel->use_property_decorate_set(
false);
68 panel->prop(item_ptr,
"socket_type",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
74 socket_items::ui::draw_items_list_with_operators<ForeachGeometryElementMainItemsAccessor>(
76 socket_items::ui::draw_active_item_props<ForeachGeometryElementMainItemsAccessor>(
78 panel->use_property_split_set(
true);
79 panel->use_property_decorate_set(
false);
80 panel->prop(item_ptr,
"socket_type",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
84 C,
"generation_items",
false,
IFACE_(
"Generated Geometry")))
86 socket_items::ui::draw_items_list_with_operators<
88 socket_items::ui::draw_active_item_props<ForeachGeometryElementGenerationItemsAccessor>(
91 storage.generation_items.items[
storage.generation_items.active_index];
92 panel->use_property_split_set(
true);
93 panel->use_property_decorate_set(
false);
94 panel->prop(item_ptr,
"socket_type",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
96 panel->prop(item_ptr,
"domain",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
102 layout.
prop(&output_node_ptr,
"inspection_index",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
111 b.use_custom_socket_order();
112 b.allow_any_socket_order();
116 b.add_default_layout();
118 if (!
node || !tree) {
131 "Index of the element in the source geometry. Note that the same index can occur more "
133 "once when iterating over multiple components at once");
137 "Single-element geometry for the current iteration. Note that it can be quite "
138 "inefficient to split up large geometries into many small geometries")
139 .propagate_all_geometry()
140 .available(output_storage &&
AttrDomain(output_storage->domain) != AttrDomain::Corner);
143 .description(
"Geometry whose elements are iterated over");
148 .evaluated_geometry_field()
149 .description(
"Selection on the iteration domain");
151 if (output_storage) {
152 for (
const int i :
IndexRange(output_storage->input_items.items_num)) {
158 b.add_input(socket_type, name, identifier)
161 .description(
"Field that is evaluated on the iteration domain")
162 .evaluated_geometry_field();
163 b.add_output(socket_type, name, identifier)
164 .align_with_previous()
165 .description(
"Evaluated field value for the current element");
170 .structure_type(StructureType::Dynamic)
172 socket_items::ui::draw_extend_socket_fn<ForeachGeometryElementInputItemsAccessor>());
174 .structure_type(StructureType::Dynamic)
175 .align_with_previous();
194 data->output_node_id = 0;
201 const int label_maxncpy)
222 "GeometryNodeForeachGeometryElementInput"_ustr,
224 ntype.
ui_name =
"For Each Geometry Element Input";
236 "NodeGeometryForeachGeometryElementInput",
251 b.use_custom_socket_order();
252 b.allow_any_socket_order();
256 "The original input geometry with potentially new attributes that are output by the "
269 b.add_input(socket_type, name, identifier)
273 "Attribute value that will be stored for the current element on the main geometry");
274 b.add_output(socket_type, name, identifier)
275 .align_with_previous()
276 .anonymous_attribute_output({0})
277 .description(
"Attribute on the geometry above");
281 socket_items::ui::draw_extend_socket_fn<ForeachGeometryElementMainItemsAccessor>());
282 b.add_output<
decl::Extend>(
""_ustr,
"__extend__main"_ustr).align_with_previous();
284 auto &panel =
b.add_panel(
"Generated"_ustr);
286 int previous_output_geometry_index = -1;
287 int previous_input_geometry_index = -1;
292 panel.add_separator();
297 auto &input_decl = panel.add_input(socket_type, name, identifier)
303 auto &output_decl = panel.add_output(socket_type, name, identifier).align_with_previous();
305 previous_input_geometry_index = input_decl.index();
306 previous_output_geometry_index = output_decl.index();
308 input_decl.description(
309 "Geometry generated in the current iteration. Will be joined with geometries from all "
311 output_decl.description(
"Result of joining generated geometries from each iteration");
314 if (previous_output_geometry_index > 0) {
315 input_decl.description(
"Field that will be stored as attribute on the geometry above");
316 input_decl.evaluated_geometry_field({previous_input_geometry_index});
317 output_decl.anonymous_attribute_output({previous_output_geometry_index});
319 output_decl.description(
"Attribute on the geometry above");
322 panel.add_input<
decl::Extend>(
""_ustr,
"__extend__generation"_ustr)
323 .custom_draw(socket_items::ui::draw_extend_socket_fn<
325 panel.add_output<
decl::Extend>(
""_ustr,
"__extend__generation"_ustr).align_with_previous();
332 MEM_new<NodeGeometryForeachGeometryElementOutput>(__func__);
334 data->generation_items.items = MEM_new_array<NodeForeachGeometryElementGenerationItem>(1,
340 data->generation_items.items_num = 1;
356 auto *dst_storage = MEM_new<NodeGeometryForeachGeometryElementOutput>(
358 dst_node->
storage = dst_storage;
387 if (
storage.generation_items.items_num > 0) {
390 row.
text =
RPT_(
"Missing Geometry");
391 row.
tooltip =
TIP_(
"Each output field has to correspond to a geometry that is above it");
392 row.
icon = ICON_STATUS_ERROR;
393 params.
rows.append(std::move(row));
433 params.add_item_full_name(
437 params.
node_tree.ensure_topology_cache();
465 "GeometryNodeForeachGeometryElementOutput"_ustr,
467 ntype.
ui_name =
"For Each Geometry Element Output";
494 &RNA_ForeachGeometryElementInputItem;
509 &RNA_ForeachGeometryElementMainItem;
524 &RNA_ForeachGeometryElementGenerationItem;
#define NODE_CLASS_INTERFACE
#define GEO_NODE_FOREACH_GEOMETRY_ELEMENT_INPUT
#define GEO_NODE_FOREACH_GEOMETRY_ELEMENT_OUTPUT
#define BLT_I18NCONTEXT_ID_NODETREE
#define CTX_IFACE_(context, msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
constexpr IndexRange()=default
std::optional< int > output_node_id
const bNode * output_node() const
const bNodeTreeZone * get_zone_by_node(const int32_t node_id) const
const bNodeSocket & other_socket() const
void add_item_full_name(std::string name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
void update_and_connect_available_socket(bNode &new_node, UString socket_name)
bNode & add_node(UString idname)
#define storage(slot, qualifiers)
void node_register_type(bNodeType &ntype)
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
static void node_extra_info(NodeExtraInfoParams ¶ms)
static void node_copy_storage(bNodeTree *, bNode *dst_node, const bNode *src_node)
static void node_register()
static void node_declare(NodeDeclarationBuilder &b)
static void node_blend_write(const bNodeTree &, const bNode &node, BlendWriter &writer)
static void node_free_storage(bNode *node)
static std::pair< bNode *, bNode * > add_foreach_zone(LinkSearchOpParams ¶ms)
NODE_STORAGE_FUNCS(NodeGeometryForeachGeometryElementOutput)
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void node_blend_read(bNodeTree &, bNode &node, BlendDataReader &reader)
static void node_operators()
static void node_init(bNodeTree *, bNode *node)
static bool node_insert_link(bke::NodeInsertLinkParams ¶ms)
static void node_layout_ex(ui::Layout &layout, bContext *C, PointerRNA *current_node_ptr)
void make_common_operators()
void blend_write(BlendWriter *writer, const bNode &node)
void destruct_array(bNode &node)
void blend_read_data(BlendDataReader *reader, bNode &node)
void copy_array(const bNode &src_node, bNode &dst_node)
bool try_add_item_via_any_extend_socket(bNodeTree &ntree, bNode &extend_node, bNode &storage_node, bNodeLink &link, const std::optional< StringRef > socket_identifier=std::nullopt, typename Accessor::ItemT **r_new_item=nullptr)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
BMesh const char void * data
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
void node_free_standard_storage(bNode *node)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
#define UI_MENU_ARROW_SEP
void write_string(const char *data)
eNodeSocketDatatype socket_type
eNodeSocketDatatype socket_type
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
NodeBlendWriteFunction blend_write_storage_content
void(*) register_operators()
NodeBlendDataReadFunction blend_data_read_storage_content
void(*) labelfunc(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
NodeExtraInfoFunction get_extra_info
void(*) draw_buttons_ex(ui::Layout &, bContext *C, PointerRNA *ptr)
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
bool(*) insert_link(NodeInsertLinkParams ¶ms)
NodeForeachGeometryElementGenerationItem ItemT
static StructRNA ** item_srna
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static std::string socket_identifier_for_item(const ItemT &item)
static std::string socket_identifier_for_item(const ItemT &item)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static StructRNA ** item_srna
NodeForeachGeometryElementMainItem ItemT
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
PanelLayout panel(const bContext *C, StringRef idname, bool default_closed)
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)