@playcanvas/supersplat-viewer 1.12.3 → 1.13.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/public/index.js CHANGED
@@ -102409,10 +102409,63 @@ const initJoystick = (dom, events, state) => {
102409
102409
  dom.joystickBase.addEventListener('pointerup', endJoystickTouch);
102410
102410
  dom.joystickBase.addEventListener('pointercancel', endJoystickTouch);
102411
102411
  };
102412
+ // Initialize the annotation navigator for stepping between annotations
102413
+ const initAnnotationNav = (dom, events, state, annotations) => {
102414
+ // Only show navigator when there are at least 2 annotations
102415
+ if (annotations.length < 2)
102416
+ return;
102417
+ let currentIndex = 0;
102418
+ const updateDisplay = () => {
102419
+ dom.annotationNavTitle.textContent = annotations[currentIndex].title || '';
102420
+ };
102421
+ const updateMode = () => {
102422
+ if (!state.loaded)
102423
+ return;
102424
+ dom.annotationNav.classList.remove('desktop', 'touch', 'hidden');
102425
+ dom.annotationNav.classList.add(state.inputMode);
102426
+ };
102427
+ const updateFade = () => {
102428
+ if (!state.loaded)
102429
+ return;
102430
+ dom.annotationNav.classList.toggle('faded-in', !state.controlsHidden);
102431
+ dom.annotationNav.classList.toggle('faded-out', state.controlsHidden);
102432
+ };
102433
+ const goTo = (index) => {
102434
+ currentIndex = index;
102435
+ updateDisplay();
102436
+ events.fire('annotation.navigate', annotations[currentIndex]);
102437
+ };
102438
+ // Prev / Next
102439
+ dom.annotationPrev.addEventListener('click', (e) => {
102440
+ e.stopPropagation();
102441
+ goTo((currentIndex - 1 + annotations.length) % annotations.length);
102442
+ });
102443
+ dom.annotationNext.addEventListener('click', (e) => {
102444
+ e.stopPropagation();
102445
+ goTo((currentIndex + 1) % annotations.length);
102446
+ });
102447
+ // Sync when an annotation is activated externally (e.g. hotspot click)
102448
+ events.on('annotation.activate', (annotation) => {
102449
+ const idx = annotations.indexOf(annotation);
102450
+ if (idx !== -1) {
102451
+ currentIndex = idx;
102452
+ updateDisplay();
102453
+ }
102454
+ });
102455
+ // React to state changes
102456
+ events.on('loaded:changed', () => {
102457
+ updateMode();
102458
+ updateFade();
102459
+ });
102460
+ events.on('inputMode:changed', updateMode);
102461
+ events.on('controlsHidden:changed', updateFade);
102462
+ // Initial state
102463
+ updateDisplay();
102464
+ };
102412
102465
  // update the poster image to start blurry and then resolve to sharp during loading
102413
102466
  const initPoster = (events) => {
102414
102467
  const poster = document.getElementById('poster');
102415
- events.on('firstFrame', () => {
102468
+ events.on('loaded:changed', () => {
102416
102469
  poster.style.display = 'none';
102417
102470
  document.documentElement.style.setProperty('--canvas-opacity', '1');
102418
102471
  });
@@ -102440,11 +102493,20 @@ const initUI = (global) => {
102440
102493
  'reset', 'frame',
102441
102494
  'loadingText', 'loadingBar',
102442
102495
  'joystickBase', 'joystick',
102443
- 'tooltip'
102496
+ 'tooltip',
102497
+ 'annotationNav', 'annotationPrev', 'annotationNext', 'annotationInfo', 'annotationNavTitle',
102498
+ 'supersplatBranding'
102444
102499
  ].reduce((acc, id) => {
102445
102500
  acc[id] = document.getElementById(id);
102446
102501
  return acc;
102447
102502
  }, {});
102503
+ // Forward wheel events from UI overlays to the canvas so the camera zooms
102504
+ // instead of the page scrolling (e.g. annotation nav, tooltips, hotspots)
102505
+ const canvas = global.app.graphicsDevice.canvas;
102506
+ dom.ui.addEventListener('wheel', (event) => {
102507
+ event.preventDefault();
102508
+ canvas.dispatchEvent(new WheelEvent(event.type, event));
102509
+ }, { passive: false });
102448
102510
  // Handle loading progress updates
102449
102511
  events.on('progress:changed', (progress) => {
102450
102512
  dom.loadingText.textContent = `${progress}%`;
@@ -102455,8 +102517,8 @@ const initUI = (global) => {
102455
102517
  dom.loadingBar.style.backgroundImage = 'linear-gradient(90deg, #F60 0%, #F60 100%)';
102456
102518
  }
102457
102519
  });
102458
- // Hide loading bar once first frame is rendered
102459
- events.on('firstFrame', () => {
102520
+ // Hide loading bar once loaded
102521
+ events.on('loaded:changed', () => {
102460
102522
  document.getElementById('loadingWrap').classList.add('hidden');
102461
102523
  });
102462
102524
  // Fullscreen support
@@ -102575,6 +102637,7 @@ const initUI = (global) => {
102575
102637
  });
102576
102638
  // show the ui and start a timer to hide it again
102577
102639
  let uiTimeout = null;
102640
+ let annotationVisible = false;
102578
102641
  const showUI = () => {
102579
102642
  if (uiTimeout) {
102580
102643
  clearTimeout(uiTimeout);
@@ -102582,11 +102645,26 @@ const initUI = (global) => {
102582
102645
  state.controlsHidden = false;
102583
102646
  uiTimeout = setTimeout(() => {
102584
102647
  uiTimeout = null;
102585
- state.controlsHidden = true;
102648
+ if (!annotationVisible) {
102649
+ state.controlsHidden = true;
102650
+ }
102586
102651
  }, 4000);
102587
102652
  };
102588
- showUI();
102653
+ // Show controls once loaded
102654
+ events.on('loaded:changed', () => {
102655
+ dom.controlsWrap.classList.remove('hidden');
102656
+ showUI();
102657
+ });
102589
102658
  events.on('inputEvent', showUI);
102659
+ // keep UI visible while an annotation tooltip is shown
102660
+ events.on('annotation.activate', () => {
102661
+ annotationVisible = true;
102662
+ showUI();
102663
+ });
102664
+ events.on('annotation.deactivate', () => {
102665
+ annotationVisible = false;
102666
+ showUI();
102667
+ });
102590
102668
  // Animation controls
102591
102669
  events.on('hasAnimation:changed', (value, prev) => {
102592
102670
  // Start and Stop animation
@@ -102678,6 +102756,8 @@ const initUI = (global) => {
102678
102756
  });
102679
102757
  // Initialize touch joystick for fly mode
102680
102758
  initJoystick(dom, events, state);
102759
+ // Initialize annotation navigator
102760
+ initAnnotationNav(dom, events, state, global.settings.annotations);
102681
102761
  // Hide all UI (poster, loading bar, controls)
102682
102762
  if (config.noui) {
102683
102763
  dom.ui.classList.add('hidden');
@@ -102696,6 +102776,23 @@ const initUI = (global) => {
102696
102776
  tooltip.register(dom.vrMode, 'Enter VR', 'top');
102697
102777
  tooltip.register(dom.enterFullscreen, 'Fullscreen', 'top');
102698
102778
  tooltip.register(dom.exitFullscreen, 'Fullscreen', 'top');
102779
+ const isThirdPartyEmbedded = () => {
102780
+ try {
102781
+ return window.location.hostname !== window.parent.location.hostname;
102782
+ }
102783
+ catch (e) {
102784
+ // cross-origin iframe — parent location is inaccessible
102785
+ return true;
102786
+ }
102787
+ };
102788
+ if (window.parent !== window && isThirdPartyEmbedded()) {
102789
+ const viewUrl = new URL(window.location.href);
102790
+ if (viewUrl.pathname === '/s') {
102791
+ viewUrl.pathname = '/view';
102792
+ }
102793
+ dom.supersplatBranding.href = viewUrl.toString();
102794
+ dom.supersplatBranding.classList.remove('hidden');
102795
+ }
102699
102796
  };
102700
102797
 
102701
102798
  // clamp the vertices of the hotspot so it is never clipped by the near or far plane
@@ -102781,7 +102878,6 @@ class Annotation extends Script {
102781
102878
  opacity: 0;
102782
102879
  transition: opacity 0.2s ease-in-out;
102783
102880
  visibility: hidden;
102784
- transform: translate(25px, -50%);
102785
102881
  }
102786
102882
 
102787
102883
  .pc-annotation-title {
@@ -102789,20 +102885,27 @@ class Annotation extends Script {
102789
102885
  margin-bottom: 4px;
102790
102886
  }
102791
102887
 
102792
- /* Add a little triangular arrow on the left edge of the tooltip */
102793
- .pc-annotation::before {
102888
+ /* Tooltip arrow */
102889
+ .pc-annotation.arrow-right::before,
102890
+ .pc-annotation.arrow-left::before {
102794
102891
  content: "";
102795
102892
  position: absolute;
102796
- left: -8px;
102797
- top: 50%;
102893
+ top: var(--arrow-top, 50%);
102798
102894
  transform: translateY(-50%);
102799
- width: 0;
102800
- height: 0;
102801
102895
  border-top: 8px solid transparent;
102802
102896
  border-bottom: 8px solid transparent;
102897
+ }
102898
+
102899
+ .pc-annotation.arrow-right::before {
102900
+ left: -8px;
102803
102901
  border-right: 8px solid rgba(0, 0, 0, 0.8);
102804
102902
  }
102805
102903
 
102904
+ .pc-annotation.arrow-left::before {
102905
+ right: -8px;
102906
+ border-left: 8px solid rgba(0, 0, 0, 0.8);
102907
+ }
102908
+
102806
102909
  .pc-annotation-hotspot {
102807
102910
  display: none;
102808
102911
  position: absolute;
@@ -103021,7 +103124,9 @@ class Annotation extends Script {
103021
103124
  this.hotspotDom.addEventListener('pointerenter', enter);
103022
103125
  this.hotspotDom.addEventListener('pointerleave', leave);
103023
103126
  document.addEventListener('click', () => {
103024
- this.hideTooltip();
103127
+ if (Annotation.activeAnnotation === this) {
103128
+ this.hideTooltip();
103129
+ }
103025
103130
  });
103026
103131
  Annotation.parentDom.appendChild(this.hotspotDom);
103027
103132
  // Clean up on entity destruction
@@ -103089,8 +103194,8 @@ class Annotation extends Script {
103089
103194
  setTimeout(() => {
103090
103195
  if (Annotation.tooltipDom.style.opacity === '0') {
103091
103196
  Annotation.tooltipDom.style.visibility = 'hidden';
103197
+ this.fire('hide');
103092
103198
  }
103093
- this.fire('hide');
103094
103199
  }, 200); // Match the transition duration
103095
103200
  }
103096
103201
  /**
@@ -103115,10 +103220,36 @@ class Annotation extends Script {
103115
103220
  this.hotspotDom.style.display = 'block';
103116
103221
  this.hotspotDom.style.left = `${screenPos.x}px`;
103117
103222
  this.hotspotDom.style.top = `${screenPos.y}px`;
103118
- // Position tooltip
103223
+ // Position tooltip, clamped to viewport
103119
103224
  if (Annotation.activeAnnotation === this) {
103120
- Annotation.tooltipDom.style.left = `${screenPos.x}px`;
103121
- Annotation.tooltipDom.style.top = `${screenPos.y}px`;
103225
+ const tooltip = Annotation.tooltipDom;
103226
+ const margin = 8;
103227
+ const arrowOffset = 25;
103228
+ const tw = tooltip.offsetWidth;
103229
+ const th = tooltip.offsetHeight;
103230
+ const vw = window.innerWidth;
103231
+ const vh = window.innerHeight;
103232
+ // Default position: to the right of hotspot, vertically centered
103233
+ let left = screenPos.x + arrowOffset;
103234
+ let top = screenPos.y - th / 2;
103235
+ let flipped = false;
103236
+ // If tooltip overflows right edge, flip to left side of hotspot
103237
+ if (left + tw > vw - margin) {
103238
+ left = screenPos.x - arrowOffset - tw;
103239
+ flipped = true;
103240
+ }
103241
+ // Clamp horizontal
103242
+ left = Math.max(margin, Math.min(left, vw - tw - margin));
103243
+ // Clamp vertical
103244
+ top = Math.max(margin, Math.min(top, vh - th - margin));
103245
+ // Position arrow to point at the hotspot, clamped within the tooltip
103246
+ const arrowY = Math.max(16, Math.min(screenPos.y - top, th - 16));
103247
+ tooltip.style.setProperty('--arrow-top', `${arrowY}px`);
103248
+ tooltip.classList.toggle('arrow-right', !flipped);
103249
+ tooltip.classList.toggle('arrow-left', flipped);
103250
+ tooltip.style.transform = 'none';
103251
+ tooltip.style.left = `${left}px`;
103252
+ tooltip.style.top = `${top}px`;
103122
103253
  }
103123
103254
  }
103124
103255
  /**
@@ -103186,6 +103317,7 @@ class Annotations {
103186
103317
  }
103187
103318
  // create annotation entities
103188
103319
  const parent = global.app.root;
103320
+ const scriptMap = new Map();
103189
103321
  for (let i = 0; i < this.annotations.length; i++) {
103190
103322
  const ann = this.annotations[i];
103191
103323
  const entity = new Entity();
@@ -103197,15 +103329,26 @@ class Annotations {
103197
103329
  script.annotation.text = ann.text;
103198
103330
  entity.setPosition(ann.position[0], ann.position[1], ann.position[2]);
103199
103331
  parent.addChild(entity);
103332
+ scriptMap.set(ann, script.annotation);
103200
103333
  // handle an annotation being activated/shown
103201
103334
  script.annotation.on('show', () => {
103202
103335
  global.events.fire('annotation.activate', ann);
103203
103336
  });
103337
+ script.annotation.on('hide', () => {
103338
+ global.events.fire('annotation.deactivate');
103339
+ });
103204
103340
  // re-render if hover state changes
103205
103341
  script.annotation.on('hover', (hover) => {
103206
103342
  global.app.renderNextFrame = true;
103207
103343
  });
103208
103344
  }
103345
+ // handle navigator requesting an annotation to be shown
103346
+ global.events.on('annotation.navigate', (ann) => {
103347
+ const script = scriptMap.get(ann);
103348
+ if (script) {
103349
+ script.showTooltip();
103350
+ }
103351
+ });
103209
103352
  }
103210
103353
  }
103211
103354
 
@@ -103603,7 +103746,7 @@ class OrbitController {
103603
103746
  p.position.copy(camera.position);
103604
103747
  p.angles.copy(camera.angles);
103605
103748
  p.distance = camera.distance;
103606
- this.controller.attach(p, true);
103749
+ this.controller.attach(p, false);
103607
103750
  }
103608
103751
  }
103609
103752
 
@@ -103665,9 +103808,14 @@ class CameraManager {
103665
103808
  let fromMode = isObjectExperience ? 'orbit' : 'fly';
103666
103809
  // enter the initial controller
103667
103810
  getController(state.cameraMode).onEnter(this.camera);
103668
- // transition time between cameras
103669
- const transitionSpeed = 2.0;
103811
+ // transition state
103812
+ const transitionSpeed = 1.0;
103670
103813
  let transitionTimer = 1;
103814
+ // start a new camera transition from the current pose
103815
+ const startTransition = () => {
103816
+ from.copy(this.camera);
103817
+ transitionTimer = 0;
103818
+ };
103671
103819
  // application update
103672
103820
  this.update = (deltaTime, frame) => {
103673
103821
  // use dt of 0 if animation is paused
@@ -103694,10 +103842,12 @@ class CameraManager {
103694
103842
  case 'frame':
103695
103843
  state.cameraMode = 'orbit';
103696
103844
  controllers.orbit.goto(frameCamera);
103845
+ startTransition();
103697
103846
  break;
103698
103847
  case 'reset':
103699
103848
  state.cameraMode = 'orbit';
103700
103849
  controllers.orbit.goto(resetCamera);
103850
+ startTransition();
103701
103851
  break;
103702
103852
  case 'playPause':
103703
103853
  if (state.hasAnimation) {
@@ -103722,7 +103872,6 @@ class CameraManager {
103722
103872
  events.on('cameraMode:changed', (value, prev) => {
103723
103873
  // store previous camera mode and pose
103724
103874
  target.copy(this.camera);
103725
- from.copy(this.camera);
103726
103875
  fromMode = prev;
103727
103876
  // exit the old controller
103728
103877
  const prevController = getController(prev);
@@ -103730,8 +103879,7 @@ class CameraManager {
103730
103879
  // enter new controller
103731
103880
  const newController = getController(value);
103732
103881
  newController.onEnter(this.camera);
103733
- // reset camera transition timer
103734
- transitionTimer = 0;
103882
+ startTransition();
103735
103883
  });
103736
103884
  // handle user scrubbing the animation timeline
103737
103885
  events.on('scrubAnim', (time) => {
@@ -103748,6 +103896,7 @@ class CameraManager {
103748
103896
  tmpCamera.copy(this.camera);
103749
103897
  tmpCamera.look(this.camera.position, position);
103750
103898
  controllers.orbit.goto(tmpCamera);
103899
+ startTransition();
103751
103900
  });
103752
103901
  events.on('annotation.activate', (annotation) => {
103753
103902
  // switch to orbit camera on pick
@@ -103757,6 +103906,8 @@ class CameraManager {
103757
103906
  tmpCamera.fov = initial.fov;
103758
103907
  tmpCamera.look(new Vec3(initial.position), new Vec3(initial.target));
103759
103908
  controllers.orbit.goto(tmpCamera);
103909
+ target.fov = tmpCamera.fov;
103910
+ startTransition();
103760
103911
  });
103761
103912
  }
103762
103913
  }
@@ -104361,8 +104512,9 @@ class Viewer {
104361
104512
  applyCamera(this.cameraManager.camera);
104362
104513
  }
104363
104514
  });
104364
- // unpause the animation on first frame
104515
+ // update state on first frame
104365
104516
  events.on('firstFrame', () => {
104517
+ state.loaded = true;
104366
104518
  state.animationPaused = !!config.noanim;
104367
104519
  });
104368
104520
  // wait for the model to load
@@ -105395,7 +105547,7 @@ const initXr = (global) => {
105395
105547
  });
105396
105548
  };
105397
105549
 
105398
- var version = "1.12.3";
105550
+ var version = "1.13.1";
105399
105551
 
105400
105552
  const loadGsplat = async (app, config, progressCallback) => {
105401
105553
  const { contents, contentUrl, unified, aa } = config;
@@ -105457,6 +105609,7 @@ const loadSkybox = (app, url) => {
105457
105609
  const main = (app, camera, settingsJson, config) => {
105458
105610
  const events = new EventHandler();
105459
105611
  const state = observe(events, {
105612
+ loaded: false,
105460
105613
  readyToRender: false,
105461
105614
  hqMode: true,
105462
105615
  progress: 0,