3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Tell the user when showcase.html is asked for a scene it does not have (#2271)
Nguyen Xuan An037f2d4247ed
diff --git a/changes/2271.md b/changes/2271.mdnew file mode 100644index 00000000..c54b8fd0--- /dev/null+++ b/changes/2271.md@@ -0,0 +1 @@+- `showcase.html?scene=<name>` now says so when the scene does not exist, naming the request and the scenes it has, instead of silently opening the airport (#2271)diff --git a/site/showcase.html b/site/showcase.htmlindex 14f294de..17517d82 100644--- a/site/showcase.html+++ b/site/showcase.html@@ -30,6 +30,7 @@<button id="showcase-reset" class="showcase-reset" type="button">Reset view</button><canvas id="showcase-viewport" tabindex="0" aria-label="Live 3D scene. Drag to orbit, right-drag or shift-drag to pan, scroll to zoom, WASD or arrow keys to move, Q and E to turn."></canvas><p id="showcase-status" role="status"></p>+ <p id="showcase-notice" role="status" hidden></p></div><details class="showcase-credits"><summary>Models and licences</summary>diff --git a/src/showcase-scene-request.js b/src/showcase-scene-request.jsnew file mode 100644index 00000000..1c0c499c--- /dev/null+++ b/src/showcase-scene-request.js@@ -0,0 +1,14 @@+// Reads the `scene` query of showcase.html. An unknown name still opens the first scene, and the notice says what was asked for.++/**+ * @param {string | null} requestedName the `scene` query value, or null when the page was opened without one+ * @param {string[]} sceneIds the scenes the page has, first one is the fallback+ * @returns {{ id: string, notice: string | null }}+ */+export function resolveRequestedScene(requestedName, sceneIds) {+ if (!Array.isArray(sceneIds) || sceneIds.length === 0) throw new Error('resolveRequestedScene needs a non-empty list of scene ids.');+ if (requestedName === null || requestedName === '') return { id: sceneIds[0], notice: null };+ if (sceneIds.includes(requestedName)) return { id: requestedName, notice: null };+ const available = sceneIds.join(', ');+ return { id: sceneIds[0], notice: `There is no scene "${requestedName}". Showing ${sceneIds[0]}. Scenes: ${available}.` };+}diff --git a/src/showcase.css b/src/showcase.cssindex 9f3bc242..01f1bba9 100644--- a/src/showcase.css+++ b/src/showcase.css@@ -62,6 +62,30 @@backdrop-filter: blur(14px) saturate(1.4);}#showcase-status[data-kind=error] { border-radius: 16px; color: var(--error); }+/* Stays after the scene loads; sits at the top so it covers neither the loading chip nor the reset button. */+#showcase-notice {+ position: absolute;+ left: 50%;+ top: 16px;+ display: flex;+ align-items: flex-start;+ gap: 10px;+ width: max-content;+ max-width: calc(100% - 32px);+ margin: 0;+ padding: 10px 16px;+ transform: translateX(-50%);+ border-radius: 16px;+ background: #17161ad9;+ color: #fefefd;+ font-size: 14px;+ font-weight: 500;+ pointer-events: none;+ -webkit-backdrop-filter: blur(14px) saturate(1.4);+ backdrop-filter: blur(14px) saturate(1.4);+}+#showcase-notice[hidden] { display: none; }+#showcase-notice .status-icon { flex: none; margin-top: 1px; color: #f0b429; }#showcase-status .status-icon { flex: none; }#showcase-status .spinner { animation: showcase-spin .9s linear infinite; }@keyframes showcase-spin { to { transform: rotate(360deg); } }diff --git a/src/showcase.js b/src/showcase.jsindex fb2be926..014e10ed 100644--- a/src/showcase.js+++ b/src/showcase.js@@ -12,6 +12,7 @@ import { applyWaterReflection, attachWaterReflection } from './water-reflection.// (issue #504), and An saw no stutter in a side-by-side. A still camera keeps its picture either way.const WATER_REFLECTION_OPTIONS = { updateEvery: 2 };import { renderCommunity } from './community-showcase.js';+import { resolveRequestedScene } from './showcase-scene-request.js';import { createDownloadMeter, downloadBlob, inWholeWorldOrder, readByteLength, readPartRanks } from './showcase-download.js';// Each scene lives in public/showcase/<id>/scene.json: its GLB, sky, camera, renderer and frame options, and credits.@@ -32,11 +33,13 @@ const KEY_MOVE_PER_SECOND = 0.6;const KEY_TURN_PER_SECOND = 1.6;const SPINNER_ICON = '<svg class="status-icon spinner" viewBox="0 0 24 24" width="18" height="18" aria-hidden="true"><circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-opacity=".25" stroke-width="3"/><path d="M21 12a9 9 0 0 0-9-9" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round"/></svg>';+const WARNING_ICON = '<svg class="status-icon" viewBox="0 0 24 24" width="18" height="18" aria-hidden="true"><circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2"/><path d="M12 11v5M12 7.8v.1" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>';const ERROR_ICON = '<svg class="status-icon" viewBox="0 0 24 24" width="18" height="18" aria-hidden="true"><path d="M12 3 2.5 20h19L12 3Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M12 10v4.5M12 17.2v.1" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>';const canvas = document.querySelector('#showcase-viewport');const frame = document.querySelector('.showcase-frame');const status = document.querySelector('#showcase-status');+const notice = document.querySelector('#showcase-notice');const tabs = document.querySelector('#showcase-tabs');const resetButton = document.querySelector('#showcase-reset');const title = document.querySelector('#showcase-title');@@ -76,6 +79,15 @@ function showStatus(kind, message) {status.append(text);}+// A notice stays up after the scene loads, unlike the loading chip, so a wrong link is still explained.+function showNotice(message) {+ notice.hidden = false;+ notice.innerHTML = WARNING_ICON;+ const text = document.createElement('span');+ text.textContent = message;+ notice.append(text);+}+// Real bytes fetched so far; the total appears once every file's size is known, so the figure never shrinks.function showProgress(label, meter) {const { received, total } = meter.summary();@@ -424,7 +436,8 @@ window.addEventListener('resize', () => {});renderTabs();-const requested = new URLSearchParams(location.search).get('scene');-selectScene(SCENE_IDS.includes(requested) ? requested : SCENE_IDS[0]);+const requestedScene = resolveRequestedScene(new URLSearchParams(location.search).get('scene'), SCENE_IDS);+if (requestedScene.notice) showNotice(requestedScene.notice);+selectScene(requestedScene.id);renderCommunity({ grid: document.querySelector('#community-grid'), emailLink: document.querySelector('#community-email') });diff --git a/tests/showcase-scene-request.test.js b/tests/showcase-scene-request.test.jsnew file mode 100644index 00000000..418a1cad--- /dev/null+++ b/tests/showcase-scene-request.test.js@@ -0,0 +1,29 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { resolveRequestedScene } from '../src/showcase-scene-request.js';++const sceneIds = ['airport', 'datacenter', 'port'];++test('a known scene opens with no notice', () => {+ assert.deepEqual(resolveRequestedScene('port', sceneIds), { id: 'port', notice: null });+});++test('no query and an empty query open the first scene with no notice', () => {+ assert.deepEqual(resolveRequestedScene(null, sceneIds), { id: 'airport', notice: null });+ assert.deepEqual(resolveRequestedScene('', sceneIds), { id: 'airport', notice: null });+});++test('an unknown scene opens the first scene and the notice names the request and every valid scene', () => {+ const { id, notice } = resolveRequestedScene('datacentre', sceneIds);+ assert.equal(id, 'airport');+ assert.match(notice, /"datacentre"/);+ for (const sceneId of sceneIds) assert.ok(notice.includes(sceneId), `notice lists ${sceneId}`);+});++test('the notice follows the scene list it is given', () => {+ assert.match(resolveRequestedScene('x', ['alpha', 'beta']).notice, /alpha, beta/);+});++test('an empty scene list is refused with what to pass', () => {+ assert.throws(() => resolveRequestedScene('x', []), /non-empty list of scene ids/);+});