Blender V5.3
node_fn_input_bool.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6#include "node_shader_util.hh"
7
9
11#include "UI_resources.hh"
12
14
16{
17 b.add_output<decl::Bool>("Boolean"_ustr).custom_draw([](CustomSocketDrawParams &params) {
19 ui::Layout &row = params.layout.row(true);
20 row.prop(
21 &params.node_ptr, "boolean", ui::ITEM_R_SPLIT_EMPTY_NAME, IFACE_("Boolean"), ICON_NONE);
22 if (gizmos::value_node_has_gizmo(params.tree, params.node)) {
23 row.prop(&params.socket_ptr, "pin_gizmo", UI_ITEM_NONE, "", ICON_GIZMO);
24 }
25 });
26}
27
29 bNode *node,
30 bNodeExecData * /*execdata*/,
31 GPUNodeStack * /*in*/,
33{
34 NodeInputBool *node_storage = static_cast<NodeInputBool *>(node->storage);
35 bool value = node_storage->boolean;
36 return GPU_link(mat, "set_bool", GPU_uniform(&value), &out->link);
37}
38
40{
41 const bNode &bnode = builder.node();
42 NodeInputBool *node_storage = static_cast<NodeInputBool *>(bnode.storage);
43 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<bool>>(node_storage->boolean);
44}
45
47#ifdef WITH_MATERIALX
48{
49 NodeItem boolean = get_output_default("Boolean", NodeItem::Type::Boolean);
50 return create_node("constant", NodeItem::Type::Boolean, {{"value", boolean}});
51}
52#endif
54
55static void node_init(bNodeTree * /*tree*/, bNode *node)
56{
57 NodeInputBool *data = MEM_new<NodeInputBool>(__func__);
58 node->storage = data;
59}
60
61static void node_register()
62{
63 static bke::bNodeType ntype;
64
65 common_node_type_base(&ntype, "FunctionNodeInputBool"_ustr, FN_NODE_INPUT_BOOL);
66 ntype.ui_name = "Boolean";
67 ntype.ui_description =
68 "Provide a True/False value that can be connected to other nodes in the tree";
69 ntype.enum_name_legacy = "INPUT_BOOL";
71 ntype.declare = node_declare;
72 ntype.initfunc = node_init;
73 ntype.gpu_fn = gpu_shader_bool;
77 ntype.materialx_fn = node_shader_materialx;
78
80}
82
83} // namespace blender::nodes::node_fn_input_bool_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define FN_NODE_INPUT_BOOL
#define IFACE_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define UI_ITEM_NONE
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
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))
Definition node.cc:6166
bool value_node_has_gizmo(const bNodeTree &tree, const bNode &node)
static int gpu_shader_bool(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
NODE_SHADER_MATERIALX_BEGIN static NODE_SHADER_MATERIALX_END void node_init(bNodeTree *, bNode *node)
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
GPUNodeLink * GPU_uniform(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
BMesh const char void * data
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
Defines a node type.
Definition BKE_node.hh:265
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:375
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:382
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
void alignment_set(LayoutAlign alignment)
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)
Layout & row(bool align)