@threenative/core 0.3.3 → 0.3.5
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/capabilities.json +2019 -59
- package/dist/{assets-CYKk2WTu.d.ts → assets-CqvE429w.d.ts} +45 -3
- package/dist/{audio-7i3Xl0l3.d.ts → audio-DIJE5HTr.d.ts} +43 -3
- package/dist/{canvas-layer-C1SnMoJ-.d.ts → canvas-layer-C1-5CviZ.d.ts} +5 -1
- package/dist/{game-D_6r-k4Y.d.ts → game-Bj8G1wmD.d.ts} +242 -17
- package/dist/hot.d.ts +5 -5
- package/dist/index.d.ts +1131 -105
- package/dist/index.js +15201 -4782
- package/dist/model-lod-BDAUYgsS.d.ts +197 -0
- package/dist/playtest.d.ts +6 -4
- package/dist/playtest.js +84 -11
- package/dist/react-css.d.ts +62 -0
- package/dist/react-css.js +591 -0
- package/dist/react.d.ts +2 -2
- package/dist/{renderer-Cy4qeBOA.d.ts → renderer-9yEo9hPa.d.ts} +676 -21
- package/dist/terrain-jobs-worker.d.ts +2 -0
- package/dist/terrain-jobs-worker.js +130 -0
- package/dist/ui-layer.d.ts +5 -3
- package/dist/ui-layer.js +59 -8
- package/dist/world.d.ts +1596 -17
- package/dist/world.js +17035 -521
- package/gpl/fixtures/make_world_fixture.py +184 -0
- package/gpl/recipes/_common.py +11 -0
- package/gpl/recipes/decimate.py +11 -5
- package/gpl/recipes/export_world.py +699 -0
- package/mcp/blender-server.mjs +61 -4
- package/mcp/blender.mjs +3 -4
- package/mcp/engine-server.mjs +55 -21
- package/mcp/servers.mjs +4 -4
- package/package.json +15 -9
- package/patches/three@0.185.1-prd269-upgrade.patch +22418 -0
- package/patches/three@0.185.1.patch +8246 -389
- package/scripts/apply-three-patch.mjs +123 -41
- package/src/animation-blend.ts +264 -0
- package/src/animation-composition.ts +362 -0
- package/src/animation-layers.ts +260 -0
- package/src/animation-root-motion.ts +283 -0
- package/src/animation.ts +896 -0
- package/src/assets.ts +1303 -0
- package/src/atmosphere/index.ts +335 -0
- package/src/atmosphere/luts.ts +298 -0
- package/src/atmosphere/params.ts +323 -0
- package/src/audio.ts +912 -0
- package/src/billboard.ts +124 -0
- package/src/bone-lengths.ts +157 -0
- package/src/camera-shake.ts +116 -0
- package/src/canvas-layer.ts +47 -0
- package/src/clip-audit.ts +401 -0
- package/src/clustered-batch.ts +492 -0
- package/src/clustered-mesh.ts +638 -0
- package/src/compute-driven.ts +176 -0
- package/src/compute-timing.ts +318 -0
- package/src/config.ts +593 -0
- package/src/debug.ts +82 -0
- package/src/engine-render-hook.ts +25 -0
- package/src/entities.ts +79 -0
- package/src/entity-snapshot.ts +53 -0
- package/src/flight.ts +683 -0
- package/src/fluid-field.ts +748 -0
- package/src/fluid-particles.ts +1253 -0
- package/src/frame-budget.ts +1368 -0
- package/src/game.ts +2390 -0
- package/src/geometry-capture.ts +1098 -0
- package/src/gpu-class.ts +160 -0
- package/src/gpu-frame-observation.ts +424 -0
- package/src/gpu-readback.ts +143 -0
- package/src/gpu-scene-bvh.ts +464 -0
- package/src/grounding.ts +100 -0
- package/src/hot.ts +161 -0
- package/src/import-meta.d.ts +13 -0
- package/src/index.ts +1536 -0
- package/src/input.ts +690 -0
- package/src/instanced-batch-lod.ts +283 -0
- package/src/instanced-batch.ts +274 -0
- package/src/interpolation.ts +129 -0
- package/src/launch-diagnostics.ts +161 -0
- package/src/loop.ts +564 -0
- package/src/matrix-world.ts +245 -0
- package/src/merge-parts.ts +812 -0
- package/src/model-lod.ts +1315 -0
- package/src/net-protocol.ts +333 -0
- package/src/net-session.ts +477 -0
- package/src/net.ts +80 -0
- package/src/ocean/fft.ts +72 -0
- package/src/ocean/spectral.ts +728 -0
- package/src/particle-significance.ts +102 -0
- package/src/particles.ts +648 -0
- package/src/path-follow.ts +175 -0
- package/src/picking.ts +250 -0
- package/src/pipeline-census.ts +1566 -0
- package/src/platform.ts +210 -0
- package/src/playtest.ts +839 -0
- package/src/pointer-events.ts +411 -0
- package/src/pose-measure.ts +435 -0
- package/src/profiling/FrameCounters.ts +231 -0
- package/src/profiling/Spans.ts +548 -0
- package/src/profiling/opacity-convention.ts +21 -0
- package/src/profiling/render-list-validate.ts +175 -0
- package/src/profiling/render-trap-audit.ts +84 -0
- package/src/profiling/scene-warning.ts +190 -0
- package/src/profiling/span-probes.ts +191 -0
- package/src/profiling/unlit-foliage-warning.ts +149 -0
- package/src/projection-apply.ts +1529 -0
- package/src/projection-marker.ts +142 -0
- package/src/projection-plan.ts +1258 -0
- package/src/projection-skinned.ts +419 -0
- package/src/projection-stability.ts +409 -0
- package/src/projection-uniform.ts +328 -0
- package/src/random.ts +41 -0
- package/src/react-css.ts +604 -0
- package/src/react-glyphs.ts +114 -0
- package/src/react-host.ts +576 -0
- package/src/react-layout.ts +265 -0
- package/src/react.ts +60 -0
- package/src/render/alpha-antialiasing.ts +159 -0
- package/src/render/batched-velocity.ts +126 -0
- package/src/render/chain.ts +1021 -0
- package/src/render/daylight.ts +189 -0
- package/src/render/depth-pyramid.ts +596 -0
- package/src/render/foliage-alpha.ts +166 -0
- package/src/render/material-key.ts +60 -0
- package/src/render/mesh-pool.ts +144 -0
- package/src/render/probe-volume.ts +1668 -0
- package/src/render/resolution-subrect.ts +253 -0
- package/src/render/velocity.ts +442 -0
- package/src/render/virtual-shadow-pages.ts +827 -0
- package/src/render/virtual-shadow-partial.ts +174 -0
- package/src/render/virtual-shadow.ts +3330 -0
- package/src/render/world-impostor-surface.ts +722 -0
- package/src/render/world-impostor.ts +558 -0
- package/src/render-camera-cull.ts +441 -0
- package/src/render-pass-budget.ts +501 -0
- package/src/renderProjection.ts +758 -0
- package/src/renderer-config.ts +127 -0
- package/src/renderer.ts +1847 -0
- package/src/replay-protocol.ts +85 -0
- package/src/replay.ts +205 -0
- package/src/resolution-scaler.ts +819 -0
- package/src/rig-preparation.ts +271 -0
- package/src/ripple-field.ts +432 -0
- package/src/scale.ts +109 -0
- package/src/scene.ts +239 -0
- package/src/schedule.ts +155 -0
- package/src/skeletal-mesh.ts +61 -0
- package/src/skeleton.ts +100 -0
- package/src/snow-field.ts +744 -0
- package/src/softbody-topology.ts +269 -0
- package/src/softbody.ts +516 -0
- package/src/sprite-animator.ts +222 -0
- package/src/startup-readiness.ts +386 -0
- package/src/state.ts +66 -0
- package/src/static-transform.ts +274 -0
- package/src/storage-buffer.ts +253 -0
- package/src/streaming.ts +308 -0
- package/src/target-fps.ts +92 -0
- package/src/terrain-jobs-worker.ts +17 -0
- package/src/terrain-jobs.ts +353 -0
- package/src/textures.ts +39 -0
- package/src/tracers.ts +237 -0
- package/src/ui-bridge.ts +368 -0
- package/src/ui-hit-regions.ts +380 -0
- package/src/ui-layer.ts +83 -0
- package/src/ui-state.ts +220 -0
- package/src/version.ts +2 -0
- package/src/viewport.ts +253 -0
- package/src/warmup.ts +1357 -0
- package/src/water-surface.ts +384 -0
- package/src/wave-field.ts +524 -0
- package/src/world-capabilities.ts +131 -0
- package/src/world-cell-proxy.ts +392 -0
- package/src/world-cells.ts +10564 -0
- package/src/world-gpu-scene.ts +3354 -0
- package/src/world-heightmap.ts +82 -0
- package/src/world-package.ts +469 -0
- package/src/world-passes.ts +582 -0
- package/src/world-region.ts +17 -0
- package/src/world-terrain-splat.ts +564 -0
- package/src/world-tiles.ts +3826 -0
- package/src/world-topology.ts +370 -0
- package/src/world-validate.ts +48 -0
- package/src/world.ts +805 -0
- package/dist/gpu-readback-CMklJs6r.d.ts +0 -112
package/src/input.ts
ADDED
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
import { Vector2 } from "three";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One action, read either as a button through `pressed`/`justPressed`, a 2D axis through
|
|
5
|
+
* `vector`, or a scalar axis through `axis`. Which one you get depends on the fields you fill in,
|
|
6
|
+
* and mixing the two is what makes bindings confusing to read:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* jump: { keys: ["Space"], buttons: [0] } // a button: key or *gamepad* button 0
|
|
10
|
+
* fire: { keys: ["Space"], mouseButtons: [0] } // a button: key or *left mouse*
|
|
11
|
+
* move: { up: ["KeyW"], down: ["KeyS"], left: [...], right: [...] } // an axis
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* **`buttons` is the gamepad, `mouseButtons` is the mouse.** They are separate devices and
|
|
15
|
+
* `buttons: [0]` on a machine with no gamepad plugged in silently never fires.
|
|
16
|
+
*
|
|
17
|
+
* `up`/`down`/`left`/`right` are **directions of an axis**, not "the keys that press this".
|
|
18
|
+
* They are named after the vector they build, so `pressed("move")` is true whenever any
|
|
19
|
+
* direction is held — including `ArrowDown`. For a button, use `keys`.
|
|
20
|
+
*/
|
|
21
|
+
export interface IInputAction {
|
|
22
|
+
/** **Gamepad** button indices that press this action. For the mouse, see `mouseButtons`. */
|
|
23
|
+
readonly buttons?: readonly number[];
|
|
24
|
+
/** **Gamepad** axis indices whose values contribute to `axis(name)`. */
|
|
25
|
+
readonly gamepadAxes?: readonly number[];
|
|
26
|
+
/**
|
|
27
|
+
* **Mouse** button indices that press this action, numbered as `MouseEvent.button`:
|
|
28
|
+
* `0` left, `1` middle, `2` right. Binding `2` also suppresses the browser context menu on
|
|
29
|
+
* the pointer target, because a right-click binding is unusable while the menu eats it.
|
|
30
|
+
*/
|
|
31
|
+
readonly mouseButtons?: readonly number[];
|
|
32
|
+
/**
|
|
33
|
+
* Keyboard codes that press this action. Use this for a button — `jump`, `restart`, `fire`.
|
|
34
|
+
* A key listed here never contributes to `vector`.
|
|
35
|
+
*/
|
|
36
|
+
readonly keys?: readonly string[];
|
|
37
|
+
/** The **−y** direction of `vector(name)`. Not "the keys that press this action" — see `keys`. */
|
|
38
|
+
readonly down?: readonly string[];
|
|
39
|
+
/** The −x direction of `vector(name)`. */
|
|
40
|
+
readonly left?: readonly string[];
|
|
41
|
+
/** Any active pointer or touch presses this action. */
|
|
42
|
+
readonly pointer?: boolean;
|
|
43
|
+
/** Add normalized browser/native wheel motion to `axis(name)`; negative DOM deltaY (toward-user) is positive. */
|
|
44
|
+
readonly scroll?: boolean;
|
|
45
|
+
/** Add the signed two-pointer distance change to `axis(name)`; moving apart is positive. */
|
|
46
|
+
readonly pinch?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Add raw mouse movement since the last input tick to `vector(name)`. A click on the pointer
|
|
49
|
+
* target automatically asks for pointer capture when this binding is present; call
|
|
50
|
+
* `captureMouse()` explicitly when a game needs to start capture from another named gesture.
|
|
51
|
+
*/
|
|
52
|
+
readonly pointerRelative?: boolean;
|
|
53
|
+
/** Disable the automatic click capture for a relative binding that has its own gesture. */
|
|
54
|
+
readonly captureOnClick?: boolean;
|
|
55
|
+
/** The +x direction of `vector(name)`. */
|
|
56
|
+
readonly right?: readonly string[];
|
|
57
|
+
/** The +y direction of `vector(name)`. */
|
|
58
|
+
readonly up?: readonly string[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type InputBindings = Record<string, IInputAction>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* What the browser context menu does over the game surface. `"suppress"` is the default: a
|
|
65
|
+
* right-click binding cannot work while the menu opens on the same press, and a context menu
|
|
66
|
+
* over a game canvas is almost never what anyone wants. `"allow"` restores the browser default.
|
|
67
|
+
*/
|
|
68
|
+
export type ContextMenuPolicy = "allow" | "suppress";
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* `MouseEvent.button` (0 left, 1 middle, 2 right) to the `PointerEvent.buttons` bit that is set
|
|
72
|
+
* while it is held (1 left, 4 middle, 2 right). The two numbering schemes disagree for the
|
|
73
|
+
* middle and right buttons, which is why this is a table rather than a shift.
|
|
74
|
+
*/
|
|
75
|
+
const MOUSE_BUTTON_BITS: readonly number[] = [1, 4, 2, 8, 16];
|
|
76
|
+
|
|
77
|
+
function mouseButtonMask(button: number): number {
|
|
78
|
+
return MOUSE_BUTTON_BITS[button] ?? 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface IInputGamepad {
|
|
82
|
+
readonly axes: ArrayLike<number>;
|
|
83
|
+
readonly buttons: readonly { readonly pressed: boolean }[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type InputPlatformSource = () => readonly (IInputGamepad | null)[];
|
|
87
|
+
|
|
88
|
+
export interface IRawInputPointer {
|
|
89
|
+
readonly id: number;
|
|
90
|
+
buttons: number;
|
|
91
|
+
readonly position: Vector2;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface IRawInputPointerEdge {
|
|
95
|
+
readonly buttons: number;
|
|
96
|
+
readonly id: number;
|
|
97
|
+
readonly position: Vector2;
|
|
98
|
+
readonly type: "cancel" | "down" | "up";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface IRawInputState {
|
|
102
|
+
readonly keys: ReadonlySet<string>;
|
|
103
|
+
readonly pointer: {
|
|
104
|
+
buttons: number;
|
|
105
|
+
captured: boolean;
|
|
106
|
+
down: boolean;
|
|
107
|
+
readonly position: Vector2;
|
|
108
|
+
/** Accumulated relative mouse motion since the last `tick`, in canvas pixels. */
|
|
109
|
+
readonly relative: Vector2;
|
|
110
|
+
};
|
|
111
|
+
/** Pointer transitions captured since the previous input tick, grouped by pointer id. */
|
|
112
|
+
readonly pointerEdges: ReadonlyMap<number, readonly IRawInputPointerEdge[]>;
|
|
113
|
+
readonly pointers: ReadonlyMap<number, IRawInputPointer>;
|
|
114
|
+
readonly gamepad: {
|
|
115
|
+
axes: readonly number[];
|
|
116
|
+
buttons: readonly boolean[];
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const DEFAULT_BINDINGS: InputBindings = {
|
|
121
|
+
move: {
|
|
122
|
+
down: ["KeyS", "ArrowDown"],
|
|
123
|
+
left: ["KeyA", "ArrowLeft"],
|
|
124
|
+
right: ["KeyD", "ArrowRight"],
|
|
125
|
+
up: ["KeyW", "ArrowUp"],
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const WHEEL_LINE_PIXELS = 16;
|
|
130
|
+
const WHEEL_PAGE_PIXELS = 800;
|
|
131
|
+
const WHEEL_PIXELS_PER_AXIS = 100;
|
|
132
|
+
const PINCH_DEAD_ZONE = 0.01;
|
|
133
|
+
|
|
134
|
+
function eventCode(event: Event): string | undefined {
|
|
135
|
+
const candidate = event as Event & { code?: string; key?: string };
|
|
136
|
+
return candidate.code ?? candidate.key;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
type PointerLockTarget = EventTarget & {
|
|
140
|
+
exitPointerLock?: () => void | Promise<void>;
|
|
141
|
+
requestPointerLock?: () => void | Promise<void>;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
type PointerLockDocument = EventTarget & {
|
|
145
|
+
exitPointerLock?: () => void | Promise<void>;
|
|
146
|
+
pointerLockElement?: unknown;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
function pointerLockDocument(): PointerLockDocument | undefined {
|
|
150
|
+
const candidate = (globalThis as typeof globalThis & { document?: unknown }).document;
|
|
151
|
+
if (candidate === null || typeof candidate !== "object") return undefined;
|
|
152
|
+
if (typeof (candidate as { addEventListener?: unknown }).addEventListener !== "function") {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
return candidate as PointerLockDocument;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const browserGamepads: InputPlatformSource = () =>
|
|
159
|
+
(globalThis.navigator as Navigator | undefined)?.getGamepads?.() ?? [];
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Ask the browser to lock the pointer to `target`, the capture every first-person mouse look needs.
|
|
163
|
+
*
|
|
164
|
+
* Returns the platform's own promise when it has one, so the caller can wait for the lock the way
|
|
165
|
+
* the browser reports it, and `undefined` when the platform answered synchronously. A target that
|
|
166
|
+
* cannot capture at all throws rather than leaving a game with a camera that never turns.
|
|
167
|
+
*/
|
|
168
|
+
export function captureMouse(target: EventTarget): Promise<void> | undefined {
|
|
169
|
+
const lockTarget = target as PointerLockTarget;
|
|
170
|
+
if (typeof lockTarget.requestPointerLock !== "function") {
|
|
171
|
+
throw new Error("Pointer capture is unavailable on the input target.");
|
|
172
|
+
}
|
|
173
|
+
const result = lockTarget.requestPointerLock();
|
|
174
|
+
return result === undefined ? undefined : Promise.resolve(result);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export class InputMap {
|
|
178
|
+
readonly raw: IRawInputState;
|
|
179
|
+
#bindings: InputBindings;
|
|
180
|
+
#bindingNames: string[] = [];
|
|
181
|
+
#vectors = new Map<string, Vector2>();
|
|
182
|
+
#target: EventTarget;
|
|
183
|
+
#heldKeys = new Set<string>();
|
|
184
|
+
#pointerPosition = new Vector2();
|
|
185
|
+
#pointerRelative = new Vector2();
|
|
186
|
+
#relativeSample = new Vector2();
|
|
187
|
+
#scrollDelta = 0;
|
|
188
|
+
#scrollSample = 0;
|
|
189
|
+
#pointerButtons = 0;
|
|
190
|
+
#pointers = new Map<number, IRawInputPointer>();
|
|
191
|
+
#pointerEdges = new Map<number, readonly IRawInputPointerEdge[]>();
|
|
192
|
+
#pendingPointerEdges = new Map<number, IRawInputPointerEdge[]>();
|
|
193
|
+
#pinchPair: readonly [number, number] | undefined;
|
|
194
|
+
#pinchDistance = 0;
|
|
195
|
+
#pinchSample = 0;
|
|
196
|
+
#gamepadAxes: number[] = [];
|
|
197
|
+
#gamepadButtons: boolean[] = [];
|
|
198
|
+
#previousPressed = new Map<string, boolean>();
|
|
199
|
+
#justPressed = new Set<string>();
|
|
200
|
+
#justReleased = new Set<string>();
|
|
201
|
+
/**
|
|
202
|
+
* Presses seen since the last `tick`, kept even if the input was already released.
|
|
203
|
+
*
|
|
204
|
+
* Device state alone is sampled once a frame, so a press that starts and ends between two
|
|
205
|
+
* ticks is simply not there when the frame looks — and a mouse click is normally shorter than
|
|
206
|
+
* a frame at 60Hz. Without this latch a quick click does nothing at all, intermittently,
|
|
207
|
+
* which reads as a broken game rather than a dropped edge.
|
|
208
|
+
*/
|
|
209
|
+
#latchedKeys = new Set<string>();
|
|
210
|
+
#latchedPointerButtons = 0;
|
|
211
|
+
#latchedPointer = false;
|
|
212
|
+
#pointerTarget: EventTarget;
|
|
213
|
+
#source: InputPlatformSource;
|
|
214
|
+
#tracksPinch = false;
|
|
215
|
+
#listeners: Array<[EventTarget, string, EventListener]> = [];
|
|
216
|
+
|
|
217
|
+
constructor(
|
|
218
|
+
bindings: InputBindings = DEFAULT_BINDINGS,
|
|
219
|
+
target: EventTarget = globalThis,
|
|
220
|
+
pointerTarget: EventTarget = target,
|
|
221
|
+
source: InputPlatformSource = browserGamepads,
|
|
222
|
+
contextMenu: ContextMenuPolicy = "suppress",
|
|
223
|
+
) {
|
|
224
|
+
this.#bindings = { ...DEFAULT_BINDINGS, ...bindings };
|
|
225
|
+
// Bindings are fixed at construction; freezing the key list keeps tick() from calling
|
|
226
|
+
// Object.keys every step.
|
|
227
|
+
this.#bindingNames = Object.keys(this.#bindings);
|
|
228
|
+
this.#target = target;
|
|
229
|
+
this.#pointerTarget = pointerTarget;
|
|
230
|
+
this.#source = source;
|
|
231
|
+
this.#tracksPinch = this.#bindingNames.some((name) => this.#bindings[name]?.pinch === true);
|
|
232
|
+
this.raw = {
|
|
233
|
+
gamepad: { axes: this.#gamepadAxes, buttons: this.#gamepadButtons },
|
|
234
|
+
keys: this.#heldKeys,
|
|
235
|
+
pointer: {
|
|
236
|
+
buttons: this.#pointerButtons,
|
|
237
|
+
captured: false,
|
|
238
|
+
down: false,
|
|
239
|
+
position: this.#pointerPosition,
|
|
240
|
+
relative: this.#pointerRelative,
|
|
241
|
+
},
|
|
242
|
+
pointerEdges: this.#pointerEdges,
|
|
243
|
+
pointers: this.#pointers,
|
|
244
|
+
};
|
|
245
|
+
this.#listen(this.#target, "keydown", (event) => {
|
|
246
|
+
const code = eventCode(event);
|
|
247
|
+
if (code !== undefined) {
|
|
248
|
+
this.#heldKeys.add(code);
|
|
249
|
+
this.#latchedKeys.add(code);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
this.#listen(this.#target, "keyup", (event) => {
|
|
253
|
+
const code = eventCode(event);
|
|
254
|
+
if (code !== undefined) this.#heldKeys.delete(code);
|
|
255
|
+
});
|
|
256
|
+
this.#listen(this.#target, "mousemove", (event) => this.#mouseEvent(event));
|
|
257
|
+
if (
|
|
258
|
+
this.#bindingNames.some(
|
|
259
|
+
(name) =>
|
|
260
|
+
this.#bindings[name]?.pointerRelative === true &&
|
|
261
|
+
this.#bindings[name]?.captureOnClick !== false,
|
|
262
|
+
)
|
|
263
|
+
) {
|
|
264
|
+
this.#listen(this.#pointerTarget, "click", (event) => {
|
|
265
|
+
// Touch and pen gestures must not enter desktop relative-mouse mode.
|
|
266
|
+
const pointerType = (event as PointerEvent).pointerType;
|
|
267
|
+
if (pointerType && pointerType !== "mouse") return;
|
|
268
|
+
this.#captureFromClick();
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
this.#listen(this.#pointerTarget, "pointerdown", (event) => this.#pointerEvent(event, "down"));
|
|
272
|
+
if (this.#bindingNames.some((name) => this.#bindings[name]?.scroll === true))
|
|
273
|
+
this.#listen(this.#target, "wheel", (event) => this.#wheelEvent(event));
|
|
274
|
+
this.#listen(this.#pointerTarget, "pointermove", (event) => this.#pointerEvent(event));
|
|
275
|
+
this.#listen(this.#pointerTarget, "pointerup", (event) => this.#pointerEvent(event, "up"));
|
|
276
|
+
this.#listen(this.#pointerTarget, "pointercancel", (event) =>
|
|
277
|
+
this.#pointerEvent(event, "cancel"),
|
|
278
|
+
);
|
|
279
|
+
this.#listen(this.#target, "blur", () => this.clear());
|
|
280
|
+
// The browser context menu is suppressed on the game surface by default. A right-click
|
|
281
|
+
// binding is simply unusable while the menu eats the press, and no game yet built here has
|
|
282
|
+
// wanted the menu over its own canvas. `contextMenu: "allow"` restores the browser default
|
|
283
|
+
// for the rare case that does.
|
|
284
|
+
if (contextMenu !== "allow") {
|
|
285
|
+
this.#listen(this.#pointerTarget, "contextmenu", (event) => event.preventDefault());
|
|
286
|
+
}
|
|
287
|
+
const lockDocument = pointerLockDocument();
|
|
288
|
+
const lockTargets = new Set<EventTarget>([this.#target, this.#pointerTarget]);
|
|
289
|
+
if (lockDocument !== undefined) lockTargets.add(lockDocument);
|
|
290
|
+
for (const target of lockTargets) {
|
|
291
|
+
this.#listen(target, "pointerlockchange", () => this.#syncCaptured());
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Returns a 2D action vector where +y is up. On a conventional XZ ground plane whose
|
|
297
|
+
* forward direction is -z, map `vector.y` to `-z`. This differs from Godot's
|
|
298
|
+
* `Input.get_vector`, where up is -y.
|
|
299
|
+
*/
|
|
300
|
+
vector(name: string): Vector2 {
|
|
301
|
+
let vector = this.#vectors.get(name);
|
|
302
|
+
if (vector === undefined) {
|
|
303
|
+
vector = new Vector2();
|
|
304
|
+
this.#vectors.set(name, vector);
|
|
305
|
+
}
|
|
306
|
+
const binding = this.#bindings[name];
|
|
307
|
+
if (binding === undefined) return vector.set(0, 0);
|
|
308
|
+
vector.set(this.#isHeld(binding.left) ? -1 : 0, this.#isHeld(binding.down) ? -1 : 0);
|
|
309
|
+
if (this.#isHeld(binding.right)) vector.x += 1;
|
|
310
|
+
if (this.#isHeld(binding.up)) vector.y += 1;
|
|
311
|
+
if (name === "move" && this.#gamepadAxes.length >= 2) {
|
|
312
|
+
vector.x += this.#gamepadAxes[0] ?? 0;
|
|
313
|
+
vector.y += -(this.#gamepadAxes[1] ?? 0);
|
|
314
|
+
}
|
|
315
|
+
if (binding.pointerRelative === true) vector.add(this.#relativeSample);
|
|
316
|
+
return binding.pointerRelative === true ? vector : vector.clampLength(0, 1);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Returns a scalar action for this fixed-step tick, clamped to `[-1, 1]`.
|
|
321
|
+
*
|
|
322
|
+
* `scroll: true` normalizes wheel deltas to pixels before scaling them: one line is 16 pixels,
|
|
323
|
+
* one page is 800 pixels, and 100 pixels is one axis unit. Browser and native wheel events use
|
|
324
|
+
* the same DOM sign convention, so scrolling the wheel toward the user (negative DOM `deltaY`) is
|
|
325
|
+
* positive and scrolling away (positive DOM `deltaY`) is negative. `pinch: true` reports the relative distance change of the first two active pointers;
|
|
326
|
+
* a third pointer is ignored and a changing pair starts a new gesture without a jump.
|
|
327
|
+
*/
|
|
328
|
+
axis(name: string): number {
|
|
329
|
+
const binding = this.#bindings[name];
|
|
330
|
+
if (binding === undefined) return 0;
|
|
331
|
+
let value = 0;
|
|
332
|
+
if (binding.scroll === true) value += this.#scrollSample;
|
|
333
|
+
if (binding.pinch === true) value += this.#pinchSample;
|
|
334
|
+
const axes = binding.gamepadAxes;
|
|
335
|
+
if (axes !== undefined) {
|
|
336
|
+
for (let index = 0; index < axes.length; index += 1) {
|
|
337
|
+
const axisIndex = axes[index] as number;
|
|
338
|
+
const axis = this.#gamepadAxes[axisIndex];
|
|
339
|
+
if (axis !== undefined && Number.isFinite(axis)) value += axis;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return Math.max(-1, Math.min(1, value));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** Request pointer capture explicitly from a named game gesture. Relative bindings request it on canvas click by default. */
|
|
346
|
+
captureMouse(): void {
|
|
347
|
+
if (this.raw.pointer.captured) return;
|
|
348
|
+
const result = captureMouse(this.#pointerTarget);
|
|
349
|
+
if (result === undefined) {
|
|
350
|
+
this.#syncCaptured(true);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
void result.then(
|
|
354
|
+
() => this.#syncCaptured(true),
|
|
355
|
+
(error: unknown) => {
|
|
356
|
+
this.raw.pointer.captured = false;
|
|
357
|
+
throw error;
|
|
358
|
+
},
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** Release pointer capture. A browser refusal remains an unhandled rejection. */
|
|
363
|
+
releaseMouse(): void {
|
|
364
|
+
const document = pointerLockDocument();
|
|
365
|
+
const target = (document ?? this.#pointerTarget) as PointerLockTarget;
|
|
366
|
+
const exit = target.exitPointerLock;
|
|
367
|
+
if (typeof exit !== "function") {
|
|
368
|
+
throw new Error("Pointer capture release is unavailable on the input target.");
|
|
369
|
+
}
|
|
370
|
+
const result = exit.call(target);
|
|
371
|
+
if (result === undefined) {
|
|
372
|
+
this.#syncCaptured(false);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
void result.then(
|
|
376
|
+
() => this.#syncCaptured(false),
|
|
377
|
+
(error: unknown) => {
|
|
378
|
+
throw error;
|
|
379
|
+
},
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
pressed(name: string): boolean {
|
|
384
|
+
const binding = this.#bindings[name];
|
|
385
|
+
if (binding === undefined) return false;
|
|
386
|
+
if (
|
|
387
|
+
this.#isHeld(binding.keys) ||
|
|
388
|
+
this.#isHeld(binding.down) ||
|
|
389
|
+
this.#isHeld(binding.left) ||
|
|
390
|
+
this.#isHeld(binding.right) ||
|
|
391
|
+
this.#isHeld(binding.up) ||
|
|
392
|
+
(binding.pointer === true && this.#pointers.size > 0)
|
|
393
|
+
)
|
|
394
|
+
return true;
|
|
395
|
+
const mouseButtons = binding.mouseButtons;
|
|
396
|
+
if (mouseButtons !== undefined) {
|
|
397
|
+
for (let index = 0; index < mouseButtons.length; index += 1) {
|
|
398
|
+
if ((this.#pointerButtons & mouseButtonMask(mouseButtons[index] as number)) !== 0)
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
const gamepadButtons = binding.buttons;
|
|
403
|
+
if (gamepadButtons !== undefined) {
|
|
404
|
+
for (let index = 0; index < gamepadButtons.length; index += 1) {
|
|
405
|
+
if (this.#gamepadButtons[gamepadButtons[index] as number] === true) return true;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
justPressed(name: string): boolean {
|
|
412
|
+
return this.#justPressed.has(name);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
justReleased(name: string): boolean {
|
|
416
|
+
return this.#justReleased.has(name);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
tick(): void {
|
|
420
|
+
this.#publishPointerEdges();
|
|
421
|
+
this.#relativeSample.copy(this.#pointerRelative);
|
|
422
|
+
this.#pointerRelative.set(0, 0);
|
|
423
|
+
this.#scrollSample = this.#clampAxis(this.#scrollDelta);
|
|
424
|
+
this.#scrollDelta = 0;
|
|
425
|
+
this.#samplePinch();
|
|
426
|
+
const sources = this.#source();
|
|
427
|
+
let gamepad: IInputGamepad | undefined;
|
|
428
|
+
for (let index = 0; index < sources.length; index += 1) {
|
|
429
|
+
const candidate = sources[index];
|
|
430
|
+
if (candidate !== null) {
|
|
431
|
+
gamepad = candidate;
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
// Reused buffers: fresh arrays here were four allocations per update step, device or not.
|
|
436
|
+
this.#gamepadAxes.length = 0;
|
|
437
|
+
this.#gamepadButtons.length = 0;
|
|
438
|
+
if (gamepad?.axes) {
|
|
439
|
+
const axes = gamepad.axes;
|
|
440
|
+
for (let axis = 0; axis < axes.length; axis += 1)
|
|
441
|
+
this.#gamepadAxes.push(axes[axis] as number);
|
|
442
|
+
}
|
|
443
|
+
if (gamepad?.buttons) {
|
|
444
|
+
for (let index = 0; index < gamepad.buttons.length; index += 1)
|
|
445
|
+
this.#gamepadButtons.push(gamepad.buttons[index]?.pressed ?? false);
|
|
446
|
+
}
|
|
447
|
+
this.raw.gamepad.axes = this.#gamepadAxes;
|
|
448
|
+
this.raw.gamepad.buttons = this.#gamepadButtons;
|
|
449
|
+
this.#justPressed.clear();
|
|
450
|
+
this.#justReleased.clear();
|
|
451
|
+
for (let index = 0; index < this.#bindingNames.length; index += 1) {
|
|
452
|
+
const name = this.#bindingNames[index] as string;
|
|
453
|
+
// A press that came and went inside this frame still counts as a press. `pressed()` stays
|
|
454
|
+
// instantaneous — it answers "is it down right now" — while the edge is latched, so a tap
|
|
455
|
+
// reports justPressed on this frame and justReleased on the next one.
|
|
456
|
+
const current = this.pressed(name) || this.#latchedPressed(name);
|
|
457
|
+
const previous = this.#previousPressed.get(name) ?? false;
|
|
458
|
+
if (current && !previous) this.#justPressed.add(name);
|
|
459
|
+
if (!current && previous) this.#justReleased.add(name);
|
|
460
|
+
this.#previousPressed.set(name, current);
|
|
461
|
+
}
|
|
462
|
+
this.#latchedKeys.clear();
|
|
463
|
+
this.#latchedPointerButtons = 0;
|
|
464
|
+
this.#latchedPointer = false;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
clear(): void {
|
|
468
|
+
this.#heldKeys.clear();
|
|
469
|
+
this.#latchedKeys.clear();
|
|
470
|
+
this.#latchedPointerButtons = 0;
|
|
471
|
+
this.#latchedPointer = false;
|
|
472
|
+
this.#pointerEdges.clear();
|
|
473
|
+
this.#pendingPointerEdges.clear();
|
|
474
|
+
this.#pointers.clear();
|
|
475
|
+
this.#pointerButtons = 0;
|
|
476
|
+
this.#pointerPosition.set(0, 0);
|
|
477
|
+
this.#pointerRelative.set(0, 0);
|
|
478
|
+
this.#relativeSample.set(0, 0);
|
|
479
|
+
this.#scrollDelta = 0;
|
|
480
|
+
this.#scrollSample = 0;
|
|
481
|
+
this.raw.pointer.buttons = 0;
|
|
482
|
+
this.raw.pointer.down = false;
|
|
483
|
+
this.#pinchPair = undefined;
|
|
484
|
+
this.#pinchDistance = 0;
|
|
485
|
+
this.#pinchSample = 0;
|
|
486
|
+
this.#previousPressed.clear();
|
|
487
|
+
this.#justPressed.clear();
|
|
488
|
+
this.#justReleased.clear();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
dispose(): void {
|
|
492
|
+
if (this.raw.pointer.captured) {
|
|
493
|
+
try {
|
|
494
|
+
this.releaseMouse();
|
|
495
|
+
} catch {
|
|
496
|
+
this.raw.pointer.captured = false;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
for (const [target, type, listener] of this.#listeners)
|
|
500
|
+
target.removeEventListener(type, listener);
|
|
501
|
+
this.#listeners = [];
|
|
502
|
+
this.clear();
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** Was this action pressed at any point since the last tick, even if already released? */
|
|
506
|
+
#latchedPressed(name: string): boolean {
|
|
507
|
+
const binding = this.#bindings[name];
|
|
508
|
+
if (binding === undefined) return false;
|
|
509
|
+
if (
|
|
510
|
+
this.#isLatched(binding.keys) ||
|
|
511
|
+
this.#isLatched(binding.down) ||
|
|
512
|
+
this.#isLatched(binding.left) ||
|
|
513
|
+
this.#isLatched(binding.right) ||
|
|
514
|
+
this.#isLatched(binding.up) ||
|
|
515
|
+
(binding.pointer === true && this.#latchedPointer)
|
|
516
|
+
)
|
|
517
|
+
return true;
|
|
518
|
+
const mouseButtons = binding.mouseButtons;
|
|
519
|
+
if (mouseButtons !== undefined) {
|
|
520
|
+
for (let index = 0; index < mouseButtons.length; index += 1) {
|
|
521
|
+
if ((this.#latchedPointerButtons & mouseButtonMask(mouseButtons[index] as number)) !== 0)
|
|
522
|
+
return true;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
#isHeld(codes: readonly string[] | undefined): boolean {
|
|
529
|
+
if (codes === undefined) return false;
|
|
530
|
+
for (let index = 0; index < codes.length; index += 1) {
|
|
531
|
+
if (this.#heldKeys.has(codes[index] as string)) return true;
|
|
532
|
+
}
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
#isLatched(codes: readonly string[] | undefined): boolean {
|
|
537
|
+
if (codes === undefined) return false;
|
|
538
|
+
for (let index = 0; index < codes.length; index += 1) {
|
|
539
|
+
if (this.#latchedKeys.has(codes[index] as string)) return true;
|
|
540
|
+
}
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
#listen(target: EventTarget, type: string, listener: EventListener): void {
|
|
545
|
+
target.addEventListener(type, listener);
|
|
546
|
+
this.#listeners.push([target, type, listener]);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
#publishPointerEdges(): void {
|
|
550
|
+
this.#pointerEdges.clear();
|
|
551
|
+
for (const [id, edges] of this.#pendingPointerEdges) this.#pointerEdges.set(id, edges);
|
|
552
|
+
this.#pendingPointerEdges.clear();
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
#mouseEvent(event: Event): void {
|
|
556
|
+
const mouse = event as MouseEvent;
|
|
557
|
+
if (Number.isFinite(mouse.movementX)) this.#pointerRelative.x += mouse.movementX;
|
|
558
|
+
if (Number.isFinite(mouse.movementY)) this.#pointerRelative.y += mouse.movementY;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
#wheelEvent(event: Event): void {
|
|
562
|
+
const wheel = event as Event & { deltaMode?: number; deltaY?: number };
|
|
563
|
+
const deltaY = wheel.deltaY;
|
|
564
|
+
if (deltaY === undefined || !Number.isFinite(deltaY)) return;
|
|
565
|
+
const deltaMode = wheel.deltaMode;
|
|
566
|
+
const pixelsPerDelta =
|
|
567
|
+
deltaMode === 1 ? WHEEL_LINE_PIXELS : deltaMode === 2 ? WHEEL_PAGE_PIXELS : 1;
|
|
568
|
+
this.#scrollDelta += (-deltaY * pixelsPerDelta) / WHEEL_PIXELS_PER_AXIS;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
#samplePinch(): void {
|
|
572
|
+
if (!this.#tracksPinch) return;
|
|
573
|
+
const pointers = this.#pointers.values();
|
|
574
|
+
const first = pointers.next().value as IRawInputPointer | undefined;
|
|
575
|
+
const second = pointers.next().value as IRawInputPointer | undefined;
|
|
576
|
+
if (first === undefined || second === undefined) {
|
|
577
|
+
this.#pinchPair = undefined;
|
|
578
|
+
this.#pinchDistance = 0;
|
|
579
|
+
this.#pinchSample = 0;
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
const distance = first.position.distanceTo(second.position);
|
|
584
|
+
const pair = this.#pinchPair;
|
|
585
|
+
if (
|
|
586
|
+
pair === undefined ||
|
|
587
|
+
pair[0] !== first.id ||
|
|
588
|
+
pair[1] !== second.id ||
|
|
589
|
+
!Number.isFinite(distance)
|
|
590
|
+
) {
|
|
591
|
+
this.#pinchPair = [first.id, second.id];
|
|
592
|
+
this.#pinchDistance = distance;
|
|
593
|
+
this.#pinchSample = 0;
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
const previousDistance = this.#pinchDistance;
|
|
598
|
+
this.#pinchDistance = distance;
|
|
599
|
+
if (previousDistance <= 0 || !Number.isFinite(previousDistance)) {
|
|
600
|
+
this.#pinchSample = 0;
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
const delta = distance / previousDistance - 1;
|
|
604
|
+
this.#pinchSample = Math.abs(delta) <= PINCH_DEAD_ZONE ? 0 : this.#clampAxis(delta);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
#clampAxis(value: number): number {
|
|
608
|
+
return Math.max(-1, Math.min(1, value));
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
#syncCaptured(fallback?: boolean): void {
|
|
612
|
+
const document = pointerLockDocument();
|
|
613
|
+
if (document?.pointerLockElement !== undefined) {
|
|
614
|
+
this.raw.pointer.captured = document.pointerLockElement === this.#pointerTarget;
|
|
615
|
+
} else if (fallback !== undefined) {
|
|
616
|
+
this.raw.pointer.captured = fallback;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
#captureFromClick(): void {
|
|
621
|
+
this.captureMouse();
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
#pointerEvent(event: Event, edgeType?: IRawInputPointerEdge["type"]): void {
|
|
625
|
+
const pointer = event as PointerEvent;
|
|
626
|
+
const id = pointer.pointerId ?? 0;
|
|
627
|
+
const buttons = pointer.buttons ?? 0;
|
|
628
|
+
const x = pointer.clientX ?? 0;
|
|
629
|
+
const y = pointer.clientY ?? 0;
|
|
630
|
+
this.#recordPointerEdge(id, buttons, x, y, edgeType);
|
|
631
|
+
if (buttons !== 0) this.#latchedPointerButtons |= buttons;
|
|
632
|
+
if (edgeType === "down") this.#latchedPointer = true;
|
|
633
|
+
const tracked = this.#pointers.get(id);
|
|
634
|
+
if (edgeType === "down") {
|
|
635
|
+
if (tracked === undefined) {
|
|
636
|
+
this.#pointers.set(id, { buttons, id, position: new Vector2(x, y) });
|
|
637
|
+
} else {
|
|
638
|
+
tracked.buttons = buttons;
|
|
639
|
+
tracked.position.set(x, y);
|
|
640
|
+
}
|
|
641
|
+
} else if (edgeType === "up" || edgeType === "cancel") {
|
|
642
|
+
this.#pointers.delete(id);
|
|
643
|
+
} else if (tracked !== undefined) {
|
|
644
|
+
tracked.buttons = buttons;
|
|
645
|
+
tracked.position.set(x, y);
|
|
646
|
+
}
|
|
647
|
+
const primary = this.#pointers.values().next().value as IRawInputPointer | undefined;
|
|
648
|
+
if (primary !== undefined) {
|
|
649
|
+
this.#pointerButtons = primary.buttons;
|
|
650
|
+
this.#pointerPosition.copy(primary.position);
|
|
651
|
+
} else if (edgeType === undefined || tracked !== undefined) {
|
|
652
|
+
this.#pointerButtons = buttons;
|
|
653
|
+
this.#pointerPosition.set(x, y);
|
|
654
|
+
}
|
|
655
|
+
this.raw.pointer.buttons = this.#pointerButtons;
|
|
656
|
+
this.raw.pointer.down = primary !== undefined;
|
|
657
|
+
const capture = this.#pointerTarget as EventTarget & {
|
|
658
|
+
releasePointerCapture?: (id: number) => void;
|
|
659
|
+
setPointerCapture?: (id: number) => void;
|
|
660
|
+
};
|
|
661
|
+
// Browser conformance injects untrusted PointerEvents with dispatchEvent(). Chromium
|
|
662
|
+
// rejects pointer capture for those events because no physical pointer is active.
|
|
663
|
+
// Real browser input remains captured; native hosts may omit isTrusted and keep their stub.
|
|
664
|
+
if (pointer.isTrusted !== false) {
|
|
665
|
+
try {
|
|
666
|
+
if (edgeType === "down") capture.setPointerCapture?.(id);
|
|
667
|
+
if (edgeType === "up" || edgeType === "cancel") capture.releasePointerCapture?.(id);
|
|
668
|
+
} catch (error) {
|
|
669
|
+
// A pointer-lock transition can make a trusted event temporarily uncapturable.
|
|
670
|
+
if (!(error instanceof Error && error.name === "InvalidStateError")) throw error;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
#recordPointerEdge(
|
|
676
|
+
id: number,
|
|
677
|
+
buttons: number,
|
|
678
|
+
x: number,
|
|
679
|
+
y: number,
|
|
680
|
+
edgeType: IRawInputPointerEdge["type"] | undefined,
|
|
681
|
+
): void {
|
|
682
|
+
if (edgeType === undefined) return;
|
|
683
|
+
let edges = this.#pendingPointerEdges.get(id);
|
|
684
|
+
if (edges === undefined) {
|
|
685
|
+
edges = [];
|
|
686
|
+
this.#pendingPointerEdges.set(id, edges);
|
|
687
|
+
}
|
|
688
|
+
edges.push({ buttons, id, position: new Vector2(x, y), type: edgeType });
|
|
689
|
+
}
|
|
690
|
+
}
|