Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GltfLoader loses animation data #1813

Closed
stephengold opened this issue May 8, 2022 · 1 comment · Fixed by #1815
Closed

GltfLoader loses animation data #1813

stephengold opened this issue May 8, 2022 · 1 comment · Fixed by #1815
Assignees
Labels
bug Something that is supposed to work, but doesn't. More severe than a "defect".
Milestone

Comments

@stephengold
Copy link
Member

stephengold commented May 8, 2022

Forum thread: https://hub.jmonkeyengine.org/t/incomplete-animation/45558

I've tracked this down to the TrackData.update() method. For the "character.gltf" model's "stand" animation, the track for node 4 ("all") has 3 translation keyframes prior to TrackData.update() but only 1 keyframe after the invocation.

timeArrays.get(0) is rotation data, for which there is a single keyframe at t=0.
timeArrays.get(1) is translation data, for which there are 3 keyframes: at t=0, t=2.25, and t=4.25.

Those last 2 keyframes never get merged into the keyFrames list, so translation data is lost.

@stephengold stephengold added the bug Something that is supposed to work, but doesn't. More severe than a "defect". label May 8, 2022
@stephengold stephengold added this to the Future Release milestone May 8, 2022
@stephengold
Copy link
Member Author

"TrackData.java" implements a merge sort using spaghetti code with poor encapsulation. But in case nobody feels like rewriting it from scratch, here is a straightforward patch that I believe will solve this issue:

--- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/TrackData.java
+++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/TrackData.java
@@ -90,7 +90,14 @@
                         KeyFrame kf = keyFrames.get(j);
                         if (Float.floatToIntBits(kf.time) != Float.floatToIntBits(time)) {
                             if (time > kf.time) {
-                                continue;
+                                if (j < keyFrames.size() - 1) {
+                                    // Keep searching for the insertion point.
+                                    continue;
+                                }
+                                kf = new KeyFrame();
+                                kf.time = time;
+                                // Add kf after the last keyframe in the list.
+                                keyFrames.add(kf);
                             } else {
                                 kf = new KeyFrame();
                                 kf.time = time;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to work, but doesn't. More severe than a "defect".
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants