@playcanvas/supersplat-viewer 1.8.4 → 1.9.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.8.4",
3
+ "version": "1.9.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",
@@ -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)) {
@@ -99779,14 +99787,15 @@ class Tooltip {
99779
99787
  const v = new Vec3();
99780
99788
  // update the poster image to start blurry and then resolve to sharp during loading
99781
99789
  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
- });
99790
+ const poster = document.getElementById('poster');
99787
99791
  events.on('firstFrame', () => {
99788
- element.style.display = 'none';
99792
+ poster.style.display = 'none';
99793
+ document.documentElement.style.setProperty('--canvas-opacity', '1');
99789
99794
  });
99795
+ const blur = (progress) => {
99796
+ poster.style.filter = `blur(${Math.floor((100 - progress) * 0.4)}px)`;
99797
+ };
99798
+ events.on('progress:changed', blur);
99790
99799
  };
99791
99800
  const initUI = (global) => {
99792
99801
  const { config, events, state } = global;
@@ -101555,7 +101564,7 @@ class Viewer {
101555
101564
  };
101556
101565
  events.on('hqMode:changed', updateHqMode);
101557
101566
  updateHqMode();
101558
- // Construct debug ministats
101567
+ // construct debug ministats
101559
101568
  if (config.ministats) {
101560
101569
  const options = MiniStats.getDefaultOptions();
101561
101570
  options.cpu.enabled = false;
@@ -101567,6 +101576,13 @@ class Viewer {
101567
101576
  multiplier: 1 / (1024 * 1024),
101568
101577
  unitsName: 'MB',
101569
101578
  watermark: 1024
101579
+ }, {
101580
+ name: 'Splats',
101581
+ stats: ['frame.gsplats'],
101582
+ decimalPlaces: 3,
101583
+ multiplier: 1 / 1000000,
101584
+ unitsName: 'M',
101585
+ watermark: 5
101570
101586
  });
101571
101587
  // eslint-disable-next-line no-new
101572
101588
  new MiniStats(app, options);
@@ -101627,6 +101643,10 @@ class Viewer {
101627
101643
  applyCamera(this.cameraManager.camera);
101628
101644
  }
101629
101645
  });
101646
+ // unpause the animation on first frame
101647
+ events.on('firstFrame', () => {
101648
+ state.animationPaused = !!config.noanim;
101649
+ });
101630
101650
  // wait for the model to load
101631
101651
  Promise.all([gsplatLoad, skyboxLoad]).then((results) => {
101632
101652
  const gsplat = results[0].gsplat;
@@ -101662,21 +101682,32 @@ class Viewer {
101662
101682
  });
101663
101683
  }
101664
101684
  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
101685
  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
101686
+ // lod ranges
101687
+ const low = [2, 5];
101688
+ const high = [0, 2];
101689
+ // in unified mode, for now we hard-code LOD range on mobile vs desktop
101690
+ gsplat.lodRangeMin = low[0];
101691
+ gsplat.lodRangeMax = low[1];
101692
+ // these two allow LOD behind camera to drop, saves lots of splats
101693
+ gsplat.lodUpdateAngle = 90;
101694
+ gsplat.lodBehindPenalty = 5;
101695
+ // same performance, but rotating on slow devices does not give us unsorted splats on sides
101696
+ gsplat.radialSorting = true;
101672
101697
  const eventHandler = app.systems.gsplat;
101673
101698
  // force render empty frames otherwise unified rendering doesn't update
101674
101699
  this.forceRenderNextFrame = true;
101700
+ let current = 0;
101701
+ let watermark = 1;
101675
101702
  const readyHandler = (camera, layer, ready, loading) => {
101676
101703
  if (ready && !loading) {
101704
+ // scene is done loading
101677
101705
  eventHandler.off('frame:ready', readyHandler);
101678
101706
  this.forceRenderNextFrame = false;
101679
101707
  state.readyToRender = true;
101708
+ const range = platform.mobile ? low : high;
101709
+ gsplat.lodRangeMin = range[0];
101710
+ gsplat.lodRangeMax = range[1];
101680
101711
  // wait for the first valid frame to complete rendering
101681
101712
  app.once('frameend', () => {
101682
101713
  events.fire('firstFrame');
@@ -101684,14 +101715,17 @@ class Viewer {
101684
101715
  window.firstFrame?.();
101685
101716
  });
101686
101717
  }
101687
- };
101688
- eventHandler.on('frame:ready', readyHandler);
101689
- // render when ready is set
101690
- eventHandler.on('frame:ready', (camera, layer, ready, loading) => {
101691
101718
  if (ready) {
101692
101719
  app.renderNextFrame = true;
101693
101720
  }
101694
- });
101721
+ // update loading status
101722
+ if (loading !== current) {
101723
+ watermark = Math.max(watermark, loading);
101724
+ current = watermark - loading;
101725
+ state.progress = Math.trunc(current / watermark * 100);
101726
+ }
101727
+ };
101728
+ eventHandler.on('frame:ready', readyHandler);
101695
101729
  }
101696
101730
  });
101697
101731
  }
@@ -102305,6 +102339,8 @@ const initXr = (global) => {
102305
102339
  });
102306
102340
  };
102307
102341
 
102342
+ var version = "1.9.0";
102343
+
102308
102344
  const loadGsplat = async (app, config, progressCallback) => {
102309
102345
  const { contents, contentUrl, unified, aa } = config;
102310
102346
  const c = contents;
@@ -102374,7 +102410,7 @@ const main = (app, camera, settingsJson, config) => {
102374
102410
  hasAnimation: false,
102375
102411
  animationDuration: 0,
102376
102412
  animationTime: 0,
102377
- animationPaused: !!config.noanim,
102413
+ animationPaused: true,
102378
102414
  hasAR: false,
102379
102415
  hasVR: false,
102380
102416
  isFullscreen: false,
@@ -102422,6 +102458,7 @@ const main = (app, camera, settingsJson, config) => {
102422
102458
  // Create the viewer
102423
102459
  return new Viewer(global, gsplatLoad, skyboxLoad);
102424
102460
  };
102461
+ console.log(`SuperSplat Viewer v${version} | Engine v${version$1} (${revision})`);
102425
102462
 
102426
102463
  export { main };
102427
102464
  //# sourceMappingURL=index.js.map