overte/scripts/system/interstitialPage.js

651 lines
23 KiB
JavaScript
Raw Normal View History

//
// interstitialPage.js
// scripts/system
//
// Created by Dante Ruiz on 08/02/2018.
// Copyright 2012 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
/* global Script, Controller, Overlays, Quat, MyAvatar, Entities, print, Vec3, AddressManager, Render, Window, Toolbars,
2018-08-20 11:14:48 -07:00
Camera, HMD, location, Account, Xform*/
(function() {
2018-08-08 18:15:27 -07:00
Script.include("/~/system/libraries/Xform.js");
2018-10-17 15:03:09 -07:00
Script.include("/~/system/libraries/globals.js");
2018-11-09 09:27:55 -08:00
var DEBUG = false;
2018-10-31 10:13:32 -07:00
var TOTAL_LOADING_PROGRESS = 3.7;
2018-10-12 11:43:03 -07:00
var EPSILON = 0.05;
var TEXTURE_EPSILON = 0.01;
2018-08-06 17:42:21 -07:00
var isVisible = false;
var VOLUME = 0.4;
2018-11-21 13:36:36 -08:00
var tune = SoundCache.getSound(Script.resourcesPath() + "sounds/crystals_and_voices.mp3");
var sample = null;
var MAX_LEFT_MARGIN = 1.9;
var INNER_CIRCLE_WIDTH = 4.7;
2018-08-08 18:15:27 -07:00
var DEFAULT_Z_OFFSET = 5.45;
2018-10-31 10:13:32 -07:00
var LOADING_IMAGE_WIDTH_PIXELS = 1024;
2018-08-30 13:22:17 -07:00
var previousCameraMode = Camera.mode;
var renderViewTask = Render.getConfig("RenderMainView");
var toolbar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system");
2018-08-08 18:15:27 -07:00
var request = Script.require('request').request;
var BUTTON_PROPERTIES = {
text: "Interstitial"
};
2018-08-08 18:15:27 -07:00
var tablet = null;
var button = null;
var errorConnectingToDomain = false;
// Tips have a character limit of 69
var userTips = [
"Tip: Visit TheSpot to explore featured domains!",
"Tip: Visit our docs online to learn more about scripting!",
"Tip: Don't want others invading your personal space? Turn on the Bubble!",
"Tip: Want to make a friend? Shake hands with them in VR!",
"Tip: Enjoy live music? Visit Rust to dance your heart out!",
"Tip: Use the Create app to import models and create custom entities.",
"Tip: We're open source! Feel free to contribute to our code on GitHub!",
"Tip: What emotes have you used in the Emote app?",
2018-10-05 15:39:51 -07:00
"Tip: Take and share your snapshots with everyone using the Snap app.",
"Tip: Did you know you can show websites in-world by creating a web entity?",
"Tip: Find out more information about domains by visiting our website!",
"Tip: Did you know you can get cool new apps from the Marketplace?",
"Tip: Print your snapshots from the Snap app to share with others!",
"Tip: Log in to make friends, visit new domains, and save avatars!"
];
2018-09-06 17:06:17 -07:00
var DEFAULT_DIMENSIONS = { x: 24, y: 24, z: 24 };
2018-08-08 18:15:27 -07:00
var BLACK_SPHERE = Script.resolvePath("/~/system/assets/models/black-sphere.fbx");
var BUTTON = Script.resourcesPath() + "images/interstitialPage/button.png";
var BUTTON_HOVER = Script.resourcesPath() + "images/interstitialPage/button_hover.png";
var LOADING_BAR_PLACARD = Script.resourcesPath() + "images/loadingBar_placard.png";
var LOADING_BAR_PROGRESS = Script.resourcesPath() + "images/loadingBar_progress.png";
ModelCache.prefetch(BLACK_SPHERE);
TextureCache.prefetch(BUTTON);
TextureCache.prefetch(BUTTON_HOVER);
TextureCache.prefetch(LOADING_BAR_PLACARD);
TextureCache.prefetch(LOADING_BAR_PROGRESS);
var loadingSphereID = Overlays.addOverlay("model", {
name: "Loading-Sphere",
position: Vec3.sum(Vec3.sum(MyAvatar.position, { x: 0.0, y: -1.0, z: 0.0 }), Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0.95, z: 0 })),
orientation: Quat.multiply(Quat.fromVec3Degrees({ x: 0, y: 180, z: 0 }), MyAvatar.orientation),
url: BLACK_SPHERE,
2018-08-08 18:15:27 -07:00
dimensions: DEFAULT_DIMENSIONS,
alpha: 1,
visible: isVisible,
ignoreRayIntersection: true,
drawInFront: true,
2018-08-06 17:42:21 -07:00
grabbable: false,
2018-08-10 10:20:39 -07:00
parentID: MyAvatar.SELF_ID
});
2018-08-08 18:15:27 -07:00
var anchorOverlay = Overlays.addOverlay("cube", {
dimensions: { x: 0.2, y: 0.2, z: 0.2 },
2018-08-10 10:20:39 -07:00
visible: false,
2018-08-08 18:15:27 -07:00
grabbable: false,
ignoreRayIntersection: true,
localPosition: { x: 0.0, y: getAnchorLocalYOffset(), z: DEFAULT_Z_OFFSET },
orientation: Quat.multiply(Quat.fromVec3Degrees({ x: 0, y: 180, z: 0 }), MyAvatar.orientation),
2018-08-08 18:15:27 -07:00
solid: true,
drawInFront: true,
2018-08-09 16:29:37 -07:00
parentID: loadingSphereID
2018-08-08 18:15:27 -07:00
});
2018-08-20 11:14:48 -07:00
var domainName = "";
var domainNameTextID = Overlays.addOverlay("text3d", {
name: "Loading-Destination-Card-Text",
2018-09-06 17:06:17 -07:00
localPosition: { x: 0.0, y: 0.8, z: -0.001 },
text: domainName,
textAlpha: 1,
2018-09-06 17:06:17 -07:00
backgroundAlpha: 1,
lineHeight: 0.42,
visible: isVisible,
ignoreRayIntersection: true,
drawInFront: true,
grabbable: false,
localOrientation: Quat.fromVec3Degrees({ x: 0, y: 180, z: 0 }),
2018-08-08 18:15:27 -07:00
parentID: anchorOverlay
});
2018-08-08 18:15:27 -07:00
var domainText = "";
var domainDescription = Overlays.addOverlay("text3d", {
name: "Loading-Hostname",
2018-08-08 18:15:27 -07:00
localPosition: { x: 0.0, y: 0.32, z: 0.0 },
text: domainText,
textAlpha: 1,
2018-09-06 17:06:17 -07:00
backgroundAlpha: 1,
lineHeight: 0.13,
visible: isVisible,
ignoreRayIntersection: true,
drawInFront: true,
grabbable: false,
localOrientation: Quat.fromVec3Degrees({ x: 0, y: 180, z: 0 }),
2018-08-08 18:15:27 -07:00
parentID: anchorOverlay
});
var toolTip = "";
var domainToolTip = Overlays.addOverlay("text3d", {
name: "Loading-Tooltip",
localPosition: { x: 0.0, y: -1.6, z: 0.0 },
text: toolTip,
textAlpha: 1,
2018-10-01 16:11:27 -07:00
backgroundAlpha: 0.00393,
lineHeight: 0.13,
visible: isVisible,
ignoreRayIntersection: true,
drawInFront: true,
grabbable: false,
localOrientation: Quat.fromVec3Degrees({ x: 0, y: 180, z: 0 }),
2018-08-08 18:15:27 -07:00
parentID: anchorOverlay
});
2018-10-01 16:11:27 -07:00
var loadingToTheSpotText = Overlays.addOverlay("text3d", {
name: "Loading-Destination-Card-Text",
localPosition: { x: 0.0, y: -1.687, z: -0.3 },
2018-10-01 16:11:27 -07:00
text: "Go To TheSpot",
textAlpha: 1,
backgroundAlpha: 0.00393,
lineHeight: 0.10,
visible: isVisible,
ignoreRayIntersection: true,
dimensions: { x: 1, y: 0.17 },
2018-10-01 16:11:27 -07:00
drawInFront: true,
grabbable: false,
localOrientation: Quat.fromVec3Degrees({ x: 0, y: 180, z: 0 }),
parentID: anchorOverlay
});
var loadingToTheSpotID = Overlays.addOverlay("image3d", {
name: "Loading-Destination-Card-GoTo-Image",
localPosition: { x: 0.0, y: -1.75, z: -0.3 },
url: BUTTON,
alpha: 1,
visible: isVisible,
emissive: true,
ignoreRayIntersection: false,
drawInFront: true,
grabbable: false,
2018-10-01 16:11:27 -07:00
localOrientation: Quat.fromVec3Degrees({ x: 0, y: 180, z: 0 }),
parentID: anchorOverlay
});
var loadingToTheSpotHoverID = Overlays.addOverlay("image3d", {
name: "Loading-Destination-Card-GoTo-Image-Hover",
localPosition: { x: 0.0, y: -1.75, z: -0.3 },
url: BUTTON_HOVER,
2018-10-01 16:11:27 -07:00
alpha: 1,
visible: false,
emissive: true,
ignoreRayIntersection: false,
drawInFront: true,
grabbable: false,
localOrientation: Quat.fromVec3Degrees({ x: 0, y: 180, z: 0 }),
2018-08-08 18:15:27 -07:00
parentID: anchorOverlay
});
2018-10-31 10:13:32 -07:00
var loadingBarProgress = Overlays.addOverlay("image3d", {
name: "Loading-Bar-Progress",
2018-11-09 09:27:55 -08:00
localPosition: { x: 0.0, y: -0.91, z: 0.0 },
url: LOADING_BAR_PROGRESS,
alpha: 1,
2018-11-01 15:43:56 -07:00
dimensions: { x: TOTAL_LOADING_PROGRESS, y: 0.3},
visible: isVisible,
emissive: true,
ignoreRayIntersection: false,
drawInFront: true,
grabbable: false,
localOrientation: Quat.fromVec3Degrees({ x: 0.0, y: 180.0, z: 0.0 }),
2018-11-01 15:43:56 -07:00
parentID: anchorOverlay,
keepAspectRatio: false
});
2018-10-31 10:13:32 -07:00
var loadingBarPlacard = Overlays.addOverlay("image3d", {
name: "Loading-Bar-Placard",
localPosition: { x: 0.0, y: -0.99, z: 0.4 },
url: LOADING_BAR_PLACARD,
alpha: 1,
2018-10-31 10:13:32 -07:00
dimensions: { x: 4, y: 2.8 },
visible: isVisible,
emissive: true,
ignoreRayIntersection: false,
drawInFront: true,
grabbable: false,
localOrientation: Quat.fromVec3Degrees({ x: 0.0, y: 180.0, z: 0.0 }),
2018-08-08 18:15:27 -07:00
parentID: anchorOverlay
});
2018-10-12 11:43:03 -07:00
var TARGET_UPDATE_HZ = 30;
var BASIC_TIMER_INTERVAL_MS = 1000 / TARGET_UPDATE_HZ;
var lastInterval = Date.now();
2018-08-30 13:22:17 -07:00
var currentDomain = "no domain";
2018-08-06 17:42:21 -07:00
var timer = null;
var target = 0;
2018-09-21 11:42:26 -07:00
var textureMemSizeStabilityCount = 0;
var textureMemSizeAtLastCheck = 0;
2018-08-09 16:29:37 -07:00
var connectionToDomainFailed = false;
2018-08-08 18:15:27 -07:00
function getAnchorLocalYOffset() {
var loadingSpherePosition = Entities.getEntityProperties(loadingSphereID, ["position"]).position;
var loadingSphereOrientation = Entities.getEntityProperties(loadingSphereID, ["rotation"]).rotation;
2018-08-08 18:15:27 -07:00
var overlayXform = new Xform(loadingSphereOrientation, loadingSpherePosition);
var worldToOverlayXform = overlayXform.inv();
var headPosition = MyAvatar.getHeadPosition();
var headPositionInOverlaySpace = worldToOverlayXform.xformPoint(headPosition);
return headPositionInOverlaySpace.y;
}
function getLeftMargin(overlayID, text) {
var textSize = Overlays.textSize(overlayID, text);
var sizeDifference = ((INNER_CIRCLE_WIDTH - textSize.width) / 2);
var leftMargin = -(MAX_LEFT_MARGIN - sizeDifference);
return leftMargin;
}
2018-08-06 17:42:21 -07:00
function lerp(a, b, t) {
2018-10-22 11:29:36 -07:00
return ((1 - t) * a + t * b);
2018-08-06 17:42:21 -07:00
}
2018-08-22 13:13:00 -07:00
function resetValues() {
2018-10-31 10:13:32 -07:00
updateProgressBar(0.0);
2018-08-22 13:13:00 -07:00
}
2018-08-06 17:42:21 -07:00
function startInterstitialPage() {
if (timer === null) {
2018-08-26 21:50:01 -07:00
updateOverlays(false);
2018-08-08 18:15:27 -07:00
startAudio();
2018-08-06 17:42:21 -07:00
target = 0;
2018-09-21 11:42:26 -07:00
textureMemSizeStabilityCount = 0;
textureMemSizeAtLastCheck = 0;
2018-11-01 15:43:56 -07:00
currentProgress = 0.0;
2018-08-09 16:29:37 -07:00
connectionToDomainFailed = false;
2018-08-30 13:22:17 -07:00
previousCameraMode = Camera.mode;
Camera.mode = "first person look at";
2018-11-01 15:43:56 -07:00
updateProgressBar(0.0);
2018-11-09 10:37:21 -08:00
scaleInterstitialPage(MyAvatar.sensorToWorldScale);
2018-10-12 11:43:03 -07:00
timer = Script.setTimeout(update, 2000);
2018-08-06 17:42:21 -07:00
}
}
function toggleInterstitialPage(isInErrorState) {
errorConnectingToDomain = isInErrorState;
if (!errorConnectingToDomain) {
domainChanged(location);
}
}
function restartAudio() {
tune.ready.disconnect(restartAudio);
startAudio();
}
2018-08-08 18:15:27 -07:00
function startAudio() {
if (tune.downloaded) {
sample = Audio.playSound(tune, {
localOnly: true,
position: MyAvatar.getHeadPosition(),
volume: VOLUME
});
} else {
tune.ready.connect(restartAudio);
}
2018-08-08 18:15:27 -07:00
}
function endAudio() {
sample.stop();
sample = null;
}
2018-08-06 17:42:21 -07:00
function domainChanged(domain) {
if (domain !== currentDomain) {
2018-08-07 16:02:54 -07:00
MyAvatar.restoreAnimation();
2018-10-01 15:26:56 -07:00
resetValues();
2018-08-30 13:22:17 -07:00
var name = location.placename;
2018-08-06 17:42:21 -07:00
domainName = name.charAt(0).toUpperCase() + name.slice(1);
2018-08-30 13:22:17 -07:00
var doRequest = true;
if (name.length === 0 && location.href === "file:///~/serverless/tutorial.json") {
2018-10-01 16:11:27 -07:00
domainName = "Serverless Domain (Tutorial)";
2018-08-30 13:22:17 -07:00
doRequest = false;
}
2018-08-06 17:42:21 -07:00
var domainNameLeftMargin = getLeftMargin(domainNameTextID, domainName);
var textProperties = {
text: domainName,
leftMargin: domainNameLeftMargin
};
// check to be sure we are going to look for an actual domain
if (!domain) {
doRequest = false;
}
2018-08-30 13:22:17 -07:00
if (doRequest) {
var url = Account.metaverseServerURL + '/api/v1/places/' + domain;
request({
uri: url
}, function(error, data) {
if (data.status === "success") {
var domainInfo = data.data;
var domainDescriptionText = domainInfo.place.description;
var leftMargin = getLeftMargin(domainDescription, domainDescriptionText);
var domainDescriptionProperties = {
text: domainDescriptionText,
leftMargin: leftMargin
};
Overlays.editOverlay(domainDescription, domainDescriptionProperties);
}
});
} else {
var domainDescriptionProperties = {
text: ""
};
Overlays.editOverlay(domainDescription, domainDescriptionProperties);
}
2018-08-06 17:42:21 -07:00
var randomIndex = Math.floor(Math.random() * userTips.length);
var tip = userTips[randomIndex];
var tipLeftMargin = getLeftMargin(domainToolTip, tip);
var toolTipProperties = {
text: tip,
leftMargin: tipLeftMargin
};
Overlays.editOverlay(domainNameTextID, textProperties);
Overlays.editOverlay(domainToolTip, toolTipProperties);
startInterstitialPage();
currentDomain = domain;
}
}
var THE_PLACE = (About.buildVersion === "dev") ? "hifi://TheSpot-dev" : "hifi://TheSpot";
function clickedOnOverlay(overlayID, event) {
2018-10-01 16:11:27 -07:00
if (loadingToTheSpotHoverID === overlayID) {
2018-08-07 16:02:54 -07:00
location.handleLookupString(THE_PLACE);
Overlays.editOverlay(loadingToTheSpotHoverID, { visible: false });
Overlays.editOverlay(loadingToTheSpotID, { visible: true });
}
}
2018-08-03 10:47:20 -07:00
2018-10-03 10:12:07 -07:00
function onEnterOverlay(overlayID, event) {
if (currentDomain === "no domain") {
return;
}
if (overlayID === loadingToTheSpotID) {
Overlays.editOverlay(loadingToTheSpotID, { visible: false });
Overlays.editOverlay(loadingToTheSpotHoverID, { visible: true });
2018-10-03 10:12:07 -07:00
}
}
function onLeaveOverlay(overlayID, event) {
if (currentDomain === "no domain") {
return;
}
if (overlayID === loadingToTheSpotHoverID) {
Overlays.editOverlay(loadingToTheSpotHoverID, { visible: false });
Overlays.editOverlay(loadingToTheSpotID, { visible: true });
2018-10-03 10:12:07 -07:00
}
}
2018-11-01 15:43:56 -07:00
var currentProgress = 0.0;
function updateOverlays(physicsEnabled) {
2018-10-17 15:03:09 -07:00
if (isInterstitialOverlaysVisible !== !physicsEnabled && !physicsEnabled === true) {
2018-10-31 10:13:32 -07:00
// visible changed to true.
isInterstitialOverlaysVisible = !physicsEnabled;
2018-10-17 15:03:09 -07:00
}
var properties = {
visible: !physicsEnabled
};
var mainSphereProperties = {
2018-08-06 17:42:21 -07:00
visible: !physicsEnabled
};
2018-08-08 18:15:27 -07:00
var domainTextProperties = {
text: domainText,
visible: !physicsEnabled
};
2018-08-10 16:53:34 -07:00
var loadingBarProperties = {
visible: !physicsEnabled
};
2018-08-08 18:15:27 -07:00
if (!HMD.active) {
MyAvatar.headOrientation = Quat.multiply(Quat.cancelOutRollAndPitch(MyAvatar.headOrientation), Quat.fromPitchYawRollDegrees(-3.0, 0, 0));
}
2018-08-10 10:20:39 -07:00
renderViewTask.getConfig("LightingModel")["enableAmbientLight"] = physicsEnabled;
renderViewTask.getConfig("LightingModel")["enableDirectionalLight"] = physicsEnabled;
renderViewTask.getConfig("LightingModel")["enablePointLight"] = physicsEnabled;
Overlays.editOverlay(loadingSphereID, mainSphereProperties);
2018-10-01 16:11:27 -07:00
Overlays.editOverlay(loadingToTheSpotText, properties);
Overlays.editOverlay(loadingToTheSpotID, properties);
Overlays.editOverlay(domainNameTextID, properties);
2018-08-08 18:15:27 -07:00
Overlays.editOverlay(domainDescription, domainTextProperties);
Overlays.editOverlay(domainToolTip, properties);
Overlays.editOverlay(loadingBarPlacard, properties);
2018-08-10 16:53:34 -07:00
Overlays.editOverlay(loadingBarProgress, loadingBarProperties);
2018-08-08 18:15:27 -07:00
2018-09-21 11:42:26 -07:00
if (!DEBUG) {
Menu.setIsOptionChecked("Show Overlays", physicsEnabled);
if (!HMD.active) {
toolbar.writeProperty("visible", physicsEnabled);
}
2018-08-22 13:13:00 -07:00
}
resetValues();
2018-08-30 13:22:17 -07:00
if (physicsEnabled) {
Camera.mode = previousCameraMode;
}
if (isInterstitialOverlaysVisible !== !physicsEnabled && !physicsEnabled === false) {
2018-10-31 10:13:32 -07:00
// visible changed to false.
isInterstitialOverlaysVisible = !physicsEnabled;
}
2018-08-08 18:15:27 -07:00
}
function scaleInterstitialPage(sensorToWorldScale) {
var yOffset = getAnchorLocalYOffset();
var localPosition = {
x: 0.0,
y: yOffset,
z: 5.45
};
Overlays.editOverlay(anchorOverlay, { localPosition: localPosition });
}
2018-09-26 15:12:48 -07:00
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds) {
2018-09-26 15:12:48 -07:00
break;
}
}
}
2018-10-31 10:13:32 -07:00
function updateProgressBar(progress) {
var progressPercentage = progress / TOTAL_LOADING_PROGRESS;
var subImageWidth = progressPercentage * LOADING_IMAGE_WIDTH_PIXELS;
2018-11-01 15:43:56 -07:00
var start = TOTAL_LOADING_PROGRESS / 2;
var end = 0;
var xLocalPosition = (progressPercentage * (end - start)) + start;
2018-10-31 10:13:32 -07:00
var properties = {
2018-11-09 10:37:21 -08:00
localPosition: { x: xLocalPosition, y: (HMD.active ? -0.93 : -0.91), z: 0.0 },
2018-10-31 10:13:32 -07:00
dimensions: {
2018-11-01 15:43:56 -07:00
x: progress,
y: 0.3
2018-10-31 10:13:32 -07:00
},
2018-11-01 15:43:56 -07:00
localOrientation: Quat.fromVec3Degrees({ x: 0.0, y: 180.0, z: 0.0 }),
2018-10-31 10:13:32 -07:00
subImage: {
x: 0.0,
y: 0.0,
width: subImageWidth,
2018-11-01 15:43:56 -07:00
height: 128
2018-10-31 10:13:32 -07:00
}
};
Overlays.editOverlay(loadingBarProgress, properties);
}
2018-10-22 12:49:24 -07:00
var MAX_TEXTURE_STABILITY_COUNT = 30;
var INTERVAL_PROGRESS = 0.04;
2018-11-01 15:43:56 -07:00
var INTERVAL_PROGRESS_PHYSICS_ENABLED = 0.09;
function update() {
2018-09-21 11:42:26 -07:00
var renderStats = Render.getConfig("Stats");
var physicsEnabled = Window.isPhysicsEnabled();
var thisInterval = Date.now();
var deltaTime = (thisInterval - lastInterval);
lastInterval = thisInterval;
2018-08-06 17:42:21 -07:00
2018-08-21 18:27:21 -07:00
var domainLoadingProgressPercentage = Window.domainLoadingProgress();
2018-09-21 11:42:26 -07:00
var progress = ((TOTAL_LOADING_PROGRESS * 0.4) * domainLoadingProgressPercentage);
2018-08-30 13:22:17 -07:00
if (progress >= target) {
2018-08-06 17:42:21 -07:00
target = progress;
2018-08-30 13:22:17 -07:00
}
2018-10-12 11:43:03 -07:00
if (currentProgress >= ((TOTAL_LOADING_PROGRESS * 0.4) - TEXTURE_EPSILON)) {
2018-09-21 11:42:26 -07:00
var textureResourceGPUMemSize = renderStats.textureResourceGPUMemSize;
var texturePopulatedGPUMemSize = renderStats.textureResourcePopulatedGPUMemSize;
if (textureMemSizeAtLastCheck === textureResourceGPUMemSize) {
textureMemSizeStabilityCount++;
} else {
textureMemSizeStabilityCount = 0;
}
textureMemSizeAtLastCheck = textureResourceGPUMemSize;
2018-10-22 12:49:24 -07:00
if (textureMemSizeStabilityCount >= MAX_TEXTURE_STABILITY_COUNT) {
2018-09-21 11:42:26 -07:00
if (textureResourceGPUMemSize > 0) {
var gpuPercantage = (TOTAL_LOADING_PROGRESS * 0.6) * (texturePopulatedGPUMemSize / textureResourceGPUMemSize);
var totalProgress = progress + gpuPercantage;
if (totalProgress >= target) {
target = totalProgress;
}
}
}
}
2018-09-06 17:06:17 -07:00
if ((physicsEnabled && (currentProgress < TOTAL_LOADING_PROGRESS))) {
target = TOTAL_LOADING_PROGRESS;
2018-08-30 13:22:17 -07:00
}
2018-08-21 18:27:21 -07:00
currentProgress = lerp(currentProgress, target, (physicsEnabled ? INTERVAL_PROGRESS_PHYSICS_ENABLED : INTERVAL_PROGRESS));
2018-08-20 11:14:48 -07:00
2018-10-31 10:13:32 -07:00
updateProgressBar(currentProgress);
2018-09-25 18:16:18 -07:00
if (errorConnectingToDomain) {
updateOverlays(errorConnectingToDomain);
2018-10-03 10:12:07 -07:00
// setting hover id to invisible
Overlays.editOverlay(loadingToTheSpotHoverID, { visible: false });
endAudio();
currentDomain = "no domain";
timer = null;
2018-09-26 15:33:57 -07:00
// The toolbar doesn't become visible in time to match the speed of
// the signal handling of redirectErrorStateChanged in both this script
// and the redirectOverlays.js script. Use a sleep function to ensure
// the toolbar becomes visible again.
2018-09-26 15:12:48 -07:00
sleep(300);
2018-09-26 15:33:57 -07:00
if (!HMD.active) {
toolbar.writeProperty("visible", true);
}
return;
} else if ((physicsEnabled && (currentProgress >= (TOTAL_LOADING_PROGRESS - EPSILON)))) {
2018-08-09 16:29:37 -07:00
updateOverlays((physicsEnabled || connectionToDomainFailed));
2018-10-03 10:12:07 -07:00
// setting hover id to invisible
Overlays.editOverlay(loadingToTheSpotHoverID, { visible: false });
2018-08-08 18:15:27 -07:00
endAudio();
2018-09-06 17:06:17 -07:00
currentDomain = "no domain";
2018-08-06 17:42:21 -07:00
timer = null;
return;
}
timer = Script.setTimeout(update, BASIC_TIMER_INTERVAL_MS);
}
var whiteColor = { red: 255, green: 255, blue: 255 };
var greyColor = { red: 125, green: 125, blue: 125 };
2018-10-31 10:13:32 -07:00
Overlays.mouseReleaseOnOverlay.connect(clickedOnOverlay);
2018-10-03 10:12:07 -07:00
Overlays.hoverEnterOverlay.connect(onEnterOverlay);
Overlays.hoverLeaveOverlay.connect(onLeaveOverlay);
2018-08-07 16:02:54 -07:00
location.hostChanged.connect(domainChanged);
Window.redirectErrorStateChanged.connect(toggleInterstitialPage);
2018-08-08 18:15:27 -07:00
MyAvatar.sensorToWorldScaleChanged.connect(scaleInterstitialPage);
2018-09-06 14:31:49 -07:00
MyAvatar.sessionUUIDChanged.connect(function() {
var avatarSessionUUID = MyAvatar.sessionUUID;
2018-10-11 11:33:19 -07:00
Overlays.editOverlay(loadingSphereID, {
position: Vec3.sum(Vec3.sum(MyAvatar.position, {x: 0.0, y: -1.0, z: 0.0}), Vec3.multiplyQbyV(MyAvatar.orientation, {x: 0, y: 0.95, z: 0})),
orientation: Quat.multiply(Quat.fromVec3Degrees({x: 0, y: 180, z: 0}), MyAvatar.orientation),
parentID: avatarSessionUUID
});
2018-09-06 14:31:49 -07:00
});
2018-08-08 18:15:27 -07:00
var toggle = true;
if (DEBUG) {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton(BUTTON_PROPERTIES);
button.clicked.connect(function() {
toggle = !toggle;
updateOverlays(toggle);
});
}
2018-10-01 16:11:27 -07:00
// set left margin of text.
var loadingTextProperties = {
leftMargin: getLeftMargin(loadingToTheSpotText, "Go To TheSpot") + 0.045
};
Overlays.editOverlay(loadingToTheSpotText, loadingTextProperties);
function cleanup() {
Overlays.deleteOverlay(loadingSphereID);
Overlays.deleteOverlay(loadingToTheSpotID);
2018-10-01 16:11:27 -07:00
Overlays.deleteOverlay(loadingToTheSpotHoverID);
Overlays.deleteOverlay(domainNameTextID);
2018-08-08 18:15:27 -07:00
Overlays.deleteOverlay(domainDescription);
Overlays.deleteOverlay(domainToolTip);
Overlays.deleteOverlay(loadingBarPlacard);
Overlays.deleteOverlay(loadingBarProgress);
2018-08-08 18:15:27 -07:00
Overlays.deleteOverlay(anchorOverlay);
if (DEBUG) {
tablet.removeButton(button);
}
2018-08-22 13:13:00 -07:00
renderViewTask.getConfig("LightingModel")["enableAmbientLight"] = true;
renderViewTask.getConfig("LightingModel")["enableDirectionalLight"] = true;
renderViewTask.getConfig("LightingModel")["enablePointLight"] = true;
2018-09-06 17:55:10 -07:00
Menu.setIsOptionChecked("Show Overlays", true);
if (!HMD.active) {
toolbar.writeProperty("visible", true);
}
}
// location.hostname may already be set by the time the script is loaded.
// Show the interstitial page if the domain isn't loaded.
if (!location.isConnected) {
domainChanged(location.hostname);
}
Script.scriptEnding.connect(cleanup);
}());