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

View file

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

View file

@ -370,7 +370,7 @@ getTabletWidthFromSettings = function () {
resizeTablet = function (width, newParentJointIndex, sensorToWorldScaleOverride) { resizeTablet = function (width, newParentJointIndex, sensorToWorldScaleOverride) {
if (!HMD.tabletID || !HMD.tabletScreenID || !HMD.homeButtonID) { if (!HMD.tabletID || !HMD.tabletScreenID || !HMD.homeButtonID || !HMD.homeButtonHighlightID) {
return; return;
} }
var sensorScaleFactor = sensorToWorldScaleOverride || MyAvatar.sensorToWorldScale; var sensorScaleFactor = sensorToWorldScaleOverride || MyAvatar.sensorToWorldScale;
@ -422,6 +422,12 @@ resizeTablet = function (width, newParentJointIndex, sensorToWorldScaleOverride)
localRotation: { x: 0, y: 1, z: 0, w: 0 }, localRotation: { x: 0, y: 1, z: 0, w: 0 },
dimensions: { x: homeButtonDim, y: homeButtonDim, z: homeButtonDim } 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 () { 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.tabletID, { isVisibleInSecondaryCamera : visibleInSecondaryCam });
Overlays.editOverlay(HMD.homeButtonID, { isVisibleInSecondaryCamera : visibleInSecondaryCam }); Overlays.editOverlay(HMD.homeButtonID, { isVisibleInSecondaryCamera : visibleInSecondaryCam });
Overlays.editOverlay(HMD.homeButtonHighlightID, { isVisibleInSecondaryCamera : visibleInSecondaryCam });
Overlays.editOverlay(HMD.tabletScreenID, { isVisibleInSecondaryCamera : visibleInSecondaryCam }); Overlays.editOverlay(HMD.tabletScreenID, { isVisibleInSecondaryCamera : visibleInSecondaryCam });
} }

View file

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