Prompt specification
Build or customize the Three.js 3D scene "Muddy-walk entryway routine" 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: Muddy-walk entryway routine
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/muddy-walk-entryway-routine-x0619
Scene Description Prompt:
Muddy-walk entryway routine. Compose a doorway with boot brush, mat, shoe tray, and coats; a visitor cleans visible mud from tread grooves before placing boots in the tray. Please build this with Three.js from cdnjs in one self-contained HTML file, using stylized solid shapes.
Working Three.js Starter (muddy-walk-entryway-routine-x0619):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Muddy-Walk Entryway</title>
<style>
:root {
--ink: #18333a;
--muted: #617278;
--paper: rgba(250, 247, 239, 0.92);
--line: rgba(24, 51, 58, 0.13);
--green: #2d7568;
--orange: #d87943;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9cdb8;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
color: var(--ink);
}
.card {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px 18px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 20px;
background: var(--paper);
box-shadow:
0 18px 48px rgba(38, 43, 39, 0.16),
inset 0 1px rgba(255, 255, 255, 0.7);
backdrop-filter: blur(12px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 4px rgba(216, 121, 67, 0.13);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 34px);
line-height: 1.03;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.steps {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 17px;
}
.step {
min-height: 67px;
padding: 10px 8px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.38);
transition:
background 220ms ease,
border-color 220ms ease,
transform 220ms ease;
}
.step.active {
transform: translateY(-2px);
border-color: rgba(45, 117, 104, 0.36);
background: rgba(45, 117, 104, 0.1);
}
.step.done {
border-color: rgba(45, 117, 104, 0.2);
background: rgba(45, 117, 104, 0.06);
}
.step-number {
display: block;
margin-bottom: 6px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
}
.step-label {
display: block;
font-size: 11px;
font-weight: 750;
line-height: 1.2;
}
.status {
display: flex;
align-items: flex-start;
gap: 10px;
min-height: 44px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.status-dot {
flex: 0 0 auto;
width: 9px;
height: 9px;
margin-top: 4px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 5px rgba(216, 121, 67, 0.12);
}
#statusText {
margin: 0;
color: #40575d;
font-size: 12px;
line-height: 1.45;
}
.progress-track {
height: 4px;
margin-top: 14px;
overflow: hidden;
border-radius: 999px;
background: rgba(24, 51, 58, 0.1);
}
#progressBar {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--orange), var(--green));
transition: width 80ms linear;
}
.controls {
position: absolute;
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 12px;
transform: translateX(-50%);
padding: 9px 10px 9px 15px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 999px;
background: rgba(250, 247, 239, 0.9);
box-shadow: 0 12px 35px rgba(38, 43, 39, 0.14);
color: var(--muted);
font-size: 11px;
white-space: nowrap;
backdrop-filter: blur(10px);
}
.controls strong {
color: var(--ink);
font-weight: 750;
}
button {
pointer-events: auto;
border: 0;
border-radius: 999px;
padding: 9px 14px;
background: var(--ink);
color: #fffdf7;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #28545b;
}
button:active {
transform: translateY(0);
}
.legend {
position: absolute;
right: 24px;
top: 24px;
display: flex;
gap: 8px;
flex-wrap: wrap;
justify-content: flex-end;
max-width: 360px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 999px;
background: rgba(250, 247, 239, 0.82);
box-shadow: 0 8px 24px rgba(38, 43, 39, 0.1);
color: var(--muted);
font-size: 10px;
font-weight: 700;
backdrop-filter: blur(10px);
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
}
@media (max-width: 720px) {
.card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 16px;
}
.intro,
.legend {
display: none;
}
.steps {
margin-bottom: 12px;
}
.step {
min-height: 58px;
}
.controls {
bottom: 12px;
width: calc(100vw - 24px);
justify-content: center;
font-size: 10px;
}
}
</style>
</head>
<body>
<div class="ui">
<section class="card" aria-label="Entryway routine">
<div class="eyebrow">Home reset · entryway</div>
<h1>Muddy-walk routine</h1>
<p class="intro">
Brush the debris out of every tread groove before the boots go into the tray.
</p>
<div class="steps">
<div class="step active" id="step0">
<span class="step-number">01</span>
<span class="step-label">Brush the tread</span>
</div>
<div class="step" id="step1">
<span class="step-number">02</span>
<span class="step-label">Catch it on the mat</span>
</div>
<div class="step" id="step2">
<span class="step-number">03</span>
<span class="step-label">Use the shoe tray</span>
</div>
</div>
<div class="status">
<span class="status-dot"></span>
<p id="statusText">Cleaning the first boot.</p>
</div>
<div class="progress-track">
<div id="progressBar"></div>
</div>
</section>
<div class="legend" aria-hidden="true">
<div class="legend-item">
<span class="swatch" style="background:#53382a"></span>
Visible tread mud
</div>
<div class="legend-item">
<span class="swatch" style="background:#d87943"></span>
Entry mat
</div>
<div class="legend-item">
<span class="swatch" style="background:#2d7568"></span>
Shoe tray
</div>
</div>
<div class="controls">
<span><strong>Drag</strong> orbit</span>
<span>·</span>
<span><strong>Scroll</strong> zoom</span>
<span>·</span>
<button id="replay" type="button">Replay routine</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color("#d9cdb8");
scene.fog = new THREE.Fog("#d9cdb8", 13, 25);
const camera = new THREE.PerspectiveCamera(
37,
innerWidth / innerHeight,
0.1,
50
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.12;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight("#fff7df", "#7f8d86", 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff0d2", 3.1);
sun.position.set(5, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.00035;
scene.add(sun);
const doorwayLight = new THREE.PointLight("#ffd29a", 12, 5, 2);
doorwayLight.position.set(0.7, 2.2, -3.6);
scene.add(doorwayLight);
// -------------------------------------------------------------------------
// Geometry and material helpers
// -------------------------------------------------------------------------
const material = (color, roughness = 0.82, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const M = {
floor: material("#cbb99d"),
wall: material("#eee4d2"),
wallSide: material("#e2d5c1"),
trim: material("#faf3e7"),
dark: material("#26383a"),
interior: material("#344744"),
teal: material("#2d7568"),
tealDark: material("#1d554f"),
orange: material("#d87943"),
navy: material("#294256"),
mustard: material("#d5a742"),
rust: material("#a95035"),
blue: material("#50778b"),
skin: material("#d9a37e"),
hair: material("#3a302a"),
white: material("#f4eee2"),
wood: material("#93603d"),
woodLight: material("#b98253"),
sole: material("#6d4933"),
tread: material("#a77750"),
mud: material("#3d291f", 0.98),
brass: material("#b78b42", 0.35, 0.42),
bristles: material("#d7c49a")
};
function box(parent, w, h, d, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
rt,
rb,
h,
mat,
x = 0,
y = 0,
z = 0,
segments = 12
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(parent, radius, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 18, 12),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const Y_AXIS = new THREE.Vector3(0, 1, 0);
function setSegment(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
Y_AXIS,
direction.clone().normalize()
);
mesh.scale.set(1, length, 1);
}
function clamp(value, min = 0, max = 1) {
return Math.max(min, Math.min(max, value));
}
function smooth(value) {
const t = clamp(value);
return t * t * (3 - 2 * t);
}
function mix(a, b, t) {
return a + (b - a) * t;
}
// -------------------------------------------------------------------------
// Floor and doorway
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(18, 15),
M.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.set(0, 0, -1.3);
floor.receiveShadow = true;
scene.add(floor);
// A slightly inset entry area.
box(
scene,
10.8,
0.025,
7.2,
material("#d7c7ae"),
0,
0.012,
-1.45
);
const doorCenterX = 0.65;
const doorWidth = 2.4;
const doorHeight = 3.45;
const wallZ = -4.18;
const wallHeight = 5.1;
const leftEdge = -5.35;
const rightEdge = 5.35;
const doorLeft = doorCenterX - doorWidth / 2;
const doorRight = doorCenterX + doorWidth / 2;
box(
scene,
doorLeft - leftEdge,
wallHeight,
0.24,
M.wall,
(leftEdge + doorLeft) / 2,
wallHeight / 2,
wallZ
);
box(
scene,
rightEdge - doorRight,
wallHeight,
0.24,
M.wall,
(doorRight + rightEdge) / 2,
wallHeight / 2,
wallZ
);
box(
scene,
doorWidth,
wallHeight - doorHeight,
0.24,
M.wall,
doorCenterX,
doorHeight + (wallHeight - doorHeight) / 2,
wallZ
);
// Dark interior seen through the doorway.
box(
scene,
doorWidth,
doorHeight,
0.08,
M.interior,
doorCenterX,
doorHeight / 2,
wallZ - 0.2
);
box(scene, 0.15, wallHeight, 0.34, M.trim, doorLeft, wallHeight / 2, wallZ + 0.04);
box(scene, 0.15, wallHeight, 0.34, M.trim, doorRight, wallHeight / 2, wallZ + 0.04);
box(scene, doorWidth + 0.3, 0.16, 0.34, M.trim, doorCenterX, doorHeight, wallZ + 0.04);
box(scene, doorWidth + 0.15, 0.12, 0.18, M.trim, doorCenterX, 0.08, wallZ + 0.08);
// An open solid door on a hinge.
const doorPivot = new THREE.Group();
doorPivot.position.set(doorLeft + 0.05, 0, wallZ - 0.03);
doorPivot.rotation.y = -0.58;
scene.add(doorPivot);
box(doorPivot, 2.16, 3.28, 0.13, M.tealDark, 1.08, 1.64, 0);
box(doorPivot, 1.72, 1.02, 0.035, M.teal, 1.08, 2.05, 0.085);
box(doorPivot, 1.72, 1.22, 0.035, M.teal, 1.08, 0.85, 0.085);
sphere(doorPivot, 0.075, M.brass, 1.92, 1.45, 0.13);
// -------------------------------------------------------------------------
// Entry mat
// -------------------------------------------------------------------------
const matGroup = new THREE.Group();
matGroup.position.set(0.62, 0, -2.7);
scene.add(matGroup);
box(matGroup, 2.45, 0.075, 1.42, M.navy, 0, 0.04, 0);
box(matGroup, 2.2, 0.028, 1.17, M.dark, 0, 0.085, 0);
for (let i = 0; i < 8; i++) {
box(
matGroup,
2.06,
0.025,
0.035,
material("#3b4a4c"),
0,
0.108,
-0.48 + i * 0.138
);
}
// Muddy footprints remain visible on the mat.
const footprintData = [
[-0.62, -0.24, -0.28],
[-0.3, -0.12, 0.24],
[0.03, 0.28, -0.12],
[0.38, 0.18, 0.2],
[0.72, -0.27, 0.1]
];
footprintData.forEach(([x, z, rotation], i) => {
const foot = sphere(
matGroup,
1,
M.mud,
x,
0.126,
z
);
foot.scale.set(0.12 + (i % 2) * 0.025, 0.018, 0.23);
foot.rotation.y = rotation;
});
// Small brush parking block beside the mat.
box(scene, 0.9, 0.12, 0.62, M.wood, -1.27, 0.06, -2.18);
box(scene, 0.7, 0.07, 0.44, M.woodLight, -1.27, 0.145, -2.18);
// -------------------------------------------------------------------------
// Shoe tray
// -------------------------------------------------------------------------
const tray = new THREE.Group();
tray.position.set(2.35, 0, -1.15);
scene.add(tray);
box(tray, 1.9, 0.12, 1.42, M.teal, 0, 0.06, 0);
box(tray, 0.13, 0.32, 1.42, M.teal, -0.885, 0.19, 0);
box(tray, 0.13, 0.32, 1.42, M.teal, 0.885, 0.19, 0);
box(tray, 1.9, 0.32, 0.13, M.teal, 0, 0.19, -0.645);
box(tray, 1.9, 0.32, 0.13, M.teal, 0, 0.19, 0.645);
for (let i = 0; i < 8; i++) {
box(
tray,
0.055,
0.012,
0.68,
M.tealDark,
-0.63 + i * 0.18,
0.127,
0
);
}
// -------------------------------------------------------------------------
// Coat rack and solid-shape coats
// -------------------------------------------------------------------------
const rack = new THREE.Group();
rack.position.set(-3.0, 0, -3.65);
scene.add(rack);
cylinder(rack, 0.055, 0.07, 2.75, M.wood, 0, 1.38, 0);
box(rack, 1.72, 0.11, 0.12, M.wood, 0, 2.56, 0);
box(rack, 1.05, 0.1, 0.58, M.wood, 0, 0.06, 0);
const coatColors = [M.orange, M.navy, M.mustard, M.blue];
const coatGroups = [];
function createCoat(color, x, index) {
const coat = new THREE.Group();
coat.position.set(x, 0, 0);
rack.add(coat);
const body = new THREE.Mesh(
new THREE.CapsuleGeometry(0.27, 0.58, 4, 10),
color
);
body.position.set(0, 1.53, 0);
body.scale.set(1, 1, 0.58);
body.castShadow = true;
coat.add(body);
box(coat, 0.48, 0.1, 0.27, color, 0, 1.94, 0);
const leftSleeve = cylinder(
coat,
0.095,
0.12,
0.66,
color,
-0.29,
1.63,
0
);
leftSleeve.rotation.z = -0.25;
const rightSleeve = cylinder(
coat,
0.095,
0.12,
0.66,
color,
0.29,
1.63,
0
);
rightSleeve.rotation.z = 0.25;
box(coat, 0.23, 0.08, 0.08, M.wood, 0, 2.02, 0.05);
if (index === 1) {
box(coat, 0.12, 0.68, 0.09, M.orange, 0.04, 1.82, 0.18);
}
coatGroups.push(coat);
}
coatColors.forEach((color, i) => {
createCoat(color, -0.78 + i * 0.52, i);
});
// -------------------------------------------------------------------------
// Boot brush: the same brush used during the animation
// -------------------------------------------------------------------------
function createBrush() {
const brush = new THREE.Group();
scene.add(brush);
box(brush, 0.59, 0.09, 0.35, M.wood, 0, 0, 0);
box(brush, 0.51, 0.025, 0.29, M.woodLight, 0, 0.057, 0);
for (let x = -0.21; x <= 0.21; x += 0.105) {
for (let z = -0.105; z <= 0.105; z += 0.105) {
cylinder(
brush,
0.023,
0.028,
0.2,
M.bristles,
x,
0.125,
z,
8
);
}
}
cylinder(brush, 0.035, 0.042, 0.29, M.wood, 0, -0.18, 0);
box(brush, 0.12, 0.16, 0.085, M.dark, 0, -0.38, 0);
return brush;
}
const brush = createBrush();
// -------------------------------------------------------------------------
// Boots with visible mud caught in the underside tread
// -------------------------------------------------------------------------
function createBoot(upperMaterial, name) {
const boot = new THREE.Group();
boot.name = name;
scene.add(boot);
box(boot, 0.43, 0.12, 0.82, M.sole, 0, 0, 0);
box(boot, 0.37, 0.48, 0.38, upperMaterial, 0, 0.31, -0.18);
box(boot, 0.38, 0.27, 0.51, upperMaterial, 0, 0.2, 0.12);
const opening = cylinder(
boot,
0.145,
0.145,
0.022,
M.dark,
0,
0.558,
-0.18
);
opening.castShadow = false;
box(boot, 0.39, 0.08, 0.42, upperMaterial, 0, 0.035, -0.18);
// Raised tread pads form visible channels.
const rows = [-0.28, -0.14, 0, 0.14, 0.28];
rows.forEach((row) => {
[-0.105, 0.105].forEach((x) => {
box(
boot,
0.15,
0.05,
0.105,
M.tread,
x,
-0.083,
row
);
});
});
// Mud pieces sit down inside the tread channels.
const mudPieces = [];
rows.forEach((row) => {
[-0.105, 0.105].forEach((x) => {
const mud = sphere(
boot,
1,
M.mud,
x + (x < 0 ? -0.012 : 0.012),
-0.122,
row
);
const baseScale = new THREE.Vector3(
0.086 + Math.random() * 0.018,
0.031,
0.077 + Math.random() * 0.014
);
mud.scale.copy(baseScale);
mudPieces.push({ mesh: mud, row, baseScale });
});
});
boot.userData.mudPieces = mudPieces;
return boot;
}
const bootA = createBoot(M.rust, "Rust boot");
const bootB = createBoot(M.navy, "Navy boot");
function setMudRemaining(boot, remaining) {
boot.userData.mudPieces.forEach(({ mesh, baseScale }) => {
mesh.scale.copy(baseScale).multiplyScalar(Math.max(0.001, remaining));
mesh.visible = remaining > 0.005;
});
}
// -------------------------------------------------------------------------
// Visitor
// -------------------------------------------------------------------------
const visitor = new THREE.Group();
scene.add(visitor);
const torso = new THREE.Mesh(
new THREE.CapsuleGeometry(0.32, 0.55, 5, 14),
M.teal
);
torso.position.set(0, 1.25, 0);
torso.scale.set(1, 1, 0.82);
torso.castShadow = true;
visitor.add(torso);
box(visitor, 0.47, 0.22, 0.36, M.navy, 0, 0.78, 0);
cylinder(visitor, 0.09, 0.1, 0.16, M.skin, 0, 1.92, 0);
sphere(visitor, 0.255, M.skin, 0, 2.13, 0);
const hair = new THREE.Mesh(
new THREE.SphereGeometry(0.263, 18, 12, 0, Math.PI * 2, 0, 1.25),
M.hair
);
hair.position.set(0, 2.19, -0.015);
hair.castShadow = true;
visitor.add(hair);
sphere(visitor, 0.024, M.dark, -0.085, 2.15, 0.235);
sphere(visitor, 0.024, M.dark, 0.085, 2.15, 0.235);
sphere(visitor, 0.045, M.skin, 0, 2.07, 0.252);
const legs = [];
[-0.145, 0.145].forEach((x) => {
const leg = new THREE.Group();
leg.position.set(x, 0.79, 0);
visitor.add(leg);
cylinder(leg, 0.105, 0.12, 0.65, M.navy, 0, -0.32, 0);
box(leg, 0.22, 0.13, 0.38, M.dark, 0, -0.68, 0.08);
legs.push(leg);
});
function createArm() {
const upper = cylinder(scene, 0.095, 0.105, 1, M.teal);
const lower = cylinder(scene, 0.08, 0.09, 1, M.teal);
const hand = sphere(scene, 0.092, M.skin);
return { upper, lower, hand };
}
const leftArm = createArm();
const rightArm = createArm();
function poseArm(arm, shoulder, hand, outward) {
const delta = new THREE.Vector3().subVectors(hand, shoulder);
const elbow = shoulder
.clone()
.addScaledVector(delta, 0.48)
.addScaledVector(outward, 0.17)
.add(new THREE.Vector3(0, -0.12, 0));
setSegment(arm.upper, shoulder, elbow);
setSegment(arm.lower, elbow, hand);
arm.hand.position.copy(hand);
}
// -------------------------------------------------------------------------
// Mud crumbs that flick away while the brush works
// -------------------------------------------------------------------------
const crumbs = [];
for (let i = 0; i < 12; i++) {
const crumb = sphere(scene, 1, M.mud);
crumb.scale.setScalar(0.024);
crumb.visible = false;
crumbs.push(crumb);
}
function updateCrumbs(brushPosition, progress, active) {
crumbs.forEach((crumb, i) => {
if (!active) {
crumb.visible = false;
return;
}
const phase = (progress * 9 + i * 0.173) % 1;
crumb.visible = phase < 0.42;
if (!crumb.visible) return;
const angle = i * 2.399;
const radius = 0.035 + (i % 4) * 0.022;
crumb.position.set(
brushPosition.x + Math.cos(angle) * radius,
brushPosition.y + 0.04 + Math.sin(angle * 2) * 0.035,
brushPosition.z + Math.sin(angle) * radius
);
crumb.position.y -= phase * 0.22;
crumb.scale.setScalar(0.025 * (1 - phase * 0.65));
});
}
// -------------------------------------------------------------------------
// Routine animation
// -------------------------------------------------------------------------
const TOTAL_TIME = 7.8;
const cleanPosition = new THREE.Vector3(-0.5, 0.85, -1.85);
const floorPositionA = new THREE.Vector3(0.03, 0.12, -2.28);
const floorPositionB = new THREE.Vector3(0.72, 0.12, -2.25);
const trayPositionA = new THREE.Vector3(2.02, 0.23, -1.17);
const trayPositionB = new THREE.Vector3(2.69, 0.23, -1.16);
const brushParkPosition = new THREE.Vector3(-1.27, 0.32, -2.18);
let routineTime = 0;
let lastTime = performance.now();
const statusText = document.getElementById("statusText");
const progressBar = document.getElementById("progressBar");
const stepElements = [
document.getElementById("step0"),
document.getElementById("step1"),
document.getElementById("step2")
];
function setStatus(text) {
if (statusText.textContent !== text) {
statusText.textContent = text;
}
}
function setStepState(activeIndex, doneIndex) {
stepElements.forEach((element, i) => {
element.classList.toggle("active", i === activeIndex);
element.classList.toggle("done", i <= doneIndex);
});
}
function applyScrub(boot, progress, index) {
const p = clamp(progress);
const brushZ = mix(-0.36, 0.36, p);
const brushX = Math.sin(p * Math.PI * 8) * 0.13;
boot.position.copy(cleanPosition);
boot.position.y += Math.sin(p * Math.PI * 12) * 0.012;
boot.rotation.set(-1.06, 0, index === 0 ? -0.07 : 0.07);
boot.updateMatrixWorld(true);
// Remove each mud piece as the brush passes its tread channel.
boot.userData.mudPieces.forEach(({ mesh, row }) => {
const removal = clamp((brushZ - row + 0.03) / 0.1);
const remaining = 1 - removal;
mesh.scale.copy(
boot.userData.mudPieces.find((piece) => piece.mesh === mesh).baseScale
).multiplyScalar(Math.max(0.001, remaining));
mesh.visible = remaining > 0.005;
});
const contact = boot.localToWorld(
new THREE.Vector3(brushX, -0.32, brushZ)
);
brush.position.copy(contact);
brush.quaternion.copy(boot.quaternion);
brush.updateMatrixWorld(true);
return {
contact,
brushZ,
leftHand: boot.localToWorld(new THREE.Vector3(0, 0.4, -0.12)),
rightHand: brush.localToWorld(new THREE.Vector3(0, -0.38, 0))
};
}
function idleBrush(boot, side = -1) {
boot.updateMatrixWorld(true);
brush.position.copy(
boot.localToWorld(new THREE.Vector3(side * 0.28, -0.3, 0))
);
brush.quaternion.copy(boot.quaternion);
brush.updateMatrixWorld(true);
return {
leftHand: boot.localToWorld(new THREE.Vector3(0, 0.4, -0.12)),
rightHand: brush.localToWorld(new THREE.Vector3(0, -0.38, 0))
};
}
function applyRoutine(t) {
let leftHand = new THREE.Vector3();
let rightHand = new THREE.Vector3();
let scrubActive = false;
let scrubContact = new THREE.Vector3();
let scrubProgress = 0;
let moving = false;
visitor.position.set(-1.28, 0, -1.36);
visitor.rotation.y = 0.08;
legs.forEach((leg) => (leg.rotation.x = 0));
// 1. Clean the first boot.
if (t < 2.0) {
const p = t / 2.0;
const hands = applyScrub(bootA, p, 0);
leftHand = hands.leftHand;
rightHand = hands.rightHand;
scrubActive = true;
scrubContact = hands.contact;
scrubProgress = p;
bootB.position.copy(floorPositionB);
bootB.rotation.set(0, 0.12, 0);
setStatus("Boot 1 of 2: work the brush across every muddy tread groove.");
setStepState(0, -1);
}
// 2. Lower the clean first boot onto the mat.
else if (t < 2.25) {
const p = smooth((t - 2.0) / 0.25);
bootA.position.lerpVectors(cleanPosition, floorPositionA, p);
bootA.position.y += Math.sin(p * Math.PI) * 0.12;
bootA.rotation.set(
mix(-1.06, 0, p),
mix(0, -0.08, p),
mix(-0.07, 0.02, p)
);
bootB.position.copy(floorPositionB);
bootB.rotation.set(0, 0.12, 0);
const hands = idleBrush(bootA);
leftHand = hands.leftHand;
rightHand = hands.rightHand;
setStatus("Boot 1 is clean. Rest it on the mat while the second boot is checked.");
setStepState(1, 0);
}
// 3. Raise the second boot.
else if (t < 2.5) {
const p = smooth((t - 2.25) / 0.25);
bootA.position.copy(floorPositionA);
bootA.rotation.set(0, -0.08, 0.02);
bootB.position.lerpVectors(floorPositionB, cleanPosition, p);
bootB.position.y += Math.sin(p * Math.PI) * 0.15;
bootB.rotation.set(
mix(0, -1.06, p),
mix(0.12, 0, p),
mix(0, 0.07, p)
);
const hands = idleBrush(bootB);
leftHand = hands.leftHand;
rightHand = hands.rightHand;
setStatus("Boot 2 of 2: lift it and turn the muddy tread toward the brush.");
setStepState(0, 0);
}
// 4. Clean the second boot.
else if (t < 4.4) {
const p = (t - 2.5) / 1.9;
const hands = applyScrub(bootB, p, 1);
leftHand = hands.leftHand;
rightHand = hands.rightHand;
scrubActive = true;
scrubContact = hands.contact;
scrubProgress = p;
bootA.position.copy(floorPositionA);
bootA.rotation.set(0, -0.08, 0.02);
setStatus("Boot 2 of 2: the remaining clumps are lifting out of the tread channels.");
setStepState(0, 0);
}
// 5. Place the first clean boot in the shoe tray.
else if (t < 5.4) {
const p = smooth((t - 4.4) / 1.0);
moving = true;
visitor.position.set(
mix(-1.28, -0.03, p),
0,
mix(-1.36, -1.62, p)
);
visitor.rotation.y = mix(0.08, 0.25, p);
bootA.position.lerpVectors(floorPositionA, trayPositionA, p);
bootA.position.y += Math.sin(p * Math.PI) * 0.68;
bootA.rotation.set(
0,
mix(-0.08, -0.1, p),
mix(0.02, -0.075, p)
);
bootB.position.copy(cleanPosition);
bootB.rotation.set(-1.06, 0, 0.07);
const hands = idleBrush(bootA, 0.2);
leftHand = hands.leftHand;
rightHand = hands.rightHand;
setStatus("Both treads are clean. Place the first boot into the shoe tray.");
setStepState(2, 1);
}
// 6. Lift the second clean boot.
else if (t < 5.7) {
const p = smooth((t - 5.4) / 0.3);
moving = true;
visitor.position.set(
mix(-0.03, -0.28, p),
0,
mix(-1.62, -1.5, p)
);
visitor.rotation.y = mix(0.25, 0.12, p);
const carryPosition = new THREE.Vector3(-0.02, 0.76, -1.62);
bootB.position.lerpVectors(cleanPosition, carryPosition, p);
bootB.rotation.set(
mix(-1.06, 0, p),
0,
mix(0.07, -0.05, p)
);
bootA.position.copy(trayPositionA);
bootA.rotation.set(0, -0.1, -0.075);
const hands = idleBrush(bootB);
leftHand = hands.leftHand;
rightHand = hands.rightHand;
setStatus("The second clean boot is ready for the tray.");
setStepState(2, 1);
}
// 7. Place the second clean boot in the tray.
else if (t < 6.7) {
const p = smooth((t - 5.7) / 1.0);
moving = true;
visitor.position.set(
mix(-0.28, 0.83, p),
0,
mix(-1.5, -0.98, p)
);
visitor.rotation.y = mix(0.12, 0.24, p);
const carryPosition = new THREE.Vector3(-0.02, 0.76, -1.62);
bootB.position.lerpVectors(carryPosition, trayPositionB, p);
bootB.position.y += Math.sin(p * Math.PI) * 0.7;
bootB.rotation.set(
0,
mix(0, 0.1, p),
mix(-0.05, 0.075, p)
);
bootA.position.copy(trayPositionA);
bootA.rotation.set(0, -0.1, -0.075);
const hands = idleBrush(bootB, 0.18);
leftHand = hands.leftHand;
rightHand = hands.rightHand;
setStatus("Place the second boot beside its partner, soles down in the tray.");
setStepState(2, 1);
}
// 8. Put the brush back and step away.
else {
const p = smooth((t - 6.7) / 1.1);
moving = p < 0.8;
visitor.position.set(
mix(0.83, -0.28, p),
0,
mix(-0.98, -1.3, p)
);
visitor.rotation.y = mix(0.24, 0.04, p);
bootA.position.copy(trayPositionA);
bootA.rotation.set(0, -0.1, -0.075);
bootB.position.copy(trayPositionB);
bootB.rotation.set(0, 0.1, 0.075);
brush.position.lerpVectors(
new THREE.Vector3(0.43, 1.05, -0.55),
brushParkPosition,
p
);
brush.position.y += Math.sin(p * Math.PI) * 0.28;
const parkQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(Math.PI, 0, 0)
);
brush.quaternion.slerp(parkQuaternion, p);
brush.updateMatrixWorld(true);
leftHand.copy(visitor.position).add(new THREE.Vector3(-0.32, 0.88, 0.18));
if (p < 0.42) {
rightHand.copy(brush.localToWorld(new THREE.Vector3(0, -0.38, 0)));
} else {
rightHand.copy(visitor.position).add(new THREE.Vector3(0.32, 0.88, 0.18));
}
setStatus("Entryway reset: clean boots in the tray, brush parked, coats ready.");
setStepState(2, 2);
}
// Subtle walking motion.
if (moving) {
const stride = Math.sin(t * 12) * 0.24;
legs[0].rotation.x = stride;
legs[1].rotation.x = -stride;
visitor.position.y += Math.abs(Math.sin(t * 12)) * 0.018;
}
const leftShoulder = visitor.position
.clone()
.add(new THREE.Vector3(-0.34, 1.57, 0));
const rightShoulder = visitor.position
.clone()
.add(new THREE.Vector3(0.34, 1.57, 0));
poseArm(
leftArm,
leftShoulder,
leftHand,
new THREE.Vector3(-0.6, 0, 0.15)
);
poseArm(
rightArm,
rightShoulder,
rightHand,
new THREE.Vector3(0.6, 0, 0.15)
);
updateCrumbs(scrubContact, scrubProgress, scrubActive);
progressBar.style.width = `${clamp(t / TOTAL_TIME) * 100}%`;
}
// -------------------------------------------------------------------------
// Direct camera controls: no external control addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0.05, 1.2, -1.35);
let cameraTheta = 0.42;
let cameraPhi = 1.1;
let cameraRadius = 9.1;
let dragging = false;
let dragX = 0;
let dragY = 0;
let activePointer = null;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointer = event.pointerId;
dragX = event.clientX;
dragY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
dragX = event.clientX;
dragY = event.clientY;
cameraTheta -= dx * 0.006;
cameraPhi = clamp(cameraPhi - dy * 0.005, 0.68, 1.43);
});
function endDrag(event) {
if (event.pointerId !== activePointer) return;
dragging = false;
activePointer = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = clamp(
cameraRadius + event.deltaY * 0.0055,
5.5,
13.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraTheta = 0.42;
cameraPhi = 1.1;
cameraRadius = 9.1;
});
addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraTheta -= 0.1;
if (event.key === "ArrowRight") cameraTheta += 0.1;
if (event.key === "ArrowUp") cameraPhi = clamp(cameraPhi - 0.08, 0.68, 1.43);
if (event.key === "ArrowDown") cameraPhi = clamp(cameraPhi + 0.08, 0.68, 1.43);
});
document.getElementById("replay").addEventListener("click", () => {
routineTime = 0;
setMudRemaining(bootA, 1);
setMudRemaining(bootB, 1);
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
function animate(now) {
const dt = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
routineTime = Math.min(routineTime + dt, TOTAL_TIME);
applyRoutine(routineTime);
coatGroups.forEach((coat, i) => {
coat.rotation.z = Math.sin(now * 0.0007 + i) * 0.008;
});
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
applyRoutine(0);
updateCamera();
requestAnimationFrame(animate);
</script>
</body>
</html>
```