Skip to content

Commit

Permalink
Set animation step from importers. Increase default step from 10 to 3…
Browse files Browse the repository at this point in the history
…0 FPS.
  • Loading branch information
lyuma committed Apr 19, 2024
1 parent 2efbc6b commit bb9674c
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc/classes/Animation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@
<member name="loop_mode" type="int" setter="set_loop_mode" getter="get_loop_mode" enum="Animation.LoopMode" default="0">
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.
</member>
<member name="step" type="float" setter="set_step" getter="get_step" default="0.1">
<member name="step" type="float" setter="set_step" getter="get_step" default="0.0333333">
The animation step value.
</member>
</members>
Expand Down
1 change: 1 addition & 0 deletions editor/import/3d/editor_import_collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions editor/import/3d/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,7 @@ void ResourceImporterScene::_create_slices(AnimationPlayer *ap, Ref<Animation> 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);

Expand Down
5 changes: 5 additions & 0 deletions editor/plugins/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,13 @@ void AnimationPlayerEditor::_animation_name_edited() {
} break;

case TOOL_NEW_ANIM: {
String current = animation->get_item_text(animation->get_selected());
Ref<Animation> current_anim = player->get_animation(current);
Ref<Animation> new_anim = Ref<Animation>(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<AnimationLibrary> al;
library_name = library->get_item_metadata(library->get_selected());
Expand Down
1 change: 1 addition & 0 deletions modules/fbx/fbx_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,7 @@ void FBXDocument::_import_animation(Ref<FBXState> p_state, AnimationPlayer *p_an
Ref<Animation> 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);
Expand Down
1 change: 1 addition & 0 deletions modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5881,6 +5881,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_
Ref<Animation> 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);
Expand Down
2 changes: 1 addition & 1 deletion scene/resources/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class Animation : public Resource {
_FORCE_INLINE_ void _track_get_key_indices_in_range(const Vector<T> &p_array, double from_time, double to_time, List<int> *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);
Expand Down
2 changes: 1 addition & 1 deletion tests/scene/test_animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TEST_CASE("[Animation] Empty animation getters") {
const Ref<Animation> 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") {
Expand Down

0 comments on commit bb9674c

Please sign in to comment.