mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 05:52:38 +02:00
marketplace now pops up a marketplace web entity
This commit is contained in:
parent
21bc06f154
commit
9bafd82b2c
2 changed files with 124 additions and 8 deletions
95
scripts/system/libraries/WebBuddy.js
Normal file
95
scripts/system/libraries/WebBuddy.js
Normal file
|
@ -0,0 +1,95 @@
|
|||
//
|
||||
// WebBuddy.js
|
||||
//
|
||||
// Created by Anthony J. Thibault on 8/8/2016
|
||||
// Copyright 2016 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 NEGATIVE_ONE = 65535;
|
||||
|
||||
// ctor
|
||||
WebBuddy = function (url) {
|
||||
|
||||
var ASPECT = 4.0 / 3.0;
|
||||
var WIDTH = 0.4;
|
||||
|
||||
var spawnPoint = Vec3.sum(Vec3.sum(MyAvatar.position, Vec3.multiply(1.0, Quat.getFront(MyAvatar.orientation))),
|
||||
{x: 0, y: 0.5, z: 0});
|
||||
|
||||
var webEntityPosition = spawnPoint;
|
||||
var webEntityRotation = MyAvatar.orientation;
|
||||
this.webEntityID = Entities.addEntity({
|
||||
type: "Web",
|
||||
sourceUrl: url,
|
||||
dimensions: {x: WIDTH, y: WIDTH * ASPECT, z: 0.1},
|
||||
position: webEntityPosition,
|
||||
rotation: webEntityRotation,
|
||||
name: "web",
|
||||
dynamic: true,
|
||||
angularDamping: 0.9,
|
||||
damping: 0.9,
|
||||
gravity: {x: 0, y: 0, z: 0},
|
||||
shapeType: "box",
|
||||
userData: JSON.stringify({
|
||||
"grabbableKey": {"grabbable": true}
|
||||
}),
|
||||
parentID: MyAvatar.sessionUUID,
|
||||
parentJointIndex: NEGATIVE_ONE
|
||||
});
|
||||
|
||||
this.state = "idle";
|
||||
|
||||
// compute the room/sensor matrix of the entity.
|
||||
var invRoomMat = Mat4.inverse(MyAvatar.sensorToWorldMatrix);
|
||||
var entityWorldMat = Mat4.createFromRotAndTrans(webEntityRotation, webEntityPosition);
|
||||
this.entityRoomMat = Mat4.multiply(invRoomMat, entityWorldMat);
|
||||
|
||||
var _this = this;
|
||||
this.updateFunc = function (dt) {
|
||||
_this.update(dt);
|
||||
};
|
||||
Script.update.connect(this.updateFunc);
|
||||
};
|
||||
|
||||
WebBuddy.prototype.destroy = function () {
|
||||
Entities.deleteEntity(this.webEntityID);
|
||||
Script.update.disconnect(this.updateFunc);
|
||||
};
|
||||
|
||||
WebBuddy.prototype.update = function (dt) {
|
||||
|
||||
var props = Entities.getEntityProperties(this.webEntityID, ["position", "rotation", "parentID", "parentJointIndex"]);
|
||||
var entityWorldMat;
|
||||
|
||||
if (this.state === "idle") {
|
||||
|
||||
if (props.parentID !== MyAvatar.sessionUUID || props.parentJointIndex !== NEGATIVE_ONE) {
|
||||
this.state = "held";
|
||||
return;
|
||||
}
|
||||
|
||||
// convert the sensor/room matrix of the entity into world space, using the current sensorToWorldMatrix
|
||||
var roomMat = MyAvatar.sensorToWorldMatrix;
|
||||
entityWorldMat = Mat4.multiply(roomMat, this.entityRoomMat);
|
||||
|
||||
// slam the world space position and orientation
|
||||
Entities.editEntity(this.webEntityID, {
|
||||
position: Mat4.extractTranslation(entityWorldMat),
|
||||
rotation: Mat4.extractRotation(entityWorldMat)
|
||||
});
|
||||
} else if (this.state === "held") {
|
||||
if (props.parentID === MyAvatar.sessionUUID && props.parentJointIndex === NEGATIVE_ONE) {
|
||||
|
||||
// re-compute the room/sensor matrix for the avatar now that it has been released.
|
||||
var invRoomMat = Mat4.inverse(MyAvatar.sensorToWorldMatrix);
|
||||
entityWorldMat = Mat4.createFromRotAndTrans(props.rotation, props.position);
|
||||
this.entityRoomMat = Mat4.multiply(invRoomMat, entityWorldMat);
|
||||
|
||||
this.state = "idle";
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -8,6 +8,9 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
/* global WebBuddy */
|
||||
Script.include("./libraries/WebBuddy.js");
|
||||
|
||||
var toolIconUrl = Script.resolvePath("assets/images/tools/");
|
||||
|
||||
var MARKETPLACE_URL = "https://metaverse.highfidelity.com/marketplace";
|
||||
|
@ -22,26 +25,44 @@ var marketplaceWindow = new OverlayWebWindow({
|
|||
var toolHeight = 50;
|
||||
var toolWidth = 50;
|
||||
var TOOLBAR_MARGIN_Y = 0;
|
||||
var marketplaceVisible = false;
|
||||
var marketplaceWebBuddy;
|
||||
|
||||
function shouldShowWebBuddyMarketplace() {
|
||||
var rightPose = Controller.getPoseValue(Controller.Standard.RightHand);
|
||||
var leftPose = Controller.getPoseValue(Controller.Standard.LeftHand);
|
||||
return HMD.active && (leftPose.valid || rightPose.valid);
|
||||
}
|
||||
|
||||
function showMarketplace(marketplaceID) {
|
||||
var url = MARKETPLACE_URL;
|
||||
if (marketplaceID) {
|
||||
url = url + "/items/" + marketplaceID;
|
||||
if (shouldShowWebBuddyMarketplace()) {
|
||||
marketplaceWebBuddy = new WebBuddy("https://metaverse.highfidelity.com/marketplace");
|
||||
} else {
|
||||
var url = MARKETPLACE_URL;
|
||||
if (marketplaceID) {
|
||||
url = url + "/items/" + marketplaceID;
|
||||
}
|
||||
marketplaceWindow.setURL(url);
|
||||
marketplaceWindow.setVisible(true);
|
||||
}
|
||||
marketplaceWindow.setURL(url);
|
||||
marketplaceWindow.setVisible(true);
|
||||
|
||||
marketplaceVisible = true;
|
||||
UserActivityLogger.openedMarketplace();
|
||||
}
|
||||
|
||||
function hideMarketplace() {
|
||||
marketplaceWindow.setVisible(false);
|
||||
marketplaceWindow.setURL("about:blank");
|
||||
if (marketplaceWindow.visible) {
|
||||
marketplaceWindow.setVisible(false);
|
||||
marketplaceWindow.setURL("about:blank");
|
||||
} else {
|
||||
marketplaceWebBuddy.destroy();
|
||||
marketplaceWebBuddy = null;
|
||||
}
|
||||
marketplaceVisible = false;
|
||||
}
|
||||
|
||||
function toggleMarketplace() {
|
||||
if (marketplaceWindow.visible) {
|
||||
if (marketplaceVisible) {
|
||||
hideMarketplace();
|
||||
} else {
|
||||
showMarketplace();
|
||||
|
|
Loading…
Reference in a new issue