@playcanvas/supersplat-viewer 1.17.0 → 1.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcanvas/supersplat-viewer",
3
- "version": "1.17.0",
3
+ "version": "1.17.2",
4
4
  "author": "PlayCanvas <support@playcanvas.com>",
5
5
  "homepage": "https://github.com/playcanvas/supersplat-viewer#readme",
6
6
  "description": "Viewer for https://superspl.at",
package/public/index.js CHANGED
@@ -73563,6 +73563,7 @@ class AnimState {
73563
73563
  result = [];
73564
73564
  position = new Vec3();
73565
73565
  target = new Vec3();
73566
+ fov = 90;
73566
73567
  constructor(spline, duration, loopMode, frameRate) {
73567
73568
  this.spline = spline;
73568
73569
  this.cursor.reset(duration, loopMode);
@@ -73578,18 +73579,20 @@ class AnimState {
73578
73579
  if (result.every(isFinite)) {
73579
73580
  position.set(result[0], result[1], result[2]);
73580
73581
  target.set(result[3], result[4], result[5]);
73582
+ this.fov = result[6];
73581
73583
  }
73582
73584
  }
73583
73585
  // construct an animation from a settings track
73584
73586
  static fromTrack(track) {
73585
73587
  const { keyframes, duration, frameRate, loopMode, smoothness } = track;
73586
73588
  const { times, values } = keyframes;
73587
- const { position, target } = values;
73588
- // construct the points array containing position and target
73589
+ const { position, target, fov } = values;
73590
+ // construct the points array containing position, target and fov
73589
73591
  const points = [];
73590
73592
  for (let i = 0; i < times.length; i++) {
73591
73593
  points.push(position[i * 3], position[i * 3 + 1], position[i * 3 + 2]);
73592
73594
  points.push(target[i * 3], target[i * 3 + 1], target[i * 3 + 2]);
73595
+ points.push(fov[i]);
73593
73596
  }
73594
73597
  const extra = (duration === times[times.length - 1] / frameRate) ? 1 : 0;
73595
73598
  const spline = CubicSpline.fromPointsLooping((duration + extra) * frameRate, times, points, smoothness);
@@ -73604,14 +73607,13 @@ class AnimController {
73604
73607
  this.animState.update(0);
73605
73608
  }
73606
73609
  onEnter(camera) {
73607
- // snap camera to start position
73608
73610
  camera.look(this.animState.position, this.animState.target);
73611
+ camera.fov = this.animState.fov;
73609
73612
  }
73610
73613
  update(deltaTime, inputFrame, camera) {
73611
73614
  this.animState.update(deltaTime);
73612
- // update camera pose
73613
73615
  camera.look(this.animState.position, this.animState.target);
73614
- // ignore input
73616
+ camera.fov = this.animState.fov;
73615
73617
  inputFrame.read();
73616
73618
  }
73617
73619
  onExit(camera) {
@@ -73667,6 +73669,7 @@ const p$1 = new Pose();
73667
73669
  const pushOut = { x: 0, y: 0, z: 0 };
73668
73670
  class FlyController {
73669
73671
  controller;
73672
+ fov = 90;
73670
73673
  /** Optional voxel collider for sphere collision with sliding */
73671
73674
  collider = null;
73672
73675
  constructor() {
@@ -73710,6 +73713,7 @@ class FlyController {
73710
73713
  }
73711
73714
  }
73712
73715
  camera.position.copy(pose.position);
73716
+ camera.fov = this.fov;
73713
73717
  }
73714
73718
  onExit(camera) {
73715
73719
  }
@@ -73721,6 +73725,7 @@ class FlyController {
73721
73725
  const p = new Pose();
73722
73726
  class OrbitController {
73723
73727
  controller;
73728
+ fov = 90;
73724
73729
  constructor() {
73725
73730
  this.controller = new OrbitController$1();
73726
73731
  this.controller.zoomRange = new Vec2(0.01, Infinity);
@@ -73740,6 +73745,7 @@ class OrbitController {
73740
73745
  camera.position.copy(pose.position);
73741
73746
  camera.angles.copy(pose.angles);
73742
73747
  camera.distance = pose.distance;
73748
+ camera.fov = this.fov;
73743
73749
  }
73744
73750
  onExit(camera) {
73745
73751
  }
@@ -73747,16 +73753,20 @@ class OrbitController {
73747
73753
  p.position.copy(camera.position);
73748
73754
  p.angles.copy(camera.angles);
73749
73755
  p.distance = camera.distance;
73756
+ this.fov = camera.fov;
73750
73757
  this.controller.attach(p, false);
73751
73758
  }
73752
73759
  }
73753
73760
 
73761
+ const FIXED_DT = 1 / 60;
73762
+ const MAX_SUBSTEPS = 10;
73754
73763
  /** Pre-allocated push-out vector for capsule collision */
73755
73764
  const out = { x: 0, y: 0, z: 0 };
73756
73765
  const v = new Vec3();
73757
73766
  const d = new Vec3();
73758
73767
  const forward = new Vec3();
73759
73768
  const right$1 = new Vec3();
73769
+ const moveStep = [0, 0, 0];
73760
73770
  const offset = new Vec3();
73761
73771
  const rotation = new Quat();
73762
73772
  /**
@@ -73775,7 +73785,7 @@ class WalkController {
73775
73785
  /**
73776
73786
  * Field of view in degrees for walk mode.
73777
73787
  */
73778
- fov = 102;
73788
+ fov = 96;
73779
73789
  /**
73780
73790
  * Total capsule height in meters (default: human proportion)
73781
73791
  */
@@ -73816,15 +73826,10 @@ class WalkController {
73816
73826
  * Velocity damping factor when grounded (0 = no damping, 1 = full damping)
73817
73827
  */
73818
73828
  velocityDampingGround = 0.99;
73819
- /**
73820
- * Velocity damping factor when grounded with no movement input.
73821
- * More aggressive than normal ground damping to prevent slope drift.
73822
- */
73823
- velocityDampingIdle = 0.9;
73824
73829
  /**
73825
73830
  * Velocity damping factor when in the air (0 = no damping, 1 = full damping)
73826
73831
  */
73827
- velocityDampingAir = 0.997;
73832
+ velocityDampingAir = 0.998;
73828
73833
  /**
73829
73834
  * Target clearance from capsule bottom to ground surface in meters.
73830
73835
  * The capsule hovers this far above terrain to avoid bouncing on noisy voxels.
@@ -73844,8 +73849,11 @@ class WalkController {
73844
73849
  */
73845
73850
  groundProbeRange = 1.0;
73846
73851
  _position = new Vec3();
73852
+ _prevPosition = new Vec3();
73847
73853
  _angles = new Vec3();
73848
73854
  _velocity = new Vec3();
73855
+ _pendingMove = [0, 0, 0];
73856
+ _accumulator = 0;
73849
73857
  _grounded = false;
73850
73858
  _jumping = false;
73851
73859
  _jumpHeld = false;
@@ -73857,12 +73865,41 @@ class WalkController {
73857
73865
  this._grounded = true;
73858
73866
  this._velocity.y = 0;
73859
73867
  this._position.y = groundY + this.hoverHeight + this.eyeHeight;
73868
+ this._prevPosition.copy(this._position);
73860
73869
  }
73861
73870
  }
73862
73871
  }
73863
73872
  update(deltaTime, inputFrame, camera) {
73864
73873
  const { move, rotate } = inputFrame.read();
73865
- const hasInput = move[0] !== 0 || move[2] !== 0;
73874
+ // apply rotation at display rate for responsive mouse look
73875
+ this._angles.add(v.set(-rotate[1], -rotate[0], 0));
73876
+ this._angles.x = math.clamp(this._angles.x, -90, 90);
73877
+ // accumulate movement input so frames without a physics step don't lose input
73878
+ this._pendingMove[0] += move[0];
73879
+ this._pendingMove[1] = this._pendingMove[1] || move[1];
73880
+ this._pendingMove[2] += move[2];
73881
+ this._accumulator = Math.min(this._accumulator + deltaTime, MAX_SUBSTEPS * FIXED_DT);
73882
+ const numSteps = Math.floor(this._accumulator / FIXED_DT);
73883
+ if (numSteps > 0) {
73884
+ const invSteps = 1 / numSteps;
73885
+ moveStep[0] = this._pendingMove[0] * invSteps;
73886
+ moveStep[1] = this._pendingMove[1];
73887
+ moveStep[2] = this._pendingMove[2] * invSteps;
73888
+ for (let i = 0; i < numSteps; i++) {
73889
+ this._prevPosition.copy(this._position);
73890
+ this._step(FIXED_DT, moveStep);
73891
+ this._accumulator -= FIXED_DT;
73892
+ }
73893
+ this._pendingMove[0] = 0;
73894
+ this._pendingMove[1] = 0;
73895
+ this._pendingMove[2] = 0;
73896
+ }
73897
+ const alpha = this._accumulator / FIXED_DT;
73898
+ camera.position.lerp(this._prevPosition, this._position, alpha);
73899
+ camera.angles.set(this._angles.x, this._angles.y, 0);
73900
+ camera.fov = this.fov;
73901
+ }
73902
+ _step(dt, move) {
73866
73903
  // ground probe: cast a ray downward to find the terrain surface
73867
73904
  const groundY = this._probeGround(this._position);
73868
73905
  const hasGround = groundY !== null;
@@ -73882,8 +73919,8 @@ class WalkController {
73882
73919
  const displacement = this._position.y - targetY;
73883
73920
  if (displacement > 0.1) {
73884
73921
  // well above target (jump/ledge): freefall, snap to rest height on arrival
73885
- this._velocity.y -= this.gravity * deltaTime;
73886
- const nextY = this._position.y + this._velocity.y * deltaTime;
73922
+ this._velocity.y -= this.gravity * dt;
73923
+ const nextY = this._position.y + this._velocity.y * dt;
73887
73924
  if (nextY <= targetY) {
73888
73925
  this._position.y = targetY;
73889
73926
  this._velocity.y = 0;
@@ -73893,17 +73930,14 @@ class WalkController {
73893
73930
  else {
73894
73931
  // at or near target (walking/slopes): spring tracks terrain
73895
73932
  const springForce = -this.springStiffness * displacement - this.springDamping * this._velocity.y;
73896
- this._velocity.y += springForce * deltaTime;
73933
+ this._velocity.y += springForce * dt;
73897
73934
  this._grounded = true;
73898
73935
  }
73899
73936
  }
73900
73937
  else {
73901
- this._velocity.y -= this.gravity * deltaTime;
73938
+ this._velocity.y -= this.gravity * dt;
73902
73939
  this._grounded = false;
73903
73940
  }
73904
- // rotate
73905
- this._angles.add(v.set(-rotate[1], -rotate[0], 0));
73906
- this._angles.x = math.clamp(this._angles.x, -90, 90);
73907
73941
  // move
73908
73942
  rotation.setFromEulerAngles(0, this._angles.y, 0);
73909
73943
  rotation.transformVector(Vec3.FORWARD, forward);
@@ -73912,20 +73946,13 @@ class WalkController {
73912
73946
  offset.add(forward.mulScalar(move[2]));
73913
73947
  offset.add(right$1.mulScalar(move[0]));
73914
73948
  this._velocity.add(offset.mulScalar(this._grounded ? this.moveGroundSpeed : this.moveAirSpeed));
73915
- // horizontal damping: aggressive when grounded with no input to prevent slope drift
73916
- const dampFactor = this._grounded ?
73917
- (hasInput ? this.velocityDampingGround : this.velocityDampingIdle) :
73918
- this.velocityDampingAir;
73919
- const alpha = damp(dampFactor, deltaTime);
73949
+ const dampFactor = this._grounded ? this.velocityDampingGround : this.velocityDampingAir;
73950
+ const alpha = damp(dampFactor, dt);
73920
73951
  this._velocity.x = math.lerp(this._velocity.x, 0, alpha);
73921
73952
  this._velocity.z = math.lerp(this._velocity.z, 0, alpha);
73922
- this._position.add(v.copy(this._velocity).mulScalar(deltaTime));
73953
+ this._position.add(v.copy(this._velocity).mulScalar(dt));
73923
73954
  // capsule collision: walls, ceiling, and fallback floor contact
73924
73955
  this._checkCollision(this._position, d);
73925
- // update camera
73926
- camera.position.copy(this._position);
73927
- camera.angles.set(this._angles.x, this._angles.y, 0);
73928
- camera.fov = this.fov;
73929
73956
  }
73930
73957
  onExit(_camera) {
73931
73958
  // nothing to clean up
@@ -73938,12 +73965,17 @@ class WalkController {
73938
73965
  goto(camera) {
73939
73966
  // position
73940
73967
  this._position.copy(camera.position);
73968
+ this._prevPosition.copy(this._position);
73941
73969
  // angles (clamp pitch to avoid gimbal lock)
73942
73970
  this._angles.set(camera.angles.x, camera.angles.y, 0);
73943
73971
  // reset velocity and state
73944
73972
  this._velocity.set(0, 0, 0);
73945
73973
  this._grounded = false;
73946
73974
  this._jumping = false;
73975
+ this._pendingMove[0] = 0;
73976
+ this._pendingMove[1] = 0;
73977
+ this._pendingMove[2] = 0;
73978
+ this._accumulator = 0;
73947
73979
  }
73948
73980
  /**
73949
73981
  * Cast multiple rays downward to find the average ground surface height.
@@ -74031,14 +74063,22 @@ class WalkSource {
74031
74063
  */
74032
74064
  walkSpeed = 4;
74033
74065
  /**
74034
- * Yaw rotation damping while auto-walking toward a target.
74066
+ * Maximum yaw turn rate in degrees per second.
74035
74067
  */
74036
- rotateDamping = 0.99;
74068
+ maxTurnRate = 192;
74069
+ /**
74070
+ * Proportional gain mapping yaw error (degrees) to desired turn rate.
74071
+ * Below maxTurnRate / turnGain degrees the turn rate scales linearly;
74072
+ * above that it is capped at maxTurnRate. The rate filter is
74073
+ * automatically critically damped so there is no overshoot.
74074
+ */
74075
+ turnGain = 5;
74037
74076
  /**
74038
74077
  * Callback fired when an auto-walk completes (arrival or obstacle).
74039
74078
  */
74040
74079
  onComplete = null;
74041
74080
  _target = null;
74081
+ _yawRate = 0;
74042
74082
  _blockedTime = 0;
74043
74083
  _prevDist = Infinity;
74044
74084
  get isWalking() {
@@ -74063,6 +74103,7 @@ class WalkSource {
74063
74103
  cancelWalk() {
74064
74104
  if (this._target) {
74065
74105
  this._target = null;
74106
+ this._yawRate = 0;
74066
74107
  this._blockedTime = 0;
74067
74108
  this.onComplete?.();
74068
74109
  }
@@ -74103,13 +74144,15 @@ class WalkSource {
74103
74144
  }
74104
74145
  }
74105
74146
  this._prevDist = xzDist;
74106
- // yaw toward target
74147
+ // yaw toward target with smoothed turn rate
74107
74148
  const targetYaw = Math.atan2(-dx, -dz) * RAD_TO_DEG;
74108
74149
  let yawDiff = targetYaw - cameraAngles.y;
74109
74150
  yawDiff = ((yawDiff % 360) + 540) % 360 - 180;
74110
- const rotAlpha = damp(this.rotateDamping, dt);
74151
+ const desiredRate = Math.max(-this.maxTurnRate, Math.min(yawDiff * this.turnGain, this.maxTurnRate));
74152
+ const smoothing = 1 - Math.exp(-4 * this.turnGain * dt);
74153
+ this._yawRate += (desiredRate - this._yawRate) * smoothing;
74111
74154
  // WalkController applies: _angles.y += -rotate[0]
74112
- frame.deltas.rotate.append([-(yawDiff * rotAlpha), 0, 0]);
74155
+ frame.deltas.rotate.append([-(this._yawRate * dt), 0, 0]);
74113
74156
  // scale forward speed by alignment: turn in place first, then accelerate
74114
74157
  const alignment = Math.max(0, Math.cos(yawDiff * Math.PI / 180));
74115
74158
  frame.deltas.move.append([0, 0, this.walkSpeed * dt * alignment]);
@@ -74161,6 +74204,8 @@ class CameraManager {
74161
74204
  walk: new WalkController(),
74162
74205
  anim: animTrack ? new AnimController(animTrack) : null
74163
74206
  };
74207
+ controllers.orbit.fov = resetCamera.fov;
74208
+ controllers.fly.fov = resetCamera.fov;
74164
74209
  controllers.fly.collider = collider;
74165
74210
  controllers.walk.collider = collider;
74166
74211
  const walkSource = new WalkSource();
@@ -74180,8 +74225,8 @@ class CameraManager {
74180
74225
  const from = new Camera(this.camera); // stores the previous camera state during transition
74181
74226
  const defaultMode = isObjectExperience ? 'orbit' : (collider ? 'walk' : 'fly');
74182
74227
  let fromMode = defaultMode;
74183
- // tracks the mode to restore when exiting FPS
74184
- let preWalkMode = defaultMode;
74228
+ // tracks the mode to restore when exiting walk
74229
+ let preWalkMode = isObjectExperience ? 'orbit' : 'fly';
74185
74230
  // enter the initial controller
74186
74231
  getController(state.cameraMode).onEnter(this.camera);
74187
74232
  // transition state
@@ -74203,10 +74248,6 @@ class CameraManager {
74203
74248
  walkSource.update(dt, this.camera.position, this.camera.angles, frame);
74204
74249
  }
74205
74250
  controller.update(dt, frame, target);
74206
- // walk controller sets its own FOV; all other modes use the authored FOV
74207
- if (state.cameraMode !== 'walk') {
74208
- target.fov = resetCamera.fov;
74209
- }
74210
74251
  if (transitionTimer < 1) {
74211
74252
  // lerp away from previous camera during transition
74212
74253
  this.camera.lerp(from, target, easeOut(transitionTimer));
@@ -74315,7 +74356,6 @@ class CameraManager {
74315
74356
  tmpCamera.fov = initial.fov;
74316
74357
  tmpCamera.look(new Vec3(initial.position), new Vec3(initial.target));
74317
74358
  controllers.orbit.goto(tmpCamera);
74318
- target.fov = tmpCamera.fov;
74319
74359
  startTransition();
74320
74360
  });
74321
74361
  // tap-to-walk: start auto-walking toward a picked 3D position
@@ -74658,10 +74698,6 @@ class InputController {
74658
74698
  // Store coordinates for click/tap-to-walk picking
74659
74699
  this._lastPointerOffsetX = event.offsetX;
74660
74700
  this._lastPointerOffsetY = event.offsetY;
74661
- // Cancel any active auto-walk in click-to-walk mode
74662
- if (state.cameraMode === 'walk' && !state.gamingControls) {
74663
- events.fire('walkCancel');
74664
- }
74665
74701
  // Start desktop click-to-walk tracking
74666
74702
  if (event.pointerType !== 'touch' && event.button === 0) {
74667
74703
  this._mouseClickTracking = true;
@@ -74685,7 +74721,13 @@ class InputController {
74685
74721
  // Desktop click-to-walk: accumulate displacement during mouse drag
74686
74722
  canvas.addEventListener('pointermove', (event) => {
74687
74723
  if (this._mouseClickTracking && event.pointerType !== 'touch') {
74724
+ const prev = this._mouseClickDelta;
74688
74725
  this._mouseClickDelta += Math.abs(event.movementX) + Math.abs(event.movementY);
74726
+ if (prev < TAP_EPSILON && this._mouseClickDelta >= TAP_EPSILON) {
74727
+ if (state.cameraMode === 'walk' && !state.gamingControls) {
74728
+ events.fire('walkCancel');
74729
+ }
74730
+ }
74689
74731
  }
74690
74732
  });
74691
74733
  // Desktop click-to-walk: detect click (low displacement) on mouse button release
@@ -74898,7 +74940,13 @@ class InputController {
74898
74940
  }
74899
74941
  // Accumulate movement while touch is active
74900
74942
  if (this._tapTouches > 0) {
74943
+ const prevDelta = this._tapDelta;
74901
74944
  this._tapDelta += Math.abs(touch[0]) + Math.abs(touch[1]);
74945
+ if (prevDelta < TAP_EPSILON && this._tapDelta >= TAP_EPSILON) {
74946
+ if (!state.gamingControls) {
74947
+ events.fire('walkCancel');
74948
+ }
74949
+ }
74902
74950
  }
74903
74951
  // Touch just ended (1+ → 0): check if it was a tap
74904
74952
  if (prevTaps > 0 && this._tapTouches === 0) {
@@ -78086,7 +78134,7 @@ const initXr = (global) => {
78086
78134
  });
78087
78135
  };
78088
78136
 
78089
- var version = "1.17.0";
78137
+ var version = "1.17.2";
78090
78138
 
78091
78139
  const loadGsplat = async (app, config, progressCallback) => {
78092
78140
  const { contents, contentUrl, unified, aa } = config;