Blender V5.3
node_fn_rotate_euler.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
5#include "BLI_listbase.hh"
8
9#include "RNA_enum_types.hh"
10
12#include "UI_resources.hh"
13
14#include "node_function_util.hh"
15
17
19{
20 b.is_function_node();
21 b.add_input<decl::Vector>("Rotation"_ustr).subtype(PROP_EULER).hide_value();
22
23 const bNode *node = b.node_or_null();
24 if (node != nullptr) {
25 const auto type = FunctionNodeRotateEulerType(node->custom1);
26 switch (type) {
28 b.add_input<decl::Vector>("Rotate By"_ustr).subtype(PROP_EULER);
29 break;
31 b.add_input<decl::Vector>("Axis"_ustr).default_value({0.0, 0.0, 1.0}).subtype(PROP_XYZ);
32 b.add_input<decl::Float>("Angle"_ustr).subtype(PROP_ANGLE);
33 break;
34 }
35 default:
37 break;
38 }
39 }
40 b.add_output<decl::Vector>("Rotation"_ustr);
41}
42
43static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
44{
45 layout.prop(ptr, "rotation_type", ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
46 layout.prop(ptr, "space", ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
47}
48
49static const mf::MultiFunction *get_multi_function(const bNode &bnode)
50{
51 static auto obj_euler_rot = mf::build::SI2_SO<float3, float3, float3>(
52 "Rotate Euler by Euler/Object", [](const float3 &input, const float3 &rotation) {
53 float input_mat[3][3];
54 eul_to_mat3(input_mat, input);
55 float rot_mat[3][3];
56 eul_to_mat3(rot_mat, rotation);
57 float mat_res[3][3];
58 mul_m3_m3m3(mat_res, rot_mat, input_mat);
60 mat3_to_eul(result, mat_res);
61 return result;
62 });
63 static auto obj_AA_rot = mf::build::SI3_SO<float3, float3, float, float3>(
64 "Rotate Euler by AxisAngle/Object",
65 [](const float3 &input, const float3 &axis, float angle) {
66 float input_mat[3][3];
67 eul_to_mat3(input_mat, input);
68 float rot_mat[3][3];
69 axis_angle_to_mat3(rot_mat, axis, angle);
70 float mat_res[3][3];
71 mul_m3_m3m3(mat_res, rot_mat, input_mat);
73 mat3_to_eul(result, mat_res);
74 return result;
75 });
76 static auto local_euler_rot = mf::build::SI2_SO<float3, float3, float3>(
77 "Rotate Euler by Euler/Local", [](const float3 &input, const float3 &rotation) {
78 float input_mat[3][3];
79 eul_to_mat3(input_mat, input);
80 float rot_mat[3][3];
81 eul_to_mat3(rot_mat, rotation);
82 float mat_res[3][3];
83 mul_m3_m3m3(mat_res, input_mat, rot_mat);
85 mat3_to_eul(result, mat_res);
86 return result;
87 });
88 static auto local_AA_rot = mf::build::SI3_SO<float3, float3, float, float3>(
89 "Rotate Euler by AxisAngle/Local", [](const float3 &input, const float3 &axis, float angle) {
90 float input_mat[3][3];
91 eul_to_mat3(input_mat, input);
92 float rot_mat[3][3];
93 axis_angle_to_mat3(rot_mat, axis, angle);
94 float mat_res[3][3];
95 mul_m3_m3m3(mat_res, input_mat, rot_mat);
97 mat3_to_eul(result, mat_res);
98 return result;
99 });
100 short type = bnode.custom1;
101 short space = bnode.custom2;
103 return space == FN_NODE_ROTATE_EULER_SPACE_OBJECT ?
104 static_cast<const mf::MultiFunction *>(&obj_AA_rot) :
105 &local_AA_rot;
106 }
108 return space == FN_NODE_ROTATE_EULER_SPACE_OBJECT ?
109 static_cast<const mf::MultiFunction *>(&obj_euler_rot) :
110 &local_euler_rot;
111 }
113 return nullptr;
114}
115
117{
118 const mf::MultiFunction *fn = get_multi_function(builder.node());
119 builder.set_matching_fn(fn);
120}
121
122static void node_register()
123{
124 static bke::bNodeType ntype;
125
126 fn_node_type_base(&ntype, "FunctionNodeRotateEuler"_ustr, FN_NODE_ROTATE_EULER);
127 ntype.ui_name = "Rotate Euler";
128 ntype.ui_description = "Apply a secondary Euler rotation to a given Euler rotation";
129 ntype.enum_name_legacy = "ROTATE_EULER";
131 ntype.declare = node_declare;
134 ntype.deprecation_notice = N_("Use the \"Rotate Rotation\" node instead");
136}
138
139} // namespace blender::nodes::node_fn_rotate_euler_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define FN_NODE_ROTATE_EULER
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define BLI_assert_unreachable()
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static const mf::MultiFunction * get_multi_function(const bNode &bnode)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
void eul_to_mat3(float mat[3][3], const float eul[3])
@ FN_NODE_ROTATE_EULER_SPACE_OBJECT
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
void mat3_to_eul(float eul[3], const float mat[3][3])
void fn_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
VecBase< float, 3 > float3
FunctionNodeRotateEulerType
@ FN_NODE_ROTATE_EULER_TYPE_EULER
@ FN_NODE_ROTATE_EULER_TYPE_AXIS_ANGLE
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
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:382
const char * deprecation_notice
Definition BKE_node.hh:455
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)
#define N_(msgid)