@playcanvas/supersplat-viewer 1.20.2 → 1.20.3
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/dist/index.js +2 -2
- package/package.json +5 -5
- package/public/index.css +3 -1
- package/public/index.js +905 -433
- package/public/index.js.map +1 -1
package/public/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const TRACEID_GPU_TIMINGS = 'GpuTimings';
|
|
2
2
|
|
|
3
|
-
const version$1 = '2.18.
|
|
4
|
-
const revision = '
|
|
3
|
+
const version$1 = '2.18.1';
|
|
4
|
+
const revision = '5e45104';
|
|
5
5
|
function extend(target, ex) {
|
|
6
6
|
for(const prop in ex){
|
|
7
7
|
const copy = ex[prop];
|
|
@@ -7237,7 +7237,7 @@ class WebgpuBindGroupFormat {
|
|
|
7237
7237
|
class WebgpuBuffer {
|
|
7238
7238
|
destroy(device) {
|
|
7239
7239
|
if (this.buffer) {
|
|
7240
|
-
this.buffer
|
|
7240
|
+
device.deferDestroy(this.buffer);
|
|
7241
7241
|
this.buffer = null;
|
|
7242
7242
|
}
|
|
7243
7243
|
}
|
|
@@ -16172,7 +16172,7 @@ Keyboard.EVENT_KEYUP = 'keyup';
|
|
|
16172
16172
|
function isMousePointerLocked() {
|
|
16173
16173
|
return !!(document.pointerLockElement || document.mozPointerLockElement || document.webkitPointerLockElement);
|
|
16174
16174
|
}
|
|
16175
|
-
class MouseEvent {
|
|
16175
|
+
let MouseEvent$1 = class MouseEvent {
|
|
16176
16176
|
constructor(mouse, event){
|
|
16177
16177
|
this.x = 0;
|
|
16178
16178
|
this.y = 0;
|
|
@@ -16230,7 +16230,7 @@ class MouseEvent {
|
|
|
16230
16230
|
this.metaKey = event.metaKey ?? false;
|
|
16231
16231
|
this.event = event;
|
|
16232
16232
|
}
|
|
16233
|
-
}
|
|
16233
|
+
};
|
|
16234
16234
|
|
|
16235
16235
|
class Mouse extends EventHandler {
|
|
16236
16236
|
static isPointerLocked() {
|
|
@@ -16322,25 +16322,25 @@ class Mouse extends EventHandler {
|
|
|
16322
16322
|
}
|
|
16323
16323
|
_handleUp(event) {
|
|
16324
16324
|
this._buttons[event.button] = false;
|
|
16325
|
-
const e = new MouseEvent(this, event);
|
|
16325
|
+
const e = new MouseEvent$1(this, event);
|
|
16326
16326
|
if (!e.event) return;
|
|
16327
16327
|
this.fire('mouseup', e);
|
|
16328
16328
|
}
|
|
16329
16329
|
_handleDown(event) {
|
|
16330
16330
|
this._buttons[event.button] = true;
|
|
16331
|
-
const e = new MouseEvent(this, event);
|
|
16331
|
+
const e = new MouseEvent$1(this, event);
|
|
16332
16332
|
if (!e.event) return;
|
|
16333
16333
|
this.fire('mousedown', e);
|
|
16334
16334
|
}
|
|
16335
16335
|
_handleMove(event) {
|
|
16336
|
-
const e = new MouseEvent(this, event);
|
|
16336
|
+
const e = new MouseEvent$1(this, event);
|
|
16337
16337
|
if (!e.event) return;
|
|
16338
16338
|
this.fire('mousemove', e);
|
|
16339
16339
|
this._lastX = e.x;
|
|
16340
16340
|
this._lastY = e.y;
|
|
16341
16341
|
}
|
|
16342
16342
|
_handleWheel(event) {
|
|
16343
|
-
const e = new MouseEvent(this, event);
|
|
16343
|
+
const e = new MouseEvent$1(this, event);
|
|
16344
16344
|
if (!e.event) return;
|
|
16345
16345
|
this.fire('mousewheel', e);
|
|
16346
16346
|
}
|
|
@@ -16422,7 +16422,7 @@ class TouchEvent {
|
|
|
16422
16422
|
}
|
|
16423
16423
|
}
|
|
16424
16424
|
|
|
16425
|
-
class TouchDevice extends EventHandler {
|
|
16425
|
+
let TouchDevice$1 = class TouchDevice extends EventHandler {
|
|
16426
16426
|
attach(element) {
|
|
16427
16427
|
if (this._element) {
|
|
16428
16428
|
this.detach();
|
|
@@ -16464,11 +16464,11 @@ class TouchDevice extends EventHandler {
|
|
|
16464
16464
|
this._cancelHandler = this._handleTouchCancel.bind(this);
|
|
16465
16465
|
this.attach(element);
|
|
16466
16466
|
}
|
|
16467
|
-
}
|
|
16468
|
-
TouchDevice.EVENT_TOUCHSTART = 'touchstart';
|
|
16469
|
-
TouchDevice.EVENT_TOUCHEND = 'touchend';
|
|
16470
|
-
TouchDevice.EVENT_TOUCHMOVE = 'touchmove';
|
|
16471
|
-
TouchDevice.EVENT_TOUCHCANCEL = 'touchcancel';
|
|
16467
|
+
};
|
|
16468
|
+
TouchDevice$1.EVENT_TOUCHSTART = 'touchstart';
|
|
16469
|
+
TouchDevice$1.EVENT_TOUCHEND = 'touchend';
|
|
16470
|
+
TouchDevice$1.EVENT_TOUCHMOVE = 'touchmove';
|
|
16471
|
+
TouchDevice$1.EVENT_TOUCHCANCEL = 'touchcancel';
|
|
16472
16472
|
|
|
16473
16473
|
class Http {
|
|
16474
16474
|
get(url, options, callback) {
|
|
@@ -70115,7 +70115,7 @@ let Picker$1 = class Picker {
|
|
|
70115
70115
|
return null;
|
|
70116
70116
|
}
|
|
70117
70117
|
const pixels = await this._readTexture(this.depthBuffer, x, y, 1, 1, this.renderTargetDepth);
|
|
70118
|
-
const intBits = pixels[0] << 24 | pixels[1] << 16 | pixels[2] << 8 | pixels[3];
|
|
70118
|
+
const intBits = (pixels[0] << 24 | pixels[1] << 16 | pixels[2] << 8 | pixels[3]) >>> 0;
|
|
70119
70119
|
if (intBits === 0xFFFFFFFF) {
|
|
70120
70120
|
return null;
|
|
70121
70121
|
}
|
|
@@ -76922,11 +76922,22 @@ const initUI = (global) => {
|
|
|
76922
76922
|
document.activeElement?.blur();
|
|
76923
76923
|
});
|
|
76924
76924
|
// Forward wheel events from UI overlays to the canvas so the camera zooms
|
|
76925
|
-
// instead of the page scrolling (e.g. annotation nav, tooltips, hotspots)
|
|
76925
|
+
// instead of the page scrolling (e.g. annotation nav, tooltips, hotspots).
|
|
76926
|
+
// The non-standard wheelDelta{X,Y} properties aren't part of WheelEventInit,
|
|
76927
|
+
// so they get dropped by `new WheelEvent(type, init)`. We re-attach them so
|
|
76928
|
+
// the trackpad-vs-mouse classifier in input-controller.ts behaves the same
|
|
76929
|
+
// whether the event originated on the canvas or was forwarded from the UI.
|
|
76926
76930
|
const canvas = global.app.graphicsDevice.canvas;
|
|
76927
76931
|
dom.ui.addEventListener('wheel', (event) => {
|
|
76928
76932
|
event.preventDefault();
|
|
76929
|
-
|
|
76933
|
+
const forwarded = new WheelEvent(event.type, event);
|
|
76934
|
+
const src = event;
|
|
76935
|
+
for (const key of ['wheelDelta', 'wheelDeltaX', 'wheelDeltaY']) {
|
|
76936
|
+
if (typeof src[key] === 'number') {
|
|
76937
|
+
Object.defineProperty(forwarded, key, { value: src[key], configurable: true });
|
|
76938
|
+
}
|
|
76939
|
+
}
|
|
76940
|
+
canvas.dispatchEvent(forwarded);
|
|
76930
76941
|
}, { passive: false });
|
|
76931
76942
|
// Handle loading progress updates
|
|
76932
76943
|
events.on('progress:changed', (progress) => {
|
|
@@ -79021,6 +79032,227 @@ class CameraManager {
|
|
|
79021
79032
|
}
|
|
79022
79033
|
}
|
|
79023
79034
|
|
|
79035
|
+
/**
|
|
79036
|
+
* Watches global pointer events and updates `state.inputMode` to reflect
|
|
79037
|
+
* whether the user is on a touch device or desktop.
|
|
79038
|
+
*/
|
|
79039
|
+
class InputModeTracker {
|
|
79040
|
+
_global = null;
|
|
79041
|
+
_onPointer = (event) => {
|
|
79042
|
+
if (this._global) {
|
|
79043
|
+
this._global.state.inputMode = event.pointerType === 'touch' ? 'touch' : 'desktop';
|
|
79044
|
+
}
|
|
79045
|
+
};
|
|
79046
|
+
attach(global) {
|
|
79047
|
+
this._global = global;
|
|
79048
|
+
window.addEventListener('pointerdown', this._onPointer);
|
|
79049
|
+
window.addEventListener('pointermove', this._onPointer);
|
|
79050
|
+
}
|
|
79051
|
+
detach() {
|
|
79052
|
+
window.removeEventListener('pointerdown', this._onPointer);
|
|
79053
|
+
window.removeEventListener('pointermove', this._onPointer);
|
|
79054
|
+
this._global = null;
|
|
79055
|
+
}
|
|
79056
|
+
}
|
|
79057
|
+
|
|
79058
|
+
/**
|
|
79059
|
+
* Keyboard shortcuts that switch camera mode and toggle UI affordances.
|
|
79060
|
+
* Listens on `window` so the user can press 1/2/3, V, G, H, F, R, Space,
|
|
79061
|
+
* or Escape regardless of which element has focus.
|
|
79062
|
+
*/
|
|
79063
|
+
class ModeShortcuts {
|
|
79064
|
+
_global = null;
|
|
79065
|
+
_pointerLock = null;
|
|
79066
|
+
_onKeyDown = (event) => {
|
|
79067
|
+
const global = this._global;
|
|
79068
|
+
if (!global)
|
|
79069
|
+
return;
|
|
79070
|
+
const { state, events } = global;
|
|
79071
|
+
if (event.key === 'Escape') {
|
|
79072
|
+
if (this._pointerLock?.recentlyExitedWalk) ;
|
|
79073
|
+
else if (state.cameraMode === 'walk' && state.gamingControls && state.inputMode === 'desktop') {
|
|
79074
|
+
state.gamingControls = false;
|
|
79075
|
+
}
|
|
79076
|
+
else if (state.cameraMode === 'walk') {
|
|
79077
|
+
events.fire('inputEvent', 'exitWalk', event);
|
|
79078
|
+
}
|
|
79079
|
+
else {
|
|
79080
|
+
events.fire('inputEvent', 'cancel', event);
|
|
79081
|
+
}
|
|
79082
|
+
return;
|
|
79083
|
+
}
|
|
79084
|
+
if (event.ctrlKey || event.altKey || event.metaKey) {
|
|
79085
|
+
return;
|
|
79086
|
+
}
|
|
79087
|
+
switch (event.key) {
|
|
79088
|
+
case '1':
|
|
79089
|
+
state.cameraMode = 'orbit';
|
|
79090
|
+
break;
|
|
79091
|
+
case '2':
|
|
79092
|
+
state.cameraMode = 'fly';
|
|
79093
|
+
break;
|
|
79094
|
+
case '3':
|
|
79095
|
+
events.fire('inputEvent', 'toggleWalk');
|
|
79096
|
+
break;
|
|
79097
|
+
case 'v':
|
|
79098
|
+
if (state.hasVoxelOverlay) {
|
|
79099
|
+
state.voxelOverlayEnabled = !state.voxelOverlayEnabled;
|
|
79100
|
+
}
|
|
79101
|
+
break;
|
|
79102
|
+
case 'g':
|
|
79103
|
+
state.gamingControls = !state.gamingControls;
|
|
79104
|
+
break;
|
|
79105
|
+
case 'h':
|
|
79106
|
+
events.fire('inputEvent', 'toggleHelp');
|
|
79107
|
+
break;
|
|
79108
|
+
default:
|
|
79109
|
+
if ((event.code === 'KeyW' || event.code === 'KeyA' || event.code === 'KeyS' || event.code === 'KeyD') &&
|
|
79110
|
+
state.cameraMode === 'walk' && state.inputMode === 'desktop' && !state.gamingControls) {
|
|
79111
|
+
state.gamingControls = true;
|
|
79112
|
+
}
|
|
79113
|
+
break;
|
|
79114
|
+
}
|
|
79115
|
+
if (state.cameraMode !== 'walk') {
|
|
79116
|
+
switch (event.key) {
|
|
79117
|
+
case 'f':
|
|
79118
|
+
events.fire('inputEvent', 'frame', event);
|
|
79119
|
+
break;
|
|
79120
|
+
case 'r':
|
|
79121
|
+
events.fire('inputEvent', 'reset', event);
|
|
79122
|
+
break;
|
|
79123
|
+
case ' ':
|
|
79124
|
+
events.fire('inputEvent', 'playPause', event);
|
|
79125
|
+
break;
|
|
79126
|
+
}
|
|
79127
|
+
}
|
|
79128
|
+
};
|
|
79129
|
+
attach(global, pointerLock) {
|
|
79130
|
+
this._global = global;
|
|
79131
|
+
this._pointerLock = pointerLock;
|
|
79132
|
+
window.addEventListener('keydown', this._onKeyDown);
|
|
79133
|
+
}
|
|
79134
|
+
detach() {
|
|
79135
|
+
window.removeEventListener('keydown', this._onKeyDown);
|
|
79136
|
+
this._global = null;
|
|
79137
|
+
this._pointerLock = null;
|
|
79138
|
+
}
|
|
79139
|
+
}
|
|
79140
|
+
|
|
79141
|
+
/**
|
|
79142
|
+
* Manages the browser's pointer-lock API for walk-mode + gaming controls
|
|
79143
|
+
* on desktop. Toggles in response to `cameraMode:changed` and
|
|
79144
|
+
* `gamingControls:changed`, and reverts state if the lock is exited or
|
|
79145
|
+
* rejected.
|
|
79146
|
+
*
|
|
79147
|
+
* Also exposes `recentlyExitedWalk` so the keyboard-shortcut handler can
|
|
79148
|
+
* de-duplicate the Escape keydown that triggered the lock exit.
|
|
79149
|
+
*/
|
|
79150
|
+
class PointerLockManager {
|
|
79151
|
+
_global = null;
|
|
79152
|
+
_canvas = null;
|
|
79153
|
+
_keyboardMouse = null;
|
|
79154
|
+
_recentlyExitedWalk = false;
|
|
79155
|
+
_onPointerLockChange = () => {
|
|
79156
|
+
const global = this._global;
|
|
79157
|
+
if (!global)
|
|
79158
|
+
return;
|
|
79159
|
+
const { state, events } = global;
|
|
79160
|
+
if (!document.pointerLockElement && state.cameraMode === 'walk' && state.gamingControls) {
|
|
79161
|
+
this._recentlyExitedWalk = true;
|
|
79162
|
+
requestAnimationFrame(() => {
|
|
79163
|
+
this._recentlyExitedWalk = false;
|
|
79164
|
+
});
|
|
79165
|
+
if (state.inputMode === 'desktop') {
|
|
79166
|
+
state.gamingControls = false;
|
|
79167
|
+
}
|
|
79168
|
+
else {
|
|
79169
|
+
events.fire('inputEvent', 'exitWalk');
|
|
79170
|
+
}
|
|
79171
|
+
}
|
|
79172
|
+
};
|
|
79173
|
+
_onPointerLockError = () => {
|
|
79174
|
+
// Pointer lock request rejected (no user gesture, document hidden,
|
|
79175
|
+
// etc). Revert state so we don't end up stuck in walk mode without
|
|
79176
|
+
// mouse capture.
|
|
79177
|
+
if (this._keyboardMouse) {
|
|
79178
|
+
this._keyboardMouse.source._pointerLock = false;
|
|
79179
|
+
}
|
|
79180
|
+
const global = this._global;
|
|
79181
|
+
if (!global)
|
|
79182
|
+
return;
|
|
79183
|
+
const { state, events } = global;
|
|
79184
|
+
if (state.inputMode === 'desktop') {
|
|
79185
|
+
state.gamingControls = false;
|
|
79186
|
+
}
|
|
79187
|
+
else {
|
|
79188
|
+
events.fire('inputEvent', 'exitWalk');
|
|
79189
|
+
}
|
|
79190
|
+
};
|
|
79191
|
+
_onCameraModeChanged = (value, prev) => {
|
|
79192
|
+
const state = this._global?.state;
|
|
79193
|
+
if (!state)
|
|
79194
|
+
return;
|
|
79195
|
+
if (value === 'walk' && state.inputMode === 'desktop' && state.gamingControls) {
|
|
79196
|
+
this._activate();
|
|
79197
|
+
}
|
|
79198
|
+
else if (prev === 'walk') {
|
|
79199
|
+
this._deactivate();
|
|
79200
|
+
}
|
|
79201
|
+
};
|
|
79202
|
+
_onGamingControlsChanged = (value) => {
|
|
79203
|
+
const state = this._global?.state;
|
|
79204
|
+
if (!state)
|
|
79205
|
+
return;
|
|
79206
|
+
if (state.cameraMode === 'walk' && state.inputMode === 'desktop') {
|
|
79207
|
+
if (value) {
|
|
79208
|
+
this._activate();
|
|
79209
|
+
}
|
|
79210
|
+
else {
|
|
79211
|
+
this._deactivate();
|
|
79212
|
+
}
|
|
79213
|
+
}
|
|
79214
|
+
};
|
|
79215
|
+
_activate() {
|
|
79216
|
+
if (this._keyboardMouse) {
|
|
79217
|
+
this._keyboardMouse.source._pointerLock = true;
|
|
79218
|
+
}
|
|
79219
|
+
this._canvas?.requestPointerLock();
|
|
79220
|
+
}
|
|
79221
|
+
_deactivate() {
|
|
79222
|
+
if (this._keyboardMouse) {
|
|
79223
|
+
this._keyboardMouse.source._pointerLock = false;
|
|
79224
|
+
}
|
|
79225
|
+
if (document.pointerLockElement === this._canvas) {
|
|
79226
|
+
document.exitPointerLock();
|
|
79227
|
+
}
|
|
79228
|
+
}
|
|
79229
|
+
get recentlyExitedWalk() {
|
|
79230
|
+
return this._recentlyExitedWalk;
|
|
79231
|
+
}
|
|
79232
|
+
attach(canvas, global, keyboardMouse) {
|
|
79233
|
+
this._canvas = canvas;
|
|
79234
|
+
this._global = global;
|
|
79235
|
+
this._keyboardMouse = keyboardMouse;
|
|
79236
|
+
const { events } = global;
|
|
79237
|
+
events.on('cameraMode:changed', this._onCameraModeChanged);
|
|
79238
|
+
events.on('gamingControls:changed', this._onGamingControlsChanged);
|
|
79239
|
+
document.addEventListener('pointerlockchange', this._onPointerLockChange);
|
|
79240
|
+
document.addEventListener('pointerlockerror', this._onPointerLockError);
|
|
79241
|
+
}
|
|
79242
|
+
detach() {
|
|
79243
|
+
if (this._global) {
|
|
79244
|
+
const { events } = this._global;
|
|
79245
|
+
events.off('cameraMode:changed', this._onCameraModeChanged);
|
|
79246
|
+
events.off('gamingControls:changed', this._onGamingControlsChanged);
|
|
79247
|
+
}
|
|
79248
|
+
document.removeEventListener('pointerlockchange', this._onPointerLockChange);
|
|
79249
|
+
document.removeEventListener('pointerlockerror', this._onPointerLockError);
|
|
79250
|
+
this._canvas = null;
|
|
79251
|
+
this._global = null;
|
|
79252
|
+
this._keyboardMouse = null;
|
|
79253
|
+
}
|
|
79254
|
+
}
|
|
79255
|
+
|
|
79024
79256
|
/**
|
|
79025
79257
|
* Double-click world picking for splat scenes.
|
|
79026
79258
|
*
|
|
@@ -79368,44 +79600,32 @@ class Picker {
|
|
|
79368
79600
|
}
|
|
79369
79601
|
}
|
|
79370
79602
|
|
|
79371
|
-
/* Vec initialisation to avoid recurrent memory allocation */
|
|
79372
|
-
const tmpV1 = new Vec3();
|
|
79373
|
-
const tmpV2 = new Vec3();
|
|
79374
|
-
const mouseRotate = new Vec3();
|
|
79375
|
-
const flyMove = new Vec3();
|
|
79376
|
-
const flyTouchPan = new Vec3();
|
|
79377
|
-
const pinchMove = new Vec3();
|
|
79378
|
-
const orbitRotate = new Vec3();
|
|
79379
|
-
const flyRotate = new Vec3();
|
|
79380
|
-
const stickMove = new Vec3();
|
|
79381
|
-
const stickRotate = new Vec3();
|
|
79382
|
-
/** Maximum accumulated touch movement (px) to still count as a tap */
|
|
79383
|
-
const TAP_EPSILON = 15;
|
|
79384
79603
|
/**
|
|
79385
|
-
* Displacement-based inputs (mouse, touch, wheel, pinch) return accumulated
|
|
79386
|
-
* offsets that already scale with frame time. This factor converts
|
|
79387
|
-
* constants (tuned for degrees-per-second) to work with
|
|
79388
|
-
* making them frame-rate-independent.
|
|
79604
|
+
* Displacement-based inputs (mouse, touch, wheel, pinch) return accumulated
|
|
79605
|
+
* pixel offsets that already scale with frame time. This factor converts
|
|
79606
|
+
* rate-based speed constants (tuned for degrees-per-second) to work with
|
|
79607
|
+
* per-frame displacements, making them frame-rate-independent.
|
|
79389
79608
|
*/
|
|
79390
79609
|
const DISPLACEMENT_SCALE = 1 / 60;
|
|
79610
|
+
/** Maximum accumulated touch movement (px) to still count as a tap. */
|
|
79611
|
+
const TAP_EPSILON = 15;
|
|
79612
|
+
const tmpHalfSize = new Vec3();
|
|
79391
79613
|
/**
|
|
79392
|
-
* Converts screen
|
|
79614
|
+
* Converts screen-space pixel deltas to a world-space pan vector at the
|
|
79615
|
+
* given depth.
|
|
79393
79616
|
*
|
|
79394
79617
|
* @param camera - The camera component.
|
|
79395
|
-
* @param dx -
|
|
79396
|
-
* @param dy -
|
|
79397
|
-
* @param dz -
|
|
79398
|
-
* @param out -
|
|
79399
|
-
* @returns
|
|
79400
|
-
* @private
|
|
79618
|
+
* @param dx - Horizontal pixel delta.
|
|
79619
|
+
* @param dy - Vertical pixel delta.
|
|
79620
|
+
* @param dz - Depth (world-space) at which to project the delta.
|
|
79621
|
+
* @param out - Optional output vector.
|
|
79622
|
+
* @returns The pan vector in world space.
|
|
79401
79623
|
*/
|
|
79402
79624
|
const screenToWorld = (camera, dx, dy, dz, out = new Vec3()) => {
|
|
79403
79625
|
const { system, fov, aspectRatio, horizontalFov, projection, orthoHeight } = camera;
|
|
79404
79626
|
const { width, height } = system.app.graphicsDevice.clientRect;
|
|
79405
|
-
// normalize deltas to device coord space
|
|
79406
79627
|
out.set(-(dx / width) * 2, (dy / height) * 2, 0);
|
|
79407
|
-
|
|
79408
|
-
const halfSize = tmpV2.set(0, 0, 0);
|
|
79628
|
+
const halfSize = tmpHalfSize.set(0, 0, 0);
|
|
79409
79629
|
if (projection === PROJECTION_PERSPECTIVE) {
|
|
79410
79630
|
const halfSlice = dz * Math.tan(0.5 * fov * math.DEG_TO_RAD);
|
|
79411
79631
|
if (horizontalFov) {
|
|
@@ -79418,12 +79638,227 @@ const screenToWorld = (camera, dx, dy, dz, out = new Vec3()) => {
|
|
|
79418
79638
|
else {
|
|
79419
79639
|
halfSize.set(orthoHeight * aspectRatio, orthoHeight, 0);
|
|
79420
79640
|
}
|
|
79421
|
-
// scale by device coord space
|
|
79422
79641
|
out.mul(halfSize);
|
|
79423
79642
|
return out;
|
|
79424
79643
|
};
|
|
79425
|
-
|
|
79426
|
-
|
|
79644
|
+
/**
|
|
79645
|
+
* The orbit camera and the fly camera disagree on the sign of the z-axis
|
|
79646
|
+
* for forward motion. Apply this when emitting a forward/back z-component
|
|
79647
|
+
* so the same wheel-style delta drives both cameras correctly.
|
|
79648
|
+
*
|
|
79649
|
+
* @param mode - The current camera mode.
|
|
79650
|
+
* @param z - The raw forward/back z-component.
|
|
79651
|
+
* @returns The z-component flipped for orbit mode, unchanged otherwise.
|
|
79652
|
+
*/
|
|
79653
|
+
const flipZForOrbit = (mode, z) => (mode === 'orbit' ? -z : z);
|
|
79654
|
+
|
|
79655
|
+
const tmpV$4 = new Vec3();
|
|
79656
|
+
/**
|
|
79657
|
+
* Click-to-walk (desktop), tap-to-walk (mobile), and double-click-to-pick
|
|
79658
|
+
* (orbit / fly) interaction. Uses a Picker against the collision mesh to
|
|
79659
|
+
* resolve the world-space target and fires `walkTo` / `pick` for the
|
|
79660
|
+
* camera manager to consume.
|
|
79661
|
+
*/
|
|
79662
|
+
class WalkInteraction {
|
|
79663
|
+
collision = null;
|
|
79664
|
+
_global = null;
|
|
79665
|
+
_canvas = null;
|
|
79666
|
+
_picker = null;
|
|
79667
|
+
_lastPointerOffsetX = 0;
|
|
79668
|
+
_lastPointerOffsetY = 0;
|
|
79669
|
+
_mouseClickTracking = false;
|
|
79670
|
+
_mouseClickDelta = 0;
|
|
79671
|
+
_lastTap = { time: 0, x: 0, y: 0 };
|
|
79672
|
+
_updateCursor = () => {
|
|
79673
|
+
const global = this._global;
|
|
79674
|
+
const canvas = this._canvas;
|
|
79675
|
+
if (!global || !canvas)
|
|
79676
|
+
return;
|
|
79677
|
+
const { state } = global;
|
|
79678
|
+
if (state.cameraMode === 'walk' && !state.gamingControls && state.inputMode === 'desktop') {
|
|
79679
|
+
canvas.style.cursor = this._mouseClickTracking ? 'default' : 'pointer';
|
|
79680
|
+
}
|
|
79681
|
+
else {
|
|
79682
|
+
canvas.style.cursor = '';
|
|
79683
|
+
}
|
|
79684
|
+
};
|
|
79685
|
+
_pickCollision(offsetX, offsetY) {
|
|
79686
|
+
if (!this.collision || !this._global)
|
|
79687
|
+
return null;
|
|
79688
|
+
const camera = this._global.camera;
|
|
79689
|
+
const cameraPos = camera.getPosition();
|
|
79690
|
+
camera.camera.screenToWorld(offsetX, offsetY, 1.0, tmpV$4);
|
|
79691
|
+
tmpV$4.sub(cameraPos).normalize();
|
|
79692
|
+
const hit = this.collision.queryRay(cameraPos.x, cameraPos.y, cameraPos.z, tmpV$4.x, tmpV$4.y, tmpV$4.z, camera.camera.farClip);
|
|
79693
|
+
if (!hit)
|
|
79694
|
+
return null;
|
|
79695
|
+
const sn = this.collision.querySurfaceNormal(hit.x, hit.y, hit.z, tmpV$4.x, tmpV$4.y, tmpV$4.z);
|
|
79696
|
+
return {
|
|
79697
|
+
position: new Vec3(hit.x, hit.y, hit.z),
|
|
79698
|
+
normal: new Vec3(sn.nx, sn.ny, sn.nz)
|
|
79699
|
+
};
|
|
79700
|
+
}
|
|
79701
|
+
_onPointerDown = (event) => {
|
|
79702
|
+
const global = this._global;
|
|
79703
|
+
if (!global)
|
|
79704
|
+
return;
|
|
79705
|
+
const { events } = global;
|
|
79706
|
+
// record offsets for click/tap-to-walk picking
|
|
79707
|
+
this._lastPointerOffsetX = event.offsetX;
|
|
79708
|
+
this._lastPointerOffsetY = event.offsetY;
|
|
79709
|
+
// start desktop click-to-walk tracking
|
|
79710
|
+
if (event.pointerType !== 'touch' && event.button === 0) {
|
|
79711
|
+
this._mouseClickTracking = true;
|
|
79712
|
+
this._mouseClickDelta = 0;
|
|
79713
|
+
this._updateCursor();
|
|
79714
|
+
}
|
|
79715
|
+
// manual double-tap detection (iOS doesn't send dblclick)
|
|
79716
|
+
const now = Date.now();
|
|
79717
|
+
const delay = Math.max(0, now - this._lastTap.time);
|
|
79718
|
+
if (delay < 300 &&
|
|
79719
|
+
Math.abs(event.clientX - this._lastTap.x) < 8 &&
|
|
79720
|
+
Math.abs(event.clientY - this._lastTap.y) < 8) {
|
|
79721
|
+
events.fire('inputEvent', 'dblclick', event);
|
|
79722
|
+
this._lastTap.time = 0;
|
|
79723
|
+
}
|
|
79724
|
+
else {
|
|
79725
|
+
this._lastTap.time = now;
|
|
79726
|
+
this._lastTap.x = event.clientX;
|
|
79727
|
+
this._lastTap.y = event.clientY;
|
|
79728
|
+
}
|
|
79729
|
+
};
|
|
79730
|
+
_onPointerMove = (event) => {
|
|
79731
|
+
const global = this._global;
|
|
79732
|
+
if (!global)
|
|
79733
|
+
return;
|
|
79734
|
+
const { state, events } = global;
|
|
79735
|
+
if (this._mouseClickTracking && event.pointerType !== 'touch') {
|
|
79736
|
+
const prev = this._mouseClickDelta;
|
|
79737
|
+
this._mouseClickDelta += Math.abs(event.movementX) + Math.abs(event.movementY);
|
|
79738
|
+
if (prev < TAP_EPSILON && this._mouseClickDelta >= TAP_EPSILON) {
|
|
79739
|
+
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
79740
|
+
events.fire('walkCancel');
|
|
79741
|
+
}
|
|
79742
|
+
}
|
|
79743
|
+
}
|
|
79744
|
+
};
|
|
79745
|
+
_onPointerUp = (event) => {
|
|
79746
|
+
const global = this._global;
|
|
79747
|
+
if (!global)
|
|
79748
|
+
return;
|
|
79749
|
+
const { state, events } = global;
|
|
79750
|
+
if (this._mouseClickTracking && event.pointerType !== 'touch' && event.button === 0) {
|
|
79751
|
+
this._mouseClickTracking = false;
|
|
79752
|
+
this._updateCursor();
|
|
79753
|
+
if (this._mouseClickDelta < TAP_EPSILON && state.cameraMode === 'walk' && !state.gamingControls) {
|
|
79754
|
+
const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
79755
|
+
if (result) {
|
|
79756
|
+
events.fire('walkTo', result.position, result.normal);
|
|
79757
|
+
}
|
|
79758
|
+
}
|
|
79759
|
+
}
|
|
79760
|
+
};
|
|
79761
|
+
_onInputEvent = async (eventName, event) => {
|
|
79762
|
+
const global = this._global;
|
|
79763
|
+
const canvas = this._canvas;
|
|
79764
|
+
if (!global || !canvas)
|
|
79765
|
+
return;
|
|
79766
|
+
if (eventName !== 'dblclick')
|
|
79767
|
+
return;
|
|
79768
|
+
if (!(event instanceof MouseEvent))
|
|
79769
|
+
return;
|
|
79770
|
+
const { app, camera, events, state } = global;
|
|
79771
|
+
if (state.cameraMode === 'walk')
|
|
79772
|
+
return;
|
|
79773
|
+
if (!this._picker) {
|
|
79774
|
+
this._picker = new Picker(app, camera);
|
|
79775
|
+
}
|
|
79776
|
+
const result = await this._picker.pick(event.offsetX / canvas.clientWidth, event.offsetY / canvas.clientHeight);
|
|
79777
|
+
if (result) {
|
|
79778
|
+
events.fire('pick', result);
|
|
79779
|
+
}
|
|
79780
|
+
};
|
|
79781
|
+
_onMobileTap = () => {
|
|
79782
|
+
const global = this._global;
|
|
79783
|
+
if (!global)
|
|
79784
|
+
return;
|
|
79785
|
+
const { state, events } = global;
|
|
79786
|
+
if (state.cameraMode !== 'walk' || state.gamingControls)
|
|
79787
|
+
return;
|
|
79788
|
+
const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
79789
|
+
if (result) {
|
|
79790
|
+
events.fire('walkTo', result.position, result.normal);
|
|
79791
|
+
}
|
|
79792
|
+
};
|
|
79793
|
+
attach(canvas, global) {
|
|
79794
|
+
this._canvas = canvas;
|
|
79795
|
+
this._global = global;
|
|
79796
|
+
const { events } = global;
|
|
79797
|
+
canvas.addEventListener('pointerdown', this._onPointerDown);
|
|
79798
|
+
canvas.addEventListener('pointermove', this._onPointerMove);
|
|
79799
|
+
canvas.addEventListener('pointerup', this._onPointerUp);
|
|
79800
|
+
// double-click → pick → fire 'pick' event (skipped in walk mode)
|
|
79801
|
+
events.on('inputEvent', this._onInputEvent);
|
|
79802
|
+
// mobile tap (no movement) → walkTo
|
|
79803
|
+
events.on('mobileTap', this._onMobileTap);
|
|
79804
|
+
// refresh cursor on mode / gaming-controls change
|
|
79805
|
+
events.on('cameraMode:changed', this._updateCursor);
|
|
79806
|
+
events.on('gamingControls:changed', this._updateCursor);
|
|
79807
|
+
}
|
|
79808
|
+
detach() {
|
|
79809
|
+
if (this._canvas) {
|
|
79810
|
+
this._canvas.removeEventListener('pointerdown', this._onPointerDown);
|
|
79811
|
+
this._canvas.removeEventListener('pointermove', this._onPointerMove);
|
|
79812
|
+
this._canvas.removeEventListener('pointerup', this._onPointerUp);
|
|
79813
|
+
}
|
|
79814
|
+
if (this._global) {
|
|
79815
|
+
const { events } = this._global;
|
|
79816
|
+
events.off('inputEvent', this._onInputEvent);
|
|
79817
|
+
events.off('mobileTap', this._onMobileTap);
|
|
79818
|
+
events.off('cameraMode:changed', this._updateCursor);
|
|
79819
|
+
events.off('gamingControls:changed', this._updateCursor);
|
|
79820
|
+
}
|
|
79821
|
+
this._canvas = null;
|
|
79822
|
+
this._global = null;
|
|
79823
|
+
this._picker = null;
|
|
79824
|
+
}
|
|
79825
|
+
}
|
|
79826
|
+
|
|
79827
|
+
const tmpV$3 = new Vec3();
|
|
79828
|
+
const stickMove = new Vec3();
|
|
79829
|
+
const stickRotate = new Vec3();
|
|
79830
|
+
class GamepadDevice {
|
|
79831
|
+
moveSpeed = 4;
|
|
79832
|
+
orbitSpeed = 18;
|
|
79833
|
+
gamepadRotateSensitivity = 1.0;
|
|
79834
|
+
_source = new GamepadSource();
|
|
79835
|
+
attach(_canvas, _global) {
|
|
79836
|
+
// GamepadSource polls navigator.getGamepads() — no DOM attach needed.
|
|
79837
|
+
}
|
|
79838
|
+
detach() { }
|
|
79839
|
+
update(ctx, frame) {
|
|
79840
|
+
const { dt, cameraComponent, isFirstPerson } = ctx;
|
|
79841
|
+
const { leftStick, rightStick } = this._source.read();
|
|
79842
|
+
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
79843
|
+
const { deltas } = frame;
|
|
79844
|
+
const v = tmpV$3.set(0, 0, 0);
|
|
79845
|
+
stickMove.set(leftStick[0], 0, -leftStick[1]);
|
|
79846
|
+
v.add(stickMove.mulScalar(this.moveSpeed * dt));
|
|
79847
|
+
deltas.move.append([v.x, v.y, v.z]);
|
|
79848
|
+
v.set(0, 0, 0);
|
|
79849
|
+
stickRotate.set(rightStick[0], rightStick[1], 0);
|
|
79850
|
+
v.add(stickRotate.mulScalar(this.orbitSpeed * orbitFactor * this.gamepadRotateSensitivity * dt));
|
|
79851
|
+
deltas.rotate.append([v.x, v.y, v.z]);
|
|
79852
|
+
}
|
|
79853
|
+
}
|
|
79854
|
+
|
|
79855
|
+
const tmpV1 = new Vec3();
|
|
79856
|
+
const keyMove = new Vec3();
|
|
79857
|
+
const panMove = new Vec3();
|
|
79858
|
+
const mouseRotate = new Vec3();
|
|
79859
|
+
const wheelMove = new Vec3();
|
|
79860
|
+
// Patch keydown / keyup so meta-key combinations don't leave keys stuck on
|
|
79861
|
+
// macOS (the OS swallows keyup for any key released while Cmd is held).
|
|
79427
79862
|
const patchKeyboardMeta = (desktopInput) => {
|
|
79428
79863
|
const origOnKeyDown = desktopInput._onKeyDown;
|
|
79429
79864
|
desktopInput._onKeyDown = (event) => {
|
|
@@ -79444,342 +79879,171 @@ const patchKeyboardMeta = (desktopInput) => {
|
|
|
79444
79879
|
}
|
|
79445
79880
|
};
|
|
79446
79881
|
};
|
|
79447
|
-
class
|
|
79448
|
-
_state = {
|
|
79449
|
-
axis: new Vec3(),
|
|
79450
|
-
mouse: [0, 0, 0],
|
|
79451
|
-
shift: 0,
|
|
79452
|
-
ctrl: 0,
|
|
79453
|
-
jump: 0,
|
|
79454
|
-
touches: 0
|
|
79455
|
-
};
|
|
79456
|
-
_desktopInput = new KeyboardMouseSource();
|
|
79457
|
-
_orbitInput = new MultiTouchSource();
|
|
79458
|
-
_gamepadInput = new GamepadSource();
|
|
79459
|
-
global;
|
|
79460
|
-
frame = new InputFrame({
|
|
79461
|
-
move: [0, 0, 0],
|
|
79462
|
-
rotate: [0, 0, 0]
|
|
79463
|
-
});
|
|
79464
|
-
// Touch joystick input values [x, y] (-1 to 1)
|
|
79465
|
-
_touchJoystick = [0, 0];
|
|
79466
|
-
// Accumulated forward/backward velocity from pinch gesture (-1 to 1)
|
|
79467
|
-
_pinchVelocity = 0;
|
|
79468
|
-
// Accumulated strafe/vertical velocity from two-finger pan [x, y] (-1 to 1)
|
|
79469
|
-
_panVelocity = [0, 0];
|
|
79470
|
-
// Sensitivity for pinch delta → velocity conversion
|
|
79471
|
-
pinchVelocitySensitivity = 0.006;
|
|
79472
|
-
// Sensitivity for two-finger pan delta → velocity conversion
|
|
79473
|
-
panVelocitySensitivity = 0.005;
|
|
79474
|
-
// Tap-to-jump state (uses existing MultiTouchSource count/touch deltas)
|
|
79475
|
-
_tapTouches = 0;
|
|
79476
|
-
_tapDelta = 0;
|
|
79477
|
-
_tapJump = false;
|
|
79478
|
-
// Screen coordinates of the last pointer start (for click/tap-to-walk picking)
|
|
79479
|
-
_lastPointerOffsetX = 0;
|
|
79480
|
-
_lastPointerOffsetY = 0;
|
|
79481
|
-
// Desktop click-to-walk tracking
|
|
79482
|
-
_mouseClickTracking = false;
|
|
79483
|
-
_mouseClickDelta = 0;
|
|
79484
|
-
_picker = null;
|
|
79485
|
-
collision = null;
|
|
79882
|
+
class KeyboardMouseDevice {
|
|
79486
79883
|
moveSpeed = 4;
|
|
79487
79884
|
orbitSpeed = 18;
|
|
79488
|
-
pinchSpeed = 0.4;
|
|
79489
79885
|
wheelSpeed = 0.06;
|
|
79490
79886
|
mouseRotateSensitivity = 0.5;
|
|
79491
|
-
|
|
79492
|
-
|
|
79493
|
-
|
|
79494
|
-
|
|
79495
|
-
|
|
79496
|
-
|
|
79497
|
-
|
|
79498
|
-
|
|
79499
|
-
|
|
79500
|
-
// Listen for joystick input from the UI (touch joystick element)
|
|
79501
|
-
events.on('joystickInput', (value) => {
|
|
79502
|
-
this._touchJoystick[0] = value.x;
|
|
79503
|
-
this._touchJoystick[1] = value.y;
|
|
79504
|
-
});
|
|
79505
|
-
this.global = global;
|
|
79506
|
-
const updateCanvasCursor = () => {
|
|
79507
|
-
if (state.cameraMode === 'walk' && !state.gamingControls && state.inputMode === 'desktop') {
|
|
79508
|
-
canvas.style.cursor = this._mouseClickTracking ? 'default' : 'pointer';
|
|
79509
|
-
}
|
|
79510
|
-
else {
|
|
79511
|
-
canvas.style.cursor = '';
|
|
79512
|
-
}
|
|
79513
|
-
};
|
|
79514
|
-
// Generate input events
|
|
79515
|
-
['wheel', 'pointerdown', 'contextmenu', 'keydown'].forEach((eventName) => {
|
|
79516
|
-
canvas.addEventListener(eventName, (event) => {
|
|
79517
|
-
events.fire('inputEvent', 'interrupt', event);
|
|
79518
|
-
});
|
|
79519
|
-
});
|
|
79520
|
-
canvas.addEventListener('pointermove', (event) => {
|
|
79521
|
-
events.fire('inputEvent', 'interact', event);
|
|
79522
|
-
});
|
|
79523
|
-
// Detect double taps manually because iOS doesn't send dblclick events
|
|
79524
|
-
const lastTap = { time: 0, x: 0, y: 0 };
|
|
79525
|
-
canvas.addEventListener('pointerdown', (event) => {
|
|
79526
|
-
// Store coordinates for click/tap-to-walk picking
|
|
79527
|
-
this._lastPointerOffsetX = event.offsetX;
|
|
79528
|
-
this._lastPointerOffsetY = event.offsetY;
|
|
79529
|
-
// Start desktop click-to-walk tracking
|
|
79530
|
-
if (event.pointerType !== 'touch' && event.button === 0) {
|
|
79531
|
-
this._mouseClickTracking = true;
|
|
79532
|
-
this._mouseClickDelta = 0;
|
|
79533
|
-
updateCanvasCursor();
|
|
79534
|
-
}
|
|
79535
|
-
const now = Date.now();
|
|
79536
|
-
const delay = Math.max(0, now - lastTap.time);
|
|
79537
|
-
if (delay < 300 &&
|
|
79538
|
-
Math.abs(event.clientX - lastTap.x) < 8 &&
|
|
79539
|
-
Math.abs(event.clientY - lastTap.y) < 8) {
|
|
79540
|
-
events.fire('inputEvent', 'dblclick', event);
|
|
79541
|
-
lastTap.time = 0;
|
|
79542
|
-
}
|
|
79543
|
-
else {
|
|
79544
|
-
lastTap.time = now;
|
|
79545
|
-
lastTap.x = event.clientX;
|
|
79546
|
-
lastTap.y = event.clientY;
|
|
79547
|
-
}
|
|
79548
|
-
});
|
|
79549
|
-
// Desktop click-to-walk: accumulate displacement during mouse drag
|
|
79550
|
-
canvas.addEventListener('pointermove', (event) => {
|
|
79551
|
-
if (this._mouseClickTracking && event.pointerType !== 'touch') {
|
|
79552
|
-
const prev = this._mouseClickDelta;
|
|
79553
|
-
this._mouseClickDelta += Math.abs(event.movementX) + Math.abs(event.movementY);
|
|
79554
|
-
if (prev < TAP_EPSILON && this._mouseClickDelta >= TAP_EPSILON) {
|
|
79555
|
-
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
79556
|
-
events.fire('walkCancel');
|
|
79557
|
-
}
|
|
79558
|
-
}
|
|
79559
|
-
}
|
|
79560
|
-
});
|
|
79561
|
-
// Desktop click-to-walk: detect click (low displacement) on mouse button release
|
|
79562
|
-
canvas.addEventListener('pointerup', (event) => {
|
|
79563
|
-
if (this._mouseClickTracking && event.pointerType !== 'touch' && event.button === 0) {
|
|
79564
|
-
this._mouseClickTracking = false;
|
|
79565
|
-
updateCanvasCursor();
|
|
79566
|
-
if (this._mouseClickDelta < TAP_EPSILON && state.cameraMode === 'walk' && !state.gamingControls) {
|
|
79567
|
-
const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
79568
|
-
if (result) {
|
|
79569
|
-
events.fire('walkTo', result.position, result.normal);
|
|
79570
|
-
}
|
|
79571
|
-
}
|
|
79572
|
-
}
|
|
79573
|
-
});
|
|
79574
|
-
// Calculate pick location on double click
|
|
79575
|
-
events.on('inputEvent', async (eventName, event) => {
|
|
79576
|
-
switch (eventName) {
|
|
79577
|
-
case 'dblclick': {
|
|
79578
|
-
if (state.cameraMode === 'walk')
|
|
79579
|
-
break;
|
|
79580
|
-
if (!this._picker) {
|
|
79581
|
-
this._picker = new Picker(app, camera);
|
|
79582
|
-
}
|
|
79583
|
-
const result = await this._picker.pick(event.offsetX / canvas.clientWidth, event.offsetY / canvas.clientHeight);
|
|
79584
|
-
if (result) {
|
|
79585
|
-
events.fire('pick', result);
|
|
79586
|
-
}
|
|
79587
|
-
break;
|
|
79588
|
-
}
|
|
79589
|
-
}
|
|
79590
|
-
});
|
|
79591
|
-
// update input mode based on pointer event
|
|
79592
|
-
['pointerdown', 'pointermove'].forEach((eventName) => {
|
|
79593
|
-
window.addEventListener(eventName, (event) => {
|
|
79594
|
-
state.inputMode = event.pointerType === 'touch' ? 'touch' : 'desktop';
|
|
79595
|
-
});
|
|
79596
|
-
});
|
|
79597
|
-
let recentlyExitedWalk = false;
|
|
79598
|
-
// handle keyboard events
|
|
79599
|
-
window.addEventListener('keydown', (event) => {
|
|
79600
|
-
if (event.key === 'Escape') {
|
|
79601
|
-
if (recentlyExitedWalk) ;
|
|
79602
|
-
else if (state.cameraMode === 'walk' && state.gamingControls && state.inputMode === 'desktop') {
|
|
79603
|
-
state.gamingControls = false;
|
|
79604
|
-
}
|
|
79605
|
-
else if (state.cameraMode === 'walk') {
|
|
79606
|
-
events.fire('inputEvent', 'exitWalk', event);
|
|
79607
|
-
}
|
|
79608
|
-
else {
|
|
79609
|
-
events.fire('inputEvent', 'cancel', event);
|
|
79610
|
-
}
|
|
79611
|
-
}
|
|
79612
|
-
else if (!event.ctrlKey && !event.altKey && !event.metaKey) {
|
|
79613
|
-
switch (event.key) {
|
|
79614
|
-
case '1':
|
|
79615
|
-
state.cameraMode = 'orbit';
|
|
79616
|
-
break;
|
|
79617
|
-
case '2':
|
|
79618
|
-
state.cameraMode = 'fly';
|
|
79619
|
-
break;
|
|
79620
|
-
case '3':
|
|
79621
|
-
events.fire('inputEvent', 'toggleWalk');
|
|
79622
|
-
break;
|
|
79623
|
-
case 'v':
|
|
79624
|
-
if (state.hasVoxelOverlay) {
|
|
79625
|
-
state.voxelOverlayEnabled = !state.voxelOverlayEnabled;
|
|
79626
|
-
}
|
|
79627
|
-
break;
|
|
79628
|
-
case 'g':
|
|
79629
|
-
state.gamingControls = !state.gamingControls;
|
|
79630
|
-
break;
|
|
79631
|
-
case 'h':
|
|
79632
|
-
events.fire('inputEvent', 'toggleHelp');
|
|
79633
|
-
break;
|
|
79634
|
-
default:
|
|
79635
|
-
if ((event.code === 'KeyW' || event.code === 'KeyA' || event.code === 'KeyS' || event.code === 'KeyD') &&
|
|
79636
|
-
state.cameraMode === 'walk' && state.inputMode === 'desktop' && !state.gamingControls) {
|
|
79637
|
-
state.gamingControls = true;
|
|
79638
|
-
}
|
|
79639
|
-
break;
|
|
79640
|
-
}
|
|
79641
|
-
if (state.cameraMode !== 'walk') {
|
|
79642
|
-
switch (event.key) {
|
|
79643
|
-
case 'f':
|
|
79644
|
-
events.fire('inputEvent', 'frame', event);
|
|
79645
|
-
break;
|
|
79646
|
-
case 'r':
|
|
79647
|
-
events.fire('inputEvent', 'reset', event);
|
|
79648
|
-
break;
|
|
79649
|
-
case ' ':
|
|
79650
|
-
events.fire('inputEvent', 'playPause', event);
|
|
79651
|
-
break;
|
|
79652
|
-
}
|
|
79653
|
-
}
|
|
79654
|
-
}
|
|
79655
|
-
});
|
|
79656
|
-
const activatePointerLock = () => {
|
|
79657
|
-
this._desktopInput._pointerLock = true;
|
|
79658
|
-
canvas.requestPointerLock();
|
|
79659
|
-
};
|
|
79660
|
-
const deactivatePointerLock = () => {
|
|
79661
|
-
this._desktopInput._pointerLock = false;
|
|
79662
|
-
if (document.pointerLockElement === canvas) {
|
|
79663
|
-
document.exitPointerLock();
|
|
79664
|
-
}
|
|
79665
|
-
};
|
|
79666
|
-
// Pointer lock management for walk mode on desktop (gaming controls only)
|
|
79667
|
-
events.on('cameraMode:changed', (value, prev) => {
|
|
79668
|
-
if (value === 'walk' && state.inputMode === 'desktop' && state.gamingControls) {
|
|
79669
|
-
activatePointerLock();
|
|
79670
|
-
}
|
|
79671
|
-
else if (prev === 'walk') {
|
|
79672
|
-
deactivatePointerLock();
|
|
79673
|
-
}
|
|
79674
|
-
updateCanvasCursor();
|
|
79675
|
-
});
|
|
79676
|
-
// Toggle pointer lock when gaming controls changes while in walk mode
|
|
79677
|
-
events.on('gamingControls:changed', (value) => {
|
|
79678
|
-
if (state.cameraMode === 'walk' && state.inputMode === 'desktop') {
|
|
79679
|
-
if (value) {
|
|
79680
|
-
activatePointerLock();
|
|
79681
|
-
}
|
|
79682
|
-
else {
|
|
79683
|
-
deactivatePointerLock();
|
|
79684
|
-
}
|
|
79685
|
-
}
|
|
79686
|
-
updateCanvasCursor();
|
|
79687
|
-
});
|
|
79688
|
-
document.addEventListener('pointerlockchange', () => {
|
|
79689
|
-
if (!document.pointerLockElement && state.cameraMode === 'walk' && state.gamingControls) {
|
|
79690
|
-
recentlyExitedWalk = true;
|
|
79691
|
-
requestAnimationFrame(() => {
|
|
79692
|
-
recentlyExitedWalk = false;
|
|
79693
|
-
});
|
|
79694
|
-
if (state.inputMode === 'desktop') {
|
|
79695
|
-
state.gamingControls = false;
|
|
79696
|
-
}
|
|
79697
|
-
else {
|
|
79698
|
-
events.fire('inputEvent', 'exitWalk');
|
|
79699
|
-
}
|
|
79700
|
-
}
|
|
79701
|
-
});
|
|
79702
|
-
// Pointer lock request rejected (e.g., no user gesture, document hidden).
|
|
79703
|
-
// Revert to avoid being stuck in walk mode without mouse capture.
|
|
79704
|
-
document.addEventListener('pointerlockerror', () => {
|
|
79705
|
-
this._desktopInput._pointerLock = false;
|
|
79706
|
-
if (state.inputMode === 'desktop') {
|
|
79707
|
-
state.gamingControls = false;
|
|
79708
|
-
}
|
|
79709
|
-
else {
|
|
79710
|
-
events.fire('inputEvent', 'exitWalk');
|
|
79711
|
-
}
|
|
79712
|
-
});
|
|
79713
|
-
}
|
|
79714
|
-
_pickCollision(offsetX, offsetY) {
|
|
79715
|
-
if (!this.collision)
|
|
79716
|
-
return null;
|
|
79717
|
-
const { camera } = this.global;
|
|
79718
|
-
const cameraPos = camera.getPosition();
|
|
79719
|
-
camera.camera.screenToWorld(offsetX, offsetY, 1.0, tmpV1);
|
|
79720
|
-
tmpV1.sub(cameraPos).normalize();
|
|
79721
|
-
const hit = this.collision.queryRay(cameraPos.x, cameraPos.y, cameraPos.z, tmpV1.x, tmpV1.y, tmpV1.z, camera.camera.farClip);
|
|
79722
|
-
if (!hit)
|
|
79723
|
-
return null;
|
|
79724
|
-
const sn = this.collision.querySurfaceNormal(hit.x, hit.y, hit.z, tmpV1.x, tmpV1.y, tmpV1.z);
|
|
79725
|
-
return {
|
|
79726
|
-
position: new Vec3(hit.x, hit.y, hit.z),
|
|
79727
|
-
normal: new Vec3(sn.nx, sn.ny, sn.nz)
|
|
79728
|
-
};
|
|
79729
|
-
}
|
|
79887
|
+
_source = new KeyboardMouseSource();
|
|
79888
|
+
_global = null;
|
|
79889
|
+
/** Running WASD/QE/arrow direction (sum of key states). */
|
|
79890
|
+
_axis = new Vec3();
|
|
79891
|
+
/** Running button-held state per index: [LMB, MMB, RMB]. */
|
|
79892
|
+
_buttons = [0, 0, 0];
|
|
79893
|
+
_shift = 0;
|
|
79894
|
+
_ctrl = 0;
|
|
79895
|
+
_jump = 0;
|
|
79730
79896
|
/**
|
|
79731
|
-
*
|
|
79732
|
-
*
|
|
79733
|
-
*
|
|
79734
|
-
*
|
|
79897
|
+
* Get the underlying source so other code (PointerLockManager) can
|
|
79898
|
+
* toggle its private pointer-lock flag, which gates how it consumes
|
|
79899
|
+
* mouse-delta events.
|
|
79900
|
+
*
|
|
79901
|
+
* @returns The PlayCanvas KeyboardMouseSource backing this device.
|
|
79735
79902
|
*/
|
|
79736
|
-
|
|
79903
|
+
get source() {
|
|
79904
|
+
return this._source;
|
|
79905
|
+
}
|
|
79906
|
+
attach(canvas, global) {
|
|
79907
|
+
this._global = global;
|
|
79908
|
+
patchKeyboardMeta(this._source);
|
|
79909
|
+
this._source.attach(canvas);
|
|
79910
|
+
}
|
|
79911
|
+
detach() {
|
|
79912
|
+
// KeyboardMouseSource does not expose a detach; nothing to undo for
|
|
79913
|
+
// its DOM listeners here.
|
|
79914
|
+
}
|
|
79915
|
+
update(ctx, frame) {
|
|
79737
79916
|
const { keyCode } = KeyboardMouseSource;
|
|
79738
|
-
const { key, button, mouse, wheel } = this.
|
|
79739
|
-
const {
|
|
79740
|
-
|
|
79741
|
-
|
|
79742
|
-
|
|
79743
|
-
|
|
79744
|
-
this.
|
|
79745
|
-
|
|
79746
|
-
|
|
79747
|
-
|
|
79748
|
-
this._state.mouse[i] += button[i];
|
|
79917
|
+
const { key, button, mouse, wheel } = this._source.read();
|
|
79918
|
+
const { events } = this._global;
|
|
79919
|
+
// accumulate running input state
|
|
79920
|
+
this._axis.add(tmpV1.set((key[keyCode.D] - key[keyCode.A]) + (key[keyCode.RIGHT] - key[keyCode.LEFT]), (key[keyCode.E] - key[keyCode.Q]), (key[keyCode.W] - key[keyCode.S]) + (key[keyCode.UP] - key[keyCode.DOWN])));
|
|
79921
|
+
this._jump += key[keyCode.SPACE];
|
|
79922
|
+
this._shift += key[keyCode.SHIFT];
|
|
79923
|
+
this._ctrl += key[keyCode.CTRL];
|
|
79924
|
+
const n = Math.min(button.length, this._buttons.length);
|
|
79925
|
+
for (let i = 0; i < n; i++) {
|
|
79926
|
+
this._buttons[i] += button[i];
|
|
79749
79927
|
}
|
|
79750
|
-
|
|
79751
|
-
|
|
79752
|
-
|
|
79753
|
-
// Cancel any active auto-walk when the user provides WASD/arrow input
|
|
79754
|
-
if (isWalk && (this._state.axis.x !== 0 || this._state.axis.z !== 0)) {
|
|
79928
|
+
const { isWalk, isFirstPerson, dt, distance, cameraComponent, mode, touchCount } = ctx;
|
|
79929
|
+
// walk-cancel and requestFirstPerson events (driven by WASD axis)
|
|
79930
|
+
if (isWalk && (this._axis.x !== 0 || this._axis.z !== 0)) {
|
|
79755
79931
|
events.fire('walkCancel');
|
|
79756
79932
|
}
|
|
79757
|
-
|
|
79933
|
+
if (!isFirstPerson && this._axis.length() > 0) {
|
|
79934
|
+
events.fire('inputEvent', 'requestFirstPerson');
|
|
79935
|
+
}
|
|
79936
|
+
// pan flag: RMB held, RMB just released this frame, or 2+ touches active
|
|
79937
|
+
const pan = this._buttons[2] || +(button[2] === -1) || +(touchCount > 1);
|
|
79938
|
+
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
79939
|
+
const { deltas } = frame;
|
|
79940
|
+
// move (WASD + mouse-drag pan + wheel)
|
|
79941
|
+
const v = tmpV1.set(0, 0, 0);
|
|
79942
|
+
keyMove.copy(this._axis);
|
|
79943
|
+
if (isWalk) {
|
|
79944
|
+
// In walk mode normalize only horizontal axes so jump doesn't
|
|
79945
|
+
// reduce horizontal speed.
|
|
79946
|
+
keyMove.y = 0;
|
|
79947
|
+
}
|
|
79948
|
+
keyMove.normalize();
|
|
79949
|
+
const shiftMul = isWalk ? 2 : 4;
|
|
79950
|
+
const ctrlMul = isWalk ? 0.5 : 0.25;
|
|
79951
|
+
const speed = this.moveSpeed * (this._shift ? shiftMul : this._ctrl ? ctrlMul : 1);
|
|
79952
|
+
v.add(keyMove.mulScalar((isFirstPerson ? 1 : 0) * speed * dt));
|
|
79953
|
+
if (isWalk) {
|
|
79954
|
+
// Pass jump signal as raw Y; WalkController uses move[1] > 0 as
|
|
79955
|
+
// a boolean trigger.
|
|
79956
|
+
v.y = this._jump > 0 ? 1 : 0;
|
|
79957
|
+
}
|
|
79958
|
+
screenToWorld(cameraComponent, mouse[0], mouse[1], distance, panMove);
|
|
79959
|
+
v.add(panMove.mulScalar(pan));
|
|
79960
|
+
wheelMove.set(0, 0, -wheel[0]);
|
|
79961
|
+
v.add(wheelMove.mulScalar(this.wheelSpeed * DISPLACEMENT_SCALE));
|
|
79962
|
+
deltas.move.append([v.x, v.y, flipZForOrbit(mode, v.z)]);
|
|
79963
|
+
// rotate (mouse-drag, masked when in pan mode)
|
|
79964
|
+
v.set(0, 0, 0);
|
|
79965
|
+
mouseRotate.set(mouse[0], mouse[1], 0);
|
|
79966
|
+
v.add(mouseRotate.mulScalar((1 - pan) * this.orbitSpeed * orbitFactor * this.mouseRotateSensitivity * DISPLACEMENT_SCALE));
|
|
79967
|
+
deltas.rotate.append([v.x, v.y, v.z]);
|
|
79968
|
+
}
|
|
79969
|
+
}
|
|
79970
|
+
|
|
79971
|
+
const tmpV$2 = new Vec3();
|
|
79972
|
+
const orbitMove = new Vec3();
|
|
79973
|
+
const flyMoveTmp = new Vec3();
|
|
79974
|
+
const flyTouchPan = new Vec3();
|
|
79975
|
+
const pinchMoveTmp = new Vec3();
|
|
79976
|
+
const orbitRotate = new Vec3();
|
|
79977
|
+
const flyRotate = new Vec3();
|
|
79978
|
+
class TouchDevice {
|
|
79979
|
+
orbitSpeed = 18;
|
|
79980
|
+
moveSpeed = 4;
|
|
79981
|
+
pinchSpeed = 0.4;
|
|
79982
|
+
touchRotateSensitivity = 1.5;
|
|
79983
|
+
touchPinchMoveSensitivity = 1.5;
|
|
79984
|
+
pinchVelocitySensitivity = 0.006;
|
|
79985
|
+
panVelocitySensitivity = 0.005;
|
|
79986
|
+
_source = new MultiTouchSource();
|
|
79987
|
+
_global = null;
|
|
79988
|
+
/** Touches currently active (running count from .read() deltas). */
|
|
79989
|
+
_touchCount = 0;
|
|
79990
|
+
/** UI joystick value [x, y], -1..1. */
|
|
79991
|
+
_joystick = [0, 0];
|
|
79992
|
+
/** Smoothed forward/back velocity from pinch gesture (-1..1). */
|
|
79993
|
+
_pinchVelocity = 0;
|
|
79994
|
+
/** Smoothed strafe/vertical velocity from two-finger pan, -1..1 each. */
|
|
79995
|
+
_panVelocity = [0, 0];
|
|
79996
|
+
/** Tap-detection state — touch count and accumulated finger movement. */
|
|
79997
|
+
_tapTouches = 0;
|
|
79998
|
+
_tapDelta = 0;
|
|
79999
|
+
/** True for one frame after a tap is detected during gaming controls. */
|
|
80000
|
+
_tapJump = false;
|
|
80001
|
+
_onJoystickInput = (value) => {
|
|
80002
|
+
this._joystick[0] = value.x;
|
|
80003
|
+
this._joystick[1] = value.y;
|
|
80004
|
+
};
|
|
80005
|
+
get touchCount() {
|
|
80006
|
+
return this._touchCount;
|
|
80007
|
+
}
|
|
80008
|
+
attach(canvas, global) {
|
|
80009
|
+
this._global = global;
|
|
80010
|
+
this._source.attach(canvas);
|
|
80011
|
+
global.events.on('joystickInput', this._onJoystickInput);
|
|
80012
|
+
}
|
|
80013
|
+
detach() {
|
|
80014
|
+
// MultiTouchSource doesn't expose a detach.
|
|
80015
|
+
if (this._global) {
|
|
80016
|
+
this._global.events.off('joystickInput', this._onJoystickInput);
|
|
80017
|
+
this._global = null;
|
|
80018
|
+
}
|
|
80019
|
+
}
|
|
80020
|
+
update(ctx, frame) {
|
|
80021
|
+
const { touch, pinch, count } = this._source.read();
|
|
80022
|
+
const { isWalk, isFirstPerson, isOrbit, gamingControls, dt, distance, cameraComponent } = ctx;
|
|
80023
|
+
// running touch count
|
|
80024
|
+
this._touchCount += count[0];
|
|
80025
|
+
// tap detection (walk mode only)
|
|
79758
80026
|
if (isWalk) {
|
|
79759
80027
|
const prevTaps = this._tapTouches;
|
|
79760
80028
|
this._tapTouches = Math.max(0, this._tapTouches + count[0]);
|
|
79761
|
-
// Touch just started (0 → 1+)
|
|
79762
80029
|
if (prevTaps === 0 && this._tapTouches > 0) {
|
|
79763
80030
|
this._tapDelta = 0;
|
|
79764
80031
|
}
|
|
79765
|
-
// Accumulate movement while touch is active
|
|
79766
80032
|
if (this._tapTouches > 0) {
|
|
79767
80033
|
const prevDelta = this._tapDelta;
|
|
79768
80034
|
this._tapDelta += Math.abs(touch[0]) + Math.abs(touch[1]);
|
|
79769
80035
|
if (prevDelta < TAP_EPSILON && this._tapDelta >= TAP_EPSILON) {
|
|
79770
|
-
if (!
|
|
79771
|
-
events.fire('walkCancel');
|
|
80036
|
+
if (!gamingControls) {
|
|
80037
|
+
this._global.events.fire('walkCancel');
|
|
79772
80038
|
}
|
|
79773
80039
|
}
|
|
79774
80040
|
}
|
|
79775
|
-
// Touch just ended (1+ → 0): check if it was a tap
|
|
79776
80041
|
if (prevTaps > 0 && this._tapTouches === 0) {
|
|
79777
80042
|
if (this._tapDelta < TAP_EPSILON) {
|
|
79778
|
-
if (!
|
|
79779
|
-
|
|
79780
|
-
|
|
79781
|
-
|
|
79782
|
-
}
|
|
80043
|
+
if (!gamingControls) {
|
|
80044
|
+
// Walk-interaction listens for this and fires walkTo
|
|
80045
|
+
// after picking.
|
|
80046
|
+
this._global.events.fire('mobileTap');
|
|
79783
80047
|
}
|
|
79784
80048
|
else {
|
|
79785
80049
|
this._tapJump = true;
|
|
@@ -79790,11 +80054,10 @@ class InputController {
|
|
|
79790
80054
|
else {
|
|
79791
80055
|
this._tapTouches = 0;
|
|
79792
80056
|
}
|
|
79793
|
-
|
|
79794
|
-
|
|
79795
|
-
|
|
79796
|
-
|
|
79797
|
-
if (isFirstPerson && !state.gamingControls && this._state.touches > 1) {
|
|
80057
|
+
// smoothed velocities for fly/walk first-person motion (non-gaming)
|
|
80058
|
+
if (isFirstPerson && !gamingControls && this._touchCount > 1) {
|
|
80059
|
+
// pinch[0] = oldDist - newDist: negative when spreading,
|
|
80060
|
+
// positive when closing. Spreading = forward → subtract.
|
|
79798
80061
|
this._pinchVelocity -= pinch[0] * this.pinchVelocitySensitivity;
|
|
79799
80062
|
this._pinchVelocity = math.clamp(this._pinchVelocity, -1, 1.0);
|
|
79800
80063
|
this._panVelocity[0] += touch[0] * this.panVelocitySensitivity;
|
|
@@ -79802,92 +80065,301 @@ class InputController {
|
|
|
79802
80065
|
this._panVelocity[1] += touch[1] * this.panVelocitySensitivity;
|
|
79803
80066
|
this._panVelocity[1] = math.clamp(this._panVelocity[1], -1, 1.0);
|
|
79804
80067
|
}
|
|
79805
|
-
else if (isFirstPerson && this.
|
|
80068
|
+
else if (isFirstPerson && this._touchCount <= 1) {
|
|
79806
80069
|
this._pinchVelocity = 0;
|
|
79807
80070
|
this._panVelocity[0] = 0;
|
|
79808
80071
|
this._panVelocity[1] = 0;
|
|
79809
80072
|
}
|
|
79810
|
-
|
|
79811
|
-
|
|
79812
|
-
|
|
79813
|
-
const
|
|
79814
|
-
const
|
|
79815
|
-
const
|
|
79816
|
-
|
|
79817
|
-
const
|
|
79818
|
-
|
|
79819
|
-
|
|
79820
|
-
|
|
79821
|
-
|
|
79822
|
-
|
|
79823
|
-
|
|
79824
|
-
|
|
79825
|
-
keyMove.y = 0;
|
|
79826
|
-
}
|
|
79827
|
-
keyMove.normalize();
|
|
79828
|
-
const shiftMul = isWalk ? 2 : 4;
|
|
79829
|
-
const ctrlMul = isWalk ? 0.5 : 0.25;
|
|
79830
|
-
const speed = this.moveSpeed * (this._state.shift ? shiftMul : this._state.ctrl ? ctrlMul : 1);
|
|
79831
|
-
v.add(keyMove.mulScalar(fly * speed * dt));
|
|
79832
|
-
if (isWalk) {
|
|
79833
|
-
// Pass jump signal as raw Y; WalkController uses move[1] > 0 as boolean trigger
|
|
79834
|
-
v.y = this._state.jump > 0 ? 1 : 0;
|
|
79835
|
-
}
|
|
79836
|
-
const panMove = screenToWorld(camera, mouse[0], mouse[1], distance);
|
|
79837
|
-
v.add(panMove.mulScalar(pan));
|
|
79838
|
-
const wheelMove = new Vec3(0, 0, -wheel[0]);
|
|
79839
|
-
v.add(wheelMove.mulScalar(this.wheelSpeed * DISPLACEMENT_SCALE));
|
|
79840
|
-
// FIXME: need to flip z axis for orbit camera
|
|
79841
|
-
deltas.move.append([v.x, v.y, orbit ? -v.z : v.z]);
|
|
79842
|
-
// desktop rotate
|
|
79843
|
-
v.set(0, 0, 0);
|
|
79844
|
-
mouseRotate.set(mouse[0], mouse[1], 0);
|
|
79845
|
-
v.add(mouseRotate.mulScalar((1 - pan) * this.orbitSpeed * orbitFactor * this.mouseRotateSensitivity * DISPLACEMENT_SCALE));
|
|
79846
|
-
deltas.rotate.append([v.x, v.y, v.z]);
|
|
79847
|
-
// mobile move
|
|
79848
|
-
v.set(0, 0, 0);
|
|
79849
|
-
const orbitMove = screenToWorld(camera, touch[0], touch[1], distance);
|
|
79850
|
-
v.add(orbitMove.mulScalar(orbit * pan));
|
|
79851
|
-
if (state.gamingControls) {
|
|
79852
|
-
// Use touch joystick values for fly movement (X = strafe, Y = forward/backward)
|
|
79853
|
-
flyMove.set(this._touchJoystick[0], 0, -this._touchJoystick[1]);
|
|
79854
|
-
v.add(flyMove.mulScalar(fly * this.moveSpeed * dt));
|
|
80073
|
+
const orbit = isOrbit ? 1 : 0;
|
|
80074
|
+
const fly = isFirstPerson ? 1 : 0;
|
|
80075
|
+
const double = this._touchCount > 1 ? 1 : 0;
|
|
80076
|
+
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
80077
|
+
const dragInvert = (isFirstPerson && !gamingControls) ? -1 : 1;
|
|
80078
|
+
const { deltas } = frame;
|
|
80079
|
+
// move
|
|
80080
|
+
const v = tmpV$2.set(0, 0, 0);
|
|
80081
|
+
// two-finger orbit-pan when in orbit mode (single touch is rotate, double is pan)
|
|
80082
|
+
screenToWorld(cameraComponent, touch[0], touch[1], distance, orbitMove);
|
|
80083
|
+
v.add(orbitMove.mulScalar(orbit * double));
|
|
80084
|
+
if (gamingControls) {
|
|
80085
|
+
// joystick UI drives strafe + forward/back in fly/walk
|
|
80086
|
+
flyMoveTmp.set(this._joystick[0], 0, -this._joystick[1]);
|
|
80087
|
+
v.add(flyMoveTmp.mulScalar(fly * this.moveSpeed * dt));
|
|
79855
80088
|
}
|
|
79856
80089
|
else {
|
|
79857
|
-
//
|
|
80090
|
+
// smoothed pan velocity → strafe (X) and vertical (Y, fly only)
|
|
79858
80091
|
flyTouchPan.set(this._panVelocity[0], isWalk ? 0 : -this._panVelocity[1], 0);
|
|
79859
80092
|
v.add(flyTouchPan.mulScalar(fly * this.touchPinchMoveSensitivity * this.moveSpeed * dt));
|
|
79860
|
-
//
|
|
79861
|
-
|
|
79862
|
-
v.add(
|
|
80093
|
+
// smoothed pinch velocity → forward/back
|
|
80094
|
+
flyMoveTmp.set(0, 0, this._pinchVelocity);
|
|
80095
|
+
v.add(flyMoveTmp.mulScalar(fly * this.touchPinchMoveSensitivity * this.moveSpeed * dt));
|
|
79863
80096
|
}
|
|
79864
|
-
|
|
79865
|
-
|
|
79866
|
-
|
|
80097
|
+
// raw pinch for orbit-mode zoom
|
|
80098
|
+
pinchMoveTmp.set(0, 0, pinch[0]);
|
|
80099
|
+
v.add(pinchMoveTmp.mulScalar(orbit * double * this.pinchSpeed * DISPLACEMENT_SCALE));
|
|
80100
|
+
// tap-to-jump in walk + gaming controls
|
|
79867
80101
|
if (isWalk && this._tapJump) {
|
|
79868
80102
|
v.y = 1;
|
|
79869
80103
|
this._tapJump = false;
|
|
79870
80104
|
}
|
|
79871
80105
|
deltas.move.append([v.x, v.y, v.z]);
|
|
79872
|
-
//
|
|
80106
|
+
// rotate
|
|
79873
80107
|
v.set(0, 0, 0);
|
|
80108
|
+
// single-touch orbit rotate (masked when there are 2+ touches)
|
|
79874
80109
|
orbitRotate.set(touch[0], touch[1], 0);
|
|
79875
|
-
v.add(orbitRotate.mulScalar(orbit * (1 -
|
|
79876
|
-
//
|
|
79877
|
-
// Exclude multi-touch (double) to avoid interference with pinch/strafe gestures
|
|
80110
|
+
v.add(orbitRotate.mulScalar(orbit * (1 - double) * this.orbitSpeed * this.touchRotateSensitivity * DISPLACEMENT_SCALE));
|
|
80111
|
+
// single-touch fly look (inverted in non-gaming first-person)
|
|
79878
80112
|
flyRotate.set(touch[0] * dragInvert, touch[1] * dragInvert, 0);
|
|
79879
80113
|
v.add(flyRotate.mulScalar(fly * (1 - double) * this.orbitSpeed * orbitFactor * this.touchRotateSensitivity * DISPLACEMENT_SCALE));
|
|
79880
80114
|
deltas.rotate.append([v.x, v.y, v.z]);
|
|
79881
|
-
|
|
79882
|
-
|
|
79883
|
-
|
|
79884
|
-
|
|
79885
|
-
|
|
79886
|
-
|
|
79887
|
-
|
|
79888
|
-
|
|
79889
|
-
|
|
79890
|
-
|
|
80115
|
+
}
|
|
80116
|
+
}
|
|
80117
|
+
|
|
80118
|
+
/**
|
|
80119
|
+
* Distinguishes a physical mouse wheel from a trackpad two-finger scroll.
|
|
80120
|
+
*
|
|
80121
|
+
* A single wheel event is unreliable (Magic Mouse, hi-res mice, and macOS
|
|
80122
|
+
* Shift-remapping all confuse per-event heuristics), so classify on the
|
|
80123
|
+
* first event of a burst and let the rest of the burst inherit that label.
|
|
80124
|
+
* A burst is a run of wheel events separated by less than BURST_GAP_MS;
|
|
80125
|
+
* trackpads stream at ~60Hz (~16ms), wheels emit one event per notch
|
|
80126
|
+
* (typically >>50ms apart).
|
|
80127
|
+
*/
|
|
80128
|
+
const BURST_GAP_MS = 80;
|
|
80129
|
+
const isMouseWheelEvent = (event) => {
|
|
80130
|
+
// Firefox: physical wheels report line/page mode; trackpads report
|
|
80131
|
+
// pixel mode. Firefox doesn't expose wheelDelta* so this is the only
|
|
80132
|
+
// reliable signal there.
|
|
80133
|
+
if (event.deltaMode !== WheelEvent.DOM_DELTA_PIXEL) {
|
|
80134
|
+
return true;
|
|
80135
|
+
}
|
|
80136
|
+
// Chrome / Safari: the non-standard wheelDelta{X,Y} properties preserve
|
|
80137
|
+
// the raw wheel-tick value (always multiples of ±120 per notch)
|
|
80138
|
+
// regardless of macOS scroll smoothing. Trackpads and Magic Mouse emit
|
|
80139
|
+
// arbitrary values that are essentially never aligned to 120.
|
|
80140
|
+
const e = event;
|
|
80141
|
+
if (typeof e.wheelDeltaY === 'number' && e.wheelDeltaY !== 0) {
|
|
80142
|
+
return e.wheelDeltaY % 120 === 0;
|
|
80143
|
+
}
|
|
80144
|
+
if (typeof e.wheelDeltaX === 'number' && e.wheelDeltaX !== 0) {
|
|
80145
|
+
return e.wheelDeltaX % 120 === 0;
|
|
80146
|
+
}
|
|
80147
|
+
// Last-resort fallback for browsers without wheelDelta*.
|
|
80148
|
+
const { deltaX, deltaY } = event;
|
|
80149
|
+
if (deltaX !== 0 && deltaY !== 0) {
|
|
80150
|
+
return false;
|
|
80151
|
+
}
|
|
80152
|
+
return Number.isInteger(deltaX) && Number.isInteger(deltaY);
|
|
80153
|
+
};
|
|
80154
|
+
class WheelClassifier {
|
|
80155
|
+
_lastTime = -Infinity;
|
|
80156
|
+
_burstIsMouseWheel = false;
|
|
80157
|
+
/**
|
|
80158
|
+
* Classify the given event. The first event of a burst sets the label
|
|
80159
|
+
* for the burst; subsequent events within BURST_GAP_MS inherit it.
|
|
80160
|
+
*
|
|
80161
|
+
* @param event - The wheel event to classify.
|
|
80162
|
+
* @returns True if the event came from a physical mouse wheel.
|
|
80163
|
+
*/
|
|
80164
|
+
classify(event) {
|
|
80165
|
+
const now = performance.now();
|
|
80166
|
+
if (now - this._lastTime > BURST_GAP_MS) {
|
|
80167
|
+
this._burstIsMouseWheel = isMouseWheelEvent(event);
|
|
80168
|
+
}
|
|
80169
|
+
this._lastTime = now;
|
|
80170
|
+
return this._burstIsMouseWheel;
|
|
80171
|
+
}
|
|
80172
|
+
}
|
|
80173
|
+
|
|
80174
|
+
const tmpV$1 = new Vec3();
|
|
80175
|
+
class TrackpadDevice {
|
|
80176
|
+
orbitSpeed = 18;
|
|
80177
|
+
wheelSpeed = 0.06;
|
|
80178
|
+
trackpadOrbitSensitivity = 0.75;
|
|
80179
|
+
trackpadPanSensitivity = 1.0;
|
|
80180
|
+
trackpadZoomSensitivity = 2.0;
|
|
80181
|
+
_classifier = new WheelClassifier();
|
|
80182
|
+
_global = null;
|
|
80183
|
+
_orbit = [0, 0];
|
|
80184
|
+
_pan = [0, 0];
|
|
80185
|
+
_zoom = 0;
|
|
80186
|
+
_onWheel = (event) => {
|
|
80187
|
+
if (this._classifier.classify(event)) {
|
|
80188
|
+
// physical mouse wheel — KeyboardMouseSource handles it
|
|
80189
|
+
return;
|
|
80190
|
+
}
|
|
80191
|
+
const mode = this._global.state.cameraMode;
|
|
80192
|
+
const isFirstPersonMode = mode === 'fly' || mode === 'walk';
|
|
80193
|
+
const hasZoomModifier = event.ctrlKey || event.metaKey;
|
|
80194
|
+
if (mode === 'orbit') ;
|
|
80195
|
+
else if (isFirstPersonMode && !hasZoomModifier) ;
|
|
80196
|
+
else {
|
|
80197
|
+
return;
|
|
80198
|
+
}
|
|
80199
|
+
event.preventDefault();
|
|
80200
|
+
// stopImmediatePropagation() blocks KeyboardMouseSource's wheel
|
|
80201
|
+
// handler (also attached to this canvas) so the wheel delta
|
|
80202
|
+
// doesn't double-up on the existing forward/back path. It also
|
|
80203
|
+
// blocks the canvas-level interrupt listener registered elsewhere,
|
|
80204
|
+
// so fire interrupt explicitly to keep parity with mouse-wheel.
|
|
80205
|
+
event.stopImmediatePropagation();
|
|
80206
|
+
this._global.events.fire('inputEvent', 'interrupt', event);
|
|
80207
|
+
const { deltaX, deltaY } = event;
|
|
80208
|
+
if (mode === 'orbit') {
|
|
80209
|
+
if (event.ctrlKey || event.metaKey) {
|
|
80210
|
+
// pinch on macOS arrives as ctrl+wheel; ctrl/meta+scroll routes here too
|
|
80211
|
+
this._zoom += deltaY;
|
|
80212
|
+
}
|
|
80213
|
+
else if (event.shiftKey) {
|
|
80214
|
+
this._pan[0] += deltaX;
|
|
80215
|
+
this._pan[1] += deltaY;
|
|
80216
|
+
}
|
|
80217
|
+
else {
|
|
80218
|
+
this._orbit[0] += deltaX;
|
|
80219
|
+
this._orbit[1] += deltaY;
|
|
80220
|
+
}
|
|
80221
|
+
}
|
|
80222
|
+
else {
|
|
80223
|
+
// fly / walk: always rotate (shift is a speed modifier, not a gesture)
|
|
80224
|
+
this._orbit[0] += deltaX;
|
|
80225
|
+
this._orbit[1] += deltaY;
|
|
80226
|
+
}
|
|
80227
|
+
};
|
|
80228
|
+
_canvas = null;
|
|
80229
|
+
/**
|
|
80230
|
+
* Trackpad must attach BEFORE KeyboardMouseSource so its
|
|
80231
|
+
* `stopImmediatePropagation()` blocks the mouse-source wheel handler
|
|
80232
|
+
* for trackpad bursts. The coordinator enforces this by attaching
|
|
80233
|
+
* trackpad before keyboard-mouse.
|
|
80234
|
+
*
|
|
80235
|
+
* @param canvas - The canvas element to listen to.
|
|
80236
|
+
* @param global - The global app context (state, events, etc.).
|
|
80237
|
+
*/
|
|
80238
|
+
attach(canvas, global) {
|
|
80239
|
+
this._canvas = canvas;
|
|
80240
|
+
this._global = global;
|
|
80241
|
+
canvas.addEventListener('wheel', this._onWheel, { passive: false });
|
|
80242
|
+
}
|
|
80243
|
+
detach() {
|
|
80244
|
+
if (this._canvas) {
|
|
80245
|
+
this._canvas.removeEventListener('wheel', this._onWheel);
|
|
80246
|
+
this._canvas = null;
|
|
80247
|
+
}
|
|
80248
|
+
this._global = null;
|
|
80249
|
+
this._orbit[0] = this._orbit[1] = 0;
|
|
80250
|
+
this._pan[0] = this._pan[1] = 0;
|
|
80251
|
+
this._zoom = 0;
|
|
80252
|
+
}
|
|
80253
|
+
update(ctx, frame) {
|
|
80254
|
+
const { isOrbit, isFirstPerson, distance, cameraComponent } = ctx;
|
|
80255
|
+
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
80256
|
+
const { deltas } = frame;
|
|
80257
|
+
if (isOrbit) {
|
|
80258
|
+
// orbit rotate
|
|
80259
|
+
const v = tmpV$1.set(this._orbit[0], this._orbit[1], 0);
|
|
80260
|
+
v.mulScalar(this.orbitSpeed * this.trackpadOrbitSensitivity * DISPLACEMENT_SCALE);
|
|
80261
|
+
deltas.rotate.append([v.x, v.y, 0]);
|
|
80262
|
+
// pan in world space (matches desktop pan path); reuse tmpV after rotate append
|
|
80263
|
+
screenToWorld(cameraComponent, this._pan[0], this._pan[1], distance, tmpV$1);
|
|
80264
|
+
tmpV$1.mulScalar(this.trackpadPanSensitivity);
|
|
80265
|
+
deltas.move.append([tmpV$1.x, tmpV$1.y, 0]);
|
|
80266
|
+
// zoom along z; positive deltaY (scroll-down / pinch-in) → zoom out → +z for orbit
|
|
80267
|
+
const zoomZ = this._zoom * this.wheelSpeed * this.trackpadZoomSensitivity * DISPLACEMENT_SCALE;
|
|
80268
|
+
deltas.move.append([0, 0, zoomZ]);
|
|
80269
|
+
}
|
|
80270
|
+
else if (isFirstPerson) {
|
|
80271
|
+
// fly / walk look-around (only the no-modifier swipe is captured;
|
|
80272
|
+
// pinch / Ctrl-swipe fall through to the wheel→forward path)
|
|
80273
|
+
const v = tmpV$1.set(this._orbit[0], this._orbit[1], 0);
|
|
80274
|
+
v.mulScalar(this.orbitSpeed * orbitFactor * this.trackpadOrbitSensitivity * DISPLACEMENT_SCALE);
|
|
80275
|
+
deltas.rotate.append([v.x, v.y, 0]);
|
|
80276
|
+
}
|
|
80277
|
+
this._orbit[0] = this._orbit[1] = 0;
|
|
80278
|
+
this._pan[0] = this._pan[1] = 0;
|
|
80279
|
+
this._zoom = 0;
|
|
80280
|
+
}
|
|
80281
|
+
}
|
|
80282
|
+
|
|
80283
|
+
/**
|
|
80284
|
+
* Coordinator that wires together input devices (keyboard-mouse, touch,
|
|
80285
|
+
* trackpad, gamepad) and app-level UX helpers (mode shortcuts, walk
|
|
80286
|
+
* interaction, pointer lock, input-mode tracker), and exposes the
|
|
80287
|
+
* resulting per-frame `InputFrame` for the camera manager to consume.
|
|
80288
|
+
*/
|
|
80289
|
+
class InputController {
|
|
80290
|
+
frame = new InputFrame({
|
|
80291
|
+
move: [0, 0, 0],
|
|
80292
|
+
rotate: [0, 0, 0]
|
|
80293
|
+
});
|
|
80294
|
+
_global;
|
|
80295
|
+
_trackpad = new TrackpadDevice();
|
|
80296
|
+
_keyboardMouse = new KeyboardMouseDevice();
|
|
80297
|
+
_touch = new TouchDevice();
|
|
80298
|
+
_gamepad = new GamepadDevice();
|
|
80299
|
+
_walkInteraction = new WalkInteraction();
|
|
80300
|
+
_pointerLock = new PointerLockManager();
|
|
80301
|
+
_modeShortcuts = new ModeShortcuts();
|
|
80302
|
+
_inputModeTracker = new InputModeTracker();
|
|
80303
|
+
set collision(value) {
|
|
80304
|
+
this._walkInteraction.collision = value;
|
|
80305
|
+
}
|
|
80306
|
+
get collision() {
|
|
80307
|
+
return this._walkInteraction.collision;
|
|
80308
|
+
}
|
|
80309
|
+
constructor(global) {
|
|
80310
|
+
this._global = global;
|
|
80311
|
+
const { app, events } = global;
|
|
80312
|
+
const canvas = app.graphicsDevice.canvas;
|
|
80313
|
+
// Trackpad MUST attach before KeyboardMouseDevice so its wheel
|
|
80314
|
+
// handler runs first; otherwise stopImmediatePropagation can't
|
|
80315
|
+
// block KeyboardMouseSource from also accumulating the wheel delta.
|
|
80316
|
+
this._trackpad.attach(canvas, global);
|
|
80317
|
+
this._keyboardMouse.attach(canvas, global);
|
|
80318
|
+
this._touch.attach(canvas, global);
|
|
80319
|
+
this._gamepad.attach(canvas, global);
|
|
80320
|
+
this._walkInteraction.attach(canvas, global);
|
|
80321
|
+
this._pointerLock.attach(canvas, global, this._keyboardMouse);
|
|
80322
|
+
this._modeShortcuts.attach(global, this._pointerLock);
|
|
80323
|
+
this._inputModeTracker.attach(global);
|
|
80324
|
+
// canvas-level signals: anything that interrupts an animation /
|
|
80325
|
+
// closes the settings panel / dismisses the walk hint
|
|
80326
|
+
['wheel', 'pointerdown', 'contextmenu', 'keydown'].forEach((eventName) => {
|
|
80327
|
+
canvas.addEventListener(eventName, (event) => {
|
|
80328
|
+
events.fire('inputEvent', 'interrupt', event);
|
|
80329
|
+
});
|
|
80330
|
+
});
|
|
80331
|
+
canvas.addEventListener('pointermove', (event) => {
|
|
80332
|
+
events.fire('inputEvent', 'interact', event);
|
|
80333
|
+
});
|
|
80334
|
+
}
|
|
80335
|
+
update(dt, distance) {
|
|
80336
|
+
const { state } = this._global;
|
|
80337
|
+
const cameraComponent = this._global.camera.camera;
|
|
80338
|
+
const isOrbit = state.cameraMode === 'orbit';
|
|
80339
|
+
const isFly = state.cameraMode === 'fly';
|
|
80340
|
+
const isWalk = state.cameraMode === 'walk';
|
|
80341
|
+
const isFirstPerson = isFly || isWalk;
|
|
80342
|
+
const ctx = {
|
|
80343
|
+
dt,
|
|
80344
|
+
distance,
|
|
80345
|
+
cameraComponent,
|
|
80346
|
+
mode: state.cameraMode,
|
|
80347
|
+
isOrbit,
|
|
80348
|
+
isFly,
|
|
80349
|
+
isWalk,
|
|
80350
|
+
isFirstPerson,
|
|
80351
|
+
gamingControls: state.gamingControls,
|
|
80352
|
+
// Touch must update first so the count is current; the running
|
|
80353
|
+
// count is also used by the keyboard-mouse pan flag.
|
|
80354
|
+
touchCount: this._touch.touchCount
|
|
80355
|
+
};
|
|
80356
|
+
// order: touch first (so touchCount in ctx reflects this frame's
|
|
80357
|
+
// count delta), then everyone else.
|
|
80358
|
+
this._touch.update(ctx, this.frame);
|
|
80359
|
+
ctx.touchCount = this._touch.touchCount;
|
|
80360
|
+
this._keyboardMouse.update(ctx, this.frame);
|
|
80361
|
+
this._trackpad.update(ctx, this.frame);
|
|
80362
|
+
this._gamepad.update(ctx, this.frame);
|
|
79891
80363
|
}
|
|
79892
80364
|
}
|
|
79893
80365
|
|
|
@@ -82096,7 +82568,7 @@ const initXr = (global) => {
|
|
|
82096
82568
|
});
|
|
82097
82569
|
};
|
|
82098
82570
|
|
|
82099
|
-
var version = "1.20.
|
|
82571
|
+
var version = "1.20.3";
|
|
82100
82572
|
|
|
82101
82573
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
82102
82574
|
const { contents, contentUrl, aa } = config;
|
|
@@ -82174,7 +82646,7 @@ const createApp = async (canvas, config) => {
|
|
|
82174
82646
|
const app = new App(canvas, {
|
|
82175
82647
|
graphicsDevice: device,
|
|
82176
82648
|
mouse: new Mouse(canvas),
|
|
82177
|
-
touch: new TouchDevice(canvas),
|
|
82649
|
+
touch: new TouchDevice$1(canvas),
|
|
82178
82650
|
keyboard: new Keyboard(window)
|
|
82179
82651
|
});
|
|
82180
82652
|
// Create entity hierarchy
|