From 6ba8d1ef7293d779dab533cc39dcd7a1417ce6f3 Mon Sep 17 00:00:00 2001 From: ArmoredDragon <43324896+Armored-Dragon@users.noreply.github.com> Date: Sat, 19 Aug 2023 00:22:45 -0500 Subject: [PATCH 1/4] Init POC --- .../characterSmoothing/AccelerationFilter.js | 240 ++++++++++++++++++ .../characterSmoothing/index.html | 65 +++++ 2 files changed, 305 insertions(+) create mode 100755 scripts/communityScripts/characterSmoothing/AccelerationFilter.js create mode 100755 scripts/communityScripts/characterSmoothing/index.html diff --git a/scripts/communityScripts/characterSmoothing/AccelerationFilter.js b/scripts/communityScripts/characterSmoothing/AccelerationFilter.js new file mode 100755 index 0000000000..fc326bcf66 --- /dev/null +++ b/scripts/communityScripts/characterSmoothing/AccelerationFilter.js @@ -0,0 +1,240 @@ +var LEFT_HAND_INDEX = 0; +var RIGHT_HAND_INDEX = 1; +var LEFT_FOOT_INDEX = 2; +var RIGHT_FOOT_INDEX = 3; +var HIPS_INDEX = 4; +var SPINE2_INDEX = 5; + +var HAND_SMOOTHING_TRANSLATION = 0.3; +var HAND_SMOOTHING_ROTATION = 0.15; +var FOOT_SMOOTHING_TRANSLATION = 0.3; +var FOOT_SMOOTHING_ROTATION = 0.15; +var TORSO_SMOOTHING_TRANSLATION = 0.3; +var TORSO_SMOOTHING_ROTATION = 0.16; + +var mappingJson = { + name: "com.highfidelity.testing.exponentialFilterApp", + channels: [ + { + from: "Standard.LeftHand", + to: "Actions.LeftHand", + filters: [ + { + type: "exponentialSmoothing", + translation: HAND_SMOOTHING_TRANSLATION, + rotation: HAND_SMOOTHING_ROTATION + } + ] + }, + { + from: "Standard.RightHand", + to: "Actions.RightHand", + filters: [ + { + type: "exponentialSmoothing", + translation: HAND_SMOOTHING_TRANSLATION, + rotation: HAND_SMOOTHING_ROTATION + } + ] + }, + { + from: "Standard.LeftFoot", + to: "Actions.LeftFoot", + filters: [ + { + type: "exponentialSmoothing", + translation: FOOT_SMOOTHING_TRANSLATION, + rotation: FOOT_SMOOTHING_ROTATION + } + ] + }, + { + from: "Standard.RightFoot", + to: "Actions.RightFoot", + filters: [ + { + type: "exponentialSmoothing", + translation: FOOT_SMOOTHING_TRANSLATION, + rotation: FOOT_SMOOTHING_ROTATION + } + ] + }, + { + from: "Standard.Hips", + to: "Actions.Hips", + filters: [ + { + type: "exponentialSmoothing", + translation: TORSO_SMOOTHING_TRANSLATION, + rotation: TORSO_SMOOTHING_ROTATION + } + ] + }, + { + from: "Standard.Spine2", + to: "Actions.Spine2", + filters: [ + { + type: "exponentialSmoothing", + translation: TORSO_SMOOTHING_TRANSLATION, + rotation: TORSO_SMOOTHING_ROTATION + } + ] + } + ] +}; + +// +// tablet app boiler plate +// + +var TABLET_BUTTON_NAME = "EXPFILT"; +var HTML_URL = Script.resolvePath("./index.html"); + +var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); +var tabletButton = tablet.addButton({ + text: TABLET_BUTTON_NAME, + icon: Script.getExternalPath(Script.ExternalPaths.HF_Public, "/tony/icons/tpose-i.svg"), + activeIcon: Script.getExternalPath(Script.ExternalPaths.HF_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); + shownChanged(true); + } + shown = true; + } else { + tabletButton.editProperties({isActive: false}); + if (shown) { + // disconnect from event bridge + tablet.webEventReceived.disconnect(onWebEventReceived); + shownChanged(false); + } + shown = false; + } +} + +function getTranslation(i) { + return mappingJson.channels[i].filters[0].translation; +} +function setTranslation(i, value) { + mappingJson.channels[i].filters[0].translation = value; + mappingChanged(); +} +function getRotation(i) { + return mappingJson.channels[i].filters[0].rotation; +} +function setRotation(i, value) { + mappingJson.channels[i].filters[0].rotation = value; mappingChanged(); +} + +function onWebEventReceived(msg) { + msg = JSON.parse(msg); + if (msg.name === "init-complete") { + var values = [ + {name: "enable-filtering", val: filterEnabled ? "on" : "off", checked: false}, + {name: "left-hand-translation", val: getTranslation(LEFT_HAND_INDEX), checked: false}, + {name: "left-hand-rotation", val: getRotation(LEFT_HAND_INDEX), checked: false}, + {name: "right-hand-translation", val: getTranslation(RIGHT_HAND_INDEX), checked: false}, + {name: "right-hand-rotation", val: getRotation(RIGHT_HAND_INDEX), checked: false}, + {name: "left-foot-translation", val: getTranslation(LEFT_FOOT_INDEX), checked: false}, + {name: "left-foot-rotation", val: getRotation(LEFT_FOOT_INDEX), checked: false}, + {name: "right-foot-translation", val: getTranslation(RIGHT_FOOT_INDEX), checked: false}, + {name: "right-foot-rotation", val: getRotation(RIGHT_FOOT_INDEX), checked: false}, + {name: "hips-translation", val: getTranslation(HIPS_INDEX), checked: false}, + {name: "hips-rotation", val: getRotation(HIPS_INDEX), checked: false}, + {name: "spine2-translation", val: getTranslation(SPINE2_INDEX), checked: false}, + {name: "spine2-rotation", val: getRotation(SPINE2_INDEX), checked: false} + ]; + tablet.emitScriptEvent(JSON.stringify(values)); + } else if (msg.name === "enable-filtering") { + if (msg.val === "on") { + filterEnabled = true; + } else if (msg.val === "off") { + filterEnabled = false; + } + mappingChanged(); + } else if (msg.name === "left-hand-translation") { + setTranslation(LEFT_HAND_INDEX, Number(msg.val)); + } else if (msg.name === "left-hand-rotation") { + setRotation(LEFT_HAND_INDEX, Number(msg.val)); + } else if (msg.name === "right-hand-translation") { + setTranslation(RIGHT_HAND_INDEX, Number(msg.val)); + } else if (msg.name === "right-hand-rotation") { + setRotation(RIGHT_HAND_INDEX, Number(msg.val)); + } else if (msg.name === "left-foot-translation") { + setTranslation(LEFT_FOOT_INDEX, Number(msg.val)); + } else if (msg.name === "left-foot-rotation") { + setRotation(LEFT_FOOT_INDEX, Number(msg.val)); + } else if (msg.name === "right-foot-translation") { + setTranslation(RIGHT_FOOT_INDEX, Number(msg.val)); + } else if (msg.name === "right-foot-rotation") { + setRotation(RIGHT_FOOT_INDEX, Number(msg.val)); + } else if (msg.name === "hips-translation") { + setTranslation(HIPS_INDEX, Number(msg.val)); + } else if (msg.name === "hips-rotation") { + setRotation(HIPS_INDEX, Number(msg.val)); + } else if (msg.name === "spine2-translation") { + setTranslation(SPINE2_INDEX, Number(msg.val)); + } else if (msg.name === "spine2-rotation") { + setRotation(SPINE2_INDEX, Number(msg.val)); + } +} + +tablet.screenChanged.connect(onScreenChanged); + +function shutdownTabletApp() { + tablet.removeButton(tabletButton); + if (shown) { + tablet.webEventReceived.disconnect(onWebEventReceived); + tablet.gotoHomeScreen(); + } + tablet.screenChanged.disconnect(onScreenChanged); +} + +// +// end tablet app boiler plate +// + +var filterEnabled = true; +var mapping; +function mappingChanged() { + if (mapping) { + mapping.disable(); + } + if (filterEnabled) { + mapping = Controller.parseMapping(JSON.stringify(mappingJson)); + mapping.enable(); + } +} + +function shownChanged(newShown) { + if (newShown) { + mappingChanged(); + } else { + mapping.disable(); + } +} + +mappingChanged(); + +Script.scriptEnding.connect(function() { + if (mapping) { + mapping.disable(); + } + tablet.removeButton(tabletButton); +}); diff --git a/scripts/communityScripts/characterSmoothing/index.html b/scripts/communityScripts/characterSmoothing/index.html new file mode 100755 index 0000000000..f31b7cb835 --- /dev/null +++ b/scripts/communityScripts/characterSmoothing/index.html @@ -0,0 +1,65 @@ + + + + + + Document + + + + + +
+ Left Hand + + + +
+
+ Right Hand + + + +
+
+ Left Foot + + + +
+ + + + \ No newline at end of file From d0226a3b05b28b2dce45b49aa1ccffbb318c6300 Mon Sep 17 00:00:00 2001 From: ArmoredDragon <43324896+Armored-Dragon@users.noreply.github.com> Date: Sat, 19 Aug 2023 13:54:25 -0500 Subject: [PATCH 2/4] beta Uses valid track points Relocated to /developer Better UI Settings persistance --- .../characterSmoothing/AccelerationFilter.js | 240 ----------------- .../characterSmoothing/index.html | 65 ----- scripts/developer/accelerationFilterApp.js | 222 --------------- .../characterSmoothing/characterSmoothing.js | 254 ++++++++++++++++++ .../developer/characterSmoothing/index.css | 80 ++++++ .../developer/characterSmoothing/index.html | 120 +++++++++ .../developer/characterSmoothing/index.scss | 98 +++++++ scripts/developer/exponentialFilterApp.js | 240 ----------------- 8 files changed, 552 insertions(+), 767 deletions(-) delete mode 100755 scripts/communityScripts/characterSmoothing/AccelerationFilter.js delete mode 100755 scripts/communityScripts/characterSmoothing/index.html delete mode 100644 scripts/developer/accelerationFilterApp.js create mode 100755 scripts/developer/characterSmoothing/characterSmoothing.js create mode 100644 scripts/developer/characterSmoothing/index.css create mode 100755 scripts/developer/characterSmoothing/index.html create mode 100644 scripts/developer/characterSmoothing/index.scss delete mode 100644 scripts/developer/exponentialFilterApp.js diff --git a/scripts/communityScripts/characterSmoothing/AccelerationFilter.js b/scripts/communityScripts/characterSmoothing/AccelerationFilter.js deleted file mode 100755 index fc326bcf66..0000000000 --- a/scripts/communityScripts/characterSmoothing/AccelerationFilter.js +++ /dev/null @@ -1,240 +0,0 @@ -var LEFT_HAND_INDEX = 0; -var RIGHT_HAND_INDEX = 1; -var LEFT_FOOT_INDEX = 2; -var RIGHT_FOOT_INDEX = 3; -var HIPS_INDEX = 4; -var SPINE2_INDEX = 5; - -var HAND_SMOOTHING_TRANSLATION = 0.3; -var HAND_SMOOTHING_ROTATION = 0.15; -var FOOT_SMOOTHING_TRANSLATION = 0.3; -var FOOT_SMOOTHING_ROTATION = 0.15; -var TORSO_SMOOTHING_TRANSLATION = 0.3; -var TORSO_SMOOTHING_ROTATION = 0.16; - -var mappingJson = { - name: "com.highfidelity.testing.exponentialFilterApp", - channels: [ - { - from: "Standard.LeftHand", - to: "Actions.LeftHand", - filters: [ - { - type: "exponentialSmoothing", - translation: HAND_SMOOTHING_TRANSLATION, - rotation: HAND_SMOOTHING_ROTATION - } - ] - }, - { - from: "Standard.RightHand", - to: "Actions.RightHand", - filters: [ - { - type: "exponentialSmoothing", - translation: HAND_SMOOTHING_TRANSLATION, - rotation: HAND_SMOOTHING_ROTATION - } - ] - }, - { - from: "Standard.LeftFoot", - to: "Actions.LeftFoot", - filters: [ - { - type: "exponentialSmoothing", - translation: FOOT_SMOOTHING_TRANSLATION, - rotation: FOOT_SMOOTHING_ROTATION - } - ] - }, - { - from: "Standard.RightFoot", - to: "Actions.RightFoot", - filters: [ - { - type: "exponentialSmoothing", - translation: FOOT_SMOOTHING_TRANSLATION, - rotation: FOOT_SMOOTHING_ROTATION - } - ] - }, - { - from: "Standard.Hips", - to: "Actions.Hips", - filters: [ - { - type: "exponentialSmoothing", - translation: TORSO_SMOOTHING_TRANSLATION, - rotation: TORSO_SMOOTHING_ROTATION - } - ] - }, - { - from: "Standard.Spine2", - to: "Actions.Spine2", - filters: [ - { - type: "exponentialSmoothing", - translation: TORSO_SMOOTHING_TRANSLATION, - rotation: TORSO_SMOOTHING_ROTATION - } - ] - } - ] -}; - -// -// tablet app boiler plate -// - -var TABLET_BUTTON_NAME = "EXPFILT"; -var HTML_URL = Script.resolvePath("./index.html"); - -var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); -var tabletButton = tablet.addButton({ - text: TABLET_BUTTON_NAME, - icon: Script.getExternalPath(Script.ExternalPaths.HF_Public, "/tony/icons/tpose-i.svg"), - activeIcon: Script.getExternalPath(Script.ExternalPaths.HF_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); - shownChanged(true); - } - shown = true; - } else { - tabletButton.editProperties({isActive: false}); - if (shown) { - // disconnect from event bridge - tablet.webEventReceived.disconnect(onWebEventReceived); - shownChanged(false); - } - shown = false; - } -} - -function getTranslation(i) { - return mappingJson.channels[i].filters[0].translation; -} -function setTranslation(i, value) { - mappingJson.channels[i].filters[0].translation = value; - mappingChanged(); -} -function getRotation(i) { - return mappingJson.channels[i].filters[0].rotation; -} -function setRotation(i, value) { - mappingJson.channels[i].filters[0].rotation = value; mappingChanged(); -} - -function onWebEventReceived(msg) { - msg = JSON.parse(msg); - if (msg.name === "init-complete") { - var values = [ - {name: "enable-filtering", val: filterEnabled ? "on" : "off", checked: false}, - {name: "left-hand-translation", val: getTranslation(LEFT_HAND_INDEX), checked: false}, - {name: "left-hand-rotation", val: getRotation(LEFT_HAND_INDEX), checked: false}, - {name: "right-hand-translation", val: getTranslation(RIGHT_HAND_INDEX), checked: false}, - {name: "right-hand-rotation", val: getRotation(RIGHT_HAND_INDEX), checked: false}, - {name: "left-foot-translation", val: getTranslation(LEFT_FOOT_INDEX), checked: false}, - {name: "left-foot-rotation", val: getRotation(LEFT_FOOT_INDEX), checked: false}, - {name: "right-foot-translation", val: getTranslation(RIGHT_FOOT_INDEX), checked: false}, - {name: "right-foot-rotation", val: getRotation(RIGHT_FOOT_INDEX), checked: false}, - {name: "hips-translation", val: getTranslation(HIPS_INDEX), checked: false}, - {name: "hips-rotation", val: getRotation(HIPS_INDEX), checked: false}, - {name: "spine2-translation", val: getTranslation(SPINE2_INDEX), checked: false}, - {name: "spine2-rotation", val: getRotation(SPINE2_INDEX), checked: false} - ]; - tablet.emitScriptEvent(JSON.stringify(values)); - } else if (msg.name === "enable-filtering") { - if (msg.val === "on") { - filterEnabled = true; - } else if (msg.val === "off") { - filterEnabled = false; - } - mappingChanged(); - } else if (msg.name === "left-hand-translation") { - setTranslation(LEFT_HAND_INDEX, Number(msg.val)); - } else if (msg.name === "left-hand-rotation") { - setRotation(LEFT_HAND_INDEX, Number(msg.val)); - } else if (msg.name === "right-hand-translation") { - setTranslation(RIGHT_HAND_INDEX, Number(msg.val)); - } else if (msg.name === "right-hand-rotation") { - setRotation(RIGHT_HAND_INDEX, Number(msg.val)); - } else if (msg.name === "left-foot-translation") { - setTranslation(LEFT_FOOT_INDEX, Number(msg.val)); - } else if (msg.name === "left-foot-rotation") { - setRotation(LEFT_FOOT_INDEX, Number(msg.val)); - } else if (msg.name === "right-foot-translation") { - setTranslation(RIGHT_FOOT_INDEX, Number(msg.val)); - } else if (msg.name === "right-foot-rotation") { - setRotation(RIGHT_FOOT_INDEX, Number(msg.val)); - } else if (msg.name === "hips-translation") { - setTranslation(HIPS_INDEX, Number(msg.val)); - } else if (msg.name === "hips-rotation") { - setRotation(HIPS_INDEX, Number(msg.val)); - } else if (msg.name === "spine2-translation") { - setTranslation(SPINE2_INDEX, Number(msg.val)); - } else if (msg.name === "spine2-rotation") { - setRotation(SPINE2_INDEX, Number(msg.val)); - } -} - -tablet.screenChanged.connect(onScreenChanged); - -function shutdownTabletApp() { - tablet.removeButton(tabletButton); - if (shown) { - tablet.webEventReceived.disconnect(onWebEventReceived); - tablet.gotoHomeScreen(); - } - tablet.screenChanged.disconnect(onScreenChanged); -} - -// -// end tablet app boiler plate -// - -var filterEnabled = true; -var mapping; -function mappingChanged() { - if (mapping) { - mapping.disable(); - } - if (filterEnabled) { - mapping = Controller.parseMapping(JSON.stringify(mappingJson)); - mapping.enable(); - } -} - -function shownChanged(newShown) { - if (newShown) { - mappingChanged(); - } else { - mapping.disable(); - } -} - -mappingChanged(); - -Script.scriptEnding.connect(function() { - if (mapping) { - mapping.disable(); - } - tablet.removeButton(tabletButton); -}); diff --git a/scripts/communityScripts/characterSmoothing/index.html b/scripts/communityScripts/characterSmoothing/index.html deleted file mode 100755 index f31b7cb835..0000000000 --- a/scripts/communityScripts/characterSmoothing/index.html +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - Document - - - - - -
- Left Hand - - - -
-
- Right Hand - - - -
-
- Left Foot - - - -
- - - - \ No newline at end of file diff --git a/scripts/developer/accelerationFilterApp.js b/scripts/developer/accelerationFilterApp.js deleted file mode 100644 index a05e7bacf0..0000000000 --- a/scripts/developer/accelerationFilterApp.js +++ /dev/null @@ -1,222 +0,0 @@ -var LEFT_HAND_INDEX = 0; -var RIGHT_HAND_INDEX = 1; -var LEFT_FOOT_INDEX = 2; -var RIGHT_FOOT_INDEX = 3; -var HIPS_INDEX = 4; -var SPINE2_INDEX = 5; - -var mappingJson = { - name: "com.highfidelity.testing.accelerationTest", - channels: [ - { - from: "Standard.LeftHand", - to: "Actions.LeftHand", - filters: [ - { - type: "accelerationLimiter", - rotationAccelerationLimit: 2000.0, - translationAccelerationLimit: 100.0, - } - ] - }, - { - from: "Standard.RightHand", - to: "Actions.RightHand", - filters: [ - { - type: "accelerationLimiter", - rotationAccelerationLimit: 2000.0, - translationAccelerationLimit: 100.0, - } - ] - }, - { - from: "Standard.LeftFoot", - to: "Actions.LeftFoot", - filters: [ - { - type: "accelerationLimiter", - rotationAccelerationLimit: 2000.0, - translationAccelerationLimit: 100.0, - } - ] - }, - { - from: "Standard.RightFoot", - to: "Actions.RightFoot", - filters: [ - { - type: "accelerationLimiter", - rotationAccelerationLimit: 2000.0, - translationAccelerationLimit: 100.0, - } - ] - }, - { - from: "Standard.Hips", - to: "Actions.Hips", - filters: [ - { - type: "accelerationLimiter", - rotationAccelerationLimit: 2000.0, - translationAccelerationLimit: 100.0, - } - ] - }, - { - from: "Standard.Spine2", - to: "Actions.Spine2", - filters: [ - { - type: "accelerationLimiter", - rotationAccelerationLimit: 2000.0, - translationAccelerationLimit: 100.0, - } - ] - } - ] -}; - -// -// tablet app boiler plate -// - -var TABLET_BUTTON_NAME = "ACCFILT"; -var HTML_URL = Script.getExternalPath(Script.ExternalPaths.HF_Public, "/tony/html/accelerationFilterApp.html?2"); - -var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); -var tabletButton = tablet.addButton({ - text: TABLET_BUTTON_NAME, - icon: Script.getExternalPath(Script.ExternalPaths.HF_Public, "/tony/icons/tpose-i.svg"), - activeIcon: Script.getExternalPath(Script.ExternalPaths.HF_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); - shownChanged(true); - } - shown = true; - } else { - tabletButton.editProperties({isActive: false}); - if (shown) { - // disconnect from event bridge - tablet.webEventReceived.disconnect(onWebEventReceived); - shownChanged(false); - } - shown = false; - } -} - -function getTranslationAccelerationLimit(i) { - return mappingJson.channels[i].filters[0].translationAccelerationLimit; -} -function setTranslationAccelerationLimit(i, value) { - mappingJson.channels[i].filters[0].translationAccelerationLimit = value; - mappingChanged(); -} -function getRotationAccelerationLimit(i) { - return mappingJson.channels[i].filters[0].rotationAccelerationLimit; -} -function setRotationAccelerationLimit(i, value) { - mappingJson.channels[i].filters[0].rotationAccelerationLimit = value; mappingChanged(); -} - -function onWebEventReceived(msg) { - if (msg.name === "init-complete") { - var values = [ - {name: "left-hand-translation-acceleration-limit", val: getTranslationAccelerationLimit(LEFT_HAND_INDEX), checked: false}, - {name: "left-hand-rotation-acceleration-limit", val: getRotationAccelerationLimit(LEFT_HAND_INDEX), checked: false}, - {name: "right-hand-translation-acceleration-limit", val: getTranslationAccelerationLimit(RIGHT_HAND_INDEX), checked: false}, - {name: "right-hand-rotation-acceleration-limit", val: getRotationAccelerationLimit(RIGHT_HAND_INDEX), checked: false}, - {name: "left-foot-translation-acceleration-limit", val: getTranslationAccelerationLimit(LEFT_FOOT_INDEX), checked: false}, - {name: "left-foot-rotation-acceleration-limit", val: getRotationAccelerationLimit(LEFT_FOOT_INDEX), checked: false}, - {name: "right-foot-translation-acceleration-limit", val: getTranslationAccelerationLimit(RIGHT_FOOT_INDEX), checked: false}, - {name: "right-foot-rotation-acceleration-limit", val: getRotationAccelerationLimit(RIGHT_FOOT_INDEX), checked: false}, - {name: "hips-translation-acceleration-limit", val: getTranslationAccelerationLimit(HIPS_INDEX), checked: false}, - {name: "hips-rotation-acceleration-limit", val: getRotationAccelerationLimit(HIPS_INDEX), checked: false}, - {name: "spine2-translation-acceleration-limit", val: getTranslationAccelerationLimit(SPINE2_INDEX), checked: false}, - {name: "spine2-rotation-acceleration-limit", val: getRotationAccelerationLimit(SPINE2_INDEX), checked: false} - ]; - tablet.emitScriptEvent(JSON.stringify(values)); - } else if (msg.name === "left-hand-translation-acceleration-limit") { - setTranslationAccelerationLimit(LEFT_HAND_INDEX, parseInt(msg.val, 10)); - } else if (msg.name === "left-hand-rotation-acceleration-limit") { - setRotationAccelerationLimit(LEFT_HAND_INDEX, parseInt(msg.val, 10)); - } else if (msg.name === "right-hand-translation-acceleration-limit") { - setTranslationAccelerationLimit(RIGHT_HAND_INDEX, parseInt(msg.val, 10)); - } else if (msg.name === "right-hand-rotation-acceleration-limit") { - setRotationAccelerationLimit(RIGHT_HAND_INDEX, parseInt(msg.val, 10)); - } else if (msg.name === "left-foot-translation-acceleration-limit") { - setTranslationAccelerationLimit(LEFT_FOOT_INDEX, parseInt(msg.val, 10)); - } else if (msg.name === "left-foot-rotation-acceleration-limit") { - setRotationAccelerationLimit(LEFT_FOOT_INDEX, parseInt(msg.val, 10)); - } else if (msg.name === "right-foot-translation-acceleration-limit") { - setTranslationAccelerationLimit(RIGHT_FOOT_INDEX, parseInt(msg.val, 10)); - } else if (msg.name === "right-foot-rotation-acceleration-limit") { - setRotationAccelerationLimit(RIGHT_FOOT_INDEX, parseInt(msg.val, 10)); - } else if (msg.name === "hips-translation-acceleration-limit") { - setTranslationAccelerationLimit(HIPS_INDEX, parseInt(msg.val, 10)); - } else if (msg.name === "hips-rotation-acceleration-limit") { - setRotationAccelerationLimit(HIPS_INDEX, parseInt(msg.val, 10)); - } else if (msg.name === "spine2-translation-acceleration-limit") { - setTranslationAccelerationLimit(SPINE2_INDEX, parseInt(msg.val, 10)); - } else if (msg.name === "spine2-rotation-acceleration-limit") { - setRotationAccelerationLimit(SPINE2_INDEX, parseInt(msg.val, 10)); - } -} - -tablet.screenChanged.connect(onScreenChanged); - -function shutdownTabletApp() { - tablet.removeButton(tabletButton); - if (shown) { - tablet.webEventReceived.disconnect(onWebEventReceived); - tablet.gotoHomeScreen(); - } - tablet.screenChanged.disconnect(onScreenChanged); -} - -// -// end tablet app boiler plate -// - -var mapping; -function mappingChanged() { - if (mapping) { - mapping.disable(); - } - mapping = Controller.parseMapping(JSON.stringify(mappingJson)); - mapping.enable(); -} - -function shownChanged(newShown) { - if (newShown) { - mappingChanged(); - } else { - mapping.disable(); - } -} - -mappingChanged(); - -Script.scriptEnding.connect(function() { - if (mapping) { - mapping.disable(); - } - tablet.removeButton(tabletButton); -}); - diff --git a/scripts/developer/characterSmoothing/characterSmoothing.js b/scripts/developer/characterSmoothing/characterSmoothing.js new file mode 100755 index 0000000000..069bf191f1 --- /dev/null +++ b/scripts/developer/characterSmoothing/characterSmoothing.js @@ -0,0 +1,254 @@ +// TODO: Good UI +// TODO: Script optimization +// TODO: AccelerationLimiter choice? +// TODO: Force limit values on smoothing_settings.targets to 0 though 1 + +// +// Copyright 2023 Overte e.V. + +// Start everything at no smoothing. +// Ideally the miniscule about of smoothing that is actually still there should be sufficient. +let smoothing_settings = { + enabled: false, + targets: { + left_hand: { + transform: 1, + rotation: 1, + }, + right_hand: { + transform: 1, + rotation: 1, + }, + left_foot: { + transform: 1, + rotation: 1, + }, + right_foot: { + transform: 1, + rotation: 1, + }, + hips: { + transform: 1, + rotation: 1, + }, + spine2: { + transform: 1, + rotation: 1, + }, + }, +}; +let mappingJson = { + name: "org.overte.controllers.smoothing", + channels: [ + { + from: "Standard.LeftHand", + to: "Actions.LeftHand", + filters: [ + { + type: "exponentialSmoothing", + translation: smoothing_settings.targets.left_hand.transform, + rotation: smoothing_settings.targets.left_hand.rotation, + }, + ], + }, + { + from: "Standard.RightHand", + to: "Actions.RightHand", + filters: [ + { + type: "exponentialSmoothing", + translation: + smoothing_settings.targets.right_hand.transform, + rotation: smoothing_settings.targets.right_hand.rotation, + }, + ], + }, + { + from: "Standard.LeftFoot", + to: "Actions.LeftFoot", + filters: [ + { + type: "exponentialSmoothing", + translation: smoothing_settings.targets.left_foot.transform, + rotation: smoothing_settings.targets.left_foot.rotation, + }, + ], + }, + { + from: "Standard.RightFoot", + to: "Actions.RightFoot", + filters: [ + { + type: "exponentialSmoothing", + translation: + smoothing_settings.targets.right_foot.transform, + rotation: smoothing_settings.targets.right_foot.rotation, + }, + ], + }, + { + from: "Standard.Hips", + to: "Actions.Hips", + filters: [ + { + type: "exponentialSmoothing", + translation: smoothing_settings.targets.hips.transform, + rotation: smoothing_settings.targets.hips.rotation, + }, + ], + }, + { + from: "Standard.Spine2", + to: "Actions.Spine2", + filters: [ + { + type: "exponentialSmoothing", + translation: smoothing_settings.targets.spine2.transform, + rotation: smoothing_settings.targets.spine2.rotation, + }, + ], + }, + ], +}; + +let mapping; + +// Build tablet +const HTML_URL = Script.resolvePath("./index.html"); +let shown = false; +let tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); +let tabletButton = tablet.addButton({ + text: "CHR", + // TODO: Icon + icon: Script.resolvePath("./img/icon.png"), +}); +tabletButton.clicked.connect(() => { + if (shown) tablet.gotoHomeScreen(); + else tablet.gotoWebScreen(HTML_URL); +}); + +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); + shownChanged(true); + } + // FIXME: Works, just need to wait for response before we send data + Script.setTimeout(() => { + _sendMessage({ + action: "load_listings", + data: smoothing_settings, + }); + }, 1000); + + shown = true; + } else { + tabletButton.editProperties({ isActive: false }); + + if (shown) { + // disconnect from event bridge + tablet.webEventReceived.disconnect(onWebEventReceived); + shownChanged(false); + } + shown = false; + } +} +tablet.screenChanged.connect(onScreenChanged); + +function shutdownTabletApp() { + tablet.removeButton(tabletButton); + if (shown) { + tablet.webEventReceived.disconnect(onWebEventReceived); + tablet.gotoHomeScreen(); + } + tablet.screenChanged.disconnect(onScreenChanged); +} + +function onWebEventReceived(msg) { + msg = JSON.parse(msg); + + // TODO + // Toggle smoothing + // if (msg.action === "set_state") { + // smoothing_settings.enabled = msg.value ? true : false; + // mappingChanged(); + // } + + // Adjust a target's rotation and transform values + if (msg.action === "new_settings") { + + smoothing_settings = msg.data + mappingChanged(); + } +} + +function mappingChanged() { + Settings.setValue("smoothing_settings", smoothing_settings); + + if (mapping) mapping.disable(); + + if (smoothing_settings.enabled) { + mapping = Controller.parseMapping(JSON.stringify(mappingJson)); + mapping.enable(); + } +} + +function shownChanged(newShown) { + if (newShown) mappingChanged(); + else if (mapping) mapping.disable(); +} + +Script.scriptEnding.connect(function () { + if (mapping) mapping.disable(); + tablet.removeButton(tabletButton); +}); + +function _sendMessage(message) { + message = JSON.stringify(message); + tablet.emitScriptEvent(message); +} + +// Load settings +smoothing_settings = Settings.getValue( + "smoothing_settings", + smoothing_settings +); + +// TODO: Does script init work? +// Settings.setValue( +// "smoothing_settings", +// { +// enabled: false, +// targets: { +// left_hand: { +// transform: 1, +// rotation: 1, +// }, +// right_hand: { +// transform: 1, +// rotation: 1, +// }, +// left_foot: { +// transform: 1, +// rotation: 1, +// }, +// right_foot: { +// transform: 1, +// rotation: 1, +// }, +// hips: { +// transform: 1, +// rotation: 1, +// }, +// spine2: { +// transform: 1, +// rotation: 1, +// }, +// }, +// } +// ); + +mappingChanged(); diff --git a/scripts/developer/characterSmoothing/index.css b/scripts/developer/characterSmoothing/index.css new file mode 100644 index 0000000000..b43782988b --- /dev/null +++ b/scripts/developer/characterSmoothing/index.css @@ -0,0 +1,80 @@ +body { + background-color: black; + color: white; + margin: 0; + padding: 0.5rem; + box-sizing: border-box; + height: 100vh; + width: 100vw; + display: flex; + flex-direction: column; + width: 100%; +} +body .container-1 { + margin-bottom: 1rem; + display: flex; + flex-direction: column; + width: 100%; +} +body .container-1 .title { + background-color: #262626; + font-size: 1.2rem; + padding: 0.2rem; + box-sizing: border-box; +} +body .container-1 .list { + display: grid; + grid-template-columns: 1fr 1fr; + padding: 1rem; + box-sizing: border-box; + background-color: #131313; +} +body .container-1 .list .option { + display: flex; + flex-direction: row; +} +body .container-1 .list .option * { + margin: auto; +} +body .container-1 .list .option div { + margin-right: 0.5rem; +} +body .container-1 .list .option input { + margin-left: 0.5rem; + text-align: center; + font-size: 1.1rem; + height: 35px; +} +body .button-container { + width: 100%; + display: flex; + flex-direction: row; + background-color: #131313; + padding: 0.5rem; + box-sizing: border-box; + display: grid; + grid-gap: 1rem; + grid-template-columns: 1fr 1fr; +} +body .button-container button { + width: 100%; + height: 35px; + background-color: #505186; + border: 0; + color: white; + border-radius: 5px; + cursor: pointer; +} +body .button-container button:hover, +body .button-container button:focus { + filter: brightness(60%); +} +body .button-container button:active { + filter: brightness(40%); +} +body .button-container .active { + background-color: #277727; +} +body .button-container .unactive { + background-color: #771d1d; +} \ No newline at end of file diff --git a/scripts/developer/characterSmoothing/index.html b/scripts/developer/characterSmoothing/index.html new file mode 100755 index 0000000000..677971baea --- /dev/null +++ b/scripts/developer/characterSmoothing/index.html @@ -0,0 +1,120 @@ + + + + + + + Character Smoothing + + + +
+ +
+ + +
+ + + + + + diff --git a/scripts/developer/characterSmoothing/index.scss b/scripts/developer/characterSmoothing/index.scss new file mode 100644 index 0000000000..8464f24597 --- /dev/null +++ b/scripts/developer/characterSmoothing/index.scss @@ -0,0 +1,98 @@ +body { + background-color: black; + color: white; + margin: 0; + padding: 0.5rem; + box-sizing: border-box; + + height: 100vh; + width: 100vw; + + display: flex; + flex-direction: column; + width: 100%; + + .container-1 { + margin-bottom: 1rem; + display: flex; + flex-direction: column; + width: 100%; + + .title { + background-color: #262626; + font-size: 1.2rem; + + padding: 0.2rem; + box-sizing: border-box; + } + + .list { + display: grid; + grid-template-columns: 1fr 1fr; + padding: 1rem; + box-sizing: border-box; + + background-color: #131313; + + .option { + display: flex; + flex-direction: row; + + * { + margin: auto; + } + + div { + margin-right: 0.5rem; + } + + input { + margin-left: 0.5rem; + text-align: center; + font-size: 1.1rem; + height: 35px; + } + } + } + } + + .button-container { + width: 100%; + display: flex; + flex-direction: row; + background-color: #131313; + padding: 0.5rem; + box-sizing: border-box; + + display: grid; + grid-gap: 1rem; + grid-template-columns: 1fr 1fr; + + button { + width: 100%; + height: 35px; + background-color: #505186; + border: 0; + color: white; + border-radius: 5px; + cursor: pointer; + } + + button:hover, + button:focus { + filter: brightness(60%); + } + + button:active { + filter: brightness(40%); + } + + .active { + background-color: #277727; + } + + .unactive { + background-color: #771d1d; + } + } +} diff --git a/scripts/developer/exponentialFilterApp.js b/scripts/developer/exponentialFilterApp.js deleted file mode 100644 index 58c0e49e31..0000000000 --- a/scripts/developer/exponentialFilterApp.js +++ /dev/null @@ -1,240 +0,0 @@ -var LEFT_HAND_INDEX = 0; -var RIGHT_HAND_INDEX = 1; -var LEFT_FOOT_INDEX = 2; -var RIGHT_FOOT_INDEX = 3; -var HIPS_INDEX = 4; -var SPINE2_INDEX = 5; - -var HAND_SMOOTHING_TRANSLATION = 0.3; -var HAND_SMOOTHING_ROTATION = 0.15; -var FOOT_SMOOTHING_TRANSLATION = 0.3; -var FOOT_SMOOTHING_ROTATION = 0.15; -var TORSO_SMOOTHING_TRANSLATION = 0.3; -var TORSO_SMOOTHING_ROTATION = 0.16; - -var mappingJson = { - name: "com.highfidelity.testing.exponentialFilterApp", - channels: [ - { - from: "Standard.LeftHand", - to: "Actions.LeftHand", - filters: [ - { - type: "exponentialSmoothing", - translation: HAND_SMOOTHING_TRANSLATION, - rotation: HAND_SMOOTHING_ROTATION - } - ] - }, - { - from: "Standard.RightHand", - to: "Actions.RightHand", - filters: [ - { - type: "exponentialSmoothing", - translation: HAND_SMOOTHING_TRANSLATION, - rotation: HAND_SMOOTHING_ROTATION - } - ] - }, - { - from: "Standard.LeftFoot", - to: "Actions.LeftFoot", - filters: [ - { - type: "exponentialSmoothing", - translation: FOOT_SMOOTHING_TRANSLATION, - rotation: FOOT_SMOOTHING_ROTATION - } - ] - }, - { - from: "Standard.RightFoot", - to: "Actions.RightFoot", - filters: [ - { - type: "exponentialSmoothing", - translation: FOOT_SMOOTHING_TRANSLATION, - rotation: FOOT_SMOOTHING_ROTATION - } - ] - }, - { - from: "Standard.Hips", - to: "Actions.Hips", - filters: [ - { - type: "exponentialSmoothing", - translation: TORSO_SMOOTHING_TRANSLATION, - rotation: TORSO_SMOOTHING_ROTATION - } - ] - }, - { - from: "Standard.Spine2", - to: "Actions.Spine2", - filters: [ - { - type: "exponentialSmoothing", - translation: TORSO_SMOOTHING_TRANSLATION, - rotation: TORSO_SMOOTHING_ROTATION - } - ] - } - ] -}; - -// -// tablet app boiler plate -// - -var TABLET_BUTTON_NAME = "EXPFILT"; -var HTML_URL = Script.getExternalPath(Script.ExternalPaths.HF_Public, "/tony/html/exponentialFilterApp.html?7"); - -var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); -var tabletButton = tablet.addButton({ - text: TABLET_BUTTON_NAME, - icon: Script.getExternalPath(Script.ExternalPaths.HF_Public, "/tony/icons/tpose-i.svg"), - activeIcon: Script.getExternalPath(Script.ExternalPaths.HF_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); - shownChanged(true); - } - shown = true; - } else { - tabletButton.editProperties({isActive: false}); - if (shown) { - // disconnect from event bridge - tablet.webEventReceived.disconnect(onWebEventReceived); - shownChanged(false); - } - shown = false; - } -} - -function getTranslation(i) { - return mappingJson.channels[i].filters[0].translation; -} -function setTranslation(i, value) { - mappingJson.channels[i].filters[0].translation = value; - mappingChanged(); -} -function getRotation(i) { - return mappingJson.channels[i].filters[0].rotation; -} -function setRotation(i, value) { - mappingJson.channels[i].filters[0].rotation = value; mappingChanged(); -} - -function onWebEventReceived(msg) { - if (msg.name === "init-complete") { - var values = [ - {name: "enable-filtering", val: filterEnabled ? "on" : "off", checked: false}, - {name: "left-hand-translation", val: getTranslation(LEFT_HAND_INDEX), checked: false}, - {name: "left-hand-rotation", val: getRotation(LEFT_HAND_INDEX), checked: false}, - {name: "right-hand-translation", val: getTranslation(RIGHT_HAND_INDEX), checked: false}, - {name: "right-hand-rotation", val: getRotation(RIGHT_HAND_INDEX), checked: false}, - {name: "left-foot-translation", val: getTranslation(LEFT_FOOT_INDEX), checked: false}, - {name: "left-foot-rotation", val: getRotation(LEFT_FOOT_INDEX), checked: false}, - {name: "right-foot-translation", val: getTranslation(RIGHT_FOOT_INDEX), checked: false}, - {name: "right-foot-rotation", val: getRotation(RIGHT_FOOT_INDEX), checked: false}, - {name: "hips-translation", val: getTranslation(HIPS_INDEX), checked: false}, - {name: "hips-rotation", val: getRotation(HIPS_INDEX), checked: false}, - {name: "spine2-translation", val: getTranslation(SPINE2_INDEX), checked: false}, - {name: "spine2-rotation", val: getRotation(SPINE2_INDEX), checked: false} - ]; - tablet.emitScriptEvent(JSON.stringify(values)); - } else if (msg.name === "enable-filtering") { - if (msg.val === "on") { - filterEnabled = true; - } else if (msg.val === "off") { - filterEnabled = false; - } - mappingChanged(); - } else if (msg.name === "left-hand-translation") { - setTranslation(LEFT_HAND_INDEX, Number(msg.val)); - } else if (msg.name === "left-hand-rotation") { - setRotation(LEFT_HAND_INDEX, Number(msg.val)); - } else if (msg.name === "right-hand-translation") { - setTranslation(RIGHT_HAND_INDEX, Number(msg.val)); - } else if (msg.name === "right-hand-rotation") { - setRotation(RIGHT_HAND_INDEX, Number(msg.val)); - } else if (msg.name === "left-foot-translation") { - setTranslation(LEFT_FOOT_INDEX, Number(msg.val)); - } else if (msg.name === "left-foot-rotation") { - setRotation(LEFT_FOOT_INDEX, Number(msg.val)); - } else if (msg.name === "right-foot-translation") { - setTranslation(RIGHT_FOOT_INDEX, Number(msg.val)); - } else if (msg.name === "right-foot-rotation") { - setRotation(RIGHT_FOOT_INDEX, Number(msg.val)); - } else if (msg.name === "hips-translation") { - setTranslation(HIPS_INDEX, Number(msg.val)); - } else if (msg.name === "hips-rotation") { - setRotation(HIPS_INDEX, Number(msg.val)); - } else if (msg.name === "spine2-translation") { - setTranslation(SPINE2_INDEX, Number(msg.val)); - } else if (msg.name === "spine2-rotation") { - setRotation(SPINE2_INDEX, Number(msg.val)); - } -} - -tablet.screenChanged.connect(onScreenChanged); - -function shutdownTabletApp() { - tablet.removeButton(tabletButton); - if (shown) { - tablet.webEventReceived.disconnect(onWebEventReceived); - tablet.gotoHomeScreen(); - } - tablet.screenChanged.disconnect(onScreenChanged); -} - -// -// end tablet app boiler plate -// - -var filterEnabled = true; -var mapping; -function mappingChanged() { - if (mapping) { - mapping.disable(); - } - if (filterEnabled) { - mapping = Controller.parseMapping(JSON.stringify(mappingJson)); - mapping.enable(); - } -} - -function shownChanged(newShown) { - if (newShown) { - mappingChanged(); - } else { - mapping.disable(); - } -} - -mappingChanged(); - -Script.scriptEnding.connect(function() { - if (mapping) { - mapping.disable(); - } - tablet.removeButton(tabletButton); -}); - From 2572ce5f019416adaee10abb8f314d7711e79634 Mon Sep 17 00:00:00 2001 From: ArmoredDragon <43324896+Armored-Dragon@users.noreply.github.com> Date: Tue, 22 Aug 2023 04:42:22 -0500 Subject: [PATCH 3/4] Finalization Refactored everything New UI --- .../characterSmoothing/characterSmoothing.js | 285 +++++------------- .../characterSmoothing/img/icon-a.png | Bin 0 -> 598 bytes .../developer/characterSmoothing/img/icon.png | Bin 0 -> 1150 bytes .../developer/characterSmoothing/index.css | 80 ----- .../developer/characterSmoothing/index.html | 120 -------- .../developer/characterSmoothing/index.scss | 98 ------ .../developer/characterSmoothing/ui/index.css | 39 +++ .../characterSmoothing/ui/index.html | 43 +++ .../developer/characterSmoothing/ui/index.js | 107 +++++++ .../characterSmoothing/ui/index.scss | 47 +++ .../developer/characterSmoothing/ui/theme.css | 75 +++++ 11 files changed, 384 insertions(+), 510 deletions(-) mode change 100755 => 100644 scripts/developer/characterSmoothing/characterSmoothing.js create mode 100644 scripts/developer/characterSmoothing/img/icon-a.png create mode 100644 scripts/developer/characterSmoothing/img/icon.png delete mode 100644 scripts/developer/characterSmoothing/index.css delete mode 100755 scripts/developer/characterSmoothing/index.html delete mode 100644 scripts/developer/characterSmoothing/index.scss create mode 100644 scripts/developer/characterSmoothing/ui/index.css create mode 100644 scripts/developer/characterSmoothing/ui/index.html create mode 100644 scripts/developer/characterSmoothing/ui/index.js create mode 100644 scripts/developer/characterSmoothing/ui/index.scss create mode 100644 scripts/developer/characterSmoothing/ui/theme.css diff --git a/scripts/developer/characterSmoothing/characterSmoothing.js b/scripts/developer/characterSmoothing/characterSmoothing.js old mode 100755 new mode 100644 index 069bf191f1..c2321b9275 --- a/scripts/developer/characterSmoothing/characterSmoothing.js +++ b/scripts/developer/characterSmoothing/characterSmoothing.js @@ -1,254 +1,115 @@ -// TODO: Good UI -// TODO: Script optimization -// TODO: AccelerationLimiter choice? -// TODO: Force limit values on smoothing_settings.targets to 0 though 1 - // // Copyright 2023 Overte e.V. -// Start everything at no smoothing. -// Ideally the miniscule about of smoothing that is actually still there should be sufficient. let smoothing_settings = { - enabled: false, + enabled: true, targets: { - left_hand: { - transform: 1, - rotation: 1, - }, - right_hand: { - transform: 1, - rotation: 1, - }, - left_foot: { - transform: 1, - rotation: 1, - }, - right_foot: { - transform: 1, - rotation: 1, - }, - hips: { - transform: 1, - rotation: 1, - }, - spine2: { - transform: 1, - rotation: 1, - }, + LeftHand: { transform: 1, rotation: 1 }, + RightHand: { transform: 1, rotation: 1 }, + LeftFoot: { transform: 1, rotation: 1 }, + RightFoot: { transform: 1, rotation: 1 }, + Hips: { transform: 1, rotation: 1 }, + Spine2: { transform: 1, rotation: 1 }, }, }; -let mappingJson = { - name: "org.overte.controllers.smoothing", - channels: [ - { - from: "Standard.LeftHand", - to: "Actions.LeftHand", - filters: [ - { - type: "exponentialSmoothing", - translation: smoothing_settings.targets.left_hand.transform, - rotation: smoothing_settings.targets.left_hand.rotation, - }, - ], - }, - { - from: "Standard.RightHand", - to: "Actions.RightHand", - filters: [ - { - type: "exponentialSmoothing", - translation: - smoothing_settings.targets.right_hand.transform, - rotation: smoothing_settings.targets.right_hand.rotation, - }, - ], - }, - { - from: "Standard.LeftFoot", - to: "Actions.LeftFoot", - filters: [ - { - type: "exponentialSmoothing", - translation: smoothing_settings.targets.left_foot.transform, - rotation: smoothing_settings.targets.left_foot.rotation, - }, - ], - }, - { - from: "Standard.RightFoot", - to: "Actions.RightFoot", - filters: [ - { - type: "exponentialSmoothing", - translation: - smoothing_settings.targets.right_foot.transform, - rotation: smoothing_settings.targets.right_foot.rotation, - }, - ], - }, - { - from: "Standard.Hips", - to: "Actions.Hips", - filters: [ - { - type: "exponentialSmoothing", - translation: smoothing_settings.targets.hips.transform, - rotation: smoothing_settings.targets.hips.rotation, - }, - ], - }, - { - from: "Standard.Spine2", - to: "Actions.Spine2", - filters: [ - { - type: "exponentialSmoothing", - translation: smoothing_settings.targets.spine2.transform, - rotation: smoothing_settings.targets.spine2.rotation, - }, - ], - }, - ], -}; let mapping; +let mapping_settings = { + name: "org.overte.controllers.smoothing", + channels: [], +}; -// Build tablet -const HTML_URL = Script.resolvePath("./index.html"); -let shown = false; +const html_url = Script.resolvePath("./ui/index.html"); let tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); +let shown = false; + +tablet.screenChanged.connect(onScreenChanged); +Script.scriptEnding.connect(shutdownTabletApp); + let tabletButton = tablet.addButton({ - text: "CHR", - // TODO: Icon + text: "AviSmooth", icon: Script.resolvePath("./img/icon.png"), + activeIcon: Script.resolvePath("./img/icon-a.png"), }); + tabletButton.clicked.connect(() => { - if (shown) tablet.gotoHomeScreen(); - else tablet.gotoWebScreen(HTML_URL); + tablet.gotoWebScreen(html_url); }); 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); - shownChanged(true); - } - // FIXME: Works, just need to wait for response before we send data - Script.setTimeout(() => { - _sendMessage({ - action: "load_listings", - data: smoothing_settings, - }); - }, 1000); - - shown = true; - } else { + if (type !== "Web" || url !== html_url) { + tablet.webEventReceived.disconnect(onWebEventReceived); tabletButton.editProperties({ isActive: false }); - - if (shown) { - // disconnect from event bridge - tablet.webEventReceived.disconnect(onWebEventReceived); - shownChanged(false); - } shown = false; + } else { + tabletButton.editProperties({ isActive: true }); + tablet.webEventReceived.connect(onWebEventReceived); + shown = true; + smoothing_settings = Settings.getValue( + "smoothing_settings", + smoothing_settings + ); } } -tablet.screenChanged.connect(onScreenChanged); function shutdownTabletApp() { - tablet.removeButton(tabletButton); - if (shown) { - tablet.webEventReceived.disconnect(onWebEventReceived); - tablet.gotoHomeScreen(); - } + if (mapping) mapping.disable(); // Disable custom mapping + tablet.removeButton(tabletButton); // Remove the app tablet.screenChanged.disconnect(onScreenChanged); + tablet.webEventReceived.disconnect(onWebEventReceived); } -function onWebEventReceived(msg) { - msg = JSON.parse(msg); +const _sendMessage = (message) => + tablet.emitScriptEvent(JSON.stringify(message)); - // TODO - // Toggle smoothing - // if (msg.action === "set_state") { - // smoothing_settings.enabled = msg.value ? true : false; - // mappingChanged(); - // } +function onWebEventReceived(message) { + message = JSON.parse(message); - // Adjust a target's rotation and transform values - if (msg.action === "new_settings") { + if (message.action === "ready") { + _sendMessage({ + action: "initialize", + data: smoothing_settings, + }); + } - smoothing_settings = msg.data + if (message.action === "new_settings") { + smoothing_settings = message.data; + mappingChanged(); + } + + if (message.action === "set_state") { + smoothing_settings.enabled = message.data; mappingChanged(); } } function mappingChanged() { Settings.setValue("smoothing_settings", smoothing_settings); - if (mapping) mapping.disable(); if (smoothing_settings.enabled) { - mapping = Controller.parseMapping(JSON.stringify(mappingJson)); + // Build mapping_settings + mapping_settings.channels = []; + + Object.keys(smoothing_settings.targets).forEach((target) => + mapping_settings.channels.push(_generateChannel(target)) + ); + + function _generateChannel(name) { + return { + from: `Standard.${name}`, + to: `Actions.${name}`, + filters: [ + { + type: "exponentialSmoothing", + translation: smoothing_settings.targets[name].transform, + rotation: smoothing_settings.targets[name].rotation, + }, + ], + }; + } + + mapping = Controller.parseMapping(JSON.stringify(mapping_settings)); mapping.enable(); } } - -function shownChanged(newShown) { - if (newShown) mappingChanged(); - else if (mapping) mapping.disable(); -} - -Script.scriptEnding.connect(function () { - if (mapping) mapping.disable(); - tablet.removeButton(tabletButton); -}); - -function _sendMessage(message) { - message = JSON.stringify(message); - tablet.emitScriptEvent(message); -} - -// Load settings -smoothing_settings = Settings.getValue( - "smoothing_settings", - smoothing_settings -); - -// TODO: Does script init work? -// Settings.setValue( -// "smoothing_settings", -// { -// enabled: false, -// targets: { -// left_hand: { -// transform: 1, -// rotation: 1, -// }, -// right_hand: { -// transform: 1, -// rotation: 1, -// }, -// left_foot: { -// transform: 1, -// rotation: 1, -// }, -// right_foot: { -// transform: 1, -// rotation: 1, -// }, -// hips: { -// transform: 1, -// rotation: 1, -// }, -// spine2: { -// transform: 1, -// rotation: 1, -// }, -// }, -// } -// ); - -mappingChanged(); diff --git a/scripts/developer/characterSmoothing/img/icon-a.png b/scripts/developer/characterSmoothing/img/icon-a.png new file mode 100644 index 0000000000000000000000000000000000000000..aa603c2a45da35bb51c787b037c99bb72105b134 GIT binary patch literal 598 zcmV-c0;&CpP)6kF#i`7Hbh0p_>@jF3dmPpKcnsKz?pfg6JDGp@YXIxfM>+g9 zVgRXf5zrw80UT_2B2dX`dJnjeM1iP;hSj$^pYp=x9&~sBI1sOCTJRjZ%uCTBRSs%v zF`l_W^Pj!F0C^ZK`ZryocVa$j;;8m`)!6_FRbI`B1%&oeKmhN#v47UjRK65c`F%jg0- zz_x~XN{PhO0N73>EW}RU`EPLbl^g(mgWxWZW>JV-02IPDNEbv-06_53$lcJd*eFD9 z08I$WZPiv@a|BQb(uoe=+8c5OFqO6au>ctVtmN7IEi~BAeThII0?#tPX=E>#Qa|9b zkHA`tC8g}3zUvQA0Z`A3bq7iWyp5nlAW(%$3Y8S{dZ46G4^P=8r3(G06iQ5ne#?hU kp?(%5t||bD4oqJD16=Z%F#vSnb^rhX07*qoM6N<$g0cPoBLDyZ literal 0 HcmV?d00001 diff --git a/scripts/developer/characterSmoothing/img/icon.png b/scripts/developer/characterSmoothing/img/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ac25aeb647feff20747dcc3999623181b8514bed GIT binary patch literal 1150 zcmV-^1cCdBP)>&rA31XC7f(OBi1d^K| zN-kc6cnX;4#o(gG7f2RS2?)klgov6Lqb8WFWYMfnRn7M2VQ0dmGmq}sNqQFMcl;jz z`u;slRna4=N~33+kjeL{dO2qPg_K; z?nOvdx6^refLpxx5A~wo4x_54QiELEqt-oHid1!7kNPb!#+ZYt*c#@4nLG$^d8R^< zD{^Xg#3V`baVoaLId@-99R*HgDHM_4a%y+P#Buxy;8OAJH0?}T5Rte0S(g<9oK@A= zQj6RfLU=NdkoW!t;AEGwy`@s=)0{JQL{yb(wR*iV=0~8^NT}**V09eFN3)7~?{5a) z1y;65zhkX^9GG3;%;zDElh`@;s)%e!<&V~CwY8N>CDZ#|r{bL3EFxnfa+#_gSJk)T zIR2n-Q#T<^SBX*Y{g=RvshY#8x;~EMpD)G$3#ECxJPSMm{Fkb^NkqO1Av|&E#>&ol z`@OaHkg9Ir!d+>Zs_ypQe^{&4)?T{tx+AS_qt3beMPw2fY14N=RVR%xQ&ALs3nUkF z$WF9001!f0t*U!~8@g!B04G#+T12LSxem2XRcA%yPvC27?G*5LFM~H|YoN|j=iCkv zd77LDTNYGx8hAdA<5!qJ&2!Vu0B~-9e-79HM7=E3h4-wrn}9QU8#5VbP_0(4GsbKJ zCV<<4C3zR@zz=hCbK@f;BfsZq%4HzM3h(_cV12IwEjXsC<9W`Uyw~Pt{!-OkPb&i} zjWM5x5LRVvScriIqpCXrpNd_js#76^JF;jLY5vAZvo9*sjB;(bK~6viZ(#G zT%IzoFvH_;7BSZBJ#5L{-t!!Kp6lim&?cMH{S1Cq_@^hoV(Tx zoB@DJrE=1HzYh4OMS81qZYTBG2hsq*=;-JvYwZ|tAe|GDE#CXrfoNb2)S0o?-YX*e zTjVx+@81}70|2v86ion=skm3wJ&VBrfVb8@3N*f7c~yNlj^ll$PF(}WoV9jy2;rY3 zNj{3>_p|%VS6wS~;(e!&4`bk7Kwo0h#H9%kg+<^WY_&188 z^nY#uIOk?W`u=Tf@xMYt14T15P&7jWMKd%|G(!VLGc-^%Ljy%KG*C4E1DAz^xR0(! QA^-pY07*qoM6N<$f(;xHcmMzZ literal 0 HcmV?d00001 diff --git a/scripts/developer/characterSmoothing/index.css b/scripts/developer/characterSmoothing/index.css deleted file mode 100644 index b43782988b..0000000000 --- a/scripts/developer/characterSmoothing/index.css +++ /dev/null @@ -1,80 +0,0 @@ -body { - background-color: black; - color: white; - margin: 0; - padding: 0.5rem; - box-sizing: border-box; - height: 100vh; - width: 100vw; - display: flex; - flex-direction: column; - width: 100%; -} -body .container-1 { - margin-bottom: 1rem; - display: flex; - flex-direction: column; - width: 100%; -} -body .container-1 .title { - background-color: #262626; - font-size: 1.2rem; - padding: 0.2rem; - box-sizing: border-box; -} -body .container-1 .list { - display: grid; - grid-template-columns: 1fr 1fr; - padding: 1rem; - box-sizing: border-box; - background-color: #131313; -} -body .container-1 .list .option { - display: flex; - flex-direction: row; -} -body .container-1 .list .option * { - margin: auto; -} -body .container-1 .list .option div { - margin-right: 0.5rem; -} -body .container-1 .list .option input { - margin-left: 0.5rem; - text-align: center; - font-size: 1.1rem; - height: 35px; -} -body .button-container { - width: 100%; - display: flex; - flex-direction: row; - background-color: #131313; - padding: 0.5rem; - box-sizing: border-box; - display: grid; - grid-gap: 1rem; - grid-template-columns: 1fr 1fr; -} -body .button-container button { - width: 100%; - height: 35px; - background-color: #505186; - border: 0; - color: white; - border-radius: 5px; - cursor: pointer; -} -body .button-container button:hover, -body .button-container button:focus { - filter: brightness(60%); -} -body .button-container button:active { - filter: brightness(40%); -} -body .button-container .active { - background-color: #277727; -} -body .button-container .unactive { - background-color: #771d1d; -} \ No newline at end of file diff --git a/scripts/developer/characterSmoothing/index.html b/scripts/developer/characterSmoothing/index.html deleted file mode 100755 index 677971baea..0000000000 --- a/scripts/developer/characterSmoothing/index.html +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - Character Smoothing - - - -
- -
- - -
- - - - - - diff --git a/scripts/developer/characterSmoothing/index.scss b/scripts/developer/characterSmoothing/index.scss deleted file mode 100644 index 8464f24597..0000000000 --- a/scripts/developer/characterSmoothing/index.scss +++ /dev/null @@ -1,98 +0,0 @@ -body { - background-color: black; - color: white; - margin: 0; - padding: 0.5rem; - box-sizing: border-box; - - height: 100vh; - width: 100vw; - - display: flex; - flex-direction: column; - width: 100%; - - .container-1 { - margin-bottom: 1rem; - display: flex; - flex-direction: column; - width: 100%; - - .title { - background-color: #262626; - font-size: 1.2rem; - - padding: 0.2rem; - box-sizing: border-box; - } - - .list { - display: grid; - grid-template-columns: 1fr 1fr; - padding: 1rem; - box-sizing: border-box; - - background-color: #131313; - - .option { - display: flex; - flex-direction: row; - - * { - margin: auto; - } - - div { - margin-right: 0.5rem; - } - - input { - margin-left: 0.5rem; - text-align: center; - font-size: 1.1rem; - height: 35px; - } - } - } - } - - .button-container { - width: 100%; - display: flex; - flex-direction: row; - background-color: #131313; - padding: 0.5rem; - box-sizing: border-box; - - display: grid; - grid-gap: 1rem; - grid-template-columns: 1fr 1fr; - - button { - width: 100%; - height: 35px; - background-color: #505186; - border: 0; - color: white; - border-radius: 5px; - cursor: pointer; - } - - button:hover, - button:focus { - filter: brightness(60%); - } - - button:active { - filter: brightness(40%); - } - - .active { - background-color: #277727; - } - - .unactive { - background-color: #771d1d; - } - } -} diff --git a/scripts/developer/characterSmoothing/ui/index.css b/scripts/developer/characterSmoothing/ui/index.css new file mode 100644 index 0000000000..641d00c6a8 --- /dev/null +++ b/scripts/developer/characterSmoothing/ui/index.css @@ -0,0 +1,39 @@ +body { + font-family: Verdana, Geneva, Tahoma, sans-serif; +} + +.container { + margin-bottom: 10px; +} +.container .content .type { + display: grid; + grid-template-columns: 1fr 3fr 1fr; + grid-template-rows: 1fr 1fr; + width: 100%; +} +.container .content .type span { + margin: 0 10px; +} +.container .content .type .header { + grid-column-start: 1; + grid-column-end: 3; +} +.container .content .type .type-value { + text-align: center; +} +.container .content .type input { + width: 100%; + grid-column-start: 1; + grid-column-end: 3; +} + +.container:last-child { + margin-bottom: 0; +} + +.horizontal-button-container { + margin-top: 10px; +} +.horizontal-button-container button:focus { + outline: 0; +} \ No newline at end of file diff --git a/scripts/developer/characterSmoothing/ui/index.html b/scripts/developer/characterSmoothing/ui/index.html new file mode 100644 index 0000000000..6d745b177a --- /dev/null +++ b/scripts/developer/characterSmoothing/ui/index.html @@ -0,0 +1,43 @@ + + + + + + + + + +
+ +
+ + +
+ + + + + + diff --git a/scripts/developer/characterSmoothing/ui/index.js b/scripts/developer/characterSmoothing/ui/index.js new file mode 100644 index 0000000000..87010164bf --- /dev/null +++ b/scripts/developer/characterSmoothing/ui/index.js @@ -0,0 +1,107 @@ +// Helper functions +const qs = (target) => document.querySelector(target); +const qsa = (target) => document.querySelectorAll(target); + +// Message listeners +const _sendMessage = (message) => + EventBridge.emitWebEvent(JSON.stringify(message)); +EventBridge.scriptEventReceived.connect((message) => + newMessage(JSON.parse(message)) +); + +// Settings & data +let smoothing_settings = {}; + +function newMessage(message) { + if (message.action === "initialize") { + initialize(message.data); + } +} + +function initialize(data) { + smoothing_settings = data; + + // Clear all existing listings (if any) + qsa("body .target-list").forEach((item) => item.remove()); + + // Set state + if (smoothing_settings.enabled === false) _toggleEnabledFalse(); + if (smoothing_settings.enabled === true) _toggleEnabledTrue(); + + // For each target point + Object.keys(smoothing_settings.targets).forEach((target) => { + // Use the target data to build a listing + let template = qs("#target-template").content.cloneNode(true); + + template.querySelector(".container").dataset.name = target; + template.querySelector(".container-header").innerText = target; + + const rotation_area = template.querySelector('[data-value="rotation"]'); + const transform_area = template.querySelector( + '[data-value="transform"]' + ); + + rotation_area.querySelector("input").value = _fromDecimal( + smoothing_settings.targets[target].rotation + ); + transform_area.querySelector("input").value = _fromDecimal( + smoothing_settings.targets[target].transform + ); + + rotation_area.querySelector(".type-value").innerText = _formatPercent( + _fromDecimal(smoothing_settings.targets[target].rotation) + ); + transform_area.querySelector(".type-value").innerText = _formatPercent( + _fromDecimal(smoothing_settings.targets[target].transform) + ); + + rotation_area.querySelector("input").addEventListener("change", () => { + rotation_area.querySelector(".type-value").innerText = + _formatPercent(rotation_area.querySelector("input").value); + smoothing_settings.targets[target].rotation = _toDecimal( + rotation_area.querySelector("input").value + ); + }); + transform_area.querySelector("input").addEventListener("change", () => { + transform_area.querySelector(".type-value").innerText = + _formatPercent(transform_area.querySelector("input").value); + smoothing_settings.targets[target].transform = _toDecimal( + transform_area.querySelector("input").value + ); + }); + + // // Append our newly created child + qs("#target-list").appendChild(template); + }); +} + +qsa("input").forEach((button) => + button.addEventListener("click", (event) => event.target.blur()) +); + +function toggleSmoothing() { + if (smoothing_settings.enabled) _toggleEnabledFalse(); + else _toggleEnabledTrue(); +} + +function _toggleEnabledFalse() { + _sendMessage({ action: "set_state", data: false }); + qs("#toggle-button").classList.remove("bad"); + qs("#toggle-button").classList.add("good"); + qs("#toggle-button").innerText = "Enable"; + smoothing_settings.enabled = false; +} +function _toggleEnabledTrue() { + _sendMessage({ action: "set_state", data: true }); + qs("#toggle-button").classList.remove("good"); + qs("#toggle-button").classList.add("bad"); + qs("#toggle-button").innerText = "Disable"; + smoothing_settings.enabled = true; +} + +_sendMessage({ action: "ready" }); +const applySettings = () => + _sendMessage({ action: "new_settings", data: smoothing_settings }); +const _formatPercent = (value) => parseInt(value).toString() + " %"; +const _toDecimal = (value) => value / 100; +const _fromDecimal = (value) => value * 100; diff --git a/scripts/developer/characterSmoothing/ui/index.scss b/scripts/developer/characterSmoothing/ui/index.scss new file mode 100644 index 0000000000..acfd97f7a5 --- /dev/null +++ b/scripts/developer/characterSmoothing/ui/index.scss @@ -0,0 +1,47 @@ +body { + font-family: Verdana, Geneva, Tahoma, sans-serif; +} + +.container { + margin-bottom: 10px; + + .content { + .type { + display: grid; + grid-template-columns: 1fr 3fr 1fr; + grid-template-rows: 1fr 1fr; + width: 100%; + + span { + margin: 0 10px; + } + + .header { + grid-column-start: 1; + grid-column-end: 3; + } + + .type-value { + text-align: center; + } + + input { + width: 100%; + grid-column-start: 1; + grid-column-end: 3; + } + } + } +} + +.container:last-child { + margin-bottom: 0; +} + +.horizontal-button-container { + margin-top: 10px; + + button:focus{ + outline: 0; + } +} diff --git a/scripts/developer/characterSmoothing/ui/theme.css b/scripts/developer/characterSmoothing/ui/theme.css new file mode 100644 index 0000000000..f45b4bdf8b --- /dev/null +++ b/scripts/developer/characterSmoothing/ui/theme.css @@ -0,0 +1,75 @@ +body { + margin: 2px; + box-sizing: border-box; + background-color: #101010; + font-size: 16px; + color: white; +} + +.color-primary { + background-color: #212121; +} + +.color-secondary { + background-color: #333333; +} + +.color-tertiary { + background-color: #454545; +} + +.container { + width: 100%; + min-height: 2px; +} +.container .container-header { + font-size: 18px; + padding: 0.5rem 1rem; + box-sizing: border-box; + margin-bottom: 5px; +} +.container .content { + padding: 0 10px; +} + +.horizontal-button-container { + display: flex; + flex-direction: row; +} +.horizontal-button-container button { + width: 100%; + margin: auto; + margin-right: 10px; +} +.horizontal-button-container button:last-child { + margin-right: 0; +} + +button { + border: 0; + padding: 1rem; + box-sizing: border-box; + background-color: #696e6f; + color: white; + cursor: pointer; +} + +button:hover { + filter: brightness(70%); +} + +button:active { + filter: brightness(50%); +} + +button.good { + background-color: #077e30; +} + +button.bad { + background-color: #771d1d; +} + +button.generic { + background-color: #505186; +} \ No newline at end of file From e4c453eba2e162bcbf65da53c5e0798b2c50aea8 Mon Sep 17 00:00:00 2001 From: ArmoredDragon <43324896+Armored-Dragon@users.noreply.github.com> Date: Tue, 22 Aug 2023 16:03:59 -0500 Subject: [PATCH 4/4] Recreated exponentialFilter and accelerationFilter. Moved them to script-archive --- script-archive/accelerationFilterApp.js | 221 ++++++++++++++++++++++ script-archive/exponentialFilterApp.js | 239 ++++++++++++++++++++++++ 2 files changed, 460 insertions(+) create mode 100644 script-archive/accelerationFilterApp.js create mode 100644 script-archive/exponentialFilterApp.js diff --git a/script-archive/accelerationFilterApp.js b/script-archive/accelerationFilterApp.js new file mode 100644 index 0000000000..7bde13ad28 --- /dev/null +++ b/script-archive/accelerationFilterApp.js @@ -0,0 +1,221 @@ +var LEFT_HAND_INDEX = 0; +var RIGHT_HAND_INDEX = 1; +var LEFT_FOOT_INDEX = 2; +var RIGHT_FOOT_INDEX = 3; +var HIPS_INDEX = 4; +var SPINE2_INDEX = 5; + +var mappingJson = { + name: "com.highfidelity.testing.accelerationTest", + channels: [ + { + from: "Standard.LeftHand", + to: "Actions.LeftHand", + filters: [ + { + type: "accelerationLimiter", + rotationAccelerationLimit: 2000.0, + translationAccelerationLimit: 100.0, + } + ] + }, + { + from: "Standard.RightHand", + to: "Actions.RightHand", + filters: [ + { + type: "accelerationLimiter", + rotationAccelerationLimit: 2000.0, + translationAccelerationLimit: 100.0, + } + ] + }, + { + from: "Standard.LeftFoot", + to: "Actions.LeftFoot", + filters: [ + { + type: "accelerationLimiter", + rotationAccelerationLimit: 2000.0, + translationAccelerationLimit: 100.0, + } + ] + }, + { + from: "Standard.RightFoot", + to: "Actions.RightFoot", + filters: [ + { + type: "accelerationLimiter", + rotationAccelerationLimit: 2000.0, + translationAccelerationLimit: 100.0, + } + ] + }, + { + from: "Standard.Hips", + to: "Actions.Hips", + filters: [ + { + type: "accelerationLimiter", + rotationAccelerationLimit: 2000.0, + translationAccelerationLimit: 100.0, + } + ] + }, + { + from: "Standard.Spine2", + to: "Actions.Spine2", + filters: [ + { + type: "accelerationLimiter", + rotationAccelerationLimit: 2000.0, + translationAccelerationLimit: 100.0, + } + ] + } + ] +}; + +// +// tablet app boiler plate +// + +var TABLET_BUTTON_NAME = "ACCFILT"; +var HTML_URL = Script.getExternalPath(Script.ExternalPaths.HF_Public, "/tony/html/accelerationFilterApp.html?2"); + +var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); +var tabletButton = tablet.addButton({ + text: TABLET_BUTTON_NAME, + icon: Script.getExternalPath(Script.ExternalPaths.HF_Public, "/tony/icons/tpose-i.svg"), + activeIcon: Script.getExternalPath(Script.ExternalPaths.HF_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); + shownChanged(true); + } + shown = true; + } else { + tabletButton.editProperties({isActive: false}); + if (shown) { + // disconnect from event bridge + tablet.webEventReceived.disconnect(onWebEventReceived); + shownChanged(false); + } + shown = false; + } +} + +function getTranslationAccelerationLimit(i) { + return mappingJson.channels[i].filters[0].translationAccelerationLimit; +} +function setTranslationAccelerationLimit(i, value) { + mappingJson.channels[i].filters[0].translationAccelerationLimit = value; + mappingChanged(); +} +function getRotationAccelerationLimit(i) { + return mappingJson.channels[i].filters[0].rotationAccelerationLimit; +} +function setRotationAccelerationLimit(i, value) { + mappingJson.channels[i].filters[0].rotationAccelerationLimit = value; mappingChanged(); +} + +function onWebEventReceived(msg) { + if (msg.name === "init-complete") { + var values = [ + {name: "left-hand-translation-acceleration-limit", val: getTranslationAccelerationLimit(LEFT_HAND_INDEX), checked: false}, + {name: "left-hand-rotation-acceleration-limit", val: getRotationAccelerationLimit(LEFT_HAND_INDEX), checked: false}, + {name: "right-hand-translation-acceleration-limit", val: getTranslationAccelerationLimit(RIGHT_HAND_INDEX), checked: false}, + {name: "right-hand-rotation-acceleration-limit", val: getRotationAccelerationLimit(RIGHT_HAND_INDEX), checked: false}, + {name: "left-foot-translation-acceleration-limit", val: getTranslationAccelerationLimit(LEFT_FOOT_INDEX), checked: false}, + {name: "left-foot-rotation-acceleration-limit", val: getRotationAccelerationLimit(LEFT_FOOT_INDEX), checked: false}, + {name: "right-foot-translation-acceleration-limit", val: getTranslationAccelerationLimit(RIGHT_FOOT_INDEX), checked: false}, + {name: "right-foot-rotation-acceleration-limit", val: getRotationAccelerationLimit(RIGHT_FOOT_INDEX), checked: false}, + {name: "hips-translation-acceleration-limit", val: getTranslationAccelerationLimit(HIPS_INDEX), checked: false}, + {name: "hips-rotation-acceleration-limit", val: getRotationAccelerationLimit(HIPS_INDEX), checked: false}, + {name: "spine2-translation-acceleration-limit", val: getTranslationAccelerationLimit(SPINE2_INDEX), checked: false}, + {name: "spine2-rotation-acceleration-limit", val: getRotationAccelerationLimit(SPINE2_INDEX), checked: false} + ]; + tablet.emitScriptEvent(JSON.stringify(values)); + } else if (msg.name === "left-hand-translation-acceleration-limit") { + setTranslationAccelerationLimit(LEFT_HAND_INDEX, parseInt(msg.val, 10)); + } else if (msg.name === "left-hand-rotation-acceleration-limit") { + setRotationAccelerationLimit(LEFT_HAND_INDEX, parseInt(msg.val, 10)); + } else if (msg.name === "right-hand-translation-acceleration-limit") { + setTranslationAccelerationLimit(RIGHT_HAND_INDEX, parseInt(msg.val, 10)); + } else if (msg.name === "right-hand-rotation-acceleration-limit") { + setRotationAccelerationLimit(RIGHT_HAND_INDEX, parseInt(msg.val, 10)); + } else if (msg.name === "left-foot-translation-acceleration-limit") { + setTranslationAccelerationLimit(LEFT_FOOT_INDEX, parseInt(msg.val, 10)); + } else if (msg.name === "left-foot-rotation-acceleration-limit") { + setRotationAccelerationLimit(LEFT_FOOT_INDEX, parseInt(msg.val, 10)); + } else if (msg.name === "right-foot-translation-acceleration-limit") { + setTranslationAccelerationLimit(RIGHT_FOOT_INDEX, parseInt(msg.val, 10)); + } else if (msg.name === "right-foot-rotation-acceleration-limit") { + setRotationAccelerationLimit(RIGHT_FOOT_INDEX, parseInt(msg.val, 10)); + } else if (msg.name === "hips-translation-acceleration-limit") { + setTranslationAccelerationLimit(HIPS_INDEX, parseInt(msg.val, 10)); + } else if (msg.name === "hips-rotation-acceleration-limit") { + setRotationAccelerationLimit(HIPS_INDEX, parseInt(msg.val, 10)); + } else if (msg.name === "spine2-translation-acceleration-limit") { + setTranslationAccelerationLimit(SPINE2_INDEX, parseInt(msg.val, 10)); + } else if (msg.name === "spine2-rotation-acceleration-limit") { + setRotationAccelerationLimit(SPINE2_INDEX, parseInt(msg.val, 10)); + } +} + +tablet.screenChanged.connect(onScreenChanged); + +function shutdownTabletApp() { + tablet.removeButton(tabletButton); + if (shown) { + tablet.webEventReceived.disconnect(onWebEventReceived); + tablet.gotoHomeScreen(); + } + tablet.screenChanged.disconnect(onScreenChanged); +} + +// +// end tablet app boiler plate +// + +var mapping; +function mappingChanged() { + if (mapping) { + mapping.disable(); + } + mapping = Controller.parseMapping(JSON.stringify(mappingJson)); + mapping.enable(); +} + +function shownChanged(newShown) { + if (newShown) { + mappingChanged(); + } else { + mapping.disable(); + } +} + +mappingChanged(); + +Script.scriptEnding.connect(function() { + if (mapping) { + mapping.disable(); + } + tablet.removeButton(tabletButton); +}); diff --git a/script-archive/exponentialFilterApp.js b/script-archive/exponentialFilterApp.js new file mode 100644 index 0000000000..86b4f3032d --- /dev/null +++ b/script-archive/exponentialFilterApp.js @@ -0,0 +1,239 @@ +var LEFT_HAND_INDEX = 0; +var RIGHT_HAND_INDEX = 1; +var LEFT_FOOT_INDEX = 2; +var RIGHT_FOOT_INDEX = 3; +var HIPS_INDEX = 4; +var SPINE2_INDEX = 5; + +var HAND_SMOOTHING_TRANSLATION = 0.3; +var HAND_SMOOTHING_ROTATION = 0.15; +var FOOT_SMOOTHING_TRANSLATION = 0.3; +var FOOT_SMOOTHING_ROTATION = 0.15; +var TORSO_SMOOTHING_TRANSLATION = 0.3; +var TORSO_SMOOTHING_ROTATION = 0.16; + +var mappingJson = { + name: "com.highfidelity.testing.exponentialFilterApp", + channels: [ + { + from: "Standard.LeftHand", + to: "Actions.LeftHand", + filters: [ + { + type: "exponentialSmoothing", + translation: HAND_SMOOTHING_TRANSLATION, + rotation: HAND_SMOOTHING_ROTATION + } + ] + }, + { + from: "Standard.RightHand", + to: "Actions.RightHand", + filters: [ + { + type: "exponentialSmoothing", + translation: HAND_SMOOTHING_TRANSLATION, + rotation: HAND_SMOOTHING_ROTATION + } + ] + }, + { + from: "Standard.LeftFoot", + to: "Actions.LeftFoot", + filters: [ + { + type: "exponentialSmoothing", + translation: FOOT_SMOOTHING_TRANSLATION, + rotation: FOOT_SMOOTHING_ROTATION + } + ] + }, + { + from: "Standard.RightFoot", + to: "Actions.RightFoot", + filters: [ + { + type: "exponentialSmoothing", + translation: FOOT_SMOOTHING_TRANSLATION, + rotation: FOOT_SMOOTHING_ROTATION + } + ] + }, + { + from: "Standard.Hips", + to: "Actions.Hips", + filters: [ + { + type: "exponentialSmoothing", + translation: TORSO_SMOOTHING_TRANSLATION, + rotation: TORSO_SMOOTHING_ROTATION + } + ] + }, + { + from: "Standard.Spine2", + to: "Actions.Spine2", + filters: [ + { + type: "exponentialSmoothing", + translation: TORSO_SMOOTHING_TRANSLATION, + rotation: TORSO_SMOOTHING_ROTATION + } + ] + } + ] +}; + +// +// tablet app boiler plate +// + +var TABLET_BUTTON_NAME = "EXPFILT"; +var HTML_URL = Script.getExternalPath(Script.ExternalPaths.HF_Public, "/tony/html/exponentialFilterApp.html?7"); + +var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); +var tabletButton = tablet.addButton({ + text: TABLET_BUTTON_NAME, + icon: Script.getExternalPath(Script.ExternalPaths.HF_Public, "/tony/icons/tpose-i.svg"), + activeIcon: Script.getExternalPath(Script.ExternalPaths.HF_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); + shownChanged(true); + } + shown = true; + } else { + tabletButton.editProperties({isActive: false}); + if (shown) { + // disconnect from event bridge + tablet.webEventReceived.disconnect(onWebEventReceived); + shownChanged(false); + } + shown = false; + } +} + +function getTranslation(i) { + return mappingJson.channels[i].filters[0].translation; +} +function setTranslation(i, value) { + mappingJson.channels[i].filters[0].translation = value; + mappingChanged(); +} +function getRotation(i) { + return mappingJson.channels[i].filters[0].rotation; +} +function setRotation(i, value) { + mappingJson.channels[i].filters[0].rotation = value; mappingChanged(); +} + +function onWebEventReceived(msg) { + if (msg.name === "init-complete") { + var values = [ + {name: "enable-filtering", val: filterEnabled ? "on" : "off", checked: false}, + {name: "left-hand-translation", val: getTranslation(LEFT_HAND_INDEX), checked: false}, + {name: "left-hand-rotation", val: getRotation(LEFT_HAND_INDEX), checked: false}, + {name: "right-hand-translation", val: getTranslation(RIGHT_HAND_INDEX), checked: false}, + {name: "right-hand-rotation", val: getRotation(RIGHT_HAND_INDEX), checked: false}, + {name: "left-foot-translation", val: getTranslation(LEFT_FOOT_INDEX), checked: false}, + {name: "left-foot-rotation", val: getRotation(LEFT_FOOT_INDEX), checked: false}, + {name: "right-foot-translation", val: getTranslation(RIGHT_FOOT_INDEX), checked: false}, + {name: "right-foot-rotation", val: getRotation(RIGHT_FOOT_INDEX), checked: false}, + {name: "hips-translation", val: getTranslation(HIPS_INDEX), checked: false}, + {name: "hips-rotation", val: getRotation(HIPS_INDEX), checked: false}, + {name: "spine2-translation", val: getTranslation(SPINE2_INDEX), checked: false}, + {name: "spine2-rotation", val: getRotation(SPINE2_INDEX), checked: false} + ]; + tablet.emitScriptEvent(JSON.stringify(values)); + } else if (msg.name === "enable-filtering") { + if (msg.val === "on") { + filterEnabled = true; + } else if (msg.val === "off") { + filterEnabled = false; + } + mappingChanged(); + } else if (msg.name === "left-hand-translation") { + setTranslation(LEFT_HAND_INDEX, Number(msg.val)); + } else if (msg.name === "left-hand-rotation") { + setRotation(LEFT_HAND_INDEX, Number(msg.val)); + } else if (msg.name === "right-hand-translation") { + setTranslation(RIGHT_HAND_INDEX, Number(msg.val)); + } else if (msg.name === "right-hand-rotation") { + setRotation(RIGHT_HAND_INDEX, Number(msg.val)); + } else if (msg.name === "left-foot-translation") { + setTranslation(LEFT_FOOT_INDEX, Number(msg.val)); + } else if (msg.name === "left-foot-rotation") { + setRotation(LEFT_FOOT_INDEX, Number(msg.val)); + } else if (msg.name === "right-foot-translation") { + setTranslation(RIGHT_FOOT_INDEX, Number(msg.val)); + } else if (msg.name === "right-foot-rotation") { + setRotation(RIGHT_FOOT_INDEX, Number(msg.val)); + } else if (msg.name === "hips-translation") { + setTranslation(HIPS_INDEX, Number(msg.val)); + } else if (msg.name === "hips-rotation") { + setRotation(HIPS_INDEX, Number(msg.val)); + } else if (msg.name === "spine2-translation") { + setTranslation(SPINE2_INDEX, Number(msg.val)); + } else if (msg.name === "spine2-rotation") { + setRotation(SPINE2_INDEX, Number(msg.val)); + } +} + +tablet.screenChanged.connect(onScreenChanged); + +function shutdownTabletApp() { + tablet.removeButton(tabletButton); + if (shown) { + tablet.webEventReceived.disconnect(onWebEventReceived); + tablet.gotoHomeScreen(); + } + tablet.screenChanged.disconnect(onScreenChanged); +} + +// +// end tablet app boiler plate +// + +var filterEnabled = true; +var mapping; +function mappingChanged() { + if (mapping) { + mapping.disable(); + } + if (filterEnabled) { + mapping = Controller.parseMapping(JSON.stringify(mappingJson)); + mapping.enable(); + } +} + +function shownChanged(newShown) { + if (newShown) { + mappingChanged(); + } else { + mapping.disable(); + } +} + +mappingChanged(); + +Script.scriptEnding.connect(function() { + if (mapping) { + mapping.disable(); + } + tablet.removeButton(tabletButton); +});