revert to use overlays instead of entities for tablet highlighting

This commit is contained in:
Dante Ruiz 2018-08-07 10:56:53 -07:00
parent 079b276c2b
commit d78c571df6
5 changed files with 59 additions and 67 deletions

View file

@ -56,8 +56,7 @@ class QScriptEngine;
* @property {Uuid} tabletID - The UUID of the tablet body model overlay.
* @property {Uuid} tabletScreenID - The UUID of the tablet's screen overlay.
* @property {Uuid} homeButtonID - The UUID of the tablet's "home" button overlay.
* @property {Uuid} homeButtonHighlightMaterialID - The UUID of the material entity used to highlight tablet button
* @property {Uuid} homeButtonUnhighlightMaterialID - The UUID of the material entity use to unhighlight the entity
* @property {Uuid} homeButtonHighlightID - The UUID of the tablet's "home" button highlight overlay.
*/
class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Dependency {
Q_OBJECT
@ -69,11 +68,10 @@ class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Depen
Q_PROPERTY(QUuid tabletID READ getCurrentTabletFrameID WRITE setCurrentTabletFrameID)
Q_PROPERTY(QUuid homeButtonID READ getCurrentHomeButtonID WRITE setCurrentHomeButtonID)
Q_PROPERTY(QUuid tabletScreenID READ getCurrentTabletScreenID WRITE setCurrentTabletScreenID)
Q_PROPERTY(QUuid homeButtonHighlightMaterialID READ getCurrentHomeButtonHighlightMaterialID WRITE setCurrentHomeButtonHighlightMaterialID)
Q_PROPERTY(QUuid homeButtonUnhighlightMaterialID READ getCurrentHomeButtonUnhighlightMaterialID WRITE setCurrentHomeButtonUnhighlightMaterialID)
Q_PROPERTY(QUuid homeButtonHighlightID READ getCurrentHomeButtonHighlightID WRITE setCurrentHomeButtonHighlightID)
public:
/**jsdoc
* Calculate the intersection of a ray with the HUD overlay.
* @function HMD.calculateRayUICollisionPoint
@ -365,15 +363,12 @@ public:
void setCurrentHomeButtonID(QUuid homeButtonID) { _homeButtonID = homeButtonID; }
QUuid getCurrentHomeButtonID() const { return _homeButtonID; }
void setCurrentHomeButtonHighlightID(QUuid homeButtonHighlightID) { _homeButtonHighlightID = homeButtonHighlightID; }
QUuid getCurrentHomeButtonHighlightID() const { return _homeButtonHighlightID; }
void setCurrentTabletScreenID(QUuid tabletID) { _tabletScreenID = tabletID; }
QUuid getCurrentTabletScreenID() const { return _tabletScreenID; }
void setCurrentHomeButtonHighlightMaterialID(QUuid homeButtonHighlightMaterialID) { _homeButtonHighlightMaterialID = homeButtonHighlightMaterialID; }
QUuid getCurrentHomeButtonHighlightMaterialID() { return _homeButtonHighlightMaterialID; }
void setCurrentHomeButtonUnhighlightMaterialID(QUuid homeButtonUnhighlightMaterialID) { _homeButtonUnhighlightMaterialID = homeButtonUnhighlightMaterialID; }
QUuid getCurrentHomeButtonUnhighlightMaterialID() { return _homeButtonUnhighlightMaterialID; }
private:
bool _showTablet { false };
bool _tabletContextualMode { false };
@ -381,8 +376,7 @@ private:
QUuid _tabletScreenID; // this is the overlayID which is part of (a child of) the tablet-ui.
QUuid _homeButtonID;
QUuid _tabletEntityID;
QUuid _homeButtonHighlightMaterialID;
QUuid _homeButtonUnhighlightMaterialID;
QUuid _homeButtonHighlightID;
// Get the position of the HMD
glm::vec3 getPosition() const;

View file

@ -87,8 +87,7 @@ cleanUpOldMaterialEntities = function() {
for (var entityID in avatarEntityData) {
var entityName = Entities.getEntityProperties(entityID, ["name"]).name;
if (entityName === TABLET_MATERIAL_ENTITY_NAME && entityID !== HMD.homeButtonHighlightMaterialID &&
entityID !== HMD.homeButtonUnhighlightMaterialID) {
if (entityName === TABLET_MATERIAL_ENTITY_NAME) {
Entities.deleteEntity(entityID);
}
}
@ -194,45 +193,21 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
parentJointIndex: -1
});
this.homeButtonUnhighlightMaterial = Entities.addEntity({
type: "Material",
name: TABLET_MATERIAL_ENTITY_NAME,
materialURL: "materialData",
localPosition: { x: 0.0, y: 0.0, z: 0.0 },
priority: HIGH_PRIORITY,
materialData: JSON.stringify({
materials: {
albedoMap: LOCAL_NORMAL_BEZEL
}
}),
userData: JSON.stringify({
"grabbableKey": {"grabbable": false}
}),
visible: false,
parentMaterialName: SUBMESH,
parentID: this.tabletEntityID
}, true);
this.homeButtonHighlightMaterial = Entities.addEntity({
type: "Material",
name: TABLET_MATERIAL_ENTITY_NAME,
materialURL: "materialData",
localPosition: { x: 0.0, y: 0.0, z: 0.0 },
priority: LOW_PRIORITY,
visible: false,
materialData: JSON.stringify({
materials: {
emissiveMap: LOCAL_BEZEL_HIGHLIGHT
}
}),
userData: JSON.stringify({
"grabbableKey": {"grabbable": false}
}),
parentMaterialName: SUBMESH,
parentID: this.tabletEntityID
}, true);
this.homeButtonHighlightID = Overlays.addOverlay("circle3d", {
name: "homeButtonHighlight",
localPosition: { x: -HOME_BUTTON_X_OFFSET, y: HOME_BUTTON_Y_OFFSET, z: -HOME_BUTTON_Z_OFFSET },
localRotation: { x: 0, y: 1, z: 0, w: 0},
dimensions: { x: homeButtonDim, y: homeButtonDim, z: homeButtonDim },
color: {red: 255, green: 255, blue: 255},
solid: true,
innerRadius: 0.9,
ignoreIntersection: true,
alpha: 0.0,
visible: visible,
drawInFront: false,
parentID: this.tabletEntityID,
parentJointIndex: -1
});
this.receive = function (channel, senderID, senderUUID, localOnly) {
if (_this.homeButtonID === senderID) {
@ -387,8 +362,7 @@ WebTablet.prototype.destroy = function () {
Overlays.deleteOverlay(this.webOverlayID);
Overlays.deleteOverlay(this.tabletEntityID);
Overlays.deleteOverlay(this.homeButtonID);
Entities.deleteEntity(this.homeButtonUnhighlightMaterial);
Entities.deleteEntity(this.homeButtonHighlightMaterial);
Overlays.deleteOverlay(this.homeButtonHighlightID);
HMD.displayModeChanged.disconnect(this.myOnHmdChanged);
Controller.mousePressEvent.disconnect(this.myMousePressEvent);
@ -482,22 +456,19 @@ WebTablet.prototype.calculateWorldAttitudeRelativeToCamera = function (windowPos
WebTablet.prototype.onHoverEnterOverlay = function (overlayID, pointerEvent) {
if (overlayID === this.homeButtonID) {
Entities.editEntity(this.homeButtonUnhighlightMaterial, {priority: LOW_PRIORITY});
Entities.editEntity(this.homeButtonHighlightMaterial, {priority: HIGH_PRIORITY});
Overlays.editOverlay(this.homeButtonHighlightID, { alpha: 1.0 });
}
};
WebTablet.prototype.onHoverOverOverlay = function (overlayID, pointerEvent) {
if (overlayID !== this.homeButtonID) {
Entities.editEntity(this.homeButtonUnhighlightMaterial, {priority: HIGH_PRIORITY});
Entities.editEntity(this.homeButtonHighlightMaterial, {priority: LOW_PRIORITY});
Overlays.editOverlay(this.homeButtonHighlightID, { alpha: 0.0 });
}
};
WebTablet.prototype.onHoverLeaveOverlay = function (overlayID, pointerEvent) {
if (overlayID === this.homeButtonID) {
Entities.editEntity(this.homeButtonUnhighlightMaterial, {priority: HIGH_PRIORITY});
Entities.editEntity(this.homeButtonHighlightMaterial, {priority: LOW_PRIORITY});
Overlays.editOverlay(this.homeButtonHighlightID, { alpha: 0.0 });
}
};
@ -627,6 +598,21 @@ WebTablet.prototype.scheduleMouseMoveProcessor = function() {
}
};
WebTablet.prototype.handleMouseButtonHover = function(x, y) {
var pickRay = Camera.computePickRay(x, y);
var entityPickResults;
var homebuttonHovered = false;
entityPickResults = Overlays.findRayIntersection(pickRay, true, [this.tabletEntityID]);
if (entityPickResults.intersects && (entityPickResults.entityID === this.tabletEntityID ||
entityPickResults.overlayID === this.tabletEntityID)) {
var overlayPickResults = Overlays.findRayIntersection(pickRay, true, [this.homeButtonID], []);
if (overlayPickResults.intersects && overlayPickResults.overlayID === this.homeButtonID) {
homebuttonHovered = true;
}
}
Overlays.editOverlay(this.homeButtonHighlightID, { alpha: homebuttonHovered ? 1.0 : 0.0 });
};
WebTablet.prototype.mouseMoveEvent = function (event) {
if (this.dragging) {
this.currentMouse = {
@ -634,6 +620,8 @@ WebTablet.prototype.mouseMoveEvent = function (event) {
y: event.y
};
this.scheduleMouseMoveProcessor();
} else {
this.handleHomeButtonHover(event.x, event.y);
}
};
@ -660,6 +648,8 @@ WebTablet.prototype.mouseMoveProcessor = function () {
});
}
this.scheduleMouseMoveProcessor();
} else {
this.handleHomeButtonHover(this.currentMouse.x, this.currentMouse.y);
}
};

View file

@ -370,7 +370,7 @@ getTabletWidthFromSettings = function () {
resizeTablet = function (width, newParentJointIndex, sensorToWorldScaleOverride) {
if (!HMD.tabletID || !HMD.tabletScreenID || !HMD.homeButtonID) {
if (!HMD.tabletID || !HMD.tabletScreenID || !HMD.homeButtonID || !HMD.homeButtonHighlightID) {
return;
}
var sensorScaleFactor = sensorToWorldScaleOverride || MyAvatar.sensorToWorldScale;
@ -422,6 +422,12 @@ resizeTablet = function (width, newParentJointIndex, sensorToWorldScaleOverride)
localRotation: { x: 0, y: 1, z: 0, w: 0 },
dimensions: { x: homeButtonDim, y: homeButtonDim, z: homeButtonDim }
});
Overlays.editOverlay(HMD.homeButtonHighlightID, {
localPosition: { x: -HOME_BUTTON_X_OFFSET, y: HOME_BUTTON_Y_OFFSET, z: -HOME_BUTTON_Z_OFFSET },
localRotation: { x: 0, y: 1, z: 0, w: 0 },
dimensions: { x: homeButtonDim, y: homeButtonDim, z: homeButtonDim }
});
};
getMainTabletIDs = function () {

View file

@ -114,6 +114,7 @@ var selectionDisplay = null; // for gridTool.js to ignore
Overlays.editOverlay(HMD.tabletID, { isVisibleInSecondaryCamera : visibleInSecondaryCam });
Overlays.editOverlay(HMD.homeButtonID, { isVisibleInSecondaryCamera : visibleInSecondaryCam });
Overlays.editOverlay(HMD.homeButtonHighlightID, { isVisibleInSecondaryCamera : visibleInSecondaryCam });
Overlays.editOverlay(HMD.tabletScreenID, { isVisibleInSecondaryCamera : visibleInSecondaryCam });
}

View file

@ -112,8 +112,7 @@
HMD.tabletID = UIWebTablet.tabletEntityID;
HMD.homeButtonID = UIWebTablet.homeButtonID;
HMD.tabletScreenID = UIWebTablet.webOverlayID;
HMD.homeButtonHighlightMaterialID = UIWebTablet.homeButtonHighlightMaterial;
HMD.homeButtonUnhighlightMaterialID = UIWebTablet.homeButtonUnhighlightMaterial;
HMD.homeButtonHighlightID = UIWebTablet.homeButtonHighlightID;
HMD.displayModeChanged.connect(onHmdChanged);
MyAvatar.sensorToWorldScaleChanged.connect(onSensorToWorldScaleChanged);
@ -139,6 +138,7 @@
tabletProperties.visible = true;
Overlays.editOverlay(HMD.tabletID, tabletProperties);
Overlays.editOverlay(HMD.homeButtonID, { visible: true });
Overlays.editOverlay(HMD.homeButtonHighlightID, { visible: true });
Overlays.editOverlay(HMD.tabletScreenID, { visible: true });
Overlays.editOverlay(HMD.tabletScreenID, { maxFPS: 90 });
updateTabletWidthFromSettings(true);
@ -159,6 +159,7 @@
Overlays.editOverlay(HMD.tabletID, { visible: false });
Overlays.editOverlay(HMD.homeButtonID, { visible: false });
Overlays.editOverlay(HMD.homeButtonHighlightID, { visible: false });
Overlays.editOverlay(HMD.tabletScreenID, { visible: false });
Overlays.editOverlay(HMD.tabletScreenID, { maxFPS: 1 });
}
@ -179,6 +180,7 @@
UIWebTablet = null;
HMD.tabletID = null;
HMD.homeButtonID = null;
HMD.homeButtonHighlightID = null;
HMD.tabletScreenID = null;
} else if (debugTablet) {
print("TABLET closeTabletUI, UIWebTablet is null");
@ -331,9 +333,8 @@
Overlays.deleteOverlay(tabletID);
HMD.tabletID = null;
HMD.homeButtonID = null;
HMD.homeButtonHighlightID = null;
HMD.tabletScreenID = null;
HMD.homeButtonHighlightMaterialID = null;
HMD.homeButtonUnhighlightMaterialID = null;
});
Script.setTimeout(cleanupMaterialEntities, 100);
}()); // END LOCAL_SCOPE