From f51c08120eea6d8f392b0a3e97af9174aebe9428 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 12 Aug 2022 17:48:00 +0200 Subject: [PATCH] Backported from Godot4: improved way of getting method track keys - TokageItLab https://github.com/godotengine/godot/commit/dedc4710a3608f6acb5285776fb40c5dac85950e --- scene/animation/animation_tree.cpp | 71 ++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 641b4d1dc..8bbc702a6 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -286,6 +286,9 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vectorbase_path) + String(p_subpath) + "/"; } + // If tracks for blending don't exist for one of the animations, Rest or RESET animation is blended as init animation instead. + // Then, blend weight is 0 means that the init animation blend weight is 1. + // Therefore, the blending process must be executed even if the blend weight is 0. if (!p_seek && p_optimize && !any_valid) { return p_node->_pre_process(new_path, new_parent, state, 0, p_seek, p_connections); } @@ -1176,12 +1179,22 @@ void AnimationTree::_process_graph(float p_delta) { continue; //nothing to blend } - List indices; - a->value_track_get_key_indices(i, time, delta, &indices); + if (seeked) { + int idx = a->track_find_key(i, time); + if (idx < 0) { + continue; + } + Variant value = a->track_get_key_value(i, idx); - for (List::Element *F = indices.front(); F; F = F->next()) { - Variant value = a->track_get_key_value(i, F->get()); t->object->set_indexed(t->subpath, value); + } else { + List indices; + a->value_track_get_key_indices(i, time, delta, &indices); + + for (List::Element *F = indices.front(); F; F = F->next()) { + Variant value = a->track_get_key_value(i, F->get()); + t->object->set_indexed(t->subpath, value); + } } } @@ -1190,25 +1203,31 @@ void AnimationTree::_process_graph(float p_delta) { if (blend < CMP_EPSILON) { continue; //nothing to blend } - if (!seeked && Math::is_zero_approx(delta)) { - continue; - } + TrackCacheMethod *t = static_cast(track); - List indices; + //List indices; - a->method_track_get_key_indices(i, time, delta, &indices); + //a->method_track_get_key_indices(i, time, delta, &indices); - for (List::Element *F = indices.front(); F; F = F->next()) { - StringName method = a->method_track_get_name(i, F->get()); - Vector params = a->method_track_get_params(i, F->get()); + //for (List::Element *F = indices.front(); F; F = F->next()) { + // StringName method = a->method_track_get_name(i, F->get()); + // Vector params = a->method_track_get_params(i, F->get()); + if (seeked) { + int idx = a->track_find_key(i, time); + if (idx < 0) { + continue; + } + + StringName method = a->method_track_get_name(i, idx); + Vector params = a->method_track_get_params(i, idx); int s = params.size(); static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); ERR_CONTINUE(s > VARIANT_ARG_MAX); if (can_call) { - t->object->call_deferred( + t->object->call( method, s >= 1 ? params[0] : Variant(), s >= 2 ? params[1] : Variant(), @@ -1219,8 +1238,32 @@ void AnimationTree::_process_graph(float p_delta) { s >= 7 ? params[6] : Variant(), s >= 8 ? params[7] : Variant()); } - } + } else { + List indices; + a->method_track_get_key_indices(i, time, delta, &indices); + for (List::Element *F = indices.front(); F; F = F->next()) { + StringName method = a->method_track_get_name(i, F->get()); + Vector params = a->method_track_get_params(i, F->get()); + + int s = params.size(); + + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); + ERR_CONTINUE(s > VARIANT_ARG_MAX); + if (can_call) { + t->object->call_deferred( + method, + s >= 1 ? params[0] : Variant(), + s >= 2 ? params[1] : Variant(), + s >= 3 ? params[2] : Variant(), + s >= 4 ? params[3] : Variant(), + s >= 5 ? params[4] : Variant(), + s >= 6 ? params[5] : Variant(), + s >= 7 ? params[6] : Variant(), + s >= 8 ? params[7] : Variant()); + } + } + } } break; case Animation::TYPE_BEZIER: { TrackCacheBezier *t = static_cast(track);