Prompt specification
Build or customize the Three.js 3D scene "Consolidate Three Deliveries Into One Route" 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: Consolidate Three Deliveries Into One Route
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/consolidate-three-deliveries-into-one-route-x2154
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Animate separate and consolidated delivery trips serving the same destinations. Compare traveled distance and load utilization before applying any stated toy impact factor.
Working Three.js Starter (consolidate-three-deliveries-into-one-route-x2154):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Last-Mile Lab — Delivery Consolidation</title>
<style>
:root {
color-scheme: dark;
--bg: #081118;
--panel: rgba(14, 29, 39, 0.88);
--panel-solid: #0e1d27;
--border: rgba(177, 218, 232, 0.14);
--text: #edf8fb;
--muted: #8fa9b5;
--cyan: #4bc4df;
--green: #a8df62;
--amber: #ffbd66;
--pink: #ef829f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
display: grid;
grid-template-rows: 70px minmax(330px, 1fr) 218px;
width: 100%;
height: 100dvh;
min-height: 650px;
}
header {
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 20px;
border-bottom: 1px solid var(--border);
background: rgba(8, 17, 24, 0.95);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 35px;
height: 35px;
flex: 0 0 auto;
border: 2px solid var(--cyan);
border-radius: 9px;
transform: rotate(30deg);
box-shadow: inset 0 0 0 6px rgba(75, 196, 223, 0.09);
}
.brand-mark::after {
content: "";
position: absolute;
width: 7px;
height: 7px;
top: 5px;
right: 5px;
border-radius: 50%;
background: var(--green);
}
.brand strong {
display: block;
font-size: 16px;
letter-spacing: 0.02em;
}
.brand small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
}
.header-right {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 9px;
min-width: 0;
}
.baseline-badge {
display: flex;
align-items: center;
gap: 8px;
margin-right: 5px;
padding: 8px 11px;
border: 1px solid rgba(168, 223, 98, 0.25);
border-radius: 999px;
background: rgba(168, 223, 98, 0.07);
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.baseline-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px var(--green);
}
.control-button {
min-height: 35px;
padding: 0 12px;
border: 1px solid var(--border);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
color: var(--text);
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.control-button:hover {
border-color: rgba(177, 218, 232, 0.35);
background: rgba(255, 255, 255, 0.075);
transform: translateY(-1px);
}
.control-button:focus-visible,
#threeCanvas:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
#stage {
position: relative;
min-height: 0;
overflow: hidden;
isolation: isolate;
background:
radial-gradient(circle at 50% 15%, rgba(43, 92, 109, 0.25), transparent 45%),
linear-gradient(180deg, #0b1821 0%, #081118 100%);
}
#threeCanvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#threeCanvas:active {
cursor: grabbing;
}
#labelLayer {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
left: 0;
top: 0;
padding: 4px 7px;
border: 1px solid rgba(222, 244, 250, 0.18);
border-radius: 6px;
background: rgba(7, 17, 24, 0.82);
color: #eaf8fc;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.035em;
white-space: nowrap;
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
will-change: transform;
}
.world-label.depot {
border-color: rgba(255, 189, 102, 0.35);
color: var(--amber);
}
.lane-overlays {
position: absolute;
z-index: 3;
top: 15px;
left: 15px;
right: 15px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
pointer-events: none;
}
.lane-card {
justify-self: start;
width: min(350px, 100%);
padding: 12px 14px;
border: 1px solid var(--border);
border-radius: 12px;
background: linear-gradient(135deg, rgba(13, 28, 38, 0.94), rgba(13, 28, 38, 0.68));
backdrop-filter: blur(10px);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
}
.lane-card.right {
justify-self: end;
}
.lane-kicker {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 5px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.lane-card.left .lane-kicker {
color: var(--cyan);
}
.lane-card.right .lane-kicker {
color: var(--green);
}
.lane-kicker::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.lane-card h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.02em;
}
.lane-card p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.lane-mini {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 9px;
padding-top: 8px;
border-top: 1px solid var(--border);
color: var(--muted);
font-size: 10px;
}
.lane-mini strong {
color: var(--text);
font-weight: 700;
}
.scene-legend {
position: absolute;
z-index: 3;
right: 16px;
bottom: 13px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px 13px;
max-width: 440px;
padding: 8px 10px;
border: 1px solid var(--border);
border-radius: 8px;
background: rgba(7, 17, 24, 0.72);
color: var(--muted);
font-size: 9px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-line {
width: 17px;
height: 3px;
border-radius: 2px;
}
.legend-line.blue {
background: var(--cyan);
}
.legend-line.green {
background: var(--green);
}
.legend-line.dashed {
height: 0;
border-top: 2px dashed var(--amber);
border-radius: 0;
}
.camera-hint {
position: absolute;
z-index: 3;
left: 16px;
bottom: 14px;
color: rgba(201, 222, 229, 0.65);
font-size: 9px;
pointer-events: none;
}
#dashboard {
z-index: 10;
display: grid;
grid-template-columns: 1.2fr 1.2fr 0.85fr;
gap: 12px;
padding: 13px 16px 15px;
border-top: 1px solid var(--border);
background: #0a151d;
}
.metric-card {
min-width: 0;
padding: 13px 15px;
border: 1px solid var(--border);
border-radius: 12px;
background: linear-gradient(145deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.012));
}
.metric-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.metric-heading h3 {
margin: 0;
font-size: 12px;
letter-spacing: 0.01em;
}
.metric-heading small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 500;
}
.metric-unit {
flex: 0 0 auto;
padding: 4px 6px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.04);
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.compare-row {
display: grid;
grid-template-columns: 94px 1fr 88px;
align-items: center;
gap: 9px;
min-height: 22px;
}
.compare-name {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
}
.dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
}
.dot.cyan {
background: var(--cyan);
box-shadow: 0 0 8px rgba(75, 196, 223, 0.5);
}
.dot.green {
background: var(--green);
box-shadow: 0 0 8px rgba(168, 223, 98, 0.45);
}
.bar {
height: 6px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.06);
}
.bar > i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width 700ms ease;
}
#separateDistanceBar {
background: linear-gradient(90deg, #258da7, var(--cyan));
}
#consolidatedDistanceBar {
background: linear-gradient(90deg, #639d3b, var(--green));
}
#separateUtilizationBar {
background: linear-gradient(90deg, #258da7, var(--cyan));
}
#consolidatedUtilizationBar {
background: linear-gradient(90deg, #639d3b, var(--green));
}
.compare-value {
text-align: right;
font-size: 12px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
.delta {
display: inline-flex;
align-items: center;
margin-top: 9px;
padding: 5px 8px;
border: 1px solid rgba(168, 223, 98, 0.18);
border-radius: 6px;
background: rgba(168, 223, 98, 0.065);
color: var(--green);
font-size: 9px;
font-weight: 750;
}
.baseline-grid {
display: grid;
grid-template-columns: 1fr auto;
gap: 7px 14px;
margin-top: 9px;
font-size: 10px;
}
.baseline-grid span {
color: var(--muted);
}
.baseline-grid strong {
text-align: right;
font-variant-numeric: tabular-nums;
}
.baseline-note {
margin-top: 11px;
padding-top: 9px;
border-top: 1px solid var(--border);
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.baseline-note strong {
color: var(--green);
}
.time-readout {
min-width: 67px;
color: var(--muted);
font-size: 9px;
font-variant-numeric: tabular-nums;
text-align: right;
white-space: nowrap;
}
@media (max-width: 850px) {
html,
body {
overflow: auto;
}
#app {
display: block;
height: auto;
min-height: 100dvh;
}
header {
min-height: 70px;
padding: 11px 14px;
}
.brand small,
.baseline-badge,
#resetCameraButton {
display: none;
}
#stage {
height: 560px;
}
.lane-overlays {
grid-template-columns: 1fr;
gap: 8px;
}
.lane-card,
.lane-card.right {
justify-self: stretch;
width: 100%;
padding: 9px 11px;
}
.lane-card p,
.lane-mini {
display: none;
}
#dashboard {
grid-template-columns: 1fr;
}
.scene-legend {
right: 10px;
bottom: 10px;
}
.camera-hint {
left: 10px;
bottom: 10px;
}
}
@media (max-width: 480px) {
.header-right {
gap: 5px;
}
.control-button {
padding: 0 9px;
font-size: 11px;
}
#stage {
height: 510px;
}
.compare-row {
grid-template-columns: 84px 1fr 76px;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<span class="brand-mark" aria-hidden="true"></span>
<div>
<strong>Last-Mile Lab</strong>
<small>Equal deliveries · raw operational baseline</small>
</div>
</div>
<div class="header-right">
<div class="baseline-badge">Raw baseline · no impact factor</div>
<button class="control-button" id="pauseButton" type="button">Pause</button>
<button class="control-button" id="replayButton" type="button">Replay</button>
<button class="control-button" id="resetCameraButton" type="button">Reset view</button>
<div class="time-readout" id="timeReadout">0.0 / 14.5 s</div>
</div>
</header>
<section id="stage" aria-label="Animated delivery route comparison">
<div class="lane-overlays">
<article class="lane-card left">
<div class="lane-kicker">Option A</div>
<h2>Separate deliveries</h2>
<p>Four small vans each serve one destination with the same eight parcels overall.</p>
<div class="lane-mini">
<span>Fleet / departures</span>
<strong>4 vans / 4</strong>
<span>Loaded capacity</span>
<strong>2 of 3 slots</strong>
</div>
</article>
<article class="lane-card right">
<div class="lane-kicker">Option B</div>
<h2>Consolidated delivery</h2>
<p>One larger truck visits A–D in sequence, carrying all eight parcels together.</p>
<div class="lane-mini">
<span>Fleet / departures</span>
<strong>1 truck / 1</strong>
<span>Loaded capacity</span>
<strong>8 of 8 slots</strong>
</div>
</article>
</div>
<div id="labelLayer"></div>
<div class="camera-hint">Drag to orbit · wheel to zoom · double-click to reset</div>
<div class="scene-legend">
<div class="legend-item"><span class="legend-line blue"></span>Separate outbound routes</div>
<div class="legend-item"><span class="legend-line green"></span>Consolidated outbound route</div>
<div class="legend-item"><span class="legend-line dashed"></span>Return to depot</div>
</div>
</section>
<section id="dashboard" aria-label="Raw delivery comparison metrics">
<article class="metric-card">
<div class="metric-heading">
<div>
<h3>Raw traveled distance</h3>
<small>Complete round trips, including return to depot</small>
</div>
<span class="metric-unit">Model km</span>
</div>
<div class="compare-row">
<span class="compare-name"><i class="dot cyan"></i>Separate</span>
<div class="bar"><i id="separateDistanceBar"></i></div>
<strong class="compare-value" id="separateDistance">—</strong>
</div>
<div class="compare-row">
<span class="compare-name"><i class="dot green"></i>Consolidated</span>
<div class="bar"><i id="consolidatedDistanceBar"></i></div>
<strong class="compare-value" id="consolidatedDistance">—</strong>
</div>
<div class="delta" id="distanceDelta">—</div>
</article>
<article class="metric-card">
<div class="metric-heading">
<div>
<h3>Mean load utilization</h3>
<small>Equal-weight parcels; utilization is loaded slots ÷ vehicle slots</small>
</div>
<span class="metric-unit">Capacity</span>
</div>
<div class="compare-row">
<span class="compare-name"><i class="dot cyan"></i>Separate</span>
<div class="bar"><i id="separateUtilizationBar"></i></div>
<strong class="compare-value" id="separateUtilization">—</strong>
</div>
<div class="compare-row">
<span class="compare-name"><i class="dot green"></i>Consolidated</span>
<div class="bar"><i id="consolidatedUtilizationBar"></i></div>
<strong class="compare-value" id="consolidatedUtilization">—</strong>
</div>
<div class="delta" id="utilizationDelta">—</div>
</article>
<article class="metric-card">
<div class="metric-heading">
<div>
<h3>Baseline snapshot</h3>
<small>Operational values before any downstream scaling</small>
</div>
<span class="metric-unit">Raw</span>
</div>
<div class="baseline-grid">
<span>Destinations served</span><strong>4 = 4</strong>
<span>Parcels delivered</span><strong>8 = 8</strong>
<span>Fleet departures</span><strong>4 → 1</strong>
<span>Impact factor</span><strong>Not applied</strong>
</div>
<div class="baseline-note">
<strong>1 scene unit = 1 model km.</strong>
Distance is route geometry, not a real-world service estimate.
Any toy impact factor should be applied only after these raw values.
</div>
</article>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and renderer
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const labelLayer = document.getElementById("labelLayer");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.domElement.id = "threeCanvas";
renderer.domElement.tabIndex = 0;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x0b1720, 52, 110);
const camera = new THREE.PerspectiveCamera(
42,
stage.clientWidth / stage.clientHeight,
0.1,
180
);
// -------------------------------------------------------------------------
// Direct camera controls: no examples/addons are used.
// -------------------------------------------------------------------------
class CameraRig {
constructor(camera, element) {
this.camera = camera;
this.element = element;
this.target = new THREE.Vector3(0, 0, 10);
this.theta = 0.025;
this.phi = 0.88;
this.radius = 53;
this.dragging = false;
this.lastX = 0;
this.lastY = 0;
this.reset();
element.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
this.dragging = true;
this.lastX = event.clientX;
this.lastY = event.clientY;
element.setPointerCapture(event.pointerId);
});
element.addEventListener("pointermove", (event) => {
if (!this.dragging) return;
const dx = event.clientX - this.lastX;
const dy = event.clientY - this.lastY;
this.lastX = event.clientX;
this.lastY = event.clientY;
this.theta -= dx * 0.0055;
this.phi = THREE.MathUtils.clamp(
this.phi + dy * 0.0045,
0.34,
1.27
);
});
const endDrag = (event) => {
this.dragging = false;
if (element.hasPointerCapture(event.pointerId)) {
element.releasePointerCapture(event.pointerId);
}
};
element.addEventListener("pointerup", endDrag);
element.addEventListener("pointercancel", endDrag);
element.addEventListener(
"wheel",
(event) => {
event.preventDefault();
this.radius = THREE.MathUtils.clamp(
this.radius * Math.exp(event.deltaY * 0.001),
28,
92
);
},
{ passive: false }
);
element.addEventListener("dblclick", () => this.reset());
element.addEventListener("contextmenu", (event) => event.preventDefault());
element.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") this.theta += step;
else if (event.key === "ArrowRight") this.theta -= step;
else if (event.key === "ArrowUp") {
this.phi = Math.max(0.34, this.phi - step * 0.65);
} else if (event.key === "ArrowDown") {
this.phi = Math.min(1.27, this.phi + step * 0.65);
} else {
return;
}
event.preventDefault();
});
}
reset() {
const aspect = stage.clientWidth / Math.max(1, stage.clientHeight);
this.theta = 0.025;
this.phi = 0.88;
this.radius = aspect < 1 ? 82 : aspect < 1.35 ? 66 : 53;
this.target.set(0, 0, 10);
this.update();
}
update() {
const sinPhi = Math.sin(this.phi);
const cosPhi = Math.cos(this.phi);
this.camera.position.set(
this.target.x + this.radius * sinPhi * Math.sin(this.theta),
this.target.y + this.radius * cosPhi,
this.target.z + this.radius * sinPhi * Math.cos(this.theta)
);
this.camera.lookAt(this.target);
}
}
const cameraRig = new CameraRig(camera, renderer.domElement);
// -------------------------------------------------------------------------
// Lighting and shared modeling helpers
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc8efff, 0x17232b, 2.0));
const keyLight = new THREE.DirectionalLight(0xfff0d8, 3.1);
keyLight.position.set(-16, 30, 18);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -35;
keyLight.shadow.camera.right = 35;
keyLight.shadow.camera.top = 35;
keyLight.shadow.camera.bottom = -35;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 85;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x67d8ff, 1.15);
fillLight.position.set(22, 12, -10);
scene.add(fillLight);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0.03,
flatShading: true
})
);
}
return materialCache.get(color);
}
function box(
parent,
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
options.material || material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.cast !== false;
mesh.receiveShadow = options.receive !== false;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
radiusTop,
radiusBottom,
height,
radialSegments,
color,
x = 0,
y = 0,
z = 0
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments
),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cone(
parent,
radius,
height,
segments,
color,
x = 0,
y = 0,
z = 0
) {
const mesh = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, segments),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeParcel(scale = 1) {
const group = new THREE.Group();
box(group, 0.52, 0.38, 0.52, 0xdca45f, 0, 0, 0);
box(group, 0.13, 0.012, 0.53, 0xf7dfae, 0, 0.197, 0);
group.scale.setScalar(scale);
return group;
}
function makeRoad(a, b, width, color, dashed = false) {
const direction = b.clone().sub(a);
direction.y = 0;
const length = direction.length();
direction.normalize();
const rotation = new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction
);
if (!dashed) {
const road = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.08, length),
material(color)
);
road.position.copy(a).add(b).multiplyScalar(0.5);
road.position.y = 0.035;
road.quaternion.copy(rotation);
road.receiveShadow = true;
scene.add(road);
return;
}
const dashLength = 0.58;
const spacing = 1.22;
for (let offset = dashLength * 0.55; offset < length; offset += spacing) {
const dash = new THREE.Mesh(
new THREE.BoxGeometry(width * 0.16, 0.045, dashLength),
material(color)
);
dash.position.copy(a).addScaledVector(direction, offset);
dash.position.y = 0.095;
dash.quaternion.copy(rotation);
scene.add(dash);
}
}
function makeTree(parent, x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
cylinder(group, 0.13, 0.17, 1.25, 5, 0x78533c, 0, 0.62, 0);
cone(group, 0.73, 1.5, 5, 0x3f7b58, 0, 1.55, 0);
cone(group, 0.53, 1.15, 5, 0x4f9665, 0, 2.17, 0);
parent.add(group);
}
function makeDepot(centerX) {
const group = new THREE.Group();
box(group, 2.8, 1.45, 2.25, 0x43545f, -2.25, 0.73, 0);
box(group, 2.9, 0.16, 2.35, 0x25353f, -2.25, 1.48, 0);
const roof = cone(group, 1.7, 0.8, 4, 0xd98a4a, -2.25, 1.85, 0);
roof.rotation.y = Math.PI * 0.25;
roof.scale.set(1.48, 1, 0.92);
box(group, 1.05, 0.95, 0.06, 0x1b2b34, -2.25, 0.5, 1.16);
box(group, 0.55, 0.22, 0.07, 0xffcf76, -2.25, 1.14, 1.16);
box(group, 0.42, 0.42, 0.42, 0xffbd66, 1.05, 0.23, -0.5);
box(group, 0.42, 0.42, 0.42, 0xffbd66, 1.05, 0.65, -0.5);
scene.add(group);
}
function makeDestination(centerX, stop) {
const house = new THREE.Group();
house.position.set(
centerX + stop.x - 1.45,
0,
stop.z
);
box(house, 1.35, 1.2, 1.45, stop.color, 0, 0.6, 0);
box(house, 0.3, 0.75, 0.04, 0x20313a, 0, 0.39, 0.74);
const roof = cone(house, 1.05, 0.75, 4, 0xe8ecdf, 0, 1.55, 0);
roof.rotation.y = Math.PI * 0.25;
roof.scale.set(1, 1, 0.88);
cylinder(house, 0.08, 0.1, 0.9, 5, 0x6d7779, 0.58, 1.92, -0.35);
scene.add(house);
}
function makeDeliveryMarker(position) {
const group = new THREE.Group();
group.position.copy(position);
group.visible = false;
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0xa8df62,
transparent: true,
opacity: 0.7,
side: THREE.DoubleSide,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.5, 0.72, 24),
ringMaterial
);
ring.rotation.x = -Math.PI * 0.5;
ring.position.y = 0.07;
group.add(ring);
const parcelA = makeParcel(0.9);
parcelA.position.set(0, 0.29, 0);
group.add(parcelA);
const parcelB = makeParcel(0.9);
parcelB.position.set(0, 0.68, 0);
group.add(parcelB);
scene.add(group);
return { group, ring };
}
function makeTruck(accent, large = false) {
const group = new THREE.Group();
const packages = [];
const wheels = [];
const bedWidth = large ? 1.45 : 1.15;
const bedLength = large ? 2.85 : 1.55;
const cabZ = large ? 1.65 : 0.82;
box(group, bedWidth, 0.16, bedLength, 0x3d4b55, 0, 0.42, -0.38);
box(group, 0.12, 0.38, bedLength, accent, -bedWidth * 0.5, 0.64, -0.38);
box(group, 0.12, 0.38, bedLength, accent, bedWidth * 0.5, 0.64, -0.38);
box(group, bedWidth, 0.38, 0.12, accent, 0, 0.64, -0.38 - bedLength * 0.5);
box(group, 1.02, 0.78, 0.82, accent, 0, 0.72, cabZ);
box(group, 0.8, 0.29, 0.035, 0x193541, 0, 0.86, cabZ + 0.425);
box(group, 1.04, 0.16, 0.82, 0xf1e5cc, 0, 0.39, cabZ);
const wheelX = large ? 0.78 : 0.62;
const wheelPositions = large
? [[-wheelX, 0.98], [wheelX, 0.98], [-wheelX, -1.15], [wheelX, -1.15]]
: [[-wheelX, 0.7], [wheelX, 0.7], [-wheelX, -0.78], [wheelX, -0.78]];
for (const [x, z] of wheelPositions) {
const pivot = new THREE.Group();
pivot.position.set(x, 0.27, z);
const wheel = cylinder(
pivot,
0.27,
0.27,
0.19,
10,
0x111a20,
0,
0,
0
);
wheel.rotation.z = Math.PI * 0.5;
const hub = cylinder(
pivot,
0.11,
0.11,
0.205,
10,
0x9ca9ad,
0,
0,
0
);
hub.rotation.z = Math.PI * 0.5;
group.add(pivot);
wheels.push(pivot);
}
if (large) {
for (let i = 0; i < 8; i++) {
const parcel = makeParcel(0.9);
const column = Math.floor(i / 2);
const layer = Math.floor(i / 4);
parcel.position.set(
i % 2 === 0 ? -0.32 : 0.32,
0.66 + layer * 0.43,
-1.22 + column * 0.75
);
group.add(parcel);
packages.push(parcel);
}
} else {
for (let i = 0; i < 2; i++) {
const parcel = makeParcel(0.9);
parcel.position.set(i === 0 ? -0.27 : 0.27, 0.69, -0.42);
group.add(parcel);
packages.push(parcel);
}
}
scene.add(group);
return { group, packages, wheels };
}
// -------------------------------------------------------------------------
// World labels
// -------------------------------------------------------------------------
const labels = [];
function addWorldLabel(text, position, className = "") {
const element = document.createElement("div");
element.className = `world-label ${className}`.trim();
element.textContent = text;
labelLayer.appendChild(element);
const label = {
element,
position: position.clone()
};
labels.push(label);
return label;
}
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -50%)`;
}
}
// -------------------------------------------------------------------------
// Route geometry and comparison calculations
// -------------------------------------------------------------------------
const stops = [
{ id: "A", name: "Market", x: 0, z: 5, color: 0xef916f },
{ id: "B", name: "Cafe", x: -0.8, z: 10, color: 0xb985d4 },
{ id: "C", name: "Clinic", x: 0.8, z: 15, color: 0x5da9cf },
{ id: "D", name: "Studio", x: 0, z: 20, color: 0xe1c55d }
];
const separateCenterX = -12;
const consolidatedCenterX = 12;
const parcelsPerStop = 2;
const separateVanCapacity = 3;
const consolidatedCapacity = 8;
const totalParcels = stops.length * parcelsPerStop;
function horizontalDistance(a, b) {
return Math.hypot(a.x - b.x, a.z - b.z);
}
const depotLocal = { x: 0, z: 0 };
const separateTripLengths = stops.map((stop) =>
horizontalDistance(depotLocal, stop)
);
const separateTotalDistance =
separateTripLengths.reduce((sum, value) => sum + value, 0) * 2;
const consolidatedPoints = [
depotLocal,
...stops,
depotLocal
];
let consolidatedOutbound = 0;
for (let i = 0; i < stops.length; i++) {
consolidatedOutbound += horizontalDistance(
consolidatedPoints[i],
consolidatedPoints[i + 1]
);
}
const consolidatedTotalDistance =
consolidatedOutbound +
horizontalDistance(stops[stops.length - 1], depotLocal);
const separateUtilization =
(totalParcels / (stops.length * separateVanCapacity)) * 100;
const consolidatedUtilization =
(totalParcels / consolidatedCapacity) * 100;
const distanceSavings =
(1 - consolidatedTotalDistance / separateTotalDistance) * 100;
document.getElementById("separateDistance").textContent =
`${separateTotalDistance.toFixed(1)} model km`;
document.getElementById("consolidatedDistance").textContent =
`${consolidatedTotalDistance.toFixed(1)} model km`;
document.getElementById("separateUtilization").textContent =
`${separateUtilization.toFixed(1)}%`;
document.getElementById("consolidatedUtilization").textContent =
`${consolidatedUtilization.toFixed(1)}%`;
document.getElementById("distanceDelta").textContent =
`${distanceSavings.toFixed(1)}% less traveled distance`;
document.getElementById("utilizationDelta").textContent =
`+${(
consolidatedUtilization - separateUtilization
).toFixed(1)} percentage points of mean load utilization`;
requestAnimationFrame(() => {
document.getElementById("separateDistanceBar").style.width = "100%";
document.getElementById("consolidatedDistanceBar").style.width =
`${(consolidatedTotalDistance / separateTotalDistance) * 100}%`;
document.getElementById("separateUtilizationBar").style.width =
`${separateUtilization}%`;
document.getElementById("consolidatedUtilizationBar").style.width =
`${consolidatedUtilization}%`;
});
// -------------------------------------------------------------------------
// Build the two comparison areas
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(72, 52),
material(0x0b1820)
);
ground.rotation.x = -Math.PI * 0.5;
ground.position.set(0, -0.2, 9);
ground.receiveShadow = true;
scene.add(ground);
const separateVehicles = [];
const consolidatedMarkers = [];
function makeLaneBase(centerX, laneColor) {
const pad = box(
scene,
21,
0.18,
27,
0x10232d,
centerX,
-0.11,
10
);
pad.castShadow = false;
box(
scene,
20.5,
0.025,
0.08,
laneColor,
centerX,
0.005,
23.25
);
}
makeLaneBase(separateCenterX, 0x28566a);
makeLaneBase(consolidatedCenterX, 0x355c3d);
// Separate-delivery lane
makeDepot(separateCenterX);
stops.forEach((stop, index) => {
makeDestination(separateCenterX, stop);
const depot = new THREE.Vector3(separateCenterX, 0, 0);
const destination = new THREE.Vector3(
separateCenterX + stop.x,
0,
stop.z
);
makeRoad(depot, destination, 1.0, 0x285567);
makeRoad(destination, depot, 1.0, 0x66818b, true);
const marker = makeDeliveryMarker(
new THREE.Vector3(destination.x + 1.12, 0, destination.z)
);
const truck = makeTruck(0x4bc4df, false);
truck.length = horizontalDistance(depot, destination);
truck.depot = depot;
truck.destination = destination;
truck.marker = marker;
truck.stop = stop;
truck.accent = index;
separateVehicles.push(truck);
addWorldLabel(
`${stop.id} · ${stop.name}`,
new THREE.Vector3(
separateCenterX + stop.x - 1.45,
2.65,
stop.z
)
);
});
addWorldLabel(
"DEPOT",
new THREE.Vector3(separateCenterX - 2.25, 2.55, 0),
"depot"
);
// Consolidated-delivery lane
makeDepot(consolidatedCenterX);
const consolidatedWorldPoints = consolidatedPoints.map(
(point) => new THREE.Vector3(consolidatedCenterX + point.x, 0, point.z)
);
for (let i = 0; i < stops.length; i++) {
const stop = stops[i];
makeDestination(consolidatedCenterX, stop);
makeRoad(
consolidatedWorldPoints[i],
consolidatedWorldPoints[i + 1],
1.22,
0x416e4c
);
const marker = makeDeliveryMarker(
new THREE.Vector3(
consolidatedCenterX + stop.x + 1.12,
0,
stop.z
)
);
consolidatedMarkers.push(marker);
addWorldLabel(
`${stop.id} · ${stop.name}`,
new THREE.Vector3(
consolidatedCenterX + stop.x - 1.45,
2.65,
stop.z
)
);
}
// Consolidated return to depot.
makeRoad(
consolidatedWorldPoints[consolidatedWorldPoints.length - 1],
consolidatedWorldPoints[0],
1.22,
0xffbd66,
true
);
addWorldLabel(
"DEPOT",
new THREE.Vector3(consolidatedCenterX - 2.25, 2.55, 0),
"depot"
);
const consolidatedTruck = makeTruck(0xa8df62, true);
// Decorative low-poly trees.
const treeLayout = [
[-4.4, 1.5, 1.0],
[-4.1, 6.2, 0.82],
[-4.5, 11.1, 1.1],
[-3.8, 16.8, 0.9],
[-4.0, 21.6, 1.04],
[4.3, 3.4, 0.9],
[4.5, 8.3, 1.08],
[3.8, 13.3, 0.85],
[4.3, 18.4, 1.02],
[4.0, 22.0, 0.82]
];
for (const centerX of [separateCenterX, consolidatedCenterX]) {
treeLayout.forEach(([x, z, scale]) => {
makeTree(scene, centerX + x, z, scale);
});
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const CYCLE_LENGTH = 14.5;
const TRUCK_SPEED = 4.0;
const UNLOAD_DURATION = 0.85;
const CONSOLIDATED_START = 0.3;
let simulationTime = 0;
let previousSimulationTime = 0;
let paused = false;
function setCargoCount(truck, count) {
truck.packages.forEach((parcel, index) => {
parcel.visible = index < count;
});
}
function poseTruck(truck, position, heading) {
truck.group.position.set(position.x, 0.035, position.z);
truck.group.rotation.y = heading;
}
function headingBetween(from, to) {
return Math.atan2(to.x - from.x, to.z - from.z);
}
function resetVisuals() {
separateVehicles.forEach((truck) => {
setCargoCount(truck, 2);
truck.marker.group.visible = false;
});
setCargoCount(consolidatedTruck, totalParcels);
consolidatedMarkers.forEach((marker) => {
marker.group.visible = false;
marker.ring.scale.setScalar(1);
marker.ring.material.opacity = 0.7;
});
}
function updateSeparateVehicles(time) {
for (const truck of separateVehicles) {
const outboundTime = truck.length / TRUCK_SPEED;
const roundTripTime = outboundTime * 2 + UNLOAD_DURATION;
if (time < outboundTime) {
const progress = time / outboundTime;
const position = truck.depot.clone().lerp(
truck.destination,
progress
);
poseTruck(
truck,
position,
headingBetween(truck.depot, truck.destination)
);
setCargoCount(truck, 2);
truck.marker.group.visible = false;
} else if (time < outboundTime + UNLOAD_DURATION) {
const progress =
(time - outboundTime) / UNLOAD_DURATION;
poseTruck(
truck,
truck.destination,
headingBetween(truck.depot, truck.destination)
);
const count =
progress < 0.27 ? 2 : progress < 0.62 ? 1 : 0;
setCargoCount(truck, count);
truck.marker.group.visible = progress >= 0.52;
truck.marker.ring.material.opacity = 0.35;
truck.marker.ring.scale.setScalar(1);
} else if (time < roundTripTime) {
const progress =
(time - outboundTime - UNLOAD_DURATION) / outboundTime;
const position = truck.destination.clone().lerp(
truck.depot,
progress
);
poseTruck(
truck,
position,
headingBetween(truck.destination, truck.depot)
);
setCargoCount(truck, 0);
truck.marker.group.visible = true;
} else {
poseTruck(
truck,
truck.depot,
headingBetween(truck.destination, truck.depot)
);
setCargoCount(truck, 0);
truck.marker.group.visible = true;
}
}
}
const consolidatedSchedule = [];
for (let i = 0; i < stops.length; i++) {
const from = consolidatedWorldPoints[i];
const to = consolidatedWorldPoints[i + 1];
const length = horizontalDistance(from, to);
consolidatedSchedule.push({
type: "travel",
from,
to,
length,
heading: headingBetween(from, to)
});
consolidatedSchedule.push({
type: "stop",
position: to,
stopIndex: i,
heading: headingBetween(from, to)
});
}
const consolidatedReturn = {
type: "travel",
from: consolidatedWorldPoints[consolidatedWorldPoints.length - 1],
to: consolidatedWorldPoints[0],
length: horizontalDistance(
consolidatedWorldPoints[consolidatedWorldPoints.length - 1],
consolidatedWorldPoints[0]
),
heading: headingBetween(
consolidatedWorldPoints[consolidatedWorldPoints.length - 1],
consolidatedWorldPoints[0]
)
};
consolidatedSchedule.push(consolidatedReturn);
function updateConsolidatedTruck(time) {
let elapsed = time - CONSOLIDATED_START;
let remainingParcels = totalParcels;
if (elapsed < 0) {
poseTruck(
consolidatedTruck,
consolidatedWorldPoints[0],
consolidatedSchedule[0].heading
);
setCargoCount(consolidatedTruck, totalParcels);
return;
}
for (const item of consolidatedSchedule) {
const duration =
item.type === "travel"
? item.length / TRUCK_SPEED
: UNLOAD_DURATION;
if (elapsed < duration) {
if (item.type === "travel") {
const progress = elapsed / duration;
const position = item.from.clone().lerp(item.to, progress);
poseTruck(consolidatedTruck, position, item.heading);
setCargoCount(consolidatedTruck, remainingParcels);
} else {
const progress = elapsed / duration;
const removed =
(progress >= 0.26 ? 1 : 0) +
(progress >= 0.61 ? 1 : 0);
poseTruck(
consolidatedTruck,
item.position,
item.heading
);
setCargoCount(
consolidatedTruck,
Math.max(0, remainingParcels - removed)
);
const marker = consolidatedMarkers[item.stopIndex];
marker.group.visible = progress >= 0.5;
if (marker.group.visible) {
marker.ring.scale.setScalar(1 + progress * 1.6);
marker.ring.material.opacity = Math.max(0, 1 - progress);
}
}
return;
}
elapsed -= duration;
if (item.type === "stop") {
remainingParcels -= parcelsPerStop;
}
}
poseTruck(
consolidatedTruck,
consolidatedWorldPoints[0],
consolidatedReturn.heading
);
setCargoCount(consolidatedTruck, 0);
consolidatedMarkers.forEach((marker) => {
marker.group.visible = true;
marker.ring.scale.setScalar(1.8);
marker.ring.material.opacity = 0;
});
}
function updateWheels(truck, time) {
for (const wheel of truck.wheels) {
wheel.rotation.x = -time * 4.5;
}
}
resetVisuals();
// -------------------------------------------------------------------------
// UI controls
// -------------------------------------------------------------------------
const pauseButton = document.getElementById("pauseButton");
const replayButton = document.getElementById("replayButton");
const resetCameraButton = document.getElementById("resetCameraButton");
const timeReadout = document.getElementById("timeReadout");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
pauseButton.setAttribute("aria-pressed", String(paused));
});
replayButton.addEventListener("click", () => {
simulationTime = 0;
previousSimulationTime = 0;
resetVisuals();
});
resetCameraButton.addEventListener("click", () => {
cameraRig.reset();
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
let lastFrameTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastFrameTime) / 1000, 0.05);
lastFrameTime = now;
if (!paused) {
simulationTime = (simulationTime + delta) % CYCLE_LENGTH;
}
if (simulationTime < previousSimulationTime) {
resetVisuals();
}
previousSimulationTime = simulationTime;
updateSeparateVehicles(simulationTime);
updateConsolidatedTruck(simulationTime);
updateWheels(consolidatedTruck, simulationTime);
separateVehicles.forEach((truck) =>
updateWheels(truck, simulationTime)
);
cameraRig.update();
updateLabels();
timeReadout.textContent =
`${simulationTime.toFixed(1)} / ${CYCLE_LENGTH.toFixed(1)} s`;
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```