Prompt specification
Build or customize the Three.js 3D scene "Cooperative laundry room scheduling" 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: Cooperative laundry room scheduling
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cooperative-laundry-room-scheduling-x0048
Scene Description Prompt:
A voxel laundry room has four machines and personal baskets; queued users advance only when a machine finishes. Three.js from cdnjs, one HTML file.
Working Three.js Starter (cooperative-laundry-room-scheduling-x0048):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Spin Cycle — Voxel Laundry Room</title>
<style>
:root {
color-scheme: dark;
--ink: #eaf4ff;
--muted: #9eb2c7;
--panel: rgba(12, 20, 34, 0.88);
--border: rgba(170, 205, 240, 0.18);
--cyan: #62e8dc;
--yellow: #ffd166;
--pink: #ff7b9c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101827;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
pointer-events: none;
}
#brand {
top: 18px;
left: 18px;
padding: 15px 17px;
border-radius: 15px;
min-width: 240px;
}
#brand h1 {
margin: 0 0 5px;
font-size: 22px;
letter-spacing: 0.12em;
}
#brand p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.brand-row {
display: flex;
gap: 7px;
margin-top: 11px;
flex-wrap: wrap;
}
.badge {
padding: 5px 7px;
border: 1px solid var(--border);
border-radius: 6px;
color: #cde5fb;
background: rgba(255, 255, 255, 0.045);
font-size: 10px;
letter-spacing: 0.05em;
}
#machine-strip {
top: 18px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 8px;
padding: 9px;
border-radius: 14px;
}
.machine-card {
width: 116px;
padding: 8px 9px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
border: 1px solid rgba(255, 255, 255, 0.08);
}
.machine-card .machine-name {
display: flex;
justify-content: space-between;
gap: 8px;
font-weight: 800;
font-size: 11px;
}
.machine-card .machine-state {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.mini-track {
height: 4px;
margin-top: 7px;
overflow: hidden;
border-radius: 3px;
background: rgba(255, 255, 255, 0.1);
}
.mini-track span {
display: block;
height: 100%;
width: 0;
background: var(--cyan);
transition: width 0.12s linear;
}
#controls {
top: 18px;
right: 18px;
padding: 10px;
border-radius: 14px;
display: flex;
gap: 7px;
align-items: center;
pointer-events: auto;
}
button,
select {
border: 1px solid var(--border);
border-radius: 8px;
padding: 8px 10px;
background: #17253a;
color: var(--ink);
font: inherit;
font-size: 11px;
cursor: pointer;
}
button:hover,
select:hover {
background: #223751;
}
button:active {
transform: translateY(1px);
}
#rule {
left: 18px;
bottom: 18px;
width: 290px;
padding: 14px 16px;
border-radius: 14px;
}
#rule h2,
#queue-panel h2 {
margin: 0 0 9px;
font-size: 12px;
letter-spacing: 0.1em;
}
#rule p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.rule-key {
display: flex;
align-items: center;
gap: 8px;
margin-top: 10px;
font-size: 10px;
color: #c9d9e9;
}
.rule-key i {
width: 11px;
height: 11px;
border-radius: 3px;
display: inline-block;
box-shadow: 0 0 12px currentColor;
}
#queue-panel {
right: 18px;
bottom: 18px;
width: 310px;
padding: 14px 16px;
border-radius: 14px;
}
#queue-list {
display: flex;
flex-wrap: wrap;
gap: 7px;
min-height: 31px;
}
.person-chip {
display: flex;
align-items: center;
gap: 6px;
padding: 6px 8px;
border-radius: 7px;
background: rgba(255, 255, 255, 0.05);
font-size: 10px;
}
.person-chip i {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--person-color);
box-shadow: 0 0 9px var(--person-color);
}
#next-person {
margin-top: 10px;
color: var(--muted);
font-size: 10px;
}
#next-person strong {
color: var(--yellow);
}
#event-log {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid var(--border);
color: #91a8bf;
font-size: 9px;
line-height: 1.55;
min-height: 29px;
}
#help {
position: fixed;
z-index: 4;
left: 50%;
bottom: 12px;
transform: translateX(-50%);
color: rgba(220, 235, 250, 0.62);
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 1050px) {
#machine-strip {
top: 112px;
}
#rule {
display: none;
}
}
@media (max-width: 700px) {
#brand {
min-width: 0;
right: 18px;
}
#brand h1 {
font-size: 18px;
}
#controls {
top: 112px;
left: 18px;
right: auto;
}
#machine-strip {
top: 168px;
max-width: calc(100vw - 36px);
overflow-x: auto;
}
.machine-card {
min-width: 106px;
}
#queue-panel {
left: 18px;
right: 18px;
bottom: 34px;
width: auto;
}
#help {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<section id="brand" class="panel">
<h1>SPIN CYCLE</h1>
<p>A tiny voxel laundry room with live service logic.</p>
<div class="brand-row">
<span class="badge">4 MACHINES</span>
<span class="badge">4 WAITING</span>
<span class="badge">PERSONAL BASKETS</span>
</div>
</section>
<section id="machine-strip" class="panel"></section>
<section id="controls" class="panel">
<button id="pause" title="Pause or resume the simulation">Pause</button>
<select id="speed" title="Simulation speed">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="2">2×</option>
<option value="4">4×</option>
</select>
<button id="camera-reset" title="Reset the camera">View</button>
<button id="reset" title="Restart the simulation">Reset</button>
</section>
<section id="rule" class="panel">
<h2>QUEUE RULE</h2>
<p>
Waiting customers remain in line. A customer advances only when one of the
four machines finishes and releases its current user.
</p>
<div class="rule-key">
<i style="color:#62e8dc;background:#62e8dc"></i>
Washing / drying
</div>
<div class="rule-key">
<i style="color:#ffd166;background:#ffd166"></i>
Loading / handoff
</div>
<div class="rule-key">
<i style="color:#8b9bb0;background:#8b9bb0"></i>
Machine available
</div>
</section>
<section id="queue-panel" class="panel">
<h2>WAITING LINE</h2>
<div id="queue-list"></div>
<div id="next-person"></div>
<div id="event-log"></div>
</section>
<div id="help">DRAG TO ORBIT · SCROLL TO ZOOM · SPACE TO PAUSE</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 custom camera controls
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101827);
scene.fog = new THREE.Fog(0x101827, 20, 37);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 1.05, -0.25);
let cameraYaw = 0.58;
let cameraPitch = 0.61;
let cameraRadius = 18.2;
function updateCamera() {
const horizontal = cameraRadius * Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraYaw = 0.58;
cameraPitch = 0.61;
cameraRadius = 18.2;
updateCamera();
}
updateCamera();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.005,
0.28,
1.13
);
updateCamera();
});
function stopDragging() {
dragging = false;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
10.5,
27
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Materials and voxel construction helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function material(color, roughness = 0.78, metalness = 0) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness
})
);
}
return materialCache.get(key);
}
function box(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cube(parent, size, position, color, castShadow = true) {
return box(
parent,
size,
position,
material(color),
castShadow
);
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xd9efff, 0x26374c, 2.15));
const sun = new THREE.DirectionalLight(0xfff2d8, 3.25);
sun.position.set(5, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x7ccfff, 1.15);
fill.position.set(-7, 7, 3);
scene.add(fill);
// -------------------------------------------------------------------------
// Voxel room
// -------------------------------------------------------------------------
cube(scene, [15.2, 0.34, 10.4], [0, -0.18, 0], 0x243448, false);
const tileGeometry = new THREE.BoxGeometry(0.96, 0.04, 0.96);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9
});
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
150
);
tiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < 10; row++) {
for (let column = 0; column < 15; column++) {
dummy.position.set(
-7 + column,
0.025,
-4.5 + row
);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const alternate = (row + column) % 2 === 0;
tileColor.set(alternate ? 0x8da4b8 : 0x7f98ad);
tileColor.offsetHSL(0, 0, (Math.random() - 0.5) * 0.025);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
scene.add(tiles);
cube(scene, [15.2, 5.1, 0.28], [0, 2.55, -5.05], 0x344b60);
cube(scene, [0.28, 5.1, 10.3], [-7.55, 2.55, 0], 0x3b5267);
cube(scene, [15, 0.24, 0.12], [0, 0.22, -4.84], 0x17283b);
cube(scene, [0.12, 0.24, 10], [-7.35, 0.22, 0], 0x17283b);
// Wall trim and a simple pixel-style clock.
cube(scene, [14.8, 0.08, 0.06], [0, 3.95, -4.88], 0x547086);
cube(scene, [0.06, 0.08, 9.8], [-7.38, 3.95, 0], 0x547086);
cube(scene, [0.78, 0.78, 0.12], [-5.85, 3.35, -4.82], 0x101927);
cube(scene, [0.12, 0.48, 0.08], [-5.85, 3.48, -4.73], 0xe9f5ff);
cube(scene, [0.38, 0.12, 0.08], [-5.72, 3.35, -4.73], 0xe9f5ff);
// Laundry sign.
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 256;
const signContext = signCanvas.getContext("2d");
signContext.fillStyle = "#102234";
signContext.fillRect(0, 0, 1024, 256);
signContext.fillStyle = "#62e8dc";
signContext.fillRect(34, 32, 956, 192);
signContext.fillStyle = "#102234";
signContext.fillRect(48, 46, 928, 164);
signContext.fillStyle = "#fff4cf";
signContext.font = "900 104px monospace";
signContext.textAlign = "center";
signContext.textBaseline = "middle";
signContext.fillText("SPIN CYCLE", 512, 125);
signContext.font = "700 27px monospace";
signContext.fillStyle = "#62e8dc";
signContext.fillText("VOXEL LAUNDRY ROOM", 512, 225);
const signTexture = new THREE.CanvasTexture(signCanvas);
signTexture.colorSpace = THREE.SRGBColorSpace;
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(5.4, 1.35),
new THREE.MeshBasicMaterial({ map: signTexture })
);
sign.position.set(0, 3.55, -4.84);
scene.add(sign);
// -------------------------------------------------------------------------
// Machines
// -------------------------------------------------------------------------
const machineX = [-4.8, -1.6, 1.6, 4.8];
const machines = [];
function createMachineDisplay(machine) {
const displayCanvas = document.createElement("canvas");
displayCanvas.width = 320;
displayCanvas.height = 120;
const texture = new THREE.CanvasTexture(displayCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const display = new THREE.Mesh(
new THREE.PlaneGeometry(1.48, 0.55),
new THREE.MeshBasicMaterial({ map: texture })
);
display.position.set(0, 2.17, 0.972);
machine.group.add(display);
machine.displayCanvas = displayCanvas;
machine.displayContext = displayCanvas.getContext("2d");
machine.displayTexture = texture;
}
function createMachine(index, x) {
const group = new THREE.Group();
group.position.set(x, 0, -3.72);
scene.add(group);
const bodyColor = index % 2 === 0 ? 0xe8eee8 : 0xd8e8e6;
cube(group, [2.3, 2.65, 1.9], [0, 1.48, 0], bodyColor);
cube(group, [2.38, 0.16, 2.02], [0, 2.88, 0], 0xf5faf5);
cube(group, [2.1, 0.1, 1.76], [0, 0.18, 0], 0x27394a);
cube(group, [1.73, 0.49, 0.09], [0, 2.17, 0.985], 0x203144);
cube(group, [0.22, 0.22, 0.12], [-0.82, 2.17, 1.02], 0xd8e4ec);
cube(group, [0.22, 0.22, 0.12], [0.76, 2.17, 1.02], 0x92a9ba);
// Voxel door frame and transparent square window.
const doorPivot = new THREE.Group();
doorPivot.position.set(-0.67, 1.05, 1.015);
group.add(doorPivot);
cube(doorPivot, [1.34, 0.15, 0.15], [0.67, 0.62, 0], 0x1c2d3d);
cube(doorPivot, [1.34, 0.15, 0.15], [0.67, -0.62, 0], 0x1c2d3d);
cube(doorPivot, [0.15, 1.1, 0.15], [0.07, 0, 0], 0x1c2d3d);
cube(doorPivot, [0.15, 1.1, 0.15], [1.27, 0, 0], 0x1c2d3d);
cube(doorPivot, [1.08, 0.98, 0.08], [0.67, 0, 0.015], 0x233a4d);
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x5dbbd2,
roughness: 0.2,
metalness: 0.05,
transparent: true,
opacity: 0.55
});
box(
doorPivot,
[0.91, 0.81, 0.055],
[0.67, 0, 0.07],
glassMaterial,
false
);
cube(doorPivot, [0.13, 0.43, 0.17], [1.16, 0, 0.12], 0xd8e6ec);
// Detergent bottle on top.
const bottleColor = [0xff7b9c, 0xffd166, 0x62e8dc, 0x9c8cff][index];
cube(group, [0.3, 0.44, 0.27], [-0.62, 3.17, -0.1], bottleColor);
cube(group, [0.18, 0.12, 0.18], [-0.62, 3.44, -0.1], 0xf6f3e9);
cube(group, [0.19, 0.24, 0.02], [-0.62, 3.16, 0.044], 0xf9fbef, false);
const bubbles = [];
for (let b = 0; b < 7; b++) {
const bubble = cube(
group,
[0.08 + Math.random() * 0.08, 0.08 + Math.random() * 0.08, 0.045],
[
(Math.random() - 0.5) * 0.7,
0.65 + Math.random() * 0.75,
1.04
],
b % 2 ? 0xd9fbff : 0xffffff,
false
);
bubbles.push({
mesh: bubble,
speed: 0.18 + Math.random() * 0.28,
offset: Math.random() * Math.PI * 2,
range: 0.12 + Math.random() * 0.2
});
}
const machine = {
index,
x,
group,
doorPivot,
bubbles,
duration: [27, 29, 26, 30][index],
progress: [0.42, 0.58, 0.7, 0.84][index],
phase: index === 1 || index === 3 ? "dry" : "wash",
userId: index,
nextName: "",
loadTimer: 0,
doorTarget: 0,
doorAmount: 0
};
createMachineDisplay(machine);
machines.push(machine);
return machine;
}
machineX.forEach((x, index) => createMachine(index, x));
// -------------------------------------------------------------------------
// Personal voxel baskets
// -------------------------------------------------------------------------
function createBasket(color) {
const group = new THREE.Group();
const basketMat = material(color, 0.66);
cube(group, [0.72, 0.09, 0.56], [0, 0.06, 0], basketMat);
cube(group, [0.08, 0.48, 0.08], [-0.32, 0.28, -0.22], basketMat);
cube(group, [0.08, 0.48, 0.08], [0.32, 0.28, -0.22], basketMat);
cube(group, [0.08, 0.48, 0.08], [-0.32, 0.28, 0.22], basketMat);
cube(group, [0.08, 0.48, 0.08], [0.32, 0.28, 0.22], basketMat);
for (let y = 0.17; y <= 0.43; y += 0.13) {
cube(group, [0.7, 0.06, 0.06], [0, y, -0.24], basketMat);
cube(group, [0.7, 0.06, 0.06], [0, y, 0.24], basketMat);
cube(group, [0.06, 0.06, 0.48], [-0.32, y, 0], basketMat);
cube(group, [0.06, 0.06, 0.48], [0.32, y, 0], basketMat);
}
cube(group, [0.4, 0.07, 0.07], [0, 0.55, 0], basketMat);
cube(group, [0.07, 0.18, 0.07], [-0.2, 0.46, 0], basketMat);
cube(group, [0.07, 0.18, 0.07], [0.2, 0.46, 0], basketMat);
return group;
}
// -------------------------------------------------------------------------
// Voxel people
// -------------------------------------------------------------------------
const peopleData = [
{ name: "Ada", color: 0xff7b9c, skin: 0xd79b76 },
{ name: "Milo", color: 0xffd166, skin: 0x9b6548 },
{ name: "June", color: 0x62e8dc, skin: 0xe3ae87 },
{ name: "Theo", color: 0x9c8cff, skin: 0x704936 },
{ name: "Bea", color: 0x67d890, skin: 0xc98762 },
{ name: "Omar", color: 0xff9f68, skin: 0x8f5c40 },
{ name: "Iris", color: 0x71a7ff, skin: 0xe1ad89 },
{ name: "Luca", color: 0xf78ad3, skin: 0xb87855 }
];
const users = [];
function createUser(id) {
const data = peopleData[id];
const group = new THREE.Group();
const clothing = material(data.color);
const skin = material(data.skin);
const dark = material(0x172333);
const hairColors = [0x2c2430, 0x51372a, 0x171c28, 0x76523b];
const hair = material(hairColors[id % hairColors.length]);
cube(group, [0.58, 0.72, 0.38], [0, 1.06, 0], data.color);
cube(group, [0.49, 0.49, 0.47], [0, 1.67, 0], data.skin);
cube(group, [0.53, 0.16, 0.5], [0, 1.93, -0.01], hair);
cube(group, [0.56, 0.25, 0.13], [0, 1.86, -0.2], hair);
cube(group, [0.08, 0.09, 0.05], [-0.12, 1.71, 0.25], dark, false);
cube(group, [0.08, 0.09, 0.05], [0.12, 1.71, 0.25], dark, false);
cube(group, [0.09, 0.04, 0.04], [0, 1.58, 0.25], 0x9f5a5a, false);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.39, 1.3, 0);
rightArm.position.set(0.39, 1.3, 0);
group.add(leftArm, rightArm);
cube(leftArm, [0.18, 0.62, 0.21], [0, -0.25, 0], data.color);
cube(rightArm, [0.18, 0.62, 0.21], [0, -0.25, 0], data.color);
cube(leftArm, [0.17, 0.17, 0.19], [0, -0.59, 0], data.skin);
cube(rightArm, [0.17, 0.17, 0.19], [0, -0.59, 0], data.skin);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.16, 0.7, 0);
rightLeg.position.set(0.16, 0.7, 0);
group.add(leftLeg, rightLeg);
cube(leftLeg, [0.22, 0.59, 0.25], [0, -0.27, 0], 0x263a52);
cube(rightLeg, [0.22, 0.59, 0.25], [0, -0.27, 0], 0x263a52);
cube(leftLeg, [0.25, 0.13, 0.37], [0, -0.57, 0.06], 0x111b28);
cube(rightLeg, [0.25, 0.13, 0.37], [0, -0.57, 0.06], 0x111b28);
const basket = createBasket(data.color);
scene.add(group);
scene.add(basket);
const user = {
id,
name: data.name,
color: data.color,
group,
basket,
leftArm,
rightArm,
leftLeg,
rightLeg,
mode: "station",
target: new THREE.Vector3(),
walkPhase: Math.random() * Math.PI * 2,
walking: false,
speed: 1.35 + Math.random() * 0.18
};
users.push(user);
return user;
}
peopleData.forEach((_, id) => createUser(id));
const queue = [4, 5, 6, 7];
function stationUserPosition(machine) {
return new THREE.Vector3(machine.x, 0, -2.18);
}
function stationBasketPosition(machine) {
return new THREE.Vector3(machine.x + 0.78, 0, -2.37);
}
function queuePosition(index) {
return new THREE.Vector3(6.35, 0, -0.55 + index * 1.27);
}
const exitPosition = new THREE.Vector3(-7.03, 0, 3.65);
machines.forEach((machine, index) => {
const user = users[machine.userId];
user.group.position.copy(stationUserPosition(machine));
user.group.rotation.y = Math.PI;
user.mode = "station";
user.basket.position.copy(stationBasketPosition(machine));
user.basket.rotation.y = 0;
});
queue.forEach((id, index) => {
const user = users[id];
user.group.position.copy(queuePosition(index));
user.group.rotation.y = Math.PI;
user.mode = "queue";
user.target.copy(queuePosition(index));
user.group.attach(user.basket);
user.basket.position.set(0.48, 0.12, 0.03);
user.basket.rotation.set(0, 0, 0);
});
// Floor queue markers.
for (let index = 0; index < 4; index++) {
const p = queuePosition(index);
cube(scene, [0.62, 0.025, 0.1], [p.x, 0.065, p.z + 0.49], 0xffd166, false);
cube(scene, [0.1, 0.025, 0.38], [p.x + 0.29, 0.065, p.z + 0.68], 0xffd166, false);
}
// -------------------------------------------------------------------------
// Room decor
// -------------------------------------------------------------------------
// Left-wall shelving.
cube(scene, [1.05, 0.12, 3.35], [-6.9, 0.72, -1.15], 0x8a684e);
cube(scene, [1.05, 0.12, 3.35], [-6.9, 1.62, -1.15], 0x8a684e);
cube(scene, [1.05, 0.12, 3.35], [-6.9, 2.52, -1.15], 0x8a684e);
const towelColors = [0xf5e9d5, 0xff9f9f, 0x8ed5c8, 0x9fb6ee];
for (let shelf = 0; shelf < 3; shelf++) {
for (let towel = 0; towel < 3; towel++) {
cube(
scene,
[0.68, 0.2, 0.65],
[
-6.85,
0.88 + shelf * 0.9,
-2.23 + towel * 0.83
],
towelColors[(shelf + towel) % towelColors.length]
);
}
}
// Folding table.
cube(scene, [3.15, 0.16, 1.22], [0, 1.13, 4.15], 0xd8b185);
cube(scene, [0.18, 1.05, 0.18], [-1.25, 0.53, 3.7], 0x52677b);
cube(scene, [0.18, 1.05, 0.18], [1.25, 0.53, 3.7], 0x52677b);
cube(scene, [0.18, 1.05, 0.18], [-1.25, 0.53, 4.6], 0x52677b);
cube(scene, [0.18, 1.05, 0.18], [1.25, 0.53, 4.6], 0x52677b);
cube(scene, [0.76, 0.18, 0.62], [-0.68, 1.31, 4.15], 0xffd166);
cube(scene, [0.65, 0.16, 0.58], [0.35, 1.29, 4.14], 0xff7b9c);
// Voxel plant.
cube(scene, [0.65, 0.62, 0.65], [-6.55, 0.33, -3.9], 0xd47f5b);
cube(scene, [0.14, 1.25, 0.14], [-6.55, 1.15, -3.9], 0x315d47);
cube(scene, [0.9, 0.35, 0.5], [-6.25, 1.62, -3.9], 0x4b8b62);
cube(scene, [0.58, 0.4, 0.9], [-6.84, 1.95, -3.9], 0x3f7657);
cube(scene, [0.52, 0.35, 0.52], [-6.25, 2.18, -3.9], 0x64a774);
// Pendant lights.
[-3.3, 0, 3.3].forEach((x, index) => {
cube(scene, [0.05, 1.15, 0.05], [x, 4.62, -0.3], 0x25384a);
cube(scene, [0.95, 0.24, 0.95], [x, 3.96, -0.3], 0xf3c96c);
cube(scene, [0.67, 0.06, 0.67], [x, 3.81, -0.3], 0xfff0b3, false);
const lamp = new THREE.PointLight(0xffd98c, 9, 8, 2);
lamp.position.set(x, 3.7, -0.3);
scene.add(lamp);
});
// Exit sign.
const exitCanvas = document.createElement("canvas");
exitCanvas.width = 256;
exitCanvas.height = 128;
const exitContext = exitCanvas.getContext("2d");
exitContext.fillStyle = "#17352f";
exitContext.fillRect(0, 0, 256, 128);
exitContext.fillStyle = "#76f3bd";
exitContext.font = "900 53px monospace";
exitContext.textAlign = "center";
exitContext.textBaseline = "middle";
exitContext.fillText("EXIT", 128, 64);
const exitTexture = new THREE.CanvasTexture(exitCanvas);
exitTexture.colorSpace = THREE.SRGBColorSpace;
const exitSign = new THREE.Mesh(
new THREE.PlaneGeometry(1.25, 0.63),
new THREE.MeshBasicMaterial({ map: exitTexture })
);
exitSign.position.set(-7.36, 2.95, 3.65);
exitSign.rotation.y = Math.PI / 2;
scene.add(exitSign);
// -------------------------------------------------------------------------
// Simulation and service logic
// -------------------------------------------------------------------------
const simulation = {
paused: false,
speed: 1,
time: 0,
lastEvent: "Room opened. Four customers are waiting."
};
const clock = new THREE.Clock();
let uiTimer = 0;
function logEvent(message) {
simulation.lastEvent = message;
document.querySelector("#event-log").textContent = message;
}
function shiftQueueTargets() {
queue.forEach((id, index) => {
users[id].target.copy(queuePosition(index));
});
}
function completeMachine(machine) {
const finishedUser = users[machine.userId];
machine.progress = 1;
machine.doorTarget = 1;
machine.nextName = "";
// The former user collects their personal basket and exits.
finishedUser.mode = "collect";
finishedUser.target.copy(stationBasketPosition(machine));
// A queued customer advances only now, at the exact completion event.
const nextId = queue.shift();
if (nextId !== undefined) {
const nextUser = users[nextId];
machine.userId = nextId;
machine.phase = "load";
machine.progress = 0;
machine.loadTimer = 0;
machine.nextName = nextUser.name;
nextUser.mode = "toMachine";
nextUser.target.copy(stationUserPosition(machine));
shiftQueueTargets();
logEvent(
`M${machine.index + 1} finished. ${finishedUser.name} collected their basket; ` +
`${nextUser.name} advances.`
);
} else {
machine.userId = null;
machine.phase = "idle";
machine.nextName = "";
logEvent(
`M${machine.index + 1} finished. ${finishedUser.name} collected their basket; ` +
`the machine is now free.`
);
}
}
function updateMachines(dt) {
machines.forEach((machine) => {
if (machine.phase === "wash" || machine.phase === "dry") {
machine.progress += dt / machine.duration;
if (machine.progress >= 0.5 && machine.phase === "wash") {
machine.phase = "dry";
}
if (machine.progress >= 1) {
completeMachine(machine);
}
} else if (machine.phase === "load" && machine.userId !== null) {
const arrivingUser = users[machine.userId];
// The machine is ready to wash once the next customer has arrived
// and placed their personal basket beside it.
if (arrivingUser.mode === "station") {
machine.loadTimer += dt;
if (machine.loadTimer >= 1.15) {
machine.phase = "wash";
machine.progress = 0;
machine.doorTarget = 0;
machine.nextName = "";
}
}
}
const desiredDoor =
machine.phase === "load" ? 1 : 0;
machine.doorAmount = THREE.MathUtils.damp(
machine.doorAmount,
desiredDoor,
7,
dt
);
machine.doorPivot.rotation.y = -1.08 * machine.doorAmount;
});
}
function updateUsers(dt) {
users.forEach((user) => {
let moving = false;
if (
user.mode === "queue" ||
user.mode === "collect" ||
user.mode === "exit" ||
user.mode === "toMachine"
) {
const dx = user.target.x - user.group.position.x;
const dz = user.target.z - user.group.position.z;
const distance = Math.hypot(dx, dz);
if (distance > 0.035) {
const step = Math.min(distance, user.speed * dt);
user.group.position.x += (dx / distance) * step;
user.group.position.z += (dz / distance) * step;
const desiredAngle = Math.atan2(dx, dz);
const angleDifference = Math.atan2(
Math.sin(desiredAngle - user.group.rotation.y),
Math.cos(desiredAngle - user.group.rotation.y)
);
user.group.rotation.y += angleDifference * Math.min(1, dt * 11);
user.walkPhase += dt * 9;
moving = true;
} else if (user.mode === "collect") {
// Pick up the personal basket.
user.group.attach(user.basket);
user.basket.position.set(0.48, 0.12, 0.03);
user.basket.rotation.set(0, 0, 0);
user.mode = "exit";
user.target.copy(exitPosition);
} else if (user.mode === "exit") {
user.group.visible = false;
user.mode = "done";
} else if (user.mode === "toMachine") {
// Place the personal basket beside the machine.
scene.attach(user.basket);
user.basket.position.copy(stationBasketPosition(machines[machineIndexForUser(user)]));
user.basket.rotation.set(0, 0, 0);
user.mode = "station";
user.walking = false;
}
}
user.walking = moving;
const swing = moving ? Math.sin(user.walkPhase) * 0.58 : 0;
user.leftLeg.rotation.x = swing;
user.rightLeg.rotation.x = -swing;
user.leftArm.rotation.x = -swing * 0.8;
user.rightArm.rotation.x = swing * 0.8;
user.group.position.y = moving
? Math.abs(Math.sin(user.walkPhase)) * 0.045
: 0;
});
}
function machineIndexForUser(user) {
return machines.findIndex((machine) => machine.userId === user.id);
}
function updateMachineAnimation(time) {
machines.forEach((machine) => {
machine.bubbles.forEach((bubble, index) => {
const active =
machine.phase === "wash" || machine.phase === "dry";
bubble.mesh.visible = active;
if (!active) return;
const phase = time * bubble.speed + bubble.offset + index * 0.6;
bubble.mesh.position.x =
Math.sin(phase * 1.3) * bubble.range;
bubble.mesh.position.y =
0.68 +
((Math.sin(phase) * 0.5 + 0.5) * 0.69);
});
});
}
// -------------------------------------------------------------------------
// UI rendering
// -------------------------------------------------------------------------
const machineStrip = document.querySelector("#machine-strip");
const queueList = document.querySelector("#queue-list");
const nextPerson = document.querySelector("#next-person");
function updateUI() {
machineStrip.innerHTML = machines
.map((machine) => {
const occupant = machine.userId === null
? "Available"
: users[machine.userId].name;
const state =
machine.phase === "wash"
? "Washing"
: machine.phase === "dry"
? "Drying"
: machine.phase === "load"
? "Loading"
: "Available";
const color =
machine.phase === "wash"
? "#62e8dc"
: machine.phase === "dry"
? "#ff9f68"
: machine.phase === "load"
? "#ffd166"
: "#8b9bb0";
return `
<div class="machine-card">
<div class="machine-name">
<span>M${machine.index + 1}</span>
<span style="color:${color}">${state}</span>
</div>
<div class="machine-state">${occupant}</div>
<div class="mini-track">
<span style="width:${Math.round(machine.progress * 100)}%;background:${color}"></span>
</div>
</div>
`;
})
.join("");
queueList.innerHTML = queue.length
? queue
.map((id) => {
const user = users[id];
return `
<div class="person-chip" style="--person-color:#${user.color.toString(16).padStart(6, "0")}">
<i></i>${user.name}
</div>
`;
})
.join("")
: `<span style="color:#8b9bb0;font-size:10px">No one waiting</span>`;
nextPerson.innerHTML = queue.length
? `Next customer: <strong>${users[queue[0]].name}</strong>`
: `Next customer: <strong>none</strong>`;
}
function drawMachineDisplays() {
machines.forEach((machine) => {
const context = machine.displayContext;
const width = 320;
const height = 120;
context.clearRect(0, 0, width, height);
context.fillStyle = "#0d1724";
context.fillRect(0, 0, width, height);
const accent =
machine.phase === "wash"
? "#62e8dc"
: machine.phase === "dry"
? "#ff9f68"
: machine.phase === "load"
? "#ffd166"
: "#8b9bb0";
context.fillStyle = accent;
context.fillRect(0, 0, 12, height);
context.fillStyle = "#edf7ff";
context.font = "900 35px monospace";
context.fillText(`M${machine.index + 1}`, 28, 39);
const status =
machine.phase === "wash"
? "WASH"
: machine.phase === "dry"
? "DRY"
: machine.phase === "load"
? "LOAD"
: "FREE";
context.fillStyle = accent;
context.font = "800 27px monospace";
context.textAlign = "right";
context.fillText(status, 296, 38);
context.textAlign = "left";
context.fillStyle = "#758ba1";
context.font = "18px monospace";
const label =
machine.userId === null
? "READY"
: users[machine.userId].name.toUpperCase();
context.fillText(label, 28, 70);
context.fillStyle = "#26384c";
context.fillRect(28, 88, 264, 12);
context.fillStyle = accent;
context.fillRect(
28,
88,
264 * Math.max(0.02, Math.min(1, machine.progress)),
12
);
machine.displayTexture.needsUpdate = true;
});
}
// -------------------------------------------------------------------------
// Controls and main loop
// -------------------------------------------------------------------------
const pauseButton = document.querySelector("#pause");
function togglePause() {
simulation.paused = !simulation.paused;
pauseButton.textContent = simulation.paused ? "Resume" : "Pause";
}
pauseButton.addEventListener("click", togglePause);
document.querySelector("#speed").addEventListener("change", (event) => {
simulation.speed = Number(event.target.value);
});
document.querySelector("#camera-reset").addEventListener("click", resetCamera);
document.querySelector("#reset").addEventListener("click", () => location.reload());
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
togglePause();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate() {
const realDt = Math.min(clock.getDelta(), 0.05);
const dt = simulation.paused ? 0 : realDt * simulation.speed;
simulation.time += dt;
updateMachines(dt);
updateUsers(dt);
updateMachineAnimation(simulation.time);
uiTimer += realDt;
if (uiTimer >= 0.1) {
uiTimer = 0;
updateUI();
drawMachineDisplays();
}
renderer.render(scene, camera);
}
updateUI();
drawMachineDisplays();
logEvent(simulation.lastEvent);
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```