Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Properly reverse and cross-fade animations in hand-controls component
  • Loading branch information
mrxz committed Jun 13, 2023
commit f9370e06309c0073043160ed7f1e0ff28c3168e7
31 changes: 16 additions & 15 deletions src/components/hand-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ module.exports.Component = registerComponent('hand-controls', {
init: function () {
var self = this;
var el = this.el;
// Current pose.
this.gesture = ANIMATIONS.open;
// Active buttons populated by events provided by the attached controls.
this.pressedButtons = {};
this.touchedButtons = {};
Expand Down Expand Up @@ -360,34 +358,37 @@ module.exports.Component = registerComponent('hand-controls', {

if (!mesh) { return; }

// Stop all current animations.
mesh.mixer.stopAllAction();

// Grab clip action.
clip = this.getClip(gesture);
toAction = mesh.mixer.clipAction(clip);

// Reverse from gesture to no gesture.
if (reverse) {
toAction.paused = false;
toAction.timeScale = -1;
return;
}

toAction.clampWhenFinished = true;
toAction.loop = THREE.LoopRepeat;
toAction.loop = THREE.LoopOnce;
toAction.repetitions = 0;
toAction.timeScale = reverse ? -1 : 1;
toAction.time = reverse ? clip.duration : 0;
toAction.timeScale = 1;
toAction.time = 0;
toAction.weight = 1;

// No gesture to gesture or gesture to no gesture.
if (!lastGesture || gesture === lastGesture) {
// Stop all current animations.
mesh.mixer.stopAllAction();
// No gesture to gesture.
if (!lastGesture) {
// Play animation.
mesh.mixer.stopAllAction();
toAction.play();
return;
}

// Animate or crossfade from gesture to gesture.
clip = this.getClip(lastGesture);
fromAction = mesh.mixer.clipAction(clip);
fromAction.weight = 0.15;
fromAction.play();
toAction.reset();
toAction.play();
fromAction = mesh.mixer.clipAction(clip);
fromAction.crossFadeTo(toAction, 0.15, true);
}
});
Expand Down