diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-05-31 10:12:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-31 10:12:37 +0200 |
commit | 7770f8cb7e9bfaf3a76e73441681e708108bfc82 (patch) | |
tree | c04018b611d22a1ee81f6fab19485ba6bb91525a | |
parent | b9802149bbe7796e174b8d6bbec9f96b44c39c59 (diff) | |
parent | adcbcf87dd285343b86b755f287748c3cd205801 (diff) |
Merge pull request #29331 from KoBeWi/animation_time_machine
Add track_set_key_time() to Animation
-rw-r--r-- | doc/classes/Animation.xml | 13 | ||||
-rw-r--r-- | scene/resources/animation.cpp | 73 | ||||
-rw-r--r-- | scene/resources/animation.h | 1 |
3 files changed, 87 insertions, 0 deletions
diff --git a/doc/classes/Animation.xml b/doc/classes/Animation.xml index 9885f30883..53d3663d4f 100644 --- a/doc/classes/Animation.xml +++ b/doc/classes/Animation.xml @@ -562,6 +562,19 @@ Set the value of an existing key. </description> </method> + <method name="track_set_key_time"> + <return type="void"> + </return> + <argument index="0" name="idx" type="int"> + </argument> + <argument index="1" name="key_idx" type="int"> + </argument> + <argument index="2" name="time" type="float"> + </argument> + <description> + Set the time of an existing key. + </description> + </method> <method name="track_set_path"> <return type="void"> </return> diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 6ab78326b2..b49b551252 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1298,6 +1298,78 @@ float Animation::track_get_key_time(int p_track, int p_key_idx) const { ERR_FAIL_V(-1); } +void Animation::track_set_key_time(int p_track, int p_key_idx, float p_time) { + + ERR_FAIL_INDEX(p_track, tracks.size()); + Track *t = tracks[p_track]; + + switch (t->type) { + + case TYPE_TRANSFORM: { + + TransformTrack *tt = static_cast<TransformTrack *>(t); + ERR_FAIL_INDEX(p_key_idx, tt->transforms.size()); + TKey<TransformKey> key = tt->transforms[p_key_idx]; + key.time = p_time; + tt->transforms.remove(p_key_idx); + _insert(p_time, tt->transforms, key); + return; + } + case TYPE_VALUE: { + + ValueTrack *vt = static_cast<ValueTrack *>(t); + ERR_FAIL_INDEX(p_key_idx, vt->values.size()); + TKey<Variant> key = vt->values[p_key_idx]; + key.time = p_time; + vt->values.remove(p_key_idx); + _insert(p_time, vt->values, key); + return; + } + case TYPE_METHOD: { + + MethodTrack *mt = static_cast<MethodTrack *>(t); + ERR_FAIL_INDEX(p_key_idx, mt->methods.size()); + MethodKey key = mt->methods[p_key_idx]; + key.time = p_time; + mt->methods.remove(p_key_idx); + _insert(p_time, mt->methods, key); + return; + } + case TYPE_BEZIER: { + + BezierTrack *bt = static_cast<BezierTrack *>(t); + ERR_FAIL_INDEX(p_key_idx, bt->values.size()); + TKey<BezierKey> key = bt->values[p_key_idx]; + key.time = p_time; + bt->values.remove(p_key_idx); + _insert(p_time, bt->values, key); + return; + } + case TYPE_AUDIO: { + + AudioTrack *at = static_cast<AudioTrack *>(t); + ERR_FAIL_INDEX(p_key_idx, at->values.size()); + TKey<AudioKey> key = at->values[p_key_idx]; + key.time = p_time; + at->values.remove(p_key_idx); + _insert(p_time, at->values, key); + return; + } + case TYPE_ANIMATION: { + + AnimationTrack *at = static_cast<AnimationTrack *>(t); + ERR_FAIL_INDEX(p_key_idx, at->values.size()); + TKey<StringName> key = at->values[p_key_idx]; + key.time = p_time; + at->values.remove(p_key_idx); + _insert(p_time, at->values, key); + return; + } + } + + ERR_FAIL(); +} + float Animation::track_get_key_transition(int p_track, int p_key_idx) const { ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); @@ -2691,6 +2763,7 @@ void Animation::_bind_methods() { ClassDB::bind_method(D_METHOD("track_remove_key_at_position", "idx", "position"), &Animation::track_remove_key_at_position); ClassDB::bind_method(D_METHOD("track_set_key_value", "idx", "key", "value"), &Animation::track_set_key_value); ClassDB::bind_method(D_METHOD("track_set_key_transition", "idx", "key_idx", "transition"), &Animation::track_set_key_transition); + ClassDB::bind_method(D_METHOD("track_set_key_time", "idx", "key_idx", "time"), &Animation::track_set_key_time); ClassDB::bind_method(D_METHOD("track_get_key_transition", "idx", "key_idx"), &Animation::track_get_key_transition); ClassDB::bind_method(D_METHOD("track_get_key_count", "idx"), &Animation::track_get_key_count); diff --git a/scene/resources/animation.h b/scene/resources/animation.h index 36ebaa25d5..59f2ae24c7 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -305,6 +305,7 @@ public: void track_insert_key(int p_track, float p_time, const Variant &p_key, float p_transition = 1); void track_set_key_transition(int p_track, int p_key_idx, float p_transition); void track_set_key_value(int p_track, int p_key_idx, const Variant &p_value); + 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); |