Blender V5.3
node_fn_rotate_rotation.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 "UI_resources.hh"
7
8#include "NOD_rna_define.hh"
9
10#include "node_function_util.hh"
11#include "node_shader_util.hh"
12
14
15enum class RotationSpace {
16 Global = 0,
17 Local = 1,
18};
19
21{
22 b.use_custom_socket_order();
23 b.allow_any_socket_order();
24 b.add_default_layout();
25 b.is_function_node();
26 b.add_input<decl::Rotation>("Rotation"_ustr);
27 b.add_output<decl::Rotation>("Rotation"_ustr).align_with_previous();
28 b.add_input<decl::Rotation>("Rotate By"_ustr);
29};
30
31static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
32{
33 layout.prop(ptr, "rotation_space", ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
34}
35
37 bNode *node,
38 bNodeExecData * /*execdata*/,
41{
42 const char *name = nullptr;
43 switch (RotationSpace(node->custom1)) {
45 name = "rotate_rotation_global";
46 break;
48 name = "rotate_rotation_local";
49 break;
50 }
51
52 if (name != nullptr) {
53 return GPU_stack_link(mat, node, name, in, out);
54 }
55 return 0;
56}
57
59{
60 switch (RotationSpace(builder.node().custom1)) {
62 static auto fn = mf::build::SI2_SO<math::Quaternion, math::Quaternion, math::Quaternion>(
63 "Rotate Rotation Global", [](math::Quaternion a, math::Quaternion b) { return b * a; });
64 builder.set_matching_fn(fn);
65 break;
66 }
68 static auto fn = mf::build::SI2_SO<math::Quaternion, math::Quaternion, math::Quaternion>(
69 "Rotate Rotation Local", [](math::Quaternion a, math::Quaternion b) { return a * b; });
70 builder.set_matching_fn(fn);
71 break;
72 }
73 }
74}
75
76static void node_rna(StructRNA *srna)
77{
78 static const EnumPropertyItem space_items[] = {
80 "GLOBAL",
81 ICON_NONE,
82 "Global",
83 "Rotate the input rotation in global space"},
85 "LOCAL",
86 ICON_NONE,
87 "Local",
88 "Rotate the input rotation in its local space"},
89 {0, nullptr, 0, nullptr, nullptr},
90 };
91
93 "rotation_space",
94 "Space",
95 "Base orientation for the rotation",
96 space_items,
98}
99
100static void node_register()
101{
102 static bke::bNodeType ntype;
103 fn_cmp_node_type_base(&ntype, "FunctionNodeRotateRotation"_ustr, FN_NODE_ROTATE_ROTATION);
104 ntype.ui_name = "Rotate Rotation";
105 ntype.ui_description = "Apply a secondary rotation to a given rotation value";
106 ntype.enum_name_legacy = "ROTATE_ROTATION";
108 ntype.declare = node_declare;
113
114 node_rna(ntype.rna_ext.srna);
115}
117
118} // namespace blender::nodes::node_fn_rotate_rotation_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define FN_NODE_ROTATE_ROTATION
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
QuaternionBase< float > Quaternion
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static int node_gpu_material(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
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 GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void fn_cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
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
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
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)