Upgrade to local Entities and Misc

Upgrade to local Entities and Misc

- All the deprecated use of 3d overly has been changes to Local Entities (Only the addEntity)
- All the preview are now unlit (it was a pain in a dark place)
- The HMD has been repositionned to be visible. (This is a try, I think it is better)
- Many bug fix in HMD
- Added a setting to switch on/off the snapshot related notification (because they are often a nuisance during capture sessions. constantly present and appearing in the capture)

(The setting still need to be plugged in the admin.)
This commit is contained in:
Alezia Kurdis 2022-09-09 23:55:49 -04:00 committed by GitHub
parent 619e36e9a9
commit efa22b8fd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,21 +4,22 @@
// //
// notifications.js // notifications.js
// Version 0.801 // Version 0.801
// Created by Adrian
// //
// Adrian McCarlie 8-10-14 // Created by Adrian McCarlie October 8th, 2014
// This script demonstrates on-screen overlay type notifications.
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// Copyright 2022 Overte e.V.
// //
// This script demonstrates on-screen overlay type notifications.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// ############################################################################
// This script generates notifications created via a number of ways, such as: // This script generates notifications created via a number of ways, such as:
// keystroke: // keystroke:
// //
// CTRL/s for snapshot. // CTRL/s for snapshot.
//
// System generated notifications: // System generated notifications:
// Connection refused. // Connection refused.
// //
@ -74,13 +75,14 @@
var backgroundAlpha = 0; var backgroundAlpha = 0;
var fontSize = 12.0; var fontSize = 12.0;
var PERSIST_TIME_2D = 10.0; // Time in seconds before notification fades var PERSIST_TIME_2D = 10.0; // Time in seconds before notification fades
var PERSIST_TIME_3D = 15.0; var PERSIST_TIME_3D = 12.0;
var persistTime = PERSIST_TIME_2D; var persistTime = PERSIST_TIME_2D;
var frame = 0; var frame = 0;
var ctrlIsPressed = false; var ctrlIsPressed = false;
var ready = true; var ready = true;
var NOTIFICATION_MENU_ITEM_POST = " Notifications"; var NOTIFICATION_MENU_ITEM_POST = " Notifications";
var NOTIFICATIONS_MESSAGE_CHANNEL = "Hifi-Notifications"; var NOTIFICATIONS_MESSAGE_CHANNEL = "Hifi-Notifications";
var NOTIFICATION_ALPHA = 9.0; // On a scale of 10.
var NotificationType = { var NotificationType = {
UNKNOWN: 0, UNKNOWN: 0,
@ -129,13 +131,14 @@
var heights = []; var heights = [];
var myAlpha = []; var myAlpha = [];
var arrays = []; var arrays = [];
var isOnHMD = false, var isOnHMD = false,
NOTIFICATIONS_3D_DIRECTION = 0.0, // Degrees from avatar orientation. NOTIFICATIONS_3D_DIRECTION = -45.0, // Degrees from avatar orientation.
NOTIFICATIONS_3D_DISTANCE = 0.6, // Horizontal distance from avatar position. NOTIFICATIONS_3D_DISTANCE = 1.2, // Horizontal distance from avatar position.
NOTIFICATIONS_3D_ELEVATION = -0.8, // Height of top middle of top notification relative to avatar eyes. NOTIFICATIONS_3D_ELEVATION = 0.5, // Height of top middle of top notification relative to avatar eyes.
NOTIFICATIONS_3D_YAW = 0.0, // Degrees relative to notifications direction. NOTIFICATIONS_3D_YAW = 10.0, // Degrees relative to notifications direction.
NOTIFICATIONS_3D_PITCH = -60.0, // Degrees from vertical. NOTIFICATIONS_3D_PITCH = 0.0, // Degrees from vertical.
NOTIFICATION_3D_SCALE = 0.002, // Multiplier that converts 2D overlay dimensions to 3D overlay dimensions. NOTIFICATION_3D_SCALE = 0.0025, // Multiplier that converts 2D overlay dimensions to 3D overlay dimensions.
NOTIFICATION_3D_BUTTON_WIDTH = 40 * NOTIFICATION_3D_SCALE, // Need a little more room for button in 3D. NOTIFICATION_3D_BUTTON_WIDTH = 40 * NOTIFICATION_3D_SCALE, // Need a little more room for button in 3D.
overlay3DDetails = []; overlay3DDetails = [];
@ -164,9 +167,9 @@
pauseTimer = Script.setInterval(function () { pauseTimer = Script.setInterval(function () {
q += 1; q += 1;
qFade = q / 10.0; qFade = q / 10.0;
Overlays.editOverlay(noticeIn, { alpha: qFade }); Overlays.editOverlay(noticeIn, { "alpha": qFade, "backgroundAlpha": qFade, "textAlpha": qFade });
Overlays.editOverlay(buttonIn, { alpha: qFade }); Overlays.editOverlay(buttonIn, { "alpha": qFade });
if (q >= 9.0) { if (q >= NOTIFICATION_ALPHA) {
Script.clearInterval(pauseTimer); Script.clearInterval(pauseTimer);
} }
}, 10); }, 10);
@ -174,15 +177,15 @@
// this fades the notification ready for dismissal, and removes it from the arrays // this fades the notification ready for dismissal, and removes it from the arrays
function fadeOut(noticeOut, buttonOut, arraysOut) { function fadeOut(noticeOut, buttonOut, arraysOut) {
var r = 9.0, var r = NOTIFICATION_ALPHA,
rFade, rFade,
pauseTimer = null; pauseTimer = null;
pauseTimer = Script.setInterval(function () { pauseTimer = Script.setInterval(function () {
r -= 1; r -= 1;
rFade = Math.max(0.0, r / 10.0); rFade = Math.max(0.0, r / 10.0);
Overlays.editOverlay(noticeOut, { alpha: rFade }); Overlays.editOverlay(noticeOut, { "alpha": rFade, "backgroundAlpha": rFade, "textAlpha": rFade });
Overlays.editOverlay(buttonOut, { alpha: rFade }); Overlays.editOverlay(buttonOut, { "alpha": rFade });
if (r <= 0) { if (r <= 0) {
dismiss(noticeOut, buttonOut, arraysOut); dismiss(noticeOut, buttonOut, arraysOut);
arrays.splice(arraysOut, 1); arrays.splice(arraysOut, 1);
@ -206,14 +209,12 @@
buttonPosition = { x: sensorScaleFactor * (noticeWidth - NOTIFICATION_3D_BUTTON_WIDTH), y: noticeY, z: 0.001 }; buttonPosition = { x: sensorScaleFactor * (noticeWidth - NOTIFICATION_3D_BUTTON_WIDTH), y: noticeY, z: 0.001 };
// Rotate plane // Rotate plane
notificationOrientation = Quat.fromPitchYawRollDegrees(NOTIFICATIONS_3D_PITCH, notificationOrientation = Quat.fromPitchYawRollDegrees(NOTIFICATIONS_3D_PITCH, NOTIFICATIONS_3D_DIRECTION + NOTIFICATIONS_3D_YAW, 0);
NOTIFICATIONS_3D_DIRECTION + NOTIFICATIONS_3D_YAW, 0);
notificationPosition = Vec3.multiplyQbyV(notificationOrientation, notificationPosition); notificationPosition = Vec3.multiplyQbyV(notificationOrientation, notificationPosition);
buttonPosition = Vec3.multiplyQbyV(notificationOrientation, buttonPosition); buttonPosition = Vec3.multiplyQbyV(notificationOrientation, buttonPosition);
// Translate plane // Translate plane
originOffset = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, NOTIFICATIONS_3D_DIRECTION, 0), originOffset = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, NOTIFICATIONS_3D_DIRECTION, 0), { x: 0, y: 0, z: -NOTIFICATIONS_3D_DISTANCE * sensorScaleFactor});
{ x: 0, y: 0, z: -NOTIFICATIONS_3D_DISTANCE * sensorScaleFactor});
originOffset.y += NOTIFICATIONS_3D_ELEVATION * sensorScaleFactor; originOffset.y += NOTIFICATIONS_3D_ELEVATION * sensorScaleFactor;
notificationPosition = Vec3.sum(originOffset, notificationPosition); notificationPosition = Vec3.sum(originOffset, notificationPosition);
buttonPosition = Vec3.sum(originOffset, buttonPosition); buttonPosition = Vec3.sum(originOffset, buttonPosition);
@ -241,12 +242,12 @@
noticeWidth = notice.width * NOTIFICATION_3D_SCALE + NOTIFICATION_3D_BUTTON_WIDTH; noticeWidth = notice.width * NOTIFICATION_3D_SCALE + NOTIFICATION_3D_BUTTON_WIDTH;
noticeHeight = notice.height * NOTIFICATION_3D_SCALE; noticeHeight = notice.height * NOTIFICATION_3D_SCALE;
notice.size = { x: noticeWidth * sensorScaleFactor, y: noticeHeight * sensorScaleFactor }; notice.dimensions = { "x": noticeWidth * sensorScaleFactor, "y": noticeHeight * sensorScaleFactor, "z": 0.01 };
positions = calculate3DOverlayPositions(noticeWidth, noticeHeight, notice.y); positions = calculate3DOverlayPositions(noticeWidth, noticeHeight, notice.y);
notice.parentID = MyAvatar.sessionUUID; notice.parentID = MyAvatar.sessionUUID;
notice.parentJointIndex = -2; notice.parentJointIndex = -2;
notice.isVisibleInSecondaryCamera = false;
if (!image) { if (!image) {
notice.topMargin = 0.75 * notice.topMargin * NOTIFICATION_3D_SCALE * sensorScaleFactor; notice.topMargin = 0.75 * notice.topMargin * NOTIFICATION_3D_SCALE * sensorScaleFactor;
@ -254,12 +255,17 @@
notice.bottomMargin = 0; notice.bottomMargin = 0;
notice.rightMargin = 0; notice.rightMargin = 0;
notice.lineHeight = 10.0 * (fontSize * sensorScaleFactor / 12.0) * NOTIFICATION_3D_SCALE; notice.lineHeight = 10.0 * (fontSize * sensorScaleFactor / 12.0) * NOTIFICATION_3D_SCALE;
notice.isFacingAvatar = false; notice.billboardMode = "none";
notice.type = "Text";
notice.unlit = true;
notificationText = Overlays.addOverlay("text3d", notice); notificationText = Entities.addEntity(notice, "local");
notifications.push(notificationText); notifications.push(notificationText);
} else { } else {
notifications.push(Overlays.addOverlay("image3d", notice)); notice.type = "Image";
notice.emissive = true;
notifications.push(Entities.addEntity(notice, "local"));
} }
button.url = button.imageURL; button.url = button.imageURL;
@ -268,21 +274,23 @@
button.parentID = MyAvatar.sessionUUID; button.parentID = MyAvatar.sessionUUID;
button.parentJointIndex = -2; button.parentJointIndex = -2;
button.visible = false; button.visible = false;
button.type = "Image";
button.emissive = true;
button.isVisibleInSecondaryCamera = false;
buttons.push((Overlays.addOverlay("image3d", button))); buttons.push(Entities.addEntity(button, "local"));
overlay3DDetails.push({ overlay3DDetails.push({
notificationOrientation: positions.notificationOrientation, "notificationOrientation": positions.notificationOrientation,
notificationPosition: positions.notificationPosition, "notificationPosition": positions.notificationPosition,
buttonPosition: positions.buttonPosition, "buttonPosition": positions.buttonPosition,
width: noticeWidth * sensorScaleFactor, "width": noticeWidth * sensorScaleFactor,
height: noticeHeight * sensorScaleFactor "height": noticeHeight * sensorScaleFactor
}); });
var defaultEyePosition, var defaultEyePosition,
avatarOrientation, avatarOrientation,
notificationPosition, notificationPosition,
notificationOrientation,
buttonPosition, buttonPosition,
notificationIndex; notificationIndex;
@ -292,17 +300,12 @@
avatarOrientation = MyAvatar.orientation; avatarOrientation = MyAvatar.orientation;
for (notificationIndex = 0; notificationIndex < notifications.length; notificationIndex += 1) { for (notificationIndex = 0; notificationIndex < notifications.length; notificationIndex += 1) {
notificationPosition = Vec3.sum(defaultEyePosition, notificationPosition = Vec3.sum(defaultEyePosition, Vec3.multiplyQbyV(avatarOrientation, overlay3DDetails[notificationIndex].notificationPosition));
Vec3.multiplyQbyV(avatarOrientation, buttonPosition = Vec3.sum(defaultEyePosition, Vec3.multiplyQbyV(avatarOrientation, overlay3DDetails[notificationIndex].buttonPosition));
overlay3DDetails[notificationIndex].notificationPosition));
notificationOrientation = Quat.multiply(avatarOrientation, Overlays.editOverlay(notifications[notificationIndex], { "position": notificationPosition, "localRotation": overlay3DDetails[notificationIndex].notificationOrientation, "velocity": Vec3.ZERO });
overlay3DDetails[notificationIndex].notificationOrientation);
buttonPosition = Vec3.sum(defaultEyePosition, Overlays.editOverlay(buttons[notificationIndex], { "position": buttonPosition, "localRotation": overlay3DDetails[notificationIndex].notificationOrientation });
Vec3.multiplyQbyV(avatarOrientation,
overlay3DDetails[notificationIndex].buttonPosition));
Overlays.editOverlay(notifications[notificationIndex], { position: notificationPosition,
rotation: notificationOrientation });
Overlays.editOverlay(buttons[notificationIndex], { position: buttonPosition, rotation: notificationOrientation });
} }
} }
@ -316,7 +319,11 @@
buttons.push(Overlays.addOverlay("image", button)); buttons.push(Overlays.addOverlay("image", button));
} }
if (isOnHMD) {
height = height + 6.0;
} else {
height = height + 1.0; height = height + 1.0;
}
heights.push(height); heights.push(height);
times.push(new Date().getTime() / 1000); times.push(new Date().getTime() / 1000);
last = notifications.length - 1; last = notifications.length - 1;
@ -326,16 +333,19 @@
if (imageProperties && !image) { if (imageProperties && !image) {
var imageHeight = notice.width / imageProperties.aspectRatio; var imageHeight = notice.width / imageProperties.aspectRatio;
if (isOnHMD) {
imageHeight = (notice.width + (NOTIFICATION_3D_BUTTON_WIDTH / NOTIFICATION_3D_SCALE)) / imageProperties.aspectRatio;
}
notice = { notice = {
x: notice.x, "x": notice.x,
y: notice.y + height, "y": notice.y + height,
width: notice.width, "width": notice.width,
height: imageHeight, "height": imageHeight,
subImage: { x: 0, y: 0 }, "subImage": { "x": 0, "y": 0 },
color: { red: 255, green: 255, blue: 255}, "color": { "red": 255, "green": 255, "blue": 255},
visible: true, "visible": true,
imageURL: imageProperties.path, "imageURL": imageProperties.path,
alpha: backgroundAlpha "alpha": backgroundAlpha
}; };
notify(notice, button, imageHeight, imageProperties, true); notify(notice, button, imageHeight, imageProperties, true);
} }
@ -373,30 +383,32 @@
height = height + extraLine; height = height + extraLine;
noticeProperties = { noticeProperties = {
x: overlayLocationX, "x": overlayLocationX,
y: level, "y": level,
width: width, "width": width,
height: height, "height": height,
color: textColor, "color": textColor,
backgroundColor: backColor, "backgroundColor": backColor,
alpha: backgroundAlpha, "alpha": backgroundAlpha,
topMargin: topMargin, "backgroundAlpha": backgroundAlpha,
leftMargin: leftMargin, "textAlpha": backgroundAlpha,
font: {size: fontSize * sensorScaleFactor}, "topMargin": topMargin,
text: text "leftMargin": leftMargin,
"font": {"size": fontSize * sensorScaleFactor},
"text": text
}; };
bLevel = level + 12.0; bLevel = level + 12.0;
buttonProperties = { buttonProperties = {
x: buttonLocationX, "x": buttonLocationX,
y: bLevel, "y": bLevel,
width: 10.0, "width": 10.0,
height: 10.0, "height": 10.0,
subImage: { x: 0, y: 0, width: 10, height: 10 }, "subImage": { "x": 0, "y": 0, "width": 10, "height": 10 },
imageURL: CLOSE_NOTIFICATION_ICON, "imageURL": CLOSE_NOTIFICATION_ICON,
color: { red: 255, green: 255, blue: 255}, "color": { "red": 255, "green": 255, "blue": 255},
visible: true, "visible": true,
alpha: backgroundAlpha "alpha": backgroundAlpha
}; };
return notify(noticeProperties, buttonProperties, height, imageProperties); return notify(noticeProperties, buttonProperties, height, imageProperties);
@ -439,11 +451,9 @@
var sensorScaleFactor = isOnHMD ? MyAvatar.sensorToWorldScale : 1.0; var sensorScaleFactor = isOnHMD ? MyAvatar.sensorToWorldScale : 1.0;
for (var i = 0; i < notifications.length; i++) { for (var i = 0; i < notifications.length; i++) {
var overlayType = Overlays.getOverlayType(notifications[i]); var overlayType = Overlays.getOverlayType(notifications[i]);
if (overlayType === "text3d") { if (overlayType === "text3d") {
var props = { var props = {
font: {size: fontSize * sensorScaleFactor}, "lineHeight": 10.0 * (fontSize * sensorScaleFactor / 12.0) * NOTIFICATION_3D_SCALE
lineHeight: 10.0 * (fontSize * sensorScaleFactor / 12.0) * NOTIFICATION_3D_SCALE
}; };
Overlays.editOverlay(notifications[i], props); Overlays.editOverlay(notifications[i], props);
} }
@ -473,14 +483,15 @@
if ((frame % 60.0) === 0) { // only update once a second if ((frame % 60.0) === 0) { // only update once a second
locationY = 20.0; locationY = 20.0;
for (i = 0; i < arrays.length; i += 1) { //repositions overlays as others fade for (i = 0; i < arrays.length; i += 1) { //repositions overlays as others fade
Overlays.editOverlay(notifications[i], { x: overlayLocationX, y: locationY });
Overlays.editOverlay(buttons[i], { x: buttonLocationX, y: locationY + 12.0 });
if (isOnHMD) { if (isOnHMD) {
positions = calculate3DOverlayPositions(overlay3DDetails[i].width, positions = calculate3DOverlayPositions(overlay3DDetails[i].width, overlay3DDetails[i].height, locationY);
overlay3DDetails[i].height, locationY);
overlay3DDetails[i].notificationOrientation = positions.notificationOrientation; overlay3DDetails[i].notificationOrientation = positions.notificationOrientation;
overlay3DDetails[i].notificationPosition = positions.notificationPosition; overlay3DDetails[i].notificationPosition = positions.notificationPosition;
overlay3DDetails[i].buttonPosition = positions.buttonPosition; overlay3DDetails[i].buttonPosition = positions.buttonPosition;
//We don't reposition in HMD, because it is very annoying.
} else {
Overlays.editOverlay(notifications[i], { x: overlayLocationX, y: locationY });
Overlays.editOverlay(buttons[i], { x: buttonLocationX, y: locationY + 12.0 });
} }
locationY = locationY + arrays[i][3]; locationY = locationY + arrays[i][3];
} }
@ -548,6 +559,7 @@
} }
function onSnapshotTaken(pathStillSnapshot, notify) { function onSnapshotTaken(pathStillSnapshot, notify) {
if (Settings.getValue("snapshotNotifications", true)) {
if (notify) { if (notify) {
var imageProperties = { var imageProperties = {
path: "file:///" + pathStillSnapshot, path: "file:///" + pathStillSnapshot,
@ -556,14 +568,17 @@
createNotification(wordWrap("Snapshot saved to " + pathStillSnapshot), NotificationType.SNAPSHOT, imageProperties); createNotification(wordWrap("Snapshot saved to " + pathStillSnapshot), NotificationType.SNAPSHOT, imageProperties);
} }
} }
}
function tabletNotification() { function tabletNotification() {
createNotification("Tablet needs your attention", NotificationType.TABLET); createNotification("Tablet needs your attention", NotificationType.TABLET);
} }
function processingGif() { function processingGif() {
if (Settings.getValue("snapshotNotifications", true)) {
createNotification("Processing GIF snapshot...", NotificationType.SNAPSHOT); createNotification("Processing GIF snapshot...", NotificationType.SNAPSHOT);
} }
}
function walletNotSetup() { function walletNotSetup() {
createNotification("Your wallet isn't activated yet. Open the WALLET app.", NotificationType.WALLET); createNotification("Your wallet isn't activated yet. Open the WALLET app.", NotificationType.WALLET);