18#include "RNA_prototypes.hh"
39 auto &index =
b.add_input<
decl::Int>(
"Index").
min(0).max(std::max<int>(0, items.
size() - 1));
40 if (supports_fields) {
41 index.supports_field();
46 auto &
input =
b.add_input(data_type, std::to_string(i), std::move(identifier));
47 if (supports_fields) {
48 input.supports_field();
54 auto &
output =
b.add_output(data_type,
"Output");
55 if (supports_fields) {
56 output.dependent_field().reference_pass_all();
75 panel->op(
"node.index_switch_item_add",
IFACE_(
"Add Item"), ICON_ADD);
79 row->
label(
node.input_socket(i + 1).name, ICON_NONE);
80 PointerRNA op_ptr = row->
op(
"node.index_switch_item_remove",
"", ICON_REMOVE);
94 ot,
"Remove Item", __func__,
"Remove an item from the index switch");
107 data->next_identifier = 0;
110 const int default_items_num = 2;
112 for (
const int i :
IndexRange(default_items_num)) {
113 data->items[i].identifier =
data->next_identifier++;
115 data->items_num = default_items_num;
125 node_storage(
node).data_type =
params.socket.type;
126 params.update_and_connect_available_socket(
node,
"Output");
131 if (
params.node_tree().typeinfo->validate_link(other_type,
SOCK_INT)) {
134 params.update_and_connect_available_socket(
node,
"Index");
150 builder.single_input<
int>(
"Index");
153 debug_names_[i] = std::to_string(i);
154 builder.single_input(debug_names_[i].c_str(), type);
156 builder.single_output(
"Output", type);
162 const int inputs_num = signature_.
params.size() - 2;
166 signature_.
params.index_range().last(),
"Output");
169 if (
const std::optional<int> i =
indices.get_if_single()) {
181 const int invalid_index = inputs_num;
194 if (!masks[i].is_empty()) {
214 bool can_be_field_ =
false;
215 const CPPType *field_base_type_;
226 const CPPType &cpp_type = *output_socket.
typeinfo->geometry_nodes_cpp_type;
230 field_base_type_ = output_socket.
typeinfo->base_cpp_type;
234 lf_index_by_bsocket[index_socket.index_in_tree()] =
inputs_.append_and_get_index_as(
236 lf_index_by_bsocket[output_socket.index_in_tree()] =
outputs_.append_and_get_index_as(
239 for (
const int i : storage.items_span().index_range()) {
241 lf_index_by_bsocket[
input.index_in_tree()] =
inputs_.append_and_get_index_as(
242 input.identifier, cpp_type, lf::ValueUsage::Maybe);
279 if (value_to_forward ==
nullptr) {
284 void *output_ptr =
params.get_output_data_ptr(0);
297 if (input_values.
as_span().contains(
nullptr)) {
307 std::unique_ptr<mf::MultiFunction> switch_fn = std::make_unique<IndexSwitchFunction>(
311 void *output_ptr =
params.get_output_data_ptr(0);
331 if (!
U.experimental.use_bundle_and_closure_nodes) {
332 if (ELEM(item.value, SOCK_BUNDLE, SOCK_CLOSURE)) {
359 socket_items::destruct_array<IndexSwitchItemsAccessor>(*
node);
367 dst_node->
storage = dst_storage;
369 socket_items::copy_array<IndexSwitchItemsAccessor>(*src_node, *dst_node);
374 return socket_items::try_add_item_via_any_extend_socket<IndexSwitchItemsAccessor>(
380 socket_items::blend_write<IndexSwitchItemsAccessor>(&writer,
node);
385 socket_items::blend_read_data<IndexSwitchItemsAccessor>(&reader,
node);
397 return &
node.input_socket(1);
405 ntype.
ui_name =
"Index Switch";
406 ntype.
ui_description =
"Choose between an arbitrary number of values with an index";
434 using namespace node_geo_index_switch_cc;
436 return std::make_unique<LazyFunctionForIndexSwitchNode>(
node, lf_graph_info);
#define NODE_CLASS_CONVERTER
#define NODE_STORAGE_FUNCS(StorageT)
#define GEO_NODE_INDEX_SWITCH
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
__forceinline float extract(const int4 &b)
Span< T > as_span() const
void reinitialize(const int64_t new_size)
static const CPPType & get()
void fill_construct_indices(const void *value, void *dst, const IndexMask &mask) const
const void * default_value() const
void move_construct(void *src, void *dst) const
constexpr bool contains(int64_t value) const
constexpr int64_t size() const
constexpr IndexRange index_range() const
void append(const T &value)
bool is_context_dependent_field() const
static std::shared_ptr< FieldOperation > Create(std::shared_ptr< const mf::MultiFunction > function, Vector< GField > inputs={})
Vector< Output > outputs_
void set_signature(const Signature *signature)
static void from_groups(const IndexMask &universe, IndexMaskMemory &memory, Fn &&get_group_index, MutableSpan< IndexMask > r_masks)
IndexSwitchFunction(const CPPType &type, const int items_num)
ExecutionHints get_execution_hints() const override
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
void execute_single(const int index, lf::Params ¶ms) const
void execute_field(Field< int > index, lf::Params ¶ms) const
LazyFunctionForIndexSwitchNode(const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
void execute_impl(lf::Params ¶ms, const lf::Context &) const override
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_callocN(size_t len, const char *str)
void * MEM_dupallocN(const void *vmemh)
void MEM_freeN(void *vmemh)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void node_register_type(bNodeType &ntype)
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))
static void node_copy_storage(bNodeTree *, bNode *dst_node, const bNode *src_node)
static void node_init(bNodeTree *, bNode *node)
static void node_blend_read(bNodeTree &, bNode &node, BlendDataReader &reader)
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void NODE_OT_index_switch_item_add(wmOperatorType *ot)
static void NODE_OT_index_switch_item_remove(wmOperatorType *ot)
static void node_declare(NodeDeclarationBuilder &b)
static void register_node()
static void node_rna(StructRNA *srna)
static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_operators()
static void node_blend_write(const bNodeTree &, const bNode &node, BlendWriter &writer)
constexpr int value_inputs_start
static void node_free_storage(bNode *node)
static const bNodeSocket * node_internally_linked_input(const bNodeTree &, const bNode &node, const bNodeSocket &)
static bool node_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
void remove_item_by_index(wmOperatorType *ot, const char *name, const char *idname, const char *description)
void add_item(wmOperatorType *ot, const char *name, const char *idname, const char *description)
std::unique_ptr< LazyFunction > get_index_switch_node_lazy_function(const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
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)
void set_default_remaining_node_outputs(lf::Params ¶ms, const bNode &node)
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)
static blender::bke::bNodeSocketTemplate inputs[]
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
bNodeSocketTypeHandle * typeinfo
NodeInternallyLinkedInputFunction internally_linked_input
NodeBlendWriteFunction blend_write_storage_content
std::string ui_description
NodeBlendDataReadFunction blend_data_read_storage_content
void(* initfunc)(bNodeTree *ntree, bNode *node)
void(* draw_buttons_ex)(uiLayout *, bContext *C, PointerRNA *ptr)
const char * enum_name_legacy
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
bool(* insert_link)(bNodeTree *ntree, bNode *node, bNodeLink *link)
NodeDeclareFunction declare
void(* register_operators)()
bool ignore_inferred_input_socket_visibility
Vector< ParamInfo > params
Array< int > lf_index_by_bsocket
GeometryNodeLazyFunctionGraphMapping mapping
static StructRNA * item_srna
static std::string socket_identifier_for_item(const IndexSwitchItem &item)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
PointerRNA op(wmOperatorType *ot, std::optional< blender::StringRef > name, int icon, wmOperatorCallContext context, eUI_Item_Flag flag)
PanelLayout panel(const bContext *C, blender::StringRef idname, bool default_closed)
void label(blender::StringRef name, int icon)
uiLayout & column(bool align)
uiLayout & row(bool align)
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)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))