@playcanvas/supersplat-viewer 1.11.2 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcanvas/supersplat-viewer",
3
- "version": "1.11.2",
3
+ "version": "1.12.0",
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.css CHANGED
@@ -325,22 +325,24 @@ button {
325
325
 
326
326
  #joystickBase {
327
327
  position: absolute;
328
- width: 96px;
329
- height: 96px;
328
+ width: 64px;
329
+ height: 120px;
330
330
  transform: translate(-50%, -50%);
331
- border-radius: 50%;
331
+ border-radius: 32px;
332
332
  touch-action: none;
333
- background: radial-gradient(circle at center, rgba(0, 0, 0, 0) 50%, black 100%);
334
- background-color: rgba(0, 0, 0, 0.1333333333);
333
+ background: linear-gradient(180deg, rgba(0, 0, 0, 0.2666666667) 0%, rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0) 70%, rgba(0, 0, 0, 0.2666666667) 100%);
334
+ background-color: rgba(0, 0, 0, 0.2);
335
+ border: 2px solid rgba(255, 255, 255, 0.2);
335
336
  }
336
337
  #joystickBase > #joystick {
337
338
  position: absolute;
339
+ left: 8px;
338
340
  width: 48px;
339
341
  height: 48px;
340
- transform: translate(-50%, -50%);
341
342
  border-radius: 50%;
342
343
  touch-action: none;
343
344
  background-color: rgba(255, 255, 255, 0.5333333333);
345
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
344
346
  }
345
347
 
346
348
  #tooltip {
package/public/index.js CHANGED
@@ -96589,9 +96589,6 @@ let InputController$1 = class InputController extends InputConsumer {
96589
96589
  }
96590
96590
  };
96591
96591
 
96592
- const DOUBLE_TAP_THRESHOLD = 250;
96593
- const DOUBLE_TAP_VARIANCE = 100;
96594
-
96595
96592
  const movementState = ()=>{
96596
96593
  const state = new Map();
96597
96594
  return {
@@ -96624,223 +96621,6 @@ const movementState = ()=>{
96624
96621
  };
96625
96622
  };
96626
96623
 
96627
- const v$1 = new Vec2();
96628
- class VirtualJoystick {
96629
- get value() {
96630
- return this._value;
96631
- }
96632
- down(x, y) {
96633
- this._position.set(x, y);
96634
- this._value.set(0, 0);
96635
- return [
96636
- x,
96637
- y,
96638
- x,
96639
- y
96640
- ];
96641
- }
96642
- move(x, y) {
96643
- v$1.set(x - this._position.x, y - this._position.y);
96644
- if (v$1.length() > this._range) {
96645
- v$1.normalize().mulScalar(this._range);
96646
- }
96647
- this._value.set(math.clamp(v$1.x / this._range, -1, 1), math.clamp(v$1.y / this._range, -1, 1));
96648
- const { x: bx, y: by } = this._position;
96649
- return [
96650
- bx,
96651
- by,
96652
- bx + v$1.x,
96653
- by + v$1.y
96654
- ];
96655
- }
96656
- up() {
96657
- this._position.set(0, 0);
96658
- this._value.set(0, 0);
96659
- return [
96660
- -1,
96661
- -1,
96662
- -1,
96663
- -1
96664
- ];
96665
- }
96666
- constructor({ range } = {}){
96667
- this._range = 70;
96668
- this._position = new Vec2();
96669
- this._value = new Vec2();
96670
- this._range = range ?? this._range;
96671
- }
96672
- }
96673
-
96674
- const startsWith = (str, prefix)=>str.indexOf(prefix) === 0;
96675
- const endsWith = (str, suffix)=>str.indexOf(suffix, str.length - suffix.length) !== -1;
96676
- class DualGestureSource extends InputSource {
96677
- set layout(value) {
96678
- if (this._layout === value) {
96679
- return;
96680
- }
96681
- this._layout = value;
96682
- this.read();
96683
- this._pointerData.clear();
96684
- }
96685
- get layout() {
96686
- return this._layout;
96687
- }
96688
- get leftJoystick() {
96689
- return this._leftJoystick;
96690
- }
96691
- get rightJoystick() {
96692
- return this._rightJoystick;
96693
- }
96694
- _onPointerDown(event) {
96695
- const { pointerType, pointerId, clientX, clientY } = event;
96696
- this._movementState.down(event);
96697
- if (pointerType !== 'touch') {
96698
- return;
96699
- }
96700
- this._element?.setPointerCapture(pointerId);
96701
- const left = clientX < window.innerWidth * 0.5;
96702
- this._pointerData.set(pointerId, {
96703
- x: clientX,
96704
- y: clientY,
96705
- left
96706
- });
96707
- const now = Date.now();
96708
- const sqrDist = (this._lastPointer.x - clientX) ** 2 + (this._lastPointer.y - clientY) ** 2;
96709
- if (sqrDist < DOUBLE_TAP_VARIANCE && now - this._lastPointer.time < DOUBLE_TAP_THRESHOLD) {
96710
- this.deltas.doubleTap.append([
96711
- 1
96712
- ]);
96713
- }
96714
- this._lastPointer.x = clientX;
96715
- this._lastPointer.y = clientY;
96716
- this._lastPointer.time = now;
96717
- if (left && startsWith(this._layout, 'joystick')) {
96718
- this.fire('joystick:position:left', this._leftJoystick.down(clientX, clientY));
96719
- }
96720
- if (!left && endsWith(this._layout, 'joystick')) {
96721
- this.fire('joystick:position:right', this._rightJoystick.down(clientX, clientY));
96722
- }
96723
- }
96724
- _onPointerMove(event) {
96725
- const { pointerType, pointerId, target, clientX, clientY } = event;
96726
- const [movementX, movementY] = this._movementState.move(event);
96727
- if (pointerType !== 'touch') {
96728
- return;
96729
- }
96730
- if (target !== this._element) {
96731
- return;
96732
- }
96733
- const data = this._pointerData.get(pointerId);
96734
- if (!data) {
96735
- return;
96736
- }
96737
- const { left } = data;
96738
- data.x = clientX;
96739
- data.y = clientY;
96740
- if (left) {
96741
- if (startsWith(this._layout, 'joystick')) {
96742
- this.fire('joystick:position:left', this._leftJoystick.move(clientX, clientY));
96743
- } else {
96744
- this.deltas.leftInput.append([
96745
- movementX,
96746
- movementY
96747
- ]);
96748
- }
96749
- } else {
96750
- if (endsWith(this._layout, 'joystick')) {
96751
- this.fire('joystick:position:right', this._rightJoystick.move(clientX, clientY));
96752
- } else {
96753
- this.deltas.rightInput.append([
96754
- movementX,
96755
- movementY
96756
- ]);
96757
- }
96758
- }
96759
- }
96760
- _onPointerUp(event) {
96761
- const { pointerType, pointerId } = event;
96762
- this._movementState.up(event);
96763
- if (pointerType !== 'touch') {
96764
- return;
96765
- }
96766
- this._element?.releasePointerCapture(pointerId);
96767
- const data = this._pointerData.get(pointerId);
96768
- if (!data) {
96769
- return;
96770
- }
96771
- const { left } = data;
96772
- this._pointerData.delete(pointerId);
96773
- if (left && startsWith(this._layout, 'joystick')) {
96774
- this.fire('joystick:position:left', this._leftJoystick.up());
96775
- }
96776
- if (!left && endsWith(this._layout, 'joystick')) {
96777
- this.fire('joystick:position:right', this._rightJoystick.up());
96778
- }
96779
- }
96780
- attach(element) {
96781
- super.attach(element);
96782
- this._element = element;
96783
- this._element.addEventListener('pointerdown', this._onPointerDown);
96784
- this._element.addEventListener('pointermove', this._onPointerMove);
96785
- this._element.addEventListener('pointerup', this._onPointerUp);
96786
- this._element.addEventListener('pointercancel', this._onPointerUp);
96787
- }
96788
- detach() {
96789
- if (!this._element) {
96790
- return;
96791
- }
96792
- this._element.removeEventListener('pointerdown', this._onPointerDown);
96793
- this._element.removeEventListener('pointermove', this._onPointerMove);
96794
- this._element.removeEventListener('pointerup', this._onPointerUp);
96795
- this._element.removeEventListener('pointercancel', this._onPointerUp);
96796
- this._pointerData.clear();
96797
- super.detach();
96798
- }
96799
- read() {
96800
- this.deltas.leftInput.append([
96801
- this._leftJoystick.value.x,
96802
- this._leftJoystick.value.y
96803
- ]);
96804
- this.deltas.rightInput.append([
96805
- this._rightJoystick.value.x,
96806
- this._rightJoystick.value.y
96807
- ]);
96808
- return super.read();
96809
- }
96810
- destroy() {
96811
- this._leftJoystick.up();
96812
- this._rightJoystick.up();
96813
- super.destroy();
96814
- }
96815
- constructor(layout){
96816
- super({
96817
- leftInput: [
96818
- 0,
96819
- 0
96820
- ],
96821
- rightInput: [
96822
- 0,
96823
- 0
96824
- ],
96825
- doubleTap: [
96826
- 0
96827
- ]
96828
- }), this._movementState = movementState(), this._layout = 'joystick-touch', this._pointerData = new Map(), this._lastPointer = {
96829
- x: 0,
96830
- y: 0,
96831
- time: 0
96832
- };
96833
- if (layout) {
96834
- this.layout = layout;
96835
- }
96836
- this._leftJoystick = new VirtualJoystick();
96837
- this._rightJoystick = new VirtualJoystick();
96838
- this._onPointerDown = this._onPointerDown.bind(this);
96839
- this._onPointerMove = this._onPointerMove.bind(this);
96840
- this._onPointerUp = this._onPointerUp.bind(this);
96841
- }
96842
- }
96843
-
96844
96624
  const tmpVa = new Vec2();
96845
96625
  class MultiTouchSource extends InputSource {
96846
96626
  _onPointerDown(event) {
@@ -102519,7 +102299,77 @@ class Tooltip {
102519
102299
  }
102520
102300
  }
102521
102301
 
102522
- const v = new Vec3();
102302
+ // Initialize the touch joystick for fly mode camera control
102303
+ const initJoystick = (dom, events, state) => {
102304
+ // Joystick dimensions (matches SCSS: base height=120, stick size=48)
102305
+ const joystickHeight = 120;
102306
+ const stickSize = 48;
102307
+ const stickCenterY = (joystickHeight - stickSize) / 2; // 36px - top position when centered
102308
+ const maxStickTravel = stickCenterY; // can travel 36px up or down from center
102309
+ // Fixed joystick position (bottom-left corner with safe area)
102310
+ const joystickFixedX = 60;
102311
+ const joystickFixedY = () => window.innerHeight - 140;
102312
+ // Joystick touch state
102313
+ let joystickPointerId = null;
102314
+ let joystickValue = 0; // -1 to 1, negative = forward, positive = backward
102315
+ // Update joystick visibility based on camera mode and input mode
102316
+ const updateJoystickVisibility = () => {
102317
+ if (state.cameraMode === 'fly' && state.inputMode === 'touch') {
102318
+ dom.joystickBase.classList.remove('hidden');
102319
+ dom.joystickBase.style.left = `${joystickFixedX}px`;
102320
+ dom.joystickBase.style.top = `${joystickFixedY()}px`;
102321
+ // Center the stick vertically (top edge at 36px)
102322
+ dom.joystick.style.top = `${stickCenterY}px`;
102323
+ }
102324
+ else {
102325
+ dom.joystickBase.classList.add('hidden');
102326
+ }
102327
+ };
102328
+ events.on('cameraMode:changed', updateJoystickVisibility);
102329
+ events.on('inputMode:changed', updateJoystickVisibility);
102330
+ window.addEventListener('resize', updateJoystickVisibility);
102331
+ // Handle joystick touch input directly on the joystick element
102332
+ const updateJoystickStick = (clientY) => {
102333
+ const baseY = joystickFixedY();
102334
+ // Calculate offset from joystick center (positive = down/backward)
102335
+ const offsetY = clientY - baseY;
102336
+ // Clamp to max travel and normalize to -1 to 1
102337
+ const clampedOffset = Math.max(-maxStickTravel, Math.min(maxStickTravel, offsetY));
102338
+ joystickValue = clampedOffset / maxStickTravel;
102339
+ // Update stick visual position
102340
+ dom.joystick.style.top = `${stickCenterY + clampedOffset}px`;
102341
+ // Fire input event for the input controller
102342
+ events.fire('joystickInput', joystickValue);
102343
+ };
102344
+ dom.joystickBase.addEventListener('pointerdown', (event) => {
102345
+ if (joystickPointerId !== null)
102346
+ return; // Already tracking a touch
102347
+ joystickPointerId = event.pointerId;
102348
+ dom.joystickBase.setPointerCapture(event.pointerId);
102349
+ updateJoystickStick(event.clientY);
102350
+ event.preventDefault();
102351
+ event.stopPropagation();
102352
+ });
102353
+ dom.joystickBase.addEventListener('pointermove', (event) => {
102354
+ if (event.pointerId !== joystickPointerId)
102355
+ return;
102356
+ updateJoystickStick(event.clientY);
102357
+ event.preventDefault();
102358
+ });
102359
+ const endJoystickTouch = (event) => {
102360
+ if (event.pointerId !== joystickPointerId)
102361
+ return;
102362
+ joystickPointerId = null;
102363
+ joystickValue = 0;
102364
+ // Reset stick to center
102365
+ dom.joystick.style.top = `${stickCenterY}px`;
102366
+ // Fire input event with zero value
102367
+ events.fire('joystickInput', 0);
102368
+ dom.joystickBase.releasePointerCapture(event.pointerId);
102369
+ };
102370
+ dom.joystickBase.addEventListener('pointerup', endJoystickTouch);
102371
+ dom.joystickBase.addEventListener('pointercancel', endJoystickTouch);
102372
+ };
102523
102373
  // update the poster image to start blurry and then resolve to sharp during loading
102524
102374
  const initPoster = (events) => {
102525
102375
  const poster = document.getElementById('poster');
@@ -102787,24 +102637,8 @@ const initUI = (global) => {
102787
102637
  dom.frame.addEventListener('click', (event) => {
102788
102638
  events.fire('inputEvent', 'frame', event);
102789
102639
  });
102790
- // update UI based on touch joystick updates
102791
- events.on('touchJoystickUpdate', (base, stick) => {
102792
- if (base === null) {
102793
- dom.joystickBase.classList.add('hidden');
102794
- }
102795
- else {
102796
- v.set(stick[0], stick[1], 0).mulScalar(1 / 48);
102797
- if (v.length() > 1) {
102798
- v.normalize();
102799
- }
102800
- v.mulScalar(48);
102801
- dom.joystickBase.classList.remove('hidden');
102802
- dom.joystickBase.style.left = `${base[0]}px`;
102803
- dom.joystickBase.style.top = `${base[1]}px`;
102804
- dom.joystick.style.left = `${48 + v.x}px`;
102805
- dom.joystick.style.top = `${48 + v.y}px`;
102806
- }
102807
- });
102640
+ // Initialize touch joystick for fly mode
102641
+ initJoystick(dom, events, state);
102808
102642
  // Hide all UI (poster, loading bar, controls)
102809
102643
  if (config.noui) {
102810
102644
  dom.ui.classList.add('hidden');
@@ -104085,14 +103919,14 @@ class InputController {
104085
103919
  };
104086
103920
  _desktopInput = new KeyboardMouseSource();
104087
103921
  _orbitInput = new MultiTouchSource();
104088
- _flyInput = new DualGestureSource();
104089
103922
  _gamepadInput = new GamepadSource();
104090
103923
  global;
104091
103924
  frame = new InputFrame({
104092
103925
  move: [0, 0, 0],
104093
103926
  rotate: [0, 0, 0]
104094
103927
  });
104095
- joystick = { base: null, stick: null };
103928
+ // Touch joystick input value (-1 to 1, negative = forward)
103929
+ _touchJoystickValue = 0;
104096
103930
  // this gets overridden by the viewer based on scene size
104097
103931
  moveSpeed = 4;
104098
103932
  orbitSpeed = 18;
@@ -104103,16 +103937,9 @@ class InputController {
104103
103937
  const canvas = app.graphicsDevice.canvas;
104104
103938
  this._desktopInput.attach(canvas);
104105
103939
  this._orbitInput.attach(canvas);
104106
- this._flyInput.attach(canvas);
104107
- // convert events to joystick state
104108
- this._flyInput.on('joystick:position:left', ([bx, by, sx, sy]) => {
104109
- if (bx < 0 || by < 0 || sx < 0 || sy < 0) {
104110
- this.joystick.base = null;
104111
- this.joystick.stick = null;
104112
- return;
104113
- }
104114
- this.joystick.base = [bx, by];
104115
- this.joystick.stick = [sx - bx, sy - by];
103940
+ // Listen for joystick input from the UI (touch joystick element)
103941
+ events.on('joystickInput', (value) => {
103942
+ this._touchJoystickValue = value;
104116
103943
  });
104117
103944
  this.global = global;
104118
103945
  // Generate input events
@@ -104193,9 +104020,8 @@ class InputController {
104193
104020
  const { keyCode } = KeyboardMouseSource;
104194
104021
  const { key, button, mouse, wheel } = this._desktopInput.read();
104195
104022
  const { touch, pinch, count } = this._orbitInput.read();
104196
- const { leftInput, rightInput } = this._flyInput.read();
104197
104023
  const { leftStick, rightStick } = this._gamepadInput.read();
104198
- const { events, state } = this.global;
104024
+ const { state } = this.global;
104199
104025
  const { camera } = this.global.camera;
104200
104026
  // update state
104201
104027
  this._state.axis.add(tmpV1.set((key[keyCode.D] - key[keyCode.A]) + (key[keyCode.RIGHT] - key[keyCode.LEFT]), (key[keyCode.E] - key[keyCode.Q]), (key[keyCode.W] - key[keyCode.S]) + (key[keyCode.UP] - key[keyCode.DOWN])));
@@ -104233,7 +104059,8 @@ class InputController {
104233
104059
  v.set(0, 0, 0);
104234
104060
  const orbitMove = screenToWorld(camera, touch[0], touch[1], distance);
104235
104061
  v.add(orbitMove.mulScalar(orbit * pan));
104236
- flyMove.set(leftInput[0], 0, -leftInput[1]);
104062
+ // Use touch joystick value for fly movement (negative = forward)
104063
+ flyMove.set(0, 0, -this._touchJoystickValue);
104237
104064
  v.add(flyMove.mulScalar(fly * this.moveSpeed * dt));
104238
104065
  pinchMove.set(0, 0, pinch[0]);
104239
104066
  v.add(pinchMove.mulScalar(orbit * double * this.pinchSpeed * dt));
@@ -104242,8 +104069,11 @@ class InputController {
104242
104069
  v.set(0, 0, 0);
104243
104070
  orbitRotate.set(touch[0], touch[1], 0);
104244
104071
  v.add(orbitRotate.mulScalar(orbit * (1 - pan) * this.orbitSpeed * dt));
104245
- flyRotate.set(rightInput[0], rightInput[1], 0);
104246
- v.add(flyRotate.mulScalar(fly * this.orbitSpeed * orbitFactor * dt));
104072
+ // In fly mode, use any touch for look-around (joystick captures its own touches)
104073
+ // Exclude multi-touch (double) to avoid interference with pinch gestures
104074
+ // 1.5x sensitivity for touch look-around
104075
+ flyRotate.set(touch[0], touch[1], 0);
104076
+ v.add(flyRotate.mulScalar(fly * (1 - double) * this.orbitSpeed * orbitFactor * 1.5 * dt));
104247
104077
  deltas.rotate.append([v.x, v.y, v.z]);
104248
104078
  // gamepad move
104249
104079
  v.set(0, 0, 0);
@@ -104255,10 +104085,6 @@ class InputController {
104255
104085
  stickRotate.set(rightStick[0], rightStick[1], 0);
104256
104086
  v.add(stickRotate.mulScalar(this.orbitSpeed * orbitFactor * dt));
104257
104087
  deltas.rotate.append([v.x, v.y, v.z]);
104258
- // update touch joystick UI
104259
- if (state.cameraMode === 'fly') {
104260
- events.fire('touchJoystickUpdate', this.joystick.base, this.joystick.stick);
104261
- }
104262
104088
  }
104263
104089
  }
104264
104090
 
@@ -104514,31 +104340,17 @@ class Viewer {
104514
104340
  // quality ranges
104515
104341
  const ranges = {
104516
104342
  mobile: {
104517
- low: {
104518
- range: [2, 8],
104519
- splatBudget: 1
104520
- },
104521
- high: {
104522
- range: [1, 8],
104523
- splatBudget: 2
104524
- }
104343
+ low: 1,
104344
+ high: 2
104525
104345
  },
104526
104346
  desktop: {
104527
- low: {
104528
- range: [1, 8],
104529
- splatBudget: 3
104530
- },
104531
- high: {
104532
- range: [0, 8],
104533
- splatBudget: 6
104534
- }
104347
+ low: 3,
104348
+ high: 6
104535
104349
  }
104536
104350
  };
104537
104351
  const quality = platform.mobile ? ranges.mobile : ranges.desktop;
104538
104352
  // start in low quality mode so we can get user interacting asap
104539
- gsplat.lodRangeMin = quality.low.range[0];
104540
- gsplat.lodRangeMax = quality.low.range[1];
104541
- results[0].gsplat.splatBudget = quality.low.splatBudget * 1000000;
104353
+ results[0].gsplat.splatBudget = quality.low * 1000000;
104542
104354
  // these two allow LOD behind camera to drop, saves lots of splats
104543
104355
  gsplat.lodUpdateAngle = 90;
104544
104356
  gsplat.lodBehindPenalty = 5;
@@ -104557,9 +104369,7 @@ class Viewer {
104557
104369
  // handle quality mode changes
104558
104370
  const updateLod = () => {
104559
104371
  const settings = state.hqMode ? quality.high : quality.low;
104560
- gsplat.lodRangeMin = settings.range[0];
104561
- gsplat.lodRangeMax = settings.range[1];
104562
- results[0].gsplat.splatBudget = settings.splatBudget * 1000000;
104372
+ results[0].gsplat.splatBudget = settings * 1000000;
104563
104373
  };
104564
104374
  events.on('hqMode:changed', updateLod);
104565
104375
  updateLod();
@@ -105521,7 +105331,7 @@ const initXr = (global) => {
105521
105331
  });
105522
105332
  };
105523
105333
 
105524
- var version = "1.11.2";
105334
+ var version = "1.12.0";
105525
105335
 
105526
105336
  const loadGsplat = async (app, config, progressCallback) => {
105527
105337
  const { contents, contentUrl, unified, aa } = config;