mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-24 07:33:46 +02:00
home button working
This commit is contained in:
parent
c8f30128c5
commit
1b7c89c41d
2 changed files with 45 additions and 3 deletions
|
@ -14,8 +14,8 @@ var Y_AXIS = {x: 0, y: 1, z: 0};
|
||||||
var DEFAULT_DPI = 32;
|
var DEFAULT_DPI = 32;
|
||||||
var DEFAULT_WIDTH = 0.5;
|
var DEFAULT_WIDTH = 0.5;
|
||||||
|
|
||||||
var TABLET_URL = "https://s3.amazonaws.com/hifi-public/tony/tablet.fbx";
|
|
||||||
|
|
||||||
|
var TABLET_URL = "https://s3.amazonaws.com/hifi-public/tony/tablet.fbx"
|
||||||
// returns object with two fields:
|
// returns object with two fields:
|
||||||
// * position - position in front of the user
|
// * position - position in front of the user
|
||||||
// * rotation - rotation of entity so it faces the user.
|
// * rotation - rotation of entity so it faces the user.
|
||||||
|
@ -39,8 +39,8 @@ function calcSpawnInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ctor
|
// ctor
|
||||||
WebTablet = function (url, width, dpi, location, clientOnly) {
|
WebTablet = function (url, width, dpi, clientOnly) {
|
||||||
|
var _this = this;
|
||||||
var ASPECT = 4.0 / 3.0;
|
var ASPECT = 4.0 / 3.0;
|
||||||
var WIDTH = width || DEFAULT_WIDTH;
|
var WIDTH = width || DEFAULT_WIDTH;
|
||||||
var HEIGHT = WIDTH * ASPECT;
|
var HEIGHT = WIDTH * ASPECT;
|
||||||
|
@ -71,8 +71,11 @@ WebTablet = function (url, width, dpi, location, clientOnly) {
|
||||||
|
|
||||||
this.tabletEntityID = Entities.addEntity(tabletProperties, clientOnly);
|
this.tabletEntityID = Entities.addEntity(tabletProperties, clientOnly);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var WEB_ENTITY_REDUCTION_FACTOR = {x: 0.78, y: 0.85};
|
var WEB_ENTITY_REDUCTION_FACTOR = {x: 0.78, y: 0.85};
|
||||||
var WEB_ENTITY_Z_OFFSET = -0.01;
|
var WEB_ENTITY_Z_OFFSET = -0.01;
|
||||||
|
var HOME_BUTTON_Y_OFFSET = -0.32;
|
||||||
|
|
||||||
this.createWebEntity = function(url) {
|
this.createWebEntity = function(url) {
|
||||||
if (_this.webEntityID) {
|
if (_this.webEntityID) {
|
||||||
|
@ -96,6 +99,28 @@ WebTablet = function (url, width, dpi, location, clientOnly) {
|
||||||
|
|
||||||
this.createWebEntity(url);
|
this.createWebEntity(url);
|
||||||
|
|
||||||
|
var homeButtonPosition = Vec3.sum(spawnInfo.position, Vec3.multiply(HOME_BUTTON_Y_OFFSET, Quat.getUp(webEntityRotation)));
|
||||||
|
this.homeButtonEntity = Entities.addEntity({
|
||||||
|
name: "homeButton",
|
||||||
|
type: "Sphere",
|
||||||
|
position: homeButtonPosition,
|
||||||
|
dimensions: {x: 0.05, y: 0.05, z: 0.05},
|
||||||
|
parentID: this.tabletEntityID,
|
||||||
|
script: "https://people.ucsc.edu/~druiz4/scripts/homeButton.js"
|
||||||
|
}, clientOnly);
|
||||||
|
|
||||||
|
this.receive = function (channel, senderID, senderUUID, localOnly) {
|
||||||
|
if (_this.homeButtonEntity == senderID) {
|
||||||
|
if (_this.clicked) {
|
||||||
|
Entities.editEntity(_this.homeButtonEntity, {color: {red: 0, green: 255, blue: 255}});
|
||||||
|
_this.clicked = false;
|
||||||
|
} else {
|
||||||
|
Entities.editEntity(_this.homeButtonEntity, {color: {red: 255, green: 255, blue: 0}});
|
||||||
|
_this.clicked = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.state = "idle";
|
this.state = "idle";
|
||||||
|
|
||||||
this.getRoot = function() {
|
this.getRoot = function() {
|
||||||
|
@ -105,15 +130,29 @@ WebTablet = function (url, width, dpi, location, clientOnly) {
|
||||||
this.getLocation = function() {
|
this.getLocation = function() {
|
||||||
return Entities.getEntityProperties(_this.tabletEntityID, ["localPosition", "localRotation"]);
|
return Entities.getEntityProperties(_this.tabletEntityID, ["localPosition", "localRotation"]);
|
||||||
};
|
};
|
||||||
|
this.clicked = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
WebTablet.prototype.destroy = function () {
|
WebTablet.prototype.destroy = function () {
|
||||||
Entities.deleteEntity(this.webEntityID);
|
Entities.deleteEntity(this.webEntityID);
|
||||||
Entities.deleteEntity(this.tabletEntityID);
|
Entities.deleteEntity(this.tabletEntityID);
|
||||||
|
Entities.deleteEntity(this.homeButtonEntity);
|
||||||
};
|
};
|
||||||
WebTablet.prototype.pickle = function () {
|
WebTablet.prototype.pickle = function () {
|
||||||
return JSON.stringify({webEntityID: this.webEntityID, tabletEntityID: this.tabletEntityID});
|
return JSON.stringify({webEntityID: this.webEntityID, tabletEntityID: this.tabletEntityID});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
WebTablet.prototype.register = function() {
|
||||||
|
Messages.subscribe("home");
|
||||||
|
Messages.messageReceived.connect(this.receive);
|
||||||
|
}
|
||||||
|
|
||||||
|
WebTablet.prototype.unregister = function() {
|
||||||
|
Messages.unsubscribe("home");
|
||||||
|
Messages.messageReceived.disconnect(this.receive);
|
||||||
|
}
|
||||||
|
|
||||||
WebTablet.unpickle = function (string) {
|
WebTablet.unpickle = function (string) {
|
||||||
if (!string) {
|
if (!string) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -30,6 +30,7 @@ var TOOLBAR_MARGIN_Y = 0;
|
||||||
var marketplaceVisible = false;
|
var marketplaceVisible = false;
|
||||||
var marketplaceWebTablet;
|
var marketplaceWebTablet;
|
||||||
|
|
||||||
|
|
||||||
// We persist clientOnly data in the .ini file, and reconsistitute it on restart.
|
// We persist clientOnly data in the .ini file, and reconsistitute it on restart.
|
||||||
// To keep things consistent, we pickle the tablet data in Settings, and kill any existing such on restart and domain change.
|
// To keep things consistent, we pickle the tablet data in Settings, and kill any existing such on restart and domain change.
|
||||||
var persistenceKey = "io.highfidelity.lastDomainTablet";
|
var persistenceKey = "io.highfidelity.lastDomainTablet";
|
||||||
|
@ -54,6 +55,7 @@ function showMarketplace(marketplaceID) {
|
||||||
null, // dpi
|
null, // dpi
|
||||||
null, // location
|
null, // location
|
||||||
true); // client-only
|
true); // client-only
|
||||||
|
marketplaceWebTablet.register();
|
||||||
}
|
}
|
||||||
Settings.setValue(persistenceKey, marketplaceWebTablet.pickle());
|
Settings.setValue(persistenceKey, marketplaceWebTablet.pickle());
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,6 +76,7 @@ function hideTablet(tablet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateButtonState(false);
|
updateButtonState(false);
|
||||||
|
tablet.unregister();
|
||||||
tablet.destroy();
|
tablet.destroy();
|
||||||
marketplaceWebTablet = null;
|
marketplaceWebTablet = null;
|
||||||
Settings.setValue(persistenceKey, "");
|
Settings.setValue(persistenceKey, "");
|
||||||
|
|
Loading…
Reference in a new issue