Blender V4.3
node_fn_rotation_to_axis_angle.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
7
10
11#include "node_function_util.hh"
12
14
16{
17 b.is_function_node();
18 b.add_input<decl::Rotation>("Rotation");
19 b.add_output<decl::Vector>("Axis");
20 b.add_output<decl::Float>("Angle").subtype(PROP_ANGLE);
21};
22
24 public:
26 {
27 static mf::Signature signature_;
28 mf::SignatureBuilder builder{"Quaternion to Axis Angle", signature_};
29 builder.single_input<math::Quaternion>("Quaternion");
30 builder.single_output<float3>("Axis");
31 builder.single_output<float>("Angle");
32 this->set_signature(&signature_);
33 }
34
35 void call(const IndexMask &mask, mf::Params params, mf::Context /*context*/) const override
36 {
37 const VArraySpan<math::Quaternion> quaternions =
38 params.readonly_single_input<math::Quaternion>(0, "Quaternion");
39 MutableSpan<float3> axes = params.uninitialized_single_output<float3>(1, "Axis");
40 MutableSpan<float> angles = params.uninitialized_single_output<float>(2, "Angle");
41 mask.foreach_index([&](const int64_t i) {
42 const math::AxisAngle axis_angle = math::to_axis_angle(quaternions[i]);
43 axes[i] = axis_angle.axis();
44 angles[i] = axis_angle.angle().radian();
45 });
46 }
47};
48
50{
52 builder.set_matching_fn(fn);
53}
54
56{
57 using namespace value_elem;
58 const RotationElem rotation_elem = params.get_input_elem<RotationElem>("Rotation");
59 params.set_output_elem("Axis", rotation_elem.axis);
60 params.set_output_elem("Angle", rotation_elem.angle);
61}
62
64{
65 using namespace value_elem;
66 RotationElem rotation_elem;
67 rotation_elem.axis = params.get_output_elem<VectorElem>("Axis");
68 rotation_elem.angle = params.get_output_elem<FloatElem>("Angle");
69 if (rotation_elem) {
70 rotation_elem.euler = VectorElem::all();
71 }
72 params.set_input_elem("Rotation", rotation_elem);
73}
74
76{
77 const float3 axis = params.get_output<float3>("Axis");
78 const float angle = params.get_output<float>("Angle");
79 math::Quaternion rotation;
80 if (math::is_zero(axis)) {
81 rotation = math::Quaternion::identity();
82 }
83 else {
84 rotation = math::to_quaternion(math::AxisAngle(math::normalize(axis), angle));
85 }
86 params.set_input("Rotation", rotation);
87}
88
89static void node_register()
90{
91 static blender::bke::bNodeType ntype;
93 &ntype, FN_NODE_ROTATION_TO_AXIS_ANGLE, "Rotation to Axis Angle", NODE_CLASS_CONVERTER);
94 ntype.declare = node_declare;
100}
102
103} // namespace blender::nodes::node_fn_rotation_to_axis_angle_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_ANGLE
Definition RNA_types.hh:155
void set_signature(const Signature *signature)
void set_matching_fn(const mf::MultiFunction *fn)
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
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)
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_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_eval_inverse(inverse_eval::InverseEvalParams &params)
static void node_eval_inverse_elem(value_elem::InverseElemEvalParams &params)
void fn_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
__int64 int64_t
Definition stdint.h:89
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