@playcanvas/supersplat-viewer 1.8.3 → 1.8.4

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.3",
3
+ "version": "1.8.4",
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",
@@ -47,14 +47,14 @@
47
47
  "concurrently": "9.2.1",
48
48
  "eslint": "9.39.1",
49
49
  "globals": "16.5.0",
50
- "playcanvas": "2.13.2",
50
+ "playcanvas": "2.13.5",
51
51
  "postcss": "8.5.6",
52
52
  "publint": "0.3.15",
53
- "rollup": "4.53.2",
53
+ "rollup": "4.53.3",
54
54
  "rollup-plugin-copy": "3.5.0",
55
55
  "rollup-plugin-scss": "4.0.1",
56
56
  "rollup-plugin-string": "3.0.0",
57
- "sass": "1.94.1",
57
+ "sass": "1.94.2",
58
58
  "serve": "14.2.5",
59
59
  "typescript": "5.9.3"
60
60
  },
package/public/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const TRACEID_GPU_TIMINGS = 'GpuTimings';
2
2
 
3
- const version = '2.13.2';
4
- const revision = '8620544';
3
+ const version = '2.13.5';
4
+ const revision = '5aa2502';
5
5
  function extend(target, ex) {
6
6
  for(const prop in ex){
7
7
  const copy = ex[prop];
@@ -3608,13 +3608,18 @@ class BoundingBox {
3608
3608
  return this._max.copy(this.center).add(this.halfExtents);
3609
3609
  }
3610
3610
  containsPoint(point) {
3611
- const min = this.getMin();
3612
- const max = this.getMax();
3613
- if (point.x < min.x || point.x > max.x || point.y < min.y || point.y > max.y || point.z < min.z || point.z > max.z) {
3611
+ const c = this.center;
3612
+ const h = this.halfExtents;
3613
+ if (point.x < c.x - h.x || point.x > c.x + h.x || point.y < c.y - h.y || point.y > c.y + h.y || point.z < c.z - h.z || point.z > c.z + h.z) {
3614
3614
  return false;
3615
3615
  }
3616
3616
  return true;
3617
3617
  }
3618
+ closestPoint(point, result = new Vec3()) {
3619
+ const c = this.center;
3620
+ const h = this.halfExtents;
3621
+ return result.set(Math.max(c.x - h.x, Math.min(point.x, c.x + h.x)), Math.max(c.y - h.y, Math.min(point.y, c.y + h.y)), Math.max(c.z - h.z, Math.min(point.z, c.z + h.z)));
3622
+ }
3618
3623
  setFromTransformedAabb(aabb, m, ignoreScale = false) {
3619
3624
  const ac = aabb.center;
3620
3625
  const ar = aabb.halfExtents;
@@ -13168,10 +13173,12 @@ class WebglUploadStream {
13168
13173
  gl.bufferSubData(gl.PIXEL_UNPACK_BUFFER, 0, new Uint8Array(data.buffer, data.byteOffset, byteSize));
13169
13174
  gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, null);
13170
13175
  device.setTexture(target, 0);
13176
+ device.activeTexture(0);
13177
+ device.bindTexture(target);
13171
13178
  gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, pboInfo.pbo);
13172
13179
  device.setUnpackFlipY(false);
13173
13180
  device.setUnpackPremultiplyAlpha(false);
13174
- gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
13181
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, data.BYTES_PER_ELEMENT);
13175
13182
  gl.pixelStorei(gl.UNPACK_ROW_LENGTH, 0);
13176
13183
  gl.pixelStorei(gl.UNPACK_SKIP_ROWS, 0);
13177
13184
  gl.pixelStorei(gl.UNPACK_SKIP_PIXELS, 0);
@@ -76255,7 +76262,8 @@ class GSplatOctreeInstance {
76255
76262
  }
76256
76263
  calculateNodeLod(localCameraPosition, localCameraForward, nodeIndex, maxLod, lodDistances, lodBehindPenalty) {
76257
76264
  const node = this.octree.nodes[nodeIndex];
76258
- _dirToNode.copy(node.bounds.center).sub(localCameraPosition);
76265
+ node.bounds.closestPoint(localCameraPosition, _dirToNode);
76266
+ _dirToNode.sub(localCameraPosition);
76259
76267
  let distance = _dirToNode.length();
76260
76268
  if (lodBehindPenalty > 1 && distance > 0.01) {
76261
76269
  const dotOverDistance = localCameraForward.dot(_dirToNode) / distance;
@@ -77082,6 +77090,7 @@ class GSplatManager {
77082
77090
  }
77083
77091
  update() {
77084
77092
  this.sorter.applyPendingSorted();
77093
+ this.renderer.updateViewport(this.cameraNode);
77085
77094
  let fullUpdate = false;
77086
77095
  this.framesTillFullUpdate--;
77087
77096
  if (this.framesTillFullUpdate <= 0) {
@@ -77221,7 +77230,6 @@ class GSplatManager {
77221
77230
  });
77222
77231
  });
77223
77232
  this.sorter.setSortParams(sorterRequest, this.scene.gsplat.radialSorting);
77224
- this.renderer.updateViewport(cameraNode);
77225
77233
  }
77226
77234
  prepareSortParameters(worldState) {
77227
77235
  return {
@@ -101187,8 +101195,16 @@ class Picker {
101187
101195
  }
101188
101196
  }
101189
101197
 
101198
+ /* Vec initialisation to avoid recurrent memory allocation */
101190
101199
  const tmpV1 = new Vec3();
101191
101200
  const tmpV2 = new Vec3();
101201
+ const mouseRotate = new Vec3();
101202
+ const flyMove = new Vec3();
101203
+ const pinchMove = new Vec3();
101204
+ const orbitRotate = new Vec3();
101205
+ const flyRotate = new Vec3();
101206
+ const stickMove = new Vec3();
101207
+ const stickRotate = new Vec3();
101192
101208
  /**
101193
101209
  * Converts screen space mouse deltas to world space pan vector.
101194
101210
  *
@@ -101374,33 +101390,33 @@ class InputController {
101374
101390
  deltas.move.append([v.x, v.y, orbit ? -v.z : v.z]);
101375
101391
  // desktop rotate
101376
101392
  v.set(0, 0, 0);
101377
- const mouseRotate = new Vec3(mouse[0], mouse[1], 0);
101393
+ mouseRotate.set(mouse[0], mouse[1], 0);
101378
101394
  v.add(mouseRotate.mulScalar((1 - pan) * this.orbitSpeed * orbitFactor * dt));
101379
101395
  deltas.rotate.append([v.x, v.y, v.z]);
101380
101396
  // mobile move
101381
101397
  v.set(0, 0, 0);
101382
101398
  const orbitMove = screenToWorld(camera, touch[0], touch[1], distance);
101383
101399
  v.add(orbitMove.mulScalar(orbit * pan));
101384
- const flyMove = new Vec3(leftInput[0], 0, -leftInput[1]);
101400
+ flyMove.set(leftInput[0], 0, -leftInput[1]);
101385
101401
  v.add(flyMove.mulScalar(fly * this.moveSpeed * dt));
101386
- const pinchMove = new Vec3(0, 0, pinch[0]);
101402
+ pinchMove.set(0, 0, pinch[0]);
101387
101403
  v.add(pinchMove.mulScalar(orbit * double * this.pinchSpeed * dt));
101388
101404
  deltas.move.append([v.x, v.y, v.z]);
101389
101405
  // mobile rotate
101390
101406
  v.set(0, 0, 0);
101391
- const orbitRotate = new Vec3(touch[0], touch[1], 0);
101407
+ orbitRotate.set(touch[0], touch[1], 0);
101392
101408
  v.add(orbitRotate.mulScalar(orbit * (1 - pan) * this.orbitSpeed * dt));
101393
- const flyRotate = new Vec3(rightInput[0], rightInput[1], 0);
101409
+ flyRotate.set(rightInput[0], rightInput[1], 0);
101394
101410
  v.add(flyRotate.mulScalar(fly * this.orbitSpeed * orbitFactor * dt));
101395
101411
  deltas.rotate.append([v.x, v.y, v.z]);
101396
101412
  // gamepad move
101397
101413
  v.set(0, 0, 0);
101398
- const stickMove = new Vec3(leftStick[0], 0, -leftStick[1]);
101414
+ stickMove.set(leftStick[0], 0, -leftStick[1]);
101399
101415
  v.add(stickMove.mulScalar(this.moveSpeed * dt));
101400
101416
  deltas.move.append([v.x, v.y, v.z]);
101401
101417
  // gamepad rotate
101402
101418
  v.set(0, 0, 0);
101403
- const stickRotate = new Vec3(rightStick[0], rightStick[1], 0);
101419
+ stickRotate.set(rightStick[0], rightStick[1], 0);
101404
101420
  v.add(stickRotate.mulScalar(this.orbitSpeed * orbitFactor * dt));
101405
101421
  deltas.rotate.append([v.x, v.y, v.z]);
101406
101422
  // update touch joystick UI
@@ -101502,6 +101518,7 @@ class Viewer {
101502
101518
  inputController;
101503
101519
  cameraManager;
101504
101520
  annotations;
101521
+ forceRenderNextFrame = false;
101505
101522
  constructor(global, gsplatLoad, skyboxLoad) {
101506
101523
  this.global = global;
101507
101524
  const { app, settings, config, events, state, camera } = global;
@@ -101572,6 +101589,9 @@ class Viewer {
101572
101589
  if (!state.readyToRender) {
101573
101590
  app.renderNextFrame = false;
101574
101591
  }
101592
+ if (this.forceRenderNextFrame) {
101593
+ app.renderNextFrame = true;
101594
+ }
101575
101595
  if (app.renderNextFrame) {
101576
101596
  prevWorld.copy(world);
101577
101597
  prevProj.copy(proj);
@@ -101615,7 +101635,9 @@ class Viewer {
101615
101635
  if (gsplatBbox) {
101616
101636
  sceneBound.setFromTransformedAabb(gsplatBbox, results[0].getWorldTransform());
101617
101637
  }
101618
- this.annotations = new Annotations(global, this.cameraFrame != null);
101638
+ if (!config.noui) {
101639
+ this.annotations = new Annotations(global, this.cameraFrame != null);
101640
+ }
101619
101641
  this.inputController = new InputController(global);
101620
101642
  this.cameraManager = new CameraManager(global, sceneBound);
101621
101643
  applyCamera(this.cameraManager.camera);
@@ -101640,11 +101662,36 @@ class Viewer {
101640
101662
  });
101641
101663
  }
101642
101664
  else {
101643
- // FIXME: unified doesn't have a sorter, need to add a "ready" event for this case
101644
- // till then screenshots will likely not work correctly.
101645
- state.readyToRender = true;
101646
- events.fire('firstFrame');
101647
- window.firstFrame?.();
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
+ 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
101672
+ const eventHandler = app.systems.gsplat;
101673
+ // force render empty frames otherwise unified rendering doesn't update
101674
+ this.forceRenderNextFrame = true;
101675
+ const readyHandler = (camera, layer, ready, loading) => {
101676
+ if (ready && !loading) {
101677
+ eventHandler.off('frame:ready', readyHandler);
101678
+ this.forceRenderNextFrame = false;
101679
+ state.readyToRender = true;
101680
+ // wait for the first valid frame to complete rendering
101681
+ app.once('frameend', () => {
101682
+ events.fire('firstFrame');
101683
+ // emit first frame event on window
101684
+ window.firstFrame?.();
101685
+ });
101686
+ }
101687
+ };
101688
+ eventHandler.on('frame:ready', readyHandler);
101689
+ // render when ready is set
101690
+ eventHandler.on('frame:ready', (camera, layer, ready, loading) => {
101691
+ if (ready) {
101692
+ app.renderNextFrame = true;
101693
+ }
101694
+ });
101648
101695
  }
101649
101696
  });
101650
101697
  }