diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 89d4c75ae4..71755e3abb 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -29,7 +29,8 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/notifications.js", "system/dialTone.js", "system/firstPersonHMD.js", - "system/tablet-ui/tabletUI.js" + "system/tablet-ui/tabletUI.js", + "system/emote.js" ]; var DEFAULT_SCRIPTS_SEPARATE = [ "system/controllers/controllerScripts.js" diff --git a/scripts/system/assets/animations/Cheering.fbx b/scripts/system/assets/animations/Cheering.fbx new file mode 100644 index 0000000000..7439c5f409 Binary files /dev/null and b/scripts/system/assets/animations/Cheering.fbx differ diff --git a/scripts/system/assets/animations/Clapping.fbx b/scripts/system/assets/animations/Clapping.fbx new file mode 100644 index 0000000000..10f3f5036d Binary files /dev/null and b/scripts/system/assets/animations/Clapping.fbx differ diff --git a/scripts/system/assets/animations/Crying.fbx b/scripts/system/assets/animations/Crying.fbx new file mode 100644 index 0000000000..5117a4156c Binary files /dev/null and b/scripts/system/assets/animations/Crying.fbx differ diff --git a/scripts/system/assets/animations/Dancing.fbx b/scripts/system/assets/animations/Dancing.fbx new file mode 100644 index 0000000000..405684f1d9 Binary files /dev/null and b/scripts/system/assets/animations/Dancing.fbx differ diff --git a/scripts/system/assets/animations/Fall.fbx b/scripts/system/assets/animations/Fall.fbx new file mode 100644 index 0000000000..b189cf40a2 Binary files /dev/null and b/scripts/system/assets/animations/Fall.fbx differ diff --git a/scripts/system/assets/animations/Pointing.fbx b/scripts/system/assets/animations/Pointing.fbx new file mode 100644 index 0000000000..b493d2e539 Binary files /dev/null and b/scripts/system/assets/animations/Pointing.fbx differ diff --git a/scripts/system/assets/animations/Surprised.fbx b/scripts/system/assets/animations/Surprised.fbx new file mode 100644 index 0000000000..9422e7730e Binary files /dev/null and b/scripts/system/assets/animations/Surprised.fbx differ diff --git a/scripts/system/assets/animations/Waving.fbx b/scripts/system/assets/animations/Waving.fbx new file mode 100644 index 0000000000..7a52a0f6ed Binary files /dev/null and b/scripts/system/assets/animations/Waving.fbx differ diff --git a/scripts/system/emote.js b/scripts/system/emote.js new file mode 100644 index 0000000000..30764514f1 --- /dev/null +++ b/scripts/system/emote.js @@ -0,0 +1,119 @@ +"use strict"; + +// +// emote.js +// scripts/system/ +// +// Created by Brad Hefta-Gaub on 7 Jan 2018 +// Copyright 2018 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 +// +/* globals Script, Tablet */ +/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */ + +(function() { // BEGIN LOCAL_SCOPE + + +var EMOTE_ANIMATIONS = ['Crying', 'Surprised', 'Dancing', 'Cheering', 'Waving', 'Fall', 'Pointing', 'Clapping']; +var ANIMATIONS = Array(); + + +EMOTE_ANIMATIONS.forEach(function (name) { + var animURL = Script.resolvePath("assets/animations/" + name + ".fbx"); + print(animURL); + var resource = AnimationCache.prefetch(animURL); + var animation = AnimationCache.getAnimation(animURL); + ANIMATIONS[name] = { url: animURL, animation: animation, resource: resource}; +}); + + +var EMOTE_APP_BASE = "html/EmoteApp.html"; +var EMOTE_APP_URL = Script.resolvePath(EMOTE_APP_BASE); + + +var onEmoteScreen = false; +var button; +var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + +var emoteLable = "EMOTE"; + +button = tablet.addButton({ + //icon: "icons/tablet-icons/emote.svg", + text: emoteLable, + sortOrder: 11 +}); + +var enabled = false; +function onClicked() { + if (onEmoteScreen) { + tablet.gotoHomeScreen(); + } else { + onEmoteScreen = true; + tablet.gotoWebScreen(EMOTE_APP_URL); + } +} + +function onScreenChanged(type, url) { + print("type:", type, "url:", url); + onEmoteScreen = type === "Web" && (url.indexOf(EMOTE_APP_BASE) == url.length - EMOTE_APP_BASE.length); + button.editProperties({ isActive: onEmoteScreen }); +} + +// Handle the events we're receiving from the web UI +function onWebEventReceived(event) { + print("emote.js received a web event: " + event); + + // Converts the event to a JavasScript Object + if (typeof event === "string") { + event = JSON.parse(event); + } + + if (event.type === "click") { + var emoteName = event.data; + print("emote.js received a click event for " + emoteName); + + print("ANIMATIONS[emoteName].resource.url:" + ANIMATIONS[emoteName].resource.url); + + + // ANIMATIONS[emoteName].animation.isLoaded + if (ANIMATIONS[emoteName].resource.state == 3) { + var frameCount = ANIMATIONS[emoteName].animation.frames.length; + print("the animation for " + emoteName + " is loaded, it has " + frameCount + " frames"); + var frameCount = ANIMATIONS[emoteName].animation.frames.length; + + var FPS = 30; + var MSEC_PER_SEC = 1000; + MyAvatar.overrideAnimation(ANIMATIONS[emoteName].url, FPS, false, 0, frameCount); + + var timeOut = MSEC_PER_SEC * frameCount / FPS; + Script.setTimeout(function () { + MyAvatar.restoreAnimation(); + }, timeOut); + + + } else { + print("the animation for " + emoteName + " is in state:" + ANIMATIONS[emoteName].resource.state); + } + } +} + +button.clicked.connect(onClicked); +tablet.screenChanged.connect(onScreenChanged); +tablet.webEventReceived.connect(onWebEventReceived); + + +Script.scriptEnding.connect(function () { + if (onEmoteScreen) { + tablet.gotoHomeScreen(); + } + button.clicked.disconnect(onClicked); + tablet.screenChanged.disconnect(onScreenChanged); + if (tablet) { + tablet.removeButton(button); + } +}); + + +}()); // END LOCAL_SCOPE diff --git a/scripts/system/html/EmoteApp.html b/scripts/system/html/EmoteApp.html new file mode 100644 index 0000000000..30ef3e17a1 --- /dev/null +++ b/scripts/system/html/EmoteApp.html @@ -0,0 +1,136 @@ + + + + Emote App + + + + + + +
+

Emote App

+
+
+

Click an emotion to Emote:

+

+

+

+

+

+

+

+

+
+ + + + + \ No newline at end of file