@playcanvas/supersplat-viewer 1.22.1 → 1.22.2

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
@@ -76580,6 +76580,8 @@ const importSettings = (settings) => {
76580
76580
  return result;
76581
76581
  };
76582
76582
 
76583
+ var version = "1.22.2";
76584
+
76583
76585
  class Tooltip {
76584
76586
  register;
76585
76587
  unregister;
@@ -76861,7 +76863,7 @@ const initUI = (global) => {
76861
76863
  'orbitCamera', 'flyCamera', 'fpsCamera',
76862
76864
  'performanceModeRow', 'performanceModeCheck', 'performanceModeOption',
76863
76865
  'gamingControlsDivider', 'gamingControlsRow', 'gamingControlsCheck', 'gamingControlsOption',
76864
- 'desktopFlyClickToFly', 'desktopClickToWalk', 'desktopGamingControls',
76866
+ 'desktopFlyClickToFly', 'desktopFlyGamingControls', 'desktopClickToWalk', 'desktopGamingControls',
76865
76867
  'touchFlyClickToWalk', 'touchFlyGamingControls',
76866
76868
  'touchClickToWalk', 'touchGamingControls',
76867
76869
  'walkHint',
@@ -76871,11 +76873,13 @@ const initUI = (global) => {
76871
76873
  'showCollision',
76872
76874
  'tooltip',
76873
76875
  'annotationNav', 'annotationPrev', 'annotationNext', 'annotationInfo', 'annotationNavTitle',
76874
- 'supersplatBranding'
76876
+ 'viewerBranding', 'viewerTitle', 'appVersionLabel'
76875
76877
  ].reduce((acc, id) => {
76876
76878
  acc[id] = document.getElementById(id);
76877
76879
  return acc;
76878
76880
  }, {});
76881
+ // populate the info-panel title with the app version
76882
+ dom.appVersionLabel.textContent = version;
76879
76883
  // Remove focus from buttons after click so keyboard input isn't captured by the UI
76880
76884
  dom.ui.addEventListener('click', () => {
76881
76885
  document.activeElement?.blur();
@@ -76980,6 +76984,7 @@ const initUI = (global) => {
76980
76984
  const updateGamingControls = () => {
76981
76985
  dom.gamingControlsCheck.classList.toggle('active', state.gamingControls);
76982
76986
  dom.desktopFlyClickToFly.classList.toggle('hidden', state.gamingControls);
76987
+ dom.desktopFlyGamingControls.classList.toggle('hidden', !state.gamingControls);
76983
76988
  dom.desktopClickToWalk.classList.toggle('hidden', state.gamingControls);
76984
76989
  dom.desktopGamingControls.classList.toggle('hidden', !state.gamingControls);
76985
76990
  dom.touchFlyClickToWalk.classList.toggle('hidden', state.gamingControls);
@@ -77284,8 +77289,9 @@ const initUI = (global) => {
77284
77289
  if (viewUrl.pathname === '/s') {
77285
77290
  viewUrl.pathname = '/view';
77286
77291
  }
77287
- dom.supersplatBranding.href = viewUrl.toString();
77288
- dom.supersplatBranding.classList.remove('hidden');
77292
+ dom.viewerBranding.href = viewUrl.toString();
77293
+ dom.viewerBranding.classList.remove('hidden');
77294
+ dom.viewerTitle.href = viewUrl.toString();
77289
77295
  }
77290
77296
  };
77291
77297
 
@@ -78749,6 +78755,7 @@ class FlySource {
78749
78755
  _pitchRate = 0;
78750
78756
  _speed = 0;
78751
78757
  _progress = new ProgressTracker();
78758
+ _speedMul = 1;
78752
78759
  get isActive() {
78753
78760
  return this._target !== null;
78754
78761
  }
@@ -78756,13 +78763,16 @@ class FlySource {
78756
78763
  * Begin auto-flying toward a world-space target position.
78757
78764
  *
78758
78765
  * @param target - The destination.
78766
+ * @param speedMul - Forward-speed multiplier (mirrors gaming-controls
78767
+ * shift/ctrl: 4 for boost, 0.25 for slow). Defaults to 1.
78759
78768
  */
78760
- navigateTo(target) {
78769
+ navigateTo(target, speedMul = 1) {
78761
78770
  const wasFlying = this._target !== null;
78762
78771
  if (!this._target) {
78763
78772
  this._target = new Vec3();
78764
78773
  }
78765
78774
  this._target.copy(target);
78775
+ this._speedMul = speedMul;
78766
78776
  if (!wasFlying) {
78767
78777
  this._yawRate = 0;
78768
78778
  this._pitchRate = 0;
@@ -78829,7 +78839,7 @@ class FlySource {
78829
78839
  const alignmentScale = smoothstep(0.05, 0.95, alignment);
78830
78840
  const brakeSpeed = Math.sqrt(2 * this.moveDeceleration * activeRemainingDist);
78831
78841
  const arrivalSpeed = activeRemainingDist * ARRIVAL_RATE;
78832
- const maxSpeed = Math.min(this.flySpeed, brakeSpeed, arrivalSpeed);
78842
+ const maxSpeed = Math.min(this.flySpeed * this._speedMul, brakeSpeed, arrivalSpeed);
78833
78843
  if (maxSpeed > this._speed) {
78834
78844
  this._speed = approach(this._speed, maxSpeed, this.moveAcceleration * alignmentScale * dt);
78835
78845
  }
@@ -79340,6 +79350,7 @@ class WalkSource {
79340
79350
  _target = null;
79341
79351
  _yawRate = 0;
79342
79352
  _progress = new ProgressTracker();
79353
+ _speedMul = 1;
79343
79354
  get isActive() {
79344
79355
  return this._target !== null;
79345
79356
  }
@@ -79347,12 +79358,15 @@ class WalkSource {
79347
79358
  * Begin auto-walking toward a world-space target position.
79348
79359
  *
79349
79360
  * @param target - The destination (XZ used for navigation).
79361
+ * @param speedMul - Forward-speed multiplier (mirrors gaming-controls
79362
+ * shift/ctrl: 2 for run, 0.5 for crawl). Defaults to 1.
79350
79363
  */
79351
- navigateTo(target) {
79364
+ navigateTo(target, speedMul = 1) {
79352
79365
  if (!this._target) {
79353
79366
  this._target = new Vec3();
79354
79367
  }
79355
79368
  this._target.copy(target);
79369
+ this._speedMul = speedMul;
79356
79370
  this._progress.reset();
79357
79371
  }
79358
79372
  /**
@@ -79402,7 +79416,7 @@ class WalkSource {
79402
79416
  frame.deltas.rotate.append([-yawStep, 0, 0]);
79403
79417
  // scale forward speed by alignment: turn in place first, then accelerate
79404
79418
  const alignment = Math.max(0, Math.cos(yawDiff * Math.PI / 180));
79405
- frame.deltas.move.append([0, 0, this.walkSpeed * dt * alignment]);
79419
+ frame.deltas.move.append([0, 0, this.walkSpeed * this._speedMul * dt * alignment]);
79406
79420
  }
79407
79421
  }
79408
79422
 
@@ -79635,10 +79649,10 @@ class CameraManager {
79635
79649
  startTransition();
79636
79650
  });
79637
79651
  // tap-to-navigate: start auto-driving the active mode toward a picked position
79638
- events.on('navigateTo', (position, normal) => {
79652
+ events.on('navigateTo', (position, normal, speedMul = 1) => {
79639
79653
  const source = sourcesByMode[state.cameraMode];
79640
79654
  if (source) {
79641
- source.navigateTo(position);
79655
+ source.navigateTo(position, speedMul);
79642
79656
  events.fire('navTarget:set', position, normal);
79643
79657
  }
79644
79658
  });
@@ -79823,6 +79837,25 @@ const flipZForOrbit = (mode, z) => (mode === 'orbit' ? -z : z);
79823
79837
  const tmpV$4 = new Vec3();
79824
79838
  const canTargetFly = (global) => (global.state.cameraMode === 'fly' &&
79825
79839
  !(global.state.inputMode === 'desktop' && global.state.gamingControls));
79840
+ // Mirror gaming-controls speed modifiers: shift = run/boost, ctrl = crawl/slow.
79841
+ // Multipliers match keyboard-mouse.ts so click-nav and held-key movement feel the same.
79842
+ const computeClickSpeedMul = (event, mode) => {
79843
+ if (!event)
79844
+ return 1;
79845
+ if (mode === 'walk') {
79846
+ if (event.shiftKey)
79847
+ return 2;
79848
+ if (event.ctrlKey)
79849
+ return 0.5;
79850
+ }
79851
+ else if (mode === 'fly') {
79852
+ if (event.shiftKey)
79853
+ return 4;
79854
+ if (event.ctrlKey)
79855
+ return 0.25;
79856
+ }
79857
+ return 1;
79858
+ };
79826
79859
  /**
79827
79860
  * Click-to-walk / click-to-fly / click-to-focus (desktop), tap equivalents
79828
79861
  * on mobile, and double-click-to-pick fallback. Uses collision first and
@@ -79894,14 +79927,15 @@ class NavInteraction {
79894
79927
  }
79895
79928
  return null;
79896
79929
  }
79897
- async _flyToPickedPosition(offsetX, offsetY) {
79930
+ async _flyToPickedPosition(offsetX, offsetY, event) {
79898
79931
  const global = this._global;
79899
79932
  if (!global || !canTargetFly(global))
79900
79933
  return;
79901
79934
  const request = ++this._targetPickRequest;
79902
79935
  const target = await this._pickSceneTarget(offsetX, offsetY);
79903
79936
  if (target && request === this._targetPickRequest && this._global && canTargetFly(this._global)) {
79904
- this._global.events.fire('navigateTo', target.position, target.normal);
79937
+ const speedMul = computeClickSpeedMul(event, this._global.state.cameraMode);
79938
+ this._global.events.fire('navigateTo', target.position, target.normal, speedMul);
79905
79939
  }
79906
79940
  }
79907
79941
  async _focusPickedPosition(offsetX, offsetY) {
@@ -79978,11 +80012,12 @@ class NavInteraction {
79978
80012
  if (state.cameraMode === 'walk' && !state.gamingControls) {
79979
80013
  const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
79980
80014
  if (result) {
79981
- events.fire('navigateTo', result.position, result.normal);
80015
+ const speedMul = computeClickSpeedMul(event, state.cameraMode);
80016
+ events.fire('navigateTo', result.position, result.normal, speedMul);
79982
80017
  }
79983
80018
  }
79984
80019
  else if (state.cameraMode === 'fly') {
79985
- this._flyToPickedPosition(this._lastPointerOffsetX, this._lastPointerOffsetY);
80020
+ this._flyToPickedPosition(this._lastPointerOffsetX, this._lastPointerOffsetY, event);
79986
80021
  }
79987
80022
  else if (state.cameraMode === 'orbit') {
79988
80023
  this._focusPickedPosition(this._lastPointerOffsetX, this._lastPointerOffsetY);
@@ -80016,7 +80051,9 @@ class NavInteraction {
80016
80051
  }
80017
80052
  else if (currentMode === 'orbit' || currentMode === 'walk') {
80018
80053
  state.cameraMode = 'fly';
80019
- events.fire('navigateTo', target.position, target.normal);
80054
+ // Modifiers apply against the destination mode (fly), not the source.
80055
+ const speedMul = computeClickSpeedMul(event, 'fly');
80056
+ events.fire('navigateTo', target.position, target.normal, speedMul);
80020
80057
  }
80021
80058
  };
80022
80059
  _onMobileTap = () => {
@@ -81227,8 +81264,18 @@ const vec4 = new Vec4();
81227
81264
  const viewProjMat = new Mat4();
81228
81265
  const clearColor = new Color(0, 0, 0, 1);
81229
81266
  const NORMAL_EPSILON$1 = 1e-12;
81230
- const NORMAL_OUTLIER_MIN_DOT = 0.35;
81231
- const NORMAL_SAMPLE_RADII = [1, 2, 4, 8];
81267
+ const NORMAL_DEGENERATE_EPSILON = 1e-20;
81268
+ // Sampling for the surface-normal estimator runs on a circular footprint of
81269
+ // fixed *world* radius, projected to pixels at the picked-point's depth.
81270
+ // Keeping the world area constant means adjacent cursor positions sample
81271
+ // almost the same world cluster, which stabilises the plane fit. The pixel
81272
+ // radius is clamped so distant picks still get enough samples and very-close
81273
+ // picks don't blow the block read.
81274
+ const NORMAL_SAMPLE_WORLD_RADIUS = 0.2;
81275
+ const NORMAL_SAMPLE_MIN_PX = 6;
81276
+ const NORMAL_SAMPLE_MAX_PX = 48;
81277
+ const NORMAL_RING_FRACTIONS = [0.3, 0.55, 0.8, 1.0];
81278
+ const NORMAL_OUTLIER_THRESHOLD = 2.5;
81232
81279
  const NORMAL_SAMPLE_DIRECTIONS = [
81233
81280
  [1, 0],
81234
81281
  [1, 1],
@@ -81364,6 +81411,145 @@ const setCameraFacingNormal = (cameraPosition, position, normal) => {
81364
81411
  }
81365
81412
  return normal;
81366
81413
  };
81414
+ // Project a world-space radius around `pos` to its on-screen pixel radius for
81415
+ // the given camera. Uses the projection matrix's [1][1] entry (= 1/tan(fov/2)
81416
+ // for perspective, = 1/orthoHeight for orthographic) so we don't need fov or
81417
+ // orthoHeight on the snapshot.
81418
+ const worldRadiusToPixelRadius = (cam, pos, canvasHeight, worldRadius) => {
81419
+ const projY = cam.projectionMatrix.data[5];
81420
+ if (cam.projection === PROJECTION_ORTHOGRAPHIC) {
81421
+ return worldRadius * projY * canvasHeight / 2;
81422
+ }
81423
+ const dx = pos.x - cam.position.x;
81424
+ const dy = pos.y - cam.position.y;
81425
+ const dz = pos.z - cam.position.z;
81426
+ const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
81427
+ if (distance < 1e-6)
81428
+ return Infinity;
81429
+ return worldRadius * projY * canvasHeight / (2 * distance);
81430
+ };
81431
+ // Single least-squares plane fit through a cluster of 3D points. The normal
81432
+ // is the eigenvector of the smallest eigenvalue of the points' 3x3 covariance
81433
+ // matrix, computed in closed form (analytic eigendecomposition for 3x3
81434
+ // symmetric, Smith 1961). Returns null on degenerate input.
81435
+ const fitPlaneOnce = (points) => {
81436
+ const n = points.length;
81437
+ if (n < 3)
81438
+ return null;
81439
+ let cx = 0, cy = 0, cz = 0;
81440
+ for (let i = 0; i < n; i++) {
81441
+ cx += points[i].x;
81442
+ cy += points[i].y;
81443
+ cz += points[i].z;
81444
+ }
81445
+ cx /= n;
81446
+ cy /= n;
81447
+ cz /= n;
81448
+ let cxx = 0, cxy = 0, cxz = 0, cyy = 0, cyz = 0, czz = 0;
81449
+ for (let i = 0; i < n; i++) {
81450
+ const dx = points[i].x - cx;
81451
+ const dy = points[i].y - cy;
81452
+ const dz = points[i].z - cz;
81453
+ cxx += dx * dx;
81454
+ cxy += dx * dy;
81455
+ cxz += dx * dz;
81456
+ cyy += dy * dy;
81457
+ cyz += dy * dz;
81458
+ czz += dz * dz;
81459
+ }
81460
+ const q = (cxx + cyy + czz) / 3;
81461
+ const a = cxx - q, b = cyy - q, c = czz - q;
81462
+ const p2 = a * a + b * b + c * c + 2 * (cxy * cxy + cxz * cxz + cyz * cyz);
81463
+ if (p2 < NORMAL_DEGENERATE_EPSILON)
81464
+ return null;
81465
+ const p = Math.sqrt(p2 / 6);
81466
+ const inv = 1 / p;
81467
+ const Bxx = a * inv, Bxy = cxy * inv, Bxz = cxz * inv;
81468
+ const Byy = b * inv, Byz = cyz * inv, Bzz = c * inv;
81469
+ const detB = Bxx * (Byy * Bzz - Byz * Byz) -
81470
+ Bxy * (Bxy * Bzz - Byz * Bxz) +
81471
+ Bxz * (Bxy * Byz - Byy * Bxz);
81472
+ const r = Math.max(-1, Math.min(1, detB / 2));
81473
+ const phi = Math.acos(r) / 3;
81474
+ const lambdaMin = q + 2 * p * Math.cos(phi + 2 * Math.PI / 3);
81475
+ const Mxx = cxx - lambdaMin, Myy = cyy - lambdaMin, Mzz = czz - lambdaMin;
81476
+ const v1x = cxy * cyz - cxz * Myy;
81477
+ const v1y = cxz * cxy - Mxx * cyz;
81478
+ const v1z = Mxx * Myy - cxy * cxy;
81479
+ const v2x = cxy * Mzz - cxz * cyz;
81480
+ const v2y = cxz * cxz - Mxx * Mzz;
81481
+ const v2z = Mxx * cyz - cxy * cxz;
81482
+ const v3x = Myy * Mzz - cyz * cyz;
81483
+ const v3y = cyz * cxz - cxy * Mzz;
81484
+ const v3z = cxy * cyz - Myy * cxz;
81485
+ const l1 = v1x * v1x + v1y * v1y + v1z * v1z;
81486
+ const l2 = v2x * v2x + v2y * v2y + v2z * v2z;
81487
+ const l3 = v3x * v3x + v3y * v3y + v3z * v3z;
81488
+ let vx, vy, vz, lSq;
81489
+ if (l1 >= l2 && l1 >= l3) {
81490
+ vx = v1x;
81491
+ vy = v1y;
81492
+ vz = v1z;
81493
+ lSq = l1;
81494
+ }
81495
+ else if (l2 >= l3) {
81496
+ vx = v2x;
81497
+ vy = v2y;
81498
+ vz = v2z;
81499
+ lSq = l2;
81500
+ }
81501
+ else {
81502
+ vx = v3x;
81503
+ vy = v3y;
81504
+ vz = v3z;
81505
+ lSq = l3;
81506
+ }
81507
+ if (lSq < NORMAL_EPSILON$1)
81508
+ return null;
81509
+ const invLen = 1 / Math.sqrt(lSq);
81510
+ return { cx, cy, cz, vx: vx * invLen, vy: vy * invLen, vz: vz * invLen };
81511
+ };
81512
+ // Two-pass plane fit: first pass on all points, then drop points whose
81513
+ // distance from the fitted plane exceeds NORMAL_OUTLIER_THRESHOLD * the mean
81514
+ // residual, refit on the inliers. Sign-flips the result toward toCamera so
81515
+ // the cursor's tangent basis stays consistent. Returns false on degenerate
81516
+ // input (fewer than 3 points, collinear/coincident samples).
81517
+ const fitPlaneNormal = (points, toCamera, outNormal) => {
81518
+ const first = fitPlaneOnce(points);
81519
+ if (!first)
81520
+ return false;
81521
+ let residualSum = 0;
81522
+ for (let i = 0; i < points.length; i++) {
81523
+ const dx = points[i].x - first.cx;
81524
+ const dy = points[i].y - first.cy;
81525
+ const dz = points[i].z - first.cz;
81526
+ residualSum += Math.abs(dx * first.vx + dy * first.vy + dz * first.vz);
81527
+ }
81528
+ const threshold = (residualSum / points.length) * NORMAL_OUTLIER_THRESHOLD;
81529
+ const inliers = [];
81530
+ for (let i = 0; i < points.length; i++) {
81531
+ const dx = points[i].x - first.cx;
81532
+ const dy = points[i].y - first.cy;
81533
+ const dz = points[i].z - first.cz;
81534
+ if (Math.abs(dx * first.vx + dy * first.vy + dz * first.vz) <= threshold) {
81535
+ inliers.push(points[i]);
81536
+ }
81537
+ }
81538
+ let result = first;
81539
+ if (inliers.length >= 3 && inliers.length < points.length) {
81540
+ const refined = fitPlaneOnce(inliers);
81541
+ if (refined)
81542
+ result = refined;
81543
+ }
81544
+ let { vx, vy, vz } = result;
81545
+ if (vx * toCamera.x + vy * toCamera.y + vz * toCamera.z < 0) {
81546
+ vx = -vx;
81547
+ vy = -vy;
81548
+ vz = -vz;
81549
+ }
81550
+ outNormal.set(vx, vy, vz);
81551
+ return true;
81552
+ };
81367
81553
  class Picker {
81368
81554
  pick;
81369
81555
  pickSurface;
@@ -81566,12 +81752,13 @@ class Picker {
81566
81752
  normal: new Vec3(0, 1, 0)
81567
81753
  };
81568
81754
  }
81569
- // Single block read serves both depth (center pixel) and normal samples (ring).
81570
- const maxRadius = NORMAL_SAMPLE_RADII[NORMAL_SAMPLE_RADII.length - 1];
81571
- const blockX = Math.max(0, screenX - maxRadius);
81572
- const blockY = Math.max(0, screenY - maxRadius);
81573
- const blockWidth = Math.min(width - 1, screenX + maxRadius) - blockX + 1;
81574
- const blockHeight = Math.min(height - 1, screenY + maxRadius) - blockY + 1;
81755
+ // Single block read serves both depth (center pixel) and normal
81756
+ // samples. Sized to the maximum possible ring pixel-radius so the
81757
+ // dynamic ring offsets always lie inside the buffer we read.
81758
+ const blockX = Math.max(0, screenX - NORMAL_SAMPLE_MAX_PX);
81759
+ const blockY = Math.max(0, screenY - NORMAL_SAMPLE_MAX_PX);
81760
+ const blockWidth = Math.min(width - 1, screenX + NORMAL_SAMPLE_MAX_PX) - blockX + 1;
81761
+ const blockHeight = Math.min(height - 1, screenY + NORMAL_SAMPLE_MAX_PX) - blockY + 1;
81575
81762
  const rasterBlock = await readRasterBlock(blockX, blockY, blockWidth, blockHeight, width, height, pickCamera);
81576
81763
  const position = rasterBlock(screenX, screenY);
81577
81764
  if (!position) {
@@ -81583,58 +81770,30 @@ class Picker {
81583
81770
  }
81584
81771
  return rasterBlock(px, py);
81585
81772
  };
81586
- const sampleRings = NORMAL_SAMPLE_RADII.map((radius) => {
81773
+ // Pixel radius corresponding to a fixed world radius at the
81774
+ // picked-point's depth. Clamped so distant picks still sample
81775
+ // enough pixels and very-close picks stay inside the block read.
81776
+ const pixelRadius = Math.max(NORMAL_SAMPLE_MIN_PX, Math.min(NORMAL_SAMPLE_MAX_PX, worldRadiusToPixelRadius(pickCamera, position, height, NORMAL_SAMPLE_WORLD_RADIUS)));
81777
+ const ringPixelRadii = NORMAL_RING_FRACTIONS.map(f => Math.max(1, Math.round(f * pixelRadius)));
81778
+ const sampleRings = ringPixelRadii.map((radius) => {
81587
81779
  return NORMAL_SAMPLE_DIRECTIONS.map(([dx, dy]) => {
81588
81780
  return samplePixel(screenX + dx * radius, screenY + dy * radius);
81589
81781
  });
81590
81782
  });
81591
81783
  const toCamera = setCameraFacingNormal(pickCamera.position, position, new Vec3());
81592
- const candidates = [];
81593
- const va = new Vec3();
81594
- const vb = new Vec3();
81595
- const sampleNormal = new Vec3();
81596
- sampleRings.forEach((points) => {
81597
- for (let i = 0; i < NORMAL_SAMPLE_DIRECTIONS.length; i++) {
81598
- const pointA = points[i];
81599
- const pointB = points[(i + 1) % NORMAL_SAMPLE_DIRECTIONS.length];
81600
- if (!pointA || !pointB) {
81601
- continue;
81602
- }
81603
- va.sub2(pointA, position);
81604
- vb.sub2(pointB, position);
81605
- if (va.lengthSq() <= NORMAL_EPSILON$1 || vb.lengthSq() <= NORMAL_EPSILON$1) {
81606
- continue;
81607
- }
81608
- // Direction order is clockwise in screen space. Screen Y points
81609
- // down, so crossing next by current gives a camera-facing normal.
81610
- sampleNormal.cross(vb, va);
81611
- if (sampleNormal.lengthSq() <= NORMAL_EPSILON$1) {
81612
- continue;
81613
- }
81614
- const candidate = sampleNormal.clone().normalize();
81615
- if (candidate.dot(toCamera) < 0) {
81616
- candidate.mulScalar(-1);
81617
- }
81618
- candidates.push(candidate);
81619
- }
81620
- });
81621
- const normal = new Vec3();
81622
- candidates.forEach((candidate) => {
81623
- normal.add(candidate);
81624
- });
81625
- if (normal.lengthSq() > NORMAL_EPSILON$1) {
81626
- normal.normalize();
81627
- const refined = new Vec3();
81628
- candidates.forEach((candidate) => {
81629
- if (candidate.dot(normal) >= NORMAL_OUTLIER_MIN_DOT) {
81630
- refined.add(candidate);
81631
- }
81632
- });
81633
- if (refined.lengthSq() > NORMAL_EPSILON$1) {
81634
- normal.copy(refined).normalize();
81784
+ // Collect every valid 3D sample: the picked position plus all ring
81785
+ // samples that didn't fall off-screen or fail the depth read.
81786
+ const fitPoints = [position];
81787
+ for (let i = 0; i < sampleRings.length; i++) {
81788
+ const ring = sampleRings[i];
81789
+ for (let j = 0; j < ring.length; j++) {
81790
+ const pt = ring[j];
81791
+ if (pt)
81792
+ fitPoints.push(pt);
81635
81793
  }
81636
81794
  }
81637
- else {
81795
+ const normal = new Vec3();
81796
+ if (!fitPlaneNormal(fitPoints, toCamera, normal)) {
81638
81797
  normal.copy(toCamera);
81639
81798
  }
81640
81799
  return {
@@ -81660,8 +81819,13 @@ class Picker {
81660
81819
 
81661
81820
  const SVGNS = 'http://www.w3.org/2000/svg';
81662
81821
  const NUM_SAMPLES = 12;
81663
- const CIRCLE_OUTER_RADIUS = 0.2;
81664
- const CIRCLE_INNER_RADIUS = 0.17;
81822
+ const BASE_OUTER_RADIUS = 0.2;
81823
+ const INNER_OUTER_RATIO = 0.17 / 0.2;
81824
+ // Scenes with halfExtents.length() below this are smaller than the walk
81825
+ // capsule (~1.5 m) — not navigable in walk mode and the world-space ring
81826
+ // engulfs the whole scene. Switch the cursor to a fixed screen size instead.
81827
+ const SMALL_SCENE_THRESHOLD = 2;
81828
+ const SCREEN_OUTER_PIXELS = 60;
81665
81829
  const BEZIER_K = 1 / 6;
81666
81830
  const NORMAL_SMOOTH_FACTOR = 0.25;
81667
81831
  const NORMAL_SNAP_ANGLE = Math.PI / 4;
@@ -81715,6 +81879,22 @@ const right = new Vec3(1, 0, 0);
81715
81879
  const tmpViewPos = new Vec3();
81716
81880
  const tmpClipVec = new Vec4();
81717
81881
  const tmpViewProj = new Mat4();
81882
+ // Compute the world-space radius such that a circle at `pos` projects to a
81883
+ // ring of `pixelDiameter` on screen. Used for the small-scene cursor mode
81884
+ // where we want a constant screen size regardless of zoom.
81885
+ const worldRadiusForPixels = (camera, canvasHeight, pos, pixelDiameter) => {
81886
+ const cam = camera.camera;
81887
+ if (cam.projection === PROJECTION_ORTHOGRAPHIC) {
81888
+ return pixelDiameter * cam.orthoHeight / canvasHeight;
81889
+ }
81890
+ const camPos = camera.getPosition();
81891
+ const dx = pos.x - camPos.x;
81892
+ const dy = pos.y - camPos.y;
81893
+ const dz = pos.z - camPos.z;
81894
+ const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
81895
+ const halfFovTan = Math.tan(cam.fov * Math.PI / 360);
81896
+ return pixelDiameter * distance * halfFovTan / canvasHeight;
81897
+ };
81718
81898
  const worldPointToDepth = (camera, worldPos) => {
81719
81899
  if (camera.projection === PROJECTION_ORTHOGRAPHIC) {
81720
81900
  tmpViewProj.mul2(camera.projectionMatrix, camera.viewMatrix);
@@ -81766,8 +81946,12 @@ const buildBezierRing = (sx, sy) => {
81766
81946
  class CursorRing {
81767
81947
  path;
81768
81948
  svg;
81949
+ canvas;
81769
81950
  camera;
81770
81951
  smoothing;
81952
+ // null = world-space ring (fixed world radius, shrinks with distance);
81953
+ // number = constant on-screen diameter in pixels.
81954
+ screenPixels;
81771
81955
  smoothNx = 0;
81772
81956
  smoothNy = 1;
81773
81957
  smoothNz = 0;
@@ -81776,10 +81960,12 @@ class CursorRing {
81776
81960
  outerY = new Float64Array(NUM_SAMPLES);
81777
81961
  innerX = new Float64Array(NUM_SAMPLES);
81778
81962
  innerY = new Float64Array(NUM_SAMPLES);
81779
- constructor(svg, camera, smoothing) {
81963
+ constructor(svg, canvas, camera, smoothing, screenPixels) {
81780
81964
  this.svg = svg;
81965
+ this.canvas = canvas;
81781
81966
  this.camera = camera;
81782
81967
  this.smoothing = smoothing;
81968
+ this.screenPixels = screenPixels;
81783
81969
  this.path = document.createElementNS(SVGNS, 'path');
81784
81970
  this.path.setAttribute('fill', 'white');
81785
81971
  this.path.setAttribute('fill-opacity', '0.6');
@@ -81836,8 +82022,12 @@ class CursorRing {
81836
82022
  this.smoothNz = nz;
81837
82023
  this.hasSmoothedNormal = true;
81838
82024
  }
81839
- this.projectCircle(pos.x, pos.y, pos.z, nx, ny, nz, CIRCLE_OUTER_RADIUS, this.outerX, this.outerY);
81840
- this.projectCircle(pos.x, pos.y, pos.z, nx, ny, nz, CIRCLE_INNER_RADIUS, this.innerX, this.innerY);
82025
+ const outerRadius = this.screenPixels !== null ?
82026
+ worldRadiusForPixels(this.camera, this.canvas.clientHeight || 1, pos, this.screenPixels) :
82027
+ BASE_OUTER_RADIUS;
82028
+ const innerRadius = outerRadius * INNER_OUTER_RATIO;
82029
+ this.projectCircle(pos.x, pos.y, pos.z, nx, ny, nz, outerRadius, this.outerX, this.outerY);
82030
+ this.projectCircle(pos.x, pos.y, pos.z, nx, ny, nz, innerRadius, this.innerX, this.innerY);
81841
82031
  this.path.setAttribute('d', `${buildBezierRing(this.outerX, this.outerY)} ${buildBezierRing(this.innerX, this.innerY)}`);
81842
82032
  this.path.style.display = '';
81843
82033
  this.svg.style.display = '';
@@ -81877,7 +82067,7 @@ class NavCursor {
81877
82067
  position: new Vec3(),
81878
82068
  normal: new Vec3()
81879
82069
  };
81880
- constructor(app, camera, collision, events, state, picker) {
82070
+ constructor(app, camera, collision, events, state, picker, sceneSize) {
81881
82071
  this.camera = camera;
81882
82072
  this.collision = collision;
81883
82073
  this.canvas = app.graphicsDevice.canvas;
@@ -81887,8 +82077,9 @@ class NavCursor {
81887
82077
  this.svg = document.createElementNS(SVGNS, 'svg');
81888
82078
  this.svg.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;overflow:visible;z-index:1';
81889
82079
  this.canvas.parentElement.appendChild(this.svg);
81890
- this.hoverRing = new CursorRing(this.svg, camera, true);
81891
- this.targetRing = new CursorRing(this.svg, camera, false);
82080
+ const screenPixels = sceneSize < SMALL_SCENE_THRESHOLD ? SCREEN_OUTER_PIXELS : null;
82081
+ this.hoverRing = new CursorRing(this.svg, this.canvas, camera, true, screenPixels);
82082
+ this.targetRing = new CursorRing(this.svg, this.canvas, camera, false, screenPixels);
81892
82083
  this.svg.style.display = 'none';
81893
82084
  this.onPointerMove = (e) => {
81894
82085
  if (e.pointerType === 'touch') {
@@ -83037,7 +83228,7 @@ class Viewer {
83037
83228
  this.cameraManager = new CameraManager(global, sceneBound, collision);
83038
83229
  applyCamera(this.cameraManager.camera);
83039
83230
  if (!config.noui) {
83040
- this.navCursor = new NavCursor(app, camera, collision ?? null, events, state, this.picker);
83231
+ this.navCursor = new NavCursor(app, camera, collision ?? null, events, state, this.picker, sceneBound.halfExtents.length());
83041
83232
  }
83042
83233
  const { instance } = gsplat;
83043
83234
  if (instance) {
@@ -84125,8 +84316,6 @@ const initXr = (global) => {
84125
84316
  });
84126
84317
  };
84127
84318
 
84128
- var version = "1.22.1";
84129
-
84130
84319
  const loadGsplat = async (app, config, progressCallback) => {
84131
84320
  const { contents, contentUrl, aa } = config;
84132
84321
  const c = contents;