Showing the changes to scripts/system/controllers/controllerModules (1 of 2 files). Show all
Unified · Split
| @@ -5,11 +5,12 @@ · 4 unmodified lines | ||
| 5 | 5 | // Distributed under the Apache License, Version 2.0. |
| 6 | 6 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html |
| 7 | 7 | |
| 8 | −/* global Script, Entities, Controller, RIGHT_HAND, LEFT_HAND, enableDispatcherModule, disableDispatcherModule, | |
| 9 | − makeRunningValues, Messages, Quat, Vec3, makeDispatcherModuleParameters, Overlays, ZERO_VEC, HMD, | |
| 10 | − INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, getGrabPointSphereOffset, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, | |
| 11 | − COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE, | |
| 12 | − TRIGGER_OFF_VALUE, getEnabledModuleByName, PICK_MAX_DISTANCE, ContextOverlay, Picks, makeLaserParams | |
| 8 | +/* global Script, Entities, Controller, RIGHT_HAND, LEFT_HAND, getControllerWorldLocation, | |
| 9 | + enableDispatcherModule, disableDispatcherModule, makeRunningValues, Messages, Quat, Vec3, | |
| 10 | + makeDispatcherModuleParameters, Overlays, ZERO_VEC, HMD, INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, | |
| 11 | + getGrabPointSphereOffset, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, | |
| 12 | + COLORS_GRAB_DISTANCE_HOLD, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE, TRIGGER_OFF_VALUE, | |
| 13 | + getEnabledModuleByName, PICK_MAX_DISTANCE, ContextOverlay, Picks, makeLaserParams | |
| 13 | 14 | */ |
| 14 | 15 | |
| 15 | 16 | Script.include("/~/system/libraries/controllerDispatcherUtils.js"); |
| @@ -19,6 +20,8 @@ Script.include("/~/system/libraries/controllers.js"); · 3 unmodified lines | ||
| 19 | 20 | function WebSurfaceLaserInput(hand) { |
| 20 | 21 | this.hand = hand; |
| 21 | 22 | this.otherHand = this.hand === RIGHT_HAND ? LEFT_HAND : RIGHT_HAND; |
| 23 | + this.ignoredEntities = []; | |
| 24 | + this.lastObjectID = null; | |
| 22 | 25 | this.running = false; |
| 23 | 26 | |
| 24 | 27 | this.parameters = makeDispatcherModuleParameters( |
| @@ -60,16 +63,20 @@ Script.include("/~/system/libraries/controllers.js"); · 35 unmodified lines | ||
| 60 | 63 | return this.hand === RIGHT_HAND ? leftOverlayLaserInput : rightOverlayLaserInput; |
| 61 | 64 | }; |
| 62 | 65 | |
| 63 | − this.isPointingAtGrabbableEntity = function(controllerData, triggerPressed) { | |
| 66 | + this.isPointingAtNearGrabbableEntity = function(controllerData, triggerPressed) { | |
| 64 | 67 | // we are searching for an entity that is not a web entity. We want to be able to |
| 65 | 68 | // grab a non-web entity if the ray-pick intersects one. |
| 66 | 69 | var intersection = controllerData.rayPicks[this.hand]; |
| 67 | 70 | if (intersection.type === Picks.INTERSECTED_ENTITY) { |
| 68 | 71 | // is pointing at an entity. |
| 69 | − var entityProperty = Entities.getEntityProperties(intersection.objectID); | |
| 70 | − var entityType = entityProperty.type; | |
| 71 | − var isGrabbable = entityIsGrabbable(entityProperty); | |
| 72 | − return (isGrabbable && triggerPressed && entityType !== "Web"); | |
| 72 | + var entityProperties = Entities.getEntityProperties(intersection.objectID); | |
| 73 | + var entityType = entityProperties.type; | |
| 74 | + if (entityIsGrabbable(entityProperties)) { | |
| 75 | + // check if entity is near grabbable. | |
| 76 | + var distance = Vec3.distance(entityProperties.position, controllerData.controllerLocations[this.hand].position); | |
| 77 | + if (distance <= NEAR_GRAB_RADIUS * MyAvatar.sensorToWorldScale) | |
| 78 | + return (triggerPressed && entityType !== "Web"); | |
| 79 | + } | |
| 73 | 80 | } |
| 74 | 81 | return false; |
| 75 | 82 | }; |
| @@ -78,21 +85,30 @@ Script.include("/~/system/libraries/controllers.js"); · 2 unmodified lines | ||
| 78 | 85 | // allow pointing at tablet, unlocked web entities, or web overlays automatically without pressing trigger, |
| 79 | 86 | // but for pointing at locked web entities or non-web overlays user must be pressing trigger |
| 80 | 87 | var intersection = controllerData.rayPicks[this.hand]; |
| 88 | + var objectID = intersection.objectID; | |
| 81 | 89 | if (intersection.type === Picks.INTERSECTED_OVERLAY) { |
| 82 | − var objectID = intersection.objectID; | |
| 83 | 90 | if ((HMD.tabletID && objectID === HMD.tabletID) || |
| 84 | 91 | (HMD.tabletScreenID && objectID === HMD.tabletScreenID) || |
| 85 | 92 | (HMD.homeButtonID && objectID === HMD.homeButtonID)) { |
| 93 | + this.lastObjectID = objectID; | |
| 86 | 94 | return true; |
| 87 | 95 | } else { |
| 88 | 96 | var overlayType = Overlays.getOverlayType(objectID); |
| 97 | + this.lastObjectID = objectID; | |
| 89 | 98 | return overlayType === "web3d" || triggerPressed; |
| 90 | 99 | } |
| 91 | 100 | } else if (intersection.type === Picks.INTERSECTED_ENTITY) { |
| 92 | − var entityProperty = Entities.getEntityProperties(intersection.objectID); | |
| 93 | − var entityType = entityProperty.type; | |
| 94 | − var isLocked = entityProperty.locked; | |
| 95 | − return entityType === "Web" && (!isLocked || triggerPressed); | |
| 101 | + var entityProperty = Entities.getEntityProperties(objectID); | |
| 102 | + if (entityProperty.type === "Web") { | |
| 103 | + var isLocked = entityProperty.locked; | |
| 104 | + this.lastObjectID = objectID; | |
| 105 | + return (!isLocked || triggerPressed); | |
| 106 | + } else if (this.ignoredEntities.indexOf(objectID) === -1 && triggerPressed && this.lastObjectID !== objectID) { | |
| 107 | + // ignore, preserve whether it's running or not. | |
| 108 | + console.log("I'm here"); | |
| 109 | + Pointers.setIgnoreItems(controllerData.pointers[this.hand], [objectID]); | |
| 110 | + this.ignoredEntities.push(objectID); | |
| 111 | + } | |
| 96 | 112 | } |
| 97 | 113 | return false; |
| 98 | 114 | }; |
| @@ -110,6 +126,11 @@ Script.include("/~/system/libraries/controllers.js"); · 11 unmodified lines | ||
| 110 | 126 | } |
| 111 | 127 | }; |
| 112 | 128 | |
| 129 | + this.reAddIgnoredEntities = function(controllerData) { | |
| 130 | + Pointers.setIncludeItems(controllerData.pointers[this.hand], this.ignoredEntities); | |
| 131 | + this.ignoredEntities = []; | |
| 132 | + } | |
| 133 | + | |
| 113 | 134 | this.updateAllwaysOn = function() { |
| 114 | 135 | var PREFER_STYLUS_OVER_LASER = "preferStylusOverLaser"; |
| 115 | 136 | this.parameters.handLaser.allwaysOn = !Settings.getValue(PREFER_STYLUS_OVER_LASER, false); |
| @@ -128,7 +149,7 @@ Script.include("/~/system/libraries/controllers.js"); · 12 unmodified lines | ||
| 128 | 149 | controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; |
| 129 | 150 | var allowThisModule = !otherModuleRunning || isTriggerPressed; |
| 130 | 151 | if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && |
| 131 | − !this.isPointingAtGrabbableEntity(controllerData, isTriggerPressed)) { | |
| 152 | + !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { | |
| 132 | 153 | this.updateAllwaysOn(); |
| 133 | 154 | if (isTriggerPressed) { |
| 134 | 155 | this.dominantHandOverride = true; // Override dominant hand. |
| @@ -150,11 +171,12 @@ Script.include("/~/system/libraries/controllers.js"); · 15 unmodified lines | ||
| 150 | 171 | var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; |
| 151 | 172 | var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; |
| 152 | 173 | if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && |
| 153 | − !this.isPointingAtGrabbableEntity(controllerData, isTriggerPressed)) { | |
| 174 | + !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { | |
| 154 | 175 | this.running = true; |
| 155 | 176 | return makeRunningValues(true, [], []); |
| 156 | 177 | } |
| 157 | 178 | this.deleteContextOverlay(); |
| 179 | + this.reAddIgnoredEntities(controllerData); | |
| 158 | 180 | this.running = false; |
| 159 | 181 | this.dominantHandOverride = false; |
| 160 | 182 | return makeRunningValues(false, [], []); |