From bb9674c1b1817d01152672c54c4ca3a4231cdb65 Mon Sep 17 00:00:00 2001 From: Lyuma Date: Fri, 19 Apr 2024 02:05:46 -0700 Subject: [PATCH] Set animation step from importers. Increase default step from 10 to 30 FPS. --- doc/classes/Animation.xml | 2 +- editor/import/3d/editor_import_collada.cpp | 1 + editor/import/3d/resource_importer_scene.cpp | 1 + editor/plugins/animation_player_editor_plugin.cpp | 5 +++++ modules/fbx/fbx_document.cpp | 1 + modules/gltf/gltf_document.cpp | 1 + scene/resources/animation.h | 2 +- tests/scene/test_animation.h | 2 +- 8 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/classes/Animation.xml b/doc/classes/Animation.xml index b00889f48315..4e9b6426740e 100644 --- a/doc/classes/Animation.xml +++ b/doc/classes/Animation.xml @@ -602,7 +602,7 @@ Determines the behavior of both ends of the animation timeline during animation playback. This is used for correct interpolation of animation cycles, and for hinting the player that it must restart the animation. - + The animation step value. diff --git a/editor/import/3d/editor_import_collada.cpp b/editor/import/3d/editor_import_collada.cpp index 4b91b1431a8d..04a3f2315457 100644 --- a/editor/import/3d/editor_import_collada.cpp +++ b/editor/import/3d/editor_import_collada.cpp @@ -1556,6 +1556,7 @@ void ColladaImport::create_animation(int p_clip, bool p_import_value_tracks) { } animation->set_length(anim_length); + animation->set_step(snapshot_interval); bool tracks_found = false; diff --git a/editor/import/3d/resource_importer_scene.cpp b/editor/import/3d/resource_importer_scene.cpp index dce68a97accb..2560d43241f2 100644 --- a/editor/import/3d/resource_importer_scene.cpp +++ b/editor/import/3d/resource_importer_scene.cpp @@ -1908,6 +1908,7 @@ void ResourceImporterScene::_create_slices(AnimationPlayer *ap, Ref a new_anim->set_loop_mode(loop_mode); new_anim->set_length(to - from); + new_anim->set_step(anim->get_step()); al->add_animation(name, new_anim); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 43928b9c176a..3399f265fc64 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -548,8 +548,13 @@ void AnimationPlayerEditor::_animation_name_edited() { } break; case TOOL_NEW_ANIM: { + String current = animation->get_item_text(animation->get_selected()); + Ref current_anim = player->get_animation(current); Ref new_anim = Ref(memnew(Animation)); new_anim->set_name(new_name); + if (current_anim.is_valid()) { + new_anim->set_step(current_anim->get_step()); + } String library_name; Ref al; library_name = library->get_item_metadata(library->get_selected()); diff --git a/modules/fbx/fbx_document.cpp b/modules/fbx/fbx_document.cpp index 44a929d285d3..685687ea859c 100644 --- a/modules/fbx/fbx_document.cpp +++ b/modules/fbx/fbx_document.cpp @@ -1699,6 +1699,7 @@ void FBXDocument::_import_animation(Ref p_state, AnimationPlayer *p_an Ref animation; animation.instantiate(); animation->set_name(anim_name); + animation->set_step(1.0 / p_bake_fps); if (anim->get_loop()) { animation->set_loop_mode(Animation::LOOP_LINEAR); diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 8f0f0d219efb..4c32a29ce00a 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -5881,6 +5881,7 @@ void GLTFDocument::_import_animation(Ref p_state, AnimationPlayer *p_ Ref animation; animation.instantiate(); animation->set_name(anim_name); + animation->set_step(1.0 / p_bake_fps); if (anim->get_loop()) { animation->set_loop_mode(Animation::LOOP_LINEAR); diff --git a/scene/resources/animation.h b/scene/resources/animation.h index c72327e46449..6005172c11fc 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -266,7 +266,7 @@ private: _FORCE_INLINE_ void _track_get_key_indices_in_range(const Vector &p_array, double from_time, double to_time, List *p_indices, bool p_is_backward) const; double length = 1.0; - real_t step = 0.1; + real_t step = 1.0 / 30; LoopMode loop_mode = LOOP_NONE; void _track_update_hash(int p_track); diff --git a/tests/scene/test_animation.h b/tests/scene/test_animation.h index 89bf29681544..6c89592e0db2 100644 --- a/tests/scene/test_animation.h +++ b/tests/scene/test_animation.h @@ -41,7 +41,7 @@ TEST_CASE("[Animation] Empty animation getters") { const Ref animation = memnew(Animation); CHECK(animation->get_length() == doctest::Approx(real_t(1.0))); - CHECK(animation->get_step() == doctest::Approx(real_t(0.1))); + CHECK(animation->get_step() == doctest::Approx(real_t(1.0 / 30))); } TEST_CASE("[Animation] Create value track") {