Skip to content

Instantly share code, notes, and snippets.

@hyperlogic
Last active October 28, 2019 17:58
Show Gist options
  • Save hyperlogic/142d319a6de61fbe89731fc1f3754c3b to your computer and use it in GitHub Desktop.
Save hyperlogic/142d319a6de61fbe89731fc1f3754c3b to your computer and use it in GitHub Desktop.
//
// blendshapetest-agent-client.js
//
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
(function() { // BEGIN LOCAL_SCOPE
var TABLET_BUTTON_NAME = "BLENDSHAPE";
var HTML_URL = "https://hifi-public.s3.amazonaws.com/tony/html/blendshapetest_arkit.html";
var BLENDSHAPETEST_CHANNEL = "com.highfidelity.blendshapetest";
var IS_LOCAL = false;
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var tabletButton = tablet.addButton({
text: TABLET_BUTTON_NAME,
icon: "https://s3.amazonaws.com/hifi-public/tony/icons/tpose-i.svg",
activeIcon: "https://s3.amazonaws.com/hifi-public/tony/icons/tpose-a.svg"
});
tabletButton.clicked.connect(function () {
if (shown) {
tablet.gotoHomeScreen();
} else {
tablet.gotoWebScreen(HTML_URL);
}
});
var shown = false;
function onScreenChanged(type, url) {
if (type === "Web" && url === HTML_URL) {
tabletButton.editProperties({isActive: true});
if (!shown) {
// hook up to event bridge
tablet.webEventReceived.connect(onWebEventReceived);
}
shown = true;
} else {
tabletButton.editProperties({isActive: false});
if (shown) {
// disconnect from event bridge
tablet.webEventReceived.disconnect(onWebEventReceived);
}
shown = false;
}
}
tablet.screenChanged.connect(onScreenChanged);
function onWebEventReceived(msg) {
if (IS_LOCAL) {
if (msg.name === "hasScriptedBlendshapes") {
MyAvatar.hasScriptedBlendshapes = (msg.value === "on");
} else if (msg.name === "hasProceduralBlinkFaceMovement") {
MyAvatar.hasProceduralBlinkFaceMovement = (msg.value === "on");
} else if (msg.name === "hasProceduralEyeFaceMovement") {
MyAvatar.hasProceduralEyeFaceMovement = (msg.value === "on");
} else if (msg.name === "hasAudioEnabledFaceMovement") {
MyAvatar.hasAudioEnabledFaceMovement = (msg.value === "on");
} else {
MyAvatar.setBlendshape(msg.name, parseInt(msg.value, 10) / 100);
}
} else {
Messages.sendMessage(BLENDSHAPETEST_CHANNEL, JSON.stringify(msg));
}
}
Script.scriptEnding.connect(function () {
tablet.removeButton(tabletButton);
if (shown) {
tablet.webEventReceived.disconnect(onWebEventReceived);
tablet.gotoHomeScreen();
}
tablet.screenChanged.disconnect(onScreenChanged);
});
}()); // END LOCAL_SCOPE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment