Prompt specification
Build or customize the Three.js 3D scene "Route Cards With Time and Fuel Blocks" 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: Route Cards With Time and Fuel Blocks
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/route-cards-with-time-and-fuel-blocks-x3549
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing tradeoffs between route objectives. Display three route options with separate time and fuel token stacks. Show a case where no option is best on both dimensions simultaneously. Stylized solid forms.
Working Three.js Starter (route-cards-with-time-and-fuel-blocks-x3549):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Route Lab — Trade-off Explorer</title>
<style>
:root {
--ink: #17241f;
--muted: #64716b;
--paper: #f7f8f4;
--panel: rgba(255, 255, 252, 0.94);
--line: #d8ded8;
--route-a: #ed6758;
--route-b: #705bd8;
--route-c: #15967f;
--time: #efb13f;
--fuel: #3b9fbd;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
position: relative;
color: var(--ink);
background:
radial-gradient(circle at 72% 20%, rgba(255, 255, 255, 0.9), transparent 34%),
#e9ede7;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
header {
position: absolute;
z-index: 10;
top: 0;
left: 0;
right: 0;
height: 118px;
padding: 24px 28px 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
}
.heading {
max-width: 760px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: #52625b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow-mark {
width: 11px;
height: 11px;
border-radius: 3px;
background: var(--ink);
box-shadow: 15px 0 0 var(--time), 30px 0 0 var(--fuel);
margin-right: 30px;
}
h1 {
margin: 0;
font-size: clamp(28px, 3.1vw, 48px);
line-height: 1;
letter-spacing: -0.045em;
font-weight: 780;
}
h1 span {
color: #7b857f;
font-weight: 480;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 14px;
}
.controls {
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid #ccd4ce;
border-radius: 999px;
padding: 10px 15px;
color: var(--ink);
background: rgba(255, 255, 252, 0.8);
box-shadow: 0 3px 10px rgba(35, 50, 43, 0.05);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: #98a59e;
background: white;
}
button.active {
color: white;
background: var(--ink);
border-color: var(--ink);
}
#stage {
position: absolute;
top: 106px;
left: 0;
right: 0;
bottom: 174px;
overflow: hidden;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#stage canvas:active {
cursor: grabbing;
}
.stage-note {
position: absolute;
z-index: 3;
top: 12px;
left: 50%;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 9px;
padding: 9px 14px;
border: 1px solid rgba(119, 132, 124, 0.22);
border-radius: 999px;
color: #516059;
background: rgba(255, 255, 252, 0.76);
box-shadow: 0 8px 30px rgba(38, 52, 45, 0.06);
backdrop-filter: blur(10px);
pointer-events: none;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
white-space: nowrap;
}
.stage-note::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--route-a);
box-shadow: 9px 0 0 var(--route-c);
margin-right: 9px;
}
.legend {
position: absolute;
z-index: 3;
left: 22px;
bottom: 10px;
display: flex;
align-items: center;
gap: 18px;
padding: 10px 13px;
border: 1px solid rgba(119, 132, 124, 0.18);
border-radius: 12px;
background: rgba(255, 255, 252, 0.8);
color: #59665f;
backdrop-filter: blur(10px);
pointer-events: none;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.token-key {
width: 13px;
height: 13px;
border-radius: 4px;
box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.08);
}
.token-key.time {
background: var(--time);
}
.token-key.fuel {
background: var(--fuel);
}
.comparison {
position: absolute;
z-index: 10;
left: 20px;
right: 20px;
bottom: 18px;
min-height: 136px;
display: grid;
grid-template-columns: 250px repeat(3, minmax(0, 1fr));
overflow: hidden;
border: 1px solid rgba(197, 207, 200, 0.95);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 45px rgba(42, 57, 49, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.9);
backdrop-filter: blur(16px);
}
.compare-intro {
padding: 20px 22px;
border-right: 1px solid var(--line);
background: #f1f3ee;
}
.compare-kicker {
color: #77827c;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.compare-intro h2 {
margin: 6px 0 5px;
font-size: 20px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.compare-intro p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.route-card {
position: relative;
min-width: 0;
padding: 15px 17px 14px;
border-right: 1px solid var(--line);
}
.route-card:last-child {
border-right: 0;
}
.route-card::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
height: 4px;
background: var(--route);
}
.card-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.route-name {
display: flex;
align-items: baseline;
gap: 8px;
min-width: 0;
}
.route-letter {
color: var(--route);
font-size: 22px;
font-weight: 850;
line-height: 1;
}
.route-label {
overflow: hidden;
color: #26332d;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-overflow: ellipsis;
white-space: nowrap;
}
.badge {
flex: none;
padding: 5px 7px;
border-radius: 999px;
color: #6a756f;
background: #edf0eb;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.badge.time-winner {
color: #85530c;
background: #fff0d3;
}
.badge.fuel-winner {
color: #17677a;
background: #dff3f8;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 12px;
}
.metric {
min-width: 0;
padding: 9px 10px;
border: 1px solid #e1e5e0;
border-radius: 10px;
background: rgba(248, 249, 246, 0.92);
}
.metric-label {
display: flex;
align-items: center;
gap: 6px;
margin-bottom: 3px;
color: #77817c;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.11em;
}
.metric-dot {
width: 8px;
height: 8px;
border-radius: 3px;
}
.metric-dot.time {
background: var(--time);
}
.metric-dot.fuel {
background: var(--fuel);
}
.metric-value {
color: #1d2b25;
font-size: 21px;
font-weight: 790;
letter-spacing: -0.04em;
}
.metric-value small {
margin-left: 3px;
color: #7b8680;
font-size: 9px;
font-weight: 800;
letter-spacing: 0;
}
#loading {
position: absolute;
z-index: 5;
inset: 0;
display: grid;
place-items: center;
color: #66736c;
background: #e9ede7;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.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: 900px) {
header {
height: 126px;
padding: 19px 20px;
}
.controls {
flex-direction: column;
}
button {
padding: 8px 12px;
}
#stage {
top: 112px;
bottom: 195px;
}
.comparison {
left: 10px;
right: 10px;
bottom: 10px;
display: flex;
overflow-x: auto;
min-height: 175px;
}
.compare-intro,
.route-card {
flex: 0 0 220px;
}
.route-card {
flex-basis: 235px;
}
.stage-note {
top: 5px;
}
}
@media (max-width: 600px) {
header {
height: 140px;
}
h1 {
font-size: 31px;
}
.subtitle {
max-width: 260px;
font-size: 12px;
}
.controls {
position: absolute;
right: 16px;
top: 18px;
}
.controls button {
font-size: 10px;
}
#stage {
top: 126px;
bottom: 190px;
}
.stage-note {
display: none;
}
.legend {
left: 10px;
gap: 10px;
font-size: 8px;
}
.comparison {
min-height: 170px;
}
}
</style>
</head>
<body>
<header>
<div class="heading">
<div class="eyebrow">
<span class="eyebrow-mark" aria-hidden="true"></span>
Route Lab · Multi-objective planning
</div>
<h1>Three routes. <span>No single winner.</span></h1>
<p class="subtitle">A faster path can consume more fuel. Compare the trade-off.</p>
</div>
<div class="controls" aria-label="Scene controls">
<button id="spin" type="button" aria-pressed="false">Auto orbit</button>
<button id="reset" type="button">Reset view</button>
</div>
</header>
<main id="stage" aria-label="Interactive three-dimensional route comparison">
<div class="stage-note">NO DOMINANT ROUTE</div>
<div class="legend" aria-label="Token legend">
<div class="legend-item">
<span class="token-key time" aria-hidden="true"></span>
<span>1 disk = 10 min</span>
</div>
<div class="legend-item">
<span class="token-key fuel" aria-hidden="true"></span>
<span>1 disk = 4 L</span>
</div>
<div class="legend-item">Fewer is better</div>
</div>
<div id="loading">Building route lab…</div>
</main>
<section class="comparison" aria-label="Route comparison">
<div class="compare-intro">
<div class="compare-kicker">The trade-off</div>
<h2>Fast ≠ efficient.</h2>
<p>
A leads on time. C leads on fuel. B is the middle-ground compromise.
No route wins both objectives.
</p>
</div>
<article class="route-card" style="--route: var(--route-a)">
<div class="card-top">
<div class="route-name">
<span class="route-letter">A</span>
<span class="route-label">EXPRESS</span>
</div>
<span class="badge time-winner">Time leader</span>
</div>
<div class="metrics">
<div class="metric">
<div class="metric-label">
<span class="metric-dot time"></span>TIME
</div>
<div class="metric-value">30<small>MIN</small></div>
</div>
<div class="metric">
<div class="metric-label">
<span class="metric-dot fuel"></span>FUEL
</div>
<div class="metric-value">32<small>L</small></div>
</div>
</div>
</article>
<article class="route-card" style="--route: var(--route-b)">
<div class="card-top">
<div class="route-name">
<span class="route-letter">B</span>
<span class="route-label">BALANCED</span>
</div>
<span class="badge">Middle ground</span>
</div>
<div class="metrics">
<div class="metric">
<div class="metric-label">
<span class="metric-dot time"></span>TIME
</div>
<div class="metric-value">50<small>MIN</small></div>
</div>
<div class="metric">
<div class="metric-label">
<span class="metric-dot fuel"></span>FUEL
</div>
<div class="metric-value">20<small>L</small></div>
</div>
</div>
</article>
<article class="route-card" style="--route: var(--route-c)">
<div class="card-top">
<div class="route-name">
<span class="route-letter">C</span>
<span class="route-label">ECO</span>
</div>
<span class="badge fuel-winner">Fuel leader</span>
</div>
<div class="metrics">
<div class="metric">
<div class="metric-label">
<span class="metric-dot time"></span>TIME
</div>
<div class="metric-value">70<small>MIN</small></div>
</div>
<div class="metric">
<div class="metric-label">
<span class="metric-dot fuel"></span>FUEL
</div>
<div class="metric-value">12<small>L</small></div>
</div>
</div>
</article>
</section>
<table class="sr-only">
<caption>Route comparison; lower values are better</caption>
<thead>
<tr><th>Route</th><th>Time</th><th>Fuel</th></tr>
</thead>
<tbody>
<tr><td>Express</td><td>30 minutes</td><td>32 liters</td></tr>
<tr><td>Balanced</td><td>50 minutes</td><td>20 liters</td></tr>
<tr><td>Eco</td><td>70 minutes</td><td>12 liters</td></tr>
</tbody>
</table>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const COLORS = {
background: 0xe9ede7,
platform: 0xd5ddd6,
ink: 0x17241f,
white: 0xf9fbf8,
routeA: 0xed6758,
routeB: 0x705bd8,
routeC: 0x15967f,
time: 0xefb13f,
fuel: 0x3b9fbd
};
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Three route paths with separate time and fuel token stacks"
);
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(COLORS.background);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const orbit = {
target: new THREE.Vector3(0, 0.15, 0),
distance: 27,
azimuth: 2.62,
elevation: 0.74,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x8d9c93, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(-8, 16, -10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xcfe4ef, 0.85);
fillLight.position.set(10, 8, 10);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: COLORS.background,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.68;
floor.receiveShadow = true;
scene.add(floor);
function roundedShape(width, height, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
const platformGeometry = new THREE.ExtrudeGeometry(
roundedShape(19, 13, 1.2),
{
depth: 0.42,
steps: 1,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: 0.16,
bevelThickness: 0.12,
curveSegments: 10
}
);
platformGeometry.rotateX(-Math.PI / 2);
const platform = new THREE.Mesh(
platformGeometry,
new THREE.MeshStandardMaterial({
color: COLORS.platform,
roughness: 0.86,
metalness: 0
})
);
platform.position.y = -0.42;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const routeDefinitions = [
{
id: "A",
name: "EXPRESS",
subtitle: "TIME LEADER",
color: COLORS.routeA,
points: [
[-7.0, 0.14, -1.7],
[-5.0, 0.14, 1.9],
[-2.6, 0.14, 4.0],
[0.6, 0.14, 3.8],
[4.0, 0.14, 1.7],
[7.0, 0.14, -1.7]
],
time: 3,
fuel: 8,
timeValue: "30 MIN",
fuelValue: "32 L",
stackPosition: [-4.25, 5.08],
labelPosition: [-1.15, 4.18]
},
{
id: "B",
name: "BALANCED",
subtitle: "MIDDLE GROUND",
color: COLORS.routeB,
points: [
[-7.0, 0.14, -1.7],
[-4.6, 0.14, -0.15],
[-1.4, 0.14, 0.35],
[2.1, 0.14, -0.15],
[4.7, 0.14, -0.8],
[7.0, 0.14, -1.7]
],
time: 5,
fuel: 5,
timeValue: "50 MIN",
fuelValue: "20 L",
stackPosition: [0.0, 1.42],
labelPosition: [2.55, 0.55]
},
{
id: "C",
name: "ECO",
subtitle: "FUEL LEADER",
color: COLORS.routeC,
points: [
[-7.0, 0.14, -1.7],
[-5.0, 0.14, -3.3],
[-2.4, 0.14, -5.0],
[1.4, 0.14, -5.1],
[4.4, 0.14, -3.7],
[7.0, 0.14, -1.7]
],
time: 7,
fuel: 3,
timeValue: "70 MIN",
fuelValue: "12 L",
stackPosition: [4.0, -5.02],
labelPosition: [0.55, -4.75]
}
];
const floaters = [];
function canvasRoundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeLabel({
title,
subtitle,
accent,
background = "#ffffff",
foreground = "#1d2a25",
width = 2.8
}) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
canvasRoundedRect(ctx, 5, 5, 502, 182, 25);
ctx.fillStyle = background;
ctx.fill();
ctx.lineWidth = 6;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = accent;
canvasRoundedRect(ctx, 27, 31, 9, 130, 4);
ctx.fill();
ctx.textBaseline = "middle";
ctx.textAlign = "left";
ctx.fillStyle = foreground;
ctx.font = "800 61px Inter, system-ui, sans-serif";
ctx.fillText(title, 56, 69);
ctx.globalAlpha = 0.72;
ctx.font = "700 39px Inter, system-ui, sans-serif";
ctx.fillText(subtitle, 56, 137);
ctx.globalAlpha = 1;
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false,
fog: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * (192 / 512), 1);
sprite.renderOrder = 30;
return sprite;
}
function addRouteArrow(curve, t) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.2, 0.55, 16),
new THREE.MeshStandardMaterial({
color: COLORS.white,
roughness: 0.6
})
);
const point = curve.getPointAt(t);
const tangent = curve.getTangentAt(t).normalize();
arrow.position.copy(point);
arrow.position.y += 0.025;
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
arrow.castShadow = true;
scene.add(arrow);
}
const tokenGeometry = new THREE.CylinderGeometry(0.31, 0.31, 0.22, 24);
const tokenTopGeometry = new THREE.CylinderGeometry(0.265, 0.265, 0.025, 24);
function createStack({
route,
x,
z,
count,
color,
title,
value
}) {
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.46, 0.1, 28),
new THREE.MeshStandardMaterial({
color: route.color,
roughness: 0.78
})
);
base.position.set(x, 0.045, z);
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const tokenMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.62,
metalness: 0
});
const capColor = new THREE.Color(color).lerp(
new THREE.Color(0xffffff),
0.24
);
const capMaterial = new THREE.MeshStandardMaterial({
color: capColor,
roughness: 0.56
});
for (let i = 0; i < count; i++) {
const y = 0.11 + (i + 0.5) * 0.25;
const token = new THREE.Mesh(tokenGeometry, tokenMaterial);
token.position.set(x, y, z);
token.castShadow = true;
token.receiveShadow = true;
scene.add(token);
const cap = new THREE.Mesh(tokenTopGeometry, capMaterial);
cap.position.set(x, y + 0.116, z);
cap.castShadow = true;
scene.add(cap);
}
const stackTop = 0.11 + count * 0.25;
const label = makeLabel({
title,
subtitle: value,
accent: color,
background: "#ffffff",
foreground: color === COLORS.time ? "#70490b" : "#155e70",
width: 1.8
});
label.position.set(x, stackTop + 0.52, z);
scene.add(label);
}
function addEndpoint(x, z, text, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.7, 0.76, 0.18, 32),
new THREE.MeshStandardMaterial({
color: 0xf8faf7,
roughness: 0.72
})
);
base.position.y = 0.08;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.49, 0.075, 12, 36),
new THREE.MeshStandardMaterial({
color,
roughness: 0.6
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.19;
ring.castShadow = true;
group.add(ring);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.28, 0.62, 20),
new THREE.MeshStandardMaterial({
color,
roughness: 0.6
})
);
post.position.y = 0.47;
post.castShadow = true;
group.add(post);
const cap = new THREE.Mesh(
new THREE.SphereGeometry(0.24, 20, 14),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.45
})
);
cap.position.y = 0.82;
cap.castShadow = true;
group.add(cap);
const label = makeLabel({
title: text,
subtitle: text === "START" ? "COMMON ORIGIN" : "COMMON DESTINATION",
accent: color,
background: "#ffffff",
foreground: "#27342e",
width: 2.25
});
label.position.set(0, 1.45, 0);
group.add(label);
scene.add(group);
}
routeDefinitions.forEach((route, routeIndex) => {
const points = route.points.map(
(point) => new THREE.Vector3(point[0], point[1], point[2])
);
const curve = new THREE.CatmullRomCurve3(
points,
false,
"catmullrom",
0.45
);
const routeUnderlay = new THREE.Mesh(
new THREE.TubeGeometry(curve, 110, 0.235, 12, false),
new THREE.MeshStandardMaterial({
color: COLORS.white,
roughness: 0.78
})
);
routeUnderlay.castShadow = true;
routeUnderlay.receiveShadow = true;
scene.add(routeUnderlay);
const routeMesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 110, 0.108, 12, false),
new THREE.MeshStandardMaterial({
color: route.color,
roughness: 0.56
})
);
routeMesh.castShadow = true;
scene.add(routeMesh);
addRouteArrow(curve, 0.34 + routeIndex * 0.035);
addRouteArrow(curve, 0.69 - routeIndex * 0.025);
const routeLabel = makeLabel({
title: `${route.id} · ${route.name}`,
subtitle: route.subtitle,
accent: route.color,
background: `#${new THREE.Color(route.color).getHexString()}`,
foreground: "#ffffff",
width: 3.1
});
routeLabel.position.set(
route.labelPosition[0],
0.88,
route.labelPosition[1]
);
scene.add(routeLabel);
floaters.push({
sprite: routeLabel,
baseY: routeLabel.position.y,
phase: routeIndex * 1.7
});
const [stackX, stackZ] = route.stackPosition;
createStack({
route,
x: stackX - 0.98,
z: stackZ,
count: route.time,
color: COLORS.time,
title: "TIME",
value: route.timeValue
});
createStack({
route,
x: stackX + 0.98,
z: stackZ,
count: route.fuel,
color: COLORS.fuel,
title: "FUEL",
value: route.fuelValue
});
});
addEndpoint(-7.0, -1.7, "START", COLORS.ink);
addEndpoint(7.0, -1.7, "FINISH", COLORS.ink);
function updateCamera() {
const { distance, azimuth, elevation, target } = orbit;
camera.position.set(
target.x + distance * Math.sin(azimuth) * Math.cos(elevation),
target.y + distance * Math.sin(elevation),
target.z + distance * Math.cos(azimuth) * Math.cos(elevation)
);
camera.lookAt(target);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
const aspect = width / Math.max(height, 1);
const viewHeight = Math.max(12.1, 24 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setSize(width, height, false);
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
resize();
updateCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
let autoOrbit = false;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
autoOrbit = false;
spinButton.classList.remove("active");
spinButton.setAttribute("aria-pressed", "false");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.azimuth -= dx * 0.006;
orbit.elevation = THREE.MathUtils.clamp(
orbit.elevation + dy * 0.005,
0.38,
1.25
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom - event.deltaY * 0.001,
0.75,
1.55
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener("keydown", (event) => {
const key = event.key;
if (key === "ArrowLeft") orbit.azimuth -= 0.08;
else if (key === "ArrowRight") orbit.azimuth += 0.08;
else if (key === "ArrowUp") {
orbit.elevation = Math.min(1.25, orbit.elevation + 0.06);
} else if (key === "ArrowDown") {
orbit.elevation = Math.max(0.38, orbit.elevation - 0.06);
} else if (key === "+" || key === "=") {
orbit.zoom = Math.min(1.55, orbit.zoom + 0.08);
} else if (key === "-") {
orbit.zoom = Math.max(0.75, orbit.zoom - 0.08);
} else {
return;
}
event.preventDefault();
updateCamera();
});
const spinButton = document.querySelector("#spin");
const resetButton = document.querySelector("#reset");
function resetView() {
orbit.azimuth = 2.62;
orbit.elevation = 0.74;
orbit.zoom = 1;
updateCamera();
}
spinButton.addEventListener("click", () => {
autoOrbit = !autoOrbit;
spinButton.classList.toggle("active", autoOrbit);
spinButton.setAttribute("aria-pressed", String(autoOrbit));
});
resetButton.addEventListener("click", resetView);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (autoOrbit && !dragging) {
orbit.azimuth += delta * 0.075;
updateCamera();
}
floaters.forEach(({ sprite, baseY, phase }) => {
sprite.position.y = baseY + Math.sin(elapsed * 1.25 + phase) * 0.045;
});
renderer.render(scene, camera);
}
loading.style.display = "none";
animate();
</script>
</body>
</html>
```