Provide mini tablet details via API instead of messages

This commit is contained in:
David Rowe 2018-09-28 14:23:08 +12:00
parent d98e7cea4e
commit 45993ba475
5 changed files with 27 additions and 63 deletions

View file

@ -57,6 +57,10 @@ class QScriptEngine;
* @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} homeButtonHighlightID - The UUID of the tablet's "home" button highlight overlay. * @property {Uuid} homeButtonHighlightID - The UUID of the tablet's "home" button highlight overlay.
* @property {Uuid} miniTabletID - The UUID of the mini tablet's body model overlay. <code>null</code> if not in HMD mode.
* @property {Uuid} miniTabletScreenID - The UUID of the mini tablet's screen overlay. <code>null</code> if not in HMD mode.
* @property {number} miniTabletHand - The hand that the mini tablet is displayed on: <code>0</code> for left hand,
* <code>1</code> for right hand, <code>-1</code> if not in HMD mode.
*/ */
class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Dependency { class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Dependency {
Q_OBJECT Q_OBJECT
@ -69,6 +73,9 @@ class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Depen
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 homeButtonHighlightID READ getCurrentHomeButtonHighlightID WRITE setCurrentHomeButtonHighlightID) Q_PROPERTY(QUuid homeButtonHighlightID READ getCurrentHomeButtonHighlightID WRITE setCurrentHomeButtonHighlightID)
Q_PROPERTY(QUuid miniTabletID READ getCurrentMiniTabletID WRITE setCurrentMiniTabletID)
Q_PROPERTY(QUuid miniTabletScreenID READ getCurrentMiniTabletScreenID WRITE setCurrentMiniTabletScreenID)
Q_PROPERTY(int miniTabletHand READ getCurrentMiniTabletHand WRITE setCurrentMiniTabletHand)
public: public:
@ -369,6 +376,15 @@ public:
void setCurrentTabletScreenID(QUuid tabletID) { _tabletScreenID = tabletID; } void setCurrentTabletScreenID(QUuid tabletID) { _tabletScreenID = tabletID; }
QUuid getCurrentTabletScreenID() const { return _tabletScreenID; } QUuid getCurrentTabletScreenID() const { return _tabletScreenID; }
void setCurrentMiniTabletID(QUuid miniTabletID) { _miniTabletID = miniTabletID; }
QUuid getCurrentMiniTabletID() const { return _miniTabletID; }
void setCurrentMiniTabletScreenID(QUuid miniTabletScreenID) { _miniTabletScreenID = miniTabletScreenID; }
QUuid getCurrentMiniTabletScreenID() const { return _miniTabletScreenID; }
void setCurrentMiniTabletHand(int miniTabletHand) { _miniTabletHand = miniTabletHand; }
int getCurrentMiniTabletHand() const { return _miniTabletHand; }
private: private:
bool _showTablet { false }; bool _showTablet { false };
bool _tabletContextualMode { false }; bool _tabletContextualMode { false };
@ -377,6 +393,9 @@ private:
QUuid _homeButtonID; QUuid _homeButtonID;
QUuid _tabletEntityID; QUuid _tabletEntityID;
QUuid _homeButtonHighlightID; QUuid _homeButtonHighlightID;
QUuid _miniTabletID;
QUuid _miniTabletScreenID;
int _miniTabletHand { -1 };
// Get the position of the HMD // Get the position of the HMD
glm::vec3 getPosition() const; glm::vec3 getPosition() const;

View file

@ -51,8 +51,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
this.tabletID = null; this.tabletID = null;
this.blacklist = []; this.blacklist = [];
this.pointerManager = new PointerManager(); this.pointerManager = new PointerManager();
this.miniTabletID = null;
this.niniTabletHand = LEFT_HAND;
// a module can occupy one or more "activity" slots while it's running. If all the required slots for a module are // a module can occupy one or more "activity" slots while it's running. If all the required slots for a module are
// not set to false (not in use), a module cannot start. When a module is using a slot, that module's name // not set to false (not in use), a module cannot start. When a module is using a slot, that module's name
@ -219,7 +217,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
// Tablet and mini-tablet must be within NEAR_TABLET_MAX_RADIUS in order to be grabbed. // Tablet and mini-tablet must be within NEAR_TABLET_MAX_RADIUS in order to be grabbed.
// Mini tablet can only be grabbed the hand it's displayed on. // Mini tablet can only be grabbed the hand it's displayed on.
var tabletIndex = nearbyOverlays.indexOf(HMD.tabletID); var tabletIndex = nearbyOverlays.indexOf(HMD.tabletID);
var miniTabletIndex = nearbyOverlays.indexOf(_this.miniTabletID); var miniTabletIndex = nearbyOverlays.indexOf(HMD.miniTabletID);
if (tabletIndex !== -1 || miniTabletIndex !== -1) { if (tabletIndex !== -1 || miniTabletIndex !== -1) {
var closebyOverlays = var closebyOverlays =
Overlays.findOverlays(controllerLocations[h].position, NEAR_TABLET_MAX_RADIUS * sensorScaleFactor); Overlays.findOverlays(controllerLocations[h].position, NEAR_TABLET_MAX_RADIUS * sensorScaleFactor);
@ -228,7 +226,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
nearbyOverlays.splice(tabletIndex, 1); nearbyOverlays.splice(tabletIndex, 1);
} }
if (miniTabletIndex !== -1 if (miniTabletIndex !== -1
&& ((closebyOverlays.indexOf(_this.miniTabletID) === -1) || h !== _this.miniTabletHand)) { && ((closebyOverlays.indexOf(HMD.miniTabletID) === -1) || h !== HMD.miniTabletHand)) {
nearbyOverlays.splice(miniTabletIndex, 1); nearbyOverlays.splice(miniTabletIndex, 1);
} }
} }
@ -493,12 +491,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
_this.setBlacklist(); _this.setBlacklist();
} }
} }
} else if (channel === 'Hifi-MiniTablet-Details') {
message = JSON.parse(data);
_this.miniTabletID = message.overlay;
_this.miniTabletHand = message.hand;
} }
} catch (e) { } catch (e) {
print("WARNING: handControllerGrab.js -- error parsing message: " + data); print("WARNING: handControllerGrab.js -- error parsing message: " + data);
} }
@ -535,7 +528,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Entities.mousePressOnEntity.connect(mousePress); Entities.mousePressOnEntity.connect(mousePress);
var controllerDispatcher = new ControllerDispatcher(); var controllerDispatcher = new ControllerDispatcher();
Messages.subscribe('Hifi-Hand-RayPick-Blacklist'); Messages.subscribe('Hifi-Hand-RayPick-Blacklist');
Messages.subscribe('Hifi-MiniTablet-Details');
Messages.messageReceived.connect(controllerDispatcher.handleHandMessage); Messages.messageReceived.connect(controllerDispatcher.handleHandMessage);
Script.scriptEnding.connect(controllerDispatcher.cleanup); Script.scriptEnding.connect(controllerDispatcher.cleanup);
Script.setTimeout(controllerDispatcher.update, BASIC_TIMER_INTERVAL_MS); Script.setTimeout(controllerDispatcher.update, BASIC_TIMER_INTERVAL_MS);

View file

@ -27,7 +27,6 @@ Script.include("/~/system/libraries/utils.js");
this.previousParentJointIndex = {}; this.previousParentJointIndex = {};
this.previouslyUnhooked = {}; this.previouslyUnhooked = {};
this.robbed = false; this.robbed = false;
this.miniTabletID = null;
this.parameters = makeDispatcherModuleParameters( this.parameters = makeDispatcherModuleParameters(
90, 90,
@ -43,10 +42,6 @@ Script.include("/~/system/libraries/utils.js");
return (this.hand === RIGHT_HAND) ? leftNearParentingGrabOverlay : rightNearParentingGrabOverlay; return (this.hand === RIGHT_HAND) ? leftNearParentingGrabOverlay : rightNearParentingGrabOverlay;
}; };
this.setMiniTabletID = function (id) {
this.miniTabletID = id;
};
this.otherHandIsParent = function(props) { this.otherHandIsParent = function(props) {
return this.getOtherModule().thisHandIsParent(props); return this.getOtherModule().thisHandIsParent(props);
}; };
@ -168,7 +163,7 @@ Script.include("/~/system/libraries/utils.js");
var handPosition = controllerData.controllerLocations[this.hand].position; var handPosition = controllerData.controllerLocations[this.hand].position;
var distance = Vec3.distance(overlayPosition, handPosition); var distance = Vec3.distance(overlayPosition, handPosition);
if (distance <= NEAR_GRAB_RADIUS * sensorScaleFactor) { if (distance <= NEAR_GRAB_RADIUS * sensorScaleFactor) {
if (overlays[i] !== this.miniTabletID || controllerData.secondaryValues[this.hand] === 0) { if (overlays[i] !== HMD.miniTabletID || controllerData.secondaryValues[this.hand] === 0) {
// Don't grab mini tablet with grip. // Don't grab mini tablet with grip.
return overlays[i]; return overlays[i];
} }
@ -225,25 +220,6 @@ Script.include("/~/system/libraries/utils.js");
}; };
} }
function handleMessage(channel, data, sender) {
if (sender !== MyAvatar.sessionUUID) {
return;
}
if (channel === 'Hifi-MiniTablet-Details') {
try {
var message = JSON.parse(data);
leftNearParentingGrabOverlay.setMiniTabletID(message.overlay);
rightNearParentingGrabOverlay.setMiniTabletID(message.overlay);
} catch (e) {
print("WARNING: nearParentGrabOverlay.js -- error parsing message: " + data);
}
}
}
Messages.subscribe('Hifi-MiniTablet-Details');
Messages.messageReceived.connect(handleMessage);
var leftNearParentingGrabOverlay = new NearParentingGrabOverlay(LEFT_HAND); var leftNearParentingGrabOverlay = new NearParentingGrabOverlay(LEFT_HAND);
var rightNearParentingGrabOverlay = new NearParentingGrabOverlay(RIGHT_HAND); var rightNearParentingGrabOverlay = new NearParentingGrabOverlay(RIGHT_HAND);

View file

@ -58,12 +58,6 @@ Script.include("/~/system/libraries/controllers.js");
enabled: true enabled: true
}); });
this.miniTabletID = null;
this.setMiniTabletID = function (id) {
this.miniTabletID = id;
};
this.disable = false; this.disable = false;
this.otherModuleNeedsToRun = function(controllerData) { this.otherModuleNeedsToRun = function(controllerData) {
@ -130,8 +124,8 @@ Script.include("/~/system/libraries/controllers.js");
} }
// Add the mini tablet. // Add the mini tablet.
if (this.miniTabletID && Overlays.getProperty(this.miniTabletID, "visible")) { if (HMD.miniTabletScreenID && Overlays.getProperty(HMD.miniTabletScreenID, "visible")) {
stylusTarget = getOverlayDistance(controllerPosition, this.miniTabletID); stylusTarget = getOverlayDistance(controllerPosition, HMD.miniTabletScreenID);
if (stylusTarget) { if (stylusTarget) {
stylusTargets.push(stylusTarget); stylusTargets.push(stylusTarget);
} }
@ -205,15 +199,6 @@ Script.include("/~/system/libraries/controllers.js");
} }
} }
function onMessageReceived(channel, message, sender) {
if (sender === MyAvatar.sessionUUID) {
if (channel === 'Hifi-MiniTablet-UI-ID') {
leftTabletStylusInput.setMiniTabletID(message);
rightTabletStylusInput.setMiniTabletID(message);
}
}
}
var leftTabletStylusInput = new StylusInput(LEFT_HAND); var leftTabletStylusInput = new StylusInput(LEFT_HAND);
var rightTabletStylusInput = new StylusInput(RIGHT_HAND); var rightTabletStylusInput = new StylusInput(RIGHT_HAND);
@ -224,11 +209,7 @@ Script.include("/~/system/libraries/controllers.js");
Overlays.hoverLeaveOverlay.connect(mouseHoverLeave); Overlays.hoverLeaveOverlay.connect(mouseHoverLeave);
Overlays.mousePressOnOverlay.connect(mousePress); Overlays.mousePressOnOverlay.connect(mousePress);
Messages.subscribe('Hifi-MiniTablet-UI-ID');
Messages.messageReceived.connect(onMessageReceived);
this.cleanup = function () { this.cleanup = function () {
Messages.messageReceived.disconnect(onMessageReceived);
leftTabletStylusInput.cleanup(); leftTabletStylusInput.cleanup();
rightTabletStylusInput.cleanup(); rightTabletStylusInput.cleanup();
disableDispatcherModule("LeftTabletStylusInput"); disableDispatcherModule("LeftTabletStylusInput");

View file

@ -231,13 +231,9 @@
function updateMiniTabletID() { function updateMiniTabletID() {
// Send mini-tablet overlay ID to controllerDispatcher so that it can use a smaller near grab distance. HMD.miniTabletID = miniOverlay;
Messages.sendLocalMessage("Hifi-MiniTablet-Details", JSON.stringify({ HMD.miniTabletScreenID = miniUIOverlay;
overlay: miniOverlay, HMD.miniTabletHand = miniOverlay ? uiHand : -1;
hand: uiHand
}));
// Send mini-tablet UI overlay ID to stylusInput so that styluses can be used on it.
Messages.sendLocalMessage("Hifi-MiniTablet-UI-ID", miniUIOverlay);
} }
function playSound(sound, volume) { function playSound(sound, volume) {