diff options
author | SaracenOne <SaracenOne@gmail.com> | 2022-10-21 18:35:25 +0100 |
---|---|---|
committer | SaracenOne <SaracenOne@gmail.com> | 2023-01-25 10:17:55 +0000 |
commit | 02a82c9531d14f5a13900dfde11b3581c3fd6ef7 (patch) | |
tree | 0e8bb3c606dfb7a9098e2f955838f8b892eaa3e2 /scene/animation | |
parent | 4368191a9f9c6290805dd4094c36379776128338 (diff) |
Add indicator for state machine transition fade progress and position of state transitioning from.
Diffstat (limited to 'scene/animation')
-rw-r--r-- | scene/animation/animation_node_state_machine.cpp | 30 | ||||
-rw-r--r-- | scene/animation/animation_node_state_machine.h | 9 |
2 files changed, 38 insertions, 1 deletions
diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index f8c09b4bde..7fb831b3b2 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -228,6 +228,22 @@ float AnimationNodeStateMachinePlayback::get_current_length() const { return len_current; } +float AnimationNodeStateMachinePlayback::get_fade_from_play_pos() const { + return pos_fade_from; +} + +float AnimationNodeStateMachinePlayback::get_fade_from_length() const { + return len_fade_from; +} + +float AnimationNodeStateMachinePlayback::get_fading_time() const { + return fading_time; +} + +float AnimationNodeStateMachinePlayback::get_fading_pos() const { + return fading_pos; +} + bool AnimationNodeStateMachinePlayback::_travel(AnimationNodeStateMachine *p_state_machine, const StringName &p_travel) { ERR_FAIL_COND_V(!playing, false); ERR_FAIL_COND_V(!p_state_machine->states.has(p_travel), false); @@ -466,7 +482,17 @@ double AnimationNodeStateMachinePlayback::_process(AnimationNodeStateMachine *p_ if (fading_from != StringName()) { double fade_blend_inv = 1.0 - fade_blend; - p_state_machine->blend_node(fading_from, p_state_machine->states[fading_from].node, p_time, p_seek, p_is_external_seeking, Math::is_zero_approx(fade_blend_inv) ? CMP_EPSILON : fade_blend_inv, AnimationNode::FILTER_IGNORE, true); // Blend values must be more than CMP_EPSILON to process discrete keys in edge. + float fading_from_rem = 0.0; + fading_from_rem = p_state_machine->blend_node(fading_from, p_state_machine->states[fading_from].node, p_time, p_seek, p_is_external_seeking, Math::is_zero_approx(fade_blend_inv) ? CMP_EPSILON : fade_blend_inv, AnimationNode::FILTER_IGNORE, true); // Blend values must be more than CMP_EPSILON to process discrete keys in edge. + //guess playback position + if (fading_from_rem > len_fade_from) { // weird but ok + len_fade_from = fading_from_rem; + } + + { //advance and loop check + float next_pos = len_fade_from - fading_from_rem; + pos_fade_from = next_pos; //looped + } if (fade_blend >= 1.0) { fading_from = StringName(); } @@ -633,6 +659,8 @@ double AnimationNodeStateMachinePlayback::_process(AnimationNodeStateMachine *p_ } current = next; + pos_fade_from = pos_current; + len_fade_from = len_current; if (reset_request) { len_current = p_state_machine->blend_node(current, p_state_machine->states[current].node, 0, true, p_is_external_seeking, CMP_EPSILON, AnimationNode::FILTER_IGNORE, true); // Process next node's first key in here. diff --git a/scene/animation/animation_node_state_machine.h b/scene/animation/animation_node_state_machine.h index 1b4e010a06..cf4d850aa6 100644 --- a/scene/animation/animation_node_state_machine.h +++ b/scene/animation/animation_node_state_machine.h @@ -118,6 +118,9 @@ class AnimationNodeStateMachinePlayback : public Resource { StringName next; }; + double len_fade_from = 0.0; + double pos_fade_from = 0.0; + double len_current = 0.0; double pos_current = 0.0; bool end_loop = false; @@ -164,6 +167,12 @@ public: float get_current_play_pos() const; float get_current_length() const; + float get_fade_from_play_pos() const; + float get_fade_from_length() const; + + float get_fading_time() const; + float get_fading_pos() const; + AnimationNodeStateMachinePlayback(); }; |