Prompt specification
Build or customize the Three.js 3D scene "Courier Chooses Speed or Coverage" 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: Courier Chooses Speed or Coverage
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/courier-chooses-speed-or-coverage-x3550
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows tradeoffs between route objectives. Build a small map offering a fast direct delivery or a slower route serving more stops. Display both outcomes without hiding the objective choice. Voxel style.
Working Three.js Starter (courier-chooses-speed-or-coverage-x3550):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Route Trade-offs — Voxel Logistics Map</title>
<style>
:root {
--bg: #07130f;
--panel: rgba(10, 25, 21, 0.88);
--panel-solid: #0c1d18;
--line: rgba(184, 229, 207, 0.14);
--text: #edf8f1;
--muted: #91aa9e;
--fast: #53f2cf;
--broad: #ffbd59;
--fast-soft: rgba(83, 242, 207, 0.12);
--broad-soft: rgba(255, 189, 89, 0.12);
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 52% 43%, transparent 30%, rgba(2, 9, 7, 0.28) 75%),
linear-gradient(180deg, rgba(3, 10, 8, 0.24), transparent 22%, transparent 75%, rgba(3, 10, 8, 0.38));
z-index: 1;
}
.header {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
height: 74px;
padding: 0 24px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
background: linear-gradient(180deg, rgba(5, 14, 11, 0.92), rgba(5, 14, 11, 0));
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 36px;
height: 36px;
display: grid;
place-items: center;
position: relative;
border: 1px solid rgba(83, 242, 207, 0.5);
background: rgba(83, 242, 207, 0.09);
box-shadow: inset 0 0 18px rgba(83, 242, 207, 0.08);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
width: 13px;
height: 13px;
border: 2px solid var(--fast);
}
.brand-mark::before {
transform: translate(-3px, -3px);
border-right: 0;
border-bottom: 0;
}
.brand-mark::after {
transform: translate(3px, 3px);
border-left: 0;
border-top: 0;
}
.brand-title {
font-size: 13px;
line-height: 1.15;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.brand-subtitle {
margin-top: 4px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.06em;
}
.simulation-pill {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid var(--line);
background: rgba(10, 27, 22, 0.72);
color: #b9cfc4;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.simulation-pill i {
width: 6px;
height: 6px;
background: var(--fast);
box-shadow: 0 0 10px var(--fast);
animation: blink 2s ease-in-out infinite;
}
@keyframes blink {
50% { opacity: 0.35; }
}
.panel {
position: fixed;
z-index: 8;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.objective-panel {
top: 94px;
left: 24px;
width: 344px;
padding: 20px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--fast);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 18px;
height: 2px;
background: currentColor;
}
h1 {
margin: 13px 0 8px;
max-width: 280px;
font-size: 27px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 0 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.6;
}
.objective-list {
display: grid;
gap: 10px;
}
.objective-option {
width: 100%;
padding: 14px;
display: grid;
grid-template-columns: 24px 1fr;
gap: 10px;
color: var(--text);
text-align: left;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.objective-option:hover {
transform: translateY(-1px);
border-color: rgba(255, 255, 255, 0.26);
}
.objective-option:focus-visible,
.compare-card:focus-visible,
#reset-camera:focus-visible {
outline: 2px solid var(--fast);
outline-offset: 3px;
}
.objective-option.active[data-mode="fast"] {
border-color: rgba(83, 242, 207, 0.58);
background: var(--fast-soft);
}
.objective-option.active[data-mode="broad"] {
border-color: rgba(255, 189, 89, 0.62);
background: var(--broad-soft);
}
.radio {
width: 18px;
height: 18px;
margin-top: 1px;
border: 1px solid #61776d;
display: grid;
place-items: center;
}
.radio::after {
content: "";
width: 8px;
height: 8px;
background: transparent;
}
.active[data-mode="fast"] .radio::after {
background: var(--fast);
box-shadow: 0 0 10px rgba(83, 242, 207, 0.65);
}
.active[data-mode="broad"] .radio::after {
background: var(--broad);
box-shadow: 0 0 10px rgba(255, 189, 89, 0.65);
}
.option-title-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.option-title {
font-size: 13px;
font-weight: 800;
}
.route-swatch {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.route-swatch::before {
content: "";
width: 15px;
height: 3px;
background: currentColor;
box-shadow: 0 0 8px currentColor;
}
.fast-color { color: var(--fast); }
.broad-color { color: var(--broad); }
.option-description {
margin-top: 5px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.option-metrics {
margin-top: 11px;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.mini-metric {
padding-left: 8px;
border-left: 1px solid var(--line);
}
.mini-metric strong {
display: block;
font-size: 14px;
letter-spacing: -0.03em;
}
.mini-metric span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.choice-note {
margin: 14px 0 0;
padding-top: 13px;
display: flex;
gap: 9px;
color: #9fb4a9;
border-top: 1px solid var(--line);
font-size: 10px;
line-height: 1.5;
}
.choice-note span {
color: var(--fast);
font-size: 14px;
line-height: 1;
}
.map-tools {
position: fixed;
z-index: 9;
top: 92px;
right: 24px;
display: flex;
align-items: center;
gap: 8px;
}
.legend {
display: flex;
gap: 15px;
padding: 10px 13px;
border: 1px solid var(--line);
background: rgba(8, 21, 17, 0.78);
backdrop-filter: blur(12px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #c3d4cc;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-item::before {
content: "";
width: 15px;
height: 3px;
background: currentColor;
box-shadow: 0 0 8px currentColor;
}
#reset-camera {
width: 36px;
height: 36px;
display: grid;
place-items: center;
color: var(--text);
border: 1px solid var(--line);
background: rgba(8, 21, 17, 0.78);
cursor: pointer;
}
#reset-camera:hover {
border-color: var(--fast);
color: var(--fast);
}
.camera-help {
position: fixed;
z-index: 7;
right: 24px;
bottom: 255px;
color: rgba(201, 221, 211, 0.6);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.comparison {
right: 24px;
bottom: 24px;
width: 548px;
padding: 17px;
}
.comparison-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.comparison-heading h2 {
margin: 0;
font-size: 13px;
letter-spacing: -0.01em;
}
.choice-badge {
padding: 5px 8px;
color: var(--fast);
border: 1px solid rgba(83, 242, 207, 0.35);
background: var(--fast-soft);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.comparison-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.compare-card {
padding: 11px;
color: var(--text);
text-align: left;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: 160ms ease;
}
.compare-card:hover {
border-color: rgba(255, 255, 255, 0.25);
}
.compare-card.active[data-mode="fast"] {
border-color: rgba(83, 242, 207, 0.55);
background: var(--fast-soft);
}
.compare-card.active[data-mode="broad"] {
border-color: rgba(255, 189, 89, 0.58);
background: var(--broad-soft);
}
.compare-name {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
font-size: 10px;
font-weight: 800;
text-transform: uppercase;
letter-spacing: 0.07em;
}
.selected-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: transparent;
border: 1px solid #657a70;
}
.active[data-mode="fast"] .selected-dot {
background: var(--fast);
border-color: var(--fast);
box-shadow: 0 0 8px var(--fast);
}
.active[data-mode="broad"] .selected-dot {
background: var(--broad);
border-color: var(--broad);
box-shadow: 0 0 8px var(--broad);
}
.metric-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
}
.metric strong {
display: block;
font-size: 15px;
letter-spacing: -0.04em;
}
.metric span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 7px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.tradeoff-copy {
margin: 11px 0 0;
color: #9db4a8;
font-size: 10px;
line-height: 1.5;
}
.tradeoff-copy strong {
color: var(--text);
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
.map-label {
position: absolute;
transform: translate(-50%, -100%);
padding: 7px 9px;
white-space: nowrap;
border: 1px solid currentColor;
background: rgba(5, 15, 12, 0.88);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.32);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.09em;
text-transform: uppercase;
transition: opacity 180ms ease;
}
.map-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
transform: translateX(-50%) rotate(45deg);
background: rgba(5, 15, 12, 0.88);
border-right: 1px solid currentColor;
border-bottom: 1px solid currentColor;
}
.map-label.fast {
color: var(--fast);
}
.map-label.broad {
color: var(--broad);
}
.depot-label {
color: #dce9e2;
border-color: rgba(220, 233, 226, 0.25);
font-size: 8px;
padding: 5px 7px;
}
.depot-label::after {
border-color: rgba(220, 233, 226, 0.25);
}
.loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
color: var(--fast);
background: var(--bg);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 400ms ease, visibility 400ms ease;
}
.loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-box {
display: flex;
align-items: center;
gap: 12px;
}
.loading-cube {
width: 17px;
height: 17px;
border: 2px solid var(--fast);
animation: loading 1.2s ease-in-out infinite;
}
@keyframes loading {
50% { transform: rotate(45deg) scale(0.75); }
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 980px) {
.objective-panel {
width: 310px;
}
.comparison {
width: 460px;
}
.camera-help {
display: none;
}
}
@media (max-width: 720px) {
.header {
height: 62px;
padding: 0 12px;
}
.brand-subtitle,
.simulation-pill {
display: none;
}
.brand-title {
font-size: 11px;
}
.objective-panel {
top: 72px;
left: 12px;
width: calc(100% - 24px);
padding: 13px;
}
.objective-panel h1,
.intro,
.choice-note {
display: none;
}
.objective-panel .eyebrow {
margin-bottom: 10px;
}
.objective-list {
grid-template-columns: 1fr 1fr;
}
.objective-option {
padding: 10px;
grid-template-columns: 18px 1fr;
gap: 7px;
}
.option-title {
font-size: 11px;
}
.option-description,
.route-swatch,
.option-metrics {
display: none;
}
.comparison {
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
padding: 12px;
}
.comparison-heading {
margin-bottom: 8px;
}
.comparison-heading h2 {
font-size: 11px;
}
.compare-card {
padding: 8px;
}
.compare-name {
font-size: 8px;
}
.metric strong {
font-size: 13px;
}
.tradeoff-copy {
margin-top: 8px;
font-size: 9px;
}
.map-tools {
top: 196px;
right: 12px;
}
.legend {
display: none;
}
.map-label {
padding: 5px 6px;
font-size: 7px;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive voxel logistics map"></canvas>
<div class="vignette"></div>
<header class="header">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="brand-title">Waypoint / Lab</div>
<div class="brand-subtitle">Route objective trade-off simulator</div>
</div>
</div>
<div class="simulation-pill"><i></i> Scenario 08:00 · Depot dispatch</div>
</header>
<aside class="objective-panel panel">
<div class="eyebrow">Choose the objective</div>
<h1>What should this route optimize?</h1>
<p class="intro">
Both delivery outcomes remain visible. Select an objective to emphasize its route,
timing, and completed stops.
</p>
<div class="objective-list" role="group" aria-label="Delivery objective">
<button class="objective-option active" data-mode="fast" aria-pressed="true">
<span class="radio" aria-hidden="true"></span>
<span>
<span class="option-title-row">
<span class="option-title">Fast direct delivery</span>
<span class="route-swatch fast-color">Fast</span>
</span>
<span class="option-description">One priority delivery to Harbor Market.</span>
<span class="option-metrics">
<span class="mini-metric"><strong>24 min</strong><span>ETA</span></span>
<span class="mini-metric"><strong>1</strong><span>Stop</span></span>
<span class="mini-metric"><strong>7.8 km</strong><span>Travel</span></span>
</span>
</span>
</button>
<button class="objective-option" data-mode="broad" aria-pressed="false">
<span class="radio" aria-hidden="true"></span>
<span>
<span class="option-title-row">
<span class="option-title">Serve more stops</span>
<span class="route-swatch broad-color">Coverage</span>
</span>
<span class="option-description">A shared run serving six neighborhood orders.</span>
<span class="option-metrics">
<span class="mini-metric"><strong>49 min</strong><span>ETA</span></span>
<span class="mini-metric"><strong>6</strong><span>Stops</span></span>
<span class="mini-metric"><strong>15.6 km</strong><span>Travel</span></span>
</span>
</span>
</button>
</div>
<p class="choice-note">
<span>↗</span>
The map never hides the alternative route; emphasis changes only to make the
selected trade-off easier to inspect.
</p>
</aside>
<div class="map-tools">
<div class="legend" aria-label="Route legend">
<span class="legend-item fast-color">Fast direct</span>
<span class="legend-item broad-color">More stops</span>
</div>
<button id="reset-camera" title="Reset camera" aria-label="Reset camera">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 11a8 8 0 1 1 2.34 5.66" stroke="currentColor" stroke-width="1.8"/>
<path d="M4 5v6h6" stroke="currentColor" stroke-width="1.8"/>
</svg>
</button>
</div>
<div id="labels" aria-hidden="true">
<div id="label-fast" class="map-label fast">Fast · 24 min · 1 stop</div>
<div id="label-broad" class="map-label broad">Coverage · 49 min · 6 stops</div>
<div id="label-depot" class="map-label depot-label">Dispatch depot</div>
</div>
<div class="camera-help">Drag to orbit · Scroll to zoom</div>
<section class="comparison panel" aria-label="Outcome comparison">
<div class="comparison-heading">
<h2>Trade-off at a glance</h2>
<span id="choice-badge" class="choice-badge">Fast direct</span>
</div>
<div class="comparison-grid">
<button class="compare-card active" data-mode="fast" aria-pressed="true">
<div class="compare-name">
<span class="fast-color">Fast direct</span>
<span class="selected-dot" aria-hidden="true"></span>
</div>
<div class="metric-row">
<div class="metric"><strong>24 min</strong><span>Arrival</span></div>
<div class="metric"><strong>1</strong><span>Stops</span></div>
<div class="metric"><strong>7.8 km</strong><span>Distance</span></div>
</div>
</button>
<button class="compare-card" data-mode="broad" aria-pressed="false">
<div class="compare-name">
<span class="broad-color">More stops</span>
<span class="selected-dot" aria-hidden="true"></span>
</div>
<div class="metric-row">
<div class="metric"><strong>49 min</strong><span>Arrival</span></div>
<div class="metric"><strong>6</strong><span>Stops</span></div>
<div class="metric"><strong>15.6 km</strong><span>Distance</span></div>
</div>
</button>
</div>
<p id="tradeoff-copy" class="tradeoff-copy">
<strong>Fast direct:</strong> Harbor Market arrives 25 minutes sooner, but only
one order is served.
</p>
</section>
<div id="status" class="sr-only" aria-live="polite"></div>
<div id="loading" class="loading">
<div class="loading-box">
<div class="loading-cube"></div>
Building route scenario
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.16;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07130f);
scene.fog = new THREE.Fog(0x07130f, 38, 70);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
target: new THREE.Vector3(0, 0.4, 0),
radius: 31,
theta: 0.67,
phi: 0.76,
desiredRadius: 31,
desiredTheta: 0.67,
desiredPhi: 0.76
};
const hemisphere = new THREE.HemisphereLight(0xbde8d8, 0x14251f, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d7, 3.3);
sun.position.set(-12, 22, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0005;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x53f2cf, 1.15);
rimLight.position.set(14, 8, -14);
scene.add(rimLight);
const palette = {
fast: 0x53f2cf,
broad: 0xffbd59,
road: 0x172825,
roadEdge: 0x294139,
base: 0x10251e,
ground: 0x19372d
};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0.03,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true
});
}
function box(width, height, depth, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
options.material || material(color, options)
);
mesh.position.set(options.x || 0, options.y || 0, options.z || 0);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
if (options.rotationY) mesh.rotation.y = options.rotationY;
return mesh;
}
// Raised voxel map base.
scene.add(box(27.4, 1, 21.4, palette.base, { y: -0.52 }));
scene.add(box(26.8, 0.1, 20.8, palette.ground, { y: -0.02 }));
// Thin raised frame.
const frameMaterial = material(0x24483a, { roughness: 0.7 });
scene.add(box(26.9, 0.2, 0.22, 0x24483a, {
y: 0.08, z: -10.35, material: frameMaterial, castShadow: false
}));
scene.add(box(26.9, 0.2, 0.22, 0x24483a, {
y: 0.08, z: 10.35, material: frameMaterial, castShadow: false
}));
scene.add(box(0.22, 0.2, 20.9, 0x24483a, {
x: -13.35, y: 0.08, material: frameMaterial, castShadow: false
}));
scene.add(box(0.22, 0.2, 20.9, 0x24483a, {
x: 13.35, y: 0.08, material: frameMaterial, castShadow: false
}));
// Street network.
const roadXs = [-8, 0, 4, 8];
const roadZs = [-5, 0, 3, 5];
for (const x of roadXs) {
scene.add(box(1.8, 0.055, 20.1, palette.road, {
x, y: 0.035, castShadow: false
}));
scene.add(box(1.98, 0.07, 20.2, palette.roadEdge, {
x, y: 0.005, castShadow: false
}));
}
for (const z of roadZs) {
scene.add(box(26.1, 0.055, 1.8, palette.road, {
z, y: 0.035, castShadow: false
}));
scene.add(box(26.2, 0.07, 1.98, palette.roadEdge, {
z, y: 0.005, castShadow: false
}));
}
// Lane dashes.
const dashMaterial = material(0x8ca69a, {
emissive: 0x31483f,
emissiveIntensity: 0.15,
roughness: 0.65
});
for (const z of roadZs) {
for (let x = -12; x <= 12; x += 2.35) {
scene.add(box(0.65, 0.025, 0.08, 0x8ca69a, {
x, y: 0.076, z, material: dashMaterial,
castShadow: false, receiveShadow: false
}));
}
}
for (const x of roadXs) {
for (let z = -9; z <= 9; z += 2.35) {
scene.add(box(0.08, 0.025, 0.65, 0x8ca69a, {
x, y: 0.076, z, material: dashMaterial,
castShadow: false, receiveShadow: false
}));
}
}
// Deterministic pseudo-random city generation.
let seed = 4182;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const xZones = [
[-12.65, -9.05],
[-6.8, -1.1],
[1.1, 2.9],
[5.1, 6.9],
[9.1, 12.65]
];
const zZones = [
[-9.6, -6.1],
[-3.9, -1.1],
[1.1, 1.9],
[4.1, 4.9],
[6.1, 9.6]
];
const buildingColors = [0x31564b, 0x3d6256, 0x294b43, 0x47675b, 0x24423c];
const roofColors = [0x1d3831, 0x29473d, 0x203b34];
const windowMaterial = material(0x9ddbc3, {
emissive: 0x5acba7,
emissiveIntensity: 0.85,
roughness: 0.4
});
const reservedTrees = [
[-12.1, -8.7], [-6.1, 8.1], [11.4, 8.2],
[12.2, -8.3], [6.1, -8.2], [-10.4, 7.3]
];
function addBuilding(x, z, width, depth, height, colorIndex) {
const bodyMaterial = material(buildingColors[colorIndex % buildingColors.length]);
const body = box(width, height, depth, 0xffffff, {
x, y: height / 2 + 0.05, z, material: bodyMaterial
});
scene.add(body);
const roofMaterial = material(roofColors[colorIndex % roofColors.length]);
scene.add(box(width + 0.12, 0.18, depth + 0.12, 0xffffff, {
x, y: height + 0.13, z, material: roofMaterial
}));
if (height > 1.4 && random() > 0.38) {
const roofUnitW = Math.min(width * 0.5, 1.1);
const roofUnitD = Math.min(depth * 0.5, 0.9);
scene.add(box(roofUnitW, 0.48, roofUnitD, 0x1a302b, {
x: x + (random() - 0.5) * 0.35,
y: height + 0.46,
z: z + (random() - 0.5) * 0.25,
material: material(0x1a302b)
}));
}
const floors = Math.max(1, Math.min(3, Math.floor(height / 1.05)));
const columns = Math.max(1, Math.floor(width / 0.72));
for (let floor = 0; floor < floors; floor++) {
for (let column = 0; column < columns; column++) {
if (random() < 0.18) continue;
const wx = x - width / 2 + (column + 0.5) * (width / columns);
const wy = 0.55 + floor * 0.82;
scene.add(box(0.22, 0.25, 0.035, 0xffffff, {
x: wx, y: wy, z: z + depth / 2 + 0.018,
material: windowMaterial,
castShadow: false,
receiveShadow: false
}));
}
}
}
for (const xZone of xZones) {
for (const zZone of zZones) {
const zoneWidth = xZone[1] - xZone[0];
const zoneDepth = zZone[1] - zZone[0];
const count = Math.max(1, Math.min(3, Math.floor((zoneWidth * zoneDepth) / 3.3)));
for (let i = 0; i < count; i++) {
const x = xZone[0] + 0.8 + random() * Math.max(0.2, zoneWidth - 1.6);
const z = zZone[0] + 0.7 + random() * Math.max(0.2, zoneDepth - 1.4);
if (reservedTrees.some(([tx, tz]) => Math.hypot(x - tx, z - tz) < 1.0)) {
continue;
}
const width = Math.min(1.9, 0.8 + random() * Math.min(1.4, zoneWidth * 0.48));
const depth = Math.min(1.8, 0.8 + random() * Math.min(1.3, zoneDepth * 0.48));
const height = 0.7 + random() * (zoneDepth > 2.3 ? 3.7 : 2.0);
addBuilding(x, z, width, depth, height, Math.floor(random() * buildingColors.length));
}
}
}
// Voxel trees.
function addTree(x, z, scale = 1) {
const trunk = box(0.25 * scale, 0.9 * scale, 0.25 * scale, 0x604c37, {
x, y: 0.45 * scale, z
});
scene.add(trunk);
const leaves = material(0x4f8f62, { roughness: 0.95 });
scene.add(box(1.05 * scale, 0.65 * scale, 1.05 * scale, 0xffffff, {
x, y: 1.08 * scale, z, material: leaves
}));
scene.add(box(0.7 * scale, 0.55 * scale, 0.7 * scale, 0xffffff, {
x, y: 1.62 * scale, z, material: leaves
}));
}
reservedTrees.forEach(([x, z], index) => addTree(x, z, 0.78 + (index % 3) * 0.1));
// Depot truck built from voxels.
const truck = new THREE.Group();
truck.position.set(-8.9, 0.08, 3);
truck.add(box(1.55, 0.62, 0.82, 0xd7e3dc, { x: 0.35, y: 0.62 }));
truck.add(box(0.62, 0.8, 0.86, 0x93b8aa, { x: -0.58, y: 0.56 }));
truck.add(box(0.06, 0.28, 0.6, 0x214c45, { x: -0.9, y: 0.72 }));
truck.add(box(0.03, 0.03, 0.85, 0xffd991, { x: -0.91, y: 0.42 }));
truck.add(box(0.46, 0.28, 0.86, 0x4b675f, { x: 0.4, y: 1.05 }));
truck.add(box(0.22, 0.22, 0.22, 0x17231f, { x: 0.95, y: 0.25, z: 0.48 }));
truck.add(box(0.22, 0.22, 0.22, 0x17231f, { x: 0.95, y: 0.25, z: -0.48 }));
truck.add(box(0.22, 0.22, 0.22, 0x17231f, { x: -0.45, y: 0.25, z: 0.48 }));
truck.add(box(0.22, 0.22, 0.22, 0x17231f, { x: -0.45, y: 0.25, z: -0.48 }));
scene.add(truck);
function createNumberSprite(number, color) {
const c = document.createElement("canvas");
c.width = 128;
c.height = 128;
const ctx = c.getContext("2d");
ctx.fillStyle = "rgba(7, 19, 15, 0.92)";
ctx.fillRect(13, 13, 102, 102);
ctx.strokeStyle = `#${new THREE.Color(color).getHexString()}`;
ctx.lineWidth = 8;
ctx.strokeRect(13, 13, 102, 102);
ctx.fillStyle = `#${new THREE.Color(color).getHexString()}`;
ctx.font = "bold 58px system-ui";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(String(number), 64, 67);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(0.95, 0.95, 0.95);
sprite.renderOrder = 20;
return sprite;
}
function createStopMarker(x, z, number, color, markerMaterial, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
group.add(box(0.86 * scale, 0.14, 0.86 * scale, 0x233a34, {
y: 0.08, material: material(0x233a34)
}));
const beacon = box(0.46 * scale, 0.52 * scale, 0.46 * scale, 0xffffff, {
y: 0.41 * scale, material: markerMaterial
});
group.add(beacon);
const numberSprite = createNumberSprite(number, color);
numberSprite.position.y = 1.12 * scale;
numberSprite.scale.multiplyScalar(scale);
group.add(numberSprite);
scene.add(group);
return group;
}
const broadMarkerMaterial = material(palette.broad, {
emissive: palette.broad,
emissiveIntensity: 1.4,
transparent: true,
opacity: 1,
roughness: 0.4
});
const fastMarkerMaterial = material(palette.fast, {
emissive: palette.fast,
emissiveIntensity: 1.65,
transparent: true,
opacity: 1,
roughness: 0.4
});
const broadStops = [
[-4, 0],
[0.35, -5],
[4.35, -5],
[7.65, 3],
[4.35, 4.65],
[0.35, 3]
];
const broadMarkerGroups = broadStops.map(([x, z], index) =>
createStopMarker(x, z, index + 1, palette.broad, broadMarkerMaterial, 0.78)
);
const fastMarkerGroup = createStopMarker(
8.35, -5, 1, palette.fast, fastMarkerMaterial, 1.08
);
// Package outcomes remain visible for both choices.
const fastPackageMaterial = material(0xc6fff0, {
emissive: palette.fast,
emissiveIntensity: 0.32,
transparent: true,
opacity: 1
});
const fastPackage = new THREE.Group();
fastPackage.position.set(8.95, 0.25, -5.65);
fastPackage.add(box(0.75, 0.62, 0.75, 0xffffff, {
material: fastPackageMaterial
}));
fastPackage.add(box(0.78, 0.12, 0.12, palette.fast, {
y: 0.1, material: material(palette.fast, { emissive: palette.fast, emissiveIntensity: 0.7 })
}));
scene.add(fastPackage);
const broadPackageMaterial = material(0xffdf9a, {
emissive: palette.broad,
emissiveIntensity: 0.26,
transparent: true,
opacity: 1
});
const broadPackages = broadStops.map(([x, z]) => {
const group = new THREE.Group();
group.position.set(x + 0.48, 0.25, z + 0.48);
group.add(box(0.48, 0.4, 0.48, 0xffffff, {
material: broadPackageMaterial
}));
group.add(box(0.5, 0.08, 0.1, palette.broad, {
y: 0.08, material: material(palette.broad, {
emissive: palette.broad,
emissiveIntensity: 0.55
})
}));
scene.add(group);
return group;
});
// Route paths are offset into parallel lanes so their trade-off is readable.
const fastPath = [
[-8.35, 3],
[-8.35, 0],
[8.35, 0],
[8.35, -5]
];
const broadPath = [
[-7.65, 3],
[-7.65, 0],
[0.35, 0],
[0.35, -5],
[4.35, -5],
[4.35, 0],
[7.65, 0],
[7.65, 3],
[4.35, 3],
[4.35, 4.65],
[0.35, 4.65],
[0.35, 3],
[-7.65, 3]
];
function createRoute(path, color) {
const group = new THREE.Group();
const routeMaterial = material(color, {
emissive: color,
emissiveIntensity: 1.65,
transparent: true,
opacity: 1,
roughness: 0.38,
depthWrite: false
});
const points = path.map(([x, z]) => new THREE.Vector3(x, 0.15, z));
const cumulative = [0];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
total += length;
cumulative.push(total);
const isX = Math.abs(dx) > Math.abs(dz);
const segment = box(
isX ? length : 0.29,
0.14,
isX ? 0.29 : length,
0xffffff,
{
x: (a.x + b.x) / 2,
y: 0.15,
z: (a.z + b.z) / 2,
material: routeMaterial,
castShadow: false,
receiveShadow: false
}
);
group.add(segment);
}
points.forEach((point) => {
group.add(box(0.39, 0.18, 0.39, 0xffffff, {
x: point.x, y: 0.17, z: point.z,
material: routeMaterial,
castShadow: false,
receiveShadow: false
}));
});
const particleMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 1
});
const particle = box(0.38, 0.38, 0.38, color, {
material: particleMaterial,
castShadow: false,
receiveShadow: false
});
group.add(particle);
scene.add(group);
return {
group,
material: routeMaterial,
particle,
particleMaterial,
points,
cumulative,
total,
distance: 0
};
}
const fastRoute = createRoute(fastPath, palette.fast);
const broadRoute = createRoute(broadPath, palette.broad);
function sampleRoute(route, distance) {
const d = ((distance % route.total) + route.total) % route.total;
for (let i = 0; i < route.points.length - 1; i++) {
if (d <= route.cumulative[i + 1]) {
const a = route.points[i];
const b = route.points[i + 1];
const segmentLength = route.cumulative[i + 1] - route.cumulative[i];
const t = segmentLength === 0 ? 0 : (d - route.cumulative[i]) / segmentLength;
return new THREE.Vector3().lerpVectors(a, b, t);
}
}
return route.points[route.points.length - 1].clone();
}
// Custom camera controls: drag/orbit, wheel zoom, keyboard nudging.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.desiredTheta -= dx * 0.006;
cameraState.desiredPhi = THREE.MathUtils.clamp(
cameraState.desiredPhi - dy * 0.005,
0.38,
1.32
);
});
function stopDragging(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.style.cursor = "grab";
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius + event.deltaY * 0.018,
17,
47
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
const step = 0.12;
if (event.key === "ArrowLeft") cameraState.desiredTheta += step;
if (event.key === "ArrowRight") cameraState.desiredTheta -= step;
if (event.key === "ArrowUp") cameraState.desiredPhi -= step;
if (event.key === "ArrowDown") cameraState.desiredPhi += step;
if (event.key === "+" || event.key === "=") cameraState.desiredRadius -= 1;
if (event.key === "-") cameraState.desiredRadius += 1;
});
document.querySelector("#reset-camera").addEventListener("click", () => {
cameraState.desiredRadius = 31;
cameraState.desiredTheta = 0.67;
cameraState.desiredPhi = 0.76;
});
let activeMode = "fast";
function setMode(mode) {
activeMode = mode;
document.querySelectorAll("[data-mode]").forEach((element) => {
const isActive = element.dataset.mode === mode;
element.classList.toggle("active", isActive);
element.setAttribute("aria-pressed", String(isActive));
});
const fastSelected = mode === "fast";
fastRoute.material.opacity = fastSelected ? 0.98 : 0.28;
fastRoute.material.emissiveIntensity = fastSelected ? 1.9 : 0.65;
fastRoute.particleMaterial.opacity = fastSelected ? 1 : 0.45;
broadRoute.material.opacity = fastSelected ? 0.28 : 0.96;
broadRoute.material.emissiveIntensity = fastSelected ? 0.65 : 1.8;
broadRoute.particleMaterial.opacity = fastSelected ? 0.45 : 1;
fastMarkerMaterial.opacity = fastSelected ? 1 : 0.48;
broadMarkerMaterial.opacity = fastSelected ? 0.48 : 1;
fastPackageMaterial.opacity = fastSelected ? 1 : 0.5;
broadPackageMaterial.opacity = fastSelected ? 0.5 : 1;
fastMarkerGroup.scale.setScalar(fastSelected ? 1 : 0.84);
broadMarkerGroups.forEach((group) => {
group.scale.setScalar(fastSelected ? 0.84 : 1);
});
document.querySelector("#label-fast").style.opacity = fastSelected ? "1" : "0.52";
document.querySelector("#label-broad").style.opacity = fastSelected ? "0.52" : "1";
const badge = document.querySelector("#choice-badge");
badge.textContent = fastSelected ? "Fast direct" : "More stops";
badge.style.color = fastSelected ? "var(--fast)" : "var(--broad)";
badge.style.borderColor = fastSelected
? "rgba(83, 242, 207, 0.35)"
: "rgba(255, 189, 89, 0.4)";
badge.style.background = fastSelected ? "var(--fast-soft)" : "var(--broad-soft)";
document.querySelector("#tradeoff-copy").innerHTML = fastSelected
? "<strong>Fast direct:</strong> Harbor Market arrives 25 minutes sooner, but only one order is served."
: "<strong>More stops:</strong> The shared run serves six orders instead of one, at the cost of 25 additional minutes.";
document.querySelector("#status").textContent = fastSelected
? "Fast direct delivery selected. Twenty-four minutes, one stop, 7.8 kilometers."
: "More stops selected. Forty-nine minutes, six stops, 15.6 kilometers.";
}
document.querySelectorAll("[data-mode]").forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
setMode("fast");
// Screen-space labels projected from 3D positions.
const labelElements = {
fast: document.querySelector("#label-fast"),
broad: document.querySelector("#label-broad"),
depot: document.querySelector("#label-depot")
};
const labelPositions = {
fast: new THREE.Vector3(8.35, 2.55, -5),
broad: new THREE.Vector3(0.35, 2.25, -5),
depot: new THREE.Vector3(-8.8, 1.85, 3)
};
function updateLabel(element, position) {
const projected = position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
cameraState.theta += (cameraState.desiredTheta - cameraState.theta) * 0.12;
cameraState.phi += (cameraState.desiredPhi - cameraState.phi) * 0.12;
cameraState.radius += (cameraState.desiredRadius - cameraState.radius) * 0.12;
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);
camera.updateMatrixWorld();
fastRoute.distance += delta * 5.4;
broadRoute.distance += delta * 3.3;
fastRoute.particle.position.copy(sampleRoute(fastRoute, fastRoute.distance));
broadRoute.particle.position.copy(sampleRoute(broadRoute, broadRoute.distance));
fastRoute.particle.rotation.y += delta * 2.2;
broadRoute.particle.rotation.y -= delta * 1.7;
const pulse = 1 + Math.sin(elapsed * 3.2) * 0.08;
fastPackage.scale.setScalar(pulse);
broadPackages.forEach((packageGroup, index) => {
packageGroup.scale.setScalar(1 + Math.sin(elapsed * 3 + index * 0.7) * 0.055);
});
renderer.render(scene, camera);
updateLabel(labelElements.fast, labelPositions.fast);
updateLabel(labelElements.broad, labelPositions.broad);
updateLabel(labelElements.depot, labelPositions.depot);
requestAnimationFrame(animate);
}
animate();
window.setTimeout(() => {
document.querySelector("#loading").classList.add("hidden");
}, 500);
</script>
</body>
</html>
```