@playcanvas/supersplat-viewer 1.20.2 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/package.json +5 -5
- package/public/index.css +3 -1
- package/public/index.html +1 -1
- package/public/index.js +1234 -467
- 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];
|
|
@@ -3684,6 +3684,7 @@ const FILTER_NEAREST_MIPMAP_LINEAR = 3;
|
|
|
3684
3684
|
const FILTER_LINEAR_MIPMAP_NEAREST = 4;
|
|
3685
3685
|
const FILTER_LINEAR_MIPMAP_LINEAR = 5;
|
|
3686
3686
|
const FUNC_LESS = 1;
|
|
3687
|
+
const FUNC_EQUAL = 2;
|
|
3687
3688
|
const FUNC_LESSEQUAL = 3;
|
|
3688
3689
|
const FUNC_ALWAYS = 7;
|
|
3689
3690
|
const INDEXFORMAT_UINT8 = 0;
|
|
@@ -7237,7 +7238,7 @@ class WebgpuBindGroupFormat {
|
|
|
7237
7238
|
class WebgpuBuffer {
|
|
7238
7239
|
destroy(device) {
|
|
7239
7240
|
if (this.buffer) {
|
|
7240
|
-
this.buffer
|
|
7241
|
+
device.deferDestroy(this.buffer);
|
|
7241
7242
|
this.buffer = null;
|
|
7242
7243
|
}
|
|
7243
7244
|
}
|
|
@@ -16172,7 +16173,7 @@ Keyboard.EVENT_KEYUP = 'keyup';
|
|
|
16172
16173
|
function isMousePointerLocked() {
|
|
16173
16174
|
return !!(document.pointerLockElement || document.mozPointerLockElement || document.webkitPointerLockElement);
|
|
16174
16175
|
}
|
|
16175
|
-
class MouseEvent {
|
|
16176
|
+
let MouseEvent$1 = class MouseEvent {
|
|
16176
16177
|
constructor(mouse, event){
|
|
16177
16178
|
this.x = 0;
|
|
16178
16179
|
this.y = 0;
|
|
@@ -16230,7 +16231,7 @@ class MouseEvent {
|
|
|
16230
16231
|
this.metaKey = event.metaKey ?? false;
|
|
16231
16232
|
this.event = event;
|
|
16232
16233
|
}
|
|
16233
|
-
}
|
|
16234
|
+
};
|
|
16234
16235
|
|
|
16235
16236
|
class Mouse extends EventHandler {
|
|
16236
16237
|
static isPointerLocked() {
|
|
@@ -16322,25 +16323,25 @@ class Mouse extends EventHandler {
|
|
|
16322
16323
|
}
|
|
16323
16324
|
_handleUp(event) {
|
|
16324
16325
|
this._buttons[event.button] = false;
|
|
16325
|
-
const e = new MouseEvent(this, event);
|
|
16326
|
+
const e = new MouseEvent$1(this, event);
|
|
16326
16327
|
if (!e.event) return;
|
|
16327
16328
|
this.fire('mouseup', e);
|
|
16328
16329
|
}
|
|
16329
16330
|
_handleDown(event) {
|
|
16330
16331
|
this._buttons[event.button] = true;
|
|
16331
|
-
const e = new MouseEvent(this, event);
|
|
16332
|
+
const e = new MouseEvent$1(this, event);
|
|
16332
16333
|
if (!e.event) return;
|
|
16333
16334
|
this.fire('mousedown', e);
|
|
16334
16335
|
}
|
|
16335
16336
|
_handleMove(event) {
|
|
16336
|
-
const e = new MouseEvent(this, event);
|
|
16337
|
+
const e = new MouseEvent$1(this, event);
|
|
16337
16338
|
if (!e.event) return;
|
|
16338
16339
|
this.fire('mousemove', e);
|
|
16339
16340
|
this._lastX = e.x;
|
|
16340
16341
|
this._lastY = e.y;
|
|
16341
16342
|
}
|
|
16342
16343
|
_handleWheel(event) {
|
|
16343
|
-
const e = new MouseEvent(this, event);
|
|
16344
|
+
const e = new MouseEvent$1(this, event);
|
|
16344
16345
|
if (!e.event) return;
|
|
16345
16346
|
this.fire('mousewheel', e);
|
|
16346
16347
|
}
|
|
@@ -16422,7 +16423,7 @@ class TouchEvent {
|
|
|
16422
16423
|
}
|
|
16423
16424
|
}
|
|
16424
16425
|
|
|
16425
|
-
class TouchDevice extends EventHandler {
|
|
16426
|
+
let TouchDevice$1 = class TouchDevice extends EventHandler {
|
|
16426
16427
|
attach(element) {
|
|
16427
16428
|
if (this._element) {
|
|
16428
16429
|
this.detach();
|
|
@@ -16464,11 +16465,11 @@ class TouchDevice extends EventHandler {
|
|
|
16464
16465
|
this._cancelHandler = this._handleTouchCancel.bind(this);
|
|
16465
16466
|
this.attach(element);
|
|
16466
16467
|
}
|
|
16467
|
-
}
|
|
16468
|
-
TouchDevice.EVENT_TOUCHSTART = 'touchstart';
|
|
16469
|
-
TouchDevice.EVENT_TOUCHEND = 'touchend';
|
|
16470
|
-
TouchDevice.EVENT_TOUCHMOVE = 'touchmove';
|
|
16471
|
-
TouchDevice.EVENT_TOUCHCANCEL = 'touchcancel';
|
|
16468
|
+
};
|
|
16469
|
+
TouchDevice$1.EVENT_TOUCHSTART = 'touchstart';
|
|
16470
|
+
TouchDevice$1.EVENT_TOUCHEND = 'touchend';
|
|
16471
|
+
TouchDevice$1.EVENT_TOUCHMOVE = 'touchmove';
|
|
16472
|
+
TouchDevice$1.EVENT_TOUCHCANCEL = 'touchcancel';
|
|
16472
16473
|
|
|
16473
16474
|
class Http {
|
|
16474
16475
|
get(url, options, callback) {
|
|
@@ -70115,7 +70116,7 @@ let Picker$1 = class Picker {
|
|
|
70115
70116
|
return null;
|
|
70116
70117
|
}
|
|
70117
70118
|
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];
|
|
70119
|
+
const intBits = (pixels[0] << 24 | pixels[1] << 16 | pixels[2] << 8 | pixels[3]) >>> 0;
|
|
70119
70120
|
if (intBits === 0xFFFFFFFF) {
|
|
70120
70121
|
return null;
|
|
70121
70122
|
}
|
|
@@ -75351,6 +75352,16 @@ class MeshCollision {
|
|
|
75351
75352
|
this._tris = tris;
|
|
75352
75353
|
this._root = buildBVH(tris, 0, numTris);
|
|
75353
75354
|
}
|
|
75355
|
+
// ---- Public accessors ----
|
|
75356
|
+
/**
|
|
75357
|
+
* Read-only view of the de-indexed triangle data, used by debug overlays.
|
|
75358
|
+
* The underlying typed arrays are reused and must not be mutated.
|
|
75359
|
+
*
|
|
75360
|
+
* @returns the triangle SoA backing this collision.
|
|
75361
|
+
*/
|
|
75362
|
+
get triangles() {
|
|
75363
|
+
return this._tris;
|
|
75364
|
+
}
|
|
75354
75365
|
// ---- Collision interface ----
|
|
75355
75366
|
queryRay(ox, oy, oz, dx, dy, dz, maxDist) {
|
|
75356
75367
|
const len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
@@ -76909,7 +76920,7 @@ const initUI = (global) => {
|
|
|
76909
76920
|
'reset', 'frame',
|
|
76910
76921
|
'loadingText', 'loadingBar',
|
|
76911
76922
|
'joystickBase', 'joystick',
|
|
76912
|
-
'
|
|
76923
|
+
'showCollision',
|
|
76913
76924
|
'tooltip',
|
|
76914
76925
|
'annotationNav', 'annotationPrev', 'annotationNext', 'annotationInfo', 'annotationNavTitle',
|
|
76915
76926
|
'supersplatBranding'
|
|
@@ -76922,11 +76933,22 @@ const initUI = (global) => {
|
|
|
76922
76933
|
document.activeElement?.blur();
|
|
76923
76934
|
});
|
|
76924
76935
|
// 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)
|
|
76936
|
+
// instead of the page scrolling (e.g. annotation nav, tooltips, hotspots).
|
|
76937
|
+
// The non-standard wheelDelta{X,Y} properties aren't part of WheelEventInit,
|
|
76938
|
+
// so they get dropped by `new WheelEvent(type, init)`. We re-attach them so
|
|
76939
|
+
// the trackpad-vs-mouse classifier in input-controller.ts behaves the same
|
|
76940
|
+
// whether the event originated on the canvas or was forwarded from the UI.
|
|
76926
76941
|
const canvas = global.app.graphicsDevice.canvas;
|
|
76927
76942
|
dom.ui.addEventListener('wheel', (event) => {
|
|
76928
76943
|
event.preventDefault();
|
|
76929
|
-
|
|
76944
|
+
const forwarded = new WheelEvent(event.type, event);
|
|
76945
|
+
const src = event;
|
|
76946
|
+
for (const key of ['wheelDelta', 'wheelDeltaX', 'wheelDeltaY']) {
|
|
76947
|
+
if (typeof src[key] === 'number') {
|
|
76948
|
+
Object.defineProperty(forwarded, key, { value: src[key], configurable: true });
|
|
76949
|
+
}
|
|
76950
|
+
}
|
|
76951
|
+
canvas.dispatchEvent(forwarded);
|
|
76930
76952
|
}, { passive: false });
|
|
76931
76953
|
// Handle loading progress updates
|
|
76932
76954
|
events.on('progress:changed', (progress) => {
|
|
@@ -77220,15 +77242,15 @@ const initUI = (global) => {
|
|
|
77220
77242
|
dom.flyCamera.classList.toggle('middle', value);
|
|
77221
77243
|
dom.flyCamera.classList.toggle('right', !value);
|
|
77222
77244
|
});
|
|
77223
|
-
//
|
|
77224
|
-
events.on('
|
|
77225
|
-
dom.
|
|
77245
|
+
// Collision overlay toggle (only visible when overlay is available)
|
|
77246
|
+
events.on('hasCollisionOverlay:changed', (value) => {
|
|
77247
|
+
dom.showCollision.classList.toggle('hidden', !value);
|
|
77226
77248
|
});
|
|
77227
|
-
dom.
|
|
77228
|
-
state.
|
|
77249
|
+
dom.showCollision.addEventListener('click', () => {
|
|
77250
|
+
state.collisionOverlayEnabled = !state.collisionOverlayEnabled;
|
|
77229
77251
|
});
|
|
77230
|
-
events.on('
|
|
77231
|
-
dom.
|
|
77252
|
+
events.on('collisionOverlayEnabled:changed', (value) => {
|
|
77253
|
+
dom.showCollision.classList.toggle('active', value);
|
|
77232
77254
|
});
|
|
77233
77255
|
dom.settings.addEventListener('click', () => {
|
|
77234
77256
|
dom.settingsPanel.classList.toggle('hidden');
|
|
@@ -77265,7 +77287,7 @@ const initUI = (global) => {
|
|
|
77265
77287
|
tooltip.register(dom.fpsCamera, 'Walk Mode', 'top');
|
|
77266
77288
|
tooltip.register(dom.reset, 'Reset Camera', 'bottom');
|
|
77267
77289
|
tooltip.register(dom.frame, 'Frame Scene', 'bottom');
|
|
77268
|
-
tooltip.register(dom.
|
|
77290
|
+
tooltip.register(dom.showCollision, 'Show Collision', 'top');
|
|
77269
77291
|
tooltip.register(dom.settings, 'Settings', 'top');
|
|
77270
77292
|
tooltip.register(dom.info, 'Help', 'top');
|
|
77271
77293
|
tooltip.register(dom.arMode, 'Enter AR', 'top');
|
|
@@ -79021,6 +79043,227 @@ class CameraManager {
|
|
|
79021
79043
|
}
|
|
79022
79044
|
}
|
|
79023
79045
|
|
|
79046
|
+
/**
|
|
79047
|
+
* Watches global pointer events and updates `state.inputMode` to reflect
|
|
79048
|
+
* whether the user is on a touch device or desktop.
|
|
79049
|
+
*/
|
|
79050
|
+
class InputModeTracker {
|
|
79051
|
+
_global = null;
|
|
79052
|
+
_onPointer = (event) => {
|
|
79053
|
+
if (this._global) {
|
|
79054
|
+
this._global.state.inputMode = event.pointerType === 'touch' ? 'touch' : 'desktop';
|
|
79055
|
+
}
|
|
79056
|
+
};
|
|
79057
|
+
attach(global) {
|
|
79058
|
+
this._global = global;
|
|
79059
|
+
window.addEventListener('pointerdown', this._onPointer);
|
|
79060
|
+
window.addEventListener('pointermove', this._onPointer);
|
|
79061
|
+
}
|
|
79062
|
+
detach() {
|
|
79063
|
+
window.removeEventListener('pointerdown', this._onPointer);
|
|
79064
|
+
window.removeEventListener('pointermove', this._onPointer);
|
|
79065
|
+
this._global = null;
|
|
79066
|
+
}
|
|
79067
|
+
}
|
|
79068
|
+
|
|
79069
|
+
/**
|
|
79070
|
+
* Keyboard shortcuts that switch camera mode and toggle UI affordances.
|
|
79071
|
+
* Listens on `window` so the user can press 1/2/3, V, G, H, F, R, Space,
|
|
79072
|
+
* or Escape regardless of which element has focus.
|
|
79073
|
+
*/
|
|
79074
|
+
class ModeShortcuts {
|
|
79075
|
+
_global = null;
|
|
79076
|
+
_pointerLock = null;
|
|
79077
|
+
_onKeyDown = (event) => {
|
|
79078
|
+
const global = this._global;
|
|
79079
|
+
if (!global)
|
|
79080
|
+
return;
|
|
79081
|
+
const { state, events } = global;
|
|
79082
|
+
if (event.key === 'Escape') {
|
|
79083
|
+
if (this._pointerLock?.recentlyExitedWalk) ;
|
|
79084
|
+
else if (state.cameraMode === 'walk' && state.gamingControls && state.inputMode === 'desktop') {
|
|
79085
|
+
state.gamingControls = false;
|
|
79086
|
+
}
|
|
79087
|
+
else if (state.cameraMode === 'walk') {
|
|
79088
|
+
events.fire('inputEvent', 'exitWalk', event);
|
|
79089
|
+
}
|
|
79090
|
+
else {
|
|
79091
|
+
events.fire('inputEvent', 'cancel', event);
|
|
79092
|
+
}
|
|
79093
|
+
return;
|
|
79094
|
+
}
|
|
79095
|
+
if (event.ctrlKey || event.altKey || event.metaKey) {
|
|
79096
|
+
return;
|
|
79097
|
+
}
|
|
79098
|
+
switch (event.key) {
|
|
79099
|
+
case '1':
|
|
79100
|
+
state.cameraMode = 'orbit';
|
|
79101
|
+
break;
|
|
79102
|
+
case '2':
|
|
79103
|
+
state.cameraMode = 'fly';
|
|
79104
|
+
break;
|
|
79105
|
+
case '3':
|
|
79106
|
+
events.fire('inputEvent', 'toggleWalk');
|
|
79107
|
+
break;
|
|
79108
|
+
case 'v':
|
|
79109
|
+
if (state.hasCollisionOverlay) {
|
|
79110
|
+
state.collisionOverlayEnabled = !state.collisionOverlayEnabled;
|
|
79111
|
+
}
|
|
79112
|
+
break;
|
|
79113
|
+
case 'g':
|
|
79114
|
+
state.gamingControls = !state.gamingControls;
|
|
79115
|
+
break;
|
|
79116
|
+
case 'h':
|
|
79117
|
+
events.fire('inputEvent', 'toggleHelp');
|
|
79118
|
+
break;
|
|
79119
|
+
default:
|
|
79120
|
+
if ((event.code === 'KeyW' || event.code === 'KeyA' || event.code === 'KeyS' || event.code === 'KeyD') &&
|
|
79121
|
+
state.cameraMode === 'walk' && state.inputMode === 'desktop' && !state.gamingControls) {
|
|
79122
|
+
state.gamingControls = true;
|
|
79123
|
+
}
|
|
79124
|
+
break;
|
|
79125
|
+
}
|
|
79126
|
+
if (state.cameraMode !== 'walk') {
|
|
79127
|
+
switch (event.key) {
|
|
79128
|
+
case 'f':
|
|
79129
|
+
events.fire('inputEvent', 'frame', event);
|
|
79130
|
+
break;
|
|
79131
|
+
case 'r':
|
|
79132
|
+
events.fire('inputEvent', 'reset', event);
|
|
79133
|
+
break;
|
|
79134
|
+
case ' ':
|
|
79135
|
+
events.fire('inputEvent', 'playPause', event);
|
|
79136
|
+
break;
|
|
79137
|
+
}
|
|
79138
|
+
}
|
|
79139
|
+
};
|
|
79140
|
+
attach(global, pointerLock) {
|
|
79141
|
+
this._global = global;
|
|
79142
|
+
this._pointerLock = pointerLock;
|
|
79143
|
+
window.addEventListener('keydown', this._onKeyDown);
|
|
79144
|
+
}
|
|
79145
|
+
detach() {
|
|
79146
|
+
window.removeEventListener('keydown', this._onKeyDown);
|
|
79147
|
+
this._global = null;
|
|
79148
|
+
this._pointerLock = null;
|
|
79149
|
+
}
|
|
79150
|
+
}
|
|
79151
|
+
|
|
79152
|
+
/**
|
|
79153
|
+
* Manages the browser's pointer-lock API for walk-mode + gaming controls
|
|
79154
|
+
* on desktop. Toggles in response to `cameraMode:changed` and
|
|
79155
|
+
* `gamingControls:changed`, and reverts state if the lock is exited or
|
|
79156
|
+
* rejected.
|
|
79157
|
+
*
|
|
79158
|
+
* Also exposes `recentlyExitedWalk` so the keyboard-shortcut handler can
|
|
79159
|
+
* de-duplicate the Escape keydown that triggered the lock exit.
|
|
79160
|
+
*/
|
|
79161
|
+
class PointerLockManager {
|
|
79162
|
+
_global = null;
|
|
79163
|
+
_canvas = null;
|
|
79164
|
+
_keyboardMouse = null;
|
|
79165
|
+
_recentlyExitedWalk = false;
|
|
79166
|
+
_onPointerLockChange = () => {
|
|
79167
|
+
const global = this._global;
|
|
79168
|
+
if (!global)
|
|
79169
|
+
return;
|
|
79170
|
+
const { state, events } = global;
|
|
79171
|
+
if (!document.pointerLockElement && state.cameraMode === 'walk' && state.gamingControls) {
|
|
79172
|
+
this._recentlyExitedWalk = true;
|
|
79173
|
+
requestAnimationFrame(() => {
|
|
79174
|
+
this._recentlyExitedWalk = false;
|
|
79175
|
+
});
|
|
79176
|
+
if (state.inputMode === 'desktop') {
|
|
79177
|
+
state.gamingControls = false;
|
|
79178
|
+
}
|
|
79179
|
+
else {
|
|
79180
|
+
events.fire('inputEvent', 'exitWalk');
|
|
79181
|
+
}
|
|
79182
|
+
}
|
|
79183
|
+
};
|
|
79184
|
+
_onPointerLockError = () => {
|
|
79185
|
+
// Pointer lock request rejected (no user gesture, document hidden,
|
|
79186
|
+
// etc). Revert state so we don't end up stuck in walk mode without
|
|
79187
|
+
// mouse capture.
|
|
79188
|
+
if (this._keyboardMouse) {
|
|
79189
|
+
this._keyboardMouse.source._pointerLock = false;
|
|
79190
|
+
}
|
|
79191
|
+
const global = this._global;
|
|
79192
|
+
if (!global)
|
|
79193
|
+
return;
|
|
79194
|
+
const { state, events } = global;
|
|
79195
|
+
if (state.inputMode === 'desktop') {
|
|
79196
|
+
state.gamingControls = false;
|
|
79197
|
+
}
|
|
79198
|
+
else {
|
|
79199
|
+
events.fire('inputEvent', 'exitWalk');
|
|
79200
|
+
}
|
|
79201
|
+
};
|
|
79202
|
+
_onCameraModeChanged = (value, prev) => {
|
|
79203
|
+
const state = this._global?.state;
|
|
79204
|
+
if (!state)
|
|
79205
|
+
return;
|
|
79206
|
+
if (value === 'walk' && state.inputMode === 'desktop' && state.gamingControls) {
|
|
79207
|
+
this._activate();
|
|
79208
|
+
}
|
|
79209
|
+
else if (prev === 'walk') {
|
|
79210
|
+
this._deactivate();
|
|
79211
|
+
}
|
|
79212
|
+
};
|
|
79213
|
+
_onGamingControlsChanged = (value) => {
|
|
79214
|
+
const state = this._global?.state;
|
|
79215
|
+
if (!state)
|
|
79216
|
+
return;
|
|
79217
|
+
if (state.cameraMode === 'walk' && state.inputMode === 'desktop') {
|
|
79218
|
+
if (value) {
|
|
79219
|
+
this._activate();
|
|
79220
|
+
}
|
|
79221
|
+
else {
|
|
79222
|
+
this._deactivate();
|
|
79223
|
+
}
|
|
79224
|
+
}
|
|
79225
|
+
};
|
|
79226
|
+
_activate() {
|
|
79227
|
+
if (this._keyboardMouse) {
|
|
79228
|
+
this._keyboardMouse.source._pointerLock = true;
|
|
79229
|
+
}
|
|
79230
|
+
this._canvas?.requestPointerLock();
|
|
79231
|
+
}
|
|
79232
|
+
_deactivate() {
|
|
79233
|
+
if (this._keyboardMouse) {
|
|
79234
|
+
this._keyboardMouse.source._pointerLock = false;
|
|
79235
|
+
}
|
|
79236
|
+
if (document.pointerLockElement === this._canvas) {
|
|
79237
|
+
document.exitPointerLock();
|
|
79238
|
+
}
|
|
79239
|
+
}
|
|
79240
|
+
get recentlyExitedWalk() {
|
|
79241
|
+
return this._recentlyExitedWalk;
|
|
79242
|
+
}
|
|
79243
|
+
attach(canvas, global, keyboardMouse) {
|
|
79244
|
+
this._canvas = canvas;
|
|
79245
|
+
this._global = global;
|
|
79246
|
+
this._keyboardMouse = keyboardMouse;
|
|
79247
|
+
const { events } = global;
|
|
79248
|
+
events.on('cameraMode:changed', this._onCameraModeChanged);
|
|
79249
|
+
events.on('gamingControls:changed', this._onGamingControlsChanged);
|
|
79250
|
+
document.addEventListener('pointerlockchange', this._onPointerLockChange);
|
|
79251
|
+
document.addEventListener('pointerlockerror', this._onPointerLockError);
|
|
79252
|
+
}
|
|
79253
|
+
detach() {
|
|
79254
|
+
if (this._global) {
|
|
79255
|
+
const { events } = this._global;
|
|
79256
|
+
events.off('cameraMode:changed', this._onCameraModeChanged);
|
|
79257
|
+
events.off('gamingControls:changed', this._onGamingControlsChanged);
|
|
79258
|
+
}
|
|
79259
|
+
document.removeEventListener('pointerlockchange', this._onPointerLockChange);
|
|
79260
|
+
document.removeEventListener('pointerlockerror', this._onPointerLockError);
|
|
79261
|
+
this._canvas = null;
|
|
79262
|
+
this._global = null;
|
|
79263
|
+
this._keyboardMouse = null;
|
|
79264
|
+
}
|
|
79265
|
+
}
|
|
79266
|
+
|
|
79024
79267
|
/**
|
|
79025
79268
|
* Double-click world picking for splat scenes.
|
|
79026
79269
|
*
|
|
@@ -79368,44 +79611,32 @@ class Picker {
|
|
|
79368
79611
|
}
|
|
79369
79612
|
}
|
|
79370
79613
|
|
|
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
79614
|
/**
|
|
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.
|
|
79615
|
+
* Displacement-based inputs (mouse, touch, wheel, pinch) return accumulated
|
|
79616
|
+
* pixel offsets that already scale with frame time. This factor converts
|
|
79617
|
+
* rate-based speed constants (tuned for degrees-per-second) to work with
|
|
79618
|
+
* per-frame displacements, making them frame-rate-independent.
|
|
79389
79619
|
*/
|
|
79390
79620
|
const DISPLACEMENT_SCALE = 1 / 60;
|
|
79621
|
+
/** Maximum accumulated touch movement (px) to still count as a tap. */
|
|
79622
|
+
const TAP_EPSILON = 15;
|
|
79623
|
+
const tmpHalfSize = new Vec3();
|
|
79391
79624
|
/**
|
|
79392
|
-
* Converts screen
|
|
79625
|
+
* Converts screen-space pixel deltas to a world-space pan vector at the
|
|
79626
|
+
* given depth.
|
|
79393
79627
|
*
|
|
79394
79628
|
* @param camera - The camera component.
|
|
79395
|
-
* @param dx -
|
|
79396
|
-
* @param dy -
|
|
79397
|
-
* @param dz -
|
|
79398
|
-
* @param out -
|
|
79399
|
-
* @returns
|
|
79400
|
-
* @private
|
|
79629
|
+
* @param dx - Horizontal pixel delta.
|
|
79630
|
+
* @param dy - Vertical pixel delta.
|
|
79631
|
+
* @param dz - Depth (world-space) at which to project the delta.
|
|
79632
|
+
* @param out - Optional output vector.
|
|
79633
|
+
* @returns The pan vector in world space.
|
|
79401
79634
|
*/
|
|
79402
79635
|
const screenToWorld = (camera, dx, dy, dz, out = new Vec3()) => {
|
|
79403
79636
|
const { system, fov, aspectRatio, horizontalFov, projection, orthoHeight } = camera;
|
|
79404
79637
|
const { width, height } = system.app.graphicsDevice.clientRect;
|
|
79405
|
-
// normalize deltas to device coord space
|
|
79406
79638
|
out.set(-(dx / width) * 2, (dy / height) * 2, 0);
|
|
79407
|
-
|
|
79408
|
-
const halfSize = tmpV2.set(0, 0, 0);
|
|
79639
|
+
const halfSize = tmpHalfSize.set(0, 0, 0);
|
|
79409
79640
|
if (projection === PROJECTION_PERSPECTIVE) {
|
|
79410
79641
|
const halfSlice = dz * Math.tan(0.5 * fov * math.DEG_TO_RAD);
|
|
79411
79642
|
if (horizontalFov) {
|
|
@@ -79418,12 +79649,227 @@ const screenToWorld = (camera, dx, dy, dz, out = new Vec3()) => {
|
|
|
79418
79649
|
else {
|
|
79419
79650
|
halfSize.set(orthoHeight * aspectRatio, orthoHeight, 0);
|
|
79420
79651
|
}
|
|
79421
|
-
// scale by device coord space
|
|
79422
79652
|
out.mul(halfSize);
|
|
79423
79653
|
return out;
|
|
79424
79654
|
};
|
|
79425
|
-
|
|
79426
|
-
|
|
79655
|
+
/**
|
|
79656
|
+
* The orbit camera and the fly camera disagree on the sign of the z-axis
|
|
79657
|
+
* for forward motion. Apply this when emitting a forward/back z-component
|
|
79658
|
+
* so the same wheel-style delta drives both cameras correctly.
|
|
79659
|
+
*
|
|
79660
|
+
* @param mode - The current camera mode.
|
|
79661
|
+
* @param z - The raw forward/back z-component.
|
|
79662
|
+
* @returns The z-component flipped for orbit mode, unchanged otherwise.
|
|
79663
|
+
*/
|
|
79664
|
+
const flipZForOrbit = (mode, z) => (mode === 'orbit' ? -z : z);
|
|
79665
|
+
|
|
79666
|
+
const tmpV$4 = new Vec3();
|
|
79667
|
+
/**
|
|
79668
|
+
* Click-to-walk (desktop), tap-to-walk (mobile), and double-click-to-pick
|
|
79669
|
+
* (orbit / fly) interaction. Uses a Picker against the collision mesh to
|
|
79670
|
+
* resolve the world-space target and fires `walkTo` / `pick` for the
|
|
79671
|
+
* camera manager to consume.
|
|
79672
|
+
*/
|
|
79673
|
+
class WalkInteraction {
|
|
79674
|
+
collision = null;
|
|
79675
|
+
_global = null;
|
|
79676
|
+
_canvas = null;
|
|
79677
|
+
_picker = null;
|
|
79678
|
+
_lastPointerOffsetX = 0;
|
|
79679
|
+
_lastPointerOffsetY = 0;
|
|
79680
|
+
_mouseClickTracking = false;
|
|
79681
|
+
_mouseClickDelta = 0;
|
|
79682
|
+
_lastTap = { time: 0, x: 0, y: 0 };
|
|
79683
|
+
_updateCursor = () => {
|
|
79684
|
+
const global = this._global;
|
|
79685
|
+
const canvas = this._canvas;
|
|
79686
|
+
if (!global || !canvas)
|
|
79687
|
+
return;
|
|
79688
|
+
const { state } = global;
|
|
79689
|
+
if (state.cameraMode === 'walk' && !state.gamingControls && state.inputMode === 'desktop') {
|
|
79690
|
+
canvas.style.cursor = this._mouseClickTracking ? 'default' : 'pointer';
|
|
79691
|
+
}
|
|
79692
|
+
else {
|
|
79693
|
+
canvas.style.cursor = '';
|
|
79694
|
+
}
|
|
79695
|
+
};
|
|
79696
|
+
_pickCollision(offsetX, offsetY) {
|
|
79697
|
+
if (!this.collision || !this._global)
|
|
79698
|
+
return null;
|
|
79699
|
+
const camera = this._global.camera;
|
|
79700
|
+
const cameraPos = camera.getPosition();
|
|
79701
|
+
camera.camera.screenToWorld(offsetX, offsetY, 1.0, tmpV$4);
|
|
79702
|
+
tmpV$4.sub(cameraPos).normalize();
|
|
79703
|
+
const hit = this.collision.queryRay(cameraPos.x, cameraPos.y, cameraPos.z, tmpV$4.x, tmpV$4.y, tmpV$4.z, camera.camera.farClip);
|
|
79704
|
+
if (!hit)
|
|
79705
|
+
return null;
|
|
79706
|
+
const sn = this.collision.querySurfaceNormal(hit.x, hit.y, hit.z, tmpV$4.x, tmpV$4.y, tmpV$4.z);
|
|
79707
|
+
return {
|
|
79708
|
+
position: new Vec3(hit.x, hit.y, hit.z),
|
|
79709
|
+
normal: new Vec3(sn.nx, sn.ny, sn.nz)
|
|
79710
|
+
};
|
|
79711
|
+
}
|
|
79712
|
+
_onPointerDown = (event) => {
|
|
79713
|
+
const global = this._global;
|
|
79714
|
+
if (!global)
|
|
79715
|
+
return;
|
|
79716
|
+
const { events } = global;
|
|
79717
|
+
// record offsets for click/tap-to-walk picking
|
|
79718
|
+
this._lastPointerOffsetX = event.offsetX;
|
|
79719
|
+
this._lastPointerOffsetY = event.offsetY;
|
|
79720
|
+
// start desktop click-to-walk tracking
|
|
79721
|
+
if (event.pointerType !== 'touch' && event.button === 0) {
|
|
79722
|
+
this._mouseClickTracking = true;
|
|
79723
|
+
this._mouseClickDelta = 0;
|
|
79724
|
+
this._updateCursor();
|
|
79725
|
+
}
|
|
79726
|
+
// manual double-tap detection (iOS doesn't send dblclick)
|
|
79727
|
+
const now = Date.now();
|
|
79728
|
+
const delay = Math.max(0, now - this._lastTap.time);
|
|
79729
|
+
if (delay < 300 &&
|
|
79730
|
+
Math.abs(event.clientX - this._lastTap.x) < 8 &&
|
|
79731
|
+
Math.abs(event.clientY - this._lastTap.y) < 8) {
|
|
79732
|
+
events.fire('inputEvent', 'dblclick', event);
|
|
79733
|
+
this._lastTap.time = 0;
|
|
79734
|
+
}
|
|
79735
|
+
else {
|
|
79736
|
+
this._lastTap.time = now;
|
|
79737
|
+
this._lastTap.x = event.clientX;
|
|
79738
|
+
this._lastTap.y = event.clientY;
|
|
79739
|
+
}
|
|
79740
|
+
};
|
|
79741
|
+
_onPointerMove = (event) => {
|
|
79742
|
+
const global = this._global;
|
|
79743
|
+
if (!global)
|
|
79744
|
+
return;
|
|
79745
|
+
const { state, events } = global;
|
|
79746
|
+
if (this._mouseClickTracking && event.pointerType !== 'touch') {
|
|
79747
|
+
const prev = this._mouseClickDelta;
|
|
79748
|
+
this._mouseClickDelta += Math.abs(event.movementX) + Math.abs(event.movementY);
|
|
79749
|
+
if (prev < TAP_EPSILON && this._mouseClickDelta >= TAP_EPSILON) {
|
|
79750
|
+
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
79751
|
+
events.fire('walkCancel');
|
|
79752
|
+
}
|
|
79753
|
+
}
|
|
79754
|
+
}
|
|
79755
|
+
};
|
|
79756
|
+
_onPointerUp = (event) => {
|
|
79757
|
+
const global = this._global;
|
|
79758
|
+
if (!global)
|
|
79759
|
+
return;
|
|
79760
|
+
const { state, events } = global;
|
|
79761
|
+
if (this._mouseClickTracking && event.pointerType !== 'touch' && event.button === 0) {
|
|
79762
|
+
this._mouseClickTracking = false;
|
|
79763
|
+
this._updateCursor();
|
|
79764
|
+
if (this._mouseClickDelta < TAP_EPSILON && state.cameraMode === 'walk' && !state.gamingControls) {
|
|
79765
|
+
const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
79766
|
+
if (result) {
|
|
79767
|
+
events.fire('walkTo', result.position, result.normal);
|
|
79768
|
+
}
|
|
79769
|
+
}
|
|
79770
|
+
}
|
|
79771
|
+
};
|
|
79772
|
+
_onInputEvent = async (eventName, event) => {
|
|
79773
|
+
const global = this._global;
|
|
79774
|
+
const canvas = this._canvas;
|
|
79775
|
+
if (!global || !canvas)
|
|
79776
|
+
return;
|
|
79777
|
+
if (eventName !== 'dblclick')
|
|
79778
|
+
return;
|
|
79779
|
+
if (!(event instanceof MouseEvent))
|
|
79780
|
+
return;
|
|
79781
|
+
const { app, camera, events, state } = global;
|
|
79782
|
+
if (state.cameraMode === 'walk')
|
|
79783
|
+
return;
|
|
79784
|
+
if (!this._picker) {
|
|
79785
|
+
this._picker = new Picker(app, camera);
|
|
79786
|
+
}
|
|
79787
|
+
const result = await this._picker.pick(event.offsetX / canvas.clientWidth, event.offsetY / canvas.clientHeight);
|
|
79788
|
+
if (result) {
|
|
79789
|
+
events.fire('pick', result);
|
|
79790
|
+
}
|
|
79791
|
+
};
|
|
79792
|
+
_onMobileTap = () => {
|
|
79793
|
+
const global = this._global;
|
|
79794
|
+
if (!global)
|
|
79795
|
+
return;
|
|
79796
|
+
const { state, events } = global;
|
|
79797
|
+
if (state.cameraMode !== 'walk' || state.gamingControls)
|
|
79798
|
+
return;
|
|
79799
|
+
const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
79800
|
+
if (result) {
|
|
79801
|
+
events.fire('walkTo', result.position, result.normal);
|
|
79802
|
+
}
|
|
79803
|
+
};
|
|
79804
|
+
attach(canvas, global) {
|
|
79805
|
+
this._canvas = canvas;
|
|
79806
|
+
this._global = global;
|
|
79807
|
+
const { events } = global;
|
|
79808
|
+
canvas.addEventListener('pointerdown', this._onPointerDown);
|
|
79809
|
+
canvas.addEventListener('pointermove', this._onPointerMove);
|
|
79810
|
+
canvas.addEventListener('pointerup', this._onPointerUp);
|
|
79811
|
+
// double-click → pick → fire 'pick' event (skipped in walk mode)
|
|
79812
|
+
events.on('inputEvent', this._onInputEvent);
|
|
79813
|
+
// mobile tap (no movement) → walkTo
|
|
79814
|
+
events.on('mobileTap', this._onMobileTap);
|
|
79815
|
+
// refresh cursor on mode / gaming-controls change
|
|
79816
|
+
events.on('cameraMode:changed', this._updateCursor);
|
|
79817
|
+
events.on('gamingControls:changed', this._updateCursor);
|
|
79818
|
+
}
|
|
79819
|
+
detach() {
|
|
79820
|
+
if (this._canvas) {
|
|
79821
|
+
this._canvas.removeEventListener('pointerdown', this._onPointerDown);
|
|
79822
|
+
this._canvas.removeEventListener('pointermove', this._onPointerMove);
|
|
79823
|
+
this._canvas.removeEventListener('pointerup', this._onPointerUp);
|
|
79824
|
+
}
|
|
79825
|
+
if (this._global) {
|
|
79826
|
+
const { events } = this._global;
|
|
79827
|
+
events.off('inputEvent', this._onInputEvent);
|
|
79828
|
+
events.off('mobileTap', this._onMobileTap);
|
|
79829
|
+
events.off('cameraMode:changed', this._updateCursor);
|
|
79830
|
+
events.off('gamingControls:changed', this._updateCursor);
|
|
79831
|
+
}
|
|
79832
|
+
this._canvas = null;
|
|
79833
|
+
this._global = null;
|
|
79834
|
+
this._picker = null;
|
|
79835
|
+
}
|
|
79836
|
+
}
|
|
79837
|
+
|
|
79838
|
+
const tmpV$3 = new Vec3();
|
|
79839
|
+
const stickMove = new Vec3();
|
|
79840
|
+
const stickRotate = new Vec3();
|
|
79841
|
+
class GamepadDevice {
|
|
79842
|
+
moveSpeed = 4;
|
|
79843
|
+
orbitSpeed = 18;
|
|
79844
|
+
gamepadRotateSensitivity = 1.0;
|
|
79845
|
+
_source = new GamepadSource();
|
|
79846
|
+
attach(_canvas, _global) {
|
|
79847
|
+
// GamepadSource polls navigator.getGamepads() — no DOM attach needed.
|
|
79848
|
+
}
|
|
79849
|
+
detach() { }
|
|
79850
|
+
update(ctx, frame) {
|
|
79851
|
+
const { dt, cameraComponent, isFirstPerson } = ctx;
|
|
79852
|
+
const { leftStick, rightStick } = this._source.read();
|
|
79853
|
+
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
79854
|
+
const { deltas } = frame;
|
|
79855
|
+
const v = tmpV$3.set(0, 0, 0);
|
|
79856
|
+
stickMove.set(leftStick[0], 0, -leftStick[1]);
|
|
79857
|
+
v.add(stickMove.mulScalar(this.moveSpeed * dt));
|
|
79858
|
+
deltas.move.append([v.x, v.y, v.z]);
|
|
79859
|
+
v.set(0, 0, 0);
|
|
79860
|
+
stickRotate.set(rightStick[0], rightStick[1], 0);
|
|
79861
|
+
v.add(stickRotate.mulScalar(this.orbitSpeed * orbitFactor * this.gamepadRotateSensitivity * dt));
|
|
79862
|
+
deltas.rotate.append([v.x, v.y, v.z]);
|
|
79863
|
+
}
|
|
79864
|
+
}
|
|
79865
|
+
|
|
79866
|
+
const tmpV1 = new Vec3();
|
|
79867
|
+
const keyMove = new Vec3();
|
|
79868
|
+
const panMove = new Vec3();
|
|
79869
|
+
const mouseRotate = new Vec3();
|
|
79870
|
+
const wheelMove = new Vec3();
|
|
79871
|
+
// Patch keydown / keyup so meta-key combinations don't leave keys stuck on
|
|
79872
|
+
// macOS (the OS swallows keyup for any key released while Cmd is held).
|
|
79427
79873
|
const patchKeyboardMeta = (desktopInput) => {
|
|
79428
79874
|
const origOnKeyDown = desktopInput._onKeyDown;
|
|
79429
79875
|
desktopInput._onKeyDown = (event) => {
|
|
@@ -79444,342 +79890,171 @@ const patchKeyboardMeta = (desktopInput) => {
|
|
|
79444
79890
|
}
|
|
79445
79891
|
};
|
|
79446
79892
|
};
|
|
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;
|
|
79893
|
+
class KeyboardMouseDevice {
|
|
79486
79894
|
moveSpeed = 4;
|
|
79487
79895
|
orbitSpeed = 18;
|
|
79488
|
-
pinchSpeed = 0.4;
|
|
79489
79896
|
wheelSpeed = 0.06;
|
|
79490
79897
|
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
|
-
}
|
|
79898
|
+
_source = new KeyboardMouseSource();
|
|
79899
|
+
_global = null;
|
|
79900
|
+
/** Running WASD/QE/arrow direction (sum of key states). */
|
|
79901
|
+
_axis = new Vec3();
|
|
79902
|
+
/** Running button-held state per index: [LMB, MMB, RMB]. */
|
|
79903
|
+
_buttons = [0, 0, 0];
|
|
79904
|
+
_shift = 0;
|
|
79905
|
+
_ctrl = 0;
|
|
79906
|
+
_jump = 0;
|
|
79730
79907
|
/**
|
|
79731
|
-
*
|
|
79732
|
-
*
|
|
79733
|
-
*
|
|
79734
|
-
*
|
|
79908
|
+
* Get the underlying source so other code (PointerLockManager) can
|
|
79909
|
+
* toggle its private pointer-lock flag, which gates how it consumes
|
|
79910
|
+
* mouse-delta events.
|
|
79911
|
+
*
|
|
79912
|
+
* @returns The PlayCanvas KeyboardMouseSource backing this device.
|
|
79735
79913
|
*/
|
|
79736
|
-
|
|
79914
|
+
get source() {
|
|
79915
|
+
return this._source;
|
|
79916
|
+
}
|
|
79917
|
+
attach(canvas, global) {
|
|
79918
|
+
this._global = global;
|
|
79919
|
+
patchKeyboardMeta(this._source);
|
|
79920
|
+
this._source.attach(canvas);
|
|
79921
|
+
}
|
|
79922
|
+
detach() {
|
|
79923
|
+
// KeyboardMouseSource does not expose a detach; nothing to undo for
|
|
79924
|
+
// its DOM listeners here.
|
|
79925
|
+
}
|
|
79926
|
+
update(ctx, frame) {
|
|
79737
79927
|
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];
|
|
79928
|
+
const { key, button, mouse, wheel } = this._source.read();
|
|
79929
|
+
const { events } = this._global;
|
|
79930
|
+
// accumulate running input state
|
|
79931
|
+
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])));
|
|
79932
|
+
this._jump += key[keyCode.SPACE];
|
|
79933
|
+
this._shift += key[keyCode.SHIFT];
|
|
79934
|
+
this._ctrl += key[keyCode.CTRL];
|
|
79935
|
+
const n = Math.min(button.length, this._buttons.length);
|
|
79936
|
+
for (let i = 0; i < n; i++) {
|
|
79937
|
+
this._buttons[i] += button[i];
|
|
79749
79938
|
}
|
|
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)) {
|
|
79939
|
+
const { isWalk, isFirstPerson, dt, distance, cameraComponent, mode, touchCount } = ctx;
|
|
79940
|
+
// walk-cancel and requestFirstPerson events (driven by WASD axis)
|
|
79941
|
+
if (isWalk && (this._axis.x !== 0 || this._axis.z !== 0)) {
|
|
79755
79942
|
events.fire('walkCancel');
|
|
79756
79943
|
}
|
|
79757
|
-
|
|
79944
|
+
if (!isFirstPerson && this._axis.length() > 0) {
|
|
79945
|
+
events.fire('inputEvent', 'requestFirstPerson');
|
|
79946
|
+
}
|
|
79947
|
+
// pan flag: RMB held, RMB just released this frame, or 2+ touches active
|
|
79948
|
+
const pan = this._buttons[2] || +(button[2] === -1) || +(touchCount > 1);
|
|
79949
|
+
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
79950
|
+
const { deltas } = frame;
|
|
79951
|
+
// move (WASD + mouse-drag pan + wheel)
|
|
79952
|
+
const v = tmpV1.set(0, 0, 0);
|
|
79953
|
+
keyMove.copy(this._axis);
|
|
79954
|
+
if (isWalk) {
|
|
79955
|
+
// In walk mode normalize only horizontal axes so jump doesn't
|
|
79956
|
+
// reduce horizontal speed.
|
|
79957
|
+
keyMove.y = 0;
|
|
79958
|
+
}
|
|
79959
|
+
keyMove.normalize();
|
|
79960
|
+
const shiftMul = isWalk ? 2 : 4;
|
|
79961
|
+
const ctrlMul = isWalk ? 0.5 : 0.25;
|
|
79962
|
+
const speed = this.moveSpeed * (this._shift ? shiftMul : this._ctrl ? ctrlMul : 1);
|
|
79963
|
+
v.add(keyMove.mulScalar((isFirstPerson ? 1 : 0) * speed * dt));
|
|
79964
|
+
if (isWalk) {
|
|
79965
|
+
// Pass jump signal as raw Y; WalkController uses move[1] > 0 as
|
|
79966
|
+
// a boolean trigger.
|
|
79967
|
+
v.y = this._jump > 0 ? 1 : 0;
|
|
79968
|
+
}
|
|
79969
|
+
screenToWorld(cameraComponent, mouse[0], mouse[1], distance, panMove);
|
|
79970
|
+
v.add(panMove.mulScalar(pan));
|
|
79971
|
+
wheelMove.set(0, 0, -wheel[0]);
|
|
79972
|
+
v.add(wheelMove.mulScalar(this.wheelSpeed * DISPLACEMENT_SCALE));
|
|
79973
|
+
deltas.move.append([v.x, v.y, flipZForOrbit(mode, v.z)]);
|
|
79974
|
+
// rotate (mouse-drag, masked when in pan mode)
|
|
79975
|
+
v.set(0, 0, 0);
|
|
79976
|
+
mouseRotate.set(mouse[0], mouse[1], 0);
|
|
79977
|
+
v.add(mouseRotate.mulScalar((1 - pan) * this.orbitSpeed * orbitFactor * this.mouseRotateSensitivity * DISPLACEMENT_SCALE));
|
|
79978
|
+
deltas.rotate.append([v.x, v.y, v.z]);
|
|
79979
|
+
}
|
|
79980
|
+
}
|
|
79981
|
+
|
|
79982
|
+
const tmpV$2 = new Vec3();
|
|
79983
|
+
const orbitMove = new Vec3();
|
|
79984
|
+
const flyMoveTmp = new Vec3();
|
|
79985
|
+
const flyTouchPan = new Vec3();
|
|
79986
|
+
const pinchMoveTmp = new Vec3();
|
|
79987
|
+
const orbitRotate = new Vec3();
|
|
79988
|
+
const flyRotate = new Vec3();
|
|
79989
|
+
class TouchDevice {
|
|
79990
|
+
orbitSpeed = 18;
|
|
79991
|
+
moveSpeed = 4;
|
|
79992
|
+
pinchSpeed = 0.4;
|
|
79993
|
+
touchRotateSensitivity = 1.5;
|
|
79994
|
+
touchPinchMoveSensitivity = 1.5;
|
|
79995
|
+
pinchVelocitySensitivity = 0.006;
|
|
79996
|
+
panVelocitySensitivity = 0.005;
|
|
79997
|
+
_source = new MultiTouchSource();
|
|
79998
|
+
_global = null;
|
|
79999
|
+
/** Touches currently active (running count from .read() deltas). */
|
|
80000
|
+
_touchCount = 0;
|
|
80001
|
+
/** UI joystick value [x, y], -1..1. */
|
|
80002
|
+
_joystick = [0, 0];
|
|
80003
|
+
/** Smoothed forward/back velocity from pinch gesture (-1..1). */
|
|
80004
|
+
_pinchVelocity = 0;
|
|
80005
|
+
/** Smoothed strafe/vertical velocity from two-finger pan, -1..1 each. */
|
|
80006
|
+
_panVelocity = [0, 0];
|
|
80007
|
+
/** Tap-detection state — touch count and accumulated finger movement. */
|
|
80008
|
+
_tapTouches = 0;
|
|
80009
|
+
_tapDelta = 0;
|
|
80010
|
+
/** True for one frame after a tap is detected during gaming controls. */
|
|
80011
|
+
_tapJump = false;
|
|
80012
|
+
_onJoystickInput = (value) => {
|
|
80013
|
+
this._joystick[0] = value.x;
|
|
80014
|
+
this._joystick[1] = value.y;
|
|
80015
|
+
};
|
|
80016
|
+
get touchCount() {
|
|
80017
|
+
return this._touchCount;
|
|
80018
|
+
}
|
|
80019
|
+
attach(canvas, global) {
|
|
80020
|
+
this._global = global;
|
|
80021
|
+
this._source.attach(canvas);
|
|
80022
|
+
global.events.on('joystickInput', this._onJoystickInput);
|
|
80023
|
+
}
|
|
80024
|
+
detach() {
|
|
80025
|
+
// MultiTouchSource doesn't expose a detach.
|
|
80026
|
+
if (this._global) {
|
|
80027
|
+
this._global.events.off('joystickInput', this._onJoystickInput);
|
|
80028
|
+
this._global = null;
|
|
80029
|
+
}
|
|
80030
|
+
}
|
|
80031
|
+
update(ctx, frame) {
|
|
80032
|
+
const { touch, pinch, count } = this._source.read();
|
|
80033
|
+
const { isWalk, isFirstPerson, isOrbit, gamingControls, dt, distance, cameraComponent } = ctx;
|
|
80034
|
+
// running touch count
|
|
80035
|
+
this._touchCount += count[0];
|
|
80036
|
+
// tap detection (walk mode only)
|
|
79758
80037
|
if (isWalk) {
|
|
79759
80038
|
const prevTaps = this._tapTouches;
|
|
79760
80039
|
this._tapTouches = Math.max(0, this._tapTouches + count[0]);
|
|
79761
|
-
// Touch just started (0 → 1+)
|
|
79762
80040
|
if (prevTaps === 0 && this._tapTouches > 0) {
|
|
79763
80041
|
this._tapDelta = 0;
|
|
79764
80042
|
}
|
|
79765
|
-
// Accumulate movement while touch is active
|
|
79766
80043
|
if (this._tapTouches > 0) {
|
|
79767
80044
|
const prevDelta = this._tapDelta;
|
|
79768
80045
|
this._tapDelta += Math.abs(touch[0]) + Math.abs(touch[1]);
|
|
79769
80046
|
if (prevDelta < TAP_EPSILON && this._tapDelta >= TAP_EPSILON) {
|
|
79770
|
-
if (!
|
|
79771
|
-
events.fire('walkCancel');
|
|
80047
|
+
if (!gamingControls) {
|
|
80048
|
+
this._global.events.fire('walkCancel');
|
|
79772
80049
|
}
|
|
79773
80050
|
}
|
|
79774
80051
|
}
|
|
79775
|
-
// Touch just ended (1+ → 0): check if it was a tap
|
|
79776
80052
|
if (prevTaps > 0 && this._tapTouches === 0) {
|
|
79777
80053
|
if (this._tapDelta < TAP_EPSILON) {
|
|
79778
|
-
if (!
|
|
79779
|
-
|
|
79780
|
-
|
|
79781
|
-
|
|
79782
|
-
}
|
|
80054
|
+
if (!gamingControls) {
|
|
80055
|
+
// Walk-interaction listens for this and fires walkTo
|
|
80056
|
+
// after picking.
|
|
80057
|
+
this._global.events.fire('mobileTap');
|
|
79783
80058
|
}
|
|
79784
80059
|
else {
|
|
79785
80060
|
this._tapJump = true;
|
|
@@ -79790,11 +80065,10 @@ class InputController {
|
|
|
79790
80065
|
else {
|
|
79791
80066
|
this._tapTouches = 0;
|
|
79792
80067
|
}
|
|
79793
|
-
|
|
79794
|
-
|
|
79795
|
-
|
|
79796
|
-
|
|
79797
|
-
if (isFirstPerson && !state.gamingControls && this._state.touches > 1) {
|
|
80068
|
+
// smoothed velocities for fly/walk first-person motion (non-gaming)
|
|
80069
|
+
if (isFirstPerson && !gamingControls && this._touchCount > 1) {
|
|
80070
|
+
// pinch[0] = oldDist - newDist: negative when spreading,
|
|
80071
|
+
// positive when closing. Spreading = forward → subtract.
|
|
79798
80072
|
this._pinchVelocity -= pinch[0] * this.pinchVelocitySensitivity;
|
|
79799
80073
|
this._pinchVelocity = math.clamp(this._pinchVelocity, -1, 1.0);
|
|
79800
80074
|
this._panVelocity[0] += touch[0] * this.panVelocitySensitivity;
|
|
@@ -79802,92 +80076,571 @@ class InputController {
|
|
|
79802
80076
|
this._panVelocity[1] += touch[1] * this.panVelocitySensitivity;
|
|
79803
80077
|
this._panVelocity[1] = math.clamp(this._panVelocity[1], -1, 1.0);
|
|
79804
80078
|
}
|
|
79805
|
-
else if (isFirstPerson && this.
|
|
80079
|
+
else if (isFirstPerson && this._touchCount <= 1) {
|
|
79806
80080
|
this._pinchVelocity = 0;
|
|
79807
80081
|
this._panVelocity[0] = 0;
|
|
79808
80082
|
this._panVelocity[1] = 0;
|
|
79809
80083
|
}
|
|
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));
|
|
80084
|
+
const orbit = isOrbit ? 1 : 0;
|
|
80085
|
+
const fly = isFirstPerson ? 1 : 0;
|
|
80086
|
+
const double = this._touchCount > 1 ? 1 : 0;
|
|
80087
|
+
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
80088
|
+
const dragInvert = (isFirstPerson && !gamingControls) ? -1 : 1;
|
|
80089
|
+
const { deltas } = frame;
|
|
80090
|
+
// move
|
|
80091
|
+
const v = tmpV$2.set(0, 0, 0);
|
|
80092
|
+
// two-finger orbit-pan when in orbit mode (single touch is rotate, double is pan)
|
|
80093
|
+
screenToWorld(cameraComponent, touch[0], touch[1], distance, orbitMove);
|
|
80094
|
+
v.add(orbitMove.mulScalar(orbit * double));
|
|
80095
|
+
if (gamingControls) {
|
|
80096
|
+
// joystick UI drives strafe + forward/back in fly/walk
|
|
80097
|
+
flyMoveTmp.set(this._joystick[0], 0, -this._joystick[1]);
|
|
80098
|
+
v.add(flyMoveTmp.mulScalar(fly * this.moveSpeed * dt));
|
|
79855
80099
|
}
|
|
79856
80100
|
else {
|
|
79857
|
-
//
|
|
80101
|
+
// smoothed pan velocity → strafe (X) and vertical (Y, fly only)
|
|
79858
80102
|
flyTouchPan.set(this._panVelocity[0], isWalk ? 0 : -this._panVelocity[1], 0);
|
|
79859
80103
|
v.add(flyTouchPan.mulScalar(fly * this.touchPinchMoveSensitivity * this.moveSpeed * dt));
|
|
79860
|
-
//
|
|
79861
|
-
|
|
79862
|
-
v.add(
|
|
80104
|
+
// smoothed pinch velocity → forward/back
|
|
80105
|
+
flyMoveTmp.set(0, 0, this._pinchVelocity);
|
|
80106
|
+
v.add(flyMoveTmp.mulScalar(fly * this.touchPinchMoveSensitivity * this.moveSpeed * dt));
|
|
79863
80107
|
}
|
|
79864
|
-
|
|
79865
|
-
|
|
79866
|
-
|
|
80108
|
+
// raw pinch for orbit-mode zoom
|
|
80109
|
+
pinchMoveTmp.set(0, 0, pinch[0]);
|
|
80110
|
+
v.add(pinchMoveTmp.mulScalar(orbit * double * this.pinchSpeed * DISPLACEMENT_SCALE));
|
|
80111
|
+
// tap-to-jump in walk + gaming controls
|
|
79867
80112
|
if (isWalk && this._tapJump) {
|
|
79868
80113
|
v.y = 1;
|
|
79869
80114
|
this._tapJump = false;
|
|
79870
80115
|
}
|
|
79871
80116
|
deltas.move.append([v.x, v.y, v.z]);
|
|
79872
|
-
//
|
|
80117
|
+
// rotate
|
|
79873
80118
|
v.set(0, 0, 0);
|
|
80119
|
+
// single-touch orbit rotate (masked when there are 2+ touches)
|
|
79874
80120
|
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
|
|
80121
|
+
v.add(orbitRotate.mulScalar(orbit * (1 - double) * this.orbitSpeed * this.touchRotateSensitivity * DISPLACEMENT_SCALE));
|
|
80122
|
+
// single-touch fly look (inverted in non-gaming first-person)
|
|
79878
80123
|
flyRotate.set(touch[0] * dragInvert, touch[1] * dragInvert, 0);
|
|
79879
80124
|
v.add(flyRotate.mulScalar(fly * (1 - double) * this.orbitSpeed * orbitFactor * this.touchRotateSensitivity * DISPLACEMENT_SCALE));
|
|
79880
80125
|
deltas.rotate.append([v.x, v.y, v.z]);
|
|
79881
|
-
|
|
79882
|
-
|
|
79883
|
-
|
|
79884
|
-
|
|
79885
|
-
|
|
79886
|
-
|
|
79887
|
-
|
|
79888
|
-
|
|
79889
|
-
|
|
79890
|
-
|
|
80126
|
+
}
|
|
80127
|
+
}
|
|
80128
|
+
|
|
80129
|
+
/**
|
|
80130
|
+
* Distinguishes a physical mouse wheel from a trackpad two-finger scroll.
|
|
80131
|
+
*
|
|
80132
|
+
* A single wheel event is unreliable (Magic Mouse, hi-res mice, and macOS
|
|
80133
|
+
* Shift-remapping all confuse per-event heuristics), so classify on the
|
|
80134
|
+
* first event of a burst and let the rest of the burst inherit that label.
|
|
80135
|
+
* A burst is a run of wheel events separated by less than BURST_GAP_MS;
|
|
80136
|
+
* trackpads stream at ~60Hz (~16ms), wheels emit one event per notch
|
|
80137
|
+
* (typically >>50ms apart).
|
|
80138
|
+
*/
|
|
80139
|
+
const BURST_GAP_MS = 80;
|
|
80140
|
+
const isMouseWheelEvent = (event) => {
|
|
80141
|
+
// Firefox: physical wheels report line/page mode; trackpads report
|
|
80142
|
+
// pixel mode. Firefox doesn't expose wheelDelta* so this is the only
|
|
80143
|
+
// reliable signal there.
|
|
80144
|
+
if (event.deltaMode !== WheelEvent.DOM_DELTA_PIXEL) {
|
|
80145
|
+
return true;
|
|
80146
|
+
}
|
|
80147
|
+
// Chrome / Safari: the non-standard wheelDelta{X,Y} properties preserve
|
|
80148
|
+
// the raw wheel-tick value (always multiples of ±120 per notch)
|
|
80149
|
+
// regardless of macOS scroll smoothing. Trackpads and Magic Mouse emit
|
|
80150
|
+
// arbitrary values that are essentially never aligned to 120.
|
|
80151
|
+
const e = event;
|
|
80152
|
+
if (typeof e.wheelDeltaY === 'number' && e.wheelDeltaY !== 0) {
|
|
80153
|
+
return e.wheelDeltaY % 120 === 0;
|
|
80154
|
+
}
|
|
80155
|
+
if (typeof e.wheelDeltaX === 'number' && e.wheelDeltaX !== 0) {
|
|
80156
|
+
return e.wheelDeltaX % 120 === 0;
|
|
80157
|
+
}
|
|
80158
|
+
// Last-resort fallback for browsers without wheelDelta*.
|
|
80159
|
+
const { deltaX, deltaY } = event;
|
|
80160
|
+
if (deltaX !== 0 && deltaY !== 0) {
|
|
80161
|
+
return false;
|
|
80162
|
+
}
|
|
80163
|
+
return Number.isInteger(deltaX) && Number.isInteger(deltaY);
|
|
80164
|
+
};
|
|
80165
|
+
class WheelClassifier {
|
|
80166
|
+
_lastTime = -Infinity;
|
|
80167
|
+
_burstIsMouseWheel = false;
|
|
80168
|
+
/**
|
|
80169
|
+
* Classify the given event. The first event of a burst sets the label
|
|
80170
|
+
* for the burst; subsequent events within BURST_GAP_MS inherit it.
|
|
80171
|
+
*
|
|
80172
|
+
* @param event - The wheel event to classify.
|
|
80173
|
+
* @returns True if the event came from a physical mouse wheel.
|
|
80174
|
+
*/
|
|
80175
|
+
classify(event) {
|
|
80176
|
+
const now = performance.now();
|
|
80177
|
+
if (now - this._lastTime > BURST_GAP_MS) {
|
|
80178
|
+
this._burstIsMouseWheel = isMouseWheelEvent(event);
|
|
80179
|
+
}
|
|
80180
|
+
this._lastTime = now;
|
|
80181
|
+
return this._burstIsMouseWheel;
|
|
80182
|
+
}
|
|
80183
|
+
}
|
|
80184
|
+
|
|
80185
|
+
const tmpV$1 = new Vec3();
|
|
80186
|
+
class TrackpadDevice {
|
|
80187
|
+
orbitSpeed = 18;
|
|
80188
|
+
wheelSpeed = 0.06;
|
|
80189
|
+
trackpadOrbitSensitivity = 0.75;
|
|
80190
|
+
trackpadPanSensitivity = 1.0;
|
|
80191
|
+
trackpadZoomSensitivity = 2.0;
|
|
80192
|
+
_classifier = new WheelClassifier();
|
|
80193
|
+
_global = null;
|
|
80194
|
+
_orbit = [0, 0];
|
|
80195
|
+
_pan = [0, 0];
|
|
80196
|
+
_zoom = 0;
|
|
80197
|
+
_onWheel = (event) => {
|
|
80198
|
+
if (this._classifier.classify(event)) {
|
|
80199
|
+
// physical mouse wheel — KeyboardMouseSource handles it
|
|
80200
|
+
return;
|
|
80201
|
+
}
|
|
80202
|
+
const mode = this._global.state.cameraMode;
|
|
80203
|
+
const isFirstPersonMode = mode === 'fly' || mode === 'walk';
|
|
80204
|
+
const hasZoomModifier = event.ctrlKey || event.metaKey;
|
|
80205
|
+
if (mode === 'orbit') ;
|
|
80206
|
+
else if (isFirstPersonMode && !hasZoomModifier) ;
|
|
80207
|
+
else {
|
|
80208
|
+
return;
|
|
80209
|
+
}
|
|
80210
|
+
event.preventDefault();
|
|
80211
|
+
// stopImmediatePropagation() blocks KeyboardMouseSource's wheel
|
|
80212
|
+
// handler (also attached to this canvas) so the wheel delta
|
|
80213
|
+
// doesn't double-up on the existing forward/back path. It also
|
|
80214
|
+
// blocks the canvas-level interrupt listener registered elsewhere,
|
|
80215
|
+
// so fire interrupt explicitly to keep parity with mouse-wheel.
|
|
80216
|
+
event.stopImmediatePropagation();
|
|
80217
|
+
this._global.events.fire('inputEvent', 'interrupt', event);
|
|
80218
|
+
const { deltaX, deltaY } = event;
|
|
80219
|
+
if (mode === 'orbit') {
|
|
80220
|
+
if (event.ctrlKey || event.metaKey) {
|
|
80221
|
+
// pinch on macOS arrives as ctrl+wheel; ctrl/meta+scroll routes here too
|
|
80222
|
+
this._zoom += deltaY;
|
|
80223
|
+
}
|
|
80224
|
+
else if (event.shiftKey) {
|
|
80225
|
+
this._pan[0] += deltaX;
|
|
80226
|
+
this._pan[1] += deltaY;
|
|
80227
|
+
}
|
|
80228
|
+
else {
|
|
80229
|
+
this._orbit[0] += deltaX;
|
|
80230
|
+
this._orbit[1] += deltaY;
|
|
80231
|
+
}
|
|
80232
|
+
}
|
|
80233
|
+
else {
|
|
80234
|
+
// fly / walk: always rotate (shift is a speed modifier, not a gesture)
|
|
80235
|
+
this._orbit[0] += deltaX;
|
|
80236
|
+
this._orbit[1] += deltaY;
|
|
80237
|
+
}
|
|
80238
|
+
};
|
|
80239
|
+
_canvas = null;
|
|
80240
|
+
/**
|
|
80241
|
+
* Trackpad must attach BEFORE KeyboardMouseSource so its
|
|
80242
|
+
* `stopImmediatePropagation()` blocks the mouse-source wheel handler
|
|
80243
|
+
* for trackpad bursts. The coordinator enforces this by attaching
|
|
80244
|
+
* trackpad before keyboard-mouse.
|
|
80245
|
+
*
|
|
80246
|
+
* @param canvas - The canvas element to listen to.
|
|
80247
|
+
* @param global - The global app context (state, events, etc.).
|
|
80248
|
+
*/
|
|
80249
|
+
attach(canvas, global) {
|
|
80250
|
+
this._canvas = canvas;
|
|
80251
|
+
this._global = global;
|
|
80252
|
+
canvas.addEventListener('wheel', this._onWheel, { passive: false });
|
|
80253
|
+
}
|
|
80254
|
+
detach() {
|
|
80255
|
+
if (this._canvas) {
|
|
80256
|
+
this._canvas.removeEventListener('wheel', this._onWheel);
|
|
80257
|
+
this._canvas = null;
|
|
80258
|
+
}
|
|
80259
|
+
this._global = null;
|
|
80260
|
+
this._orbit[0] = this._orbit[1] = 0;
|
|
80261
|
+
this._pan[0] = this._pan[1] = 0;
|
|
80262
|
+
this._zoom = 0;
|
|
80263
|
+
}
|
|
80264
|
+
update(ctx, frame) {
|
|
80265
|
+
const { isOrbit, isFirstPerson, distance, cameraComponent } = ctx;
|
|
80266
|
+
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
80267
|
+
const { deltas } = frame;
|
|
80268
|
+
if (isOrbit) {
|
|
80269
|
+
// orbit rotate
|
|
80270
|
+
const v = tmpV$1.set(this._orbit[0], this._orbit[1], 0);
|
|
80271
|
+
v.mulScalar(this.orbitSpeed * this.trackpadOrbitSensitivity * DISPLACEMENT_SCALE);
|
|
80272
|
+
deltas.rotate.append([v.x, v.y, 0]);
|
|
80273
|
+
// pan in world space (matches desktop pan path); reuse tmpV after rotate append
|
|
80274
|
+
screenToWorld(cameraComponent, this._pan[0], this._pan[1], distance, tmpV$1);
|
|
80275
|
+
tmpV$1.mulScalar(this.trackpadPanSensitivity);
|
|
80276
|
+
deltas.move.append([tmpV$1.x, tmpV$1.y, 0]);
|
|
80277
|
+
// zoom along z; positive deltaY (scroll-down / pinch-in) → zoom out → +z for orbit
|
|
80278
|
+
const zoomZ = this._zoom * this.wheelSpeed * this.trackpadZoomSensitivity * DISPLACEMENT_SCALE;
|
|
80279
|
+
deltas.move.append([0, 0, zoomZ]);
|
|
80280
|
+
}
|
|
80281
|
+
else if (isFirstPerson) {
|
|
80282
|
+
// fly / walk look-around (only the no-modifier swipe is captured;
|
|
80283
|
+
// pinch / Ctrl-swipe fall through to the wheel→forward path)
|
|
80284
|
+
const v = tmpV$1.set(this._orbit[0], this._orbit[1], 0);
|
|
80285
|
+
v.mulScalar(this.orbitSpeed * orbitFactor * this.trackpadOrbitSensitivity * DISPLACEMENT_SCALE);
|
|
80286
|
+
deltas.rotate.append([v.x, v.y, 0]);
|
|
80287
|
+
}
|
|
80288
|
+
this._orbit[0] = this._orbit[1] = 0;
|
|
80289
|
+
this._pan[0] = this._pan[1] = 0;
|
|
80290
|
+
this._zoom = 0;
|
|
80291
|
+
}
|
|
80292
|
+
}
|
|
80293
|
+
|
|
80294
|
+
/**
|
|
80295
|
+
* Coordinator that wires together input devices (keyboard-mouse, touch,
|
|
80296
|
+
* trackpad, gamepad) and app-level UX helpers (mode shortcuts, walk
|
|
80297
|
+
* interaction, pointer lock, input-mode tracker), and exposes the
|
|
80298
|
+
* resulting per-frame `InputFrame` for the camera manager to consume.
|
|
80299
|
+
*/
|
|
80300
|
+
class InputController {
|
|
80301
|
+
frame = new InputFrame({
|
|
80302
|
+
move: [0, 0, 0],
|
|
80303
|
+
rotate: [0, 0, 0]
|
|
80304
|
+
});
|
|
80305
|
+
_global;
|
|
80306
|
+
_trackpad = new TrackpadDevice();
|
|
80307
|
+
_keyboardMouse = new KeyboardMouseDevice();
|
|
80308
|
+
_touch = new TouchDevice();
|
|
80309
|
+
_gamepad = new GamepadDevice();
|
|
80310
|
+
_walkInteraction = new WalkInteraction();
|
|
80311
|
+
_pointerLock = new PointerLockManager();
|
|
80312
|
+
_modeShortcuts = new ModeShortcuts();
|
|
80313
|
+
_inputModeTracker = new InputModeTracker();
|
|
80314
|
+
set collision(value) {
|
|
80315
|
+
this._walkInteraction.collision = value;
|
|
80316
|
+
}
|
|
80317
|
+
get collision() {
|
|
80318
|
+
return this._walkInteraction.collision;
|
|
80319
|
+
}
|
|
80320
|
+
constructor(global) {
|
|
80321
|
+
this._global = global;
|
|
80322
|
+
const { app, events } = global;
|
|
80323
|
+
const canvas = app.graphicsDevice.canvas;
|
|
80324
|
+
// Trackpad MUST attach before KeyboardMouseDevice so its wheel
|
|
80325
|
+
// handler runs first; otherwise stopImmediatePropagation can't
|
|
80326
|
+
// block KeyboardMouseSource from also accumulating the wheel delta.
|
|
80327
|
+
this._trackpad.attach(canvas, global);
|
|
80328
|
+
this._keyboardMouse.attach(canvas, global);
|
|
80329
|
+
this._touch.attach(canvas, global);
|
|
80330
|
+
this._gamepad.attach(canvas, global);
|
|
80331
|
+
this._walkInteraction.attach(canvas, global);
|
|
80332
|
+
this._pointerLock.attach(canvas, global, this._keyboardMouse);
|
|
80333
|
+
this._modeShortcuts.attach(global, this._pointerLock);
|
|
80334
|
+
this._inputModeTracker.attach(global);
|
|
80335
|
+
// canvas-level signals: anything that interrupts an animation /
|
|
80336
|
+
// closes the settings panel / dismisses the walk hint
|
|
80337
|
+
['wheel', 'pointerdown', 'contextmenu', 'keydown'].forEach((eventName) => {
|
|
80338
|
+
canvas.addEventListener(eventName, (event) => {
|
|
80339
|
+
events.fire('inputEvent', 'interrupt', event);
|
|
80340
|
+
});
|
|
80341
|
+
});
|
|
80342
|
+
canvas.addEventListener('pointermove', (event) => {
|
|
80343
|
+
events.fire('inputEvent', 'interact', event);
|
|
80344
|
+
});
|
|
80345
|
+
}
|
|
80346
|
+
update(dt, distance) {
|
|
80347
|
+
const { state } = this._global;
|
|
80348
|
+
const cameraComponent = this._global.camera.camera;
|
|
80349
|
+
const isOrbit = state.cameraMode === 'orbit';
|
|
80350
|
+
const isFly = state.cameraMode === 'fly';
|
|
80351
|
+
const isWalk = state.cameraMode === 'walk';
|
|
80352
|
+
const isFirstPerson = isFly || isWalk;
|
|
80353
|
+
const ctx = {
|
|
80354
|
+
dt,
|
|
80355
|
+
distance,
|
|
80356
|
+
cameraComponent,
|
|
80357
|
+
mode: state.cameraMode,
|
|
80358
|
+
isOrbit,
|
|
80359
|
+
isFly,
|
|
80360
|
+
isWalk,
|
|
80361
|
+
isFirstPerson,
|
|
80362
|
+
gamingControls: state.gamingControls,
|
|
80363
|
+
// Touch must update first so the count is current; the running
|
|
80364
|
+
// count is also used by the keyboard-mouse pan flag.
|
|
80365
|
+
touchCount: this._touch.touchCount
|
|
80366
|
+
};
|
|
80367
|
+
// order: touch first (so touchCount in ctx reflects this frame's
|
|
80368
|
+
// count delta), then everyone else.
|
|
80369
|
+
this._touch.update(ctx, this.frame);
|
|
80370
|
+
ctx.touchCount = this._touch.touchCount;
|
|
80371
|
+
this._keyboardMouse.update(ctx, this.frame);
|
|
80372
|
+
this._trackpad.update(ctx, this.frame);
|
|
80373
|
+
this._gamepad.update(ctx, this.frame);
|
|
80374
|
+
}
|
|
80375
|
+
}
|
|
80376
|
+
|
|
80377
|
+
// Single-layer overlay rendered after the gaussians, three passes on a fresh
|
|
80378
|
+
// depth buffer:
|
|
80379
|
+
//
|
|
80380
|
+
// 1. Surface depth pre-pass: color writes masked off, depth test/write on.
|
|
80381
|
+
// Stamps the front-most surface depth into the depth buffer.
|
|
80382
|
+
// 2. Surface color pass: depthFunc EQUAL, depth write off, vertex-color
|
|
80383
|
+
// tinted via StandardMaterial. Only the front-most fragment from pass 1
|
|
80384
|
+
// survives so a single layer of semi-transparent surface color blends
|
|
80385
|
+
// onto the camera target.
|
|
80386
|
+
// 3. Wireframe pass: opaque-looking black lines (RENDERSTYLE_WIREFRAME),
|
|
80387
|
+
// depth-tested against the surface depth so back-facing edges are
|
|
80388
|
+
// hidden.
|
|
80389
|
+
//
|
|
80390
|
+
// All three passes use BLEND_NORMAL so they share the layer's *transparent*
|
|
80391
|
+
// render action. PlayCanvas creates separate opaque and transparent render
|
|
80392
|
+
// actions per layer and `clearDepthBuffer` clears the depth buffer for each
|
|
80393
|
+
// of them — if the depth pre-pass were opaque, the transparent action would
|
|
80394
|
+
// wipe the depth before pass 2 and FUNC_EQUAL would always fail.
|
|
80395
|
+
// Linear gray levels picked by dominant face axis, plus the surface alpha.
|
|
80396
|
+
// These values are what we want the framebuffer to actually contain — pre-
|
|
80397
|
+
// encoding below makes that true regardless of the gamma path taken.
|
|
80398
|
+
const SURFACE_GRAY_X = 0.85;
|
|
80399
|
+
const SURFACE_GRAY_Y = 0.55;
|
|
80400
|
+
const SURFACE_GRAY_Z = 0.30;
|
|
80401
|
+
const SURFACE_ALPHA = 0.30;
|
|
80402
|
+
// Build an unindexed mesh where every triangle has three unique vertices that
|
|
80403
|
+
// share the triangle's flat face color (tint by dominant axis of the face
|
|
80404
|
+
// normal, alpha baked in). Per-triangle vertices give the surface a faceted
|
|
80405
|
+
// look matching the voxel overlay.
|
|
80406
|
+
//
|
|
80407
|
+
// `cameraFrameEnabled` controls how the per-vertex color is encoded so the
|
|
80408
|
+
// overlay looks identical between the WebGL (no CameraFrame) and
|
|
80409
|
+
// WebGPU/compute (CameraFrame) paths. With CameraFrame on, the engine's
|
|
80410
|
+
// `gammaCorrectOutput` is a no-op (GAMMA_NONE) and the StandardMaterial
|
|
80411
|
+
// output lands in the framebuffer as-is — so we feed the raw gray value.
|
|
80412
|
+
// Without CameraFrame, `gammaCorrectOutput` applies `pow(1/2.2)` to the
|
|
80413
|
+
// material output, so we feed `pow(gray, 2.2)` here and gamma-correct
|
|
80414
|
+
// undoes it; the framebuffer ends up storing the same raw gray value.
|
|
80415
|
+
// Encode the per-triangle gray + alpha into a flat Uint8 RGBA color stream
|
|
80416
|
+
// (one entry per unwelded vertex, three vertices per triangle). Reuses an
|
|
80417
|
+
// existing buffer if one is provided so colors can be re-baked when the
|
|
80418
|
+
// CameraFrame state toggles at runtime (e.g. XR start/end).
|
|
80419
|
+
const encodeFlatColors = (tris, cameraFrameEnabled, out) => {
|
|
80420
|
+
const encode = (v) => Math.round((cameraFrameEnabled ? v : Math.pow(v, 2.2)) * 255);
|
|
80421
|
+
const grayX = encode(SURFACE_GRAY_X);
|
|
80422
|
+
const grayY = encode(SURFACE_GRAY_Y);
|
|
80423
|
+
const grayZ = encode(SURFACE_GRAY_Z);
|
|
80424
|
+
const alpha = Math.round(SURFACE_ALPHA * 255);
|
|
80425
|
+
const numTris = tris.count;
|
|
80426
|
+
const colors = out ?? new Uint8Array(numTris * 12);
|
|
80427
|
+
for (let i = 0; i < numTris; i++) {
|
|
80428
|
+
const ax = Math.abs(tris.nx[i]);
|
|
80429
|
+
const ay = Math.abs(tris.ny[i]);
|
|
80430
|
+
const az = Math.abs(tris.nz[i]);
|
|
80431
|
+
let gray;
|
|
80432
|
+
if (ax > ay && ax > az) {
|
|
80433
|
+
gray = grayX;
|
|
80434
|
+
}
|
|
80435
|
+
else if (ay > az) {
|
|
80436
|
+
gray = grayY;
|
|
80437
|
+
}
|
|
80438
|
+
else {
|
|
80439
|
+
gray = grayZ;
|
|
80440
|
+
}
|
|
80441
|
+
const oc = i * 12;
|
|
80442
|
+
for (let j = 0; j < 3; j++) {
|
|
80443
|
+
const k = oc + j * 4;
|
|
80444
|
+
colors[k] = gray;
|
|
80445
|
+
colors[k + 1] = gray;
|
|
80446
|
+
colors[k + 2] = gray;
|
|
80447
|
+
colors[k + 3] = alpha;
|
|
80448
|
+
}
|
|
80449
|
+
}
|
|
80450
|
+
return colors;
|
|
80451
|
+
};
|
|
80452
|
+
const buildFlatMesh = (tris, cameraFrameEnabled) => {
|
|
80453
|
+
const numTris = tris.count;
|
|
80454
|
+
const flatPositions = new Float32Array(numTris * 9);
|
|
80455
|
+
const flatColors = encodeFlatColors(tris, cameraFrameEnabled);
|
|
80456
|
+
const flatIndices = new Uint32Array(numTris * 3);
|
|
80457
|
+
for (let i = 0; i < numTris; i++) {
|
|
80458
|
+
const op = i * 9;
|
|
80459
|
+
flatPositions[op] = tris.v0x[i];
|
|
80460
|
+
flatPositions[op + 1] = tris.v0y[i];
|
|
80461
|
+
flatPositions[op + 2] = tris.v0z[i];
|
|
80462
|
+
flatPositions[op + 3] = tris.v1x[i];
|
|
80463
|
+
flatPositions[op + 4] = tris.v1y[i];
|
|
80464
|
+
flatPositions[op + 5] = tris.v1z[i];
|
|
80465
|
+
flatPositions[op + 6] = tris.v2x[i];
|
|
80466
|
+
flatPositions[op + 7] = tris.v2y[i];
|
|
80467
|
+
flatPositions[op + 8] = tris.v2z[i];
|
|
80468
|
+
const oi = i * 3;
|
|
80469
|
+
flatIndices[oi] = oi;
|
|
80470
|
+
flatIndices[oi + 1] = oi + 1;
|
|
80471
|
+
flatIndices[oi + 2] = oi + 2;
|
|
80472
|
+
}
|
|
80473
|
+
return { flatPositions, flatColors, flatIndices };
|
|
80474
|
+
};
|
|
80475
|
+
// Configures a StandardMaterial that emits the per-vertex color directly. The
|
|
80476
|
+
// depth pre-pass and the color pass use the same configuration (so they
|
|
80477
|
+
// compile to identical shaders and produce bit-identical depth values for
|
|
80478
|
+
// FUNC_EQUAL); only their write masks and depth state differ.
|
|
80479
|
+
const makeSurfaceMaterial = () => {
|
|
80480
|
+
const m = new StandardMaterial();
|
|
80481
|
+
m.useLighting = false;
|
|
80482
|
+
m.useSkybox = false;
|
|
80483
|
+
m.useFog = false;
|
|
80484
|
+
m.useTonemap = false;
|
|
80485
|
+
m.ambient = new Color(0, 0, 0);
|
|
80486
|
+
m.diffuse = new Color(0, 0, 0);
|
|
80487
|
+
m.specular = new Color(0, 0, 0);
|
|
80488
|
+
m.emissive = new Color(1, 1, 1);
|
|
80489
|
+
m.emissiveVertexColor = true;
|
|
80490
|
+
m.emissiveVertexColorChannel = 'rgb';
|
|
80491
|
+
m.opacityVertexColor = true;
|
|
80492
|
+
m.opacityVertexColorChannel = 'a';
|
|
80493
|
+
m.opacity = 1;
|
|
80494
|
+
return m;
|
|
80495
|
+
};
|
|
80496
|
+
class MeshDebugOverlay {
|
|
80497
|
+
app;
|
|
80498
|
+
camera;
|
|
80499
|
+
layer;
|
|
80500
|
+
entity;
|
|
80501
|
+
mesh;
|
|
80502
|
+
triangles;
|
|
80503
|
+
flatColors;
|
|
80504
|
+
materials;
|
|
80505
|
+
_enabled = false;
|
|
80506
|
+
constructor(app, collision, camera, cameraFrameEnabled) {
|
|
80507
|
+
this.app = app;
|
|
80508
|
+
this.camera = camera;
|
|
80509
|
+
this.triangles = collision.triangles;
|
|
80510
|
+
const device = app.graphicsDevice;
|
|
80511
|
+
const { flatPositions, flatColors, flatIndices } = buildFlatMesh(this.triangles, cameraFrameEnabled);
|
|
80512
|
+
this.flatColors = flatColors;
|
|
80513
|
+
const mesh = new Mesh(device);
|
|
80514
|
+
mesh.setPositions(flatPositions);
|
|
80515
|
+
mesh.setColors32(flatColors);
|
|
80516
|
+
mesh.setIndices(flatIndices);
|
|
80517
|
+
mesh.update(PRIMITIVE_TRIANGLES);
|
|
80518
|
+
mesh.generateWireframe();
|
|
80519
|
+
this.mesh = mesh;
|
|
80520
|
+
this.layer = new Layer({
|
|
80521
|
+
name: 'CollisionOverlay',
|
|
80522
|
+
enabled: false,
|
|
80523
|
+
clearColorBuffer: false,
|
|
80524
|
+
clearDepthBuffer: true,
|
|
80525
|
+
opaqueSortMode: SORTMODE_MANUAL,
|
|
80526
|
+
transparentSortMode: SORTMODE_MANUAL
|
|
80527
|
+
});
|
|
80528
|
+
app.scene.layers.push(this.layer);
|
|
80529
|
+
camera.camera.layers = [...camera.camera.layers, this.layer.id];
|
|
80530
|
+
// Pass 1: depth pre-pass. Color writes masked off so only depth lands
|
|
80531
|
+
// in the buffer. Both this and pass 2 use the same depthBias /
|
|
80532
|
+
// slopeDepthBias so they write/test identical depth values
|
|
80533
|
+
// (FUNC_EQUAL relies on this) while still sitting slightly behind the
|
|
80534
|
+
// wireframe lines so pass 3's FUNC_LESSEQUAL passes reliably without
|
|
80535
|
+
// z-fighting.
|
|
80536
|
+
const depthMaterial = makeSurfaceMaterial();
|
|
80537
|
+
depthMaterial.cull = CULLFACE_BACK;
|
|
80538
|
+
depthMaterial.blendType = BLEND_NORMAL;
|
|
80539
|
+
depthMaterial.depthTest = true;
|
|
80540
|
+
depthMaterial.depthWrite = true;
|
|
80541
|
+
depthMaterial.depthBias = 1;
|
|
80542
|
+
depthMaterial.slopeDepthBias = 1;
|
|
80543
|
+
depthMaterial.redWrite = false;
|
|
80544
|
+
depthMaterial.greenWrite = false;
|
|
80545
|
+
depthMaterial.blueWrite = false;
|
|
80546
|
+
depthMaterial.alphaWrite = false;
|
|
80547
|
+
depthMaterial.update();
|
|
80548
|
+
const depthInstance = new MeshInstance(mesh, depthMaterial);
|
|
80549
|
+
depthInstance.drawOrder = 0;
|
|
80550
|
+
const depthEntity = new Entity('CollisionDepthPrepass');
|
|
80551
|
+
depthEntity.addComponent('render', {
|
|
80552
|
+
meshInstances: [depthInstance],
|
|
80553
|
+
layers: [this.layer.id]
|
|
80554
|
+
});
|
|
80555
|
+
// Pass 2: surface color, depth EQUAL. Only the front-most fragment
|
|
80556
|
+
// from pass 1 survives, so a single layer of vertex color blends onto
|
|
80557
|
+
// the camera target.
|
|
80558
|
+
const surfaceMaterial = makeSurfaceMaterial();
|
|
80559
|
+
surfaceMaterial.cull = CULLFACE_BACK;
|
|
80560
|
+
surfaceMaterial.blendType = BLEND_NORMAL;
|
|
80561
|
+
surfaceMaterial.depthTest = true;
|
|
80562
|
+
surfaceMaterial.depthFunc = FUNC_EQUAL;
|
|
80563
|
+
surfaceMaterial.depthWrite = false;
|
|
80564
|
+
surfaceMaterial.depthBias = 1;
|
|
80565
|
+
surfaceMaterial.slopeDepthBias = 1;
|
|
80566
|
+
surfaceMaterial.update();
|
|
80567
|
+
const surfaceInstance = new MeshInstance(mesh, surfaceMaterial);
|
|
80568
|
+
surfaceInstance.drawOrder = 1;
|
|
80569
|
+
const surfaceEntity = new Entity('CollisionSurface');
|
|
80570
|
+
surfaceEntity.addComponent('render', {
|
|
80571
|
+
meshInstances: [surfaceInstance],
|
|
80572
|
+
layers: [this.layer.id]
|
|
80573
|
+
});
|
|
80574
|
+
// Pass 3: wireframe — black lines depth-tested against the surface so
|
|
80575
|
+
// back-facing edges are hidden. BLEND_NORMAL with opacity = 1 looks
|
|
80576
|
+
// opaque but routes through the same transparent render action as the
|
|
80577
|
+
// other two passes, keeping all three under one depth clear.
|
|
80578
|
+
const wireframeMaterial = new StandardMaterial();
|
|
80579
|
+
wireframeMaterial.useLighting = false;
|
|
80580
|
+
wireframeMaterial.useSkybox = false;
|
|
80581
|
+
wireframeMaterial.useFog = false;
|
|
80582
|
+
wireframeMaterial.useTonemap = false;
|
|
80583
|
+
wireframeMaterial.ambient = new Color(0, 0, 0);
|
|
80584
|
+
wireframeMaterial.diffuse = new Color(0, 0, 0);
|
|
80585
|
+
wireframeMaterial.specular = new Color(0, 0, 0);
|
|
80586
|
+
wireframeMaterial.emissive = new Color(0, 0, 0);
|
|
80587
|
+
wireframeMaterial.opacity = 1;
|
|
80588
|
+
wireframeMaterial.blendType = BLEND_NORMAL;
|
|
80589
|
+
wireframeMaterial.depthTest = true;
|
|
80590
|
+
wireframeMaterial.depthFunc = FUNC_LESSEQUAL;
|
|
80591
|
+
wireframeMaterial.depthWrite = false;
|
|
80592
|
+
wireframeMaterial.cull = CULLFACE_NONE;
|
|
80593
|
+
wireframeMaterial.update();
|
|
80594
|
+
const wireframeInstance = new MeshInstance(mesh, wireframeMaterial);
|
|
80595
|
+
wireframeInstance.drawOrder = 2;
|
|
80596
|
+
const wireframeEntity = new Entity('CollisionWireframe');
|
|
80597
|
+
wireframeEntity.addComponent('render', {
|
|
80598
|
+
meshInstances: [wireframeInstance],
|
|
80599
|
+
layers: [this.layer.id]
|
|
80600
|
+
});
|
|
80601
|
+
wireframeEntity.render.renderStyle = RENDERSTYLE_WIREFRAME;
|
|
80602
|
+
this.materials = [depthMaterial, surfaceMaterial, wireframeMaterial];
|
|
80603
|
+
this.entity = new Entity('MeshCollisionDebug');
|
|
80604
|
+
this.entity.addChild(depthEntity);
|
|
80605
|
+
this.entity.addChild(surfaceEntity);
|
|
80606
|
+
this.entity.addChild(wireframeEntity);
|
|
80607
|
+
this.entity.enabled = false;
|
|
80608
|
+
app.root.addChild(this.entity);
|
|
80609
|
+
}
|
|
80610
|
+
set enabled(value) {
|
|
80611
|
+
this._enabled = value;
|
|
80612
|
+
this.entity.enabled = value;
|
|
80613
|
+
// Disable the layer too — otherwise its render actions still execute
|
|
80614
|
+
// each frame and the per-layer `clearDepthBuffer` would wipe depth
|
|
80615
|
+
// even when no overlay meshes are submitted.
|
|
80616
|
+
this.layer.enabled = value;
|
|
80617
|
+
}
|
|
80618
|
+
get enabled() {
|
|
80619
|
+
return this._enabled;
|
|
80620
|
+
}
|
|
80621
|
+
/**
|
|
80622
|
+
* Re-bake and re-upload the per-vertex colors so the overlay stays
|
|
80623
|
+
* correct if CameraFrame is destroyed or recreated at runtime (the
|
|
80624
|
+
* gamma path differs between the two states).
|
|
80625
|
+
*
|
|
80626
|
+
* @param cameraFrameEnabled - whether CameraFrame is currently active.
|
|
80627
|
+
*/
|
|
80628
|
+
setCameraFrameEnabled(cameraFrameEnabled) {
|
|
80629
|
+
encodeFlatColors(this.triangles, cameraFrameEnabled, this.flatColors);
|
|
80630
|
+
this.mesh.setColors32(this.flatColors);
|
|
80631
|
+
this.mesh.update(PRIMITIVE_TRIANGLES);
|
|
80632
|
+
}
|
|
80633
|
+
destroy() {
|
|
80634
|
+
// Entity.destroy() removes child entities and tears down their render
|
|
80635
|
+
// components, which destroy the MeshInstances and decref the shared
|
|
80636
|
+
// Mesh (the last decref destroys its GPU buffers). Materials are not
|
|
80637
|
+
// owned by MeshInstance so destroy them explicitly here.
|
|
80638
|
+
this.entity?.destroy();
|
|
80639
|
+
for (const m of this.materials)
|
|
80640
|
+
m.destroy();
|
|
80641
|
+
this.materials.length = 0;
|
|
80642
|
+
this.app.scene.layers.remove(this.layer);
|
|
80643
|
+
this.camera.camera.layers = this.camera.camera.layers.filter(id => id !== this.layer.id);
|
|
79891
80644
|
}
|
|
79892
80645
|
}
|
|
79893
80646
|
|
|
@@ -79905,11 +80658,12 @@ const MAX_STEPS: u32 = 512u;
|
|
|
79905
80658
|
// Target wireframe edge width in pixels
|
|
79906
80659
|
const EDGE_PIXELS: f32 = 1.5;
|
|
79907
80660
|
|
|
79908
|
-
// Wireframe edge alpha
|
|
79909
|
-
|
|
80661
|
+
// Wireframe edge alpha (1.0 = pure black opaque edges, matching the mesh
|
|
80662
|
+
// overlay's wireframe pass).
|
|
80663
|
+
const EDGE_ALPHA: f32 = 0.8;
|
|
79910
80664
|
|
|
79911
|
-
// Interior fill alpha (
|
|
79912
|
-
const FILL_ALPHA: f32 = 0.
|
|
80665
|
+
// Interior fill alpha (matching the mesh overlay's surface alpha).
|
|
80666
|
+
const FILL_ALPHA: f32 = 0.30;
|
|
79913
80667
|
|
|
79914
80668
|
struct Uniforms {
|
|
79915
80669
|
invVP: mat4x4<f32>,
|
|
@@ -80018,14 +80772,16 @@ fn edgeFactor(hitPos: vec3f, voxMin: vec3f, voxSize: f32, edgeWidth: f32) -> f32
|
|
|
80018
80772
|
return 1.0 - smoothstep(0.0, edgeWidth, edgeDist);
|
|
80019
80773
|
}
|
|
80020
80774
|
|
|
80021
|
-
// Shade a voxel hit, returning premultiplied RGBA
|
|
80022
|
-
|
|
80775
|
+
// Shade a voxel hit, returning premultiplied RGBA. Uses the same face-axis
|
|
80776
|
+
// grayscale palette as the mesh collision overlay (0.85 / 0.55 / 0.30 by
|
|
80777
|
+
// dominant axis), with pure black at face edges to mimic that overlay's
|
|
80778
|
+
// wireframe pass.
|
|
80779
|
+
fn shadeVoxelHit(hitPos: vec3f, voxMin: vec3f, voxelRes: f32, ro: vec3f) -> vec4f {
|
|
80023
80780
|
let dist = length(hitPos - ro);
|
|
80024
80781
|
let pixelWorld = 2.0 * dist / (f32(uniforms.screenHeight) * uniforms.projScaleY);
|
|
80025
80782
|
let ew = clamp(EDGE_PIXELS * pixelWorld / voxelRes, 0.01, 0.5);
|
|
80026
80783
|
|
|
80027
80784
|
let ef = edgeFactor(hitPos, voxMin, voxelRes, ew);
|
|
80028
|
-
let distFade = clamp(1.0 - dist * 0.01, 0.2, 1.0);
|
|
80029
80785
|
|
|
80030
80786
|
let local = (hitPos - voxMin) / voxelRes;
|
|
80031
80787
|
let fx = min(local.x, 1.0 - local.x);
|
|
@@ -80040,19 +80796,17 @@ fn shadeVoxelHit(hitPos: vec3f, voxMin: vec3f, voxelRes: f32, ro: vec3f, isFullB
|
|
|
80040
80796
|
}
|
|
80041
80797
|
|
|
80042
80798
|
var baseColor: vec3f;
|
|
80043
|
-
if (
|
|
80044
|
-
|
|
80045
|
-
|
|
80046
|
-
else { baseColor = vec3f(0.55, 0.08, 0.05); }
|
|
80047
|
-
} else {
|
|
80048
|
-
if (faceAxis == 0u) { baseColor = vec3f(0.7, 0.7, 0.72); }
|
|
80049
|
-
else if (faceAxis == 1u) { baseColor = vec3f(0.5, 0.5, 0.52); }
|
|
80050
|
-
else { baseColor = vec3f(0.33, 0.33, 0.35); }
|
|
80051
|
-
}
|
|
80799
|
+
if (faceAxis == 0u) { baseColor = vec3f(0.85); }
|
|
80800
|
+
else if (faceAxis == 1u) { baseColor = vec3f(0.55); }
|
|
80801
|
+
else { baseColor = vec3f(0.30); }
|
|
80052
80802
|
|
|
80053
|
-
|
|
80803
|
+
// Mix the surface base color toward black as the edge factor approaches 1
|
|
80804
|
+
// and ramp alpha from FILL_ALPHA up to EDGE_ALPHA so face edges read as
|
|
80805
|
+
// opaque black lines while the interior stays at the surface tint.
|
|
80806
|
+
let color = mix(baseColor, vec3f(0.0), ef);
|
|
80807
|
+
let alpha = mix(FILL_ALPHA, EDGE_ALPHA, ef);
|
|
80054
80808
|
|
|
80055
|
-
return vec4f(
|
|
80809
|
+
return vec4f(color * alpha, alpha);
|
|
80056
80810
|
}
|
|
80057
80811
|
|
|
80058
80812
|
// Blue (0) -> Cyan (0.25) -> Green (0.5) -> Yellow (0.75) -> Red (1.0)
|
|
@@ -80249,8 +81003,7 @@ fn main(@builtin(global_invocation_id) gid: vec3u) {
|
|
|
80249
81003
|
let voxMin = blockOrigin + vec3f(f32(vx), f32(vy), f32(vz)) * voxelRes;
|
|
80250
81004
|
let vHit = intersectAABB(ro, invDir, voxMin, voxMin + vec3f(voxelRes));
|
|
80251
81005
|
let hitPos = ro + rd * max(vHit.x, 0.0);
|
|
80252
|
-
let
|
|
80253
|
-
let result = shadeVoxelHit(hitPos, voxMin, voxelRes, ro, isFullBlock);
|
|
81006
|
+
let result = shadeVoxelHit(hitPos, voxMin, voxelRes, ro);
|
|
80254
81007
|
textureStore(outputTexture, vec2i(px, py), result);
|
|
80255
81008
|
} else {
|
|
80256
81009
|
let effort = f32(totalWork) / 256.0;
|
|
@@ -80852,6 +81605,7 @@ class Viewer {
|
|
|
80852
81605
|
annotations;
|
|
80853
81606
|
forceRenderNextFrame = false;
|
|
80854
81607
|
voxelOverlay = null;
|
|
81608
|
+
meshOverlay = null;
|
|
80855
81609
|
walkCursor = null;
|
|
80856
81610
|
origChunks;
|
|
80857
81611
|
constructor(global, gsplatLoad, skyboxLoad, collisionLoad) {
|
|
@@ -80999,16 +81753,25 @@ class Viewer {
|
|
|
80999
81753
|
this.inputController = new InputController(global);
|
|
81000
81754
|
this.inputController.collision = collision ?? null;
|
|
81001
81755
|
state.hasCollision = !!collision;
|
|
81002
|
-
// Create
|
|
81756
|
+
// Create collision debug overlay (voxel uses a compute shader, mesh
|
|
81757
|
+
// uses standard line rendering). The voxel path requires WebGPU.
|
|
81003
81758
|
if (collision instanceof VoxelCollision && config.renderer !== 'webgl') {
|
|
81004
81759
|
this.voxelOverlay = new VoxelDebugOverlay(app, collision, camera);
|
|
81005
81760
|
this.voxelOverlay.mode = config.heatmap ? 'heatmap' : 'overlay';
|
|
81006
|
-
state.
|
|
81007
|
-
events.on('
|
|
81761
|
+
state.hasCollisionOverlay = true;
|
|
81762
|
+
events.on('collisionOverlayEnabled:changed', (value) => {
|
|
81008
81763
|
this.voxelOverlay.enabled = value;
|
|
81009
81764
|
app.renderNextFrame = true;
|
|
81010
81765
|
});
|
|
81011
81766
|
}
|
|
81767
|
+
else if (collision instanceof MeshCollision) {
|
|
81768
|
+
this.meshOverlay = new MeshDebugOverlay(app, collision, camera, !!this.cameraFrame);
|
|
81769
|
+
state.hasCollisionOverlay = true;
|
|
81770
|
+
events.on('collisionOverlayEnabled:changed', (value) => {
|
|
81771
|
+
this.meshOverlay.enabled = value;
|
|
81772
|
+
app.renderNextFrame = true;
|
|
81773
|
+
});
|
|
81774
|
+
}
|
|
81012
81775
|
this.cameraManager = new CameraManager(global, sceneBound, collision);
|
|
81013
81776
|
applyCamera(this.cameraManager.camera);
|
|
81014
81777
|
if (collision) {
|
|
@@ -81187,6 +81950,10 @@ class Viewer {
|
|
|
81187
81950
|
camera.camera.clearColor = new Color(background.color);
|
|
81188
81951
|
}
|
|
81189
81952
|
}
|
|
81953
|
+
// Mesh overlay bakes its vertex colors based on the current gamma
|
|
81954
|
+
// path; reapply when CameraFrame is created/destroyed (e.g. on XR
|
|
81955
|
+
// start/end) so the overlay tracks the new path.
|
|
81956
|
+
this.meshOverlay?.setCameraFrameEnabled(!!this.cameraFrame);
|
|
81190
81957
|
}
|
|
81191
81958
|
}
|
|
81192
81959
|
|
|
@@ -82096,7 +82863,7 @@ const initXr = (global) => {
|
|
|
82096
82863
|
});
|
|
82097
82864
|
};
|
|
82098
82865
|
|
|
82099
|
-
var version = "1.
|
|
82866
|
+
var version = "1.21.0";
|
|
82100
82867
|
|
|
82101
82868
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
82102
82869
|
const { contents, contentUrl, aa } = config;
|
|
@@ -82174,7 +82941,7 @@ const createApp = async (canvas, config) => {
|
|
|
82174
82941
|
const app = new App(canvas, {
|
|
82175
82942
|
graphicsDevice: device,
|
|
82176
82943
|
mouse: new Mouse(canvas),
|
|
82177
|
-
touch: new TouchDevice(canvas),
|
|
82944
|
+
touch: new TouchDevice$1(canvas),
|
|
82178
82945
|
keyboard: new Keyboard(window)
|
|
82179
82946
|
});
|
|
82180
82947
|
// Create entity hierarchy
|
|
@@ -82264,8 +83031,8 @@ const main = async (canvas, settingsJson, config) => {
|
|
|
82264
83031
|
hasAR: false,
|
|
82265
83032
|
hasVR: false,
|
|
82266
83033
|
hasCollision: false,
|
|
82267
|
-
|
|
82268
|
-
|
|
83034
|
+
hasCollisionOverlay: false,
|
|
83035
|
+
collisionOverlayEnabled: false,
|
|
82269
83036
|
isFullscreen: false,
|
|
82270
83037
|
controlsHidden: false,
|
|
82271
83038
|
gamingControls: localStorage.getItem('gamingControls') === 'true'
|