@playcanvas/supersplat-viewer 1.26.4 → 1.27.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.26.4",
3
+ "version": "1.27.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",
@@ -51,7 +51,7 @@
51
51
  "concurrently": "9.2.3",
52
52
  "eslint": "9.39.4",
53
53
  "globals": "17.7.0",
54
- "playcanvas": "2.20.2",
54
+ "playcanvas": "2.20.4",
55
55
  "postcss": "8.5.16",
56
56
  "publint": "0.3.21",
57
57
  "rollup": "4.62.2",
package/public/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const TRACEID_GPU_TIMINGS = "GpuTimings";
2
2
 
3
- const version$1 = "2.20.2";
4
- const revision = "4590e5f";
3
+ const version$1 = "2.20.4";
4
+ const revision = "0756c51";
5
5
  function extend(target, ex) {
6
6
  for (const prop in ex) {
7
7
  const copy = ex[prop];
@@ -37777,6 +37777,9 @@ class ResourceHandler {
37777
37777
  this._app = app;
37778
37778
  this.handlerType = handlerType;
37779
37779
  }
37780
+ get app() {
37781
+ return this._app;
37782
+ }
37780
37783
  set maxRetries(value) {
37781
37784
  this._maxRetries = value;
37782
37785
  }
@@ -42316,6 +42319,7 @@ float median(float r, float g, float b) {
42316
42319
  return max(min(r, g), min(max(r, g), b));
42317
42320
  }
42318
42321
  uniform float font_sdfIntensity;
42322
+ uniform float font_pxrange;
42319
42323
  #ifndef LIT_MSDF_TEXT_ATTRIBUTE
42320
42324
  uniform vec4 outline_color;
42321
42325
  uniform float outline_thickness;
@@ -42335,10 +42339,11 @@ vec4 applyMsdf(vec4 color) {
42335
42339
  float sigDist = median(tsample.r, tsample.g, tsample.b);
42336
42340
  float sigDistShdw = median(ssample.r, ssample.g, ssample.b);
42337
42341
  float edge = 0.5 - 0.5 * font_sdfIntensity;
42338
- float aa = max(fwidth(sigDist), 1e-4);
42339
- float inside = clamp((sigDist - edge) / aa + 0.5, 0.0, 1.0);
42340
- float outline = clamp((sigDist + outline_thickness - edge) / aa + 0.5, 0.0, 1.0);
42341
- float shadow = clamp((sigDistShdw + outline_thickness - edge) / aa + 0.5, 0.0, 1.0);
42342
+ vec2 unitRange = vec2(font_pxrange) / vec2(textureSize(texture_msdfMap, 0));
42343
+ float screenPxRange = max(0.5 * dot(unitRange, 1.0 / max(fwidth(vUv0), vec2(1e-6))), 1.0);
42344
+ float inside = clamp(screenPxRange * (sigDist - edge) + 0.5, 0.0, 1.0);
42345
+ float outline = clamp(screenPxRange * (sigDist + outline_thickness - edge) + 0.5, 0.0, 1.0);
42346
+ float shadow = clamp(screenPxRange * (sigDistShdw + outline_thickness - edge) + 0.5, 0.0, 1.0);
42342
42347
  vec4 tcolor = (outline > inside) ? outline * vec4(outline_color.a * outline_color.rgb, outline_color.a) : vec4(0.0);
42343
42348
  tcolor = mix(tcolor, color, inside);
42344
42349
  vec4 scolor = (shadow > outline) ? shadow * vec4(shadow_color.a * shadow_color.rgb, shadow_color.a) : tcolor;
@@ -47789,6 +47794,7 @@ fn median(r: f32, g: f32, b: f32) -> f32 {
47789
47794
  return max(min(r, g), min(max(r, g), b));
47790
47795
  }
47791
47796
  uniform font_sdfIntensity: f32;
47797
+ uniform font_pxrange: f32;
47792
47798
  #ifndef LIT_MSDF_TEXT_ATTRIBUTE
47793
47799
  uniform outline_color: vec4f;
47794
47800
  uniform outline_thickness: f32;
@@ -47819,10 +47825,12 @@ fn applyMsdf(color_in: vec4f) -> vec4f {
47819
47825
  let sigDist: f32 = median(tsample.r, tsample.g, tsample.b);
47820
47826
  let sigDistShdw: f32 = median(ssample.r, ssample.g, ssample.b);
47821
47827
  let edge: f32 = 0.5 - 0.5 * uniform.font_sdfIntensity;
47822
- let aa: f32 = max(abs(dpdx(sigDist)) + abs(dpdy(sigDist)), 1e-4);
47823
- let inside: f32 = clamp((sigDist - edge) / aa + 0.5, 0.0, 1.0);
47824
- let outline: f32 = clamp((sigDist + outline_thicknessValue - edge) / aa + 0.5, 0.0, 1.0);
47825
- let shadow: f32 = clamp((sigDistShdw + outline_thicknessValue - edge) / aa + 0.5, 0.0, 1.0);
47828
+ let unitRange: vec2f = vec2f(uniform.font_pxrange) / vec2f(textureDimensions(texture_msdfMap, 0));
47829
+ let uvDeriv: vec2f = max(abs(dpdx(vUv0)) + abs(dpdy(vUv0)), vec2f(1e-6));
47830
+ let screenPxRange: f32 = max(0.5 * dot(unitRange, vec2f(1.0) / uvDeriv), 1.0);
47831
+ let inside: f32 = clamp(screenPxRange * (sigDist - edge) + 0.5, 0.0, 1.0);
47832
+ let outline: f32 = clamp(screenPxRange * (sigDist + outline_thicknessValue - edge) + 0.5, 0.0, 1.0);
47833
+ let shadow: f32 = clamp(screenPxRange * (sigDistShdw + outline_thicknessValue - edge) + 0.5, 0.0, 1.0);
47826
47834
  let tcolor_outline: vec4f = outline * vec4f(outline_colorValue.a * outline_colorValue.rgb, outline_colorValue.a);
47827
47835
  var tcolor: vec4f = select(vec4f(0.0), tcolor_outline, outline > inside);
47828
47836
  tcolor = mix(tcolor, color, inside);
@@ -69234,6 +69242,7 @@ class GSplatAssetLoader extends GSplatAssetLoaderBase {
69234
69242
  _currentlyLoading = /* @__PURE__ */ new Set();
69235
69243
  _loadQueue = [];
69236
69244
  _retryCount = /* @__PURE__ */ new Map();
69245
+ _failed = /* @__PURE__ */ new Set();
69237
69246
  _destroyed = false;
69238
69247
  constructor(registry) {
69239
69248
  super();
@@ -69252,12 +69261,16 @@ class GSplatAssetLoader extends GSplatAssetLoaderBase {
69252
69261
  this._loadQueue.length = 0;
69253
69262
  this._currentlyLoading.clear();
69254
69263
  this._retryCount.clear();
69264
+ this._failed.clear();
69255
69265
  }
69256
69266
  _canLoad() {
69257
69267
  return !!this._registry.loader?.getHandler("gsplat");
69258
69268
  }
69259
69269
  load(url) {
69260
69270
  const asset = this._urlToAsset.get(url);
69271
+ if (asset && asset.loaded && !asset.resource && !this._currentlyLoading.has(url) && !this._failed.has(url)) {
69272
+ asset.loaded = false;
69273
+ }
69261
69274
  if (asset?.loaded || this._currentlyLoading.has(url)) {
69262
69275
  return;
69263
69276
  }
@@ -69301,10 +69314,12 @@ class GSplatAssetLoader extends GSplatAssetLoaderBase {
69301
69314
  this._retryCount.set(url, retryCount + 1);
69302
69315
  asset.loaded = false;
69303
69316
  asset.loading = false;
69317
+ asset.once("error", (retryErr) => this._onAssetLoadError(url, asset, retryErr));
69304
69318
  this._registry.load(asset);
69305
69319
  } else {
69306
69320
  this._currentlyLoading.delete(url);
69307
69321
  this._retryCount.delete(url);
69322
+ this._failed.add(url);
69308
69323
  this._processQueue();
69309
69324
  }
69310
69325
  }
@@ -69326,6 +69341,7 @@ class GSplatAssetLoader extends GSplatAssetLoaderBase {
69326
69341
  this._loadQueue.splice(queueIndex, 1);
69327
69342
  }
69328
69343
  this._retryCount.delete(url);
69344
+ this._failed.delete(url);
69329
69345
  const asset = this._urlToAsset.get(url);
69330
69346
  if (asset) {
69331
69347
  asset.fire("unload", asset);
@@ -69341,6 +69357,9 @@ class GSplatAssetLoader extends GSplatAssetLoaderBase {
69341
69357
  const asset = this._urlToAsset.get(url);
69342
69358
  return asset?.resource;
69343
69359
  }
69360
+ hasFailed(url) {
69361
+ return this._failed.has(url);
69362
+ }
69344
69363
  }
69345
69364
 
69346
69365
  class GSplatOctreeParser {
@@ -81122,7 +81141,7 @@ const importSettings = (settings) => {
81122
81141
  return result;
81123
81142
  };
81124
81143
 
81125
- var version = "1.26.4";
81144
+ var version = "1.27.0";
81126
81145
 
81127
81146
  class Tooltip {
81128
81147
  register;
@@ -84432,6 +84451,210 @@ class CameraManager {
84432
84451
  }
84433
84452
  }
84434
84453
 
84454
+ // Box-average downsample of a supersampled render. Each output texel averages the
84455
+ // `uRatio` x `uRatio` block of source texels it covers — true NxN supersampling, which
84456
+ // keeps thin high-frequency features (splat strings, edges) smooth, unlike a
84457
+ // bilinear/compositor downscale which aliases them. `uFlipY` flips vertically because
84458
+ // render targets and readback disagree on row order.
84459
+ const boxDownsampleGLSL = /* glsl */ `
84460
+ varying vec2 vUv0;
84461
+
84462
+ uniform sampler2D source;
84463
+ uniform vec2 uSrcSize;
84464
+ uniform float uRatio;
84465
+ uniform float uFlipY;
84466
+
84467
+ void main(void) {
84468
+ int r = int(uRatio);
84469
+ vec2 outSize = uSrcSize / uRatio;
84470
+ vec2 uv = vUv0;
84471
+ if (uFlipY > 0.5) {
84472
+ uv.y = 1.0 - uv.y;
84473
+ }
84474
+ vec2 base = floor(uv * outSize) * uRatio;
84475
+ vec4 sum = vec4(0.0);
84476
+ for (int y = 0; y < 8; y++) {
84477
+ if (y >= r) break;
84478
+ for (int x = 0; x < 8; x++) {
84479
+ if (x >= r) break;
84480
+ vec2 texel = base + vec2(float(x) + 0.5, float(y) + 0.5);
84481
+ sum += texture2D(source, texel / uSrcSize);
84482
+ }
84483
+ }
84484
+ gl_FragColor = sum / (uRatio * uRatio);
84485
+ }
84486
+ `;
84487
+ // WGSL twin of the box downsample (WebGPU can't compile GLSL, so a custom fullscreen
84488
+ // shader must supply WGSL too — the built-in fullscreenQuadVS chunk covers the vertex).
84489
+ const boxDownsampleWGSL = /* wgsl */ `
84490
+ varying vUv0: vec2f;
84491
+ var source: texture_2d<f32>;
84492
+ var sourceSampler: sampler;
84493
+ uniform uSrcSize: vec2f;
84494
+ uniform uRatio: f32;
84495
+ uniform uFlipY: f32;
84496
+
84497
+ @fragment
84498
+ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
84499
+ var output: FragmentOutput;
84500
+ let r: i32 = i32(uniform.uRatio);
84501
+ let outSize: vec2f = uniform.uSrcSize / uniform.uRatio;
84502
+ var uv: vec2f = input.vUv0;
84503
+ if (uniform.uFlipY > 0.5) {
84504
+ uv.y = 1.0 - uv.y;
84505
+ }
84506
+ let base: vec2f = floor(uv * outSize) * uniform.uRatio;
84507
+ var sum: vec4f = vec4f(0.0);
84508
+ for (var y: i32 = 0; y < 8; y = y + 1) {
84509
+ if (y >= r) { break; }
84510
+ for (var x: i32 = 0; x < 8; x = x + 1) {
84511
+ if (x >= r) { break; }
84512
+ let texel: vec2f = base + vec2f(f32(x) + 0.5, f32(y) + 0.5);
84513
+ sum = sum + textureSample(source, sourceSampler, texel / uniform.uSrcSize);
84514
+ }
84515
+ }
84516
+ output.color = sum / (uniform.uRatio * uniform.uRatio);
84517
+ return output;
84518
+ }
84519
+ `;
84520
+ // Grabs downsampled snapshots of the viewer entirely on the GPU. The scene is rendered
84521
+ // (with post effects) into an app-owned render target at `supersample` x the requested
84522
+ // output size, box-downsampled to the output size, and only that small buffer is read
84523
+ // back. Rendering into our own target (rather than the backbuffer) means no
84524
+ // preserveDrawingBuffer, and it works on both WebGL and WebGPU.
84525
+ class Capture {
84526
+ app;
84527
+ device;
84528
+ camera;
84529
+ getCameraFrame;
84530
+ shader;
84531
+ srcRT = null;
84532
+ dstRT = null;
84533
+ constructor(app, camera, getCameraFrame) {
84534
+ this.app = app;
84535
+ this.device = app.graphicsDevice;
84536
+ this.camera = camera;
84537
+ this.getCameraFrame = getCameraFrame;
84538
+ this.shader = ShaderUtils.createShader(this.device, {
84539
+ uniqueName: 'captureBoxDownsample',
84540
+ attributes: { vertex_position: SEMANTIC_POSITION },
84541
+ vertexChunk: 'fullscreenQuadVS',
84542
+ fragmentGLSL: boxDownsampleGLSL,
84543
+ fragmentWGSL: boxDownsampleWGSL
84544
+ });
84545
+ }
84546
+ makeRT(name, width, height, depth) {
84547
+ // Plain RGBA8 (RGBA channel order, non-sRGB) so the box shader samples raw bytes
84548
+ // and the readback returns raw RGBA — no channel swap (WebGPU backbuffers are
84549
+ // often BGRA) and no sRGB decode/encode surprises; we average in the same gamma
84550
+ // space sharp did. We only mirror the backbuffer's sRGB *flag* (which the viewer
84551
+ // sets true only when post effects are active) — that drives the gamma the render
84552
+ // pipeline writes with, so our target receives identical bytes to the screen.
84553
+ const dev = this.device;
84554
+ const srgb = dev.backBuffer?.isColorBufferSrgb?.(0) ?? false;
84555
+ const colorBuffer = new Texture(this.device, {
84556
+ name,
84557
+ width,
84558
+ height,
84559
+ format: PIXELFORMAT_RGBA8,
84560
+ mipmaps: false,
84561
+ minFilter: FILTER_LINEAR,
84562
+ magFilter: FILTER_LINEAR,
84563
+ addressU: ADDRESS_CLAMP_TO_EDGE,
84564
+ addressV: ADDRESS_CLAMP_TO_EDGE
84565
+ });
84566
+ const rt = new RenderTarget({ name, colorBuffer, depth });
84567
+ rt.isColorBufferSrgb = () => srgb;
84568
+ return rt;
84569
+ }
84570
+ ensure(target, width, height, depth) {
84571
+ const existing = this[target];
84572
+ if (existing && existing.width === width && existing.height === height) {
84573
+ return existing;
84574
+ }
84575
+ existing?.colorBuffer.destroy();
84576
+ existing?.destroy();
84577
+ const rt = this.makeRT(target, width, height, depth);
84578
+ this[target] = rt;
84579
+ return rt;
84580
+ }
84581
+ // Point the camera at `renderTarget` and re-target CameraFrame's compose pass. Post
84582
+ // effects bind their output inside setupRenderPasses, which only re-runs on a reset,
84583
+ // so a plain renderTarget change doesn't take effect — force a reset via layersDirty,
84584
+ // otherwise the composited frame keeps going to the old target (reads back black).
84585
+ setCameraTarget(renderTarget) {
84586
+ this.camera.renderTarget = renderTarget;
84587
+ const cameraFrame = this.getCameraFrame();
84588
+ if (cameraFrame) {
84589
+ const rpc = cameraFrame.renderPassCamera;
84590
+ if (rpc) {
84591
+ rpc.layersDirty = true;
84592
+ }
84593
+ cameraFrame.update();
84594
+ }
84595
+ }
84596
+ async grab({ time, width, height, supersample = 2, scrub }) {
84597
+ const device = this.device;
84598
+ // clamp to the box shaders' 8x8 sample cap: a larger ratio would sum at most 64
84599
+ // texels yet still divide by ss*ss, producing an under-exposed (too dark) frame.
84600
+ const ss = Math.min(8, Math.max(1, Math.round(supersample)));
84601
+ // normalize the output size to positive integers so texture/RT creation and
84602
+ // readback don't fail confusingly on 0/negative/non-integer input
84603
+ const outW = Math.max(1, Math.round(width));
84604
+ const outH = Math.max(1, Math.round(height));
84605
+ const srcW = outW * ss;
84606
+ const srcH = outH * ss;
84607
+ // render the scene (incl. post effects) into our own supersampled target
84608
+ const srcRT = this.ensure('srcRT', srcW, srcH, true);
84609
+ // Redirect the camera into our offscreen target for the capture, then restore it.
84610
+ // window.captureFrame is a global API, so leaving the camera pointed at our target
84611
+ // would freeze on-screen rendering after the first call.
84612
+ const camera = this.camera;
84613
+ const saved = {
84614
+ renderTarget: camera.renderTarget,
84615
+ aspectRatioMode: camera.aspectRatioMode,
84616
+ aspectRatio: camera.aspectRatio,
84617
+ horizontalFov: camera.horizontalFov
84618
+ };
84619
+ try {
84620
+ camera.aspectRatioMode = ASPECT_AUTO; // aspect follows the target dims
84621
+ camera.horizontalFov = srcW >= srcH;
84622
+ this.setCameraTarget(srcRT);
84623
+ if (time !== undefined && scrub) {
84624
+ scrub(time);
84625
+ }
84626
+ this.app.renderNextFrame = true;
84627
+ await new Promise((resolve) => {
84628
+ this.app.once('frameend', () => resolve());
84629
+ });
84630
+ // box-downsample the supersampled render to the output size
84631
+ const dstRT = this.ensure('dstRT', outW, outH, false);
84632
+ const { scope } = device;
84633
+ scope.resolve('source').setValue(srcRT.colorBuffer);
84634
+ scope.resolve('uSrcSize').setValue([srcW, srcH]);
84635
+ scope.resolve('uRatio').setValue(ss);
84636
+ scope.resolve('uFlipY').setValue(srcRT.flipY ? 0 : 1);
84637
+ device.setBlendState(BlendState.NOBLEND);
84638
+ drawQuadWithShader(device, dstRT, this.shader);
84639
+ const pixels = await dstRT.colorBuffer.read(0, 0, outW, outH, { renderTarget: dstRT, immediate: true });
84640
+ const u8 = pixels instanceof Uint8Array ? pixels : new Uint8Array(pixels.buffer);
84641
+ const chunks = [];
84642
+ const chunk = 0x8000;
84643
+ for (let i = 0; i < u8.length; i += chunk) {
84644
+ chunks.push(String.fromCharCode.apply(null, u8.subarray(i, i + chunk)));
84645
+ }
84646
+ return { width: outW, height: outH, data: btoa(chunks.join('')) };
84647
+ }
84648
+ finally {
84649
+ camera.aspectRatioMode = saved.aspectRatioMode;
84650
+ camera.aspectRatio = saved.aspectRatio;
84651
+ camera.horizontalFov = saved.horizontalFov;
84652
+ this.setCameraTarget(saved.renderTarget);
84653
+ this.app.renderNextFrame = true;
84654
+ }
84655
+ }
84656
+ }
84657
+
84435
84658
  const captureCameraState = (cm, state) => ({
84436
84659
  position: [cm.camera.position.x, cm.camera.position.y, cm.camera.position.z],
84437
84660
  angles: [cm.camera.angles.x, cm.camera.angles.y, cm.camera.angles.z],
@@ -88086,6 +88309,37 @@ class Viewer {
88086
88309
  });
88087
88310
  };
88088
88311
  window.animationDuration = state.animationDuration;
88312
+ // Capture hook for the thumbnail pipeline. Renders the scene (with post
88313
+ // effects) into an offscreen supersampled target, GPU box-downsamples it to
88314
+ // the requested size and returns just that small buffer. Lazily created on
88315
+ // first use — no ?capture flag and no preserveDrawingBuffer needed, and it
88316
+ // works on both WebGL and WebGPU.
88317
+ let capture = null;
88318
+ let captureQueue = Promise.resolve();
88319
+ window.captureFrame = ({ time, width = 480, height = width, supersample } = {}) => {
88320
+ const run = () => {
88321
+ if (!capture) {
88322
+ capture = new Capture(app, camera.camera, () => this.cameraFrame ?? null);
88323
+ }
88324
+ return capture.grab({
88325
+ time,
88326
+ width,
88327
+ height,
88328
+ supersample,
88329
+ scrub: (t) => {
88330
+ if (state.hasAnimation) {
88331
+ state.animationPaused = true;
88332
+ events.fire('scrubAnim', t);
88333
+ }
88334
+ }
88335
+ });
88336
+ };
88337
+ // serialize calls: they share the viewer camera, so concurrent captures
88338
+ // would interleave the redirect/restore and could leave it mis-targeted
88339
+ const result = captureQueue.then(run, run);
88340
+ captureQueue = result.then(() => { }, () => { });
88341
+ return result;
88342
+ };
88089
88343
  });
88090
88344
  // wait for the model to load
88091
88345
  Promise.all([gsplatLoad, skyboxLoad, collisionLoad]).then((results) => {