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