Prompt specification
Build or customize the Three.js 3D scene "Silent Comic Diorama Triptych" 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: Silent Comic Diorama Triptych
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/silent-comic-diorama-triptych-x3351
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring visual story sequences and continuity. Build three connected dioramas showing a fictional lost-and-found event. Use gaze, placement, and action consequences to make the sequence legible without dialogue. Voxel style.
Working Three.js Starter (silent-comic-diorama-triptych-x3351):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
<title>The Thing Between Places — A Lost-and-Found Diorama</title>
<style>
:root {
--ink: #101827;
--paper: #f5ead2;
--muted: #aab5c2;
--gold: #f4b942;
--cyan: #57d8df;
--panel: rgba(15, 24, 38, 0.84);
--line: rgba(245, 234, 210, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
color: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
button {
font: inherit;
}
.ui {
position: fixed;
z-index: 10;
pointer-events: none;
}
.topbar {
top: 0;
left: 0;
right: 0;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
padding: 24px 28px;
background: linear-gradient(180deg, rgba(8, 14, 24, .78), transparent);
}
.eyebrow {
margin: 0 0 7px;
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: .25em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 37px);
line-height: .98;
letter-spacing: -.045em;
font-weight: 850;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: .04em;
}
.top-actions {
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.glass-button {
border: 1px solid var(--line);
border-radius: 999px;
padding: 10px 14px;
color: var(--paper);
background: rgba(15, 24, 38, .64);
backdrop-filter: blur(12px);
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: .13em;
text-transform: uppercase;
transition: border-color .2s, background .2s, transform .2s;
}
.glass-button:hover {
border-color: rgba(244, 185, 66, .7);
background: rgba(244, 185, 66, .1);
transform: translateY(-1px);
}
.progress-wrap {
position: fixed;
z-index: 12;
top: 26px;
left: 50%;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 12px;
padding: 9px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(12, 20, 32, .64);
backdrop-filter: blur(12px);
pointer-events: none;
}
.progress-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #465263;
transition: background .3s, box-shadow .3s, transform .3s;
}
.progress-dot.active {
background: var(--gold);
box-shadow: 0 0 0 4px rgba(244, 185, 66, .13);
transform: scale(1.12);
}
.progress-dot.done {
background: var(--cyan);
}
.progress-label {
min-width: 62px;
color: var(--paper);
font-size: 9px;
font-weight: 800;
letter-spacing: .16em;
text-align: right;
}
.objective-panel {
left: 28px;
bottom: 104px;
width: min(360px, calc(100vw - 56px));
padding: 15px 17px 16px;
border: 1px solid var(--line);
border-left: 3px solid var(--gold);
border-radius: 3px 14px 14px 3px;
background: var(--panel);
backdrop-filter: blur(15px);
box-shadow: 0 16px 45px rgba(0, 0, 0, .24);
}
.objective-kicker {
color: var(--gold);
font-size: 9px;
font-weight: 850;
letter-spacing: .2em;
text-transform: uppercase;
}
.objective-text {
margin-top: 7px;
font-size: 14px;
font-weight: 650;
line-height: 1.4;
}
.objective-detail {
margin-top: 7px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.stage-rail {
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
align-items: stretch;
gap: 6px;
width: min(760px, calc(100vw - 36px));
padding: 7px;
border: 1px solid var(--line);
border-radius: 18px;
background: rgba(12, 20, 32, .8);
backdrop-filter: blur(18px);
box-shadow: 0 20px 60px rgba(0, 0, 0, .32);
pointer-events: auto;
}
.stage-card {
position: relative;
flex: 1;
min-width: 0;
padding: 12px 14px;
border: 1px solid transparent;
border-radius: 12px;
background: transparent;
color: var(--muted);
cursor: default;
transition: .25s;
}
.stage-card.current {
border-color: rgba(244, 185, 66, .28);
background: rgba(244, 185, 66, .08);
color: var(--paper);
}
.stage-card.done {
color: #b9dadd;
}
.stage-number {
color: var(--gold);
font-size: 9px;
font-weight: 900;
letter-spacing: .18em;
}
.stage-name {
margin-top: 5px;
overflow: hidden;
font-size: 12px;
font-weight: 800;
text-overflow: ellipsis;
white-space: nowrap;
}
.stage-state {
position: absolute;
top: 13px;
right: 13px;
width: 7px;
height: 7px;
border-radius: 50%;
background: #465263;
}
.stage-card.current .stage-state { background: var(--gold); }
.stage-card.done .stage-state { background: var(--cyan); }
.legend {
right: 28px;
bottom: 113px;
color: rgba(245, 234, 210, .55);
font-size: 9px;
font-weight: 700;
letter-spacing: .09em;
line-height: 1.8;
text-align: right;
text-transform: uppercase;
}
.legend b { color: var(--paper); }
#cursor {
position: fixed;
z-index: 30;
top: 0;
left: 0;
width: 28px;
height: 28px;
margin: -14px 0 0 -14px;
border: 1px solid rgba(245, 234, 210, .34);
border-radius: 50%;
pointer-events: none;
opacity: 0;
transition: width .2s, height .2s, margin .2s, border-color .2s, box-shadow .2s;
}
#cursor.active {
border-color: var(--gold);
box-shadow: 0 0 0 5px rgba(244, 185, 66, .1);
}
#cursor.searching {
width: 38px;
height: 38px;
margin: -19px 0 0 -19px;
border-color: var(--cyan);
box-shadow: 0 0 0 7px rgba(87, 216, 223, .09);
}
#tooltip {
position: fixed;
z-index: 31;
top: 0;
left: 0;
max-width: 230px;
padding: 7px 10px;
border: 1px solid rgba(244, 185, 66, .35);
border-radius: 7px;
background: rgba(8, 14, 24, .9);
color: var(--paper);
font-size: 9px;
font-weight: 850;
letter-spacing: .12em;
line-height: 1.3;
pointer-events: none;
opacity: 0;
transform: translate(17px, 18px);
transition: opacity .15s;
text-transform: uppercase;
}
#tooltip.visible { opacity: 1; }
.grain {
position: fixed;
z-index: 4;
inset: 0;
opacity: .1;
pointer-events: none;
background-image:
radial-gradient(circle at 30% 20%, rgba(255,255,255,.12) 0 1px, transparent 1px),
radial-gradient(circle at 70% 60%, rgba(255,255,255,.09) 0 1px, transparent 1px);
background-size: 7px 7px, 11px 11px;
mix-blend-mode: soft-light;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: var(--ink);
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: .22em;
transition: opacity .5s;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
.progress-wrap { top: 102px; }
.topbar { padding: 20px; }
.subtitle, .legend { display: none; }
.objective-panel {
left: 18px;
bottom: 94px;
width: calc(100vw - 36px);
}
.stage-rail { bottom: 14px; }
.stage-card { padding: 11px 9px; }
.stage-name { font-size: 10px; }
.top-actions { flex-direction: column; align-items: flex-end; }
.glass-button { padding: 8px 10px; font-size: 8px; }
}
</style>
</head>
<body>
<div id="loading">BUILDING THE DIORAMA…</div>
<div class="grain"></div>
<header class="ui topbar">
<div>
<p class="eyebrow">A miniature lost-and-found story</p>
<h1>THE THING BETWEEN PLACES</h1>
<p class="subtitle">One cobalt mitten. Three connected moments. No words required.</p>
</div>
<div class="top-actions">
<button class="glass-button" id="overview">Overview</button>
<button class="glass-button" id="reset">Restart</button>
</div>
</header>
<div class="progress-wrap">
<span class="progress-dot active" data-progress="0"></span>
<span class="progress-dot" data-progress="1"></span>
<span class="progress-dot" data-progress="2"></span>
<span class="progress-label" id="progressLabel">01 / 03</span>
</div>
<section class="ui objective-panel">
<div class="objective-kicker" id="objectiveKicker">Current action</div>
<div class="objective-text" id="objectiveText">Hold your gaze on the fallen mitten.</div>
<div class="objective-detail" id="objectiveDetail">
Look carefully; attention reveals what is easy to miss.
</div>
</section>
<nav class="ui stage-rail" aria-label="Story stages">
<div class="stage-card current" data-stage="0">
<span class="stage-number">01</span>
<div class="stage-name">Departure</div>
<span class="stage-state"></span>
</div>
<div class="stage-card" data-stage="1">
<span class="stage-number">02</span>
<div class="stage-name">The Trace</div>
<span class="stage-state"></span>
</div>
<div class="stage-card" data-stage="2">
<span class="stage-number">03</span>
<div class="stage-name">Return</div>
<span class="stage-state"></span>
</div>
</nav>
<div class="ui legend">
<b>Drag</b> to orbit<br />
<b>Scroll</b> to zoom<br />
<b>Hover</b> to look<br />
<b>Click</b> to take / place
</div>
<div id="cursor"></div>
<div id="tooltip"></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 renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101827);
scene.fog = new THREE.Fog(0x101827, 26, 62);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 120);
const hemi = new THREE.HemisphereLight(0xcfe7ff, 0x273247, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe2b0, 3.4);
sun.position.set(-7, 18, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x78bde0, 1.25);
coolFill.position.set(18, 8, -12);
scene.add(coolFill);
const warmReturn = new THREE.PointLight(0xffb94f, 0, 12, 2);
warmReturn.position.set(14, 4, 2);
scene.add(warmReturn);
const gazeLight = new THREE.PointLight(0xffe3a0, 0, 6, 2);
scene.add(gazeLight);
const interactiveMeshes = [];
const targets = [];
const people = [];
const confetti = [];
const tweens = [];
const C = {
ink: 0x101827,
navy: 0x1d3148,
blue: 0x294b66,
stone: 0x526170,
stoneDark: 0x354454,
cream: 0xf2e5c7,
gold: 0xf4b942,
cyan: 0x57d8df,
cobalt: 0x287fc4,
rust: 0xc75d42,
green: 0x4d8a68,
greenDark: 0x315946,
wood: 0x936846,
white: 0xfff7df,
red: 0xd34b4e,
glass: 0x8ad7df
};
const materialCache = new Map();
function material(color, options = {}) {
if (Object.keys(options).length) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
}
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({ color, roughness: 0.82, metalness: 0 })
);
}
return materialCache.get(color);
}
function box(w, h, d, color, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
typeof color === "number" ? material(color) : color
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeCanvasTexture(draw, width = 512, height = 160) {
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 labelTexture(text, bg = "#152237", fg = "#f5ead2") {
return makeCanvasTexture((ctx, w, h) => {
ctx.fillStyle = bg;
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#f4b942";
ctx.lineWidth = 8;
ctx.strokeRect(8, 8, w - 16, h - 16);
ctx.fillStyle = fg;
ctx.font = "800 47px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, w / 2, h / 2 + 2);
});
}
function sign(text, x, y, z, w = 4.5, h = 1.15, accent = false) {
const group = new THREE.Group();
group.position.set(x, y, z);
scene.add(group);
box(w + .14, h + .14, .16, C.ink, 0, 0, 0, group);
box(w + .02, h + .02, .18, accent ? C.gold : C.stone, 0, 0, -.015, group);
const texture = labelTexture(text, accent ? "#f4b942" : "#152237", accent ? "#101827" : "#f5ead2");
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(w, h),
new THREE.MeshBasicMaterial({ map: texture })
);
plane.position.z = .105;
group.add(plane);
return group;
}
function pixelStar(pattern, size, color, parent, z = .16) {
const group = new THREE.Group();
parent.add(group);
const rows = pattern.length;
const cols = pattern[0].length;
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
if (pattern[y][x] !== "1") continue;
const px = (x - (cols - 1) / 2) * size;
const py = ((rows - 1) / 2 - y) * size;
box(size * .92, size * .92, .035, color, px, py, z, group);
}
}
return group;
}
const starPattern = [
"00100",
"01110",
"11111",
"01110",
"00100"
];
// -------------------------------------------------------------------------
// Shared diorama floor and connecting path
// -------------------------------------------------------------------------
box(72, .45, 24, 0x182638, 0, -.95, 0);
function makeDiorama(x, width, accent) {
box(width, 1, 10, C.stoneDark, x, -.5, 0);
box(width - .2, .13, 9.8, 0x667382, x, -.06, 0);
box(width - .5, .06, .65, accent, x, .04, 2.7);
box(width - .5, .06, .65, accent, x, .04, -2.7);
}
makeDiorama(-14, 15, C.gold);
makeDiorama(0, 14, C.cyan);
makeDiorama(14, 15, C.gold);
// Physical connectors between the three scenes.
box(2.2, .13, 2.4, C.stone, -6.5, -.02, 1.3);
box(2.2, .13, 2.4, C.stone, 6.5, -.02, 1.3);
for (let i = 0; i < 9; i++) {
box(.22, .04, .65, C.gold, -6.9 + i * .75, .075, 1.3);
box(.22, .04, .65, C.gold, 6.9 + i * .75, .075, 1.3);
}
// -------------------------------------------------------------------------
// Scene 1 — Departure
// -------------------------------------------------------------------------
const station = new THREE.Group();
scene.add(station);
// Rails and train.
box(15.5, .08, .09, 0x8d9aa5, -14.3, .08, -4.45, station);
box(15.5, .08, .09, 0x8d9aa5, -14.3, .08, -5.35, station);
for (let x = -21.5; x < -6.5; x += 1.2) {
box(.16, .08, 1.35, C.wood, x, .02, -4.9, station);
}
box(8.7, 2.15, 1.65, C.navy, -15.1, 1.15, -4.9, station);
box(8.9, .18, 1.78, C.cream, -15.1, 2.28, -4.9, station);
box(8.3, .4, 1.72, C.gold, -15.1, .38, -4.9, station);
box(8.9, .45, 1.65, C.ink, -15.1, .26, -4.9, station);
for (let i = 0; i < 5; i++) {
box(1.05, .72, .05, C.glass, -18.2 + i * 1.55, 1.52, -4.05, station);
box(1.05, .72, .05, C.glass, -18.2 + i * 1.55, 1.52, -5.75, station);
}
// Bench.
box(4.2, .18, .75, C.wood, -14.3, .66, .2, station);
box(4.2, .75, .15, C.wood, -14.3, 1.13, -.15, station);
box(.18, .9, .18, C.stoneDark, -16.1, .32, .2, station);
box(.18, .9, .18, C.stoneDark, -12.5, .32, .2, station);
// Platform lamp.
box(.16, 4.2, .16, C.stoneDark, -18.1, 2.1, -1.7, station);
box(.9, .18, .5, C.ink, -17.67, 4.12, -1.7, station);
box(.62, .12, .35, 0xffdf94, -17.67, 3.96, -1.7, station);
sign("01 / DEPARTURE", -18.1, 3.25, -2.6, 4.3, 1.05);
// Station basket / intake.
const basket = new THREE.Group();
basket.position.set(-7.45, 0, 1.55);
scene.add(basket);
box(1.65, .18, 1.25, C.stoneDark, 0, .14, 0, basket);
box(1.65, .85, .13, C.stone, 0, .55, -.56, basket);
box(.13, .85, 1.25, C.stone, -.76, .55, 0, basket);
box(.13, .85, 1.25, C.stone, .76, .55, 0, basket);
box(.18, .42, .8, C.ink, 0, .42, .12, basket);
box(.22, .12, .92, C.gold, 0, .83, 0, basket);
// A generic commuter in the first scene.
const commuter = makePerson(C.rust, 0xc98963, 0x342d32, -18.0, 0, 1.25);
commuter.rotation.y = -.35;
// -------------------------------------------------------------------------
// Scene 2 — Lost-and-found booth
// -------------------------------------------------------------------------
const booth = new THREE.Group();
scene.add(booth);
// Open booth structure.
box(10.8, 3.5, .35, C.navy, 0, 1.75, -2.55, booth);
box(11.2, .3, 2.1, C.cream, 0, 3.55, -1.55, booth);
box(.28, 3.4, .28, C.gold, -5.35, 1.7, -.55, booth);
box(.28, 3.4, .28, C.gold, 5.35, 1.7, -.55, booth);
box(10.8, .25, .25, C.gold, 0, 3.35, -.55, booth);
// Counter.
box(9.4, 1.05, 1.35, C.blue, 0, .52, -.45, booth);
box(9.65, .18, 1.55, C.cream, 0, 1.13, -.45, booth);
box(9.3, .12, .1, C.gold, 0, .87, .25, booth);
sign("02 / THE TRACE", 0, 3.05, -2.3, 5.8, 1.0);
// Intake tray.
box(2.25, .15, 1.7, C.stoneDark, -2.55, 1.26, .82, booth);
box(2.05, .08, 1.5, C.cyan, -2.55, 1.36, .82, booth);
sign("INTAKE", -2.55, .72, .31, 1.8, .55);
// Inspection pad.
box(2.25, .15, 1.7, C.stoneDark, -.05, 1.26, .82, booth);
box(2.02, .08, 1.48, C.gold, -.05, 1.36, .82, booth);
sign("MATCH", -.05, .72, .31, 1.65, .55, true);
// Ticket rack.
box(1.7, .16, 1.1, C.stoneDark, 3.0, 1.28, -.05, booth);
box(.13, .9, .13, C.stoneDark, 2.35, 1.75, -.45, booth);
box(.13, .9, .13, C.stoneDark, 3.65, 1.75, -.45, booth);
box(1.55, .12, .15, C.stoneDark, 3.0, 2.12, -.45, booth);
sign("CLAIMS", 3.0, 2.75, -.4, 2.5, .72);
// Dispatch drawer.
box(2.0, 1.3, 1.4, C.navy, 4.25, .7, 1.55, booth);
box(1.72, .15, .06, C.gold, 4.25, .95, 2.28, booth);
box(1.72, .15, .06, C.gold, 4.25, .48, 2.28, booth);
sign("OUT", 4.25, .28, 2.35, 1.25, .48);
// Magnifying inspection lamp.
const magnifier = new THREE.Group();
magnifier.position.set(-3.25, 2.45, .7);
scene.add(magnifier);
box(.12, 1.55, .12, C.stoneDark, 0, -.3, 0, magnifier);
box(1.0, .09, .09, C.stoneDark, .42, .42, 0, magnifier);
box(.9, .08, .75, C.gold, .82, .34, 0, magnifier);
box(.75, .035, .6, 0xffe6a0, .82, .285, 0, magnifier);
// -------------------------------------------------------------------------
// Scene 3 — Return garden
// -------------------------------------------------------------------------
const garden = new THREE.Group();
scene.add(garden);
// Notice board.
box(.2, 2.75, .2, C.wood, 9.25, 1.35, -2.0, garden);
box(.2, 2.75, .2, C.wood, 11.95, 1.35, -2.0, garden);
box(3.35, 2.25, .2, C.wood, 10.6, 2.05, -2.0, garden);
const noticeTexture = makeCanvasTexture((ctx, w, h) => {
ctx.fillStyle = "#17253a";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#f4b942";
ctx.lineWidth = 12;
ctx.strokeRect(10, 10, w - 20, h - 20);
const pattern = [
"00100",
"01110",
"11111",
"01110",
"00100"
];
const size = 24;
const ox = w / 2 - 60;
const oy = 42;
ctx.fillStyle = "#f4b942";
for (let y = 0; y < pattern.length; y++) {
for (let x = 0; x < pattern[y].length; x++) {
if (pattern[y][x] === "1") ctx.fillRect(ox + x * size, oy + y * size, size, size);
}
}
ctx.fillStyle = "#f5ead2";
ctx.font = "800 41px sans-serif";
ctx.textAlign = "center";
ctx.fillText("GOLD STAR", w / 2, 220);
ctx.font = "800 29px sans-serif";
ctx.fillText("MITTEN", w / 2, 262);
ctx.fillStyle = "#57d8df";
ctx.font = "800 24px sans-serif";
ctx.fillText("RETURN DESK", w / 2, 332);
}, 512, 390);
const noticeFace = new THREE.Mesh(
new THREE.PlaneGeometry(3.02, 2.02),
new THREE.MeshBasicMaterial({ map: noticeTexture })
);
noticeFace.position.set(10.6, 2.05, -1.88);
garden.add(noticeFace);
const noticeHalo = new THREE.Group();
noticeHalo.position.set(10.6, 2.05, -1.78);
scene.add(noticeHalo);
box(3.35, .06, .06, C.gold, 0, 1.18, 0, noticeHalo);
box(3.35, .06, .06, C.gold, 0, -1.18, 0, noticeHalo);
box(.06, 2.42, .06, C.gold, -1.67, 0, 0, noticeHalo);
box(.06, 2.42, .06, C.gold, 1.67, 0, 0, noticeHalo);
noticeHalo.visible = false;
// Arrival tray.
box(2.0, 1.0, 1.4, C.blue, 16.45, .5, 1.6, garden);
box(2.15, .15, 1.55, C.cyan, 16.45, 1.05, 1.6, garden);
sign("ARRIVALS", 16.45, .65, 2.33, 1.85, .55);
// Return cradle.
box(1.7, .18, 1.5, C.stoneDark, 13.35, .95, 1.45, garden);
box(1.45, .12, 1.2, C.gold, 13.35, 1.09, 1.45, garden);
box(.12, .65, 1.4, C.gold, 12.55, 1.3, 1.45, garden);
box(.12, .65, 1.4, C.gold, 14.15, 1.3, 1.45, garden);
sign("RETURN", 13.35, .55, 2.25, 1.75, .55, true);
// Bench and waiting traveler.
box(3.3, .18, .72, C.wood, 15.55, .64, -.55, garden);
box(3.3, .72, .14, C.wood, 15.55, 1.08, -.87, garden);
box(.17, .8, .17, C.stoneDark, 14.15, .3, -.55, garden);
box(.17, .8, .17, C.stoneDark, 16.95, .3, -.55, garden);
const owner = makePerson(C.blue, 0xdca77e, 0x51352f, 15.65, 0, -.15);
owner.rotation.y = .08;
// Voxel trees and planters.
makeTree(19.1, -2.45, 1.0);
makeTree(8.0, -2.75, .78);
box(1.4, .55, 1.4, C.wood, 18.8, .27, 2.55, garden);
box(.8, .55, .8, C.greenDark, 18.8, .78, 2.55, garden);
// Small garden lamp.
box(.14, 3.4, .14, C.stoneDark, 12.0, 1.7, 2.8, garden);
box(.62, .16, .62, C.ink, 12, 3.45, 2.8, garden);
box(.42, .1, .42, 0xffdc83, 12, 3.32, 2.8, garden);
// -------------------------------------------------------------------------
// Character factory
// -------------------------------------------------------------------------
function makePerson(coatColor, skinColor, hairColor, x, y, z) {
const group = new THREE.Group();
group.position.set(x, y, z);
scene.add(group);
box(.27, .65, .32, C.ink, -.19, .38, 0, group);
box(.27, .65, .32, C.ink, .19, .38, 0, group);
box(.3, .18, .46, C.ink, -.19, .09, .08, group);
box(.3, .18, .46, C.ink, .19, .09, .08, group);
box(.78, .78, .46, coatColor, 0, 1.05, 0, group);
box(.1, .55, .02, C.cream, .06, 1.08, .24, group);
const leftArm = box(.2, .7, .23, coatColor, -.51, 1.03, 0, group);
const rightArm = box(.2, .7, .23, coatColor, .51, 1.03, 0, group);
leftArm.rotation.z = -.1;
rightArm.rotation.z = .1;
box(.2, .18, .22, skinColor, -.51, .64, 0, group);
box(.2, .18, .22, skinColor, .51, .64, 0, group);
const head = new THREE.Group();
head.position.y = 1.72;
group.add(head);
box(.62, .62, .58, skinColor, 0, 0, 0, head);
box(.66, .2, .62, hairColor, 0, .28, -.02, head);
box(.16, .34, .54, hairColor, -.28, .03, -.03, head);
box(.07, .07, .03, C.ink, -.13, .02, .301, head);
box(.07, .07, .03, C.ink, .13, .02, .301, head);
box(.16, .04, .03, 0x8f5c51, 0, -.14, .304, head);
const handAnchor = new THREE.Object3D();
handAnchor.position.set(.51, .67, .05);
group.add(handAnchor);
people.push({ group, head });
group.userData.handAnchor = handAnchor;
return group;
}
function makeTree(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.scale.setScalar(scale);
scene.add(g);
box(.42, 2.5, .42, C.wood, 0, 1.25, 0, g);
box(2.4, 1.4, 1.7, C.greenDark, 0, 2.7, 0, g);
box(1.65, 1.25, 1.4, C.green, -.28, 3.45, .08, g);
box(1.5, 1.0, 1.25, 0x639774, .52, 3.05, -.18, g);
}
// -------------------------------------------------------------------------
// The persistent mitten and claim card
// -------------------------------------------------------------------------
const mitten = new THREE.Group();
mitten.position.set(-10.75, .04, 2.1);
scene.add(mitten);
box(.68, .62, .3, C.cobalt, 0, .38, 0, mitten);
box(.3, .31, .26, C.cobalt, .43, .45, 0, mitten);
box(.75, .22, .35, C.navy, 0, .07, 0, mitten);
box(.16, .12, .11, C.cream, .2, .76, 0, mitten);
const mittenStar = pixelStar(starPattern, .075, C.gold, mitten, .171);
mittenStar.position.set(.02, .43, 0);
mittenStar.visible = false;
const ticket = new THREE.Group();
ticket.position.set(3.0, 1.92, -.43);
scene.add(ticket);
box(.72, .82, .07, C.cream, 0, 0, 0, ticket);
const ticketTexture = makeCanvasTexture((ctx, w, h) => {
ctx.fillStyle = "#f5ead2";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#d4a638";
ctx.lineWidth = 10;
ctx.strokeRect(6, 6, w - 12, h - 12);
ctx.fillStyle = "#17253a";
ctx.font = "800 36px sans-serif";
ctx.textAlign = "center";
ctx.fillText("GOLD STAR", w / 2, 73);
const p = [
"00100",
"01110",
"11111",
"01110",
"00100"
];
const s = 19;
const ox = w / 2 - 47.5;
const oy = 93;
ctx.fillStyle = "#f4b942";
for (let y = 0; y < p.length; y++) {
for (let x = 0; x < p[y].length; x++) {
if (p[y][x] === "1") ctx.fillRect(ox + x * s, oy + y * s, s, s);
}
}
ctx.fillStyle = "#17253a";
ctx.font = "700 23px sans-serif";
ctx.fillText("MITTEN / CLAIM", w / 2, 226);
}, 400, 260);
const ticketFace = new THREE.Mesh(
new THREE.PlaneGeometry(.65, .75),
new THREE.MeshBasicMaterial({ map: ticketTexture })
);
ticketFace.position.z = .039;
ticket.add(ticketFace);
// -------------------------------------------------------------------------
// Interactive registrations and placement targets
// -------------------------------------------------------------------------
function register(root, base) {
root.traverse(obj => {
if (!obj.isMesh) return;
obj.userData.interaction = { base };
interactiveMeshes.push(obj);
});
}
register(mitten, "mitten");
register(ticket, "ticket");
register(noticeFace, "notice");
function createTarget(key, x, y, z, color = C.gold, size = 1.7) {
const group = new THREE.Group();
group.position.set(x, y, z);
scene.add(group);
const targetMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: .22,
depthWrite: false
});
const h = size / 2;
const arm = .42;
const thickness = .075;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(arm, thickness, thickness, targetMaterial, sx * (h - arm / 2), 0, sz * h, group);
box(thickness, thickness, arm, targetMaterial, sx * h, 0, sz * (h - arm / 2), group);
}
}
const hit = new THREE.Mesh(
new THREE.BoxGeometry(size * .9, .6, size * .9),
new THREE.MeshBasicMaterial({ transparent: true, opacity: 0, depthWrite: false })
);
hit.position.y = .22;
group.add(hit);
register(hit, key);
targets.push({ key, group, material: targetMaterial, baseOpacity: .22 });
return group;
}
createTarget("basket", -7.45, .88, 1.55, C.gold, 1.8);
createTarget("pad", -.05, 1.43, .82, C.gold, 1.8);
createTarget("cradle", 13.35, 1.18, 1.45, C.gold, 1.7);
// Small visual beacon revealed after the first act of looking.
const itemBeacon = new THREE.Group();
scene.add(itemBeacon);
box(.055, .65, .055, C.gold, 0, .35, 0, itemBeacon);
box(.16, .16, .16, C.gold, 0, .75, 0, itemBeacon);
itemBeacon.visible = false;
// -------------------------------------------------------------------------
// State and UI
// -------------------------------------------------------------------------
const state = {
stage: 0,
unlocked: 0,
gazeMitten: false,
inspected: false,
noticed: false,
carrying: null,
interactionLocked: false,
completed: [false, false, false],
overview: false
};
const objectiveKicker = document.getElementById("objectiveKicker");
const objectiveText = document.getElementById("objectiveText");
const objectiveDetail = document.getElementById("objectiveDetail");
const progressLabel = document.getElementById("progressLabel");
const cursor = document.getElementById("cursor");
const tooltip = document.getElementById("tooltip");
const overviewButton = document.getElementById("overview");
const stageCards = [...document.querySelectorAll(".stage-card")];
const progressDots = [...document.querySelectorAll(".progress-dot")];
function updateUI() {
progressLabel.textContent = `${String(state.stage + 1).padStart(2, "0")} / 03`;
progressDots.forEach((dot, i) => {
dot.classList.toggle("active", i === state.stage && !state.completed[i]);
dot.classList.toggle("done", state.completed[i]);
});
stageCards.forEach((card, i) => {
card.classList.toggle("current", i === state.stage && !state.completed[i]);
card.classList.toggle("done", state.completed[i]);
});
if (state.completed[2]) {
objectiveKicker.textContent = "Match confirmed";
objectiveText.textContent = "The cobalt mitten is back in its owner’s hand.";
objectiveDetail.textContent = "The gold star connected the departure, the claim card, and the return.";
} else if (state.stage === 0) {
objectiveKicker.textContent = "01 — Departure";
if (!state.gazeMitten) {
objectiveText.textContent = "Hold your gaze on the fallen mitten.";
objectiveDetail.textContent = "Look carefully; attention reveals what is easy to miss.";
} else {
objectiveText.textContent = "Take the mitten and place it in the glowing intake basket.";
objectiveDetail.textContent = "Click the mitten, then click the gold target beside the path.";
}
} else if (state.stage === 1) {
objectiveKicker.textContent = "02 — The trace";
if (!state.inspected) {
objectiveText.textContent = "Inspect the mitten under the booth lamp.";
objectiveDetail.textContent = "Keep looking at the mitten until the hidden star is revealed.";
} else {
objectiveText.textContent = "Place the gold-star claim card beside the mitten.";
objectiveDetail.textContent = "Take the card from the claims rack and place it on the match pad.";
}
} else {
objectiveKicker.textContent = "03 — Return";
if (!state.noticed) {
objectiveText.textContent = "Look at the garden’s return notice.";
objectiveDetail.textContent = "The notice repeats the symbol discovered during inspection.";
} else {
objectiveText.textContent = "Take the arrived mitten and place it in the return cradle.";
objectiveDetail.textContent = "The same cobalt mitten has followed the entire route.";
}
}
}
// -------------------------------------------------------------------------
// Camera: authored views plus direct orbit / zoom controls
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(-13.4, .7, .1),
desiredTarget: new THREE.Vector3(-13.4, .7, .1),
yaw: .58,
desiredYaw: .58,
pitch: .73,
desiredPitch: .73,
zoom: 1.03,
desiredZoom: 1.03
};
const views = [
{ target: [-13.4, .7, .1], yaw: .58, pitch: .73, zoom: 1.03 },
{ target: [-.2, 1.1, .1], yaw: .65, pitch: .76, zoom: 1.07 },
{ target: [14.0, .8, .1], yaw: .72, pitch: .73, zoom: 1.03 }
];
function focusStage(index) {
const view = views[index];
cameraState.desiredTarget.set(...view.target);
cameraState.desiredYaw = view.yaw;
cameraState.desiredPitch = view.pitch;
cameraState.desiredZoom = view.zoom;
state.overview = false;
overviewButton.textContent = "Overview";
}
function showOverview() {
cameraState.desiredTarget.set(0, .55, 0);
cameraState.desiredYaw = .72;
cameraState.desiredPitch = .9;
cameraState.desiredZoom = .55;
state.overview = true;
overviewButton.textContent = "Focus scene";
}
overviewButton.addEventListener("click", () => {
if (state.overview) focusStage(state.stage);
else showOverview();
});
function updateCamera() {
const lerp = .075;
cameraState.target.lerp(cameraState.desiredTarget, lerp);
cameraState.yaw = THREE.MathUtils.lerp(cameraState.yaw, cameraState.desiredYaw, lerp);
cameraState.pitch = THREE.MathUtils.lerp(cameraState.pitch, cameraState.desiredPitch, lerp);
cameraState.zoom = THREE.MathUtils.lerp(cameraState.zoom, cameraState.desiredZoom, lerp);
const radius = 23;
const cp = Math.cos(cameraState.pitch);
const offset = new THREE.Vector3(
Math.sin(cameraState.yaw) * cp,
Math.sin(cameraState.pitch),
Math.cos(cameraState.yaw) * cp
).multiplyScalar(radius);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
// -------------------------------------------------------------------------
// Tween helper
// -------------------------------------------------------------------------
function animateTween(duration, update) {
return new Promise(resolve => {
tweens.push({
start: performance.now(),
duration,
update,
resolve
});
});
}
function updateTweens(now) {
for (let i = tweens.length - 1; i >= 0; i--) {
const tween = tweens[i];
const raw = Math.min(1, (now - tween.start) / tween.duration);
const eased = raw * raw * (3 - 2 * raw);
tween.update(eased);
if (raw >= 1) {
tweens.splice(i, 1);
tween.resolve();
}
}
}
// -------------------------------------------------------------------------
// Raycasting, gaze, carrying, and placement
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const carryPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -1.5);
const carryPoint = new THREE.Vector3();
let hovered = null;
let hoverStart = 0;
let hoverKey = "";
let pointerDown = false;
let orbitDrag = false;
let draggingItem = false;
let lastPointerX = 0;
let lastPointerY = 0;
let pointerTravel = 0;
function isEffectivelyVisible(object) {
let current = object;
while (current) {
if (!current.visible) return false;
current = current.parent;
}
return true;
}
function setPointerFromEvent(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;
}
function getInteraction(mesh) {
const data = mesh.userData.interaction;
if (!data) return null;
const base = data.base;
if (base === "mitten") {
if (state.stage === 0) {
return { kind: state.gazeMitten ? "take" : "look", payload: "mitten", label: "Cobalt mitten" };
}
if (state.stage === 1) {
return { kind: state.inspected ? "hint" : "look", payload: "inspect", label: "Mitten under lamp" };
}
if (state.stage === 2) {
return { kind: "take", payload: "mitten", label: "Arrived mitten" };
}
}
if (base === "ticket" && state.stage === 1) {
if (!state.inspected) return { kind: "hint", payload: "ticket", label: "Inspect the mitten first" };
return { kind: "take", payload: "ticket", label: "Gold-star claim card" };
}
if (base === "notice" && state.stage === 2) {
return { kind: state.noticed ? "hint" : "look", payload: "notice", label: "Return notice" };
}
if (base === "basket" && state.stage === 0) {
return state.carrying === "mitten"
? { kind: "place", payload: "basket", label: "Place in intake basket" }
: { kind: "hint", payload: "basket", label: "Intake basket" };
}
if (base === "pad" && state.stage === 1) {
return state.carrying === "ticket"
? { kind: "place", payload: "pad", label: "Place on match pad" }
: { kind: "hint", payload: "pad", label: "Inspection pad" };
}
if (base === "cradle" && state.stage === 2) {
return state.carrying === "mitten"
? { kind: "place", payload: "cradle", label: "Place in return cradle" }
: { kind: "hint", payload: "cradle", label: "Return cradle" };
}
return null;
}
function updateHover(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactiveMeshes, false);
let found = null;
for (const hit of hits) {
if (!isEffectivelyVisible(hit.object) || hit.object.userData.ownerCarried) continue;
const interaction = getInteraction(hit.object);
if (interaction) {
found = { mesh: hit.object, interaction };
break;
}
}
hovered = found;
if (found) {
const key = found.mesh.uuid + found.interaction.kind;
if (key !== hoverKey) {
hoverKey = key;
hoverStart = performance.now();
}
cursor.classList.add("active");
tooltip.classList.add("visible");
cursor.style.transform = `translate(${event.clientX}px, ${event.clientY}px)`;
tooltip.style.transform = `translate(${event.clientX + 17}px, ${event.clientY + 18}px)`;
let label = found.interaction.label;
if (found.interaction.kind === "look") label = "Look · " + label;
if (found.interaction.kind === "take") label = "Take · " + label;
if (found.interaction.kind === "place") label = "Place · " + label;
tooltip.textContent = label;
} else {
cursor.classList.remove("active");
tooltip.classList.remove("visible");
hoverKey = "";
}
}
function setCarriedFlag(group, value) {
group.traverse(obj => {
if (obj.isMesh) obj.userData.ownerCarried = value;
});
}
function startCarry(payload) {
const group = payload === "ticket" ? ticket : mitten;
state.carrying = payload;
state.carryObject = group;
state.carryScale = group.scale.clone();
setCarriedFlag(group, true);
draggingItem = true;
pointerDown = true;
pointerTravel = 0;
updateCarryPosition();
}
function updateCarryPosition() {
if (!state.carrying) return;
const height = state.carrying === "ticket" ? 1.9 : 1.55;
carryPlane.constant = -height;
raycaster.setFromCamera(pointer, camera);
if (raycaster.ray.intersectPlane(carryPlane, carryPoint)) {
state.carryObject.position.x = carryPoint.x;
state.carryObject.position.z = carryPoint.z;
state.carryObject.position.y = height;
}
}
async function triggerLook(payload) {
if (state.interactionLocked) return;
if (payload === "mitten" && state.stage === 0 && !state.gazeMitten) {
state.gazeMitten = true;
itemBeacon.visible = true;
updateUI();
}
if (payload === "inspect" && state.stage === 1 && !state.inspected) {
state.inspected = true;
mittenStar.visible = true;
updateUI();
}
if (payload === "notice" && state.stage === 2 && !state.noticed) {
state.noticed = true;
noticeHalo.visible = true;
updateUI();
}
hoverStart = performance.now();
}
async function placeCarried() {
if (!state.carrying || state.interactionLocked) return;
const payload = state.carrying;
const object = state.carryObject;
if (payload === "mitten" && state.stage === 0) {
state.interactionLocked = true;
state.carrying = null;
setCarriedFlag(object, false);
const start = object.position.clone();
const end = new THREE.Vector3(-7.45, .58, 1.55);
const startScale = object.scale.clone();
await animateTween(650, t => {
object.position.lerpVectors(start, end, t);
object.scale.setScalar(THREE.MathUtils.lerp(startScale.x, .16, t));
});
object.visible = false;
state.completed[0] = true;
state.stage = 1;
state.unlocked = 1;
itemBeacon.visible = false;
focusStage(1);
object.visible = true;
object.position.set(-2.55, 1.36, .82);
object.scale.setScalar(.05);
await animateTween(500, t => {
const s = THREE.MathUtils.lerp(.05, 1, t);
object.scale.setScalar(s);
object.position.y = THREE.MathUtils.lerp(1.28, 1.36, t);
});
state.interactionLocked = false;
clearHover();
updateUI();
}
if (payload === "ticket" && state.stage === 1) {
state.interactionLocked = true;
state.carrying = null;
setCarriedFlag(object, false);
const start = object.position.clone();
const end = new THREE.Vector3(-.05, 1.53, .82);
const startRotation = object.rotation.clone();
await animateTween(550, t => {
object.position.lerpVectors(start, end, t);
object.rotation.x = THREE.MathUtils.lerp(startRotation.x, -.12, t);
object.rotation.z = THREE.MathUtils.lerp(startRotation.z, -.08, t);
});
// The card physically attaches to the mitten.
mitten.attach(ticket);
ticket.position.set(.42, .56, .21);
ticket.rotation.set(0, 0, -.08);
ticket.scale.setScalar(.44);
const dispatchStart = mitten.position.clone();
const dispatchEnd = new THREE.Vector3(4.25, 1.45, 1.55);
await animateTween(700, t => {
mitten.position.lerpVectors(dispatchStart, dispatchEnd, t);
mitten.scale.setScalar(THREE.MathUtils.lerp(1, .18, t));
});
state.completed[1] = true;
state.stage = 2;
state.unlocked = 2;
focusStage(2);
mitten.position.set(16.45, 1.36, 1.6);
mitten.scale.setScalar(.08);
await animateTween(550, t => {
mitten.scale.setScalar(THREE.MathUtils.lerp(.08, 1, t));
mitten.position.y = THREE.MathUtils.lerp(1.25, 1.36, t);
});
state.interactionLocked = false;
clearHover();
updateUI();
}
if (payload === "mitten" && state.stage === 2) {
state.interactionLocked = true;
state.carrying = null;
setCarriedFlag(object, false);
const start = object.position.clone();
const end = new THREE.Vector3(13.35, 1.25, 1.45);
await animateTween(650, t => {
object.position.lerpVectors(start, end, t);
});
// The waiting traveler steps forward.
const ownerStart = owner.position.clone();
const ownerEnd = new THREE.Vector3(14.45, 0, 1.15);
await animateTween(900, t => {
owner.position.lerpVectors(ownerStart, ownerEnd, t);
});
const hand = owner.userData.handAnchor;
owner.updateMatrixWorld(true);
const handWorld = new THREE.Vector3();
hand.getWorldPosition(handWorld);
const handStart = object.position.clone();
await animateTween(700, t => {
object.position.lerpVectors(handStart, handWorld, t);
object.rotation.z = THREE.MathUtils.lerp(0, -.15, t);
});
hand.attach(object);
object.position.set(0, 0, 0);
object.rotation.set(0, 0, 0);
object.scale.setScalar(.78);
state.completed[2] = true;
state.interactionLocked = false;
warmReturn.intensity = 3.6;
spawnConfetti();
clearHover();
updateUI();
}
}
function clearHover() {
hovered = null;
hoverKey = "";
cursor.classList.remove("active", "searching");
tooltip.classList.remove("visible");
}
renderer.domElement.addEventListener("pointermove", event => {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (pointerDown) pointerTravel += Math.abs(dx) + Math.abs(dy);
if (orbitDrag) {
cameraState.desiredYaw -= dx * .006;
cameraState.desiredPitch = THREE.MathUtils.clamp(
cameraState.desiredPitch + dy * .004,
.42,
1.15
);
} else if (draggingItem) {
updateCarryPosition();
}
updateHover(event);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
renderer.domElement.addEventListener("pointerdown", event => {
lastPointerX = event.clientX;
lastPointerY = event.clientY;
pointerTravel = 0;
pointerDown = true;
updateHover(event);
if (state.interactionLocked) return;
if (state.carrying && hovered?.interaction.kind === "place") {
placeCarried();
return;
}
if (hovered?.interaction.kind === "take") {
startCarry(hovered.interaction.payload);
renderer.domElement.setPointerCapture(event.pointerId);
return;
}
orbitDrag = true;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointerup", event => {
if (draggingItem) {
if (hovered?.interaction.kind === "place") {
placeCarried();
}
draggingItem = false;
} else if (hovered?.interaction.kind === "look" && pointerTravel < 12) {
triggerLook(hovered.interaction.payload);
}
orbitDrag = false;
pointerDown = false;
clearTimeout(window.__releaseTimer);
window.__releaseTimer = setTimeout(() => {
if (!draggingItem) state.carrying = state.carrying;
}, 0);
});
renderer.domElement.addEventListener("pointercancel", () => {
orbitDrag = false;
draggingItem = false;
pointerDown = false;
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!pointerDown) clearHover();
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.desiredZoom = THREE.MathUtils.clamp(
cameraState.desiredZoom - event.deltaY * .001,
.5,
1.55
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Final celebration
// -------------------------------------------------------------------------
function spawnConfetti() {
const colors = [C.gold, C.cyan, C.cream, C.rust, C.green];
for (let i = 0; i < 44; i++) {
const size = .08 + Math.random() * .1;
const mesh = box(
size,
size,
size,
colors[i % colors.length],
owner.position.x + (Math.random() - .5) * 1.6,
2.4 + Math.random() * 1.4,
owner.position.z + (Math.random() - .5) * 1.2
);
confetti.push({
mesh,
velocity: new THREE.Vector3(
(Math.random() - .5) * 2.5,
1.5 + Math.random() * 2.2,
(Math.random() - .5) * 2.0
),
spin: new THREE.Vector3(
Math.random() * 5,
Math.random() * 5,
Math.random() * 5
)
});
}
}
function updateConfetti(dt) {
for (let i = confetti.length - 1; i >= 0; i--) {
const particle = confetti[i];
particle.velocity.y -= 3.8 * dt;
particle.mesh.position.addScaledVector(particle.velocity, dt);
particle.mesh.rotation.x += particle.spin.x * dt;
particle.mesh.rotation.y += particle.spin.y * dt;
particle.mesh.rotation.z += particle.spin.z * dt;
if (particle.mesh.position.y < .05) {
scene.remove(particle.mesh);
particle.mesh.geometry.dispose();
confetti.splice(i, 1);
}
}
}
// -------------------------------------------------------------------------
// Reset
// -------------------------------------------------------------------------
document.getElementById("reset").addEventListener("click", () => {
window.location.reload();
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
let lastTime = performance.now();
function animate(now) {
const dt = Math.min((now - lastTime) / 1000, .05);
lastTime = now;
updateTweens(now);
updateCamera();
updateConfetti(dt);
// Gaze dwell is measured on the currently inspected story object.
if (
hovered?.interaction.kind === "look" &&
!state.interactionLocked
) {
const elapsed = now - hoverStart;
cursor.classList.toggle("searching", elapsed > 260);
if (elapsed > 900) {
triggerLook(hovered.interaction.payload);
}
} else {
cursor.classList.remove("searching");
}
// A soft pool of light follows the user's attention.
if (hovered) {
const world = new THREE.Vector3();
hovered.mesh.getWorldPosition(world);
gazeLight.position.copy(world);
gazeLight.position.y += .8;
gazeLight.intensity = THREE.MathUtils.lerp(gazeLight.intensity, 1.15, .16);
} else {
gazeLight.intensity = THREE.MathUtils.lerp(gazeLight.intensity, 0, .12);
}
// Placement targets glow only when they are useful.
for (const target of targets) {
let active = false;
if (target.key === "basket") active = state.stage === 0 && state.carrying === "mitten";
if (target.key === "pad") active = state.stage === 1 && state.carrying === "ticket";
if (target.key === "cradle") active = state.stage === 2 && state.carrying === "mitten";
const pulse = .72 + Math.sin(now * .004) * .18;
target.material.opacity = THREE.MathUtils.lerp(
target.material.opacity,
active ? .9 * pulse : .16,
.12
);
}
// Inspection lamp slides over the mitten once it has been examined.
if (state.inspected) {
magnifier.position.x = THREE.MathUtils.lerp(magnifier.position.x, -2.55, .08);
magnifier.position.z = THREE.MathUtils.lerp(magnifier.position.z, .82, .08);
}
if (itemBeacon.visible) {
itemBeacon.position.copy(mitten.position);
itemBeacon.position.y += .92;
itemBeacon.position.y += Math.sin(now * .004) * .08;
itemBeacon.rotation.y = now * .001;
}
if (noticeHalo.visible) {
noticeHalo.rotation.z = Math.sin(now * .0018) * .025;
}
warmReturn.intensity = THREE.MathUtils.lerp(warmReturn.intensity, state.completed[2] ? 3.6 : 0, .04);
// Characters turn their heads toward the current point of attention.
for (const person of people) {
if (hovered) {
const point = new THREE.Vector3();
hovered.mesh.getWorldPosition(point);
const local = person.group.worldToLocal(point.clone());
const desiredYaw = Math.atan2(local.x, local.z);
person.head.rotation.y = THREE.MathUtils.lerp(
person.head.rotation.y,
THREE.MathUtils.clamp(desiredYaw, -.65, .65),
.06
);
} else {
person.head.rotation.y = THREE.MathUtils.lerp(person.head.rotation.y, 0, .04);
}
}
renderer.render(scene, camera);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
camera.left = -8 * aspect;
camera.right = 8 * aspect;
camera.top = 8;
camera.bottom = -8;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
}
window.addEventListener("resize", resize);
resize();
updateUI();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
setTimeout(() => document.getElementById("loading").remove(), 600);
});
</script>
</body>
</html>
```