Repository navigation
Conversation
Frank3K
force-pushed
the
fix/restart-finished-appended-animation
branch
from
November 17, 2026 21:44
a443bda to
8d803b3
Compare
When an appended animation is appended again, appendAnimation() only called action.stop() if the action's time equaled the clip's duration. That check went wrong in two ways: - It ignored the direction. A reverse run finishes at time 0, so its action was never reset. three.js then kept the loop count of the previous run, and the next run with repetitions was cut short. - It undid the time option. The time was applied first, so with `time: duration` the check matched, and stop() moved the action back to 0. stop() also cancelled the fade and warp that were just applied. Instead, stop a finished or faded-out (disabled) action before applying the options. Stopping rather than only resetting it deactivates the action, so the new loop mode and repetitions are still applied. A finished action is paused and clamped at exactly 0 or the clip's duration. Paused alone is not enough: a warp to a time scale of 0 also pauses the action, mid-clip, and it should resume from there. This doesn't use !isRunning() either: that is also true for an action paused with a time scale of 0, which would then jump back to the start when it is resumed.
Frank3K
force-pushed
the
fix/restart-finished-appended-animation
branch
from
November 17, 2026 21:49
8d803b3 to
e23142f
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Appending an animation that has already finished is meant to restart it.
ModelScene.appendAnimation()only reset the action whenaction.time == duration, which goes wrong in two ways:timeScale) finishes at time 0, so the check doesn't match. three.js keeps the loop count of the finished run, so the next run withrepetitionsstops early. For example, after a reverse run withrepetitions: 2, a forward run withrepetitions: 2plays only once and dispatches noloopevent.timeoption is undone. The time is applied before the check. Withtimeat the clip's end (the way to start a one-shot reverse run at the end), the check matches andstop()moves the action back to 0, so the reverse run finishes on its first frame.stop()also cancels thefadeandwarpthat were just applied.Live demo: https://jsfiddle.net/kp6dj8hw/ (uses 4.4.0). Both scenarios fail there:
repetitions: 2after a reverse run (at 2× speed)loopevents, 919 ms (one pass)loopevent, ~1850 msThe "with this fix" numbers come from running the same page against a local build of this branch.
Fix
Before the options are applied, stop an action that has finished or was faded out by
detachAnimation()(disabled). model-viewer setsclampWhenFinished, so a finished action is paused at exactly 0 or the clip's duration. The new options then apply to a clean run, and the end-of-clipstop()is removed.It stops the action rather than only calling
reset():reset()leaves the action active in the mixer, so it would count as running and the new loop mode andrepetitionswould not be applied.It doesn't stop an action that was halted mid-clip, so that it can be resumed where it was. That means one paused with
timeScale: 0(which!action.isRunning()would have included), and one halted by a warp to 0, which three.js pauses without moving it to either end.Tests
animation-spec.ts: tests that use only the public API (appendAnimation()and theloop/finishedevents): one for each problem above, plus one checking that newrepetitionsare applied when a finished animation is appended again.ModelScene-spec.ts: tests that drive the mixer frame by frame. They cover a finished reverse run, thetimeoption, a faded-out animation, newrepetitionsfor a finished animation, and resuming an animation paused with a time scale of 0 or halted by a warp to 0.Without the fix, the five tests for the two problems fail in Chromium and WebKit; with it, all tests in both spec files pass in both browsers. I couldn't run Firefox locally (the browser failed to start).