Prompt specification
Build or customize the Three.js 3D scene "Rainy family entrance" 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 family entrance
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rainy-family-entrance-x0007
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a coat-hook rail. Compose an entryway with hooks, bench, wet shoes, mat, and umbrella; a returning character hangs a coat before sitting to remove their footwear. Stylized solid forms.
Working Three.js Starter (rainy-family-entrance-x0007):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Returning Home — Entryway Scene</title>
<style>
:root {
color-scheme: light;
--ink: #24312e;
--paper: #f4efe5;
--accent: #c66b42;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7d0c3;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.title {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
max-width: 330px;
pointer-events: none;
text-shadow: 0 1px 12px rgba(244, 239, 229, .75);
}
.eyebrow {
margin: 0 0 7px;
font-size: 10px;
font-weight: 800;
letter-spacing: .24em;
text-transform: uppercase;
color: #76503c;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 54px);
font-weight: 500;
line-height: .98;
letter-spacing: -.035em;
}
.subtitle {
margin: 12px 0 0;
max-width: 270px;
font-size: 12px;
line-height: 1.5;
color: #50605a;
}
.controls {
position: fixed;
right: 26px;
bottom: 24px;
z-index: 5;
display: flex;
align-items: center;
gap: 13px;
}
button {
appearance: none;
border: 1px solid rgba(36, 49, 46, .2);
border-radius: 999px;
padding: 11px 17px;
background: rgba(244, 239, 229, .88);
color: var(--ink);
font: 700 11px/1 inherit;
letter-spacing: .06em;
cursor: pointer;
box-shadow: 0 8px 25px rgba(43, 38, 30, .12);
backdrop-filter: blur(9px);
transition: transform .2s ease, background .2s ease;
}
button:hover {
transform: translateY(-2px);
background: #fffaf0;
}
button:active { transform: translateY(0); }
.timeline {
width: 118px;
height: 4px;
overflow: hidden;
border-radius: 4px;
background: rgba(36, 49, 46, .16);
}
.timeline > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--accent);
}
.hint {
position: fixed;
left: 30px;
bottom: 27px;
z-index: 5;
font-size: 10px;
font-weight: 700;
letter-spacing: .12em;
text-transform: uppercase;
color: rgba(36, 49, 46, .58);
pointer-events: none;
}
@media (max-width: 680px) {
.title { top: 20px; left: 20px; }
.subtitle { display: none; }
.hint { left: 20px; bottom: 24px; }
.controls { right: 18px; bottom: 18px; }
.timeline { width: 72px; }
}
</style>
</head>
<body>
<header class="title">
<p class="eyebrow">A small homecoming</p>
<h1>The Mudroom</h1>
<p class="subtitle">A coat goes on the hook, wet shoes come off, and the day finally settles.</p>
</header>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="controls">
<div class="timeline" aria-hidden="true"><span id="progress"></span></div>
<button id="replay" type="button">Replay arrival</button>
</div>
<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 direct camera controls
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd7d0c3);
scene.fog = new THREE.Fog(0xd7d0c3, 12, 22);
const camera = new THREE.PerspectiveCamera(38, innerWidth / innerHeight, 0.1, 60);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "An animated three-dimensional entryway with a returning character");
document.body.prepend(renderer.domElement);
const cameraState = {
theta: 0.63,
phi: 1.13,
radius: 10.4,
target: new THREE.Vector3(-0.15, 1.35, -0.45)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
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;
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - dy * 0.004, 0.62, 1.42);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.006,
6.4,
15
);
updateCamera();
}, { passive: false });
// -------------------------------------------------------------------------
// Materials and construction helpers
// -------------------------------------------------------------------------
const palette = {
wall: 0xded7c9,
wallSide: 0xc9c1b2,
floor: 0xa88e72,
floorEdge: 0x806b56,
trim: 0xf0eadf,
wood: 0x9a6545,
woodLight: 0xb77a52,
darkWood: 0x684734,
metal: 0x3e4b49,
brass: 0xc3974d,
door: 0x56756d,
teal: 0x2f7776,
sweater: 0x4c7775,
trousers: 0x394449,
skin: 0xc98f6e,
hair: 0x3b302d,
coat: 0xc98a3e,
coatDark: 0xa7672e,
shoe: 0x8a4837,
wetShoe: 0x40525d,
mat: 0x53645c,
cream: 0xe6ddca,
terracotta: 0xb76e4b,
leaf: 0x4f7657,
puddle: 0x719091
};
const material = (color, roughness = 0.78, metalness = 0) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
});
const M = {
wall: material(palette.wall),
wallSide: material(palette.wallSide),
floor: material(palette.floor),
floorEdge: material(palette.floorEdge),
trim: material(palette.trim),
wood: material(palette.wood),
woodLight: material(palette.woodLight),
darkWood: material(palette.darkWood),
metal: material(palette.metal, 0.58, 0.22),
brass: material(palette.brass, 0.38, 0.48),
door: material(palette.door),
sweater: material(palette.sweater),
trousers: material(palette.trousers),
skin: material(palette.skin),
hair: material(palette.hair),
coat: material(palette.coat),
coatDark: material(palette.coatDark),
shoe: material(palette.shoe),
wetShoe: material(palette.wetShoe),
mat: material(palette.mat),
cream: material(palette.cream),
terracotta: material(palette.terracotta),
leaf: material(palette.leaf),
puddle: new THREE.MeshStandardMaterial({
color: palette.puddle,
roughness: 0.2,
metalness: 0.08,
transparent: true,
opacity: 0.52,
depthWrite: false
})
};
function addMesh(geometry, mat, parent, position = [0, 0, 0], rotation = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(parent, size, position, mat, rotation = [0, 0, 0]) {
return addMesh(new THREE.BoxGeometry(...size), mat, parent, position, rotation);
}
function cylinder(parent, radiusTop, radiusBottom, height, position, mat, segments = 12, rotation = [0, 0, 0]) {
return addMesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat,
parent,
position,
rotation
);
}
function sphere(parent, radius, position, mat, scale = [1, 1, 1]) {
const mesh = addMesh(new THREE.SphereGeometry(radius, 14, 10), mat, parent, position);
mesh.scale.set(...scale);
return mesh;
}
function capsule(parent, radius, length, position, mat, rotation = [0, 0, 0]) {
return addMesh(
new THREE.CapsuleGeometry(radius, length, 4, 10),
mat,
parent,
position,
rotation
);
}
// -------------------------------------------------------------------------
// Entryway architecture
// -------------------------------------------------------------------------
const room = new THREE.Group();
scene.add(room);
box(room, [9.6, 0.28, 7.5], [0, -0.14, 0.35], M.floor);
box(room, [9.6, 0.26, 0.12], [0, -0.12, 4.02], M.floorEdge);
box(room, [9.4, 5.7, 0.2], [0, 2.72, -2.92], M.wall);
box(room, [0.2, 5.7, 6.6], [-4.62, 2.72, 0.25], M.wallSide);
box(room, [9.3, 0.18, 0.08], [0, 0.1, -2.79], M.trim);
box(room, [0.08, 0.18, 6.6], [-4.49, 0.1, 0.25], M.trim);
// Back door and frame.
box(room, [1.68, 3.55, 0.11], [3.25, 1.78, -2.77], M.door);
box(room, [1.92, 0.16, 0.22], [3.25, 3.62, -2.72], M.trim);
box(room, [0.16, 3.72, 0.22], [2.36, 1.83, -2.72], M.trim);
box(room, [0.16, 3.72, 0.22], [4.14, 1.83, -2.72], M.trim);
box(room, [1.28, 0.05, 0.06], [3.25, 2.7, -2.69], M.door);
box(room, [1.28, 0.05, 0.06], [3.25, 0.93, -2.69], M.door);
sphere(room, 0.075, [2.62, 1.62, -2.66], M.brass);
// Small wall plaque.
cylinder(room, 0.24, 0.24, 0.07, [3.26, 3.95, -2.75], M.brass, 16, [Math.PI / 2, 0, 0]);
cylinder(room, 0.185, 0.185, 0.08, [3.26, 3.95, -2.69], M.cream, 16, [Math.PI / 2, 0, 0]);
// -------------------------------------------------------------------------
// Hook rail
// -------------------------------------------------------------------------
const rail = new THREE.Group();
scene.add(rail);
const railX = -0.75;
box(rail, [4.75, 0.18, 0.16], [railX, 3.38, -2.61], M.darkWood);
const hookXs = [-2.35, -1.4, -0.45, 0.5, 1.45];
hookXs.forEach((x) => {
cylinder(rail, 0.052, 0.052, 0.32, [x, 3.36, -2.38], M.brass, 10, [Math.PI / 2, 0, 0]);
sphere(rail, 0.09, [x, 3.36, -2.21], M.brass);
cylinder(rail, 0.052, 0.052, 0.3, [x, 3.48, -2.2], M.brass, 10, [0, 0, 0]);
sphere(rail, 0.075, [x, 3.63, -2.2], M.brass);
});
// -------------------------------------------------------------------------
// Bench
// -------------------------------------------------------------------------
const bench = new THREE.Group();
scene.add(bench);
const benchX = -0.75;
const benchZ = -1.78;
for (let i = 0; i < 5; i++) {
box(
bench,
[3.45, 0.13, 0.16],
[benchX, 0.76, benchZ - 0.34 + i * 0.17],
i % 2 ? M.wood : M.woodLight
);
}
[-2.12, 0.62].forEach((x) => {
[-2.1, -1.46].forEach((z) => {
box(bench, [0.12, 0.72, 0.12], [x, 0.36, z], M.metal);
});
});
box(bench, [3.0, 0.1, 0.1], [benchX, 0.27, -2.08], M.metal);
box(bench, [3.0, 0.1, 0.1], [benchX, 0.27, -1.48], M.metal);
// Small cushion.
const cushion = box(bench, [1.0, 0.14, 0.72], [-1.63, 0.9, -1.75], M.cream);
cushion.rotation.y = -0.03;
// -------------------------------------------------------------------------
// Doormat, puddle, wet shoes, umbrella, and plant
// -------------------------------------------------------------------------
const matGroup = new THREE.Group();
scene.add(matGroup);
box(matGroup, [3.25, 0.055, 1.78], [-0.63, 0.035, -0.12], M.mat);
box(matGroup, [2.94, 0.018, 1.48], [-0.63, 0.07, -0.12], material(0x627269));
for (let i = 0; i < 8; i++) {
box(matGroup, [0.025, 0.012, 1.35], [-1.83 + i * 0.34, 0.084, -0.12], material(0x46584f));
}
const puddle = addMesh(
new THREE.CircleGeometry(0.72, 32),
M.puddle,
scene,
[2.13, 0.018, 0.78],
[-Math.PI / 2, 0, 0]
);
puddle.scale.set(1.45, 0.76, 1);
puddle.castShadow = false;
function createShoe(shoeColor, parent = scene) {
const group = new THREE.Group();
parent.add(group);
box(group, [0.29, 0.075, 0.56], [0, 0.045, 0.08], material(0x343c3b));
box(group, [0.27, 0.18, 0.39], [0, 0.15, -0.01], shoeColor);
sphere(group, 0.145, [0, 0.15, 0.16], shoeColor, [0.93, 0.85, 1.18]);
box(group, [0.17, 0.035, 0.14], [0, 0.235, -0.09], material(0x303a39));
for (let i = 0; i < 3; i++) {
box(group, [0.18, 0.018, 0.025], [0, 0.255, -0.01 + i * 0.065], M.cream);
}
return group;
}
const wetShoeA = createShoe(M.wetShoe);
wetShoeA.position.set(1.75, 0, 0.75);
wetShoeA.rotation.y = -0.18;
const wetShoeB = createShoe(M.wetShoe);
wetShoeB.position.set(2.18, 0, 0.86);
wetShoeB.rotation.y = 0.12;
// Umbrella stand and folded umbrella.
cylinder(scene, 0.33, 0.29, 0.68, [-3.35, 0.35, -1.86], M.metal, 16);
cylinder(scene, 0.27, 0.27, 0.035, [-3.35, 0.7, -1.86], material(0x263231), 16);
const umbrella = new THREE.Group();
scene.add(umbrella);
umbrella.position.set(-3.34, 0.25, -1.84);
umbrella.rotation.z = -0.16;
cylinder(umbrella, 0.035, 0.035, 1.65, [0, 0.94, 0], M.darkWood, 10);
addMesh(new THREE.ConeGeometry(0.28, 0.86, 8), M.coatDark, umbrella, [0, 0.67, 0]);
cylinder(umbrella, 0.045, 0.045, 0.18, [0, 1.18, 0], M.brass, 10);
const umbrellaHandle = addMesh(
new THREE.TorusGeometry(0.16, 0.035, 8, 18, Math.PI * 1.55),
M.darkWood,
umbrella,
[0, 1.83, 0],
[Math.PI / 2, 0, 0]
);
// Potted plant.
cylinder(scene, 0.32, 0.25, 0.52, [3.67, 0.27, -2.28], M.terracotta, 12);
cylinder(scene, 0.27, 0.27, 0.035, [3.67, 0.54, -2.28], material(0x483b30), 12);
cylinder(scene, 0.045, 0.06, 1.1, [3.67, 1.05, -2.28], M.darkWood, 8);
const leafPositions = [
[3.35, 1.25, -2.24, -0.55, 0.15],
[3.92, 1.4, -2.23, 0.55, 0.05],
[3.46, 1.68, -2.25, -0.42, -0.25],
[3.86, 1.9, -2.24, 0.48, 0.2],
[3.65, 2.12, -2.25, 0.08, -0.05]
];
leafPositions.forEach(([x, y, z, rz, rx]) => {
const leaf = sphere(scene, 0.3, [x, y, z], M.leaf, [0.46, 1.0, 0.19]);
leaf.rotation.set(rx, 0.2, rz);
});
// -------------------------------------------------------------------------
// Returning character
// -------------------------------------------------------------------------
const character = new THREE.Group();
scene.add(character);
const pelvis = new THREE.Group();
character.add(pelvis);
box(pelvis, [0.62, 0.28, 0.38], [0, 0, 0], M.trousers);
const torso = new THREE.Group();
pelvis.add(torso);
capsule(torso, 0.34, 0.57, [0, 0.47, 0], M.sweater);
cylinder(torso, 0.13, 0.14, 0.22, [0, 1.04, 0], M.skin, 12);
const head = new THREE.Group();
head.position.set(0, 1.34, 0);
torso.add(head);
sphere(head, 0.31, [0, 0, 0], M.skin, [0.95, 1.08, 0.94]);
sphere(head, 0.315, [0, 0.11, -0.025], M.hair, [0.98, 0.65, 1.0]);
sphere(head, 0.055, [0, -0.015, 0.29], M.skin, [0.85, 0.9, 1]);
sphere(head, 0.027, [-0.105, 0.055, 0.276], material(0x263330));
sphere(head, 0.027, [0.105, 0.055, 0.276], material(0x263330));
function createArm(side) {
const arm = new THREE.Group();
arm.position.set(side * 0.43, 0.83, 0);
torso.add(arm);
capsule(arm, 0.135, 0.43, [0, -0.35, 0], M.sweater);
const elbow = new THREE.Group();
elbow.position.y = -0.69;
arm.add(elbow);
capsule(elbow, 0.115, 0.39, [0, -0.31, 0], M.sweater);
sphere(elbow, 0.125, [0, -0.66, 0], M.skin, [0.9, 1.08, 0.85]);
return { root: arm, elbow };
}
const leftArm = createArm(-1);
const rightArm = createArm(1);
function createLeg(side) {
const upper = new THREE.Group();
upper.position.set(side * 0.19, 0, 0);
pelvis.add(upper);
capsule(upper, 0.16, 0.2, [0, -0.25, 0], M.trousers);
const lower = new THREE.Group();
lower.position.y = -0.5;
upper.add(lower);
capsule(lower, 0.135, 0.47, [0, -0.39, 0], M.trousers);
cylinder(lower, 0.135, 0.135, 0.2, [0, -0.71, 0], M.cream, 10);
const shoe = createShoe(M.shoe, lower);
shoe.position.set(0, -0.82, 0.05);
return { upper, lower, shoe };
}
const leftLeg = createLeg(-1);
const rightLeg = createLeg(1);
// Anchor representing the coat collar while it is carried.
const carryAnchor = new THREE.Object3D();
carryAnchor.position.set(0.64, 0.76, 0.09);
pelvis.add(carryAnchor);
// -------------------------------------------------------------------------
// Coat
// -------------------------------------------------------------------------
const coat = new THREE.Group();
scene.add(coat);
box(coat, [0.92, 1.04, 0.24], [0, 0, 0], M.coat);
box(coat, [1.08, 0.25, 0.26], [0, 0.39, 0], M.coat);
const leftSleeve = capsule(coat, 0.15, 0.55, [-0.52, 0.03, 0], M.coat);
leftSleeve.rotation.z = -0.18;
const rightSleeve = capsule(coat, 0.15, 0.55, [0.52, 0.03, 0], M.coat);
rightSleeve.rotation.z = 0.18;
box(coat, [0.18, 0.3, 0.04], [-0.18, 0.43, 0.145], M.coatDark, [0, 0, -0.28]);
box(coat, [0.18, 0.3, 0.04], [0.18, 0.43, 0.145], M.coatDark, [0, 0, 0.28]);
box(coat, [0.32, 0.18, 0.035], [-0.25, -0.23, 0.137], M.coatDark);
box(coat, [0.32, 0.18, 0.035], [0.25, -0.23, 0.137], M.coatDark);
[-0.12, 0.13, 0.38].forEach((y) => {
sphere(coat, 0.035, [0, y, 0.15], M.coatDark);
});
const coatHook = new THREE.Vector3(-0.45, 2.68, -2.34);
// -------------------------------------------------------------------------
// Soft contact shadow under the character
// -------------------------------------------------------------------------
const blob = addMesh(
new THREE.CircleGeometry(0.6, 32),
new THREE.MeshBasicMaterial({
color: 0x35413e,
transparent: true,
opacity: 0.14,
depthWrite: false
}),
scene,
[0, 0.016, 0],
[-Math.PI / 2, 0, 0]
);
blob.castShadow = false;
blob.receiveShadow = false;
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf6eee0, 0x6b746e, 2.15));
const keyLight = new THREE.DirectionalLight(0xfff0d8, 3.2);
keyLight.position.set(4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const warmLight = new THREE.PointLight(0xffc990, 14, 9, 2);
warmLight.position.set(-3.1, 4.2, -1.4);
scene.add(warmLight);
const fillLight = new THREE.DirectionalLight(0xb9d8db, 0.75);
fillLight.position.set(-5, 3, 2);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Animation helpers
// -------------------------------------------------------------------------
const clamp01 = (v) => THREE.MathUtils.clamp(v, 0, 1);
const smooth = (v) => {
const x = clamp01(v);
return x * x * (3 - 2 * x);
};
const mix = THREE.MathUtils.lerp;
const startPosition = new THREE.Vector3(4.65, 0, 0.55);
const railPosition = new THREE.Vector3(0, 0, -1.36);
const benchPosition = new THREE.Vector3(-0.75, 0, -1.78);
const shoeTargets = [
new THREE.Vector3(-1.12, 0.035, -0.36),
new THREE.Vector3(-0.42, 0.035, -0.27)
];
let shoesRemoved = false;
const shoeStarts = [new THREE.Vector3(), new THREE.Vector3()];
const shoeStartQuaternions = [new THREE.Quaternion(), new THREE.Quaternion()];
function resetShoes() {
[leftLeg, rightLeg].forEach((leg) => {
if (leg.shoe.parent !== leg.lower) leg.lower.add(leg.shoe);
leg.shoe.position.set(0, -0.82, 0.05);
leg.shoe.rotation.set(0, 0, 0);
leg.shoe.scale.setScalar(1);
});
shoesRemoved = false;
}
function captureAndRemoveShoes() {
if (shoesRemoved) return;
scene.updateMatrixWorld(true);
[leftLeg, rightLeg].forEach((leg, i) => {
scene.attach(leg.shoe);
leg.shoe.getWorldPosition(shoeStarts[i]);
leg.shoe.getWorldQuaternion(shoeStartQuaternions[i]);
});
shoesRemoved = true;
}
const tempWorldPosition = new THREE.Vector3();
const tempTarget = new THREE.Vector3();
const tempDirection = new THREE.Vector3();
const tempQuaternion = new THREE.Quaternion();
const inverseTorsoQuaternion = new THREE.Quaternion();
function aimArm(arm, worldTarget, bend = 0.1) {
arm.root.getWorldPosition(tempWorldPosition);
tempDirection.copy(worldTarget).sub(tempWorldPosition).normalize();
torso.getWorldQuaternion(inverseTorsoQuaternion).invert();
tempDirection.applyQuaternion(inverseTorsoQuaternion);
const xAngle = Math.atan2(-tempDirection.z, -tempDirection.y);
const zAngle = Math.atan2(tempDirection.x, -tempDirection.y);
arm.root.rotation.x = xAngle;
arm.root.rotation.z = zAngle;
arm.elbow.rotation.x = bend;
}
function setWalkPose(amount, phase) {
const swing = Math.sin(phase) * 0.55 * amount;
const lift = Math.max(0, -Math.sin(phase)) * 0.6 * amount;
leftLeg.upper.rotation.x = swing;
rightLeg.upper.rotation.x = -swing;
leftLeg.lower.rotation.x = lift;
rightLeg.lower.rotation.x = Math.max(0, Math.sin(phase)) * 0.6 * amount;
leftArm.root.rotation.x = -swing * 0.65;
leftArm.root.rotation.z = 0;
leftArm.elbow.rotation.x = 0.12;
}
function updateScene(time) {
let position = railPosition.clone();
let rotationY = -Math.PI / 2;
let pelvisY = 1.28;
let torsoLean = 0.04;
let walkAmount = 0;
let walkPhase = 0;
// Arrival.
if (time < 2.45) {
const u = smooth(time / 2.45);
position.lerpVectors(startPosition, railPosition, u);
rotationY = -Math.PI / 2;
walkAmount = 1 - smooth((time - 1.9) / 0.55);
walkPhase = time * 8.2;
pelvisY += Math.abs(Math.sin(walkPhase)) * 0.035 * walkAmount;
}
// Turn toward the hooks.
else if (time < 3.15) {
const u = smooth((time - 2.45) / 0.7);
position.copy(railPosition);
rotationY = mix(-Math.PI / 2, -Math.PI, u);
pelvisY += Math.sin(u * Math.PI) * 0.025;
}
// Hang the coat.
else if (time < 4.85) {
position.copy(railPosition);
rotationY = -Math.PI;
}
// Turn and step toward the bench.
else if (time < 6.35) {
const u = smooth((time - 4.85) / 1.5);
position.lerpVectors(railPosition, benchPosition, u);
rotationY = mix(-Math.PI, 0, u);
walkAmount = Math.sin(u * Math.PI) * 0.65;
walkPhase = time * 8;
pelvisY += Math.abs(Math.sin(walkPhase)) * 0.025 * walkAmount;
}
// Sit.
else {
const u = smooth((time - 6.35) / 1.8);
position.copy(benchPosition);
rotationY = 0;
pelvisY = mix(1.28, 0.93, u);
torsoLean = mix(0.04, 0.3, u);
}
character.position.copy(position);
character.rotation.y = rotationY;
if (walkAmount > 0.001) {
setWalkPose(walkAmount, walkPhase);
} else {
leftLeg.upper.rotation.x = 0;
rightLeg.upper.rotation.x = 0;
leftLeg.lower.rotation.x = 0;
rightLeg.lower.rotation.x = 0;
}
// Bench sitting pose.
if (time >= 6.35) {
const sit = smooth((time - 6.35) / 1.8);
leftLeg.upper.rotation.x = mix(leftLeg.upper.rotation.x, -1.45, sit);
rightLeg.upper.rotation.x = mix(rightLeg.upper.rotation.x, -1.45, sit);
leftLeg.lower.rotation.x = mix(leftLeg.lower.rotation.x, 1.45, sit);
rightLeg.lower.rotation.x = mix(rightLeg.lower.rotation.x, 1.45, sit);
leftArm.root.rotation.x = mix(leftArm.root.rotation.x, -0.7, sit);
rightArm.root.rotation.x = mix(rightArm.root.rotation.x, -0.7, sit);
leftArm.root.rotation.z = mix(leftArm.root.rotation.z, -0.08, sit);
rightArm.root.rotation.z = mix(rightArm.root.rotation.z, 0.08, sit);
leftArm.elbow.rotation.x = mix(leftArm.elbow.rotation.x, 0.28, sit);
rightArm.elbow.rotation.x = mix(rightArm.elbow.rotation.x, 0.28, sit);
}
// Raise the right arm toward the hook.
if (time >= 3.0 && time < 5.25) {
const raise = smooth((time - 3.0) / 0.65);
const lower = smooth((time - 4.75) / 0.5);
const amount = raise * (1 - lower);
rightArm.root.rotation.x = mix(rightArm.root.rotation.x, -2.42, amount);
rightArm.root.rotation.z = mix(rightArm.root.rotation.z, 0.04, amount);
rightArm.elbow.rotation.x = mix(rightArm.elbow.rotation.x, 0.18, amount);
}
pelvis.position.y = pelvisY;
torso.rotation.x = torsoLean;
// Remove shoes and reach toward them.
if (time >= 8.15) {
const remove = smooth((time - 8.15) / 0.75);
torsoLean = mix(torsoLean, 0.58, remove);
}
if (time >= 8.75) {
captureAndRemoveShoes();
const u = clamp01((time - 8.75) / 1.65);
const eased = smooth(u);
[leftLeg, rightLeg].forEach((leg, i) => {
leg.shoe.position.lerpVectors(shoeStarts[i], shoeTargets[i], eased);
leg.shoe.position.y += Math.sin(u * Math.PI) * 0.24;
leg.shoe.quaternion.slerpQuaternions(
shoeStartQuaternions[i],
new THREE.Quaternion().setFromEuler(new THREE.Euler(0, i === 0 ? -0.08 : 0.08, 0)),
eased
);
});
scene.updateMatrixWorld(true);
aimArm(leftArm, shoeTargets[0], 0.18);
aimArm(rightArm, shoeTargets[1], 0.18);
} else if (shoesRemoved) {
resetShoes();
}
// Coat position and orientation.
scene.updateMatrixWorld(true);
carryAnchor.getWorldPosition(tempWorldPosition);
tempTarget.copy(tempWorldPosition);
tempTarget.y -= 0.51;
if (time < 3.35) {
coat.position.copy(tempTarget);
coat.quaternion.setFromEuler(new THREE.Euler(0, character.rotation.y, -0.11));
} else if (time < 4.55) {
const u = smooth((time - 3.35) / 1.2);
coat.position.lerpVectors(tempTarget, coatHook, u);
coat.position.y += Math.sin(u * Math.PI) * 0.22;
const carriedQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(0, character.rotation.y, -0.11)
);
coat.quaternion.slerpQuaternions(carriedQuaternion, new THREE.Quaternion(), u);
} else {
coat.position.copy(coatHook);
coat.quaternion.identity();
}
// Contact shadow follows the character.
blob.position.x = position.x;
blob.position.z = position.z + 0.05;
blob.scale.setScalar(time >= 6.35 ? 0.82 : 1);
blob.material.opacity = time >= 6.35 ? 0.11 : 0.14;
}
// -------------------------------------------------------------------------
// Timeline and replay
// -------------------------------------------------------------------------
const duration = 13.5;
let elapsed = 0;
let playing = true;
const progress = document.getElementById("progress");
const replayButton = document.getElementById("replay");
replayButton.addEventListener("click", () => {
elapsed = 0;
playing = true;
resetShoes();
replayButton.textContent = "Replay arrival";
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
elapsed = Math.min(duration, elapsed + delta);
if (elapsed >= duration) {
playing = false;
replayButton.textContent = "Watch again";
}
}
updateScene(elapsed);
progress.style.width = `${(elapsed / duration) * 100}%`;
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
resetShoes();
updateCamera();
animate();
</script>
</body>
</html>
```