History

trying to get near-triggering working

Seth Alves committed 9 years ago

Commit ddca2561 parent 1d245236 files · +182 −56Browse files

Showing the changes to scripts/system/controllers/controllerModules (3 of 6 files). Show all

Unified · Split

3 files
  1. scripts/system/controllers/controllerModules/nearActionGrabEntity.js +8 −26
  2. scripts/system/controllers/controllerModules/nearParentGrabEntity.js +11 −8
  3. scripts/system/controllers/controllerModules/nearTrigger.js +119 −0
scripts/system/controllers/controllerModules/nearActionGrabEntity.js+8−26
@@ -9,7 +9,7 @@ · 8 unmodified lines
99 getControllerJointIndex, getGrabbableData, NULL_UUID, enableDispatcherModule, disableDispatcherModule,
1010 propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, entityIsGrabbable,
1111 Quat, Vec3, MSECS_PER_SEC, getControllerWorldLocation, makeDispatcherModuleParameters, makeRunningValues,
12− TRIGGER_OFF_VALUE, NEAR_GRAB_RADIUS
12+ TRIGGER_OFF_VALUE, NEAR_GRAB_RADIUS, findGroupParent
1313 */
1414
1515 Script.include("/~/system/controllers/controllerDispatcherUtils.js");
@@ -152,6 +152,11 @@ Script.include("/~/system/libraries/controllers.js"); · 136 unmodified lines
152152 break;
153153 }
154154 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+ }
155160 return props;
156161 }
157162 }
@@ -162,23 +167,18 @@ Script.include("/~/system/libraries/controllers.js"); · 4 unmodified lines
162167 this.targetEntityID = null;
163168
164169 if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE) {
165− makeRunningValues(false, [], []);
170+ return makeRunningValues(false, [], []);
166171 }
167172
168173 var targetProps = this.getTargetProps(controllerData);
169174 if (targetProps) {
170175 if (!propsArePhysical(targetProps)) {
171− // XXX make sure no highlights are enabled from this module
172176 return makeRunningValues(false, [], []); // let nearParentGrabEntity handle it
173177 } else {
174178 this.targetEntityID = targetProps.id;
175− ContextOverlay.entityWithContextOverlay = this.targetEntityID;
176− ContextOverlay.enabled = true;
177− // XXX highlight this.targetEntityID here
178179 return makeRunningValues(true, [this.targetEntityID], []);
179180 }
180181 } else {
181− // XXX make sure no highlights are enabled from this module
182182 return makeRunningValues(false, [], []);
183183 }
184184 };
@@ -204,26 +204,8 @@ Script.include("/~/system/libraries/controllers.js"); · 19 unmodified lines
204204
205205 var targetProps = this.getTargetProps(controllerData);
206206 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−
224207 if (controllerData.triggerClicks[this.hand] == 1) {
225− // stop highlighting, switch to grabbing
226− // XXX stop highlight here
208+ // switch to grabbing
227209 this.startNearGrabAction(controllerData, targetProps);
228210 }
229211 }
scripts/system/controllers/controllerModules/nearParentGrabEntity.js+11−8
@@ -9,7 +9,8 @@ · 8 unmodified lines
99 /* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID,
1010 getControllerJointIndex, NULL_UUID, enableDispatcherModule, disableDispatcherModule,
1111 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
1314 */
1415
1516 Script.include("/~/system/controllers/controllerDispatcherUtils.js");
@@ -29,7 +30,7 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js"); · 13 unmodified lines
2930
3031 this.parameters = makeDispatcherModuleParameters(
3132 500,
32− this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
33+ this.hand === RIGHT_HAND ? ["rightHand", "rightHandTrigger"] : ["leftHand", "leftHandTrigger"],
3334 [],
3435 100);
3536
@@ -64,6 +65,7 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js"); · 28 unmodified lines
6465 };
6566
6667 this.startNearParentingGrabEntity = function (controllerData, targetProps) {
68+
6769 Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);
6870
6971 var handJointIndex;
@@ -135,6 +137,11 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js"); · 65 unmodified lines
135137 break;
136138 }
137139 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+ }
138145 return props;
139146 }
140147 }
@@ -146,21 +153,18 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js"); · 5 unmodified lines
146153 this.grabbing = false;
147154
148155 if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE) {
149− makeRunningValues(false, [], []);
156+ return makeRunningValues(false, [], []);
150157 }
151158
152159 var targetProps = this.getTargetProps(controllerData);
153160 if (targetProps) {
154161 if (propsArePhysical(targetProps)) {
155− // XXX make sure no highlights are enabled from this module
156162 return makeRunningValues(false, [], []); // let nearActionGrabEntity handle it
157163 } else {
158164 this.targetEntityID = targetProps.id;
159− // XXX highlight this.targetEntityID here
160165 return makeRunningValues(true, [this.targetEntityID], []);
161166 }
162167 } else {
163− // XXX make sure no highlights are enabled from this module
164168 return makeRunningValues(false, [], []);
165169 }
166170 };
@@ -181,8 +185,7 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js"); · 14 unmodified lines
181185 return readiness;
182186 }
183187 if (controllerData.triggerClicks[this.hand] == 1) {
184− // stop highlighting, switch to grabbing
185− // XXX stop highlight here
188+ // switch to grab
186189 var targetProps = this.getTargetProps(controllerData);
187190 if (targetProps) {
188191 this.grabbing = true;
scripts/system/controllers/controllerModules/nearTrigger.js+119−0
@@ -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+}());