Prompt specification
Build or customize the Three.js 3D scene "Laundry Machine Batch Loading" 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: Laundry Machine Batch Loading
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/laundry-machine-batch-loading-x3194
Scene Description Prompt:
Load laundry baskets into a machine cutaway within its marked capacity; compare required cycles with a fixed timer. Standalone HTML using Three.js from cdnjs.
Working Three.js Starter (laundry-machine-batch-loading-x3194):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laundry Load Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #071119;
--panel: #0c1821;
--panel-2: #12242e;
--line: rgba(180, 220, 230, 0.14);
--text: #edf7f8;
--muted: #89a4ad;
--cyan: #58d9e7;
--green: #a7ed72;
--orange: #ffb45c;
--red: #ff7474;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
border: 0;
}
#app {
display: grid;
grid-template-columns: 360px minmax(0, 1fr);
width: 100%;
height: 100%;
}
.panel {
position: relative;
z-index: 5;
overflow-y: auto;
padding: 26px 24px;
background:
linear-gradient(160deg, rgba(22, 48, 61, 0.72), transparent 42%),
var(--panel);
border-right: 1px solid var(--line);
box-shadow: 18px 0 50px rgba(0, 0, 0, 0.25);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
background: var(--cyan);
content: "";
box-shadow: 0 0 12px var(--cyan);
}
h1 {
margin: 14px 0 8px;
font-size: 38px;
line-height: 0.98;
letter-spacing: -0.055em;
}
.intro {
margin: 0 0 22px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.card {
margin-top: 14px;
padding: 16px;
background: rgba(255, 255, 255, 0.035);
border: 1px solid var(--line);
border-radius: 16px;
}
.card-title,
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
color: #c9dde1;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.capacity-number {
color: var(--text);
font-size: 25px;
font-weight: 800;
letter-spacing: -0.04em;
}
.capacity-number small {
color: var(--muted);
font-size: 12px;
font-weight: 600;
letter-spacing: 0;
}
.segments {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin: 13px 0 9px;
}
.segment {
height: 9px;
overflow: hidden;
background: rgba(255, 255, 255, 0.07);
border-radius: 999px;
}
.segment::after {
display: block;
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--cyan), var(--green));
border-radius: inherit;
box-shadow: 0 0 12px rgba(88, 217, 231, 0.5);
content: "";
transition: width 350ms ease;
}
.segment.on::after {
width: 100%;
}
.subtle {
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.basket-rack {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 7px;
}
.basket-chip {
position: relative;
aspect-ratio: 1;
padding: 0;
color: var(--muted);
background: rgba(255, 255, 255, 0.045);
border: 1px solid var(--line);
border-radius: 10px;
cursor: pointer;
font-size: 11px;
font-weight: 800;
transition: 180ms ease;
}
.basket-chip:hover:not(:disabled) {
color: var(--text);
border-color: rgba(88, 217, 231, 0.65);
transform: translateY(-2px);
}
.basket-chip.staged {
color: #d8b888;
background: rgba(255, 180, 92, 0.08);
}
.basket-chip.loading,
.basket-chip.loaded {
color: var(--cyan);
background: rgba(88, 217, 231, 0.13);
border-color: rgba(88, 217, 231, 0.5);
}
.basket-chip.clean {
color: var(--green);
background: rgba(167, 237, 114, 0.13);
border-color: rgba(167, 237, 114, 0.5);
}
.basket-chip.done {
color: #68818a;
background: rgba(255, 255, 255, 0.025);
}
.basket-chip:disabled {
cursor: default;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 12px;
}
.button {
min-height: 42px;
padding: 10px 12px;
color: var(--text);
background: #18303b;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 11px;
cursor: pointer;
font-size: 12px;
font-weight: 800;
transition: 180ms ease;
}
.button:hover:not(:disabled) {
background: #224252;
transform: translateY(-1px);
}
.button.primary {
color: #062027;
background: linear-gradient(135deg, var(--cyan), #8be6dc);
box-shadow: 0 8px 22px rgba(88, 217, 231, 0.16);
}
.button.primary:hover:not(:disabled) {
background: linear-gradient(135deg, #76e4ee, #a3f0df);
}
.button.ghost {
color: var(--muted);
background: transparent;
}
.button:disabled {
opacity: 0.34;
cursor: not-allowed;
}
.wide {
width: 100%;
}
.comparison-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.metric {
min-height: 76px;
padding: 11px;
background: rgba(0, 0, 0, 0.15);
border: 1px solid rgba(255, 255, 255, 0.055);
border-radius: 11px;
}
.metric-label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-size: 23px;
font-weight: 800;
letter-spacing: -0.045em;
}
.metric-value small {
color: var(--muted);
font-size: 11px;
letter-spacing: 0;
}
.result {
margin-top: 10px;
padding: 11px 12px;
color: #ffc989;
background: rgba(255, 180, 92, 0.08);
border: 1px solid rgba(255, 180, 92, 0.22);
border-radius: 11px;
font-size: 11px;
line-height: 1.5;
}
.result.good {
color: #c7f5a4;
background: rgba(167, 237, 114, 0.08);
border-color: rgba(167, 237, 114, 0.22);
}
.range-label {
display: flex;
justify-content: space-between;
margin-bottom: 9px;
color: var(--muted);
font-size: 11px;
}
.range-label strong {
color: var(--text);
}
input[type="range"] {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
.range-scale {
display: flex;
justify-content: space-between;
margin-top: 4px;
color: #58717a;
font-size: 9px;
}
.progress-track {
height: 6px;
margin: 12px 0 9px;
overflow: hidden;
background: rgba(255, 255, 255, 0.07);
border-radius: 999px;
}
.progress-fill {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--cyan), var(--green));
border-radius: inherit;
box-shadow: 0 0 12px rgba(88, 217, 231, 0.5);
}
.run-status {
min-height: 17px;
color: var(--muted);
font-size: 10px;
text-align: center;
}
.stats-line {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 12px;
padding-top: 12px;
color: var(--muted);
border-top: 1px solid var(--line);
font-size: 10px;
}
.stats-line strong {
color: var(--text);
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 70% 18%, rgba(37, 90, 105, 0.24), transparent 35%),
#071119;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.scene-heading {
position: absolute;
z-index: 2;
top: 28px;
left: 30px;
pointer-events: none;
}
.scene-heading h2 {
margin: 7px 0 0;
font-size: clamp(22px, 3vw, 38px);
letter-spacing: -0.045em;
}
.scene-heading p {
margin: 6px 0 0;
color: var(--muted);
font-size: 12px;
}
.capacity-pill {
position: absolute;
z-index: 2;
top: 30px;
right: 30px;
padding: 10px 13px;
color: var(--green);
background: rgba(10, 27, 34, 0.74);
border: 1px solid rgba(167, 237, 114, 0.24);
border-radius: 999px;
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
pointer-events: none;
}
.scene-help {
position: absolute;
z-index: 2;
bottom: 24px;
left: 50%;
padding: 10px 15px;
color: #a7bec4;
background: rgba(5, 14, 19, 0.72);
border: 1px solid var(--line);
border-radius: 999px;
backdrop-filter: blur(12px);
font-size: 10px;
letter-spacing: 0.04em;
transform: translateX(-50%);
pointer-events: none;
white-space: nowrap;
}
.legend {
position: absolute;
z-index: 2;
right: 28px;
bottom: 24px;
display: grid;
gap: 7px;
color: var(--muted);
font-size: 9px;
pointer-events: none;
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
}
.dot {
width: 7px;
height: 7px;
background: var(--cyan);
border-radius: 50%;
box-shadow: 0 0 9px currentColor;
}
.dot.green {
background: var(--green);
}
.dot.orange {
background: var(--orange);
}
@media (max-width: 820px) {
html,
body {
height: auto;
min-height: 100%;
overflow: auto;
}
#app {
grid-template-columns: 1fr;
height: auto;
}
.panel {
max-height: none;
border-right: 0;
border-bottom: 1px solid var(--line);
}
#viewport {
height: 68vh;
min-height: 520px;
}
.scene-heading {
top: 20px;
left: 20px;
}
.capacity-pill {
top: 20px;
right: 20px;
}
.legend {
display: none;
}
.scene-help {
bottom: 16px;
}
}
</style>
</head>
<body>
<div id="app">
<aside class="panel">
<div class="eyebrow">Laundry load lab</div>
<h1>Pack it.<br>Plan it.</h1>
<p class="intro">
Load baskets into the cutaway without exceeding the marked capacity.
Compare the remaining workload with a fixed timer.
</p>
<section class="card">
<div class="card-title">
<span>Machine capacity</span>
<span class="capacity-number">
<span id="basketCount">0</span><small> / 3 baskets</small>
</span>
</div>
<div class="segments" aria-hidden="true">
<div class="segment" id="segment0"></div>
<div class="segment" id="segment1"></div>
<div class="segment" id="segment2"></div>
</div>
<div class="subtle">
<span id="weightCount">0 kg</span> loaded ·
<span id="capacityState">Capacity available</span>
</div>
</section>
<section class="card">
<div class="section-title">
<span>Six-basket workload</span>
<span id="pendingCount">6 pending</span>
</div>
<div class="basket-rack" id="basketRack"></div>
<div class="button-row">
<button class="button" id="loadButton" type="button">Load basket</button>
<button class="button" id="unloadButton" type="button">Unload basket</button>
</div>
<div class="button-row">
<button class="button ghost" id="fillButton" type="button">
Fill to capacity
</button>
<button class="button ghost" id="emptyButton" type="button">
Empty machine
</button>
</div>
</section>
<section class="card">
<div class="section-title">
<span>Cycle comparison</span>
<span id="cycleCount">0 cycles run</span>
</div>
<div class="comparison-grid">
<div class="metric">
<span class="metric-label">Required cycles</span>
<span class="metric-value" id="requiredCycles">2</span>
</div>
<div class="metric">
<span class="metric-label">Needed time</span>
<span class="metric-value" id="neededTime">116<small> min</small></span>
</div>
<div class="metric">
<span class="metric-label">Fixed schedule</span>
<span class="metric-value" id="fixedTotal">90<small> min</small></span>
</div>
<div class="metric">
<span class="metric-label">Current batch</span>
<span class="metric-value" id="currentBatch">—</span>
</div>
</div>
<div class="result" id="comparisonResult">
The fixed schedule needs 26 more minutes.
</div>
</section>
<section class="card">
<div class="section-title">
<span>Fixed timer per cycle</span>
<strong id="timerValue">45 min</strong>
</div>
<div class="range-label">
<span>Timer duration</span>
<span>20–80 minutes</span>
</div>
<input
id="timerSlider"
type="range"
min="20"
max="80"
step="5"
value="45"
aria-label="Fixed timer duration"
>
<div class="range-scale">
<span>20 min</span>
<span>45 min</span>
<span>80 min</span>
</div>
<div class="button-row">
<button class="button primary wide" id="runButton" type="button">
Run cycle
</button>
</div>
<div class="progress-track">
<div class="progress-fill" id="progressFill"></div>
</div>
<div class="run-status" id="runStatus">
Load at least one basket to begin.
</div>
</section>
<div class="stats-line">
<span>Cycle model: <strong>28 / 42 / 58 min</strong></span>
<button class="button ghost" id="resetButton" type="button">Reset</button>
</div>
</aside>
<main id="viewport" aria-label="Interactive 3D washing machine cutaway">
<div class="scene-heading">
<div class="eyebrow">Interactive cutaway</div>
<h2>Front-load studio</h2>
<p>Click a staged basket to load it. Click a loaded basket to unload.</p>
</div>
<div class="capacity-pill" id="capacityPill">0 / 3 capacity used</div>
<div class="scene-help">
Drag background to orbit · Scroll to zoom · Double-click to reset view
</div>
<div class="legend">
<span><i class="dot"></i> Staged / loading</span>
<span><i class="dot green"></i> Clean</span>
<span><i class="dot orange"></i> Capacity limit</span>
</div>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const TOTAL_BASKETS = 6;
const CAPACITY = 3;
const KG_PER_BASKET = 7;
const durationByLoad = {
1: 28,
2: 42,
3: 58
};
const state = {
baskets: [],
fixedMinutes: 45,
completedCycles: 0,
running: false,
progress: 0,
currentCycleMinutes: 0,
cycleNumber: 0
};
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071119);
scene.fog = new THREE.Fog(0x071119, 13, 24);
const camera = new THREE.PerspectiveCamera(
42,
viewport.clientWidth / viewport.clientHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xbfefff, 0x14202a, 2.1);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xdff8ff, 4.2);
key.position.set(3.5, 7.5, 6);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -8;
key.shadow.camera.right = 8;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -8;
key.shadow.normalBias = 0.025;
scene.add(key);
const rim = new THREE.DirectionalLight(0x47d7e9, 2.6);
rim.position.set(-5, 4, -4);
scene.add(rim);
const warm = new THREE.PointLight(0xffb45c, 18, 10, 2);
warm.position.set(4, 3, 2);
scene.add(warm);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x09161d,
roughness: 0.87,
metalness: 0.08
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.03;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x1c3c47, 0x102832);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
// ------------------------------------------------------------
// Shared materials
// ------------------------------------------------------------
const materials = {
cabinet: new THREE.MeshStandardMaterial({
color: 0x24343d,
roughness: 0.42,
metalness: 0.68
}),
cabinetLight: new THREE.MeshStandardMaterial({
color: 0xc8d5d8,
roughness: 0.3,
metalness: 0.52
}),
cabinetDark: new THREE.MeshStandardMaterial({
color: 0x111c23,
roughness: 0.5,
metalness: 0.6
}),
cutaway: new THREE.MeshPhysicalMaterial({
color: 0x91e5ed,
roughness: 0.18,
metalness: 0.05,
transparent: true,
opacity: 0.11,
depthWrite: false,
side: THREE.DoubleSide
}),
drum: new THREE.MeshStandardMaterial({
color: 0x71818a,
roughness: 0.32,
metalness: 0.88,
transparent: true,
opacity: 0.48,
side: THREE.DoubleSide,
depthWrite: false
}),
rim: new THREE.MeshStandardMaterial({
color: 0xa9bac0,
roughness: 0.23,
metalness: 0.92
}),
dark: new THREE.MeshStandardMaterial({
color: 0x0c151b,
roughness: 0.6,
metalness: 0.5
}),
black: new THREE.MeshBasicMaterial({
color: 0x081014
}),
capacity: new THREE.MeshBasicMaterial({
color: 0xa7ed72,
transparent: true,
opacity: 0.9
}),
basket: new THREE.MeshStandardMaterial({
color: 0xb98b59,
roughness: 0.72,
metalness: 0.02
}),
basketDark: new THREE.MeshStandardMaterial({
color: 0x765534,
roughness: 0.78
})
};
function addBox(
width,
height,
depth,
material,
x,
y,
z,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, opacity = 0.18) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color: 0xbcecf0,
transparent: true,
opacity
})
);
edges.position.copy(mesh.position);
edges.rotation.copy(mesh.rotation);
edges.scale.copy(mesh.scale);
mesh.parent.add(edges);
return edges;
}
function makeLabel(text, options = {}) {
const {
width = 768,
height = 150,
background = "rgba(7,19,26,0.88)",
color = "#eaf9fa",
accent = "#58d9e7",
fontSize = 46
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
const radius = 24;
const x = 4;
const y = 4;
const w = width - 8;
const h = height - 8;
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + w - radius, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + radius);
ctx.lineTo(x + w, y + h - radius);
ctx.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);
ctx.lineTo(x + radius, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(24, 30, 8, height - 60);
ctx.fillStyle = color;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2 + 7, height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.needsUpdate = true;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
})
);
sprite.scale.set(3.15, 3.15 * height / width, 1);
sprite.renderOrder = 20;
return sprite;
}
// ------------------------------------------------------------
// Washing-machine cutaway
// ------------------------------------------------------------
const machine = new THREE.Group();
machine.position.set(-1.25, 0, 0);
scene.add(machine);
const base = addBox(
4.65, 0.25, 3.15,
materials.cabinetDark,
0, 0.22, 0,
machine
);
addEdges(base);
const top = addBox(
4.65, 0.2, 3.15,
materials.cabinetLight,
0, 3.18, 0,
machine
);
addEdges(top, 0.12);
const leftWall = addBox(
0.18, 2.85, 3.0,
materials.cabinet,
-2.24, 1.68, -0.02,
machine
);
addEdges(leftWall, 0.12);
const rightWall = addBox(
0.12, 2.85, 3.0,
materials.cutaway,
2.24, 1.68, -0.02,
machine,
false
);
const backWall = addBox(
4.4, 2.85, 0.13,
materials.cabinetDark,
0, 1.68, -1.48,
machine
);
addEdges(backWall, 0.1);
// Front frame leaves the drum opening exposed.
addBox(0.86, 3.0, 0.18, materials.cabinet, -1.78, 1.67, 1.48, machine);
addBox(0.86, 3.0, 0.18, materials.cabinet, 1.78, 1.67, 1.48, machine);
addBox(2.72, 0.72, 0.18, materials.cabinet, 0, 2.75, 1.48, machine);
addBox(2.72, 0.67, 0.18, materials.cabinet, 0, 0.54, 1.48, machine);
// Control fascia.
addBox(
1.34, 0.39, 0.1,
materials.cabinetDark,
1.28, 2.75, 1.61,
machine
);
const displayLabel = makeLabel("CUTAWAY • READY", {
width: 640,
height: 112,
background: "rgba(5,14,19,0.95)",
color: "#91e6ed",
accent: "#58d9e7",
fontSize: 39
});
displayLabel.scale.set(1.13, 1.13 * 112 / 640, 1);
displayLabel.position.set(1.27, 2.76, 1.69);
machine.add(displayLabel);
const knob = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.14, 0.08, 32),
materials.rim
);
knob.rotation.x = Math.PI / 2;
knob.position.set(0.4, 2.75, 1.63);
machine.add(knob);
// Feet.
for (const x of [-1.85, 1.85]) {
for (const z of [-1.05, 1.05]) {
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.16, 0.18, 20),
materials.dark
);
foot.position.set(x, 0.06, z);
foot.castShadow = true;
machine.add(foot);
}
}
const drum = new THREE.Group();
drum.position.set(0, 1.58, -0.03);
machine.add(drum);
const shell = new THREE.Mesh(
new THREE.CylinderGeometry(1.23, 1.23, 1.9, 64, 1, true),
materials.drum
);
shell.rotation.x = Math.PI / 2;
shell.renderOrder = 1;
drum.add(shell);
const backDisk = new THREE.Mesh(
new THREE.CircleGeometry(1.21, 64),
new THREE.MeshStandardMaterial({
color: 0x34444d,
roughness: 0.5,
metalness: 0.72,
side: THREE.DoubleSide
})
);
backDisk.position.z = -0.94;
backDisk.receiveShadow = true;
drum.add(backDisk);
const rearRing = new THREE.Mesh(
new THREE.TorusGeometry(1.2, 0.065, 12, 64),
materials.rim
);
rearRing.position.z = -0.9;
drum.add(rearRing);
const frontRing = new THREE.Mesh(
new THREE.TorusGeometry(1.23, 0.095, 16, 80),
materials.rim
);
frontRing.position.z = 0.93;
frontRing.castShadow = true;
drum.add(frontRing);
// Three internal lifting paddles.
for (let i = 0; i < 3; i++) {
const angle = (i / 3) * Math.PI * 2;
const paddle = addBox(
0.16, 0.16, 1.48,
materials.rim,
Math.cos(angle) * 0.98,
Math.sin(angle) * 0.98,
0,
drum
);
paddle.rotation.z = angle + Math.PI / 2;
}
// Perforation pattern near the drum mouth.
const perforationGeometry = new THREE.CircleGeometry(0.033, 12);
for (let ring = 0; ring < 2; ring++) {
const radius = ring === 0 ? 1.06 : 0.78;
const count = ring === 0 ? 32 : 22;
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2 + ring * 0.06;
const dot = new THREE.Mesh(perforationGeometry, materials.black);
dot.position.set(
Math.cos(angle) * radius,
Math.sin(angle) * radius,
0.941
);
drum.add(dot);
}
}
// Green machine-limit ring.
const capacityRing = new THREE.Mesh(
new THREE.TorusGeometry(1.42, 0.026, 8, 100),
materials.capacity
);
capacityRing.position.set(0, 1.58, 1.48);
machine.add(capacityRing);
const capacityLabel = makeLabel("MAX CAPACITY • 21 KG / 3 BASKETS", {
width: 900,
height: 125,
background: "rgba(7,19,26,0.92)",
color: "#e9f7ec",
accent: "#a7ed72",
fontSize: 38
});
capacityLabel.position.set(0, 3.62, 1.47);
machine.add(capacityLabel);
// Small translucent bubbles, visible during the wash cycle.
const bubbles = [];
for (let i = 0; i < 18; i++) {
const bubble = new THREE.Mesh(
new THREE.SphereGeometry(0.025 + (i % 3) * 0.009, 10, 8),
new THREE.MeshPhysicalMaterial({
color: 0xdffbff,
roughness: 0,
transparent: true,
opacity: 0.42,
depthWrite: false
})
);
const angle = i * 2.399;
const radius = 0.3 + (i % 5) * 0.15;
bubble.position.set(
Math.cos(angle) * radius,
0.35 + (i % 6) * 0.18,
Math.sin(angle) * radius
);
bubble.userData.seed = i;
drum.add(bubble);
bubbles.push(bubble);
}
// ------------------------------------------------------------
// Staging area
// ------------------------------------------------------------
const stageMaterial = new THREE.MeshStandardMaterial({
color: 0x122a34,
roughness: 0.62,
metalness: 0.45
});
addBox(
3.25, 0.12, 0.82,
stageMaterial,
3.48, 0.13, 0.52,
scene
);
addBox(
3.25, 0.12, 0.82,
stageMaterial,
3.48, 0.13, -0.53,
scene
);
const stageLabel = makeLabel("STAGING • 6 BASKETS", {
width: 700,
height: 120,
background: "rgba(7,19,26,0.88)",
color: "#ffd49f",
accent: "#ffb45c",
fontSize: 42
});
stageLabel.scale.set(2.35, 2.35 * 120 / 700, 1);
stageLabel.position.set(3.48, 2.12, 0.08);
scene.add(stageLabel);
// ------------------------------------------------------------
// Basket construction
// ------------------------------------------------------------
const loadedSlots = [
new THREE.Vector3(-0.61, 0.58, 0.24),
new THREE.Vector3(0.0, 0.4, -0.23),
new THREE.Vector3(0.61, 0.58, 0.24)
];
const laundryColors = [
0xf07171,
0x5bc7db,
0xf2c45e,
0x9579db,
0x73d99a,
0xe99bc3
];
function createBasket(index) {
const group = new THREE.Group();
group.userData.basketId = index;
const width = 0.84;
const depth = 0.68;
const height = 0.56;
addBox(
width, 0.09, depth,
materials.basketDark,
0, 0.055, 0,
group
);
// Rim.
addBox(width, 0.075, 0.075, materials.basket, 0, height, depth / 2, group);
addBox(width, 0.075, 0.075, materials.basket, 0, height, -depth / 2, group);
addBox(0.075, 0.075, depth, materials.basket, width / 2, height, 0, group);
addBox(0.075, 0.075, depth, materials.basket, -width / 2, height, 0, group);
// Corner posts.
for (const x of [-width / 2, width / 2]) {
for (const z of [-depth / 2, depth / 2]) {
addBox(
0.065, height, 0.065,
materials.basketDark,
x, height / 2, z,
group
);
}
}
// Front and back horizontal slats.
for (const z of [-depth / 2, depth / 2]) {
for (const y of [0.16, 0.31, 0.46]) {
addBox(
width, 0.055, 0.055,
materials.basket,
0, y, z,
group
);
}
}
// End slats.
for (const x of [-width / 2, width / 2]) {
for (const y of [0.16, 0.31, 0.46]) {
addBox(
0.055, 0.055, depth,
materials.basket,
x, y, 0,
group
);
}
}
// Laundry contents.
for (let i = 0; i < 6; i++) {
const laundry = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.14 + (i % 2) * 0.025, 0),
new THREE.MeshStandardMaterial({
color: laundryColors[(index + i) % laundryColors.length],
roughness: 0.86,
metalness: 0
})
);
laundry.position.set(
-0.23 + (i % 3) * 0.22,
0.35 + (i % 2) * 0.08,
-0.15 + Math.floor(i / 3) * 0.27
);
laundry.rotation.set(i * 0.7, i * 0.4, i * 0.2);
laundry.castShadow = true;
group.add(laundry);
}
// Status light.
const statusMaterial = new THREE.MeshBasicMaterial({
color: 0xffb45c
});
const statusLight = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 16, 12),
statusMaterial
);
statusLight.position.set(0.3, 0.59, 0.25);
group.add(statusLight);
const row = Math.floor(index / 3);
const column = index % 3;
const home = new THREE.Vector3(
2.57 + column * 0.91,
0.2,
0.52 - row * 1.05
);
group.position.copy(home);
group.rotation.y = (column - 1) * 0.1;
group.scale.setScalar(0.93);
scene.add(group);
const basket = {
index,
group,
home,
statusLight,
state: "staged",
clean: false,
slot: null,
animation: null
};
group.traverse((child) => {
child.userData.basketId = index;
});
state.baskets.push(basket);
return basket;
}
for (let i = 0; i < TOTAL_BASKETS; i++) {
createBasket(i);
}
// ------------------------------------------------------------
// Basket loading logic and animation
// ------------------------------------------------------------
function inMachineCount() {
return state.baskets.filter((basket) =>
["loaded", "loading", "unloading"].includes(basket.state)
).length;
}
function isBusy() {
return state.baskets.some((basket) =>
["loading", "unloading"].includes(basket.state)
);
}
function firstFreeSlot() {
const occupied = new Set(
state.baskets
.filter((basket) => basket.slot !== null)
.map((basket) => basket.slot)
);
for (let i = 0; i < CAPACITY; i++) {
if (!occupied.has(i)) return i;
}
return -1;
}
function startTransition(basket, nextState, targetPosition, targetScale = 0.74) {
basket.animation = {
elapsed: 0,
duration: 0.95,
fromPosition: basket.group.position.clone(),
toPosition: targetPosition.clone(),
fromScale: basket.group.scale.x,
toScale: targetScale,
arc: nextState === "loaded" ? 1.25 : 0.8
};
basket.state = nextState === "loaded" ? "loading" : "unloading";
updateUI();
}
function loadBasket(index) {
if (state.running) return;
const basket = state.baskets[index];
if (!basket || basket.state !== "staged") return;
const count = inMachineCount();
if (count >= CAPACITY) return;
const slot = firstFreeSlot();
if (slot < 0) return;
basket.slot = slot;
basket.clean = false;
basket.statusLight.material.color.set(0x58d9e7);
const target = loadedSlots[slot].clone();
machine.localToWorld(target);
startTransition(basket, "loaded", target, 0.74);
}
function unloadBasket(index) {
if (state.running) return;
const basket = state.baskets[index];
if (!basket || basket.state !== "loaded") return;
const wasClean = basket.clean;
basket.statusLight.material.color.set(wasClean ? 0xa7ed72 : 0xffb45c);
startTransition(
basket,
wasClean ? "done" : "staged",
basket.home,
0.93
);
}
function loadNextBasket() {
if (state.running || isBusy()) return;
const next = state.baskets.find((basket) => basket.state === "staged");
if (next) loadBasket(next.index);
}
function unloadNextBasket() {
if (state.running || isBusy()) return;
const loaded = state.baskets
.filter((basket) => basket.state === "loaded")
.reverse();
if (loaded.length) unloadBasket(loaded[0].index);
}
function fillCapacity() {
if (state.running || isBusy()) return;
while (inMachineCount() < CAPACITY) {
const next = state.baskets.find((basket) => basket.state === "staged");
if (!next) break;
loadBasket(next.index);
}
}
function emptyMachine() {
if (state.running || isBusy()) return;
const loaded = state.baskets
.filter((basket) => basket.state === "loaded")
.reverse();
for (const basket of loaded) {
unloadBasket(basket.index);
}
}
function updateBasketAnimations(delta) {
for (const basket of state.baskets) {
if (!basket.animation) continue;
const animation = basket.animation;
animation.elapsed += delta;
const t = Math.min(animation.elapsed / animation.duration, 1);
const eased = 1 - Math.pow(1 - t, 3);
basket.group.position.lerpVectors(
animation.fromPosition,
animation.toPosition,
eased
);
basket.group.position.y += Math.sin(t * Math.PI) * animation.arc;
const scale = THREE.MathUtils.lerp(
animation.fromScale,
animation.toScale,
eased
);
basket.group.scale.setScalar(scale);
if (t >= 1) {
const completedState =
animation.toPosition.equals(basket.home) &&
basket.clean
? "done"
: basket.state === "loading"
? "loaded"
: "staged";
basket.group.position.copy(animation.toPosition);
basket.group.scale.setScalar(animation.toScale);
basket.state = completedState;
basket.animation = null;
if (basket.state === "done") {
basket.slot = null;
}
if (basket.state === "staged") {
basket.slot = null;
}
updateUI();
}
}
}
// ------------------------------------------------------------
// Cycle planning and UI
// ------------------------------------------------------------
function doneCount() {
return state.baskets.filter((basket) => basket.state === "done").length;
}
function remainingCount() {
return TOTAL_BASKETS - doneCount();
}
function optimalPlan(remaining) {
let left = remaining;
let cycles = 0;
let minutes = 0;
const batches = [];
while (left > 0) {
const load = Math.min(CAPACITY, left);
const batchMinutes = durationByLoad[load];
batches.push({ load, minutes: batchMinutes });
cycles++;
minutes += batchMinutes;
left -= load;
}
return { cycles, minutes, batches };
}
const ui = {
basketCount: document.querySelector("#basketCount"),
weightCount: document.querySelector("#weightCount"),
capacityState: document.querySelector("#capacityState"),
capacityPill: document.querySelector("#capacityPill"),
pendingCount: document.querySelector("#pendingCount"),
basketRack: document.querySelector("#basketRack"),
loadButton: document.querySelector("#loadButton"),
unloadButton: document.querySelector("#unloadButton"),
fillButton: document.querySelector("#fillButton"),
emptyButton: document.querySelector("#emptyButton"),
requiredCycles: document.querySelector("#requiredCycles"),
neededTime: document.querySelector("#neededTime"),
fixedTotal: document.querySelector("#fixedTotal"),
currentBatch: document.querySelector("#currentBatch"),
comparisonResult: document.querySelector("#comparisonResult"),
cycleCount: document.querySelector("#cycleCount"),
timerValue: document.querySelector("#timerValue"),
timerSlider: document.querySelector("#timerSlider"),
runButton: document.querySelector("#runButton"),
progressFill: document.querySelector("#progressFill"),
runStatus: document.querySelector("#runStatus"),
resetButton: document.querySelector("#resetButton")
};
function createBasketChips() {
ui.basketRack.replaceChildren();
state.baskets.forEach((basket) => {
const button = document.createElement("button");
button.type = "button";
button.className = "basket-chip";
button.textContent = basket.index + 1;
button.addEventListener("click", () => {
if (basket.state === "staged") {
loadBasket(basket.index);
} else if (basket.state === "loaded") {
unloadBasket(basket.index);
}
});
basket.chip = button;
ui.basketRack.append(button);
});
}
function updateUI() {
const count = inMachineCount();
const remaining = remainingCount();
const plan = optimalPlan(remaining);
const fixedTotal = plan.cycles * state.fixedMinutes;
const difference = fixedTotal - plan.minutes;
const hasClean = state.baskets.some(
(basket) => basket.state === "loaded" && basket.clean
);
ui.basketCount.textContent = count;
ui.weightCount.textContent = `${count * KG_PER_BASKET} kg`;
ui.capacityState.textContent =
count === 0
? "Capacity available"
: count < CAPACITY
? `${CAPACITY - count} slot${CAPACITY - count === 1 ? "" : "s"} remaining`
: "At marked capacity";
ui.capacityPill.textContent = `${count} / ${CAPACITY} capacity used`;
for (let i = 0; i < CAPACITY; i++) {
document.querySelector(`#segment${i}`).classList.toggle("on", i < count);
}
ui.pendingCount.textContent = `${remaining} pending`;
ui.cycleCount.textContent = `${state.completedCycles} cycle${state.completedCycles === 1 ? "" : "s"} run`;
for (const basket of state.baskets) {
const chip = basket.chip;
chip.className = "basket-chip";
if (basket.state === "loading") {
chip.classList.add("loading");
chip.textContent = "↗";
chip.title = "Loading into machine";
chip.disabled = true;
} else if (basket.state === "unloading") {
chip.classList.add("loading");
chip.textContent = "↙";
chip.title = "Unloading";
chip.disabled = true;
} else if (basket.state === "loaded") {
chip.classList.add(basket.clean ? "clean" : "loaded");
chip.textContent = basket.index + 1;
chip.title = basket.clean
? "Clean basket — click to unload"
: "Loaded basket — click to unload";
chip.disabled = state.running || isBusy();
} else if (basket.state === "done") {
chip.classList.add("done");
chip.textContent = "✓";
chip.title = "Complete";
chip.disabled = true;
} else {
chip.classList.add("staged");
chip.textContent = basket.index + 1;
chip.title = "Staged basket — click to load";
chip.disabled = state.running || isBusy() || count >= CAPACITY;
}
}
ui.loadButton.disabled =
state.running ||
isBusy() ||
count >= CAPACITY ||
hasClean ||
!state.baskets.some((basket) => basket.state === "staged");
ui.unloadButton.disabled =
state.running ||
isBusy() ||
!state.baskets.some((basket) => basket.state === "loaded");
ui.fillButton.disabled =
state.running ||
isBusy() ||
count >= CAPACITY ||
hasClean;
ui.emptyButton.disabled =
state.running ||
isBusy() ||
!state.baskets.some((basket) => basket.state === "loaded");
ui.requiredCycles.textContent = plan.cycles;
ui.neededTime.innerHTML = `${plan.minutes}<small> min</small>`;
ui.fixedTotal.innerHTML = `${fixedTotal}<small> min</small>`;
if (count > 0) {
const currentMinutes = durationByLoad[count];
ui.currentBatch.innerHTML = `${currentMinutes}<small> min</small>`;
} else {
ui.currentBatch.innerHTML = `—`;
}
if (remaining === 0) {
ui.comparisonResult.textContent = "All six baskets are complete.";
ui.comparisonResult.classList.add("good");
} else if (difference >= 0) {
ui.comparisonResult.textContent =
`The fixed schedule has ${difference} minute${difference === 1 ? "" : "s"} of spare time.`;
ui.comparisonResult.classList.add("good");
} else {
ui.comparisonResult.textContent =
`The fixed schedule needs ${-difference} more minute${difference === -1 ? "" : "s"}.`;
ui.comparisonResult.classList.remove("good");
}
ui.timerValue.textContent = `${state.fixedMinutes} min`;
ui.runButton.disabled =
state.running ||
isBusy() ||
count === 0 ||
hasClean;
if (state.running) {
ui.runButton.textContent = "Cycle running";
} else if (hasClean) {
ui.runButton.textContent = "Unload clean load";
} else {
ui.runButton.textContent = "Run cycle";
}
if (!state.running && state.progress === 0) {
if (count === 0) {
ui.runStatus.textContent = "Load at least one basket to begin.";
} else if (hasClean) {
ui.runStatus.textContent = "Cycle complete — unload the clean baskets.";
} else {
ui.runStatus.textContent =
`${durationByLoad[count]}-minute cycle · simulation compressed to 9 seconds.`;
}
}
}
ui.loadButton.addEventListener("click", loadNextBasket);
ui.unloadButton.addEventListener("click", unloadNextBasket);
ui.fillButton.addEventListener("click", fillCapacity);
ui.emptyButton.addEventListener("click", emptyMachine);
ui.timerSlider.addEventListener("input", (event) => {
state.fixedMinutes = Number(event.target.value);
updateUI();
});
ui.runButton.addEventListener("click", () => {
const count = inMachineCount();
if (!count || state.running || isBusy()) return;
state.running = true;
state.progress = 0;
state.cycleNumber++;
state.currentCycleMinutes = durationByLoad[count];
updateUI();
});
ui.resetButton.addEventListener("click", () => {
state.running = false;
state.progress = 0;
state.completedCycles = 0;
state.cycleNumber = 0;
for (const basket of state.baskets) {
basket.state = "staged";
basket.clean = false;
basket.slot = null;
basket.animation = null;
basket.group.position.copy(basket.home);
basket.group.scale.setScalar(0.93);
basket.statusLight.material.color.set(0xffb45c);
}
ui.progressFill.style.width = "0%";
updateUI();
});
// ------------------------------------------------------------
// Custom camera controls; no Three.js addons are used
// ------------------------------------------------------------
const orbit = {
theta: 0.48,
phi: 1.31,
radius: 9.6,
target: new THREE.Vector3(0.45, 1.42, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.theta = 0.48;
orbit.phi = 1.31;
orbit.radius = 9.6;
orbit.target.set(0.45, 1.42, 0);
updateCamera();
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
let orbiting = false;
let basketCandidate = null;
function setPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function basketAtPointer() {
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(
state.baskets.map((basket) => basket.group),
true
);
if (!hits.length) return null;
let object = hits[0].object;
while (object && object.userData.basketId === undefined) {
object = object.parent;
}
return object ? state.baskets[object.userData.basketId] : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
setPointer(event);
pointerDown = {
x: event.clientX,
y: event.clientY,
moved: false
};
basketCandidate = basketAtPointer();
orbiting = !basketCandidate;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.hypot(dx, dy) > 5) {
pointerDown.moved = true;
}
if (orbiting && pointerDown.moved) {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.78,
1.49
);
updateCamera();
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerDown) return;
setPointer(event);
if (basketCandidate && !pointerDown.moved && !state.running && !isBusy()) {
const basket = basketAtPointer();
if (basket) {
if (basket.state === "staged") {
loadBasket(basket.index);
} else if (basket.state === "loaded") {
unloadBasket(basket.index);
}
}
}
pointerDown = null;
basketCandidate = null;
orbiting = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
basketCandidate = null;
orbiting = false;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.008,
6.4,
14
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
// ------------------------------------------------------------
// Resize and animation loop
// ------------------------------------------------------------
function resizeRenderer() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(viewport);
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
updateBasketAnimations(delta);
if (state.running) {
state.progress = Math.min(state.progress + delta / 9, 1);
drum.rotation.z -= delta * 2.5;
const minutesRemaining = Math.ceil(
state.currentCycleMinutes * (1 - state.progress)
);
ui.progressFill.style.width = `${state.progress * 100}%`;
ui.runStatus.textContent =
`Cycle ${state.cycleNumber} • ${minutesRemaining} min remaining in accelerated view.`;
if (state.progress >= 1) {
state.running = false;
state.completedCycles++;
for (const basket of state.baskets) {
if (basket.state === "loaded") {
basket.clean = true;
basket.statusLight.material.color.set(0xa7ed72);
}
}
ui.progressFill.style.width = "100%";
updateUI();
ui.runStatus.textContent =
"Cycle complete — unload the clean baskets before continuing.";
}
}
if (state.baskets.some((basket) => basket.state === "loaded")) {
drum.rotation.z -= delta * 0.035;
}
for (const bubble of bubbles) {
const seed = bubble.userData.seed;
const rise = (elapsed * (0.2 + (seed % 4) * 0.025) + seed * 0.11) % 1.35;
bubble.position.y = 0.2 + rise;
bubble.position.x += Math.sin(elapsed * 1.6 + seed) * delta * 0.025;
if (bubble.position.x > 0.9) bubble.position.x = -0.9;
if (bubble.position.x < -0.9) bubble.position.x = 0.9;
}
const pulse = 0.72 + Math.sin(elapsed * 2.4) * 0.2;
materials.capacity.opacity = pulse;
renderer.render(scene, camera);
}
createBasketChips();
updateUI();
animate();
</script>
</body>
</html>
```