Skip to content

Commit 55979d9

Browse files
committed
Properly reverse and cross-fade animations in hand-controls component
1 parent 96b6f46 commit 55979d9

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

‎src/components/hand-controls.js‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports.Component = registerComponent('hand-controls', {
5858
var self = this;
5959
var el = this.el;
6060
// Current pose.
61-
this.gesture = ANIMATIONS.open;
61+
this.gesture = undefined;
6262
// Active buttons populated by events provided by the attached controls.
6363
this.pressedButtons = {};
6464
this.touchedButtons = {};
@@ -360,34 +360,37 @@ module.exports.Component = registerComponent('hand-controls', {
360360

361361
if (!mesh) { return; }
362362

363-
// Stop all current animations.
364-
mesh.mixer.stopAllAction();
365-
366363
// Grab clip action.
367364
clip = this.getClip(gesture);
368365
toAction = mesh.mixer.clipAction(clip);
366+
367+
// Reverse from gesture to no gesture.
368+
if (reverse) {
369+
toAction.paused = false;
370+
toAction.timeScale = -1;
371+
return;
372+
}
373+
369374
toAction.clampWhenFinished = true;
370-
toAction.loop = THREE.LoopRepeat;
375+
toAction.loop = THREE.LoopOnce;
371376
toAction.repetitions = 0;
372-
toAction.timeScale = reverse ? -1 : 1;
373-
toAction.time = reverse ? clip.duration : 0;
377+
toAction.timeScale = 1;
378+
toAction.time = 0;
374379
toAction.weight = 1;
375380

376-
// No gesture to gesture or gesture to no gesture.
377-
if (!lastGesture || gesture === lastGesture) {
378-
// Stop all current animations.
379-
mesh.mixer.stopAllAction();
381+
// No gesture to gesture.
382+
if (!lastGesture) {
380383
// Play animation.
384+
mesh.mixer.stopAllAction();
381385
toAction.play();
382386
return;
383387
}
384388

385389
// Animate or crossfade from gesture to gesture.
386390
clip = this.getClip(lastGesture);
387-
fromAction = mesh.mixer.clipAction(clip);
388-
fromAction.weight = 0.15;
389-
fromAction.play();
391+
toAction.reset();
390392
toAction.play();
393+
fromAction = mesh.mixer.clipAction(clip);
391394
fromAction.crossFadeTo(toAction, 0.15, true);
392395
}
393396
});

0 commit comments

Comments
 (0)