Blender V4.3
node_fn_axis_angle_to_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
9
10#include "node_function_util.hh"
11
13
15{
16 b.is_function_node();
17 b.add_input<decl::Vector>("Axis").default_value({0.0f, 0.0f, 1.0f});
18 b.add_input<decl::Float>("Angle").subtype(PROP_ANGLE);
19 b.add_output<decl::Rotation>("Rotation");
20};
21
23{
24 static auto fn = mf::build::SI2_SO<float3, float, math::Quaternion>(
25 "Axis Angle to Quaternion", [](float3 axis, float angle) {
26 if (UNLIKELY(math::is_zero(axis))) {
28 }
29 const float3 axis_normalized = math::normalize(axis);
30 const math::AxisAngle axis_angle = math::AxisAngle(axis_normalized, angle);
31 return math::to_quaternion(axis_angle);
32 });
33 builder.set_matching_fn(fn);
34}
35
37{
38 using namespace value_elem;
39 RotationElem rotation_elem;
40 rotation_elem.axis = params.get_input_elem<VectorElem>("Axis");
41 rotation_elem.angle = params.get_input_elem<FloatElem>("Angle");
42 if (rotation_elem) {
43 rotation_elem.euler = VectorElem::all();
44 }
45 params.set_output_elem("Rotation", rotation_elem);
46}
47
49{
50 using namespace value_elem;
51 const RotationElem rotation_elem = params.get_output_elem<RotationElem>("Rotation");
52 VectorElem axis_elem = rotation_elem.axis;
53 FloatElem angle_elem = rotation_elem.angle;
54 params.set_input_elem("Axis", axis_elem);
55 params.set_input_elem("Angle", angle_elem);
56}
57
59{
60 using namespace inverse_eval;
61 const math::Quaternion rotation = params.get_output<math::Quaternion>("Rotation");
62 const math::AxisAngle axis_angle = math::to_axis_angle(rotation);
63 params.set_input("Axis", axis_angle.axis());
64 params.set_input("Angle", axis_angle.angle().radian());
65}
66
67static void node_register()
68{
69 static blender::bke::bNodeType ntype;
71 &ntype, FN_NODE_AXIS_ANGLE_TO_ROTATION, "Axis Angle to Rotation", NODE_CLASS_CONVERTER);
72 ntype.declare = node_declare;
78}
80
81} // namespace blender::nodes::node_fn_axis_angle_to_rotation_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
#define UNLIKELY(x)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_ANGLE
Definition RNA_types.hh:155
void set_matching_fn(const mf::MultiFunction *fn)
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
QuaternionBase< T > to_quaternion(const AxisAngleBase< T, AngleT > &axis_angle)
AxisAngleBase< float, AngleRadianBase< float > > AxisAngle
bool is_zero(const T &a)
AxisAngleBase< T, AngleT > to_axis_angle(const EulerXYZBase< T > &euler)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
static void node_eval_elem(value_elem::ElemEvalParams &params)
static void node_eval_inverse_elem(value_elem::InverseElemEvalParams &params)
static void node_eval_inverse(inverse_eval::InverseEvalParams &params)
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
void fn_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
Defines a node type.
Definition BKE_node.hh:218
NodeInverseElemEvalFunction eval_inverse_elem
Definition BKE_node.hh:378
NodeInverseEvalFunction eval_inverse
Definition BKE_node.hh:385
NodeElemEvalFunction eval_elem
Definition BKE_node.hh:372
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:336
NodeDeclareFunction declare
Definition BKE_node.hh:347