Blender V5.0
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
23class QuaterniontoAxisAngleFunction : public mf::MultiFunction {
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
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 {
85 }
86 params.set_input("Rotation", rotation);
87}
88
89static void node_register()
90{
91 static blender::bke::bNodeType ntype;
92 fn_node_type_base(&ntype, "FunctionNodeRotationToAxisAngle", FN_NODE_ROTATION_TO_AXIS_ANGLE);
93 ntype.ui_name = "Rotation to Axis Angle";
94 ntype.ui_description = "Convert a rotation to axis angle components";
95 ntype.enum_name_legacy = "ROTATION_TO_AXIS_ANGLE";
97 ntype.declare = node_declare;
103}
105
106} // namespace blender::nodes::node_fn_rotation_to_axis_angle_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define FN_NODE_ROTATION_TO_AXIS_ANGLE
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_ANGLE
Definition RNA_types.hh:252
long long int int64_t
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
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
QuaternionBase< float > Quaternion
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_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_eval_inverse(inverse_eval::InverseEvalParams &params)
static void node_eval_inverse_elem(value_elem::InverseElemEvalParams &params)
VecBase< float, 3 > float3
void fn_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
NodeInverseElemEvalFunction eval_inverse_elem
Definition BKE_node.hh:403
NodeInverseEvalFunction eval_inverse
Definition BKE_node.hh:410
std::string ui_description
Definition BKE_node.hh:244
NodeElemEvalFunction eval_elem
Definition BKE_node.hh:397
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:351
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362
i
Definition text_draw.cc:230