mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 09:33:29 +02:00
initial version of the lobby script to jump to locations
This commit is contained in:
parent
7ad590c578
commit
cb4ae5f1bb
2 changed files with 119 additions and 87 deletions
119
examples/lobby.js
Normal file
119
examples/lobby.js
Normal file
|
@ -0,0 +1,119 @@
|
|||
//
|
||||
// lobby.js
|
||||
// examples
|
||||
//
|
||||
// Created by Stephen Birarda on October 17, 2014
|
||||
// Copyright 2014 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
|
||||
//
|
||||
|
||||
var panelWall = false;
|
||||
|
||||
var avatarStickPosition = {};
|
||||
|
||||
var panelsNaturalExtentsMin = { x: -1181, y: -326, z: 56 };
|
||||
var panelsNaturalExtentsMax = { x: 1181, y: 576, z: 1183 };
|
||||
|
||||
var panelsNaturalDimensions = Vec3.subtract(panelsNaturalExtentsMax, panelsNaturalExtentsMin);
|
||||
var SCALING_FACTOR = 0.01;
|
||||
var panelsDimensions = Vec3.multiply(panelsNaturalDimensions, SCALING_FACTOR);
|
||||
|
||||
function drawLobby() {
|
||||
if (!panelWall) {
|
||||
print("Adding an overlay for the lobby panel wall.")
|
||||
|
||||
var front = Quat.getFront(Camera.getOrientation());
|
||||
front.y = 0
|
||||
front = Vec3.normalize(front)
|
||||
|
||||
var cameraEuler = Quat.safeEulerAngles(Camera.getOrientation());
|
||||
|
||||
var panelWallProps = {
|
||||
url: "https://s3.amazonaws.com/hifi-public/models/sets/Lobby/LobbyPrototype/PanelWall3.fbx",
|
||||
position: Vec3.sum(Camera.getPosition(), Vec3.multiply(front, 0.5)),
|
||||
rotation: Quat.angleAxis(cameraEuler.y + 180, { x: 0, y: 1, z: 0}),
|
||||
dimensions: panelsDimensions
|
||||
}
|
||||
|
||||
avatarStickPosition = MyAvatar.position
|
||||
|
||||
panelWall = Overlays.addOverlay("model", panelWallProps)
|
||||
}
|
||||
}
|
||||
|
||||
var locations = {}
|
||||
|
||||
function changeLobbyTextures() {
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("GET", "https://data.highfidelity.io/api/v1/locations?limit=21", false);
|
||||
req.send();
|
||||
|
||||
locations = JSON.parse(req.responseText).data.locations
|
||||
|
||||
var NUM_PANELS = locations.length;
|
||||
|
||||
var textureProp = {
|
||||
textures: {}
|
||||
};
|
||||
|
||||
for (var j = 0; j < NUM_PANELS; j++) {
|
||||
textureProp["textures"]["file" + (j + 1)] = "http:" + locations[j].thumbnail_url
|
||||
}
|
||||
|
||||
Overlays.editOverlay(panelWall, textureProp)
|
||||
}
|
||||
|
||||
function cleanupLobby() {
|
||||
Overlays.deleteOverlay(panelWall)
|
||||
panelWall = false
|
||||
locations = {}
|
||||
}
|
||||
|
||||
function actionStartEvent(event) {
|
||||
if (panelWall) {
|
||||
// we've got an action event and our panel wall is up
|
||||
// check if we hit a panel and if we should jump there
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var result = Overlays.findRayIntersection(pickRay);
|
||||
|
||||
if (result.intersects && result.overlayID == panelWall) {
|
||||
var panelName = result.extraInfo
|
||||
var panelStringIndex = panelName.indexOf("Panel")
|
||||
if (panelStringIndex != -1) {
|
||||
var panelIndex = parseInt(panelName.slice(5)) - 1
|
||||
if (panelIndex < locations.length) {
|
||||
var actionLocation = locations[panelIndex]
|
||||
|
||||
print("Jumping to " + actionLocation.name + " at " + actionLocation.path + " in " + actionLocation.domain.name)
|
||||
|
||||
Window.location = actionLocation
|
||||
maybeCleanupLobby()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function backStartEvent() {
|
||||
if (!panelWall) {
|
||||
drawLobby()
|
||||
changeLobbyTextures()
|
||||
} else {
|
||||
cleanupLobby()
|
||||
}
|
||||
}
|
||||
|
||||
var CLEANUP_EPSILON_DISTANCE = 0.025
|
||||
|
||||
function maybeCleanupLobby() {
|
||||
if (Vec3.length(Vec3.subtract(avatarStickPosition, MyAvatar.position)) > CLEANUP_EPSILON_DISTANCE) {
|
||||
cleanupLobby()
|
||||
}
|
||||
}
|
||||
|
||||
Controller.actionStartEvent.connect(actionStartEvent)
|
||||
Controller.backStartEvent.connect(backStartEvent)
|
||||
Script.update.connect(maybeCleanupLobby)
|
||||
Script.scriptEnding.connect(maybeCleanupLobby);
|
|
@ -1,87 +0,0 @@
|
|||
var position = Vec3.sum(MyAvatar.position, { x: 0, y: -1, z: 0});
|
||||
|
||||
var scalingFactor = 0.01;
|
||||
|
||||
var sphereNaturalExtentsMin = { x: -1230, y: -1223, z: -1210 };
|
||||
var sphereNaturalExtentsMax = { x: 1230, y: 1229, z: 1223 };
|
||||
var panelsNaturalExtentsMin = { x: -1181, y: -326, z: 56 };
|
||||
var panelsNaturalExtentsMax = { x: 1181, y: 576, z: 1183 };
|
||||
|
||||
var sphereNaturalDimensions = Vec3.subtract(sphereNaturalExtentsMax, sphereNaturalExtentsMin);
|
||||
var panelsNaturalDimensions = Vec3.subtract(panelsNaturalExtentsMax, panelsNaturalExtentsMin);
|
||||
Vec3.print("sphereNaturalDimensions:", sphereNaturalDimensions);
|
||||
Vec3.print("panelsNaturalDimensions:", panelsNaturalDimensions);
|
||||
|
||||
var sphereNaturalCenter = Vec3.sum(sphereNaturalExtentsMin, Vec3.multiply(sphereNaturalDimensions, 0.5));
|
||||
var panelsNaturalCenter = Vec3.sum(panelsNaturalExtentsMin, Vec3.multiply(panelsNaturalDimensions, 0.5));
|
||||
Vec3.print("sphereNaturalCenter:", sphereNaturalCenter);
|
||||
Vec3.print("panelsNaturalCenter:", panelsNaturalCenter);
|
||||
|
||||
var sphereDimensions = Vec3.multiply(sphereNaturalDimensions, scalingFactor);
|
||||
var panelsDimensions = Vec3.multiply(panelsNaturalDimensions, scalingFactor);
|
||||
Vec3.print("sphereDimensions:", sphereDimensions);
|
||||
Vec3.print("panelsDimensions:", panelsDimensions);
|
||||
|
||||
var sphereCenter = Vec3.multiply(sphereNaturalCenter, scalingFactor);
|
||||
var panelsCenter = Vec3.multiply(panelsNaturalCenter, scalingFactor);
|
||||
Vec3.print("sphereCenter:", sphereCenter);
|
||||
Vec3.print("panelsCenter:", panelsCenter);
|
||||
|
||||
var centerShift = Vec3.subtract(panelsCenter, sphereCenter);
|
||||
Vec3.print("centerShift:", centerShift);
|
||||
|
||||
var spherePosition = position;
|
||||
Vec3.print("spherePosition:", spherePosition);
|
||||
var panelsPosition = Vec3.sum(spherePosition, centerShift);
|
||||
Vec3.print("panelsPosition:", panelsPosition);
|
||||
|
||||
|
||||
var screensOverlay = Overlays.addOverlay("model", {
|
||||
position: panelsPosition,
|
||||
dimensions: panelsDimensions,
|
||||
url: "https://s3.amazonaws.com/hifi-public/models/sets/Lobby/LobbyConcepts/Lobby5_IsolatedPanelsFreezeTransforms.fbx"
|
||||
});
|
||||
|
||||
|
||||
var structureOverlay = Overlays.addOverlay("model", {
|
||||
position: spherePosition,
|
||||
dimensions: sphereDimensions,
|
||||
url: "https://s3.amazonaws.com/hifi-public/models/sets/Lobby/LobbyConcepts/Lobby5_OrbShellOnly.fbx",
|
||||
ignoreRayIntersection: true, // we don't want to ray pick against any of this
|
||||
});
|
||||
|
||||
var statusText = Overlays.addOverlay("text", {
|
||||
x: 200,
|
||||
y: 100,
|
||||
width: 200,
|
||||
height: 20,
|
||||
backgroundColor: { red: 0, green: 0, blue: 0},
|
||||
alpha: 1.0,
|
||||
color: { red: 255, green: 255, blue: 255},
|
||||
topMargin: 4,
|
||||
leftMargin: 4,
|
||||
text: "",
|
||||
});
|
||||
|
||||
|
||||
Controller.mouseMoveEvent.connect(function(event){
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var result = Overlays.findRayIntersection(pickRay);
|
||||
|
||||
if (result.intersects) {
|
||||
if (result.overlayID == screensOverlay) {
|
||||
Overlays.editOverlay(statusText, { text: "You are pointing at: " + result.extraInfo });
|
||||
} else {
|
||||
Overlays.editOverlay(statusText, { text: "You are not pointing at a panel..." });
|
||||
}
|
||||
} else {
|
||||
Overlays.editOverlay(statusText, { text: "You are not pointing at a panel..." });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Script.scriptEnding.connect(function(){
|
||||
Overlays.deleteOverlay(screensOverlay);
|
||||
Overlays.deleteOverlay(structureOverlay);
|
||||
Overlays.deleteOverlay(statusText);
|
||||
});
|
Loading…
Reference in a new issue