diff --git a/applications/aaswitcher/FiraSans-SemiBold.ttf b/applications/aaswitcher/FiraSans-SemiBold.ttf new file mode 100644 index 0000000..821a43d Binary files /dev/null and b/applications/aaswitcher/FiraSans-SemiBold.ttf differ diff --git a/applications/aaswitcher/aaSwitcher.html b/applications/aaswitcher/aaSwitcher.html new file mode 100644 index 0000000..5cb355d --- /dev/null +++ b/applications/aaswitcher/aaSwitcher.html @@ -0,0 +1,144 @@ + + + + + + + + + +

ANTI-ALIASING SWITCHER

+
+

+

HMD:

+ None
+ TAA
+ FXAA
+
+

DESKTOP:

+ None
+ TAA
+ FXAA
+ + + diff --git a/applications/aaswitcher/app-aaSwitcher.js b/applications/aaswitcher/app-aaSwitcher.js new file mode 100644 index 0000000..c828792 --- /dev/null +++ b/applications/aaswitcher/app-aaSwitcher.js @@ -0,0 +1,155 @@ +"use strict"; +// +// app-aaSwitcher.js +// +// Created by Alezia Kurdis, April 7th 2022. +// Copyright 2022 Overte e.V. +// +// This application let you setup different Anti-Aliasing setup for HMD and Desktop. +// And it switches the configuration when the mode changes. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +(function() { + var jsMainFileName = "app-aaSwitcher.js"; + var ROOT = Script.resolvePath('').split(jsMainFileName)[0]; + + var APP_NAME = "AA-SWITCH"; + var APP_URL = ROOT + "aaSwitcher.html"; + var APP_ICON_INACTIVE = ROOT + "icon_inactive.png"; + var APP_ICON_ACTIVE = ROOT + "icon_active.png"; + var appStatus = false; + + var isActive = "OFF"; + var hmdAA = "1"; + var desktopAA = "1"; + var SETTING_AASWITCHER = "application_aaSwitcher"; + var channel = "com.overte.aaswitcher"; + var timestamp = 0; + var INTERCALL_DELAY = 200; //0.3 sec + + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + + tablet.screenChanged.connect(onScreenChanged); + + var button = tablet.addButton({ + text: APP_NAME, + icon: APP_ICON_INACTIVE, + activeIcon: APP_ICON_ACTIVE + }); + + + function clicked(){ + if (appStatus === true) { + tablet.webEventReceived.disconnect(onAppWebEventReceived); + tablet.gotoHomeScreen(); + appStatus = false; + }else{ + loadSetting(); + var uIurl = APP_URL + "?isActive=" + isActive + "&hmdAA=" + hmdAA + "&desktopAA=" + desktopAA; + tablet.gotoWebScreen(uIurl); + tablet.webEventReceived.connect(onAppWebEventReceived); + appStatus = true; + } + + button.editProperties({ + isActive: appStatus + }); + } + + button.clicked.connect(clicked); + + + function onAppWebEventReceived(message) { + var d = new Date(); + var n = d.getTime(); + + var messageObj = JSON.parse(message); + if (messageObj.channel === channel) { + if (messageObj.action === "HMDAA" && (n - timestamp) > INTERCALL_DELAY) { + d = new Date(); + timestamp = d.getTime(); + hmdAA = messageObj.value; + setAAbasedOnMode(); + saveSetting(); + } else if (messageObj.action === "DESKTOPAA" && (n - timestamp) > INTERCALL_DELAY) { + d = new Date(); + timestamp = d.getTime(); + desktopAA = messageObj.value; + setAAbasedOnMode(); + saveSetting(); + } else if (messageObj.action === "ACTIVATION" && (n - timestamp) > INTERCALL_DELAY) { + d = new Date(); + timestamp = d.getTime(); + isActive = messageObj.value; + if (isActive === "ON") { + setAAbasedOnMode(); + } + saveSetting(); + } + } + } + + HMD.displayModeChanged.connect(function (isHMDMode) { + setAAbasedOnMode(); + }); + + function setAAbasedOnMode() { + var aaValue = 0; + if (isActive === "ON") { + if (HMD.active) { + aaValue = parseInt(hmdAA); + } else { + aaValue = parseInt(desktopAA); + } + Render.antialiasingMode = aaValue; + } + } + + function onScreenChanged(type, url) { + if (type === "Web" && url.indexOf(APP_URL) !== -1) { + appStatus = true; + } else { + appStatus = false; + } + + button.editProperties({ + isActive: appStatus + }); + } + + function cleanup() { + + if (appStatus) { + tablet.gotoHomeScreen(); + tablet.webEventReceived.disconnect(onMoreAppWebEventReceived); + } + + tablet.screenChanged.disconnect(onScreenChanged); + tablet.removeButton(button); + } + + function loadSetting() { + var settings = Settings.getValue(SETTING_AASWITCHER, []); + if (JSON.stringify(settings) !== "[]") { + isActive = settings.isActive; + hmdAA = settings.hmdAA; + desktopAA = settings.desktopAA; + } + } + + function saveSetting() { + var data = { + "isActive": isActive, + "hmdAA": hmdAA, + "desktopAA": desktopAA + }; + Settings.setValue(SETTING_AASWITCHER, data); + } + + Script.scriptEnding.connect(cleanup); + + loadSetting(); + +}()); diff --git a/applications/aaswitcher/icon_active.png b/applications/aaswitcher/icon_active.png new file mode 100644 index 0000000..640f086 Binary files /dev/null and b/applications/aaswitcher/icon_active.png differ diff --git a/applications/aaswitcher/icon_inactive.png b/applications/aaswitcher/icon_inactive.png new file mode 100644 index 0000000..44a26b1 Binary files /dev/null and b/applications/aaswitcher/icon_inactive.png differ diff --git a/applications/metadata.js b/applications/metadata.js index 9c5f33b..231db82 100644 --- a/applications/metadata.js +++ b/applications/metadata.js @@ -117,6 +117,15 @@ var metadata = { "applications": "icon": "odometer/appicon_i.png", "caption": "ODOMETER" }, + { + "isActive": true, + "directory": "aaswitcher", + "name": "Anti-Aliasing Switcher", + "description": "Allow different Anti-Aliasing configuration for HMD and Desktop. This application changes automatically the Anti-Aliasing configuration as you put on or remove your VR Headset.", + "jsfile": "aaswitcher/app-aaSwitcher.js", + "icon": "aaswitcher/icon_inactive.png", + "caption": "AA-SWITCH" + }, { "isActive": true, "directory": "notes",