Blender V5.0
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
13
14enum class RotationSpace {
15 Global = 0,
16 Local = 1,
17};
18
20{
21 b.use_custom_socket_order();
22 b.allow_any_socket_order();
23 b.add_default_layout();
24 b.is_function_node();
25 b.add_input<decl::Rotation>("Rotation");
26 b.add_output<decl::Rotation>("Rotation").align_with_previous();
27 b.add_input<decl::Rotation>("Rotate By");
28};
29
30static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
31{
32 layout->prop(ptr, "rotation_space", UI_ITEM_R_EXPAND, std::nullopt, ICON_NONE);
33}
34
36{
37 switch (RotationSpace(builder.node().custom1)) {
39 static auto fn = mf::build::SI2_SO<math::Quaternion, math::Quaternion, math::Quaternion>(
40 "Rotate Rotation Global", [](math::Quaternion a, math::Quaternion b) { return b * a; });
41 builder.set_matching_fn(fn);
42 break;
43 }
45 static auto fn = mf::build::SI2_SO<math::Quaternion, math::Quaternion, math::Quaternion>(
46 "Rotate Rotation Local", [](math::Quaternion a, math::Quaternion b) { return a * b; });
47 builder.set_matching_fn(fn);
48 break;
49 }
50 }
51}
52
53static void node_rna(StructRNA *srna)
54{
55 static const EnumPropertyItem space_items[] = {
57 "GLOBAL",
58 ICON_NONE,
59 "Global",
60 "Rotate the input rotation in global space"},
62 "LOCAL",
63 ICON_NONE,
64 "Local",
65 "Rotate the input rotation in its local space"},
66 {0, nullptr, 0, nullptr, nullptr},
67 };
68
70 "rotation_space",
71 "Space",
72 "Base orientation for the rotation",
75}
76
77static void node_register()
78{
79 static blender::bke::bNodeType ntype;
80 fn_node_type_base(&ntype, "FunctionNodeRotateRotation", FN_NODE_ROTATE_ROTATION);
81 ntype.ui_name = "Rotate Rotation";
82 ntype.ui_description = "Apply a secondary rotation to a given rotation value";
83 ntype.enum_name_legacy = "ROTATE_ROTATION";
85 ntype.declare = node_declare;
89
90 node_rna(ntype.rna_ext.srna);
91}
93
94} // namespace blender::nodes::node_fn_rotate_rotation_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define FN_NODE_ROTATE_ROTATION
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
@ UI_ITEM_R_EXPAND
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
QuaternionBase< float > Quaternion
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
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)
void fn_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
static const EnumPropertyItem space_items[]
StructRNA * srna
int16_t custom1
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:351
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238