Blender V5.3
node_fn_input_vector.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 int dimensions = 3;
18 if (const bNode *node = b.node_or_null()) {
19 const auto &storage = *static_cast<NodeInputVector *>(node->storage);
20 dimensions = storage.dimensions;
21 }
22 b.add_output<decl::Vector>("Vector"_ustr)
23 .dimensions(dimensions)
24 .custom_draw([](CustomSocketDrawParams &params) {
26 ui::Layout &row = params.layout.row(true);
27 row.column(true).prop(
28 &params.node_ptr, "vector", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
29 if (gizmos::value_node_has_gizmo(params.tree, params.node)) {
30 row.prop(&params.socket_ptr, "pin_gizmo", UI_ITEM_NONE, "", ICON_GIZMO);
31 }
32 });
33}
34
36 bNode *node,
37 bNodeExecData * /*execdata*/,
38 GPUNodeStack * /*in*/,
40{
41 NodeInputVector *node_storage = static_cast<NodeInputVector *>(node->storage);
42 return GPU_link(mat, "set_rgb", GPU_uniform(node_storage->vector), &out->link);
43}
44
46#ifdef WITH_MATERIALX
47{
48 NodeItem vector = get_output_default("Vector", NodeItem::Type::Vector3);
49 return create_node("constant", NodeItem::Type::Vector3, {{"value", vector}});
50}
51#endif
53
55{
56 const bNode &bnode = builder.node();
57 NodeInputVector *node_storage = static_cast<NodeInputVector *>(bnode.storage);
58 switch (node_storage->dimensions) {
59 case 2: {
60 float2 vector(node_storage->vector);
61 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<float2>>(vector);
62 break;
63 }
64 case 3: {
65 float3 vector(node_storage->vector);
66 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<float3>>(vector);
67 break;
68 }
69 case 4: {
70 float4 vector(node_storage->vector);
71 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<float4>>(vector);
72 break;
73 }
74 }
75}
76
77static void node_init(bNodeTree * /*tree*/, bNode *node)
78{
79 NodeInputVector *data = MEM_new<NodeInputVector>(__func__);
80 node->storage = data;
81}
82
83static void node_layout_ex(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
84{
85 layout.use_property_split_set(true);
86 layout.use_property_decorate_set(false);
87 layout.prop(ptr, "vector_dimensions", UI_ITEM_NONE, std::nullopt, ICON_NONE);
88}
89
90static void node_register()
91{
92 static bke::bNodeType ntype;
93
94 common_node_type_base(&ntype, "FunctionNodeInputVector"_ustr, FN_NODE_INPUT_VECTOR);
95 ntype.ui_name = "Vector";
96 ntype.ui_description = "Provide a vector value that can be connected to other nodes in the tree";
97 ntype.enum_name_legacy = "INPUT_VECTOR";
99 ntype.declare = node_declare;
100 ntype.initfunc = node_init;
104 ntype, "NodeInputVector", node_free_standard_storage, node_copy_standard_storage);
106 ntype.materialx_fn = node_shader_materialx;
107
109}
111
112} // namespace blender::nodes::node_fn_input_vector_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define FN_NODE_INPUT_VECTOR
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define UI_ITEM_NONE
#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
bool value_node_has_gizmo(const bNodeTree &tree, const bNode &node)
static int gpu_shader_vector(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *, GPUNodeStack *out)
NODE_SHADER_MATERIALX_BEGIN static NODE_SHADER_MATERIALX_END 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)
GPUNodeLink * GPU_uniform(const float *num)
VecBase< float, 4 > float4
VecBase< float, 2 > float2
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
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(*) 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
const char * enum_name_legacy
Definition BKE_node.hh:274
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)