Prompt specification
Build or customize the Three.js 3D scene "Missing Bottle Caps at a Juice Stand" 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: Missing Bottle Caps at a Juice Stand
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/missing-bottle-caps-at-a-juice-stand-x3170
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a low-poly juice stand waiting for bottle caps. Animate a short run in which bottles can be filled but the cap tray becomes empty. Filled bottles should accumulate in a clearly separate waiting area while the finished-unit counter stays unchanged. When a small delivery supplies more caps, resume completion from that queue. Track each bottle through empty, filled, and capped states, and keep unused fruit and bottles visible to show that the missing component is specifically the cap.
Working Three.js Starter (missing-bottle-caps-at-a-juice-stand-x3170):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pip & Peeks Juice Stand</title>
<style>
:root {
--ink: #173e38;
--cream: #fff9e9;
--coral: #ee735d;
--orange: #f4a340;
--mint: #55b89d;
--yellow: #f4cd55;
--red: #cf4b45;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #efe3ca;
color: var(--ink);
font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.panel {
border: 1px solid rgba(23, 62, 56, 0.14);
background: rgba(255, 249, 233, 0.9);
box-shadow: 0 10px 30px rgba(55, 43, 22, 0.13);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.brand {
position: absolute;
top: 20px;
left: 20px;
width: 280px;
padding: 15px 17px;
border-radius: 18px;
}
.brand-top {
display: flex;
align-items: center;
gap: 11px;
}
.brand-icon {
display: grid;
width: 39px;
height: 39px;
place-items: center;
border-radius: 12px;
background: var(--orange);
color: white;
font-size: 22px;
box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.08);
}
.brand h1 {
margin: 0;
font-size: 19px;
line-height: 1;
letter-spacing: 0.02em;
}
.brand p {
margin: 8px 0 0;
color: #55736d;
font-size: 12px;
line-height: 1.4;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 12px;
}
.legend span {
padding: 4px 7px;
border-radius: 999px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
}
.legend .empty {
color: #536a68;
background: #e3e9e5;
}
.legend .filled {
color: #8b4c0a;
background: #ffe0a9;
}
.legend .capped {
color: #17644f;
background: #c9ecdc;
}
.metrics {
position: absolute;
top: 20px;
right: 20px;
display: grid;
grid-template-columns: repeat(3, 150px);
gap: 10px;
}
.metric {
min-height: 90px;
padding: 13px 15px;
border-radius: 16px;
}
.metric-label {
display: block;
color: #5b7771;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 4px;
font-size: 31px;
line-height: 1;
}
.metric small {
display: block;
margin-top: 5px;
color: #66817b;
font-size: 10px;
white-space: nowrap;
}
.metric.counter {
border-top: 4px solid var(--mint);
}
.metric.caps {
border-top: 4px solid var(--coral);
}
.metric.queue {
border-top: 4px solid var(--yellow);
}
.metric.caps.danger {
border-top-color: var(--red);
background: rgba(255, 231, 221, 0.94);
}
.metric.caps.danger strong {
color: var(--red);
}
.controls {
position: absolute;
left: 20px;
bottom: 22px;
width: 350px;
padding: 15px;
border-radius: 19px;
pointer-events: auto;
}
.status-card {
padding: 13px 14px;
border-radius: 13px;
background: #e7f3ec;
border-left: 4px solid var(--mint);
transition: background 180ms ease, border-color 180ms ease;
}
.status-card.alert {
background: #ffe4dc;
border-left-color: var(--red);
}
.status-card.good {
background: #dff4e8;
border-left-color: var(--mint);
}
.status-card h2 {
margin: 0;
font-size: 15px;
line-height: 1.2;
}
.status-card p {
margin: 5px 0 0;
color: #5c746f;
font-size: 12px;
line-height: 1.4;
}
.status-card.alert h2 {
color: #a53531;
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 9px;
margin-top: 11px;
}
button {
border: 0;
font: inherit;
cursor: pointer;
transition: transform 130ms ease, opacity 130ms ease, box-shadow 130ms ease;
}
button:focus-visible {
outline: 3px solid rgba(238, 115, 93, 0.35);
outline-offset: 3px;
}
button:disabled {
cursor: not-allowed;
opacity: 0.47;
}
.delivery {
display: flex;
min-height: 61px;
align-items: center;
gap: 11px;
padding: 10px 13px;
border-radius: 13px;
background: var(--coral);
color: white;
text-align: left;
box-shadow: 0 7px 0 #b94f40;
}
.delivery:not(:disabled):hover {
transform: translateY(-2px);
box-shadow: 0 9px 0 #b94f40;
}
.delivery:not(:disabled):active {
transform: translateY(4px);
box-shadow: 0 3px 0 #b94f40;
}
.delivery.ready {
animation: deliveryPulse 1.5s ease-in-out infinite;
}
@keyframes deliveryPulse {
0%, 100% { box-shadow: 0 7px 0 #b94f40, 0 0 0 0 rgba(238, 115, 93, 0.28); }
50% { box-shadow: 0 7px 0 #b94f40, 0 0 0 8px rgba(238, 115, 93, 0); }
}
.delivery-icon {
display: grid;
width: 37px;
height: 37px;
flex: 0 0 auto;
place-items: center;
border-radius: 11px;
background: rgba(255, 255, 255, 0.18);
font-size: 21px;
}
.delivery b,
.delivery small {
display: block;
}
.delivery b {
font-size: 13px;
}
.delivery small {
margin-top: 2px;
color: rgba(255, 255, 255, 0.78);
font-size: 10px;
}
.replay {
align-self: stretch;
padding: 0 13px;
border-radius: 13px;
background: #e6e3d8;
color: var(--ink);
font-size: 11px;
font-weight: 800;
}
.replay:not(:disabled):hover {
transform: translateY(-2px);
}
.ledger {
position: absolute;
right: 20px;
bottom: 22px;
width: 330px;
padding: 14px;
border-radius: 18px;
}
.ledger-head {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 10px;
}
.ledger-head h2 {
margin: 0;
font-size: 13px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.ledger-head span {
color: #68817c;
font-size: 10px;
}
.ledger-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
}
.bottle-chip {
padding: 8px 5px;
border-radius: 10px;
text-align: center;
background: #e5ebe7;
border: 1px solid transparent;
transition: background 180ms ease, transform 180ms ease;
}
.bottle-chip span {
display: block;
margin-bottom: 4px;
font-size: 10px;
font-weight: 850;
}
.bottle-chip i {
display: block;
font-size: 8px;
font-style: normal;
font-weight: 850;
letter-spacing: 0.06em;
}
.bottle-chip.state-filled {
background: #ffe0a9;
border-color: #eeb75e;
transform: translateY(-2px);
}
.bottle-chip.state-filled i {
color: #9a5409;
}
.bottle-chip.state-capped {
background: #c9ecdc;
border-color: #70b99b;
}
.bottle-chip.state-capped i {
color: #17644f;
}
.hint {
position: absolute;
left: 50%;
bottom: 16px;
padding: 7px 12px;
border-radius: 999px;
background: rgba(23, 62, 56, 0.76);
color: white;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
transform: translateX(-50%);
white-space: nowrap;
}
@media (max-width: 920px) {
.brand {
width: 235px;
}
.metrics {
grid-template-columns: repeat(3, 115px);
}
.metric {
min-height: 78px;
padding: 10px;
}
.metric strong {
font-size: 25px;
}
.ledger {
right: 12px;
bottom: 12px;
width: 285px;
}
.controls {
left: 12px;
bottom: 12px;
width: 330px;
}
.hint {
display: none;
}
}
@media (max-width: 680px) {
.brand {
top: 10px;
left: 10px;
width: 205px;
padding: 11px 12px;
}
.brand h1 {
font-size: 15px;
}
.brand p,
.legend {
display: none;
}
.metrics {
top: 10px;
right: 10px;
grid-template-columns: repeat(3, 82px);
gap: 5px;
}
.metric {
min-height: 66px;
padding: 8px;
border-radius: 12px;
}
.metric-label {
font-size: 8px;
}
.metric strong {
font-size: 22px;
}
.metric small {
display: none;
}
.controls {
left: 10px;
bottom: 121px;
width: calc(100% - 20px);
padding: 10px;
}
.status-card {
padding: 9px 11px;
}
.status-card h2 {
font-size: 13px;
}
.status-card p {
font-size: 10px;
}
.actions {
margin-top: 8px;
}
.delivery {
min-height: 48px;
}
.delivery-icon {
width: 31px;
height: 31px;
}
.ledger {
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
padding: 9px;
}
.ledger-grid {
grid-template-columns: repeat(8, 1fr);
gap: 4px;
}
.bottle-chip {
padding: 6px 2px;
}
.bottle-chip i {
font-size: 7px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Low-poly juice stand production line"></canvas>
<div id="hud">
<section class="brand panel">
<div class="brand-top">
<div class="brand-icon">◆</div>
<div>
<h1>PIP & PEEKS</h1>
<div style="margin-top:3px;font-size:10px;font-weight:800;letter-spacing:.13em;color:#e26a54">
FRESH JUICE ASSEMBLY LINE
</div>
</div>
</div>
<p>Fruit and empty bottles are ready. Watch the bottle state change from empty to filled to capped.</p>
<div class="legend">
<span class="empty">EMPTY</span>
<span class="filled">FILLED</span>
<span class="capped">CAPPED</span>
</div>
</section>
<section class="metrics">
<div class="metric counter panel">
<span class="metric-label">Finished units</span>
<strong id="finishedCount">0</strong>
<small id="counterNote">0 of 8 capped</small>
</div>
<div class="metric caps panel" id="capMetric">
<span class="metric-label">Cap tray</span>
<strong id="capCount">2</strong>
<small id="capNote">2 caps available</small>
</div>
<div class="metric queue panel">
<span class="metric-label">Filled queue</span>
<strong id="queueCount">0</strong>
<small>waiting for caps</small>
</div>
</section>
<section class="controls panel">
<div class="status-card" id="statusCard" aria-live="polite">
<h2 id="statusTitle">Line starting…</h2>
<p id="statusDetail">Fruit, bottles, and a small cap tray are ready.</p>
</div>
<div class="actions">
<button class="delivery" id="deliveryBtn" disabled>
<span class="delivery-icon">▣</span>
<span>
<b id="deliveryTitle">Deliver 6 caps</b>
<small id="deliverySubtitle">Available when the tray empties</small>
</span>
</button>
<button class="replay" id="replayBtn" disabled>Replay</button>
</div>
</section>
<section class="ledger panel">
<div class="ledger-head">
<h2>Bottle state ledger</h2>
<span>EMPTY → FILLED → CAPPED</span>
</div>
<div class="ledger-grid" id="ledgerGrid"></div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom</div>
</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.getElementById("scene");
const finishedCountEl = document.getElementById("finishedCount");
const counterNoteEl = document.getElementById("counterNote");
const capCountEl = document.getElementById("capCount");
const capNoteEl = document.getElementById("capNote");
const queueCountEl = document.getElementById("queueCount");
const capMetricEl = document.getElementById("capMetric");
const statusCardEl = document.getElementById("statusCard");
const statusTitleEl = document.getElementById("statusTitle");
const statusDetailEl = document.getElementById("statusDetail");
const deliveryBtn = document.getElementById("deliveryBtn");
const deliveryTitleEl = document.getElementById("deliveryTitle");
const deliverySubtitleEl = document.getElementById("deliverySubtitle");
const replayBtn = document.getElementById("replayBtn");
const ledgerGrid = document.getElementById("ledgerGrid");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xefe3ca);
scene.fog = new THREE.Fog(0xefe3ca, 25, 48);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.setClearColor(0xefe3ca);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
theta: 0.53,
phi: 0.91,
radius: 18.5,
target: new THREE.Vector3(0, 1.55, 0)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
// Direct camera controls: no examples/addons modules are used.
let dragging = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.42,
1.25
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
11,
28
);
updateCamera();
},
{ passive: false }
);
const hemi = new THREE.HemisphereLight(0xfff4d7, 0x78958b, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffefd0, 3.1);
sun.position.set(-8, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xb9e8de, 1.1);
fillLight.position.set(9, 7, -6);
scene.add(fillLight);
const materials = {
cream: new THREE.MeshStandardMaterial({ color: 0xfff4d7, roughness: 0.82, flatShading: true }),
paleMint: new THREE.MeshStandardMaterial({ color: 0xb9d8c7, roughness: 0.86, flatShading: true }),
teal: new THREE.MeshStandardMaterial({ color: 0x397f75, roughness: 0.72, flatShading: true }),
darkTeal: new THREE.MeshStandardMaterial({ color: 0x20554e, roughness: 0.76, flatShading: true }),
coral: new THREE.MeshStandardMaterial({ color: 0xee735d, roughness: 0.78, flatShading: true }),
orange: new THREE.MeshStandardMaterial({ color: 0xf39a32, roughness: 0.72, flatShading: true }),
yellow: new THREE.MeshStandardMaterial({ color: 0xf4cd55, roughness: 0.8, flatShading: true }),
green: new THREE.MeshStandardMaterial({ color: 0x65b996, roughness: 0.78, flatShading: true }),
wood: new THREE.MeshStandardMaterial({ color: 0xb87945, roughness: 0.9, flatShading: true }),
lightWood: new THREE.MeshStandardMaterial({ color: 0xd4a065, roughness: 0.88, flatShading: true }),
darkWood: new THREE.MeshStandardMaterial({ color: 0x78472f, roughness: 0.92, flatShading: true }),
metal: new THREE.MeshStandardMaterial({ color: 0x9fb4ad, roughness: 0.42, metalness: 0.25, flatShading: true }),
white: new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 0.75, flatShading: true }),
black: new THREE.MeshStandardMaterial({ color: 0x334440, roughness: 0.7, flatShading: true }),
capRed: new THREE.MeshStandardMaterial({ color: 0xd95248, roughness: 0.58, flatShading: true }),
juice: new THREE.MeshStandardMaterial({ color: 0xf59a25, roughness: 0.4, flatShading: true }),
glass: new THREE.MeshStandardMaterial({
color: 0xc5eee6,
roughness: 0.18,
metalness: 0,
transparent: true,
opacity: 0.48,
depthWrite: false,
side: THREE.DoubleSide,
flatShading: true
})
};
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rTop, rBottom, height, material, x = 0, y = 0, z = 0, segments = 8, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rTop, rBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(text, width = 2.5, bg = "#fff9e9", fg = "#173e38", border = "#d7c9a8") {
const lines = text.split("\n");
const canvasLabel = document.createElement("canvas");
canvasLabel.width = 1024;
canvasLabel.height = lines.length > 1 ? 300 : 190;
const ctx = canvasLabel.getContext("2d");
roundedRect(ctx, 8, 8, canvasLabel.width - 16, canvasLabel.height - 16, 34);
ctx.fillStyle = bg;
ctx.fill();
ctx.lineWidth = 9;
ctx.strokeStyle = border;
ctx.stroke();
ctx.fillStyle = fg;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `900 ${lines.length > 1 ? 63 : 72}px Inter, Segoe UI, sans-serif`;
const startY = lines.length > 1 ? 92 : canvasLabel.height / 2;
const gap = lines.length > 1 ? 112 : 0;
lines.forEach((line, index) => {
ctx.fillText(line, canvasLabel.width / 2, startY + index * gap);
});
const texture = new THREE.CanvasTexture(canvasLabel);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * canvasLabel.height / canvasLabel.width, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
// Ground and stand.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({ color: 0xe7d8b9, roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const island = cylinder(9.4, 9.8, 0.16, new THREE.MeshStandardMaterial({
color: 0xf4ead1,
roughness: 1,
flatShading: true
}), 0, 0.02, 0, 48);
island.receiveShadow = true;
box(16.2, 0.22, 5.8, materials.lightWood, 0, 0.16, 0);
box(15.2, 0.24, 2.75, materials.lightWood, 0, 1.35, 0);
box(15.0, 1.08, 0.18, materials.wood, 0, 0.72, 1.3);
box(15.0, 2.65, 0.18, materials.paleMint, 0, 2.75, -2.38);
for (let x = -7; x <= 7; x += 1.4) {
box(0.035, 1.0, 0.025, materials.darkWood, x, 0.72, 1.405);
}
for (const x of [-7.25, 7.25]) {
box(0.2, 3.6, 0.2, materials.darkWood, x, 2.9, -2.25);
box(0.2, 3.6, 0.2, materials.darkWood, x, 2.9, 1.15);
}
for (let i = 0; i < 11; i++) {
const stripeMat = i % 2 === 0 ? materials.coral : materials.cream;
box(1.39, 0.14, 1.75, stripeMat, -6.95 + i * 1.39, 4.58, -1.67);
}
const mainSign = makeLabel("PIP & PEEKS • JUICE BAR", 5.2, "#fff4d7", "#173e38", "#ee735d");
mainSign.position.set(0, 3.55, -2.24);
const processSign = makeLabel(
"FRESH FRUIT → JUICE → CAP → FINISHED",
6.6,
"#fff9e9",
"#20554e",
"#d4a065"
);
processSign.position.set(0, 0.8, 1.47);
// Fruit crate.
const FRUIT_X = -5.75;
const FRUIT_Z = -0.28;
box(1.65, 0.12, 1.15, materials.darkWood, FRUIT_X, 1.51, FRUIT_Z);
box(1.65, 0.32, 0.1, materials.lightWood, FRUIT_X, 1.67, FRUIT_Z - 0.54);
box(1.65, 0.32, 0.1, materials.lightWood, FRUIT_X, 1.67, FRUIT_Z + 0.54);
box(0.1, 0.32, 1.05, materials.lightWood, FRUIT_X - 0.78, 1.67, FRUIT_Z);
box(0.1, 0.32, 1.05, materials.lightWood, FRUIT_X + 0.78, 1.67, FRUIT_Z);
let seed = 27;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const fruitMeshes = [];
for (let i = 0; i < 14; i++) {
const fruit = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18 + random() * 0.025, 0),
i % 4 === 0 ? materials.orange : new THREE.MeshStandardMaterial({
color: i % 4 === 1 ? 0xf7b23f : 0xed922d,
roughness: 0.85,
flatShading: true
})
);
fruit.position.set(
FRUIT_X - 0.55 + (i % 5) * 0.27,
1.78 + (i % 2) * 0.05,
FRUIT_Z - 0.31 + Math.floor(i / 5) * 0.29 + random() * 0.06
);
fruit.rotation.set(random() * 2, random() * 2, random() * 2);
fruit.castShadow = true;
fruit.receiveShadow = true;
fruit.userData.home = fruit.position.clone();
scene.add(fruit);
fruitMeshes.push(fruit);
}
const fruitSign = makeLabel("FRESH FRUIT\nSTOCK", 1.75, "#ffe2a4", "#7b4a11", "#e6a640");
fruitSign.position.set(FRUIT_X, 2.15, -1.08);
// Juicer and filler.
const juicerGroup = new THREE.Group();
juicerGroup.position.set(-3.75, 1.48, -0.12);
scene.add(juicerGroup);
cylinder(0.56, 0.62, 0.18, materials.teal, 0, 0.09, 0, 10, juicerGroup);
cylinder(0.44, 0.36, 0.42, materials.metal, 0, 0.36, 0, 10, juicerGroup);
cylinder(0.36, 0.22, 0.28, materials.cream, 0, 0.7, 0, 10, juicerGroup);
box(0.12, 0.48, 0.12, materials.darkTeal, 0.42, 0.42, 0, juicerGroup);
box(0.55, 0.1, 0.13, materials.coral, 0.59, 0.64, 0, juicerGroup);
const fillerGroup = new THREE.Group();
fillerGroup.position.set(0, 1.48, -0.36);
scene.add(fillerGroup);
box(1.0, 0.18, 0.85, materials.teal, 0, 0.09, 0, fillerGroup);
cylinder(0.38, 0.38, 0.72, materials.cream, 0, 0.55, 0, 10, fillerGroup);
cylinder(0.22, 0.22, 0.12, materials.orange, 0, 0.96, 0, 10, fillerGroup);
box(0.13, 0.13, 0.62, materials.metal, 0, 0.79, 0.32, fillerGroup);
box(0.42, 0.13, 0.42, materials.metal, 0, 0.83, 0.55, fillerGroup);
const juicePipe = cylinder(0.1, 0.1, 3.3, materials.metal, -1.95, 2.38, -0.35, 8);
juicePipe.rotation.z = Math.PI / 2;
const juicePulse = new THREE.Mesh(
new THREE.SphereGeometry(0.11, 8, 6),
materials.juice
);
juicePulse.position.set(-3.35, 2.38, -0.35);
juicePulse.visible = false;
scene.add(juicePulse);
const emptySign = makeLabel("EMPTY BOTTLES", 2.25, "#edf3ef", "#315e57", "#a9c3ba");
emptySign.position.set(-2.45, 2.05, -1.16);
const reserveSign = makeLabel("BOTTLE RESERVE", 2.1, "#edf3ef", "#315e57", "#a9c3ba");
reserveSign.position.set(-4.35, 2.05, 1.12);
const fillSign = makeLabel("FILL", 1.25, "#ffe2a4", "#7b4a11", "#e6a640");
fillSign.position.set(0, 2.58, -0.72);
// Empty-bottle rack.
box(2.05, 0.08, 1.0, materials.darkWood, -2.3, 1.51, -0.72);
box(2.05, 0.3, 0.07, materials.lightWood, -2.3, 1.63, -1.2);
box(0.07, 0.3, 0.9, materials.lightWood, -3.3, 1.63, -0.72);
box(0.07, 0.3, 0.9, materials.lightWood, -1.3, 1.63, -0.72);
// Separate reserve crate keeps unused empty bottles visible.
box(1.6, 0.1, 0.8, materials.darkWood, -4.4, 1.51, 0.88);
box(1.6, 0.25, 0.08, materials.lightWood, -4.4, 1.64, 1.26);
box(0.08, 0.25, 0.75, materials.lightWood, -5.18, 1.64, 0.88);
box(0.08, 0.25, 0.75, materials.lightWood, -3.62, 1.64, 0.88);
// Bottle construction and explicit state tracking.
const COUNTER_Y = 1.48;
function setLiquidFill(bottle, fraction) {
const f = Math.max(0.001, fraction);
bottle.liquid.visible = fraction > 0.002;
bottle.liquid.scale.y = f;
bottle.liquid.position.y = 0.06 + 0.23 * f;
}
function createBottle() {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.215, 0.58, 8),
materials.glass
);
body.position.y = 0.29;
group.add(body);
const baseRing = new THREE.Mesh(
new THREE.CylinderGeometry(0.216, 0.216, 0.045, 8),
materials.glass
);
baseRing.position.y = 0.025;
group.add(baseRing);
const liquid = new THREE.Mesh(
new THREE.CylinderGeometry(0.165, 0.165, 0.46, 8),
materials.juice
);
liquid.position.y = 0.29;
liquid.visible = false;
group.add(liquid);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.12, 0.17, 8),
materials.glass
);
neck.position.y = 0.66;
group.add(neck);
const lip = new THREE.Mesh(
new THREE.CylinderGeometry(0.125, 0.125, 0.045, 8),
materials.glass
);
lip.position.y = 0.755;
group.add(lip);
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.135, 0.135, 0.075, 10),
materials.capRed
);
cap.position.y = 0.81;
cap.visible = false;
group.add(cap);
group.traverse((child) => {
if (child.isMesh) {
child.castShadow = child !== liquid;
child.receiveShadow = true;
}
});
scene.add(group);
return { group, liquid, cap };
}
const bottles = [];
const activeHomes = [];
const rackXs = [-3.0, -2.55, -2.1, -1.65];
const rackZs = [-0.92, -0.48];
for (let i = 0; i < 8; i++) {
const bottle = createBottle();
const home = new THREE.Vector3(
rackXs[i % rackXs.length],
COUNTER_Y,
rackZs[Math.floor(i / rackXs.length)]
);
bottle.group.position.copy(home);
bottle.id = `B${String(i + 1).padStart(2, "0")}`;
bottle.state = "empty";
bottle.home = home.clone();
bottle.queueSlot = null;
bottles.push(bottle);
activeHomes.push(home);
}
// Unused reserve bottles.
for (let i = 0; i < 6; i++) {
const spare = createBottle();
spare.group.position.set(
-4.92 + (i % 3) * 0.46,
COUNTER_Y,
0.66 + Math.floor(i / 3) * 0.39
);
spare.group.rotation.y = (random() - 0.5) * 0.16;
}
// Cap tray.
const capTray = new THREE.Group();
capTray.position.set(1.72, 1.56, -0.76);
scene.add(capTray);
box(1.45, 0.08, 1.2, materials.darkTeal, 0, 0, 0, capTray);
box(1.45, 0.2, 0.08, materials.teal, 0, 0.1, -0.56, capTray);
box(1.45, 0.2, 0.08, materials.teal, 0, 0.1, 0.56, capTray);
box(0.08, 0.2, 1.12, materials.teal, -0.69, 0.1, 0, capTray);
box(0.08, 0.2, 1.12, materials.teal, 0.69, 0.1, 0, capTray);
const capMeshes = [];
for (let i = 0; i < 10; i++) {
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.115, 0.115, 0.07, 10),
materials.capRed
);
cap.castShadow = true;
scene.add(cap);
capMeshes.push(cap);
}
function traySlotWorld(index) {
const columns = 3;
return new THREE.Vector3(
1.72 - 0.42 + (index % columns) * 0.42,
1.64,
-0.76 - 0.32 + Math.floor(index / columns) * 0.31
);
}
const capSign = makeLabel("CAP TRAY", 1.55, "#ffe2df", "#a5443d", "#e66c61");
capSign.position.set(1.72, 2.12, -1.2);
const emptyCapSign = makeLabel("EMPTY", 1.15, "#cf4b45", "#ffffff", "#a93b36");
emptyCapSign.position.set(1.72, 1.9, -0.76);
emptyCapSign.visible = false;
// Capping press.
const capperX = 2.85;
box(0.95, 0.14, 0.85, materials.teal, capperX, 1.56, 0.03);
box(0.12, 0.95, 0.16, materials.darkTeal, capperX - 0.36, 2.02, -0.16);
box(0.12, 0.95, 0.16, materials.darkTeal, capperX + 0.36, 2.02, -0.16);
box(0.9, 0.13, 0.25, materials.darkTeal, capperX, 2.49, -0.16);
const pressHead = box(
0.62,
0.16,
0.6,
materials.coral,
capperX,
2.29,
0.05
);
const pressHomeY = pressHead.position.y;
// Clearly separated filled queue.
const queueCenterX = 5.02;
const queueCenterZ = 0.7;
box(3.85, 0.055, 1.27, materials.yellow, queueCenterX, 1.505, queueCenterZ);
box(3.85, 0.035, 0.06, materials.darkWood, queueCenterX, 1.54, queueCenterZ - 0.61);
box(3.85, 0.035, 0.06, materials.darkWood, queueCenterX, 1.54, queueCenterZ + 0.61);
box(0.06, 0.035, 1.22, materials.darkWood, queueCenterX - 1.89, 1.54, queueCenterZ);
box(0.06, 0.035, 1.22, materials.darkWood, queueCenterX + 1.89, 1.54, queueCenterZ);
const queuePositions = [];
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
queuePositions.push(new THREE.Vector3(
4.02 + col * 1.0,
COUNTER_Y,
0.4 + row * 0.6
));
}
}
const queueSign = makeLabel(
"FILLED • WAITING\nFOR CAPS",
2.25,
"#fff0b5",
"#7b5710",
"#d8a938"
);
queueSign.position.set(5.1, 2.35, 1.17);
// Clearly separated finished shelf.
const finishedCenterX = 6.12;
const finishedCenterZ = -0.76;
box(2.2, 0.065, 1.25, materials.green, finishedCenterX, 1.515, finishedCenterZ);
box(2.2, 0.3, 0.08, materials.teal, finishedCenterX, 1.63, finishedCenterZ - 0.59);
box(0.08, 0.3, 1.18, materials.teal, finishedCenterX - 1.06, 1.63, finishedCenterZ);
box(0.08, 0.3, 1.18, materials.teal, finishedCenterX + 1.06, 1.63, finishedCenterZ);
const finishedPositions = [];
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 4; col++) {
finishedPositions.push(new THREE.Vector3(
5.43 + col * 0.46,
COUNTER_Y,
-0.98 + row * 0.45
));
}
}
const finishedSign = makeLabel("CAPPED\nFINISHED", 1.8, "#d8f2e4", "#17644f", "#70b99b");
finishedSign.position.set(6.13, 2.34, -1.19);
// Small cap courier delivery.
const deliveryBox = new THREE.Group();
scene.add(deliveryBox);
box(1.25, 0.55, 0.95, materials.lightWood, 0, 0.38, 0, deliveryBox);
box(1.3, 0.09, 0.22, materials.darkWood, 0, 0.69, 0, deliveryBox);
box(0.22, 0.58, 1.0, materials.coral, 0, 0.39, 0, deliveryBox);
const deliveryLabel = makeLabel("+6 CAPS", 1.0, "#fff9e9", "#a5443d", "#ee735d");
deliveryLabel.position.set(0, 0.43, 0.51);
for (const x of [-0.48, 0.48]) {
const wheel = cylinder(0.13, 0.13, 0.09, materials.black, x, 0.13, 0.29, 8, deliveryBox);
wheel.rotation.x = Math.PI / 2;
}
deliveryBox.position.set(8.2, 0.18, 2.45);
deliveryBox.visible = false;
// Generic tween system.
const tweens = new Set();
const easeInOutCubic = (t) =>
t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
const easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
function animate(duration, update, easing = easeInOutCubic) {
return new Promise((resolve) => {
tweens.add({
start: performance.now(),
duration,
update,
easing,
resolve
});
});
}
function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function moveTo(object, target, duration = 0.45, arc = 0.16) {
const from = object.position.clone();
const to = target.clone();
return animate(duration, (t) => {
object.position.lerpVectors(from, to, t);
object.position.y += Math.sin(Math.PI * t) * arc;
});
}
function createFlyingCap(colorMaterial = materials.capRed) {
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.115, 0.115, 0.07, 10),
colorMaterial
);
cap.castShadow = true;
scene.add(cap);
return cap;
}
let capStock = 2;
let finishedCount = 0;
let fruitCursor = 0;
let queueSlotCursor = 0;
let busy = false;
let runToken = 0;
function refreshCapTray() {
capMeshes.forEach((cap, index) => {
cap.visible = index < capStock;
if (cap.visible) {
cap.position.copy(traySlotWorld(index));
cap.rotation.y = index * 0.3;
}
});
emptyCapSign.visible = capStock === 0;
}
function getQueueCount() {
return bottles.filter((bottle) => bottle.state === "filled").length;
}
function updateLedger() {
bottles.forEach((bottle) => {
const chip = document.getElementById(`chip-${bottle.id}`);
chip.className = `bottle-chip state-${bottle.state}`;
chip.querySelector("i").textContent = bottle.state.toUpperCase();
});
}
function updateUI() {
const queueCount = getQueueCount();
finishedCountEl.textContent = finishedCount;
capCountEl.textContent = capStock;
queueCountEl.textContent = queueCount;
counterNoteEl.textContent =
capStock === 0 && queueCount > 0
? "HELD — waiting for caps"
: `${finishedCount} of ${bottles.length} capped`;
capNoteEl.textContent =
capStock === 0 ? "No caps available" : `${capStock} caps available`;
capMetricEl.classList.toggle("danger", capStock === 0);
const canDeliver = !busy && capStock === 0 && queueCount > 0;
deliveryBtn.disabled = !canDeliver;
deliveryBtn.classList.toggle("ready", canDeliver);
replayBtn.disabled = busy;
if (capStock === 0 && queueCount > 0) {
deliveryTitleEl.textContent = "Deliver 6 caps";
deliverySubtitleEl.textContent = "Caps exhausted — courier ready";
} else if (queueCount === 0 && capStock === 0 && finishedCount === bottles.length) {
deliveryTitleEl.textContent = "Queue cleared";
deliverySubtitleEl.textContent = "All bottles are capped";
} else {
deliveryTitleEl.textContent = "Deliver 6 caps";
deliverySubtitleEl.textContent = "Available when the tray empties";
}
updateLedger();
}
function setStatus(title, detail, tone = "normal") {
statusTitleEl.textContent = title;
statusDetailEl.textContent = detail;
statusCardEl.className = `status-card ${tone}`;
}
refreshCapTray();
// Ledger DOM.
bottles.forEach((bottle) => {
const chip = document.createElement("div");
chip.id = `chip-${bottle.id}`;
chip.className = "bottle-chip state-empty";
chip.innerHTML = `<span>${bottle.id}</span><i>EMPTY</i>`;
ledgerGrid.appendChild(chip);
});
updateUI();
const FILLER_POSITION = new THREE.Vector3(0, COUNTER_Y, 0.18);
const CAPPER_POSITION = new THREE.Vector3(capperX, COUNTER_Y, 0.05);
async function applyCap(bottle, token) {
if (token !== runToken || capStock <= 0) return false;
const sourceMesh = capMeshes.find((cap) => cap.visible);
const sourcePosition = sourceMesh
? sourceMesh.position.clone()
: traySlotWorld(0);
capStock -= 1;
refreshCapTray();
const flyingCap = createFlyingCap();
flyingCap.position.copy(sourcePosition);
const target = bottle.group.position.clone().add(new THREE.Vector3(0, 0.81, 0));
const pressAnimation = animate(
0.42,
(t) => {
const down = Math.sin(Math.PI * t);
pressHead.position.y = pressHomeY - down * 0.16;
},
easeOutCubic
);
const capAnimation = animate(
0.42,
(t) => {
flyingCap.position.lerpVectors(sourcePosition, target, t);
flyingCap.position.y += Math.sin(Math.PI * t) * 0.38;
flyingCap.rotation.y = t * Math.PI * 2;
},
easeInOutCubic
);
await Promise.all([pressAnimation, capAnimation]);
if (token !== runToken) return false;
bottle.cap.visible = true;
bottle.state = "capped";
bottle.queueSlot = null;
finishedCount += 1;
scene.remove(flyingCap);
updateUI();
return true;
}
async function runLine(token) {
busy = true;
updateUI();
setStatus(
"Production line running",
"Fruit becomes juice and bottles move from empty to filled. Caps are limited.",
"normal"
);
for (let index = 0; index < bottles.length; index++) {
if (token !== runToken) return;
const bottle = bottles[index];
setStatus(
`Filling ${bottle.id}`,
capStock === 0
? "Fruit and bottles are still available. This bottle can be filled, but no cap is available."
: "The fruit is pressed and fresh juice is poured into the bottle.",
capStock === 0 ? "alert" : "normal"
);
await moveTo(bottle.group, FILLER_POSITION, 0.36, 0.22);
if (token !== runToken) return;
// One piece of fruit is visibly consumed; six remain in the crate.
const fruit = fruitMeshes[fruitCursor];
fruitCursor += 1;
const fruitStart = fruit.position.clone();
const hopperPosition = new THREE.Vector3(-3.75, 2.22, -0.12);
await animate(0.44, (t) => {
fruit.position.lerpVectors(fruitStart, hopperPosition, t);
fruit.position.y += Math.sin(Math.PI * t) * 0.32;
fruit.rotation.x += 0.09;
fruit.rotation.z += 0.07;
});
if (token !== runToken) return;
fruit.visible = false;
setLiquidFill(bottle, 0.02);
juicePulse.visible = true;
const fillAnimation = animate(0.78, (t) => {
setLiquidFill(bottle, 0.02 + t * 0.98);
}, easeOutCubic);
const juicerAnimation = animate(0.62, (t) => {
juicerGroup.rotation.z = Math.sin(t * Math.PI * 10) * 0.035;
juicePulse.position.x = -3.35 + t * 3.1;
});
await Promise.all([fillAnimation, juicerAnimation]);
if (token !== runToken) return;
juicePulse.visible = false;
juicerGroup.rotation.z = 0;
bottle.state = "filled";
bottle.queueSlot = queueSlotCursor;
updateUI();
const waitingPosition = queuePositions[bottle.queueSlot];
await moveTo(bottle.group, waitingPosition, 0.34, 0.12);
if (token !== runToken) return;
if (capStock > 0) {
await moveTo(bottle.group, CAPPER_POSITION, 0.35, 0.12);
if (token !== runToken) return;
const capped = await applyCap(bottle, token);
if (!capped) return;
await moveTo(
bottle.group,
finishedPositions[finishedCount - 1],
0.42,
0.12
);
} else {
// The slot remains occupied: the filled bottle waits visibly for a cap.
queueSlotCursor += 1;
setStatus(
`${bottle.id} filled — cap missing`,
`The finished counter is held at ${finishedCount}. Fruit and empty bottles remain available; caps are the only blocker.`,
"alert"
);
}
await delay(90);
}
busy = false;
updateUI();
const remaining = getQueueCount();
if (remaining > 0 && capStock === 0) {
setStatus(
"CAP TRAY EMPTY",
`${remaining} filled bottles are waiting in the yellow queue. The finished-unit counter is unchanged until caps arrive.`,
"alert"
);
} else {
setStatus(
"Production complete",
"Every bottle is filled, capped, and counted as a finished unit.",
"good"
);
}
}
async function deliverCaps() {
if (busy || capStock !== 0 || getQueueCount() === 0) return;
busy = true;
updateUI();
setStatus(
"Cap courier arriving",
"A small delivery of six caps is coming to replenish the empty tray.",
"normal"
);
deliveryBox.visible = true;
deliveryBox.position.set(8.2, 0.18, 2.45);
deliveryBox.rotation.y = -0.15;
await moveTo(
deliveryBox,
new THREE.Vector3(1.6, 0.18, 2.25),
1.05,
0.06
);
if (runToken !== runToken) return;
for (let i = 0; i < 6; i++) {
const source = deliveryBox.position.clone().add(
new THREE.Vector3(
-0.38 + (i % 3) * 0.38,
0.7,
-0.16 + Math.floor(i / 3) * 0.3
)
);
const target = traySlotWorld(capStock);
const flyingCap = createFlyingCap();
flyingCap.position.copy(source);
await animate(
0.43,
(t) => {
flyingCap.position.lerpVectors(source, target, t);
flyingCap.position.y += Math.sin(Math.PI * t) * 0.72;
flyingCap.rotation.x = t * Math.PI * 2;
},
easeInOutCubic
);
scene.remove(flyingCap);
capStock += 1;
refreshCapTray();
updateUI();
}
await moveTo(
deliveryBox,
new THREE.Vector3(8.5, 0.18, 2.45),
0.8,
0
);
deliveryBox.visible = false;
setStatus(
"Caps delivered — draining the queue",
"The waiting filled bottles are returning to the capping press in order.",
"good"
);
const waitingBottles = bottles
.filter((bottle) => bottle.state === "filled")
.sort((a, b) => a.id.localeCompare(b.id));
for (const bottle of waitingBottles) {
await moveTo(bottle.group, CAPPER_POSITION, 0.4, 0.13);
const capped = await applyCap(bottle, runToken);
if (!capped) break;
await moveTo(
bottle.group,
finishedPositions[finishedCount - 1],
0.45,
0.13
);
}
busy = false;
updateUI();
setStatus(
"Queue cleared",
"The delivered caps completed the waiting bottles. The finished-unit counter now matches the capped bottles.",
"good"
);
}
function resetWorld() {
capStock = 2;
finishedCount = 0;
fruitCursor = 0;
queueSlotCursor = 0;
busy = false;
bottles.forEach((bottle) => {
bottle.group.position.copy(bottle.home);
bottle.group.rotation.set(0, 0, 0);
bottle.state = "empty";
bottle.queueSlot = null;
bottle.cap.visible = false;
setLiquidFill(bottle, 0);
});
fruitMeshes.forEach((fruit) => {
fruit.visible = true;
fruit.position.copy(fruit.userData.home);
fruit.scale.setScalar(1);
});
juicePulse.visible = false;
juicerGroup.rotation.z = 0;
pressHead.position.y = pressHomeY;
deliveryBox.visible = false;
refreshCapTray();
updateUI();
deliveryTitleEl.textContent = "Deliver 6 caps";
deliverySubtitleEl.textContent = "Available when the tray empties";
setStatus(
"Line starting…",
"Fruit, empty bottles, and a small cap tray are ready.",
"normal"
);
}
async function startNewRun() {
const token = ++runToken;
resetWorld();
await delay(750);
if (token === runToken) runLine(token);
}
deliveryBtn.addEventListener("click", deliverCaps);
replayBtn.addEventListener("click", () => {
if (!busy) startNewRun();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
function frame() {
requestAnimationFrame(frame);
const now = performance.now();
for (const tween of [...tweens]) {
const raw = Math.min(1, (now - tween.start) / tween.duration);
tween.update(tween.easing(raw), raw);
if (raw >= 1) {
tweens.delete(tween);
tween.resolve();
}
}
renderer.render(scene, camera);
}
frame();
startNewRun();
</script>
</body>
</html>
```