From 6770a9413b8a4ec58414054b24469e44b1334540 Mon Sep 17 00:00:00 2001 From: ArdaE Date: Thu, 18 Mar 2021 01:50:28 -0700 Subject: GLTF import: Prevent significant numerical errors in keyframe times Keyframe times shift slowly in imported animations, starting with a zero shift at the beginning and increasing and becoming erratic slowly farther into an animation, reaching significant levels at times after about 3 minutes into an animation. This commit fixes the issue by increasing the precision of the floating point numbers used for keyframe time calculations. Only the most significant cases that cause fast accumulation of errors over a short animation duration are fixed. Other cases that would have a marginal benefit from switching to double precision numbers are left for another PR/further analysis. Note that this change has no impact on the runtime performance of games/apps created using Godot. It only affects the GLTF importer. Fixes #47127. --- modules/gltf/gltf_document.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules/gltf') diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index caf8e3f48f..7ea0aa8ba2 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -5633,8 +5633,8 @@ void GLTFDocument::_import_animation(Ref state, AnimationPlayer *ap, animation->track_set_path(track_idx, node_path); //first determine animation length - const float increment = 1.0 / float(bake_fps); - float time = 0.0; + const double increment = 1.0 / bake_fps; + double time = 0.0; Vector3 base_pos; Quat base_rot; @@ -5724,8 +5724,8 @@ void GLTFDocument::_import_animation(Ref state, AnimationPlayer *ap, } } else { // CATMULLROMSPLINE or CUBIC_SPLINE have to be baked, apologies. - const float increment = 1.0 / float(bake_fps); - float time = 0.0; + const double increment = 1.0 / bake_fps; + double time = 0.0; bool last = false; while (true) { _interpolate_track(track.weight_tracks[i].times, track.weight_tracks[i].values, time, gltf_interp); -- cgit v1.2.3