@playcanvas/supersplat-viewer 1.12.2 → 1.13.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/dist/index.js +3 -3
- package/package.json +2 -2
- package/public/index.css +173 -7
- package/public/index.html +110 -69
- package/public/index.js +166 -21
- package/public/index.js.map +1 -1
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('
|
|
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
|
|
102459
|
-
events.on('
|
|
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
|
-
|
|
102648
|
+
if (!annotationVisible) {
|
|
102649
|
+
state.controlsHidden = true;
|
|
102650
|
+
}
|
|
102586
102651
|
}, 4000);
|
|
102587
102652
|
};
|
|
102588
|
-
|
|
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
|
-
/*
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
103121
|
-
|
|
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
|
|
|
@@ -104361,8 +104504,9 @@ class Viewer {
|
|
|
104361
104504
|
applyCamera(this.cameraManager.camera);
|
|
104362
104505
|
}
|
|
104363
104506
|
});
|
|
104364
|
-
//
|
|
104507
|
+
// update state on first frame
|
|
104365
104508
|
events.on('firstFrame', () => {
|
|
104509
|
+
state.loaded = true;
|
|
104366
104510
|
state.animationPaused = !!config.noanim;
|
|
104367
104511
|
});
|
|
104368
104512
|
// wait for the model to load
|
|
@@ -105395,7 +105539,7 @@ const initXr = (global) => {
|
|
|
105395
105539
|
});
|
|
105396
105540
|
};
|
|
105397
105541
|
|
|
105398
|
-
var version = "1.
|
|
105542
|
+
var version = "1.13.0";
|
|
105399
105543
|
|
|
105400
105544
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
105401
105545
|
const { contents, contentUrl, unified, aa } = config;
|
|
@@ -105457,10 +105601,11 @@ const loadSkybox = (app, url) => {
|
|
|
105457
105601
|
const main = (app, camera, settingsJson, config) => {
|
|
105458
105602
|
const events = new EventHandler();
|
|
105459
105603
|
const state = observe(events, {
|
|
105604
|
+
loaded: false,
|
|
105460
105605
|
readyToRender: false,
|
|
105461
105606
|
hqMode: true,
|
|
105462
105607
|
progress: 0,
|
|
105463
|
-
inputMode: 'desktop',
|
|
105608
|
+
inputMode: platform.mobile ? 'touch' : 'desktop',
|
|
105464
105609
|
cameraMode: 'orbit',
|
|
105465
105610
|
hasAnimation: false,
|
|
105466
105611
|
animationDuration: 0,
|