Blender V5.3
node_fn_input_int_vector.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6#include "node_shader_util.hh"
7
9#include "UI_resources.hh"
10
12
14{
15 int dimensions = 3;
16 if (const bNode *node = b.node_or_null()) {
17 const auto &storage = *static_cast<NodeInputIntVector *>(node->storage);
18 dimensions = storage.dimensions;
19 }
20 b.add_output<decl::IntVector>("Vector"_ustr)
21 .dimensions(dimensions)
22 .custom_draw([](CustomSocketDrawParams &params) {
24 ui::Layout &row = params.layout.row(true);
25 row.column(true).prop(
26 &params.node_ptr, "vector", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
27 });
28}
29
30static int node_gpu(GPUMaterial *mat,
31 bNode *node,
32 bNodeExecData * /*execdata*/,
33 GPUNodeStack * /*in*/,
35{
36 NodeInputIntVector *node_storage = static_cast<NodeInputIntVector *>(node->storage);
37 /* Passed as float3 for now since GPU material graphs do not support integer vectors. */
38 const float3 vector = float3(int3(node_storage->vector));
39 return GPU_link(mat, "set_rgb", GPU_uniform(vector), &out->link);
40}
41
43{
44 const bNode &bnode = builder.node();
45 NodeInputIntVector *node_storage = static_cast<NodeInputIntVector *>(bnode.storage);
46 switch (node_storage->dimensions) {
47 case 2: {
48 int2 vector(node_storage->vector);
49 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<int2>>(vector);
50 break;
51 }
52 case 3: {
53 int3 vector(node_storage->vector);
54 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<int3>>(vector);
55 break;
56 }
57 default:
59 break;
60 }
61}
62
63static void node_init(bNodeTree * /*tree*/, bNode *node)
64{
65 NodeInputIntVector *data = MEM_new<NodeInputIntVector>(__func__);
66 node->storage = data;
67}
68
69static void node_layout_ex(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
70{
71 layout.use_property_split_set(true);
72 layout.use_property_decorate_set(false);
73 layout.prop(ptr, "vector_dimensions", UI_ITEM_NONE, std::nullopt, ICON_NONE);
74}
75
76static void node_register()
77{
78 static bke::bNodeType ntype;
79
80 fn_cmp_node_type_base(&ntype, "FunctionNodeInputIntVector"_ustr);
81 ntype.ui_name = "Integer Vector";
82 ntype.ui_description =
83 "Provide an integer vector value that can be connected to other nodes in the tree";
85 ntype.declare = node_declare;
86 ntype.initfunc = node_init;
87 ntype.gpu_fn = node_gpu;
90 ntype, "NodeInputIntVector", node_free_standard_storage, node_copy_standard_storage);
92
94}
96
97} // namespace blender::nodes::node_fn_input_int_vector_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define UI_ITEM_NONE
#define BLI_assert_unreachable()
#define storage(slot, qualifiers)
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
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_declare(NodeDeclarationBuilder &b)
static void node_init(bNodeTree *, bNode *node)
static void node_layout_ex(ui::Layout &layout, bContext *, PointerRNA *ptr)
static int node_gpu(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *, GPUNodeStack *out)
void fn_cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
GPUNodeLink * GPU_uniform(const float *num)
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
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
VecBase< float, 3 > float3
Defines a node type.
Definition BKE_node.hh:265
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(*) draw_buttons_ex(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:292
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
NodeDeclareFunction declare
Definition BKE_node.hh:393
void alignment_set(LayoutAlign alignment)
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
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 & column(bool align)
Layout & row(bool align)