Blender V5.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#include "node_shader_util.hh"
12
14
16{
17 b.is_function_node();
18 b.add_input<decl::Vector>("Axis"_ustr).default_value({0.0f, 0.0f, 1.0f});
19 b.add_input<decl::Float>("Angle"_ustr).subtype(PROP_ANGLE);
20 b.add_output<decl::Rotation>("Rotation"_ustr);
21};
22
24{
25 static auto fn = mf::build::SI2_SO<float3, float, math::Quaternion>(
26 "Axis Angle to Quaternion", [](float3 axis, float angle) {
27 if (math::is_zero(axis)) [[unlikely]] {
29 }
30 const float3 axis_normalized = math::normalize(axis);
31 const math::AxisAngle axis_angle = math::AxisAngle(axis_normalized, angle);
32 return math::to_quaternion(axis_angle);
33 });
34 builder.set_matching_fn(fn);
35}
36
38 bNode *node,
39 bNodeExecData * /*execdata*/,
42{
43 return GPU_stack_link(mat, node, "axis_angle_to_rotation", in, out);
44}
45
47{
48 using namespace value_elem;
49 RotationElem rotation_elem;
50 rotation_elem.axis = params.get_input_elem<VectorElem>("Axis"_ustr);
51 rotation_elem.angle = params.get_input_elem<FloatElem>("Angle"_ustr);
52 if (rotation_elem) {
53 rotation_elem.euler = VectorElem::all();
54 }
55 params.set_output_elem("Rotation"_ustr, rotation_elem);
56}
57
59{
60 using namespace value_elem;
61 const RotationElem rotation_elem = params.get_output_elem<RotationElem>("Rotation"_ustr);
62 VectorElem axis_elem = rotation_elem.axis;
63 FloatElem angle_elem = rotation_elem.angle;
64 params.set_input_elem("Axis"_ustr, axis_elem);
65 params.set_input_elem("Angle"_ustr, angle_elem);
66}
67
69{
70 using namespace inverse_eval;
71 const math::Quaternion rotation = params.get_output<math::Quaternion>("Rotation"_ustr);
72 const math::AxisAngle axis_angle = math::to_axis_angle(rotation);
73 params.set_input("Axis"_ustr, axis_angle.axis());
74 params.set_input("Angle"_ustr, axis_angle.angle().radian());
75}
76
77static void node_register()
78{
79 static bke::bNodeType ntype;
81 &ntype, "FunctionNodeAxisAngleToRotation"_ustr, FN_NODE_AXIS_ANGLE_TO_ROTATION);
82 ntype.ui_name = "Axis Angle to Rotation";
83 ntype.ui_description = "Build a rotation from an axis and a rotation around that axis";
84 ntype.enum_name_legacy = "AXIS_ANGLE_TO_ROTATION";
86 ntype.declare = node_declare;
93}
95
96} // namespace blender::nodes::node_fn_axis_angle_to_rotation_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define FN_NODE_AXIS_ANGLE_TO_ROTATION
#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_matching_fn(const mf::MultiFunction *fn)
void set_input(const UString identifier, T value)
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_eval_inverse_elem(value_elem::InverseElemEvalParams &params)
static void node_eval_inverse(inverse_eval::InverseEvalParams &params)
static int node_gpu_material(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
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