summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/animation/animation_player.cpp14
-rw-r--r--scene/resources/animation.cpp17
-rw-r--r--scene/resources/animation.h3
3 files changed, 32 insertions, 2 deletions
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index cecdd2bc40..22c41dda8e 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -538,6 +538,7 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd,float p_delta,flo
float len=cd.from->animation->get_length();
bool loop=cd.from->animation->has_loop();
+ bool loop_interpolation=cd.from->animation->has_loop_interpolation();
if (!loop) {
@@ -563,10 +564,21 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd,float p_delta,flo
}
- } else {
+ } else if (loop_interpolation) {
next_pos=Math::fposmod(next_pos,len);
+ } else {
+
+ if (next_pos<0 or next_pos>len) {
+ if (!backwards)
+ next_pos=0;
+ else if (backwards)
+ next_pos=len;
+ }
+ // fix delta - not sure if needed here
+ delta=next_pos-cd.pos;
+
}
cd.pos=next_pos;
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index f7d5ddc744..c8525b29b6 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -38,6 +38,8 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) {
set_length(p_value);
else if (name=="loop")
set_loop(p_value);
+ else if (name=="loop_interpolation")
+ set_loop_interpolation(p_value);
else if (name=="step")
set_step(p_value);
else if (name.begins_with("tracks/")) {
@@ -1221,7 +1223,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 and loop_interpolation) {
// loop
if (idx>=0) {
@@ -1607,10 +1609,19 @@ void Animation::set_loop(bool p_enabled) {
loop=p_enabled;
emit_changed();
}
+void Animation::set_loop_interpolation(bool p_enabled) {
+
+ loop_interpolation=p_enabled;
+ emit_changed();
+}
bool Animation::has_loop() const {
return loop;
}
+bool Animation::has_loop_interpolation() const {
+
+ return loop_interpolation;
+}
void Animation::track_move_up(int p_track) {
@@ -1689,7 +1700,9 @@ void Animation::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_length"),&Animation::get_length);
ObjectTypeDB::bind_method(_MD("set_loop","enabled"),&Animation::set_loop);
+ ObjectTypeDB::bind_method(_MD("set_loop_interpolation","enabled"),&Animation::set_loop_interpolation);
ObjectTypeDB::bind_method(_MD("has_loop"),&Animation::has_loop);
+ ObjectTypeDB::bind_method(_MD("has_loop_interpolation"),&Animation::has_loop_interpolation);
ObjectTypeDB::bind_method(_MD("set_step","size_sec"),&Animation::set_step);
ObjectTypeDB::bind_method(_MD("get_step"),&Animation::get_step);
@@ -1712,6 +1725,7 @@ void Animation::clear() {
memdelete( tracks[i] );
tracks.clear();
loop=false;
+ loop_interpolation=true;
length=1;
}
@@ -1971,6 +1985,7 @@ Animation::Animation() {
step=0.1;
loop=false;
+ loop_interpolation=true;
length=1;
}
diff --git a/scene/resources/animation.h b/scene/resources/animation.h
index 1f2d9b80ab..e1d76d1ffd 100644
--- a/scene/resources/animation.h
+++ b/scene/resources/animation.h
@@ -163,6 +163,7 @@ private:
float length;
float step;
bool loop;
+ bool loop_interpolation;
// bind helpers
private:
@@ -265,7 +266,9 @@ public:
float get_length() const;
void set_loop(bool p_enabled);
+ void set_loop_interpolation(bool p_enabled);
bool has_loop() const;
+ bool has_loop_interpolation() const;
void set_step(float p_step);
float get_step() const;