Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/animation.h
9896 views
1
/**************************************************************************/
2
/* animation.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/io/resource.h"
34
#include "core/templates/local_vector.h"
35
36
#define ANIM_MIN_LENGTH 0.001
37
38
class Animation : public Resource {
39
GDCLASS(Animation, Resource);
40
RES_BASE_EXTENSION("anim");
41
42
public:
43
typedef uint32_t TypeHash;
44
45
static inline String PARAMETERS_BASE_PATH = "parameters/";
46
static constexpr real_t DEFAULT_STEP = 1.0 / 30;
47
48
enum TrackType : uint8_t {
49
TYPE_VALUE, // Set a value in a property, can be interpolated.
50
TYPE_POSITION_3D, // Position 3D track, can be compressed.
51
TYPE_ROTATION_3D, // Rotation 3D track, can be compressed.
52
TYPE_SCALE_3D, // Scale 3D track, can be compressed.
53
TYPE_BLEND_SHAPE, // Blend Shape track, can be compressed.
54
TYPE_METHOD, // Call any method on a specific node.
55
TYPE_BEZIER, // Bezier curve.
56
TYPE_AUDIO,
57
TYPE_ANIMATION,
58
};
59
60
enum InterpolationType : uint8_t {
61
INTERPOLATION_NEAREST,
62
INTERPOLATION_LINEAR,
63
INTERPOLATION_CUBIC,
64
INTERPOLATION_LINEAR_ANGLE,
65
INTERPOLATION_CUBIC_ANGLE,
66
};
67
68
enum UpdateMode : uint8_t {
69
UPDATE_CONTINUOUS,
70
UPDATE_DISCRETE,
71
UPDATE_CAPTURE,
72
};
73
74
enum LoopMode : uint8_t {
75
LOOP_NONE,
76
LOOP_LINEAR,
77
LOOP_PINGPONG,
78
};
79
80
// LoopedFlag is used in Animataion to "process the keys at both ends correct".
81
enum LoopedFlag : uint8_t {
82
LOOPED_FLAG_NONE,
83
LOOPED_FLAG_END,
84
LOOPED_FLAG_START,
85
};
86
87
enum FindMode : uint8_t {
88
FIND_MODE_NEAREST,
89
FIND_MODE_APPROX,
90
FIND_MODE_EXACT,
91
};
92
93
#ifdef TOOLS_ENABLED
94
enum HandleMode {
95
HANDLE_MODE_FREE,
96
HANDLE_MODE_LINEAR,
97
HANDLE_MODE_BALANCED,
98
HANDLE_MODE_MIRRORED,
99
};
100
enum HandleSetMode {
101
HANDLE_SET_MODE_NONE,
102
HANDLE_SET_MODE_RESET,
103
HANDLE_SET_MODE_AUTO,
104
};
105
#endif // TOOLS_ENABLED
106
107
struct Track {
108
TrackType type = TrackType::TYPE_ANIMATION;
109
InterpolationType interpolation = INTERPOLATION_LINEAR;
110
bool loop_wrap = true;
111
NodePath path; // Path to something.
112
TypeHash thash = 0; // Hash by Path + SubPath + TrackType.
113
bool imported = false;
114
bool enabled = true;
115
virtual ~Track() {}
116
};
117
118
private:
119
struct Key {
120
real_t transition = 1.0;
121
double time = 0.0; // Time in secs.
122
};
123
124
// Transform key holds either Vector3 or Quaternion.
125
template <typename T>
126
struct TKey : public Key {
127
T value;
128
};
129
130
const int32_t POSITION_TRACK_SIZE = 5;
131
const int32_t ROTATION_TRACK_SIZE = 6;
132
const int32_t SCALE_TRACK_SIZE = 5;
133
const int32_t BLEND_SHAPE_TRACK_SIZE = 3;
134
135
/* POSITION TRACK */
136
137
struct PositionTrack : public Track {
138
Vector<TKey<Vector3>> positions;
139
int32_t compressed_track = -1;
140
PositionTrack() { type = TYPE_POSITION_3D; }
141
};
142
143
/* ROTATION TRACK */
144
145
struct RotationTrack : public Track {
146
Vector<TKey<Quaternion>> rotations;
147
int32_t compressed_track = -1;
148
RotationTrack() { type = TYPE_ROTATION_3D; }
149
};
150
151
/* SCALE TRACK */
152
153
struct ScaleTrack : public Track {
154
Vector<TKey<Vector3>> scales;
155
int32_t compressed_track = -1;
156
ScaleTrack() { type = TYPE_SCALE_3D; }
157
};
158
159
/* BLEND SHAPE TRACK */
160
161
struct BlendShapeTrack : public Track {
162
Vector<TKey<float>> blend_shapes;
163
int32_t compressed_track = -1;
164
BlendShapeTrack() { type = TYPE_BLEND_SHAPE; }
165
};
166
167
/* PROPERTY VALUE TRACK */
168
169
struct ValueTrack : public Track {
170
UpdateMode update_mode = UPDATE_CONTINUOUS;
171
bool update_on_seek = false;
172
Vector<TKey<Variant>> values;
173
174
ValueTrack() {
175
type = TYPE_VALUE;
176
}
177
};
178
179
/* METHOD TRACK */
180
181
struct MethodKey : public Key {
182
StringName method;
183
Vector<Variant> params;
184
};
185
186
struct MethodTrack : public Track {
187
Vector<MethodKey> methods;
188
MethodTrack() { type = TYPE_METHOD; }
189
};
190
191
/* BEZIER TRACK */
192
193
struct BezierKey {
194
Vector2 in_handle; // Relative (x always <0)
195
Vector2 out_handle; // Relative (x always >0)
196
real_t value = 0.0;
197
#ifdef TOOLS_ENABLED
198
HandleMode handle_mode = HANDLE_MODE_FREE;
199
#endif // TOOLS_ENABLED
200
};
201
202
struct BezierTrack : public Track {
203
Vector<TKey<BezierKey>> values;
204
205
BezierTrack() {
206
type = TYPE_BEZIER;
207
}
208
};
209
210
/* AUDIO TRACK */
211
212
struct AudioKey {
213
Ref<Resource> stream;
214
real_t start_offset = 0.0; // Offset from start.
215
real_t end_offset = 0.0; // Offset from end, if 0 then full length or infinite.
216
AudioKey() {
217
}
218
};
219
220
struct AudioTrack : public Track {
221
Vector<TKey<AudioKey>> values;
222
bool use_blend = true;
223
224
AudioTrack() {
225
type = TYPE_AUDIO;
226
}
227
};
228
229
/* ANIMATION TRACK */
230
231
struct AnimationTrack : public Track {
232
Vector<TKey<StringName>> values;
233
234
AnimationTrack() {
235
type = TYPE_ANIMATION;
236
}
237
};
238
239
/* Marker */
240
241
struct MarkerKey {
242
double time;
243
StringName name;
244
MarkerKey(double p_time, const StringName &p_name) :
245
time(p_time), name(p_name) {}
246
MarkerKey() = default;
247
};
248
249
Vector<MarkerKey> marker_names; // time -> name
250
HashMap<StringName, double> marker_times; // name -> time
251
HashMap<StringName, Color> marker_colors; // name -> color
252
253
Vector<Track *> tracks;
254
255
template <typename T, typename V>
256
int _insert(double p_time, T &p_keys, const V &p_value);
257
258
int _marker_insert(double p_time, Vector<MarkerKey> &p_keys, const MarkerKey &p_value);
259
260
template <typename K>
261
262
inline int _find(const Vector<K> &p_keys, double p_time, bool p_backward = false, bool p_limit = false) const;
263
264
_FORCE_INLINE_ Vector3 _interpolate(const Vector3 &p_a, const Vector3 &p_b, real_t p_c) const;
265
_FORCE_INLINE_ Quaternion _interpolate(const Quaternion &p_a, const Quaternion &p_b, real_t p_c) const;
266
_FORCE_INLINE_ Variant _interpolate(const Variant &p_a, const Variant &p_b, real_t p_c) const;
267
_FORCE_INLINE_ real_t _interpolate(const real_t &p_a, const real_t &p_b, real_t p_c) const;
268
_FORCE_INLINE_ Variant _interpolate_angle(const Variant &p_a, const Variant &p_b, real_t p_c) const;
269
270
_FORCE_INLINE_ Vector3 _cubic_interpolate_in_time(const Vector3 &p_pre_a, const Vector3 &p_a, const Vector3 &p_b, const Vector3 &p_post_b, real_t p_c, real_t p_pre_a_t, real_t p_b_t, real_t p_post_b_t) const;
271
_FORCE_INLINE_ Quaternion _cubic_interpolate_in_time(const Quaternion &p_pre_a, const Quaternion &p_a, const Quaternion &p_b, const Quaternion &p_post_b, real_t p_c, real_t p_pre_a_t, real_t p_b_t, real_t p_post_b_t) const;
272
_FORCE_INLINE_ Variant _cubic_interpolate_in_time(const Variant &p_pre_a, const Variant &p_a, const Variant &p_b, const Variant &p_post_b, real_t p_c, real_t p_pre_a_t, real_t p_b_t, real_t p_post_b_t) const;
273
_FORCE_INLINE_ real_t _cubic_interpolate_in_time(const real_t &p_pre_a, const real_t &p_a, const real_t &p_b, const real_t &p_post_b, real_t p_c, real_t p_pre_a_t, real_t p_b_t, real_t p_post_b_t) const;
274
_FORCE_INLINE_ Variant _cubic_interpolate_angle_in_time(const Variant &p_pre_a, const Variant &p_a, const Variant &p_b, const Variant &p_post_b, real_t p_c, real_t p_pre_a_t, real_t p_b_t, real_t p_post_b_t) const;
275
276
template <typename T>
277
_FORCE_INLINE_ T _interpolate(const Vector<TKey<T>> &p_keys, double p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok, bool p_backward = false) const;
278
279
template <typename T>
280
_FORCE_INLINE_ void _track_get_key_indices_in_range(const Vector<T> &p_array, double from_time, double to_time, List<int> *p_indices, bool p_is_backward) const;
281
282
double length = 1.0;
283
real_t step = DEFAULT_STEP;
284
LoopMode loop_mode = LOOP_NONE;
285
bool capture_included = false;
286
void _check_capture_included();
287
288
void _track_update_hash(int p_track);
289
290
/* Animation compression page format (version 1):
291
*
292
* Animation uses bitwidth based compression separated into small pages. The intention is that pages fit easily in the cache, so decoding is cache efficient.
293
* The page-based nature also makes future animation streaming from disk possible.
294
*
295
* Actual format:
296
*
297
* num_compressed_tracks = bounds.size()
298
* header : (x num_compressed_tracks)
299
* -------
300
* timeline_keys_offset : uint32_t - offset to time keys
301
* timeline_size : uint32_t - amount of time keys
302
* data_keys_offset : uint32_t offset to key data
303
*
304
* time key (uint32_t):
305
* ------------------
306
* frame : bits 0-15 - time offset of key, computed as: page.time_offset + frame * (1.0/fps)
307
* data_key_offset : bits 16-27 - offset to key data, computed as: data_keys_offset * 4 + data_key_offset
308
* data_key_count : bits 28-31 - amount of data keys pointed to, computed as: data_key_count+1 (max 16)
309
*
310
* data key:
311
* ---------
312
* X / Blend Shape : uint16_t - X coordinate of XYZ vector key, or Blend Shape value. If Blend shape, Y and Z are not present and can be ignored.
313
* Y : uint16_t
314
* Z : uint16_t
315
* If data_key_count+1 > 1 (if more than 1 key is stored):
316
* data_bitwidth : uint16_t - This is only present if data_key_count > 1. Contains delta bitwidth information.
317
* X / Blend Shape delta bitwidth: bits 0-3 -
318
* if 0, nothing is present for X (use the first key-value for subsequent keys),
319
* else assume the number of bits present for each element (+ 1 for sign). Assumed always 16 bits, delta max signed 15 bits, with underflow and overflow supported.
320
* Y delta bitwidth : bits 4-7
321
* Z delta bitwidth : bits 8-11
322
* FRAME delta bitwidth : 12-15 bits - always present (obviously), actual bitwidth is FRAME+1
323
* Data key is 4 bytes long for Blend Shapes, 8 bytes long for pos/rot/scale.
324
*
325
* delta keys:
326
* -----------
327
* Compressed format is packed in the following format after the data key, containing delta keys one after the next in a tightly bit packed fashion.
328
* FRAME bits -> X / Blend Shape Bits (if bitwidth > 0) -> Y Bits (if not Blend Shape and Y Bitwidth > 0) -> Z Bits (if not Blend Shape and Z Bitwidth > 0)
329
*
330
* data key format:
331
* ----------------
332
* Decoding keys means starting from the base key and going key by key applying deltas until the proper position is reached needed for interpolation.
333
* Resulting values are uint32_t
334
* data for X / Blend Shape, Y and Z must be normalized first: unorm = float(data) / 65535.0
335
* **Blend Shape**: (unorm * 2.0 - 1.0) * Compression::BLEND_SHAPE_RANGE
336
* **Pos/Scale**: unorm_vec3 * bounds[track].size + bounds[track].position
337
* **Rotation**: Quaternion(Vector3::octahedron_decode(unorm_vec3.xy),unorm_vec3.z * Math::PI * 2.0)
338
* **Frame**: page.time_offset + frame * (1.0/fps)
339
*/
340
341
struct Compression {
342
enum {
343
MAX_DATA_TRACK_SIZE = 16384,
344
BLEND_SHAPE_RANGE = 8, // -8.0 to 8.0.
345
FORMAT_VERSION = 1
346
};
347
struct Page {
348
Vector<uint8_t> data;
349
double time_offset;
350
};
351
352
uint32_t fps = 120;
353
LocalVector<Page> pages;
354
LocalVector<AABB> bounds; // Used by position and scale tracks (which contain index to track and index to bounds).
355
bool enabled = false;
356
} compression;
357
358
Vector3i _compress_key(uint32_t p_track, const AABB &p_bounds, int32_t p_key = -1, float p_time = 0.0);
359
bool _rotation_interpolate_compressed(uint32_t p_compressed_track, double p_time, Quaternion &r_ret) const;
360
bool _pos_scale_interpolate_compressed(uint32_t p_compressed_track, double p_time, Vector3 &r_ret) const;
361
bool _blend_shape_interpolate_compressed(uint32_t p_compressed_track, double p_time, float &r_ret) const;
362
template <uint32_t COMPONENTS>
363
bool _fetch_compressed(uint32_t p_compressed_track, double p_time, Vector3i &r_current_value, double &r_current_time, Vector3i &r_next_value, double &r_next_time, uint32_t *key_index = nullptr) const;
364
template <uint32_t COMPONENTS>
365
bool _fetch_compressed_by_index(uint32_t p_compressed_track, int p_index, Vector3i &r_value, double &r_time) const;
366
int _get_compressed_key_count(uint32_t p_compressed_track) const;
367
template <uint32_t COMPONENTS>
368
void _get_compressed_key_indices_in_range(uint32_t p_compressed_track, double p_time, double p_delta, List<int> *r_indices) const;
369
_FORCE_INLINE_ Quaternion _uncompress_quaternion(const Vector3i &p_value) const;
370
_FORCE_INLINE_ Vector3 _uncompress_pos_scale(uint32_t p_compressed_track, const Vector3i &p_value) const;
371
_FORCE_INLINE_ float _uncompress_blend_shape(const Vector3i &p_value) const;
372
373
// bind helpers
374
private:
375
bool _float_track_optimize_key(const TKey<float> t0, const TKey<float> t1, const TKey<float> t2, real_t p_allowed_velocity_err, real_t p_allowed_precision_error, bool p_is_nearest);
376
bool _vector2_track_optimize_key(const TKey<Vector2> t0, const TKey<Vector2> t1, const TKey<Vector2> t2, real_t p_allowed_velocity_err, real_t p_allowed_angular_error, real_t p_allowed_precision_error, bool p_is_nearest);
377
bool _vector3_track_optimize_key(const TKey<Vector3> t0, const TKey<Vector3> t1, const TKey<Vector3> t2, real_t p_allowed_velocity_err, real_t p_allowed_angular_error, real_t p_allowed_precision_error, bool p_is_nearest);
378
bool _quaternion_track_optimize_key(const TKey<Quaternion> t0, const TKey<Quaternion> t1, const TKey<Quaternion> t2, real_t p_allowed_velocity_err, real_t p_allowed_angular_error, real_t p_allowed_precision_error, bool p_is_nearest);
379
380
void _position_track_optimize(int p_idx, real_t p_allowed_velocity_err, real_t p_allowed_angular_err, real_t p_allowed_precision_error);
381
void _rotation_track_optimize(int p_idx, real_t p_allowed_velocity_err, real_t p_allowed_angular_error, real_t p_allowed_precision_error);
382
void _scale_track_optimize(int p_idx, real_t p_allowed_velocity_err, real_t p_allowed_angular_err, real_t p_allowed_precision_error);
383
void _blend_shape_track_optimize(int p_idx, real_t p_allowed_velocity_err, real_t p_allowed_precision_error);
384
void _value_track_optimize(int p_idx, real_t p_allowed_velocity_err, real_t p_allowed_angular_err, real_t p_allowed_precision_error);
385
386
protected:
387
bool _set(const StringName &p_name, const Variant &p_value);
388
bool _get(const StringName &p_name, Variant &r_ret) const;
389
void _get_property_list(List<PropertyInfo> *p_list) const;
390
391
virtual void reset_state() override;
392
393
static void _bind_methods();
394
395
static bool inform_variant_array(int &r_min, int &r_max); // Returns true if max and min are swapped.
396
397
#ifndef DISABLE_DEPRECATED
398
Vector3 _position_track_interpolate_bind_compat_86629(int p_track, double p_time) const;
399
Quaternion _rotation_track_interpolate_bind_compat_86629(int p_track, double p_time) const;
400
Vector3 _scale_track_interpolate_bind_compat_86629(int p_track, double p_time) const;
401
float _blend_shape_track_interpolate_bind_compat_86629(int p_track, double p_time) const;
402
Variant _value_track_interpolate_bind_compat_86629(int p_track, double p_time) const;
403
int _track_find_key_bind_compat_92861(int p_track, double p_time, FindMode p_find_mode = FIND_MODE_NEAREST) const;
404
static void _bind_compatibility_methods();
405
#endif // DISABLE_DEPRECATED
406
407
public:
408
int add_track(TrackType p_type, int p_at_pos = -1);
409
void remove_track(int p_track);
410
411
_FORCE_INLINE_ const Vector<Track *> get_tracks() {
412
return tracks;
413
}
414
415
bool is_capture_included() const;
416
417
int get_track_count() const;
418
TrackType track_get_type(int p_track) const;
419
420
void track_set_path(int p_track, const NodePath &p_path);
421
NodePath track_get_path(int p_track) const;
422
int find_track(const NodePath &p_path, const TrackType p_type) const;
423
424
TypeHash track_get_type_hash(int p_track) const;
425
426
void track_move_up(int p_track);
427
void track_move_down(int p_track);
428
void track_move_to(int p_track, int p_to_index);
429
void track_swap(int p_track, int p_with_track);
430
431
void track_set_imported(int p_track, bool p_imported);
432
bool track_is_imported(int p_track) const;
433
434
void track_set_enabled(int p_track, bool p_enabled);
435
bool track_is_enabled(int p_track) const;
436
437
int track_insert_key(int p_track, double p_time, const Variant &p_key, real_t p_transition = 1);
438
void track_set_key_transition(int p_track, int p_key_idx, real_t p_transition);
439
void track_set_key_value(int p_track, int p_key_idx, const Variant &p_value);
440
void track_set_key_time(int p_track, int p_key_idx, double p_time);
441
int track_find_key(int p_track, double p_time, FindMode p_find_mode = FIND_MODE_NEAREST, bool p_limit = false, bool p_backward = false) const;
442
void track_remove_key(int p_track, int p_idx);
443
void track_remove_key_at_time(int p_track, double p_time);
444
int track_get_key_count(int p_track) const;
445
Variant track_get_key_value(int p_track, int p_key_idx) const;
446
double track_get_key_time(int p_track, int p_key_idx) const;
447
real_t track_get_key_transition(int p_track, int p_key_idx) const;
448
bool track_is_compressed(int p_track) const;
449
450
int position_track_insert_key(int p_track, double p_time, const Vector3 &p_position);
451
Error position_track_get_key(int p_track, int p_key, Vector3 *r_position) const;
452
Error try_position_track_interpolate(int p_track, double p_time, Vector3 *r_interpolation, bool p_backward = false) const;
453
Vector3 position_track_interpolate(int p_track, double p_time, bool p_backward = false) const;
454
455
int rotation_track_insert_key(int p_track, double p_time, const Quaternion &p_rotation);
456
Error rotation_track_get_key(int p_track, int p_key, Quaternion *r_rotation) const;
457
Error try_rotation_track_interpolate(int p_track, double p_time, Quaternion *r_interpolation, bool p_backward = false) const;
458
Quaternion rotation_track_interpolate(int p_track, double p_time, bool p_backward = false) const;
459
460
int scale_track_insert_key(int p_track, double p_time, const Vector3 &p_scale);
461
Error scale_track_get_key(int p_track, int p_key, Vector3 *r_scale) const;
462
Error try_scale_track_interpolate(int p_track, double p_time, Vector3 *r_interpolation, bool p_backward = false) const;
463
Vector3 scale_track_interpolate(int p_track, double p_time, bool p_backward = false) const;
464
465
int blend_shape_track_insert_key(int p_track, double p_time, float p_blend);
466
Error blend_shape_track_get_key(int p_track, int p_key, float *r_blend) const;
467
Error try_blend_shape_track_interpolate(int p_track, double p_time, float *r_blend, bool p_backward = false) const;
468
float blend_shape_track_interpolate(int p_track, double p_time, bool p_backward = false) const;
469
470
void track_set_interpolation_type(int p_track, InterpolationType p_interp);
471
InterpolationType track_get_interpolation_type(int p_track) const;
472
473
Array make_default_bezier_key(float p_value);
474
int bezier_track_insert_key(int p_track, double p_time, real_t p_value, const Vector2 &p_in_handle, const Vector2 &p_out_handle);
475
void bezier_track_set_key_value(int p_track, int p_index, real_t p_value);
476
void bezier_track_set_key_in_handle(int p_track, int p_index, const Vector2 &p_handle, real_t p_balanced_value_time_ratio = 1.0);
477
void bezier_track_set_key_out_handle(int p_track, int p_index, const Vector2 &p_handle, real_t p_balanced_value_time_ratio = 1.0);
478
real_t bezier_track_get_key_value(int p_track, int p_index) const;
479
Vector2 bezier_track_get_key_in_handle(int p_track, int p_index) const;
480
Vector2 bezier_track_get_key_out_handle(int p_track, int p_index) const;
481
#ifdef TOOLS_ENABLED
482
void bezier_track_set_key_handle_mode(int p_track, int p_index, HandleMode p_mode, HandleSetMode p_set_mode = HANDLE_SET_MODE_NONE);
483
HandleMode bezier_track_get_key_handle_mode(int p_track, int p_index) const;
484
bool bezier_track_calculate_handles(int p_track, int p_index, HandleMode p_mode, HandleSetMode p_set_mode, Vector2 *r_in_handle, Vector2 *r_out_handle);
485
bool bezier_track_calculate_handles(float p_time, float p_prev_time, float p_prev_value, float p_next_time, float p_next_value, HandleMode p_mode, HandleSetMode p_set_mode, Vector2 *r_in_handle, Vector2 *r_out_handle);
486
#endif // TOOLS_ENABLED
487
488
real_t bezier_track_interpolate(int p_track, double p_time) const;
489
490
int audio_track_insert_key(int p_track, double p_time, const Ref<Resource> &p_stream, real_t p_start_offset = 0, real_t p_end_offset = 0);
491
void audio_track_set_key_stream(int p_track, int p_key, const Ref<Resource> &p_stream);
492
void audio_track_set_key_start_offset(int p_track, int p_key, real_t p_offset);
493
void audio_track_set_key_end_offset(int p_track, int p_key, real_t p_offset);
494
Ref<Resource> audio_track_get_key_stream(int p_track, int p_key) const;
495
real_t audio_track_get_key_start_offset(int p_track, int p_key) const;
496
real_t audio_track_get_key_end_offset(int p_track, int p_key) const;
497
void audio_track_set_use_blend(int p_track, bool p_enable);
498
bool audio_track_is_use_blend(int p_track) const;
499
500
int animation_track_insert_key(int p_track, double p_time, const StringName &p_animation);
501
void animation_track_set_key_animation(int p_track, int p_key, const StringName &p_animation);
502
StringName animation_track_get_key_animation(int p_track, int p_key) const;
503
504
void track_set_interpolation_loop_wrap(int p_track, bool p_enable);
505
bool track_get_interpolation_loop_wrap(int p_track) const;
506
507
Variant value_track_interpolate(int p_track, double p_time, bool p_backward = false) const;
508
void value_track_set_update_mode(int p_track, UpdateMode p_mode);
509
UpdateMode value_track_get_update_mode(int p_track) const;
510
511
Vector<Variant> method_track_get_params(int p_track, int p_key_idx) const;
512
StringName method_track_get_name(int p_track, int p_key_idx) const;
513
514
void copy_track(int p_track, Ref<Animation> p_to_animation);
515
516
void track_get_key_indices_in_range(int p_track, double p_time, double p_delta, List<int> *p_indices, Animation::LoopedFlag p_looped_flag = Animation::LOOPED_FLAG_NONE) const;
517
518
void add_marker(const StringName &p_name, double p_time);
519
void remove_marker(const StringName &p_name);
520
bool has_marker(const StringName &p_name) const;
521
StringName get_marker_at_time(double p_time) const;
522
StringName get_next_marker(double p_time) const;
523
StringName get_prev_marker(double p_time) const;
524
double get_marker_time(const StringName &p_time) const;
525
PackedStringArray get_marker_names() const;
526
Color get_marker_color(const StringName &p_name) const;
527
void set_marker_color(const StringName &p_name, const Color &p_color);
528
529
void set_length(real_t p_length);
530
real_t get_length() const;
531
532
void set_loop_mode(LoopMode p_loop_mode);
533
LoopMode get_loop_mode() const;
534
535
void set_step(real_t p_step);
536
real_t get_step() const;
537
538
void clear();
539
540
void optimize(real_t p_allowed_velocity_err = 0.01, real_t p_allowed_angular_err = 0.01, int p_precision = 3);
541
void compress(uint32_t p_page_size = 8192, uint32_t p_fps = 120, float p_split_tolerance = 4.0); // 4.0 seems to be the split tolerance sweet spot from many tests.
542
543
// Helper functions for Variant.
544
static bool is_variant_interpolatable(const Variant p_value);
545
static bool validate_type_match(const Variant &p_from, Variant &r_to);
546
547
static Variant cast_to_blendwise(const Variant p_value);
548
static Variant cast_from_blendwise(const Variant p_value, const Variant::Type p_type);
549
550
static Variant string_to_array(const Variant p_value);
551
static Variant array_to_string(const Variant p_value);
552
553
static Variant add_variant(const Variant &a, const Variant &b);
554
static Variant subtract_variant(const Variant &a, const Variant &b);
555
static Variant blend_variant(const Variant &a, const Variant &b, float c);
556
static Variant interpolate_variant(const Variant &a, const Variant &b, float c, bool p_snap_array_element = false);
557
static Variant cubic_interpolate_in_time_variant(const Variant &pre_a, const Variant &a, const Variant &b, const Variant &post_b, float c, real_t p_pre_a_t, real_t p_b_t, real_t p_post_b_t, bool p_snap_array_element = false);
558
559
static bool is_less_or_equal_approx(double a, double b) {
560
return a < b || Math::is_equal_approx(a, b);
561
}
562
563
static bool is_less_approx(double a, double b) {
564
return a < b && !Math::is_equal_approx(a, b);
565
}
566
567
static bool is_greater_or_equal_approx(double a, double b) {
568
return a > b || Math::is_equal_approx(a, b);
569
}
570
571
static bool is_greater_approx(double a, double b) {
572
return a > b && !Math::is_equal_approx(a, b);
573
}
574
575
static TrackType get_cache_type(TrackType p_type);
576
577
Animation();
578
~Animation();
579
};
580
581
VARIANT_ENUM_CAST(Animation::TrackType);
582
VARIANT_ENUM_CAST(Animation::InterpolationType);
583
VARIANT_ENUM_CAST(Animation::UpdateMode);
584
VARIANT_ENUM_CAST(Animation::LoopMode);
585
VARIANT_ENUM_CAST(Animation::LoopedFlag);
586
VARIANT_ENUM_CAST(Animation::FindMode);
587
#ifdef TOOLS_ENABLED
588
VARIANT_ENUM_CAST(Animation::HandleMode);
589
VARIANT_ENUM_CAST(Animation::HandleSetMode);
590
#endif // TOOLS_ENABLED
591
592