Blender  V3.3
node_fn_rotate_euler.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "BLI_listbase.h"
4 #include "BLI_math_vector.h"
5 #include "BLI_string.h"
6 
7 #include "RNA_enum_types.h"
8 
9 #include "UI_interface.h"
10 #include "UI_resources.h"
11 
12 #include "node_function_util.hh"
13 
15 
17 {
18  auto enable_axis_angle = [](bNode &node) {
20  };
21 
22  b.is_function_node();
23  b.add_input<decl::Vector>(N_("Rotation")).subtype(PROP_EULER).hide_value();
24  b.add_input<decl::Vector>(N_("Rotate By")).subtype(PROP_EULER).make_available([](bNode &node) {
26  });
27  b.add_input<decl::Vector>(N_("Axis"))
28  .default_value({0.0, 0.0, 1.0})
29  .subtype(PROP_XYZ)
30  .make_available(enable_axis_angle);
31  b.add_input<decl::Float>(N_("Angle")).subtype(PROP_ANGLE).make_available(enable_axis_angle);
32  b.add_output<decl::Vector>(N_("Rotation"));
33 }
34 
36 {
37  bNodeSocket *rotate_by_socket = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 1));
38  bNodeSocket *axis_socket = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 2));
39  bNodeSocket *angle_socket = static_cast<bNodeSocket *>(BLI_findlink(&node->inputs, 3));
40 
42  ntree, rotate_by_socket, ELEM(node->custom1, FN_NODE_ROTATE_EULER_TYPE_EULER));
44  ntree, axis_socket, ELEM(node->custom1, FN_NODE_ROTATE_EULER_TYPE_AXIS_ANGLE));
46  ntree, angle_socket, ELEM(node->custom1, FN_NODE_ROTATE_EULER_TYPE_AXIS_ANGLE));
47 }
48 
50 {
51  uiItemR(layout, ptr, "type", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
52  uiItemR(layout, ptr, "space", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
53 }
54 
56 {
58  "Rotate Euler by Euler/Object", [](const float3 &input, const float3 &rotation) {
59  float input_mat[3][3];
60  eul_to_mat3(input_mat, input);
61  float rot_mat[3][3];
62  eul_to_mat3(rot_mat, rotation);
63  float mat_res[3][3];
64  mul_m3_m3m3(mat_res, rot_mat, input_mat);
65  float3 result;
66  mat3_to_eul(result, mat_res);
67  return result;
68  }};
70  "Rotate Euler by AxisAngle/Object",
71  [](const float3 &input, const float3 &axis, float angle) {
72  float input_mat[3][3];
73  eul_to_mat3(input_mat, input);
74  float rot_mat[3][3];
75  axis_angle_to_mat3(rot_mat, axis, angle);
76  float mat_res[3][3];
77  mul_m3_m3m3(mat_res, rot_mat, input_mat);
78  float3 result;
79  mat3_to_eul(result, mat_res);
80  return result;
81  }};
82  static fn::CustomMF_SI_SI_SO<float3, float3, float3> local_euler_rot{
83  "Rotate Euler by Euler/Local", [](const float3 &input, const float3 &rotation) {
84  float input_mat[3][3];
85  eul_to_mat3(input_mat, input);
86  float rot_mat[3][3];
87  eul_to_mat3(rot_mat, rotation);
88  float mat_res[3][3];
89  mul_m3_m3m3(mat_res, input_mat, rot_mat);
90  float3 result;
91  mat3_to_eul(result, mat_res);
92  return result;
93  }};
95  "Rotate Euler by AxisAngle/Local", [](const float3 &input, const float3 &axis, float angle) {
96  float input_mat[3][3];
97  eul_to_mat3(input_mat, input);
98  float rot_mat[3][3];
99  axis_angle_to_mat3(rot_mat, axis, angle);
100  float mat_res[3][3];
101  mul_m3_m3m3(mat_res, input_mat, rot_mat);
102  float3 result;
103  mat3_to_eul(result, mat_res);
104  return result;
105  }};
106  short type = bnode.custom1;
107  short space = bnode.custom2;
109  return space == FN_NODE_ROTATE_EULER_SPACE_OBJECT ? &obj_AA_rot : &local_AA_rot;
110  }
112  return space == FN_NODE_ROTATE_EULER_SPACE_OBJECT ? &obj_euler_rot : &local_euler_rot;
113  }
115  return nullptr;
116 }
117 
119 {
120  const fn::MultiFunction *fn = get_multi_function(builder.node());
121  builder.set_matching_fn(fn);
122 }
123 
124 } // namespace blender::nodes::node_fn_rotate_euler_cc
125 
127 {
128  namespace file_ns = blender::nodes::node_fn_rotate_euler_cc;
129 
130  static bNodeType ntype;
131 
137  nodeRegisterType(&ntype);
138 }
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4443
#define NODE_CLASS_CONVERTER
Definition: BKE_node.h:351
void nodeSetSocketAvailability(struct bNodeTree *ntree, struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3664
#define FN_NODE_ROTATE_EULER
Definition: BKE_node.h:1530
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
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])
Definition: math_matrix.c:388
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 UNUSED(x)
#define ELEM(...)
@ FN_NODE_ROTATE_EULER_TYPE_EULER
@ FN_NODE_ROTATE_EULER_TYPE_AXIS_ANGLE
@ FN_NODE_ROTATE_EULER_SPACE_OBJECT
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
@ PROP_XYZ
Definition: RNA_types.h:162
@ PROP_ANGLE
Definition: RNA_types.h:145
@ PROP_EULER
Definition: RNA_types.h:159
@ UI_ITEM_R_EXPAND
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
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 MultiFunction *fn)
OperationNode * node
bNodeTree * ntree
ccl_global KernelShaderEvalInput * input
static void fn_node_rotate_euler_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static const fn::MultiFunction * get_multi_function(bNode &bnode)
static void fn_node_rotate_euler_declare(NodeDeclarationBuilder &b)
static void fn_node_rotate_euler_update(bNodeTree *ntree, bNode *node)
static void fn_node_rotate_euler_build_multi_function(NodeMultiFunctionBuilder &builder)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_fn_rotate_euler()
void fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
Defines a node type.
Definition: BKE_node.h:226
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeMultiFunctionBuildFunction build_multi_function
Definition: BKE_node.h:313
NodeDeclareFunction declare
Definition: BKE_node.h:324
short custom1
short custom2
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480