Prompt specification
Build or customize the Three.js 3D scene "Load Assumptions Change the Comparison" 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: Load Assumptions Change the Comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/load-assumptions-change-the-comparison-x2156
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring delivery loads, routes, and emissions proxies. Create a controlled transport comparison varying occupancy or cargo load under fixed routes. Show sensitivity of the declared proxy and distinguish model output from measured environmental impact. Voxel style.
Working Three.js Starter (load-assumptions-change-the-comparison-x2156):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fleet Lab — Controlled Transport Comparison</title>
<style>
:root {
--paper: #eef0e7;
--panel: #fbfcf7;
--ink: #182825;
--muted: #66736e;
--line: #d6ddd4;
--green: #267b78;
--green-light: #d9ece7;
--orange: #df6843;
--orange-light: #f8e3d9;
--yellow: #e8b44d;
--blue: #376d92;
--shadow: 0 8px 0 rgba(24, 40, 37, 0.07);
}
* {
box-sizing: border-box;
}
html {
color-scheme: light;
}
body {
margin: 0;
min-width: 320px;
background:
linear-gradient(rgba(24, 40, 37, 0.025) 1px, transparent 1px),
linear-gradient(90deg, rgba(24, 40, 37, 0.025) 1px, transparent 1px),
var(--paper);
background-size: 24px 24px;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button,
select {
cursor: pointer;
}
button:focus-visible,
select:focus-visible,
input:focus-visible,
canvas:focus-visible {
outline: 3px solid rgba(38, 123, 120, 0.35);
outline-offset: 3px;
}
.app {
width: min(1580px, calc(100% - 32px));
margin: 0 auto;
padding: 22px 0 30px;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
margin-bottom: 18px;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
display: grid;
width: 46px;
height: 46px;
place-items: center;
border: 2px solid var(--ink);
background: var(--yellow);
box-shadow: 4px 4px 0 var(--ink);
font-size: 25px;
font-weight: 900;
}
.brand-name {
margin: 0;
font-size: 19px;
font-weight: 850;
letter-spacing: -0.02em;
}
.brand-subtitle {
margin: 3px 0 0;
color: var(--muted);
font-size: 12px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-pill {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
border: 1px solid #d9c699;
background: #fff4d5;
color: #76561e;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
background: var(--orange);
box-shadow: 0 0 0 3px rgba(223, 104, 67, 0.15);
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1.55fr) minmax(350px, 0.75fr);
gap: 18px;
align-items: start;
}
.card {
border: 1px solid var(--line);
background: var(--panel);
box-shadow: var(--shadow);
}
.visual-card {
position: sticky;
top: 14px;
overflow: hidden;
}
.stage {
position: relative;
height: min(71vh, 760px);
min-height: 590px;
overflow: hidden;
background: #e7ece2;
isolation: isolate;
}
.webgl {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.scene-header {
position: absolute;
z-index: 3;
top: 22px;
left: 22px;
max-width: 430px;
pointer-events: none;
}
.eyebrow {
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.scene-header h1 {
margin: 7px 0 7px;
font-size: clamp(26px, 3vw, 43px);
line-height: 0.99;
letter-spacing: -0.045em;
}
.scene-header p {
max-width: 390px;
margin: 0;
color: #53625d;
font-size: 13px;
line-height: 1.45;
}
.route-badge {
position: absolute;
z-index: 4;
top: 22px;
right: 22px;
min-width: 190px;
padding: 12px 14px;
border: 1px solid rgba(24, 40, 37, 0.13);
background: rgba(251, 252, 247, 0.92);
backdrop-filter: blur(8px);
box-shadow: 0 5px 0 rgba(24, 40, 37, 0.08);
}
.route-badge small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.route-badge strong {
display: block;
font-size: 14px;
}
.route-badge span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
}
.scene-footer {
position: absolute;
z-index: 4;
right: 22px;
bottom: 22px;
left: 22px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.legend-panel {
display: flex;
flex-wrap: wrap;
gap: 8px;
padding: 10px;
border: 1px solid rgba(24, 40, 37, 0.12);
background: rgba(251, 252, 247, 0.92);
backdrop-filter: blur(8px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
padding: 3px 5px;
font-size: 11px;
font-weight: 750;
}
.legend-swatch {
width: 11px;
height: 11px;
box-shadow: 2px 2px 0 rgba(24, 40, 37, 0.15);
}
.legend-item.route {
color: var(--muted);
}
.legend-item.route .legend-swatch {
background: var(--yellow);
}
.camera-tools {
display: flex;
gap: 5px;
pointer-events: auto;
}
.camera-tools button {
min-width: 38px;
height: 36px;
padding: 0 10px;
border: 1px solid rgba(24, 40, 37, 0.18);
background: rgba(251, 252, 247, 0.94);
color: var(--ink);
font-size: 12px;
font-weight: 800;
}
.camera-tools button:hover {
background: white;
}
.vehicle-label {
position: absolute;
z-index: 2;
min-width: 82px;
padding: 6px 8px;
border: 1px solid rgba(24, 40, 37, 0.18);
background: rgba(251, 252, 247, 0.94);
color: var(--ink);
font-size: 10px;
font-weight: 850;
line-height: 1.15;
text-align: center;
pointer-events: none;
transform: translate(-50%, -100%);
box-shadow: 3px 3px 0 rgba(24, 40, 37, 0.11);
}
.vehicle-label span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.rail {
display: grid;
gap: 14px;
}
.panel {
padding: 19px;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.panel-heading h2 {
margin: 3px 0 0;
font-size: 19px;
line-height: 1.15;
letter-spacing: -0.025em;
}
.lock-tag {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 6px 8px;
background: var(--green-light);
color: var(--green);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
white-space: nowrap;
}
.field-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
}
.select-wrap {
position: relative;
}
.select-wrap::after {
position: absolute;
top: 50%;
right: 13px;
content: "▾";
pointer-events: none;
transform: translateY(-50%);
}
select {
width: 100%;
height: 43px;
padding: 0 38px 0 12px;
appearance: none;
border: 1px solid #cbd4ca;
border-radius: 0;
background: white;
color: var(--ink);
font-weight: 750;
}
.mode-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px;
margin-top: 12px;
padding: 4px;
border: 1px solid var(--line);
background: #eef2eb;
}
.mode-button {
min-height: 34px;
border: 0;
background: transparent;
color: var(--muted);
font-size: 11px;
font-weight: 800;
}
.mode-button.active {
background: var(--ink);
color: white;
box-shadow: 2px 2px 0 rgba(24, 40, 37, 0.16);
}
.divider {
height: 1px;
margin: 17px 0;
background: var(--line);
}
.scenario + .scenario {
margin-top: 17px;
}
.scenario-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
}
.scenario-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
font-weight: 850;
}
.scenario-badge {
display: grid;
width: 24px;
height: 24px;
place-items: center;
color: white;
font-size: 10px;
}
.scenario-badge.a {
background: var(--green);
}
.scenario-badge.b {
background: var(--orange);
}
.scenario-value {
color: var(--muted);
font-size: 11px;
font-weight: 750;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
appearance: none;
background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 5px;
border-radius: 0;
background:
linear-gradient(
to right,
var(--range-color, var(--green)) 0 var(--fill, 30%),
#dce2d9 var(--fill, 30%) 100%
);
}
input[type="range"]::-moz-range-track {
height: 5px;
border-radius: 0;
background: #dce2d9;
}
input[type="range"]::-moz-range-progress {
height: 5px;
background: var(--range-color, var(--green));
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
margin-top: -5.5px;
appearance: none;
border: 2px solid var(--ink);
border-radius: 0;
background: white;
box-shadow: 2px 2px 0 rgba(24, 40, 37, 0.16);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 2px solid var(--ink);
border-radius: 0;
background: white;
}
.range-scale {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: #8a958f;
font-size: 9px;
font-weight: 750;
}
.parameter-block {
margin-top: 17px;
padding: 12px;
border: 1px solid #e2d5ae;
background: #fff8e6;
}
.parameter-block .field-label {
color: #6e5725;
}
.parameter-block .field-label output {
color: var(--ink);
font-size: 12px;
}
.parameter-note {
margin: 6px 0 0;
color: #7b6c47;
font-size: 10px;
line-height: 1.4;
}
.result-grid {
display: grid;
gap: 9px;
}
.result-row {
display: grid;
grid-template-columns: minmax(92px, 1fr) auto;
gap: 10px;
padding: 12px;
border: 1px solid var(--line);
background: white;
}
.result-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 800;
}
.result-dot {
width: 9px;
height: 9px;
}
.result-value {
text-align: right;
}
.result-value strong {
display: block;
font-size: 20px;
line-height: 1;
letter-spacing: -0.03em;
}
.result-value small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
}
.result-meter {
grid-column: 1 / -1;
height: 5px;
background: #e5e9e2;
}
.result-meter span {
display: block;
height: 100%;
transition: width 180ms ease;
}
.comparison-box {
margin-top: 11px;
padding: 12px;
border-left: 4px solid var(--green);
background: var(--green-light);
color: #315c58;
font-size: 11px;
line-height: 1.5;
}
.comparison-box strong {
display: block;
margin-bottom: 3px;
color: #214d49;
font-size: 11px;
}
.metric-pair {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.mini-metric {
padding: 10px;
border: 1px solid var(--line);
background: #f4f6f0;
}
.mini-metric small {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 750;
}
.mini-metric strong {
display: block;
margin-top: 4px;
font-size: 16px;
letter-spacing: -0.02em;
}
.good {
color: var(--green);
}
.higher {
color: var(--orange);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 5px;
}
.section-title h3 {
margin: 0;
font-size: 13px;
letter-spacing: -0.015em;
}
.model-tag {
padding: 5px 7px;
background: var(--orange-light);
color: #9a432b;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.section-subtitle {
margin: 0 0 12px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.chart-wrap {
border: 1px solid var(--line);
background: white;
}
.chart-wrap svg {
display: block;
width: 100%;
height: auto;
}
.sensitivity-facts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 9px;
}
.sensitivity-fact {
padding: 9px;
background: #f0f3ed;
}
.sensitivity-fact small {
display: block;
color: var(--muted);
font-size: 9px;
line-height: 1.3;
}
.sensitivity-fact strong {
display: block;
margin-top: 3px;
font-size: 12px;
}
details {
border-top: 1px solid var(--line);
}
details summary {
padding: 12px 0;
cursor: pointer;
font-size: 11px;
font-weight: 850;
}
details p,
details code {
font-size: 10px;
line-height: 1.55;
}
details code {
display: block;
overflow-x: auto;
padding: 9px;
background: #edf1ea;
color: #35524d;
white-space: normal;
}
.measurement-panel {
border-color: #d6cfc0;
background: #f7f5ef;
}
.measurement-panel .model-tag {
background: #e7e3d9;
color: #6d675b;
}
.measurement-list {
display: grid;
gap: 6px;
margin-top: 12px;
}
.measurement-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 8px 9px;
background: rgba(255, 255, 255, 0.72);
color: #514d46;
font-size: 10px;
}
.measurement-item span:last-child {
color: #8c5b45;
font-weight: 850;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.measurement-note {
margin: 12px 0 0;
padding: 11px;
border: 1px solid #dfd4c2;
background: #fffaf0;
color: #695d49;
font-size: 10px;
line-height: 1.55;
}
.footer {
display: flex;
justify-content: space-between;
gap: 24px;
margin-top: 17px;
padding: 0 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.footer strong {
color: var(--ink);
}
@media (max-width: 1050px) {
.layout {
grid-template-columns: 1fr;
}
.visual-card {
position: relative;
top: auto;
}
.stage {
height: 66vh;
min-height: 540px;
}
.rail {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.measurement-panel {
grid-column: 1 / -1;
}
}
@media (max-width: 680px) {
.app {
width: min(100% - 18px, 1580px);
padding-top: 12px;
}
.header {
align-items: flex-start;
}
.status-pill {
max-width: 150px;
font-size: 8px;
line-height: 1.4;
}
.stage {
height: 570px;
min-height: 570px;
}
.scene-header {
top: 16px;
left: 16px;
max-width: calc(100% - 32px);
}
.scene-header h1 {
max-width: 250px;
font-size: 31px;
}
.scene-header p {
max-width: 250px;
}
.route-badge {
top: auto;
right: 14px;
bottom: 70px;
min-width: 155px;
}
.scene-footer {
right: 14px;
bottom: 14px;
left: 14px;
}
.legend-panel {
max-width: 210px;
}
.rail {
grid-template-columns: 1fr;
}
.measurement-panel {
grid-column: auto;
}
.footer {
flex-direction: column;
gap: 8px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="header">
<div class="brand">
<div class="brand-mark" aria-hidden="true">▦</div>
<div>
<p class="brand-name">FLEET LAB / 04</p>
<p class="brand-subtitle">Controlled transport comparison</p>
</div>
</div>
<div class="status-pill">
<span class="status-dot" aria-hidden="true"></span>
Model output · field data not connected
</div>
</header>
<main class="layout">
<section class="card visual-card" aria-label="Voxel transport comparison scene">
<div class="stage" id="stage">
<div class="scene-header">
<span class="eyebrow">Same route / controlled payload</span>
<h1>Same streets.<br>Different payload.</h1>
<p>
Two scenarios share the same route, vehicle, and model assumptions.
Change only cargo utilization or passenger occupancy.
</p>
</div>
<div class="route-badge">
<small>Fixed route</small>
<strong id="sceneRouteName">Harbor Loop</strong>
<span id="sceneRouteStats">4.2 km · 8 stops · terrain ×1.00</span>
</div>
<div class="vehicle-label" id="labelA">
<b>A / REFERENCE</b>
<span id="labelAText">30% cargo</span>
</div>
<div class="vehicle-label" id="labelB">
<b>B / ALTERNATIVE</b>
<span id="labelBText">80% cargo</span>
</div>
<div class="scene-footer">
<div class="legend-panel" aria-label="Scene legend">
<div class="legend-item">
<span class="legend-swatch" style="background: var(--green)"></span>
A / Reference
</div>
<div class="legend-item">
<span class="legend-swatch" style="background: var(--orange)"></span>
B / Alternative
</div>
<div class="legend-item route">
<span class="legend-swatch"></span>
Fixed route
</div>
</div>
<div class="camera-tools" aria-label="Camera controls">
<button type="button" id="zoomIn" title="Zoom in">+</button>
<button type="button" id="zoomOut" title="Zoom out">−</button>
<button type="button" id="resetCamera" title="Reset camera">Reset</button>
<button type="button" id="topCamera" title="Top view">Top</button>
</div>
</div>
</div>
</section>
<aside class="rail">
<section class="card panel">
<div class="panel-heading">
<div>
<span class="eyebrow">Experiment controls</span>
<h2>Hold the route constant</h2>
</div>
<span class="lock-tag">▣ Route locked</span>
</div>
<label class="field-label" for="routeSelect">Route</label>
<div class="select-wrap">
<select id="routeSelect">
<option value="harbor">Harbor Loop</option>
<option value="market">Market Grid</option>
<option value="ridge">Ridge Circuit</option>
</select>
</div>
<div class="mode-switch" role="group" aria-label="Payload study type">
<button
class="mode-button active"
type="button"
data-mode="cargo"
aria-pressed="true"
>
Cargo load
</button>
<button
class="mode-button"
type="button"
data-mode="passenger"
aria-pressed="false"
>
Passenger occupancy
</button>
</div>
<div class="divider"></div>
<div class="scenario">
<div class="scenario-header">
<div class="scenario-name">
<span class="scenario-badge a">A</span>
Reference scenario
</div>
<output class="scenario-value" id="valueA">30%</output>
</div>
<input
id="scenarioA"
type="range"
min="0"
max="100"
step="1"
value="30"
aria-label="Scenario A cargo utilization"
>
<div class="range-scale">
<span>Empty</span>
<span id="capacityA">900 kg capacity</span>
<span>Full</span>
</div>
</div>
<div class="scenario">
<div class="scenario-header">
<div class="scenario-name">
<span class="scenario-badge b">B</span>
Alternative scenario
</div>
<output class="scenario-value" id="valueB">80%</output>
</div>
<input
id="scenarioB"
type="range"
min="0"
max="100"
step="1"
value="80"
aria-label="Scenario B cargo utilization"
>
<div class="range-scale">
<span>Empty</span>
<span id="capacityB">900 kg capacity</span>
<span>Full</span>
</div>
</div>
<div class="parameter-block">
<label class="field-label" for="gridFactor">
<span>Declared grid carbon factor</span>
<output id="gridValue">0.38 kg CO₂e/kWh</output>
</label>
<input
id="gridFactor"
type="range"
min="0.20"
max="0.60"
step="0.01"
value="0.38"
style="--range-color: var(--yellow)"
aria-label="Declared grid carbon factor"
>
<p class="parameter-note">
An explicit screening assumption, not a measured value. Change it to
expose the proxy’s dependence on electricity mix.
</p>
</div>
</section>
<section class="card panel" aria-live="polite">
<div class="section-title">
<h3>Declared proxy comparison</h3>
<span class="model-tag">Model output</span>
</div>
<p class="section-subtitle">
Total modeled trip emissions plus normalized intensity. The two answer
different operational questions.
</p>
<div class="result-grid">
<div class="result-row">
<div class="result-name">
<span class="result-dot" style="background: var(--green)"></span>
A / Reference
</div>
<div class="result-value">
<strong id="aCo2">—</strong>
<small>kg CO₂e / modeled trip</small>
</div>
<div class="result-meter">
<span id="aBar" style="width: 40%; background: var(--green)"></span>
</div>
</div>
<div class="result-row">
<div class="result-name">
<span class="result-dot" style="background: var(--orange)"></span>
B / Alternative
</div>
<div class="result-value">
<strong id="bCo2">—</strong>
<small>kg CO₂e / modeled trip</small>
</div>
<div class="result-meter">
<span id="bBar" style="width: 70%; background: var(--orange)"></span>
</div>
</div>
</div>
<div class="metric-pair">
<div class="mini-metric">
<small id="intensityLabelA">A / kg shipment</small>
<strong id="aIntensity">—</strong>
</div>
<div class="mini-metric">
<small id="intensityLabelB">B / kg shipment</small>
<strong id="bIntensity">—</strong>
</div>
</div>
<div class="comparison-box">
<strong>Controlled comparison</strong>
<span id="comparisonText">Calculating modeled outcomes…</span>
</div>
</section>
<section class="card panel">
<div class="section-title">
<h3>Proxy sensitivity</h3>
<span class="model-tag">Not uncertainty</span>
</div>
<p class="section-subtitle">
Response of the declared trip proxy to the controlled load variable.
All other assumptions remain fixed.
</p>
<div class="chart-wrap" id="sensitivityChart"></div>
<div class="sensitivity-facts">
<div class="sensitivity-fact">
<small id="sensitivityDeltaLabel">B, +10 load points</small>
<strong id="sensitivityDelta">—</strong>
</div>
<div class="sensitivity-fact">
<small>Local elasticity at B</small>
<strong id="sensitivityElasticity">—</strong>
</div>
</div>
<details>
<summary>Declared equation and assumptions</summary>
<p id="equationText"></p>
<code id="equationCode"></code>
<p>
Route length, stops, terrain multiplier, grid factor, and charge-loss
factor are explicit model inputs. The vehicle body, route, and other
assumptions are held constant across A and B.
</p>
</details>
</section>
<section class="card panel measurement-panel">
<div class="section-title">
<h3>Measured environmental impact</h3>
<span class="model-tag">Not connected</span>
</div>
<p class="section-subtitle">
This scene contains no live sensors or verified emissions observations.
</p>
<div class="measurement-list">
<div class="measurement-item">
<span>Route distance and stops</span>
<span>Model input</span>
</div>
<div class="measurement-item">
<span>Vehicle energy or fuel use</span>
<span>Modeled</span>
</div>
<div class="measurement-item">
<span>Cargo mass / passenger count</span>
<span>Scenario input</span>
</div>
<div class="measurement-item">
<span>Observed CO₂e emissions</span>
<span>Unavailable</span>
</div>
</div>
<div class="measurement-note">
<strong>Do not interpret the proxy as measured impact.</strong>
Field validation would require timestamped GPS traces, a calibrated
energy or fuel meter, verified payload logs, ambient conditions, and
an agreed emissions boundary.
</div>
</section>
</aside>
</main>
<footer class="footer">
<div>
<strong>Illustrative screening proxy.</strong>
Not a regulatory inventory, full lifecycle assessment, or claim of observed
emissions. Vehicle production, infrastructure, battery manufacture, and
local air pollutants are excluded.
</div>
<div>
Drag to orbit · Scroll to zoom · Arrow keys to move camera
</div>
</footer>
</div>
<noscript>This scene requires JavaScript.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* ------------------------------------------------------------------
Controlled experiment state
------------------------------------------------------------------ */
const ROUTES = {
harbor: {
name: "Harbor Loop",
distanceKm: 4.2,
stops: 8,
terrain: 1.0,
path: [
[-11, -6], [-4, -6], [-4, 1], [2, 1],
[2, 7], [10, 7], [10, -6], [-11, -6]
]
},
market: {
name: "Market Grid",
distanceKm: 6.8,
stops: 14,
terrain: 1.16,
path: [
[-11, -5], [-11, 2], [-3, 2], [-3, -5],
[4, -5], [4, 5], [10, 5], [10, -5], [-11, -5]
]
},
ridge: {
name: "Ridge Circuit",
distanceKm: 8.1,
stops: 10,
terrain: 1.38,
path: [
[-11, 6], [-3, 6], [-3, -4], [1, -4],
[1, 3], [8, 3], [8, -6], [11, -6], [11, 6], [-11, 6]
]
}
};
const state = {
route: "harbor",
mode: "cargo",
a: 30,
b: 80,
gridFactor: 0.38,
chargeFactor: 1.12
};
const COLORS = {
ink: 0x182825,
green: 0x267b78,
orange: 0xdf6843,
yellow: 0xe8b44d,
road: 0xb8c2bb,
ground: 0xdfe5da
};
const stage = document.getElementById("stage");
const routeSelect = document.getElementById("routeSelect");
const scenarioA = document.getElementById("scenarioA");
const scenarioB = document.getElementById("scenarioB");
const gridFactor = document.getElementById("gridFactor");
const modeButtons = [...document.querySelectorAll(".mode-button")];
/* ------------------------------------------------------------------
Model: explicit screening proxy, not measured impact
------------------------------------------------------------------ */
function calculate(loadPercent) {
const route = ROUTES[state.route];
const p = THREE.MathUtils.clamp(Number(loadPercent), 0, 100);
if (state.mode === "cargo") {
const capacityKg = 900;
const payloadKg = capacityKg * p / 100;
const energyKwh =
0.45 +
route.distanceKm *
(0.21 + route.terrain * 0.075 + payloadKg * 0.00013) +
route.stops * 0.10;
const co2 = energyKwh * state.gridFactor * state.chargeFactor;
const intensity = payloadKg > 0
? co2 / (payloadKg / 1000)
: null;
return {
p,
payloadKg,
people: null,
capacityKg,
energyKwh,
co2,
intensity,
intensityUnit: "kg CO₂e / kg shipment"
};
}
const capacity = 16;
const people = Math.round(capacity * p / 100);
const energyKwh =
0.65 +
route.distanceKm *
(0.42 + route.terrain * 0.10 + people * 0.008) +
route.stops * 0.10;
const co2 = energyKwh * state.gridFactor * state.chargeFactor;
const intensity = people > 0 ? co2 / people : null;
return {
p,
payloadKg: null,
people,
capacity,
energyKwh,
co2,
intensity,
intensityUnit: "kg CO₂e / passenger"
};
}
function signedPercent(value) {
const rounded = Math.abs(value) < 0.05 ? 0 : value;
return `${rounded > 0 ? "+" : ""}${rounded.toFixed(1)}%`;
}
function setRangeFill(input, color) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percent = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percent}%`);
input.style.setProperty("--range-color", color);
}
function updateEquation() {
const route = ROUTES[state.route];
if (state.mode === "cargo") {
document.getElementById("equationText").innerHTML =
`Cargo load is ${route.distanceKm} km × (0.21 + terrain × 0.075 + ` +
`payload kg × 0.00013), plus fixed auxiliary and stop energy. ` +
`Energy is multiplied by the declared grid factor and a 1.12 charge-loss factor.`;
document.getElementById("equationCode").textContent =
"CO₂e/trip = [0.45 + km × (0.21 + terrain × 0.075 + kg × 0.00013) " +
"+ stops × 0.10] × grid factor × 1.12";
} else {
document.getElementById("equationText").innerHTML =
`Passenger occupancy is ${route.distanceKm} km × (0.42 + terrain × 0.10 + ` +
`people × 0.008), plus fixed auxiliary and stop energy. ` +
`Energy is multiplied by the declared grid factor and a 1.12 charge-loss factor.`;
document.getElementById("equationCode").textContent =
"CO₂e/trip = [0.65 + km × (0.42 + terrain × 0.10 + people × 0.008) " +
"+ stops × 0.10] × grid factor × 1.12";
}
}
function updateSensitivityChart() {
const values = [];
for (let p = 0; p <= 100; p += 2) {
values.push({ p, value: calculate(p).co2 });
}
const width = 360;
const height = 170;
const margin = { left: 42, right: 14, top: 16, bottom: 30 };
const innerW = width - margin.left - margin.right;
const innerH = height - margin.top - margin.bottom;
const rawMin = Math.min(...values.map(v => v.value));
const rawMax = Math.max(...values.map(v => v.value));
const padding = Math.max((rawMax - rawMin) * 0.18, 0.04);
const min = Math.max(0, rawMin - padding);
const max = rawMax + padding;
const x = p => margin.left + (p / 100) * innerW;
const y = value =>
margin.top + innerH - ((value - min) / (max - min || 1)) * innerH;
const line = values
.map((v, i) => `${i === 0 ? "M" : "L"}${x(v.p).toFixed(2)},${y(v.value).toFixed(2)}`)
.join(" ");
const area =
`${line} L${x(100)},${margin.top + innerH} L${x(0)},${margin.top + innerH} Z`;
const grid = [0, 0.5, 1].map(fraction => {
const yy = margin.top + innerH - fraction * innerH;
const value = min + fraction * (max - min);
return `
<line x1="${margin.left}" y1="${yy}" x2="${width - margin.right}"
y2="${yy}" stroke="#dfe4dc" stroke-width="1"/>
<text x="${margin.left - 7}" y="${yy + 3}" text-anchor="end"
fill="#7a8580" font-size="8">${value.toFixed(2)}</text>
`;
}).join("");
const marker = (p, color, label) => `
<line x1="${x(p)}" y1="${margin.top}" x2="${x(p)}"
y2="${margin.top + innerH}" stroke="${color}"
stroke-width="1.5" stroke-dasharray="3 3"/>
<text x="${x(p)}" y="${margin.top - 4}" text-anchor="middle"
fill="${color}" font-size="8" font-weight="700">${label}</text>
`;
const chart = `
<svg viewBox="0 0 ${width} ${height}" role="img"
aria-label="Modeled trip emissions proxy across the controlled load range">
<rect x="${margin.left}" y="${margin.top}" width="${innerW}"
height="${innerH}" fill="#fbfcf8"/>
${grid}
<path d="${area}" fill="#d9ece7" opacity="0.7"/>
<path d="${line}" fill="none" stroke="#267b78" stroke-width="2.5"/>
${marker(state.a, "#267b78", "A")}
${marker(state.b, "#df6843", "B")}
<line x1="${margin.left}" y1="${margin.top + innerH}"
x2="${width - margin.right}" y2="${margin.top + innerH}"
stroke="#9aa59f"/>
<text x="${margin.left}" y="${height - 10}"
fill="#7a8580" font-size="8">0%</text>
<text x="${x(50)}" y="${height - 10}" text-anchor="middle"
fill="#7a8580" font-size="8">50%</text>
<text x="${x(100)}" y="${height - 10}" text-anchor="end"
fill="#7a8580" font-size="8">100%</text>
<text x="${margin.left + innerW / 2}" y="${height - 1}"
text-anchor="middle" fill="#52615c" font-size="8"
font-weight="700">${state.mode === "cargo" ? "CARGO UTILIZATION" : "SEAT OCCUPANCY"}</text>
<text x="9" y="${margin.top + innerH / 2}" text-anchor="middle"
fill="#52615c" font-size="8" font-weight="700"
transform="rotate(-90 9 ${margin.top + innerH / 2})">
KG CO₂E / TRIP
</text>
</svg>
`;
document.getElementById("sensitivityChart").innerHTML = chart;
}
function updateUI() {
const route = ROUTES[state.route];
const a = calculate(state.a);
const b = calculate(state.b);
setRangeFill(scenarioA, COLORS_HEX.green);
setRangeFill(scenarioB, COLORS_HEX.orange);
setRangeFill(gridFactor, COLORS_HEX.yellow);
const modeName = state.mode === "cargo" ? "cargo" : "occupancy";
document.getElementById("valueA").textContent = `${state.a}%`;
document.getElementById("valueB").textContent = `${state.b}%`;
document.getElementById("labelAText").textContent = `${state.a}% ${modeName}`;
document.getElementById("labelBText").textContent = `${state.b}% ${modeName}`;
scenarioA.setAttribute(
"aria-label",
`Scenario A ${state.mode === "cargo" ? "cargo utilization" : "passenger occupancy"}`
);
scenarioB.setAttribute(
"aria-label",
`Scenario B ${state.mode === "cargo" ? "cargo utilization" : "passenger occupancy"}`
);
if (state.mode === "cargo") {
document.getElementById("capacityA").textContent = "900 kg capacity";
document.getElementById("capacityB").textContent = "900 kg capacity";
document.getElementById("intensityLabelA").textContent = "A / kg shipment";
document.getElementById("intensityLabelB").textContent = "B / kg shipment";
} else {
document.getElementById("capacityA").textContent = "16 seat capacity";
document.getElementById("capacityB").textContent = "16 seat capacity";
document.getElementById("intensityLabelA").textContent = "A / passenger";
document.getElementById("intensityLabelB").textContent = "B / passenger";
}
document.getElementById("sceneRouteName").textContent = route.name;
document.getElementById("sceneRouteStats").textContent =
`${route.distanceKm.toFixed(1)} km · ${route.stops} stops · terrain ×${route.terrain.toFixed(2)}`;
document.getElementById("gridValue").textContent =
`${state.gridFactor.toFixed(2)} kg CO₂e/kWh`;
document.getElementById("aCo2").textContent = a.co2.toFixed(2);
document.getElementById("bCo2").textContent = b.co2.toFixed(2);
document.getElementById("aIntensity").textContent =
a.intensity === null ? "—" : `${a.intensity.toFixed(2)}`;
document.getElementById("bIntensity").textContent =
b.intensity === null ? "—" : `${b.intensity.toFixed(2)}`;
const maxTrip = Math.max(a.co2, b.co2, 0.001);
document.getElementById("aBar").style.width = `${Math.max(4, a.co2 / maxTrip * 100)}%`;
document.getElementById("bBar").style.width = `${Math.max(4, b.co2 / maxTrip * 100)}%`;
const tripDelta = b.co2 - a.co2;
const tripDeltaPercent = a.co2 > 0 ? tripDelta / a.co2 * 100 : 0;
let summary;
if (state.mode === "cargo") {
const payloadDelta = b.payloadKg - a.payloadKg;
const intensityDelta =
a.intensity !== null && b.intensity !== null
? (b.intensity - a.intensity) / a.intensity * 100
: null;
const winner =
intensityDelta === null
? "Normalized comparison requires cargo in at least one scenario."
: intensityDelta < 0
? "Scenario B has the lower normalized proxy."
: "Scenario A has the lower normalized proxy.";
summary =
`${winner} B changes modeled trip proxy by ${signedPercent(tripDeltaPercent)} ` +
`and carries ${payloadDelta >= 0 ? "+" : ""}${payloadDelta.toFixed(0)} kg. ` +
(intensityDelta === null
? ""
: `Normalized proxy changes by ${signedPercent(intensityDelta)}.`);
} else {
const peopleDelta = b.people - a.people;
const intensityDelta =
a.intensity !== null && b.intensity !== null
? (b.intensity - a.intensity) / a.intensity * 100
: null;
const winner =
intensityDelta === null
? "Normalized comparison requires passengers in at least one scenario."
: intensityDelta < 0
? "Scenario B has the lower per-passenger proxy."
: "Scenario A has the lower per-passenger proxy.";
summary =
`${winner} B changes modeled trip proxy by ${signedPercent(tripDeltaPercent)} ` +
`and carries ${peopleDelta >= 0 ? "+" : ""}${peopleDelta} passengers. ` +
(intensityDelta === null
? ""
: `Per-passenger proxy changes by ${signedPercent(intensityDelta)}.`);
}
document.getElementById("comparisonText").textContent = summary;
const direction = state.b <= 90 ? 10 : -10;
const shifted = calculate(THREE.MathUtils.clamp(state.b + direction, 0, 100));
const sensitivityPercent = b.co2 > 0
? (shifted.co2 - b.co2) / b.co2 * 100
: 0;
const lower = calculate(THREE.MathUtils.clamp(state.b - 1, 0, 100));
const upper = calculate(THREE.MathUtils.clamp(state.b + 1, 0, 100));
const elasticity = b.co2 > 0
? (upper.co2 - lower.co2) / (2 * b.co2)
: 0;
document.getElementById("sensitivityDeltaLabel").textContent =
`B, ${direction > 0 ? "+" : "−"}10 ${state.mode === "cargo" ? "load" : "occupancy"} points`;
document.getElementById("sensitivityDelta").textContent =
`${signedPercent(sensitivityPercent)} trip proxy`;
document.getElementById("sensitivityElasticity").textContent =
elasticity.toFixed(3);
updateSensitivityChart();
updateEquation();
updateVehicleLoads();
}
const COLORS_HEX = {
green: "#267b78",
orange: "#df6843",
yellow: "#e8b44d"
};
/* ------------------------------------------------------------------
Three.js scene
------------------------------------------------------------------ */
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7ece2);
scene.fog = new THREE.Fog(0xe7ece2, 28, 48);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.domElement.className = "webgl";
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel city showing two vehicles on the same fixed route"
);
stage.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf7fff4, 0x748278, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4d7, 3.2);
sun.position.set(-9, 16, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -19;
sun.shadow.camera.right = 19;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const cityGroup = new THREE.Group();
const routeGroup = new THREE.Group();
const vehicleGroup = new THREE.Group();
scene.add(cityGroup, routeGroup, vehicleGroup);
const vehicleA = new THREE.Group();
const vehicleB = new THREE.Group();
vehicleGroup.add(vehicleA, vehicleB);
const vehicleObjects = {
a: { group: vehicleA, loadMeshes: [] },
b: { group: vehicleB, loadMeshes: [] }
};
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach(material => material.dispose());
}
});
group.remove(child);
}
}
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
});
}
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function distanceToSegment(px, pz, ax, az, bx, bz) {
const dx = bx - ax;
const dz = bz - az;
const lengthSquared = dx * dx + dz * dz;
if (lengthSquared === 0) {
return Math.hypot(px - ax, pz - az);
}
const t = THREE.MathUtils.clamp(
((px - ax) * dx + (pz - az) * dz) / lengthSquared,
0,
1
);
return Math.hypot(px - (ax + t * dx), pz - (az + t * dz));
}
function nearRoute(x, z, path, clearance) {
for (let i = 0; i < path.length - 1; i++) {
const a = path[i];
const b = path[i + 1];
if (
distanceToSegment(x, z, a[0], a[1], b[0], b[1]) <
clearance
) {
return true;
}
}
return false;
}
function createCity() {
clearGroup(cityGroup);
clearGroup(routeGroup);
const route = ROUTES[state.route];
const ground = addBox(
cityGroup,
[30, 0.38, 24],
[0, -0.24, 0],
standardMaterial(COLORS.ground),
false
);
ground.receiveShadow = true;
const roadMaterial = standardMaterial(COLORS.road);
const roadEdgeMaterial = standardMaterial(0xcbd2ca);
for (let i = 0; i < route.path.length - 1; i++) {
const a = route.path[i];
const b = route.path[i + 1];
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
const angle = -Math.atan2(dz, dx);
const road = addBox(
routeGroup,
[length + 0.08, 0.08, 1.72],
[(a[0] + b[0]) / 2, 0.03, (a[1] + b[1]) / 2],
roadMaterial,
false
);
road.rotation.y = angle;
road.receiveShadow = true;
const edgeA = addBox(
routeGroup,
[length, 0.035, 0.06],
[(a[0] + b[0]) / 2, 0.09, (a[1] + b[1]) / 2],
roadEdgeMaterial,
false
);
edgeA.rotation.y = angle;
}
const dashMaterial = standardMaterial(COLORS.yellow);
for (let i = 0; i < route.path.length - 1; i++) {
const a = route.path[i];
const b = route.path[i + 1];
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
const angle = -Math.atan2(dz, dx);
const count = Math.max(1, Math.floor(length / 0.7));
for (let j = 0; j < count; j++) {
const t = (j + 0.5) / count;
const dash = addBox(
routeGroup,
[0.25, 0.045, 0.11],
[a[0] + dx * t, 0.115, a[1] + dz * t],
dashMaterial,
false
);
dash.rotation.y = angle;
}
}
for (const point of route.path.slice(0, -1)) {
addBox(
routeGroup,
[0.42, 0.16, 0.42],
[point[0], 0.12, point[1]],
standardMaterial(0xf3d988),
false
);
}
const depotMaterial = standardMaterial(0x526c67);
const depot = new THREE.Group();
depot.position.set(route.path[0][0], 0, route.path[0][1]);
addBox(depot, [1.3, 0.65, 1.1], [0, 0.38, 0], depotMaterial);
addBox(
depot,
[1.45, 0.16, 1.25],
[0, 0.78, 0],
standardMaterial(COLORS.yellow)
);
routeGroup.add(depot);
const buildingPalette = [
0xc7d8d1, 0xd7d9c6, 0xe3cbb9, 0xb9cbd4,
0xd8d5c0, 0xbfd4cc, 0xe0d4c1, 0xc5cfda
];
const roofPalette = [
0x6f8882, 0x9a806d, 0x66809a, 0x7c8d72
];
const windowMaterial = standardMaterial(0x5d7475, {
roughness: 0.42,
metalness: 0.12
});
let seed = 731;
const random = () => {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
};
const buildings = [];
let attempts = 0;
while (buildings.length < 43 && attempts < 600) {
attempts++;
const x = -13.4 + random() * 26.8;
const z = -10.7 + random() * 21.4;
if (nearRoute(x, z, route.path, 2.45)) continue;
let overlaps = false;
for (const other of buildings) {
if (Math.hypot(x - other.x, z - other.z) < 1.65) {
overlaps = true;
break;
}
}
if (overlaps) continue;
buildings.push({ x, z });
const width = 0.75 + random() * 1.15;
const depth = 0.75 + random() * 1.15;
const height = 0.65 + random() * 3.4;
const paletteIndex = Math.floor(random() * buildingPalette.length);
const body = addBox(
cityGroup,
[width, height, depth],
[x, height / 2, z],
standardMaterial(buildingPalette[paletteIndex])
);
body.receiveShadow = true;
addBox(
cityGroup,
[width + 0.08, 0.14, depth + 0.08],
[x, height + 0.07, z],
standardMaterial(roofPalette[paletteIndex])
);
if (height > 1.2) {
addBox(
cityGroup,
[width * 0.68, 0.16, 0.025],
[x, height * 0.58, z + depth / 2 + 0.012],
windowMaterial,
false
);
addBox(
cityGroup,
[0.025, 0.16, depth * 0.68],
[x + width / 2 + 0.012, height * 0.58, z],
windowMaterial,
false
);
}
}
const trunkMaterial = standardMaterial(0x745941);
const leafMaterials = [
standardMaterial(0x7da16d),
standardMaterial(0x628e67),
standardMaterial(0x91aa71)
];
for (let i = 0; i < 18; i++) {
const x = -13 + random() * 26;
const z = -10.5 + random() * 21;
if (nearRoute(x, z, route.path, 2.05)) continue;
addBox(cityGroup, [0.16, 0.65, 0.16], [x, 0.32, z], trunkMaterial);
addBox(
cityGroup,
[0.72, 0.72, 0.72],
[x, 0.95, z],
leafMaterials[i % leafMaterials.length]
);
addBox(
cityGroup,
[0.48, 0.42, 0.48],
[x + 0.12, 1.4, z - 0.08],
leafMaterials[(i + 1) % leafMaterials.length]
);
}
}
function createCargoVehicle(color) {
const group = new THREE.Group();
const accent = standardMaterial(color);
const cream = standardMaterial(0xece9d9);
const dark = standardMaterial(0x26312f);
const glass = standardMaterial(0x5d7f87, {
roughness: 0.35,
metalness: 0.1
});
addBox(group, [2.55, 0.18, 1.02], [0, 0.35, 0], dark);
addBox(group, [1.42, 0.12, 0.92], [-0.43, 0.52, 0], accent);
addBox(group, [1.45, 0.28, 0.08], [-0.43, 0.69, 0.47], accent);
addBox(group, [1.45, 0.28, 0.08], [-0.43, 0.69, -0.47], accent);
addBox(group, [0.08, 0.32, 0.92], [-1.15, 0.69, 0], accent);
addBox(group, [0.82, 0.78, 0.94], [0.78, 0.88, 0], accent);
addBox(group, [0.82, 0.18, 1.0], [0.78, 1.31, 0], cream);
addBox(group, [0.045, 0.34, 0.72], [1.205, 1.0, 0], glass);
addBox(group, [0.47, 0.32, 0.025], [0.79, 1.02, 0.485], glass);
for (const x of [-0.82, 0.84]) {
for (const z of [-0.55, 0.55]) {
addBox(group, [0.38, 0.38, 0.18], [x, 0.35, z], dark);
}
}
const parcelMaterials = [
standardMaterial(0xd7a85d),
standardMaterial(0xb77b52),
standardMaterial(0xc7b47c),
standardMaterial(0x799b8d)
];
const loadMeshes = [];
const positions = [];
for (const z of [-0.24, 0.24]) {
for (let col = 0; col < 4; col++) {
positions.push([-0.99 + col * 0.31, 0.69, z]);
}
}
for (let col = 0; col < 4; col++) {
positions.push([-0.99 + col * 0.31, 0.89, 0]);
}
positions.forEach((position, index) => {
const parcel = addBox(
group,
[0.27, 0.18, 0.39],
position,
parcelMaterials[index % parcelMaterials.length]
);
loadMeshes.push(parcel);
});
return { group, loadMeshes };
}
function createPassengerVehicle(color) {
const group = new THREE.Group();
const accent = standardMaterial(color);
const dark = standardMaterial(0x26312f);
const cream = standardMaterial(0xece9d9);
const glass = standardMaterial(0x6f9398, {
transparent: true,
opacity: 0.55,
depthWrite: false,
roughness: 0.25
});
addBox(group, [2.65, 0.18, 1.05], [0, 0.34, 0], dark);
addBox(group, [2.55, 0.42, 1.02], [0, 0.64, 0], accent);
addBox(group, [2.48, 0.15, 1.02], [0, 1.28, 0], cream);
for (let i = 0; i < 8; i++) {
const x = -1.05 + i * 0.30;
addBox(group, [0.25, 0.42, 0.035], [x, 0.98, 0.525], glass, false);
addBox(group, [0.25, 0.42, 0.035], [x, 0.98, -0.525], glass, false);
}
addBox(group, [0.045, 0.42, 0.78], [1.27, 0.98, 0], glass, false);
for (const x of [-0.84, 0.84]) {
for (const z of [-0.56, 0.56]) {
addBox(group, [0.38, 0.38, 0.18], [x, 0.35, z], dark);
}
}
const loadMeshes = [];
const personColors = [
0xe7b858, 0xd66e50, 0x4f8d88, 0x6d7fa2,
0xb68a62, 0x8a9d70
];
for (let i = 0; i < 16; i++) {
const x = -1.04 + Math.floor(i / 2) * 0.285;
const z = i % 2 === 0 ? 0.32 : -0.32;
const person = new THREE.Group();
person.position.set(x, 0.74, z);
addBox(
person,
[0.13, 0.23, 0.13],
[0, 0.11, 0],
standardMaterial(personColors[i % personColors.length])
);
addBox(
person,
[0.14, 0.14, 0.14],
[0, 0.30, 0],
standardMaterial(0xd9b68f)
);
group.add(person);
loadMeshes.push(person);
}
return { group, loadMeshes };
}
function createVehicles() {
clearGroup(vehicleGroup);
vehicleGroup.add(vehicleA, vehicleB);
const a =
state.mode === "cargo"
? createCargoVehicle(COLORS.green)
: createPassengerVehicle(COLORS.green);
const b =
state.mode === "cargo"
? createCargoVehicle(COLORS.orange)
: createPassengerVehicle(COLORS.orange);
vehicleObjects.a.group = a.group;
vehicleObjects.a.loadMeshes = a.loadMeshes;
vehicleObjects.b.group = b.group;
vehicleObjects.b.loadMeshes = b.loadMeshes;
vehicleGroup.add(a.group, b.group);
updateVehicleLoads();
}
function updateVehicleLoads() {
const countA =
state.mode === "cargo"
? Math.round(state.a / 100 * 12)
: calculate(state.a).people;
const countB =
state.mode === "cargo"
? Math.round(state.b / 100 * 12)
: calculate(state.b).people;
vehicleObjects.a.loadMeshes.forEach((mesh, index) => {
mesh.visible = index < countA;
});
vehicleObjects.b.loadMeshes.forEach((mesh, index) => {
mesh.visible = index < countB;
});
}
function sampleRoute(t, lateralOffset) {
const path = ROUTES[state.route].path;
const segmentLengths = [];
let totalLength = 0;
for (let i = 0; i < path.length - 1; i++) {
const length = Math.hypot(
path[i + 1][0] - path[i][0],
path[i + 1][1] - path[i][1]
);
segmentLengths.push(length);
totalLength += length;
}
let distance = ((t % 1) + 1) % 1 * totalLength;
for (let i = 0; i < segmentLengths.length; i++) {
if (distance <= segmentLengths[i] || i === segmentLengths.length - 1) {
const a = path[i];
const b = path[i + 1];
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = segmentLengths[i];
const local = length > 0 ? distance / length : 0;
const x = a[0] + dx * local;
const z = a[1] + dz * local;
const nx = -dz / length;
const nz = dx / length;
return {
x: x + nx * lateralOffset,
z: z + nz * lateralOffset,
rotation: -Math.atan2(dz, dx)
};
}
distance -= segmentLengths[i];
}
return { x: path[0][0], z: path[0][1], rotation: 0 };
}
function updateVehiclePositions(timeSeconds) {
const speed = 0.032;
const tA = (timeSeconds * speed + 0.08) % 1;
const tB = (timeSeconds * speed + 0.57) % 1;
const pa = sampleRoute(tA, -0.43);
const pb = sampleRoute(tB, 0.43);
vehicleObjects.a.group.position.set(pa.x, 0.12, pa.z);
vehicleObjects.a.group.rotation.y = pa.rotation;
vehicleObjects.b.group.position.set(pb.x, 0.12, pb.z);
vehicleObjects.b.group.rotation.y = pb.rotation;
}
/* ------------------------------------------------------------------
Direct camera controls: no addons
------------------------------------------------------------------ */
const cameraState = {
target: new THREE.Vector3(0, 0.7, 0),
theta: 0.73,
phi: 1.02,
radius: 22
};
function updateCamera() {
const { target, theta, phi, radius } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.target.set(0, 0.7, 0);
cameraState.theta = 0.73;
cameraState.phi = 1.02;
cameraState.radius = 22;
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
cameraState.theta -= dx * 0.008;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.006,
0.22,
1.38
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
12,
34
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.08;
break;
case "ArrowRight":
cameraState.theta -= 0.08;
break;
case "ArrowUp":
cameraState.phi = Math.max(0.22, cameraState.phi - 0.06);
break;
case "ArrowDown":
cameraState.phi = Math.min(1.38, cameraState.phi + 0.06);
break;
case "+":
case "=":
cameraState.radius = Math.max(12, cameraState.radius - 1);
break;
case "-":
cameraState.radius = Math.min(34, cameraState.radius + 1);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("zoomIn").addEventListener("click", () => {
cameraState.radius = Math.max(12, cameraState.radius - 1.5);
updateCamera();
});
document.getElementById("zoomOut").addEventListener("click", () => {
cameraState.radius = Math.min(34, cameraState.radius + 1.5);
updateCamera();
});
document.getElementById("resetCamera").addEventListener("click", resetCamera);
document.getElementById("topCamera").addEventListener("click", () => {
cameraState.phi = 0.22;
cameraState.theta = 0;
cameraState.radius = 24;
updateCamera();
});
/* ------------------------------------------------------------------
Interaction and initial state
------------------------------------------------------------------ */
routeSelect.addEventListener("change", () => {
state.route = routeSelect.value;
createCity();
updateUI();
});
scenarioA.addEventListener("input", () => {
state.a = Number(scenarioA.value);
updateUI();
});
scenarioB.addEventListener("input", () => {
state.b = Number(scenarioB.value);
updateUI();
});
gridFactor.addEventListener("input", () => {
state.gridFactor = Number(gridFactor.value);
updateUI();
});
modeButtons.forEach(button => {
button.addEventListener("click", () => {
state.mode = button.dataset.mode;
modeButtons.forEach(item => {
const active = item === button;
item.classList.toggle("active", active);
item.setAttribute("aria-pressed", String(active));
});
createVehicles();
updateUI();
});
});
const resizeObserver = new ResizeObserver(() => {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
});
resizeObserver.observe(stage);
function updateOverlayLabel(element, object) {
const position = new THREE.Vector3();
object.getWorldPosition(position);
position.y += state.mode === "cargo" ? 1.85 : 1.65;
position.project(camera);
const visible = position.z > -1 && position.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (position.x * 0.5 + 0.5) * stage.clientWidth;
const y = (-position.y * 0.5 + 0.5) * stage.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
createCity();
createVehicles();
updateCamera();
updateUI();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateVehiclePositions(elapsed);
updateOverlayLabel(
document.getElementById("labelA"),
vehicleObjects.a.group
);
updateOverlayLabel(
document.getElementById("labelB"),
vehicleObjects.b.group
);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```