Blender V5.3
ED_anim_transformable.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#pragma once
13
14#include "BLI_array.hh"
16#include "BLI_span.hh"
17#include "BLI_string_ref.hh"
18
19#include "DNA_action_types.h"
20
21#include "RNA_types.hh"
22
23namespace blender {
24
25struct bPoseChannel;
26struct bContext;
27struct ID;
28struct Depsgraph;
29
30namespace ed {
31
43 AXIS_MUTABLE_ALL = (1 << 8) - 1,
48};
50
51/* By using Array<float, 4> we enforce a stack allocation limit of 4. Since we use at most 4
52 * elements per property, we ensure that the values are always on the stack
53 * for better performance. */
56
60struct Rotation {
61 /* The array size differs depending on the rotation mode. */
64
71 Rotation converted_to_mode(eRotationModes mode, const Rotation *reference_euler = nullptr) const;
75 void mirror();
76};
77
84 public:
85 enum class Type : int8_t {
86 POSE_BONE,
87 OBJECT,
88 };
89
90 enum class PropertyType : int8_t { LOCATION, ROTATION, SCALE };
91
92 private:
93 Type type_;
94 ID *owner_id_;
95 /* The struct wrapped by the AnimTransformable. For possible types see `Type`. */
96 void *data_;
97
98 /* This is the path from the owner ID to the struct that the AnimTransformable represents. Has to
99 * be created in the constructor. For structs that are an ID this is an empty string. */
100 std::string rna_path_from_id_;
101 std::string fcurve_group_name_;
102 StringRefNull name_;
103
104 /* We are assuming here that the ground truth of transforms is store in separate loc rot scale
105 * and not in a matrix, thus skew is not supported. */
106 MutableSpan<float> location_;
107 /* Rotation can be expressed in different modes, which are stored in separate arrays. We have to
108 * use an Array of float* because the angle of axis-angle is a separate float property. This is
109 * in contrast to e.g. `location_` which is always a float array so it can be referenced with a
110 * `MutableSpan`. For the order of elements, see `RotationModeIndices` in `transformable.cc`. */
111 Array<TransformFloatPtrs> rotations_;
112 /* Points to an enum with the current rotation mode. See `eRotationModes`. */
113 eRotationModes *rotation_mode_;
114 MutableSpan<float> scale_;
115
120 const TransformFloatPtrs *get_rotation_array_from_mode(eRotationModes mode) const;
121
122 public:
123 /* There has to be a constructor for every struct supported. */
124 /* Constructor for pose bones. */
126 /* Constructor for Objects. */
127 explicit AnimTransformable(Object &object);
128
129 Type type() const
130 {
131 return type_;
132 }
133
134 ID *owner_id() const
135 {
136 return owner_id_;
137 }
138
140 {
141 return fcurve_group_name_;
142 }
143
145 {
146 return name_;
147 }
148
149 template<typename T> T data() const;
150
151 /* Returns the rna path from the ID to the struct represented by this transformable. If the
152 * struct is an ID this is an empty string. */
153 StringRefNull rna_path() const;
157 std::string rna_path_to_property(PropertyType prop_type) const;
163 std::string rna_path_to_property(const StringRef property_name) const;
164 std::string rna_path_to_rotation(eRotationModes rotation_mode) const;
165 std::string rna_path_to_rotation_mode() const;
166
170 Rotation get_rotation() const;
182 void set_rotation(const Rotation &rotation);
191
198 void blend_rotation_to(const Rotation &target, float factor, AxisMutable axis_flag);
199
211 void set_property(PropertyType prop_type, Span<float> values, AxisMutable axis_flag);
220 void blend_property_to(PropertyType prop_type,
221 Span<float> target,
222 float factor,
223 AxisMutable axis_flag);
227 void blend_property_to(PropertyType prop_type,
228 float target,
229 float factor,
230 AxisMutable axis_flag);
231
235 float4x4 get_world_space(const Depsgraph &depsgraph) const;
236
240 float4x4 world_to_local(const Depsgraph &depsgraph, const float4x4 &world_matrix) const;
241};
242
254Rotation rotation_interpolated(const Rotation &a, const Rotation &b, float factor);
255
261
266
267} // namespace ed
268} // namespace blender
#define C
Definition RandGen.cpp:29
Rotation get_rotation_for_mode(eRotationModes mode) const
float4x4 get_world_space(const Depsgraph &depsgraph) const
void blend_property_to(PropertyType prop_type, Span< float > target, float factor, AxisMutable axis_flag)
void set_rotation(const Rotation &rotation)
std::string rna_path_to_property(PropertyType prop_type) const
void blend_rotation_to(const Rotation &target, float factor, AxisMutable axis_flag)
StringRefNull rna_path() const
void set_rotation_mode(eRotationModes mode)
std::string rna_path_to_rotation(eRotationModes rotation_mode) const
eRotationModes get_rotation_mode() const
TransformFloats get_property(PropertyType prop_type) const
std::string rna_path_to_rotation_mode() const
AnimTransformable(Object &owner_id, bPoseChannel &pchan)
float4x4 world_to_local(const Depsgraph &depsgraph, const float4x4 &world_matrix) const
void set_property(PropertyType prop_type, Span< float > values, AxisMutable axis_flag)
#define T
ENUM_OPERATORS(AxisMutable)
Rotation identity_rotation(const eRotationModes mode)
Array< float *, 4 > TransformFloatPtrs
Rotation rotation_interpolated(const Rotation &a, const Rotation &b, const float factor)
Array< float > property_interpolated(const Span< float > a, const Span< float > b, const float factor)
Array< float, 4 > TransformFloats
Vector< ed::AnimTransformable > selected_transformables_from_context(bContext &C)
BMesh Iterators.
MatBase< float, 4, 4 > float4x4
unsigned char uint8_t
Definition BKE_text.h:79
signed char int8_t
Definition BKE_text.h:76
Rotation converted_to_mode(eRotationModes mode, const Rotation *reference_euler=nullptr) const