Skip to content

Commit

Permalink
Merge pull request #78 from AleziaKurdis/App-hmd3rdPerson
Browse files Browse the repository at this point in the history
New application: "HMD 3rd Person View" (quick toggler button)
  • Loading branch information
ksuprynowicz authored Jun 9, 2024
2 parents 3ad1b98 + c70f384 commit 0360a1a
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
112 changes: 112 additions & 0 deletions applications/hmd3rdPerson/app-hmd3rdPerson.js
Original file line number Diff line number Diff line change
@@ -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);
}
}());
Binary file added applications/hmd3rdPerson/icon_active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added applications/hmd3rdPerson/icon_inactive_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added applications/hmd3rdPerson/icon_inactive_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions applications/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
};

0 comments on commit 0360a1a

Please sign in to comment.