From 5852224a317089396de3b42955215661a1f054c5 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 13 Nov 2017 13:37:53 -0800 Subject: [PATCH] clean up code and finialize changes --- .../controllers/controllerDispatcher.js | 12 +++---- .../controllerModules/hudOverlayPointer.js | 1 - .../controllerModules/inEditMode.js | 2 +- .../controllerModules/tabletStylusInput.js | 35 +++++++------------ ...yLaserInput.js => webSurfaceLaserInput.js} | 13 +++++-- .../system/controllers/controllerScripts.js | 2 +- .../libraries/controllerDispatcherUtils.js | 3 +- scripts/system/libraries/pointersUtils.js | 14 +++++++- 8 files changed, 44 insertions(+), 38 deletions(-) rename scripts/system/controllers/controllerModules/{overlayLaserInput.js => webSurfaceLaserInput.js} (90%) diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 1ec78f0b14..b04363e2fb 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -11,7 +11,7 @@ controllerDispatcherPlugins:true, controllerDispatcherPluginsNeedSort:true, LEFT_HAND, RIGHT_HAND, NEAR_GRAB_PICK_RADIUS, DEFAULT_SEARCH_SPHERE_DISTANCE, DISPATCHER_PROPERTIES, getGrabPointSphereOffset, HMD, MyAvatar, Messages, findHandChildEntities, Pointers, PickType, COLORS_GRAB_SEARCHING_HALF_SQUEEZE - COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, Picks, TRIGGER_ON_VALUE + COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, Picks, TRIGGER_ON_VALUE, PointerManager */ controllerDispatcherPlugins = {}; @@ -325,11 +325,10 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); _this.runningPluginNames[orderedPluginName] = true; _this.markSlots(candidatePlugin, orderedPluginName); _this.pointerManager.makePointerVisible(candidatePlugin.parameters.handLaser); - //_this.enableLaserForPlugin(candidatePlugin); if (DEBUG) { print("controllerDispatcher running " + orderedPluginName); } -} + } if (PROFILE) { Script.endProfileRange("dispatch.isReady." + orderedPluginName); } @@ -473,14 +472,11 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.cleanup = function () { Script.update.disconnect(_this.update); Controller.disableMapping(MAPPING_NAME); - Pointers.removePointer(_this.leftControllerPointer); - Pointers.removePointer(_this.rightControllerPointer); - Pointers.removePointer(_this.rightControllerHudRayPick); - Pointers.removePointer(_this.leftControllerHudRayPick); + this.pointerManager.removePointers(); }; } function mouseReleaseOnOverlay(overlayID, event) { - if (overlayID === HMD.homeButtonID) { + if (overlayID === HMD.homeButtonID && event.button === "Primary") { Messages.sendLocalMessage("home", overlayID); } } diff --git a/scripts/system/controllers/controllerModules/hudOverlayPointer.js b/scripts/system/controllers/controllerModules/hudOverlayPointer.js index b80bfbb00f..7d86087cde 100644 --- a/scripts/system/controllers/controllerModules/hudOverlayPointer.js +++ b/scripts/system/controllers/controllerModules/hudOverlayPointer.js @@ -25,7 +25,6 @@ var MARGIN = 25; var HUD_LASER_OFFSET = 2; function HudOverlayPointer(hand) { - var _this = this; this.hand = hand; this.reticleMinX = MARGIN; this.reticleMaxX; diff --git a/scripts/system/controllers/controllerModules/inEditMode.js b/scripts/system/controllers/controllerModules/inEditMode.js index 97c4147785..ff7f10be28 100644 --- a/scripts/system/controllers/controllerModules/inEditMode.js +++ b/scripts/system/controllers/controllerModules/inEditMode.js @@ -77,7 +77,7 @@ Script.include("/~/system/libraries/utils.js"); this.isReady = function(controllerData) { if (isInEditMode()) { - if (controllerData.triggerValues[this.hand] < TRIGGER_ON_VALUE) { + if (controllerData.triggerValues[this.hand] < TRIGGER_ON_VALUE) { this.triggerClicked = false; } return makeRunningValues(true, [], []); diff --git a/scripts/system/controllers/controllerModules/tabletStylusInput.js b/scripts/system/controllers/controllerModules/tabletStylusInput.js index fb51df998b..d2fcb94804 100644 --- a/scripts/system/controllers/controllerModules/tabletStylusInput.js +++ b/scripts/system/controllers/controllerModules/tabletStylusInput.js @@ -9,14 +9,13 @@ enableDispatcherModule, disableDispatcherModule, makeRunningValues, Messages, Quat, Vec3, getControllerWorldLocation, makeDispatcherModuleParameters, Overlays, ZERO_VEC, HMD, INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, Settings, getGrabPointSphereOffset, - getEnabledModuleByName + getEnabledModuleByName, Pointers, Picks, PickType */ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Script.include("/~/system/libraries/controllers.js"); (function() { - var TouchEventUtils = Script.require("/~/system/libraries/touchEventUtils.js"); function isNearStylusTarget(stylusTargets, maxNormalDistance) { var stylusTargetIDs = []; for (var index = 0; index < stylusTargets.length; index++) { @@ -36,7 +35,14 @@ Script.include("/~/system/libraries/controllers.js"); }; } - function TabletStylusInput(hand) { + function getEntityDistance(controllerPosition, entityProps) { + return { + id: entityProps.id, + distance: Vec3.distance(entityProps.position, controllerPosition) + }; + } + + function TabletStylusInput(hand) { this.hand = hand; this.parameters = makeDispatcherModuleParameters( @@ -82,21 +88,9 @@ Script.include("/~/system/libraries/controllers.js"); // build list of stylus targets, near the stylusTip var stylusTargets = []; - var candidateEntities = controllerData.nearbyEntityProperties; var candidateOverlays = controllerData.nearbyOverlayIDs; var controllerPosition = controllerData.controllerLocations[this.hand].position; - var i, props, stylusTarget; - - /*for (i = 0; i < candidateEntities.length; i++) { - props = candidateEntities[i]; - if (props && props.type === "Web") { - stylusTarget = TouchEventUtils.calculateTouchTargetFromEntity({position: controllerPosition}, candidateEntities[i]); - if (stylusTarget) { - stylusTargets.push(stylusTarget); - } - } - }*/ - + var i, stylusTarget; for (i = 0; i < candidateOverlays.length; i++) { if (candidateOverlays[i] !== HMD.tabletID && @@ -108,8 +102,6 @@ Script.include("/~/system/libraries/controllers.js"); } } - - // add the tabletScreen, if it is valid if (HMD.tabletScreenID && HMD.tabletScreenID !== Uuid.NULL && Overlays.getProperty(HMD.tabletScreenID, "visible")) { @@ -132,7 +124,6 @@ Script.include("/~/system/libraries/controllers.js"); var nearStylusTarget = isNearStylusTarget(stylusTargets, WEB_DISPLAY_STYLUS_DISTANCE * sensorScaleFactor); if (nearStylusTarget.length !== 0) { - print(this.hand + "---" + this.disable); if (!this.disable) { Pointers.setRenderState(this.pointer,"events on"); Pointers.setIncludeItems(this.pointer, nearStylusTarget); @@ -145,8 +136,6 @@ Script.include("/~/system/libraries/controllers.js"); Pointers.setIncludeItems(this.pointer, []); return false; } - - // var nearestStylusTarget = calculateNearestStylusTarget(stylusTargets); }; this.isReady = function (controllerData) { @@ -160,9 +149,9 @@ Script.include("/~/system/libraries/controllers.js"); this.run = function (controllerData, deltaTime) { return this.isReady(controllerData); }; - + this.cleanup = function () { - //Pointers.createPointer(this.pointer); + Pointers.removePointer(this.pointer); }; } diff --git a/scripts/system/controllers/controllerModules/overlayLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js similarity index 90% rename from scripts/system/controllers/controllerModules/overlayLaserInput.js rename to scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 10235a63e9..c5e2e885a7 100644 --- a/scripts/system/controllers/controllerModules/overlayLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -1,6 +1,6 @@ "use strict"; -// overlayLaserInput.js +// webSurfaceLaserInput.js // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -18,6 +18,7 @@ Script.include("/~/system/libraries/controllers.js"); (function() { function OverlayLaserInput(hand) { this.hand = hand; + this.running = false; this.parameters = makeDispatcherModuleParameters( 120, @@ -44,6 +45,10 @@ Script.include("/~/system/libraries/controllers.js"); return false; }; + this.getOtherModule = function() { + return this.hand === RIGHT_HAND ? leftOverlayLaserInput : rightOverlayLaserInput; + }; + this.isPointingAtWebEntity = function(controllerData) { var intersection = controllerData.rayPicks[this.hand]; var entityProperty = Entities.getEntityProperties(intersection.objectID); @@ -72,7 +77,9 @@ Script.include("/~/system/libraries/controllers.js"); }; this.isReady = function (controllerData) { - if (this.isPointingAtOverlay(controllerData) || this.isPointingAtWebEntity(controllerData)) { + var otherModuleRunning = this.getOtherModule().running; + if ((this.isPointingAtOverlay(controllerData) || this.isPointingAtWebEntity(controllerData)) && + !otherModuleRunning) { if (controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE) { return makeRunningValues(true, [], []); } @@ -83,9 +90,11 @@ Script.include("/~/system/libraries/controllers.js"); this.run = function (controllerData, deltaTime) { var grabModuleNeedsToRun = this.grabModuleWantsNearbyOverlay(controllerData); if (controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE && !grabModuleNeedsToRun) { + this.running = true; return makeRunningValues(true, [], []); } this.deleteContextOverlay(); + this.running = false; return makeRunningValues(false, [], []); }; } diff --git a/scripts/system/controllers/controllerScripts.js b/scripts/system/controllers/controllerScripts.js index a15536977d..2e74797383 100644 --- a/scripts/system/controllers/controllerScripts.js +++ b/scripts/system/controllers/controllerScripts.js @@ -22,7 +22,7 @@ var CONTOLLER_SCRIPTS = [ "controllerModules/tabletStylusInput.js", "controllerModules/equipEntity.js", "controllerModules/nearTrigger.js", - "controllerModules/overlayLaserInput.js", + "controllerModules/webSurfaceLaserInput.js", "controllerModules/inEditMode.js", "controllerModules/inVREditMode.js", "controllerModules/disableOtherModule.js", diff --git a/scripts/system/libraries/controllerDispatcherUtils.js b/scripts/system/libraries/controllerDispatcherUtils.js index 6b5869cd4b..e0024fb7e7 100644 --- a/scripts/system/libraries/controllerDispatcherUtils.js +++ b/scripts/system/libraries/controllerDispatcherUtils.js @@ -101,7 +101,8 @@ DISPATCHER_PROPERTIES = [ "parentJointIndex", "density", "dimensions", - "userData" + "userData", + "type" ]; // priority -- a lower priority means the module will be asked sooner than one with a higher priority in a given update step diff --git a/scripts/system/libraries/pointersUtils.js b/scripts/system/libraries/pointersUtils.js index db2e16368c..63bef21637 100644 --- a/scripts/system/libraries/pointersUtils.js +++ b/scripts/system/libraries/pointersUtils.js @@ -109,9 +109,15 @@ Pointer = function(hudLayer, pickType, pointerData) { } this.enable = function() { + Pointers.enablePointer(this.pointerID); }; this.disable = function() { + Pointers.disablePointer(this.pointerID); + }; + + this.removePointer = function() { + Pointers.removePointer(this.pointerID); }; this.makeVisible = function() { @@ -153,7 +159,6 @@ Pointer = function(hudLayer, pickType, pointerData) { pointerData.renderStates = this.renderStates; pointerData.defaultRenderStates = this.defaultRenderStates; this.pointerID = createPointer(pickType, pointerData); - print(this.pointerID); }; @@ -189,4 +194,11 @@ PointerManager = function() { this.pointers[index].updateRenderState(triggerClicks, triggerValues); } }; + + this.removePointers = function() { + for (var index = 0; index < this.pointers.length; index++) { + this.pointers[index].removePointer(); + } + this.pointers = []; + }; };