Blender V5.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#include "node_shader_util.hh"
13
15
17{
18 b.is_function_node();
19 b.add_input<decl::Rotation>("Rotation"_ustr);
20 b.add_output<decl::Vector>("Axis"_ustr);
21 b.add_output<decl::Float>("Angle"_ustr).subtype(PROP_ANGLE);
22};
23
24class QuaterniontoAxisAngleFunction : public mf::MultiFunction {
25 public:
27 {
28 static mf::Signature signature_;
29 mf::SignatureBuilder builder{"Quaternion to Axis Angle", signature_};
30 builder.single_input<math::Quaternion>("Quaternion");
31 builder.single_output<float3>("Axis");
32 builder.single_output<float>("Angle");
33 this->set_signature(&signature_);
34 }
35
36 void call(const IndexMask &mask, mf::Params params, mf::Context /*context*/) const override
37 {
38 const VArraySpan<math::Quaternion> quaternions =
39 params.readonly_single_input<math::Quaternion>(0, "Quaternion");
40 MutableSpan<float3> axes = params.uninitialized_single_output<float3>(1, "Axis");
41 MutableSpan<float> angles = params.uninitialized_single_output<float>(2, "Angle");
42 mask.foreach_index([&](const int64_t i) {
43 const math::AxisAngle axis_angle = math::to_axis_angle(quaternions[i]);
44 axes[i] = axis_angle.axis();
45 angles[i] = axis_angle.angle().radian();
46 });
47 }
48};
49
51 bNode *node,
52 bNodeExecData * /*execdata*/,
55{
56 return GPU_stack_link(mat, node, "rotation_to_axis_angle", in, out);
57}
58
64
66{
67 using namespace value_elem;
68 const RotationElem rotation_elem = params.get_input_elem<RotationElem>("Rotation"_ustr);
69 params.set_output_elem("Axis"_ustr, rotation_elem.axis);
70 params.set_output_elem("Angle"_ustr, rotation_elem.angle);
71}
72
74{
75 using namespace value_elem;
76 RotationElem rotation_elem;
77 rotation_elem.axis = params.get_output_elem<VectorElem>("Axis"_ustr);
78 rotation_elem.angle = params.get_output_elem<FloatElem>("Angle"_ustr);
79 if (rotation_elem) {
80 rotation_elem.euler = VectorElem::all();
81 }
82 params.set_input_elem("Rotation"_ustr, rotation_elem);
83}
84
86{
87 const float3 axis = params.get_output<float3>("Axis"_ustr);
88 const float angle = params.get_output<float>("Angle"_ustr);
89 math::Quaternion rotation;
90 if (math::is_zero(axis)) {
91 rotation = math::Quaternion::identity();
92 }
93 else {
95 }
96 params.set_input("Rotation"_ustr, rotation);
97}
98
99static void node_register()
100{
101 static bke::bNodeType ntype;
103 &ntype, "FunctionNodeRotationToAxisAngle"_ustr, FN_NODE_ROTATION_TO_AXIS_ANGLE);
104 ntype.ui_name = "Rotation to Axis Angle";
105 ntype.ui_description = "Convert a rotation to axis angle components";
106 ntype.enum_name_legacy = "ROTATION_TO_AXIS_ANGLE";
108 ntype.declare = node_declare;
115}
117
118} // namespace blender::nodes::node_fn_rotation_to_axis_angle_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define FN_NODE_ROTATION_TO_AXIS_ANGLE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
void set_signature(const Signature *signature)
void set_matching_fn(const mf::MultiFunction *fn)
void set_input(const UString identifier, T value)
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
T get_input_elem(const UString identifier) const
void set_output_elem(const UString identifier, T elem)
void set_input_elem(const UString identifier, T elem)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
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 int node_gpu_material(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_eval_inverse(inverse_eval::InverseEvalParams &params)
static void node_eval_inverse_elem(value_elem::InverseElemEvalParams &params)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
__int64 int64_t
Definition BKE_text.h:90
void fn_cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
VecBase< float, 3 > float3
Defines a node type.
Definition BKE_node.hh:265
NodeInverseElemEvalFunction eval_inverse_elem
Definition BKE_node.hh:434
NodeInverseEvalFunction eval_inverse
Definition BKE_node.hh:441
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
NodeElemEvalFunction eval_elem
Definition BKE_node.hh:428
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:382
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393