Prompt specification
Build or customize the Three.js 3D scene "Public waiting area replenishment" 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: Public waiting area replenishment
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/public-waiting-area-replenishment-x0072
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing an interleaved tissue dispenser. Build a waiting area with tables, seats, and supply cart; demonstrate replacement of an empty dispenser while remaining supplies and circulation routes stay visibly organized. Low-poly.
Working Three.js Starter (public-waiting-area-replenishment-x0072):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Interleaved Tissue Station</title>
<style>
:root {
--ink: #16333a;
--muted: #597177;
--panel: rgba(250, 253, 251, 0.91);
--line: rgba(22, 51, 58, 0.14);
--teal: #169c91;
--amber: #f08a45;
--red: #d85c55;
--green: #4aa876;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background: #dbe7e5;
}
#scene {
position: fixed;
inset: 0;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 14px 35px rgba(30, 67, 69, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#brand {
position: fixed;
top: 22px;
left: 22px;
width: min(380px, calc(100vw - 44px));
padding: 17px 19px 15px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 3vw, 29px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 8px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
#legend {
position: fixed;
top: 22px;
right: 22px;
width: 210px;
padding: 14px 16px;
border-radius: 16px;
font-size: 12px;
}
.legend-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 6px 0;
}
.legend-label {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 3px rgba(22, 156, 145, 0.12);
}
.dot.amber {
background: var(--amber);
box-shadow: 0 0 0 3px rgba(240, 138, 69, 0.13);
}
.dot.green {
background: var(--green);
box-shadow: 0 0 0 3px rgba(74, 168, 118, 0.13);
}
.dot.red {
background: var(--red);
box-shadow: 0 0 0 3px rgba(216, 92, 85, 0.13);
}
.unit-state {
font-weight: 800;
font-size: 10px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#status-card {
position: fixed;
left: 50%;
bottom: 24px;
width: min(590px, calc(100vw - 36px));
padding: 15px 18px 13px;
border-radius: 18px;
transform: translateX(-50%);
pointer-events: none;
}
.status-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
}
#status-title {
margin: 0 0 4px;
font-size: 15px;
font-weight: 850;
letter-spacing: -0.015em;
}
#status-detail {
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
#time {
flex: 0 0 auto;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
font-weight: 800;
letter-spacing: 0.08em;
}
.progress-track {
height: 5px;
margin-top: 12px;
overflow: hidden;
border-radius: 99px;
background: rgba(22, 51, 58, 0.09);
}
#progress {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--amber), var(--teal));
transition: width 80ms linear;
}
#controls {
position: fixed;
left: 22px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: min(470px, calc(100vw - 44px));
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 12px;
color: var(--ink);
background: rgba(250, 253, 251, 0.93);
box-shadow: 0 8px 22px rgba(30, 67, 69, 0.1);
font: inherit;
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition: transform 140ms ease, background 140ms ease;
}
button:hover {
transform: translateY(-2px);
background: #fff;
}
button.primary {
color: #fff;
border-color: transparent;
background: var(--ink);
}
button.primary:hover {
background: #23515a;
}
#help {
position: fixed;
right: 22px;
bottom: 24px;
padding: 10px 13px;
border-radius: 12px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: var(--ink);
background: #dbe7e5;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
#brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle {
display: none;
}
#legend {
top: auto;
right: 12px;
bottom: 134px;
width: 190px;
padding: 10px 12px;
}
#controls {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
}
button {
min-height: 35px;
padding: 0 11px;
font-size: 10px;
}
#status-card {
bottom: 62px;
width: calc(100vw - 24px);
}
#help {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<section id="brand" class="panel">
<div class="eyebrow">Facilities / Supply Operations</div>
<h1>Interleaved Tissue Station</h1>
<div class="subtitle">
A low-poly waiting area demonstrating an empty-unit replacement without
interrupting the clear public aisle.
</div>
</section>
<section id="legend" class="panel">
<div class="legend-row">
<span class="legend-label"><i class="dot green"></i> Unit A</span>
<span id="unit-a" class="unit-state">Ready</span>
</div>
<div class="legend-row">
<span class="legend-label"><i id="unit-b-dot" class="dot red"></i> Unit B</span>
<span id="unit-b" class="unit-state">Empty</span>
</div>
<div class="legend-row">
<span class="legend-label"><i class="dot"></i> Public route</span>
<span class="unit-state">Clear</span>
</div>
<div class="legend-row">
<span class="legend-label"><i class="dot amber"></i> Service spur</span>
<span class="unit-state">Active</span>
</div>
</section>
<section id="status-card" class="panel">
<div class="status-top">
<div>
<h2 id="status-title">Unit B needs service</h2>
<div id="status-detail">Unit A continues serving while B is replenished.</div>
</div>
<div id="time">00.0 / 16.0</div>
</div>
<div class="progress-track"><div id="progress"></div></div>
</section>
<nav id="controls" aria-label="Animation controls">
<button id="pause" class="primary">Pause</button>
<button id="replay">Replay</button>
<button id="room-view">Room view</button>
<button id="service-view">Service view</button>
</nav>
<div id="help" class="panel">
Drag to orbit · Scroll to zoom<br />
Right-drag to pan · Space to pause
</div>
<div id="loading">Building the tissue station…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dbe7e5");
scene.fog = new THREE.Fog("#dbe7e5", 28, 54);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemi = new THREE.HemisphereLight("#f8fffb", "#78928d", 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff3dc", 3.2);
sun.position.set(8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#bce9e3", 1.1);
fill.position.set(-9, 7, 3);
scene.add(fill);
const COLORS = {
ink: "#17363c",
wall: "#edf0e8",
wallSide: "#d7e4df",
floor: "#e8e4d8",
outside: "#b8ccc6",
cream: "#f7f3e8",
teal: "#169c91",
tealLight: "#8fcfc3",
amber: "#f08a45",
coral: "#d9785b",
blue: "#6f9fc0",
red: "#d85c55",
green: "#4aa876",
metal: "#587278",
metalLight: "#9eb1b1",
wood: "#c69a6d",
woodDark: "#946b4d"
};
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
ink: standard(COLORS.ink),
cream: standard(COLORS.cream),
teal: standard(COLORS.teal),
tealLight: standard(COLORS.tealLight),
amber: standard(COLORS.amber),
coral: standard(COLORS.coral),
blue: standard(COLORS.blue),
red: standard(COLORS.red),
green: standard(COLORS.green),
metal: standard(COLORS.metal, { metalness: 0.28, roughness: 0.52 }),
metalLight: standard(COLORS.metalLight, { metalness: 0.25, roughness: 0.5 }),
wood: standard(COLORS.wood),
woodDark: standard(COLORS.woodDark),
white: standard("#fffefa"),
tissue: standard("#fffdf5", { roughness: 0.92 }),
dark: standard("#24383d"),
wall: standard(COLORS.wall),
wallSide: standard(COLORS.wallSide),
floor: standard(COLORS.floor)
};
function mesh(parent, geometry, material, x = 0, y = 0, z = 0) {
const object = new THREE.Mesh(geometry, material);
object.position.set(x, y, z);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(parent, w, h, d, material, x = 0, y = 0, z = 0) {
return mesh(parent, new THREE.BoxGeometry(w, h, d), material, x, y, z);
}
function cylinder(parent, rTop, rBottom, height, material, x = 0, y = 0, z = 0, segments = 8) {
return mesh(
parent,
new THREE.CylinderGeometry(rTop, rBottom, height, segments),
material,
x,
y,
z
);
}
function makeLabel(text, width, height, options = {}) {
const {
background = "rgba(255,255,255,0.92)",
foreground = COLORS.ink,
fontSize = 44,
fontWeight = 800,
dashed = false
} = options;
const c = document.createElement("canvas");
c.width = 768;
c.height = 192;
const ctx = c.getContext("2d");
if (background !== "transparent") {
ctx.fillStyle = background;
ctx.beginPath();
const x = 8;
const y = 8;
const w = c.width - 16;
const h = c.height - 16;
const r = 28;
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
ctx.fill();
if (dashed) {
ctx.strokeStyle = "rgba(240,138,69,0.9)";
ctx.lineWidth = 8;
ctx.setLineDash([18, 12]);
ctx.stroke();
}
}
ctx.fillStyle = foreground;
ctx.font = `${fontWeight} ${fontSize}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, c.width / 2, c.height / 2 + 2, c.width - 44);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
})
);
}
function addFloorLabel(text, x, z, width, height, rotation = 0, options = {}) {
const label = makeLabel(text, width, height, {
background: "transparent",
foreground: options.foreground || "#5c7778",
fontSize: options.fontSize || 42,
fontWeight: options.fontWeight || 800
});
label.rotation.x = -Math.PI / 2;
label.rotation.z = rotation;
label.position.set(x, 0.035, z);
scene.add(label);
return label;
}
function addShadowReceiver(parent, geometry, material, x = 0, y = 0, z = 0) {
const object = mesh(parent, geometry, material, x, y, z);
object.castShadow = false;
object.receiveShadow = true;
return object;
}
// Room shell ------------------------------------------------------
const outside = addShadowReceiver(
scene,
new THREE.PlaneGeometry(45, 40),
standard(COLORS.outside),
0,
-0.07,
0
);
outside.rotation.x = -Math.PI / 2;
const floor = addShadowReceiver(
scene,
new THREE.BoxGeometry(18, 0.18, 12.5),
M.floor,
0,
-0.09,
0
);
box(scene, 18.2, 5.7, 0.24, M.wall, 0, 2.75, -6.25);
box(scene, 0.24, 5.7, 12.5, M.wallSide, -9.1, 2.75, 0);
box(scene, 18, 0.18, 0.14, M.tealLight, 0, 0.12, -6.08);
box(scene, 0.14, 0.18, 12.5, M.tealLight, -8.93, 0.12, 0);
const wallSign = makeLabel("A ⇄ B / INTERLEAVED TISSUE", 4.65, 0.75, {
background: "rgba(255,255,255,0.95)",
foreground: COLORS.ink,
fontSize: 39
});
wallSign.position.set(4.65, 4.45, -6.1);
scene.add(wallSign);
const waitingSign = makeLabel("WAITING AREA", 3.2, 0.65, {
background: "rgba(255,255,255,0.86)",
foreground: COLORS.ink,
fontSize: 43
});
waitingSign.position.set(-3.75, 4.35, -6.1);
scene.add(waitingSign);
// Waiting-area rug and border -------------------------------------
const rugBorder = addShadowReceiver(
scene,
new THREE.PlaneGeometry(8.3, 7.3),
standard("#bfd8cf"),
-3.75,
0.008,
0.85
);
rugBorder.rotation.x = -Math.PI / 2;
const rug = addShadowReceiver(
scene,
new THREE.PlaneGeometry(8.05, 7.05),
standard("#d7e6de"),
-3.75,
0.014,
0.85
);
rug.rotation.x = -Math.PI / 2;
addFloorLabel("WAITING", -3.75, -2.05, 2.7, 0.55, 0, {
foreground: "#72918d",
fontSize: 52
});
// Tables, chairs, and small props ---------------------------------
function createChair(x, z, facingX, facingZ) {
const chair = new THREE.Group();
chair.position.set(x, 0, z);
chair.rotation.y = Math.atan2(facingX, facingZ);
scene.add(chair);
box(chair, 0.64, 0.13, 0.62, M.teal, 0, 0.48, 0);
box(chair, 0.64, 0.68, 0.12, M.teal, 0, 0.86, -0.27);
box(chair, 0.08, 0.48, 0.08, M.metal, -0.25, 0.23, 0.21);
box(chair, 0.08, 0.48, 0.08, M.metal, 0.25, 0.23, 0.21);
box(chair, 0.08, 0.48, 0.08, M.metal, -0.25, 0.23, -0.21);
box(chair, 0.08, 0.48, 0.08, M.metal, 0.25, 0.23, -0.21);
return chair;
}
function createTable(x, z) {
const table = new THREE.Group();
table.position.set(x, 0, z);
scene.add(table);
cylinder(table, 1.05, 1.05, 0.16, M.wood, 0, 0.91, 0, 12);
cylinder(table, 0.13, 0.22, 0.82, M.metal, 0, 0.43, 0, 8);
cylinder(table, 0.55, 0.55, 0.09, M.metal, 0, 0.055, 0, 10);
const radius = 1.45;
createChair(x, z + radius, 0, -1);
createChair(x, z - radius, 0, 1);
createChair(x - radius, z, 1, 0);
createChair(x + radius, z, -1, 0);
cylinder(table, 0.12, 0.1, 0.2, M.white, 0.38, 1.08, 0.1, 8);
const magazine = box(table, 0.36, 0.035, 0.25, M.coral, -0.32, 1.015, -0.08);
magazine.rotation.y = 0.35;
}
createTable(-4.75, 0.05);
createTable(-1.85, 3.25);
// Organized wall shelving -----------------------------------------
const rack = new THREE.Group();
rack.position.set(-6.55, 0, -5.55);
scene.add(rack);
for (const x of [-1.55, 1.55]) {
for (const z of [-0.38, 0.38]) {
box(rack, 0.08, 2.9, 0.08, M.metal, x, 1.45, z);
}
}
for (const y of [0.28, 1.12, 1.96, 2.8]) {
box(rack, 3.25, 0.08, 0.82, M.metalLight, 0, y, 0);
}
const rackColors = [M.tealLight, M.amber, M.blue];
const rackLabels = ["A PACKS", "B PACKS", "SPARES"];
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 3; col++) {
const bin = new THREE.Group();
bin.position.set(-1.02 + col * 1.02, 0.39 + row * 0.84, 0.02);
rack.add(bin);
box(bin, 0.78, 0.48, 0.6, rackColors[(row + col) % 3], 0, 0, 0);
box(bin, 0.65, 0.035, 0.47, M.white, 0, 0.26, 0);
const label = makeLabel(`${rackLabels[col]} ${row + 1}`, 0.66, 0.22, {
background: "rgba(255,255,255,0.88)",
foreground: COLORS.ink,
fontSize: 30
});
label.position.set(0, 0.01, 0.306);
bin.add(label);
}
}
const rackSign = makeLabel("SEALED SUPPLIES", 2.8, 0.43, {
background: "rgba(255,255,255,0.9)",
foreground: COLORS.ink,
fontSize: 38
});
rackSign.position.set(0, 3.18, 0);
rack.add(rackSign);
// Route markings ---------------------------------------------------
const publicLane = addShadowReceiver(
scene,
new THREE.PlaneGeometry(1.08, 9.25),
new THREE.MeshBasicMaterial({
color: COLORS.teal,
transparent: true,
opacity: 0.1,
depthWrite: false
}),
8.28,
0.021,
0.55
);
publicLane.rotation.x = -Math.PI / 2;
function dashedPath(points, color, width = 0.075, dash = 0.32, gap = 0.18) {
const group = new THREE.Group();
scene.add(group);
const material = standard(color, {
emissive: color,
emissiveIntensity: 0.12
});
for (let i = 0; i < points.length - 1; i++) {
const [x1, z1] = points[i];
const [x2, z2] = points[i + 1];
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const count = Math.max(1, Math.floor(length / (dash + gap)));
for (let j = 0; j < count; j++) {
const t = (j + 0.5) / count;
const piece = box(
group,
dash,
0.022,
width,
material,
x1 + dx * t,
0.032,
z1 + dz * t
);
piece.rotation.y = -Math.atan2(dz, dx);
piece.castShadow = false;
}
}
return group;
}
function addArrow(x, z, dx, dz, color) {
const group = new THREE.Group();
group.position.set(x, 0.05, z);
group.rotation.y = -Math.atan2(dz, dx);
scene.add(group);
const arrow = mesh(
group,
new THREE.ConeGeometry(0.16, 0.43, 3),
standard(color, { emissive: color, emissiveIntensity: 0.08 }),
0,
0,
0
);
arrow.rotation.z = -Math.PI / 2;
}
const publicRoute = [
[8.28, 5.1],
[8.28, -3.92],
[2.8, -3.92]
];
const serviceRoute = [
[6.65, 2.02],
[7.45, 1.45],
[7.45, -3.22],
[5.7, -3.22],
[5.7, -4.12]
];
dashedPath(publicRoute, COLORS.teal, 0.09, 0.34, 0.2);
dashedPath(serviceRoute, COLORS.amber, 0.075, 0.25, 0.2);
addArrow(8.28, 3.7, 0, -1, COLORS.teal);
addArrow(8.28, -1.1, 0, -1, COLORS.teal);
addArrow(4.6, -3.92, -1, 0, COLORS.teal);
addArrow(7.45, -0.55, 0, -1, COLORS.amber);
addArrow(5.7, -3.55, 0, -1, COLORS.amber);
addFloorLabel("PUBLIC AISLE", 8.27, 1.65, 2.35, 0.42, Math.PI / 2, {
foreground: "#438d87",
fontSize: 38
});
addFloorLabel("SERVICE", 7.43, -0.85, 1.55, 0.34, Math.PI / 2, {
foreground: "#c66f3f",
fontSize: 36
});
// Dispenser factory -------------------------------------------------
function createDispenser(labelText, accentColor, labelBackground = "rgba(255,255,255,0.94)") {
const group = new THREE.Group();
box(group, 1.17, 1.67, 0.47, M.cream, 0, 0, 0);
box(group, 1.24, 0.12, 0.52, standard(accentColor), 0, 0.87, 0);
box(group, 0.11, 1.54, 0.08, standard(accentColor), -0.52, 0, 0.25);
box(group, 1.02, 1.44, 0.055, standard("#edf1e9"), 0, 0, 0.25);
box(group, 0.68, 0.29, 0.035, M.dark, 0, -0.16, 0.29);
box(group, 0.54, 0.035, 0.045, M.metalLight, 0, -0.305, 0.315);
const statusMaterial = standard(COLORS.green, {
emissive: COLORS.green,
emissiveIntensity: 0.65
});
const statusLight = mesh(
group,
new THREE.SphereGeometry(0.075, 8, 6),
statusMaterial,
0.44,
0.64,
0.315
);
const label = makeLabel(labelText, 0.76, 0.25, {
background: labelBackground,
foreground: COLORS.ink,
fontSize: 34
});
label.position.set(-0.12, 0.39, 0.32);
group.add(label);
const tissueStack = new THREE.Group();
tissueStack.position.set(0, 0, 0.328);
group.add(tissueStack);
for (let i = 0; i < 4; i++) {
const sheet = box(
tissueStack,
0.48 - i * 0.025,
0.027,
0.025,
M.tissue,
(i % 2 ? 0.015 : -0.01),
-0.065 + i * 0.031,
i * 0.002
);
sheet.rotation.z = i % 2 ? 0.025 : -0.02;
}
const hanging = new THREE.Group();
hanging.position.set(0, -0.025, 0.355);
hanging.scale.y = 0.08;
group.add(hanging);
const hangingSheet = box(hanging, 0.46, 0.64, 0.022, M.tissue, 0, -0.32, 0);
hangingSheet.rotation.z = -0.025;
return {
group,
statusLight,
statusMaterial,
tissueStack,
hanging
};
}
const unitA = createDispenser("A / READY", COLORS.teal);
unitA.group.position.set(3.6, 2.13, -5.87);
scene.add(unitA.group);
const unitBOld = createDispenser("B / EMPTY", COLORS.red);
unitBOld.group.position.set(5.7, 2.13, -5.87);
unitBOld.tissueStack.visible = false;
unitBOld.statusMaterial.color.set(COLORS.red);
unitBOld.statusMaterial.emissive.set(COLORS.red);
scene.add(unitBOld.group);
const unitBNew = createDispenser("B / READY", COLORS.teal);
unitBNew.group.position.set(5.7, 2.13, -5.87);
unitBNew.group.visible = false;
scene.add(unitBNew.group);
// Empty-unit floor beacon.
const beaconMaterial = new THREE.MeshBasicMaterial({
color: COLORS.amber,
transparent: true,
opacity: 0.6,
depthWrite: false
});
const beacon = mesh(
scene,
new THREE.TorusGeometry(0.47, 0.035, 6, 24),
beaconMaterial,
5.7,
0.055,
-4.55
);
beacon.rotation.x = Math.PI / 2;
beacon.castShadow = false;
// Supply cart --------------------------------------------------------
const cart = new THREE.Group();
cart.position.set(6.65, 0, 0.85);
scene.add(cart);
for (const x of [-0.93, 0.93]) {
for (const z of [-0.49, 0.49]) {
box(cart, 0.075, 1.85, 0.075, M.metal, x, 0.96, z);
}
}
box(cart, 2.04, 0.09, 1.1, M.metalLight, 0, 0.3, 0);
box(cart, 2.04, 0.09, 1.1, M.metalLight, 0, 1.48, 0);
for (const x of [-0.78, 0.78]) {
for (const z of [-0.43, 0.43]) {
const wheel = cylinder(cart, 0.18, 0.18, 0.12, M.dark, x, 0.18, z, 10);
wheel.rotation.z = Math.PI / 2;
const hub = cylinder(cart, 0.075, 0.075, 0.13, M.metalLight, x, 0.18, z, 8);
hub.rotation.z = Math.PI / 2;
}
}
box(cart, 0.08, 0.95, 0.08, M.amber, 1.02, 1.94, -0.43);
box(cart, 0.08, 0.95, 0.08, M.amber, 1.02, 1.94, 0.43);
box(cart, 0.08, 0.08, 0.94, M.amber, 1.02, 2.39, 0);
const cartLabel = makeLabel("SORTED SUPPLY CART", 1.78, 0.32, {
background: "rgba(255,255,255,0.93)",
foreground: COLORS.ink,
fontSize: 32
});
cartLabel.position.set(0, 1.48, 0.56);
cart.add(cartLabel);
const trayColors = [M.tealLight, M.amber, M.blue];
const trayLabels = ["A PACKS", "B PACKS", "SPARES"];
for (let i = 0; i < 3; i++) {
const x = -0.66 + i * 0.66;
box(cart, 0.56, 0.3, 0.69, trayColors[i], x, 1.68, 0);
box(cart, 0.47, 0.025, 0.57, M.white, x, 1.85, 0);
const label = makeLabel(trayLabels[i], 0.52, 0.19, {
background: "rgba(255,255,255,0.9)",
foreground: COLORS.ink,
fontSize: 27
});
label.position.set(x, 1.69, 0.355);
cart.add(label);
}
const replacementOnCart = createDispenser("B / SEALED", COLORS.teal);
replacementOnCart.group.scale.setScalar(0.66);
replacementOnCart.group.position.set(0, 0.86, 0);
cart.add(replacementOnCart.group);
const returnedOldUnit = createDispenser("B / EMPTY", COLORS.red);
returnedOldUnit.group.scale.setScalar(0.66);
returnedOldUnit.group.position.set(0, 0.86, 0);
returnedOldUnit.group.visible = false;
returnedOldUnit.tissueStack.visible = false;
cart.add(returnedOldUnit.group);
// Technician ---------------------------------------------------------
function createWorker() {
const worker = new THREE.Group();
scene.add(worker);
const scrubs = standard("#258c88");
const vest = standard("#e77750");
const skin = standard("#c98864");
const hair = standard("#293c3e");
box(worker, 0.56, 0.67, 0.34, scrubs, 0, 1.13, 0);
box(worker, 0.59, 0.31, 0.37, vest, 0, 1.26, 0);
const head = mesh(
worker,
new THREE.DodecahedronGeometry(0.235, 0),
skin,
0,
1.68,
0
);
head.scale.set(0.92, 1.06, 0.92);
const hairCap = mesh(
worker,
new THREE.DodecahedronGeometry(0.23, 0),
hair,
0,
1.79,
-0.025
);
hairCap.scale.set(0.94, 0.6, 0.94);
const legL = new THREE.Group();
const legR = new THREE.Group();
legL.position.set(-0.16, 0.82, 0);
legR.position.set(0.16, 0.82, 0);
worker.add(legL, legR);
box(legL, 0.2, 0.67, 0.22, scrubs, 0, -0.34, 0);
box(legR, 0.2, 0.67, 0.22, scrubs, 0, -0.34, 0);
box(legL, 0.23, 0.14, 0.37, M.dark, 0, -0.72, 0.07);
box(legR, 0.23, 0.14, 0.37, M.dark, 0, -0.72, 0.07);
const armL = new THREE.Group();
const armR = new THREE.Group();
armL.position.set(-0.38, 1.39, 0);
armR.position.set(0.38, 1.39, 0);
worker.add(armL, armR);
box(armL, 0.17, 0.55, 0.19, vest, 0, -0.27, 0);
box(armR, 0.17, 0.55, 0.19, vest, 0, -0.27, 0);
box(armL, 0.16, 0.17, 0.17, skin, 0, -0.61, 0);
box(armR, 0.16, 0.17, 0.17, skin, 0, -0.61, 0);
return { group: worker, legL, legR, armL, armR };
}
const technician = createWorker();
const carriedNew = createDispenser("B / SEALED", COLORS.teal);
carriedNew.group.scale.setScalar(0.58);
carriedNew.group.position.set(0, 1.03, 0.62);
carriedNew.group.visible = false;
technician.group.add(carriedNew.group);
const carriedOld = createDispenser("B / EMPTY", COLORS.red);
carriedOld.group.scale.setScalar(0.55);
carriedOld.group.position.set(0, 1.02, 0.62);
carriedOld.group.visible = false;
carriedOld.tissueStack.visible = false;
technician.group.add(carriedOld.group);
// Decorative low-poly plant.
const plant = new THREE.Group();
plant.position.set(-8.05, 0, 4.45);
scene.add(plant);
cylinder(plant, 0.36, 0.27, 0.62, M.coral, 0, 0.31, 0, 7);
cylinder(plant, 0.035, 0.045, 1.25, M.woodDark, 0, 1.05, 0, 6);
const leafMaterial = standard("#4f9b70");
for (let i = 0; i < 7; i++) {
const leaf = mesh(
plant,
new THREE.ConeGeometry(0.27, 0.85, 5),
leafMaterial,
0,
1.35 + i * 0.07,
0
);
leaf.rotation.z = (i % 2 ? 1 : -1) * 0.62;
leaf.rotation.x = (i - 3) * 0.12;
}
// Camera controls, implemented without addons ------------------------
const cameraState = {
target: new THREE.Vector3(-0.8, 0.8, 0.15),
goalTarget: new THREE.Vector3(-0.8, 0.8, 0.15),
radius: 22.5,
goalRadius: 22.5,
theta: 0.72,
goalTheta: 0.72,
phi: 0.76,
goalPhi: 0.76
};
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-dt * 7);
cameraState.target.lerp(cameraState.goalTarget, smoothing);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.goalRadius,
smoothing
);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.goalTheta,
smoothing
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.goalPhi,
smoothing
);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function setRoomView() {
cameraState.goalTarget.set(-0.8, 0.8, 0.15);
cameraState.goalRadius = 22.5;
cameraState.goalTheta = 0.72;
cameraState.goalPhi = 0.76;
}
function setServiceView() {
cameraState.goalTarget.set(4.8, 1.55, -3.55);
cameraState.goalRadius = 10.2;
cameraState.goalTheta = 0.5;
cameraState.goalPhi = 0.78;
}
let dragging = false;
let panning = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (panning) {
const scale = cameraState.radius * 0.0015;
const right = new THREE.Vector3(
Math.cos(cameraState.theta),
0,
-Math.sin(cameraState.theta)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.theta),
0,
-Math.cos(cameraState.theta)
);
cameraState.goalTarget.addScaledVector(right, -dx * scale);
cameraState.goalTarget.addScaledVector(forward, -dy * scale);
} else {
cameraState.goalTheta -= dx * 0.006;
cameraState.goalPhi = THREE.MathUtils.clamp(
cameraState.goalPhi + dy * 0.005,
0.42,
1.25
);
}
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.goalRadius = THREE.MathUtils.clamp(
cameraState.goalRadius * Math.exp(event.deltaY * 0.001),
8,
31
);
},
{ passive: false }
);
// Demo timeline -------------------------------------------------------
const DURATION = 16;
let demoTime = 0;
let paused = false;
let walkPhase = 0;
const start = new THREE.Vector3(7.55, 0, 4.48);
const pickup = new THREE.Vector3(6.65, 0, 2.02);
const outwardPath = [
pickup.clone(),
new THREE.Vector3(7.45, 0, 1.45),
new THREE.Vector3(7.45, 0, -3.22),
new THREE.Vector3(5.7, 0, -3.22),
new THREE.Vector3(5.7, 0, -4.12)
];
const returnPath = [...outwardPath].reverse().map((point) => point.clone());
function samplePath(path, t) {
const lengths = [];
let total = 0;
for (let i = 0; i < path.length - 1; i++) {
const length = path[i].distanceTo(path[i + 1]);
lengths.push(length);
total += length;
}
let distance = THREE.MathUtils.clamp(t, 0, 1) * total;
for (let i = 0; i < lengths.length; i++) {
if (distance <= lengths[i] || i === lengths.length - 1) {
const amount = THREE.MathUtils.clamp(distance / lengths[i], 0, 1);
const position = path[i].clone().lerp(path[i + 1], amount);
const direction = path[i + 1].clone().sub(path[i]);
const angle = Math.atan2(direction.x, direction.z);
return { position, angle };
}
distance -= lengths[i];
}
return { position: path[path.length - 1].clone(), angle: Math.PI };
}
function resetDemo() {
demoTime = 0;
walkPhase = 0;
paused = false;
technician.group.position.copy(start);
technician.group.rotation.y = Math.PI;
document.querySelector("#pause").textContent = "Pause";
updateDemo(0, 0);
}
function updateDemo(time, dt) {
const t = time;
unitBOld.group.visible = t < 7.0;
unitBNew.group.visible = t >= 7.35;
replacementOnCart.group.visible = t < 2.55;
returnedOldUnit.group.visible = t >= 12.5;
carriedNew.group.visible = t >= 2.55 && t < 7.35;
carriedOld.group.visible = t >= 7.0 && t < 12.5;
let desiredPosition = start.clone();
let desiredAngle = Math.PI;
if (t < 1.3) {
desiredPosition = start.clone();
desiredAngle = Math.PI;
} else if (t < 2.7) {
const amount = (t - 1.3) / 1.4;
desiredPosition = start.clone().lerp(pickup, amount);
const direction = pickup.clone().sub(start);
desiredAngle = Math.atan2(direction.x, direction.z);
} else if (t < 6.8) {
const sample = samplePath(outwardPath, (t - 2.7) / 4.1);
desiredPosition = sample.position;
desiredAngle = sample.angle;
} else if (t < 8.3) {
desiredPosition = outwardPath[outwardPath.length - 1].clone();
desiredAngle = Math.PI;
} else if (t < 12.5) {
const sample = samplePath(returnPath, (t - 8.3) / 4.2);
desiredPosition = sample.position;
desiredAngle = sample.angle;
} else if (t < 15.8) {
const amount = (t - 12.5) / 3.3;
desiredPosition = pickup.clone().lerp(start, amount);
const direction = start.clone().sub(pickup);
desiredAngle = Math.atan2(direction.x, direction.z);
}
const previousX = technician.group.position.x;
const previousZ = technician.group.position.z;
technician.group.position.lerp(desiredPosition, 1 - Math.exp(-dt * 15));
technician.group.rotation.y = desiredAngle;
const moved = Math.hypot(
technician.group.position.x - previousX,
technician.group.position.z - previousZ
);
const walking = moved > 0.001;
if (walking) {
walkPhase += dt * 10;
}
const swing = walking ? Math.sin(walkPhase) * 0.55 : 0;
technician.legL.rotation.x = swing;
technician.legR.rotation.x = -swing;
const carrying = t >= 2.55 && t < 12.5;
technician.armL.rotation.x = carrying ? -1.12 : -swing * 0.72;
technician.armR.rotation.x = carrying ? -1.12 : swing * 0.72;
// The old unit and its status beacon blink until replacement.
const pulse = 0.5 + 0.5 * Math.sin(t * 5.5);
unitBOld.statusMaterial.emissiveIntensity = 0.25 + pulse * 0.85;
beaconMaterial.opacity = 0.28 + pulse * 0.42;
beacon.scale.setScalar(0.95 + pulse * 0.1);
beacon.visible = t < 7.35;
// A and B alternate after B becomes available.
const slotDuration = 2.4;
const activeSlot = Math.floor(t / slotDuration) % 2;
const localProgress = t % slotDuration;
function updateServing(dispenser, active, ready) {
dispenser.tissueStack.visible = ready;
const extending = active && ready && localProgress < 0.86;
dispenser.hanging.visible = extending;
if (extending) {
const amount = localProgress / 0.86;
dispenser.hanging.scale.y = 0.08 + amount * 0.92;
dispenser.hanging.rotation.z = Math.sin(amount * Math.PI) * 0.035;
}
}
const bReady = t >= 7.35;
const effectiveSlot = activeSlot === 1 && !bReady ? 0 : activeSlot;
updateServing(unitA, effectiveSlot === 0, true);
updateServing(unitBNew, effectiveSlot === 1, bReady);
unitA.statusMaterial.color.set(COLORS.green);
unitA.statusMaterial.emissive.set(COLORS.green);
unitA.statusMaterial.emissiveIntensity = effectiveSlot === 0 ? 0.75 : 0.3;
unitBNew.statusMaterial.color.set(COLORS.green);
unitBNew.statusMaterial.emissive.set(COLORS.green);
unitBNew.statusMaterial.emissiveIntensity = effectiveSlot === 1 ? 0.75 : 0.3;
updateStatusUI(t, effectiveSlot);
}
function updateStatusUI(t, activeSlot) {
let title;
let detail;
if (t < 1.3) {
title = "Unit B needs service";
detail = "Unit A continues serving while the empty B unit is identified.";
} else if (t < 2.7) {
title = "Collecting a sealed replacement";
detail = "The technician takes the labeled B unit from the sorted cart.";
} else if (t < 6.8) {
title = "Following the amber service spur";
detail = "The public aisle remains clear while the replacement is carried to B.";
} else if (t < 8.3) {
title = "Replacing and testing unit B";
detail = "The empty housing is removed and the sealed replacement is mounted.";
} else if (t < 12.5) {
title = "Returning the empty housing";
detail = "Both dispensers are available again; the removed unit returns to the cart.";
} else if (t < 15.8) {
title = "Restoring the organized station";
detail = "The empty housing is placed in its designated return bay.";
} else {
title = "Replacement complete";
detail = "Units A and B now alternate service with all routes remaining clear.";
}
document.querySelector("#status-title").textContent = title;
document.querySelector("#status-detail").textContent = detail;
document.querySelector("#progress").style.width = `${Math.min(100, (t / DURATION) * 100)}%`;
document.querySelector("#time").textContent = `${t.toFixed(1).padStart(4, "0")} / ${DURATION.toFixed(1)}`;
const unitAText = document.querySelector("#unit-a");
const unitBText = document.querySelector("#unit-b");
const unitBDot = document.querySelector("#unit-b-dot");
unitAText.textContent = activeSlot === 0 ? "Serving" : "Ready";
unitBText.textContent = t < 7.35 ? "Empty" : activeSlot === 1 ? "Serving" : "Ready";
unitBDot.className = t < 7.35 ? "dot red" : "dot green";
}
// UI actions ----------------------------------------------------------
const pauseButton = document.querySelector("#pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
document.querySelector("#replay").addEventListener("click", resetDemo);
document.querySelector("#room-view").addEventListener("click", setRoomView);
document.querySelector("#service-view").addEventListener("click", setServiceView);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetDemo();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// Animation loop ------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) {
demoTime = Math.min(DURATION, demoTime + dt);
}
updateDemo(demoTime, dt);
updateCamera(dt);
renderer.render(scene, camera);
}
resetDemo();
updateCamera(1);
renderer.render(scene, camera);
loading.classList.add("hidden");
animate();
</script>
</body>
</html>
```