summaryrefslogtreecommitdiff
path: root/scene/animation/animation_blend_tree.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/animation/animation_blend_tree.cpp')
-rw-r--r--scene/animation/animation_blend_tree.cpp88
1 files changed, 45 insertions, 43 deletions
diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp
index 433f21f91f..3de3ab256e 100644
--- a/scene/animation/animation_blend_tree.cpp
+++ b/scene/animation/animation_blend_tree.cpp
@@ -64,7 +64,7 @@ void AnimationNodeAnimation::_validate_property(PropertyInfo &property) const {
}
}
-double AnimationNodeAnimation::process(double p_time, bool p_seek) {
+double AnimationNodeAnimation::process(double p_time, bool p_seek, bool p_seek_root) {
AnimationPlayer *ap = state->player;
ERR_FAIL_COND_V(!ap, 0);
@@ -101,8 +101,8 @@ double AnimationNodeAnimation::process(double p_time, bool p_seek) {
}
}
- if (anim->get_loop_mode() == Animation::LoopMode::LOOP_PINGPONG) {
- if (anim_size) {
+ if (anim->get_loop_mode() == Animation::LOOP_PINGPONG) {
+ if (!Math::is_zero_approx(anim_size)) {
if ((int)Math::floor(abs(time - prev_time) / anim_size) % 2 == 0) {
if (prev_time > 0 && time <= 0) {
backward = !backward;
@@ -116,22 +116,24 @@ double AnimationNodeAnimation::process(double p_time, bool p_seek) {
time = Math::pingpong(time, anim_size);
}
} else {
- if (anim->get_loop_mode() == Animation::LoopMode::LOOP_LINEAR) {
- if (anim_size) {
+ if (anim->get_loop_mode() == Animation::LOOP_LINEAR) {
+ if (!Math::is_zero_approx(anim_size)) {
time = Math::fposmod(time, anim_size);
}
} else if (time < 0) {
+ step += time;
time = 0;
} else if (time > anim_size) {
+ step += anim_size - time;
time = anim_size;
}
backward = false;
}
if (play_mode == PLAY_MODE_FORWARD) {
- blend_animation(animation, time, step, p_seek, 1.0, pingponged);
+ blend_animation(animation, time, step, p_seek, p_seek_root, 1.0, pingponged);
} else {
- blend_animation(animation, anim_size - time, -step, p_seek, 1.0, pingponged);
+ blend_animation(animation, anim_size - time, -step, p_seek, p_seek_root, 1.0, pingponged);
}
set_parameter(this->time, time);
@@ -251,7 +253,7 @@ bool AnimationNodeOneShot::has_filter() const {
return true;
}
-double AnimationNodeOneShot::process(double p_time, bool p_seek) {
+double AnimationNodeOneShot::process(double p_time, bool p_seek, bool p_seek_root) {
bool active = get_parameter(this->active);
bool prev_active = get_parameter(this->prev_active);
double time = get_parameter(this->time);
@@ -274,7 +276,7 @@ double AnimationNodeOneShot::process(double p_time, bool p_seek) {
}
if (!active) {
- return blend_input(0, p_time, p_seek, 1.0, FILTER_IGNORE, !sync);
+ return blend_input(0, p_time, p_seek, p_seek_root, 1.0, FILTER_IGNORE, !sync);
}
}
@@ -311,12 +313,12 @@ double AnimationNodeOneShot::process(double p_time, bool p_seek) {
double main_rem;
if (mix == MIX_MODE_ADD) {
- main_rem = blend_input(0, p_time, p_seek, 1.0, FILTER_IGNORE, !sync);
+ main_rem = blend_input(0, p_time, p_seek, p_seek_root, 1.0, FILTER_IGNORE, !sync);
} else {
- main_rem = blend_input(0, p_time, p_seek, 1.0 - blend, FILTER_BLEND, !sync);
+ main_rem = blend_input(0, p_time, p_seek, p_seek_root, 1.0 - blend, FILTER_BLEND, !sync);
}
- double os_rem = blend_input(1, os_seek ? time : p_time, os_seek, blend, FILTER_PASS, false);
+ double os_rem = blend_input(1, os_seek ? time : p_time, os_seek, p_seek_root, blend, FILTER_PASS, false);
if (do_start) {
remaining = os_rem;
@@ -420,10 +422,10 @@ bool AnimationNodeAdd2::has_filter() const {
return true;
}
-double AnimationNodeAdd2::process(double p_time, bool p_seek) {
+double AnimationNodeAdd2::process(double p_time, bool p_seek, bool p_seek_root) {
double amount = get_parameter(add_amount);
- double rem0 = blend_input(0, p_time, p_seek, 1.0, FILTER_IGNORE, !sync);
- blend_input(1, p_time, p_seek, amount, FILTER_PASS, !sync);
+ double rem0 = blend_input(0, p_time, p_seek, p_seek_root, 1.0, FILTER_IGNORE, !sync);
+ blend_input(1, p_time, p_seek, p_seek_root, amount, FILTER_PASS, !sync);
return rem0;
}
@@ -466,11 +468,11 @@ bool AnimationNodeAdd3::has_filter() const {
return true;
}
-double AnimationNodeAdd3::process(double p_time, bool p_seek) {
+double AnimationNodeAdd3::process(double p_time, bool p_seek, bool p_seek_root) {
double amount = get_parameter(add_amount);
- blend_input(0, p_time, p_seek, MAX(0, -amount), FILTER_PASS, !sync);
- double rem0 = blend_input(1, p_time, p_seek, 1.0, FILTER_IGNORE, !sync);
- blend_input(2, p_time, p_seek, MAX(0, amount), FILTER_PASS, !sync);
+ blend_input(0, p_time, p_seek, p_seek_root, MAX(0, -amount), FILTER_PASS, !sync);
+ double rem0 = blend_input(1, p_time, p_seek, p_seek_root, 1.0, FILTER_IGNORE, !sync);
+ blend_input(2, p_time, p_seek, p_seek_root, MAX(0, amount), FILTER_PASS, !sync);
return rem0;
}
@@ -502,11 +504,11 @@ String AnimationNodeBlend2::get_caption() const {
return "Blend2";
}
-double AnimationNodeBlend2::process(double p_time, bool p_seek) {
+double AnimationNodeBlend2::process(double p_time, bool p_seek, bool p_seek_root) {
double amount = get_parameter(blend_amount);
- double rem0 = blend_input(0, p_time, p_seek, 1.0 - amount, FILTER_BLEND, !sync);
- double rem1 = blend_input(1, p_time, p_seek, amount, FILTER_PASS, !sync);
+ double rem0 = blend_input(0, p_time, p_seek, p_seek_root, 1.0 - amount, FILTER_BLEND, !sync);
+ double rem1 = blend_input(1, p_time, p_seek, p_seek_root, amount, FILTER_PASS, !sync);
return amount > 0.5 ? rem1 : rem0; //hacky but good enough
}
@@ -557,11 +559,11 @@ bool AnimationNodeBlend3::is_using_sync() const {
return sync;
}
-double AnimationNodeBlend3::process(double p_time, bool p_seek) {
+double AnimationNodeBlend3::process(double p_time, bool p_seek, bool p_seek_root) {
double amount = get_parameter(blend_amount);
- double rem0 = blend_input(0, p_time, p_seek, MAX(0, -amount), FILTER_IGNORE, !sync);
- double rem1 = blend_input(1, p_time, p_seek, 1.0 - ABS(amount), FILTER_IGNORE, !sync);
- double rem2 = blend_input(2, p_time, p_seek, MAX(0, amount), FILTER_IGNORE, !sync);
+ double rem0 = blend_input(0, p_time, p_seek, p_seek_root, MAX(0, -amount), FILTER_IGNORE, !sync);
+ double rem1 = blend_input(1, p_time, p_seek, p_seek_root, 1.0 - ABS(amount), FILTER_IGNORE, !sync);
+ double rem2 = blend_input(2, p_time, p_seek, p_seek_root, MAX(0, amount), FILTER_IGNORE, !sync);
return amount > 0.5 ? rem2 : (amount < -0.5 ? rem0 : rem1); //hacky but good enough
}
@@ -595,12 +597,12 @@ String AnimationNodeTimeScale::get_caption() const {
return "TimeScale";
}
-double AnimationNodeTimeScale::process(double p_time, bool p_seek) {
+double AnimationNodeTimeScale::process(double p_time, bool p_seek, bool p_seek_root) {
double scale = get_parameter(this->scale);
if (p_seek) {
- return blend_input(0, p_time, true, 1.0, FILTER_IGNORE, false);
+ return blend_input(0, p_time, true, p_seek_root, 1.0, FILTER_IGNORE, false);
} else {
- return blend_input(0, p_time * scale, false, 1.0, FILTER_IGNORE, false);
+ return blend_input(0, p_time * scale, false, p_seek_root, 1.0, FILTER_IGNORE, false);
}
}
@@ -625,16 +627,16 @@ String AnimationNodeTimeSeek::get_caption() const {
return "Seek";
}
-double AnimationNodeTimeSeek::process(double p_time, bool p_seek) {
+double AnimationNodeTimeSeek::process(double p_time, bool p_seek, bool p_seek_root) {
double seek_pos = get_parameter(this->seek_pos);
if (p_seek) {
- return blend_input(0, p_time, true, 1.0, FILTER_IGNORE, false);
+ return blend_input(0, p_time, true, p_seek_root, 1.0, FILTER_IGNORE, false);
} else if (seek_pos >= 0) {
- double ret = blend_input(0, seek_pos, true, 1.0, FILTER_IGNORE, false);
+ double ret = blend_input(0, seek_pos, true, true, 1.0, FILTER_IGNORE, false);
set_parameter(this->seek_pos, -1.0); //reset
return ret;
} else {
- return blend_input(0, p_time, false, 1.0, FILTER_IGNORE, false);
+ return blend_input(0, p_time, false, p_seek_root, 1.0, FILTER_IGNORE, false);
}
}
@@ -726,7 +728,7 @@ float AnimationNodeTransition::get_cross_fade_time() const {
return xfade;
}
-double AnimationNodeTransition::process(double p_time, bool p_seek) {
+double AnimationNodeTransition::process(double p_time, bool p_seek, bool p_seek_root) {
int current = get_parameter(this->current);
int prev = get_parameter(this->prev);
int prev_current = get_parameter(this->prev_current);
@@ -754,7 +756,7 @@ double AnimationNodeTransition::process(double p_time, bool p_seek) {
if (prev < 0) { // process current animation, check for transition
- rem = blend_input(current, p_time, p_seek, 1.0, FILTER_IGNORE, false);
+ rem = blend_input(current, p_time, p_seek, p_seek_root, 1.0, FILTER_IGNORE, false);
if (p_seek) {
time = p_time;
@@ -772,16 +774,16 @@ double AnimationNodeTransition::process(double p_time, bool p_seek) {
if (!p_seek && switched) { //just switched, seek to start of current
- rem = blend_input(current, 0, true, 1.0 - blend, FILTER_IGNORE, false);
+ rem = blend_input(current, 0, true, p_seek_root, 1.0 - blend, FILTER_IGNORE, false);
} else {
- rem = blend_input(current, p_time, p_seek, 1.0 - blend, FILTER_IGNORE, false);
+ rem = blend_input(current, p_time, p_seek, p_seek_root, 1.0 - blend, FILTER_IGNORE, false);
}
if (p_seek) { // don't seek prev animation
- blend_input(prev, 0, false, blend, FILTER_IGNORE, false);
+ blend_input(prev, 0, false, p_seek_root, blend, FILTER_IGNORE, false);
time = p_time;
} else {
- blend_input(prev, p_time, false, blend, FILTER_IGNORE, false);
+ blend_input(prev, p_time, false, p_seek_root, blend, FILTER_IGNORE, false);
time += p_time;
prev_xfading -= p_time;
if (prev_xfading < 0) {
@@ -844,8 +846,8 @@ String AnimationNodeOutput::get_caption() const {
return "Output";
}
-double AnimationNodeOutput::process(double p_time, bool p_seek) {
- return blend_input(0, p_time, p_seek, 1.0);
+double AnimationNodeOutput::process(double p_time, bool p_seek, bool p_seek_root) {
+ return blend_input(0, p_time, p_seek, p_seek_root, 1.0);
}
AnimationNodeOutput::AnimationNodeOutput() {
@@ -1057,9 +1059,9 @@ String AnimationNodeBlendTree::get_caption() const {
return "BlendTree";
}
-double AnimationNodeBlendTree::process(double p_time, bool p_seek) {
+double AnimationNodeBlendTree::process(double p_time, bool p_seek, bool p_seek_root) {
Ref<AnimationNodeOutput> output = nodes[SceneStringNames::get_singleton()->output].node;
- return _blend_node("output", nodes[SceneStringNames::get_singleton()->output].connections, this, output, p_time, p_seek, 1.0);
+ return _blend_node("output", nodes[SceneStringNames::get_singleton()->output].connections, this, output, p_time, p_seek, p_seek_root, 1.0);
}
void AnimationNodeBlendTree::get_node_list(List<StringName> *r_list) {