@iwsdk/xr-input 0.1.0
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/LICENSE +21 -0
- package/dist/gamepad/generated-profiles.d.ts +10 -0
- package/dist/gamepad/generated-profiles.d.ts.map +1 -0
- package/dist/gamepad/generated-profiles.js +12798 -0
- package/dist/gamepad/generated-profiles.js.map +1 -0
- package/dist/gamepad/input-profiles.d.ts +62 -0
- package/dist/gamepad/input-profiles.d.ts.map +1 -0
- package/dist/gamepad/input-profiles.js +98 -0
- package/dist/gamepad/input-profiles.js.map +1 -0
- package/dist/gamepad/stateful-gamepad.d.ts +79 -0
- package/dist/gamepad/stateful-gamepad.d.ts.map +1 -0
- package/dist/gamepad/stateful-gamepad.js +212 -0
- package/dist/gamepad/stateful-gamepad.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/super-three@0.177.0/node_modules/super-three/src/math/MathUtils.js +17 -0
- package/dist/node_modules/.pnpm/super-three@0.177.0/node_modules/super-three/src/math/MathUtils.js.map +1 -0
- package/dist/pointer/grab-pointer.d.ts +15 -0
- package/dist/pointer/grab-pointer.d.ts.map +1 -0
- package/dist/pointer/grab-pointer.js +18 -0
- package/dist/pointer/grab-pointer.js.map +1 -0
- package/dist/pointer/multi-pointer.d.ts +45 -0
- package/dist/pointer/multi-pointer.d.ts.map +1 -0
- package/dist/pointer/multi-pointer.js +164 -0
- package/dist/pointer/multi-pointer.js.map +1 -0
- package/dist/pointer/ray-pointer.d.ts +32 -0
- package/dist/pointer/ray-pointer.d.ts.map +1 -0
- package/dist/pointer/ray-pointer.js +197 -0
- package/dist/pointer/ray-pointer.js.map +1 -0
- package/dist/rig/xr-origin.d.ts +30 -0
- package/dist/rig/xr-origin.d.ts.map +1 -0
- package/dist/rig/xr-origin.js +43 -0
- package/dist/rig/xr-origin.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/visual/adapter/base-visual-adapter.d.ts +63 -0
- package/dist/visual/adapter/base-visual-adapter.d.ts.map +1 -0
- package/dist/visual/adapter/base-visual-adapter.js +91 -0
- package/dist/visual/adapter/base-visual-adapter.js.map +1 -0
- package/dist/visual/adapter/controller-visual-adapter.d.ts +18 -0
- package/dist/visual/adapter/controller-visual-adapter.d.ts.map +1 -0
- package/dist/visual/adapter/controller-visual-adapter.js +43 -0
- package/dist/visual/adapter/controller-visual-adapter.js.map +1 -0
- package/dist/visual/adapter/hand-visual-adapter.d.ts +32 -0
- package/dist/visual/adapter/hand-visual-adapter.d.ts.map +1 -0
- package/dist/visual/adapter/hand-visual-adapter.js +183 -0
- package/dist/visual/adapter/hand-visual-adapter.js.map +1 -0
- package/dist/visual/impl/animated-controller-hand.d.ts +23 -0
- package/dist/visual/impl/animated-controller-hand.d.ts.map +1 -0
- package/dist/visual/impl/animated-controller-hand.js +412 -0
- package/dist/visual/impl/animated-controller-hand.js.map +1 -0
- package/dist/visual/impl/animated-controller.d.ts +15 -0
- package/dist/visual/impl/animated-controller.d.ts.map +1 -0
- package/dist/visual/impl/animated-controller.js +91 -0
- package/dist/visual/impl/animated-controller.js.map +1 -0
- package/dist/visual/impl/animated-hand.d.ts +16 -0
- package/dist/visual/impl/animated-hand.d.ts.map +1 -0
- package/dist/visual/impl/animated-hand.js +126 -0
- package/dist/visual/impl/animated-hand.js.map +1 -0
- package/dist/visual/impl/base-impl.d.ts +60 -0
- package/dist/visual/impl/base-impl.d.ts.map +1 -0
- package/dist/visual/impl/base-impl.js +73 -0
- package/dist/visual/impl/base-impl.js.map +1 -0
- package/dist/visual/utils/flex-batched-mesh.d.ts +15 -0
- package/dist/visual/utils/flex-batched-mesh.d.ts.map +1 -0
- package/dist/visual/utils/flex-batched-mesh.js +73 -0
- package/dist/visual/utils/flex-batched-mesh.js.map +1 -0
- package/dist/xr-input-manager.d.ts +74 -0
- package/dist/xr-input-manager.d.ts.map +1 -0
- package/dist/xr-input-manager.js +252 -0
- package/dist/xr-input-manager.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createGrabPointer } from '@pmndrs/pointer-events';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
class GrabPointer {
|
|
10
|
+
constructor(camera, xrOrigin, handedness) {
|
|
11
|
+
this.pointer = createGrabPointer(() => camera, { current: xrOrigin.gripSpaces[handedness] }, {});
|
|
12
|
+
}
|
|
13
|
+
// Align interface with RayPointer (no visuals for now)
|
|
14
|
+
update(_connected, _delta, _time, _start, _end) { }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { GrabPointer };
|
|
18
|
+
//# sourceMappingURL=grab-pointer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grab-pointer.js","sources":["../../src/pointer/grab-pointer.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;;;AAKG;MAMU,WAAW,CAAA;AAGtB,IAAA,WAAA,CACE,MAAyB,EACzB,QAAkB,EAClB,UAA4B,EAAA;QAE5B,IAAI,CAAC,OAAO,GAAG,iBAAiB,CAC9B,MAAM,MAAM,EACZ,EAAE,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,EAC5C,EAAE,CACH;IACH;;IAGA,MAAM,CACJ,UAAmB,EACnB,MAAc,EACd,KAAa,EACb,MAAe,EACf,IAAa,EAAA,EACZ;AACJ;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Object3D, PerspectiveCamera } from 'three';
|
|
8
|
+
import type { XROrigin } from '../rig/xr-origin.js';
|
|
9
|
+
export type PointerKind = 'ray' | 'grab' | 'custom';
|
|
10
|
+
export declare class MultiPointer {
|
|
11
|
+
private readonly handedness;
|
|
12
|
+
private readonly scene;
|
|
13
|
+
private readonly camera;
|
|
14
|
+
private readonly xrOrigin;
|
|
15
|
+
private readonly combined;
|
|
16
|
+
private readonly registered;
|
|
17
|
+
private ray?;
|
|
18
|
+
private grab?;
|
|
19
|
+
private defaultKind;
|
|
20
|
+
constructor(handedness: 'left' | 'right', scene: Object3D, camera: PerspectiveCamera, xrOrigin: XROrigin);
|
|
21
|
+
update(connected: boolean, delta: number, time: number, input?: {
|
|
22
|
+
selectStart?: boolean;
|
|
23
|
+
selectEnd?: boolean;
|
|
24
|
+
squeezeStart?: boolean;
|
|
25
|
+
squeezeEnd?: boolean;
|
|
26
|
+
}): void;
|
|
27
|
+
getPolicyForRay(): {
|
|
28
|
+
forceHideRay: boolean;
|
|
29
|
+
forceHideCursor: boolean;
|
|
30
|
+
};
|
|
31
|
+
getRayBusy(): boolean;
|
|
32
|
+
routeDown(kind: 'select' | 'squeeze' | 'custom', target: 'ray' | 'grab' | 'active', nativeEvent: {
|
|
33
|
+
timeStamp: number;
|
|
34
|
+
}): void;
|
|
35
|
+
routeUp(kind: 'select' | 'squeeze' | 'custom', target: 'ray' | 'grab' | 'active', nativeEvent: {
|
|
36
|
+
timeStamp: number;
|
|
37
|
+
}): void;
|
|
38
|
+
private pickTarget;
|
|
39
|
+
toggleSubPointer(kind: PointerKind, enabled: boolean): boolean;
|
|
40
|
+
getSubPointerState(kind: PointerKind): {
|
|
41
|
+
registered: boolean;
|
|
42
|
+
};
|
|
43
|
+
setDefault(kind: PointerKind): void;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=multi-pointer.d.ts.map
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W,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE;IAUpC,OAAO,CACL,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,EACrC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,EACjC,WAAW,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE;IAUpC,OAAO,CAAC,UAAU;IAqBlB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IAyB9D,kBAAkB,CAAC,IAAI,EAAE,WAAW,GAAG;QAAE,UAAU,EAAE,OAAO,CAAA;KAAE;IAK9D,UAAU,CAAC,IAAI,EAAE,WAAW;CAqC7B"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { CombinedPointer } from '@pmndrs/pointer-events';
|
|
2
|
+
import { GrabPointer } from './grab-pointer.js';
|
|
3
|
+
import { RayPointer } from './ray-pointer.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/
|
|
11
|
+
class MultiPointer {
|
|
12
|
+
constructor(handedness, scene, camera, xrOrigin) {
|
|
13
|
+
this.handedness = handedness;
|
|
14
|
+
this.scene = scene;
|
|
15
|
+
this.camera = camera;
|
|
16
|
+
this.xrOrigin = xrOrigin;
|
|
17
|
+
this.registered = [];
|
|
18
|
+
this.defaultKind = 'ray';
|
|
19
|
+
this.combined = new CombinedPointer(false);
|
|
20
|
+
// Build built-ins (register only ray by default)
|
|
21
|
+
const ray = new RayPointer(this.camera, this.xrOrigin, this.handedness);
|
|
22
|
+
const grab = new GrabPointer(this.camera, this.xrOrigin, this.handedness);
|
|
23
|
+
this.ray = { pointer: ray.pointer, visual: ray, registered: false };
|
|
24
|
+
this.grab = { pointer: grab.pointer, visual: grab, registered: false };
|
|
25
|
+
this.toggleSubPointer('ray', true);
|
|
26
|
+
}
|
|
27
|
+
update(connected, delta, time, input) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const timeStamp = time * 1000;
|
|
30
|
+
this.combined.setEnabled(connected, { timeStamp });
|
|
31
|
+
this.combined.move(this.scene, { timeStamp });
|
|
32
|
+
// Visuals policy for ray
|
|
33
|
+
const policy = this.getPolicyForRay();
|
|
34
|
+
(_a = this.ray) === null || _a === void 0 ? void 0 : _a.visual.update(connected, delta, time, !!(input === null || input === void 0 ? void 0 : input.selectStart), !!(input === null || input === void 0 ? void 0 : input.selectEnd), policy);
|
|
35
|
+
// Emit down/up based on input
|
|
36
|
+
if ((_b = this.grab) === null || _b === void 0 ? void 0 : _b.registered) {
|
|
37
|
+
if (input === null || input === void 0 ? void 0 : input.squeezeStart) {
|
|
38
|
+
this.routeDown('squeeze', 'grab', { timeStamp });
|
|
39
|
+
}
|
|
40
|
+
if (input === null || input === void 0 ? void 0 : input.squeezeEnd) {
|
|
41
|
+
this.routeUp('squeeze', 'grab', { timeStamp });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (input === null || input === void 0 ? void 0 : input.selectStart) {
|
|
45
|
+
this.routeDown('select', 'ray', { timeStamp });
|
|
46
|
+
}
|
|
47
|
+
if (input === null || input === void 0 ? void 0 : input.selectEnd) {
|
|
48
|
+
this.routeUp('select', 'ray', { timeStamp });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
getPolicyForRay() {
|
|
52
|
+
var _a, _b, _c;
|
|
53
|
+
const rayCaptured = !!((_c = (_a = this.ray) === null || _a === void 0 ? void 0 : (_b = _a.pointer).getPointerCapture) === null || _c === void 0 ? void 0 : _c.call(_b));
|
|
54
|
+
const nonRayCaptured = this.registered.some((r) => { var _a, _b; return r.kind !== 'ray' && !!((_b = (_a = r.pointer).getPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a)); });
|
|
55
|
+
// Policy
|
|
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
|
+
};
|
|
63
|
+
}
|
|
64
|
+
getRayBusy() {
|
|
65
|
+
var _a;
|
|
66
|
+
return !!((_a = this.ray) === null || _a === void 0 ? void 0 : _a.visual.busy);
|
|
67
|
+
}
|
|
68
|
+
routeDown(kind, target, nativeEvent) {
|
|
69
|
+
const ptr = this.pickTarget(target);
|
|
70
|
+
if (!ptr) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const button = kind === 'select' ? 0 : 2;
|
|
74
|
+
ptr.down({ button, timeStamp: nativeEvent.timeStamp });
|
|
75
|
+
}
|
|
76
|
+
routeUp(kind, target, nativeEvent) {
|
|
77
|
+
const ptr = this.pickTarget(target);
|
|
78
|
+
if (!ptr) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const button = kind === 'select' ? 0 : 2;
|
|
82
|
+
ptr.up({ button, timeStamp: nativeEvent.timeStamp });
|
|
83
|
+
}
|
|
84
|
+
pickTarget(target) {
|
|
85
|
+
var _a, _b, _c, _d, _e;
|
|
86
|
+
if (target === 'active') {
|
|
87
|
+
// Prefer captured pointer if any, else fall back to ray
|
|
88
|
+
const captured = this.registered.find((r) => { var _a, _b; return !!((_b = (_a = r.pointer).getPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a)); });
|
|
89
|
+
if (captured) {
|
|
90
|
+
return captured.pointer;
|
|
91
|
+
}
|
|
92
|
+
return (_a = this.ray) === null || _a === void 0 ? void 0 : _a.pointer;
|
|
93
|
+
}
|
|
94
|
+
if (target === 'ray') {
|
|
95
|
+
return (_b = this.ray) === null || _b === void 0 ? void 0 : _b.pointer;
|
|
96
|
+
}
|
|
97
|
+
return ((_d = (_c = this.grab) === null || _c === void 0 ? void 0 : _c.pointer) !== null && _d !== void 0 ? _d : (_e = this.registered.find((r) => r.kind === 'grab')) === null || _e === void 0 ? void 0 : _e.pointer);
|
|
98
|
+
}
|
|
99
|
+
// Public toggle API
|
|
100
|
+
toggleSubPointer(kind, enabled) {
|
|
101
|
+
var _a;
|
|
102
|
+
const entry = kind === 'ray' ? this.ray : this.grab;
|
|
103
|
+
if (!entry) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (enabled && !entry.registered) {
|
|
107
|
+
const isDefault = kind === this.defaultKind;
|
|
108
|
+
const unregister = this.combined.register(entry.pointer, isDefault);
|
|
109
|
+
this.registered.push({ kind, pointer: entry.pointer, unregister });
|
|
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;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
getSubPointerState(kind) {
|
|
127
|
+
const entry = kind === 'ray' ? this.ray : this.grab;
|
|
128
|
+
return { registered: !!(entry === null || entry === void 0 ? void 0 : entry.registered) };
|
|
129
|
+
}
|
|
130
|
+
setDefault(kind) {
|
|
131
|
+
this.defaultKind = kind;
|
|
132
|
+
// Re-register current pointers to update default preference
|
|
133
|
+
const snapshot = [...this.registered];
|
|
134
|
+
// Unregister all
|
|
135
|
+
snapshot.forEach((r) => r.unregister());
|
|
136
|
+
this.registered.length = 0;
|
|
137
|
+
// Re-register in same order with updated isDefault flags
|
|
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
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { MultiPointer };
|
|
164
|
+
//# sourceMappingURL=multi-pointer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-pointer.js","sources":["../../src/pointer/multi-pointer.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;;;;;AAKG;MAgBU,YAAY,CAAA;AAiBvB,IAAA,WAAA,CACmB,UAA4B,EAC5B,KAAe,EACf,MAAyB,EACzB,QAAkB,EAAA;QAHlB,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,KAAK,GAAL,KAAK;QACL,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,QAAQ,GAAR,QAAQ;QAnBV,IAAA,CAAA,UAAU,GAAiB,EAAE;QAatC,IAAA,CAAA,WAAW,GAAgB,KAAK;QAQtC,IAAI,CAAC,QAAQ,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC;;AAE1C,QAAA,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC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
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { Pointer } from '@pmndrs/pointer-events';
|
|
8
|
+
import { CircleGeometry, CylinderGeometry, Intersection, Mesh, MeshBasicMaterial, PerspectiveCamera, ShaderMaterial } from 'three';
|
|
9
|
+
import { XROrigin } from '../rig/xr-origin.js';
|
|
10
|
+
export declare enum RayDisplayMode {
|
|
11
|
+
Visible = 1,
|
|
12
|
+
VisibleOnIntersection = 2,
|
|
13
|
+
Invisible = 3
|
|
14
|
+
}
|
|
15
|
+
export declare class RayPointer {
|
|
16
|
+
private xrOrigin;
|
|
17
|
+
static pointerCount: number;
|
|
18
|
+
pointer: Pointer;
|
|
19
|
+
ray: Mesh<CylinderGeometry, ShaderMaterial>;
|
|
20
|
+
cursor: Mesh<CircleGeometry, MeshBasicMaterial>;
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
rayIntersection: Intersection | undefined;
|
|
23
|
+
rayDisplayMode: RayDisplayMode;
|
|
24
|
+
constructor(camera: PerspectiveCamera, xrOrigin: XROrigin, handedness: 'left' | 'right');
|
|
25
|
+
update(connected: boolean, delta: number, _time: number, selectStart: boolean, selectEnd: boolean, policy?: {
|
|
26
|
+
forceHideRay?: boolean;
|
|
27
|
+
forceHideCursor?: boolean;
|
|
28
|
+
}): void;
|
|
29
|
+
private updatePointerRendering;
|
|
30
|
+
get busy(): boolean;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=ray-pointer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ray-pointer.d.ts","sourceRoot":"","sources":["../../src/pointer/ray-pointer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAoB,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAEL,cAAc,EAEd,gBAAgB,EAChB,YAAY,EACZ,IAAI,EACJ,iBAAiB,EAEjB,iBAAiB,EAEjB,cAAc,EAEf,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AA+C/C,oBAAY,cAAc;IACxB,OAAO,IAAI;IACX,qBAAqB,IAAI;IACzB,SAAS,IAAI;CACd;AAED,qBAAa,UAAU;IAWnB,OAAO,CAAC,QAAQ;IAVlB,MAAM,CAAC,YAAY,SAAK;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,IAAI,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;IAC5C,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;IAChD,OAAO,UAAQ;IACf,eAAe,EAAE,YAAY,GAAG,SAAS,CAAC;IAC1C,cAAc,EAAE,cAAc,CAAwC;gBAG3E,MAAM,EAAE,iBAAiB,EACjB,QAAQ,EAAE,QAAQ,EAC1B,UAAU,EAAE,MAAM,GAAG,OAAO;IAmD9B,MAAM,CACJ,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,OAAO,EAClB,MAAM,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,CAAA;KAAE;IA0BhE,OAAO,CAAC,sBAAsB;IAgF9B,IAAI,IAAI,YAEP;CACF"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { createRayPointer } from '@pmndrs/pointer-events';
|
|
2
|
+
import { CanvasTexture, Vector3, Quaternion, Color, Mesh, CylinderGeometry, ShaderMaterial, CircleGeometry, MeshBasicMaterial, Matrix3 } from 'three';
|
|
3
|
+
import { lerp } from '../node_modules/.pnpm/super-three@0.177.0/node_modules/super-three/src/math/MathUtils.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/
|
|
11
|
+
const vertexShader = `
|
|
12
|
+
varying float vPosition;
|
|
13
|
+
void main() {
|
|
14
|
+
vPosition = (position.z + 1.0) / 1.0;
|
|
15
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
const fragmentShader = `
|
|
19
|
+
uniform float endValue;
|
|
20
|
+
uniform float opacity;
|
|
21
|
+
uniform vec3 color;
|
|
22
|
+
varying float vPosition;
|
|
23
|
+
void main() {
|
|
24
|
+
float alpha = vPosition < endValue ? smoothstep(endValue-0.05, endValue, vPosition) :
|
|
25
|
+
vPosition < 0.97 ? 1.0 :
|
|
26
|
+
1.0 - smoothstep(0.97, 1.0, vPosition);
|
|
27
|
+
gl_FragColor = vec4(color, alpha * opacity);
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
// create cursor texture
|
|
31
|
+
const cursorRes = 512;
|
|
32
|
+
const canvas = document.createElement('canvas');
|
|
33
|
+
canvas.width = cursorRes;
|
|
34
|
+
canvas.height = cursorRes;
|
|
35
|
+
const ctx = canvas.getContext('2d');
|
|
36
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
37
|
+
ctx.fillStyle = 'white';
|
|
38
|
+
ctx.beginPath();
|
|
39
|
+
ctx.arc(cursorRes / 2, cursorRes / 2, (cursorRes / 16) * 7, 0, Math.PI * 2);
|
|
40
|
+
ctx.fill();
|
|
41
|
+
ctx.strokeStyle = 'gray';
|
|
42
|
+
ctx.lineWidth = 3;
|
|
43
|
+
ctx.beginPath();
|
|
44
|
+
ctx.arc(cursorRes / 2, cursorRes / 2, (cursorRes / 16) * 7, 0, Math.PI * 2);
|
|
45
|
+
ctx.stroke();
|
|
46
|
+
const cursorTexture = new CanvasTexture(canvas);
|
|
47
|
+
const ZAxis = new Vector3(0, 0, 1);
|
|
48
|
+
const offsetHelper = new Vector3();
|
|
49
|
+
const cursorPosition = new Vector3();
|
|
50
|
+
const quaternionHelper = new Quaternion();
|
|
51
|
+
const rayPressedColor = new Color(0x3383e6);
|
|
52
|
+
const rayDefaultColor = new Color(0xffffff);
|
|
53
|
+
var RayDisplayMode;
|
|
54
|
+
(function (RayDisplayMode) {
|
|
55
|
+
RayDisplayMode[RayDisplayMode["Visible"] = 1] = "Visible";
|
|
56
|
+
RayDisplayMode[RayDisplayMode["VisibleOnIntersection"] = 2] = "VisibleOnIntersection";
|
|
57
|
+
RayDisplayMode[RayDisplayMode["Invisible"] = 3] = "Invisible";
|
|
58
|
+
})(RayDisplayMode || (RayDisplayMode = {}));
|
|
59
|
+
class RayPointer {
|
|
60
|
+
constructor(camera, xrOrigin, handedness) {
|
|
61
|
+
this.xrOrigin = xrOrigin;
|
|
62
|
+
this.enabled = true;
|
|
63
|
+
this.rayDisplayMode = RayDisplayMode.VisibleOnIntersection;
|
|
64
|
+
this.pointer = createRayPointer(() => camera, { current: xrOrigin.raySpaces[handedness] }, {}, {
|
|
65
|
+
// Disable contextmenu on button 2 (squeeze) to avoid spurious events
|
|
66
|
+
contextMenuButton: -1,
|
|
67
|
+
});
|
|
68
|
+
// Optimize raycaster for BVH acceleration - only get first hit for better performance
|
|
69
|
+
const raycaster = this.pointer.intersector.raycaster;
|
|
70
|
+
if (raycaster) {
|
|
71
|
+
raycaster.firstHitOnly = true;
|
|
72
|
+
}
|
|
73
|
+
this.ray = new Mesh(new CylinderGeometry(0.001, 0.001, 1, 6, 1, true)
|
|
74
|
+
.translate(0, 0.5, 0)
|
|
75
|
+
.rotateX(-Math.PI / 2), new ShaderMaterial({
|
|
76
|
+
vertexShader: vertexShader,
|
|
77
|
+
fragmentShader: fragmentShader,
|
|
78
|
+
transparent: true,
|
|
79
|
+
depthWrite: false,
|
|
80
|
+
uniforms: {
|
|
81
|
+
endValue: { value: 0.75 },
|
|
82
|
+
color: { value: new Color().copy(rayDefaultColor) },
|
|
83
|
+
opacity: { value: 1 },
|
|
84
|
+
},
|
|
85
|
+
}));
|
|
86
|
+
// Ensure the cursor renders above the ray
|
|
87
|
+
this.ray.renderOrder = 0;
|
|
88
|
+
xrOrigin.raySpaces[handedness].add(this.ray);
|
|
89
|
+
this.cursor = new Mesh(new CircleGeometry(0.008), new MeshBasicMaterial({
|
|
90
|
+
map: cursorTexture,
|
|
91
|
+
transparent: true,
|
|
92
|
+
}));
|
|
93
|
+
this.cursor.renderOrder = Infinity;
|
|
94
|
+
this.cursor.userData.attached = true;
|
|
95
|
+
this.cursor.userData.zOffset = 0.004 + RayPointer.pointerCount++ * 0.001;
|
|
96
|
+
this.cursor.userData.focused = false;
|
|
97
|
+
this.cursor.userData.focusAlpha = 0;
|
|
98
|
+
xrOrigin.add(this.cursor);
|
|
99
|
+
}
|
|
100
|
+
update(connected, delta, _time, selectStart, selectEnd, policy) {
|
|
101
|
+
// CombinedPointer is responsible for moving/enabling; we only render visuals
|
|
102
|
+
// CombinedPointer controls actual pointer enablement; reflect that in visuals
|
|
103
|
+
const pointerEnabled = this.pointer.getEnabled();
|
|
104
|
+
const active = pointerEnabled && connected && this.enabled;
|
|
105
|
+
this.ray.visible = active && !(policy === null || policy === void 0 ? void 0 : policy.forceHideRay);
|
|
106
|
+
this.cursor.visible = active && !(policy === null || policy === void 0 ? void 0 : policy.forceHideCursor);
|
|
107
|
+
if (active) {
|
|
108
|
+
if (pointerEnabled && selectStart) {
|
|
109
|
+
this.ray.material.uniforms.color.value.copy(rayPressedColor);
|
|
110
|
+
if (this.cursor) {
|
|
111
|
+
this.cursor.userData.focused = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (pointerEnabled && selectEnd) {
|
|
115
|
+
this.ray.material.uniforms.color.value.copy(rayDefaultColor);
|
|
116
|
+
if (this.cursor) {
|
|
117
|
+
this.cursor.userData.focused = false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Movement is handled by the owning CombinedPointer aggregator
|
|
121
|
+
}
|
|
122
|
+
this.updatePointerRendering(active, delta);
|
|
123
|
+
}
|
|
124
|
+
updatePointerRendering(pointerActive, delta = 1) {
|
|
125
|
+
var _a, _b, _c, _d;
|
|
126
|
+
let rayOpacityTarget = 0;
|
|
127
|
+
if (pointerActive) {
|
|
128
|
+
const captured = !!((_b = (_a = this.pointer).getPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
129
|
+
const intersection = this.pointer.getIntersection();
|
|
130
|
+
const intersectionValid = !!(intersection && !intersection.object.isVoidObject);
|
|
131
|
+
this.rayIntersection = intersectionValid ? intersection : undefined;
|
|
132
|
+
switch (this.rayDisplayMode) {
|
|
133
|
+
case RayDisplayMode.Visible:
|
|
134
|
+
rayOpacityTarget = 1;
|
|
135
|
+
break;
|
|
136
|
+
case RayDisplayMode.Invisible:
|
|
137
|
+
rayOpacityTarget = 0;
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
rayOpacityTarget = intersectionValid ? 1 : 0;
|
|
141
|
+
}
|
|
142
|
+
if (intersectionValid && !captured) {
|
|
143
|
+
cursorPosition.copy(intersection.pointOnFace);
|
|
144
|
+
this.cursor.userData.focusAlpha = lerp(this.cursor.userData.focusAlpha, this.cursor.userData.focused ? 1 : 0, 30 * delta);
|
|
145
|
+
const cursorScale = (Math.max(0, intersection.distance - 0.3) + 1) *
|
|
146
|
+
lerp(1, 0.8, this.cursor.userData.focusAlpha);
|
|
147
|
+
this.cursor.material.opacity = lerp(0.7, 1, this.cursor.userData.focusAlpha);
|
|
148
|
+
this.cursor.scale.setScalar(cursorScale);
|
|
149
|
+
this.ray.material.uniforms.endValue.value =
|
|
150
|
+
1.05 - Math.min(0.3, intersection.distance);
|
|
151
|
+
const normal = (_c = intersection.normal) !== null && _c !== void 0 ? _c : (_d = intersection.face) === null || _d === void 0 ? void 0 : _d.normal;
|
|
152
|
+
if (normal != null) {
|
|
153
|
+
// Convert local-space normal to world-space using normal matrix to handle non-uniform scales
|
|
154
|
+
const normalWorld = normal.clone();
|
|
155
|
+
const normalMatrix = new Matrix3().getNormalMatrix(intersection.object.matrixWorld);
|
|
156
|
+
normalWorld.applyNormalMatrix(normalMatrix).normalize();
|
|
157
|
+
// Build world-space orientation from +Z to world normal
|
|
158
|
+
this.cursor.quaternion.setFromUnitVectors(ZAxis, normalWorld);
|
|
159
|
+
// Convert world orientation to xrOrigin local space
|
|
160
|
+
quaternionHelper.copy(this.xrOrigin.quaternion).invert();
|
|
161
|
+
this.cursor.quaternion.multiply(quaternionHelper);
|
|
162
|
+
// Offset slightly along the oriented normal to avoid z-fighting
|
|
163
|
+
offsetHelper.set(0, 0, this.cursor.userData.zOffset);
|
|
164
|
+
offsetHelper.applyQuaternion(this.cursor.quaternion);
|
|
165
|
+
cursorPosition.add(offsetHelper);
|
|
166
|
+
}
|
|
167
|
+
else if (intersection.pointerQuaternion) {
|
|
168
|
+
// Fallback: align cursor with pointer direction when no surface normal is available
|
|
169
|
+
this.cursor.quaternion.copy(intersection.pointerQuaternion);
|
|
170
|
+
quaternionHelper.copy(this.xrOrigin.quaternion).invert();
|
|
171
|
+
this.cursor.quaternion.multiply(quaternionHelper);
|
|
172
|
+
offsetHelper.set(0, 0, this.cursor.userData.zOffset);
|
|
173
|
+
offsetHelper.applyQuaternion(this.cursor.quaternion);
|
|
174
|
+
cursorPosition.add(offsetHelper);
|
|
175
|
+
}
|
|
176
|
+
this.xrOrigin.worldToLocal(cursorPosition);
|
|
177
|
+
this.cursor.position.copy(cursorPosition);
|
|
178
|
+
this.cursor.updateMatrix();
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
this.cursor.visible = false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
this.cursor.visible = false;
|
|
186
|
+
this.rayIntersection = undefined;
|
|
187
|
+
}
|
|
188
|
+
this.ray.material.uniforms.opacity.value = lerp(this.ray.material.uniforms.opacity.value, rayOpacityTarget, delta * 10);
|
|
189
|
+
}
|
|
190
|
+
get busy() {
|
|
191
|
+
return !!this.rayIntersection;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
RayPointer.pointerCount = 0;
|
|
195
|
+
|
|
196
|
+
export { RayDisplayMode, RayPointer };
|
|
197
|
+
//# sourceMappingURL=ray-pointer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ray-pointer.js","sources":["../../src/pointer/ray-pointer.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;;;;;AAKG;AAoBH,MAAM,YAAY,GAAG;;;;;;CAMpB;AAED,MAAM,cAAc,GAAG;;;;;;;;;;;CAWtB;AACD;AACA,MAAM,SAAS,GAAG,GAAG;AACrB,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;AAC/C,MAAM,CAAC,KAAK,GAAG,SAAS;AACxB,MAAM,CAAC,MAAM,GAAG,SAAS;AACzB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAE;AACpC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;AAChD,GAAG,CAAC,SAAS,GAAG,OAAO;AACvB,GAAG,CAAC,SAAS,EAAE;AACf,GAAG,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAC3E,GAAG,CAAC,IAAI,EAAE;AACV,GAAG,CAAC,WAAW,GAAG,MAAM;AACxB,GAAG,CAAC,SAAS,GAAG,CAAC;AACjB,GAAG,CAAC,SAAS,EAAE;AACf,GAAG,CAAC,GAAG,CAAC,SAAS,G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AE;YAC5B;iBAAO;AACL,gBAAA,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,KAAK;YAC7B;QACF;aAAO;AACL,YAAA,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,KAAK;AAC3B,YAAA,IAAI,CAAC,eAAe,GAAG,SAAS;QAClC;AACA,QAAA,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG,IAAI,CAC7C,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EACxC,gBAAgB,EAChB,KAAK,GAAG,EAAE,CACX;IACH;AAEA,IAAA,IAAI,IAAI,GAAA;AACN,QAAA,OAAO,CAAC,CAAC,IAAI,CAAC,eAAe;IAC/B;;AAhLO,UAAA,CAAA,YAAY,GAAG,CAAH;;;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { Group } from 'three';
|
|
8
|
+
export declare class XROrigin extends Group {
|
|
9
|
+
readonly head: Group;
|
|
10
|
+
readonly raySpaces: {
|
|
11
|
+
left: Group<import("three").Object3DEventMap>;
|
|
12
|
+
right: Group<import("three").Object3DEventMap>;
|
|
13
|
+
};
|
|
14
|
+
readonly gripSpaces: {
|
|
15
|
+
left: Group<import("three").Object3DEventMap>;
|
|
16
|
+
right: Group<import("three").Object3DEventMap>;
|
|
17
|
+
};
|
|
18
|
+
readonly secondaryRaySpaces: {
|
|
19
|
+
left: Group<import("three").Object3DEventMap>;
|
|
20
|
+
right: Group<import("three").Object3DEventMap>;
|
|
21
|
+
};
|
|
22
|
+
readonly secondaryGripSpaces: {
|
|
23
|
+
left: Group<import("three").Object3DEventMap>;
|
|
24
|
+
right: Group<import("three").Object3DEventMap>;
|
|
25
|
+
};
|
|
26
|
+
private headsetMatrix;
|
|
27
|
+
constructor();
|
|
28
|
+
updateHead(frame: XRFrame, referenceSpace: XRReferenceSpace): void;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=xr-origin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xr-origin.d.ts","sourceRoot":"","sources":["../../src/rig/xr-origin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAW,MAAM,OAAO,CAAC;AAEvC,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAgB,IAAI,EAAE,KAAK,CAAC;IAE5B,SAAgB,SAAS;;;MAGvB;IAEF,SAAgB,UAAU;;;MAGxB;IAEF,SAAgB,kBAAkB;;;MAGhC;IAEF,SAAgB,mBAAmB;;;MAGjC;IAEF,OAAO,CAAC,aAAa,CAAiB;;IAgBtC,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,gBAAgB,GAAG,IAAI;CAWnE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Group, Matrix4 } from 'three';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
class XROrigin extends Group {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.raySpaces = {
|
|
13
|
+
left: new Group(),
|
|
14
|
+
right: new Group(),
|
|
15
|
+
};
|
|
16
|
+
this.gripSpaces = {
|
|
17
|
+
left: new Group(),
|
|
18
|
+
right: new Group(),
|
|
19
|
+
};
|
|
20
|
+
this.secondaryRaySpaces = {
|
|
21
|
+
left: new Group(),
|
|
22
|
+
right: new Group(),
|
|
23
|
+
};
|
|
24
|
+
this.secondaryGripSpaces = {
|
|
25
|
+
left: new Group(),
|
|
26
|
+
right: new Group(),
|
|
27
|
+
};
|
|
28
|
+
this.headsetMatrix = new Matrix4();
|
|
29
|
+
this.head = new Group();
|
|
30
|
+
this.head.name = 'xr-origin-head';
|
|
31
|
+
this.add(this.head, this.raySpaces.left, this.raySpaces.right, this.gripSpaces.left, this.gripSpaces.right);
|
|
32
|
+
}
|
|
33
|
+
updateHead(frame, referenceSpace) {
|
|
34
|
+
const pose = frame.getViewerPose(referenceSpace);
|
|
35
|
+
if (pose) {
|
|
36
|
+
this.headsetMatrix.fromArray(pose.transform.matrix);
|
|
37
|
+
this.headsetMatrix.decompose(this.head.position, this.head.quaternion, this.head.scale);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { XROrigin };
|
|
43
|
+
//# sourceMappingURL=xr-origin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xr-origin.js","sources":["../../src/rig/xr-origin.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;;;AAKG;AAIG,MAAO,QAAS,SAAQ,KAAK,CAAA;AAyBjC,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE;AAvBO,QAAA,IAAA,CAAA,SAAS,GAAG;YAC1B,IAAI,EAAE,IAAI,KAAK,EAAE;YACjB,KAAK,EAAE,IAAI,KAAK,EAAE;SACnB;AAEe,QAAA,IAAA,CAAA,UAAU,GAAG;YAC3B,IAAI,EAAE,IAAI,KAAK,EAAE;YACjB,KAAK,EAAE,IAAI,KAAK,EAAE;SACnB;AAEe,QAAA,IAAA,CAAA,kBAAkB,GAAG;YACnC,IAAI,EAAE,IAAI,KAAK,EAAE;YACjB,KAAK,EAAE,IAAI,KAAK,EAAE;SACnB;AAEe,QAAA,IAAA,CAAA,mBAAmB,GAAG;YACpC,IAAI,EAAE,IAAI,KAAK,EAAE;YACjB,KAAK,EAAE,IAAI,KAAK,EAAE;SACnB;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