Prompt specification
Build or customize the Three.js 3D scene "Asking directions route reveal" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Asking directions route reveal
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/asking-directions-route-reveal-x0402
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts public information desks. Animate a visitor approaching the desk, selecting a destination card, and receiving a highlighted route; the route begins at their current position and ends at the requested service. Low-poly.
Working Three.js Starter (asking-directions-route-reveal-x0402):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Civic Center — Public Information Desk</title>
<style>
:root {
--ink: #163238;
--muted: #62767a;
--paper: rgba(255, 255, 255, 0.88);
--line: rgba(22, 50, 56, 0.12);
--accent: #0faaa5;
--accent-dark: #087a78;
--warm: #ffca58;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe7e8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
}
.ui {
position: fixed;
z-index: 10;
pointer-events: none;
}
.panel {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow:
0 18px 50px rgba(31, 62, 68, 0.14),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.brand {
top: 24px;
left: 24px;
display: flex;
align-items: center;
gap: 14px;
}
.brand-mark {
width: 48px;
height: 48px;
display: grid;
place-items: center;
border-radius: 15px;
background: var(--ink);
color: #fff;
font-size: 28px;
font-weight: 800;
box-shadow: 0 10px 30px rgba(22, 50, 56, 0.2);
}
.brand-copy {
padding: 11px 15px 12px;
border-radius: 15px;
}
.eyebrow {
margin-bottom: 3px;
color: var(--accent-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(16px, 2vw, 22px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.destination-panel {
top: 24px;
right: 24px;
width: min(310px, calc(100vw - 48px));
padding: 18px;
border-radius: 20px;
pointer-events: auto;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.panel-heading h2 {
margin: 0 0 4px;
font-size: 17px;
letter-spacing: -0.02em;
}
.panel-heading p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.live-badge {
flex: 0 0 auto;
display: flex;
align-items: center;
gap: 6px;
padding: 6px 8px;
border-radius: 999px;
background: #e0f5f1;
color: #087a78;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
}
.live-badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #12b8a7;
box-shadow: 0 0 0 4px rgba(18, 184, 167, 0.12);
}
.destinations {
display: grid;
gap: 8px;
}
.destination {
width: 100%;
display: grid;
grid-template-columns: 38px 1fr 18px;
align-items: center;
gap: 10px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.68);
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
box-shadow 160ms ease;
}
.destination:hover {
transform: translateY(-2px);
border-color: rgba(15, 170, 165, 0.4);
background: white;
box-shadow: 0 8px 20px rgba(31, 62, 68, 0.08);
}
.destination.selected {
border-color: var(--accent);
background: #effbf9;
box-shadow: 0 0 0 2px rgba(15, 170, 165, 0.1);
}
.destination-icon {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border-radius: 11px;
color: white;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.03em;
}
.destination strong {
display: block;
margin-bottom: 2px;
font-size: 12px;
}
.destination small {
display: block;
color: var(--muted);
font-size: 10px;
}
.destination-arrow {
color: #8ba0a3;
font-size: 17px;
transition: transform 160ms ease;
}
.destination:hover .destination-arrow {
transform: translateX(2px);
color: var(--accent-dark);
}
.status-panel {
left: 24px;
bottom: 24px;
width: min(390px, calc(100vw - 48px));
padding: 17px 18px;
border-radius: 18px;
}
.status-top {
display: flex;
align-items: flex-start;
gap: 12px;
}
.status-icon {
flex: 0 0 auto;
width: 36px;
height: 36px;
display: grid;
place-items: center;
border-radius: 50%;
background: var(--ink);
color: #fff;
font-size: 17px;
}
.status-copy {
min-width: 0;
}
.status-copy h3 {
margin: 0 0 4px;
font-size: 14px;
}
.status-copy p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.steps {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 14px;
}
.step {
position: relative;
padding-top: 10px;
color: #8b9da0;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.step::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 3px;
border-radius: 999px;
background: rgba(22, 50, 56, 0.1);
transition: background 250ms ease;
}
.step.active,
.step.done {
color: var(--accent-dark);
}
.step.active::before {
background: var(--warm);
}
.step.done::before {
background: var(--accent);
}
.controls {
right: 24px;
bottom: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
.control {
height: 42px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 12px;
background: rgba(255, 255, 255, 0.86);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 10px 28px rgba(31, 62, 68, 0.12);
transition:
transform 150ms ease,
background 150ms ease;
}
.control:hover {
transform: translateY(-2px);
background: white;
}
.control.primary {
border-color: var(--ink);
background: var(--ink);
color: white;
}
.control:disabled {
opacity: 0.42;
cursor: default;
transform: none;
}
.hint {
position: fixed;
z-index: 9;
left: 50%;
bottom: 29px;
transform: translateX(-50%);
padding: 8px 12px;
border-radius: 999px;
background: rgba(22, 50, 56, 0.76);
color: rgba(255, 255, 255, 0.86);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
pointer-events: none;
backdrop-filter: blur(10px);
}
.loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #e3ecec;
transition: opacity 500ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader {
display: grid;
justify-items: center;
gap: 14px;
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.loader-ring {
width: 46px;
height: 46px;
border: 4px solid rgba(22, 50, 56, 0.12);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 800ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 720px) {
.brand {
top: 12px;
left: 12px;
}
.brand-copy {
display: none;
}
.destination-panel {
top: 12px;
right: 12px;
width: 210px;
padding: 12px;
}
.destination-panel .panel-heading p,
.destination small {
display: none;
}
.destination {
grid-template-columns: 30px 1fr 14px;
gap: 7px;
padding: 7px;
}
.destination-icon {
width: 30px;
height: 30px;
}
.destination strong {
font-size: 10px;
}
.status-panel {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 12px;
}
.status-copy p {
display: none;
}
.controls {
right: 12px;
top: 148px;
bottom: auto;
flex-direction: column;
}
.control {
height: 36px;
padding: 0 10px;
font-size: 9px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly public information desk scene"></div>
<header class="ui brand">
<div class="brand-mark">i</div>
<div class="brand-copy panel">
<div class="eyebrow">Civic Center · Wayfinding</div>
<h1>Public Information</h1>
</div>
</header>
<aside class="ui destination-panel panel" aria-label="Destination cards">
<div class="panel-heading">
<div>
<h2>Where do you need to go?</h2>
<p>Select a physical or on-screen destination card.</p>
</div>
<div class="live-badge">LIVE</div>
</div>
<div class="destinations">
<button class="destination" data-index="0">
<span class="destination-icon" style="background:#0faaa5">G</span>
<span>
<strong>Main Gallery</strong>
<small>North wing · Exhibition level</small>
</span>
<span class="destination-arrow">↗</span>
</button>
<button class="destination" data-index="1">
<span class="destination-icon" style="background:#5674b8">WC</span>
<span>
<strong>Restrooms</strong>
<small>East corridor · Public facilities</small>
</span>
<span class="destination-arrow">↗</span>
</button>
<button class="destination" data-index="2">
<span class="destination-icon" style="background:#e98752">C</span>
<span>
<strong>Café</strong>
<small>West commons · Food and seating</small>
</span>
<span class="destination-arrow">↗</span>
</button>
<button class="destination" data-index="3">
<span class="destination-icon" style="background:#735b9c">↕</span>
<span>
<strong>Elevator</strong>
<small>East lobby · All floors</small>
</span>
<span class="destination-arrow">↗</span>
</button>
</div>
</aside>
<section class="ui status-panel panel" aria-live="polite">
<div class="status-top">
<div class="status-icon">➜</div>
<div class="status-copy">
<h3 id="statusTitle">Visitor approaching</h3>
<p id="statusText">A visitor is walking toward the main information desk.</p>
</div>
</div>
<div class="steps" aria-label="Wayfinding progress">
<div class="step active" id="stepApproach">Approach</div>
<div class="step" id="stepSelect">Select</div>
<div class="step" id="stepRoute">Route</div>
</div>
</section>
<nav class="ui controls" aria-label="Scene controls">
<button class="control" id="homeButton">Reset view</button>
<button class="control" id="focusButton" disabled>Focus route</button>
<button class="control primary" id="replayButton">Replay</button>
</nav>
<div class="hint">Drag to orbit · Scroll to zoom · Select a card</div>
<div class="loading" id="loading">
<div class="loader">
<div class="loader-ring"></div>
Building the civic center
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const container = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe7e8);
scene.fog = new THREE.Fog(0xdbe7e8, 26, 48);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
container.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const clock = new THREE.Clock();
const palette = {
ink: 0x18383d,
teal: 0x0faaa5,
tealDark: 0x087a78,
cream: 0xf1eee5,
paper: 0xfffaf0,
coral: 0xe96955,
yellow: 0xffca58,
blue: 0x5674b8,
purple: 0x735b9c,
orange: 0xe98752,
floorA: 0xe8e5dc,
floorB: 0xdeded5,
floorC: 0xefece4
};
const destinations = [
{
name: "Main Gallery",
short: "Gallery",
color: palette.teal,
css: "#0faaa5",
symbol: "G",
wing: "North wing",
endpoint: new THREE.Vector3(-8, 0.075, -10.65),
side: -1
},
{
name: "Restrooms",
short: "Restrooms",
color: palette.blue,
css: "#5674b8",
symbol: "WC",
wing: "East corridor",
endpoint: new THREE.Vector3(8, 0.075, -10.65),
side: 1
},
{
name: "Café",
short: "Café",
color: palette.orange,
css: "#e98752",
symbol: "C",
wing: "West commons",
endpoint: new THREE.Vector3(-11.2, 0.075, 4),
side: -1
},
{
name: "Elevator",
short: "Elevator",
color: palette.purple,
css: "#735b9c",
symbol: "↕",
wing: "East lobby",
endpoint: new THREE.Vector3(14.45, 0.075, -4),
side: 1
}
];
const statusTitle = document.querySelector("#statusTitle");
const statusText = document.querySelector("#statusText");
const stepApproach = document.querySelector("#stepApproach");
const stepSelect = document.querySelector("#stepSelect");
const stepRoute = document.querySelector("#stepRoute");
const focusButton = document.querySelector("#focusButton");
const destinationButtons = [...document.querySelectorAll(".destination")];
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf8fbf7, 0x6e7770, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d6, 3.2);
sun.position.set(-9, 17, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9e7ea, 1.05);
fill.position.set(12, 9, -10);
scene.add(fill);
// -------------------------------------------------------------------------
// Geometry and material helpers
// -------------------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
}
function addBox(parent, size, position, color, options = {}) {
const geometry = new THREE.BoxGeometry(...size);
const material = standardMaterial(color, options.material || {});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
color,
radialSegments = 8,
options = {}
) {
const geometry = new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments
);
const material = standardMaterial(color, options.material || {});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function canvasTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
draw(ctx, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeSign(text, background = "#18383d", foreground = "#ffffff") {
return canvasTexture(1024, 256, (ctx, width, height) => {
ctx.clearRect(0, 0, width, height);
roundedRect(ctx, 8, 8, width - 16, height - 16, 42);
ctx.fillStyle = background;
ctx.fill();
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "800 76px Arial, sans-serif";
ctx.fillText(text, width / 2, height / 2 + 4);
});
}
function makeSpriteLabel(text, color = "#18383d", width = 3.1) {
const texture = canvasTexture(768, 176, (ctx, w, h) => {
roundedRect(ctx, 8, 8, w - 16, h - 16, 32);
ctx.fillStyle = "rgba(255,255,255,0.94)";
ctx.fill();
ctx.strokeStyle = "rgba(24,56,61,0.12)";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = color;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "800 56px Arial, sans-serif";
ctx.fillText(text, w / 2, h / 2 + 3);
});
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * (176 / 768), 1);
return sprite;
}
// -------------------------------------------------------------------------
// Civic interior
// -------------------------------------------------------------------------
addBox(scene, [33, 0.16, 25], [0, -0.1, 0], 0xc9cfca, {
castShadow: false
});
const tileGeometry = new THREE.BoxGeometry(1.96, 0.08, 1.96);
const tileMaterial = standardMaterial(0xffffff);
const tileCount = 16 * 12;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCount);
tiles.receiveShadow = true;
const matrix = new THREE.Matrix4();
const tileColors = [palette.floorA, palette.floorB, palette.floorC];
let tileIndex = 0;
for (let z = 0; z < 12; z++) {
for (let x = 0; x < 16; x++) {
matrix.makeTranslation(
-15 + x * 2,
0,
-11 + z * 2
);
tiles.setMatrixAt(tileIndex, matrix);
const stripe = (x + z * 2) % 7 === 0 ? 1 : 0;
const color = new THREE.Color(
stripe ? 0xd8dfdb : tileColors[(x * 7 + z * 3) % tileColors.length]
);
tiles.setColorAt(tileIndex, color);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// Rear wall, right wall and architectural framing.
addBox(scene, [32.5, 7.2, 0.35], [0, 3.55, -12.25], palette.cream);
addBox(scene, [0.35, 7.2, 24], [15.8, 3.55, 0], 0xe6e4db);
for (const x of [-14.2, -4.4, 4.4, 14.2]) {
addBox(scene, [0.42, 7.2, 0.58], [x, 3.55, -11.98], 0xd7ded8);
addBox(scene, [0.7, 0.24, 0.75], [x, 7.05, -11.9], 0xf8f5ed);
}
addBox(scene, [32, 0.28, 0.65], [0, 6.72, -11.9], 0xd1dbd6);
addBox(scene, [0.18, 0.05, 23], [15.55, 0.8, 0], 0xcfd8d3);
addBox(scene, [31.5, 0.05, 0.18], [0, 0.8, -11.98], 0xcfd8d3);
// Welcome sign.
const welcomeTexture = makeSign("CIVIC INFORMATION", "#18383d", "#ffffff");
const welcomeSign = new THREE.Mesh(
new THREE.PlaneGeometry(6.8, 1.7),
new THREE.MeshBasicMaterial({ map: welcomeTexture, transparent: true })
);
welcomeSign.position.set(0, 5.45, -11.95);
scene.add(welcomeSign);
// -------------------------------------------------------------------------
// Main information desk
// -------------------------------------------------------------------------
const deskGroup = new THREE.Group();
scene.add(deskGroup);
addBox(deskGroup, [7.4, 1.08, 2.25], [0, 0.59, -1.27], palette.tealDark);
addBox(deskGroup, [7.85, 0.17, 2.78], [0, 1.22, -1.12], 0xfaf5e9);
addBox(deskGroup, [7.58, 0.08, 2.5], [0, 1.33, -1.14], 0xe4dfd3);
// Front panel and trim.
addBox(deskGroup, [7.0, 0.8, 0.06], [0, 0.63, -0.115], 0x087a78);
addBox(deskGroup, [7.1, 0.07, 0.09], [0, 1.04, -0.09], 0xffca58);
const infoTexture = canvasTexture(1024, 256, (ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = "#0b8581";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#ffffff";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 126px Arial, sans-serif";
ctx.fillText("i", w / 2, h / 2 + 7);
ctx.font = "800 48px Arial, sans-serif";
ctx.fillText("INFORMATION", w / 2, h - 40);
});
const infoPanel = new THREE.Mesh(
new THREE.PlaneGeometry(3.7, 0.94),
new THREE.MeshBasicMaterial({ map: infoTexture, transparent: true })
);
infoPanel.position.set(0, 0.64, -0.075);
deskGroup.add(infoPanel);
// Low-poly desk accessories.
addBox(deskGroup, [0.72, 0.4, 0.58], [-2.75, 1.53, -1.28], 0x53686d);
const deskScreen = addBox(
deskGroup,
[0.82, 0.48, 0.08],
[-2.75, 1.98, -1.45],
0x203e44
);
deskScreen.rotation.x = -0.12;
addCylinder(deskGroup, 0.18, 0.2, 0.36, [2.85, 1.57, -1.18], 0xe6b76f, 8);
for (let i = 0; i < 3; i++) {
addCylinder(
deskGroup,
0.035,
0.035,
0.46,
[2.7 + i * 0.13, 1.77, -1.18],
[0xe96955, 0x5674b8, 0xffca58][i],
6
);
}
// A low rug defines the information point.
const rug = addBox(
scene,
[10.2, 0.025, 5.4],
[0, 0.065, 0.8],
0xd7c9ae,
{ castShadow: false }
);
rug.receiveShadow = true;
// Secondary public help desk.
const satellite = new THREE.Group();
satellite.position.set(11.5, 0, 7.1);
satellite.rotation.y = -0.12;
scene.add(satellite);
addBox(satellite, [2.45, 1.05, 1.35], [0, 0.57, 0], palette.teal);
addBox(satellite, [2.65, 0.15, 1.55], [0, 1.18, 0], 0xfaf5e9);
const satelliteInfo = new THREE.Mesh(
new THREE.PlaneGeometry(0.68, 0.68),
new THREE.MeshBasicMaterial({ map: infoTexture })
);
satelliteInfo.position.set(0, 0.6, 0.69);
satellite.add(satelliteInfo);
// -------------------------------------------------------------------------
// Physical destination cards
// -------------------------------------------------------------------------
const cardGroups = [];
const cardMeshes = [];
function makeCardTexture(index) {
const destination = destinations[index];
const css = `#${destination.color.toString(16).padStart(6, "0")}`;
return canvasTexture(768, 384, (ctx, w, h) => {
ctx.fillStyle = "#fffdf7";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = css;
ctx.fillRect(0, 0, 20, h);
roundedRect(ctx, 44, 42, 160, 160, 42);
ctx.fillStyle = css;
ctx.fill();
ctx.fillStyle = "#ffffff";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 70px Arial, sans-serif";
ctx.fillText(destination.symbol, 124, 126);
ctx.fillStyle = "#18383d";
ctx.textAlign = "left";
ctx.font = "800 44px Arial, sans-serif";
const words = destination.name.toUpperCase().split(" ");
if (words.length > 1) {
ctx.fillText(words[0], 238, 100);
ctx.fillText(words.slice(1).join(" "), 238, 153);
} else {
ctx.fillText(words[0], 238, 126);
}
ctx.fillStyle = "#708286";
ctx.font = "700 27px Arial, sans-serif";
ctx.fillText(destination.wing.toUpperCase(), 48, 270);
ctx.fillText("SELECT", 48, 322);
});
}
const cardXs = [-2.4, -0.8, 0.8, 2.4];
destinations.forEach((destination, index) => {
const group = new THREE.Group();
group.position.set(cardXs[index], 1.7, -0.05);
group.rotation.x = -0.28;
group.userData.index = index;
group.userData.baseY = group.position.y;
deskGroup.add(group);
const edgeMaterial = standardMaterial(0x35545a);
const body = new THREE.Mesh(
new THREE.BoxGeometry(1.36, 0.8, 0.11),
edgeMaterial
);
body.castShadow = true;
group.add(body);
const frontMaterial = standardMaterial(0xffffff, {
map: makeCardTexture(index),
roughness: 0.72
});
const front = new THREE.Mesh(
new THREE.PlaneGeometry(1.26, 0.7),
frontMaterial
);
front.position.z = 0.061;
front.userData.index = index;
group.add(front);
addBox(
deskGroup,
[0.9, 0.08, 0.46],
[cardXs[index], 1.39, -0.03],
0x5f7477
);
cardGroups.push(group);
cardMeshes.push(front);
});
// -------------------------------------------------------------------------
// Service destinations
// -------------------------------------------------------------------------
function makeServiceDoor(x, color, label) {
addBox(scene, [3.5, 4.0, 0.18], [x, 2.0, -11.98], 0xd3ddd8);
addBox(scene, [3.0, 3.65, 0.14], [x, 1.85, -11.84], color);
addBox(scene, [0.16, 3.8, 0.28], [x - 1.6, 1.95, -11.72], 0xf9f5eb);
addBox(scene, [0.16, 3.8, 0.28], [x + 1.6, 1.95, -11.72], 0xf9f5eb);
addBox(scene, [3.35, 0.18, 0.28], [x, 3.92, -11.72], 0xf9f5eb);
const sprite = makeSpriteLabel(label, `#${color.toString(16).padStart(6, "0")}`, 3.2);
sprite.position.set(x, 4.55, -11.5);
scene.add(sprite);
}
makeServiceDoor(-8, 0x155f61, "MAIN GALLERY");
makeServiceDoor(8, 0x3e5a91, "RESTROOMS");
// Gallery artwork visible through the opening.
addBox(scene, [1.25, 1.55, 0.08], [-8.65, 2.0, -11.7], 0xe9b55f);
addBox(scene, [0.34, 1.9, 0.09], [-7.95, 1.9, -11.69], 0xe87358);
addBox(scene, [1.1, 0.42, 0.1], [-7.15, 2.4, -11.68], 0x6f8e91);
// Restroom pictogram panels.
addBox(scene, [0.7, 0.95, 0.08], [7.2, 2.1, -11.68], 0x91a8ce);
addBox(scene, [0.7, 0.95, 0.08], [8.8, 2.1, -11.68], 0x91a8ce);
// Café kiosk in the west commons.
const cafe = new THREE.Group();
cafe.position.set(-13.25, 0, 4);
scene.add(cafe);
addBox(cafe, [2.35, 1.15, 4.4], [0, 0.6, 0], 0xd77d50);
addBox(cafe, [2.65, 0.16, 4.7], [0, 1.26, 0], 0xf9f2e5);
addBox(cafe, [0.18, 2.8, 4.7], [1.14, 2.55, 0], 0x58716f);
for (let i = 0; i < 4; i++) {
const awning = addBox(
cafe,
[0.85, 0.14, 1.0],
[1.46, 3.72, -1.65 + i * 1.1],
i % 2 ? 0xf4e8d5 : palette.orange
);
awning.rotation.z = -0.12;
}
const cafeLabel = makeSpriteLabel("CAFÉ", "#e98752", 2.4);
cafeLabel.position.set(1.35, 4.25, 0);
cafe.add(cafeLabel);
// Café tables and stools.
addCylinder(scene, 0.72, 0.72, 0.11, [-9.0, 0.9, 6.6], 0xf2e4ca, 10);
addCylinder(scene, 0.1, 0.14, 0.86, [-9.0, 0.45, 6.6], 0x53666a, 8);
for (const dz of [-1.25, 1.25]) {
addCylinder(scene, 0.42, 0.42, 0.14, [-9.0, 0.66, 6.6 + dz], palette.orange, 8);
addCylinder(scene, 0.09, 0.11, 0.62, [-9.0, 0.31, 6.6 + dz], 0x53666a, 7);
}
// Elevator doors on the east wall.
addBox(scene, [0.2, 3.7, 3.25], [15.55, 1.87, -4], 0xb8c5c2);
addBox(scene, [0.16, 3.25, 1.38], [15.4, 1.7, -4.35], 0x5b6d71);
addBox(scene, [0.16, 3.25, 1.38], [15.4, 1.7, -3.35], 0x52666a);
addBox(scene, [0.12, 3.3, 0.05], [15.29, 1.7, -3.84], 0x9ba9a8);
addBox(scene, [0.16, 0.55, 0.42], [15.32, 1.7, -2.25], 0x354a50);
const elevatorLabel = makeSpriteLabel("ELEVATOR", "#735b9c", 2.8);
elevatorLabel.position.set(14.65, 4.15, -4);
elevatorLabel.rotation.y = -Math.PI / 2;
scene.add(elevatorLabel);
// Benches and low-poly planters.
function makeBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
addBox(group, [3.2, 0.17, 0.72], [0, 0.65, 0], 0xc89355);
addBox(group, [3.2, 0.78, 0.16], [0, 1.02, -0.3], 0xc89355);
for (const dx of [-1.1, 1.1]) {
addBox(group, [0.18, 0.62, 0.58], [dx, 0.31, 0], 0x52676a);
}
}
makeBench(-9.5, 8.4, 0.08);
makeBench(8.0, 8.5, -0.06);
function makePlant(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
addCylinder(group, 0.52, 0.39, 0.72, [0, 0.36, 0], 0xcf8d68, 8);
addCylinder(group, 0.08, 0.12, 1.25, [0, 1.18, 0], 0x775f43, 7);
const foliage = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.86, 0),
standardMaterial(0x4d8b67)
);
foliage.position.set(0, 2.05, 0);
foliage.scale.set(1, 1.12, 0.9);
foliage.castShadow = true;
group.add(foliage);
const foliage2 = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.62, 0),
standardMaterial(0x6ea77b)
);
foliage2.position.set(0.42, 2.45, 0.05);
foliage2.castShadow = true;
group.add(foliage2);
}
makePlant(-13.8, 8.8, 1.12);
makePlant(13.5, 9.0, 1.0);
makePlant(-13.7, -8.8, 0.86);
makePlant(13.7, -9.2, 0.9);
// -------------------------------------------------------------------------
// People
// -------------------------------------------------------------------------
function createPerson({
shirt = palette.coral,
pants = 0x263f48,
skin = 0xd7a078,
hair = 0x343236,
scale = 1
} = {}) {
const root = new THREE.Group();
root.scale.setScalar(scale);
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.43, 0.88, 6),
standardMaterial(shirt)
);
torso.position.y = 1.19;
torso.castShadow = true;
root.add(torso);
const neck = addCylinder(root, 0.1, 0.1, 0.17, [0, 1.68, 0], skin, 7);
neck.castShadow = true;
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.28, 0),
standardMaterial(skin)
);
head.position.y = 1.88;
head.castShadow = true;
root.add(head);
const hairMesh = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.29, 0),
standardMaterial(hair)
);
hairMesh.position.set(0, 2.01, 0.035);
hairMesh.scale.set(1, 0.56, 0.95);
hairMesh.castShadow = true;
root.add(hairMesh);
const nose = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.075, 0),
standardMaterial(skin)
);
nose.position.set(0, 1.86, -0.265);
root.add(nose);
const legLeft = new THREE.Group();
const legRight = new THREE.Group();
legLeft.position.set(-0.16, 0.79, 0);
legRight.position.set(0.16, 0.79, 0);
root.add(legLeft, legRight);
for (const leg of [legLeft, legRight]) {
const limb = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.12, 0.63, 6),
standardMaterial(pants)
);
limb.position.y = -0.31;
limb.castShadow = true;
leg.add(limb);
const shoe = addBox(leg, [0.23, 0.15, 0.39], [0, -0.62, -0.08], 0x24373d);
shoe.castShadow = true;
}
const armLeft = new THREE.Group();
const armRight = new THREE.Group();
armLeft.position.set(-0.38, 1.5, 0);
armRight.position.set(0.38, 1.5, 0);
root.add(armLeft, armRight);
for (const arm of [armLeft, armRight]) {
const limb = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.105, 0.63, 6),
standardMaterial(shirt)
);
limb.position.y = -0.3;
limb.castShadow = true;
arm.add(limb);
const hand = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.11, 0),
standardMaterial(skin)
);
hand.position.y = -0.64;
hand.castShadow = true;
arm.add(hand);
}
root.userData = { legLeft, legRight, armLeft, armRight };
return root;
}
const visitor = createPerson({
shirt: palette.coral,
pants: 0x243f48,
skin: 0xd7a078
});
visitor.position.set(-5.5, 0, 7.5);
scene.add(visitor);
const staff = createPerson({
shirt: 0xf2c75c,
pants: 0x324f55,
skin: 0x8f5f46,
hair: 0x292a29,
scale: 0.98
});
staff.position.set(0.25, 0, -2.16);
staff.rotation.y = Math.PI;
scene.add(staff);
const staticVisitorA = createPerson({
shirt: 0x5674b8,
pants: 0x36474c,
skin: 0xe0b18d,
scale: 0.94
});
staticVisitorA.position.set(-8.2, 0, 7.0);
staticVisitorA.rotation.y = 0.45;
scene.add(staticVisitorA);
const staticVisitorB = createPerson({
shirt: 0x735b9c,
pants: 0x263e46,
skin: 0x6e493d,
scale: 1.04
});
staticVisitorB.position.set(5.6, 0, 9.0);
staticVisitorB.rotation.y = -0.6;
scene.add(staticVisitorB);
// -------------------------------------------------------------------------
// Route construction
// -------------------------------------------------------------------------
const routeGroup = new THREE.Group();
scene.add(routeGroup);
let routeData = null;
function disposeGroup(group) {
group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach((material) => material.dispose());
}
});
group.clear();
}
function makeRoundedCurve(points, radius = 0.52) {
const curvePath = new THREE.CurvePath();
let last = points[0].clone();
for (let i = 1; i < points.length - 1; i++) {
const previous = points[i - 1];
const current = points[i];
const next = points[i + 1];
const incoming = current.clone().sub(previous);
const outgoing = next.clone().sub(current);
const incomingLength = incoming.length();
const outgoingLength = outgoing.length();
if (incomingLength < 0.001 || outgoingLength < 0.001) continue;
const cut = Math.min(radius, incomingLength * 0.35, outgoingLength * 0.35);
const a = current.clone().addScaledVector(
incoming.clone().normalize(),
-cut
);
const b = current.clone().addScaledVector(
outgoing.clone().normalize(),
cut
);
curvePath.add(new THREE.LineCurve3(last, a));
curvePath.add(new THREE.QuadraticBezierCurve3(a, current, b));
last = b;
}
curvePath.add(new THREE.LineCurve3(last, points.at(-1).clone()));
return curvePath;
}
function makeRibbon(curve, width, color, opacity) {
const samples = curve.getSpacedPoints(170);
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i < samples.length; i++) {
const previous = samples[Math.max(0, i - 1)];
const next = samples[Math.min(samples.length - 1, i + 1)];
const tangent = next.clone().sub(previous);
tangent.y = 0;
tangent.normalize();
const perpendicular = new THREE.Vector3(-tangent.z, 0, tangent.x);
const point = samples[i];
const left = point.clone().addScaledVector(perpendicular, width / 2);
const right = point.clone().addScaledVector(perpendicular, -width / 2);
positions.push(left.x, 0.083, left.z);
positions.push(right.x, 0.083, right.z);
const u = i / (samples.length - 1);
uvs.push(0, u, 1, u);
if (i < samples.length - 1) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 2, a + 3, a + 1);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeBoundingSphere();
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
side: THREE.DoubleSide,
depthWrite: false
});
const mesh = new THREE.Mesh(geometry, material);
mesh.renderOrder = 5;
routeGroup.add(mesh);
return { mesh, geometry, material };
}
function makeArrowGeometry() {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
-0.13, 0, -0.12,
0.13, 0, -0.12,
0, 0, 0.18
],
3
)
);
geometry.computeVertexNormals();
return geometry;
}
function pointsForDestination(destination, start) {
const side = destination.side;
const sideX = side < 0 ? -4.85 : 4.85;
if (destination.short === "Gallery") {
return [
start,
new THREE.Vector3(sideX, 0.075, 1.15),
new THREE.Vector3(sideX, 0.075, -5.65),
new THREE.Vector3(-8, 0.075, -8.25),
destination.endpoint.clone()
];
}
if (destination.short === "Restrooms") {
return [
start,
new THREE.Vector3(sideX, 0.075, 1.15),
new THREE.Vector3(sideX, 0.075, -5.65),
new THREE.Vector3(8, 0.075, -8.25),
destination.endpoint.clone()
];
}
if (destination.short === "Café") {
return [
start,
new THREE.Vector3(-5.0, 0.075, 1.45),
new THREE.Vector3(-7.55, 0.075, 2.45),
new THREE.Vector3(-10.0, 0.075, 4),
destination.endpoint.clone()
];
}
return [
start,
new THREE.Vector3(5.0, 0.075, 1.0),
new THREE.Vector3(7.2, 0.075, -1.15),
new THREE.Vector3(11.2, 0.075, -3.25),
destination.endpoint.clone()
];
}
function clearRoute() {
disposeGroup(routeGroup);
routeData = null;
focusButton.disabled = true;
}
function createRoute(destination) {
clearRoute();
const start = visitor.position.clone();
start.y = 0.075;
const points = pointsForDestination(destination, start);
const curve = makeRoundedCurve(points, 0.58);
const under = makeRibbon(curve, 0.5, 0x123e45, 0.2);
const bright = makeRibbon(curve, 0.22, palette.teal, 0.93);
const arrows = [];
for (let i = 0; i < 13; i++) {
const material = new THREE.MeshBasicMaterial({
color: palette.yellow,
transparent: true,
opacity: 0.95,
side: THREE.DoubleSide,
depthWrite: false
});
const arrow = new THREE.Mesh(makeArrowGeometry(), material);
arrow.renderOrder = 7;
routeGroup.add(arrow);
arrows.push({ mesh: arrow, offset: i / 13 });
}
const startRing = new THREE.Mesh(
new THREE.RingGeometry(0.33, 0.48, 28),
new THREE.MeshBasicMaterial({
color: palette.yellow,
transparent: true,
opacity: 0.95,
side: THREE.DoubleSide,
depthWrite: false
})
);
startRing.rotation.x = -Math.PI / 2;
startRing.position.set(start.x, 0.098, start.z);
startRing.renderOrder = 8;
routeGroup.add(startRing);
const startLabel = makeSpriteLabel("YOU ARE HERE", "#087a78", 1.7);
startLabel.position.set(start.x, 0.66, start.z);
startLabel.material.opacity = 0;
routeGroup.add(startLabel);
const endRing = new THREE.Mesh(
new THREE.RingGeometry(0.46, 0.66, 32),
new THREE.MeshBasicMaterial({
color: palette.teal,
transparent: true,
opacity: 0.95,
side: THREE.DoubleSide,
depthWrite: false
})
);
endRing.rotation.x = -Math.PI / 2;
endRing.position.set(
destination.endpoint.x,
0.102,
destination.endpoint.z
);
endRing.renderOrder = 8;
routeGroup.add(endRing);
const beacon = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.12, 2.15, 7),
new THREE.MeshBasicMaterial({
color: destination.color,
transparent: true,
opacity: 0.52,
depthWrite: false
})
);
beacon.position.set(
destination.endpoint.x,
1.08,
destination.endpoint.z
);
beacon.renderOrder = 7;
routeGroup.add(beacon);
routeData = {
destination,
curve,
points,
under,
bright,
arrows,
startRing,
startLabel,
endRing,
beacon,
createdAt: timeline,
reveal: 0
};
focusButton.disabled = false;
const length = Math.round(curve.getLength());
statusTitle.textContent = `${destination.name} selected`;
statusText.textContent =
`The highlighted route begins at the visitor’s current position and ends at the ${destination.short.toLowerCase()}. Approximate distance: ${length} m.`;
updateSteps();
}
function updateRoute() {
if (!routeData) return;
routeData.reveal = Math.min(
1,
(timeline - routeData.createdAt) / 1.35
);
const totalIndices = routeData.bright.geometry.index.count;
const visibleIndices = Math.floor(
(totalIndices * routeData.reveal) / 6
) * 6;
routeData.bright.geometry.setDrawRange(0, visibleIndices);
routeData.under.geometry.setDrawRange(0, visibleIndices);
routeData.bright.material.opacity =
0.84 + Math.sin(timeline * 4.5) * 0.08;
for (const arrowData of routeData.arrows) {
const u = (arrowData.offset + timeline * 0.055) % 1;
arrowData.mesh.visible = u <= routeData.reveal;
if (!arrowData.mesh.visible) continue;
const point = routeData.curve.getPointAt(u);
const nextPoint = routeData.curve.getPointAt(Math.min(1, u + 0.003));
const tangent = nextPoint.clone().sub(point);
tangent.y = 0;
tangent.normalize();
arrowData.mesh.position.set(point.x, 0.115, point.z);
arrowData.mesh.rotation.y = Math.atan2(tangent.x, tangent.z);
arrowData.mesh.material.opacity =
0.65 + Math.sin(timeline * 6 + arrowData.offset * 12) * 0.25;
}
const pulse = 1 + Math.sin(timeline * 3.6) * 0.13;
routeData.endRing.scale.setScalar(pulse);
routeData.startRing.scale.setScalar(1 + Math.sin(timeline * 4.2) * 0.06);
routeData.startLabel.material.opacity = Math.max(
0,
(routeData.reveal - 0.45) / 0.4
);
routeData.beacon.material.opacity =
0.32 + Math.sin(timeline * 3.2) * 0.12;
}
// -------------------------------------------------------------------------
// Interaction state
// -------------------------------------------------------------------------
let timeline = 0;
let phase = "approach";
let selectedIndex = null;
let hoveredIndex = null;
let selectionStart = 0;
let selectionFrom = visitor.position.clone();
let autoSelectionPending = true;
let userHasSelected = false;
const visitorStart = new THREE.Vector3(-5.5, 0, 7.5);
const deskApproachPoint = new THREE.Vector3(0, 0, 1.35);
function updateSteps() {
stepApproach.className = "step";
stepSelect.className = "step";
stepRoute.className = "step";
if (phase === "approach") stepApproach.classList.add("active");
if (phase === "ready") {
stepApproach.classList.add("done");
stepSelect.classList.add("active");
}
if (phase === "selecting") {
stepApproach.classList.add("done");
stepSelect.classList.add("active");
}
if (phase === "routed") {
stepApproach.classList.add("done");
stepSelect.classList.add("done");
stepRoute.classList.add("done");
}
}
function updateCardAppearance(dt) {
cardGroups.forEach((group, index) => {
const selected = selectedIndex === index;
const hovered = hoveredIndex === index;
const targetY = group.userData.baseY + (selected ? 0.09 : 0) + (hovered ? 0.045 : 0);
group.position.y = THREE.MathUtils.damp(group.position.y, targetY, 11, dt);
group.rotation.z = THREE.MathUtils.damp(
group.rotation.z,
selected ? -0.035 : 0,
9,
dt
);
const front = cardMeshes[index];
front.material.emissive.setHex(selected ? destinations[index].color : 0x000000);
front.material.emissiveIntensity = selected ? 0.28 : hovered ? 0.12 : 0;
});
destinationButtons.forEach((button, index) => {
button.classList.toggle("selected", selectedIndex === index);
});
}
function beginSelection(index) {
selectedIndex = index;
updateCardAppearance(0.016);
if (routeData) clearRoute();
phase = "selecting";
selectionStart = timeline;
selectionFrom.copy(visitor.position);
statusTitle.textContent = `Selecting ${destinations[index].name}`;
statusText.textContent =
"The visitor is choosing a destination card at the information desk.";
updateSteps();
}
function chooseDestination(index, source = "user") {
selectedIndex = index;
userHasSelected = true;
autoSelectionPending = false;
if (source === "auto") {
beginSelection(index);
return;
}
if (phase === "approach") {
statusTitle.textContent = `${destinations[index].name} queued`;
statusText.textContent =
"The destination is queued. The visitor will select the card on reaching the desk.";
updateCardAppearance(0.016);
return;
}
beginSelection(index);
}
function resetScene() {
clearRoute();
timeline = 0;
phase = "approach";
selectedIndex = null;
hoveredIndex = null;
autoSelectionPending = true;
userHasSelected = false;
selectionFrom.copy(visitorStart);
visitor.position.copy(visitorStart);
visitor.rotation.y = -0.72;
visitor.userData.legLeft.rotation.x = 0;
visitor.userData.legRight.rotation.x = 0;
visitor.userData.armLeft.rotation.x = 0;
visitor.userData.armRight.rotation.x = 0;
statusTitle.textContent = "Visitor approaching";
statusText.textContent =
"A visitor is walking toward the main information desk.";
updateSteps();
updateCardAppearance(0.016);
}
function updateAnimation(dt) {
timeline += dt;
if (phase === "approach") {
const t = Math.min(timeline / 4.8, 1);
const eased = t * t * (3 - 2 * t);
visitor.position.lerpVectors(visitorStart, deskApproachPoint, eased);
const movementDirection = deskApproachPoint.clone().sub(visitorStart);
const targetYaw = Math.atan2(-movementDirection.x, -movementDirection.z);
visitor.rotation.y = THREE.MathUtils.damp(
visitor.rotation.y,
targetYaw * (1 - eased * 0.7),
6,
dt
);
if (t >= 1) {
phase = "ready";
statusTitle.textContent = "Ready to choose";
statusText.textContent =
"The visitor has reached the desk. Choose a physical or on-screen destination card.";
updateSteps();
}
}
if (phase === "ready" && autoSelectionPending && timeline > 5.25) {
chooseDestination(0, "auto");
}
if (phase === "selecting") {
const targetX = cardXs[selectedIndex];
const targetZ = 1.12;
const t = Math.min((timeline - selectionStart) / 1.35, 1);
const eased = t * t * (3 - 2 * t);
visitor.position.x = THREE.MathUtils.lerp(
selectionFrom.x,
targetX,
eased
);
visitor.position.z = THREE.MathUtils.lerp(
selectionFrom.z,
targetZ,
eased
);
visitor.rotation.y = THREE.MathUtils.damp(
visitor.rotation.y,
0,
6,
dt
);
const reach = THREE.MathUtils.smoothstep(t, 0.12, 0.58) * 1.48;
visitor.userData.armRight.rotation.x = reach;
if (t >= 1) {
createRoute(destinations[selectedIndex]);
phase = "routed";
updateSteps();
}
}
if (phase === "routed") {
visitor.userData.armRight.rotation.x = THREE.MathUtils.damp(
visitor.userData.armRight.rotation.x,
0.12,
5,
dt
);
}
let walking = 0;
if (phase === "approach") {
walking = 1 - Math.min(timeline / 4.8, 1);
} else if (phase === "selecting") {
walking =
Math.sin(
Math.min((timeline - selectionStart) / 1.35, 1) * Math.PI
) * 0.28;
}
const stride = Math.sin(timeline * 8.5) * 0.58 * walking;
visitor.userData.legLeft.rotation.x = stride;
visitor.userData.legRight.rotation.x = -stride;
visitor.userData.armLeft.rotation.x = -stride * 0.7;
if (phase === "approach") {
visitor.position.y = Math.abs(Math.sin(timeline * 8.5)) * 0.035 * walking;
} else {
visitor.position.y = THREE.MathUtils.damp(
visitor.position.y,
0,
8,
dt
);
}
updateCardAppearance(dt);
updateRoute();
}
// -------------------------------------------------------------------------
// Camera and controls implemented directly without Three.js addons
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0.62,
pitch: 0.52,
distance: 21,
distanceTarget: 21,
target: new THREE.Vector3(0, 0.85, -1),
targetDesired: new THREE.Vector3(0, 0.85, -1)
};
function updateCamera(dt) {
cameraState.target.lerp(
cameraState.targetDesired,
1 - Math.exp(-dt * 4.5)
);
cameraState.distance = THREE.MathUtils.damp(
cameraState.distance,
cameraState.distanceTarget,
5,
dt
);
const horizontal = Math.cos(cameraState.pitch) * cameraState.distance;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
}
let pointerDown = false;
let pointerMoved = false;
let pointerX = 0;
let pointerY = 0;
let previousX = 0;
let previousY = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function cardHit(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(cardMeshes, false);
return hits.length ? hits[0].object.userData.index : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
pointerX = previousX = event.clientX;
pointerY = previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerDown) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (
Math.abs(event.clientX - pointerX) +
Math.abs(event.clientY - pointerY) >
4
) {
pointerMoved = true;
}
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.18,
1.08
);
previousX = event.clientX;
previousY = event.clientY;
cameraState.targetDesired.copy(cameraState.target);
} else {
const hit = cardHit(event);
if (hit !== hoveredIndex) {
hoveredIndex = hit;
renderer.domElement.style.cursor = hit === null ? "grab" : "pointer";
}
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick = pointerDown && !pointerMoved;
pointerDown = false;
if (wasClick) {
const hit = cardHit(event);
if (hit !== null) chooseDestination(hit);
}
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distanceTarget = THREE.MathUtils.clamp(
cameraState.distanceTarget + event.deltaY * 0.012,
9,
31
);
},
{ passive: false }
);
function resetCamera() {
cameraState.yaw = 0.62;
cameraState.pitch = 0.52;
cameraState.distanceTarget = 21;
cameraState.targetDesired.set(0, 0.85, -1);
}
function focusRoute() {
if (!routeData) return;
const bounds = new THREE.Box3();
routeData.points.forEach((point) => bounds.expandByPoint(point));
const center = bounds.getCenter(new THREE.Vector3());
center.y = 0.8;
const size = bounds.getSize(new THREE.Vector3());
cameraState.targetDesired.copy(center);
cameraState.distanceTarget = THREE.MathUtils.clamp(
Math.max(size.x, size.z) * 1.05,
12,
26
);
cameraState.pitch = 0.65;
}
destinationButtons.forEach((button) => {
button.addEventListener("click", () => {
chooseDestination(Number(button.dataset.index));
});
});
document.querySelector("#replayButton").addEventListener("click", resetScene);
document.querySelector("#homeButton").addEventListener("click", resetCamera);
focusButton.addEventListener("click", focusRoute);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetScene();
if (event.key.toLowerCase() === "h") resetCamera();
if (event.key.toLowerCase() === "f") focusRoute();
if (["1", "2", "3", "4"].includes(event.key)) {
chooseDestination(Number(event.key) - 1);
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
resetScene();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
updateAnimation(dt);
updateCamera(dt);
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```