Prompt specification
Build or customize the Three.js 3D scene "Rainy walk preparation 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: Rainy walk preparation scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/rainy-walk-preparation-scene-x0611
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a voxel entryway before and after a rainy walk. Place a raincoat on a hook, boots below a bench, an umbrella beside the door, and a bag on a shelf. A simple visitor collects the items in sequence and leaves through the doorway; later the same items return with a few visible droplets. Put wet boots and the umbrella in a separate drying tray, while the bag stays on the dry shelf. Keep object identities and locations consistent between the two moments, and let the small room remain visible as one coherent space.
Working Three.js Starter (rainy-walk-preparation-scene-x0611):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Entryway — Before and After a Rainy Walk</title>
<style>
:root {
--ink: #23343a;
--muted: #64777d;
--paper: rgba(249, 247, 239, 0.94);
--line: rgba(35, 52, 58, 0.14);
--accent: #cf8134;
--blue: #397e88;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce5e7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.75);
background: var(--paper);
box-shadow: 0 12px 35px rgba(38, 54, 58, 0.14);
backdrop-filter: blur(12px);
}
#intro {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 18px 19px 16px;
border-radius: 16px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.2vw, 29px);
line-height: 1.08;
letter-spacing: -0.035em;
}
#intro p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
#stage {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.65);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#stage::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
content: "";
box-shadow: 0 0 0 4px rgba(207, 129, 52, 0.12);
}
#status-panel {
top: 18px;
right: 18px;
width: 235px;
padding: 14px;
border-radius: 14px;
pointer-events: none;
}
.status-title {
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.status-row {
display: grid;
grid-template-columns: 12px 1fr;
gap: 8px;
align-items: center;
padding: 6px 0;
border-top: 1px solid var(--line);
font-size: 11px;
}
.status-row:first-of-type {
border-top: 0;
}
.status-dot {
width: 9px;
height: 9px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.status-name {
font-weight: 800;
}
.status-value {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
#timeline {
right: 18px;
bottom: 18px;
left: 18px;
min-height: 91px;
padding: 12px 15px;
border-radius: 15px;
}
.timeline-top {
display: flex;
gap: 12px;
align-items: center;
}
button {
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.86);
color: var(--ink);
padding: 8px 11px;
font: inherit;
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
button:hover {
background: white;
transform: translateY(-1px);
}
button.primary {
min-width: 76px;
border-color: transparent;
background: var(--ink);
color: white;
}
button:focus-visible,
input:focus-visible {
outline: 3px solid rgba(57, 126, 136, 0.25);
outline-offset: 2px;
}
#scrubber {
width: 100%;
height: 5px;
accent-color: var(--accent);
cursor: pointer;
}
.timeline-bottom {
display: flex;
justify-content: space-between;
gap: 15px;
margin-top: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#time {
color: var(--ink);
font-variant-numeric: tabular-nums;
}
.object-tag {
position: fixed;
z-index: 6;
padding: 4px 7px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 6px;
background: rgba(35, 52, 58, 0.88);
color: white;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.11em;
pointer-events: none;
transform: translate(-50%, -50%);
opacity: 0;
transition: opacity 180ms ease;
white-space: nowrap;
}
#help {
position: fixed;
z-index: 7;
right: 18px;
bottom: 121px;
padding: 7px 9px;
border-radius: 8px;
background: rgba(35, 52, 58, 0.76);
color: white;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 760px) {
#intro {
width: calc(100vw - 36px);
padding: 14px 15px;
}
#intro p {
display: none;
}
#status-panel {
top: 112px;
right: 12px;
width: 178px;
padding: 10px;
}
#status-panel .status-title {
margin-bottom: 5px;
}
.status-row {
padding: 4px 0;
}
#timeline {
right: 12px;
bottom: 12px;
left: 12px;
}
#help {
display: none;
}
.timeline-bottom span:nth-child(2) {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="intro" class="panel">
<div class="eyebrow">A small story in one room</div>
<h1>Before & After the Rain</h1>
<p>
The visitor gathers the same coat, boots, umbrella, and bag.
They return damp: the wet gear drains in the blue tray while the bag stays dry.
</p>
<div id="stage">01 · Before the walk</div>
</section>
<aside id="status-panel" class="panel">
<div class="status-title">Same objects · tracked live</div>
<div class="status-row">
<span class="status-dot" style="background:#d99534"></span>
<div>
<span class="status-name">Coat</span>
<span id="coat-status" class="status-value">On hook</span>
</div>
</div>
<div class="status-row">
<span class="status-dot" style="background:#76513b"></span>
<div>
<span class="status-name">Boots</span>
<span id="boots-status" class="status-value">Below bench</span>
</div>
</div>
<div class="status-row">
<span class="status-dot" style="background:#3c8b86"></span>
<div>
<span class="status-name">Umbrella</span>
<span id="umbrella-status" class="status-value">Beside door</span>
</div>
</div>
<div class="status-row">
<span class="status-dot" style="background:#b8794f"></span>
<div>
<span class="status-name">Bag</span>
<span id="bag-status" class="status-value">On dry shelf</span>
</div>
</div>
</aside>
<div id="tag-coat" class="object-tag">COAT</div>
<div id="tag-boots" class="object-tag">BOOTS</div>
<div id="tag-umbrella" class="object-tag">UMBRELLA</div>
<div id="tag-bag" class="object-tag">BAG</div>
<div id="help">Drag to orbit · scroll to zoom</div>
<section id="timeline" class="panel">
<div class="timeline-top">
<button id="play" class="primary" type="button">Pause</button>
<button id="restart" type="button">Restart</button>
<button id="before" type="button">Before</button>
<button id="after" type="button">After</button>
<input
id="scrubber"
type="range"
min="0"
max="22.4"
step="0.01"
value="0"
aria-label="Animation timeline"
/>
</div>
<div class="timeline-bottom">
<span>Arrival → collect → leave → rain → return</span>
<span id="time">00.0 / 22.4 s</span>
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const mount = document.querySelector("#scene");
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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce5e7);
scene.fog = new THREE.Fog(0xdce5e7, 15, 25);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const view = {
target: new THREE.Vector3(0, 1.25, -0.45),
radius: 11.4,
theta: 0.64,
phi: 0.91
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xf3f8fb, 0x786c62, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4df, 3.25);
sun.position.set(5, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 22;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dce7, 1.1);
fill.position.set(-5, 4, -4);
scene.add(fill);
// -------------------------------------------------------------------------
// Helpers and materials
// -------------------------------------------------------------------------
const M = {
wall: new THREE.MeshStandardMaterial({
color: 0xe8e0d2,
roughness: 0.94
}),
wallSide: new THREE.MeshStandardMaterial({
color: 0xd9d8cf,
roughness: 0.95
}),
trim: new THREE.MeshStandardMaterial({
color: 0xf2ecdf,
roughness: 0.8
}),
floorA: new THREE.MeshStandardMaterial({
color: 0xd7c9b2,
roughness: 0.92
}),
floorB: new THREE.MeshStandardMaterial({
color: 0xc8b69b,
roughness: 0.94
}),
grout: new THREE.MeshStandardMaterial({
color: 0x80776d,
roughness: 1
}),
wood: new THREE.MeshStandardMaterial({
color: 0x966647,
roughness: 0.82
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x5d4435,
roughness: 0.88
}),
teal: new THREE.MeshStandardMaterial({
color: 0x3c777a,
roughness: 0.8
}),
darkTeal: new THREE.MeshStandardMaterial({
color: 0x28585d,
roughness: 0.76
}),
brass: new THREE.MeshStandardMaterial({
color: 0xd4a34b,
roughness: 0.42,
metalness: 0.25
}),
navy: new THREE.MeshStandardMaterial({
color: 0x344650,
roughness: 0.9
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x242b2c,
roughness: 0.95
}),
sky: new THREE.MeshStandardMaterial({
color: 0x789aa6,
roughness: 0.7
}),
window: new THREE.MeshStandardMaterial({
color: 0xbdd7dc,
roughness: 0.35,
emissive: 0x73949b,
emissiveIntensity: 0.14
})
};
function box(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function signSprite(text, color = "#294a50") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(248,246,237,0.94)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = color;
ctx.lineWidth = 8;
ctx.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
ctx.fillStyle = color;
ctx.font = "800 31px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
})
);
sprite.scale.set(1.55, 0.34, 1);
return sprite;
}
// -------------------------------------------------------------------------
// Cutaway room
// -------------------------------------------------------------------------
box(8.3, 0.22, 6.3, M.grout, 0, -0.17, 0);
for (let x = 0; x < 8; x++) {
for (let z = 0; z < 6; z++) {
const material = (x + z) % 2 === 0 ? M.floorA : M.floorB;
box(
0.965,
0.065,
0.965,
material,
-3.5 + x,
-0.045,
-2.5 + z
);
}
}
const backZ = -3.08;
const wallHeight = 4.3;
const doorLeft = 1.6;
const doorRight = 3.2;
const doorHeight = 2.8;
box(
doorLeft + 4,
wallHeight,
0.22,
M.wall,
(-4 + doorLeft) / 2,
wallHeight / 2,
backZ
);
box(
4 - doorRight,
wallHeight,
0.22,
M.wall,
(doorRight + 4) / 2,
wallHeight / 2,
backZ
);
box(
doorRight - doorLeft,
wallHeight - doorHeight,
0.22,
M.wall,
(doorLeft + doorRight) / 2,
doorHeight + (wallHeight - doorHeight) / 2,
backZ
);
box(0.22, wallHeight, 6.15, M.wallSide, -4.08, wallHeight / 2, 0);
// Subtle voxel wall courses.
for (let y = 0.75; y < wallHeight; y += 0.75) {
box(8, 0.035, 0.025, M.trim, 0, y, backZ + 0.125);
box(0.025, 0.035, 6, M.trim, -3.955, y, 0);
}
// Left wall window.
box(0.07, 1.45, 1.65, M.trim, -3.94, 2.45, 0.1);
box(0.085, 1.23, 1.43, M.window, -3.90, 2.45, 0.1);
box(0.11, 0.07, 1.45, M.trim, -3.86, 2.45, 0.1);
box(0.11, 1.25, 0.07, M.trim, -3.86, 2.45, 0.1);
box(0.32, 0.12, 1.82, M.trim, -3.80, 1.67, 0.1);
// Doorway trim and threshold.
box(0.15, 2.85, 0.3, M.darkTeal, doorLeft - 0.025, 1.425, backZ + 0.08);
box(0.15, 2.85, 0.3, M.darkTeal, doorRight + 0.025, 1.425, backZ + 0.08);
box(1.75, 0.17, 0.3, M.darkTeal, 2.4, 2.86, backZ + 0.08);
box(1.65, 0.07, 0.42, M.brass, 2.4, 0.015, backZ + 0.13);
// Open door slab, folded outward.
const doorHinge = new THREE.Group();
doorHinge.position.set(3.25, 0, backZ - 0.02);
doorHinge.rotation.y = Math.PI / 2;
scene.add(doorHinge);
box(1.48, 2.67, 0.12, M.teal, 0.74, 1.36, 0, doorHinge);
box(1.08, 0.77, 0.035, M.window, 0.74, 1.87, 0.08, doorHinge);
box(0.07, 0.82, 0.06, M.trim, 0.74, 1.87, 0.11, doorHinge);
box(0.12, 0.12, 0.14, M.brass, 1.27, 1.22, 0.12, doorHinge);
// Exterior landing visible through the open door.
box(2.7, 0.18, 2.8, M.darkTeal, 2.4, -0.13, -4.35);
box(2.55, 4.7, 0.12, M.sky, 2.4, 2.25, -5.15);
// Entrance mat.
box(1.45, 0.035, 0.82, M.navy, 2.35, 0.02, -0.53);
for (let i = 0; i < 7; i++) {
box(1.33, 0.012, 0.035, M.darkTeal, 2.35, 0.044, -0.84 + i * 0.1);
}
// -------------------------------------------------------------------------
// Bench, hook, shelf, and separate drying tray
// -------------------------------------------------------------------------
const benchX = -2.55;
const benchZ = -2.43;
box(1.86, 0.16, 0.72, M.wood, benchX, 0.74, benchZ);
box(0.16, 0.67, 0.16, M.darkWood, benchX - 0.73, 0.36, benchZ - 0.18);
box(0.16, 0.67, 0.16, M.darkWood, benchX + 0.73, 0.36, benchZ - 0.18);
box(0.16, 0.67, 0.16, M.darkWood, benchX - 0.73, 0.36, benchZ + 0.18);
box(0.16, 0.67, 0.16, M.darkWood, benchX + 0.73, 0.36, benchZ + 0.18);
box(1.62, 0.22, 0.12, M.darkWood, benchX, 0.58, benchZ - 0.23);
// Coat hook.
box(0.12, 0.32, 0.12, M.darkWood, -2.72, 2.4, -2.91);
box(0.31, 0.09, 0.11, M.brass, -2.62, 2.55, -2.82);
// Dry shelf.
const shelfX = -0.22;
const shelfZ = -2.68;
const shelfTop = 2.38;
box(1.58, 0.14, 0.62, M.wood, shelfX, shelfTop - 0.07, shelfZ);
box(0.13, 0.57, 0.13, M.darkWood, shelfX - 0.55, 2.05, shelfZ - 0.15);
box(0.13, 0.57, 0.13, M.darkWood, shelfX + 0.55, 2.05, shelfZ - 0.15);
box(1.2, 0.12, 0.13, M.darkWood, shelfX, 2.11, shelfZ - 0.2);
// Separate drying tray.
const trayX = 0.73;
const trayZ = -2.03;
for (let i = 0; i < 8; i++) {
box(
0.16,
0.075,
1.08,
M.teal,
trayX - 0.65 + i * 0.185,
0.075,
trayZ
);
}
box(1.58, 0.18, 0.09, M.darkTeal, trayX, 0.13, trayZ - 0.55);
box(1.58, 0.18, 0.09, M.darkTeal, trayX, 0.13, trayZ + 0.55);
box(0.09, 0.18, 1.08, M.darkTeal, trayX - 0.79, 0.13, trayZ);
box(0.09, 0.18, 1.08, M.darkTeal, trayX + 0.79, 0.13, trayZ);
const traySign = signSprite("DRYING TRAY", "#2d676d");
traySign.position.set(trayX, 0.67, trayZ + 0.35);
scene.add(traySign);
const shelfSign = signSprite("DRY SHELF", "#77523b");
shelfSign.position.set(shelfX, 3.04, shelfZ + 0.12);
scene.add(shelfSign);
// Small wall clock.
const clock = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.34, 0.08, 16),
M.trim
);
clock.rotation.x = Math.PI / 2;
clock.position.set(-3.25, 3.35, -2.91);
clock.castShadow = true;
scene.add(clock);
box(0.045, 0.2, 0.035, M.navy, -3.25, 3.4, -2.85);
box(0.17, 0.04, 0.035, M.navy, -3.19, 3.35, -2.85);
// -------------------------------------------------------------------------
// Persistent, uniquely modeled item objects
// -------------------------------------------------------------------------
const itemDefinitions = {
coat: {
pickupStart: 3.3,
pickupEnd: 3.9,
dropStart: 19.6,
dropEnd: 20.3,
home: new THREE.Vector3(-2.72, 1.86, -2.72),
final: new THREE.Vector3(-2.72, 1.86, -2.72),
labelOffset: new THREE.Vector3(0, 0.88, 0)
},
boots: {
pickupStart: 4.9,
pickupEnd: 5.5,
dropStart: 16.2,
dropEnd: 16.9,
home: new THREE.Vector3(-2.54, 0.015, -2.25),
final: new THREE.Vector3(0.43, 0.12, -1.78),
labelOffset: new THREE.Vector3(0, 0.76, 0)
},
umbrella: {
pickupStart: 6.8,
pickupEnd: 7.4,
dropStart: 18.1,
dropEnd: 18.8,
home: new THREE.Vector3(3.48, 0.015, -2.42),
final: new THREE.Vector3(0.63, 0.28, -2.39),
labelOffset: new THREE.Vector3(0, 1.55, 0)
},
bag: {
pickupStart: 8.7,
pickupEnd: 9.3,
dropStart: 21.1,
dropEnd: 21.8,
home: new THREE.Vector3(shelfX, shelfTop + 0.015, shelfZ),
final: new THREE.Vector3(shelfX, shelfTop + 0.015, shelfZ),
labelOffset: new THREE.Vector3(0, 0.86, 0)
}
};
const items = {};
function addDroplets(group, positions) {
const geometry = new THREE.SphereGeometry(0.038, 7, 5);
const material = new THREE.MeshStandardMaterial({
color: 0x8fd3e7,
emissive: 0x3a8da4,
emissiveIntensity: 0.38,
roughness: 0.18,
metalness: 0.05,
transparent: true,
opacity: 0.88,
depthWrite: false
});
const droplets = new THREE.Group();
positions.forEach((position, index) => {
const drop = new THREE.Mesh(geometry, material);
drop.position.copy(position);
drop.scale.set(0.8, index % 2 ? 1.45 : 1.1, 0.8);
drop.castShadow = false;
droplets.add(drop);
});
droplets.visible = false;
group.add(droplets);
group.userData.droplets = droplets;
}
function makeCoat() {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: 0xd99534,
roughness: 0.82
});
box(0.68, 0.82, 0.24, material, 0, 0, 0, group);
box(0.78, 0.15, 0.26, material, 0, 0.36, 0, group);
const leftSleeve = box(0.21, 0.72, 0.23, material, -0.45, 0.02, 0, group);
const rightSleeve = box(0.21, 0.72, 0.23, material, 0.45, 0.02, 0, group);
leftSleeve.rotation.z = -0.16;
rightSleeve.rotation.z = 0.16;
box(0.29, 0.15, 0.28, material, 0, 0.48, 0, group);
box(0.2, 0.18, 0.055, material, -0.18, -0.09, 0.145, group);
box(0.2, 0.18, 0.055, material, 0.18, -0.09, 0.145, group);
const buttonMaterial = new THREE.MeshStandardMaterial({
color: 0x5d432b,
roughness: 0.72
});
[-0.2, 0, 0.2].forEach((y) => {
box(0.055, 0.055, 0.04, buttonMaterial, 0, y, 0.145, group);
});
// Hanger loop and shoulders.
box(0.12, 0.2, 0.06, M.darkWood, 0, 0.63, 0, group);
box(0.38, 0.06, 0.06, M.darkWood, 0, 0.51, 0, group);
addDroplets(group, [
new THREE.Vector3(-0.2, 0.19, 0.16),
new THREE.Vector3(0.12, -0.05, 0.17),
new THREE.Vector3(0.24, 0.31, 0.15),
new THREE.Vector3(-0.34, -0.2, 0.14)
]);
group.userData.primary = material;
group.userData.base = new THREE.Color(0xd99534);
group.userData.wet = new THREE.Color(0xa96729);
return group;
}
function makeBoots() {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: 0x76513b,
roughness: 0.88
});
[-0.19, 0.19].forEach((x) => {
box(0.29, 0.5, 0.29, material, x, 0.28, 0, group);
box(0.31, 0.18, 0.48, material, x, 0.1, 0.1, group);
box(0.31, 0.12, 0.2, material, x, 0.18, 0.29, group);
box(0.33, 0.065, 0.54, M.rubber, x, 0.035, 0.1, group);
const laceMaterial = new THREE.MeshStandardMaterial({
color: 0xc6a36b,
roughness: 0.95
});
for (let i = 0; i < 3; i++) {
box(0.23, 0.025, 0.028, laceMaterial, x, 0.39 - i * 0.09, 0.153, group);
}
});
addDroplets(group, [
new THREE.Vector3(-0.19, 0.35, 0.155),
new THREE.Vector3(-0.1, 0.08, 0.35),
new THREE.Vector3(0.17, 0.32, 0.155),
new THREE.Vector3(0.25, 0.09, 0.34)
]);
group.userData.primary = material;
group.userData.base = new THREE.Color(0x76513b);
group.userData.wet = new THREE.Color(0x49362f);
return group;
}
function makeUmbrella() {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: 0x3c8b86,
roughness: 0.76
});
box(0.055, 1.35, 0.055, M.darkWood, 0, 0.7, 0, group);
box(0.3, 0.08, 0.08, M.darkWood, 0, 1.38, 0, group);
box(0.3, 0.08, 0.08, M.darkWood, 0, 1.58, 0, group);
box(0.08, 0.08, 0.3, M.darkWood, 0, 1.58, 0, group);
box(0.48, 0.23, 0.45, material, 0, 1.26, 0, group);
box(0.78, 0.17, 0.57, material, 0, 1.11, 0, group);
box(0.96, 0.12, 0.66, material, 0, 0.98, 0, group);
box(0.23, 0.19, 0.31, material, 0, 1.45, 0, group);
// Voxel ribs.
[-0.31, 0, 0.31].forEach((x) => {
box(0.035, 0.22, 0.7, M.darkTeal, x, 1.14, 0, group);
});
addDroplets(group, [
new THREE.Vector3(-0.25, 1.2, 0.34),
new THREE.Vector3(0.14, 1.27, 0.3),
new THREE.Vector3(0.34, 1.02, 0.28),
new THREE.Vector3(-0.08, 0.91, 0.35),
new THREE.Vector3(0.03, 1.46, 0.18)
]);
group.userData.primary = material;
group.userData.base = new THREE.Color(0x3c8b86);
group.userData.wet = new THREE.Color(0x286462);
return group;
}
function makeBag() {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: 0xb8794f,
roughness: 0.9
});
box(0.72, 0.5, 0.34, material, 0, 0.26, 0, group);
box(0.74, 0.16, 0.37, M.darkWood, 0, 0.49, 0, group);
box(0.1, 0.27, 0.06, M.darkWood, -0.2, 0.7, 0, group);
box(0.1, 0.27, 0.06, M.darkWood, 0.2, 0.7, 0, group);
box(0.5, 0.1, 0.06, M.darkWood, 0, 0.82, 0, group);
box(0.13, 0.13, 0.06, M.brass, 0, 0.49, 0.205, group);
group.userData.primary = material;
group.userData.base = new THREE.Color(0xb8794f);
group.userData.wet = new THREE.Color(0xb8794f); // Deliberately stays dry.
return group;
}
items.coat = makeCoat();
items.boots = makeBoots();
items.umbrella = makeUmbrella();
items.bag = makeBag();
Object.entries(items).forEach(([key, item]) => {
const definition = itemDefinitions[key];
item.position.copy(definition.home);
item.userData.definition = definition;
scene.add(item);
});
// -------------------------------------------------------------------------
// Voxel visitor
// -------------------------------------------------------------------------
const visitor = new THREE.Group();
scene.add(visitor);
const visitorJacket = new THREE.MeshStandardMaterial({
color: 0x4f7182,
roughness: 0.86
});
const visitorPants = new THREE.MeshStandardMaterial({
color: 0x303d49,
roughness: 0.9
});
const visitorSkin = new THREE.MeshStandardMaterial({
color: 0xdca47f,
roughness: 0.92
});
const visitorHair = new THREE.MeshStandardMaterial({
color: 0x3b302d,
roughness: 1
});
box(0.72, 0.82, 0.42, visitorJacket, 0, 1.26, 0, visitor);
box(0.55, 0.55, 0.53, visitorSkin, 0, 1.96, 0.015, visitor);
box(0.59, 0.17, 0.57, visitorHair, 0, 2.2, 0, visitor);
box(0.58, 0.08, 0.08, visitorHair, 0, 2.03, 0.27, visitor);
box(0.38, 0.12, 0.42, visitorHair, 0, 2.25, -0.04, visitor);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.19, 0.86, 0);
rightLeg.position.set(0.19, 0.86, 0);
visitor.add(leftLeg, rightLeg);
box(0.25, 0.69, 0.28, visitorPants, 0, -0.34, 0, leftLeg);
box(0.25, 0.69, 0.28, visitorPants, 0, -0.34, 0, rightLeg);
box(0.29, 0.15, 0.43, M.rubber, 0, -0.73, 0.07, leftLeg);
box(0.29, 0.15, 0.43, M.rubber, 0, -0.73, 0.07, rightLeg);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.49, 1.56, 0);
rightArm.position.set(0.49, 1.56, 0);
visitor.add(leftArm, rightArm);
box(0.22, 0.69, 0.26, visitorJacket, 0, -0.31, 0, leftArm);
box(0.22, 0.69, 0.26, visitorJacket, 0, -0.31, 0, rightArm);
box(0.2, 0.2, 0.22, visitorSkin, 0, -0.72, 0.02, leftArm);
box(0.2, 0.2, 0.22, visitorSkin, 0, -0.72, 0.02, rightArm);
// Carrying slots are children of the visitor, so carried objects remain
// attached to the same physical visitor throughout the walk.
const slots = {};
function makeSlot(name, x, y, z, rx, ry, rz) {
const slot = new THREE.Object3D();
slot.position.set(x, y, z);
slot.rotation.set(rx, ry, rz);
visitor.add(slot);
slots[name] = slot;
}
makeSlot("coat", -0.66, 1.03, 0.28, 0.08, 0.1, -0.32);
makeSlot("boots", -0.48, 0.42, 0.34, 0.05, 0, 0.12);
makeSlot("umbrella", 0.65, 0.13, 0.36, -0.08, 0, -0.16);
makeSlot("bag", 0.64, 0.66, 0.26, 0.04, 0, -0.1);
// -------------------------------------------------------------------------
// Rain behind the doorway
// -------------------------------------------------------------------------
const rainCount = 95;
const rainPositions = new Float32Array(rainCount * 6);
const rainData = [];
for (let i = 0; i < rainCount; i++) {
rainData.push({
x: 1.62 + Math.random() * 1.56,
y: Math.random() * 4.6,
z: -3.25 - Math.random() * 1.55,
speed: 2.8 + Math.random() * 2.7,
length: 0.17 + Math.random() * 0.2
});
}
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rainPositions, 3)
);
const rainMaterial = new THREE.LineBasicMaterial({
color: 0xc6edfa,
transparent: true,
opacity: 0.68,
depthWrite: false
});
const rain = new THREE.LineSegments(rainGeometry, rainMaterial);
rain.frustumCulled = false;
scene.add(rain);
const puddleMaterial = new THREE.MeshStandardMaterial({
color: 0x4f9da9,
roughness: 0.18,
metalness: 0.05,
transparent: true,
opacity: 0.46,
depthWrite: false
});
const puddle = new THREE.Mesh(
new THREE.CircleGeometry(0.48, 24),
puddleMaterial
);
puddle.rotation.x = -Math.PI / 2;
puddle.position.set(0.82, 0.127, -2.02);
puddle.scale.set(1.18, 0.62, 1);
puddle.visible = false;
scene.add(puddle);
// -------------------------------------------------------------------------
// Timeline and visitor track
// -------------------------------------------------------------------------
const duration = 22.4;
const track = [
{ t: 0.0, x: 2.4, z: -4.65, yaw: 0 },
{ t: 1.3, x: 2.4, z: -0.92, yaw: 0 },
{ t: 3.3, x: -1.55, z: -1.25, yaw: Math.PI },
{ t: 4.9, x: -1.82, z: -1.42, yaw: Math.PI },
{ t: 6.8, x: 2.88, z: -1.45, yaw: Math.PI },
{ t: 8.7, x: -0.24, z: -1.36, yaw: Math.PI },
{ t: 10.8, x: 2.4, z: -1.18, yaw: Math.PI },
{ t: 12.6, x: 2.4, z: -4.85, yaw: Math.PI },
{ t: 14.2, x: 2.4, z: -1.03, yaw: 0 },
{ t: 16.2, x: 0.22, z: -1.36, yaw: Math.PI },
{ t: 18.1, x: 0.42, z: -1.5, yaw: Math.PI },
{ t: 19.6, x: -1.53, z: -1.25, yaw: Math.PI },
{ t: 21.1, x: -0.24, z: -1.28, yaw: Math.PI },
{ t: 22.4, x: 1.15, z: 0.42, yaw: 2.15 }
];
function clamp01(v) {
return Math.max(0, Math.min(1, v));
}
function ease(v) {
const x = clamp01(v);
return x * x * (3 - 2 * x);
}
function lerpAngle(a, b, amount) {
let difference = ((b - a + Math.PI) % (Math.PI * 2)) - Math.PI;
if (difference < -Math.PI) difference += Math.PI * 2;
return a + difference * amount;
}
function sampleTrack(time) {
if (time <= track[0].t) {
return {
x: track[0].x,
z: track[0].z,
yaw: track[0].yaw
};
}
for (let i = 0; i < track.length - 1; i++) {
const a = track[i];
const b = track[i + 1];
if (time >= a.t && time <= b.t) {
const amount = ease((time - a.t) / (b.t - a.t));
return {
x: THREE.MathUtils.lerp(a.x, b.x, amount),
z: THREE.MathUtils.lerp(a.z, b.z, amount),
yaw: lerpAngle(a.yaw, b.yaw, amount)
};
}
}
const last = track[track.length - 1];
return { x: last.x, z: last.z, yaw: last.yaw };
}
const tempPosition = new THREE.Vector3();
const tempQuaternion = new THREE.Quaternion();
const tempQuaternion2 = new THREE.Quaternion();
const worldPosition = new THREE.Vector3();
const worldQuaternion = new THREE.Quaternion();
function getCarryTransform(name, targetPosition, targetQuaternion) {
slots[name].updateWorldMatrix(true, false);
slots[name].getWorldPosition(targetPosition);
slots[name].getWorldQuaternion(targetQuaternion);
}
function updateItems(time) {
Object.entries(items).forEach(([name, item]) => {
const d = itemDefinitions[name];
getCarryTransform(name, worldPosition, worldQuaternion);
if (time < d.pickupStart) {
item.position.copy(d.home);
item.quaternion.identity();
} else if (time < d.pickupEnd) {
const amount = ease((time - d.pickupStart) / (d.pickupEnd - d.pickupStart));
item.position.copy(d.home).lerp(worldPosition, amount);
item.quaternion.identity().slerp(worldQuaternion, amount);
} else if (time < d.dropStart) {
item.position.copy(worldPosition);
item.quaternion.copy(worldQuaternion);
} else if (time < d.dropEnd) {
const amount = ease((time - d.dropStart) / (d.dropEnd - d.dropStart));
item.position.copy(worldPosition).lerp(d.final, amount);
const finalQuaternion = new THREE.Quaternion();
if (name === "umbrella") {
finalQuaternion.setFromEuler(
new THREE.Euler(0, 0, Math.PI / 2)
);
}
item.quaternion.copy(worldQuaternion).slerp(finalQuaternion, amount);
} else {
item.position.copy(d.final);
if (name === "umbrella") {
item.quaternion.setFromEuler(
new THREE.Euler(0, 0, Math.PI / 2)
);
} else {
item.quaternion.identity();
}
}
// The bag never changes color or receives droplets.
if (name !== "bag") {
const wetness = ease((time - 12.4) / 1.8);
item.userData.primary.color
.copy(item.userData.base)
.lerp(item.userData.wet, wetness);
item.userData.droplets.visible = time >= 14.05;
} else {
item.userData.primary.color.copy(item.userData.base);
}
});
}
// -------------------------------------------------------------------------
// UI state
// -------------------------------------------------------------------------
const playButton = document.querySelector("#play");
const restartButton = document.querySelector("#restart");
const beforeButton = document.querySelector("#before");
const afterButton = document.querySelector("#after");
const scrubber = document.querySelector("#scrubber");
const timeLabel = document.querySelector("#time");
const stageLabel = document.querySelector("#stage");
const statusElements = {
coat: document.querySelector("#coat-status"),
boots: document.querySelector("#boots-status"),
umbrella: document.querySelector("#umbrella-status"),
bag: document.querySelector("#bag-status")
};
let time = 0;
let playing = true;
let lastUiState = "";
function setPlaying(value) {
playing = value;
playButton.textContent = playing ? "Pause" : "Play";
}
playButton.addEventListener("click", () => setPlaying(!playing));
restartButton.addEventListener("click", () => {
time = 0;
setPlaying(true);
});
beforeButton.addEventListener("click", () => {
time = 0.2;
setPlaying(false);
});
afterButton.addEventListener("click", () => {
time = duration;
setPlaying(false);
});
scrubber.addEventListener("input", (event) => {
time = Number(event.target.value);
setPlaying(false);
});
function itemStatus(name) {
const d = itemDefinitions[name];
if (time < d.pickupStart) {
if (name === "coat") return "On hook";
if (name === "boots") return "Below bench";
if (name === "umbrella") return "Beside door";
return "On dry shelf";
}
if (time < d.pickupEnd) return "Being collected";
if (time < d.dropStart) {
if (time >= 12.4) return "Carried · visibly wet";
return "Carried by visitor";
}
if (time < d.dropEnd) return "Being placed";
if (name === "coat") return "Back on hook";
if (name === "boots") return "Wet · drying tray";
if (name === "umbrella") return "Wet · drying tray";
return "Dry · dry shelf";
}
function updateUi() {
const uiState = [
time < 1.3,
time < 9.3,
time < 12.4,
time < 14.2,
time < 21.8,
itemStatus("coat"),
itemStatus("boots"),
itemStatus("umbrella"),
itemStatus("bag")
].join("|");
if (uiState !== lastUiState) {
lastUiState = uiState;
if (time < 1.3) {
stageLabel.textContent = "01 · Before the walk";
} else if (time < 9.3) {
stageLabel.textContent = "02 · Collecting four items";
} else if (time < 12.4) {
stageLabel.textContent = "03 · Leaving through the door";
} else if (time < 14.2) {
stageLabel.textContent = "04 · The rainy walk";
} else if (time < 21.8) {
stageLabel.textContent = "05 · Returning with the same items";
} else {
stageLabel.textContent = "06 · After: wet gear drying";
}
Object.keys(statusElements).forEach((name) => {
statusElements[name].textContent = itemStatus(name);
});
}
scrubber.value = time.toFixed(2);
timeLabel.textContent = `${time.toFixed(1).padStart(4, "0")} / ${duration.toFixed(1)} s`;
}
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi + dy * 0.0045,
0.53,
1.22
);
updateCamera();
});
function stopDragging() {
dragging = false;
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.008,
7.6,
15.5
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Object tags
// -------------------------------------------------------------------------
const tags = {
coat: document.querySelector("#tag-coat"),
boots: document.querySelector("#tag-boots"),
umbrella: document.querySelector("#tag-umbrella"),
bag: document.querySelector("#tag-bag")
};
function updateTags() {
const width = window.innerWidth;
const height = window.innerHeight;
Object.entries(items).forEach(([name, item]) => {
const projected = item
.localToWorld(itemDefinitions[name].labelOffset.clone())
.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.05 &&
projected.x < 1.05 &&
projected.y > -1.05 &&
projected.y < 1.05;
// Labels appear in the clear "before" and "after" compositions.
const show = visible && (time < 1.35 || time > 21.7);
tags[name].style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
tags[name].style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
tags[name].style.opacity = show ? "0.92" : "0";
});
}
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const animationClock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(animationClock.getDelta(), 0.05);
if (playing) {
time += delta;
if (time >= duration) {
time = duration;
setPlaying(false);
}
}
const pose = sampleTrack(time);
const previousPose = sampleTrack(Math.max(0, time - 0.04));
const nextPose = sampleTrack(Math.min(duration, time + 0.04));
const speed = Math.hypot(
nextPose.x - previousPose.x,
nextPose.z - previousPose.z
) / 0.08;
const moving = THREE.MathUtils.clamp(speed / 1.6, 0, 1);
const walkPhase = time * 9.2;
visitor.position.set(pose.x, 0, pose.z);
visitor.rotation.y = pose.yaw;
visitor.position.y += Math.sin(walkPhase * 2) * 0.018 * moving;
leftLeg.rotation.x = Math.sin(walkPhase) * 0.46 * moving;
rightLeg.rotation.x = -Math.sin(walkPhase) * 0.46 * moving;
leftArm.rotation.x = -Math.sin(walkPhase) * 0.18 * moving;
rightArm.rotation.x = Math.sin(walkPhase) * 0.18 * moving;
visitor.updateMatrixWorld(true);
updateItems(time);
// The visitor's clothing darkens slightly during the rainy walk.
const visitorWetness = ease((time - 12.45) / 1.45);
visitorJacket.color
.set(0x4f7182)
.lerp(new THREE.Color(0x3b5968), visitorWetness);
visitorPants.color
.set(0x303d49)
.lerp(new THREE.Color(0x222d35), visitorWetness);
// Animate the rain only outside the doorway.
for (let i = 0; i < rainCount; i++) {
const drop = rainData[i];
drop.y -= drop.speed * delta;
if (drop.y < -0.1) {
drop.y = 4.7;
drop.x = 1.62 + Math.random() * 1.56;
}
const offset = i * 6;
rainPositions[offset] = drop.x;
rainPositions[offset + 1] = drop.y;
rainPositions[offset + 2] = drop.z;
rainPositions[offset + 3] = drop.x - 0.025;
rainPositions[offset + 4] = drop.y + drop.length;
rainPositions[offset + 5] = drop.z;
}
rainGeometry.attributes.position.needsUpdate = true;
rainMaterial.opacity = time > 9.5 ? 0.72 : 0.32;
puddle.visible = time >= 16.85;
puddleMaterial.opacity = 0.42 + Math.sin(time * 2.1) * 0.035;
updateUi();
updateTags();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```