@iwsdk/xr-input 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -0
- package/dist/gamepad/generated-profiles.d.ts.map +1 -1
- package/dist/gamepad/generated-profiles.js +9998 -12843
- package/dist/gamepad/generated-profiles.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/super-three@0.181.0/node_modules/super-three/src/math/MathUtils.js.map +1 -0
- package/dist/pointer/cursor-visual.d.ts +34 -0
- package/dist/pointer/cursor-visual.d.ts.map +1 -0
- package/dist/pointer/cursor-visual.js +110 -0
- package/dist/pointer/cursor-visual.js.map +1 -0
- package/dist/pointer/multi-pointer.d.ts +137 -12
- package/dist/pointer/multi-pointer.d.ts.map +1 -1
- package/dist/pointer/multi-pointer.js +481 -107
- package/dist/pointer/multi-pointer.js.map +1 -1
- package/dist/pointer/ray-pointer.d.ts +5 -5
- package/dist/pointer/ray-pointer.d.ts.map +1 -1
- package/dist/pointer/ray-pointer.js +11 -84
- package/dist/pointer/ray-pointer.js.map +1 -1
- package/dist/pointer/touch-pointer.d.ts +42 -0
- package/dist/pointer/touch-pointer.d.ts.map +1 -0
- package/dist/pointer/touch-pointer.js +51 -0
- package/dist/pointer/touch-pointer.js.map +1 -0
- package/dist/rig/xr-origin.d.ts +10 -0
- package/dist/rig/xr-origin.d.ts.map +1 -1
- package/dist/rig/xr-origin.js +11 -1
- package/dist/rig/xr-origin.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/visual/adapter/hand-visual-adapter.d.ts +5 -0
- package/dist/visual/adapter/hand-visual-adapter.d.ts.map +1 -1
- package/dist/visual/adapter/hand-visual-adapter.js +7 -0
- package/dist/visual/adapter/hand-visual-adapter.js.map +1 -1
- package/dist/visual/impl/animated-controller-hand.js +1 -1
- package/dist/visual/utils/flex-batched-mesh.d.ts.map +1 -1
- package/dist/visual/utils/flex-batched-mesh.js +10 -5
- package/dist/visual/utils/flex-batched-mesh.js.map +1 -1
- package/dist/visual/utils/simple-batched-mesh.d.ts +47 -0
- package/dist/visual/utils/simple-batched-mesh.d.ts.map +1 -0
- package/dist/visual/utils/simple-batched-mesh.js +389 -0
- package/dist/visual/utils/simple-batched-mesh.js.map +1 -0
- package/dist/xr-input-manager.d.ts +5 -0
- package/dist/xr-input-manager.d.ts.map +1 -1
- package/dist/xr-input-manager.js +24 -0
- package/dist/xr-input-manager.js.map +1 -1
- package/package.json +1 -1
- package/dist/node_modules/.pnpm/super-three@0.177.0/node_modules/super-three/src/math/MathUtils.js.map +0 -1
- /package/dist/node_modules/.pnpm/{super-three@0.177.0 → super-three@0.181.0}/node_modules/super-three/src/math/MathUtils.js +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CursorVisual } from './cursor-visual.js';
|
|
2
2
|
import { GrabPointer } from './grab-pointer.js';
|
|
3
3
|
import { RayPointer } from './ray-pointer.js';
|
|
4
|
+
import { TouchPointer } from './touch-pointer.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -8,63 +9,457 @@ import { RayPointer } from './ray-pointer.js';
|
|
|
8
9
|
* This source code is licensed under the MIT license found in the
|
|
9
10
|
* LICENSE file in the root directory of this source tree.
|
|
10
11
|
*/
|
|
12
|
+
/**
|
|
13
|
+
* Interactor state machine states
|
|
14
|
+
*/
|
|
15
|
+
var InteractorState;
|
|
16
|
+
(function (InteractorState) {
|
|
17
|
+
/** Pointer not registered or not enabled */
|
|
18
|
+
InteractorState["DISABLED"] = "disabled";
|
|
19
|
+
/** Pointer enabled, no candidate */
|
|
20
|
+
InteractorState["NORMAL"] = "normal";
|
|
21
|
+
/** Pointer has candidate, hovering over object */
|
|
22
|
+
InteractorState["HOVER"] = "hover";
|
|
23
|
+
/** Pointer actively selecting object */
|
|
24
|
+
InteractorState["SELECT"] = "select";
|
|
25
|
+
})(InteractorState || (InteractorState = {}));
|
|
26
|
+
/**
|
|
27
|
+
* Priority order for pointer types (lower index = higher priority)
|
|
28
|
+
*/
|
|
29
|
+
const PRIORITY_ORDER = ['touch', 'grab', 'ray'];
|
|
30
|
+
/**
|
|
31
|
+
* Hysteresis thresholds for touch pointer (in meters)
|
|
32
|
+
*/
|
|
33
|
+
const TOUCH_HYSTERESIS = {
|
|
34
|
+
enterHoverDistance: 0.15, // 15cm - distance to start hover
|
|
35
|
+
exitHoverDistance: 0.2, // 20cm - distance to end hover
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* MultiPointer orchestrates multiple pointer types using priority-based selection.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* - Priority order: Touch > Grab > Ray
|
|
42
|
+
* - Uses state machine: DISABLED ↔ NORMAL ↔ HOVER ↔ SELECT
|
|
43
|
+
* - Selection lock: Once a pointer starts selecting, it stays locked until release
|
|
44
|
+
* - Hysteresis: Touch pointer uses separate enter/exit thresholds to prevent flickering
|
|
45
|
+
*
|
|
46
|
+
* @category Pointer
|
|
47
|
+
*/
|
|
11
48
|
class MultiPointer {
|
|
12
49
|
constructor(handedness, scene, camera, xrOrigin) {
|
|
13
50
|
this.handedness = handedness;
|
|
14
51
|
this.scene = scene;
|
|
15
52
|
this.camera = camera;
|
|
16
53
|
this.xrOrigin = xrOrigin;
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.
|
|
54
|
+
/** Current active pointer kind (winner of priority selection) */
|
|
55
|
+
this.activeKind = null;
|
|
56
|
+
/** State for each pointer type */
|
|
57
|
+
this.pointerStates = new Map();
|
|
58
|
+
/** Hysteresis tracking: whether touch is currently in hover state */
|
|
59
|
+
this.touchHoverActive = false;
|
|
60
|
+
/** Reusable native event object to avoid per-frame allocations */
|
|
61
|
+
this.nativeEvent = { timeStamp: 0 };
|
|
62
|
+
/** Reusable policy object for ray rendering */
|
|
63
|
+
this.rayPolicy = { forceHideRay: false };
|
|
64
|
+
/** Reusable event object for pointer down/up with button */
|
|
65
|
+
this.buttonEvent = { timeStamp: 0, button: 0 };
|
|
66
|
+
// Create all pointer instances
|
|
67
|
+
const rayVisual = new RayPointer(this.camera, this.xrOrigin, this.handedness);
|
|
68
|
+
const grabVisual = new GrabPointer(this.camera, this.xrOrigin, this.handedness);
|
|
69
|
+
const touchVisual = new TouchPointer(this.camera, this.xrOrigin, this.handedness);
|
|
70
|
+
this.ray = {
|
|
71
|
+
pointer: rayVisual.pointer,
|
|
72
|
+
visual: rayVisual,
|
|
73
|
+
registered: false,
|
|
74
|
+
};
|
|
75
|
+
this.grab = {
|
|
76
|
+
pointer: grabVisual.pointer,
|
|
77
|
+
visual: grabVisual,
|
|
78
|
+
registered: false,
|
|
79
|
+
};
|
|
80
|
+
this.touch = {
|
|
81
|
+
pointer: touchVisual.pointer,
|
|
82
|
+
visual: touchVisual,
|
|
83
|
+
registered: false,
|
|
84
|
+
};
|
|
85
|
+
// Cache scene reference for descendant swapping (avoids repeated casts)
|
|
86
|
+
this.sceneWithDescendants = this.scene;
|
|
87
|
+
// Create shared cursor visual
|
|
88
|
+
this.cursorVisual = new CursorVisual(xrOrigin, handedness === 'left' ? 0 : 1);
|
|
89
|
+
// Initialize states
|
|
90
|
+
PRIORITY_ORDER.forEach((kind) => {
|
|
91
|
+
this.pointerStates.set(kind, InteractorState.DISABLED);
|
|
92
|
+
});
|
|
93
|
+
// Enable ray and touch by default
|
|
25
94
|
this.toggleSubPointer('ray', true);
|
|
95
|
+
this.toggleSubPointer('touch', true);
|
|
26
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Main update loop - implements priority-based pointer selection
|
|
99
|
+
*/
|
|
27
100
|
update(connected, delta, time, input) {
|
|
28
|
-
var _a, _b;
|
|
29
|
-
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
101
|
+
var _a, _b, _c, _d, _e, _f;
|
|
102
|
+
// Reuse nativeEvent object to avoid allocation
|
|
103
|
+
this.nativeEvent.timeStamp = time * 1000;
|
|
104
|
+
// Phase 1: Update enabled state for all registered pointers
|
|
105
|
+
this.updatePointerEnabled(connected);
|
|
106
|
+
// Phase 2: Check selection lock - if active pointer is selecting, stay locked
|
|
107
|
+
const activePointer = this.getActivePointer();
|
|
108
|
+
const activeState = activePointer
|
|
109
|
+
? this.pointerStates.get(this.activeKind)
|
|
110
|
+
: null;
|
|
111
|
+
const isSelecting = activeState === InteractorState.SELECT;
|
|
112
|
+
if (!isSelecting) {
|
|
113
|
+
// Phase 3: Compute intersections for all enabled pointers
|
|
114
|
+
this.computeAllIntersections();
|
|
115
|
+
// Phase 4: Pick winner by priority
|
|
116
|
+
this.pickActiveByPriority();
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
// Selection locked - only update the active pointer's intersection
|
|
120
|
+
// Still use type-specific descendants for the locked pointer
|
|
121
|
+
if (activePointer && this.activeKind) {
|
|
122
|
+
this.movePointerWithDescendants(this.activeKind, activePointer);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Phase 5: Process lifecycle (state transitions)
|
|
126
|
+
this.processLifecycle(input);
|
|
127
|
+
// Phase 6: Update shared cursor from active pointer
|
|
128
|
+
const anyPointerHasCapture = !!((_b = (_a = this.ray.pointer).getPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a)) ||
|
|
129
|
+
!!((_d = (_c = this.grab.pointer).getPointerCapture) === null || _d === void 0 ? void 0 : _d.call(_c)) ||
|
|
130
|
+
!!((_f = (_e = this.touch.pointer).getPointerCapture) === null || _f === void 0 ? void 0 : _f.call(_e));
|
|
131
|
+
if (this.activeKind && !anyPointerHasCapture) {
|
|
132
|
+
const activeEntry = this.getEntry(this.activeKind);
|
|
133
|
+
const intersection = activeEntry.pointer.getIntersection();
|
|
134
|
+
const focused = this.pointerStates.get(this.activeKind) === InteractorState.SELECT;
|
|
135
|
+
const visible = !!intersection && !intersection.object.isVoidObject;
|
|
136
|
+
this.cursorVisual.setVisible(visible);
|
|
137
|
+
if (visible && intersection) {
|
|
138
|
+
this.cursorVisual.updateFromIntersection(intersection, delta, focused);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this.cursorVisual.setVisible(false);
|
|
143
|
+
}
|
|
144
|
+
// Phase 7: Update visuals - reuse rayPolicy object
|
|
145
|
+
this.rayPolicy.forceHideRay =
|
|
146
|
+
this.activeKind !== 'ray' && this.activeKind !== null;
|
|
147
|
+
this.ray.visual.update(connected && this.ray.registered, delta, time, !!(input === null || input === void 0 ? void 0 : input.selectStart), !!(input === null || input === void 0 ? void 0 : input.selectEnd), this.rayPolicy);
|
|
148
|
+
this.grab.visual.update(connected && this.grab.registered, delta, time, !!(input === null || input === void 0 ? void 0 : input.squeezeStart), !!(input === null || input === void 0 ? void 0 : input.squeezeEnd));
|
|
149
|
+
this.touch.visual.update(connected && this.touch.registered, delta, time, false, false);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Update enabled state for all registered pointers
|
|
153
|
+
*/
|
|
154
|
+
updatePointerEnabled(connected) {
|
|
155
|
+
// Process ray pointer
|
|
156
|
+
this.updateSinglePointerEnabled('ray', this.ray, connected);
|
|
157
|
+
// Process grab pointer
|
|
158
|
+
this.updateSinglePointerEnabled('grab', this.grab, connected);
|
|
159
|
+
// Process touch pointer
|
|
160
|
+
this.updateSinglePointerEnabled('touch', this.touch, connected);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Update enabled state for a single pointer (avoids array allocation)
|
|
164
|
+
*/
|
|
165
|
+
updateSinglePointerEnabled(kind, entry, connected) {
|
|
166
|
+
const shouldBeEnabled = connected && entry.registered;
|
|
167
|
+
const currentState = this.pointerStates.get(kind);
|
|
168
|
+
const isEnabled = currentState !== InteractorState.DISABLED;
|
|
169
|
+
if (shouldBeEnabled && !isEnabled) {
|
|
170
|
+
entry.pointer.setEnabled(true, this.nativeEvent, false);
|
|
171
|
+
this.pointerStates.set(kind, InteractorState.NORMAL);
|
|
172
|
+
}
|
|
173
|
+
else if (!shouldBeEnabled && isEnabled) {
|
|
174
|
+
entry.pointer.setEnabled(false, this.nativeEvent, true);
|
|
175
|
+
this.pointerStates.set(kind, InteractorState.DISABLED);
|
|
176
|
+
// Clear active if this was the active pointer
|
|
177
|
+
if (this.activeKind === kind) {
|
|
178
|
+
this.activeKind = null;
|
|
39
179
|
}
|
|
40
|
-
|
|
41
|
-
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Compute intersections for all enabled pointers using type-specific descendant arrays.
|
|
184
|
+
* Swaps scene.interactableDescendants per pointer type for optimized traversal.
|
|
185
|
+
*/
|
|
186
|
+
computeAllIntersections() {
|
|
187
|
+
// Store original descendants once
|
|
188
|
+
const originalDescendants = this.sceneWithDescendants.interactableDescendants;
|
|
189
|
+
// Process each pointer with its type-specific descendants
|
|
190
|
+
// Ray pointer
|
|
191
|
+
if (this.pointerStates.get('ray') !== InteractorState.DISABLED) {
|
|
192
|
+
this.sceneWithDescendants.interactableDescendants =
|
|
193
|
+
this.sceneWithDescendants.rayDescendants;
|
|
194
|
+
this.ray.pointer.move(this.scene, this.nativeEvent);
|
|
195
|
+
}
|
|
196
|
+
// Grab pointer
|
|
197
|
+
if (this.pointerStates.get('grab') !== InteractorState.DISABLED) {
|
|
198
|
+
this.sceneWithDescendants.interactableDescendants =
|
|
199
|
+
this.sceneWithDescendants.grabDescendants;
|
|
200
|
+
this.grab.pointer.move(this.scene, this.nativeEvent);
|
|
201
|
+
}
|
|
202
|
+
// Touch pointer
|
|
203
|
+
if (this.pointerStates.get('touch') !== InteractorState.DISABLED) {
|
|
204
|
+
this.sceneWithDescendants.interactableDescendants =
|
|
205
|
+
this.sceneWithDescendants.touchDescendants;
|
|
206
|
+
this.touch.pointer.move(this.scene, this.nativeEvent);
|
|
207
|
+
}
|
|
208
|
+
// Restore original descendants
|
|
209
|
+
this.sceneWithDescendants.interactableDescendants = originalDescendants;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Move a single pointer using its type-specific descendants.
|
|
213
|
+
* Used when selection is locked to avoid unnecessary traversal.
|
|
214
|
+
*/
|
|
215
|
+
movePointerWithDescendants(kind, pointer) {
|
|
216
|
+
const originalDescendants = this.sceneWithDescendants.interactableDescendants;
|
|
217
|
+
switch (kind) {
|
|
218
|
+
case 'ray':
|
|
219
|
+
this.sceneWithDescendants.interactableDescendants =
|
|
220
|
+
this.sceneWithDescendants.rayDescendants;
|
|
221
|
+
break;
|
|
222
|
+
case 'grab':
|
|
223
|
+
this.sceneWithDescendants.interactableDescendants =
|
|
224
|
+
this.sceneWithDescendants.grabDescendants;
|
|
225
|
+
break;
|
|
226
|
+
case 'touch':
|
|
227
|
+
this.sceneWithDescendants.interactableDescendants =
|
|
228
|
+
this.sceneWithDescendants.touchDescendants;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
pointer.move(this.scene, this.nativeEvent);
|
|
232
|
+
this.sceneWithDescendants.interactableDescendants = originalDescendants;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Pick active pointer by priority - first with valid candidate wins
|
|
236
|
+
*/
|
|
237
|
+
pickActiveByPriority() {
|
|
238
|
+
let newActiveKind = null;
|
|
239
|
+
for (const kind of PRIORITY_ORDER) {
|
|
240
|
+
const state = this.pointerStates.get(kind);
|
|
241
|
+
if (state === InteractorState.DISABLED) {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (this.hasValidCandidate(kind)) {
|
|
245
|
+
newActiveKind = kind;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// Switch active pointer if changed
|
|
250
|
+
if (newActiveKind !== this.activeKind) {
|
|
251
|
+
this.switchActivePointer(newActiveKind);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Check if a pointer has a valid candidate (intersection)
|
|
256
|
+
*/
|
|
257
|
+
hasValidCandidate(kind) {
|
|
258
|
+
const entry = this.getEntry(kind);
|
|
259
|
+
const intersection = entry.pointer.getIntersection();
|
|
260
|
+
// No intersection or void object = no candidate
|
|
261
|
+
if (!intersection || intersection.object.isVoidObject) {
|
|
262
|
+
// For touch, update hysteresis state
|
|
263
|
+
if (kind === 'touch') {
|
|
264
|
+
this.touchHoverActive = false;
|
|
42
265
|
}
|
|
266
|
+
return false;
|
|
43
267
|
}
|
|
44
|
-
|
|
45
|
-
|
|
268
|
+
// For touch pointer, apply hysteresis
|
|
269
|
+
if (kind === 'touch') {
|
|
270
|
+
const threshold = this.touchHoverActive
|
|
271
|
+
? TOUCH_HYSTERESIS.exitHoverDistance
|
|
272
|
+
: TOUCH_HYSTERESIS.enterHoverDistance;
|
|
273
|
+
if (intersection.distance > threshold) {
|
|
274
|
+
// Outside threshold
|
|
275
|
+
if (!this.touchHoverActive) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
// Was hovering but now outside exit threshold
|
|
279
|
+
this.touchHoverActive = false;
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
// Within threshold
|
|
283
|
+
this.touchHoverActive = true;
|
|
284
|
+
return true;
|
|
46
285
|
}
|
|
47
|
-
|
|
48
|
-
|
|
286
|
+
// For ray and grab, any valid intersection is a candidate
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Switch active pointer to a new kind
|
|
291
|
+
*/
|
|
292
|
+
switchActivePointer(newKind) {
|
|
293
|
+
// Disable previous active pointer (but keep it enabled in the pointer system)
|
|
294
|
+
if (this.activeKind && this.activeKind !== newKind) {
|
|
295
|
+
const prevState = this.pointerStates.get(this.activeKind);
|
|
296
|
+
if (prevState === InteractorState.HOVER) {
|
|
297
|
+
this.pointerStates.set(this.activeKind, InteractorState.NORMAL);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
this.activeKind = newKind;
|
|
301
|
+
// Update new active pointer state
|
|
302
|
+
if (newKind) {
|
|
303
|
+
const state = this.pointerStates.get(newKind);
|
|
304
|
+
if (state === InteractorState.NORMAL) {
|
|
305
|
+
this.pointerStates.set(newKind, InteractorState.HOVER);
|
|
306
|
+
}
|
|
49
307
|
}
|
|
50
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Process lifecycle transitions based on input
|
|
311
|
+
*/
|
|
312
|
+
processLifecycle(input) {
|
|
313
|
+
if (!this.activeKind) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const entry = this.getEntry(this.activeKind);
|
|
317
|
+
const state = this.pointerStates.get(this.activeKind);
|
|
318
|
+
switch (this.activeKind) {
|
|
319
|
+
case 'touch':
|
|
320
|
+
// Touch auto-selects based on distance
|
|
321
|
+
this.processTouchLifecycle(entry, state);
|
|
322
|
+
break;
|
|
323
|
+
case 'grab':
|
|
324
|
+
// Grab uses squeeze button
|
|
325
|
+
this.processButtonLifecycle(entry, state, !!(input === null || input === void 0 ? void 0 : input.squeezeStart), !!(input === null || input === void 0 ? void 0 : input.squeezeEnd), 2);
|
|
326
|
+
break;
|
|
327
|
+
case 'ray':
|
|
328
|
+
// Ray uses select button
|
|
329
|
+
this.processButtonLifecycle(entry, state, !!(input === null || input === void 0 ? void 0 : input.selectStart), !!(input === null || input === void 0 ? void 0 : input.selectEnd), 0);
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Process touch pointer lifecycle - auto-selects based on distance
|
|
335
|
+
*/
|
|
336
|
+
processTouchLifecycle(entry, state) {
|
|
337
|
+
const intersection = entry.pointer.getIntersection();
|
|
338
|
+
if (!intersection || intersection.object.isVoidObject) {
|
|
339
|
+
// Lost candidate - transition to NORMAL
|
|
340
|
+
if (state === InteractorState.SELECT) {
|
|
341
|
+
// Force release if touch was selecting when intersection was lost
|
|
342
|
+
this.buttonEvent.timeStamp = this.nativeEvent.timeStamp;
|
|
343
|
+
this.buttonEvent.button = 0;
|
|
344
|
+
entry.pointer.up(this.buttonEvent);
|
|
345
|
+
}
|
|
346
|
+
if (state === InteractorState.HOVER || state === InteractorState.SELECT) {
|
|
347
|
+
this.pointerStates.set('touch', InteractorState.NORMAL);
|
|
348
|
+
}
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
// Touch auto-selection is handled by the pointer's onMoveCommited callback
|
|
352
|
+
// (createTouchPointer sets this up). We just need to track the state.
|
|
353
|
+
// Check if pointer is currently selecting (has buttons down)
|
|
354
|
+
const isSelecting = entry.pointer.getButtonsDown().size > 0;
|
|
355
|
+
if (state === InteractorState.HOVER && isSelecting) {
|
|
356
|
+
this.pointerStates.set('touch', InteractorState.SELECT);
|
|
357
|
+
}
|
|
358
|
+
else if (state === InteractorState.SELECT && !isSelecting) {
|
|
359
|
+
this.pointerStates.set('touch', InteractorState.HOVER);
|
|
360
|
+
}
|
|
361
|
+
else if (state === InteractorState.NORMAL) {
|
|
362
|
+
this.pointerStates.set('touch', InteractorState.HOVER);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Process button-based pointer lifecycle (ray/grab)
|
|
367
|
+
*/
|
|
368
|
+
processButtonLifecycle(entry, state, buttonDown, buttonUp, button) {
|
|
369
|
+
const intersection = entry.pointer.getIntersection();
|
|
370
|
+
if (!intersection || intersection.object.isVoidObject) {
|
|
371
|
+
// Lost candidate - can happen during selection (pointer capture handles this)
|
|
372
|
+
if (state === InteractorState.HOVER) {
|
|
373
|
+
this.pointerStates.set(this.activeKind, InteractorState.NORMAL);
|
|
374
|
+
}
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
// HOVER → SELECT on button down
|
|
378
|
+
if (state === InteractorState.HOVER && buttonDown) {
|
|
379
|
+
this.buttonEvent.timeStamp = this.nativeEvent.timeStamp;
|
|
380
|
+
this.buttonEvent.button = button;
|
|
381
|
+
entry.pointer.down(this.buttonEvent);
|
|
382
|
+
this.pointerStates.set(this.activeKind, InteractorState.SELECT);
|
|
383
|
+
}
|
|
384
|
+
// SELECT → HOVER on button up
|
|
385
|
+
else if (state === InteractorState.SELECT && buttonUp) {
|
|
386
|
+
this.buttonEvent.timeStamp = this.nativeEvent.timeStamp;
|
|
387
|
+
this.buttonEvent.button = button;
|
|
388
|
+
entry.pointer.up(this.buttonEvent);
|
|
389
|
+
this.pointerStates.set(this.activeKind, InteractorState.HOVER);
|
|
390
|
+
}
|
|
391
|
+
// NORMAL → HOVER when we have a candidate
|
|
392
|
+
else if (state === InteractorState.NORMAL) {
|
|
393
|
+
this.pointerStates.set(this.activeKind, InteractorState.HOVER);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Get the policy for ray visual rendering
|
|
398
|
+
*/
|
|
51
399
|
getPolicyForRay() {
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
//
|
|
56
|
-
// - if ray captured → show ray, hide cursor
|
|
57
|
-
// - else if other captured → hide both
|
|
58
|
-
// - else → show both as usual
|
|
59
|
-
return {
|
|
60
|
-
forceHideRay: nonRayCaptured && !rayCaptured,
|
|
61
|
-
forceHideCursor: rayCaptured || nonRayCaptured,
|
|
62
|
-
};
|
|
400
|
+
// Hide ray when touch or grab is active
|
|
401
|
+
const hideRay = this.activeKind !== 'ray' && this.activeKind !== null;
|
|
402
|
+
return { forceHideRay: hideRay };
|
|
403
|
+
// Cursor is now managed by MultiPointer, not RayPointer
|
|
63
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Check if ray is busy (has intersection)
|
|
407
|
+
*/
|
|
64
408
|
getRayBusy() {
|
|
65
|
-
|
|
66
|
-
return !!((_a = this.ray) === null || _a === void 0 ? void 0 : _a.visual.busy);
|
|
409
|
+
return !!this.ray.visual.busy;
|
|
67
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Toggle a sub-pointer on/off
|
|
413
|
+
*/
|
|
414
|
+
toggleSubPointer(kind, enabled) {
|
|
415
|
+
const entry = this.getEntry(kind);
|
|
416
|
+
if (entry.registered === enabled) {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
entry.registered = enabled;
|
|
420
|
+
if (!enabled) {
|
|
421
|
+
this.pointerStates.set(kind, InteractorState.DISABLED);
|
|
422
|
+
if (this.activeKind === kind) {
|
|
423
|
+
this.activeKind = null;
|
|
424
|
+
}
|
|
425
|
+
if (kind === 'touch') {
|
|
426
|
+
this.touchHoverActive = false;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Get the registration state of a sub-pointer
|
|
433
|
+
*/
|
|
434
|
+
getSubPointerState(kind) {
|
|
435
|
+
const entry = this.getEntry(kind);
|
|
436
|
+
return { registered: entry.registered };
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Get the currently active pointer kind
|
|
440
|
+
*/
|
|
441
|
+
getActiveKind() {
|
|
442
|
+
return this.activeKind;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Get the currently active pointer
|
|
446
|
+
*/
|
|
447
|
+
getActivePointer() {
|
|
448
|
+
if (!this.activeKind) {
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
return this.getEntry(this.activeKind).pointer;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Get a specific pointer by kind
|
|
455
|
+
*/
|
|
456
|
+
getPointer(kind) {
|
|
457
|
+
return this.getEntry(kind).pointer;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Route a down event to a specific pointer target.
|
|
461
|
+
* Used by grab-system for hand pinch gestures.
|
|
462
|
+
*/
|
|
68
463
|
routeDown(kind, target, nativeEvent) {
|
|
69
464
|
const ptr = this.pickTarget(target);
|
|
70
465
|
if (!ptr) {
|
|
@@ -73,6 +468,10 @@ class MultiPointer {
|
|
|
73
468
|
const button = kind === 'select' ? 0 : 2;
|
|
74
469
|
ptr.down({ button, timeStamp: nativeEvent.timeStamp });
|
|
75
470
|
}
|
|
471
|
+
/**
|
|
472
|
+
* Route an up event to a specific pointer target.
|
|
473
|
+
* Used by grab-system for hand pinch gestures.
|
|
474
|
+
*/
|
|
76
475
|
routeUp(kind, target, nativeEvent) {
|
|
77
476
|
const ptr = this.pickTarget(target);
|
|
78
477
|
if (!ptr) {
|
|
@@ -81,84 +480,59 @@ class MultiPointer {
|
|
|
81
480
|
const button = kind === 'select' ? 0 : 2;
|
|
82
481
|
ptr.up({ button, timeStamp: nativeEvent.timeStamp });
|
|
83
482
|
}
|
|
483
|
+
/**
|
|
484
|
+
* Pick pointer by target type.
|
|
485
|
+
*/
|
|
84
486
|
pickTarget(target) {
|
|
85
|
-
var _a, _b, _c, _d, _e;
|
|
487
|
+
var _a, _b, _c, _d, _e, _f;
|
|
86
488
|
if (target === 'active') {
|
|
87
|
-
// Prefer captured pointer if any, else fall back to ray
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
489
|
+
// Prefer captured pointer if any, else fall back to active or ray
|
|
490
|
+
if ((_b = (_a = this.ray.pointer).getPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a)) {
|
|
491
|
+
return this.ray.pointer;
|
|
492
|
+
}
|
|
493
|
+
if ((_d = (_c = this.grab.pointer).getPointerCapture) === null || _d === void 0 ? void 0 : _d.call(_c)) {
|
|
494
|
+
return this.grab.pointer;
|
|
495
|
+
}
|
|
496
|
+
if ((_f = (_e = this.touch.pointer).getPointerCapture) === null || _f === void 0 ? void 0 : _f.call(_e)) {
|
|
497
|
+
return this.touch.pointer;
|
|
91
498
|
}
|
|
92
|
-
|
|
499
|
+
// Fall back to active pointer or ray
|
|
500
|
+
return this.activeKind
|
|
501
|
+
? this.getEntry(this.activeKind).pointer
|
|
502
|
+
: this.ray.pointer;
|
|
93
503
|
}
|
|
94
504
|
if (target === 'ray') {
|
|
95
|
-
return
|
|
505
|
+
return this.ray.pointer;
|
|
96
506
|
}
|
|
97
|
-
return
|
|
507
|
+
return this.grab.pointer;
|
|
98
508
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
entry.unregister = unregister;
|
|
111
|
-
entry.registered = true;
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
else if (!enabled && entry.registered) {
|
|
115
|
-
(_a = entry.unregister) === null || _a === void 0 ? void 0 : _a.call(entry);
|
|
116
|
-
entry.unregister = undefined;
|
|
117
|
-
entry.registered = false;
|
|
118
|
-
const idx = this.registered.findIndex((r) => r.pointer === entry.pointer);
|
|
119
|
-
if (idx >= 0) {
|
|
120
|
-
this.registered.splice(idx, 1);
|
|
121
|
-
}
|
|
122
|
-
return true;
|
|
509
|
+
/**
|
|
510
|
+
* Get the entry for a pointer kind
|
|
511
|
+
*/
|
|
512
|
+
getEntry(kind) {
|
|
513
|
+
switch (kind) {
|
|
514
|
+
case 'ray':
|
|
515
|
+
return this.ray;
|
|
516
|
+
case 'grab':
|
|
517
|
+
return this.grab;
|
|
518
|
+
case 'touch':
|
|
519
|
+
return this.touch;
|
|
123
520
|
}
|
|
124
|
-
return false;
|
|
125
521
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
if (this.ray) {
|
|
139
|
-
if (this.ray.registered) {
|
|
140
|
-
const unregister = this.combined.register(this.ray.pointer, this.defaultKind === 'ray');
|
|
141
|
-
this.registered.push({
|
|
142
|
-
kind: 'ray',
|
|
143
|
-
pointer: this.ray.pointer,
|
|
144
|
-
unregister,
|
|
145
|
-
});
|
|
146
|
-
this.ray.unregister = unregister;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (this.grab) {
|
|
150
|
-
if (this.grab.registered) {
|
|
151
|
-
const unregister = this.combined.register(this.grab.pointer, this.defaultKind === 'grab');
|
|
152
|
-
this.registered.push({
|
|
153
|
-
kind: 'grab',
|
|
154
|
-
pointer: this.grab.pointer,
|
|
155
|
-
unregister,
|
|
156
|
-
});
|
|
157
|
-
this.grab.unregister = unregister;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
522
|
+
/**
|
|
523
|
+
* Dispose of all pointer resources.
|
|
524
|
+
* Call this when the MultiPointer is no longer needed.
|
|
525
|
+
*/
|
|
526
|
+
dispose() {
|
|
527
|
+
// Dispose cursor visual
|
|
528
|
+
this.cursorVisual.dispose();
|
|
529
|
+
// Dispose ray pointer (has geometry/material)
|
|
530
|
+
this.ray.visual.dispose();
|
|
531
|
+
// Clear state
|
|
532
|
+
this.pointerStates.clear();
|
|
533
|
+
this.activeKind = null;
|
|
160
534
|
}
|
|
161
535
|
}
|
|
162
536
|
|
|
163
|
-
export { MultiPointer };
|
|
537
|
+
export { InteractorState, MultiPointer };
|
|
164
538
|
//# sourceMappingURL=multi-pointer.js.map
|