Merge pull request #13884 from ctrlaltdavid/M17853

Highlight tablet when it is near-grabbable
This commit is contained in:
Brad Hefta-Gaub 2018-10-23 12:31:41 -07:00 committed by GitHub
commit 447bfae828
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 158 additions and 17 deletions

View file

@ -528,6 +528,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Selection.disableListHighlight(DISPATCHER_HOVERING_LIST); Selection.disableListHighlight(DISPATCHER_HOVERING_LIST);
}; };
} }
function mouseReleaseOnOverlay(overlayID, event) { function mouseReleaseOnOverlay(overlayID, event) {
if (HMD.homeButtonID && overlayID === HMD.homeButtonID && event.button === "Primary") { if (HMD.homeButtonID && overlayID === HMD.homeButtonID && event.button === "Primary") {
Messages.sendLocalMessage("home", overlayID); Messages.sendLocalMessage("home", overlayID);
@ -546,9 +547,11 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
} }
} }
} }
Overlays.mouseReleaseOnOverlay.connect(mouseReleaseOnOverlay); Overlays.mouseReleaseOnOverlay.connect(mouseReleaseOnOverlay);
Overlays.mousePressOnOverlay.connect(mousePress); Overlays.mousePressOnOverlay.connect(mousePress);
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.messageReceived.connect(controllerDispatcher.handleHandMessage); Messages.messageReceived.connect(controllerDispatcher.handleHandMessage);

View file

@ -427,7 +427,8 @@ Script.include("/~/system/libraries/controllers.js");
this.hand === RIGHT_HAND ? "RightFarTriggerEntity" : "LeftFarTriggerEntity", this.hand === RIGHT_HAND ? "RightFarTriggerEntity" : "LeftFarTriggerEntity",
this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity", this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity",
this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity", this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity",
this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay" this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay",
this.hand === RIGHT_HAND ? "RightNearTabletHighlight" : "LeftNearTabletHighlight"
]; ];
var nearGrabReadiness = []; var nearGrabReadiness = [];

View file

@ -376,7 +376,8 @@ Script.include("/~/system/libraries/controllers.js");
this.hand === RIGHT_HAND ? "RightFarTriggerEntity" : "LeftFarTriggerEntity", this.hand === RIGHT_HAND ? "RightFarTriggerEntity" : "LeftFarTriggerEntity",
this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity", this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity",
this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity", this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity",
this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay" this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay",
this.hand === RIGHT_HAND ? "RightNearTabletHighlight" : "LeftNearTabletHighlight"
]; ];
var nearGrabReadiness = []; var nearGrabReadiness = [];

View file

@ -469,7 +469,8 @@ Script.include("/~/system/libraries/controllers.js");
this.hand === RIGHT_HAND ? "RightFarTriggerEntity" : "LeftFarTriggerEntity", this.hand === RIGHT_HAND ? "RightFarTriggerEntity" : "LeftFarTriggerEntity",
this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity", this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity",
this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity", this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity",
this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay" this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay",
this.hand === RIGHT_HAND ? "RightNearTabletHighlight" : "LeftNearTabletHighlight"
]; ];
var nearGrabReadiness = []; var nearGrabReadiness = [];

View file

@ -158,11 +158,12 @@ Script.include("/~/system/libraries/utils.js");
} }
} }
var nearOverlay = getEnabledModuleByName(this.hand === RIGHT_HAND // Tablet highlight and grabbing.
? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay"); var tabletHighlight = getEnabledModuleByName(this.hand === RIGHT_HAND
if (nearOverlay) { ? "RightNearTabletHighlight" : "LeftNearTabletHighlight");
var nearOverlayReady = nearOverlay.isReady(controllerData); if (tabletHighlight) {
if (nearOverlayReady.active && HMD.tabletID && nearOverlay.grabbedThingID === HMD.tabletID) { var tabletHighlightReady = tabletHighlight.isReady(controllerData);
if (tabletHighlightReady.active) {
return this.exitModule(); return this.exitModule();
} }
} }

View file

@ -101,13 +101,12 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
} }
} }
// Tablet grabbing. // Tablet highlight and grabbing.
var nearOverlay = getEnabledModuleByName(this.hand === RIGHT_HAND ? var tabletHighlight = getEnabledModuleByName(this.hand === RIGHT_HAND
"RightNearParentingGrabOverlay" : ? "RightNearTabletHighlight" : "LeftNearTabletHighlight");
"LeftNearParentingGrabOverlay"); if (tabletHighlight) {
if (nearOverlay) { var tabletHighlightReady = tabletHighlight.isReady(controllerData);
var nearOverlayReady = nearOverlay.isReady(controllerData); if (tabletHighlightReady.active) {
if (nearOverlayReady.active && HMD.tabletID && nearOverlay.grabbedThingID === HMD.tabletID) {
return this.exitModule(); return this.exitModule();
} }
} }

View file

@ -0,0 +1,121 @@
//
// nearTabletHighlight.js
//
// Highlight the tablet if a hand is near enough to grab it and it isn't grabbed.
//
// Created by David Rowe on 28 Aug 2018.
// Copyright 2018 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
//
/* global LEFT_HAND, RIGHT_HAND, makeDispatcherModuleParameters, makeRunningValues, enableDispatcherModule,
* disableDispatcherModule */
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
(function () {
"use strict";
var TABLET_GRABBABLE_SELECTION_NAME = "tabletGrabbableSelection";
var TABLET_GRABBABLE_SELECTION_STYLE = {
outlineUnoccludedColor: { red: 0, green: 180, blue: 239 }, // #00b4ef
outlineUnoccludedAlpha: 1,
outlineOccludedColor: { red: 0, green: 0, blue: 0 },
outlineOccludedAlpha: 0,
fillUnoccludedColor: { red: 0, green: 0, blue: 0 },
fillUnoccludedAlpha: 0,
fillOccludedColor: { red: 0, green: 0, blue: 0 },
fillOccludedAlpha: 0,
outlineWidth: 4,
isOutlineSmooth: false
};
var isTabletNearGrabbable = [false, false];
var isTabletHighlighted = false;
function setTabletNearGrabbable(hand, enabled) {
if (enabled === isTabletNearGrabbable[hand]) {
return;
}
isTabletNearGrabbable[hand] = enabled;
if (isTabletNearGrabbable[LEFT_HAND] || isTabletNearGrabbable[RIGHT_HAND]) {
if (!isTabletHighlighted) {
Selection.addToSelectedItemsList(TABLET_GRABBABLE_SELECTION_NAME, "overlay", HMD.tabletID);
isTabletHighlighted = true;
}
} else {
if (isTabletHighlighted) {
Selection.removeFromSelectedItemsList(TABLET_GRABBABLE_SELECTION_NAME, "overlay", HMD.tabletID);
isTabletHighlighted = false;
}
}
}
function NearTabletHighlight(hand) {
this.hand = hand;
this.parameters = makeDispatcherModuleParameters(
95,
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
[],
100
);
this.isNearTablet = function (controllerData) {
return HMD.tabletID && controllerData.nearbyOverlayIDs[this.hand].indexOf(HMD.tabletID) !== -1;
};
this.isReady = function (controllerData) {
if (this.isNearTablet(controllerData)) {
return makeRunningValues(true, [], []);
}
setTabletNearGrabbable(this.hand, false);
return makeRunningValues(false, [], []);
};
this.run = function (controllerData) {
if (!this.isNearTablet(controllerData)) {
setTabletNearGrabbable(this.hand, false);
return makeRunningValues(false, [], []);
}
if (controllerData.triggerClicks[this.hand] || controllerData.secondaryValues[this.hand]) {
setTabletNearGrabbable(this.hand, false);
return makeRunningValues(false, [], []);
}
setTabletNearGrabbable(this.hand, true);
return makeRunningValues(true, [], []);
};
}
var leftNearTabletHighlight = new NearTabletHighlight(LEFT_HAND);
var rightNearTabletHighlight = new NearTabletHighlight(RIGHT_HAND);
enableDispatcherModule("LeftNearTabletHighlight", leftNearTabletHighlight);
enableDispatcherModule("RightNearTabletHighlight", rightNearTabletHighlight);
function onDisplayModeChanged() {
if (HMD.active) {
Selection.enableListHighlight(TABLET_GRABBABLE_SELECTION_NAME, TABLET_GRABBABLE_SELECTION_STYLE);
} else {
Selection.disableListHighlight(TABLET_GRABBABLE_SELECTION_NAME);
Selection.clearSelectedItemsList(TABLET_GRABBABLE_SELECTION_NAME);
}
}
HMD.displayModeChanged.connect(onDisplayModeChanged);
HMD.mountedChanged.connect(onDisplayModeChanged);
onDisplayModeChanged();
function cleanUp() {
disableDispatcherModule("LeftNearTabletHighlight");
disableDispatcherModule("RightNearTabletHighlight");
Selection.disableListHighlight(TABLET_GRABBABLE_SELECTION_NAME);
}
Script.scriptEnding.connect(cleanUp);
}());

View file

@ -61,7 +61,13 @@ Script.include("/~/system/libraries/controllers.js");
var farGrabModuleName = this.hand === RIGHT_HAND ? "RightFarActionGrabEntity" : "LeftFarActionGrabEntity"; var farGrabModuleName = this.hand === RIGHT_HAND ? "RightFarActionGrabEntity" : "LeftFarActionGrabEntity";
var farGrabModule = getEnabledModuleByName(farGrabModuleName); var farGrabModule = getEnabledModuleByName(farGrabModuleName);
var farGrabModuleReady = farGrabModule ? farGrabModule.isReady(controllerData) : makeRunningValues(false, [], []); var farGrabModuleReady = farGrabModule ? farGrabModule.isReady(controllerData) : makeRunningValues(false, [], []);
return grabOverlayModuleReady.active || farGrabModuleReady.active || grabEntityModuleReady.active; var nearTabletHighlightModuleName =
this.hand === RIGHT_HAND ? "RightNearTabletHighlight" : "LeftNearTabletHighlight";
var nearTabletHighlightModule = getEnabledModuleByName(nearTabletHighlightModuleName);
var nearTabletHighlightModuleReady = nearTabletHighlightModule
? nearTabletHighlightModule.isReady(controllerData) : makeRunningValues(false, [], []);
return grabOverlayModuleReady.active || farGrabModuleReady.active || grabEntityModuleReady.active
|| nearTabletHighlightModuleReady.active;
}; };
this.overlayLaserActive = function(controllerData) { this.overlayLaserActive = function(controllerData) {

View file

@ -58,6 +58,13 @@ Script.include("/~/system/libraries/controllers.js");
} }
} }
} }
var nearTabletHighlightModule = getEnabledModuleByName(this.hand === RIGHT_HAND
? "RightNearTabletHighlight" : "LeftNearTabletHighlight");
if (nearTabletHighlightModule) {
return nearTabletHighlightModule.isNearTablet(controllerData);
}
return false; return false;
}; };

View file

@ -37,7 +37,8 @@ var CONTOLLER_SCRIPTS = [
"controllerModules/scaleEntity.js", "controllerModules/scaleEntity.js",
"controllerModules/highlightNearbyEntities.js", "controllerModules/highlightNearbyEntities.js",
"controllerModules/nearGrabHyperLinkEntity.js", "controllerModules/nearGrabHyperLinkEntity.js",
"controllerModules/mouseHighlightEntities.js" "controllerModules/mouseHighlightEntities.js",
"controllerModules/nearTabletHighlight.js"
]; ];
var DEBUG_MENU_ITEM = "Debug defaultScripts.js"; var DEBUG_MENU_ITEM = "Debug defaultScripts.js";