32 auto &switch_decl =
b.add_input<
decl::Bool>(
"Switch"_ustr);
35 if (!node_tree || !
node) {
41 auto &false_decl =
b.add_input(socket_type,
"False"_ustr);
42 auto &true_decl =
b.add_input(socket_type,
"True"_ustr);
43 auto &output_decl =
b.add_output(socket_type,
"Output"_ustr).propagate_all();
45 StructureType value_structure_type = StructureType::Dynamic;
46 StructureType condition_structure_type = StructureType::Dynamic;
51 if (is_single_compositor_type) {
52 value_structure_type = StructureType::Single;
54 condition_structure_type = StructureType::Single;
61 output_decl.inferred_structure_type();
64 output_decl.inferred_structure_type({false_decl.index(), true_decl.index()});
68 switch_decl.structure_type(condition_structure_type);
69 false_decl.structure_type(value_structure_type);
70 true_decl.structure_type(value_structure_type);
71 output_decl.structure_type(value_structure_type);
97 int true_false_weights = 0;
103 true_false_weights--;
128 bool can_be_field_ =
false;
140 if (socket->type == data_type) {
141 socket_type = socket->typeinfo;
149 debug_name_ =
node.name;
151 inputs_.append_as(
"False", cpp_type, lf::ValueUsage::Maybe);
152 inputs_.append_as(
"True", cpp_type, lf::ValueUsage::Maybe);
153 outputs_.append_as(
"Value", cpp_type);
156 void execute_impl(lf::Params ¶ms,
const lf::Context &context)
const override
172 tree_logger->node_warnings.append(
173 *tree_logger->allocator,
174 {node_id_, {NodeWarningType::Error, N_(
"Type cannot be switched by a field")}});
177 this->
execute_single(condition_variant.ensure_type<
bool>(), params);
188 params.set_input_unused(input_to_ignore);
189 void *value_to_forward = params.try_get_input_data_ptr_or_request(input_to_forward);
190 if (value_to_forward ==
nullptr) {
195 const CPPType &type = *outputs_[0].type;
196 void *output_ptr = params.get_output_data_ptr(0);
198 params.output_set(0);
204 auto *false_value_variant = params.try_get_input_data_ptr_or_request<
SocketValueVariant>(
206 auto *true_value_variant = params.try_get_input_data_ptr_or_request<
SocketValueVariant>(
208 if (
ELEM(
nullptr, false_value_variant, true_value_variant)) {
215 GField false_field = std::move(false_value_variant->ensure_type<
GField>());
219 switch_multi_function,
220 {std::move(
condition), std::move(false_field), std::move(true_field)})};
222 void *output_ptr = params.get_output_data_ptr(0);
224 params.output_set(0);
229 const MultiFunction *switch_multi_function =
nullptr;
230 base_type_->to_static_type<
float,
239 static auto switch_fn = mf::build::SI3_SO<bool, T, T, T>(
240 "Switch", [](
const bool condition,
const T &false_value,
const T &true_value) {
241 return condition ? true_value : false_value;
243 switch_multi_function = &switch_fn;
246 return *switch_multi_function;
265 return this->
get_input(
"Switch").get_single_value_default<
bool>();
279 return &
node.input_socket(1);
336 return std::make_unique<LazyFunctionForSwitchNode>(
node);
#define NODE_CLASS_CONVERTER
#define NODE_STORAGE_FUNCS(StorageT)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
static const CPPType & get()
void move_construct(void *src, void *dst) const
bool is_context_dependent_field() const
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Result & get_input(StringRef identifier) const
static bool is_single_value_only_type(ResultType type)
static FieldOperationPtr from(std::shared_ptr< const mf::MultiFunction > fn, Vector< GField > inputs)
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
const bNodeSocket & other_socket() const
eNodeSocketInOut in_out() const
void update_and_connect_available_socket(bNode &new_node, UString socket_name)
bNode & add_node(UString idname)
SocketValueVariant()=default
static SocketValueVariant from(T &&value)
void execute_impl(lf::Params ¶ms, const lf::Context &context) const override
const MultiFunction & get_switch_multi_function() const
LazyFunctionForSwitchNode(const bNode &node)
void execute_field(Field< bool > condition, lf::Params ¶ms) const
void execute_single(const bool condition, lf::Params ¶ms) const
static constexpr int false_input_index
static constexpr int true_input_index
NodeOperation(Context &context, const bNode &node)
#define storage(slot, qualifiers)
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))
bool node_tree_type_supports_socket_type_static(const int ntree_type, const eNodeSocketDatatype socket_type)
ResultType socket_data_type_to_result_type(const eNodeSocketDatatype data_type, const std::optional< int > dimensions=std::nullopt)
QuaternionBase< float > Quaternion
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void register_node()
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_init(bNodeTree *tree, bNode *node)
static void node_declare(NodeDeclarationBuilder &b)
static void node_rna(StructRNA *srna)
static const bNodeSocket * node_internally_linked_input(const bNodeTree &, const bNode &node, const bNodeSocket &)
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)
std::unique_ptr< LazyFunction > get_switch_node_lazy_function(const bNode &node)
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)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
BMesh const char void * data
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
void node_free_standard_storage(bNode *node)
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const CPPType * base_cpp_type
NodeInternallyLinkedInputFunction internally_linked_input
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
bool ignore_inferred_input_socket_visibility
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)