From a7162eefbebbc550548f9eba209331643a7c0deb Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Tue, 3 Nov 2015 13:10:25 -0800 Subject: [PATCH 1/3] Add alphaVar for ik. --- .../resources/meshes/defaultAvatar_full/avatar-animation.json | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/resources/meshes/defaultAvatar_full/avatar-animation.json b/interface/resources/meshes/defaultAvatar_full/avatar-animation.json index 9398b94890..df8b9b16c8 100644 --- a/interface/resources/meshes/defaultAvatar_full/avatar-animation.json +++ b/interface/resources/meshes/defaultAvatar_full/avatar-animation.json @@ -5,6 +5,7 @@ "type": "overlay", "data": { "alpha": 1.0, + "alphaVar": "ikOverlayAlpha", "boneSet": "fullBody" }, "children": [ From fb4174b9a2753fbf280c6e59520264e360589bc5 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Tue, 3 Nov 2015 13:11:31 -0800 Subject: [PATCH 2/3] Control alphaVar, and deal with overlapping cycles. --- examples/away.js | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/examples/away.js b/examples/away.js index 9fd688dbb7..c183f236fd 100644 --- a/examples/away.js +++ b/examples/away.js @@ -5,6 +5,7 @@ // Goes into "paused" when the '.' key (and automatically when started in HMD), and normal when pressing any key. // See MAIN CONTROL, below, for what "paused" actually does. +var IK_WINDOW_AFTER_GOING_ACTIVE = 3000; // milliseconds var OVERLAY_DATA = { text: "Paused:\npress any key to continue", font: {size: 75}, @@ -15,23 +16,41 @@ var OVERLAY_DATA = { // ANIMATION // We currently don't have play/stopAnimation integrated with the animation graph, but we can get the same effect // using an animation graph with a state that we turn on and off through the animation var defined with that state. -var awayAnimationHandlerId, activeAnimationHandlerId; +var awayAnimationHandlerId, activeAnimationHandlerId, stopper; function playAwayAnimation() { function animateAway() { - return {isAway: true, isNotAway: false, isNotMoving: false}; + return {isAway: true, isNotAway: false, isNotMoving: false, ikOverlayAlpha: 0.0}; + } + if (stopper) { + Script.clearTimeout(stopper); + MyAvatar.removeAnimationStateHandler(activeAnimationHandlerId); // do it now, before making new assignment } awayAnimationHandlerId = MyAvatar.addAnimationStateHandler(animateAway, null); } function stopAwayAnimation() { MyAvatar.removeAnimationStateHandler(awayAnimationHandlerId); + if (stopper) { print('WARNING: unexpected double stop'); return; } + // How do we know when to turn ikOverlayAlpha back on? + // It cannot be as soon as we want to stop the away animation, because then things will look goofy as we come out of that animation. + // (Imagine an away animation that sits or kneels, and then stands back up when coming out of it. If head is at the HMD, then it won't + // want to track the standing up animation.) + // Our standard anim graph flips 'awayOutroOnDone' for one frame, but it's a trigger (not an animVar) and other folks might use different graphs. + // So... Just give us a fixed amount of time to be done with animation, before we turn ik back on. + var backToNormal = false; + stopper = Script.setTimeout(function () { + backToNormal = true; + stopper = false; + }, IK_WINDOW_AFTER_GOING_ACTIVE); function animateActive(state) { - if (!state.isAway) { // Once the right state gets reflected back to us, we don't need the hander any more. - // But we are locked against handler changes during the execution of a handler, so remove asynchronously. - Script.setTimeout(function () { MyAvatar.removeAnimationStateHandler(activeAnimationHandlerId); }, 0); - } - return {isAway: false, isNotAway: true}; // IWBNI we had a way of deleting an anim var. + if (state.ikOverlayAlpha) { + // Once the right state gets reflected back to us, we don't need the hander any more. + // But we are locked against handler changes during the execution of a handler, so remove asynchronously. + Script.setTimeout(function () { MyAvatar.removeAnimationStateHandler(activeAnimationHandlerId); }, 0); + } + // It might be cool to "come back to life" by fading the ik overlay back in over a short time. But let's see how this goes. + return {isAway: false, isNotAway: true, ikOverlayAlpha: backToNormal ? 1.0 : 0.0}; // IWBNI we had a way of deleting an anim var. } - activeAnimationHandlerId = MyAvatar.addAnimationStateHandler(animateActive, ['isAway']); + activeAnimationHandlerId = MyAvatar.addAnimationStateHandler(animateActive, ['isAway', 'isNotAway', 'isNotMoving', 'ikOverlayAlpha']); } // OVERLAY @@ -48,8 +67,8 @@ hideOverlay(); // MAIN CONTROL var wasMuted, isAway; -function goAway() { - if (isAway) { +function goAway(event) { + if (isAway || event.isAutoRepeat) { // isAutoRepeat is true when held down (or when Windows feels like it) return; } isAway = true; @@ -63,9 +82,9 @@ function goAway() { showOverlay(); } function goActive(event) { - if (!isAway) { + if (!isAway || event.isAutoRepeat) { if (event.text === '.') { - goAway(); + goAway(event); } return; } @@ -79,6 +98,7 @@ function goActive(event) { hideOverlay(); } Controller.keyPressEvent.connect(goActive); +Script.scriptEnding.connect(goActive); if (HMD.active) { - goAway(); + goAway({}); // give a dummy event object } From 4bf98613505631009bb9b799d11d81bc9f3d3fa9 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Tue, 3 Nov 2015 15:36:02 -0800 Subject: [PATCH 3/3] Forgot license header. --- examples/away.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/away.js b/examples/away.js index c183f236fd..dba26e0697 100644 --- a/examples/away.js +++ b/examples/away.js @@ -1,7 +1,16 @@ "use strict"; /*jslint vars: true, plusplus: true*/ /*global HMD, AudioDevice, MyAvatar, Controller, Script, Overlays, print*/ - +// +// away.js +// examples +// +// Created by Howard Stearns 11/3/15 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// // Goes into "paused" when the '.' key (and automatically when started in HMD), and normal when pressing any key. // See MAIN CONTROL, below, for what "paused" actually does.