Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(3d-diff): put the GLB structural diff on a page

nirholas3eed2a2aa007
diff --git a/pages/diff.html b/pages/diff.html
new file mode 100644
index 000000000..849b8de9d
--- /dev/null
+++ b/pages/diff.html
@@ -0,0 +1,197 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <script>/* three.ws theme boot - no-flash; runtime in /theme-switcher.js */(function(){try{var m=localStorage.getItem('twx_theme');var l=m==='auto'?(window.matchMedia&&window.matchMedia('(prefers-color-scheme: light)').matches):m==='light';document.documentElement.setAttribute('data-theme',l?'light':'dark');}catch(e){document.documentElement.setAttribute('data-theme','dark');}})();</script>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>Model Diff &middot; What changed between two 3D models &middot; three.ws</title>
+ <meta
+ name="description"
+ content="Drop two .glb files and see exactly what changed: geometry, materials, textures, skeletons, and animation clips, with git-style rename and move detection and a severity you can gate a build on. Runs in your browser, nothing is uploaded."
+ />
+ <meta name="theme-color" content="#000000" />
+
+ <meta property="og:type" content="website" />
+ <meta property="og:site_name" content="three.ws" />
+ <meta property="og:title" content="Model Diff &middot; git diff for 3D" />
+ <meta
+ property="og:description"
+ content="Two models in, one change set out: what moved, what was renamed, which joints disappeared, and whether anything downstream just broke."
+ />
+ <meta property="og:url" content="https://three.ws/diff" />
+ <meta property="og:image" content="https://three.ws/api/page-og?s=build&amp;t=Model+Diff&amp;d=Drop+two+.glb+files+and+see+exactly+what+changed%3A+geometry%2C+materials%2C+skeletons%2C+and+clips%2C+with+rename+detection+and+a+severity+you+can+gate+CI+on&amp;p=%2Fdiff" />
+ <meta name="twitter:card" content="summary_large_image" />
+ <meta name="twitter:title" content="Model Diff &middot; three.ws" />
+ <meta name="twitter:description" content="git diff for 3D. Two models in, one change set out. Runs in your browser." />
+ <meta name="twitter:site" content="@trythreews" />
+ <meta name="twitter:image" content="https://three.ws/api/page-og?s=build&amp;t=Model+Diff&amp;d=Drop+two+.glb+files+and+see+exactly+what+changed%3A+geometry%2C+materials%2C+skeletons%2C+and+clips%2C+with+rename+detection+and+a+severity+you+can+gate+CI+on&amp;p=%2Fdiff" />
+ <meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1" />
+ <meta property="og:locale" content="en_US" />
+ <meta property="og:image:alt" content="Model Diff - three.ws" />
+
+ <link rel="canonical" href="https://three.ws/diff" />
+ <link rel="icon" href="/favicon.ico" sizes="any" />
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
+ <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
+ <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
+ <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
+ <link rel="manifest" href="/manifest.webmanifest" />
+ <link rel="stylesheet" href="/style.css" />
+ <link rel="stylesheet" href="/nav.css" />
+ <link rel="stylesheet" href="/footer.css" />
+ <link rel="stylesheet" href="/fonts/fonts.css" />
+ <link rel="stylesheet" href="/mobile.css" />
+ <link rel="stylesheet" href="/model-diff.css" />
+ <script defer src="/footer-newsletter.js"></script>
+
+ <script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@type":"WebApplication","name":"Model Diff","description":"Compare two glTF/GLB models in the browser. Reports geometry, material, texture, skeleton, and animation changes with git-style rename and move detection, and a severity you can gate a build on.","url":"https://three.ws/diff","applicationCategory":"DeveloperApplication","operatingSystem":"Any","browserRequirements":"Requires WebGL2","offers":{"@type":"Offer","price":"0","priceCurrency":"USD"},"isPartOf":{"@type":"WebSite","name":"three.ws","url":"https://three.ws"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Are my models uploaded anywhere?","acceptedAnswer":{"@type":"Answer","text":"Files you drop are read with the browser File API and compared on your machine. Nothing is sent to a server. Models given as URLs are fetched through the same-origin proxy at /api/glb so cross-origin CORS policies cannot block the comparison."}},{"@type":"Question","name":"Why does a re-export show as unchanged?","acceptedAnswer":{"@type":"Answer","text":"Vertex data is compared with a tolerance of 1e-4 units, so the float noise a re-export or a lossless recompression introduces does not register, while a genuine edit does. Objects are matched by name first, then by content hash, then by similarity, which is how a renamed mesh reads as a rename instead of a deletion plus an unrelated addition."}},{"@type":"Question","name":"What makes a change breaking?","acceptedAnswer":{"@type":"Answer","text":"Anything a consumer references by name that is now gone: a removed animation clip, a removed skeleton joint, a removed mesh. Clips address joints by name, so a dropped joint is a silent no-op at runtime rather than an error anyone sees, which is the most expensive failure in a 3D pipeline."}},{"@type":"Question","name":"Can I run this in CI?","acceptedAnswer":{"@type":"Answer","text":"Yes. npx @three-ws/glb-diff before.glb after.glb --fail-on breaking exits 1 when the severity reaches the threshold, or call GET /api/3d/diff?a=&b= which is free and keyless and can return a Markdown report for a pull-request comment."}}]}]}</script>
+ </head>
+ <body>
+ <header><div id="nav-container"></div></header>
+
+ <main>
+ <section class="dx-hero">
+ <span class="dx-badge"><span class="dx-badge-dot" aria-hidden="true"></span>Runs in your browser</span>
+ <h1 class="dx-title">What actually changed between these two models?</h1>
+ <p class="dx-sub">
+ A checksum says two files differ. It cannot tell a lossless recompression from a
+ rig that quietly lost three finger joints, and only one of those takes your
+ avatar off the screen. Drop a <code>.glb</code> on each side and get the change
+ set: geometry, materials, textures, skeletons, and clips, with renames and moves
+ detected the way <code>git</code> detects them.
+ </p>
+ </section>
+
+ <section class="dx-inputs" aria-label="Choose two models">
+ <div class="dx-slot" id="dx-slot-a" data-state="idle">
+ <div class="dx-slot-head">
+ <span class="dx-slot-role">Before</span>
+ <span class="dx-slot-meta" id="dx-meta-a"></span>
+ </div>
+ <label class="dx-drop" id="dx-drop-a">
+ <input type="file" id="dx-file-a" accept=".glb,.gltf,model/gltf-binary,model/gltf+json" />
+ <span class="dx-slot-name" id="dx-name-a">Drop the baseline .glb</span>
+ <span class="dx-row-detail">or click to choose. Nothing is uploaded.</span>
+ </label>
+ <div class="dx-url-row">
+ <input type="url" class="dx-url" id="dx-url-a" placeholder="https://.../before.glb" aria-label="Baseline model URL" spellcheck="false" />
+ <button type="button" class="dx-btn" id="dx-load-a">Load</button>
+ </div>
+ <p class="dx-slot-error" id="dx-error-a" hidden></p>
+ </div>
+
+ <button type="button" class="dx-swap" id="dx-swap" title="Swap the two models" aria-label="Swap the two models">
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden="true">
+ <path d="M7 4 4 7l3 3" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" />
+ <path d="M4 7h13a3 3 0 0 1 3 3" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" />
+ <path d="m17 20 3-3-3-3" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" />
+ <path d="M20 17H7a3 3 0 0 1-3-3" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" />
+ </svg>
+ </button>
+
+ <div class="dx-slot" id="dx-slot-b" data-state="idle">
+ <div class="dx-slot-head">
+ <span class="dx-slot-role">After</span>
+ <span class="dx-slot-meta" id="dx-meta-b"></span>
+ </div>
+ <label class="dx-drop" id="dx-drop-b">
+ <input type="file" id="dx-file-b" accept=".glb,.gltf,model/gltf-binary,model/gltf+json" />
+ <span class="dx-slot-name" id="dx-name-b">Drop the candidate .glb</span>
+ <span class="dx-row-detail">or click to choose. Nothing is uploaded.</span>
+ </label>
+ <div class="dx-url-row">
+ <input type="url" class="dx-url" id="dx-url-b" placeholder="https://.../after.glb" aria-label="Candidate model URL" spellcheck="false" />
+ <button type="button" class="dx-btn" id="dx-load-b">Load</button>
+ </div>
+ <p class="dx-slot-error" id="dx-error-b" hidden></p>
+ </div>
+ </section>
+
+ <section class="dx-examples" id="dx-examples" aria-label="Example comparisons">
+ <span class="dx-examples-label">No files handy?</span>
+ </section>
+
+ <section class="dx-workbench">
+ <div class="dx-stage-card">
+ <div class="dx-stage" id="dx-stage">
+ <div class="dx-stage-empty" id="dx-stage-empty">
+ <strong>Both models render here</strong>
+ <span>Overlay the after on top of the before, wipe between them, or set them side by side.</span>
+ </div>
+ </div>
+ <div class="dx-stage-bar" id="dx-stage-bar" hidden>
+ <div class="dx-seg" role="group" aria-label="Comparison mode">
+ <button type="button" data-mode="overlay" aria-pressed="true">Overlay</button>
+ <button type="button" data-mode="wipe" aria-pressed="false">Wipe</button>
+ <button type="button" data-mode="split" aria-pressed="false">Side by side</button>
+ </div>
+ <label class="dx-toggle"><input type="checkbox" id="dx-highlight" checked /> Highlight changes</label>
+ <label class="dx-toggle" id="dx-play-wrap" hidden><input type="checkbox" id="dx-play" /> Play clips</label>
+ <input type="range" class="dx-wipe" id="dx-wipe" min="0" max="100" value="50" aria-label="Wipe position" hidden />
+ </div>
+ <div class="dx-legend" id="dx-legend" hidden>
+ <span><i style="background: #60a5fa"></i> before</span>
+ <span><i style="background: #e8e8e8"></i> after</span>
+ <span><i style="background: #fbbf24"></i> changed</span>
+ <span><i style="background: #4ade80"></i> added</span>
+ <span><i style="background: #f87171"></i> removed</span>
+ </div>
+ </div>
+
+ <div class="dx-report" id="dx-report">
+ <div class="dx-card">
+ <div class="dx-empty">
+ <strong>Load two models</strong>
+ Drop a file on each side, paste two URLs, or pick one of the example pairs
+ above. The comparison runs on your machine.
+ </div>
+ </div>
+ </div>
+ </section>
+
+ <section class="dx-explain">
+ <h2>How it decides</h2>
+ <article>
+ <h3>Renames, not churn</h3>
+ <p>
+ Objects are matched by name, then by content hash, then by similarity, the
+ same three-tier strategy git uses for file renames. An exporter that
+ renumbers <code>Mesh.001</code> reads as a rename, not as a rewrite.
+ </p>
+ </article>
+ <article>
+ <h3>Tolerant on noise, strict on edits</h3>
+ <p>
+ Vertex data is compared at a quantum of 1e-4 units, so the float drift a
+ re-export or a Draco round trip introduces does not register while a genuine
+ edit does.
+ </p>
+ </article>
+ <article>
+ <h3>Severity you can gate on</h3>
+ <p>
+ <code>none</code>, <code>cosmetic</code>, <code>minor</code>,
+ <code>major</code>, <code>breaking</code>. Breaking means something a
+ consumer references by name is gone: a clip, a joint, a mesh. That is the
+ failure that renders fine and never moves.
+ </p>
+ </article>
+ <article>
+ <h3>Same engine everywhere</h3>
+ <p>
+ This page, the <code>glb-diff</code> CLI, and
+ <a href="/docs/model-diff">the free API</a> all run
+ <a href="https://www.npmjs.com/package/@three-ws/glb-diff">@three-ws/glb-diff</a>,
+ so a verdict in CI can never disagree with what you see here.
+ </p>
+ </article>
+ </section>
+ </main>
+
+ <script src="/nav.js" defer></script>
+ <script type="module" src="/src/model-diff.js"></script>
+ <script src="/brand.js" defer></script>
+ <script src="/footer.js"></script>
+ <script type="module" src="/i18n.js"></script>
+ </body>
+</html>
diff --git a/public/model-diff.css b/public/model-diff.css
new file mode 100644
index 000000000..dd41cc252
--- /dev/null
+++ b/public/model-diff.css
@@ -0,0 +1,609 @@
+/* Model Diff (/diff)
+ *
+ * Built on the tokens in /tokens.css, so the light theme comes free: nothing
+ * here hardcodes a colour the light-theme block cannot swap. The five severity
+ * colours are the exception and they are the token set's own --success /
+ * --warn / --danger plus two neutrals.
+ *
+ * Class prefix `dx-` throughout (diff explorer), so this file can never collide
+ * with the shared nav, footer, or mobile stylesheets loaded alongside it.
+ */
+
+.dx-hero,
+.dx-workbench,
+.dx-explain {
+ --dx-max: 1320px;
+}
+
+.dx-sr-only {
+ position: absolute;
+ width: 1px;
+ height: 1px;
+ padding: 0;
+ margin: -1px;
+ overflow: hidden;
+ clip: rect(0 0 0 0);
+ white-space: nowrap;
+ border: 0;
+}
+
+/* Severity palette. One place, used by the banner, the chips, and the rows. */
+.dx-sev-none { --dx-sev: var(--ink-dim); }
+.dx-sev-cosmetic { --dx-sev: var(--ink-dim); }
+.dx-sev-minor { --dx-sev: #60a5fa; }
+.dx-sev-major { --dx-sev: var(--warn); }
+.dx-sev-breaking { --dx-sev: var(--danger); }
+
+/* ── Hero ───────────────────────────────────────────────────────────────── */
+
+.dx-hero {
+ position: relative;
+ padding: clamp(var(--space-lg), 5vw, var(--space-xl)) var(--space-lg) var(--space-md);
+ max-width: var(--dx-max);
+ margin: 0 auto;
+}
+
+.dx-badge {
+ display: inline-flex;
+ align-items: center;
+ gap: var(--space-xs);
+ font: var(--weight-medium) var(--text-2xs) / 1 var(--font-body);
+ letter-spacing: 0.06em;
+ text-transform: uppercase;
+ color: var(--ink-faint);
+ background: var(--surface-1);
+ border: 1px solid var(--hairline);
+ border-radius: var(--radius-pill);
+ padding: var(--space-xs) var(--space-sm);
+}
+
+.dx-badge-dot {
+ width: 6px;
+ height: 6px;
+ border-radius: 50%;
+ background: var(--success);
+ box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.15);
+}
+
+.dx-title {
+ font: var(--weight-bold) clamp(1.9rem, 4.5vw, var(--text-2xl)) / var(--leading-tight) var(--font-display);
+ letter-spacing: -0.02em;
+ margin: var(--space-md) 0 var(--space-sm);
+}
+
+.dx-sub {
+ color: var(--ink-faint);
+ font-size: var(--text-base);
+ line-height: var(--leading-normal);
+ max-width: 68ch;
+ margin: 0;
+}
+
+.dx-sub code {
+ font-family: var(--font-mono);
+ font-size: 0.92em;
+ background: var(--surface-2);
+ border: 1px solid var(--hairline);
+ border-radius: var(--radius-sm);
+ padding: 0.08em 0.35em;
+}
+
+/* ── Inputs ─────────────────────────────────────────────────────────────── */
+
+.dx-inputs {
+ max-width: var(--dx-max);
+ margin: 0 auto;
+ padding: var(--space-md) var(--space-lg) 0;
+ display: grid;
+ grid-template-columns: 1fr auto 1fr;
+ gap: var(--space-md);
+ align-items: stretch;
+}
+
+.dx-swap {
+ align-self: center;
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 38px;
+ height: 38px;
+ border-radius: 50%;
+ border: 1px solid var(--stroke);
+ background: var(--surface-1);
+ color: var(--ink-dim);
+ cursor: pointer;
+ transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
+}
+
+.dx-swap:hover { color: var(--ink); border-color: var(--stroke-strong); background: var(--surface-2); }
+.dx-swap:active { transform: scale(0.94); }
+
+.dx-slot {
+ position: relative;
+ display: flex;
+ flex-direction: column;
+ gap: var(--space-sm);
+ background: var(--surface-1);
+ border: 1px solid var(--hairline);
+ border-radius: var(--radius-lg);
+ padding: var(--space-md);
+ transition: border-color 0.18s ease, background 0.18s ease;
+}
+
+.dx-slot[data-state='dragging'] {
+ border-color: var(--stroke-strong);
+ background: var(--surface-2);
+}
+
+.dx-slot[data-state='loaded'] { border-color: var(--stroke); }
+.dx-slot[data-state='error'] { border-color: color-mix(in srgb, var(--danger) 55%, transparent); }
+
+.dx-slot-head {
+ display: flex;
+ align-items: baseline;
+ justify-content: space-between;
+ gap: var(--space-sm);
+}
+
+.dx-slot-role {
+ font: var(--weight-semibold) var(--text-2xs) / 1 var(--font-body);
+ letter-spacing: 0.1em;
+ text-transform: uppercase;
+ color: var(--ink-dim);
+}
+
+.dx-slot-name {
+ font: var(--weight-medium) var(--text-md) / 1.3 var(--font-mono);
+ color: var(--ink);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ max-width: 100%;
+}
+
+.dx-slot-meta { font-size: var(--text-sm); color: var(--ink-dim); }
+
+.dx-drop {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: var(--space-2xs);
+ min-height: 84px;
+ border: 1px dashed var(--stroke);
+ border-radius: var(--radius-md);
+ background: transparent;
+ color: var(--ink-dim);
+ font-size: var(--text-sm);
+ cursor: pointer;
+ text-align: center;
+ padding: var(--space-sm);
+ transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
+}
+
+.dx-drop:hover { border-color: var(--stroke-strong); color: var(--ink); background: var(--surface-1); }
+.dx-drop:focus-within { outline: 2px solid var(--accent-soft); outline-offset: 2px; }
+.dx-drop input[type='file'] { position: absolute; opacity: 0; width: 0; height: 0; }
+
+.dx-url-row { display: flex; gap: var(--space-xs); }
+
+.dx-url {
+ flex: 1;
+ min-width: 0;
+ background: var(--surface-2);
+ border: 1px solid var(--hairline);
+ border-radius: var(--radius-md);
+ color: var(--ink);
+ font: var(--weight-regular) var(--text-sm) / 1.4 var(--font-mono);
+ padding: var(--space-sm);
+ transition: border-color 0.15s ease;
+}
+
+.dx-url:focus { outline: none; border-color: var(--stroke-strong); }
+.dx-url::placeholder { color: var(--ink-dim); }
+
+.dx-btn {
+ appearance: none;
+ border: 1px solid var(--stroke);
+ background: var(--surface-2);
+ color: var(--ink);
+ border-radius: var(--radius-md);
+ font: var(--weight-medium) var(--text-sm) / 1 var(--font-body);
+ padding: var(--space-sm) var(--space-md);
+ cursor: pointer;
+ transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
+ white-space: nowrap;
+}
+
+.dx-btn:hover { background: var(--surface-3); border-color: var(--stroke-strong); }
+.dx-btn:active { transform: translateY(1px); }
+.dx-btn:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }
+.dx-btn[disabled] { opacity: 0.45; cursor: not-allowed; }
+.dx-btn.is-primary { background: var(--ink); color: var(--bg-0); border-color: var(--ink); }
+.dx-btn.is-primary:hover { background: var(--ink-bright); }
+
+.dx-slot-error {
+ color: var(--danger);
+ font-size: var(--text-sm);
+ line-height: var(--leading-tight);
+}
+
+/* ── Example pairs ──────────────────────────────────────────────────────── */
+
+.dx-examples {
+ max-width: var(--dx-max);
+ margin: 0 auto;
+ padding: var(--space-md) var(--space-lg) 0;
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: var(--space-xs);
+}
+
+.dx-examples-label { font-size: var(--text-sm); color: var(--ink-dim); margin-right: var(--space-2xs); }
+
+.dx-example {
+ appearance: none;
+ border: 1px solid var(--hairline);
+ background: var(--surface-1);
+ color: var(--ink-faint);
+ border-radius: var(--radius-pill);
+ font: var(--weight-medium) var(--text-sm) / 1 var(--font-body);
+ padding: var(--space-sm) var(--space-md);
+ cursor: pointer;
+ transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
+}
+
+.dx-example:hover { color: var(--ink); border-color: var(--stroke-strong); background: var(--surface-2); }
+.dx-example:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }
+
+/* ── Workbench ──────────────────────────────────────────────────────────── */
+
+.dx-workbench {
+ max-width: var(--dx-max);
+ margin: 0 auto;
+ padding: var(--space-lg) var(--space-lg) var(--space-2xl);
+ display: grid;
+ grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
+ gap: var(--space-lg);
+ align-items: start;
+}
+
+.dx-stage-card {
+ position: relative;
+ background: var(--surface-1);
+ border: 1px solid var(--hairline);
+ border-radius: var(--radius-lg);
+ overflow: hidden;
+ position: sticky;
+ top: calc(var(--header-h) + var(--space-sm));
+}
+
+.dx-stage {
+ position: relative;
+ width: 100%;
+ aspect-ratio: 4 / 3;
+ min-height: 320px;
+ background:
+ radial-gradient(120% 90% at 50% 0%, rgba(255, 255, 255, 0.05), transparent 70%),
+ var(--bg-0);
+}
+
+.dx-stage canvas { display: block; width: 100%; height: 100%; }
+
+.dx-stage-empty {
+ position: absolute;
+ inset: 0;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: var(--space-xs);
+ color: var(--ink-dim);
+ font-size: var(--text-sm);
+ text-align: center;
+ padding: var(--space-lg);
+}
+
+.dx-stage-bar {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: var(--space-xs);
+ padding: var(--space-sm) var(--space-md);
+ border-top: 1px solid var(--hairline);
+ background: var(--surface-1);
+}
+
+.dx-seg {
+ display: inline-flex;
+ border: 1px solid var(--hairline);
+ border-radius: var(--radius-pill);
+ overflow: hidden;
+ background: var(--surface-2);
+}
+
+.dx-seg button {
+ appearance: none;
+ border: 0;
+ background: transparent;
+ color: var(--ink-dim);
+ font: var(--weight-medium) var(--text-sm) / 1 var(--font-body);
+ padding: var(--space-sm) var(--space-md);
+ cursor: pointer;
+ transition: background 0.15s ease, color 0.15s ease;
+}
+
+.dx-seg button:hover { color: var(--ink); }
+.dx-seg button[aria-pressed='true'] { background: var(--surface-3); color: var(--ink); }
+.dx-seg button:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: -2px; }
+
+.dx-toggle {
+ display: inline-flex;
+ align-items: center;
+ gap: var(--space-xs);
+ font-size: var(--text-sm);
+ color: var(--ink-faint);
+ cursor: pointer;
+ user-select: none;
+}
+
+.dx-toggle input { accent-color: var(--ink); cursor: pointer; }
+
+.dx-wipe {
+ flex: 1;
+ min-width: 120px;
+ accent-color: var(--ink);
+ cursor: ew-resize;
+}
+
+.dx-legend {
+ display: flex;
+ gap: var(--space-md);
+ padding: var(--space-sm) var(--space-md);
+ border-top: 1px solid var(--hairline);
+ font-size: var(--text-2xs);
+ color: var(--ink-dim);
+ flex-wrap: wrap;
+}
+
+.dx-legend span { display: inline-flex; align-items: center; gap: var(--space-2xs); }
+.dx-legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
+
+/* ── Report ─────────────────────────────────────────────────────────────── */
+
+.dx-report { display: flex; flex-direction: column; gap: var(--space-md); min-width: 0; }
+
+.dx-verdict {
+ border: 1px solid var(--hairline);
+ border-left: 3px solid var(--dx-sev, var(--ink-dim));
+ border-radius: var(--radius-lg);
+ background: var(--surface-1);
+ padding: var(--space-md);
+}
+
+.dx-verdict-top {
+ display: flex;
+ align-items: center;
+ gap: var(--space-sm);
+ flex-wrap: wrap;
+}
+
+.dx-verdict-level {
+ font: var(--weight-bold) var(--text-2xs) / 1 var(--font-body);
+ letter-spacing: 0.12em;
+ text-transform: uppercase;
+ color: var(--dx-sev, var(--ink-dim));
+ border: 1px solid color-mix(in srgb, var(--dx-sev, var(--ink-dim)) 45%, transparent);
+ border-radius: var(--radius-pill);
+ padding: var(--space-2xs) var(--space-sm);
+}
+
+.dx-verdict-counts { font-size: var(--text-sm); color: var(--ink-dim); font-family: var(--font-mono); }
+.dx-verdict-why { margin: var(--space-sm) 0 0; color: var(--ink-faint); font-size: var(--text-md); line-height: var(--leading-normal); }
+
+.dx-highlights { list-style: none; margin: var(--space-md) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-sm); }
+
+.dx-highlight {
+ display: grid;
+ grid-template-columns: 10px 1fr;
+ gap: var(--space-sm);
+ align-items: start;
+ font-size: var(--text-md);
+ line-height: var(--leading-normal);
+ color: var(--ink);
+}
+
+.dx-highlight::before {
+ content: '';
+ width: 6px;
+ height: 6px;
+ margin-top: 0.5em;
+ border-radius: 50%;
+ background: var(--dx-sev, var(--ink-dim));
+}
+
+.dx-card {
+ border: 1px solid var(--hairline);
+ border-radius: var(--radius-lg);
+ background: var(--surface-1);
+ overflow: hidden;
+}
+
+.dx-card-head {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: var(--space-sm);
+ padding: var(--space-sm) var(--space-md);
+ border-bottom: 1px solid var(--hairline);
+ font: var(--weight-semibold) var(--text-sm) / 1 var(--font-body);
+ letter-spacing: 0.04em;
+ text-transform: uppercase;
+ color: var(--ink-dim);
+}
+
+.dx-totals { width: 100%; border-collapse: collapse; font-size: var(--text-md); }
+.dx-totals th { text-align: left; font-weight: var(--weight-medium); color: var(--ink-dim); font-size: var(--text-sm); padding: var(--space-xs) var(--space-md); }
+.dx-totals td { padding: var(--space-xs) var(--space-md); font-family: var(--font-mono); font-size: var(--text-sm); }
+.dx-totals td:first-child { font-family: var(--font-body); color: var(--ink-faint); }
+.dx-totals td.dx-num { text-align: right; }
+.dx-totals tr + tr td { border-top: 1px solid var(--hairline); }
+.dx-totals tr + tr th { border-top: 1px solid var(--hairline); }
+.dx-up { color: var(--warn); }
+.dx-down { color: #60a5fa; }
+
+.dx-section { border-top: 1px solid var(--hairline); }
+.dx-section:first-of-type { border-top: 0; }
+
+.dx-section > summary {
+ display: flex;
+ align-items: center;
+ gap: var(--space-sm);
+ padding: var(--space-sm) var(--space-md);
+ cursor: pointer;
+ list-style: none;
+ font-size: var(--text-md);
+ transition: background 0.15s ease;
+}
+
+.dx-section > summary::-webkit-details-marker { display: none; }
+.dx-section > summary:hover { background: var(--surface-2); }
+.dx-section > summary:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: -2px; }
+
+.dx-caret { transition: transform 0.18s ease; color: var(--ink-dim); flex: none; }
+.dx-section[open] .dx-caret { transform: rotate(90deg); }
+
+.dx-section-name { font-weight: var(--weight-medium); }
+.dx-section-count { margin-left: auto; font-family: var(--font-mono); font-size: var(--text-sm); color: var(--ink-dim); }
+
+.dx-rows { list-style: none; margin: 0; padding: 0 0 var(--space-sm); }
+
+.dx-row {
+ display: grid;
+ grid-template-columns: 18px minmax(0, 1fr);
+ gap: var(--space-sm);
+ padding: var(--space-xs) var(--space-md);
+ font-size: var(--text-md);
+ align-items: start;
+}
+
+button.dx-row {
+ appearance: none;
+ width: 100%;
+ text-align: left;
+ border: 0;
+ background: transparent;
+ color: inherit;
+ font: inherit;
+ cursor: pointer;
+ transition: background 0.12s ease;
+}
+
+button.dx-row:hover { background: var(--surface-2); }
+button.dx-row:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: -2px; }
+button.dx-row[aria-pressed='true'] { background: var(--surface-3); }
+
+.dx-mark { font-family: var(--font-mono); font-weight: var(--weight-bold); line-height: 1.5; }
+.dx-mark-add { color: var(--success); }
+.dx-mark-del { color: var(--danger); }
+.dx-mark-mod { color: var(--warn); }
+.dx-mark-ren { color: #c4b5fd; }
+.dx-mark-mov { color: #60a5fa; }
+
+.dx-row-name { font-family: var(--font-mono); font-size: var(--text-sm); word-break: break-word; }
+.dx-row-detail { color: var(--ink-dim); font-size: var(--text-sm); }
+.dx-fields { list-style: none; margin: var(--space-2xs) 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
+.dx-field { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--ink-dim); word-break: break-word; }
+.dx-field b { font-weight: var(--weight-medium); color: var(--ink-faint); }
+
+.dx-actions { display: flex; flex-wrap: wrap; gap: var(--space-xs); }
+
+.dx-cli {
+ font-family: var(--font-mono);
+ font-size: var(--text-sm);
+ color: var(--ink-faint);
+ background: var(--bg-0);
+ border: 1px solid var(--hairline);
+ border-radius: var(--radius-md);
+ padding: var(--space-sm) var(--space-md);
+ overflow-x: auto;
+ white-space: pre;
+ margin: 0;
+}
+
+.dx-empty {
+ padding: var(--space-xl) var(--space-lg);
+ text-align: center;
+ color: var(--ink-dim);
+ font-size: var(--text-md);
+ line-height: var(--leading-normal);
+}
+
+.dx-empty strong { display: block; color: var(--ink); font-size: var(--text-lg); margin-bottom: var(--space-xs); font-family: var(--font-display); }
+
+/* Skeleton shimmer for the report while the two models parse. */
+.dx-skeleton { display: flex; flex-direction: column; gap: var(--space-sm); padding: var(--space-md); }
+.dx-skeleton i {
+ display: block;
+ height: 14px;
+ border-radius: var(--radius-sm);
+ background: linear-gradient(90deg, var(--surface-1), var(--surface-3), var(--surface-1));
+ background-size: 200% 100%;
+ animation: dx-shimmer 1.4s ease-in-out infinite;
+}
+.dx-skeleton i:nth-child(2) { width: 78%; }
+.dx-skeleton i:nth-child(3) { width: 54%; }
+.dx-skeleton i:nth-child(4) { width: 88%; }
+
+@keyframes dx-shimmer {
+ 0% { background-position: 200% 0; }
+ 100% { background-position: -200% 0; }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .dx-skeleton i { animation: none; }
+ .dx-caret { transition: none; }
+}
+
+/* ── Explainer ──────────────────────────────────────────────────────────── */
+
+.dx-explain {
+ max-width: var(--dx-max);
+ margin: 0 auto;
+ padding: 0 var(--space-lg) var(--space-2xl);
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
+ gap: var(--space-md);
+}
+
+.dx-explain h2 {
+ grid-column: 1 / -1;
+ font: var(--weight-semibold) var(--text-lg) / 1.3 var(--font-display);
+ margin: 0 0 var(--space-2xs);
+}
+
+.dx-explain article {
+ border: 1px solid var(--hairline);
+ border-radius: var(--radius-lg);
+ background: var(--surface-1);
+ padding: var(--space-md);
+}
+
+.dx-explain h3 { font: var(--weight-semibold) var(--text-md) / 1.3 var(--font-body); margin: 0 0 var(--space-xs); }
+.dx-explain p { margin: 0; color: var(--ink-faint); font-size: var(--text-md); line-height: var(--leading-normal); }
+.dx-explain code { font-family: var(--font-mono); font-size: 0.92em; color: var(--ink); }
+.dx-explain a { color: var(--ink); }
+
+/* ── Responsive ─────────────────────────────────────────────────────────── */
+
+@media (max-width: 1000px) {
+ .dx-workbench { grid-template-columns: 1fr; }
+ .dx-stage-card { position: relative; top: auto; }
+}
+
+@media (max-width: 720px) {
+ .dx-inputs { grid-template-columns: 1fr; }
+ .dx-swap { transform: rotate(90deg); justify-self: center; }
+ .dx-swap:active { transform: rotate(90deg) scale(0.94); }
+}
diff --git a/src/model-diff-stage.js b/src/model-diff-stage.js
new file mode 100644
index 000000000..bb9674d50
--- /dev/null
+++ b/src/model-diff-stage.js
@@ -0,0 +1,474 @@
+// The 3D stage behind /diff.
+//
+// A change set tells you a mesh moved. Seeing it move is what makes the change
+// obvious, so this renders both models in the same scene and offers the three
+// ways people actually compare things:
+//
+// overlay the baseline as a translucent ghost, the candidate solid on top
+// wipe one screen-aligned clipping plane, dragged across the view
+// split both models placed side by side, orbiting together
+//
+// The wipe plane is rebuilt from the camera basis every frame rather than fixed
+// to world X. A plane pinned to a world axis stops being a wipe the moment you
+// orbit: it slices the models diagonally and then edge-on. Deriving it from the
+// camera's right vector keeps the seam vertical on screen no matter where the
+// camera is, which is the only version that reads as a wipe.
+//
+// Loaded lazily by src/model-diff.js: three.js plus the glTF loader stack is by
+// far the heaviest thing on the page, and a visitor who reads the explainer and
+// leaves should not pay for it.
+
+import {
+ AmbientLight,
+ AnimationMixer,
+ Box3,
+ Clock,
+ Color,
+ DirectionalLight,
+ Group,
+ MeshStandardMaterial,
+ PMREMGenerator,
+ PerspectiveCamera,
+ Plane,
+ Scene,
+ Vector3,
+ WebGLRenderer,
+} from 'three';
+import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
+import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
+import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
+import { getDecoders } from './viewer/internal.js';
+
+// Ghost blue for the baseline, warm amber for edits, green for additions, red
+// for what is gone. The same five values the page legend prints, so the picture
+// and the caption can never drift apart.
+const COLOR = {
+ before: 0x60a5fa,
+ changed: 0xfbbf24,
+ added: 0x4ade80,
+ removed: 0xf87171,
+};
+
+let loaderPromise = null;
+function getLoader() {
+ if (!loaderPromise) {
+ loaderPromise = getDecoders().then(({ dracoLoader, ktx2Loader, meshoptDecoder }) => {
+ const loader = new GLTFLoader();
+ loader.setDRACOLoader(dracoLoader);
+ loader.setKTX2Loader(ktx2Loader);
+ loader.setMeshoptDecoder(meshoptDecoder);
+ return loader;
+ });
+ }
+ return loaderPromise;
+}
+
+// Rebuild the same node paths describe.js produces, against the loaded scene
+// graph, so a row in the report can point at an object in the viewport. glTF
+// node names survive on `userData.name`; `object.name` has been through three's
+// PropertyBinding sanitizer and would not match a path built from the file.
+function indexByPath(root) {
+ const byPath = new Map();
+ const seen = new Set();
+ let index = 0;
+
+ const visit = (object, parentPath) => {
+ const raw = object.userData?.name || object.name || `#node.${index}`;
+ const path = parentPath ? `${parentPath}/${raw}` : raw;
+ let unique = path;
+ let bump = 1;
+ while (seen.has(unique)) unique = `${path}#${bump++}`;
+ seen.add(unique);
+ byPath.set(unique, object);
+ index++;
+ for (const child of object.children) visit(child, unique);
+ };
+
+ for (const child of root.children) visit(child, '');
+ return byPath;
+}
+
+function disposeObject(object) {
+ object.traverse((node) => {
+ if (node.geometry) node.geometry.dispose();
+ const materials = Array.isArray(node.material) ? node.material : node.material ? [node.material] : [];
+ for (const material of materials) {
+ for (const value of Object.values(material)) {
+ if (value && value.isTexture) value.dispose();
+ }
+ material.dispose();
+ }
+ });
+}
+
+class Side {
+ constructor(role) {
+ this.role = role;
+ this.group = new Group();
+ this.root = null;
+ this.mixer = null;
+ this.clips = [];
+ this.byPath = new Map();
+ this.originalMaterials = new Map();
+ this.overrides = new Set();
+ this.clipPlanes = [];
+ }
+
+ adopt(scene, animations) {
+ this.clear();
+ this.root = scene;
+ this.group.add(scene);
+ this.byPath = indexByPath(scene);
+ this.clips = animations || [];
+ this.mixer = this.clips.length ? new AnimationMixer(scene) : null;
+ scene.traverse((node) => {
+ if (node.isMesh || node.isSkinnedMesh) this.originalMaterials.set(node, node.material);
+ });
+ }
+
+ clear() {
+ if (this.root) {
+ this.group.remove(this.root);
+ disposeObject(this.root);
+ }
+ for (const material of this.overrides) material.dispose();
+ this.overrides.clear();
+ this.originalMaterials.clear();
+ this.byPath.clear();
+ this.root = null;
+ this.mixer = null;
+ this.clips = [];
+ }
+
+ get loaded() {
+ return Boolean(this.root);
+ }
+
+ // Swap in a generated material while remembering the authored one, so
+ // toggling highlight off restores exactly what the file shipped.
+ override(node, build) {
+ const original = this.originalMaterials.get(node);
+ if (!original) return;
+ const source = Array.isArray(original) ? original[0] : original;
+ const material = build(source);
+ this.overrides.add(material);
+ node.material = material;
+ }
+
+ restore() {
+ for (const [node, material] of this.originalMaterials) node.material = material;
+ for (const material of this.overrides) material.dispose();
+ this.overrides.clear();
+ }
+
+ applyClipPlanes(planes) {
+ this.clipPlanes = planes;
+ const walk = (material) => {
+ material.clippingPlanes = planes.length ? planes : null;
+ material.clipShadows = true;
+ material.needsUpdate = true;
+ };
+ this.group.traverse((node) => {
+ const materials = Array.isArray(node.material) ? node.material : node.material ? [node.material] : [];
+ for (const material of materials) walk(material);
+ });
+ }
+}
+
+/**
+ * Mount the comparison stage inside `container`.
+ * @param {HTMLElement} container
+ */
+export async function createDiffStage(container) {
+ const renderer = new WebGLRenderer({ antialias: true, powerPreference: 'high-performance' });
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
+ renderer.localClippingEnabled = true;
+ container.appendChild(renderer.domElement);
+
+ const scene = new Scene();
+ scene.background = new Color(0x0a0a0a);
+
+ const pmrem = new PMREMGenerator(renderer);
+ scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
+
+ scene.add(new AmbientLight(0xffffff, 0.35));
+ const key = new DirectionalLight(0xffffff, 1.6);
+ key.position.set(2.5, 4, 3);
+ scene.add(key);
+
+ const camera = new PerspectiveCamera(45, 1, 0.01, 2000);
+ camera.position.set(0, 1.4, 3.4);
+
+ const controls = new OrbitControls(camera, renderer.domElement);
+ controls.enableDamping = true;
+ controls.dampingFactor = 0.08;
+ controls.target.set(0, 0.9, 0);
+
+ const sides = { a: new Side('a'), b: new Side('b') };
+ scene.add(sides.a.group, sides.b.group);
+
+ const state = {
+ mode: 'overlay',
+ wipe: 0.5,
+ highlight: true,
+ playing: false,
+ // Node paths, straight from the change set: `removed` exists only in the
+ // baseline, `added` only in the candidate, `edited` in both but different.
+ removed: new Set(),
+ added: new Set(),
+ edited: new Set(),
+ disposed: false,
+ visible: true,
+ };
+
+ const clock = new Clock();
+ const planeA = new Plane();
+ const planeB = new Plane();
+ const right = new Vector3();
+ const seam = new Vector3();
+ const center = new Vector3();
+ const size = new Vector3();
+ const box = new Box3();
+
+ // ── Framing ────────────────────────────────────────────────────────────
+
+ function unionBox() {
+ box.makeEmpty();
+ for (const side of Object.values(sides)) {
+ if (side.loaded) box.expandByObject(side.root);
+ }
+ return box;
+ }
+
+ function frameAll() {
+ const bounds = unionBox();
+ if (bounds.isEmpty()) return;
+ bounds.getCenter(center);
+ bounds.getSize(size);
+ const radius = Math.max(size.x, size.y, size.z) * 0.5 || 1;
+ const distance = (radius / Math.sin((camera.fov * Math.PI) / 360)) * 1.5;
+ controls.target.copy(center);
+ camera.position.set(center.x + distance * 0.25, center.y + radius * 0.35, center.z + distance);
+ camera.near = Math.max(distance / 500, 0.001);
+ camera.far = distance * 20;
+ camera.updateProjectionMatrix();
+ controls.update();
+ }
+
+ function focus(object) {
+ if (!object) return;
+ const bounds = new Box3().setFromObject(object);
+ if (bounds.isEmpty()) return;
+ const target = new Vector3();
+ const extent = new Vector3();
+ bounds.getCenter(target);
+ bounds.getSize(extent);
+ const radius = Math.max(extent.x, extent.y, extent.z, 0.05) * 0.5;
+ const distance = (radius / Math.sin((camera.fov * Math.PI) / 360)) * 2.4;
+ const direction = camera.position.clone().sub(controls.target).normalize();
+ controls.target.copy(target);
+ camera.position.copy(target).addScaledVector(direction, distance);
+ camera.updateProjectionMatrix();
+ controls.update();
+ }
+
+ // ── Presentation ───────────────────────────────────────────────────────
+
+ function ghostMaterial() {
+ return new MeshStandardMaterial({
+ color: COLOR.before,
+ transparent: true,
+ opacity: 0.28,
+ depthWrite: false,
+ roughness: 0.9,
+ metalness: 0,
+ });
+ }
+
+ function tintMaterial(source, color, opacity = 1) {
+ const material = new MeshStandardMaterial({
+ color,
+ emissive: new Color(color).multiplyScalar(0.35),
+ roughness: 0.55,
+ metalness: 0.05,
+ transparent: opacity < 1,
+ opacity,
+ depthWrite: opacity >= 1,
+ });
+ if (source?.map) material.map = source.map;
+ return material;
+ }
+
+ // Which objects wear which colour is decided here and nowhere else, so the
+ // legend, the report rows, and the viewport always agree.
+ function paint() {
+ for (const side of Object.values(sides)) side.restore();
+ if (!sides.a.loaded || !sides.b.loaded) return;
+
+ const ghostA = state.mode === 'overlay';
+ for (const [path, object] of sides.a.byPath) {
+ const removed = state.highlight && state.removed.has(path);
+ if (!ghostA && !removed) continue;
+ object.traverse((node) => {
+ if (!node.isMesh && !node.isSkinnedMesh) return;
+ if (removed) sides.a.override(node, (source) => tintMaterial(source, COLOR.removed, ghostA ? 0.5 : 1));
+ else sides.a.override(node, ghostMaterial);
+ });
+ }
+
+ if (!state.highlight) return;
+ for (const [path, object] of sides.b.byPath) {
+ const isAdded = state.added.has(path);
+ if (!isAdded && !state.edited.has(path)) continue;
+ object.traverse((node) => {
+ if (!node.isMesh && !node.isSkinnedMesh) return;
+ sides.b.override(node, (source) => tintMaterial(source, isAdded ? COLOR.added : COLOR.changed));
+ });
+ }
+ }
+
+ function layout() {
+ const bounds = unionBox();
+ bounds.getSize(size);
+ const separation = state.mode === 'split' ? Math.max(size.x, 0.5) * 0.62 : 0;
+ sides.a.group.position.x = -separation;
+ sides.b.group.position.x = separation;
+
+ if (state.mode === 'wipe') {
+ sides.a.applyClipPlanes([planeA]);
+ sides.b.applyClipPlanes([planeB]);
+ } else {
+ sides.a.applyClipPlanes([]);
+ sides.b.applyClipPlanes([]);
+ }
+ paint();
+ }
+
+ function updateWipePlanes() {
+ if (state.mode !== 'wipe') return;
+ unionBox().getCenter(center);
+ right.setFromMatrixColumn(camera.matrixWorld, 0).normalize();
+ const distance = camera.position.distanceTo(center);
+ const halfWidth = Math.tan((camera.fov * Math.PI) / 360) * distance * camera.aspect;
+ seam.copy(center).addScaledVector(right, (state.wipe - 0.5) * 2 * halfWidth);
+ planeA.setFromNormalAndCoplanarPoint(right.clone().negate(), seam);
+ planeB.setFromNormalAndCoplanarPoint(right.clone(), seam);
+ }
+
+ // ── Loop ───────────────────────────────────────────────────────────────
+
+ renderer.setAnimationLoop(() => {
+ if (state.disposed || !state.visible) return;
+ const delta = clock.getDelta();
+ if (state.playing) {
+ for (const side of Object.values(sides)) side.mixer?.update(delta);
+ }
+ controls.update();
+ updateWipePlanes();
+ renderer.render(scene, camera);
+ });
+
+ function resize() {
+ const width = container.clientWidth || 1;
+ const height = container.clientHeight || 1;
+ renderer.setSize(width, height, false);
+ camera.aspect = width / height;
+ camera.updateProjectionMatrix();
+ }
+
+ const resizeObserver = new ResizeObserver(resize);
+ resizeObserver.observe(container);
+ resize();
+
+ // A WebGL loop running against an off-screen canvas is pure battery drain on
+ // a page whose report is long enough to scroll the viewer away.
+ const visibility = new IntersectionObserver(
+ (entries) => {
+ state.visible = entries.some((entry) => entry.isIntersecting);
+ },
+ { threshold: 0.01 },
+ );
+ visibility.observe(container);
+
+ return {
+ /**
+ * Load one side from raw bytes.
+ * @param {'a'|'b'} role
+ * @param {ArrayBuffer} buffer
+ */
+ async setModel(role, buffer) {
+ const loader = await getLoader();
+ const gltf = await loader.parseAsync(buffer.slice(0), '');
+ sides[role].adopt(gltf.scene, gltf.animations);
+ frameAll();
+ layout();
+ return { clips: gltf.animations.map((clip) => clip.name) };
+ },
+
+ /**
+ * Colour the viewport from a change set: which node paths were removed
+ * from the baseline, and which were added or edited in the candidate.
+ */
+ applyChangeSet(changeset) {
+ state.removed = new Set(changeset.sections.nodes.removed.map((item) => item.name));
+ state.added = new Set(changeset.sections.nodes.added.map((item) => item.name));
+ state.edited = new Set([
+ ...changeset.sections.nodes.modified.map((item) => item.name),
+ ...changeset.sections.nodes.moved.map((item) => item.to),
+ ]);
+ paint();
+ },
+
+ setMode(mode) {
+ state.mode = mode;
+ layout();
+ },
+
+ setWipe(fraction) {
+ state.wipe = Math.min(1, Math.max(0, fraction));
+ },
+
+ setHighlight(on) {
+ state.highlight = Boolean(on);
+ paint();
+ },
+
+ setPlaying(on) {
+ state.playing = Boolean(on);
+ for (const side of Object.values(sides)) {
+ if (!side.mixer) continue;
+ if (on) {
+ side.mixer.stopAllAction();
+ const clip = side.clips[0];
+ if (clip) side.mixer.clipAction(clip).reset().play();
+ } else {
+ side.mixer.stopAllAction();
+ }
+ }
+ },
+
+ hasClips() {
+ return sides.a.clips.length > 0 || sides.b.clips.length > 0;
+ },
+
+ /** Frame one node by its diff path. Falls back to the other side when only one has it. */
+ focusPath(path) {
+ focus(sides.b.byPath.get(path) || sides.a.byPath.get(path));
+ },
+
+ frameAll,
+
+ dispose() {
+ state.disposed = true;
+ renderer.setAnimationLoop(null);
+ resizeObserver.disconnect();
+ visibility.disconnect();
+ controls.dispose();
+ for (const side of Object.values(sides)) side.clear();
+ pmrem.dispose();
+ scene.environment?.dispose();
+ renderer.dispose();
+ renderer.domElement.remove();
+ },
+ };
+}