{"action":"created","comment":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/43919494","id":43919494,"diff_hunk":"@@ -0,0 +1,113 @@\n+\"use strict\";\n+/*jslint vars: true, plusplus: true*/\n+/*global HMD, AudioDevice, MyAvatar, Controller, Script, Overlays, print*/\n+//\n+//  away.js\n+//  examples\n+//\n+//  Created by Howard Stearns 11/3/15\n+//  Copyright 2015 High Fidelity, Inc.\n+//\n+//  Distributed under the Apache License, Version 2.0.\n+//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html\n+//\n+// Goes into \"paused\" when the '.' key (and automatically when started in HMD), and normal when pressing any key.\n+// See MAIN CONTROL, below, for what \"paused\" actually does.\n+\n+var IK_WINDOW_AFTER_GOING_ACTIVE = 3000; // milliseconds\n+var OVERLAY_DATA = {\n+    text: \"Paused:\\npress any key to continue\",\n+    font: {size: 75},\n+    color: {red: 200, green: 255, blue: 255},\n+    alpha: 0.9\n+};\n+\n+// ANIMATION\n+// We currently don't have play/stopAnimation integrated with the animation graph, but we can get the same effect\n+// using an animation graph with a state that we turn on and off through the animation var defined with that state.\n+var awayAnimationHandlerId, activeAnimationHandlerId, stopper;\n+function playAwayAnimation() {\n+    function animateAway() {\n+        return {isAway: true, isNotAway: false, isNotMoving: false, ikOverlayAlpha: 0.0};\n+    }\n+    if (stopper) {\n+\tScript.clearTimeout(stopper);\n+\tMyAvatar.removeAnimationStateHandler(activeAnimationHandlerId); // do it now, before making new assignment\n+    }\n+    awayAnimationHandlerId = MyAvatar.addAnimationStateHandler(animateAway, null);\n+}\n+function stopAwayAnimation() {\n+    MyAvatar.removeAnimationStateHandler(awayAnimationHandlerId);\n+    if (stopper) { print('WARNING: unexpected double stop'); return; }\n+    // How do we know when to turn ikOverlayAlpha back on?\n+    // 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.\n+    // (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\n+    //  want to track the standing up animation.)\n+    // Our standard anim graph flips 'awayOutroOnDone' for one frame, but it's a trigger (not an animVar) and other folks might use different graphs.\n+    // So... Just give us a fixed amount of time to be done with animation, before we turn ik back on.\n+    var backToNormal = false;\n+    stopper = Script.setTimeout(function () {\n+\tbackToNormal = true;\n+\tstopper = false;\n+    }, IK_WINDOW_AFTER_GOING_ACTIVE);\n+    function animateActive(state) {\n+\tif (state.ikOverlayAlpha) {\n+\t    // Once the right state gets reflected back to us, we don't need the hander any more.\n+\t    // But we are locked against handler changes during the execution of a handler, so remove asynchronously.\n+\t    Script.setTimeout(function () { MyAvatar.removeAnimationStateHandler(activeAnimationHandlerId); }, 0);\n+\t}\n+\t// 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.\n+        return {isAway: false, isNotAway: true, ikOverlayAlpha: backToNormal ? 1.0 : 0.0}; // IWBNI we had a way of deleting an anim var.\n+    }\n+    activeAnimationHandlerId = MyAvatar.addAnimationStateHandler(animateActive, ['isAway', 'isNotAway', 'isNotMoving', 'ikOverlayAlpha']);\n+}\n+\n+// OVERLAY\n+var overlay = Overlays.addOverlay(\"text\", OVERLAY_DATA);\n+function showOverlay() {\n+    var screen = Controller.getViewportDimensions();\n+    Overlays.editOverlay(overlay, {visible: true, x: screen.x / 4, y: screen.y / 4});\n+}\n+function hideOverlay() {\n+    Overlays.editOverlay(overlay, {visible: false});\n+}\n+hideOverlay();\n+\n+\n+// MAIN CONTROL\n+var wasMuted, isAway;\n+function goAway(event) {\n+    if (isAway || event.isAutoRepeat) { // isAutoRepeat is true when held down (or when Windows feels like it)","path":"examples/away.js","position":80,"original_position":80,"commit_id":"4bf98613505631009bb9b799d11d81bc9f3d3fa9","original_commit_id":"4bf98613505631009bb9b799d11d81bc9f3d3fa9","user":{"login":"hyperlogic","id":20499,"avatar_url":"https://avatars.githubusercontent.com/u/20499?v=3","gravatar_id":"","url":"https://api.github.com/users/hyperlogic","html_url":"https://github.com/hyperlogic","followers_url":"https://api.github.com/users/hyperlogic/followers","following_url":"https://api.github.com/users/hyperlogic/following{/other_user}","gists_url":"https://api.github.com/users/hyperlogic/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperlogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperlogic/subscriptions","organizations_url":"https://api.github.com/users/hyperlogic/orgs","repos_url":"https://api.github.com/users/hyperlogic/repos","events_url":"https://api.github.com/users/hyperlogic/events{/privacy}","received_events_url":"https://api.github.com/users/hyperlogic/received_events","type":"User","site_admin":false},"body":"This check is duplicated on line 94 as well, do we need to check twice?","created_at":"2015-11-04T18:37:23Z","updated_at":"2015-11-04T18:37:23Z","html_url":"https://github.com/highfidelity/hifi/pull/6284#discussion_r43919494","pull_request_url":"https://api.github.com/repos/highfidelity/hifi/pulls/6284","_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/43919494"},"html":{"href":"https://github.com/highfidelity/hifi/pull/6284#discussion_r43919494"},"pull_request":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6284"}}},"pull_request":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/6284","id":49519245,"html_url":"https://github.com/highfidelity/hifi/pull/6284","diff_url":"https://github.com/highfidelity/hifi/pull/6284.diff","patch_url":"https://github.com/highfidelity/hifi/pull/6284.patch","issue_url":"https://api.github.com/repos/highfidelity/hifi/issues/6284","number":6284,"state":"open","locked":false,"title":"Away/Pause","user":{"login":"howard-stearns","id":7015115,"avatar_url":"https://avatars.githubusercontent.com/u/7015115?v=3","gravatar_id":"","url":"https://api.github.com/users/howard-stearns","html_url":"https://github.com/howard-stearns","followers_url":"https://api.github.com/users/howard-stearns/followers","following_url":"https://api.github.com/users/howard-stearns/following{/other_user}","gists_url":"https://api.github.com/users/howard-stearns/gists{/gist_id}","starred_url":"https://api.github.com/users/howard-stearns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howard-stearns/subscriptions","organizations_url":"https://api.github.com/users/howard-stearns/orgs","repos_url":"https://api.github.com/users/howard-stearns/repos","events_url":"https://api.github.com/users/howard-stearns/events{/privacy}","received_events_url":"https://api.github.com/users/howard-stearns/received_events","type":"User","site_admin":false},"body":"Adds a default script (away.js), which enters pause mode when you press the \".\" key (and automatically when starting in HMD), and goes active when pressing any key:\r\n - Displays \"Away\" for just you.\r\n - Make your avatar invisible to just you (regardless of first/third person).\r\n - Shows a paused avatar animation to everyone else (currently \"takes a knee\")\r\n - Mutes microphone.\r\n - Turns off ik, so that the avatar seen by others isn't affected by HMD, hand controlers, etc. -- even during the time one is \"coming back to life\" in the animation.\r\n\r\nAlso fixes an animation bug in which non-looping/triggering animations were not respecting start frame (and we were not setting the right start frame for finger pointing \"outro\").","created_at":"2015-11-03T04:47:48Z","updated_at":"2015-11-04T18:37:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"54fc1c4739d9656fa788950e3ca111762bfb88be","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/highfidelity/hifi/pulls/6284/commits","review_comments_url":"https://api.github.com/repos/highfidelity/hifi/pulls/6284/comments","review_comment_url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/highfidelity/hifi/issues/6284/comments","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/4bf98613505631009bb9b799d11d81bc9f3d3fa9","head":{"label":"howard-stearns:away","ref":"away","sha":"4bf98613505631009bb9b799d11d81bc9f3d3fa9","user":{"login":"howard-stearns","id":7015115,"avatar_url":"https://avatars.githubusercontent.com/u/7015115?v=3","gravatar_id":"","url":"https://api.github.com/users/howard-stearns","html_url":"https://github.com/howard-stearns","followers_url":"https://api.github.com/users/howard-stearns/followers","following_url":"https://api.github.com/users/howard-stearns/following{/other_user}","gists_url":"https://api.github.com/users/howard-stearns/gists{/gist_id}","starred_url":"https://api.github.com/users/howard-stearns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howard-stearns/subscriptions","organizations_url":"https://api.github.com/users/howard-stearns/orgs","repos_url":"https://api.github.com/users/howard-stearns/repos","events_url":"https://api.github.com/users/howard-stearns/events{/privacy}","received_events_url":"https://api.github.com/users/howard-stearns/received_events","type":"User","site_admin":false},"repo":{"id":34746667,"name":"hifi","full_name":"howard-stearns/hifi","owner":{"login":"howard-stearns","id":7015115,"avatar_url":"https://avatars.githubusercontent.com/u/7015115?v=3","gravatar_id":"","url":"https://api.github.com/users/howard-stearns","html_url":"https://github.com/howard-stearns","followers_url":"https://api.github.com/users/howard-stearns/followers","following_url":"https://api.github.com/users/howard-stearns/following{/other_user}","gists_url":"https://api.github.com/users/howard-stearns/gists{/gist_id}","starred_url":"https://api.github.com/users/howard-stearns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howard-stearns/subscriptions","organizations_url":"https://api.github.com/users/howard-stearns/orgs","repos_url":"https://api.github.com/users/howard-stearns/repos","events_url":"https://api.github.com/users/howard-stearns/events{/privacy}","received_events_url":"https://api.github.com/users/howard-stearns/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/howard-stearns/hifi","description":"Open source software for shared virtual worlds using HMDs and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.com/jobs  Documentation at http://docs.highfidelity.com  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":true,"url":"https://api.github.com/repos/howard-stearns/hifi","forks_url":"https://api.github.com/repos/howard-stearns/hifi/forks","keys_url":"https://api.github.com/repos/howard-stearns/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/howard-stearns/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/howard-stearns/hifi/teams","hooks_url":"https://api.github.com/repos/howard-stearns/hifi/hooks","issue_events_url":"https://api.github.com/repos/howard-stearns/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/howard-stearns/hifi/events","assignees_url":"https://api.github.com/repos/howard-stearns/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/howard-stearns/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/howard-stearns/hifi/tags","blobs_url":"https://api.github.com/repos/howard-stearns/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/howard-stearns/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/howard-stearns/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/howard-stearns/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/howard-stearns/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/howard-stearns/hifi/languages","stargazers_url":"https://api.github.com/repos/howard-stearns/hifi/stargazers","contributors_url":"https://api.github.com/repos/howard-stearns/hifi/contributors","subscribers_url":"https://api.github.com/repos/howard-stearns/hifi/subscribers","subscription_url":"https://api.github.com/repos/howard-stearns/hifi/subscription","commits_url":"https://api.github.com/repos/howard-stearns/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/howard-stearns/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/howard-stearns/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/howard-stearns/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/howard-stearns/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/howard-stearns/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/howard-stearns/hifi/merges","archive_url":"https://api.github.com/repos/howard-stearns/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/howard-stearns/hifi/downloads","issues_url":"https://api.github.com/repos/howard-stearns/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/howard-stearns/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/howard-stearns/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/howard-stearns/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/howard-stearns/hifi/labels{/name}","releases_url":"https://api.github.com/repos/howard-stearns/hifi/releases{/id}","created_at":"2015-04-28T17:54:06Z","updated_at":"2015-04-29T18:26:52Z","pushed_at":"2015-11-03T23:36:32Z","git_url":"git://github.com/howard-stearns/hifi.git","ssh_url":"git@github.com:howard-stearns/hifi.git","clone_url":"https://github.com/howard-stearns/hifi.git","svn_url":"https://github.com/howard-stearns/hifi","homepage":"","size":182426,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"highfidelity:master","ref":"master","sha":"192e4c8185337030a635687e5904fae60a0c61b7","user":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"repo":{"id":5372872,"name":"hifi","full_name":"highfidelity/hifi","owner":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/highfidelity/hifi","description":"Open source software for shared virtual worlds using HMDs and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.com/jobs  Documentation at http://docs.highfidelity.com  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":false,"url":"https://api.github.com/repos/highfidelity/hifi","forks_url":"https://api.github.com/repos/highfidelity/hifi/forks","keys_url":"https://api.github.com/repos/highfidelity/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/highfidelity/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/highfidelity/hifi/teams","hooks_url":"https://api.github.com/repos/highfidelity/hifi/hooks","issue_events_url":"https://api.github.com/repos/highfidelity/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/highfidelity/hifi/events","assignees_url":"https://api.github.com/repos/highfidelity/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/highfidelity/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/highfidelity/hifi/tags","blobs_url":"https://api.github.com/repos/highfidelity/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/highfidelity/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/highfidelity/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/highfidelity/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/highfidelity/hifi/languages","stargazers_url":"https://api.github.com/repos/highfidelity/hifi/stargazers","contributors_url":"https://api.github.com/repos/highfidelity/hifi/contributors","subscribers_url":"https://api.github.com/repos/highfidelity/hifi/subscribers","subscription_url":"https://api.github.com/repos/highfidelity/hifi/subscription","commits_url":"https://api.github.com/repos/highfidelity/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/highfidelity/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/highfidelity/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/highfidelity/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/highfidelity/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/highfidelity/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/highfidelity/hifi/merges","archive_url":"https://api.github.com/repos/highfidelity/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/highfidelity/hifi/downloads","issues_url":"https://api.github.com/repos/highfidelity/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/highfidelity/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/highfidelity/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/highfidelity/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/highfidelity/hifi/labels{/name}","releases_url":"https://api.github.com/repos/highfidelity/hifi/releases{/id}","created_at":"2012-08-10T18:26:22Z","updated_at":"2015-11-04T12:13:55Z","pushed_at":"2015-11-04T18:26:58Z","git_url":"git://github.com/highfidelity/hifi.git","ssh_url":"git@github.com:highfidelity/hifi.git","clone_url":"https://github.com/highfidelity/hifi.git","svn_url":"https://github.com/highfidelity/hifi","homepage":"","size":253631,"stargazers_count":322,"watchers_count":322,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":186,"mirror_url":null,"open_issues_count":60,"forks":186,"open_issues":60,"watchers":322,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6284"},"html":{"href":"https://github.com/highfidelity/hifi/pull/6284"},"issue":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/6284"},"comments":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/6284/comments"},"review_comments":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6284/comments"},"review_comment":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/6284/commits"},"statuses":{"href":"https://api.github.com/repos/highfidelity/hifi/statuses/4bf98613505631009bb9b799d11d81bc9f3d3fa9"}}}}