Skip to content

Commit

Permalink
Wrap around catmull rom keyframes in loop, closes #1965
Browse files Browse the repository at this point in the history
Improve animation looping preview smoothness
  • Loading branch information
JannisX11 committed Apr 5, 2024
1 parent 9e68220 commit 6f06677
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
33 changes: 18 additions & 15 deletions js/animations/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,23 +549,24 @@ const Timeline = {
Timeline.loop()
},
loop() {
Animator.preview(true);
if (Animation.selected && Timeline.time < (Animation.selected.length||1e3)) {
if (!Animation.selected) return;

var new_time;
if (Animation.selected && Animation.selected.anim_time_update) {
var new_time = Animator.MolangParser.parse(Animation.selected.anim_time_update);
}
if (new_time == undefined || new_time <= Timeline.time) {
var new_time = Animator.MolangParser.parse('query.anim_time + query.delta_time')
}
let time = Timeline.time + (new_time - Timeline.time) * (Timeline.playback_speed/100)
if (Animation.selected.loop == 'hold') {
time = Math.clamp(time, 0, Animation.selected.length);
}
Timeline.last_frame_timecode = Date.now();
Timeline.setTime(time);
let max_length = Animation.selected.length || 1e3;
let new_time;
if (Animation.selected && Animation.selected.anim_time_update) {
new_time = Animator.MolangParser.parse(Animation.selected.anim_time_update);
}
if (new_time == undefined || new_time <= Timeline.time) {
new_time = Animator.MolangParser.parse('query.anim_time + query.delta_time')
}
let time = Timeline.time + (new_time - Timeline.time) * (Timeline.playback_speed/100)
if (Animation.selected.loop == 'hold') {
time = Math.clamp(time, 0, Animation.selected.length);
}
Timeline.last_frame_timecode = Date.now();

if (time < max_length) {
Timeline.setTime(time);
} else {
if (Animation.selected.loop == 'loop' || BarItems.looped_animation_playback.value) {
Timeline.setTime(0)
Expand All @@ -574,9 +575,11 @@ const Timeline = {
Animator.preview()
Timeline.pause()
} else if (Animation.selected.loop == 'hold') {
Timeline.setTime(max_length);
Timeline.pause()
}
}
Animator.preview(true);
},
pause() {
Animator.preview();
Expand Down
4 changes: 4 additions & 0 deletions js/animations/timeline_animators.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ class BoneAnimator extends GeneralAnimator {
let before_index = sorted.indexOf(before);
let before_plus = sorted[before_index-1];
let after_plus = sorted[before_index+2];
if (this.animation.loop == 'loop' && sorted.length >= 3) {
if (!before_plus) before_plus = sorted.at(-2);
if (!after_plus) after_plus = sorted[1];
}

return mapAxes(axis => before.getCatmullromLerp(before_plus, before, after, after_plus, axis, alpha));

Expand Down

0 comments on commit 6f06677

Please # to comment.