Prompt specification
Build or customize the Three.js 3D scene "Winter coatroom departure scene" 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: Winter coatroom departure scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/winter-coatroom-departure-scene-x0615
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Compose coats, scarves, bench, and doorway; a visitor wraps a scarf, collects a bag, and leaves while unused garments remain neatly associated with their hooks.
Working Three.js Starter (winter-coatroom-departure-scene-x0615):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Last Thread — A Voxel Cloakroom</title>
<style>
:root {
--ink: #253b39;
--muted: #6c7771;
--paper: rgba(248, 244, 232, 0.92);
--line: rgba(37, 59, 57, 0.16);
--accent: #dda94c;
--blue: #4e78a5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e2d5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow:
0 18px 50px rgba(49, 57, 50, 0.14),
0 2px 8px rgba(49, 57, 50, 0.06);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 22px 24px 20px;
border-radius: 18px;
}
.eyebrow {
margin: 0 0 8px;
color: #8b6d35;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 43px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
#description {
margin: 13px 0 17px;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.steps {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.step {
position: relative;
min-width: 0;
padding: 9px 8px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 10px;
color: #8b938e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: 180ms ease;
}
.step::before {
content: "";
display: block;
width: 7px;
height: 7px;
margin-bottom: 7px;
border-radius: 50%;
background: #c9ccc5;
}
.step.active {
border-color: rgba(221, 169, 76, 0.55);
background: rgba(221, 169, 76, 0.09);
color: var(--ink);
}
.step.active::before {
background: var(--accent);
box-shadow: 0 0 0 4px rgba(221, 169, 76, 0.16);
}
.step.done {
color: var(--ink);
border-color: rgba(78, 120, 165, 0.3);
}
.step.done::before {
background: var(--blue);
}
#manifest {
position: absolute;
top: 24px;
right: 24px;
width: 230px;
padding: 17px;
border-radius: 16px;
}
.manifest-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.manifest-title span:last-child {
color: #9a9f97;
font-size: 9px;
}
.manifest-row {
display: grid;
grid-template-columns: 28px 1fr auto;
align-items: center;
gap: 7px;
padding: 7px 0;
border-top: 1px solid var(--line);
font-size: 12px;
}
.swatch {
width: 11px;
height: 11px;
border: 1px solid rgba(0, 0, 0, 0.12);
border-radius: 3px;
}
.manifest-row small {
color: #9a9f97;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#hook-four-state {
color: #b67e32;
}
#controls {
position: absolute;
left: 50%;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
width: min(610px, calc(100vw - 48px));
padding: 10px;
transform: translateX(-50%);
border-radius: 16px;
}
#action {
flex: 1;
min-height: 49px;
padding: 0 20px;
border: 0;
border-radius: 11px;
background: var(--ink);
color: #fffdf4;
cursor: pointer;
font-size: 14px;
font-weight: 750;
text-align: left;
transition:
transform 150ms ease,
background 150ms ease,
opacity 150ms ease;
}
#action:hover:not(:disabled) {
transform: translateY(-1px);
background: #36514d;
}
#action:active:not(:disabled) {
transform: translateY(1px);
}
#action:disabled {
cursor: wait;
opacity: 0.62;
}
.secondary {
min-height: 49px;
padding: 0 16px;
border: 1px solid var(--line);
border-radius: 11px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition: 150ms ease;
}
.secondary:hover {
background: rgba(37, 59, 57, 0.06);
}
#view-reset {
position: absolute;
right: 24px;
bottom: 24px;
pointer-events: auto;
padding: 12px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--paper);
color: var(--ink);
cursor: pointer;
box-shadow: 0 10px 28px rgba(49, 57, 50, 0.1);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#toast {
position: absolute;
left: 50%;
bottom: 104px;
max-width: calc(100vw - 48px);
padding: 10px 15px;
transform: translate(-50%, 12px);
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 999px;
background: rgba(37, 59, 57, 0.92);
color: #fffdf4;
box-shadow: 0 12px 30px rgba(37, 59, 57, 0.16);
font-size: 12px;
font-weight: 650;
opacity: 0;
transition: 220ms ease;
}
#toast.show {
transform: translate(-50%, 0);
opacity: 1;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e8e2d5;
color: var(--ink);
transition: opacity 500ms ease;
}
#loading.hidden {
pointer-events: none;
opacity: 0;
}
.loading-mark {
display: grid;
place-items: center;
gap: 14px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.loading-cube {
width: 24px;
height: 24px;
background: var(--accent);
animation: turn 1.2s infinite ease-in-out;
}
@keyframes turn {
0%, 100% {
transform: rotate(0deg) scale(0.85);
}
50% {
transform: rotate(90deg) scale(1);
}
}
@media (max-width: 780px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
}
h1 {
font-size: 31px;
}
#description {
margin: 9px 0 12px;
font-size: 12px;
}
#manifest {
display: none;
}
#controls {
bottom: 12px;
width: calc(100vw - 24px);
}
#view-reset {
right: 12px;
bottom: 86px;
}
#toast {
bottom: 92px;
}
}
@media (max-width: 480px) {
#description {
display: none;
}
.steps {
margin-top: 12px;
}
#action {
padding: 0 14px;
font-size: 12px;
}
.secondary {
padding: 0 11px;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive voxel cloakroom"></main>
<div class="overlay">
<section id="intro" class="panel">
<p class="eyebrow">A small cloakroom ritual</p>
<h1>The Last Thread</h1>
<p id="description">
Take the blue scarf from hook 04, collect the canvas bag from the bench,
and step quietly into the light.
</p>
<div class="steps" aria-label="Visit progress">
<div id="step-scarf" class="step active">Wrap scarf</div>
<div id="step-bag" class="step">Take bag</div>
<div id="step-leave" class="step">Leave</div>
</div>
</section>
<aside id="manifest" class="panel">
<div class="manifest-title">
<span>Hook manifest</span>
<span>4 places</span>
</div>
<div class="manifest-row">
<span class="swatch" style="background:#426d69"></span>
<span>Teal coat</span>
<small>01</small>
</div>
<div class="manifest-row">
<span class="swatch" style="background:#d5a33f"></span>
<span>Ochre coat</span>
<small>02</small>
</div>
<div class="manifest-row">
<span class="swatch" style="background:#b95d45"></span>
<span>Clay coat</span>
<small>03</small>
</div>
<div class="manifest-row">
<span class="swatch" style="background:#4e78a5"></span>
<span>Blue scarf</span>
<small id="hook-four-state">04</small>
</div>
</aside>
<div id="controls" class="panel">
<button id="action" type="button">Wrap the blue scarf →</button>
<button id="reset" class="secondary" type="button" title="Reset the visit">
Reset
</button>
</div>
<button id="view-reset" type="button" title="Restore the original camera">
↺ Reset view
</button>
<div id="toast" role="status" aria-live="polite"></div>
</div>
<div id="loading">
<div class="loading-mark">
<span class="loading-cube"></span>
<span>Opening the cloakroom</span>
</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 stage = document.getElementById("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e2d5);
scene.fog = new THREE.Fog(0xe8e2d5, 13, 23);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-6, 6, 4, -4, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(0xfff4d7, 0x66746f, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedcb, 3.1);
sun.position.set(-3.5, 8, 6.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.0007;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const doorwayLight = new THREE.PointLight(0xd9f2eb, 14, 7, 2);
doorwayLight.position.set(2.7, 2.3, -2.2);
scene.add(doorwayLight);
const room = new THREE.Group();
scene.add(room);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0
})
);
}
return materialCache.get(color);
}
function cube(parent, w, h, d, x, y, z, color) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(parent, x = 0, y = 0, z = 0) {
const result = new THREE.Group();
result.position.set(x, y, z);
parent.add(result);
return result;
}
// -------------------------------------------------------------------------
// Floor, walls, and doorway
// -------------------------------------------------------------------------
cube(room, 9.35, 0.34, 5.45, 0, -0.21, -0.1, 0x8b694d);
const plankColors = [
0xc89c6c, 0xd0a574, 0xbd8f61, 0xd4aa7b,
0xc59667, 0xcda170, 0xb9875b, 0xd2a675
];
for (let i = 0; i < 18; i++) {
const plank = cube(
room,
0.485,
0.11,
5.12,
-4.35 + i * 0.51,
0.015,
-0.08,
plankColors[i % plankColors.length]
);
plank.castShadow = false;
}
// Back wall with a genuine opening for the doorway.
cube(room, 6.38, 3.6, 0.26, -1.41, 1.8, -2.65, 0xe6dfce);
cube(room, 0.95, 3.6, 0.26, 4.13, 1.8, -2.65, 0xe6dfce);
cube(room, 1.9, 0.7, 0.26, 2.7, 3.25, -2.65, 0xe6dfce);
cube(room, 0.24, 3.6, 5.12, -4.56, 1.8, -0.09, 0xd8d1c0);
// Voxel panel seams.
for (let x = -4.05; x < 1.55; x += 0.95) {
cube(room, 0.025, 3.24, 0.025, x, 1.83, -2.505, 0xcfc7b7);
}
cube(room, 6.35, 0.025, 0.025, -1.42, 1.83, -2.5, 0xcfc7b7);
// Baseboards.
cube(room, 6.38, 0.2, 0.08, -1.41, 0.15, -2.46, 0x65756e);
cube(room, 0.95, 0.2, 0.08, 4.13, 0.15, -2.46, 0x65756e);
cube(room, 0.08, 0.2, 5.02, -4.39, 0.15, -0.08, 0x65756e);
const doorGroup = group(room);
doorGroup.userData.action = "leave";
cube(doorGroup, 1.82, 2.86, 0.08, 2.7, 1.43, -2.84, 0xa9c9c2);
cube(doorGroup, 0.18, 3.02, 0.34, 1.68, 1.51, -2.48, 0x3e5752);
cube(doorGroup, 0.18, 3.02, 0.34, 3.72, 1.51, -2.48, 0x3e5752);
cube(doorGroup, 2.22, 0.18, 0.34, 2.7, 3.0, -2.48, 0x3e5752);
cube(doorGroup, 2.12, 0.09, 0.46, 2.7, 0.05, -2.35, 0x72563e);
// Soft, blocky light visible beyond the open doorway.
cube(doorGroup, 0.25, 2.72, 0.05, 2.18, 1.45, -2.90, 0xc9dfd7);
cube(doorGroup, 0.25, 2.72, 0.05, 3.22, 1.45, -2.90, 0xc9dfd7);
cube(doorGroup, 1.78, 0.25, 0.05, 2.7, 2.52, -2.90, 0xc9dfd7);
// -------------------------------------------------------------------------
// Hooks, labels, coats, and scarves
// -------------------------------------------------------------------------
const hookX = [-3.75, -2.55, -1.35, -0.15];
cube(room, 4.35, 0.12, 0.17, -1.95, 2.72, -2.39, 0x9b754d);
function drawRoundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function plaqueTexture(number, label, accent = "#d9ad57") {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 112;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawRoundedRect(ctx, 4, 4, 248, 104, 18);
ctx.fillStyle = "#2d4541";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 5;
ctx.stroke();
ctx.fillStyle = "#fff8df";
ctx.font = "700 48px system-ui";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText(number, 22, 53);
ctx.fillStyle = "#d8ded4";
ctx.font = "800 23px system-ui";
ctx.textAlign = "right";
ctx.fillText(label, 232, 55);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
function makePlaque(number, label, x, accent) {
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: plaqueTexture(number, label, accent),
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(x, 3.12, -2.43);
sprite.scale.set(0.5, 0.22, 1);
sprite.renderOrder = 10;
room.add(sprite);
return sprite;
}
const plaques = [
makePlaque("01", "COAT", hookX[0], "#6ca29b"),
makePlaque("02", "COAT", hookX[1], "#e0b756"),
makePlaque("03", "COAT", hookX[2], "#ce7d63"),
makePlaque("04", "SCARF", hookX[3], "#7b9fc4")
];
hookX.forEach((x) => {
cube(room, 0.11, 0.18, 0.3, x, 2.49, -2.28, 0xc49b52);
cube(room, 0.17, 0.08, 0.12, x, 2.41, -2.12, 0xc49b52);
});
function makeCoat(x, color, darkColor) {
const coat = group(room, x, 0, -2.06);
cube(coat, 0.9, 0.2, 0.35, 0, 2.03, 0, color);
cube(coat, 0.68, 0.94, 0.32, 0, 1.52, 0, color);
cube(coat, 0.74, 0.13, 0.34, 0, 1.05, 0, color);
const leftSleeve = cube(coat, 0.2, 0.74, 0.3, -0.43, 1.53, 0, color);
const rightSleeve = cube(coat, 0.2, 0.74, 0.3, 0.43, 1.53, 0, color);
leftSleeve.rotation.z = -0.07;
rightSleeve.rotation.z = 0.07;
cube(coat, 0.18, 0.17, 0.35, -0.16, 2.02, 0.015, darkColor);
cube(coat, 0.18, 0.17, 0.35, 0.16, 2.02, 0.015, darkColor);
cube(coat, 0.12, 0.18, 0.12, 0, 2.25, -0.08, 0x657068);
cube(coat, 0.035, 0.035, 0.025, 0, 1.68, 0.18, 0xeadbb9);
cube(coat, 0.035, 0.035, 0.025, 0, 1.45, 0.18, 0xeadbb9);
cube(coat, 0.035, 0.035, 0.025, 0, 1.22, 0.18, 0xeadbb9);
cube(coat, 0.21, 0.03, 0.025, -0.17, 1.3, 0.18, darkColor);
cube(coat, 0.21, 0.03, 0.025, 0.17, 1.3, 0.18, darkColor);
return coat;
}
makeCoat(hookX[0], 0x426d69, 0x315552);
makeCoat(hookX[1], 0xd5a33f, 0x9b762f);
makeCoat(hookX[2], 0xb95d45, 0x874634);
const scarfGroup = group(room, -0.15, 2.44, -2.04);
scarfGroup.userData.action = "scarf";
cube(scarfGroup, 0.46, 0.13, 0.23, 0, 0, 0, 0x4e78a5);
cube(scarfGroup, 0.16, 0.64, 0.12, -0.12, -0.34, 0.02, 0x4e78a5);
cube(scarfGroup, 0.16, 0.56, 0.12, 0.12, -0.3, 0.02, 0x6389b2);
cube(scarfGroup, 0.16, 0.04, 0.12, -0.12, -0.68, 0.02, 0x7698bc);
cube(scarfGroup, 0.16, 0.04, 0.12, 0.12, -0.6, 0.02, 0x7698bc);
const scarfHome = scarfGroup.position.clone();
// -------------------------------------------------------------------------
// Bench and bag
// -------------------------------------------------------------------------
const bench = group(room, -1.45, 0, -0.55);
for (let i = 0; i < 4; i++) {
cube(bench, 3.8, 0.12, 0.15, 0, 0.58, -0.33 + i * 0.22, 0xb47d4f);
}
cube(bench, 3.9, 0.1, 0.1, 0, 0.42, -0.94, 0x704e37);
cube(bench, 3.9, 0.1, 0.1, 0, 0.42, 0.25, 0x704e37);
[-1.63, 1.63].forEach((x) => {
[-0.4, 0.26].forEach((z) => {
cube(bench, 0.18, 0.52, 0.18, x, 0.25, z, 0x704e37);
});
});
const bagGroup = group(room, -0.05, 0.97, -0.56);
bagGroup.userData.action = "bag";
cube(bagGroup, 0.62, 0.48, 0.36, 0, 0, 0, 0xc9b68d);
cube(bagGroup, 0.64, 0.12, 0.37, 0, 0.19, 0, 0xb59f76);
cube(bagGroup, 0.08, 0.3, 0.08, -0.18, 0.35, 0, 0x5b4a39);
cube(bagGroup, 0.08, 0.3, 0.08, 0.18, 0.35, 0, 0x5b4a39);
cube(bagGroup, 0.43, 0.07, 0.08, 0, 0.48, 0, 0x5b4a39);
cube(bagGroup, 0.16, 0.1, 0.025, 0, 0.02, 0.19, 0xf0dfb3);
const bagHome = {
position: bagGroup.position.clone(),
rotation: bagGroup.rotation.clone(),
scale: bagGroup.scale.clone()
};
// -------------------------------------------------------------------------
// Visitor
// -------------------------------------------------------------------------
const visitor = group(room, 1.0, 0, 0.25);
cube(visitor, 0.27, 0.15, 0.42, -0.18, 0.09, 0.05, 0x35413e);
cube(visitor, 0.27, 0.15, 0.42, 0.18, 0.09, 0.05, 0x35413e);
cube(visitor, 0.24, 0.68, 0.26, -0.18, 0.48, 0, 0x485450);
cube(visitor, 0.24, 0.68, 0.26, 0.18, 0.48, 0, 0x485450);
cube(visitor, 0.7, 0.16, 0.42, 0, 0.76, 0, 0x59605f);
cube(visitor, 0.68, 0.72, 0.4, 0, 1.17, 0, 0x776a77);
cube(visitor, 0.7, 0.14, 0.42, 0, 0.83, 0, 0x776a77);
cube(visitor, 0.2, 0.62, 0.24, -0.43, 1.16, 0, 0x776a77);
cube(visitor, 0.2, 0.62, 0.24, 0.43, 1.16, 0, 0x776a77);
cube(visitor, 0.2, 0.17, 0.22, -0.43, 0.76, 0.01, 0xd3a27f);
cube(visitor, 0.2, 0.17, 0.22, 0.43, 0.76, 0.01, 0xd3a27f);
cube(visitor, 0.19, 0.14, 0.18, 0, 1.57, 0, 0xd3a27f);
cube(visitor, 0.46, 0.46, 0.42, 0, 1.84, 0, 0xd9aa87);
cube(visitor, 0.49, 0.18, 0.45, 0, 2.05, -0.01, 0x443b35);
cube(visitor, 0.49, 0.4, 0.12, 0, 1.94, -0.18, 0x443b35);
cube(visitor, 0.05, 0.055, 0.025, -0.1, 1.86, 0.22, 0x293330);
cube(visitor, 0.05, 0.055, 0.025, 0.1, 1.86, 0.22, 0x293330);
cube(visitor, 0.08, 0.045, 0.03, 0, 1.72, 0.225, 0xb97761);
const wornScarf = group(visitor);
wornScarf.visible = false;
cube(wornScarf, 0.72, 0.15, 0.44, 0, 1.58, 0.015, 0x4e78a5);
cube(wornScarf, 0.2, 0.53, 0.12, -0.15, 1.32, 0.15, 0x4e78a5);
cube(wornScarf, 0.2, 0.42, 0.12, 0.16, 1.36, 0.15, 0x6389b2);
cube(wornScarf, 0.2, 0.045, 0.12, -0.15, 1.04, 0.15, 0x7698bc);
// -------------------------------------------------------------------------
// Small animated interaction markers
// -------------------------------------------------------------------------
function makeMarker(color) {
const marker = group(scene);
const markerMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9
});
const center = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.11, 0.11),
markerMaterial
);
marker.add(center);
for (let i = 0; i < 4; i++) {
const satellite = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 0.045, 0.045),
markerMaterial
);
satellite.position.set(
i % 2 ? 0.13 : -0.13,
i < 2 ? 0.13 : -0.13,
0
);
marker.add(satellite);
}
marker.userData.baseY = marker.position.y;
return marker;
}
const scarfMarker = makeMarker(0xf0c458);
scarfMarker.position.set(scarfHome.x, scarfHome.y + 0.58, scarfHome.z);
const bagMarker = makeMarker(0xf0c458);
bagMarker.position.set(bagHome.position.x, bagHome.position.y + 0.77, bagHome.position.z);
const doorMarker = makeMarker(0xa9d4c8);
doorMarker.position.set(2.7, 3.28, -2.24);
// -------------------------------------------------------------------------
// Camera controls implemented directly, without addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.15, -0.42);
const defaultView = {
azimuth: 0.68,
elevation: 0.48,
radius: 11.5,
zoom: 1
};
let cameraView = { ...defaultView };
let viewHeight = 7.25;
let dragging = false;
let pointerStart = { x: 0, y: 0 };
let previousPointer = { x: 0, y: 0 };
let pointerTravel = 0;
function updateCamera() {
const { azimuth, elevation, radius } = cameraView;
camera.position.set(
cameraTarget.x + radius * Math.cos(elevation) * Math.sin(azimuth),
cameraTarget.y + radius * Math.sin(elevation),
cameraTarget.z + radius * Math.cos(elevation) * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
viewHeight = Math.max(7.25, 10.5 / aspect) * cameraView.zoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
function resetView() {
cameraView = { ...defaultView };
resize();
updateCamera();
}
updateCamera();
resize();
window.addEventListener("resize", resize);
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerTravel = 0;
pointerStart = { x: event.clientX, y: event.clientY };
previousPointer = { ...pointerStart };
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
pointerTravel += Math.abs(dx) + Math.abs(dy);
cameraView.azimuth -= dx * 0.006;
cameraView.elevation = THREE.MathUtils.clamp(
cameraView.elevation + dy * 0.004,
0.23,
0.92
);
previousPointer = { x: event.clientX, y: event.clientY };
updateCamera();
} else {
const action = pickAction(event);
renderer.domElement.style.cursor = action ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (pointerTravel < 6) {
const action = pickAction(event);
if (action) runAction(action);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraView.zoom = THREE.MathUtils.clamp(
cameraView.zoom + event.deltaY * 0.00065,
0.72,
1.38
);
resize();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Picking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function hierarchyVisible(object) {
let current = object;
while (current) {
if (!current.visible) return false;
current = current.parent;
}
return true;
}
function actionFor(object) {
let current = object;
while (current) {
if (current.userData.action) return current.userData.action;
current = current.parent;
}
return null;
}
function pickAction(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(
[scarfGroup, bagGroup, doorGroup],
true
);
for (const hit of hits) {
if (!hierarchyVisible(hit.object)) continue;
const action = actionFor(hit.object);
if (action) return action;
}
return null;
}
// -------------------------------------------------------------------------
// Animation helpers
// -------------------------------------------------------------------------
const smooth = (t) => t * t * (3 - 2 * t);
function tween(duration, update) {
return new Promise((resolve) => {
const start = performance.now();
function frame(now) {
const progress = THREE.MathUtils.clamp(
(now - start) / duration,
0,
1
);
update(progress, smooth(progress));
if (progress < 1) {
requestAnimationFrame(frame);
} else {
resolve();
}
}
requestAnimationFrame(frame);
});
}
function quadraticBezier(a, b, c, t) {
const inverse = 1 - t;
return new THREE.Vector3()
.addScaledVector(a, inverse * inverse)
.addScaledVector(b, 2 * inverse * t)
.addScaledVector(c, t * t);
}
// -------------------------------------------------------------------------
// Interaction state and UI
// -------------------------------------------------------------------------
const state = {
scarf: false,
bag: false,
left: false,
busy: false
};
const actionButton = document.getElementById("action");
const resetButton = document.getElementById("reset");
const viewResetButton = document.getElementById("view-reset");
const description = document.getElementById("description");
const toast = document.getElementById("toast");
const hookFourState = document.getElementById("hook-four-state");
const stepScarf = document.getElementById("step-scarf");
const stepBag = document.getElementById("step-bag");
const stepLeave = document.getElementById("step-leave");
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2300);
}
function updateUI() {
stepScarf.classList.toggle("done", state.scarf);
stepScarf.classList.toggle("active", !state.scarf && !state.left);
stepBag.classList.toggle("done", state.bag);
stepBag.classList.toggle(
"active",
state.scarf && !state.bag && !state.left
);
stepLeave.classList.toggle("done", state.left);
stepLeave.classList.toggle(
"active",
state.scarf && state.bag && !state.left
);
if (state.left) {
actionButton.textContent = "Replay the visit ↻";
description.textContent =
"The visitor has gone. The coats are back in line, hook 04 is free, and the bench is clear.";
} else if (state.bag) {
actionButton.textContent = "Leave through the doorway →";
description.textContent =
"The scarf is wrapped and the canvas bag is in hand. The doorway is waiting.";
} else if (state.scarf) {
actionButton.textContent = "Take the canvas bag →";
description.textContent =
"The blue scarf is wrapped. One canvas bag remains waiting on the bench.";
} else {
actionButton.textContent = "Wrap the blue scarf →";
description.textContent =
"Take the blue scarf from hook 04, collect the canvas bag from the bench, and step quietly into the light.";
}
hookFourState.textContent = state.scarf ? "FREE" : "04";
hookFourState.style.color = state.scarf ? "#4e78a5" : "#b67e32";
scarfMarker.visible = !state.scarf;
bagMarker.visible = state.scarf && !state.bag;
doorMarker.visible = state.bag && !state.left;
}
async function wrapScarf() {
if (state.busy || state.scarf) return;
state.busy = true;
actionButton.disabled = true;
actionButton.textContent = "Wrapping the scarf…";
const start = scarfGroup.position.clone();
const end = visitor.position.clone().add(
new THREE.Vector3(0, 1.58, 0.08)
);
const control = start.clone().lerp(end, 0.48);
control.y = 2.85;
control.z += 0.58;
await tween(1100, (progress) => {
scarfGroup.position.copy(
quadraticBezier(start, control, end, progress)
);
scarfGroup.rotation.y = progress * Math.PI * 0.5;
scarfGroup.rotation.z = Math.sin(progress * Math.PI) * 0.32;
scarfGroup.scale.setScalar(1 - progress * 0.45);
});
scarfGroup.visible = false;
wornScarf.visible = true;
await tween(280, (progress) => {
const scale = 0.72 + progress * 0.28;
wornScarf.scale.setScalar(scale);
});
wornScarf.scale.setScalar(1);
state.scarf = true;
state.busy = false;
actionButton.disabled = false;
updateUI();
showToast("Blue scarf wrapped · hook 04 is now free");
}
async function collectBag() {
if (state.busy || state.bag) return;
if (!state.scarf) {
showToast("Wrap the scarf first, then take the bag.");
return;
}
state.busy = true;
actionButton.disabled = true;
actionButton.textContent = "Taking the bag…";
const start = bagGroup.position.clone();
const end = visitor.position.clone().add(
new THREE.Vector3(0.52, 0.78, 0.14)
);
const control = start.clone().lerp(end, 0.5);
control.y = 1.7;
await tween(900, (progress) => {
bagGroup.position.copy(
quadraticBezier(start, control, end, progress)
);
bagGroup.rotation.y = progress * 0.35;
bagGroup.rotation.z = Math.sin(progress * Math.PI) * 0.12;
bagGroup.scale.setScalar(1 - progress * 0.1);
});
visitor.add(bagGroup);
bagGroup.position.set(0.52, 0.78, 0.14);
bagGroup.rotation.set(0, -0.12, 0);
bagGroup.scale.setScalar(0.9);
state.bag = true;
state.busy = false;
actionButton.disabled = false;
updateUI();
showToast("Canvas bag collected · the bench is clear");
}
async function leaveRoom() {
if (state.busy || state.left) return;
if (!state.bag) {
showToast("Collect the canvas bag before leaving.");
return;
}
state.busy = true;
actionButton.disabled = true;
actionButton.textContent = "Walking into the light…";
const path = new THREE.CatmullRomCurve3(
[
visitor.position.clone(),
new THREE.Vector3(1.65, 0, -0.12),
new THREE.Vector3(2.62, 0, -0.7),
new THREE.Vector3(2.7, 0, -2.02),
new THREE.Vector3(2.7, 0, -3.25)
],
false,
"catmullrom",
0.3
);
const startingRotation = visitor.rotation.y;
await tween(3100, (progress) => {
const point = path.getPointAt(progress);
visitor.position.copy(point);
visitor.position.y = Math.abs(Math.sin(progress * Math.PI * 12)) * 0.035;
const turn = smooth(Math.min(progress * 3.2, 1));
visitor.rotation.y = THREE.MathUtils.lerp(
startingRotation,
Math.PI,
turn
);
});
visitor.visible = false;
state.left = true;
state.busy = false;
actionButton.disabled = false;
updateUI();
showToast("The room is left exactly as it was found");
}
function resetVisit() {
if (state.busy) return;
visitor.remove(bagGroup);
room.add(bagGroup);
bagGroup.position.copy(bagHome.position);
bagGroup.rotation.copy(bagHome.rotation);
bagGroup.scale.copy(bagHome.scale);
bagGroup.visible = true;
scarfGroup.position.copy(scarfHome);
scarfGroup.rotation.set(0, 0, 0);
scarfGroup.scale.setScalar(1);
scarfGroup.visible = true;
wornScarf.visible = false;
wornScarf.scale.setScalar(1);
visitor.visible = true;
visitor.position.set(1.0, 0, 0.25);
visitor.rotation.set(0, 0, 0);
state.scarf = false;
state.bag = false;
state.left = false;
state.busy = false;
actionButton.disabled = false;
updateUI();
showToast("The visit has been reset");
}
function runAction(action) {
if (action === "scarf") wrapScarf();
if (action === "bag") collectBag();
if (action === "leave") leaveRoom();
}
actionButton.addEventListener("click", () => {
if (state.left) {
resetVisit();
} else if (state.bag) {
leaveRoom();
} else if (state.scarf) {
collectBag();
} else {
wrapScarf();
}
});
resetButton.addEventListener("click", resetVisit);
viewResetButton.addEventListener("click", resetView);
updateUI();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
if (scarfMarker.visible) {
scarfMarker.position.y =
scarfMarker.userData.baseY + Math.sin(time * 2.8) * 0.07;
scarfMarker.rotation.y = time * 0.9;
}
if (bagMarker.visible) {
bagMarker.position.y =
bagMarker.userData.baseY + Math.sin(time * 2.8 + 1.2) * 0.07;
bagMarker.rotation.y = time * 0.9;
}
if (doorMarker.visible) {
doorMarker.position.y =
doorMarker.userData.baseY + Math.sin(time * 2.8 + 2.1) * 0.07;
doorMarker.rotation.y = time * 0.9;
}
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
setTimeout(() => {
document.getElementById("loading").remove();
}, 600);
});
</script>
</body>
</html>
```