sceneview-mcp 4.3.4 → 4.4.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/generated/llms-txt.js +1 -1
- package/dist/generated/symbols.js +36 -2
- package/dist/generated/version.js +2 -2
- package/dist/tools/definitions.js +9 -2
- package/dist/tools/handler.js +9 -2
- package/dist/widget-space.js +127 -0
- package/dist/widgets.js +394 -119
- package/package.json +1 -1
package/dist/widgets.js
CHANGED
|
@@ -20,15 +20,16 @@
|
|
|
20
20
|
* parameters so the page can be opened directly for a manual preview.
|
|
21
21
|
*
|
|
22
22
|
* The renderer is **SceneView.js + Filament.js**, the same WebGL2/WASM stack
|
|
23
|
-
* that powers `sceneview-web` and the sceneview.github.io playground.
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* that powers `sceneview-web` and the sceneview.github.io playground. A
|
|
24
|
+
* WASM-free glTF renderer is loaded lazily as a compatibility path for stricter hosts.
|
|
25
|
+
* Filament remains the primary renderer wherever the host permits it.
|
|
26
26
|
*
|
|
27
27
|
* This file used to live in the hosted gateway (`mcp-gateway/src/mcp/widgets.ts`,
|
|
28
28
|
* deleted 2026-08-31). It now ships inside the npm package so the stdio server
|
|
29
29
|
* and the Streamable HTTP server (`http.ts`) serve the exact same widget.
|
|
30
30
|
*/
|
|
31
31
|
import { LATEST_SCENEVIEW_RELEASE, PACKAGE_VERSION } from "./generated/version.js";
|
|
32
|
+
import { SPACE_DRAWING_JS } from "./widget-space.js";
|
|
32
33
|
/** Canonical MCP Apps mime type for widget resources. */
|
|
33
34
|
export const MCP_APP_MIME_TYPE = "text/html;profile=mcp-app";
|
|
34
35
|
/**
|
|
@@ -102,6 +103,7 @@ export function serveWidgetsTo(settings) {
|
|
|
102
103
|
}
|
|
103
104
|
/** Resource URI of the 3D viewer widget (`ui://widget/<name>.html` convention). */
|
|
104
105
|
export const WIDGET_3D_VIEWER_URI = "ui://widget/3d-viewer.html";
|
|
106
|
+
export const WIDGET_SHOW_IN_SPACE_URI = "ui://widget/show-in-space.html";
|
|
105
107
|
/**
|
|
106
108
|
* MCP Apps `_meta.ui` block attached to the widget resource. `csp` is what the
|
|
107
109
|
* host uses to build the iframe's Content-Security-Policy:
|
|
@@ -124,6 +126,9 @@ export const WIDGET_UI_META = {
|
|
|
124
126
|
"https://media.sketchfab.com",
|
|
125
127
|
"https://cdn.jsdelivr.net",
|
|
126
128
|
"https://arcamera-api.mcp-tools-lab.workers.dev",
|
|
129
|
+
// Local GLB conversions and embedded glTF textures, never external origins.
|
|
130
|
+
"blob:",
|
|
131
|
+
"data:",
|
|
127
132
|
],
|
|
128
133
|
},
|
|
129
134
|
};
|
|
@@ -158,6 +163,7 @@ const NEUTRAL_IBL_URL = `${CDN_BASE}/environments/neutral_ibl.ktx`;
|
|
|
158
163
|
* desktop-sized viewport only: a phone never downloads it. The QR is drawn in the browser —
|
|
159
164
|
* no QR image service ever sees the link.
|
|
160
165
|
*/
|
|
166
|
+
const FALLBACK_JS_URL = `${CDN_BASE}/js/widget-fallback.js?v=${LATEST_SCENEVIEW_RELEASE}`;
|
|
161
167
|
const QRCODE_JS_URL = `${CDN_BASE}/js/qrcode-vendor.js?v=${LATEST_SCENEVIEW_RELEASE}`;
|
|
162
168
|
/**
|
|
163
169
|
* The 3D AR Model Viewer app's universal link for a remote model (`ar.sceneview.dev/open?url=`). A phone
|
|
@@ -195,19 +201,20 @@ export const OPEN_IN_AR_JS = `function openInArUrl(modelUrl, source) {
|
|
|
195
201
|
* With no `modelUrl` from any source the widget shows a placeholder with the
|
|
196
202
|
* SceneView mark, so it never renders as an empty box.
|
|
197
203
|
*/
|
|
198
|
-
|
|
204
|
+
function buildWidgetHtml(space) {
|
|
205
|
+
return `<!DOCTYPE html>
|
|
199
206
|
<html lang="en">
|
|
200
207
|
<head>
|
|
201
208
|
<meta charset="UTF-8" />
|
|
202
209
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
203
|
-
<title
|
|
210
|
+
<title>${space ? "SceneView · Real size" : "SceneView 3D Viewer"}</title>
|
|
204
211
|
<style>
|
|
205
212
|
/* Colour tokens from DESIGN.md, light first. The host picks the theme
|
|
206
213
|
(MCP Apps \`hostContext.theme\`, ChatGPT \`window.openai.theme\`) and
|
|
207
214
|
the script mirrors it onto <html data-theme>; without one the OS
|
|
208
215
|
preference applies. The 3D stage stays dark in both themes — DESIGN.md
|
|
209
216
|
\`stage-background-embedded\` — so everything drawn over it (loader,
|
|
210
|
-
placeholder
|
|
217
|
+
placeholder) is styled for a dark ground; the AR action uses host chrome. */
|
|
211
218
|
:root {
|
|
212
219
|
color-scheme: light;
|
|
213
220
|
--sv-surface: #ffffff;
|
|
@@ -229,7 +236,7 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
229
236
|
--sv-surface: #0d1117;
|
|
230
237
|
--sv-on-surface: #f3f4f6;
|
|
231
238
|
--sv-on-surface-dim: #a4abb7;
|
|
232
|
-
--sv-on-surface-faint: #
|
|
239
|
+
--sv-on-surface-faint: #a4abb7;
|
|
233
240
|
--sv-outline-subtle: #21262d;
|
|
234
241
|
--sv-chip: #21262d;
|
|
235
242
|
--sv-link: #a4c1ff;
|
|
@@ -237,7 +244,7 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
237
244
|
--sv-primary-hover: #b8d0ff;
|
|
238
245
|
--sv-on-primary: #0d1117;
|
|
239
246
|
--sv-card: #232a39;
|
|
240
|
-
--sv-stage:
|
|
247
|
+
--sv-stage: #0b0f16;
|
|
241
248
|
}
|
|
242
249
|
}
|
|
243
250
|
:root[data-theme="dark"] {
|
|
@@ -245,7 +252,7 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
245
252
|
--sv-surface: #0d1117;
|
|
246
253
|
--sv-on-surface: #f3f4f6;
|
|
247
254
|
--sv-on-surface-dim: #a4abb7;
|
|
248
|
-
--sv-on-surface-faint: #
|
|
255
|
+
--sv-on-surface-faint: #a4abb7;
|
|
249
256
|
--sv-outline-subtle: #21262d;
|
|
250
257
|
--sv-chip: #21262d;
|
|
251
258
|
--sv-link: #a4c1ff;
|
|
@@ -253,7 +260,7 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
253
260
|
--sv-primary-hover: #b8d0ff;
|
|
254
261
|
--sv-on-primary: #0d1117;
|
|
255
262
|
--sv-card: #232a39;
|
|
256
|
-
--sv-stage:
|
|
263
|
+
--sv-stage: #0b0f16;
|
|
257
264
|
}
|
|
258
265
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
259
266
|
html, body { height: 100%; }
|
|
@@ -279,7 +286,9 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
279
286
|
gap: 8px;
|
|
280
287
|
border-bottom: 1px solid var(--sv-outline-subtle);
|
|
281
288
|
}
|
|
282
|
-
#
|
|
289
|
+
#heading { min-width: 0; }
|
|
290
|
+
#real-size { display: block; margin-top: 3px; font-size: 0.75rem; color: var(--sv-on-surface-dim); }
|
|
291
|
+
#header strong { overflow-wrap: anywhere; font-size: 0.95rem; font-weight: 600; }
|
|
283
292
|
#brand {
|
|
284
293
|
font-size: 0.75rem;
|
|
285
294
|
color: var(--sv-on-surface-dim);
|
|
@@ -294,12 +303,19 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
294
303
|
min-height: 0;
|
|
295
304
|
background: var(--sv-stage);
|
|
296
305
|
}
|
|
306
|
+
#preview {
|
|
307
|
+
flex: 1 1 auto;
|
|
308
|
+
min-height: 0;
|
|
309
|
+
position: relative;
|
|
310
|
+
display: flex;
|
|
311
|
+
flex-direction: column;
|
|
312
|
+
}
|
|
297
313
|
#canvas {
|
|
298
314
|
display: block;
|
|
299
315
|
width: 100%;
|
|
300
316
|
height: 100%;
|
|
301
317
|
background: transparent;
|
|
302
|
-
transition: opacity 0.
|
|
318
|
+
transition: opacity 0.65s cubic-bezier(0.2, 0, 0, 1);
|
|
303
319
|
}
|
|
304
320
|
#placeholder, #loader, #error {
|
|
305
321
|
position: absolute;
|
|
@@ -316,15 +332,12 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
316
332
|
background: var(--sv-stage);
|
|
317
333
|
}
|
|
318
334
|
[hidden] { display: none !important; }
|
|
319
|
-
#loader .
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
border-radius: 50%;
|
|
325
|
-
animation: spin 0.8s linear infinite;
|
|
335
|
+
#loader svg { color: #adc6ff; animation: breathe 2.4s ease-in-out infinite; }
|
|
336
|
+
#loader { font-size: 0.8rem; letter-spacing: 0.02em; }
|
|
337
|
+
@keyframes breathe {
|
|
338
|
+
0%, 100% { opacity: 0.3; transform: translateY(3px) scale(0.96); }
|
|
339
|
+
50% { opacity: 0.85; transform: translateY(-3px) scale(1); }
|
|
326
340
|
}
|
|
327
|
-
@keyframes spin { to { transform: rotate(360deg); } }
|
|
328
341
|
#error { color: #ffb4ab; }
|
|
329
342
|
#placeholder svg { opacity: 0.5; }
|
|
330
343
|
#footer {
|
|
@@ -349,16 +362,15 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
349
362
|
also gets a QR code of the same link, because AR happens on the
|
|
350
363
|
phone in a pocket, not on the monitor. */
|
|
351
364
|
#ar {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
bottom: 12px;
|
|
365
|
+
flex: 0 0 auto;
|
|
366
|
+
padding: 12px 16px;
|
|
367
|
+
background: var(--sv-surface);
|
|
356
368
|
z-index: 1;
|
|
357
369
|
display: flex;
|
|
358
370
|
justify-content: center;
|
|
359
371
|
pointer-events: none;
|
|
360
372
|
}
|
|
361
|
-
#ar-card { pointer-events: auto; display: flex; align-items: center; gap: 12px; }
|
|
373
|
+
#ar-card { pointer-events: auto; display: flex; align-items: center; gap: 12px; width: 100%; }
|
|
362
374
|
#ar-open {
|
|
363
375
|
display: inline-flex;
|
|
364
376
|
align-items: center;
|
|
@@ -374,64 +386,82 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
374
386
|
font-weight: 600;
|
|
375
387
|
line-height: 1.2;
|
|
376
388
|
text-decoration: none;
|
|
377
|
-
|
|
389
|
+
text-align: center;
|
|
390
|
+
width: 100%;
|
|
378
391
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
|
|
379
392
|
transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.15s ease;
|
|
380
393
|
}
|
|
381
394
|
#ar-open:hover { background: var(--sv-primary-hover); }
|
|
382
395
|
#ar-open:active { transform: scale(0.97); }
|
|
383
|
-
#ar-open:focus-visible { outline: 2px solid
|
|
396
|
+
#ar-open:focus-visible { outline: 2px solid var(--sv-link); outline-offset: 3px; }
|
|
384
397
|
#ar-open svg { flex: 0 0 auto; }
|
|
385
398
|
#ar .long, #ar-qr, #ar-scan { display: none; }
|
|
386
|
-
#ar.wide .long { display: inline; }
|
|
387
|
-
#ar.wide
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
399
|
+
#ar.wide:not(.has-qr) .long { display: inline; }
|
|
400
|
+
#ar.wide {
|
|
401
|
+
position: absolute;
|
|
402
|
+
bottom: 12px;
|
|
403
|
+
right: 12px;
|
|
404
|
+
padding: 0;
|
|
405
|
+
background: transparent;
|
|
406
|
+
}
|
|
407
|
+
#ar.wide #ar-card {
|
|
408
|
+
width: auto;
|
|
409
|
+
max-width: 280px;
|
|
410
|
+
padding: 10px;
|
|
411
|
+
border-radius: 12px;
|
|
412
|
+
background: var(--sv-surface);
|
|
392
413
|
color: var(--sv-on-surface);
|
|
393
|
-
box-shadow: 0
|
|
414
|
+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
|
|
394
415
|
}
|
|
395
416
|
#ar.wide.has-qr #ar-qr {
|
|
396
417
|
display: block;
|
|
397
|
-
width:
|
|
398
|
-
height:
|
|
418
|
+
width: 96px;
|
|
419
|
+
height: 96px;
|
|
420
|
+
flex: 0 0 auto;
|
|
399
421
|
padding: 6px;
|
|
400
422
|
border-radius: 8px;
|
|
401
423
|
background: #ffffff;
|
|
402
424
|
}
|
|
403
425
|
#ar-qr svg { display: block; width: 100%; height: 100%; shape-rendering: crispEdges; }
|
|
404
426
|
#ar.wide.has-qr #ar-scan { display: flex; flex-direction: column; gap: 4px; }
|
|
405
|
-
#ar-copy { display: flex; flex-direction: column; align-items: flex-start; gap:
|
|
406
|
-
#ar-scan strong { font-size: 0.
|
|
427
|
+
#ar-copy { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; width: 100%; }
|
|
428
|
+
#ar-scan strong { font-size: 0.8rem; font-weight: 600; }
|
|
407
429
|
#ar-scan span { font-size: 0.75rem; color: var(--sv-on-surface-dim); }
|
|
408
|
-
#ar.wide
|
|
430
|
+
#ar.wide #ar-open { min-height: 44px; padding: 8px 12px; font-size: 0.8rem; box-shadow: none; }
|
|
431
|
+
@media (prefers-reduced-motion: reduce) {
|
|
432
|
+
#loader svg { animation: none; opacity: 0.6; }
|
|
433
|
+
#canvas, #ar-open { transition: none; }
|
|
434
|
+
}
|
|
409
435
|
</style>
|
|
410
|
-
<script src="${FILAMENT_JS_URL}"></script>
|
|
411
|
-
<script src="${SCENEVIEW_JS_URL}"></script>
|
|
412
436
|
</head>
|
|
413
437
|
<body>
|
|
414
438
|
<div id="stage">
|
|
415
439
|
<div id="header">
|
|
416
|
-
<strong id="title"
|
|
440
|
+
<div id="heading"><strong id="title">${space ? "See it at real size" : "SceneView 3D Viewer"}</strong><span id="real-size" hidden></span></div>
|
|
417
441
|
<span id="brand">Powered by <a href="https://sceneview.github.io" target="_blank" rel="noopener">SceneView</a></span>
|
|
418
442
|
</div>
|
|
443
|
+
<div id="preview">
|
|
419
444
|
<div id="canvas-wrap">
|
|
420
|
-
<canvas id="canvas" style="opacity:0" role="img" aria-label="3D model"></canvas>
|
|
421
|
-
<div id="loader"
|
|
445
|
+
<canvas id="canvas" style="opacity:0" role="img" tabindex="0" aria-label="3D model"></canvas>
|
|
446
|
+
<div id="loader" role="status" aria-live="polite">
|
|
447
|
+
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" aria-hidden="true">
|
|
448
|
+
<path d="M12 2 4 6v12l8 4 8-4V6l-8-4Z M4 6l8 4 8-4 M12 22V10"/>
|
|
449
|
+
</svg><div>${space ? "Putting its size in perspective…" : "Bringing your model into view…"}</div>
|
|
450
|
+
</div>
|
|
422
451
|
<div id="placeholder" hidden>
|
|
423
452
|
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
|
424
453
|
<path d="M12 2 4 6v12l8 4 8-4V6l-8-4Z"/>
|
|
425
454
|
<path d="m4 6 8 4 8-4"/>
|
|
426
455
|
<path d="M12 22V10"/>
|
|
427
456
|
</svg>
|
|
428
|
-
<div
|
|
429
|
-
<div style="font-size:0.8rem"
|
|
457
|
+
<div>${space ? "No dimensions provided" : "No 3D model URL provided"}</div>
|
|
458
|
+
<div style="font-size:0.8rem">${space ? "Ask to see an object’s width, height and depth in your room." : 'Pass <code style="background:#21262d;padding:2px 6px;border-radius:3px">modelUrl</code> in structuredContent or as a query parameter.'}</div>
|
|
430
459
|
</div>
|
|
431
460
|
<div id="error" hidden>
|
|
432
|
-
<div>Could not load
|
|
461
|
+
<div>Could not load preview</div>
|
|
433
462
|
<div id="error-detail" style="font-size:0.75rem;color:#a4abb7"></div>
|
|
434
463
|
</div>
|
|
464
|
+
</div>
|
|
435
465
|
<div id="ar" hidden>
|
|
436
466
|
<div id="ar-card">
|
|
437
467
|
<div id="ar-qr" role="img" aria-label="QR code: scan with your phone to open this model in AR"></div>
|
|
@@ -450,15 +480,19 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
450
480
|
</div>
|
|
451
481
|
</div>
|
|
452
482
|
<div id="footer">
|
|
453
|
-
<span class="pill" id="format"
|
|
454
|
-
<span class="pill" id="engine"
|
|
455
|
-
<span style="margin-left:auto" id="hint"
|
|
483
|
+
<span class="pill" id="format">${space ? "cm" : "GLB"}</span>
|
|
484
|
+
<span class="pill" id="engine">${space ? "Size preview" : "3D preview"}</span>
|
|
485
|
+
<span style="margin-left:auto" id="hint">${space ? "Human reference · 1.75 m" : "Drag to orbit · Scroll to zoom"}</span>
|
|
456
486
|
</div>
|
|
457
487
|
</div>
|
|
458
488
|
<script>
|
|
459
489
|
(function () {
|
|
490
|
+
var SPACE_WIDGET = ${space};
|
|
460
491
|
var WIDGET_VERSION = "${PACKAGE_VERSION}";
|
|
461
492
|
var IBL_URL = "${NEUTRAL_IBL_URL}";
|
|
493
|
+
var FILAMENT_URL = "${FILAMENT_JS_URL}";
|
|
494
|
+
var SCENEVIEW_URL = "${SCENEVIEW_JS_URL}";
|
|
495
|
+
var FALLBACK_URL = "${FALLBACK_JS_URL}";
|
|
462
496
|
// The 3MF converter (#3482), fetched only when a payload needs it.
|
|
463
497
|
var CONVERTER_URL = "${SCENEVIEW_WEB_URL}";
|
|
464
498
|
|
|
@@ -468,12 +502,28 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
468
502
|
var placeholder = document.getElementById("placeholder");
|
|
469
503
|
var errorEl = document.getElementById("error");
|
|
470
504
|
var errorDetail = document.getElementById("error-detail");
|
|
505
|
+
var sizeEl = document.getElementById("real-size");
|
|
471
506
|
var formatEl = document.getElementById("format");
|
|
472
507
|
|
|
473
508
|
// What is on screen right now, and the payload waiting for the renderer.
|
|
474
509
|
var rendered = null;
|
|
475
510
|
var pending = null;
|
|
476
511
|
var viewer = null;
|
|
512
|
+
var viewerCreation = null;
|
|
513
|
+
var loadController = null;
|
|
514
|
+
var rendererPromise = null;
|
|
515
|
+
var rendererKind = null;
|
|
516
|
+
var disposed = false;
|
|
517
|
+
var interacted = false;
|
|
518
|
+
var canvasWrap = document.getElementById("canvas-wrap");
|
|
519
|
+
function stopTurntable() {
|
|
520
|
+
interacted = true;
|
|
521
|
+
if (viewer && viewer.setAutoRotate) viewer.setAutoRotate(false);
|
|
522
|
+
}
|
|
523
|
+
["pointerdown", "wheel", "keydown"].forEach(function (event) {
|
|
524
|
+
canvasWrap.addEventListener(event, stopTurntable, { capture: true, passive: true });
|
|
525
|
+
});
|
|
526
|
+
var reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
477
527
|
|
|
478
528
|
// ── Payload sources, in priority order ───────────────────────────────
|
|
479
529
|
//
|
|
@@ -486,6 +536,17 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
486
536
|
|
|
487
537
|
function normalise(sc) {
|
|
488
538
|
if (!sc || typeof sc !== "object") return null;
|
|
539
|
+
if (SPACE_WIDGET) {
|
|
540
|
+
if (!Array.isArray(sc.sizeCm) || sc.sizeCm.length !== 3 || sc.sizeCm.some(function (v) {
|
|
541
|
+
return typeof v !== "number" || !Number.isFinite(v) || v <= 1 || v > 1000;
|
|
542
|
+
}) || typeof sc.label !== "string" || (sc.placement !== "floor" && sc.placement !== "table")) return null;
|
|
543
|
+
try {
|
|
544
|
+
var link = new URL(sc.url);
|
|
545
|
+
if (link.origin !== "https://sceneview.github.io" || link.pathname !== "/open" ||
|
|
546
|
+
link.searchParams.get("demo") !== "spatial-answer" || !link.searchParams.get("answer")) return null;
|
|
547
|
+
} catch (e) { return null; }
|
|
548
|
+
return sc;
|
|
549
|
+
}
|
|
489
550
|
if (typeof sc.modelUrl !== "string" || !sc.modelUrl) return null;
|
|
490
551
|
return sc;
|
|
491
552
|
}
|
|
@@ -504,13 +565,24 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
504
565
|
|
|
505
566
|
function request(method, params, onDone) {
|
|
506
567
|
var id = nextRequestId++;
|
|
507
|
-
|
|
568
|
+
var timer = setTimeout(function () {
|
|
569
|
+
if (!awaiting[id]) return;
|
|
570
|
+
delete awaiting[id];
|
|
571
|
+
onDone(false);
|
|
572
|
+
}, 2500);
|
|
573
|
+
awaiting[id] = function (ok) { clearTimeout(timer); onDone(ok); };
|
|
508
574
|
post({ jsonrpc: "2.0", id: id, method: method, params: params });
|
|
509
575
|
}
|
|
510
576
|
|
|
511
577
|
window.addEventListener("message", function (event) {
|
|
578
|
+
if (event.source !== window.parent) return;
|
|
512
579
|
var msg = event.data;
|
|
513
580
|
if (!msg || typeof msg !== "object" || msg.jsonrpc !== "2.0") return;
|
|
581
|
+
if (msg.method === "ui/resource-teardown") {
|
|
582
|
+
dispose();
|
|
583
|
+
post({ jsonrpc: "2.0", id: msg.id, result: {} });
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
514
586
|
if (msg.method === "ui/notifications/tool-result" && msg.params) {
|
|
515
587
|
var data = normalise(msg.params.structuredContent);
|
|
516
588
|
if (data) render(data);
|
|
@@ -528,6 +600,7 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
528
600
|
applyTheme(init.hostContext && init.hostContext.theme);
|
|
529
601
|
}
|
|
530
602
|
post({ jsonrpc: "2.0", method: "ui/notifications/initialized" });
|
|
603
|
+
post({ jsonrpc: "2.0", method: "ui/notifications/size-changed", params: { height: 560 } });
|
|
531
604
|
return;
|
|
532
605
|
}
|
|
533
606
|
if (typeof msg.id === "number" && awaiting[msg.id]) {
|
|
@@ -543,7 +616,7 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
543
616
|
method: "ui/initialize",
|
|
544
617
|
params: {
|
|
545
618
|
protocolVersion: "2026-01-26",
|
|
546
|
-
appInfo: { name: "sceneview-3d-viewer", version: WIDGET_VERSION },
|
|
619
|
+
appInfo: { name: "${space ? "sceneview-show-in-space" : "sceneview-3d-viewer"}", version: WIDGET_VERSION },
|
|
547
620
|
appCapabilities: {},
|
|
548
621
|
},
|
|
549
622
|
});
|
|
@@ -564,6 +637,11 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
564
637
|
|
|
565
638
|
function fromQuery() {
|
|
566
639
|
var p = new URLSearchParams(location.search);
|
|
640
|
+
if (SPACE_WIDGET) return normalise({
|
|
641
|
+
sizeCm: [Number(p.get("widthCm")), Number(p.get("heightCm")), Number(p.get("depthCm"))],
|
|
642
|
+
label: p.get("label") || "Size preview", placement: p.get("placement") || "floor",
|
|
643
|
+
dimensionSource: p.get("dimensionSource") || "user", url: p.get("url"),
|
|
644
|
+
});
|
|
567
645
|
var modelUrl = p.get("modelUrl") || p.get("src");
|
|
568
646
|
if (!modelUrl) return null;
|
|
569
647
|
return {
|
|
@@ -622,7 +700,7 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
622
700
|
}
|
|
623
701
|
|
|
624
702
|
function updateArAction(data) {
|
|
625
|
-
arLink = data.ar === false ? null : openInArUrl(data.modelUrl, linkSource());
|
|
703
|
+
arLink = SPACE_WIDGET ? data.url : (data.ar === false ? null : openInArUrl(data.modelUrl, linkSource()));
|
|
626
704
|
arEl.classList.remove("has-qr");
|
|
627
705
|
arQr.textContent = "";
|
|
628
706
|
if (!arLink) { arEl.hidden = true; return; }
|
|
@@ -718,21 +796,53 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
718
796
|
// ── Rendering ────────────────────────────────────────────────────────
|
|
719
797
|
|
|
720
798
|
function render(data) {
|
|
721
|
-
if (rendered && rendered
|
|
799
|
+
if (disposed || (!pending && (viewer || SPACE_WIDGET) && rendered && JSON.stringify(rendered) === JSON.stringify(data))) return;
|
|
800
|
+
if (loadController) loadController.abort();
|
|
801
|
+
var controller = new AbortController();
|
|
802
|
+
loadController = controller;
|
|
722
803
|
pending = data;
|
|
804
|
+
canvas.style.opacity = "0";
|
|
805
|
+
sizeEl.hidden = true;
|
|
723
806
|
placeholder.hidden = true;
|
|
724
807
|
errorEl.hidden = true;
|
|
725
808
|
loader.hidden = false;
|
|
726
|
-
titleEl.textContent = cleanTitle(data.title) || "SceneView 3D Viewer";
|
|
809
|
+
titleEl.textContent = cleanTitle(SPACE_WIDGET ? data.label : data.title) || "SceneView 3D Viewer";
|
|
727
810
|
// Before the model loads, and whether or not it does: a file this
|
|
728
811
|
// browser cannot draw may still open in the app.
|
|
729
812
|
updateArAction(data);
|
|
813
|
+
if (SPACE_WIDGET) {
|
|
814
|
+
try {
|
|
815
|
+
drawSpace(data);
|
|
816
|
+
rendered = data; pending = null;
|
|
817
|
+
loader.hidden = true; canvas.style.opacity = "1";
|
|
818
|
+
document.documentElement.dataset.renderer = "canvas2d";
|
|
819
|
+
notifyReady();
|
|
820
|
+
} catch (err) { fail(err); }
|
|
821
|
+
if (loadController === controller) loadController = null;
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
730
824
|
canvas.setAttribute("aria-label", data.alt || data.title || "3D model");
|
|
731
825
|
var ext = (data.modelUrl.split("?")[0].split(".").pop() || "GLB").toUpperCase();
|
|
732
826
|
formatEl.textContent = ext === "GLTF" ? "glTF" : ext;
|
|
733
|
-
|
|
827
|
+
// A new result aborts this operation and starts independently. Renderer
|
|
828
|
+
// loadModel() calls also use newest-wins tickets, so an old download can
|
|
829
|
+
// never repaint a newer model when it eventually settles.
|
|
830
|
+
(async function () {
|
|
831
|
+
if (pending !== data || disposed) return;
|
|
832
|
+
try {
|
|
833
|
+
await chooseRenderer();
|
|
834
|
+
if (pending === data && !disposed) await start(data, controller);
|
|
835
|
+
} catch (err) {
|
|
836
|
+
if (err && err.name === "AbortError") return;
|
|
837
|
+
if (pending === data && !disposed) fail(err);
|
|
838
|
+
} finally {
|
|
839
|
+
if (loadController === controller) loadController = null;
|
|
840
|
+
}
|
|
841
|
+
})();
|
|
734
842
|
}
|
|
735
843
|
|
|
844
|
+
${space ? SPACE_DRAWING_JS : ""}
|
|
845
|
+
|
|
736
846
|
// ── 3MF (#3482) ──────────────────────────────────────────────────────
|
|
737
847
|
//
|
|
738
848
|
// ChatGPT emits a \`.3mf\` when it turns a drawing into a printable model.
|
|
@@ -744,12 +854,9 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
744
854
|
var threeMfScriptPromise = null;
|
|
745
855
|
function loadThreeMfConverter() {
|
|
746
856
|
if (!threeMfScriptPromise) {
|
|
747
|
-
threeMfScriptPromise =
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
el.onload = function () { resolve(); };
|
|
751
|
-
el.onerror = function () { reject(new Error("could not load the 3MF converter")); };
|
|
752
|
-
document.head.appendChild(el);
|
|
857
|
+
threeMfScriptPromise = loadScript(CONVERTER_URL).catch(function (error) {
|
|
858
|
+
threeMfScriptPromise = null;
|
|
859
|
+
throw error;
|
|
753
860
|
});
|
|
754
861
|
}
|
|
755
862
|
return threeMfScriptPromise;
|
|
@@ -772,13 +879,13 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
772
879
|
* still costs exactly one download, and a glTF keeps resolving its own
|
|
773
880
|
* external buffers and textures against its own URL.
|
|
774
881
|
*/
|
|
775
|
-
function resolveModelUrl(url) {
|
|
882
|
+
function resolveModelUrl(url, controller) {
|
|
776
883
|
var path = String(url).split("?")[0].split("#")[0].toLowerCase();
|
|
777
884
|
var isThreeMfUrl = /.3mf$/.test(path);
|
|
778
885
|
var isKnownGltf = /.(glb|gltf)$/.test(path);
|
|
779
886
|
if (!isThreeMfUrl && isKnownGltf) return Promise.resolve(url);
|
|
780
887
|
|
|
781
|
-
|
|
888
|
+
var download = fetch(url, { signal: controller.signal })
|
|
782
889
|
.then(function (r) {
|
|
783
890
|
if (!r.ok) throw new Error("HTTP " + r.status + " loading the model");
|
|
784
891
|
var type = (r.headers.get("content-type") || "").toLowerCase();
|
|
@@ -788,7 +895,7 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
788
895
|
})
|
|
789
896
|
.then(function (payload) {
|
|
790
897
|
if (!looksLikeZip(payload.buffer) && !payload.isThreeMfType) return url;
|
|
791
|
-
return loadThreeMfConverter().then(function () {
|
|
898
|
+
return abortable(loadThreeMfConverter(), controller.signal).then(function () {
|
|
792
899
|
if (!window.sceneview || typeof window.sceneview.threeMfToGlb !== "function") {
|
|
793
900
|
throw new Error("the 3MF converter did not load");
|
|
794
901
|
}
|
|
@@ -801,86 +908,246 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
801
908
|
return URL.createObjectURL(new Blob([glb], { type: "model/gltf-binary" }));
|
|
802
909
|
});
|
|
803
910
|
});
|
|
911
|
+
return deadline(download, 15000, "The model download timed out.", function () { controller.abort(); });
|
|
804
912
|
}
|
|
805
913
|
|
|
806
|
-
function start(data) {
|
|
807
|
-
|
|
808
|
-
resolveModelUrl(data.modelUrl
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
914
|
+
async function start(data, controller) {
|
|
915
|
+
var signal = controller.signal;
|
|
916
|
+
var url = await resolveModelUrl(data.modelUrl, controller);
|
|
917
|
+
try {
|
|
918
|
+
if (pending !== data || disposed) return;
|
|
919
|
+
try { await startWith(data, url, signal); }
|
|
920
|
+
catch (err) {
|
|
921
|
+
if (err && err.name === "AbortError") return;
|
|
922
|
+
if (pending !== data || disposed) return;
|
|
923
|
+
if (rendererKind !== "filament") throw err;
|
|
924
|
+
// WASM compilation can succeed while Filament's initialization fails.
|
|
925
|
+
// Keep a fresh WebGL context for the fallback in that case.
|
|
926
|
+
console.warn("SceneView: Filament failed; trying the WASM-free renderer.", err);
|
|
927
|
+
await useFallback();
|
|
928
|
+
resetCanvas();
|
|
929
|
+
await startWith(data, url, signal);
|
|
930
|
+
}
|
|
931
|
+
} finally {
|
|
932
|
+
if (url !== data.modelUrl && url.indexOf("blob:") === 0) URL.revokeObjectURL(url);
|
|
933
|
+
}
|
|
812
934
|
}
|
|
813
935
|
|
|
814
|
-
function
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
936
|
+
function deadline(promise, ms, message, onTimeout) {
|
|
937
|
+
return new Promise(function (resolve, reject) {
|
|
938
|
+
var timer = setTimeout(function () {
|
|
939
|
+
reject(new Error(message));
|
|
940
|
+
if (onTimeout) onTimeout();
|
|
941
|
+
}, ms);
|
|
942
|
+
Promise.resolve(promise).then(function (value) {
|
|
943
|
+
clearTimeout(timer); resolve(value);
|
|
944
|
+
}, function (error) { clearTimeout(timer); reject(error); });
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
function abortError() {
|
|
949
|
+
var error = new Error("The model load was superseded.");
|
|
950
|
+
error.name = "AbortError";
|
|
951
|
+
return error;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
function abortable(promise, signal) {
|
|
955
|
+
if (!signal) return Promise.resolve(promise);
|
|
956
|
+
if (signal.aborted) return Promise.reject(abortError());
|
|
957
|
+
return new Promise(function (resolve, reject) {
|
|
958
|
+
function cleanup() { signal.removeEventListener("abort", onAbort); }
|
|
959
|
+
function onAbort() { cleanup(); reject(abortError()); }
|
|
960
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
961
|
+
Promise.resolve(promise).then(function (value) {
|
|
962
|
+
cleanup(); resolve(value);
|
|
963
|
+
}, function (error) { cleanup(); reject(error); });
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
function createViewer(data, signal) {
|
|
968
|
+
if (viewer) return Promise.resolve(viewer);
|
|
969
|
+
var kind = rendererKind;
|
|
970
|
+
var targetCanvas = canvas;
|
|
971
|
+
var record = viewerCreation;
|
|
972
|
+
if (!record || record.kind !== kind || record.canvas !== targetCanvas) {
|
|
973
|
+
var factory = kind === "filament" ? window.SceneView : window.SceneViewFallback;
|
|
974
|
+
record = { kind: kind, canvas: targetCanvas, promise: null };
|
|
975
|
+
record.promise = Promise.resolve(factory.create(targetCanvas, {
|
|
976
|
+
backgroundColor: [0, 0, 0, 0],
|
|
977
|
+
lightIntensity: 150000,
|
|
978
|
+
autoRotate: data.autoRotate !== false && !reducedMotion && !interacted,
|
|
979
|
+
studio: {
|
|
980
|
+
theme: "dark", environment: IBL_URL, shadow: 0.9, reflection: 0.08,
|
|
981
|
+
top: "#0b0f16", horizon: "#0b0f16", floor: "#111722", pool: "#232d40",
|
|
982
|
+
},
|
|
983
|
+
fov: 35,
|
|
984
|
+
iblUrl: IBL_URL,
|
|
985
|
+
})).then(function (value) {
|
|
986
|
+
if (disposed || viewerCreation !== record || canvas !== targetCanvas || rendererKind !== kind) {
|
|
987
|
+
value.dispose(); return null;
|
|
988
|
+
}
|
|
989
|
+
viewer = value;
|
|
990
|
+
return value;
|
|
991
|
+
}, function (error) {
|
|
992
|
+
if (viewerCreation === record) viewerCreation = null;
|
|
993
|
+
throw error;
|
|
821
994
|
});
|
|
822
|
-
|
|
995
|
+
viewerCreation = record;
|
|
823
996
|
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
997
|
+
return abortable(deadline(record.promise, 30000, "The renderer took too long to start. Try the AR link."), signal)
|
|
998
|
+
.catch(function (error) {
|
|
999
|
+
if ((!error || error.name !== "AbortError") && viewerCreation === record) viewerCreation = null;
|
|
1000
|
+
throw error;
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
async function startWith(data, url, signal) {
|
|
1005
|
+
var instance = await createViewer(data, signal);
|
|
1006
|
+
if (!instance) throw abortError();
|
|
1007
|
+
await abortable(
|
|
1008
|
+
deadline(instance.loadModel(url), 30000, "The model took too long to load. Try the AR link."),
|
|
1009
|
+
signal
|
|
1010
|
+
);
|
|
1011
|
+
if (pending === data && !disposed) {
|
|
1012
|
+
framePreview();
|
|
1013
|
+
updateRealSize();
|
|
834
1014
|
reveal(data);
|
|
835
|
-
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
function framePreview() {
|
|
1019
|
+
if (!viewer || interacted) return;
|
|
1020
|
+
if (viewer.frameModel) viewer.frameModel({ fill: rendererKind === "filament" ? 0.9 : 0.8 });
|
|
1021
|
+
if (viewer.getCameraOrbit && viewer.setCameraOrbit) {
|
|
1022
|
+
var orbit = viewer.getCameraOrbit();
|
|
1023
|
+
// The swept box has empty corners above rounded models: a 90% height
|
|
1024
|
+
// envelope puts the visible Astronaut at about 80%. Keep the swept width
|
|
1025
|
+
// at 80% independently, including on portrait canvases and during orbit.
|
|
1026
|
+
var radius = orbit.radius;
|
|
1027
|
+
if (viewer._asset && viewer._assetBox) {
|
|
1028
|
+
var box = viewer._assetBox(viewer._asset);
|
|
1029
|
+
var sweep = Math.hypot(box.max[0] - box.min[0], box.max[2] - box.min[2]) / 2;
|
|
1030
|
+
var aspect = canvas.clientWidth / Math.max(1, canvas.clientHeight);
|
|
1031
|
+
var tangent = 0.8 * Math.tan((orbit.fov || 35) * Math.PI / 360) * aspect;
|
|
1032
|
+
radius = Math.max(radius, sweep * Math.sqrt(1 + 1 / (tangent * tangent)));
|
|
1033
|
+
}
|
|
1034
|
+
// Keep the renderer's front-facing three-quarter angle.
|
|
1035
|
+
viewer.setCameraOrbit({ radius: radius, height: orbit.target[1] + radius * 0.12 });
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
var frameObserver = typeof ResizeObserver === "function" ? new ResizeObserver(function () {
|
|
1039
|
+
if (!pending) framePreview();
|
|
1040
|
+
}) : null;
|
|
1041
|
+
if (frameObserver) frameObserver.observe(canvasWrap);
|
|
1042
|
+
|
|
1043
|
+
function updateRealSize() {
|
|
1044
|
+
sizeEl.hidden = true;
|
|
1045
|
+
try {
|
|
1046
|
+
var size;
|
|
1047
|
+
if (viewer.getModelSize) size = viewer.getModelSize();
|
|
1048
|
+
// sceneview.js exposes corrected glTF bounds internally, including quantized
|
|
1049
|
+
// positions. Keep this optional: older website builds omit the readout safely.
|
|
1050
|
+
else if (viewer._asset && viewer._assetBox) {
|
|
1051
|
+
var box = viewer._assetBox(viewer._asset);
|
|
1052
|
+
size = [0, 1, 2].map(function (axis) { return box.max[axis] - box.min[axis]; });
|
|
1053
|
+
}
|
|
1054
|
+
// glTF units are metres; reject degenerate, microscopic and building-scale
|
|
1055
|
+
// boxes. This is a scale plausibility check, never a measurement guarantee.
|
|
1056
|
+
if (!size || size.some(function (v) { return !Number.isFinite(v) || v < 0.001 || v > 20; }) || size[1] < 0.01) return;
|
|
1057
|
+
var height = size[1];
|
|
1058
|
+
sizeEl.textContent = "≈ " + (height < 1 ? Math.round(height * 100) + " cm" : Number(height.toFixed(1)) + " m") + " tall";
|
|
1059
|
+
sizeEl.hidden = false;
|
|
1060
|
+
} catch (e) { /* optional readout */ }
|
|
836
1061
|
}
|
|
837
1062
|
|
|
838
1063
|
function reveal(data) {
|
|
839
1064
|
rendered = data;
|
|
840
1065
|
pending = null;
|
|
841
1066
|
loader.hidden = true;
|
|
842
|
-
// An error an earlier payload left must not sit over the model that loaded.
|
|
843
1067
|
errorEl.hidden = true;
|
|
844
1068
|
canvas.style.opacity = "1";
|
|
845
|
-
if (data.autoRotate
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
}
|
|
1069
|
+
if (viewer && viewer.setAutoRotate) viewer.setAutoRotate(data.autoRotate !== false && !reducedMotion && !interacted);
|
|
1070
|
+
document.documentElement.dataset.renderer = rendererKind;
|
|
1071
|
+
document.getElementById("engine").textContent = rendererKind === "filament"
|
|
1072
|
+
? "Interactive 3D" : "Compatibility preview";
|
|
850
1073
|
notifyReady();
|
|
851
1074
|
}
|
|
852
1075
|
|
|
853
1076
|
function fail(err) {
|
|
854
1077
|
pending = null;
|
|
1078
|
+
rendered = null;
|
|
1079
|
+
// Fallback disposal loses its WebGL context, including when the factory
|
|
1080
|
+
// rejects before assigning viewer. Never retry on that canvas.
|
|
1081
|
+
if (rendererKind === "fallback") resetCanvas();
|
|
1082
|
+
else if (viewer) { viewer.dispose(); viewer = null; }
|
|
855
1083
|
showError((err && err.message) || String(err));
|
|
856
1084
|
}
|
|
857
1085
|
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
1086
|
+
function resetCanvas() {
|
|
1087
|
+
viewerCreation = null;
|
|
1088
|
+
if (viewer) { viewer.dispose(); viewer = null; }
|
|
1089
|
+
// Filament can insert overlays before a viewer exists, so dispose alone
|
|
1090
|
+
// cannot remove them. Both initialization and load failures use this class.
|
|
1091
|
+
canvasWrap.querySelectorAll(".sceneview-fallback").forEach(function (overlay) { overlay.remove(); });
|
|
1092
|
+
var replacement = canvas.cloneNode(false);
|
|
1093
|
+
replacement.style.opacity = "0";
|
|
1094
|
+
canvas.replaceWith(replacement);
|
|
1095
|
+
canvas = replacement;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
function loadScript(url) {
|
|
1099
|
+
return deadline(new Promise(function (resolve, reject) {
|
|
1100
|
+
var script = document.createElement("script");
|
|
1101
|
+
script.src = url;
|
|
1102
|
+
script.onload = resolve;
|
|
1103
|
+
script.onerror = function () { reject(new Error("Could not load " + url)); };
|
|
1104
|
+
document.head.appendChild(script);
|
|
1105
|
+
}), 15000, "The renderer download timed out.");
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
var fallbackScriptPromise = null;
|
|
1109
|
+
async function useFallback() {
|
|
1110
|
+
if (!fallbackScriptPromise) fallbackScriptPromise = loadScript(FALLBACK_URL).catch(function (error) {
|
|
1111
|
+
fallbackScriptPromise = null;
|
|
1112
|
+
throw error;
|
|
1113
|
+
});
|
|
1114
|
+
await fallbackScriptPromise;
|
|
1115
|
+
if (!window.SceneViewFallback || !window.SceneViewFallback.create) throw new Error("This host could not start the 3D renderer. Use the AR link below.");
|
|
1116
|
+
rendererKind = "fallback";
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
function chooseRenderer() {
|
|
1120
|
+
if (!rendererPromise) rendererPromise = (async function () {
|
|
1121
|
+
try {
|
|
1122
|
+
// A valid, empty WASM module tests the actual iframe policy, without
|
|
1123
|
+
// a network request, eval(), or an invented CSP metadata permission.
|
|
1124
|
+
await WebAssembly.compile(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0]));
|
|
1125
|
+
await loadScript(FILAMENT_URL);
|
|
1126
|
+
await loadScript(SCENEVIEW_URL);
|
|
1127
|
+
if (!window.SceneView || !window.SceneView.create) throw new Error("SceneView.js did not initialize.");
|
|
1128
|
+
rendererKind = "filament";
|
|
1129
|
+
} catch (error) {
|
|
1130
|
+
console.info("SceneView: using the WASM-free renderer because Filament is unavailable.", error);
|
|
1131
|
+
await useFallback();
|
|
880
1132
|
}
|
|
881
|
-
}
|
|
1133
|
+
})().catch(function (error) {
|
|
1134
|
+
rendererPromise = null;
|
|
1135
|
+
throw error;
|
|
1136
|
+
});
|
|
1137
|
+
return rendererPromise;
|
|
882
1138
|
}
|
|
883
1139
|
|
|
1140
|
+
function dispose() {
|
|
1141
|
+
disposed = true;
|
|
1142
|
+
pending = null;
|
|
1143
|
+
if (loadController) { loadController.abort(); loadController = null; }
|
|
1144
|
+
viewerCreation = null;
|
|
1145
|
+
if (frameObserver) frameObserver.disconnect();
|
|
1146
|
+
${space ? "if (spaceObserver) spaceObserver.disconnect();" : ""}
|
|
1147
|
+
if (viewer) { viewer.dispose(); viewer = null; }
|
|
1148
|
+
}
|
|
1149
|
+
window.addEventListener("pagehide", dispose);
|
|
1150
|
+
|
|
884
1151
|
// ── Boot ─────────────────────────────────────────────────────────────
|
|
885
1152
|
var initial = fromOpenAI() || fromQuery();
|
|
886
1153
|
if (initial) {
|
|
@@ -896,12 +1163,20 @@ export const WIDGET_3D_VIEWER_HTML = `<!DOCTYPE html>
|
|
|
896
1163
|
</script>
|
|
897
1164
|
</body>
|
|
898
1165
|
</html>`;
|
|
1166
|
+
}
|
|
1167
|
+
export const WIDGET_3D_VIEWER_HTML = buildWidgetHtml(false);
|
|
1168
|
+
export const WIDGET_SHOW_IN_SPACE_HTML = buildWidgetHtml(true);
|
|
899
1169
|
const WIDGETS = {
|
|
900
1170
|
[WIDGET_3D_VIEWER_URI]: {
|
|
901
1171
|
name: "SceneView 3D Viewer",
|
|
902
1172
|
description: "MCP Apps widget: interactive SceneView.js + Filament.js viewer for a GLB / glTF model, rendered inline by the host when `view_3d_model` is called.",
|
|
903
1173
|
html: WIDGET_3D_VIEWER_HTML,
|
|
904
1174
|
},
|
|
1175
|
+
[WIDGET_SHOW_IN_SPACE_URI]: {
|
|
1176
|
+
name: "SceneView · Show in space",
|
|
1177
|
+
description: "Dimensioned size preview with a human reference and a phone link to the SceneView app.",
|
|
1178
|
+
html: WIDGET_SHOW_IN_SPACE_HTML,
|
|
1179
|
+
},
|
|
905
1180
|
};
|
|
906
1181
|
/** Every widget resource, in `resources/list` shape. */
|
|
907
1182
|
export function listWidgetResources() {
|