summaryrefslogtreecommitdiff
path: root/scene/resources/animation.h
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/animation.h')
-rw-r--r--scene/resources/animation.h107
1 files changed, 43 insertions, 64 deletions
diff --git a/scene/resources/animation.h b/scene/resources/animation.h
index 6ac0ea04d9..1484007333 100644
--- a/scene/resources/animation.h
+++ b/scene/resources/animation.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,17 +31,18 @@
#ifndef ANIMATION_H
#define ANIMATION_H
-#include "core/resource.h"
+#include "core/io/resource.h"
-class Animation : public Resource {
+#define ANIM_MIN_LENGTH 0.001
+class Animation : public Resource {
GDCLASS(Animation, Resource);
RES_BASE_EXTENSION("anim");
public:
enum TrackType {
TYPE_VALUE, ///< Set a value in a property, can be interpolated.
- TYPE_TRANSFORM, ///< Transform a node or a bone.
+ TYPE_TRANSFORM3D, ///< Transform a node or a bone.
TYPE_METHOD, ///< Call any method on a specific node.
TYPE_BEZIER, ///< Bezier curve
TYPE_AUDIO,
@@ -64,76 +65,61 @@ public:
private:
struct Track {
-
- TrackType type;
- InterpolationType interpolation;
- bool loop_wrap;
+ TrackType type = TrackType::TYPE_ANIMATION;
+ InterpolationType interpolation = INTERPOLATION_LINEAR;
+ bool loop_wrap = true;
NodePath path; // path to something
- bool imported;
- bool enabled;
- Track() {
- interpolation = INTERPOLATION_LINEAR;
- imported = false;
- loop_wrap = true;
- enabled = true;
- }
+ bool imported = false;
+ bool enabled = true;
+ Track() {}
virtual ~Track() {}
};
struct Key {
-
- float transition;
- float time; // time in secs
- Key() { transition = 1; }
+ float transition = 1.0;
+ float time = 0.0; // time in secs
};
// transform key holds either Vector3 or Quaternion
template <class T>
struct TKey : public Key {
-
T value;
};
struct TransformKey {
-
Vector3 loc;
- Quat rot;
+ Quaternion rot;
Vector3 scale;
};
/* TRANSFORM TRACK */
struct TransformTrack : public Track {
+ Vector<TKey<TransformKey>> transforms;
- Vector<TKey<TransformKey> > transforms;
-
- TransformTrack() { type = TYPE_TRANSFORM; }
+ TransformTrack() { type = TYPE_TRANSFORM3D; }
};
/* PROPERTY VALUE TRACK */
struct ValueTrack : public Track {
-
- UpdateMode update_mode;
- bool update_on_seek;
- Vector<TKey<Variant> > values;
+ UpdateMode update_mode = UPDATE_CONTINUOUS;
+ bool update_on_seek = false;
+ Vector<TKey<Variant>> values;
ValueTrack() {
type = TYPE_VALUE;
- update_mode = UPDATE_CONTINUOUS;
}
};
/* METHOD TRACK */
struct MethodKey : public Key {
-
StringName method;
Vector<Variant> params;
};
struct MethodTrack : public Track {
-
Vector<MethodKey> methods;
MethodTrack() { type = TYPE_METHOD; }
};
@@ -143,12 +129,11 @@ private:
struct BezierKey {
Vector2 in_handle; //relative (x always <0)
Vector2 out_handle; //relative (x always >0)
- float value;
+ float value = 0.0;
};
struct BezierTrack : public Track {
-
- Vector<TKey<BezierKey> > values;
+ Vector<TKey<BezierKey>> values;
BezierTrack() {
type = TYPE_BEZIER;
@@ -159,17 +144,14 @@ private:
struct AudioKey {
RES stream;
- float start_offset; //offset from start
- float end_offset; //offset from end, if 0 then full length or infinite
+ float start_offset = 0.0; //offset from start
+ float end_offset = 0.0; //offset from end, if 0 then full length or infinite
AudioKey() {
- start_offset = 0;
- end_offset = 0;
}
};
struct AudioTrack : public Track {
-
- Vector<TKey<AudioKey> > values;
+ Vector<TKey<AudioKey>> values;
AudioTrack() {
type = TYPE_AUDIO;
@@ -179,8 +161,7 @@ private:
/* AUDIO TRACK */
struct AnimationTrack : public Track {
-
- Vector<TKey<StringName> > values;
+ Vector<TKey<StringName>> values;
AnimationTrack() {
type = TYPE_ANIMATION;
@@ -205,18 +186,18 @@ private:
_FORCE_INLINE_ Animation::TransformKey _interpolate(const Animation::TransformKey &p_a, const Animation::TransformKey &p_b, float p_c) const;
_FORCE_INLINE_ Vector3 _interpolate(const Vector3 &p_a, const Vector3 &p_b, float p_c) const;
- _FORCE_INLINE_ Quat _interpolate(const Quat &p_a, const Quat &p_b, float p_c) const;
+ _FORCE_INLINE_ Quaternion _interpolate(const Quaternion &p_a, const Quaternion &p_b, float p_c) const;
_FORCE_INLINE_ Variant _interpolate(const Variant &p_a, const Variant &p_b, float p_c) const;
_FORCE_INLINE_ float _interpolate(const float &p_a, const float &p_b, float p_c) const;
_FORCE_INLINE_ Animation::TransformKey _cubic_interpolate(const Animation::TransformKey &p_pre_a, const Animation::TransformKey &p_a, const Animation::TransformKey &p_b, const Animation::TransformKey &p_post_b, float p_c) const;
_FORCE_INLINE_ Vector3 _cubic_interpolate(const Vector3 &p_pre_a, const Vector3 &p_a, const Vector3 &p_b, const Vector3 &p_post_b, float p_c) const;
- _FORCE_INLINE_ Quat _cubic_interpolate(const Quat &p_pre_a, const Quat &p_a, const Quat &p_b, const Quat &p_post_b, float p_c) const;
+ _FORCE_INLINE_ Quaternion _cubic_interpolate(const Quaternion &p_pre_a, const Quaternion &p_a, const Quaternion &p_b, const Quaternion &p_post_b, float p_c) const;
_FORCE_INLINE_ Variant _cubic_interpolate(const Variant &p_pre_a, const Variant &p_a, const Variant &p_b, const Variant &p_post_b, float p_c) const;
_FORCE_INLINE_ float _cubic_interpolate(const float &p_pre_a, const float &p_a, const float &p_b, const float &p_post_b, float p_c) const;
template <class T>
- _FORCE_INLINE_ T _interpolate(const Vector<TKey<T> > &p_keys, float p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok) const;
+ _FORCE_INLINE_ T _interpolate(const Vector<TKey<T>> &p_keys, float p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok) const;
template <class T>
_FORCE_INLINE_ void _track_get_key_indices_in_range(const Vector<T> &p_array, float from_time, float to_time, List<int> *p_indices) const;
@@ -224,15 +205,15 @@ private:
_FORCE_INLINE_ void _value_track_get_key_indices_in_range(const ValueTrack *vt, float from_time, float to_time, List<int> *p_indices) const;
_FORCE_INLINE_ void _method_track_get_key_indices_in_range(const MethodTrack *mt, float from_time, float to_time, List<int> *p_indices) const;
- float length;
- float step;
- bool loop;
+ float length = 1.0;
+ float step = 0.1;
+ bool loop = false;
// bind helpers
private:
Array _transform_track_interpolate(int p_track, float p_time) const {
Vector3 loc;
- Quat rot;
+ Quaternion rot;
Vector3 scale;
transform_track_interpolate(p_track, p_time, &loc, &rot, &scale);
Array ret;
@@ -242,26 +223,22 @@ private:
return ret;
}
- PoolVector<int> _value_track_get_key_indices(int p_track, float p_time, float p_delta) const {
-
+ Vector<int> _value_track_get_key_indices(int p_track, float p_time, float p_delta) const {
List<int> idxs;
value_track_get_key_indices(p_track, p_time, p_delta, &idxs);
- PoolVector<int> idxr;
+ Vector<int> idxr;
for (List<int>::Element *E = idxs.front(); E; E = E->next()) {
-
idxr.push_back(E->get());
}
return idxr;
}
- PoolVector<int> _method_track_get_key_indices(int p_track, float p_time, float p_delta) const {
-
+ Vector<int> _method_track_get_key_indices(int p_track, float p_time, float p_delta) const {
List<int> idxs;
method_track_get_key_indices(p_track, p_time, p_delta, &idxs);
- PoolVector<int> idxr;
+ Vector<int> idxr;
for (List<int>::Element *E = idxs.front(); E; E = E->next()) {
-
idxr.push_back(E->get());
}
return idxr;
@@ -275,6 +252,8 @@ protected:
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
+ virtual void reset_state() override;
+
static void _bind_methods();
public:
@@ -306,14 +285,14 @@ public:
void track_set_key_time(int p_track, int p_key_idx, float p_time);
int track_find_key(int p_track, float p_time, bool p_exact = false) const;
void track_remove_key(int p_track, int p_idx);
- void track_remove_key_at_position(int p_track, float p_pos);
+ void track_remove_key_at_time(int p_track, float p_time);
int track_get_key_count(int p_track) const;
Variant track_get_key_value(int p_track, int p_key_idx) const;
float track_get_key_time(int p_track, int p_key_idx) const;
float track_get_key_transition(int p_track, int p_key_idx) const;
- int transform_track_insert_key(int p_track, float p_time, const Vector3 &p_loc, const Quat &p_rot = Quat(), const Vector3 &p_scale = Vector3());
- Error transform_track_get_key(int p_track, int p_key, Vector3 *r_loc, Quat *r_rot, Vector3 *r_scale) const;
+ int transform_track_insert_key(int p_track, float p_time, const Vector3 &p_loc, const Quaternion &p_rot = Quaternion(), const Vector3 &p_scale = Vector3());
+ Error transform_track_get_key(int p_track, int p_key, Vector3 *r_loc, Quaternion *r_rot, Vector3 *r_scale) const;
void track_set_interpolation_type(int p_track, InterpolationType p_interp);
InterpolationType track_get_interpolation_type(int p_track) const;
@@ -342,7 +321,7 @@ public:
void track_set_interpolation_loop_wrap(int p_track, bool p_enable);
bool track_get_interpolation_loop_wrap(int p_track) const;
- Error transform_track_interpolate(int p_track, float p_time, Vector3 *r_loc, Quat *r_rot, Vector3 *r_scale) const;
+ Error transform_track_interpolate(int p_track, float p_time, Vector3 *r_loc, Quaternion *r_rot, Vector3 *r_scale) const;
Variant value_track_interpolate(int p_track, float p_time) const;
void value_track_get_key_indices(int p_track, float p_time, float p_delta, List<int> *p_indices) const;