diff --git a/applications/hmd3rdPerson/app-hmd3rdPerson.js b/applications/hmd3rdPerson/app-hmd3rdPerson.js new file mode 100644 index 0000000..3cceabb --- /dev/null +++ b/applications/hmd3rdPerson/app-hmd3rdPerson.js @@ -0,0 +1,112 @@ +// +// app-hmd3rdPerson.js +// +// Created by Alezia Kurdis, May 8th 2024. +// Copyright 2024 Overte e.V. +// +// This application add a button to switch to 3rd Person View in HDM (witout reseting the camera distance) +// +// 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-hmd3rdPerson.js"; + var ROOT = Script.resolvePath('').split(jsMainFileName)[0]; + + var APP_ICON_INACTIVE = ROOT + "icon_inactive_white.png"; + var ICON_CAPTION_COLOR = "#FFFFFF"; + if (ROOT.substr(0, 4) !== "http") { + APP_ICON_INACTIVE = ROOT + "icon_inactive_green.png"; + ICON_CAPTION_COLOR = "#00FF00"; + } + var APP_ICON_ACTIVE = ROOT + "icon_active.png"; + var APP_SORT_ORDER = 4; + var APP_NAME = "3rd PERS"; + var appStatus = false; + + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + + var button = null; + + function clicked(){ + if (HMD.active) { + var colorCaption; + if (appStatus === true) { + setFirstPersonView(); + colorCaption = ICON_CAPTION_COLOR; + appStatus = false; + }else{ + setThirdPersonView(); + colorCaption = "#000000"; + appStatus = true; + } + + button.editProperties({ + "isActive": appStatus, + "captionColor": colorCaption + }); + } else { + Window.displayAnnouncement("This is only effective in HMD."); + } + } + + function displayChange(isHMDMode) { + print("Display mode changed"); + print("isHMD = " + isHMDMode); + print("HMD.active = " + HMD.active); + print("HMD.mounted = " + HMD.mounted); + if (isHMDMode) { + if (button === null) { + button = tablet.addButton({ + "text": APP_NAME, + "icon": APP_ICON_INACTIVE, + "activeIcon": APP_ICON_ACTIVE, + "captionColor": ICON_CAPTION_COLOR, + "sortOrder": APP_SORT_ORDER + }); + button.clicked.connect(clicked); + } + } else { + if (button !== null) { + button.clicked.disconnect(clicked); + tablet.removeButton(button); + button = null; + } + } + } + + function setFirstPersonView() { + Camera.mode = "first person look at"; + } + + function setThirdPersonView() { + Camera.mode = "third person"; + } + + HMD.displayModeChanged.connect(displayChange); + + function cleanup() { + if (appStatus) { + setFirstPersonView(); + } + if (HMD.active) { + button.clicked.disconnect(clicked); + tablet.removeButton(button); + button = null; + } + HMD.displayModeChanged.disconnect(displayChange); + } + + Script.scriptEnding.connect(cleanup); + + if (HMD.active) { + button = tablet.addButton({ + "text": APP_NAME, + "icon": APP_ICON_INACTIVE, + "activeIcon": APP_ICON_ACTIVE, + "captionColor": ICON_CAPTION_COLOR, + "sortOrder": APP_SORT_ORDER + }); + button.clicked.connect(clicked); + } +}()); diff --git a/applications/hmd3rdPerson/icon_active.png b/applications/hmd3rdPerson/icon_active.png new file mode 100644 index 0000000..7c8f21d Binary files /dev/null and b/applications/hmd3rdPerson/icon_active.png differ diff --git a/applications/hmd3rdPerson/icon_inactive_green.png b/applications/hmd3rdPerson/icon_inactive_green.png new file mode 100644 index 0000000..d0df85f Binary files /dev/null and b/applications/hmd3rdPerson/icon_inactive_green.png differ diff --git a/applications/hmd3rdPerson/icon_inactive_white.png b/applications/hmd3rdPerson/icon_inactive_white.png new file mode 100644 index 0000000..bbb6561 Binary files /dev/null and b/applications/hmd3rdPerson/icon_inactive_white.png differ diff --git a/applications/metadata.js b/applications/metadata.js index e26114e..6507bad 100644 --- a/applications/metadata.js +++ b/applications/metadata.js @@ -332,6 +332,15 @@ var metadata = { "applications": "jsfile": "domainMapper/app-domainMapper.js", "icon": "domainMapper/icon_inactive_white.png", "caption": "DOMAP" + }, + { + "isActive": true, + "directory": "hmd3rdPerson", + "name": "HMD 3rd Person View", + "description": "This application adds a button on your tablet to toggle rapidly between 1st and 3rd person view in HMD. It also prevents the distance of the 3rd person camera to be reset as the 'View' menu does. This application is only visible in HMD. It can be useful for people who want to capture their avatar performance in HMD while they are in movement.", + "jsfile": "hmd3rdPerson/app-hmd3rdPerson.js", + "icon": "hmd3rdPerson/icon_inactive_white.png", + "caption": "3rd PERS" } ] }; \ No newline at end of file