Prompt specification
Build or customize the Three.js 3D scene "Commuter packing morning" 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: Commuter packing morning
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/commuter-packing-morning-x0603
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring garment pockets. Compose coat, bag, keys, transit card, and doorway; a visitor places frequently used items in reachable pockets and retrieves the correct card at a station gate. Stylized solid forms.
Working Three.js Starter (commuter-packing-morning-x0603):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pocketbound — An Interactive Doorway Scene</title>
<style>
:root {
--ink: #173332;
--muted: #60706e;
--paper: rgba(250, 248, 241, 0.92);
--line: rgba(23, 51, 50, 0.14);
--teal: #198f83;
--rust: #c66c4b;
--gold: #c99a37;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe4df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#stage canvas {
display: block;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.62);
background: var(--paper);
box-shadow:
0 18px 50px rgba(31, 50, 47, 0.13),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
header {
position: fixed;
z-index: 12;
top: 24px;
left: 28px;
max-width: 390px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 52px);
font-weight: 500;
letter-spacing: -0.045em;
line-height: 0.98;
}
header p {
max-width: 320px;
margin: 12px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
#mission {
top: 24px;
right: 28px;
width: min(350px, calc(100vw - 56px));
padding: 18px 18px 17px;
border-radius: 18px;
}
.mission-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#count {
color: var(--ink);
letter-spacing: 0.04em;
}
#instruction {
min-height: 52px;
margin: 11px 0 14px;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
line-height: 1.28;
}
.progress {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.progress span {
height: 4px;
border-radius: 999px;
background: rgba(23, 51, 50, 0.12);
transition: background 220ms ease, transform 220ms ease;
transform-origin: left;
}
.progress span.done {
background: var(--teal);
transform: scaleY(1.45);
}
#inventory {
position: fixed;
z-index: 12;
left: 28px;
bottom: 28px;
display: flex;
gap: 10px;
padding: 10px;
border-radius: 17px;
}
.item-button {
position: relative;
min-width: 145px;
padding: 12px 14px 12px 38px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.54);
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
opacity 160ms ease;
}
.item-button:hover:not(:disabled),
.item-button.selected {
border-color: rgba(25, 143, 131, 0.55);
background: white;
transform: translateY(-2px);
}
.item-button:disabled {
cursor: default;
opacity: 0.54;
}
.item-icon {
position: absolute;
top: 14px;
left: 14px;
width: 14px;
height: 20px;
border: 2px solid var(--teal);
border-radius: 3px;
}
.item-icon.keys {
width: 17px;
height: 17px;
border-radius: 50%;
border-color: var(--rust);
}
.item-button strong,
.item-button small {
display: block;
}
.item-button strong {
margin-bottom: 3px;
font-size: 12px;
}
.item-button small {
color: var(--muted);
font-size: 10px;
}
#actions {
position: fixed;
z-index: 12;
right: 28px;
bottom: 28px;
display: flex;
align-items: center;
gap: 12px;
}
.hint {
color: rgba(23, 51, 50, 0.7);
font-size: 11px;
text-shadow: 0 1px 8px white;
}
#reset {
padding: 11px 15px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 12px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 10px 30px rgba(31, 50, 47, 0.12);
cursor: pointer;
}
#reset:hover {
transform: translateY(-1px);
}
#hotspots {
position: fixed;
inset: 0;
z-index: 8;
pointer-events: none;
}
.hotspot {
position: absolute;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 999px;
background: rgba(250, 248, 241, 0.9);
color: var(--ink);
box-shadow: 0 7px 22px rgba(31, 50, 47, 0.14);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: auto;
cursor: pointer;
transform: translate(-50%, -50%);
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
.hotspot:hover {
background: white;
transform: translate(-50%, -50%) scale(1.04);
}
.hotspot::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 15px;
background: rgba(23, 51, 50, 0.42);
}
.hotspot.item-keys {
color: var(--rust);
}
.hotspot.item-card {
color: var(--teal);
}
.hotspot.complete {
border-color: rgba(25, 143, 131, 0.45);
background: var(--teal);
color: white;
}
#toast {
position: fixed;
z-index: 30;
left: 50%;
bottom: 32px;
max-width: min(430px, calc(100vw - 40px));
padding: 12px 17px;
border-radius: 12px;
background: #173332;
color: white;
box-shadow: 0 16px 45px rgba(15, 32, 31, 0.3);
font-size: 12px;
text-align: center;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition: opacity 180ms ease, transform 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
[hidden] {
display: none !important;
}
@media (max-width: 760px) {
header {
top: 16px;
left: 16px;
}
header p {
display: none;
}
#mission {
top: auto;
right: 16px;
bottom: 102px;
width: min(330px, calc(100vw - 32px));
}
#instruction {
min-height: 0;
margin-bottom: 10px;
font-size: 17px;
}
#inventory {
left: 16px;
bottom: 16px;
padding: 7px;
}
.item-button {
min-width: 115px;
padding: 10px 10px 10px 32px;
}
.item-icon {
top: 11px;
left: 11px;
}
#actions {
right: 16px;
bottom: 18px;
}
.hint {
display: none;
}
#toast {
bottom: 160px;
}
}
@media (max-width: 480px) {
h1 {
max-width: 210px;
font-size: 31px;
}
#mission {
bottom: 92px;
}
#inventory {
right: 16px;
}
.item-button {
min-width: 0;
flex: 1;
}
.item-button small {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header>
<div class="eyebrow">Interactive doorway · 07:42</div>
<h1>One less thing<br />to forget.</h1>
<p>Prepare for the platform. Place the everyday things within reach, then find the right card at the gate.</p>
</header>
<section id="mission" class="panel" aria-live="polite">
<div class="mission-top">
<span>Visitor checklist</span>
<span id="count">0 / 3</span>
</div>
<div id="instruction">Choose the keys or transit card, then tap a coat pocket.</div>
<div class="progress" aria-hidden="true">
<span id="progress-keys"></span>
<span id="progress-card"></span>
<span id="progress-gate"></span>
</div>
</section>
<div id="inventory" class="panel" aria-label="Items to place">
<button class="item-button" data-item="keys" aria-pressed="false">
<span class="item-icon keys"></span>
<strong>Keys</strong>
<small>Everyday pocket</small>
</button>
<button class="item-button" data-item="card" aria-pressed="false">
<span class="item-icon"></span>
<strong>Transit card</strong>
<small>Pass pocket</small>
</button>
</div>
<div id="actions">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset scene</button>
</div>
<div id="hotspots">
<button id="label-keys" class="hotspot item-keys" type="button">Keys</button>
<button id="label-card" class="hotspot item-card" type="button">Transit card</button>
<button id="label-pocket-keys" class="hotspot" type="button">Everyday pocket</button>
<button id="label-pocket-card" class="hotspot" type="button">Pass pocket</button>
<button id="label-bag" class="hotspot" type="button">Satchel</button>
<button id="label-gate" class="hotspot" type="button">Gate 04</button>
</div>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const toast = document.getElementById("toast");
const inventoryButtons = [...document.querySelectorAll(".item-button")];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe5df);
scene.fog = new THREE.Fog(0xdfe5df, 18, 36);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute("aria-label", "Interactive coat, bag and station gate scene");
stage.appendChild(renderer.domElement);
const cameraState = {
azimuth: 0.43,
polar: 1.12,
radius: 16,
target: new THREE.Vector3(-0.3, 2.05, -0.45)
};
const cameraHome = {
azimuth: 0.43,
polar: 1.12,
radius: 16,
target: new THREE.Vector3(-0.3, 2.05, -0.45)
};
const clock = new THREE.Clock();
const tweens = [];
const pickables = [];
const state = {
selected: null,
stored: { keys: false, card: false },
gateUsed: false,
gateOpen: 0,
cardAnimating: false
};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
});
}
const palette = {
wall: material(0xd9d6cd),
wallEdge: material(0xbab7ad),
floor: material(0xbeb7aa),
rug: material(0x80948a),
navy: material(0x24454c),
navyLight: material(0x315b60),
rust: material(0xc36b4d),
rustDark: material(0x9d4e37),
gold: material(0xd0a34e),
teal: material(0x36b6aa),
tealDark: material(0x196d68),
wood: material(0x8d6549),
woodDark: material(0x5c4133),
black: material(0x263331),
cream: material(0xeee5d3),
white: material(0xf6f3e9),
brass: material(0xc5a55d, {
metalness: 0.55,
roughness: 0.38
})
};
function box(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(parent, radius, position, mat, scale = [1, 1, 1]) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 24, 16),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.scale.set(scale[0], scale[1], scale[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
topRadius,
bottomRadius,
height,
position,
mat,
segments = 20
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(topRadius, bottomRadius, height, segments),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedBox(width, height, depth, radius, mat) {
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.04,
bevelThickness: 0.04,
curveSegments: 8
});
geometry.translate(0, 0, -depth / 2);
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function registerPick(object, data) {
object.userData.pick = data;
pickables.push(object);
}
function makeTextPlane({
title,
subtitle = "",
width = 2,
height = 0.65,
background = "#173f3e",
foreground = "#f4f0e4"
}) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "700 82px Arial";
context.fillText(title, 512, subtitle ? 98 : 132);
if (subtitle) {
context.globalAlpha = 0.78;
context.font = "500 31px Arial";
context.fillText(subtitle, 512, 184);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false,
side: THREE.DoubleSide
})
);
return mesh;
}
// Lighting
const hemisphere = new THREE.HemisphereLight(0xf7f1df, 0x65736e, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefd0, 3.1);
sun.position.set(-6, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const doorwayLight = new THREE.PointLight(0xa9e8df, 18, 12, 2);
doorwayLight.position.set(3.2, 3.7, -3.8);
scene.add(doorwayLight);
const warmLight = new THREE.PointLight(0xffc987, 8, 8, 2);
warmLight.position.set(-4.7, 4.7, -0.6);
scene.add(warmLight);
// Room and floor
box(scene, [20, 0.18, 18], [0, -0.12, -1.8], palette.floor, false);
const rug = box(
scene,
[8.4, 0.025, 3.45],
[-3.25, 0.005, 1.45],
palette.rug,
false
);
rug.receiveShadow = true;
// Wall with a true doorway opening
const wallShape = new THREE.Shape();
wallShape.moveTo(-8, 0);
wallShape.lineTo(8, 0);
wallShape.lineTo(8, 6.7);
wallShape.lineTo(-8, 6.7);
wallShape.closePath();
const doorwayHole = new THREE.Path();
doorwayHole.moveTo(1.35, 0);
doorwayHole.lineTo(1.35, 4.55);
doorwayHole.lineTo(5.25, 4.55);
doorwayHole.lineTo(5.25, 0);
doorwayHole.closePath();
wallShape.holes.push(doorwayHole);
const wall = new THREE.Mesh(
new THREE.ExtrudeGeometry(wallShape, {
depth: 0.35,
bevelEnabled: false
}),
palette.wall
);
wall.position.z = -2.55;
wall.receiveShadow = true;
wall.castShadow = true;
scene.add(wall);
box(scene, [9.35, 0.16, 0.18], [-3.325, 0.08, -2.14], palette.wallEdge);
box(scene, [2.75, 0.16, 0.18], [6.625, 0.08, -2.14], palette.wallEdge);
// Door frame and threshold
box(scene, [0.19, 4.63, 0.3], [1.27, 2.315, -2.08], palette.woodDark);
box(scene, [0.19, 4.63, 0.3], [5.33, 2.315, -2.08], palette.woodDark);
box(scene, [4.25, 0.19, 0.3], [3.3, 4.61, -2.08], palette.woodDark);
box(scene, [4.05, 0.07, 0.9], [3.3, 0.035, -2.45], palette.brass, false);
const doorwaySign = makeTextPlane({
title: "PLATFORM 04",
subtitle: "TRAINS →",
width: 2.1,
height: 0.55
});
doorwaySign.position.set(3.3, 5.04, -2.14);
scene.add(doorwaySign);
// Stylized wall poster
const posterCanvas = document.createElement("canvas");
posterCanvas.width = 900;
posterCanvas.height = 600;
const posterContext = posterCanvas.getContext("2d");
posterContext.fillStyle = "#f0e7d7";
posterContext.fillRect(0, 0, 900, 600);
posterContext.fillStyle = "#d69c45";
posterContext.beginPath();
posterContext.arc(630, 205, 120, 0, Math.PI * 2);
posterContext.fill();
posterContext.fillStyle = "#347b73";
posterContext.beginPath();
posterContext.moveTo(120, 510);
posterContext.lineTo(120, 270);
posterContext.quadraticCurveTo(260, 105, 400, 270);
posterContext.lineTo(400, 510);
posterContext.closePath();
posterContext.fill();
posterContext.fillStyle = "#193b3a";
posterContext.font = "700 58px Georgia";
posterContext.fillText("LEAVE LIGHT", 92, 110);
posterContext.font = "28px Arial";
posterContext.fillText("a small story about going", 96, 164);
const posterTexture = new THREE.CanvasTexture(posterCanvas);
posterTexture.colorSpace = THREE.SRGBColorSpace;
const poster = new THREE.Mesh(
new THREE.PlaneGeometry(2.35, 1.58),
new THREE.MeshBasicMaterial({ map: posterTexture, toneMapped: false })
);
poster.position.set(-4.6, 3.85, -2.14);
scene.add(poster);
// Bench
const bench = new THREE.Group();
scene.add(bench);
box(bench, [4.2, 0.18, 1.2], [-5.0, 0.74, 0.4], palette.wood);
box(bench, [0.22, 0.73, 0.9], [-6.55, 0.36, 0.4], palette.woodDark);
box(bench, [0.22, 0.73, 0.9], [-3.45, 0.36, 0.4], palette.woodDark);
box(bench, [3.25, 0.12, 0.11], [-5.0, 1.18, -0.06], palette.woodDark);
// Satchel
const bag = new THREE.Group();
bag.position.set(-5.55, 1.42, 0.32);
scene.add(bag);
const bagBody = roundedBox(1.72, 1.28, 0.74, 0.22, palette.rust);
bag.add(bagBody);
const bagFlap = roundedBox(1.61, 0.55, 0.12, 0.16, palette.rustDark);
bagFlap.position.set(0, 0.31, 0.43);
bag.add(bagFlap);
const bagHandle = new THREE.Mesh(
new THREE.TorusGeometry(0.46, 0.075, 10, 32, Math.PI),
palette.woodDark
);
bagHandle.position.y = 0.62;
bagHandle.scale.y = 0.8;
bagHandle.castShadow = true;
bag.add(bagHandle);
box(bag, [0.18, 0.22, 0.08], [0, 0.12, 0.54], palette.brass);
box(bag, [0.66, 0.04, 0.035], [0, 0.39, 0.51], palette.gold, false);
const bagTag = roundedBox(0.28, 0.4, 0.05, 0.05, palette.cream);
bagTag.position.set(0.55, 0.14, 0.52);
bagTag.rotation.z = -0.13;
bag.add(bagTag);
registerPick(bag, { kind: "bag" });
// Coat
const coat = new THREE.Group();
coat.position.set(-1.42, 0, -1.72);
scene.add(coat);
const coatBody = new THREE.Mesh(
new THREE.CapsuleGeometry(0.86, 1.3, 8, 18),
palette.navy
);
coatBody.position.y = 2.8;
coatBody.scale.set(1.05, 1, 0.42);
coatBody.castShadow = true;
coatBody.receiveShadow = true;
coat.add(coatBody);
const coatSkirt = cylinder(
coat,
0.76,
1.02,
1.35,
[0, 1.34, 0],
palette.navy,
10
);
coatSkirt.scale.z = 0.48;
const leftSleeve = new THREE.Mesh(
new THREE.CapsuleGeometry(0.32, 1.4, 6, 14),
palette.navyLight
);
leftSleeve.position.set(-1.03, 2.58, 0);
leftSleeve.rotation.z = -0.17;
leftSleeve.castShadow = true;
coat.add(leftSleeve);
const rightSleeve = leftSleeve.clone();
rightSleeve.position.x = 1.03;
rightSleeve.rotation.z = 0.17;
coat.add(rightSleeve);
box(coat, [0.12, 2.85, 0.06], [0, 2.63, 0.44], palette.tealDark, false);
const leftLapel = box(
coat,
[0.39, 0.8, 0.14],
[-0.3, 3.96, 0.4],
palette.navyLight
);
leftLapel.rotation.z = -0.24;
const rightLapel = box(
coat,
[0.39, 0.8, 0.14],
[0.3, 3.96, 0.4],
palette.navyLight
);
rightLapel.rotation.z = 0.24;
for (let i = 0; i < 3; i++) {
const button = cylinder(
coat,
0.07,
0.07,
0.045,
[0, 2.9 - i * 0.48, 0.49],
palette.brass,
16
);
button.rotation.x = Math.PI / 2;
}
// Coat hook
box(coat, [0.18, 0.18, 0.2], [0, 4.55, 0.1], palette.brass);
const hook = new THREE.Mesh(
new THREE.TorusGeometry(0.14, 0.035, 8, 18, Math.PI * 1.5),
palette.brass
);
hook.position.set(0, 4.42, 0.17);
hook.rotation.z = Math.PI / 2;
coat.add(hook);
const pockets = {};
function makePocket(id, x, width, color) {
const group = new THREE.Group();
group.position.set(x, 1.87, 0.49);
coat.add(group);
const pocketMaterial = material(color);
const panel = roundedBox(width, 0.67, 0.12, 0.12, pocketMaterial);
group.add(panel);
box(
group,
[width + 0.03, 0.08, 0.08],
[0, 0.31, 0.1],
palette.navyLight
);
registerPick(group, { kind: "pocket", id });
pockets[id] = { group, material: pocketMaterial };
return group;
}
makePocket("keys", -0.57, 0.72, 0xb75f43);
makePocket("card", 0.62, 1.04, 0xc89b40);
// Keys
const keys = new THREE.Group();
keys.position.set(-4.12, 0.91, 1.03);
keys.rotation.x = -Math.PI / 2;
scene.add(keys);
const keyMetal = material(0xc7aa61, {
metalness: 0.65,
roughness: 0.3
});
const keyRing = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.043, 10, 28),
keyMetal
);
keyRing.position.y = 0.24;
keyRing.castShadow = true;
keys.add(keyRing);
box(keys, [0.085, 0.53, 0.065], [0, -0.14, 0], keyMetal);
box(keys, [0.18, 0.08, 0.065], [0.06, -0.32, 0], keyMetal);
box(keys, [0.14, 0.08, 0.065], [0.04, -0.43, 0], keyMetal);
const keyTag = roundedBox(0.2, 0.25, 0.05, 0.05, palette.teal);
keyTag.position.set(0.19, 0.2, 0);
keyTag.rotation.z = 0.25;
keys.add(keyTag);
registerPick(keys, { kind: "item", id: "keys" });
// Transit card
const card = new THREE.Group();
card.position.set(-3.24, 0.91, 1.08);
card.rotation.x = -Math.PI / 2;
scene.add(card);
const cardMaterial = material(0x27a89c, {
roughness: 0.48,
metalness: 0.08
});
const cardBody = roundedBox(0.92, 0.58, 0.07, 0.075, cardMaterial);
card.add(cardBody);
box(card, [0.92, 0.12, 0.015], [0, -0.15, 0.047], palette.cream, false);
box(card, [0.18, 0.28, 0.016], [-0.31, 0.07, 0.048], palette.gold, false);
box(card, [0.43, 0.035, 0.018], [0.1, 0.12, 0.05], palette.cream, false);
registerPick(card, { kind: "item", id: "card" });
const initialKeysTransform = {
position: keys.position.clone(),
quaternion: keys.quaternion.clone()
};
const initialCardTransform = {
position: card.position.clone(),
quaternion: card.quaternion.clone()
};
// Plant near the doorway
const plant = new THREE.Group();
plant.position.set(6.65, 0, -0.25);
scene.add(plant);
cylinder(plant, 0.43, 0.31, 0.68, [0, 0.34, 0], palette.rust, 12);
cylinder(plant, 0.38, 0.38, 0.08, [0, 0.68, 0], palette.woodDark, 16);
const leafMaterial = material(0x4f7962);
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const leaf = sphere(
plant,
0.32,
[Math.cos(angle) * 0.25, 1.1 + (i % 2) * 0.15, Math.sin(angle) * 0.25],
leafMaterial,
[0.48, 1.35, 0.28]
);
leaf.rotation.z = Math.cos(angle) * 0.42;
leaf.rotation.x = Math.sin(angle) * 0.42;
}
// Platform beyond the doorway
box(scene, [7.8, 0.2, 4.9], [3.3, -0.03, -4.85], material(0x526267), false);
box(scene, [7.8, 4.9, 0.22], [3.3, 2.45, -6.42], material(0x80999a));
const stationSign = makeTextPlane({
title: "GATE 04",
subtitle: "VALID TRANSIT PASS REQUIRED",
width: 3.05,
height: 0.76,
background: "#173f3e",
foreground: "#f3e9d5"
});
stationSign.position.set(3.3, 4.25, -6.27);
scene.add(stationSign);
const platformStripe = box(
scene,
[7.3, 0.025, 0.16],
[3.3, 0.085, -3.15],
palette.gold,
false
);
// Station gate
const gate = new THREE.Group();
scene.add(gate);
box(gate, [0.75, 1.3, 0.82], [2.1, 0.67, -4.55], palette.navy);
box(gate, [0.83, 0.12, 0.9], [2.1, 1.37, -4.55], palette.black);
const scanner = new THREE.Group();
scanner.position.set(2.1, 1.48, -4.48);
gate.add(scanner);
const readerMaterial = material(0x38b9aa, {
emissive: 0x0c4d49,
emissiveIntensity: 0.45,
roughness: 0.35
});
const reader = roundedBox(0.54, 0.08, 0.42, 0.07, readerMaterial);
reader.rotation.x = -0.18;
scanner.add(reader);
const readerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.12, 0.025, 8, 24),
palette.cream
);
readerRing.position.set(0, 0.07, 0.02);
readerRing.rotation.x = Math.PI / 2;
scanner.add(readerRing);
registerPick(scanner, { kind: "gate" });
box(gate, [0.74, 1.3, 0.82], [4.35, 0.67, -4.55], palette.navy);
box(gate, [0.82, 0.12, 0.9], [4.35, 1.37, -4.55], palette.black);
const gatePivot = new THREE.Group();
gatePivot.position.set(4.28, 1.02, -4.55);
gate.add(gatePivot);
const barrier = roundedBox(2.15, 0.12, 0.13, 0.06, palette.gold);
barrier.position.x = -1.02;
gatePivot.add(barrier);
const gateIndicator = sphere(
gate,
0.09,
[4.35, 1.56, -4.48],
palette.teal,
[1, 1, 0.5]
);
// Soft decorative floor line near the platform
const floorArrow = box(
scene,
[0.16, 0.025, 1.0],
[2.95, 0.09, -3.65],
palette.gold,
false
);
floorArrow.rotation.y = -0.35;
// UI and interaction
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2600);
}
function refreshUI() {
const completed =
Number(state.stored.keys) +
Number(state.stored.card) +
Number(state.gateUsed);
document.getElementById("count").textContent = `${completed} / 3`;
document.getElementById("progress-keys").classList.toggle("done", state.stored.keys);
document.getElementById("progress-card").classList.toggle("done", state.stored.card);
document.getElementById("progress-gate").classList.toggle("done", state.gateUsed);
let instruction;
if (state.gateUsed) {
instruction = "Access granted. The gate is open and the platform is ready.";
} else if (!state.stored.keys && !state.stored.card) {
instruction = "Choose the keys or transit card, then tap a coat pocket.";
} else if (!state.stored.card) {
instruction = "The pass pocket is empty. Place the transit card there.";
} else if (!state.stored.keys) {
instruction = "Your pass is ready. Stow the keys in the everyday pocket.";
} else {
instruction = "Everything is within reach. Tap Gate 04 to use your card.";
}
document.getElementById("instruction").textContent = instruction;
inventoryButtons.forEach((button) => {
const id = button.dataset.item;
const selected = state.selected === id;
const done = state.stored[id];
button.disabled = done;
button.classList.toggle("selected", selected);
button.setAttribute("aria-pressed", String(selected));
button.querySelector("small").textContent = done
? "Pocket reached"
: id === "keys"
? "Everyday pocket"
: "Pass pocket";
});
document.getElementById("label-pocket-keys").classList.toggle(
"complete",
state.stored.keys
);
document.getElementById("label-pocket-card").classList.toggle(
"complete",
state.stored.card
);
document.getElementById("label-gate").classList.toggle(
"complete",
state.gateUsed
);
}
function selectItem(id) {
if (state.stored[id] || state.cardAnimating) return;
state.selected = id;
refreshUI();
showToast(
id === "keys"
? "Keys selected — now tap the everyday pocket."
: "Transit card selected — now tap the pass pocket."
);
}
function easeInOut(t) {
return t * t * (3 - 2 * t);
}
function addTween({
object,
toPosition,
toQuaternion = null,
duration = 700,
onUpdate,
onComplete
}) {
tweens.push({
object,
fromPosition: object.position.clone(),
toPosition: toPosition.clone(),
fromQuaternion: object.quaternion.clone(),
toQuaternion: toQuaternion
? toQuaternion.clone()
: object.quaternion.clone(),
duration,
start: performance.now(),
onUpdate,
onComplete
});
}
function storeItem(id) {
if (state.stored[id]) return;
if (!state.selected) {
showToast(
id === "keys"
? "Choose the keys from the satchel first."
: "Choose the transit card first."
);
return;
}
if (state.selected !== id) {
showToast(
id === "keys"
? "The keys belong in the smaller everyday pocket."
: "The transit card belongs in the wider pass pocket."
);
return;
}
state.selected = null;
state.stored[id] = true;
const target = new THREE.Vector3();
pockets[id].group.getWorldPosition(target);
target.z += 0.17;
target.y += id === "keys" ? 0.15 : 0.02;
const item = id === "keys" ? keys : card;
const targetQuaternion = new THREE.Quaternion();
addTween({
object: item,
toPosition: target,
toQuaternion: targetQuaternion,
duration: 800,
onComplete: () => {
showToast(
id === "keys"
? "Keys tucked into the everyday pocket."
: "Transit card secured in the pass pocket."
);
}
});
refreshUI();
}
function attemptGate() {
if (state.gateUsed || state.cardAnimating) return;
if (!state.stored.card) {
showToast("The transit card is not in the pass pocket yet.");
return;
}
if (!state.stored.keys) {
showToast("Your card is ready — but first, keep the keys within reach.");
return;
}
state.cardAnimating = true;
state.selected = null;
refreshUI();
showToast("Taking the pass from your pocket…");
const start = card.position.clone();
const end = new THREE.Vector3(2.1, 1.58, -4.43);
const path = new THREE.CatmullRomCurve3([
start,
new THREE.Vector3(-0.15, 2.25, -0.8),
new THREE.Vector3(1.4, 1.95, -2.15),
end
]);
const targetQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(-0.15, 0.08, 0)
);
addTween({
object: card,
toPosition: end,
toQuaternion: targetQuaternion,
duration: 1500,
onUpdate: (object, t) => {
const point = path.getPoint(easeInOut(t));
object.position.copy(point);
object.quaternion.slerpQuaternions(
new THREE.Quaternion(),
targetQuaternion,
easeInOut(t)
);
},
onComplete: () => {
state.cardAnimating = false;
state.gateUsed = true;
readerMaterial.color.set(0x48d47e);
readerMaterial.emissive.set(0x1b7a45);
readerMaterial.emissiveIntensity = 0.8;
gateIndicator.material.color.set(0x48d47e);
gateIndicator.material.emissive.set(0x1b7a45);
showToast("Correct card. Gate 04 is open — have a good journey.");
refreshUI();
}
});
// Move the camera toward the doorway and platform.
cameraState.azimuth = 0.15;
cameraState.polar = 1.12;
cameraState.radius = 10.2;
cameraState.target.set(2.45, 2.0, -3.05);
}
function resetScene() {
tweens.length = 0;
state.selected = null;
state.stored.keys = false;
state.stored.card = false;
state.gateUsed = false;
state.gateOpen = 0;
state.cardAnimating = false;
keys.position.copy(initialKeysTransform.position);
keys.quaternion.copy(initialKeysTransform.quaternion);
card.position.copy(initialCardTransform.position);
card.quaternion.copy(initialCardTransform.quaternion);
gatePivot.rotation.y = 0;
readerMaterial.color.set(0x38b9aa);
readerMaterial.emissive.set(0x0c4d49);
readerMaterial.emissiveIntensity = 0.45;
gateIndicator.material.color.set(0x38b9aa);
gateIndicator.material.emissive.set(0x1b7a45);
cameraState.azimuth = cameraHome.azimuth;
cameraState.polar = cameraHome.polar;
cameraState.radius = cameraHome.radius;
cameraState.target.copy(cameraHome.target);
refreshUI();
showToast("Scene reset. Choose an item to begin.");
}
inventoryButtons.forEach((button) => {
button.addEventListener("click", () => selectItem(button.dataset.item));
});
document.getElementById("reset").addEventListener("click", resetScene);
document.getElementById("label-keys").addEventListener("click", () => {
selectItem("keys");
});
document.getElementById("label-card").addEventListener("click", () => {
selectItem("card");
});
document.getElementById("label-pocket-keys").addEventListener("click", () => {
storeItem("keys");
});
document.getElementById("label-pocket-card").addEventListener("click", () => {
storeItem("card");
});
document.getElementById("label-gate").addEventListener("click", attemptGate);
document.getElementById("label-bag").addEventListener("click", () => {
showToast("The satchel is packed. The loose essentials are ready to place.");
});
// Custom orbit controls, implemented directly without addons.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let pointerMoved = false;
let previousX = 0;
let previousY = 0;
function findPick(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(pickables, true);
for (const intersection of intersections) {
let object = intersection.object;
while (object && !object.userData.pick) {
object = object.parent;
}
if (object?.userData.pick) return object.userData.pick;
}
return null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerMoved = false;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
cameraState.azimuth -= dx * 0.005;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + dy * 0.004,
0.68,
1.38
);
previousX = event.clientX;
previousY = event.clientY;
} else {
renderer.domElement.style.cursor = findPick(event.clientX, event.clientY)
? "pointer"
: "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (!pointerMoved) {
const pick = findPick(event.clientX, event.clientY);
if (pick?.kind === "item") {
selectItem(pick.id);
} else if (pick?.kind === "pocket") {
storeItem(pick.id);
} else if (pick?.kind === "gate") {
attemptGate();
} else if (pick?.kind === "bag") {
showToast("The satchel is packed. The loose essentials are ready to place.");
}
}
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
9,
21
);
},
{ passive: false }
);
// Project HTML hotspots from their Three.js anchors.
const hotspotElements = {
keys: document.getElementById("label-keys"),
card: document.getElementById("label-card"),
pocketKeys: document.getElementById("label-pocket-keys"),
pocketCard: document.getElementById("label-pocket-card"),
bag: document.getElementById("label-bag"),
gate: document.getElementById("label-gate")
};
function positionHotspot(element, object, offsetX = 0, offsetY = 0, visible = true) {
if (!visible) {
element.hidden = true;
return;
}
const worldPosition = new THREE.Vector3();
object.getWorldPosition(worldPosition);
worldPosition.project(camera);
const onScreen =
worldPosition.z > -1 &&
worldPosition.z < 1 &&
Math.abs(worldPosition.x) < 1.2 &&
Math.abs(worldPosition.y) < 1.2;
element.hidden = !onScreen;
if (!onScreen) return;
const x = (worldPosition.x * 0.5 + 0.5) * innerWidth + offsetX;
const y = (-worldPosition.y * 0.5 + 0.5) * innerHeight + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateHotspots() {
hotspotElements.keys.textContent = state.stored.keys
? "Keys · reachable"
: "Keys";
hotspotElements.card.textContent = state.stored.card
? "Pass · pocketed"
: "Transit card";
hotspotElements.pocketKeys.textContent = state.stored.keys
? "Keys · in reach"
: "Everyday pocket";
hotspotElements.pocketCard.textContent = state.stored.card
? "Pass · in reach"
: "Pass pocket";
hotspotElements.gate.textContent = state.gateUsed
? "Gate 04 · open"
: "Gate 04";
positionHotspot(
hotspotElements.keys,
keys,
0,
-38,
!state.stored.keys
);
positionHotspot(
hotspotElements.card,
card,
0,
-38,
!state.stored.card && !state.gateUsed
);
positionHotspot(hotspotElements.pocketKeys, pockets.keys.group, 0, -43, true);
positionHotspot(hotspotElements.pocketCard, pockets.card.group, 0, -43, true);
positionHotspot(hotspotElements.bag, bag, 0, -75, true);
positionHotspot(hotspotElements.gate, scanner, 0, -66, true);
}
function updateCamera() {
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.polar),
cameraState.target.z +
cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
function animate() {
requestAnimationFrame(animate);
const now = performance.now();
const elapsed = clock.getElapsedTime();
for (let i = tweens.length - 1; i >= 0; i--) {
const tween = tweens[i];
const raw = THREE.MathUtils.clamp(
(now - tween.start) / tween.duration,
0,
1
);
const t = easeInOut(raw);
if (tween.onUpdate) {
tween.onUpdate(tween.object, t);
} else {
tween.object.position.lerpVectors(
tween.fromPosition,
tween.toPosition,
t
);
tween.object.quaternion.slerpQuaternions(
tween.fromQuaternion,
tween.toQuaternion,
t
);
}
if (raw >= 1) {
tweens.splice(i, 1);
tween.onComplete?.();
}
}
// Gentle selected-item pulse.
keys.scale.setScalar(
state.selected === "keys" ? 1 + Math.sin(elapsed * 7) * 0.035 : 1
);
card.scale.setScalar(
state.selected === "card" ? 1 + Math.sin(elapsed * 7) * 0.025 : 1
);
// Highlight the matching pocket.
pockets.keys.material.emissive.set(
state.selected === "keys" ? 0x552015 : 0x000000
);
pockets.keys.material.emissiveIntensity = state.selected === "keys" ? 0.55 : 0;
pockets.card.material.emissive.set(
state.selected === "card" ? 0x5a3d00 : 0x000000
);
pockets.card.material.emissiveIntensity = state.selected === "card" ? 0.55 : 0;
// Open the turnstile after a successful card scan.
if (state.gateUsed) {
state.gateOpen = THREE.MathUtils.lerp(state.gateOpen, 1, 0.045);
}
gatePivot.rotation.y = -1.18 * state.gateOpen;
readerRing.rotation.z = elapsed * 0.45;
gateIndicator.scale.y = 0.5 + Math.sin(elapsed * 3) * 0.04;
updateCamera();
updateHotspots();
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
refreshUI();
updateCamera();
animate();
</script>
</body>
</html>
```