Prompt specification
Build or customize the Three.js 3D scene "Bread from field to table" 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: Bread from field to table
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bread-from-field-to-table-x0088
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: bread from field to table. Build four connected miniature stations for grain, flour, dough, and bread; move labeled batches through transformations, showing which steps change shape and which produce new structure. Return one self-contained HTML file.
Working Three.js Starter (bread-from-field-to-table-x0088):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#eee6d8" />
<title>Field to Table — Four Miniature Stations</title>
<style>
:root {
--ink: #28342e;
--muted: #697169;
--paper: rgba(255, 252, 245, 0.88);
--line: rgba(45, 59, 50, 0.13);
--amber: #d9912f;
--amber-soft: #f4d8a9;
--teal: #258b83;
--teal-soft: #bde0da;
--green: #557a58;
--shadow: 0 18px 55px rgba(67, 55, 36, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 30%, #fbf8ef 0%, #eee6d8 72%);
color: var(--ink);
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#scene,
#labels {
position: fixed;
inset: 0;
}
#scene {
z-index: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
#labels {
z-index: 4;
overflow: hidden;
pointer-events: none;
}
header {
position: fixed;
z-index: 10;
top: 28px;
left: 32px;
max-width: 480px;
pointer-events: none;
}
.eyebrow {
display: block;
margin-bottom: 8px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 3.4vw, 52px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.04em;
}
header p {
max-width: 420px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: fixed;
z-index: 12;
top: 26px;
right: 28px;
display: flex;
align-items: center;
gap: 8px;
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 15px;
background: var(--paper);
box-shadow: 0 10px 35px rgba(68, 55, 36, 0.1);
backdrop-filter: blur(16px);
}
.live-pill {
display: flex;
align-items: center;
gap: 7px;
height: 34px;
padding: 0 11px;
border-radius: 9px;
background: rgba(85, 122, 88, 0.1);
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
}
.live-pill i {
width: 7px;
height: 7px;
border-radius: 50%;
background: #6c9b69;
box-shadow: 0 0 0 4px rgba(108, 155, 105, 0.14);
animation: pulse 1.8s ease-in-out infinite;
}
.controls button {
height: 34px;
min-width: 36px;
padding: 0 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.7);
color: var(--ink);
cursor: pointer;
font-size: 12px;
font-weight: 700;
transition: transform 150ms ease, background 150ms ease;
}
.controls button:hover {
background: #fff;
transform: translateY(-1px);
}
.controls button:active {
transform: translateY(0);
}
.controls button:focus-visible {
outline: 2px solid var(--teal);
outline-offset: 2px;
}
.camera-hint {
position: fixed;
z-index: 8;
right: 30px;
bottom: 156px;
color: rgba(40, 52, 46, 0.58);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
pointer-events: none;
}
.process-panel {
position: fixed;
z-index: 12;
left: 50%;
bottom: 22px;
width: min(1040px, calc(100vw - 48px));
padding: 16px 18px 15px;
transform: translateX(-50%);
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.process-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
margin-bottom: 13px;
}
.process-title {
display: flex;
align-items: baseline;
gap: 12px;
}
.process-title .eyebrow {
margin: 0;
font-size: 9px;
}
.process-title strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
font-weight: 500;
}
.legend {
display: flex;
align-items: center;
gap: 15px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
white-space: nowrap;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
display: inline-block;
width: 9px;
height: 9px;
border-radius: 50%;
}
.legend .shape-dot {
background: var(--amber);
}
.legend .structure-dot {
background: var(--teal);
}
.process-scroll {
overflow-x: auto;
scrollbar-width: thin;
}
.process-track {
display: grid;
grid-template-columns:
minmax(126px, 1fr) 105px minmax(126px, 1fr) 125px
minmax(126px, 1fr) 125px minmax(126px, 1fr);
align-items: center;
min-width: 760px;
}
.process-step {
position: relative;
display: flex;
align-items: center;
gap: 10px;
min-height: 49px;
padding: 8px 11px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.48);
transition: border-color 200ms ease, background 200ms ease;
}
.process-step::before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 3px;
content: "";
background: var(--station-color);
opacity: 0.65;
}
.process-step.active {
border-color: color-mix(in srgb, var(--station-color), transparent 55%);
background: rgba(255, 255, 255, 0.88);
}
.step-no {
display: grid;
width: 29px;
height: 29px;
flex: 0 0 auto;
place-items: center;
border-radius: 50%;
background: color-mix(in srgb, var(--station-color), white 77%);
color: color-mix(in srgb, var(--station-color), #17251f 25%);
font-size: 10px;
font-weight: 900;
}
.process-step strong,
.process-step small {
display: block;
}
.process-step strong {
font-size: 11px;
letter-spacing: 0.09em;
}
.process-step small {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.connector {
position: relative;
display: flex;
align-items: center;
justify-content: center;
gap: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.connector::before,
.connector::after {
width: 15px;
height: 1px;
content: "";
background: rgba(40, 52, 46, 0.2);
}
.tag {
padding: 4px 6px;
border-radius: 999px;
white-space: nowrap;
}
.tag.shape {
background: rgba(217, 145, 47, 0.16);
color: #a76716;
}
.tag.structure {
background: rgba(37, 139, 131, 0.15);
color: #20766f;
}
.station-label,
.flow-label,
.batch-label {
position: absolute;
top: 0;
left: 0;
will-change: transform;
transition: opacity 120ms ease;
}
.station-label {
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px 7px 7px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 10px;
background: rgba(255, 253, 247, 0.91);
box-shadow: 0 7px 20px rgba(61, 49, 32, 0.12);
backdrop-filter: blur(8px);
white-space: nowrap;
}
.station-label .station-number {
display: grid;
width: 27px;
height: 27px;
place-items: center;
border-radius: 8px;
background: var(--station-color);
color: white;
font-size: 9px;
font-weight: 900;
}
.station-label strong,
.station-label small {
display: block;
}
.station-label strong {
font-size: 10px;
letter-spacing: 0.11em;
}
.station-label small {
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
.flow-label {
display: flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 999px;
box-shadow: 0 5px 15px rgba(61, 49, 32, 0.1);
backdrop-filter: blur(8px);
white-space: nowrap;
}
.flow-label i {
width: 8px;
height: 8px;
border-radius: 50%;
}
.flow-label strong,
.flow-label small {
display: block;
}
.flow-label strong {
font-size: 8px;
letter-spacing: 0.1em;
}
.flow-label small {
margin-top: 1px;
color: var(--muted);
font-size: 7px;
}
.flow-label.shape {
background: rgba(255, 247, 230, 0.92);
}
.flow-label.shape i {
background: var(--amber);
}
.flow-label.structure {
background: rgba(235, 251, 247, 0.92);
}
.flow-label.structure i {
background: var(--teal);
}
.flow-label.both {
background: rgba(255, 249, 239, 0.94);
}
.flow-label.both i {
background: linear-gradient(90deg, var(--amber) 50%, var(--teal) 50%);
}
.batch-label {
display: flex;
align-items: center;
gap: 7px;
min-width: 108px;
padding: 6px 9px 6px 6px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 10px;
background: rgba(42, 55, 47, 0.9);
color: white;
box-shadow: 0 8px 22px rgba(35, 43, 37, 0.22);
backdrop-filter: blur(8px);
white-space: nowrap;
}
.batch-label .batch-id {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border-radius: 7px;
background: #f1e8d5;
color: #344139;
font-size: 10px;
font-weight: 900;
}
.batch-label strong,
.batch-label small {
display: block;
}
.batch-label strong {
font-size: 9px;
letter-spacing: 0.1em;
}
.batch-label small {
margin-top: 2px;
color: rgba(255, 255, 255, 0.65);
font-size: 7px;
}
.batch-label.mode-shape {
border-color: rgba(244, 216, 169, 0.9);
}
.batch-label.mode-shape .batch-id {
background: var(--amber-soft);
color: #855015;
}
.batch-label.mode-structure {
border-color: rgba(189, 224, 218, 0.9);
}
.batch-label.mode-structure .batch-id {
background: var(--teal-soft);
color: #176b64;
}
.batch-label.mode-both {
border-color: rgba(233, 190, 120, 0.9);
}
.batch-label.mode-both .batch-id {
background: linear-gradient(135deg, var(--amber-soft), var(--teal-soft));
color: #324139;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #eee6d8;
transition: opacity 400ms ease, visibility 400ms ease;
}
#loading.hide {
visibility: hidden;
opacity: 0;
}
.loader {
text-align: center;
}
.loader-wheel {
width: 34px;
height: 34px;
margin: 0 auto 13px;
border: 4px solid rgba(85, 122, 88, 0.18);
border-top-color: var(--green);
border-radius: 50%;
animation: spin 900ms linear infinite;
}
.loader span {
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@keyframes pulse {
0%,
100% {
transform: scale(0.85);
opacity: 0.72;
}
50% {
transform: scale(1.1);
opacity: 1;
}
}
@media (max-width: 760px) {
header {
top: 18px;
left: 18px;
max-width: 270px;
}
h1 {
font-size: 34px;
}
header p {
display: none;
}
.controls {
top: 16px;
right: 14px;
gap: 5px;
padding: 5px;
}
.live-pill {
display: none;
}
.controls button {
height: 32px;
padding: 0 9px;
}
.process-panel {
bottom: 10px;
width: calc(100vw - 20px);
padding: 12px;
border-radius: 14px;
}
.process-top {
margin-bottom: 9px;
}
.process-title strong {
display: none;
}
.legend {
gap: 9px;
font-size: 8px;
}
.camera-hint {
display: none;
}
.station-label small,
.flow-label small,
.batch-label small {
display: none;
}
.station-label {
gap: 5px;
padding: 5px;
}
.station-label .station-number {
width: 22px;
height: 22px;
border-radius: 6px;
font-size: 7px;
}
.station-label strong {
font-size: 8px;
}
.flow-label {
padding: 4px 6px;
}
.flow-label strong {
font-size: 7px;
}
.batch-label {
min-width: 0;
gap: 5px;
padding: 4px 6px 4px 4px;
}
.batch-label .batch-id {
width: 21px;
height: 21px;
border-radius: 6px;
font-size: 8px;
}
.batch-label strong {
font-size: 7px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="scene"></div>
<div id="labels"></div>
<header>
<span class="eyebrow">Field → Table · Miniature Process</span>
<h1>Four stations.<br />One loaf.</h1>
<p>
Follow three labeled batches as whole grain becomes flour, flour
becomes structured dough, and dough becomes bread.
</p>
</header>
<nav class="controls" aria-label="Animation controls">
<div class="live-pill">
<i></i>
<span id="liveText">LIVE</span>
</div>
<button id="pauseButton" type="button" title="Pause or play">Pause</button>
<button id="stepButton" type="button" title="Advance two seconds">+2s</button>
<button id="speedButton" type="button" title="Change speed">1×</button>
<button id="resetButton" type="button" title="Reset batches" aria-label="Reset batches">↺</button>
</nav>
<div class="camera-hint">DRAG TO ORBIT · SCROLL TO ZOOM · SPACE TO PAUSE</div>
<section class="process-panel" aria-label="Bread transformation map">
<div class="process-top">
<div class="process-title">
<span class="eyebrow">Process Map</span>
<strong>Kernel → flour → dough → bread</strong>
</div>
<div class="legend" aria-label="Transformation legend">
<span><i class="shape-dot"></i> Shape change</span>
<span><i class="structure-dot"></i> New structure</span>
</div>
</div>
<div class="process-scroll">
<div class="process-track">
<div class="process-step" data-stage="0" style="--station-color:#d3a044">
<span class="step-no">01</span>
<span><strong>GRAIN</strong><small>whole kernels</small></span>
</div>
<div class="connector"><span class="tag shape">Shape</span></div>
<div class="process-step" data-stage="1" style="--station-color:#d9c6a2">
<span class="step-no">02</span>
<span><strong>FLOUR</strong><small>resized particles</small></span>
</div>
<div class="connector"><span class="tag structure">Structure</span></div>
<div class="process-step" data-stage="2" style="--station-color:#a8b99d">
<span class="step-no">03</span>
<span><strong>DOUGH</strong><small>gluten network</small></span>
</div>
<div class="connector">
<span class="tag shape">Shape</span>
<span class="tag structure">Structure</span>
</div>
<div class="process-step" data-stage="3" style="--station-color:#b96d38">
<span class="step-no">04</span>
<span><strong>BREAD</strong><small>crust + crumb</small></span>
</div>
</div>
</div>
</section>
<div id="loading">
<div class="loader">
<div class="loader-wheel"></div>
<span>Building the miniature</span>
</div>
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene, renderer, camera, and direct camera controls
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee6d8);
scene.fog = new THREE.Fog(0xeee6d8, 24, 43);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly scene showing grain becoming flour, dough, and bread"
);
document.querySelector("#scene").appendChild(renderer.domElement);
const target = new THREE.Vector3(0, 0.7, -0.25);
let azimuth = 0.31;
let polar = 0.68;
let defaultAzimuth = azimuth;
let defaultPolar = polar;
function fittedRadius() {
const verticalFov = THREE.MathUtils.degToRad(camera.fov);
const horizontalFov =
2 * Math.atan(Math.tan(verticalFov / 2) * camera.aspect);
return Math.max(
17,
(9.7 / Math.tan(horizontalFov / 2)) * 1.05
);
}
let radius = fittedRadius();
const defaultRadius = radius;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
azimuth -= deltaX * 0.006;
polar = THREE.MathUtils.clamp(polar + deltaY * 0.005, 0.36, 1.22);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
8,
46
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
azimuth = defaultAzimuth;
polar = defaultPolar;
radius = defaultRadius;
});
// -------------------------------------------------------------------------
// Lighting and common low-poly construction helpers
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff8e8, 0x72816d, 2.2));
const sun = new THREE.DirectionalLight(0xfff5df, 3.1);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d7d3, 1.25);
fill.position.set(9, 6, -8);
scene.add(fill);
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
function addMesh(parent, geometry, material, position = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(
parent,
width,
height,
depth,
position,
material,
castShadow = true
) {
const mesh = addMesh(
parent,
new THREE.BoxGeometry(width, height, depth),
material,
position
);
mesh.castShadow = castShadow;
return mesh;
}
function addCylinder(
parent,
topRadius,
bottomRadius,
height,
segments,
position,
material
) {
return addMesh(
parent,
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
material,
position
);
}
let randomSeed = 82471;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const palette = {
base: makeMaterial(0xcbbda5),
top: makeMaterial(0xe7dcc8),
belt: makeMaterial(0x53625a),
beltTop: makeMaterial(0x69766d),
rail: makeMaterial(0x9b7650),
dark: makeMaterial(0x3f4c45),
stone: makeMaterial(0xc8bca7),
roof: makeMaterial(0x9d5941),
wood: makeMaterial(0xa8794e),
woodLight: makeMaterial(0xc59663),
soil: makeMaterial(0x9e744b),
wheat: makeMaterial(0xd5a63e),
wheatLight: makeMaterial(0xe5c264),
leaf: makeMaterial(0x849358),
flour: makeMaterial(0xf0e6cc),
flourLight: makeMaterial(0xfff7e4),
dough: makeMaterial(0xe8d2a5),
crumb: makeMaterial(0xf3dfb6),
crust: makeMaterial(0xc77d35),
crustDark: makeMaterial(0x8f4f27),
brick: makeMaterial(0xb86445),
sack: makeMaterial(0xd7c49d),
teal: makeMaterial(0x4caaa0, {
emissive: 0x174d49,
emissiveIntensity: 0.45
})
};
// -------------------------------------------------------------------------
// Diorama base
// -------------------------------------------------------------------------
const diorama = new THREE.Group();
scene.add(diorama);
const base = addBox(
diorama,
19.8,
0.42,
7.7,
[0, -0.25, -0.45],
palette.base,
false
);
base.receiveShadow = true;
addBox(
diorama,
19.45,
0.08,
7.35,
[0, -0.01, -0.45],
palette.top,
false
);
const edgeMaterial = makeMaterial(0xb6a88f);
addBox(
diorama,
19.55,
0.1,
0.12,
[0, -0.03, 3.34],
edgeMaterial,
false
);
addBox(
diorama,
19.55,
0.1,
0.12,
[0, -0.03, -4.24],
edgeMaterial,
false
);
// Small ground markings make the model feel intentionally constructed.
const markingMaterial = makeMaterial(0xd8cbb5);
for (let x = -8.4; x <= 8.4; x += 1.4) {
addBox(
diorama,
0.035,
0.012,
0.38,
[x, 0.045, 2.75],
markingMaterial,
false
);
}
// -------------------------------------------------------------------------
// Connected conveyor
// -------------------------------------------------------------------------
const routeZ = 0.62;
const conveyor = new THREE.Group();
scene.add(conveyor);
addBox(
conveyor,
17.4,
0.18,
0.78,
[0, 0.64, routeZ],
palette.belt
);
addBox(
conveyor,
17.4,
0.055,
0.68,
[0, 0.765, routeZ],
palette.beltTop,
false
);
addBox(
conveyor,
17.55,
0.09,
0.09,
[0, 0.8, routeZ - 0.46],
palette.rail
);
addBox(
conveyor,
17.55,
0.09,
0.09,
[0, 0.8, routeZ + 0.46],
palette.rail
);
const slatMaterial = makeMaterial(0x829087);
for (let x = -8.35; x <= 8.35; x += 0.42) {
addBox(
conveyor,
0.045,
0.025,
0.64,
[x, 0.805, routeZ],
slatMaterial,
false
);
}
const supportMaterial = makeMaterial(0x6d6557);
for (let x = -8.1; x <= 8.1; x += 1.62) {
addBox(
conveyor,
0.11,
0.58,
0.11,
[x, 0.29, routeZ - 0.27],
supportMaterial
);
addBox(
conveyor,
0.11,
0.58,
0.11,
[x, 0.29, routeZ + 0.27],
supportMaterial
);
}
// -------------------------------------------------------------------------
// Station 1: grain field
// -------------------------------------------------------------------------
const grainStation = new THREE.Group();
scene.add(grainStation);
addBox(
grainStation,
3.85,
0.12,
2.45,
[-7.2, 0.07, -1.5],
palette.soil
);
const furrowMaterial = makeMaterial(0x8c683f);
for (let row = 0; row < 4; row++) {
addBox(
grainStation,
3.55,
0.025,
0.09,
[-7.2, 0.145, -2.35 + row * 0.55],
furrowMaterial,
false
);
}
const stalkGeometry = new THREE.CylinderGeometry(0.022, 0.032, 1, 5);
const headGeometry = new THREE.DodecahedronGeometry(0.105, 0);
const leafGeometry = new THREE.ConeGeometry(0.085, 0.34, 4);
for (let row = 0; row < 4; row++) {
for (let column = 0; column < 5; column++) {
const x = -8.55 + column * 0.67 + (random() - 0.5) * 0.12;
const z = -2.32 + row * 0.55 + (random() - 0.5) * 0.1;
const height = 0.85 + random() * 0.3;
const stalk = addMesh(
grainStation,
stalkGeometry,
palette.wheat,
[x, 0.14 + height / 2, z]
);
stalk.rotation.z = (random() - 0.5) * 0.09;
const leaf = addMesh(
grainStation,
leafGeometry,
palette.leaf,
[x + 0.08, 0.42 + height * 0.2, z]
);
leaf.rotation.z = random() > 0.5 ? -0.9 : 0.9;
leaf.rotation.x = 0.25;
for (let kernel = 0; kernel < 3; kernel++) {
const head = addMesh(
grainStation,
headGeometry,
kernel % 2 ? palette.wheat : palette.wheatLight,
[
x + (random() - 0.5) * 0.045,
0.88 + height * 0.53 + kernel * 0.115,
z + (random() - 0.5) * 0.045
]
);
head.scale.set(0.8, 1.25, 0.8);
}
}
}
function addSack(x, z, rotation = 0) {
const sack = new THREE.Group();
sack.position.set(x, 0, z);
sack.rotation.y = rotation;
scene.add(sack);
addCylinder(
sack,
0.29,
0.43,
0.74,
8,
[0, 0.38, 0],
palette.sack
);
const band = addMesh(
sack,
new THREE.TorusGeometry(0.305, 0.025, 4, 12),
palette.woodLight,
[0, 0.47, 0]
);
band.rotation.x = Math.PI / 2;
addCylinder(
sack,
0.24,
0.27,
0.1,
8,
[0, 0.78, 0],
palette.flour
);
}
addSack(-8.95, -0.05, 0.2);
addSack(-5.48, 0.03, -0.18);
// -------------------------------------------------------------------------
// Station 2: flour mill
// -------------------------------------------------------------------------
const millStation = new THREE.Group();
scene.add(millStation);
addCylinder(
millStation,
1.02,
1.08,
0.16,
10,
[-2.4, 0.08, -1.45],
palette.stone
);
addCylinder(
millStation,
0.78,
0.87,
1.48,
9,
[-2.4, 0.85, -1.45],
palette.stone
);
addMesh(
millStation,
new THREE.ConeGeometry(1.02, 0.72, 9),
palette.roof,
[-2.4, 1.93, -1.45]
);
addBox(
millStation,
0.48,
0.75,
0.055,
[-2.4, 0.43, -0.605],
palette.dark
);
const millBand = addMesh(
millStation,
new THREE.TorusGeometry(0.8, 0.055, 5, 16),
palette.wood,
[-2.4, 0.91, -1.45]
);
millBand.rotation.x = Math.PI / 2;
const millRotor = new THREE.Group();
millRotor.position.set(-2.4, 1.25, -0.55);
millStation.add(millRotor);
for (let blade = 0; blade < 4; blade++) {
const part = addBox(
millRotor,
0.15,
0.58,
0.055,
[0, 0, 0],
palette.woodLight
);
part.rotation.z = (blade * Math.PI) / 2;
part.position.x = Math.sin((blade * Math.PI) / 2) * 0.16;
part.position.y = Math.cos((blade * Math.PI) / 2) * 0.16;
}
addMesh(
millStation,
new THREE.CircleGeometry(0.12, 10),
palette.dark,
[-2.4, 1.25, -0.505]
);
addCylinder(
millStation,
0.48,
0.26,
0.55,
8,
[-1.18, 1.37, -1.23],
palette.woodLight
);
addCylinder(
millStation,
0.35,
0.35,
0.45,
10,
[-1.18, 0.78, -1.23],
palette.flour
);
// -------------------------------------------------------------------------
// Station 3: dough table
// -------------------------------------------------------------------------
const doughStation = new THREE.Group();
scene.add(doughStation);
addBox(
doughStation,
3.05,
0.18,
1.5,
[2.4, 1.02, -1.45],
palette.woodLight
);
const tableLegMaterial = makeMaterial(0x79563c);
[
[1.08, -2.02],
[3.72, -2.02],
[1.08, -0.88],
[3.72, -0.88]
].forEach(([x, z]) => {
addBox(
doughStation,
0.16,
1.02,
0.16,
[x, 0.49, z],
tableLegMaterial
);
});
const bowlProfile = [
new THREE.Vector2(0.14, 0),
new THREE.Vector2(0.27, 0.05),
new THREE.Vector2(0.43, 0.22),
new THREE.Vector2(0.5, 0.29)
];
addMesh(
doughStation,
new THREE.LatheGeometry(bowlProfile, 12),
palette.flour,
[2.02, 1.12, -1.4]
);
const tableDough = addMesh(
doughStation,
new THREE.IcosahedronGeometry(0.39, 1),
palette.dough,
[2.05, 1.39, -1.4]
);
tableDough.scale.set(1.1, 0.68, 0.95);
const rollingPin = addCylinder(
doughStation,
0.11,
0.11,
0.88,
10,
[3.25, 1.22, -1.08],
palette.wood
);
rollingPin.rotation.z = Math.PI / 2;
addCylinder(
doughStation,
0.045,
0.045,
0.4,
8,
[2.85, 1.22, -1.08],
palette.woodLight
).rotation.z = Math.PI / 2;
addSack(3.85, -0.1, 0.35);
// -------------------------------------------------------------------------
// Station 4: bread oven and cooling table
// -------------------------------------------------------------------------
const breadStation = new THREE.Group();
scene.add(breadStation);
addBox(
breadStation,
2.7,
0.18,
2.25,
[7.2, 0.09, -1.43],
palette.brick
);
const ovenDome = addMesh(
breadStation,
new THREE.SphereGeometry(1.12, 11, 7),
palette.brick,
[7.2, 0.72, -1.42]
);
ovenDome.scale.set(1, 0.8, 1);
const archShape = new THREE.Shape();
archShape.moveTo(-0.48, 0);
archShape.lineTo(0.48, 0);
archShape.lineTo(0.48, 0.52);
archShape.absarc(0, 0.52, 0.48, 0, Math.PI, false);
archShape.lineTo(-0.48, 0);
archShape.closePath();
addMesh(
breadStation,
new THREE.ShapeGeometry(archShape),
makeMaterial(0x2c2924),
[7.2, 0.17, -0.245]
);
const innerShape = new THREE.Shape();
innerShape.moveTo(-0.34, 0);
innerShape.lineTo(0.34, 0);
innerShape.lineTo(0.34, 0.48);
innerShape.absarc(0, 0.48, 0.34, 0, Math.PI, false);
innerShape.lineTo(-0.34, 0);
innerShape.closePath();
const fire = addMesh(
breadStation,
new THREE.ShapeGeometry(innerShape),
makeMaterial(0xe48b36, {
emissive: 0xb84f13,
emissiveIntensity: 0.8
}),
[7.2, 0.22, -0.225]
);
fire.castShadow = false;
addBox(
breadStation,
0.34,
0.8,
0.36,
[7.72, 2.05, -1.53],
palette.brick
);
addBox(
breadStation,
0.43,
0.12,
0.43,
[7.72, 2.48, -1.53],
palette.dark
);
addBox(
breadStation,
1.25,
0.14,
0.75,
[8.65, 0.93, -0.92],
palette.woodLight
);
for (const x of [8.2, 9.1]) {
addBox(
breadStation,
0.12,
0.88,
0.12,
[x, 0.44, -0.92],
tableLegMaterial
);
}
const displayLoaf = addMesh(
breadStation,
new THREE.SphereGeometry(0.44, 10, 6),
palette.crust,
[8.65, 1.16, -0.92]
);
displayLoaf.scale.set(1.2, 0.72, 0.82);
// -------------------------------------------------------------------------
// Ambient steam
// -------------------------------------------------------------------------
const steam = [];
for (let index = 0; index < 5; index++) {
const material = makeMaterial(0xfff8e8, {
transparent: true,
opacity: 0.2,
depthWrite: false
});
const puff = addMesh(
breadStation,
new THREE.IcosahedronGeometry(0.13, 0),
material,
[7.2 + (random() - 0.5) * 0.25, 1.7, -1.18]
);
puff.castShadow = false;
steam.push({
mesh: puff,
offset: random(),
speed: 0.12 + random() * 0.06
});
}
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelLayer = document.querySelector("#labels");
const projectedVector = new THREE.Vector3();
function createOverlay(html, className, position) {
const element = document.createElement("div");
element.className = className;
element.innerHTML = html;
labelLayer.appendChild(element);
return {
element,
position: new THREE.Vector3(...position)
};
}
function placeOverlay(item, dynamicPosition = null) {
projectedVector.copy(dynamicPosition || item.position).project(camera);
const visible = projectedVector.z > -1 && projectedVector.z < 1;
item.element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projectedVector.x * 0.5 + 0.5) * innerWidth;
const y = (-projectedVector.y * 0.5 + 0.5) * innerHeight;
item.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -100%)`;
}
const stationLabels = [
createOverlay(
`<span class="station-number">01</span>
<span><strong>GRAIN</strong><small>whole kernels</small></span>`,
"station-label",
[-7.2, 2.33, -1.48]
),
createOverlay(
`<span class="station-number">02</span>
<span><strong>FLOUR</strong><small>resized particles</small></span>`,
"station-label",
[-2.4, 2.72, -1.43]
),
createOverlay(
`<span class="station-number">03</span>
<span><strong>DOUGH</strong><small>gluten network</small></span>`,
"station-label",
[2.4, 2.12, -1.42]
),
createOverlay(
`<span class="station-number">04</span>
<span><strong>BREAD</strong><small>crust + crumb</small></span>`,
"station-label",
[7.2, 2.68, -1.3]
)
];
stationLabels[0].element.style.setProperty("--station-color", "#d3a044");
stationLabels[1].element.style.setProperty("--station-color", "#c9ae77");
stationLabels[2].element.style.setProperty("--station-color", "#78936f");
stationLabels[3].element.style.setProperty("--station-color", "#b96d38");
const flowLabels = [
createOverlay(
`<i></i><span><strong>RESIZE</strong><small>shape change</small></span>`,
"flow-label shape",
[-4.8, 1.65, routeZ]
),
createOverlay(
`<i></i><span><strong>GLUTEN</strong><small>new structure</small></span>`,
"flow-label structure",
[0, 1.65, routeZ]
),
createOverlay(
`<i></i><span><strong>SPRING + SET</strong><small>shape and structure</small></span>`,
"flow-label both",
[4.8, 1.65, routeZ]
)
];
// -------------------------------------------------------------------------
// Batch shapes
// -------------------------------------------------------------------------
function createGrainVariant(index) {
const group = new THREE.Group();
const positions = [
[-0.24, 0.15, -0.09],
[-0.12, 0.12, 0.08],
[0.01, 0.17, -0.04],
[0.17, 0.13, 0.08],
[0.27, 0.16, -0.1],
[-0.08, 0.29, -0.02],
[0.11, 0.31, -0.04],
[-0.29, 0.28, 0.02],
[0.02, 0.24, 0.18]
];
const geometry = new THREE.DodecahedronGeometry(0.135, 0);
positions.forEach((position, kernelIndex) => {
const material = makeMaterial(
kernelIndex % 2 ? 0xd7a238 : 0xe3b951
);
const kernel = addMesh(group, geometry, material, position);
kernel.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
kernel.scale.set(
0.8 + random() * 0.2,
1.15 + random() * 0.25,
0.8 + random() * 0.2
);
});
return group;
}
function createFlourVariant(index) {
const group = new THREE.Group();
const tint = index === 1 ? 0xeee1c3 : 0xf2e8d0;
addMesh(
group,
new THREE.ConeGeometry(0.61, 0.61, 9),
makeMaterial(tint),
[0, 0.305, 0]
);
addMesh(
group,
new THREE.IcosahedronGeometry(0.3, 0),
makeMaterial(index === 1 ? 0xf6ead2 : 0xfff5df),
[0.04, 0.55, 0.01]
).scale.set(1.25, 0.65, 1);
const powderGeometry = new THREE.IcosahedronGeometry(0.045, 0);
for (let speck = 0; speck < 8; speck++) {
const angle = (speck / 8) * Math.PI * 2;
addMesh(
group,
powderGeometry,
palette.flourLight,
[
Math.cos(angle) * (0.39 + random() * 0.2),
0.045,
Math.sin(angle) * (0.39 + random() * 0.2)
]
);
}
return group;
}
function createDoughVariant(index) {
const group = new THREE.Group();
const geometry = new THREE.IcosahedronGeometry(0.58, 1);
const positions = geometry.attributes.position;
for (let vertex = 0; vertex < positions.count; vertex++) {
const x = positions.getX(vertex);
const y = positions.getY(vertex);
const z = positions.getZ(vertex);
const variation = 0.94 + Math.sin(vertex * 4.91 + index) * 0.075;
positions.setXYZ(
vertex,
x * 1.08 * variation,
y * 0.72 * variation,
z * 0.92 * variation
);
}
geometry.computeVertexNormals();
addMesh(
group,
geometry,
makeMaterial(index === 1 ? 0xe5cca0 : palette.dough.color.getHex()),
[0, 0.43, 0]
);
const bubbleGeometry = new THREE.IcosahedronGeometry(0.048, 0);
[
[-0.24, 0.73, 0.13],
[0.18, 0.75, -0.04],
[0.04, 0.65, 0.34]
].forEach((position) => {
addMesh(
group,
bubbleGeometry,
palette.flourLight,
position
);
});
return group;
}
function createBreadVariant(index) {
const group = new THREE.Group();
const crustColor = index === 1 ? 0xbf7130 : 0xc77d35;
const loaf = addMesh(
group,
new THREE.SphereGeometry(0.62, 10, 6),
makeMaterial(crustColor),
[0, 0.39, 0]
);
loaf.scale.set(1.25, 0.72, 0.84);
const scoreMaterial = makeMaterial(0x8c4826);
[-0.31, 0, 0.31].forEach((x, scoreIndex) => {
const normalized = x / 0.775;
const y =
0.39 +
0.446 * Math.sqrt(Math.max(0, 1 - normalized * normalized)) +
0.012;
const score = addBox(
group,
0.3,
0.026,
0.055,
[x, y, 0.025],
scoreMaterial
);
score.rotation.z = [-0.22, 0, 0.22][scoreIndex];
});
const flourDustGeometry = new THREE.IcosahedronGeometry(0.025, 0);
for (let speck = 0; speck < 6; speck++) {
addMesh(
group,
flourDustGeometry,
palette.flourLight,
[
-0.4 + random() * 0.8,
0.78 - random() * 0.1,
-0.18 + random() * 0.36
]
);
}
return group;
}
// -------------------------------------------------------------------------
// Batch animation
// -------------------------------------------------------------------------
const stations = [
{ x: -7.2 },
{ x: -2.4 },
{ x: 2.4 },
{ x: 7.2 }
];
const cycleDuration = 17;
const timeline = [
{ type: "dwell", stage: 0, start: 0, end: 2.4 },
{
type: "move",
from: 0,
to: 1,
start: 2.4,
end: 4.6,
mode: "shape"
},
{ type: "dwell", stage: 1, start: 4.6, end: 6.5 },
{
type: "move",
from: 1,
to: 2,
start: 6.5,
end: 9,
mode: "structure"
},
{ type: "dwell", stage: 2, start: 9, end: 11 },
{
type: "move",
from: 2,
to: 3,
start: 11,
end: 14,
mode: "both"
},
{ type: "dwell", stage: 3, start: 14, end: 17 }
];
function smoothstep(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function getPhase(time) {
const wrapped = ((time % cycleDuration) + cycleDuration) % cycleDuration;
for (const phase of timeline) {
if (wrapped >= phase.start && wrapped < phase.end) {
return { ...phase, progress: (wrapped - phase.start) / (phase.end - phase.start) };
}
}
return { ...timeline[timeline.length - 1], progress: 1 };
}
class Batch {
constructor(index, offset) {
this.index = index;
this.offset = offset;
this.root = new THREE.Group();
scene.add(this.root);
this.variants = [
createGrainVariant(index),
createFlourVariant(index),
createDoughVariant(index),
createBreadVariant(index)
];
this.variants.forEach((variant) => {
variant.visible = false;
this.root.add(variant);
});
this.label = document.createElement("div");
this.label.className = "batch-label";
this.label.innerHTML = `
<span class="batch-id">${String.fromCharCode(65 + index)}</span>
<span><strong>GRAIN</strong><small>whole kernels</small></span>
`;
labelLayer.appendChild(this.label);
this.labelKey = "";
this.targetStage = 0;
this.particleMaterials = {
amber: makeMaterial(0xe0ad45, {
emissive: 0x6b4310,
emissiveIntensity: 0.4
}),
cream: makeMaterial(0xfff4dc, {
emissive: 0x806b3b,
emissiveIntensity: 0.25
}),
teal: makeMaterial(0x3aa69b, {
emissive: 0x155b55,
emissiveIntensity: 0.75
}),
orange: makeMaterial(0xd57b2f, {
emissive: 0x78330e,
emissiveIntensity: 0.65
})
};
this.particles = [];
const particleGeometry = new THREE.TetrahedronGeometry(0.055, 0);
for (let particle = 0; particle < 16; particle++) {
const mesh = addMesh(
this.root,
particleGeometry,
this.particleMaterials.amber,
[0, 0, 0]
);
mesh.castShadow = false;
this.particles.push(mesh);
}
this.ringMaterial = makeMaterial(0xe3a13b, {
emissive: 0x815016,
emissiveIntensity: 0.6,
transparent: true,
opacity: 0.85
});
this.ring = addMesh(
this.root,
new THREE.TorusGeometry(0.66, 0.035, 6, 28),
this.ringMaterial,
[0, 0.14, 0]
);
this.ring.rotation.x = Math.PI / 2;
this.ring.visible = false;
this.webMaterial = new THREE.LineBasicMaterial({
color: 0x2caaa0,
transparent: true,
opacity: 0,
depthWrite: false
});
const webPoints = [];
for (let node = 0; node < 10; node++) {
webPoints.push(
new THREE.Vector3(
(random() - 0.5) * 0.95,
0.25 + random() * 0.58,
(random() - 0.5) * 0.7
)
);
}
const webPositions = [];
for (let edge = 0; edge < 14; edge++) {
const first = webPoints[edge % webPoints.length];
const second = webPoints[(edge * 3 + 2) % webPoints.length];
webPositions.push(
first.x,
first.y,
first.z,
second.x,
second.y,
second.z
);
}
const webGeometry = new THREE.BufferGeometry();
webGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(webPositions, 3)
);
this.web = new THREE.LineSegments(webGeometry, this.webMaterial);
this.root.add(this.web);
this.web.visible = false;
}
update(time) {
const phase = getPhase(time + this.offset);
const progress = phase.progress;
this.variants.forEach((variant) => {
variant.visible = false;
variant.scale.setScalar(0.001);
variant.position.set(0, 0, 0);
variant.rotation.set(0, 0, 0);
});
this.particles.forEach((particle) => {
particle.visible = false;
});
this.ring.visible = false;
this.web.visible = false;
this.webMaterial.opacity = 0;
if (phase.type === "dwell") {
const variant = this.variants[phase.stage];
variant.visible = true;
variant.scale.setScalar(1);
this.root.position.set(
stations[phase.stage].x,
0.84,
routeZ
);
this.targetStage = phase.stage;
} else {
const oldVariant = this.variants[phase.from];
const newVariant = this.variants[phase.to];
const eased = smoothstep(progress);
const oldScale = Math.max(0.001, 1 - Math.pow(progress, 1.65));
const newScale = Math.max(0.001, Math.pow(progress, 0.68));
oldVariant.visible = oldScale > 0.012;
newVariant.visible = newScale > 0.012;
oldVariant.scale.setScalar(oldScale);
newVariant.scale.setScalar(newScale);
oldVariant.rotation.y = -progress * Math.PI * 0.55;
newVariant.rotation.y = (1 - progress) * Math.PI * 0.55;
oldVariant.position.y = Math.sin(progress * Math.PI) * 0.08;
newVariant.position.y = Math.sin(progress * Math.PI) * 0.06;
const startX = stations[phase.from].x;
const endX = stations[phase.to].x;
this.root.position.set(
THREE.MathUtils.lerp(startX, endX, eased),
0.84 + Math.sin(progress * Math.PI) * 0.14,
routeZ + Math.sin(progress * Math.PI) * 0.16
);
this.targetStage = phase.to;
this.ring.visible = true;
this.ring.position.y = 0.14;
this.ring.scale.setScalar(
0.75 + Math.sin(progress * Math.PI) * 0.4
);
this.ring.rotation.z = progress * Math.PI;
let particleMaterial = this.particleMaterials.amber;
let ringColor = 0xe0a03a;
if (phase.mode === "structure") {
particleMaterial = this.particleMaterials.teal;
ringColor = 0x36a89f;
} else if (phase.mode === "both") {
particleMaterial =
this.particles[0].material === this.particleMaterials.teal
? this.particleMaterials.teal
: this.particleMaterials.orange;
ringColor = 0xd17832;
}
this.ringMaterial.color.setHex(ringColor);
this.ringMaterial.emissive.setHex(ringColor);
this.ringMaterial.emissiveIntensity = 0.45;
this.particles.forEach((particle, particleIndex) => {
particle.visible = true;
if (phase.mode === "shape") {
particle.material =
particleIndex % 3 === 0
? this.particleMaterials.cream
: this.particleMaterials.amber;
} else if (phase.mode === "structure") {
particle.material = this.particleMaterials.teal;
} else {
particle.material =
particleIndex % 2 === 0
? this.particleMaterials.orange
: this.particleMaterials.teal;
}
const angle =
particleIndex * 2.399 +
progress * Math.PI * (phase.mode === "structure" ? 4 : 2);
const radius =
phase.mode === "structure"
? 0.52 + Math.sin(progress * Math.PI) * 0.18
: 0.24 + Math.sin(progress * Math.PI) * 0.56;
particle.position.set(
Math.cos(angle) * radius,
0.25 + Math.sin(angle * 1.7) * 0.22 + progress * 0.12,
Math.sin(angle) * radius
);
particle.rotation.set(
angle,
angle * 0.7,
progress * Math.PI * 2
);
particle.scale.setScalar(
0.65 + Math.sin(progress * Math.PI) * 0.8
);
});
if (phase.mode === "structure" || phase.mode === "both") {
this.web.visible = true;
this.webMaterial.opacity =
Math.sin(progress * Math.PI) * 0.72;
this.web.rotation.y = progress * Math.PI * 0.3;
}
}
const key = `${phase.type}-${phase.stage ?? ""}-${
phase.from ?? ""
}-${phase.to ?? ""}`;
if (key !== this.labelKey) {
this.labelKey = key;
let mode = "neutral";
let heading = "";
let detail = "";
if (phase.type === "dwell") {
const details = [
["GRAIN", "whole kernels", "neutral"],
["FLOUR", "smaller particles", "shape"],
["DOUGH", "gluten network", "structure"],
["BREAD", "crust + crumb", "both"]
];
[heading, detail, mode] = details[phase.stage];
} else if (phase.mode === "shape") {
heading = "RESIZING";
detail = "shape change";
mode = "shape";
} else if (phase.mode === "structure") {
heading = "GLUTEN FORMS";
detail = "new structure";
mode = "structure";
} else {
heading = "OVEN SPRING";
detail = "shape + set structure";
mode = "both";
}
this.label.className = `batch-label mode-${mode}`;
this.label.innerHTML = `
<span class="batch-id">${String.fromCharCode(65 + this.index)}</span>
<span><strong>${heading}</strong><small>${detail}</small></span>
`;
}
}
}
const batches = [
new Batch(0, 0),
new Batch(1, 5.7),
new Batch(2, 11.4)
];
// -------------------------------------------------------------------------
// Interface controls
// -------------------------------------------------------------------------
let elapsed = 0;
let paused = matchMedia("(prefers-reduced-motion: reduce)").matches;
let speed = 1;
const speeds = [0.5, 1, 1.5, 2];
const pauseButton = document.querySelector("#pauseButton");
const speedButton = document.querySelector("#speedButton");
const resetButton = document.querySelector("#resetButton");
const stepButton = document.querySelector("#stepButton");
const liveText = document.querySelector("#liveText");
const processSteps = [
...document.querySelectorAll(".process-step")
];
function updateControlLabels() {
pauseButton.textContent = paused ? "Play" : "Pause";
pauseButton.setAttribute("aria-pressed", String(paused));
liveText.textContent = paused ? "PAUSED" : "LIVE";
speedButton.textContent = `${speed}×`;
}
pauseButton.addEventListener("click", () => {
paused = !paused;
updateControlLabels();
});
speedButton.addEventListener("click", () => {
const nextIndex = (speeds.indexOf(speed) + 1) % speeds.length;
speed = speeds[nextIndex];
updateControlLabels();
});
resetButton.addEventListener("click", () => {
elapsed = 0;
updateActiveSteps();
});
stepButton.addEventListener("click", () => {
elapsed += 2;
updateActiveSteps();
});
updateControlLabels();
function updateActiveSteps() {
const active = new Set(batches.map((batch) => batch.targetStage));
processSteps.forEach((step, index) => {
step.classList.toggle("active", active.has(index));
});
}
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.code === "Space") {
event.preventDefault();
paused = !paused;
updateControlLabels();
} else if (event.key.toLowerCase() === "r") {
elapsed = 0;
updateActiveSteps();
} else if (event.key === "ArrowLeft") {
azimuth += 0.08;
} else if (event.key === "ArrowRight") {
azimuth -= 0.08;
} else if (event.key === "ArrowUp") {
polar = Math.max(0.36, polar - 0.06);
} else if (event.key === "ArrowDown") {
polar = Math.min(1.22, polar + 0.06);
}
});
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
function onResize() {
camera.fov = innerWidth < 700 ? 52 : 42;
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
onResize();
radius = fittedRadius();
const clock = new THREE.Clock();
const batchLabelPosition = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) elapsed += delta * speed;
updateCamera();
millRotor.rotation.z = elapsed * 0.34;
steam.forEach((puff, index) => {
const progress = (puff.offset + elapsed * puff.speed) % 1;
puff.mesh.position.y = 1.65 + progress * 1.15;
puff.mesh.position.x =
7.2 + Math.sin(progress * 5 + index) * 0.15;
puff.mesh.position.z =
-1.18 + Math.cos(progress * 4 + index) * 0.08;
puff.mesh.scale.setScalar(0.7 + progress * 1.4);
puff.mesh.material.opacity =
Math.sin(progress * Math.PI) * 0.2;
});
batches.forEach((batch) => {
batch.update(elapsed);
batchLabelPosition.set(
batch.root.position.x,
batch.root.position.y + 1.25,
batch.root.position.z
);
placeOverlay({ element: batch.label }, batchLabelPosition);
});
stationLabels.forEach((label) => placeOverlay(label));
flowLabels.forEach((label) => placeOverlay(label));
updateActiveSteps();
renderer.render(scene, camera);
}
batches.forEach((batch) => batch.update(elapsed));
updateActiveSteps();
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hide");
});
</script>
</body>
</html>
```