@playcanvas/supersplat-viewer 1.23.1 → 1.24.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.23.1",
3
+ "version": "1.24.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.html CHANGED
@@ -43,6 +43,7 @@
43
43
  budget,
44
44
  heatmap: url.searchParams.has('heatmap'),
45
45
  fullload: url.searchParams.has('fullload'),
46
+ debug: url.searchParams.has('debug'),
46
47
  };
47
48
 
48
49
  window.sse = {
package/public/index.js CHANGED
@@ -77723,7 +77723,7 @@ const importSettings = (settings) => {
77723
77723
  return result;
77724
77724
  };
77725
77725
 
77726
- var version = "1.23.1";
77726
+ var version = "1.24.0";
77727
77727
 
77728
77728
  class Tooltip {
77729
77729
  register;
@@ -80590,6 +80590,11 @@ const createFrameCamera = (bbox, fov) => {
80590
80590
  };
80591
80591
  class CameraManager {
80592
80592
  update;
80593
+ // Re-seed the active controller from the current camera pose and
80594
+ // cancel any in-progress transition lerp. Use after externally
80595
+ // mutating `camera` and/or `state.cameraMode` to make the change
80596
+ // visible instantly.
80597
+ snap;
80593
80598
  // holds the camera state
80594
80599
  camera = new Camera();
80595
80600
  constructor(global, bbox, collision = null) {
@@ -80665,6 +80670,12 @@ class CameraManager {
80665
80670
  from.copy(this.camera);
80666
80671
  transitionTimer = 0;
80667
80672
  };
80673
+ this.snap = () => {
80674
+ getController(state.cameraMode).onEnter(this.camera);
80675
+ target.copy(this.camera);
80676
+ transitionTimer = 1;
80677
+ global.app.renderNextFrame = true;
80678
+ };
80668
80679
  // application update
80669
80680
  this.update = (deltaTime, frame) => {
80670
80681
  // use dt of 0 if animation is paused
@@ -80823,6 +80834,363 @@ class CameraManager {
80823
80834
  }
80824
80835
  }
80825
80836
 
80837
+ const captureCameraState = (cm, state) => ({
80838
+ position: [cm.camera.position.x, cm.camera.position.y, cm.camera.position.z],
80839
+ angles: [cm.camera.angles.x, cm.camera.angles.y, cm.camera.angles.z],
80840
+ distance: cm.camera.distance,
80841
+ fov: cm.camera.fov,
80842
+ mode: state.cameraMode
80843
+ });
80844
+ const restoreCameraState = (cm, state, snapshot) => {
80845
+ cm.camera.position.set(snapshot.position[0], snapshot.position[1], snapshot.position[2]);
80846
+ cm.camera.angles.set(snapshot.angles[0], snapshot.angles[1], snapshot.angles[2]);
80847
+ cm.camera.distance = snapshot.distance;
80848
+ cm.camera.fov = snapshot.fov;
80849
+ // Mode change (if any) fires cameraMode:changed which runs the new
80850
+ // controller's onEnter against our just-set pose; snap() then cancels
80851
+ // the resulting transition lerp. Same-mode case: snap() re-seeds the
80852
+ // active controller in place.
80853
+ if (state.cameraMode !== snapshot.mode) {
80854
+ state.cameraMode = snapshot.mode;
80855
+ }
80856
+ cm.snap();
80857
+ };
80858
+
80859
+ // Developer / debug panel. Hidden by default; surfaced via `?debug` URL
80860
+ // param or Ctrl+Shift+D keyboard shortcut. DOM and styles are injected
80861
+ // lazily on first show so there's no footprint on production URLs.
80862
+ const STYLE_ID = 'sse-debug-panel-style';
80863
+ const PANEL_ID = 'sse-debug-panel';
80864
+ const STYLES = `
80865
+ #${PANEL_ID} {
80866
+ position: fixed;
80867
+ top: max(8px, env(safe-area-inset-top));
80868
+ left: max(8px, env(safe-area-inset-left));
80869
+ padding: 8px 10px;
80870
+ background: rgba(0, 0, 0, 0.7);
80871
+ color: #eee;
80872
+ font: 11px/1.4 ui-monospace, Menlo, Consolas, monospace;
80873
+ border: 1px solid rgba(255, 255, 255, 0.1);
80874
+ border-radius: 4px;
80875
+ z-index: 1000;
80876
+ pointer-events: auto;
80877
+ user-select: none;
80878
+ min-width: 220px;
80879
+ }
80880
+ #${PANEL_ID} .row {
80881
+ display: flex;
80882
+ justify-content: space-between;
80883
+ gap: 12px;
80884
+ white-space: nowrap;
80885
+ }
80886
+ #${PANEL_ID} .row .label {
80887
+ color: #888;
80888
+ }
80889
+ #${PANEL_ID} .row .value {
80890
+ color: #eee;
80891
+ font-variant-numeric: tabular-nums;
80892
+ cursor: text;
80893
+ padding: 0 4px;
80894
+ margin: 0 -4px;
80895
+ border-radius: 2px;
80896
+ transition: background-color 0.15s ease;
80897
+ outline: none;
80898
+ }
80899
+ #${PANEL_ID} .row .value:hover {
80900
+ background: rgba(255, 255, 255, 0.08);
80901
+ }
80902
+ #${PANEL_ID} .row .value:focus {
80903
+ background: rgba(255, 255, 255, 0.12);
80904
+ box-shadow: inset 0 0 0 1px rgba(120, 180, 255, 0.45);
80905
+ }
80906
+ #${PANEL_ID} .row .value.flash-ok {
80907
+ background: rgba(120, 220, 140, 0.35);
80908
+ }
80909
+ #${PANEL_ID} .row .value.flash-bad {
80910
+ background: rgba(220, 100, 100, 0.45);
80911
+ }
80912
+ #${PANEL_ID} .buttons {
80913
+ display: flex;
80914
+ gap: 6px;
80915
+ margin-top: 6px;
80916
+ }
80917
+ #${PANEL_ID} button {
80918
+ flex: 1;
80919
+ background: rgba(255, 255, 255, 0.08);
80920
+ color: #eee;
80921
+ border: 1px solid rgba(255, 255, 255, 0.12);
80922
+ border-radius: 3px;
80923
+ padding: 4px 8px;
80924
+ font: inherit;
80925
+ cursor: pointer;
80926
+ transition: background-color 0.15s ease;
80927
+ }
80928
+ #${PANEL_ID} button:hover {
80929
+ background: rgba(255, 255, 255, 0.16);
80930
+ }
80931
+ #${PANEL_ID} button.flash {
80932
+ background: rgba(120, 220, 140, 0.35);
80933
+ }
80934
+ `;
80935
+ const fmt = (v) => `${v.x.toFixed(3)}, ${v.y.toFixed(3)}, ${v.z.toFixed(3)}`;
80936
+ // Accepts "1,2,3", "1, 2, 3", "1 2 3", with or without trailing whitespace.
80937
+ const parseVector = (text) => {
80938
+ const parts = text.trim().split(/[\s,]+/).filter(p => p.length > 0);
80939
+ if (parts.length !== 3)
80940
+ return null;
80941
+ const nums = parts.map(Number);
80942
+ if (nums.some(n => !Number.isFinite(n)))
80943
+ return null;
80944
+ return [nums[0], nums[1], nums[2]];
80945
+ };
80946
+ class DebugPanel {
80947
+ _global;
80948
+ _cameraManager;
80949
+ _focusTmp = new Vec3();
80950
+ _root = null;
80951
+ _positionValue = null;
80952
+ _focusValue = null;
80953
+ _copyButton = null;
80954
+ _pasteButton = null;
80955
+ _screenshotButton = null;
80956
+ _editing = null;
80957
+ _editCanceled = false;
80958
+ _visible = false;
80959
+ _onPrerender = () => this._render();
80960
+ _onKeyDown = (event) => {
80961
+ // Ctrl+Shift+D — also accept Meta+Shift+D on macOS for parity
80962
+ if (event.code === 'KeyD' && event.shiftKey && (event.ctrlKey || event.metaKey)) {
80963
+ event.preventDefault();
80964
+ this.toggle();
80965
+ }
80966
+ };
80967
+ constructor(global, cameraManager) {
80968
+ this._global = global;
80969
+ this._cameraManager = cameraManager;
80970
+ window.addEventListener('keydown', this._onKeyDown);
80971
+ if (global.config.debug) {
80972
+ this.show();
80973
+ }
80974
+ }
80975
+ show() {
80976
+ if (this._visible)
80977
+ return;
80978
+ this._visible = true;
80979
+ if (!this._root) {
80980
+ this._build();
80981
+ }
80982
+ this._root.style.display = '';
80983
+ this._global.app.on('prerender', this._onPrerender);
80984
+ window.getCameraState = () => captureCameraState(this._cameraManager, this._global.state);
80985
+ window.setCameraState = snapshot => restoreCameraState(this._cameraManager, this._global.state, snapshot);
80986
+ this._render();
80987
+ }
80988
+ hide() {
80989
+ if (!this._visible)
80990
+ return;
80991
+ this._visible = false;
80992
+ if (this._root) {
80993
+ this._root.style.display = 'none';
80994
+ }
80995
+ this._global.app.off('prerender', this._onPrerender);
80996
+ delete window.getCameraState;
80997
+ delete window.setCameraState;
80998
+ }
80999
+ toggle() {
81000
+ if (this._visible)
81001
+ this.hide();
81002
+ else
81003
+ this.show();
81004
+ }
81005
+ destroy() {
81006
+ this.hide();
81007
+ window.removeEventListener('keydown', this._onKeyDown);
81008
+ if (this._root) {
81009
+ this._root.remove();
81010
+ this._root = null;
81011
+ }
81012
+ document.getElementById(STYLE_ID)?.remove();
81013
+ }
81014
+ _build() {
81015
+ if (!document.getElementById(STYLE_ID)) {
81016
+ const style = document.createElement('style');
81017
+ style.id = STYLE_ID;
81018
+ style.textContent = STYLES;
81019
+ document.head.appendChild(style);
81020
+ }
81021
+ const root = document.createElement('div');
81022
+ root.id = PANEL_ID;
81023
+ root.innerHTML = `
81024
+ <div class="row"><span class="label">camera</span><span class="value" data-id="position" contenteditable="plaintext-only" spellcheck="false" title="Edit to set camera position">—</span></div>
81025
+ <div class="row"><span class="label">focus</span><span class="value" data-id="focus" contenteditable="plaintext-only" spellcheck="false" title="Edit to look at this point">—</span></div>
81026
+ <div class="buttons">
81027
+ <button data-id="copy">Copy</button>
81028
+ <button data-id="paste">Paste</button>
81029
+ </div>
81030
+ <div class="buttons">
81031
+ <button data-id="screenshot">Screenshot</button>
81032
+ </div>
81033
+ `;
81034
+ document.body.appendChild(root);
81035
+ this._root = root;
81036
+ this._positionValue = root.querySelector('[data-id="position"]');
81037
+ this._focusValue = root.querySelector('[data-id="focus"]');
81038
+ this._copyButton = root.querySelector('[data-id="copy"]');
81039
+ this._pasteButton = root.querySelector('[data-id="paste"]');
81040
+ this._screenshotButton = root.querySelector('[data-id="screenshot"]');
81041
+ this._copyButton.addEventListener('click', () => this._copy());
81042
+ this._pasteButton.addEventListener('click', () => this._paste());
81043
+ this._screenshotButton.addEventListener('click', () => this._screenshot());
81044
+ this._wireEditable(this._positionValue, 'position');
81045
+ this._wireEditable(this._focusValue, 'focus');
81046
+ }
81047
+ _wireEditable(span, kind) {
81048
+ span.addEventListener('focus', () => {
81049
+ this._editing = span;
81050
+ this._editCanceled = false;
81051
+ // select all text so the user can start typing to replace
81052
+ const range = document.createRange();
81053
+ range.selectNodeContents(span);
81054
+ const sel = window.getSelection();
81055
+ sel?.removeAllRanges();
81056
+ sel?.addRange(range);
81057
+ });
81058
+ // Stop key events from bubbling to the canvas / window listeners
81059
+ // (PlayCanvas KeyboardMouseSource and the wheel/key interrupt
81060
+ // listeners) so arrow keys, WASD, etc. behave as text editing
81061
+ // instead of moving the camera.
81062
+ const stopKey = (e) => e.stopPropagation();
81063
+ span.addEventListener('keydown', (e) => {
81064
+ stopKey(e);
81065
+ if (e.key === 'Enter') {
81066
+ e.preventDefault();
81067
+ span.blur();
81068
+ }
81069
+ else if (e.key === 'Escape') {
81070
+ e.preventDefault();
81071
+ this._editCanceled = true;
81072
+ span.blur();
81073
+ }
81074
+ });
81075
+ span.addEventListener('keyup', stopKey);
81076
+ span.addEventListener('keypress', stopKey);
81077
+ span.addEventListener('blur', () => {
81078
+ const wasCanceled = this._editCanceled;
81079
+ this._editing = null;
81080
+ this._editCanceled = false;
81081
+ // clear any leftover selection
81082
+ window.getSelection()?.removeAllRanges();
81083
+ if (wasCanceled) {
81084
+ this._render();
81085
+ return;
81086
+ }
81087
+ const parsed = parseVector(span.textContent ?? '');
81088
+ if (!parsed) {
81089
+ this._flashBad(span);
81090
+ this._render();
81091
+ return;
81092
+ }
81093
+ if (kind === 'position') {
81094
+ this._applyPosition(parsed);
81095
+ }
81096
+ else {
81097
+ this._applyFocus(parsed);
81098
+ }
81099
+ this._flashOk(span);
81100
+ });
81101
+ }
81102
+ _applyPosition(pos) {
81103
+ this._cameraManager.camera.position.set(pos[0], pos[1], pos[2]);
81104
+ this._cameraManager.snap();
81105
+ }
81106
+ _applyFocus(focus) {
81107
+ // Keep camera position fixed; recompute angles + distance so the
81108
+ // camera looks at the new focus point. Camera.look() does the math
81109
+ // in place; snap() then re-seeds the active controller.
81110
+ const cam = this._cameraManager.camera;
81111
+ const from = this._focusTmp.copy(cam.position);
81112
+ const to = new Vec3(focus[0], focus[1], focus[2]);
81113
+ cam.look(from, to);
81114
+ this._cameraManager.snap();
81115
+ }
81116
+ _render() {
81117
+ if (!this._visible || !this._positionValue || !this._focusValue)
81118
+ return;
81119
+ const cam = this._cameraManager.camera;
81120
+ cam.calcFocusPoint(this._focusTmp);
81121
+ // Skip the span currently being edited so user input isn't
81122
+ // overwritten by the per-frame refresh.
81123
+ if (this._editing !== this._positionValue) {
81124
+ this._positionValue.textContent = fmt(cam.position);
81125
+ }
81126
+ if (this._editing !== this._focusValue) {
81127
+ this._focusValue.textContent = fmt(this._focusTmp);
81128
+ }
81129
+ }
81130
+ async _copy() {
81131
+ const snapshot = captureCameraState(this._cameraManager, this._global.state);
81132
+ try {
81133
+ await navigator.clipboard.writeText(JSON.stringify(snapshot));
81134
+ this._flash(this._copyButton);
81135
+ }
81136
+ catch (err) {
81137
+ console.warn('[debug-panel] copy failed', err);
81138
+ }
81139
+ }
81140
+ async _paste() {
81141
+ try {
81142
+ const text = await navigator.clipboard.readText();
81143
+ const snapshot = JSON.parse(text);
81144
+ restoreCameraState(this._cameraManager, this._global.state, snapshot);
81145
+ this._flash(this._pasteButton);
81146
+ }
81147
+ catch (err) {
81148
+ console.warn('[debug-panel] paste failed', err);
81149
+ }
81150
+ }
81151
+ _screenshot() {
81152
+ const app = this._global.app;
81153
+ const canvas = app.graphicsDevice.canvas;
81154
+ // PlayCanvas runs with preserveDrawingBuffer off, so the canvas
81155
+ // pixels are only readable in the same task as the render. Force
81156
+ // a render and capture in frameend.
81157
+ app.renderNextFrame = true;
81158
+ app.once('frameend', () => {
81159
+ // Quality 1.0 with image/webp produces lossless WebP in
81160
+ // Chromium / Firefox. Safari (which lacks WebP encode) falls
81161
+ // back to PNG automatically — blob.type tells us which.
81162
+ canvas.toBlob((blob) => {
81163
+ if (!blob) {
81164
+ console.warn('[debug-panel] screenshot toBlob returned null');
81165
+ return;
81166
+ }
81167
+ const ext = blob.type === 'image/webp' ? 'webp' : 'png';
81168
+ const url = URL.createObjectURL(blob);
81169
+ const a = document.createElement('a');
81170
+ a.href = url;
81171
+ a.download = `supersplat-viewer.${ext}`;
81172
+ a.click();
81173
+ URL.revokeObjectURL(url);
81174
+ this._flash(this._screenshotButton);
81175
+ }, 'image/webp', 1.0);
81176
+ });
81177
+ }
81178
+ _flash(el) {
81179
+ if (!el)
81180
+ return;
81181
+ el.classList.add('flash');
81182
+ setTimeout(() => el.classList.remove('flash'), 250);
81183
+ }
81184
+ _flashOk(el) {
81185
+ el.classList.add('flash-ok');
81186
+ setTimeout(() => el.classList.remove('flash-ok'), 250);
81187
+ }
81188
+ _flashBad(el) {
81189
+ el.classList.add('flash-bad');
81190
+ setTimeout(() => el.classList.remove('flash-bad'), 400);
81191
+ }
81192
+ }
81193
+
80826
81194
  /**
80827
81195
  * Watches global pointer events and updates `state.inputMode` to reflect
80828
81196
  * whether the user is on a touch device or desktop.
@@ -83993,6 +84361,7 @@ class Viewer {
83993
84361
  voxelOverlay = null;
83994
84362
  meshOverlay = null;
83995
84363
  navCursor = null;
84364
+ debugPanel = null;
83996
84365
  origChunks;
83997
84366
  constructor(global, gsplatLoad, skyboxLoad, collisionLoad) {
83998
84367
  this.global = global;
@@ -84168,6 +84537,7 @@ class Viewer {
84168
84537
  if (!config.noui) {
84169
84538
  this.navCursor = new NavCursor(app, camera, collision ?? null, events, state);
84170
84539
  }
84540
+ this.debugPanel = new DebugPanel(global, this.cameraManager);
84171
84541
  const { instance } = gsplat;
84172
84542
  if (instance) {
84173
84543
  // kick off gsplat sorting immediately now that camera is in position