@playcanvas/supersplat-viewer 1.8.4 → 1.9.1

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.8.4",
3
+ "version": "1.9.1",
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",
@@ -39,15 +39,16 @@
39
39
  "devDependencies": {
40
40
  "@playcanvas/eslint-config": "2.1.0",
41
41
  "@playcanvas/web-components": "0.2.11",
42
+ "@rollup/plugin-json": "6.1.0",
42
43
  "@rollup/plugin-node-resolve": "16.0.3",
43
44
  "@rollup/plugin-typescript": "12.3.0",
44
- "@typescript-eslint/eslint-plugin": "8.47.0",
45
- "@typescript-eslint/parser": "8.47.0",
45
+ "@typescript-eslint/eslint-plugin": "8.48.0",
46
+ "@typescript-eslint/parser": "8.48.0",
46
47
  "autoprefixer": "10.4.22",
47
48
  "concurrently": "9.2.1",
48
49
  "eslint": "9.39.1",
49
50
  "globals": "16.5.0",
50
- "playcanvas": "2.13.5",
51
+ "playcanvas": "2.13.6",
51
52
  "postcss": "8.5.6",
52
53
  "publint": "0.3.15",
53
54
  "rollup": "4.53.3",
package/public/index.css CHANGED
@@ -1,3 +1,7 @@
1
+ :root {
2
+ --canvas-opacity: 1;
3
+ }
4
+
1
5
  * {
2
6
  margin: 0;
3
7
  padding: 0;
@@ -13,6 +17,10 @@ body {
13
17
  -webkit-touch-callout: none;
14
18
  }
15
19
 
20
+ canvas {
21
+ opacity: var(--canvas-opacity);
22
+ }
23
+
16
24
  button {
17
25
  -webkit-appearance: none;
18
26
  -moz-appearance: none;
@@ -48,6 +56,7 @@ button {
48
56
  left: 0;
49
57
  width: 100%;
50
58
  height: 100%;
59
+ background-image: var(--poster-url);
51
60
  background-size: cover;
52
61
  background-position: center;
53
62
  background-repeat: no-repeat;
package/public/index.html CHANGED
@@ -311,9 +311,12 @@
311
311
  // Show the poster image
312
312
  if (poster) {
313
313
  const element = document.getElementById('poster');
314
- element.style.backgroundImage = `url(${poster.src})`;
314
+ element.style.setProperty('--poster-url', `url(${poster.src})`);
315
315
  element.style.display = 'block';
316
316
  element.style.filter = 'blur(40px)';
317
+
318
+ // hide the canvas
319
+ document.documentElement.style.setProperty('--canvas-opacity', '0');
317
320
  }
318
321
 
319
322
  document.addEventListener('DOMContentLoaded', async () => {
package/public/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const TRACEID_GPU_TIMINGS = 'GpuTimings';
2
2
 
3
- const version = '2.13.5';
4
- const revision = '5aa2502';
3
+ const version$1 = '2.13.6';
4
+ const revision = 'e43e870';
5
5
  function extend(target, ex) {
6
6
  for(const prop in ex){
7
7
  const copy = ex[prop];
@@ -6504,7 +6504,7 @@ class GraphicsDevice extends EventHandler {
6504
6504
  }, this._shadersDirty = false, this.capsDefines = new Map(), this.mapsToClear = new Set();
6505
6505
  this.canvas = canvas;
6506
6506
  if ('setAttribute' in canvas) {
6507
- canvas.setAttribute('data-engine', `PlayCanvas ${version}`);
6507
+ canvas.setAttribute('data-engine', `PlayCanvas ${version$1}`);
6508
6508
  }
6509
6509
  this.initOptions = {
6510
6510
  ...options
@@ -11277,6 +11277,7 @@ class WebgpuUploadStream {
11277
11277
  this.uploadStream = uploadStream;
11278
11278
  this.useSingleBuffer = uploadStream.useSingleBuffer;
11279
11279
  }
11280
+ _onDeviceLost() {}
11280
11281
  destroy() {
11281
11282
  this._destroyed = true;
11282
11283
  this.availableStagingBuffers.forEach((buffer)=>buffer.destroy());
@@ -13119,6 +13120,10 @@ class WebglUploadStream {
13119
13120
  gl.deleteBuffer(item.pbo);
13120
13121
  });
13121
13122
  }
13123
+ _onDeviceLost() {
13124
+ this.availablePBOs.length = 0;
13125
+ this.pendingPBOs.length = 0;
13126
+ }
13122
13127
  update(minByteSize) {
13123
13128
  const gl = this.uploadStream.device.gl;
13124
13129
  const pending = this.pendingPBOs;
@@ -33615,7 +33620,7 @@ class ProgramLibrary {
33615
33620
  }
33616
33621
  text += '\n];\n';
33617
33622
  text += 'pc.getProgramLibrary(device).precompile(shaders);\n';
33618
- text += `if (pc.version != \"${version}\" || pc.revision != \"${revision}\")\n`;
33623
+ text += `if (pc.version != \"${version$1}\" || pc.revision != \"${revision}\")\n`;
33619
33624
  text += '\tconsole.warn(\"precompile-shaders.js: engine version mismatch, rebuild shaders lib with current engine\");';
33620
33625
  const element = document.createElement('a');
33621
33626
  element.setAttribute('href', `data:text/plain;charset=utf-8,${encodeURIComponent(text)}`);
@@ -33983,17 +33988,24 @@ class GSplatData {
33983
33988
 
33984
33989
  class UploadStream {
33985
33990
  constructor(device, useSingleBuffer = false){
33991
+ this._deviceLostEvent = null;
33986
33992
  this.device = device;
33987
33993
  this.useSingleBuffer = useSingleBuffer;
33988
33994
  this.impl = device.createUploadStreamImpl(this);
33989
- }
33990
- upload(data, target, offset = 0, size = data.length) {
33991
- this.impl?.upload(data, target, offset, size);
33995
+ this._deviceLostEvent = this.device.on('devicelost', this._onDeviceLost, this);
33992
33996
  }
33993
33997
  destroy() {
33998
+ this._deviceLostEvent?.off();
33999
+ this._deviceLostEvent = null;
33994
34000
  this.impl?.destroy();
33995
34001
  this.impl = null;
33996
34002
  }
34003
+ upload(data, target, offset = 0, size = data.length) {
34004
+ this.impl?.upload(data, target, offset, size);
34005
+ }
34006
+ _onDeviceLost() {
34007
+ this.impl?._onDeviceLost?.();
34008
+ }
33997
34009
  }
33998
34010
 
33999
34011
  var glslGsplatCopyToWorkBufferPS = `
@@ -76215,8 +76227,12 @@ new BoundingBox();
76215
76227
  new Color(1, 0, 1)
76216
76228
  ];
76217
76229
  class GSplatOctreeInstance {
76218
- get hasPendingLoads() {
76219
- return this.pending.size > 0 || this.prefetchPending.size > 0;
76230
+ get pendingLoadCount() {
76231
+ let count = this.pending.size + this.prefetchPending.size;
76232
+ if (this.octree.environmentUrl && !this.environmentPlacement) {
76233
+ count++;
76234
+ }
76235
+ return count;
76220
76236
  }
76221
76237
  constructor(octree, placement, assetLoader){
76222
76238
  this.activePlacements = new Set();
@@ -77080,13 +77096,11 @@ class GSplatManager {
77080
77096
  }
77081
77097
  fireFrameReadyEvent() {
77082
77098
  const ready = this.sortedVersion === this.lastWorldStateVersion;
77083
- let loading = this.director.assetLoader.isLoading;
77084
- if (!loading) {
77085
- for (const [, inst] of this.octreeInstances){
77086
- loading ||= inst.hasPendingLoads;
77087
- }
77099
+ let loadingCount = 0;
77100
+ for (const [, inst] of this.octreeInstances){
77101
+ loadingCount += inst.pendingLoadCount;
77088
77102
  }
77089
- this.director.eventHandler.fire('frame:ready', this.cameraNode.camera, this.renderer.layer, ready, loading);
77103
+ this.director.eventHandler.fire('frame:ready', this.cameraNode.camera, this.renderer.layer, ready, loadingCount);
77090
77104
  }
77091
77105
  update() {
77092
77106
  this.sorter.applyPendingSorted();
@@ -77688,9 +77702,6 @@ class GSplatAssetLoaderBase {
77688
77702
  load(url) {}
77689
77703
  unload(url) {}
77690
77704
  getResource(url) {}
77691
- get isLoading() {
77692
- return false;
77693
- }
77694
77705
  constructor(){
77695
77706
  this.cooldownTicks = 100;
77696
77707
  }
@@ -77701,9 +77712,6 @@ class GSplatAssetLoader extends GSplatAssetLoaderBase {
77701
77712
  super(), this._urlToAsset = new Map(), this.maxConcurrentLoads = 2, this.maxRetries = 2, this._currentlyLoading = new Set(), this._loadQueue = [], this._retryCount = new Map();
77702
77713
  this._registry = registry;
77703
77714
  }
77704
- get isLoading() {
77705
- return this._currentlyLoading.size > 0 || this._loadQueue.length > 0;
77706
- }
77707
77715
  load(url) {
77708
77716
  const asset = this._urlToAsset.get(url);
77709
77717
  if (asset?.loaded || this._currentlyLoading.has(url)) {
@@ -99583,21 +99591,27 @@ const observe = (events, target) => {
99583
99591
  };
99584
99592
 
99585
99593
  const migrateV1 = (settings) => {
99586
- settings.animTracks?.forEach((track) => {
99587
- // some early settings did not have frameRate set on anim tracks
99588
- if (!track.frameRate) {
99589
- const defaultFrameRate = 30;
99590
- track.frameRate = defaultFrameRate;
99591
- const times = track.keyframes.times;
99592
- for (let i = 0; i < times.length; i++) {
99593
- times[i] *= defaultFrameRate;
99594
+ if (settings.animTracks) {
99595
+ settings.animTracks?.forEach((track) => {
99596
+ // some early settings did not have frameRate set on anim tracks
99597
+ if (!track.frameRate) {
99598
+ const defaultFrameRate = 30;
99599
+ track.frameRate = defaultFrameRate;
99600
+ const times = track.keyframes.times;
99601
+ for (let i = 0; i < times.length; i++) {
99602
+ times[i] *= defaultFrameRate;
99603
+ }
99594
99604
  }
99595
- }
99596
- // smoothness property added in v1.4.0
99597
- if (!track.hasOwnProperty('smoothness')) {
99598
- track.smoothness = 0;
99599
- }
99600
- });
99605
+ // smoothness property added in v1.4.0
99606
+ if (!track.hasOwnProperty('smoothness')) {
99607
+ track.smoothness = 0;
99608
+ }
99609
+ });
99610
+ }
99611
+ else {
99612
+ // some scenes were published without animTracks
99613
+ settings.animTracks = [];
99614
+ }
99601
99615
  return settings;
99602
99616
  };
99603
99617
  const migrateAnimTrackV2 = (animTrackV1, fov) => {
@@ -99779,14 +99793,15 @@ class Tooltip {
99779
99793
  const v = new Vec3();
99780
99794
  // update the poster image to start blurry and then resolve to sharp during loading
99781
99795
  const initPoster = (events) => {
99782
- const element = document.getElementById('poster');
99783
- const blur = (progress) => `blur(${Math.floor((100 - progress) * 0.4)}px)`;
99784
- events.on('progress:changed', (progress) => {
99785
- element.style.filter = blur(progress);
99786
- });
99796
+ const poster = document.getElementById('poster');
99787
99797
  events.on('firstFrame', () => {
99788
- element.style.display = 'none';
99798
+ poster.style.display = 'none';
99799
+ document.documentElement.style.setProperty('--canvas-opacity', '1');
99789
99800
  });
99801
+ const blur = (progress) => {
99802
+ poster.style.filter = `blur(${Math.floor((100 - progress) * 0.4)}px)`;
99803
+ };
99804
+ events.on('progress:changed', blur);
99790
99805
  };
99791
99806
  const initUI = (global) => {
99792
99807
  const { config, events, state } = global;
@@ -101555,7 +101570,7 @@ class Viewer {
101555
101570
  };
101556
101571
  events.on('hqMode:changed', updateHqMode);
101557
101572
  updateHqMode();
101558
- // Construct debug ministats
101573
+ // construct debug ministats
101559
101574
  if (config.ministats) {
101560
101575
  const options = MiniStats.getDefaultOptions();
101561
101576
  options.cpu.enabled = false;
@@ -101567,6 +101582,13 @@ class Viewer {
101567
101582
  multiplier: 1 / (1024 * 1024),
101568
101583
  unitsName: 'MB',
101569
101584
  watermark: 1024
101585
+ }, {
101586
+ name: 'Splats',
101587
+ stats: ['frame.gsplats'],
101588
+ decimalPlaces: 3,
101589
+ multiplier: 1 / 1000000,
101590
+ unitsName: 'M',
101591
+ watermark: 5
101570
101592
  });
101571
101593
  // eslint-disable-next-line no-new
101572
101594
  new MiniStats(app, options);
@@ -101627,6 +101649,10 @@ class Viewer {
101627
101649
  applyCamera(this.cameraManager.camera);
101628
101650
  }
101629
101651
  });
101652
+ // unpause the animation on first frame
101653
+ events.on('firstFrame', () => {
101654
+ state.animationPaused = !!config.noanim;
101655
+ });
101630
101656
  // wait for the model to load
101631
101657
  Promise.all([gsplatLoad, skyboxLoad]).then((results) => {
101632
101658
  const gsplat = results[0].gsplat;
@@ -101662,21 +101688,32 @@ class Viewer {
101662
101688
  });
101663
101689
  }
101664
101690
  else {
101665
- // in unified mode, for now we hard-code LOD range on mobile vs desktop
101666
- const range = platform.mobile ? [2, 5] : [0, 2];
101667
101691
  const { gsplat } = app.scene;
101668
- gsplat.lodRangeMin = range[0];
101669
- gsplat.lodRangeMax = range[1];
101670
- // FIXME: remove ignore when gsplat system is documented
101671
- // @ts-ignore
101692
+ // lod ranges
101693
+ const low = [2, 5];
101694
+ const high = [0, 2];
101695
+ // in unified mode, for now we hard-code LOD range on mobile vs desktop
101696
+ gsplat.lodRangeMin = low[0];
101697
+ gsplat.lodRangeMax = low[1];
101698
+ // these two allow LOD behind camera to drop, saves lots of splats
101699
+ gsplat.lodUpdateAngle = 90;
101700
+ gsplat.lodBehindPenalty = 5;
101701
+ // same performance, but rotating on slow devices does not give us unsorted splats on sides
101702
+ gsplat.radialSorting = true;
101672
101703
  const eventHandler = app.systems.gsplat;
101673
101704
  // force render empty frames otherwise unified rendering doesn't update
101674
101705
  this.forceRenderNextFrame = true;
101706
+ let current = 0;
101707
+ let watermark = 1;
101675
101708
  const readyHandler = (camera, layer, ready, loading) => {
101676
101709
  if (ready && !loading) {
101710
+ // scene is done loading
101677
101711
  eventHandler.off('frame:ready', readyHandler);
101678
101712
  this.forceRenderNextFrame = false;
101679
101713
  state.readyToRender = true;
101714
+ const range = platform.mobile ? low : high;
101715
+ gsplat.lodRangeMin = range[0];
101716
+ gsplat.lodRangeMax = range[1];
101680
101717
  // wait for the first valid frame to complete rendering
101681
101718
  app.once('frameend', () => {
101682
101719
  events.fire('firstFrame');
@@ -101684,14 +101721,17 @@ class Viewer {
101684
101721
  window.firstFrame?.();
101685
101722
  });
101686
101723
  }
101687
- };
101688
- eventHandler.on('frame:ready', readyHandler);
101689
- // render when ready is set
101690
- eventHandler.on('frame:ready', (camera, layer, ready, loading) => {
101691
101724
  if (ready) {
101692
101725
  app.renderNextFrame = true;
101693
101726
  }
101694
- });
101727
+ // update loading status
101728
+ if (loading !== current) {
101729
+ watermark = Math.max(watermark, loading);
101730
+ current = watermark - loading;
101731
+ state.progress = Math.trunc(current / watermark * 100);
101732
+ }
101733
+ };
101734
+ eventHandler.on('frame:ready', readyHandler);
101695
101735
  }
101696
101736
  });
101697
101737
  }
@@ -102305,6 +102345,8 @@ const initXr = (global) => {
102305
102345
  });
102306
102346
  };
102307
102347
 
102348
+ var version = "1.9.1";
102349
+
102308
102350
  const loadGsplat = async (app, config, progressCallback) => {
102309
102351
  const { contents, contentUrl, unified, aa } = config;
102310
102352
  const c = contents;
@@ -102374,7 +102416,7 @@ const main = (app, camera, settingsJson, config) => {
102374
102416
  hasAnimation: false,
102375
102417
  animationDuration: 0,
102376
102418
  animationTime: 0,
102377
- animationPaused: !!config.noanim,
102419
+ animationPaused: true,
102378
102420
  hasAR: false,
102379
102421
  hasVR: false,
102380
102422
  isFullscreen: false,
@@ -102422,6 +102464,7 @@ const main = (app, camera, settingsJson, config) => {
102422
102464
  // Create the viewer
102423
102465
  return new Viewer(global, gsplatLoad, skyboxLoad);
102424
102466
  };
102467
+ console.log(`SuperSplat Viewer v${version} | Engine v${version$1} (${revision})`);
102425
102468
 
102426
102469
  export { main };
102427
102470
  //# sourceMappingURL=index.js.map