glTF: Fix import of animations with INTERPOLATION_LINEAR

Bug found thanks to GCC 8's -Wduplicated-branches.
Slight refactor for readability.

(cherry picked from commit b486f5dde0)
This commit is contained in:
Rémi Verschelde 2019-06-15 15:16:11 +02:00
parent 8148732bd1
commit cfd9121fa6
1 changed files with 7 additions and 6 deletions

View File

@ -2087,22 +2087,23 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye
animation->add_track(Animation::TYPE_VALUE); animation->add_track(Animation::TYPE_VALUE);
animation->track_set_path(track_idx, node_path); animation->track_set_path(track_idx, node_path);
if (track.weight_tracks[i].interpolation <= GLTFAnimation::INTERP_STEP) { // Only LINEAR and STEP (NEAREST) can be supported out of the box by Godot's Animation,
animation->track_set_interpolation_type(track_idx, track.weight_tracks[i].interpolation == GLTFAnimation::INTERP_STEP ? Animation::INTERPOLATION_NEAREST : Animation::INTERPOLATION_NEAREST); // the other modes have to be baked.
GLTFAnimation::Interpolation gltf_interp = track.weight_tracks[i].interpolation;
if (gltf_interp == GLTFAnimation::INTERP_LINEAR || gltf_interp == GLTFAnimation::INTERP_STEP) {
animation->track_set_interpolation_type(track_idx, gltf_interp == GLTFAnimation::INTERP_STEP ? Animation::INTERPOLATION_NEAREST : Animation::INTERPOLATION_LINEAR);
for (int j = 0; j < track.weight_tracks[i].times.size(); j++) { for (int j = 0; j < track.weight_tracks[i].times.size(); j++) {
float t = track.weight_tracks[i].times[j]; float t = track.weight_tracks[i].times[j];
float w = track.weight_tracks[i].values[j]; float w = track.weight_tracks[i].values[j];
animation->track_insert_key(track_idx, t, w); animation->track_insert_key(track_idx, t, w);
} }
} else { } else {
//must bake, apologies. // CATMULLROMSPLINE or CUBIC_SPLINE have to be baked, apologies.
float increment = 1.0 / float(bake_fps); float increment = 1.0 / float(bake_fps);
float time = 0.0; float time = 0.0;
bool last = false; bool last = false;
while (true) { while (true) {
_interpolate_track<float>(track.weight_tracks[i].times, track.weight_tracks[i].values, time, gltf_interp);
_interpolate_track<float>(track.weight_tracks[i].times, track.weight_tracks[i].values, time, track.weight_tracks[i].interpolation);
if (last) { if (last) {
break; break;
} }