Prompt specification
Build or customize the Three.js 3D scene "Harvest timing cooperative game" 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: Harvest timing cooperative game
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/harvest-timing-cooperative-game-x0116
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Create an orchard-to-market board with simplified ripening stages and delivery delays; users choose harvest timing and observe freshness categories change along the visible transport route.
Working Three.js Starter (harvest-timing-cooperative-game-x0116):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Orchard → Market</title>
<style>
:root {
--ink: #26352d;
--muted: #6f796f;
--panel: rgba(255, 253, 245, 0.92);
--line: rgba(57, 79, 63, 0.14);
--green: #2f8f68;
--green-dark: #24664d;
--fresh: #2f9f76;
--good: #ddb23f;
--soon: #e76f51;
--overripe: #8b5a73;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8ebdf;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
position: relative;
width: 100%;
height: 100%;
min-height: 560px;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.topbar {
position: absolute;
z-index: 10;
top: 0;
left: 0;
right: 0;
height: 78px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 26px;
pointer-events: none;
background: linear-gradient(
to bottom,
rgba(239, 241, 229, 0.94),
rgba(239, 241, 229, 0)
);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border-radius: 13px 13px 16px 16px;
background: var(--green-dark);
box-shadow: 0 7px 18px rgba(37, 87, 63, 0.18);
}
.brand-mark::before {
content: "";
position: absolute;
left: 17px;
top: -5px;
width: 5px;
height: 13px;
border-radius: 4px;
background: #5d754a;
transform: rotate(25deg);
}
.brand-mark::after {
content: "";
position: absolute;
left: 10px;
top: 12px;
width: 18px;
height: 15px;
border-radius: 50% 50% 48% 48%;
background: #ef9e64;
}
.brand h1 {
margin: 0;
font-size: 19px;
line-height: 1;
letter-spacing: -0.04em;
}
.brand h1 span {
color: var(--muted);
font-weight: 500;
}
.brand p {
margin: 6px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.live-pill {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
border: 1px solid rgba(54, 101, 75, 0.18);
border-radius: 999px;
background: rgba(255, 255, 248, 0.75);
color: var(--green-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #45a477;
box-shadow: 0 0 0 4px rgba(69, 164, 119, 0.12);
}
.icon-button {
width: 38px;
height: 38px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 248, 0.78);
cursor: pointer;
backdrop-filter: blur(10px);
transition:
transform 160ms ease,
background 160ms ease;
}
.icon-button:hover {
transform: translateY(-1px);
background: #fffdf7;
}
.panel {
position: absolute;
z-index: 9;
border: 1px solid rgba(62, 82, 65, 0.14);
border-radius: 22px;
background: var(--panel);
box-shadow:
0 20px 60px rgba(52, 65, 50, 0.12),
0 2px 10px rgba(52, 65, 50, 0.04);
backdrop-filter: blur(18px);
}
.control-panel {
top: 98px;
left: 24px;
width: 326px;
padding: 22px;
}
.route-panel {
top: 98px;
right: 24px;
width: 302px;
padding: 22px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 22px;
line-height: 1.15;
letter-spacing: -0.045em;
}
.intro {
margin: 10px 0 20px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.field-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 10px;
color: #59645b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.timing-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.timing-choice {
min-width: 0;
padding: 12px 5px 10px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.45);
cursor: pointer;
text-align: center;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease,
box-shadow 160ms ease;
}
.timing-choice:hover {
transform: translateY(-1px);
border-color: rgba(47, 143, 104, 0.35);
}
.timing-choice[aria-pressed="true"] {
border-color: var(--green);
background: #edf6ed;
box-shadow: inset 0 0 0 1px var(--green);
}
.timing-icon {
display: block;
margin-bottom: 5px;
font-size: 20px;
line-height: 1;
}
.timing-choice strong {
display: block;
font-size: 12px;
}
.timing-choice small {
display: block;
margin-top: 4px;
overflow: hidden;
color: var(--muted);
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
.stage-strip {
display: flex;
align-items: center;
gap: 6px;
margin: 10px 0 22px;
padding: 10px 12px;
border-radius: 12px;
background: rgba(229, 233, 220, 0.62);
color: #5d695f;
font-size: 11px;
}
.stage-strip strong {
color: var(--ink);
}
.stage-dots {
display: flex;
flex: 1;
gap: 4px;
}
.stage-dot {
height: 4px;
flex: 1;
border-radius: 99px;
background: #cbd2c3;
}
.stage-dot.on {
background: var(--green);
}
.delay-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
}
.delay-value {
color: var(--green-dark);
font-size: 12px;
font-weight: 850;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 7px 0 8px;
border-radius: 999px;
outline: none;
appearance: none;
background:
linear-gradient(
to right,
var(--green) 0%,
var(--green) var(--range-fill, 0%),
#dce1d7 var(--range-fill, 0%),
#dce1d7 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #fff;
border-radius: 50%;
appearance: none;
background: var(--green);
box-shadow: 0 2px 7px rgba(29, 70, 48, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #fff;
border-radius: 50%;
background: var(--green);
box-shadow: 0 2px 7px rgba(29, 70, 48, 0.25);
}
.range-caption {
display: flex;
justify-content: space-between;
color: #899087;
font-size: 9px;
}
.brief {
position: relative;
margin: 19px 0;
padding: 13px 13px 13px 37px;
border: 1px solid rgba(55, 103, 74, 0.12);
border-radius: 13px;
background: #edf3e8;
color: #536358;
font-size: 11px;
line-height: 1.5;
}
.brief::before {
content: "i";
position: absolute;
left: 13px;
top: 13px;
display: grid;
width: 16px;
height: 16px;
place-items: center;
border-radius: 50%;
background: var(--green);
color: white;
font-size: 10px;
font-weight: 800;
}
.primary-button {
display: flex;
width: 100%;
min-height: 47px;
align-items: center;
justify-content: center;
gap: 9px;
border: 0;
border-radius: 13px;
background: var(--green-dark);
color: white;
box-shadow: 0 9px 20px rgba(36, 102, 77, 0.18);
cursor: pointer;
font-size: 13px;
font-weight: 800;
transition:
transform 160ms ease,
background 160ms ease;
}
.primary-button:hover {
transform: translateY(-1px);
background: #1e5b43;
}
.primary-button:active {
transform: translateY(1px);
}
.button-icon {
font-size: 11px;
}
.panel-footer {
margin-top: 12px;
color: #8a9189;
font-size: 9px;
text-align: center;
}
.route-summary {
display: flex;
align-items: center;
justify-content: space-between;
margin: 16px 0 18px;
padding: 12px;
border-radius: 13px;
background: #eef1e7;
}
.route-summary small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.route-summary strong {
font-size: 12px;
}
.route-badge {
min-width: 74px;
padding: 7px 9px;
border-radius: 9px;
color: white;
font-size: 10px;
font-weight: 850;
text-align: center;
}
.route-list {
position: relative;
margin: 0;
padding: 0;
list-style: none;
}
.route-list::before {
content: "";
position: absolute;
top: 15px;
bottom: 15px;
left: 9px;
width: 1px;
background: #d5dbd1;
}
.route-step {
position: relative;
display: grid;
grid-template-columns: 20px 1fr auto;
gap: 9px;
align-items: start;
padding: 8px 0;
}
.route-node {
z-index: 1;
width: 9px;
height: 9px;
margin: 5px 0 0 5px;
border: 2px solid #fffdf6;
border-radius: 50%;
background: var(--step-color);
box-shadow: 0 0 0 1px var(--step-color);
}
.step-title {
display: block;
font-size: 11px;
font-weight: 800;
}
.step-detail {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.step-category {
margin-top: 1px;
padding: 5px 7px;
border-radius: 7px;
background: color-mix(in srgb, var(--step-color) 14%, white);
color: var(--step-color);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.arrival {
margin-top: 16px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.arrival-line {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 8px;
}
.arrival-line span {
color: var(--muted);
font-size: 10px;
}
.arrival-line strong {
font-size: 12px;
}
.quality-track {
height: 7px;
overflow: hidden;
border-radius: 99px;
background: #e1e5dc;
}
.quality-fill {
width: 50%;
height: 100%;
border-radius: inherit;
background: var(--fresh);
transition:
width 300ms ease,
background 300ms ease;
}
.legend {
position: absolute;
z-index: 8;
bottom: 23px;
left: 50%;
display: flex;
align-items: center;
gap: 16px;
padding: 11px 16px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 253, 245, 0.86);
box-shadow: 0 10px 30px rgba(53, 65, 51, 0.09);
backdrop-filter: blur(14px);
transform: translateX(-50%);
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #667067;
font-size: 9px;
font-weight: 750;
white-space: nowrap;
}
.legend-swatch {
width: 8px;
height: 8px;
border-radius: 50%;
}
.camera-hint {
position: absolute;
z-index: 7;
right: 26px;
bottom: 27px;
color: rgba(55, 71, 59, 0.64);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
@media (max-width: 900px) {
.route-panel {
display: none;
}
.control-panel {
width: 306px;
}
.legend {
left: auto;
right: 18px;
transform: none;
}
.camera-hint {
display: none;
}
}
@media (max-width: 620px) {
#app {
min-height: 620px;
}
.topbar {
height: 66px;
padding: 0 14px;
}
.brand h1 {
font-size: 16px;
}
.brand p,
.live-pill {
display: none;
}
.brand-mark {
width: 34px;
height: 34px;
}
.control-panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 47vh;
padding: 17px;
overflow-y: auto;
border-radius: 18px;
}
.control-panel h2,
.intro {
display: none;
}
.control-panel .eyebrow {
margin-bottom: 12px;
}
.stage-strip {
margin-bottom: 14px;
}
.brief {
margin: 13px 0;
}
.legend {
top: 72px;
right: 10px;
bottom: auto;
gap: 9px;
padding: 8px 10px;
}
.legend-item {
font-size: 8px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="scene" aria-label="Interactive low-poly orchard to market scene"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Orchard <span>/ Market</span></h1>
<p>Field-to-fork freshness board</p>
</div>
</div>
<div class="top-actions">
<div class="live-pill">
<span class="live-dot"></span>
<span id="liveStatus">Live simulation</span>
</div>
<button
id="resetCamera"
class="icon-button"
type="button"
aria-label="Reset camera"
title="Reset camera"
>
↺
</button>
</div>
</header>
<section class="panel control-panel" aria-labelledby="planTitle">
<div class="eyebrow">01 / Harvest plan</div>
<h2 id="planTitle">Pick the harvest moment</h2>
<p class="intro">
Change ripeness and holding time to see how freshness shifts at every
stop on the route.
</p>
<div class="field-label">
<span>Harvest timing</span>
<span id="harvestDate">JUL 20</span>
</div>
<div class="timing-grid" role="group" aria-label="Harvest timing">
<button
class="timing-choice"
data-timing="early"
type="button"
aria-pressed="false"
>
<span class="timing-icon">◔</span>
<strong>Early</strong>
<small>Developing</small>
</button>
<button
class="timing-choice"
data-timing="peak"
type="button"
aria-pressed="true"
>
<span class="timing-icon">◕</span>
<strong>Peak</strong>
<small>Market ripe</small>
</button>
<button
class="timing-choice"
data-timing="late"
type="button"
aria-pressed="false"
>
<span class="timing-icon">●</span>
<strong>Late</strong>
<small>Fully ripe</small>
</button>
</div>
<div class="stage-strip">
<span>Ripening</span>
<div class="stage-dots" aria-hidden="true">
<span class="stage-dot"></span>
<span class="stage-dot"></span>
<span class="stage-dot"></span>
</div>
<strong id="stageLabel">Market ripe</strong>
</div>
<div class="field-label">
<span>Delivery delay</span>
</div>
<div class="delay-row">
<span style="font-size: 11px; color: var(--muted)">Warm holding time</span>
<span id="delayValue" class="delay-value">0 days</span>
</div>
<input
id="delayRange"
type="range"
min="0"
max="3"
step="1"
value="0"
aria-label="Delivery delay in days"
/>
<div class="range-caption">
<span>Same day</span>
<span>3 days</span>
</div>
<div id="routeMessage" class="brief"></div>
<button id="startDelivery" class="primary-button" type="button">
<span id="buttonIcon" class="button-icon">▶</span>
<span id="buttonLabel">Send to market</span>
</button>
<div class="panel-footer">12 minute route · visual quality model</div>
</section>
<aside class="panel route-panel" aria-labelledby="routeTitle">
<div class="eyebrow">02 / Route watch</div>
<h2 id="routeTitle">Freshness along the way</h2>
<div class="route-summary">
<div>
<small>Current plan</small>
<strong id="currentPlan">Peak harvest · same day</strong>
</div>
<div id="routeBadge" class="route-badge">Fresh</div>
</div>
<ol id="routeList" class="route-list"></ol>
<div class="arrival">
<div class="arrival-line">
<span>Predicted market quality</span>
<strong id="arrivalQuality">98%</strong>
</div>
<div class="quality-track">
<div id="qualityFill" class="quality-fill"></div>
</div>
</div>
</aside>
<div class="legend" aria-label="Freshness category legend">
<div class="legend-item">
<span class="legend-swatch" style="background: var(--fresh)"></span>
Fresh
</div>
<div class="legend-item">
<span class="legend-swatch" style="background: var(--good)"></span>
Good
</div>
<div class="legend-item">
<span class="legend-swatch" style="background: var(--soon)"></span>
Use soon
</div>
<div class="legend-item">
<span class="legend-swatch" style="background: var(--overripe)"></span>
Overripe
</div>
</div>
<div class="camera-hint">Drag to orbit · scroll to zoom</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Application state
// ---------------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const timingButtons = [...document.querySelectorAll("[data-timing]")];
const delayRange = document.querySelector("#delayRange");
const delayValue = document.querySelector("#delayValue");
const harvestDate = document.querySelector("#harvestDate");
const stageLabel = document.querySelector("#stageLabel");
const routeMessage = document.querySelector("#routeMessage");
const routeList = document.querySelector("#routeList");
const routeBadge = document.querySelector("#routeBadge");
const currentPlan = document.querySelector("#currentPlan");
const arrivalQuality = document.querySelector("#arrivalQuality");
const qualityFill = document.querySelector("#qualityFill");
const startButton = document.querySelector("#startDelivery");
const buttonIcon = document.querySelector("#buttonIcon");
const buttonLabel = document.querySelector("#buttonLabel");
const liveStatus = document.querySelector("#liveStatus");
const stageDots = [...document.querySelectorAll(".stage-dot")];
const timingConfig = {
early: {
label: "Early",
date: "JUL 18",
maturity: 0.48,
stage: "Developing"
},
peak: {
label: "Peak",
date: "JUL 20",
maturity: 0.66,
stage: "Market ripe"
},
late: {
label: "Late",
date: "JUL 22",
maturity: 0.82,
stage: "Fully ripe"
}
};
const categories = {
fresh: {
label: "Fresh",
color: 0x2f9f76,
css: "#2f9f76"
},
good: {
label: "Good",
color: 0xddb23f,
css: "#ddb23f"
},
soon: {
label: "Use soon",
color: 0xe76f51,
css: "#e76f51"
},
overripe: {
label: "Overripe",
color: 0x8b5a73,
css: "#8b5a73"
}
};
const routeNodes = [
{ title: "Orchard pick", t: 0.0 },
{ title: "Packhouse", t: 0.25 },
{ title: "Country road", t: 0.52 },
{ title: "Market gate", t: 0.78 },
{ title: "Market stall", t: 1.0 }
];
let selectedTiming = "peak";
let deliveryDelay = 0;
let deliveryRunning = false;
let deliveryProgress = 0;
let deliveryComplete = false;
// ---------------------------------------------------------------------
// Three.js renderer, scene, lighting
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(sceneHost.clientWidth, sceneHost.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8ebdf);
scene.fog = new THREE.Fog(0xe8ebdf, 24, 39);
const camera = new THREE.PerspectiveCamera(
42,
sceneHost.clientWidth / sceneHost.clientHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xf8f4df, 0x8c9a82, 2.35);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d5, 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 = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xb8d7cf, 0.65);
fillLight.position.set(10, 6, -8);
scene.add(fillLight);
// ---------------------------------------------------------------------
// Custom camera controls: drag to orbit, wheel/pinch to zoom
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.45, 0),
theta: 0.66,
phi: 0.87,
radius: 21
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
const narrow = sceneHost.clientWidth / sceneHost.clientHeight < 1;
cameraState.theta = 0.66;
cameraState.phi = 0.87;
cameraState.radius = narrow ? 27 : 21;
cameraState.target.set(0, 0.45, 0);
updateCamera();
}
resetCamera();
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.theta -= deltaX * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.004,
0.38,
1.28
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch {
// Pointer may already have been released.
}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.015,
12,
31
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#resetCamera").addEventListener("click", resetCamera);
// ---------------------------------------------------------------------
// Materials and geometry helpers
// ---------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.86,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
}
function mesh(geometry, mat, position, parent = scene) {
const object = new THREE.Mesh(geometry, mat);
if (position) object.position.copy(position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(size, position, color, parent = scene, options = {}) {
return mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material(color, options),
position,
parent
);
}
function cylinder(
radiusTop,
radiusBottom,
height,
position,
color,
segments = 8,
parent = scene
) {
return mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material(color),
position,
parent
);
}
function lowPolySphere(radius, position, color, parent = scene) {
return mesh(
new THREE.IcosahedronGeometry(radius, 0),
material(color),
position,
parent
);
}
let randomSeed = 9472;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
// ---------------------------------------------------------------------
// Board, grass, soil and decorative patches
// ---------------------------------------------------------------------
const board = box(
new THREE.Vector3(18.8, 0.5, 11.4),
new THREE.Vector3(0, -0.25, 0),
0xd7cdb3
);
board.castShadow = false;
const grass = box(
new THREE.Vector3(18.45, 0.08, 11.05),
new THREE.Vector3(0, 0.04, 0),
0xa8bb8f
);
grass.castShadow = false;
const patchMaterial = material(0xb9c89b);
const dryPatchMaterial = material(0xc6c89e);
const patches = [
[-6.9, -3.4, 2.1, 0xb4c393],
[-0.1, -3.2, 1.65, 0xc4c69c],
[4.8, -3.1, 2.0, 0xb4c393],
[7.7, 2.8, 1.45, 0xc1c69a]
];
for (const [x, z, radius, color] of patches) {
const patch = mesh(
new THREE.CircleGeometry(radius, 12),
material(color),
new THREE.Vector3(x, 0.086, z)
);
patch.rotation.x = -Math.PI / 2;
patch.castShadow = false;
}
// Fine decorative tufts.
const tuftMaterial = material(0x718b65);
for (let i = 0; i < 34; i++) {
const x = -8.6 + random() * 17.2;
const z = -4.8 + random() * 9.6;
if (x > -7.7 && x < -4.5 && z > -4 && z < -1.2) continue;
const tuft = mesh(
new THREE.ConeGeometry(0.09, 0.3, 3),
tuftMaterial,
new THREE.Vector3(x, 0.23, z)
);
tuft.rotation.z = (random() - 0.5) * 0.22;
}
// ---------------------------------------------------------------------
// Transport route
// ---------------------------------------------------------------------
const routeCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-7.1, 0.13, -1.05),
new THREE.Vector3(-5.3, 0.13, -0.1),
new THREE.Vector3(-3.4, 0.13, 0.67),
new THREE.Vector3(-0.8, 0.13, 1.02),
new THREE.Vector3(2.0, 0.13, 0.8),
new THREE.Vector3(4.2, 0.13, 0.08),
new THREE.Vector3(6.4, 0.13, -0.08)
],
false,
"catmullrom",
0.35
);
const roadSegments = 34;
const routeTiles = [];
for (let i = 0; i < roadSegments; i++) {
const t1 = i / roadSegments;
const t2 = (i + 1) / roadSegments;
const p1 = routeCurve.getPointAt(t1);
const p2 = routeCurve.getPointAt(t2);
const midpoint = p1.clone().add(p2).multiplyScalar(0.5);
const dx = p2.x - p1.x;
const dz = p2.z - p1.z;
const length = Math.hypot(dx, dz);
const road = box(
new THREE.Vector3(length + 0.025, 0.045, 0.72),
new THREE.Vector3(midpoint.x, 0.105, midpoint.z),
0xd9d1b9
);
road.rotation.y = -Math.atan2(dz, dx);
road.castShadow = false;
const tileMaterial = material(categories.fresh.color);
const tile = box(
new THREE.Vector3(length * 0.92, 0.022, 0.16),
new THREE.Vector3(midpoint.x, 0.133, midpoint.z),
categories.fresh.color
);
tile.material = tileMaterial;
tile.rotation.y = road.rotation.y;
tile.castShadow = false;
routeTiles.push(tileMaterial);
}
// Small roadside posts.
for (const t of [0.16, 0.4, 0.63, 0.87]) {
const point = routeCurve.getPointAt(t);
const tangent = routeCurve.getTangentAt(t);
const normal = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
for (const side of [-1, 1]) {
const postPosition = point
.clone()
.add(normal.clone().multiplyScalar(side * 0.56));
postPosition.y = 0.43;
cylinder(
0.035,
0.045,
0.7,
postPosition,
0xf1ead5,
6
);
const cap = mesh(
new THREE.SphereGeometry(0.065, 6, 4),
material(side > 0 ? 0xe8b651 : 0x6c9b74),
new THREE.Vector3(postPosition.x, 0.8, postPosition.z)
);
cap.castShadow = false;
}
}
// ---------------------------------------------------------------------
// Orchard
// ---------------------------------------------------------------------
const orchardSoil = box(
new THREE.Vector3(4.5, 0.045, 2.65),
new THREE.Vector3(-6.25, 0.092, -2.75),
0x9d8765
);
orchardSoil.castShadow = false;
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(
0.11,
0.16,
1.25,
new THREE.Vector3(0, 0.62, 0),
0x78553b,
7,
group
);
const branch = cylinder(
0.045,
0.065,
0.72,
new THREE.Vector3(0.18, 1.02, 0),
0x78553b,
6,
group
);
branch.rotation.z = -0.65;
const foliageColors = [0x648d58, 0x739b61, 0x587f4f];
const canopyData = [
[0, 1.55, 0, 0.76],
[-0.42, 1.39, 0.12, 0.56],
[0.4, 1.45, -0.04, 0.59]
];
canopyData.forEach(([cx, cy, cz, radius], index) => {
const canopy = mesh(
new THREE.IcosahedronGeometry(radius, 0),
material(foliageColors[index]),
new THREE.Vector3(cx, cy, cz),
group
);
canopy.rotation.set(random(), random(), random());
});
const fruitPositions = [
[-0.44, 1.35, 0.47],
[0.42, 1.4, 0.4],
[0.06, 1.06, 0.59],
[-0.1, 1.75, 0.51]
];
fruitPositions.forEach((position) => {
lowPolySphere(
0.105,
new THREE.Vector3(...position),
0xe77845,
group
);
});
return group;
}
createTree(-7.35, -3.15, 1.08);
createTree(-5.85, -3.55, 0.96);
createTree(-6.65, -1.85, 0.86);
createTree(-5.05, -2.15, 0.9);
// Fence around the orchard.
const fenceMaterial = material(0xe6d8b8);
const fencePostPositions = [];
for (let x = -8.15; x <= -4.25; x += 0.78) {
fencePostPositions.push([x, -4.4]);
}
for (let z = -4.4; z <= -1.45; z += 0.78) {
fencePostPositions.push([-8.15, z]);
}
for (const [x, z] of fencePostPositions) {
cylinder(
0.045,
0.055,
0.6,
new THREE.Vector3(x, 0.36, z),
0xe6d8b8,
6
);
}
for (const z of [-4.4, -3.45]) {
const rail = box(
new THREE.Vector3(4.05, 0.07, 0.065),
new THREE.Vector3(-6.2, 0.44, z),
0xe6d8b8
);
rail.castShadow = false;
}
// Crates and hay in the orchard.
function createCrate(parent, position, size = 0.56) {
const group = new THREE.Group();
group.position.copy(position);
parent.add(group);
box(
new THREE.Vector3(size, 0.22, size * 0.85),
new THREE.Vector3(0, 0.12, 0),
0xbd8750,
group
);
box(
new THREE.Vector3(size + 0.03, 0.045, 0.055),
new THREE.Vector3(0, 0.23, -size * 0.29),
0xd39a5e,
group
);
box(
new THREE.Vector3(size + 0.03, 0.045, 0.055),
new THREE.Vector3(0, 0.23, size * 0.29),
0xd39a5e,
group
);
return group;
}
createCrate(scene, new THREE.Vector3(-4.35, 0.1, -3.45), 0.65);
for (let i = 0; i < 5; i++) {
const apple = lowPolySphere(
0.095,
new THREE.Vector3(
-4.35 + (random() - 0.5) * 0.38,
0.31,
-3.45 + (random() - 0.5) * 0.34
),
0xe57b45
);
apple.castShadow = false;
}
for (let i = 0; i < 2; i++) {
const bale = cylinder(
0.36,
0.36,
0.62,
new THREE.Vector3(-8.0 + i * 0.7, 0.43, -0.25),
0xd9b86b,
10
);
bale.rotation.z = Math.PI / 2;
}
// ---------------------------------------------------------------------
// Packhouse
// ---------------------------------------------------------------------
const packhouse = new THREE.Group();
packhouse.position.set(-3.75, 0.08, -2.35);
scene.add(packhouse);
box(
new THREE.Vector3(2.25, 1.35, 1.45),
new THREE.Vector3(0, 0.675, 0),
0xe9dfc4,
packhouse
);
box(
new THREE.Vector3(2.38, 0.16, 1.58),
new THREE.Vector3(0, 1.36, 0),
0x496b57,
packhouse
);
const leftRoof = box(
new THREE.Vector3(1.38, 0.13, 1.72),
new THREE.Vector3(-0.57, 1.56, 0),
0x496b57,
packhouse
);
leftRoof.rotation.z = 0.32;
const rightRoof = box(
new THREE.Vector3(1.38, 0.13, 1.72),
new THREE.Vector3(0.57, 1.56, 0),
0x496b57,
packhouse
);
rightRoof.rotation.z = -0.32;
box(
new THREE.Vector3(0.62, 0.93, 0.05),
new THREE.Vector3(0.22, 0.48, 0.75),
0x8b6247,
packhouse
);
box(
new THREE.Vector3(0.68, 0.13, 0.06),
new THREE.Vector3(0.22, 1.0, 0.77),
0xf3e9cf,
packhouse
);
createCrate(packhouse, new THREE.Vector3(-0.72, 0.02, 1.0), 0.5);
// ---------------------------------------------------------------------
// Market stall
// ---------------------------------------------------------------------
const market = new THREE.Group();
market.position.set(6.25, 0.08, -1.8);
scene.add(market);
box(
new THREE.Vector3(2.55, 0.24, 1.5),
new THREE.Vector3(0, 0.12, 0),
0xc3925f,
market
);
for (const x of [-1.05, 1.05]) {
for (const z of [-0.53, 0.53]) {
cylinder(
0.055,
0.065,
1.55,
new THREE.Vector3(x, 0.87, z),
0xf0e4c9,
6,
market
);
}
}
const awningColors = [0xf0ead8, 0xc75d4d];
for (let i = 0; i < 6; i++) {
const stripe = box(
new THREE.Vector3(0.43, 0.11, 1.85),
new THREE.Vector3(-1.075 + i * 0.43, 1.66, 0),
awningColors[i % 2],
market
);
stripe.rotation.x = -0.08;
}
box(
new THREE.Vector3(2.55, 0.42, 0.18),
new THREE.Vector3(0, 0.38, 0.68),
0xb47b4e,
market
);
const marketFruitMaterial = material(0xe87843);
for (let i = 0; i < 12; i++) {
const fruit = lowPolySphere(
0.11,
new THREE.Vector3(
-0.92 + (i % 6) * 0.36,
0.7 + (i > 5 ? 0.1 : 0),
(i > 5 ? -0.2 : 0.18)
),
i % 3 === 0 ? 0xe3a244 : 0xe87843,
market
);
fruit.castShadow = false;
}
// Small market baskets.
createCrate(market, new THREE.Vector3(-0.6, 0.62, -0.12), 0.44);
createCrate(market, new THREE.Vector3(0.25, 0.62, -0.12), 0.44);
// ---------------------------------------------------------------------
// Canvas sprite helpers
// ---------------------------------------------------------------------
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.lineTo(x + width - r, y);
context.quadraticCurveTo(x + width, y, x + width, y + r);
context.lineTo(x + width, y + height - r);
context.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
context.lineTo(x + r, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - r);
context.lineTo(x, y + r);
context.quadraticCurveTo(x, y, x + r, y);
context.closePath();
}
function createTextSprite(title, subtitle, accent = "#2f8f68") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 220;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const spriteMaterial = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
});
const sprite = new THREE.Sprite(spriteMaterial);
sprite.scale.set(2.15, 0.74, 1);
sprite.renderOrder = 20;
function draw(nextTitle, nextSubtitle, nextAccent) {
context.clearRect(0, 0, canvas.width, canvas.height);
context.shadowColor = "rgba(38, 53, 45, 0.13)";
context.shadowBlur = 18;
context.shadowOffsetY = 5;
roundedRect(
context,
12,
12,
canvas.width - 24,
canvas.height - 24,
30
);
context.fillStyle = "rgba(255, 253, 245, 0.96)";
context.fill();
context.shadowColor = "transparent";
context.lineWidth = 8;
context.strokeStyle = nextAccent;
roundedRect(
context,
12,
12,
canvas.width - 24,
canvas.height - 24,
30
);
context.stroke();
context.beginPath();
context.arc(64, 108, 25, 0, Math.PI * 2);
context.fillStyle = nextAccent;
context.fill();
context.fillStyle = "#2b3b31";
context.font = "800 34px system-ui, sans-serif";
context.fillText(nextTitle.toUpperCase(), 108, 88);
context.fillStyle = nextAccent;
context.font = "800 27px system-ui, sans-serif";
context.fillText(nextSubtitle.toUpperCase(), 108, 137);
texture.needsUpdate = true;
}
draw(title, subtitle, accent);
return { sprite, draw };
}
// Market sign.
const marketSign = createTextSprite(
"Farmers Market",
"Open today",
"#c75d4d"
);
marketSign.sprite.position.set(6.35, 2.45, -2.25);
marketSign.sprite.scale.set(2.75, 0.95, 1);
scene.add(marketSign.sprite);
// Route status signs.
const routeSigns = [];
const signOffsets = [
new THREE.Vector3(0, 0, -1.0),
new THREE.Vector3(0, 0, -0.85),
new THREE.Vector3(0, 0, 0.85),
new THREE.Vector3(0, 0, -0.85),
new THREE.Vector3(0, 0, -1.15)
];
routeNodes.forEach((node, index) => {
const point = routeCurve.getPointAt(node.t).clone();
point.add(signOffsets[index]);
point.y = 0.08;
cylinder(
0.025,
0.035,
1.55,
new THREE.Vector3(point.x, 0.83, point.z),
0xe9dec0,
6
);
const label = createTextSprite(node.title, "Fresh", "#2f9f76");
label.sprite.position.set(point.x, 1.72, point.z);
scene.add(label.sprite);
routeSigns.push({
...label,
node
});
});
// ---------------------------------------------------------------------
// Route sample crates and fruit
// ---------------------------------------------------------------------
const routeSamples = [];
const sampleTimes = [0.08, 0.28, 0.5, 0.72, 0.92];
sampleTimes.forEach((t, index) => {
const point = routeCurve.getPointAt(t);
const tangent = routeCurve.getTangentAt(t);
const normal = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
const side = index % 2 === 0 ? 1 : -1;
const samplePosition = point
.clone()
.add(normal.multiplyScalar(side * 0.67));
samplePosition.y = 0.11;
const group = new THREE.Group();
group.position.copy(samplePosition);
group.rotation.y = -Math.atan2(tangent.z, tangent.x);
scene.add(group);
box(
new THREE.Vector3(0.52, 0.2, 0.44),
new THREE.Vector3(0, 0.1, 0),
0xb9824d,
group
);
box(
new THREE.Vector3(0.54, 0.035, 0.045),
new THREE.Vector3(0, 0.21, -0.16),
0xd29a5d,
group
);
const fruitMaterial = material(categories.fresh.color);
const fruitGeometry = new THREE.IcosahedronGeometry(0.09, 0);
for (let i = 0; i < 3; i++) {
const fruit = mesh(
fruitGeometry,
fruitMaterial,
new THREE.Vector3(
(i - 1) * 0.13,
0.27,
(i % 2 === 0 ? -1 : 1) * 0.055
),
group
);
fruit.castShadow = false;
}
routeSamples.push({ fruitMaterial, t });
});
// ---------------------------------------------------------------------
// Delivery truck
// ---------------------------------------------------------------------
const truck = new THREE.Group();
scene.add(truck);
box(
new THREE.Vector3(1.12, 0.52, 0.78),
new THREE.Vector3(-0.24, 0.51, 0),
0xf1e8cf,
truck
);
box(
new THREE.Vector3(0.57, 0.54, 0.72),
new THREE.Vector3(0.56, 0.48, 0),
0x3f795d,
truck
);
box(
new THREE.Vector3(0.08, 0.31, 0.58),
new THREE.Vector3(0.87, 0.54, 0),
0xb9d6cf,
truck
);
box(
new THREE.Vector3(0.25, 0.18, 0.75),
new THREE.Vector3(0.99, 0.31, 0),
0x3f795d,
truck
);
box(
new THREE.Vector3(0.72, 0.07, 0.83),
new THREE.Vector3(-0.25, 0.81, 0),
0xd8a35f,
truck
);
const wheelGeometry = new THREE.CylinderGeometry(
0.18,
0.18,
0.12,
10
);
const wheelMaterial = material(0x39433e);
for (const x of [-0.52, 0.58]) {
for (const z of [-0.4, 0.4]) {
const wheel = mesh(
wheelGeometry,
wheelMaterial,
new THREE.Vector3(x, 0.23, z),
truck
);
wheel.rotation.x = Math.PI / 2;
}
}
const payloadMaterial = material(categories.fresh.color);
const payloadGeometry = new THREE.IcosahedronGeometry(0.1, 0);
for (let i = 0; i < 6; i++) {
const fruit = mesh(
payloadGeometry,
payloadMaterial,
new THREE.Vector3(
-0.66 + (i % 3) * 0.2,
0.91,
i < 3 ? -0.18 : 0.18
),
truck
);
fruit.castShadow = false;
}
function updateTruck() {
const point = routeCurve.getPointAt(deliveryProgress);
const tangent = routeCurve.getTangentAt(deliveryProgress);
truck.position.copy(point);
truck.rotation.y = -Math.atan2(tangent.z, tangent.x);
payloadMaterial.color.setHex(
categories[evaluateQuality(deliveryProgress).category].color
);
}
updateTruck();
// ---------------------------------------------------------------------
// Freshness model
// ---------------------------------------------------------------------
function evaluateQuality(routePosition) {
const timing = timingConfig[selectedTiming];
let maturity = timing.maturity;
if (selectedTiming === "early") {
maturity += 0.1 * routePosition;
} else if (selectedTiming === "peak") {
maturity += 0.015 * routePosition;
} else {
maturity -= 0.025 * routePosition;
}
// Warm holding before delivery raises ripeness and adds handling loss.
maturity += deliveryDelay * 0.065;
const deviation = Math.abs(maturity - 0.67);
const overripeDamage = Math.max(0, maturity - 0.86) * 1.3;
const conditionLoss =
deviation * 1.2 +
deliveryDelay * 0.145 +
routePosition * 0.11 +
overripeDamage;
const quality = THREE.MathUtils.clamp(1 - conditionLoss, 0, 1);
let category;
if (quality >= 0.88) category = "fresh";
else if (quality >= 0.62) category = "good";
else if (quality >= 0.34) category = "soon";
else category = "overripe";
let stage;
if (maturity < 0.55) stage = "Developing";
else if (maturity < 0.7) stage = "Market ripe";
else if (maturity < 0.83) stage = "Fully ripe";
else stage = "Past peak";
return {
quality,
maturity,
category,
stage
};
}
// ---------------------------------------------------------------------
// UI and scene synchronization
// ---------------------------------------------------------------------
function refreshUI() {
const timing = timingConfig[selectedTiming];
timingButtons.forEach((button) => {
button.setAttribute(
"aria-pressed",
String(button.dataset.timing === selectedTiming)
);
});
harvestDate.textContent = timing.date;
stageLabel.textContent = timing.stage;
const activeStage =
selectedTiming === "early" ? 1 : selectedTiming === "peak" ? 2 : 3;
stageDots.forEach((dot, index) => {
dot.classList.toggle("on", index < activeStage);
});
delayValue.textContent = `${deliveryDelay} ${
deliveryDelay === 1 ? "day" : "days"
}`;
const fill = (deliveryDelay / 3) * 100;
delayRange.style.setProperty("--range-fill", `${fill}%`);
if (deliveryDelay === 0) {
if (selectedTiming === "early") {
routeMessage.textContent =
"Early fruit has lower sugar and needs more ripening time, but it has a gentler spoilage risk.";
} else if (selectedTiming === "peak") {
routeMessage.textContent =
"Peak-season fruit starts with the widest market-ready window and should travel well.";
} else {
routeMessage.textContent =
"Late fruit is sweet now, but it has little ripening headroom left in reserve.";
}
} else {
routeMessage.textContent =
`${deliveryDelay} ${deliveryDelay === 1 ? "day" : "days"} of warm holding adds ripeness and handling loss. ` +
(selectedTiming === "late"
? "Late fruit is most vulnerable to overripening."
: selectedTiming === "early"
? "Early fruit ripens further while it waits."
: "Peak fruit loses market-ready shelf life.");
}
currentPlan.textContent = `${timing.label} harvest · ${
deliveryDelay === 0 ? "same day" : `+${deliveryDelay} day`
}`;
routeList.innerHTML = routeNodes
.map((node) => {
const result = evaluateQuality(node.t);
const category = categories[result.category];
return `
<li class="route-step" style="--step-color:${category.css}">
<span class="route-node"></span>
<span>
<span class="step-title">${node.title}</span>
<span class="step-detail">
${result.stage} · ${Math.round(result.quality * 100)}% quality
</span>
</span>
<span class="step-category">${category.label}</span>
</li>
`;
})
.join("");
const arrival = evaluateQuality(1);
const arrivalCategory = categories[arrival.category];
routeBadge.textContent = arrivalCategory.label;
routeBadge.style.background = arrivalCategory.css;
arrivalQuality.textContent = `${Math.round(arrival.quality * 100)}%`;
qualityFill.style.width = `${arrival.quality * 100}%`;
qualityFill.style.background = arrivalCategory.css;
}
function refreshScene() {
routeTiles.forEach((tileMaterial, index) => {
const t = (index + 0.5) / routeTiles.length;
const category = evaluateQuality(t).category;
tileMaterial.color.setHex(categories[category].color);
});
routeSamples.forEach((sample) => {
const category = evaluateQuality(sample.t).category;
sample.fruitMaterial.color.setHex(categories[category].color);
});
routeSigns.forEach((sign) => {
const result = evaluateQuality(sign.node.t);
const category = categories[result.category];
sign.draw(sign.node.title, category.label, category.css);
});
updateTruck();
}
function refreshAll() {
refreshUI();
refreshScene();
}
timingButtons.forEach((button) => {
button.addEventListener("click", () => {
selectedTiming = button.dataset.timing;
refreshAll();
});
});
delayRange.addEventListener("input", () => {
deliveryDelay = Number(delayRange.value);
refreshAll();
});
startButton.addEventListener("click", () => {
if (deliveryRunning) {
deliveryRunning = false;
buttonIcon.textContent = "▶";
buttonLabel.textContent = "Resume delivery";
liveStatus.textContent = "Delivery paused";
return;
}
if (deliveryProgress >= 1) deliveryProgress = 0;
deliveryRunning = true;
deliveryComplete = false;
buttonIcon.textContent = "Ⅱ";
buttonLabel.textContent = "Pause delivery";
liveStatus.textContent = "In transit";
});
refreshAll();
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
const routeDuration = 12;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (deliveryRunning) {
deliveryProgress = Math.min(
1,
deliveryProgress + delta / routeDuration
);
updateTruck();
if (deliveryProgress >= 1) {
deliveryRunning = false;
deliveryComplete = true;
buttonIcon.textContent = "↻";
buttonLabel.textContent = "Run delivery again";
liveStatus.textContent = "Market arrival";
const arrival = evaluateQuality(1);
const category = categories[arrival.category];
routeBadge.textContent = category.label;
routeBadge.style.background = category.css;
arrivalQuality.textContent = `${Math.round(arrival.quality * 100)}%`;
qualityFill.style.width = `${arrival.quality * 100}%`;
qualityFill.style.background = category.css;
}
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// ---------------------------------------------------------------------
// Resize handling
// ---------------------------------------------------------------------
function resize() {
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
</script>
</body>
</html>
```