@playcanvas/supersplat-viewer 1.16.9 → 1.16.10

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/public/index.js CHANGED
@@ -19317,7 +19317,7 @@ const rotation$5 = new Quat();
19317
19317
  const invParentRot = new Quat();
19318
19318
  const matrix = new Mat4();
19319
19319
  const target = new Vec3();
19320
- const up$1 = new Vec3();
19320
+ const up$2 = new Vec3();
19321
19321
  function createTest(attr, value) {
19322
19322
  if (attr instanceof Function) {
19323
19323
  return attr;
@@ -19850,17 +19850,17 @@ class GraphNode extends EventHandler {
19850
19850
  if (x instanceof Vec3) {
19851
19851
  target.copy(x);
19852
19852
  if (y instanceof Vec3) {
19853
- up$1.copy(y);
19853
+ up$2.copy(y);
19854
19854
  } else {
19855
- up$1.copy(Vec3.UP);
19855
+ up$2.copy(Vec3.UP);
19856
19856
  }
19857
19857
  } else if (z === undefined) {
19858
19858
  return;
19859
19859
  } else {
19860
19860
  target.set(x, y, z);
19861
- up$1.set(ux, uy, uz);
19861
+ up$2.set(ux, uy, uz);
19862
19862
  }
19863
- matrix.setLookAt(this.getPosition(), target, up$1);
19863
+ matrix.setLookAt(this.getPosition(), target, up$2);
19864
19864
  rotation$5.setFromMat4(matrix);
19865
19865
  this.setRotation(rotation$5);
19866
19866
  }
@@ -22084,7 +22084,7 @@ class RenderPassUpdateClustered extends RenderPass {
22084
22084
  let _skinUpdateIndex = 0;
22085
22085
  const viewProjMat = new Mat4();
22086
22086
  const viewInvMat = new Mat4();
22087
- const viewMat$1 = new Mat4();
22087
+ const viewMat = new Mat4();
22088
22088
  const viewMat3 = new Mat3();
22089
22089
  const tempSphere = new BoundingSphere();
22090
22090
  const tempFrustum = new Frustum();
@@ -22231,11 +22231,11 @@ class Renderer {
22231
22231
  viewInvMat.setTRS(pos, rot, Vec3.ONE);
22232
22232
  }
22233
22233
  this.viewInvId.setValue(viewInvMat.data);
22234
- viewMat$1.copy(viewInvMat).invert();
22235
- this.viewId.setValue(viewMat$1.data);
22236
- viewMat3.setFromMat4(viewMat$1);
22234
+ viewMat.copy(viewInvMat).invert();
22235
+ this.viewId.setValue(viewMat.data);
22236
+ viewMat3.setFromMat4(viewMat);
22237
22237
  this.viewId3.setValue(viewMat3.data);
22238
- viewProjMat.mul2(projMat, viewMat$1);
22238
+ viewProjMat.mul2(projMat, viewMat);
22239
22239
  this.viewProjId.setValue(viewProjMat.data);
22240
22240
  camera._storeShaderMatrices(viewProjMat, jitterX, jitterY, this.device.renderVersion);
22241
22241
  this.flipYId.setValue(flipY ? -1 : 1);
@@ -22319,8 +22319,8 @@ class Renderer {
22319
22319
  viewInvMat.setTRS(pos, rot, Vec3.ONE);
22320
22320
  this.viewInvId.setValue(viewInvMat.data);
22321
22321
  }
22322
- viewMat$1.copy(viewInvMat).invert();
22323
- viewProjMat.mul2(projMat, viewMat$1);
22322
+ viewMat.copy(viewInvMat).invert();
22323
+ viewProjMat.mul2(projMat, viewMat);
22324
22324
  camera.frustum.setFromMat4(viewProjMat);
22325
22325
  }
22326
22326
  setBaseConstants(device, material) {
@@ -70288,8 +70288,8 @@ const damp$1 = (damping, dt)=>1 - Math.pow(damping, dt * 1000);
70288
70288
  const offset$2 = new Vec3();
70289
70289
  const angles$1 = new Vec3();
70290
70290
  const forward$1 = new Vec3();
70291
- const right$1 = new Vec3();
70292
- const up = new Vec3();
70291
+ const right$2 = new Vec3();
70292
+ const up$1 = new Vec3();
70293
70293
  const rotation$3 = new Quat();
70294
70294
  let FlyController$1 = class FlyController extends InputController$1 {
70295
70295
  set pitchRange(value) {
@@ -70320,12 +70320,12 @@ let FlyController$1 = class FlyController extends InputController$1 {
70320
70320
  this._targetPose.rotate(angles$1.set(-rotate[1], -rotate[0], 0));
70321
70321
  rotation$3.setFromEulerAngles(this._pose.angles);
70322
70322
  rotation$3.transformVector(Vec3.FORWARD, forward$1);
70323
- rotation$3.transformVector(Vec3.RIGHT, right$1);
70324
- rotation$3.transformVector(Vec3.UP, up);
70323
+ rotation$3.transformVector(Vec3.RIGHT, right$2);
70324
+ rotation$3.transformVector(Vec3.UP, up$1);
70325
70325
  offset$2.set(0, 0, 0);
70326
70326
  offset$2.add(forward$1.mulScalar(move[2]));
70327
- offset$2.add(right$1.mulScalar(move[0]));
70328
- offset$2.add(up.mulScalar(move[1]));
70327
+ offset$2.add(right$2.mulScalar(move[0]));
70328
+ offset$2.add(up$1.mulScalar(move[1]));
70329
70329
  this._targetPose.move(offset$2);
70330
70330
  return this._pose.lerp(this._pose, this._targetPose, damp$1(this.moveDamping, dt), damp$1(this.rotateDamping, dt));
70331
70331
  }
@@ -72126,7 +72126,7 @@ const initJoystick = (dom, events, state) => {
72126
72126
  let lastTapTime = 0;
72127
72127
  // Update joystick visibility based on camera mode and input mode
72128
72128
  const updateJoystickVisibility = () => {
72129
- if ((state.cameraMode === 'fly' || state.cameraMode === 'fps') && state.inputMode === 'touch' && state.gamingControls) {
72129
+ if ((state.cameraMode === 'fly' || state.cameraMode === 'walk') && state.inputMode === 'touch' && state.gamingControls) {
72130
72130
  dom.joystickBase.classList.remove('hidden');
72131
72131
  dom.joystickBase.classList.toggle('mode-2d', joystickMode === '2d');
72132
72132
  dom.joystickBase.style.left = `${joystickFixedX}px`;
@@ -72297,7 +72297,7 @@ const initUI = (global) => {
72297
72297
  'settings', 'settingsPanel',
72298
72298
  'orbitCamera', 'flyCamera', 'fpsCamera',
72299
72299
  'retinaDisplayRow', 'retinaDisplayCheck', 'retinaDisplayOption',
72300
- 'gamingControlsRow', 'gamingControlsCheck', 'gamingControlsOption',
72300
+ 'gamingControlsDivider', 'gamingControlsRow', 'gamingControlsCheck', 'gamingControlsOption',
72301
72301
  'desktopClickToWalk', 'desktopGamingControls',
72302
72302
  'touchFlyClickToWalk', 'touchFlyGamingControls',
72303
72303
  'touchClickToWalk', 'touchGamingControls',
@@ -72360,17 +72360,9 @@ const initUI = (global) => {
72360
72360
  state.isFullscreen = false;
72361
72361
  }
72362
72362
  };
72363
- let shouldRestoreFullscreen = false;
72364
- events.on('restoreFullscreen', () => {
72365
- shouldRestoreFullscreen = true;
72366
- });
72367
72363
  if (hasFullscreenAPI) {
72368
72364
  document.addEventListener('fullscreenchange', () => {
72369
72365
  state.isFullscreen = !!document.fullscreenElement;
72370
- if (!document.fullscreenElement && shouldRestoreFullscreen) {
72371
- shouldRestoreFullscreen = false;
72372
- requestFullscreen();
72373
- }
72374
72366
  });
72375
72367
  }
72376
72368
  dom.enterFullscreen.addEventListener('click', requestFullscreen);
@@ -72400,14 +72392,23 @@ const initUI = (global) => {
72400
72392
  };
72401
72393
  events.on('retinaDisplay:changed', updateRetinaDisplay);
72402
72394
  updateRetinaDisplay();
72403
- // Gaming mode toggle
72395
+ // Gaming mode toggle (settings row visible on mobile only)
72404
72396
  dom.gamingControlsRow.addEventListener('click', () => {
72405
72397
  state.gamingControls = !state.gamingControls;
72406
72398
  });
72399
+ const updateGamingSettingsVisibility = () => {
72400
+ const isDesktop = state.inputMode === 'desktop';
72401
+ dom.gamingControlsDivider.classList.toggle('hidden', isDesktop);
72402
+ dom.gamingControlsRow.classList.toggle('hidden', isDesktop);
72403
+ };
72404
+ events.on('inputMode:changed', updateGamingSettingsVisibility);
72405
+ updateGamingSettingsVisibility();
72407
72406
  const updateGamingControls = () => {
72408
72407
  dom.gamingControlsCheck.classList.toggle('active', state.gamingControls);
72409
- dom.desktopClickToWalk.classList.toggle('hidden', state.gamingControls);
72410
- dom.desktopGamingControls.classList.toggle('hidden', !state.gamingControls);
72408
+ if (state.inputMode !== 'desktop') {
72409
+ dom.desktopClickToWalk.classList.toggle('hidden', state.gamingControls);
72410
+ dom.desktopGamingControls.classList.toggle('hidden', !state.gamingControls);
72411
+ }
72411
72412
  dom.touchFlyClickToWalk.classList.toggle('hidden', state.gamingControls);
72412
72413
  dom.touchFlyGamingControls.classList.toggle('hidden', !state.gamingControls);
72413
72414
  dom.touchClickToWalk.classList.toggle('hidden', state.gamingControls);
@@ -72446,15 +72447,19 @@ const initUI = (global) => {
72446
72447
  dom.touchTab.addEventListener('click', () => {
72447
72448
  updateInfoTab('touch');
72448
72449
  });
72449
- dom.info.addEventListener('click', () => {
72450
+ const toggleHelp = () => {
72450
72451
  updateInfoTab(state.inputMode);
72451
72452
  dom.infoPanel.classList.toggle('hidden');
72452
- });
72453
+ };
72454
+ dom.info.addEventListener('click', toggleHelp);
72453
72455
  dom.infoPanel.addEventListener('pointerdown', () => {
72454
72456
  dom.infoPanel.classList.add('hidden');
72455
72457
  });
72456
72458
  events.on('inputEvent', (event) => {
72457
- if (event === 'cancel') {
72459
+ if (event === 'toggleHelp') {
72460
+ toggleHelp();
72461
+ }
72462
+ else if (event === 'cancel') {
72458
72463
  // close info panel on cancel
72459
72464
  dom.infoPanel.classList.add('hidden');
72460
72465
  dom.settingsPanel.classList.add('hidden');
@@ -72575,28 +72580,26 @@ const initUI = (global) => {
72575
72580
  const updateCameraModeUI = () => {
72576
72581
  dom.orbitCamera.classList.toggle('active', state.cameraMode === 'orbit');
72577
72582
  dom.flyCamera.classList.toggle('active', state.cameraMode === 'fly');
72578
- dom.fpsCamera.classList.toggle('active', state.cameraMode === 'fps');
72583
+ dom.fpsCamera.classList.toggle('active', state.cameraMode === 'walk');
72579
72584
  };
72580
72585
  events.on('cameraMode:changed', updateCameraModeUI);
72581
72586
  // Walk mode hint banner (shown once per session on first FPS entry)
72582
72587
  let walkHintShown = false;
72583
72588
  const getWalkHintText = () => {
72584
72589
  if (state.inputMode === 'desktop') {
72585
- return state.gamingControls ?
72586
- 'WASD to move. Mouse to look around. Space to jump.' :
72587
- 'Click to walk. Click and drag to look around.';
72590
+ return 'Click to walk. WASD to move freely.';
72588
72591
  }
72589
72592
  return state.gamingControls ?
72590
72593
  'Use the joystick to move. Drag to look around. Tap to jump.' :
72591
72594
  'Tap to walk. Drag to look around.';
72592
72595
  };
72593
72596
  events.on('cameraMode:changed', (value) => {
72594
- if (value === 'fps' && !walkHintShown) {
72597
+ if (value === 'walk' && !walkHintShown) {
72595
72598
  walkHintShown = true;
72596
72599
  dom.walkHint.textContent = getWalkHintText();
72597
72600
  dom.walkHint.classList.remove('hidden');
72598
72601
  }
72599
- else if (value !== 'fps') {
72602
+ else if (value !== 'walk') {
72600
72603
  dom.walkHint.classList.add('hidden');
72601
72604
  }
72602
72605
  });
@@ -72633,7 +72636,7 @@ const initUI = (global) => {
72633
72636
  state.cameraMode = 'fly';
72634
72637
  });
72635
72638
  dom.fpsCamera.addEventListener('click', () => {
72636
- events.fire('inputEvent', 'toggleFps');
72639
+ events.fire('inputEvent', 'toggleWalk');
72637
72640
  });
72638
72641
  dom.reset.addEventListener('click', (event) => {
72639
72642
  events.fire('inputEvent', 'reset', event);
@@ -73669,12 +73672,45 @@ class FlyController {
73669
73672
  }
73670
73673
  }
73671
73674
 
73675
+ const p = new Pose();
73676
+ class OrbitController {
73677
+ controller;
73678
+ constructor() {
73679
+ this.controller = new OrbitController$1();
73680
+ this.controller.zoomRange = new Vec2(0.01, Infinity);
73681
+ this.controller.pitchRange = new Vec2(-90, 90);
73682
+ this.controller.rotateDamping = 0.97;
73683
+ this.controller.moveDamping = 0.97;
73684
+ this.controller.zoomDamping = 0.97;
73685
+ }
73686
+ onEnter(camera) {
73687
+ p.position.copy(camera.position);
73688
+ p.angles.copy(camera.angles);
73689
+ p.distance = camera.distance;
73690
+ this.controller.attach(p, false);
73691
+ }
73692
+ update(deltaTime, inputFrame, camera) {
73693
+ const pose = this.controller.update(inputFrame, deltaTime);
73694
+ camera.position.copy(pose.position);
73695
+ camera.angles.copy(pose.angles);
73696
+ camera.distance = pose.distance;
73697
+ }
73698
+ onExit(camera) {
73699
+ }
73700
+ goto(camera) {
73701
+ p.position.copy(camera.position);
73702
+ p.angles.copy(camera.angles);
73703
+ p.distance = camera.distance;
73704
+ this.controller.attach(p, false);
73705
+ }
73706
+ }
73707
+
73672
73708
  /** Pre-allocated push-out vector for capsule collision */
73673
73709
  const out = { x: 0, y: 0, z: 0 };
73674
73710
  const v = new Vec3();
73675
73711
  const d = new Vec3();
73676
73712
  const forward = new Vec3();
73677
- const right = new Vec3();
73713
+ const right$1 = new Vec3();
73678
73714
  const offset = new Vec3();
73679
73715
  const rotation = new Quat();
73680
73716
  /**
@@ -73684,7 +73720,7 @@ const rotation = new Quat();
73684
73720
  * Vertical motion is driven by gravity and resolved by capsule collision with the
73685
73721
  * voxel grid. The camera is positioned at eye height within the capsule.
73686
73722
  */
73687
- class FpsController {
73723
+ class WalkController {
73688
73724
  /**
73689
73725
  * Optional voxel collider for capsule collision with sliding
73690
73726
  */
@@ -73767,10 +73803,10 @@ class FpsController {
73767
73803
  // move
73768
73804
  rotation.setFromEulerAngles(0, this._angles.y, 0);
73769
73805
  rotation.transformVector(Vec3.FORWARD, forward);
73770
- rotation.transformVector(Vec3.RIGHT, right);
73806
+ rotation.transformVector(Vec3.RIGHT, right$1);
73771
73807
  offset.set(0, 0, 0);
73772
73808
  offset.add(forward.mulScalar(move[2]));
73773
- offset.add(right.mulScalar(move[0]));
73809
+ offset.add(right$1.mulScalar(move[0]));
73774
73810
  this._velocity.add(offset.mulScalar(this._grounded ? this.moveGroundSpeed : this.moveAirSpeed));
73775
73811
  const alpha = damp(this._grounded ? this.velocityDampingGround : this.velocityDampingAir, deltaTime);
73776
73812
  this._velocity.x = math.lerp(this._velocity.x, 0, alpha);
@@ -73836,39 +73872,6 @@ class FpsController {
73836
73872
  }
73837
73873
  }
73838
73874
 
73839
- const p = new Pose();
73840
- class OrbitController {
73841
- controller;
73842
- constructor() {
73843
- this.controller = new OrbitController$1();
73844
- this.controller.zoomRange = new Vec2(0.01, Infinity);
73845
- this.controller.pitchRange = new Vec2(-90, 90);
73846
- this.controller.rotateDamping = 0.97;
73847
- this.controller.moveDamping = 0.97;
73848
- this.controller.zoomDamping = 0.97;
73849
- }
73850
- onEnter(camera) {
73851
- p.position.copy(camera.position);
73852
- p.angles.copy(camera.angles);
73853
- p.distance = camera.distance;
73854
- this.controller.attach(p, false);
73855
- }
73856
- update(deltaTime, inputFrame, camera) {
73857
- const pose = this.controller.update(inputFrame, deltaTime);
73858
- camera.position.copy(pose.position);
73859
- camera.angles.copy(pose.angles);
73860
- camera.distance = pose.distance;
73861
- }
73862
- onExit(camera) {
73863
- }
73864
- goto(camera) {
73865
- p.position.copy(camera.position);
73866
- p.angles.copy(camera.angles);
73867
- p.distance = camera.distance;
73868
- this.controller.attach(p, false);
73869
- }
73870
- }
73871
-
73872
73875
  const RAD_TO_DEG = 180 / Math.PI;
73873
73876
  /** XZ distance below which the walker considers itself arrived */
73874
73877
  const ARRIVAL_DIST = 0.5;
@@ -73879,7 +73882,7 @@ const BLOCKED_DURATION = 0.2;
73879
73882
  /**
73880
73883
  * Generates synthetic move/rotate input to auto-walk toward a target position.
73881
73884
  *
73882
- * Designed to feed into FpsController's existing update path so there is no
73885
+ * Designed to feed into WalkController's existing update path so there is no
73883
73886
  * duplicated physics. Each frame it appends yaw-rotation and forward-movement
73884
73887
  * deltas to the shared CameraFrame, and monitors arrival / blocked conditions.
73885
73888
  */
@@ -73967,7 +73970,7 @@ class WalkSource {
73967
73970
  let yawDiff = targetYaw - cameraAngles.y;
73968
73971
  yawDiff = ((yawDiff % 360) + 540) % 360 - 180;
73969
73972
  const rotAlpha = damp(this.rotateDamping, dt);
73970
- // FpsController applies: _angles.y += -rotate[0]
73973
+ // WalkController applies: _angles.y += -rotate[0]
73971
73974
  frame.deltas.rotate.append([-(yawDiff * rotAlpha), 0, 0]);
73972
73975
  // scale forward speed by alignment: turn in place first, then accelerate
73973
73976
  const alignment = Math.max(0, Math.cos(yawDiff * Math.PI / 180));
@@ -74017,11 +74020,11 @@ class CameraManager {
74017
74020
  const controllers = {
74018
74021
  orbit: new OrbitController(),
74019
74022
  fly: new FlyController(),
74020
- fps: new FpsController(),
74023
+ walk: new WalkController(),
74021
74024
  anim: animTrack ? new AnimController(animTrack) : null
74022
74025
  };
74023
74026
  controllers.fly.collider = collider;
74024
- controllers.fps.collider = collider;
74027
+ controllers.walk.collider = collider;
74025
74028
  const walkSource = new WalkSource();
74026
74029
  walkSource.onComplete = () => {
74027
74030
  events.fire('walkComplete');
@@ -74039,7 +74042,7 @@ class CameraManager {
74039
74042
  const from = new Camera(this.camera); // stores the previous camera state during transition
74040
74043
  let fromMode = isObjectExperience ? 'orbit' : 'fly';
74041
74044
  // tracks the mode to restore when exiting FPS
74042
- let preFpsMode = 'fly';
74045
+ let preWalkMode = 'fly';
74043
74046
  // enter the initial controller
74044
74047
  getController(state.cameraMode).onEnter(this.camera);
74045
74048
  // transition state
@@ -74057,7 +74060,7 @@ class CameraManager {
74057
74060
  // update transition timer
74058
74061
  transitionTimer = Math.min(1, transitionTimer + deltaTime * transitionSpeed);
74059
74062
  const controller = getController(state.cameraMode);
74060
- if (state.cameraMode === 'fps') {
74063
+ if (state.cameraMode === 'walk') {
74061
74064
  walkSource.update(dt, this.camera.position, this.camera.angles, frame);
74062
74065
  }
74063
74066
  controller.update(dt, frame, target);
@@ -74100,20 +74103,20 @@ class CameraManager {
74100
74103
  case 'requestFirstPerson':
74101
74104
  state.cameraMode = 'fly';
74102
74105
  break;
74103
- case 'toggleFps':
74106
+ case 'toggleWalk':
74104
74107
  if (collider) {
74105
- if (state.cameraMode === 'fps') {
74106
- state.cameraMode = preFpsMode;
74108
+ if (state.cameraMode === 'walk') {
74109
+ state.cameraMode = preWalkMode;
74107
74110
  }
74108
74111
  else {
74109
- preFpsMode = state.cameraMode;
74110
- state.cameraMode = 'fps';
74112
+ preWalkMode = state.cameraMode;
74113
+ state.cameraMode = 'walk';
74111
74114
  }
74112
74115
  }
74113
74116
  break;
74114
- case 'exitFps':
74115
- if (state.cameraMode === 'fps') {
74116
- state.cameraMode = preFpsMode;
74117
+ case 'exitWalk':
74118
+ if (state.cameraMode === 'walk') {
74119
+ state.cameraMode = preWalkMode;
74117
74120
  }
74118
74121
  break;
74119
74122
  case 'cancel':
@@ -74130,7 +74133,7 @@ class CameraManager {
74130
74133
  });
74131
74134
  // handle camera mode switching
74132
74135
  events.on('cameraMode:changed', (value, prev) => {
74133
- if (prev === 'fps') {
74136
+ if (prev === 'walk') {
74134
74137
  walkSource.cancelWalk();
74135
74138
  }
74136
74139
  // snapshot the current pose before any controller mutation
@@ -74173,19 +74176,19 @@ class CameraManager {
74173
74176
  startTransition();
74174
74177
  });
74175
74178
  // tap-to-walk: start auto-walking toward a picked 3D position
74176
- events.on('walkTo', (position) => {
74177
- if (state.cameraMode === 'fps') {
74179
+ events.on('walkTo', (position, normal) => {
74180
+ if (state.cameraMode === 'walk') {
74178
74181
  walkSource.walkTo(position);
74179
- events.fire('walkIndicator:setTarget', position);
74182
+ events.fire('walkTarget:set', position, normal);
74180
74183
  }
74181
74184
  });
74182
74185
  // cancel any active auto-walk
74183
74186
  events.on('walkCancel', () => {
74184
74187
  walkSource.cancelWalk();
74185
- events.fire('walkIndicator:setTarget', null);
74188
+ events.fire('walkTarget:clear');
74186
74189
  });
74187
74190
  events.on('walkComplete', () => {
74188
- events.fire('walkIndicator:setTarget', null);
74191
+ events.fire('walkTarget:clear');
74189
74192
  });
74190
74193
  }
74191
74194
  }
@@ -74468,6 +74471,7 @@ class InputController {
74468
74471
  _mouseClickTracking = false;
74469
74472
  _mouseClickDelta = 0;
74470
74473
  _picker = null;
74474
+ collider = null;
74471
74475
  moveSpeed = 4;
74472
74476
  orbitSpeed = 18;
74473
74477
  pinchSpeed = 0.4;
@@ -74489,8 +74493,8 @@ class InputController {
74489
74493
  });
74490
74494
  this.global = global;
74491
74495
  const updateCanvasCursor = () => {
74492
- if (state.cameraMode === 'fps' && !state.gamingControls && state.inputMode === 'desktop') {
74493
- canvas.style.cursor = this._mouseClickTracking ? 'move' : 'pointer';
74496
+ if (state.cameraMode === 'walk' && !state.gamingControls && state.inputMode === 'desktop') {
74497
+ canvas.style.cursor = this._mouseClickTracking ? 'default' : 'pointer';
74494
74498
  }
74495
74499
  else {
74496
74500
  canvas.style.cursor = '';
@@ -74512,7 +74516,7 @@ class InputController {
74512
74516
  this._lastPointerOffsetX = event.offsetX;
74513
74517
  this._lastPointerOffsetY = event.offsetY;
74514
74518
  // Cancel any active auto-walk in click-to-walk mode
74515
- if (state.cameraMode === 'fps' && !state.gamingControls) {
74519
+ if (state.cameraMode === 'walk' && !state.gamingControls) {
74516
74520
  events.fire('walkCancel');
74517
74521
  }
74518
74522
  // Start desktop click-to-walk tracking
@@ -74546,17 +74550,11 @@ class InputController {
74546
74550
  if (this._mouseClickTracking && event.pointerType !== 'touch' && event.button === 0) {
74547
74551
  this._mouseClickTracking = false;
74548
74552
  updateCanvasCursor();
74549
- if (this._mouseClickDelta < TAP_EPSILON && state.cameraMode === 'fps' && !state.gamingControls) {
74550
- if (!this._picker) {
74551
- this._picker = new Picker(app, camera);
74553
+ if (this._mouseClickDelta < TAP_EPSILON && state.cameraMode === 'walk' && !state.gamingControls) {
74554
+ const result = this._pickVoxel(this._lastPointerOffsetX, this._lastPointerOffsetY);
74555
+ if (result) {
74556
+ events.fire('walkTo', result.position, result.normal);
74552
74557
  }
74553
- const pickX = this._lastPointerOffsetX / canvas.clientWidth;
74554
- const pickY = this._lastPointerOffsetY / canvas.clientHeight;
74555
- this._picker.pick(pickX, pickY).then((result) => {
74556
- if (result && state.cameraMode === 'fps' && !state.gamingControls) {
74557
- events.fire('walkTo', result);
74558
- }
74559
- });
74560
74558
  }
74561
74559
  }
74562
74560
  });
@@ -74564,7 +74562,7 @@ class InputController {
74564
74562
  events.on('inputEvent', async (eventName, event) => {
74565
74563
  switch (eventName) {
74566
74564
  case 'dblclick': {
74567
- if (state.cameraMode === 'fps')
74565
+ if (state.cameraMode === 'walk')
74568
74566
  break;
74569
74567
  if (!this._picker) {
74570
74568
  this._picker = new Picker(app, camera);
@@ -74583,13 +74581,16 @@ class InputController {
74583
74581
  state.inputMode = event.pointerType === 'touch' ? 'touch' : 'desktop';
74584
74582
  });
74585
74583
  });
74586
- let recentlyExitedFps = false;
74584
+ let recentlyExitedWalk = false;
74587
74585
  // handle keyboard events
74588
74586
  window.addEventListener('keydown', (event) => {
74589
74587
  if (event.key === 'Escape') {
74590
- if (recentlyExitedFps) ;
74591
- else if (state.cameraMode === 'fps') {
74592
- events.fire('inputEvent', 'exitFps', event);
74588
+ if (recentlyExitedWalk) ;
74589
+ else if (state.cameraMode === 'walk' && state.gamingControls && state.inputMode === 'desktop') {
74590
+ state.gamingControls = false;
74591
+ }
74592
+ else if (state.cameraMode === 'walk') {
74593
+ events.fire('inputEvent', 'exitWalk', event);
74593
74594
  }
74594
74595
  else {
74595
74596
  events.fire('inputEvent', 'cancel', event);
@@ -74604,10 +74605,29 @@ class InputController {
74604
74605
  state.cameraMode = 'fly';
74605
74606
  break;
74606
74607
  case '3':
74607
- events.fire('inputEvent', 'toggleFps');
74608
+ events.fire('inputEvent', 'toggleWalk');
74609
+ break;
74610
+ case 'v':
74611
+ if (state.hasVoxelOverlay) {
74612
+ state.voxelOverlayEnabled = !state.voxelOverlayEnabled;
74613
+ }
74614
+ break;
74615
+ case 'g':
74616
+ state.gamingControls = !state.gamingControls;
74617
+ break;
74618
+ case 'h':
74619
+ events.fire('inputEvent', 'toggleHelp');
74620
+ break;
74621
+ case 'w':
74622
+ case 'a':
74623
+ case 's':
74624
+ case 'd':
74625
+ if (state.cameraMode === 'walk' && state.inputMode === 'desktop' && !state.gamingControls) {
74626
+ state.gamingControls = true;
74627
+ }
74608
74628
  break;
74609
74629
  }
74610
- if (state.cameraMode !== 'fps') {
74630
+ if (state.cameraMode !== 'walk') {
74611
74631
  switch (event.key) {
74612
74632
  case 'f':
74613
74633
  events.fire('inputEvent', 'frame', event);
@@ -74618,59 +74638,33 @@ class InputController {
74618
74638
  case ' ':
74619
74639
  events.fire('inputEvent', 'playPause', event);
74620
74640
  break;
74621
- case 'v':
74622
- if (state.hasVoxelOverlay) {
74623
- state.voxelOverlayEnabled = !state.voxelOverlayEnabled;
74624
- }
74625
- break;
74626
74641
  }
74627
74642
  }
74628
74643
  }
74629
74644
  });
74630
- // Lock/unlock Escape key in fullscreen to prevent the browser from
74631
- // exiting both pointer lock and fullscreen on the same Escape press.
74632
- const lockEscape = () => {
74633
- const keyboard = navigator.keyboard;
74634
- if (keyboard && 'lock' in keyboard) {
74635
- keyboard.lock(['Escape']).catch(() => { });
74636
- }
74637
- };
74638
- const unlockKeyboard = () => {
74639
- const keyboard = navigator.keyboard;
74640
- if (keyboard && 'unlock' in keyboard) {
74641
- keyboard.unlock();
74642
- }
74643
- };
74644
74645
  const activatePointerLock = () => {
74645
74646
  this._desktopInput._pointerLock = true;
74646
74647
  canvas.requestPointerLock();
74647
- if (state.isFullscreen) {
74648
- lockEscape();
74649
- }
74650
74648
  };
74651
74649
  const deactivatePointerLock = () => {
74652
- unlockKeyboard();
74653
74650
  this._desktopInput._pointerLock = false;
74654
74651
  if (document.pointerLockElement === canvas) {
74655
- if (state.isFullscreen) {
74656
- events.fire('restoreFullscreen');
74657
- }
74658
74652
  document.exitPointerLock();
74659
74653
  }
74660
74654
  };
74661
- // Pointer lock management for FPS mode on desktop (gaming controls only)
74655
+ // Pointer lock management for walk mode on desktop (gaming controls only)
74662
74656
  events.on('cameraMode:changed', (value, prev) => {
74663
- if (value === 'fps' && state.inputMode === 'desktop' && state.gamingControls) {
74657
+ if (value === 'walk' && state.inputMode === 'desktop' && state.gamingControls) {
74664
74658
  activatePointerLock();
74665
74659
  }
74666
- else if (prev === 'fps') {
74660
+ else if (prev === 'walk') {
74667
74661
  deactivatePointerLock();
74668
74662
  }
74669
74663
  updateCanvasCursor();
74670
74664
  });
74671
- // Toggle pointer lock when gaming controls changes while in FPS
74665
+ // Toggle pointer lock when gaming controls changes while in walk mode
74672
74666
  events.on('gamingControls:changed', (value) => {
74673
- if (state.cameraMode === 'fps' && state.inputMode === 'desktop') {
74667
+ if (state.cameraMode === 'walk' && state.inputMode === 'desktop') {
74674
74668
  if (value) {
74675
74669
  activatePointerLock();
74676
74670
  }
@@ -74680,28 +74674,49 @@ class InputController {
74680
74674
  }
74681
74675
  updateCanvasCursor();
74682
74676
  });
74683
- // Also lock Escape if entering fullscreen while already in FPS mode
74684
- events.on('isFullscreen:changed', (value) => {
74685
- if (value && state.cameraMode === 'fps' && state.inputMode === 'desktop' && state.gamingControls) {
74686
- lockEscape();
74687
- }
74688
- });
74689
74677
  document.addEventListener('pointerlockchange', () => {
74690
- if (!document.pointerLockElement && state.cameraMode === 'fps' && state.gamingControls) {
74691
- recentlyExitedFps = true;
74678
+ if (!document.pointerLockElement && state.cameraMode === 'walk' && state.gamingControls) {
74679
+ recentlyExitedWalk = true;
74692
74680
  requestAnimationFrame(() => {
74693
- recentlyExitedFps = false;
74681
+ recentlyExitedWalk = false;
74694
74682
  });
74695
- events.fire('inputEvent', 'exitFps');
74683
+ if (state.inputMode === 'desktop') {
74684
+ state.gamingControls = false;
74685
+ }
74686
+ else {
74687
+ events.fire('inputEvent', 'exitWalk');
74688
+ }
74696
74689
  }
74697
74690
  });
74698
74691
  // Pointer lock request rejected (e.g., no user gesture, document hidden).
74699
- // Revert to avoid being stuck in FPS mode without mouse capture.
74692
+ // Revert to avoid being stuck in walk mode without mouse capture.
74700
74693
  document.addEventListener('pointerlockerror', () => {
74701
74694
  this._desktopInput._pointerLock = false;
74702
- events.fire('inputEvent', 'exitFps');
74695
+ if (state.inputMode === 'desktop') {
74696
+ state.gamingControls = false;
74697
+ }
74698
+ else {
74699
+ events.fire('inputEvent', 'exitWalk');
74700
+ }
74703
74701
  });
74704
74702
  }
74703
+ _pickVoxel(offsetX, offsetY) {
74704
+ if (!this.collider)
74705
+ return null;
74706
+ const { camera } = this.global;
74707
+ const cameraPos = camera.getPosition();
74708
+ camera.camera.screenToWorld(offsetX, offsetY, 1.0, tmpV1);
74709
+ tmpV1.sub(cameraPos).normalize();
74710
+ // PlayCanvas → voxel space: negate X and Y
74711
+ const hit = this.collider.queryRay(-cameraPos.x, -cameraPos.y, cameraPos.z, -tmpV1.x, -tmpV1.y, tmpV1.z, camera.camera.farClip);
74712
+ if (!hit)
74713
+ return null;
74714
+ const sn = this.collider.querySurfaceNormal(hit.x, hit.y, hit.z);
74715
+ return {
74716
+ position: new Vec3(-hit.x, -hit.y, hit.z),
74717
+ normal: new Vec3(-sn.nx, -sn.ny, sn.nz)
74718
+ };
74719
+ }
74705
74720
  /**
74706
74721
  * @param dt - delta time in seconds
74707
74722
  * @param state - the current state of the app
@@ -74724,13 +74739,13 @@ class InputController {
74724
74739
  }
74725
74740
  this._state.shift += key[keyCode.SHIFT];
74726
74741
  this._state.ctrl += key[keyCode.CTRL];
74727
- const isFps = state.cameraMode === 'fps';
74742
+ const isWalk = state.cameraMode === 'walk';
74728
74743
  // Cancel any active auto-walk when the user provides WASD/arrow input
74729
- if (isFps && (this._state.axis.x !== 0 || this._state.axis.z !== 0)) {
74744
+ if (isWalk && (this._state.axis.x !== 0 || this._state.axis.z !== 0)) {
74730
74745
  events.fire('walkCancel');
74731
74746
  }
74732
74747
  // Tap detection using existing MultiTouchSource deltas
74733
- if (isFps) {
74748
+ if (isWalk) {
74734
74749
  const prevTaps = this._tapTouches;
74735
74750
  this._tapTouches = Math.max(0, this._tapTouches + count[0]);
74736
74751
  // Touch just started (0 → 1+)
@@ -74745,19 +74760,10 @@ class InputController {
74745
74760
  if (prevTaps > 0 && this._tapTouches === 0) {
74746
74761
  if (this._tapDelta < TAP_EPSILON) {
74747
74762
  if (!state.gamingControls) {
74748
- // Tap-to-walk: pick the 3D location and auto-walk toward it
74749
- const { app, camera } = this.global;
74750
- const canvas = app.graphicsDevice.canvas;
74751
- if (!this._picker) {
74752
- this._picker = new Picker(app, camera);
74763
+ const result = this._pickVoxel(this._lastPointerOffsetX, this._lastPointerOffsetY);
74764
+ if (result && state.cameraMode === 'walk' && !state.gamingControls) {
74765
+ events.fire('walkTo', result.position, result.normal);
74753
74766
  }
74754
- const pickX = this._lastPointerOffsetX / canvas.clientWidth;
74755
- const pickY = this._lastPointerOffsetY / canvas.clientHeight;
74756
- this._picker.pick(pickX, pickY).then((result) => {
74757
- if (result && state.cameraMode === 'fps' && !state.gamingControls) {
74758
- events.fire('walkTo', result);
74759
- }
74760
- });
74761
74767
  }
74762
74768
  else {
74763
74769
  this._tapJump = true;
@@ -74768,7 +74774,7 @@ class InputController {
74768
74774
  else {
74769
74775
  this._tapTouches = 0;
74770
74776
  }
74771
- const isFirstPerson = state.cameraMode === 'fly' || isFps;
74777
+ const isFirstPerson = state.cameraMode === 'fly' || isWalk;
74772
74778
  // Accumulate pinch and pan deltas into velocity when not in gaming controls
74773
74779
  // pinch[0] = oldDist - newDist: negative when spreading, positive when closing
74774
74780
  // Spreading = forward → subtract pinch delta
@@ -74793,22 +74799,22 @@ class InputController {
74793
74799
  const double = +(this._state.touches > 1);
74794
74800
  const pan = this._state.mouse[2] || +(button[2] === -1) || double;
74795
74801
  const orbitFactor = fly ? camera.fov / 120 : 1;
74796
- const dragInvert = (isFps && !state.gamingControls) ? -1 : 1;
74802
+ const dragInvert = (isFirstPerson && !state.gamingControls) ? -1 : 1;
74797
74803
  const { deltas } = this.frame;
74798
74804
  // desktop move
74799
74805
  const v = tmpV1.set(0, 0, 0);
74800
74806
  const keyMove = this._state.axis.clone();
74801
- if (isFps) {
74802
- // In FPS mode, normalize only horizontal axes so jump doesn't reduce speed
74807
+ if (isWalk) {
74808
+ // In walk mode, normalize only horizontal axes so jump doesn't reduce speed
74803
74809
  keyMove.y = 0;
74804
74810
  }
74805
74811
  keyMove.normalize();
74806
- const shiftMul = isFps ? 2 : 4;
74807
- const ctrlMul = isFps ? 0.5 : 0.25;
74812
+ const shiftMul = isWalk ? 2 : 4;
74813
+ const ctrlMul = isWalk ? 0.5 : 0.25;
74808
74814
  const speed = this.moveSpeed * (this._state.shift ? shiftMul : this._state.ctrl ? ctrlMul : 1);
74809
74815
  v.add(keyMove.mulScalar(fly * speed * dt));
74810
- if (isFps) {
74811
- // Pass jump signal as raw Y; FPS controller uses move[1] > 0 as boolean trigger
74816
+ if (isWalk) {
74817
+ // Pass jump signal as raw Y; WalkController uses move[1] > 0 as boolean trigger
74812
74818
  v.y = this._state.jump > 0 ? 1 : 0;
74813
74819
  }
74814
74820
  const panMove = screenToWorld(camera, mouse[0], mouse[1], distance);
@@ -74819,7 +74825,7 @@ class InputController {
74819
74825
  deltas.move.append([v.x, v.y, orbit ? -v.z : v.z]);
74820
74826
  // desktop rotate
74821
74827
  v.set(0, 0, 0);
74822
- mouseRotate.set(mouse[0] * dragInvert, mouse[1] * dragInvert, 0);
74828
+ mouseRotate.set(mouse[0], mouse[1], 0);
74823
74829
  v.add(mouseRotate.mulScalar((1 - pan) * this.orbitSpeed * orbitFactor * this.mouseRotateSensitivity * DISPLACEMENT_SCALE));
74824
74830
  deltas.rotate.append([v.x, v.y, v.z]);
74825
74831
  // mobile move
@@ -74832,8 +74838,8 @@ class InputController {
74832
74838
  v.add(flyMove.mulScalar(fly * this.moveSpeed * dt));
74833
74839
  }
74834
74840
  else {
74835
- // Pan velocity → strafe (X) and vertical (Y, fly only — FPS uses gravity)
74836
- flyTouchPan.set(this._panVelocity[0], isFps ? 0 : -this._panVelocity[1], 0);
74841
+ // Pan velocity → strafe (X) and vertical (Y, fly only — walk uses gravity)
74842
+ flyTouchPan.set(this._panVelocity[0], isWalk ? 0 : -this._panVelocity[1], 0);
74837
74843
  v.add(flyTouchPan.mulScalar(fly * this.touchPinchMoveSensitivity * this.moveSpeed * dt));
74838
74844
  // Pinch velocity → forward/backward
74839
74845
  flyMove.set(0, 0, this._pinchVelocity);
@@ -74841,8 +74847,8 @@ class InputController {
74841
74847
  }
74842
74848
  pinchMove.set(0, 0, pinch[0]);
74843
74849
  v.add(pinchMove.mulScalar(orbit * double * this.pinchSpeed * DISPLACEMENT_SCALE));
74844
- // Tap-to-jump for mobile FPS mode
74845
- if (isFps && this._tapJump) {
74850
+ // Tap-to-jump for mobile walk mode
74851
+ if (isWalk && this._tapJump) {
74846
74852
  v.y = 1;
74847
74853
  this._tapJump = false;
74848
74854
  }
@@ -75469,566 +75475,204 @@ class VoxelDebugOverlay {
75469
75475
  }
75470
75476
  }
75471
75477
 
75472
- // ── gsplat fragment shader overrides (GLSL) ─────────────────────────────────
75473
- const gsplatPSGlsl = /* glsl */ `
75474
-
75475
- #ifndef DITHER_NONE
75476
- #include "bayerPS"
75477
- #include "opacityDitherPS"
75478
- varying float id;
75479
- #endif
75480
-
75481
- #if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
75482
- uniform float alphaClip;
75483
- #endif
75484
-
75485
- #ifdef PREPASS_PASS
75486
- varying float vLinearDepth;
75487
- #include "floatAsUintPS"
75488
- #endif
75489
-
75490
- varying mediump vec2 gaussianUV;
75491
- varying mediump vec4 gaussianColor;
75492
-
75493
- #if defined(GSPLAT_UNIFIED_ID) && defined(PICK_PASS)
75494
- flat varying uint vPickId;
75495
- #endif
75496
-
75497
- #ifdef PICK_PASS
75498
- #include "pickPS"
75499
- #endif
75500
-
75501
- #ifndef PICK_PASS
75502
- uniform vec4 camera_params;
75503
- #endif
75504
- uniform vec4 viewport_size;
75505
- uniform mat4 matrix_projection;
75506
-
75507
- uniform mat4 walk_viewInverse;
75508
- uniform vec3 walk_target;
75509
- uniform float walk_radius;
75510
- uniform float walk_time;
75511
-
75512
- float walkLinearizeDepth(float z) {
75513
- if (camera_params.w == 0.0)
75514
- return (camera_params.z * camera_params.y) /
75515
- (camera_params.y + z * (camera_params.z - camera_params.y));
75516
- else
75517
- return camera_params.z + z * (camera_params.y - camera_params.z);
75518
- }
75519
-
75520
- vec3 walkReconstructWorldPos() {
75521
- float linearDepth = walkLinearizeDepth(gl_FragCoord.z);
75522
- vec2 ndc = gl_FragCoord.xy * viewport_size.zw * 2.0 - 1.0;
75523
- vec3 viewPos = vec3(
75524
- ndc.x * linearDepth / matrix_projection[0][0],
75525
- ndc.y * linearDepth / matrix_projection[1][1],
75526
- -linearDepth
75527
- );
75528
- return (walk_viewInverse * vec4(viewPos, 1.0)).xyz;
75529
- }
75530
-
75531
- const float EXP4 = exp(-4.0);
75532
- const float INV_EXP4 = 1.0 / (1.0 - EXP4);
75533
-
75534
- float normExp(float x) {
75535
- return (exp(x * -4.0) - EXP4) * INV_EXP4;
75536
- }
75537
-
75538
- void main(void) {
75539
- mediump float A = dot(gaussianUV, gaussianUV);
75540
- if (A > 1.0) {
75541
- discard;
75542
- }
75543
-
75544
- mediump float alpha = normExp(A) * gaussianColor.a;
75545
-
75546
- #if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
75547
- if (alpha < alphaClip) {
75548
- discard;
75549
- }
75550
- #endif
75551
-
75552
- #ifdef PICK_PASS
75553
-
75554
- #ifdef GSPLAT_UNIFIED_ID
75555
- pcFragColor0 = encodePickOutput(vPickId);
75556
- #else
75557
- pcFragColor0 = getPickOutput();
75558
- #endif
75559
- #ifdef DEPTH_PICK_PASS
75560
- pcFragColor1 = getPickDepth();
75561
- #endif
75562
-
75563
- #elif SHADOW_PASS
75564
-
75565
- gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
75566
-
75567
- #elif PREPASS_PASS
75568
-
75569
- gl_FragColor = float2vec4(vLinearDepth);
75570
-
75571
- #else
75572
- if (alpha < 1.0 / 255.0) {
75573
- discard;
75574
- }
75575
-
75576
- #ifndef DITHER_NONE
75577
- opacityDither(alpha, id * 0.013);
75578
- #endif
75579
-
75580
- if (walk_radius > 0.0) {
75581
- vec3 walkWorldPos = walkReconstructWorldPos();
75582
- float xzDist = length(walkWorldPos.xz - walk_target.xz);
75583
-
75584
- float nd = xzDist / walk_radius;
75585
- float lightFalloff = 1.0 / (1.0 + nd * nd * 8.0);
75586
- float coreBoost = 1.0 / (1.0 + nd * nd * 200.0);
75587
-
75588
- float pulse = 1.0 + 0.1 * sin(walk_time * 3.0);
75589
-
75590
- float ringPhase = fract(walk_time * 0.5);
75591
- float ringPos = nd - ringPhase;
75592
- float ringFade = 1.0 - ringPhase;
75593
- float crest = smoothstep(0.1, 0.0, abs(ringPos)) * 1.0 * ringFade * (1.0 + lightFalloff);
75594
- float trough = smoothstep(0.25, 0.0, abs(ringPos + 0.15)) * -1.0 * ringFade;
75595
- float ring = crest + trough;
75596
-
75597
- float intensity = (lightFalloff * 0.8 + coreBoost * 1.5 + ring) * pulse;
75598
-
75599
- float lum = dot(gaussianColor.rgb, vec3(0.299, 0.587, 0.114));
75600
- float adaptiveIntensity = intensity * (1.0 - lum * 0.7);
75601
- vec3 litColor = gaussianColor.xyz * (1.0 + vec3(0.85, 0.92, 1.0) * adaptiveIntensity);
75602
- float spatialFalloff = normExp(A);
75603
- float boostedBase = mix(gaussianColor.a, 1.0, min(intensity * 0.3, 1.0));
75604
- float glowAlpha = spatialFalloff * boostedBase;
75605
-
75606
- gl_FragColor = vec4(litColor * glowAlpha, glowAlpha);
75607
- } else {
75608
- gl_FragColor = vec4(gaussianColor.xyz * alpha, alpha);
75609
- }
75610
- #endif
75611
- }
75612
- `;
75613
- // ── gsplat fragment shader overrides (WGSL) ─────────────────────────────────
75614
- const gsplatPSWgsl = /* wgsl */ `
75615
-
75616
- #ifndef DITHER_NONE
75617
- #include "bayerPS"
75618
- #include "opacityDitherPS"
75619
- varying id: f32;
75620
- #endif
75621
-
75622
- #if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
75623
- uniform alphaClip: f32;
75624
- #endif
75625
-
75626
- #ifdef PREPASS_PASS
75627
- varying vLinearDepth: f32;
75628
- #include "floatAsUintPS"
75629
- #endif
75630
-
75631
- const EXP4_F: f32 = exp(-4.0);
75632
- const INV_EXP4_F: f32 = 1.0 / (1.0 - EXP4_F);
75633
-
75634
- fn normExp(x: f32) -> f32 {
75635
- return (exp(x * -4.0) - EXP4_F) * INV_EXP4_F;
75636
- }
75637
-
75638
- varying gaussianUV: half2;
75639
- varying gaussianColor: half4;
75640
-
75641
- #if defined(GSPLAT_UNIFIED_ID) && defined(PICK_PASS)
75642
- varying @interpolate(flat) vPickId: u32;
75643
- #endif
75644
-
75645
- #ifdef PICK_PASS
75646
- #include "pickPS"
75647
- #endif
75648
-
75649
- uniform walk_viewInverse: mat4x4f;
75650
- uniform walk_target: vec3f;
75651
- uniform walk_radius: f32;
75652
- uniform walk_time: f32;
75653
-
75654
- fn walkLinearizeDepth(z: f32) -> f32 {
75655
- if (uniform.camera_params.w == 0.0) {
75656
- return (uniform.camera_params.z * uniform.camera_params.y) /
75657
- (uniform.camera_params.y + z * (uniform.camera_params.z - uniform.camera_params.y));
75658
- } else {
75659
- return uniform.camera_params.z + z * (uniform.camera_params.y - uniform.camera_params.z);
75660
- }
75661
- }
75662
-
75663
- fn walkReconstructWorldPos(fragCoord: vec4f) -> vec3f {
75664
- let linearDepth = walkLinearizeDepth(fragCoord.z);
75665
- let ndc = fragCoord.xy * uniform.viewport_size.zw * 2.0 - 1.0;
75666
- let viewPos = vec3f(
75667
- ndc.x * linearDepth / uniform.matrix_projection[0][0],
75668
- -ndc.y * linearDepth / uniform.matrix_projection[1][1],
75669
- -linearDepth
75670
- );
75671
- return (uniform.walk_viewInverse * vec4f(viewPos, 1.0)).xyz;
75672
- }
75673
-
75674
- @fragment
75675
- fn fragmentMain(input: FragmentInput) -> FragmentOutput {
75676
- var output: FragmentOutput;
75677
-
75678
- let uv = vec2f(gaussianUV);
75679
- let color = vec4f(gaussianColor);
75680
- let A: f32 = dot(uv, uv);
75681
- if (A > 1.0) {
75682
- discard;
75683
- return output;
75478
+ const SVGNS = 'http://www.w3.org/2000/svg';
75479
+ const NUM_SAMPLES = 12;
75480
+ const CIRCLE_OUTER_RADIUS = 0.3;
75481
+ const CIRCLE_INNER_RADIUS = 0.22;
75482
+ const BEZIER_K = 1 / 6;
75483
+ const tmpV = new Vec3();
75484
+ const tmpScreen = new Vec3();
75485
+ const tangent = new Vec3();
75486
+ const bitangent = new Vec3();
75487
+ const worldPt = new Vec3();
75488
+ const up = new Vec3(0, 1, 0);
75489
+ const right = new Vec3(1, 0, 0);
75490
+ const buildBezierRing = (sx, sy) => {
75491
+ const n = sx.length;
75492
+ let p = `M${sx[0].toFixed(1)},${sy[0].toFixed(1)}`;
75493
+ for (let i = 0; i < n; i++) {
75494
+ const i0 = (i - 1 + n) % n;
75495
+ const i1 = i;
75496
+ const i2 = (i + 1) % n;
75497
+ const i3 = (i + 2) % n;
75498
+ const cp1x = sx[i1] + (sx[i2] - sx[i0]) * BEZIER_K;
75499
+ const cp1y = sy[i1] + (sy[i2] - sy[i0]) * BEZIER_K;
75500
+ const cp2x = sx[i2] - (sx[i3] - sx[i1]) * BEZIER_K;
75501
+ const cp2y = sy[i2] - (sy[i3] - sy[i1]) * BEZIER_K;
75502
+ p += ` C${cp1x.toFixed(1)},${cp1y.toFixed(1)} ${cp2x.toFixed(1)},${cp2y.toFixed(1)} ${sx[i2].toFixed(1)},${sy[i2].toFixed(1)}`;
75684
75503
  }
75685
-
75686
- var alpha: f32 = normExp(A) * color.a;
75687
-
75688
- #if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
75689
- if (alpha < uniform.alphaClip) {
75690
- discard;
75691
- return output;
75692
- }
75693
- #endif
75694
-
75695
- #ifdef PICK_PASS
75696
-
75697
- #ifdef GSPLAT_UNIFIED_ID
75698
- output.color = encodePickOutput(vPickId);
75699
- #else
75700
- output.color = getPickOutput();
75701
- #endif
75702
- #ifdef DEPTH_PICK_PASS
75703
- output.color1 = getPickDepth();
75704
- #endif
75705
-
75706
- #elif SHADOW_PASS
75707
-
75708
- output.color = vec4f(0.0, 0.0, 0.0, 1.0);
75709
-
75710
- #elif PREPASS_PASS
75711
-
75712
- output.color = float2vec4(vLinearDepth);
75713
-
75714
- #else
75715
-
75716
- if (alpha < 1.0 / 255.0) {
75717
- discard;
75718
- return output;
75719
- }
75720
-
75721
- #ifndef DITHER_NONE
75722
- opacityDither(alpha, id * 0.013);
75723
- #endif
75724
-
75725
- let gc = color.xyz;
75726
-
75727
- if (uniform.walk_radius > 0.0) {
75728
- let walkWorldPos = walkReconstructWorldPos(pcPosition);
75729
- let xzDist = length(walkWorldPos.xz - uniform.walk_target.xz);
75730
-
75731
- let nd = xzDist / uniform.walk_radius;
75732
- let lightFalloff = 1.0 / (1.0 + nd * nd * 8.0);
75733
- let coreBoost = 1.0 / (1.0 + nd * nd * 200.0);
75734
-
75735
- let pulse = 1.0 + 0.1 * sin(uniform.walk_time * 3.0);
75736
-
75737
- let ringPhase = fract(uniform.walk_time * 0.5);
75738
- let ringPos = nd - ringPhase;
75739
- let ringFade = 1.0 - ringPhase;
75740
- let crest = smoothstep(0.1, 0.0, abs(ringPos)) * 1.0 * ringFade * (1.0 + lightFalloff);
75741
- let trough = smoothstep(0.25, 0.0, abs(ringPos + 0.15)) * -1.0 * ringFade;
75742
- let ring = crest + trough;
75743
-
75744
- let intensity = (lightFalloff * 0.8 + coreBoost * 1.5 + ring) * pulse;
75745
-
75746
- let lum = dot(gc, vec3f(0.299, 0.587, 0.114));
75747
- let adaptiveIntensity = intensity * (1.0 - lum * 0.7);
75748
- let litColor = gc * (1.0 + vec3f(0.85, 0.92, 1.0) * adaptiveIntensity);
75749
- let spatialFalloff = normExp(A);
75750
- let boostedBase = mix(color.a, 1.0, min(intensity * 0.3, 1.0));
75751
- let glowAlpha = spatialFalloff * boostedBase;
75752
-
75753
- output.color = vec4f(litColor * glowAlpha, glowAlpha);
75754
- } else {
75755
- output.color = vec4f(gc * alpha, alpha);
75756
- }
75757
- #endif
75758
-
75759
- return output;
75760
- }`;
75761
- // ── Particle shaders ────────────────────────────────────────────────────────
75762
- const particleVS = /* glsl */ `
75763
- attribute vec3 vertex_position;
75764
- attribute vec2 aQuadCorner;
75765
-
75766
- uniform mat4 matrix_viewProjection;
75767
- uniform mat4 walk_viewInverse;
75768
- uniform vec3 walk_target;
75769
- uniform float walk_time;
75770
-
75771
- varying vec2 vUV;
75772
- varying float vFade;
75773
-
75774
- void main() {
75775
- float rand0 = vertex_position.x;
75776
- float rand1 = vertex_position.y;
75777
- float rand2 = vertex_position.z;
75778
-
75779
- float baseAngle = rand0 * 6.28318530718;
75780
- float rBase = sqrt(rand2) * 0.4;
75781
- float r = rBase * smoothstep(0.0, 0.5, walk_time);
75782
-
75783
- float riseSpeed = 0.3 + rand2 * 0.4;
75784
- float t = fract(max(walk_time - rand1 * 2.0, 0.0) * riseSpeed);
75785
- float y = t * t * 1.5 - 0.1;
75786
-
75787
- float swirl = baseAngle + t * (0.5 + rand1);
75788
- float swirlR = r + 0.01;
75789
- vec3 center = walk_target + vec3(swirlR * cos(swirl), y, swirlR * sin(swirl));
75790
-
75791
- vec3 camRight = walk_viewInverse[0].xyz;
75792
- vec3 camUp = walk_viewInverse[1].xyz;
75793
- float halfSize = 0.00625;
75794
-
75795
- vec3 worldPos = center
75796
- + camRight * aQuadCorner.x * halfSize
75797
- + camUp * aQuadCorner.y * halfSize;
75798
-
75799
- gl_Position = matrix_viewProjection * vec4(worldPos, 1.0);
75800
- vUV = aQuadCorner;
75801
- float maxT = 1.0 - rBase;
75802
- vFade = smoothstep(0.0, 0.1, t) * smoothstep(maxT, maxT - 0.15, t);
75803
- }
75804
- `;
75805
- const particleVS_WGSL = /* wgsl */ `
75806
- attribute vertex_position: vec3f;
75807
- attribute aQuadCorner: vec2f;
75808
-
75809
- uniform matrix_viewProjection: mat4x4f;
75810
- uniform walk_viewInverse: mat4x4f;
75811
- uniform walk_target: vec3f;
75812
- uniform walk_time: f32;
75813
-
75814
- varying vUV: vec2f;
75815
- varying vFade: f32;
75816
-
75817
- @vertex fn vertexMain(input: VertexInput) -> VertexOutput {
75818
- var output: VertexOutput;
75819
-
75820
- let rand0 = input.vertex_position.x;
75821
- let rand1 = input.vertex_position.y;
75822
- let rand2 = input.vertex_position.z;
75823
-
75824
- let baseAngle = rand0 * 6.28318530718;
75825
- let rBase = sqrt(rand2) * 0.4;
75826
- let r = rBase * smoothstep(0.0, 0.5, uniform.walk_time);
75827
-
75828
- let riseSpeed = 0.3 + rand2 * 0.4;
75829
- let t = fract(max(uniform.walk_time - rand1 * 2.0, 0.0) * riseSpeed);
75830
- let y = t * t * 1.5 - 0.1;
75831
-
75832
- let swirl = baseAngle + t * (0.5 + rand1);
75833
- let swirlR = r + 0.01;
75834
- let center = uniform.walk_target + vec3f(swirlR * cos(swirl), y, swirlR * sin(swirl));
75835
-
75836
- let camRight = uniform.walk_viewInverse[0].xyz;
75837
- let camUp = uniform.walk_viewInverse[1].xyz;
75838
- let halfSize = 0.00625;
75839
-
75840
- let worldPos = center
75841
- + camRight * input.aQuadCorner.x * halfSize
75842
- + camUp * input.aQuadCorner.y * halfSize;
75843
-
75844
- output.position = uniform.matrix_viewProjection * vec4f(worldPos, 1.0);
75845
- output.vUV = input.aQuadCorner;
75846
- let maxT = 1.0 - rBase;
75847
- output.vFade = smoothstep(0.0, 0.1, t) * smoothstep(maxT, maxT - 0.15, t);
75848
- return output;
75849
- }
75850
- `;
75851
- const particleFS = /* glsl */ `
75852
- precision highp float;
75853
-
75854
- varying vec2 vUV;
75855
- varying float vFade;
75856
-
75857
- void main() {
75858
- float r = length(vUV);
75859
- if (r > 1.0 || vFade < 0.5) discard;
75860
- gl_FragColor = vec4(2.55, 2.76, 3.0, 1.0);
75861
- }
75862
- `;
75863
- const particleFS_WGSL = /* wgsl */ `
75864
- varying vUV: vec2f;
75865
- varying vFade: f32;
75866
-
75867
- @fragment fn fragmentMain(input: FragmentInput) -> FragmentOutput {
75868
- var output: FragmentOutput;
75869
-
75870
- let r = length(input.vUV);
75871
- if (r > 1.0 || input.vFade < 0.5) {
75872
- discard;
75873
- return output;
75874
- }
75875
- output.color = vec4f(2.55, 2.76, 3.0, 1.0);
75876
- return output;
75877
- }
75878
- `;
75879
- // ── Constants & helpers ─────────────────────────────────────────────────────
75880
- const PARTICLE_COUNT = 250;
75881
- const QUAD_CORNERS = [-1, -1, 1, -1, 1, 1, -1, 1];
75882
- const viewMat = new Mat4();
75883
- const invViewMat = new Mat4();
75884
- const targetVec = new Float32Array(3);
75885
- const mulberry32 = (seed) => {
75886
- return () => {
75887
- seed |= 0;
75888
- seed = seed + 0x6D2B79F5 | 0;
75889
- let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
75890
- t ^= t + Math.imul(t ^ t >>> 7, 61 | t);
75891
- return ((t ^ t >>> 14) >>> 0) / 4294967296;
75892
- };
75504
+ return `${p} Z`;
75893
75505
  };
75894
- // ── WalkIndicator ───────────────────────────────────────────────────────────
75895
- class WalkIndicator {
75506
+ class WalkCursor {
75507
+ svg;
75508
+ cursorPath;
75509
+ targetPath;
75896
75510
  app;
75897
- target = null;
75898
- startTime = 0;
75899
- visible = false;
75900
- origGlsl;
75901
- origWgsl;
75902
- particleEntity;
75903
- constructor(app) {
75511
+ camera;
75512
+ collider;
75513
+ canvas;
75514
+ active = false;
75515
+ walking = false;
75516
+ targetPos = null;
75517
+ targetNormal = null;
75518
+ onPointerMove;
75519
+ onPointerLeave;
75520
+ scratchX = new Float64Array(NUM_SAMPLES);
75521
+ scratchY = new Float64Array(NUM_SAMPLES);
75522
+ outerX = new Float64Array(NUM_SAMPLES);
75523
+ outerY = new Float64Array(NUM_SAMPLES);
75524
+ innerX = new Float64Array(NUM_SAMPLES);
75525
+ innerY = new Float64Array(NUM_SAMPLES);
75526
+ constructor(app, camera, collider, events, state) {
75904
75527
  this.app = app;
75905
- const device = app.graphicsDevice;
75906
- const glsl = ShaderChunks.get(device, 'glsl');
75907
- const wgsl = ShaderChunks.get(device, 'wgsl');
75908
- this.origGlsl = glsl.get('gsplatPS');
75909
- this.origWgsl = wgsl.get('gsplatPS');
75910
- glsl.set('gsplatPS', gsplatPSGlsl);
75911
- wgsl.set('gsplatPS', gsplatPSWgsl);
75912
- this.particleEntity = this.createParticleEntity();
75913
- app.on('framerender', () => {
75914
- if (this.target && this.visible) {
75915
- app.renderNextFrame = true;
75916
- }
75917
- });
75918
- }
75919
- createParticleEntity() {
75920
- const device = this.app.graphicsDevice;
75921
- const rng = mulberry32(42);
75922
- const totalVerts = PARTICLE_COUNT * 4;
75923
- const totalIndices = PARTICLE_COUNT * 6;
75924
- const particleData = new Float32Array(totalVerts * 3);
75925
- const corners = new Float32Array(totalVerts * 2);
75926
- const indices = new Uint16Array(totalIndices);
75927
- for (let i = 0; i < PARTICLE_COUNT; i++) {
75928
- const rand0 = i / PARTICLE_COUNT;
75929
- const rand1 = rng();
75930
- const rand2 = rng();
75931
- const base = i * 4;
75932
- for (let j = 0; j < 4; j++) {
75933
- const vi = base + j;
75934
- particleData[vi * 3] = rand0;
75935
- particleData[vi * 3 + 1] = rand1;
75936
- particleData[vi * 3 + 2] = rand2;
75937
- corners[vi * 2] = QUAD_CORNERS[j * 2];
75938
- corners[vi * 2 + 1] = QUAD_CORNERS[j * 2 + 1];
75528
+ this.camera = camera;
75529
+ this.collider = collider;
75530
+ this.canvas = app.graphicsDevice.canvas;
75531
+ this.svg = document.createElementNS(SVGNS, 'svg');
75532
+ this.svg.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;overflow:visible;z-index:1';
75533
+ this.canvas.parentElement.appendChild(this.svg);
75534
+ // Hover cursor: thick ring
75535
+ this.cursorPath = document.createElementNS(SVGNS, 'path');
75536
+ this.cursorPath.setAttribute('fill', 'white');
75537
+ this.cursorPath.setAttribute('fill-opacity', '0.6');
75538
+ this.cursorPath.setAttribute('fill-rule', 'evenodd');
75539
+ this.cursorPath.setAttribute('stroke', 'none');
75540
+ this.svg.appendChild(this.cursorPath);
75541
+ // Walk target: filled circle
75542
+ this.targetPath = document.createElementNS(SVGNS, 'path');
75543
+ this.targetPath.setAttribute('fill', 'white');
75544
+ this.targetPath.setAttribute('fill-opacity', '0.5');
75545
+ this.targetPath.setAttribute('stroke', 'none');
75546
+ this.targetPath.style.display = 'none';
75547
+ this.svg.appendChild(this.targetPath);
75548
+ this.svg.style.display = 'none';
75549
+ this.onPointerMove = (e) => {
75550
+ if (e.pointerType === 'touch')
75551
+ return;
75552
+ if (e.buttons) {
75553
+ this.cursorPath.style.display = 'none';
75554
+ return;
75939
75555
  }
75940
- const ii = i * 6;
75941
- indices[ii] = base;
75942
- indices[ii + 1] = base + 1;
75943
- indices[ii + 2] = base + 2;
75944
- indices[ii + 3] = base;
75945
- indices[ii + 4] = base + 2;
75946
- indices[ii + 5] = base + 3;
75947
- }
75948
- const mesh = new Mesh(device);
75949
- mesh.setPositions(particleData, 3);
75950
- mesh.setVertexStream(SEMANTIC_TEXCOORD1, corners, 2);
75951
- mesh.setIndices(indices);
75952
- mesh.update(PRIMITIVE_TRIANGLES);
75953
- const material = new ShaderMaterial({
75954
- uniqueName: 'walkParticleMaterial',
75955
- vertexGLSL: particleVS,
75956
- fragmentGLSL: particleFS,
75957
- vertexWGSL: particleVS_WGSL,
75958
- fragmentWGSL: particleFS_WGSL,
75959
- attributes: {
75960
- vertex_position: SEMANTIC_POSITION,
75961
- aQuadCorner: SEMANTIC_TEXCOORD1
75556
+ this.updateCursor(e.offsetX, e.offsetY);
75557
+ };
75558
+ this.onPointerLeave = () => {
75559
+ this.cursorPath.style.display = 'none';
75560
+ };
75561
+ this.canvas.addEventListener('pointermove', this.onPointerMove);
75562
+ this.canvas.addEventListener('pointerleave', this.onPointerLeave);
75563
+ const updateActive = () => {
75564
+ this.active = state.cameraMode === 'walk' &&
75565
+ !state.gamingControls &&
75566
+ state.inputMode === 'desktop';
75567
+ if (!this.active) {
75568
+ this.svg.style.display = 'none';
75962
75569
  }
75570
+ };
75571
+ events.on('cameraMode:changed', updateActive);
75572
+ events.on('gamingControls:changed', updateActive);
75573
+ events.on('inputMode:changed', updateActive);
75574
+ events.on('walkTo', () => {
75575
+ this.walking = true;
75576
+ this.cursorPath.style.display = 'none';
75963
75577
  });
75964
- material.blendType = BLEND_NONE;
75965
- material.depthWrite = true;
75966
- material.depthTest = true;
75967
- material.cull = CULLFACE_NONE;
75968
- material.update();
75969
- const mi = new MeshInstance(mesh, material);
75970
- mi.cull = false;
75971
- const entity = new Entity('walkParticles');
75972
- entity.addComponent('render', {
75973
- meshInstances: [mi]
75578
+ events.on('walkCancel', () => {
75579
+ this.walking = false;
75580
+ this.clearTarget();
75581
+ });
75582
+ events.on('walkComplete', () => {
75583
+ this.walking = false;
75584
+ this.clearTarget();
75585
+ });
75586
+ events.on('walkTarget:set', (pos, normal) => {
75587
+ this.setTarget(pos, normal);
75588
+ });
75589
+ events.on('walkTarget:clear', () => {
75590
+ this.clearTarget();
75591
+ });
75592
+ app.on('prerender', () => {
75593
+ this.updateTarget();
75974
75594
  });
75975
- entity.enabled = false;
75976
- this.app.root.addChild(entity);
75977
- return entity;
75595
+ updateActive();
75978
75596
  }
75979
- /**
75980
- * Set or clear the walk target position.
75981
- *
75982
- * @param pos - World-space target position, or null to clear.
75983
- */
75984
- setTarget(pos) {
75985
- this.target = pos ? pos.clone() : null;
75986
- this.visible = !!pos;
75987
- if (pos) {
75988
- this.startTime = performance.now() / 1000;
75989
- }
75990
- this.particleEntity.enabled = this.visible;
75991
- this.app.renderNextFrame = true;
75597
+ setTarget(pos, normal) {
75598
+ this.targetPos = pos.clone();
75599
+ this.targetNormal = normal.clone();
75992
75600
  }
75993
- /**
75994
- * Update uniforms for the walk highlight effect. Call from a prerender hook.
75995
- *
75996
- * @param camera - The camera entity used for rendering.
75997
- */
75998
- update(camera) {
75999
- const device = this.app.graphicsDevice;
76000
- const scope = device.scope;
76001
- const cam = camera.camera;
76002
- viewMat.copy(cam.viewMatrix);
76003
- invViewMat.copy(viewMat).invert();
76004
- scope.resolve('walk_viewInverse').setValue(invViewMat.data);
76005
- if (this.target) {
76006
- const camPos = camera.getPosition();
76007
- const dist = camPos.distance(this.target);
76008
- this.visible = dist > 2.0;
76009
- this.particleEntity.enabled = this.visible;
76010
- const elapsed = performance.now() / 1000 - this.startTime;
76011
- targetVec[0] = this.target.x;
76012
- targetVec[1] = this.target.y;
76013
- targetVec[2] = this.target.z;
76014
- scope.resolve('walk_target').setValue(targetVec);
76015
- scope.resolve('walk_radius').setValue(this.visible ? 1.5 : 0);
76016
- scope.resolve('walk_time').setValue(elapsed);
75601
+ clearTarget() {
75602
+ this.targetPos = null;
75603
+ this.targetNormal = null;
75604
+ this.targetPath.style.display = 'none';
75605
+ }
75606
+ projectCircle(px, py, pz, nx, ny, nz, radius, outX, outY) {
75607
+ const normal = tmpV.set(nx, ny, nz);
75608
+ if (Math.abs(normal.y) < 0.99) {
75609
+ tangent.cross(normal, up).normalize();
76017
75610
  }
76018
75611
  else {
76019
- targetVec[0] = 0;
76020
- targetVec[1] = 0;
76021
- targetVec[2] = 0;
76022
- scope.resolve('walk_target').setValue(targetVec);
76023
- scope.resolve('walk_radius').setValue(0);
76024
- scope.resolve('walk_time').setValue(0);
75612
+ tangent.cross(normal, right).normalize();
75613
+ }
75614
+ bitangent.cross(normal, tangent);
75615
+ const cam = this.camera.camera;
75616
+ const angleStep = (2 * Math.PI) / NUM_SAMPLES;
75617
+ for (let i = 0; i < NUM_SAMPLES; i++) {
75618
+ const theta = i * angleStep;
75619
+ const ct = Math.cos(theta);
75620
+ const st = Math.sin(theta);
75621
+ const tx = ct * tangent.x + st * bitangent.x;
75622
+ const ty = ct * tangent.y + st * bitangent.y;
75623
+ const tz = ct * tangent.z + st * bitangent.z;
75624
+ worldPt.set(px + tx * radius, py + ty * radius, pz + tz * radius);
75625
+ cam.worldToScreen(worldPt, tmpScreen);
75626
+ outX[i] = tmpScreen.x;
75627
+ outY[i] = tmpScreen.y;
76025
75628
  }
76026
75629
  }
75630
+ updateCursor(offsetX, offsetY) {
75631
+ if (!this.active || this.walking) {
75632
+ this.cursorPath.style.display = 'none';
75633
+ return;
75634
+ }
75635
+ const { camera, collider } = this;
75636
+ const cameraPos = camera.getPosition();
75637
+ camera.camera.screenToWorld(offsetX, offsetY, 1.0, tmpV);
75638
+ tmpV.sub(cameraPos).normalize();
75639
+ const hit = collider.queryRay(-cameraPos.x, -cameraPos.y, cameraPos.z, -tmpV.x, -tmpV.y, tmpV.z, camera.camera.farClip);
75640
+ if (!hit) {
75641
+ this.cursorPath.style.display = 'none';
75642
+ return;
75643
+ }
75644
+ const px = -hit.x;
75645
+ const py = -hit.y;
75646
+ const pz = hit.z;
75647
+ const sn = collider.querySurfaceNormal(hit.x, hit.y, hit.z);
75648
+ const nx = -sn.nx;
75649
+ const ny = -sn.ny;
75650
+ const nz = sn.nz;
75651
+ this.projectCircle(px, py, pz, nx, ny, nz, CIRCLE_OUTER_RADIUS, this.outerX, this.outerY);
75652
+ this.projectCircle(px, py, pz, nx, ny, nz, CIRCLE_INNER_RADIUS, this.innerX, this.innerY);
75653
+ this.cursorPath.setAttribute('d', `${buildBezierRing(this.outerX, this.outerY)} ${buildBezierRing(this.innerX, this.innerY)}`);
75654
+ this.cursorPath.style.display = '';
75655
+ this.svg.style.display = '';
75656
+ }
75657
+ updateTarget() {
75658
+ if (!this.active || !this.targetPos || !this.targetNormal) {
75659
+ return;
75660
+ }
75661
+ const camPos = this.camera.getPosition();
75662
+ const dist = camPos.distance(this.targetPos);
75663
+ if (dist < 2.0) {
75664
+ this.targetPath.style.display = 'none';
75665
+ return;
75666
+ }
75667
+ this.projectCircle(this.targetPos.x, this.targetPos.y, this.targetPos.z, this.targetNormal.x, this.targetNormal.y, this.targetNormal.z, CIRCLE_OUTER_RADIUS, this.scratchX, this.scratchY);
75668
+ this.targetPath.setAttribute('d', buildBezierRing(this.scratchX, this.scratchY));
75669
+ this.targetPath.style.display = '';
75670
+ this.svg.style.display = '';
75671
+ }
76027
75672
  destroy() {
76028
- const device = this.app.graphicsDevice;
76029
- ShaderChunks.get(device, 'glsl').set('gsplatPS', this.origGlsl);
76030
- ShaderChunks.get(device, 'wgsl').set('gsplatPS', this.origWgsl);
76031
- this.particleEntity.destroy();
75673
+ this.canvas.removeEventListener('pointermove', this.onPointerMove);
75674
+ this.canvas.removeEventListener('pointerleave', this.onPointerLeave);
75675
+ this.svg.remove();
76032
75676
  }
76033
75677
  }
76034
75678
 
@@ -76113,7 +75757,7 @@ class Viewer {
76113
75757
  annotations;
76114
75758
  forceRenderNextFrame = false;
76115
75759
  voxelOverlay = null;
76116
- walkIndicator = null;
75760
+ walkCursor = null;
76117
75761
  origChunks;
76118
75762
  constructor(global, gsplatLoad, skyboxLoad, voxelLoad) {
76119
75763
  this.global = global;
@@ -76221,10 +75865,9 @@ class Viewer {
76221
75865
  applyCamera(this.cameraManager.camera);
76222
75866
  }
76223
75867
  });
76224
- // Render voxel debug overlay and update walk indicator
75868
+ // Render voxel debug overlay
76225
75869
  app.on('prerender', () => {
76226
75870
  this.voxelOverlay?.update();
76227
- this.walkIndicator?.update(camera);
76228
75871
  });
76229
75872
  // update state on first frame
76230
75873
  events.on('firstFrame', () => {
@@ -76244,6 +75887,7 @@ class Viewer {
76244
75887
  this.annotations = new Annotations(global, this.cameraFrame != null);
76245
75888
  }
76246
75889
  this.inputController = new InputController(global);
75890
+ this.inputController.collider = collider ?? null;
76247
75891
  state.hasCollision = !!collider;
76248
75892
  // Create voxel debug overlay in WebGPU only
76249
75893
  if (collider && config.webgpu) {
@@ -76257,10 +75901,9 @@ class Viewer {
76257
75901
  }
76258
75902
  this.cameraManager = new CameraManager(global, sceneBound, collider);
76259
75903
  applyCamera(this.cameraManager.camera);
76260
- this.walkIndicator = new WalkIndicator(app);
76261
- events.on('walkIndicator:setTarget', (pos) => {
76262
- this.walkIndicator?.setTarget(pos);
76263
- });
75904
+ if (collider) {
75905
+ this.walkCursor = new WalkCursor(app, camera, collider, events, state);
75906
+ }
76264
75907
  const { instance } = gsplat;
76265
75908
  if (instance) {
76266
75909
  // kick off gsplat sorting immediately now that camera is in position
@@ -76401,6 +76044,19 @@ class Viewer {
76401
76044
  const SOLID_LEAF_MARKER = 0xFF000000 >>> 0;
76402
76045
  /** Minimum penetration depth to report a collision (avoids floating-point noise at corners) */
76403
76046
  const PENETRATION_EPSILON = 1e-4;
76047
+ /** Precomputed offsets and inverse-length weights for querySurfaceNormal's 7x7x7 neighborhood. */
76048
+ const NORMAL_R = 3;
76049
+ const normalOffsets = [];
76050
+ for (let dz = -NORMAL_R; dz <= NORMAL_R; dz++) {
76051
+ for (let dy = -NORMAL_R; dy <= NORMAL_R; dy++) {
76052
+ for (let dx = -NORMAL_R; dx <= NORMAL_R; dx++) {
76053
+ if (dx === 0 && dy === 0 && dz === 0)
76054
+ continue;
76055
+ const invLen = 1.0 / Math.sqrt(dx * dx + dy * dy + dz * dz);
76056
+ normalOffsets.push({ dx, dy, dz, wx: dx * invLen, wy: dy * invLen, wz: dz * invLen });
76057
+ }
76058
+ }
76059
+ }
76404
76060
  /**
76405
76061
  * Count the number of set bits in a 32-bit integer.
76406
76062
  *
@@ -76440,6 +76096,8 @@ class VoxelCollider {
76440
76096
  _leafData;
76441
76097
  /** Pre-allocated scratch push-out vector to avoid per-frame allocations */
76442
76098
  _push = { x: 0, y: 0, z: 0 };
76099
+ /** Pre-allocated result for querySurfaceNormal to avoid per-call allocation */
76100
+ _normalResult = { nx: 0, ny: 0, nz: 0 };
76443
76101
  /** Pre-allocated constraint normals for iterative corner resolution (max 3 walls) */
76444
76102
  _constraintNormals = [
76445
76103
  { x: 0, y: 0, z: 0 },
@@ -76588,6 +76246,195 @@ class VoxelCollider {
76588
76246
  const iz = Math.floor((z - this.gridMinZ) / this.voxelResolution);
76589
76247
  return this.isVoxelSolid(ix, iy, iz);
76590
76248
  }
76249
+ /**
76250
+ * Compute a smoothed surface normal at a world-space position by sampling the surrounding
76251
+ * voxel neighborhood. Uses a gradient-of-occupancy approach: for each solid voxel in the
76252
+ * neighborhood, its offset is subtracted from the accumulated normal (pointing away from
76253
+ * the solid mass). This produces stable normals — floors consistently point upward even
76254
+ * on uneven surfaces, and walls produce horizontal normals.
76255
+ *
76256
+ * @param x - World X coordinate of the surface point.
76257
+ * @param y - World Y coordinate of the surface point.
76258
+ * @param z - World Z coordinate of the surface point.
76259
+ * @returns Object with nx, ny, nz components of the normalized surface normal.
76260
+ */
76261
+ querySurfaceNormal(x, y, z) {
76262
+ const ix = Math.floor((x - this._gridMinX) / this._voxelResolution);
76263
+ const iy = Math.floor((y - this._gridMinY) / this._voxelResolution);
76264
+ const iz = Math.floor((z - this._gridMinZ) / this._voxelResolution);
76265
+ let nx = 0;
76266
+ let ny = 0;
76267
+ let nz = 0;
76268
+ for (let i = 0; i < normalOffsets.length; i++) {
76269
+ const o = normalOffsets[i];
76270
+ if (this.isVoxelSolid(ix + o.dx, iy + o.dy, iz + o.dz)) {
76271
+ nx -= o.wx;
76272
+ ny -= o.wy;
76273
+ nz -= o.wz;
76274
+ }
76275
+ }
76276
+ const len = Math.sqrt(nx * nx + ny * ny + nz * nz);
76277
+ if (len > 1e-6) {
76278
+ const invLen = 1.0 / len;
76279
+ nx *= invLen;
76280
+ ny *= invLen;
76281
+ nz *= invLen;
76282
+ }
76283
+ else {
76284
+ nx = 0;
76285
+ ny = 1;
76286
+ nz = 0;
76287
+ }
76288
+ const result = this._normalResult;
76289
+ result.nx = nx;
76290
+ result.ny = ny;
76291
+ result.nz = nz;
76292
+ return result;
76293
+ }
76294
+ /**
76295
+ * Cast a ray through the voxel grid using 3D-DDA and return the entry point on the first
76296
+ * solid voxel hit. Coordinates are in voxel world space (the same frame used by queryPoint).
76297
+ *
76298
+ * @param ox - Ray origin X.
76299
+ * @param oy - Ray origin Y.
76300
+ * @param oz - Ray origin Z.
76301
+ * @param dx - Ray direction X (must be normalized).
76302
+ * @param dy - Ray direction Y (must be normalized).
76303
+ * @param dz - Ray direction Z (must be normalized).
76304
+ * @param maxDist - Maximum ray distance.
76305
+ * @returns The entry point on the first solid voxel, or null if no hit.
76306
+ */
76307
+ queryRay(ox, oy, oz, dx, dy, dz, maxDist) {
76308
+ if (this._nodes.length === 0) {
76309
+ return null;
76310
+ }
76311
+ const res = this._voxelResolution;
76312
+ const gMinX = this._gridMinX;
76313
+ const gMinY = this._gridMinY;
76314
+ const gMinZ = this._gridMinZ;
76315
+ const gMaxX = gMinX + this._numVoxelsX * res;
76316
+ const gMaxY = gMinY + this._numVoxelsY * res;
76317
+ const gMaxZ = gMinZ + this._numVoxelsZ * res;
76318
+ const EPS = 1e-12;
76319
+ // Ray-AABB slab intersection to find the range [tNear, tFar]
76320
+ let tNear = 0;
76321
+ let tFar = maxDist;
76322
+ if (Math.abs(dx) > EPS) {
76323
+ let t1 = (gMinX - ox) / dx;
76324
+ let t2 = (gMaxX - ox) / dx;
76325
+ if (t1 > t2) {
76326
+ const tmp = t1;
76327
+ t1 = t2;
76328
+ t2 = tmp;
76329
+ }
76330
+ if (t1 > tNear) {
76331
+ tNear = t1;
76332
+ }
76333
+ tFar = Math.min(tFar, t2);
76334
+ if (tNear > tFar)
76335
+ return null;
76336
+ }
76337
+ else if (ox < gMinX || ox >= gMaxX) {
76338
+ return null;
76339
+ }
76340
+ if (Math.abs(dy) > EPS) {
76341
+ let t1 = (gMinY - oy) / dy;
76342
+ let t2 = (gMaxY - oy) / dy;
76343
+ if (t1 > t2) {
76344
+ const tmp = t1;
76345
+ t1 = t2;
76346
+ t2 = tmp;
76347
+ }
76348
+ if (t1 > tNear) {
76349
+ tNear = t1;
76350
+ }
76351
+ tFar = Math.min(tFar, t2);
76352
+ if (tNear > tFar)
76353
+ return null;
76354
+ }
76355
+ else if (oy < gMinY || oy >= gMaxY) {
76356
+ return null;
76357
+ }
76358
+ if (Math.abs(dz) > EPS) {
76359
+ let t1 = (gMinZ - oz) / dz;
76360
+ let t2 = (gMaxZ - oz) / dz;
76361
+ if (t1 > t2) {
76362
+ const tmp = t1;
76363
+ t1 = t2;
76364
+ t2 = tmp;
76365
+ }
76366
+ if (t1 > tNear) {
76367
+ tNear = t1;
76368
+ }
76369
+ tFar = Math.min(tFar, t2);
76370
+ if (tNear > tFar)
76371
+ return null;
76372
+ }
76373
+ else if (oz < gMinZ || oz >= gMaxZ) {
76374
+ return null;
76375
+ }
76376
+ // Entry point on the grid AABB (or origin if already inside)
76377
+ const entryX = ox + dx * tNear;
76378
+ const entryY = oy + dy * tNear;
76379
+ const entryZ = oz + dz * tNear;
76380
+ // Convert to voxel indices, clamping to valid range for boundary cases
76381
+ let ix = Math.max(0, Math.min(Math.floor((entryX - gMinX) / res), this._numVoxelsX - 1));
76382
+ let iy = Math.max(0, Math.min(Math.floor((entryY - gMinY) / res), this._numVoxelsY - 1));
76383
+ let iz = Math.max(0, Math.min(Math.floor((entryZ - gMinZ) / res), this._numVoxelsZ - 1));
76384
+ // DDA setup
76385
+ const stepX = dx > 0 ? 1 : (dx < 0 ? -1 : 0);
76386
+ const stepY = dy > 0 ? 1 : (dy < 0 ? -1 : 0);
76387
+ const stepZ = dz > 0 ? 1 : (dz < 0 ? -1 : 0);
76388
+ const invDx = Math.abs(dx) > EPS ? 1.0 / dx : 0;
76389
+ const invDy = Math.abs(dy) > EPS ? 1.0 / dy : 0;
76390
+ const invDz = Math.abs(dz) > EPS ? 1.0 / dz : 0;
76391
+ let tMaxX = Math.abs(dx) > EPS ? (gMinX + (ix + (dx > 0 ? 1 : 0)) * res - ox) * invDx : Infinity;
76392
+ let tMaxY = Math.abs(dy) > EPS ? (gMinY + (iy + (dy > 0 ? 1 : 0)) * res - oy) * invDy : Infinity;
76393
+ let tMaxZ = Math.abs(dz) > EPS ? (gMinZ + (iz + (dz > 0 ? 1 : 0)) * res - oz) * invDz : Infinity;
76394
+ const tDeltaX = Math.abs(dx) > EPS ? res * Math.abs(invDx) : Infinity;
76395
+ const tDeltaY = Math.abs(dy) > EPS ? res * Math.abs(invDy) : Infinity;
76396
+ const tDeltaZ = Math.abs(dz) > EPS ? res * Math.abs(invDz) : Infinity;
76397
+ let currentT = tNear;
76398
+ const maxSteps = this._numVoxelsX + this._numVoxelsY + this._numVoxelsZ;
76399
+ for (let step = 0; step < maxSteps; step++) {
76400
+ if (this.isVoxelSolid(ix, iy, iz)) {
76401
+ return {
76402
+ x: ox + dx * currentT,
76403
+ y: oy + dy * currentT,
76404
+ z: oz + dz * currentT
76405
+ };
76406
+ }
76407
+ // Advance along the axis with the smallest tMax
76408
+ if (tMaxX < tMaxY) {
76409
+ if (tMaxX < tMaxZ) {
76410
+ currentT = tMaxX;
76411
+ ix += stepX;
76412
+ tMaxX += tDeltaX;
76413
+ }
76414
+ else {
76415
+ currentT = tMaxZ;
76416
+ iz += stepZ;
76417
+ tMaxZ += tDeltaZ;
76418
+ }
76419
+ }
76420
+ else if (tMaxY < tMaxZ) {
76421
+ currentT = tMaxY;
76422
+ iy += stepY;
76423
+ tMaxY += tDeltaY;
76424
+ }
76425
+ else {
76426
+ currentT = tMaxZ;
76427
+ iz += stepZ;
76428
+ tMaxZ += tDeltaZ;
76429
+ }
76430
+ if (ix < 0 || iy < 0 || iz < 0 ||
76431
+ ix >= this._numVoxelsX || iy >= this._numVoxelsY || iz >= this._numVoxelsZ ||
76432
+ currentT > maxDist) {
76433
+ return null;
76434
+ }
76435
+ }
76436
+ return null;
76437
+ }
76591
76438
  /**
76592
76439
  * Query a sphere against the voxel grid and write a push-out vector to resolve penetration.
76593
76440
  * Uses iterative single-voxel resolution: each iteration finds the deepest penetrating voxel,
@@ -77989,7 +77836,7 @@ const initXr = (global) => {
77989
77836
  });
77990
77837
  };
77991
77838
 
77992
- var version = "1.16.9";
77839
+ var version = "1.16.10";
77993
77840
 
77994
77841
  const loadGsplat = async (app, config, progressCallback) => {
77995
77842
  const { contents, contentUrl, unified, aa } = config;