Prompt specification
Build or customize the Three.js 3D scene "Batch Tray With Empty Slots" 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: Batch Tray With Empty Slots
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/batch-tray-with-empty-slots-x3193
Scene Description Prompt:
Please make a low-poly Three.js scene in one standalone HTML file using cdnjs. Model a single carrying tray with eight cup-shaped slots and a handle. Compare carrying one cup with a full batch while preserving identical tray travel distance.
Working Three.js Starter (batch-tray-with-empty-slots-x3193):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tray Carry — Controlled Load Comparison</title>
<style>
:root {
--ink: #18333b;
--muted: #60757a;
--paper: #f4efe4;
--orange: #e87550;
--teal: #237c76;
--gold: #e6b94f;
--active: var(--orange);
--panel: rgba(250, 247, 239, 0.88);
--border: rgba(24, 51, 59, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e2d5;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.hero {
position: absolute;
top: 28px;
left: 32px;
width: min(520px, calc(100vw - 64px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 26px;
height: 3px;
background: var(--active);
border-radius: 3px;
transition: background 180ms ease;
}
h1 {
margin: 0;
max-width: 500px;
font-size: clamp(34px, 5vw, 66px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 850;
}
h1 em {
color: var(--active);
font-style: normal;
transition: color 180ms ease;
}
.hero p {
max-width: 440px;
margin: 15px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.camera-help {
position: absolute;
top: 28px;
right: 30px;
display: flex;
align-items: center;
gap: 12px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
}
.camera-help button {
pointer-events: auto;
border: 1px solid var(--border);
border-radius: 999px;
padding: 9px 13px;
color: var(--ink);
background: rgba(250, 247, 239, 0.75);
cursor: pointer;
backdrop-filter: blur(10px);
}
.camera-help button:hover {
background: #fffaf0;
}
.control-panel,
.comparison-panel {
pointer-events: auto;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.65);
box-shadow:
0 18px 60px rgba(49, 54, 50, 0.13),
0 2px 8px rgba(49, 54, 50, 0.06);
backdrop-filter: blur(16px);
}
.control-panel {
position: absolute;
left: 30px;
bottom: 28px;
width: 372px;
padding: 18px;
border-radius: 22px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.panel-heading strong {
font-size: 13px;
letter-spacing: 0.02em;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--active);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--active) 18%, transparent);
transition: background 180ms ease;
}
.scenario-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.scenario {
position: relative;
min-height: 92px;
padding: 14px;
overflow: hidden;
text-align: left;
color: var(--ink);
background: rgba(255, 255, 255, 0.48);
border: 1px solid var(--border);
border-radius: 15px;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
.scenario:hover {
transform: translateY(-2px);
background: rgba(255, 255, 255, 0.78);
}
.scenario.active {
color: white;
border-color: transparent;
background: var(--active);
box-shadow: 0 8px 20px color-mix(in srgb, var(--active) 26%, transparent);
}
.scenario .number {
display: block;
margin-bottom: 6px;
font-size: 25px;
font-weight: 850;
line-height: 1;
}
.scenario .label {
display: block;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.scenario .distance {
display: block;
margin-top: 5px;
opacity: 0.72;
font-size: 10px;
font-weight: 700;
}
.route-lock {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 4px 12px;
margin: 14px 0 12px;
padding: 12px 13px;
border: 1px dashed rgba(24, 51, 59, 0.22);
border-radius: 13px;
background: rgba(255, 255, 255, 0.35);
}
.route-lock span {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.route-lock b {
font-size: 13px;
}
.route-lock small {
color: var(--muted);
font-size: 10px;
}
.progress-track {
grid-column: 1 / -1;
height: 4px;
margin-top: 5px;
overflow: hidden;
border-radius: 4px;
background: rgba(24, 51, 59, 0.1);
}
.progress-fill {
width: 0%;
height: 100%;
border-radius: inherit;
background: var(--active);
transition: background 180ms ease;
}
.run-button {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
min-height: 45px;
border: 0;
border-radius: 13px;
color: white;
background: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.025em;
cursor: pointer;
transition:
transform 160ms ease,
opacity 160ms ease;
}
.run-button:hover {
transform: translateY(-1px);
}
.run-button:active {
transform: translateY(1px);
}
.run-button:disabled {
cursor: default;
opacity: 0.72;
transform: none;
}
.keyboard-note {
margin-top: 10px;
color: var(--muted);
font-size: 10px;
text-align: center;
}
.comparison-panel {
position: absolute;
right: 30px;
bottom: 28px;
width: 330px;
padding: 18px;
border-radius: 22px;
}
.comparison-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
}
.comparison-title strong {
font-size: 13px;
}
.locked-pill {
padding: 5px 8px;
border-radius: 999px;
color: var(--teal);
background: rgba(35, 124, 118, 0.1);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.comparison-row {
display: grid;
grid-template-columns: 32px 1fr auto;
align-items: center;
gap: 10px;
padding: 11px 0;
border-top: 1px solid var(--border);
}
.load-badge {
display: grid;
place-items: center;
width: 30px;
height: 30px;
border-radius: 9px;
color: white;
background: var(--orange);
font-size: 12px;
font-weight: 850;
}
.comparison-row.full .load-badge {
background: var(--teal);
}
.comparison-row strong {
display: block;
font-size: 11px;
}
.comparison-row small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.equal-distance {
font-size: 12px;
font-weight: 850;
}
.distance-bars {
margin-top: 8px;
padding-top: 13px;
border-top: 1px solid var(--border);
}
.bar-row {
display: grid;
grid-template-columns: 46px 1fr 45px;
align-items: center;
gap: 8px;
margin: 9px 0;
color: var(--muted);
font-size: 9px;
font-weight: 800;
}
.bar {
height: 6px;
overflow: hidden;
border-radius: 6px;
background: rgba(24, 51, 59, 0.08);
}
.bar > span {
display: block;
width: 100%;
height: 100%;
border-radius: inherit;
background: var(--orange);
}
.bar.full > span {
background: var(--teal);
}
.bar-row b {
color: var(--ink);
text-align: right;
}
.comparison-footer {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--border);
color: var(--muted);
font-size: 9px;
font-weight: 750;
}
.comparison-footer b {
color: var(--ink);
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: var(--ink);
background: #e9e2d5;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 880px) {
.camera-help span {
display: none;
}
.comparison-panel {
width: 290px;
}
.control-panel {
width: 340px;
}
}
@media (max-width: 700px) {
.hero {
top: 18px;
left: 18px;
}
.hero p {
max-width: 330px;
font-size: 12px;
}
.camera-help {
top: 18px;
right: 18px;
}
.control-panel {
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
padding: 14px;
border-radius: 18px;
}
.comparison-panel {
display: none;
}
.scenario {
min-height: 77px;
padding: 11px;
}
.route-lock {
margin: 10px 0;
padding: 9px 11px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<header class="hero">
<div class="eyebrow">Controlled carry study · 08 slots</div>
<h1>Same journey.<br /><em>Different load.</em></h1>
<p>
One low-poly tray, two payload states. Switch between a single cup and
a full batch, then run the same fixed 3.60-meter route.
</p>
</header>
<div class="camera-help">
<span>Drag to orbit · Scroll to zoom</span>
<button id="resetCamera" type="button">Reset view</button>
</div>
<section class="control-panel" aria-label="Carry comparison controls">
<div class="panel-heading">
<strong>Choose payload</strong>
<span class="status" id="currentStatus">One cup</span>
</div>
<div class="scenario-grid">
<button
class="scenario active"
data-load="1"
type="button"
aria-pressed="true"
>
<span class="number">1</span>
<span class="label">Cup</span>
<span class="distance">3.60 m route</span>
</button>
<button
class="scenario"
data-load="8"
type="button"
aria-pressed="false"
>
<span class="number">8</span>
<span class="label">Cup batch</span>
<span class="distance">3.60 m route</span>
</button>
</div>
<div class="route-lock">
<span>Distance lock</span>
<b>3.60 m</b>
<small id="routeState">Ready · fixed one-way route</small>
<div class="progress-track" aria-hidden="true">
<div class="progress-fill" id="progressFill"></div>
</div>
</div>
<button class="run-button" id="runRoute" type="button">
▶ Run identical route
</button>
<div class="keyboard-note">Keyboard: 1 / 8 to switch · Space to run</div>
</section>
<aside class="comparison-panel" aria-label="Comparison summary">
<div class="comparison-title">
<strong>Controlled comparison</strong>
<span class="locked-pill">Distance locked</span>
</div>
<div class="comparison-row">
<div class="load-badge">1</div>
<div>
<strong>One cup</strong>
<small>Single occupied slot</small>
</div>
<div class="equal-distance">3.60 m</div>
</div>
<div class="comparison-row full">
<div class="load-badge">8</div>
<div>
<strong>Full batch</strong>
<small>All eight slots occupied</small>
</div>
<div class="equal-distance">3.60 m</div>
</div>
<div class="distance-bars" aria-hidden="true">
<div class="bar-row">
<span>ONE CUP</span>
<div class="bar"><span></span></div>
<b>3.60 m</b>
</div>
<div class="bar-row">
<span>FULL</span>
<div class="bar full"><span></span></div>
<b>3.60 m</b>
</div>
</div>
<div class="comparison-footer">
<span>Fixed speed <b>0.75 m/s</b></span>
<span>Same tray <b>100%</b></span>
</div>
</aside>
</div>
<div id="loading">Building the carry scene…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e2d5);
scene.fog = new THREE.Fog(0xe9e2d5, 14, 27);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 0.75, 0);
let cameraYaw = 0.67;
let cameraPitch = 0.73;
let cameraRadius = 10.8;
let desiredYaw = cameraYaw;
let desiredPitch = cameraPitch;
let desiredRadius = cameraRadius;
function updateCamera() {
cameraYaw = THREE.MathUtils.lerp(cameraYaw, desiredYaw, 0.08);
cameraPitch = THREE.MathUtils.lerp(cameraPitch, desiredPitch, 0.08);
cameraRadius = THREE.MathUtils.lerp(cameraRadius, desiredRadius, 0.08);
const horizontal = cameraRadius * Math.sin(cameraPitch);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraYaw),
cameraTarget.y + cameraRadius * Math.cos(cameraPitch),
cameraTarget.z + horizontal * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfff7df,
0x8ca6a0,
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d4, 3.4);
sun.position.set(5, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9d6, 1.1);
fill.position.set(-6, 4, -5);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const materials = {
plate: new THREE.MeshStandardMaterial({
color: 0x245c5e,
roughness: 0.68,
metalness: 0.06,
flatShading: true
}),
underside: new THREE.MeshStandardMaterial({
color: 0x163b42,
roughness: 0.78,
flatShading: true
}),
liner: new THREE.MeshStandardMaterial({
color: 0x102c33,
roughness: 0.9,
side: THREE.DoubleSide,
flatShading: true
}),
rim: new THREE.MeshStandardMaterial({
color: 0xe8b94d,
roughness: 0.55,
metalness: 0.1,
flatShading: true
}),
handle: new THREE.MeshStandardMaterial({
color: 0xe87550,
roughness: 0.56,
flatShading: true
}),
grip: new THREE.MeshStandardMaterial({
color: 0x18333b,
roughness: 0.85,
flatShading: true
}),
cup: new THREE.MeshStandardMaterial({
color: 0xf7edda,
roughness: 0.8,
side: THREE.DoubleSide,
flatShading: true
}),
coffee: new THREE.MeshStandardMaterial({
color: 0x4d2d24,
roughness: 0.36,
side: THREE.DoubleSide
}),
floor: new THREE.MeshStandardMaterial({
color: 0xe4ddce,
roughness: 0.96
}),
route: new THREE.MeshStandardMaterial({
color: 0xd99b55,
roughness: 0.78
}),
routeDark: new THREE.MeshStandardMaterial({
color: 0x718b86,
roughness: 0.85
})
};
const sleeveMaterials = [
0xe87550,
0x237c76,
0xe8b94d,
0x446d7c
].map(
color =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
side: THREE.DoubleSide,
flatShading: true
})
);
// -------------------------------------------------------------------------
// Floor, route, and environmental accents
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const routeLine = new THREE.Mesh(
new THREE.BoxGeometry(4.25, 0.025, 0.10),
materials.route
);
routeLine.position.set(0, 0.026, 0);
routeLine.receiveShadow = true;
scene.add(routeLine);
for (let x = -1.8; x <= 1.81; x += 0.6) {
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 0.032, 0.19),
materials.routeDark
);
tick.position.set(x, 0.038, 0);
tick.receiveShadow = true;
scene.add(tick);
}
function makeRouteRing(x, color) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.23, 0.026, 4, 12),
new THREE.MeshStandardMaterial({
color,
roughness: 0.7,
flatShading: true
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, 0.055, 0);
ring.castShadow = true;
scene.add(ring);
}
makeRouteRing(-1.8, 0xe87550);
makeRouteRing(1.8, 0x237c76);
function makeTextSprite(text, color = "#18333b") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(244, 239, 228, 0.82)";
context.beginPath();
context.roundRect(8, 12, 496, 104, 28);
context.fill();
context.strokeStyle = "rgba(24, 51, 59, 0.13)";
context.lineWidth = 4;
context.stroke();
context.fillStyle = color;
context.font = "800 48px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.35, 0.3375, 1);
sprite.renderOrder = 5;
return sprite;
}
const startLabel = makeTextSprite("START", "#b65135");
startLabel.position.set(-2.35, 0.28, 0);
scene.add(startLabel);
const finishLabel = makeTextSprite("FINISH", "#237c76");
finishLabel.position.set(2.35, 0.28, 0);
scene.add(finishLabel);
const rockMaterialA = new THREE.MeshStandardMaterial({
color: 0xc7c8b4,
roughness: 0.95,
flatShading: true
});
const rockMaterialB = new THREE.MeshStandardMaterial({
color: 0xb6c3b7,
roughness: 0.95,
flatShading: true
});
[
[-6.3, 0.46, -4.2, 1.1, rockMaterialA],
[-5.1, 0.32, -4.8, 0.78, rockMaterialB],
[6.1, 0.52, -4.5, 1.2, rockMaterialB],
[5.2, 0.28, 4.8, 0.8, rockMaterialA]
].forEach(([x, y, z, scale, material]) => {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(scale, 0),
material
);
rock.position.set(x, y, z);
rock.rotation.set(0.25, x * 0.7, 0.15);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
});
// -------------------------------------------------------------------------
// Tray construction
// -------------------------------------------------------------------------
const tray = new THREE.Group();
scene.add(tray);
const slots = [
{ x: -1.95, z: -0.67 },
{ x: -0.65, z: -0.67 },
{ x: 0.65, z: -0.67 },
{ x: 1.95, z: -0.67 },
{ x: -1.95, z: 0.67 },
{ x: -0.65, z: 0.67 },
{ x: 0.65, z: 0.67 },
{ x: 1.95, z: 0.67 }
];
function makeRoundedRectangle(width, height, radius) {
const shape = new THREE.Shape();
const left = -width / 2;
const right = width / 2;
const bottom = -height / 2;
const top = height / 2;
shape.moveTo(left + radius, bottom);
shape.lineTo(right - radius, bottom);
shape.quadraticCurveTo(right, bottom, right, bottom + radius);
shape.lineTo(right, top - radius);
shape.quadraticCurveTo(right, top, right - radius, top);
shape.lineTo(left + radius, top);
shape.quadraticCurveTo(left, top, left, top - radius);
shape.lineTo(left, bottom + radius);
shape.quadraticCurveTo(left, bottom, left + radius, bottom);
return shape;
}
const trayShape = makeRoundedRectangle(5.4, 3.0, 0.24);
// Actual holes in the top plate.
slots.forEach((slot) => {
const hole = new THREE.Path();
hole.absarc(slot.x, -slot.z, 0.46, 0, Math.PI * 2, true);
trayShape.holes.push(hole);
});
const plateGeometry = new THREE.ExtrudeGeometry(trayShape, {
depth: 0.16,
steps: 1,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.035,
bevelThickness: 0.035,
curveSegments: 8
});
plateGeometry.rotateX(-Math.PI / 2);
const plate = new THREE.Mesh(plateGeometry, materials.plate);
plate.position.y = 0.94;
plate.castShadow = true;
plate.receiveShadow = true;
tray.add(plate);
// Structural rails below the plate.
[-1.12, 1.12].forEach((z) => {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(4.85, 0.12, 0.12),
materials.underside
);
rail.position.set(0, 0.82, z);
rail.castShadow = true;
tray.add(rail);
});
// Low-poly recessed slot liners and gold rim rings.
slots.forEach((slot) => {
const liner = new THREE.Mesh(
new THREE.CylinderGeometry(0.49, 0.38, 0.52, 12, 1, true),
materials.liner
);
liner.position.set(slot.x, 0.815, slot.z);
liner.castShadow = true;
liner.receiveShadow = true;
tray.add(liner);
const bottom = new THREE.Mesh(
new THREE.CircleGeometry(0.385, 12),
materials.liner
);
bottom.rotation.x = -Math.PI / 2;
bottom.position.set(slot.x, 0.555, slot.z);
tray.add(bottom);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.035, 4, 12),
materials.rim
);
rim.rotation.x = Math.PI / 2;
rim.position.set(slot.x, 1.145, slot.z);
rim.castShadow = true;
tray.add(rim);
});
// Angular U-shaped carrying handle.
const handleCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-0.85, 1.04, 1.42),
new THREE.Vector3(-0.85, 1.17, 1.94),
new THREE.Vector3(-0.45, 1.23, 2.30),
new THREE.Vector3(0.45, 1.23, 2.30),
new THREE.Vector3(0.85, 1.17, 1.94),
new THREE.Vector3(0.85, 1.04, 1.42)
],
false,
"centripetal"
);
const handle = new THREE.Mesh(
new THREE.TubeGeometry(handleCurve, 18, 0.075, 4, false),
materials.handle
);
handle.castShadow = true;
tray.add(handle);
const grip = new THREE.Mesh(
new THREE.BoxGeometry(0.78, 0.16, 0.18),
materials.grip
);
grip.position.set(0, 1.23, 2.30);
grip.castShadow = true;
tray.add(grip);
const rivetGeometry = new THREE.SphereGeometry(0.055, 6, 4);
[-0.85, 0.85].forEach((x) => {
const rivet = new THREE.Mesh(rivetGeometry, materials.rim);
rivet.position.set(x, 1.055, 1.46);
rivet.castShadow = true;
tray.add(rivet);
});
// -------------------------------------------------------------------------
// Cups
// -------------------------------------------------------------------------
const cupGroups = [];
function makeCup(index, slot) {
const group = new THREE.Group();
group.position.set(slot.x, 1.04, slot.z);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.37, 0.29, 0.78, 12, 1, true),
materials.cup
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const sleeve = new THREE.Mesh(
new THREE.CylinderGeometry(0.333, 0.319, 0.28, 12, 1, true),
sleeveMaterials[index % sleeveMaterials.length]
);
sleeve.position.y = -0.17;
sleeve.castShadow = true;
group.add(sleeve);
const liquid = new THREE.Mesh(
new THREE.CircleGeometry(0.335, 12),
materials.coffee
);
liquid.rotation.x = -Math.PI / 2;
liquid.position.y = 0.383;
group.add(liquid);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.357, 0.024, 4, 12),
materials.cup
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.391;
rim.castShadow = true;
group.add(rim);
tray.add(group);
cupGroups.push(group);
}
slots.forEach((slot, index) => makeCup(index, slot));
// -------------------------------------------------------------------------
// Controlled route and payload states
// -------------------------------------------------------------------------
const ROUTE_DISTANCE = 3.6;
const ROUTE_DURATION = 4.8;
const ROUTE_SPEED = ROUTE_DISTANCE / ROUTE_DURATION;
const START_X = -1.8;
const END_X = 1.8;
let currentLoad = 1;
let routeElapsed = 0;
let routeProgress = 0;
let routePlaying = false;
const cupAppearance = slots.map((_, index) =>
index === 5 ? 1 : 0
);
const scenarioButtons = [
...document.querySelectorAll(".scenario")
];
const currentStatus = document.getElementById("currentStatus");
const runRouteButton = document.getElementById("runRoute");
const routeState = document.getElementById("routeState");
const progressFill = document.getElementById("progressFill");
function resetRoute() {
routeElapsed = 0;
routeProgress = 0;
routePlaying = false;
tray.position.x = START_X;
tray.position.y = 0;
progressFill.style.width = "0%";
runRouteButton.disabled = false;
runRouteButton.textContent = "▶ Run identical route";
routeState.textContent = "Ready · fixed one-way route";
}
function setLoad(load) {
currentLoad = load;
const accent = load === 1 ? "#e87550" : "#237c76";
document.documentElement.style.setProperty("--active", accent);
scenarioButtons.forEach((button) => {
const active = Number(button.dataset.load) === load;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
currentStatus.textContent =
load === 1 ? "One cup" : "Full batch · eight cups";
resetRoute();
}
function startRoute() {
routeElapsed = 0;
routeProgress = 0;
routePlaying = true;
tray.position.x = START_X;
runRouteButton.disabled = true;
runRouteButton.textContent = "● Running at 0.75 m/s";
routeState.textContent = "Travelling · 0.00 / 3.60 m";
}
scenarioButtons.forEach((button) => {
button.addEventListener("click", () => {
setLoad(Number(button.dataset.load));
});
});
runRouteButton.addEventListener("click", startRoute);
window.addEventListener("keydown", (event) => {
if (event.key === "1") {
setLoad(1);
} else if (event.key === "8") {
setLoad(8);
} else if (event.code === "Space") {
event.preventDefault();
startRoute();
}
});
// -------------------------------------------------------------------------
// Direct camera controls: pointer orbit and wheel zoom
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desiredYaw -= dx * 0.006;
desiredPitch = THREE.MathUtils.clamp(
desiredPitch + dy * 0.005,
0.35,
1.25
);
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius + event.deltaY * 0.008,
7,
16
);
},
{ passive: false }
);
function resetCamera() {
desiredYaw = 0.67;
desiredPitch = 0.73;
desiredRadius = 10.8;
}
document
.getElementById("resetCamera")
.addEventListener("click", resetCamera);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
// Cup appearance transitions.
cupGroups.forEach((cup, index) => {
const target =
currentLoad === 8 || index === 5 ? 1 : 0;
cupAppearance[index] = THREE.MathUtils.lerp(
cupAppearance[index],
target,
Math.min(1, delta * 8)
);
const appearance = cupAppearance[index];
cup.visible = appearance > 0.005;
cup.position.y = 1.04 + (1 - appearance) * 0.28;
cup.scale.setScalar(0.78 + appearance * 0.22);
});
// Exact linear route motion preserves equal distance and equal speed.
if (routePlaying) {
routeElapsed += delta;
routeProgress = Math.min(routeElapsed / ROUTE_DURATION, 1);
tray.position.x = THREE.MathUtils.lerp(
START_X,
END_X,
routeProgress
);
// A tiny carried-load bob does not change horizontal travel distance.
tray.position.y =
Math.sin(routeProgress * Math.PI * 8) * 0.016;
const travelled = routeProgress * ROUTE_DISTANCE;
progressFill.style.width = `${routeProgress * 100}%`;
routeState.textContent = `Travelling · ${travelled.toFixed(
2
)} / 3.60 m`;
if (routeProgress >= 1) {
routePlaying = false;
runRouteButton.disabled = false;
runRouteButton.textContent = "↻ Run route again";
routeState.textContent = "Complete · 3.60 / 3.60 m";
}
}
updateCamera();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.getElementById("loading").classList.add("hidden");
}
}
resetRoute();
updateCamera();
animate();
</script>
</body>
</html>
```