mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:21:16 +02:00
commit
b6b596b8af
4 changed files with 210 additions and 12 deletions
129
examples/away.js
Normal file
129
examples/away.js
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
"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.
|
||||||
|
|
||||||
|
var IK_WINDOW_AFTER_GOING_ACTIVE = 3000; // milliseconds
|
||||||
|
var OVERLAY_DATA = {
|
||||||
|
text: "Paused:\npress any key to continue",
|
||||||
|
font: {size: 75},
|
||||||
|
color: {red: 200, green: 255, blue: 255},
|
||||||
|
alpha: 0.9
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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, stopper;
|
||||||
|
function playAwayAnimation() {
|
||||||
|
function animateAway() {
|
||||||
|
return {isAway: true, isNotAway: false, isNotMoving: false, ikOverlayAlpha: 0.0};
|
||||||
|
}
|
||||||
|
if (stopper) {
|
||||||
|
Script.clearTimeout(stopper);
|
||||||
|
stopper = false;
|
||||||
|
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.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', 'isNotAway', 'isNotMoving', 'ikOverlayAlpha']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// OVERLAY
|
||||||
|
var overlay = Overlays.addOverlay("text", OVERLAY_DATA);
|
||||||
|
function showOverlay() {
|
||||||
|
var screen = Controller.getViewportDimensions();
|
||||||
|
Overlays.editOverlay(overlay, {visible: true, x: screen.x / 4, y: screen.y / 4});
|
||||||
|
}
|
||||||
|
function hideOverlay() {
|
||||||
|
Overlays.editOverlay(overlay, {visible: false});
|
||||||
|
}
|
||||||
|
hideOverlay();
|
||||||
|
|
||||||
|
|
||||||
|
// MAIN CONTROL
|
||||||
|
var wasMuted, isAway;
|
||||||
|
function goAway() {
|
||||||
|
if (isAway) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isAway = true;
|
||||||
|
print('going "away"');
|
||||||
|
wasMuted = AudioDevice.getMuted();
|
||||||
|
if (!wasMuted) {
|
||||||
|
AudioDevice.toggleMute();
|
||||||
|
}
|
||||||
|
MyAvatar.setEnableMeshVisible(false); // just for our own display, without changing point of view
|
||||||
|
playAwayAnimation(); // animation is still seen by others
|
||||||
|
showOverlay();
|
||||||
|
}
|
||||||
|
function goActive() {
|
||||||
|
if (!isAway) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isAway = false;
|
||||||
|
print('going "active"');
|
||||||
|
if (!wasMuted) {
|
||||||
|
AudioDevice.toggleMute();
|
||||||
|
}
|
||||||
|
MyAvatar.setEnableMeshVisible(true); // IWBNI we respected Developer->Avatar->Draw Mesh setting.
|
||||||
|
stopAwayAnimation();
|
||||||
|
hideOverlay();
|
||||||
|
}
|
||||||
|
Script.scriptEnding.connect(goActive);
|
||||||
|
Controller.keyPressEvent.connect(function (event) {
|
||||||
|
if (event.isAutoRepeat) { // isAutoRepeat is true when held down (or when Windows feels like it)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isAway && (event.text === '.')) {
|
||||||
|
goAway();
|
||||||
|
} else {
|
||||||
|
goActive();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var wasHmdActive = false;
|
||||||
|
Script.update.connect(function () {
|
||||||
|
if (HMD.active !== wasHmdActive) {
|
||||||
|
wasHmdActive = !wasHmdActive;
|
||||||
|
if (wasHmdActive) {
|
||||||
|
goAway();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
|
@ -8,6 +8,7 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
Script.load("away.js");
|
||||||
Script.load("progress.js");
|
Script.load("progress.js");
|
||||||
Script.load("edit.js");
|
Script.load("edit.js");
|
||||||
Script.load("selectAudioDevice.js");
|
Script.load("selectAudioDevice.js");
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
"type": "overlay",
|
"type": "overlay",
|
||||||
"data": {
|
"data": {
|
||||||
"alpha": 1.0,
|
"alpha": 1.0,
|
||||||
|
"alphaVar": "ikOverlayAlpha",
|
||||||
"boneSet": "fullBody"
|
"boneSet": "fullBody"
|
||||||
},
|
},
|
||||||
"children": [
|
"children": [
|
||||||
|
@ -178,7 +179,7 @@
|
||||||
"type": "clip",
|
"type": "clip",
|
||||||
"data": {
|
"data": {
|
||||||
"url": "http://hifi-public.s3.amazonaws.com/ozan/anim/hand_anims/point_right_hand.fbx",
|
"url": "http://hifi-public.s3.amazonaws.com/ozan/anim/hand_anims/point_right_hand.fbx",
|
||||||
"startFrame": 0.0,
|
"startFrame": 12.0,
|
||||||
"endFrame": 65.0,
|
"endFrame": 65.0,
|
||||||
"timeScale": 1.0,
|
"timeScale": 1.0,
|
||||||
"loopFlag": false
|
"loopFlag": false
|
||||||
|
@ -327,7 +328,7 @@
|
||||||
"type": "clip",
|
"type": "clip",
|
||||||
"data": {
|
"data": {
|
||||||
"url": "http://hifi-public.s3.amazonaws.com/ozan/anim/hand_anims/point_left_hand.fbx",
|
"url": "http://hifi-public.s3.amazonaws.com/ozan/anim/hand_anims/point_left_hand.fbx",
|
||||||
"startFrame": 0.0,
|
"startFrame": 12.0,
|
||||||
"endFrame": 65.0,
|
"endFrame": 65.0,
|
||||||
"timeScale": 1.0,
|
"timeScale": 1.0,
|
||||||
"loopFlag": false
|
"loopFlag": false
|
||||||
|
@ -378,15 +379,16 @@
|
||||||
"states": [
|
"states": [
|
||||||
{
|
{
|
||||||
"id": "idle",
|
"id": "idle",
|
||||||
"interpTarget": 6,
|
"interpTarget": 15,
|
||||||
"interpDuration": 6,
|
"interpDuration": 15,
|
||||||
"transitions": [
|
"transitions": [
|
||||||
{ "var": "isMovingForward", "state": "walkFwd" },
|
{ "var": "isMovingForward", "state": "walkFwd" },
|
||||||
{ "var": "isMovingBackward", "state": "walkBwd" },
|
{ "var": "isMovingBackward", "state": "walkBwd" },
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" }
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
|
{ "var": "isAway", "state": "awayIntro" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -399,7 +401,8 @@
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" }
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
|
{ "var": "isAway", "state": "awayIntro" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -412,7 +415,8 @@
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" }
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
|
{ "var": "isAway", "state": "awayIntro" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -425,7 +429,8 @@
|
||||||
{ "var": "isMovingBackward", "state": "walkBwd" },
|
{ "var": "isMovingBackward", "state": "walkBwd" },
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" }
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
|
{ "var": "isAway", "state": "awayIntro" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -438,7 +443,8 @@
|
||||||
{ "var": "isMovingBackward", "state": "walkBwd" },
|
{ "var": "isMovingBackward", "state": "walkBwd" },
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" }
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
|
{ "var": "isAway", "state": "awayIntro" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -451,7 +457,8 @@
|
||||||
{ "var": "isMovingBackward", "state": "walkBwd" },
|
{ "var": "isMovingBackward", "state": "walkBwd" },
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" }
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
|
{ "var": "isAway", "state": "awayIntro" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -464,7 +471,32 @@
|
||||||
{ "var": "isMovingBackward", "state": "walkBwd" },
|
{ "var": "isMovingBackward", "state": "walkBwd" },
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" }
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
|
{ "var": "isAway", "state": "awayIntro" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "awayIntro",
|
||||||
|
"interpTarget": 30,
|
||||||
|
"interpDuration": 30,
|
||||||
|
"transitions": [
|
||||||
|
{ "var": "awayIntroOnDone", "state": "away"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "away",
|
||||||
|
"interpTarget": 3,
|
||||||
|
"interpDuration": 3,
|
||||||
|
"transitions": [
|
||||||
|
{ "var": "isNotAway", "state": "awayOutro" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "awayOutro",
|
||||||
|
"interpTarget": 3,
|
||||||
|
"interpDuration": 3,
|
||||||
|
"transitions": [
|
||||||
|
{ "var": "awayOutroOnDone", "state": "idle" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -704,6 +736,42 @@
|
||||||
"children": []
|
"children": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "awayIntro",
|
||||||
|
"type": "clip",
|
||||||
|
"data": {
|
||||||
|
"url": "https://hifi-public.s3.amazonaws.com/ozan/anim/kneel/kneel.fbx",
|
||||||
|
"startFrame": 0.0,
|
||||||
|
"endFrame": 83.0,
|
||||||
|
"timeScale": 1.0,
|
||||||
|
"loopFlag": false
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "away",
|
||||||
|
"type": "clip",
|
||||||
|
"data": {
|
||||||
|
"url": "https://hifi-public.s3.amazonaws.com/ozan/anim/kneel/kneel.fbx",
|
||||||
|
"startFrame": 83.0,
|
||||||
|
"endFrame": 84.0,
|
||||||
|
"timeScale": 1.0,
|
||||||
|
"loopFlag": true
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "awayOutro",
|
||||||
|
"type": "clip",
|
||||||
|
"data": {
|
||||||
|
"url": "https://hifi-public.s3.amazonaws.com/ozan/anim/kneel/kneel.fbx",
|
||||||
|
"startFrame": 84.0,
|
||||||
|
"endFrame": 167.0,
|
||||||
|
"timeScale": 1.0,
|
||||||
|
"loopFlag": false
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ void AnimClip::setCurrentFrameInternal(float frame) {
|
||||||
// because dt is 0, we should not encounter any triggers
|
// because dt is 0, we should not encounter any triggers
|
||||||
const float dt = 0.0f;
|
const float dt = 0.0f;
|
||||||
Triggers triggers;
|
Triggers triggers;
|
||||||
_frame = ::accumulateTime(_startFrame, _endFrame, _timeScale, frame, dt, _loopFlag, _id, triggers);
|
_frame = ::accumulateTime(_startFrame, _endFrame, _timeScale, frame + _startFrame, dt, _loopFlag, _id, triggers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimClip::copyFromNetworkAnim() {
|
void AnimClip::copyFromNetworkAnim() {
|
||||||
|
|
Loading…
Reference in a new issue