diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-01-09 00:41:16 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-01-09 00:41:16 -0300 |
commit | a168cd7a235d803680b0093df9baa427ffa7b21e (patch) | |
tree | 2bf7eff42461388d05ec9f7ce956dbbd3924700c /scene/resources | |
parent | 62273e51a252287d1c60228e8a8e8939ecaa73c6 (diff) |
Add clamp and wrap loop modes for animation tracks.
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/animation.cpp | 28 | ||||
-rw-r--r-- | scene/resources/animation.h | 12 |
2 files changed, 29 insertions, 11 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 76c6f29bcb..c962e1a671 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -72,6 +72,8 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) { track_set_path(track,p_value); else if (what=="interp") track_set_interpolation_type(track,InterpolationType(p_value.operator int())); + else if (what=="loop_wrap") + track_set_interpolation_loop_wrap(track,p_value); else if (what=="imported") track_set_imported(track,p_value); else if (what == "keys" || what=="key_values") { @@ -291,6 +293,8 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const { r_ret=track_get_path(track); else if (what=="interp") r_ret = track_get_interpolation_type(track); + else if (what=="loop_wrap") + r_ret = track_get_interpolation_loop_wrap(track); else if (what=="imported") r_ret = track_is_imported(track); else if (what=="keys") { @@ -440,6 +444,7 @@ void Animation::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::STRING, "tracks/"+itos(i)+"/type", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::NODE_PATH, "tracks/"+itos(i)+"/path", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::INT, "tracks/"+itos(i)+"/interp", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); + p_list->push_back( PropertyInfo( Variant::BOOL, "tracks/"+itos(i)+"/loop_wrap", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::BOOL, "tracks/"+itos(i)+"/imported", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::ARRAY, "tracks/"+itos(i)+"/keys", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); } @@ -559,6 +564,19 @@ Animation::InterpolationType Animation::track_get_interpolation_type(int p_track return tracks[p_track]->interpolation; } +void Animation::track_set_interpolation_loop_wrap(int p_track,bool p_enable) { + ERR_FAIL_INDEX(p_track, tracks.size()); + tracks[p_track]->loop_wrap=p_enable; + emit_changed(); + +} + +bool Animation::track_get_interpolation_loop_wrap(int p_track) const{ + + ERR_FAIL_INDEX_V(p_track, tracks.size(),INTERPOLATION_NEAREST); + return tracks[p_track]->loop_wrap; + +} // transform /* @@ -1211,7 +1229,7 @@ float Animation::_cubic_interpolate( const float& p_pre_a,const float& p_a, cons } template<class T> -T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, InterpolationType p_interp, bool *p_ok) const { +T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, InterpolationType p_interp, bool p_loop_wrap,bool *p_ok) const { int len=_find( p_keys, length )+1; // try to find last key (there may be more past the end) @@ -1239,7 +1257,7 @@ T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, Inter float c=0; // prepare for all cases of interpolation - if (loop) { + if (loop && p_loop_wrap) { // loop if (idx>=0) { @@ -1363,7 +1381,7 @@ Error Animation::transform_track_interpolate(int p_track, float p_time, Vector3 bool ok; - TransformKey tk = _interpolate( tt->transforms, p_time, tt->interpolation, &ok ); + TransformKey tk = _interpolate( tt->transforms, p_time, tt->interpolation, tt->loop_wrap, &ok ); if (!ok) // ?? return ERR_UNAVAILABLE; @@ -1391,7 +1409,7 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const { bool ok; - Variant res = _interpolate( vt->values, p_time, vt->update_mode==UPDATE_CONTINUOUS?vt->interpolation:INTERPOLATION_NEAREST, &ok ); + Variant res = _interpolate( vt->values, p_time, vt->update_mode==UPDATE_CONTINUOUS?vt->interpolation:INTERPOLATION_NEAREST,vt->loop_wrap, &ok ); if (ok) { @@ -1711,6 +1729,8 @@ void Animation::_bind_methods() { ClassDB::bind_method(_MD("track_set_interpolation_type","idx","interpolation"),&Animation::track_set_interpolation_type); ClassDB::bind_method(_MD("track_get_interpolation_type","idx"),&Animation::track_get_interpolation_type); + ClassDB::bind_method(_MD("track_set_interpolation_loop_wrap","idx","interpolation"),&Animation::track_set_interpolation_loop_wrap); + ClassDB::bind_method(_MD("track_get_interpolation_loop_wrap","idx"),&Animation::track_get_interpolation_loop_wrap); ClassDB::bind_method(_MD("transform_track_interpolate","idx","time_sec"),&Animation::_transform_track_interpolate); diff --git a/scene/resources/animation.h b/scene/resources/animation.h index c236b3ef37..b81ac4f1bf 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -39,12 +39,7 @@ class Animation : public Resource { RES_BASE_EXTENSION("anm"); public: - enum LoopMode { - LOOP_NONE, - LOOP_ENABLED, - LOOP_WRAP - }; enum TrackType { TYPE_VALUE, ///< Set a value in a property, can be interpolated. @@ -71,9 +66,10 @@ private: TrackType type; InterpolationType interpolation; + bool loop_wrap; NodePath path; // path to something bool imported; - Track() { interpolation=INTERPOLATION_LINEAR; imported=false;} + Track() { interpolation=INTERPOLATION_LINEAR; imported=false; loop_wrap=true;} virtual ~Track() {} }; @@ -164,7 +160,7 @@ private: _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_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; _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; @@ -260,6 +256,8 @@ public: void track_set_interpolation_type(int p_track,InterpolationType p_interp); InterpolationType track_get_interpolation_type(int p_track) const; + 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; |