Blender V4.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.h"
6#include "BLI_math_matrix.h"
7#include "BLI_math_rotation.h"
8#include "BLI_math_vector.h"
9#include "BLI_string.h"
10
11#include "RNA_enum_types.hh"
12
13#include "UI_interface.hh"
14#include "UI_resources.hh"
15
16#include "node_function_util.hh"
17
19
21{
22 auto enable_axis_angle = [](bNode &node) {
24 };
25
26 b.is_function_node();
27 b.add_input<decl::Vector>("Rotation").subtype(PROP_EULER).hide_value();
28 b.add_input<decl::Vector>("Rotate By").subtype(PROP_EULER).make_available([](bNode &node) {
30 });
31 b.add_input<decl::Vector>("Axis")
32 .default_value({0.0, 0.0, 1.0})
33 .subtype(PROP_XYZ)
34 .make_available(enable_axis_angle);
35 b.add_input<decl::Float>("Angle").subtype(PROP_ANGLE).make_available(enable_axis_angle);
36 b.add_output<decl::Vector>("Rotation");
37}
38
39static void node_update(bNodeTree *ntree, bNode *node)
40{
41 bNodeSocket *rotate_by_socket = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 1));
42 bNodeSocket *axis_socket = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 2));
43 bNodeSocket *angle_socket = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 3));
44
46 ntree, rotate_by_socket, ELEM(node->custom1, FN_NODE_ROTATE_EULER_TYPE_EULER));
48 ntree, axis_socket, ELEM(node->custom1, FN_NODE_ROTATE_EULER_TYPE_AXIS_ANGLE));
50 ntree, angle_socket, ELEM(node->custom1, FN_NODE_ROTATE_EULER_TYPE_AXIS_ANGLE));
51}
52
53static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
54{
55 uiItemR(layout, ptr, "rotation_type", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
56 uiItemR(layout, ptr, "space", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
57}
58
59static const mf::MultiFunction *get_multi_function(const bNode &bnode)
60{
61 static auto obj_euler_rot = mf::build::SI2_SO<float3, float3, float3>(
62 "Rotate Euler by Euler/Object", [](const float3 &input, const float3 &rotation) {
63 float input_mat[3][3];
64 eul_to_mat3(input_mat, input);
65 float rot_mat[3][3];
66 eul_to_mat3(rot_mat, rotation);
67 float mat_res[3][3];
68 mul_m3_m3m3(mat_res, rot_mat, input_mat);
70 mat3_to_eul(result, mat_res);
71 return result;
72 });
73 static auto obj_AA_rot = mf::build::SI3_SO<float3, float3, float, float3>(
74 "Rotate Euler by AxisAngle/Object",
75 [](const float3 &input, const float3 &axis, float angle) {
76 float input_mat[3][3];
77 eul_to_mat3(input_mat, input);
78 float rot_mat[3][3];
79 axis_angle_to_mat3(rot_mat, axis, angle);
80 float mat_res[3][3];
81 mul_m3_m3m3(mat_res, rot_mat, input_mat);
83 mat3_to_eul(result, mat_res);
84 return result;
85 });
86 static auto local_euler_rot = mf::build::SI2_SO<float3, float3, float3>(
87 "Rotate Euler by Euler/Local", [](const float3 &input, const float3 &rotation) {
88 float input_mat[3][3];
89 eul_to_mat3(input_mat, input);
90 float rot_mat[3][3];
91 eul_to_mat3(rot_mat, rotation);
92 float mat_res[3][3];
93 mul_m3_m3m3(mat_res, input_mat, rot_mat);
95 mat3_to_eul(result, mat_res);
96 return result;
97 });
98 static auto local_AA_rot = mf::build::SI3_SO<float3, float3, float, float3>(
99 "Rotate Euler by AxisAngle/Local", [](const float3 &input, const float3 &axis, float angle) {
100 float input_mat[3][3];
101 eul_to_mat3(input_mat, input);
102 float rot_mat[3][3];
103 axis_angle_to_mat3(rot_mat, axis, angle);
104 float mat_res[3][3];
105 mul_m3_m3m3(mat_res, input_mat, rot_mat);
107 mat3_to_eul(result, mat_res);
108 return result;
109 });
110 short type = bnode.custom1;
111 short space = bnode.custom2;
113 return space == FN_NODE_ROTATE_EULER_SPACE_OBJECT ?
114 static_cast<const mf::MultiFunction *>(&obj_AA_rot) :
115 &local_AA_rot;
116 }
118 return space == FN_NODE_ROTATE_EULER_SPACE_OBJECT ?
119 static_cast<const mf::MultiFunction *>(&obj_euler_rot) :
120 &local_euler_rot;
121 }
123 return nullptr;
124}
125
127{
128 const mf::MultiFunction *fn = get_multi_function(builder.node());
129 builder.set_matching_fn(fn);
130}
131
132static void node_register()
133{
134 static blender::bke::bNodeType ntype;
135
136 fn_node_type_base(&ntype, FN_NODE_ROTATE_EULER, "Rotate Euler", NODE_CLASS_CONVERTER);
137 ntype.declare = node_declare;
139 ntype.updatefunc = node_update;
141 ntype.deprecation_notice = N_("Use the \"Rotate Rotation\" node instead");
143}
145
146} // namespace blender::nodes::node_fn_rotate_euler_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void eul_to_mat3(float mat[3][3], const float eul[3])
void mat3_to_eul(float eul[3], const float mat[3][3])
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
#define ELEM(...)
@ FN_NODE_ROTATE_EULER_TYPE_EULER
@ FN_NODE_ROTATE_EULER_TYPE_AXIS_ANGLE
@ FN_NODE_ROTATE_EULER_SPACE_OBJECT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_XYZ
Definition RNA_types.hh:172
@ PROP_ANGLE
Definition RNA_types.hh:155
@ PROP_EULER
Definition RNA_types.hh:169
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_EXPAND
void set_matching_fn(const mf::MultiFunction *fn)
void make_available(bNode &node) const
local_group_size(16, 16) .push_constant(Type b
OperationNode * node
void node_set_socket_availability(bNodeTree *ntree, bNodeSocket *sock, bool is_available)
Definition node.cc:3911
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static const mf::MultiFunction * get_multi_function(const bNode &bnode)
static void node_update(bNodeTree *ntree, bNode *node)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
void fn_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
int16_t custom1
int16_t custom2
Defines a node type.
Definition BKE_node.hh:218
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:336
const char * deprecation_notice
Definition BKE_node.hh:397
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:257
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4126