Showing the changes to scripts/system/controllers/controllerModules (3 of 6 files). Show all
Unified · Split
| @@ -9,7 +9,7 @@ · 8 unmodified lines | |||
| 9 | getControllerJointIndex, getGrabbableData, NULL_UUID, enableDispatcherModule, disableDispatcherModule, | 9 | getControllerJointIndex, getGrabbableData, NULL_UUID, enableDispatcherModule, disableDispatcherModule, |
| 10 | propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, entityIsGrabbable, | 10 | propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, entityIsGrabbable, |
| 11 | Quat, Vec3, MSECS_PER_SEC, getControllerWorldLocation, makeDispatcherModuleParameters, makeRunningValues, | 11 | Quat, Vec3, MSECS_PER_SEC, getControllerWorldLocation, makeDispatcherModuleParameters, makeRunningValues, |
| 12 | TRIGGER_OFF_VALUE, NEAR_GRAB_RADIUS | 12 | TRIGGER_OFF_VALUE, NEAR_GRAB_RADIUS, findGroupParent |
| 13 | */ | 13 | */ |
| 14 | 14 | ||
| 15 | Script.include("/~/system/controllers/controllerDispatcherUtils.js"); | 15 | Script.include("/~/system/controllers/controllerDispatcherUtils.js"); |
| @@ -152,6 +152,11 @@ Script.include("/~/system/libraries/controllers.js"); · 136 unmodified lines | |||
| 152 | break; | 152 | break; |
| 153 | } | 153 | } |
| 154 | if (entityIsGrabbable(props)) { | 154 | if (entityIsGrabbable(props)) { |
| 155 | // if we've attempted to grab a child, roll up to the root of the tree | ||
| 156 | var groupRootProps = findGroupParent(controllerData, props); | ||
| 157 | if (entityIsGrabbable(groupRootProps)) { | ||
| 158 | return groupRootProps; | ||
| 159 | } | ||
| 155 | return props; | 160 | return props; |
| 156 | } | 161 | } |
| 157 | } | 162 | } |
| @@ -162,23 +167,18 @@ Script.include("/~/system/libraries/controllers.js"); · 4 unmodified lines | |||
| 162 | this.targetEntityID = null; | 167 | this.targetEntityID = null; |
| 163 | 168 | ||
| 164 | if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE) { | 169 | if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE) { |
| 165 | makeRunningValues(false, [], []); | 170 | return makeRunningValues(false, [], []); |
| 166 | } | 171 | } |
| 167 | 172 | ||
| 168 | var targetProps = this.getTargetProps(controllerData); | 173 | var targetProps = this.getTargetProps(controllerData); |
| 169 | if (targetProps) { | 174 | if (targetProps) { |
| 170 | if (!propsArePhysical(targetProps)) { | 175 | if (!propsArePhysical(targetProps)) { |
| 171 | // XXX make sure no highlights are enabled from this module | ||
| 172 | return makeRunningValues(false, [], []); // let nearParentGrabEntity handle it | 176 | return makeRunningValues(false, [], []); // let nearParentGrabEntity handle it |
| 173 | } else { | 177 | } else { |
| 174 | this.targetEntityID = targetProps.id; | 178 | this.targetEntityID = targetProps.id; |
| 175 | ContextOverlay.entityWithContextOverlay = this.targetEntityID; | ||
| 176 | ContextOverlay.enabled = true; | ||
| 177 | // XXX highlight this.targetEntityID here | ||
| 178 | return makeRunningValues(true, [this.targetEntityID], []); | 179 | return makeRunningValues(true, [this.targetEntityID], []); |
| 179 | } | 180 | } |
| 180 | } else { | 181 | } else { |
| 181 | // XXX make sure no highlights are enabled from this module | ||
| 182 | return makeRunningValues(false, [], []); | 182 | return makeRunningValues(false, [], []); |
| 183 | } | 183 | } |
| 184 | }; | 184 | }; |
| @@ -204,26 +204,8 @@ Script.include("/~/system/libraries/controllers.js"); · 19 unmodified lines | |||
| 204 | 204 | ||
| 205 | var targetProps = this.getTargetProps(controllerData); | 205 | var targetProps = this.getTargetProps(controllerData); |
| 206 | if (targetProps) { | 206 | if (targetProps) { |
| 207 | |||
| 208 | // XXX | ||
| 209 | var rayPickInfo = controllerData.rayPicks[this.hand]; | ||
| 210 | var pointerEvent = { | ||
| 211 | type: "Move", | ||
| 212 | id: this.hand + 1, // 0 is reserved for hardware mouse | ||
| 213 | pos2D: projectOntoEntityXYPlane(rayPickInfo.entityID, rayPickInfo.intersection, targetProps), | ||
| 214 | pos3D: rayPickInfo.intersection, | ||
| 215 | normal: rayPickInfo.normal, | ||
| 216 | direction: rayPickInfo.searchRay.direction, | ||
| 217 | button: "Secondary" | ||
| 218 | }; | ||
| 219 | if (ContextOverlay.createOrDestroyContextOverlay(rayPickInfo.entityID, pointerEvent)) { | ||
| 220 | } | ||
| 221 | // XXX | ||
| 222 | |||
| 223 | |||
| 224 | if (controllerData.triggerClicks[this.hand] == 1) { | 207 | if (controllerData.triggerClicks[this.hand] == 1) { |
| 225 | // stop highlighting, switch to grabbing | 208 | // switch to grabbing |
| 226 | // XXX stop highlight here | ||
| 227 | this.startNearGrabAction(controllerData, targetProps); | 209 | this.startNearGrabAction(controllerData, targetProps); |
| 228 | } | 210 | } |
| 229 | } | 211 | } |
| @@ -9,7 +9,8 @@ · 8 unmodified lines | |||
| 9 | /* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, | 9 | /* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, |
| 10 | getControllerJointIndex, NULL_UUID, enableDispatcherModule, disableDispatcherModule, | 10 | getControllerJointIndex, NULL_UUID, enableDispatcherModule, disableDispatcherModule, |
| 11 | propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, TRIGGER_OFF_VALUE, | 11 | propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, TRIGGER_OFF_VALUE, |
| 12 | makeDispatcherModuleParameters, entityIsGrabbable, makeRunningValues, NEAR_GRAB_RADIUS | 12 | makeDispatcherModuleParameters, entityIsGrabbable, makeRunningValues, NEAR_GRAB_RADIUS, |
| 13 | findGroupParent, Vec3 | ||
| 13 | */ | 14 | */ |
| 14 | 15 | ||
| 15 | Script.include("/~/system/controllers/controllerDispatcherUtils.js"); | 16 | Script.include("/~/system/controllers/controllerDispatcherUtils.js"); |
| @@ -29,7 +30,7 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js"); · 13 unmodified lines | |||
| 29 | 30 | ||
| 30 | this.parameters = makeDispatcherModuleParameters( | 31 | this.parameters = makeDispatcherModuleParameters( |
| 31 | 500, | 32 | 500, |
| 32 | this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"], | 33 | this.hand === RIGHT_HAND ? ["rightHand", "rightHandTrigger"] : ["leftHand", "leftHandTrigger"], |
| 33 | [], | 34 | [], |
| 34 | 100); | 35 | 100); |
| 35 | 36 | ||
| @@ -64,6 +65,7 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js"); · 28 unmodified lines | |||
| 64 | }; | 65 | }; |
| 65 | 66 | ||
| 66 | this.startNearParentingGrabEntity = function (controllerData, targetProps) { | 67 | this.startNearParentingGrabEntity = function (controllerData, targetProps) { |
| 68 | |||
| 67 | Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); | 69 | Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); |
| 68 | 70 | ||
| 69 | var handJointIndex; | 71 | var handJointIndex; |
| @@ -135,6 +137,11 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js"); · 65 unmodified lines | |||
| 135 | break; | 137 | break; |
| 136 | } | 138 | } |
| 137 | if (entityIsGrabbable(props)) { | 139 | if (entityIsGrabbable(props)) { |
| 140 | // if we've attempted to grab a child, roll up to the root of the tree | ||
| 141 | var groupRootProps = findGroupParent(controllerData, props); | ||
| 142 | if (entityIsGrabbable(groupRootProps)) { | ||
| 143 | return groupRootProps; | ||
| 144 | } | ||
| 138 | return props; | 145 | return props; |
| 139 | } | 146 | } |
| 140 | } | 147 | } |
| @@ -146,21 +153,18 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js"); · 5 unmodified lines | |||
| 146 | this.grabbing = false; | 153 | this.grabbing = false; |
| 147 | 154 | ||
| 148 | if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE) { | 155 | if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE) { |
| 149 | makeRunningValues(false, [], []); | 156 | return makeRunningValues(false, [], []); |
| 150 | } | 157 | } |
| 151 | 158 | ||
| 152 | var targetProps = this.getTargetProps(controllerData); | 159 | var targetProps = this.getTargetProps(controllerData); |
| 153 | if (targetProps) { | 160 | if (targetProps) { |
| 154 | if (propsArePhysical(targetProps)) { | 161 | if (propsArePhysical(targetProps)) { |
| 155 | // XXX make sure no highlights are enabled from this module | ||
| 156 | return makeRunningValues(false, [], []); // let nearActionGrabEntity handle it | 162 | return makeRunningValues(false, [], []); // let nearActionGrabEntity handle it |
| 157 | } else { | 163 | } else { |
| 158 | this.targetEntityID = targetProps.id; | 164 | this.targetEntityID = targetProps.id; |
| 159 | // XXX highlight this.targetEntityID here | ||
| 160 | return makeRunningValues(true, [this.targetEntityID], []); | 165 | return makeRunningValues(true, [this.targetEntityID], []); |
| 161 | } | 166 | } |
| 162 | } else { | 167 | } else { |
| 163 | // XXX make sure no highlights are enabled from this module | ||
| 164 | return makeRunningValues(false, [], []); | 168 | return makeRunningValues(false, [], []); |
| 165 | } | 169 | } |
| 166 | }; | 170 | }; |
| @@ -181,8 +185,7 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js"); · 14 unmodified lines | |||
| 181 | return readiness; | 185 | return readiness; |
| 182 | } | 186 | } |
| 183 | if (controllerData.triggerClicks[this.hand] == 1) { | 187 | if (controllerData.triggerClicks[this.hand] == 1) { |
| 184 | // stop highlighting, switch to grabbing | 188 | // switch to grab |
| 185 | // XXX stop highlight here | ||
| 186 | var targetProps = this.getTargetProps(controllerData); | 189 | var targetProps = this.getTargetProps(controllerData); |
| 187 | if (targetProps) { | 190 | if (targetProps) { |
| 188 | this.grabbing = true; | 191 | this.grabbing = true; |
| @@ -0,0 +1,119 @@ | |||
| 1 | "use strict"; | ||
| 2 | |||
| 3 | // nearParentGrabEntity.js | ||
| 4 | // | ||
| 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 | ||
| 7 | |||
| 8 | |||
| 9 | /* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, | ||
| 10 | enableDispatcherModule, disableDispatcherModule, getGrabbableData, Vec3, | ||
| 11 | TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, makeRunningValues, NEAR_GRAB_RADIUS | ||
| 12 | */ | ||
| 13 | |||
| 14 | Script.include("/~/system/controllers/controllerDispatcherUtils.js"); | ||
| 15 | |||
| 16 | (function() { | ||
| 17 | |||
| 18 | function entityWantsNearTrigger(props) { | ||
| 19 | return getGrabbableData(props).triggerable; | ||
| 20 | } | ||
| 21 | |||
| 22 | function NearTriggerEntity(hand) { | ||
| 23 | this.hand = hand; | ||
| 24 | this.targetEntityID = null; | ||
| 25 | this.grabbing = false; | ||
| 26 | this.previousParentID = {}; | ||
| 27 | this.previousParentJointIndex = {}; | ||
| 28 | this.previouslyUnhooked = {}; | ||
| 29 | |||
| 30 | this.parameters = makeDispatcherModuleParameters( | ||
| 31 | 200, | ||
| 32 | this.hand === RIGHT_HAND ? ["rightHandTrigger"] : ["leftHandTrigger"], | ||
| 33 | [], | ||
| 34 | 100); | ||
| 35 | |||
| 36 | this.getTargetProps = function (controllerData) { | ||
| 37 | // nearbyEntityProperties is already sorted by length from controller | ||
| 38 | var nearbyEntityProperties = controllerData.nearbyEntityProperties[this.hand]; | ||
| 39 | for (var i = 0; i < nearbyEntityProperties.length; i++) { | ||
| 40 | var props = nearbyEntityProperties[i]; | ||
| 41 | var handPosition = controllerData.controllerLocations[this.hand].position; | ||
| 42 | var distance = Vec3.distance(props.position, handPosition); | ||
| 43 | // if (distance > NEAR_GRAB_RADIUS) { | ||
| 44 | // print("QQQ nop 0"); | ||
| 45 | // break; | ||
| 46 | // } | ||
| 47 | if (entityWantsNearTrigger(props)) { | ||
| 48 | return props; | ||
| 49 | } else { | ||
| 50 | print("QQQ nop 1"); | ||
| 51 | } | ||
| 52 | } | ||
| 53 | return null; | ||
| 54 | }; | ||
| 55 | |||
| 56 | this.startNearTrigger = function (controllerData) { | ||
| 57 | Controller.triggerShortHapticPulse(1.0, this.hand); | ||
| 58 | var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; | ||
| 59 | Entities.callEntityMethod(this.targetEntityID, "startNearTrigger", args); | ||
| 60 | }; | ||
| 61 | |||
| 62 | this.continueNearTrigger = function (controllerData) { | ||
| 63 | var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; | ||
| 64 | Entities.callEntityMethod(this.targetEntityID, "continueNearTrigger", args); | ||
| 65 | }; | ||
| 66 | |||
| 67 | this.endNearTrigger = function (controllerData) { | ||
| 68 | var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; | ||
| 69 | Entities.callEntityMethod(this.targetEntityID, "endNearTrigger", args); | ||
| 70 | }; | ||
| 71 | |||
| 72 | this.isReady = function (controllerData) { | ||
| 73 | this.targetEntityID = null; | ||
| 74 | |||
| 75 | if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE) { | ||
| 76 | return makeRunningValues(false, [], []); | ||
| 77 | } | ||
| 78 | |||
| 79 | var targetProps = this.getTargetProps(controllerData); | ||
| 80 | if (targetProps) { | ||
| 81 | this.targetEntityID = targetProps.id; | ||
| 82 | this.startNearTrigger(controllerData); | ||
| 83 | return makeRunningValues(true, [this.targetEntityID], []); | ||
| 84 | } else { | ||
| 85 | return makeRunningValues(false, [], []); | ||
| 86 | } | ||
| 87 | }; | ||
| 88 | |||
| 89 | this.run = function (controllerData) { | ||
| 90 | if (controllerData.triggerClicks[this.hand] == 0) { | ||
| 91 | this.endNearTrigger(controllerData); | ||
| 92 | return makeRunningValues(false, [], []); | ||
| 93 | } | ||
| 94 | |||
| 95 | this.continueNearTrigger(controllerData); | ||
| 96 | return makeRunningValues(true, [this.targetEntityID], []); | ||
| 97 | }; | ||
| 98 | |||
| 99 | this.cleanup = function () { | ||
| 100 | if (this.targetEntityID) { | ||
| 101 | this.endNearParentingGrabEntity(); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 105 | |||
| 106 | var leftNearParentingGrabEntity = new NearTriggerEntity(LEFT_HAND); | ||
| 107 | var rightNearParentingGrabEntity = new NearTriggerEntity(RIGHT_HAND); | ||
| 108 | |||
| 109 | enableDispatcherModule("LeftNearParentingGrabEntity", leftNearParentingGrabEntity); | ||
| 110 | enableDispatcherModule("RightNearParentingGrabEntity", rightNearParentingGrabEntity); | ||
| 111 | |||
| 112 | this.cleanup = function () { | ||
| 113 | leftNearParentingGrabEntity.cleanup(); | ||
| 114 | rightNearParentingGrabEntity.cleanup(); | ||
| 115 | disableDispatcherModule("LeftNearParentingGrabEntity"); | ||
| 116 | disableDispatcherModule("RightNearParentingGrabEntity"); | ||
| 117 | }; | ||
| 118 | Script.scriptEnding.connect(this.cleanup); | ||
| 119 | }()); | ||