27 b.add_input<
decl::Vector>(
"Vector"_ustr).default_value({0.0, 0.0, 1.0});
43 const float3 local_main_axis,
47 const float3 vector = vectors[i];
49 output_rotations[i] = input_rotations[i];
53 float old_rotation[3][3];
56 mul_v3_m3v3(old_axis, old_rotation, local_main_axis);
70 const float angle = factors[i] * full_angle;
75 float new_rotation_matrix[3][3];
76 mul_m3_m3m3(new_rotation_matrix, rotation, old_rotation);
81 output_rotations[i] = new_rotation;
89 const float3 local_main_axis,
90 const float3 local_pivot_axis,
94 if (local_main_axis == local_pivot_axis) {
96 output_rotations[i] = input_rotations[i];
100 const float3 vector = vectors[i];
102 output_rotations[i] = input_rotations[i];
106 float old_rotation[3][3];
109 mul_v3_m3v3(old_axis, old_rotation, local_main_axis);
111 mul_v3_m3v3(pivot_axis, old_rotation, local_pivot_axis);
114 if (full_angle >
M_PI) {
116 full_angle -= 2.0f *
M_PI;
118 const float angle = factors[i] * full_angle;
120 float rotation[3][3];
123 float new_rotation_matrix[3][3];
124 mul_m3_m3m3(new_rotation_matrix, rotation, old_rotation);
129 output_rotations[i] = new_rotation;
136 int pivot_axis_mode_;
140 : main_axis_mode_(main_axis_mode), pivot_axis_mode_(pivot_axis_mode)
142 static const mf::Signature
signature = []() {
144 mf::SignatureBuilder builder{
"Align Euler to Vector",
signature};
145 builder.single_input<
float3>(
"Rotation");
146 builder.single_input<
float>(
"Factor");
147 builder.single_input<
float3>(
"Vector");
148 builder.single_output<
float3>(
"Rotation");
157 const VArray<float> &factors = params.readonly_single_input<
float>(1,
"Factor");
160 auto output_rotations = params.uninitialized_single_output<
float3>(3,
"Rotation");
162 float3 local_main_axis = {0.0f, 0.0f, 0.0f};
163 local_main_axis[main_axis_mode_] = 1;
167 mask, input_rotations, vectors, factors, local_main_axis, output_rotations);
170 float3 local_pivot_axis = {0.0f, 0.0f, 0.0f};
171 local_pivot_axis[pivot_axis_mode_ - 1] = 1;
203 "Align the X axis with the vector"},
208 "Align the Y axis with the vector"},
213 "Align the Z axis with the vector"},
214 {0,
nullptr, 0,
nullptr,
nullptr},
222 "Automatically detect the best rotation axis to rotate towards the vector"},
227 "Rotate around the local X axis"},
232 "Rotate around the local Y axis"},
237 "Rotate around the local Z axis"},
238 {0,
nullptr, 0,
nullptr,
nullptr},
244 "Axis to align to the vector",
254 "Axis to rotate around",
267 ntype.
ui_name =
"Align Euler to Vector";
268 ntype.
ui_description =
"Orient an Euler rotation along the given direction";
#define NODE_CLASS_CONVERTER
#define FN_NODE_ALIGN_EULER_TO_VECTOR
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
const Signature & signature() const
void set_signature(const Signature *signature)
void construct_and_set_matching_fn(Args &&...args)
ExecutionHints get_execution_hints() const override
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
MF_AlignEulerToVector(int main_axis_mode, int pivot_axis_mode)
void node_register_type(bNodeType &ntype)
VecBase< float, 3 > cross_high_precision(const VecBase< float, 3 > &a, const VecBase< float, 3 > &b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_register()
static void align_rotations_fixed_pivot(const IndexMask &mask, const VArray< float3 > &input_rotations, const VArray< float3 > &vectors, const VArray< float > &factors, const float3 local_main_axis, const float3 local_pivot_axis, MutableSpan< float3 > output_rotations)
static void align_rotations_auto_pivot(const IndexMask &mask, const VArray< float3 > &input_rotations, const VArray< float3 > &vectors, const VArray< float > &factors, const float3 local_main_axis, MutableSpan< float3 > output_rotations)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_rna(StructRNA *srna)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
void eul_to_mat3(float mat[3][3], const float eul[3])
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
float angle_signed_on_axis_v3v3_v3(const float v1[3], const float v2[3], const float axis[3]) ATTR_WARN_UNUSED_RESULT
void mat3_to_eul(float eul[3], const float mat[3][3])
@ FN_NODE_ALIGN_EULER_TO_VECTOR_AXIS_X
@ FN_NODE_ALIGN_EULER_TO_VECTOR_AXIS_Y
@ FN_NODE_ALIGN_EULER_TO_VECTOR_AXIS_Z
void fn_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
VecBase< float, 3 > float3
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
@ FN_NODE_ALIGN_EULER_TO_VECTOR_PIVOT_AXIS_Y
@ FN_NODE_ALIGN_EULER_TO_VECTOR_PIVOT_AXIS_Z
@ FN_NODE_ALIGN_EULER_TO_VECTOR_PIVOT_AXIS_X
@ FN_NODE_ALIGN_EULER_TO_VECTOR_PIVOT_AXIS_AUTO
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
std::string ui_description
NodeMultiFunctionBuildFunction build_multi_function
const char * deprecation_notice
const char * enum_name_legacy
NodeDeclareFunction declare
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)