Add "Anti-Aliasing Switcher" application

Add "Anti-Aliasing Switcher" application
This commit is contained in:
Alezia Kurdis 2022-07-13 22:06:12 -04:00 committed by GitHub
parent 897ca71ad5
commit 8d76dbdf1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 310 additions and 2 deletions

Binary file not shown.

View file

@ -0,0 +1,144 @@
<!DOCTYPE html>
<!--
aaSwitcher.html
Created by Alezia Kurdis, April 7th 2022.
Copyright 2022 Overte e.V.
This application UI let you setup different Anti-Aliasing setup for HMD and Desktop.
Distributed under the Apache License, Version 2.0.
See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
-->
<html>
<head>
<meta charset="UTF-8">
<script>
//Parameters
function findGetParameter(parameterName) {
var result = null,
tmp = [];
var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
return result;
}
//Paths
var thisPageName = "aaSwitcher.html";
var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname;
var ROOTPATH = currentPath.replace(thisPageName, "");
var channel = "com.overte.aaswitcher";
</script>
<style>
@font-face {
font-family: FiraSans-SemiBold;
src: url(FiraSans-SemiBold.ttf);
}
body {
background: #3b424a;
font-family: FiraSans-SemiBold;
font-size: 12px;
color: #FFFFFF;
text-decoration: none;
font-style: normal;
font-variant: normal;
text-transform: none;
}
</style>
</head>
<body>
<div style="width:100%; text-align:center;"><h1 style='color:#FFFF00;'>ANTI-ALIASING SWITCHER</h1></div>
<hr>
<div id='activeMode'></div><hr>
<h1>HMD:</h1>
<input type = "radio" id="hmdAA0" name="hmdAA" onclick="checkHmdAA(this.value);" value = "0">None<br>
<input type = "radio" id="hmdAA1" name="hmdAA" onclick="checkHmdAA(this.value);" value = "1">TAA<br>
<input type = "radio" id="hmdAA2" name="hmdAA" onclick="checkHmdAA(this.value);" value = "2">FXAA<br>
<hr>
<h1>DESKTOP:</h1>
<input type = "radio" id="desktopAA0" name="desktopAA" onclick="checkDesktopAA(this.value);" value = "0">None<br>
<input type = "radio" id="desktopAA1" name="desktopAA" onclick="checkDesktopAA(this.value);" value = "1">TAA<br>
<input type = "radio" id="desktopAA2" name="desktopAA" onclick="checkDesktopAA(this.value);" value = "2">FXAA<br>
<script>
function setForm() {
document.getElementById("hmdAA0").checked = false;
document.getElementById("hmdAA1").checked = false;
document.getElementById("hmdAA2").checked = false;
var currentRadio = "hmdAA" + hmdAA;
document.getElementById(currentRadio).checked = true;
document.getElementById("desktopAA0").checked = false;
document.getElementById("desktopAA1").checked = false;
document.getElementById("desktopAA2").checked = false;
currentRadio = "desktopAA" + desktopAA;
document.getElementById(currentRadio).checked = true;
if (isActive === "ON") {
document.getElementById("activeMode").innerHTML = "<h1 style='color:#00ff00;'>ON</h1><button type='button' onclick='activator();'>Deactivate</button>";
} else {
document.getElementById("activeMode").innerHTML = "<h1 style='color:#ff2200;'>OFF</h1><button type='button' onclick='activator();'>Activate</button>";
}
}
function checkHmdAA(value) {
hmdAA = value;
var goSignal = {
"channel": channel,
"action": "HMDAA",
"value": hmdAA
};
EventBridge.emitWebEvent(JSON.stringify(goSignal));
}
function checkDesktopAA(value) {
desktopAA = value;
var goSignal = {
"channel": channel,
"action": "DESKTOPAA",
"value": desktopAA
};
EventBridge.emitWebEvent(JSON.stringify(goSignal));
}
function activator() {
if (isActive === "ON") {
isActive = "OFF";
} else {
isActive = "ON";
}
var goSignal = {
"channel": channel,
"action": "ACTIVATION",
"value": isActive
};
EventBridge.emitWebEvent(JSON.stringify(goSignal));
setForm();
}
var hmdAA = findGetParameter("hmdAA");
if (hmdAA === "") {
hmdAA = "1";
}
var desktopAA = findGetParameter("desktopAA");
if (desktopAA === "") {
desktopAA = "1";
}
var isActive = findGetParameter("isActive");
if (isActive === "") {
isActive = "OFF";
}
setForm();
</script>
</body>
</html>

View file

@ -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();
}());

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -67,7 +67,7 @@ var metadata = { "applications":
"isActive": true,
"directory": "radar",
"name": "Radar",
"description": "Show where people are and teleport in the domain. <a href='http://ctrlaltstudio.com/vircadia/radar' target=`_blank`>More info...</a>",
"description": "Show where people are and teleport in the domain.",
"jsfile": "radar/radar.js",
"icon": "radar/assets/radar-i.svg",
"caption": "RADAR"
@ -85,7 +85,7 @@ var metadata = { "applications":
"isActive": true,
"directory": "nametags",
"name": "Nametags",
"description": "Display users' display names above their heads. <a href='http://ctrlaltstudio.com/vircadia/nametags' target=`_blank`>More info...</a>",
"description": "Display users' display names above their heads.",
"jsfile": "nametags/nametags.js",
"icon": "nametags/assets/nametags-i.svg",
"caption": "NAMETAGS"
@ -116,6 +116,15 @@ var metadata = { "applications":
"jsfile": "odometer/odometer.js",
"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"
}
]
};