Prompt specification
Build or customize the Three.js 3D scene "Pareto Frontier Route Explorer" 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: Pareto Frontier Route Explorer
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pareto-frontier-route-explorer-x3552
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing tradeoffs between route objectives. Generate a bounded set of feasible routes for a tiny map. Highlight dominated and nondominated choices under two stated objectives without asserting that a frontier point is morally optimal. Low-poly.
Working Three.js Starter (pareto-frontier-route-explorer-x3552):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Route Trade-offs — Low-Poly Network</title>
<style>
:root {
color-scheme: dark;
--bg: #101722;
--panel: #151f2c;
--panel-2: #1b2837;
--line: #2b3a4d;
--text: #edf3f7;
--muted: #9eafbf;
--teal: #29c7b2;
--orange: #ffc857;
--gray: #8390a2;
--danger: #b9c1cc;
}
* {
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;
}
button:focus-visible,
[tabindex]:focus-visible {
outline: 2px solid var(--orange);
outline-offset: 2px;
}
#app {
display: grid;
grid-template-columns: 370px minmax(0, 1fr);
width: 100%;
height: 100%;
}
.sidebar {
position: relative;
z-index: 5;
display: flex;
min-height: 0;
flex-direction: column;
overflow: hidden;
border-right: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(41, 199, 178, 0.05), transparent 28%),
var(--panel);
}
.sidebar-header {
padding: 22px 20px 16px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
display: block;
margin-bottom: 6px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1,
h2,
h3,
p {
margin-top: 0;
}
.sidebar h1 {
margin-bottom: 9px;
font-size: 24px;
line-height: 1.05;
}
.intro {
margin-bottom: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.sidebar-scroll {
min-height: 0;
flex: 1;
overflow-y: auto;
scrollbar-color: #3b4c61 transparent;
}
.section {
padding: 17px 20px;
border-bottom: 1px solid var(--line);
}
.section-title {
margin-bottom: 11px;
color: #c7d3df;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.objective-grid {
display: grid;
gap: 9px;
}
.objective {
display: grid;
grid-template-columns: 34px 1fr auto;
gap: 10px;
align-items: center;
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.objective-icon {
display: grid;
width: 34px;
height: 34px;
place-items: center;
border-radius: 8px;
background: rgba(41, 199, 178, 0.11);
color: var(--teal);
font-size: 18px;
font-weight: 800;
}
.objective strong {
display: block;
margin-bottom: 2px;
font-size: 13px;
}
.objective small {
display: block;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.direction {
padding: 4px 7px;
border-radius: 999px;
background: rgba(255, 200, 87, 0.1);
color: var(--orange);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.notice {
border-left: 3px solid var(--orange);
border-radius: 4px 9px 9px 4px;
background: rgba(255, 200, 87, 0.075);
color: #d9e0e8;
font-size: 12px;
line-height: 1.5;
}
.notice strong {
color: var(--orange);
}
.filter-row {
display: flex;
gap: 8px;
margin-bottom: 12px;
}
.button {
cursor: pointer;
border: 1px solid var(--line);
border-radius: 8px;
background: #1c2938;
color: var(--text);
font-size: 12px;
font-weight: 700;
transition:
background 150ms ease,
border-color 150ms ease,
color 150ms ease;
}
.button:hover {
border-color: #53677d;
background: #243447;
}
.button.active {
border-color: rgba(41, 199, 178, 0.65);
background: rgba(41, 199, 178, 0.12);
color: #8af0e2;
}
.filter-row .button {
flex: 1;
padding: 9px 10px;
}
.generator-note {
margin-bottom: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.list-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.list-heading h2 {
margin: 0;
font-size: 13px;
}
.list-heading span {
color: var(--muted);
font-size: 11px;
}
.route-list {
display: grid;
gap: 8px;
}
.route-row {
width: 100%;
cursor: pointer;
padding: 11px 12px;
border: 1px solid var(--line);
border-left: 3px solid var(--gray);
border-radius: 9px;
background: rgba(255, 255, 255, 0.025);
color: var(--text);
text-align: left;
transition:
background 130ms ease,
border-color 130ms ease,
transform 130ms ease;
}
.route-row:hover {
background: rgba(255, 255, 255, 0.055);
transform: translateX(2px);
}
.route-row.nondominated {
border-left-color: var(--teal);
}
.route-row.selected {
border-color: var(--orange);
border-left-color: var(--orange);
background: rgba(255, 200, 87, 0.08);
}
.route-row[hidden] {
display: none;
}
.route-top,
.route-metrics {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.route-name {
font-size: 12px;
font-weight: 800;
}
.route-id {
margin-left: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.badge {
flex: none;
padding: 3px 6px;
border-radius: 999px;
background: rgba(131, 144, 162, 0.12);
color: var(--danger);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.badge.nondominated {
background: rgba(41, 199, 178, 0.12);
color: #7de8db;
}
.route-metrics {
margin-top: 8px;
color: #d8e1ea;
font-size: 11px;
}
.route-path {
margin-top: 7px;
overflow: hidden;
color: var(--muted);
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.sidebar-footer {
padding: 12px 20px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #cbd5d1;
}
.webgl {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.stage::after {
position: absolute;
inset: 0;
z-index: 1;
pointer-events: none;
content: "";
box-shadow: inset 0 0 90px rgba(15, 30, 35, 0.13);
}
.stage-header {
position: absolute;
top: 18px;
left: 20px;
z-index: 3;
max-width: 340px;
pointer-events: none;
color: #15222b;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}
.stage-header .eyebrow {
color: #126b63;
}
.stage-header h2 {
margin-bottom: 4px;
font-size: 20px;
}
.stage-header p {
margin-bottom: 0;
color: #43535d;
font-size: 11px;
}
.view-tools {
position: absolute;
top: 18px;
right: 18px;
z-index: 4;
display: flex;
gap: 7px;
}
.view-tools .button {
border-color: rgba(18, 32, 43, 0.18);
background: rgba(247, 250, 250, 0.88);
color: #263743;
box-shadow: 0 3px 14px rgba(20, 35, 40, 0.12);
backdrop-filter: blur(8px);
}
.view-tools .button:hover {
background: white;
}
.selection-card {
position: absolute;
top: 78px;
left: 20px;
z-index: 3;
width: min(340px, calc(100% - 40px));
padding: 13px 14px;
border: 1px solid rgba(27, 45, 55, 0.12);
border-radius: 11px;
background: rgba(248, 251, 251, 0.89);
color: #172631;
box-shadow: 0 8px 28px rgba(20, 35, 40, 0.12);
backdrop-filter: blur(10px);
pointer-events: none;
}
.selection-label {
display: block;
margin-bottom: 5px;
color: #63717a;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.selection-card strong {
display: block;
margin-bottom: 7px;
font-size: 15px;
}
.selection-stats {
display: flex;
gap: 18px;
margin-bottom: 7px;
font-size: 11px;
}
.selection-status {
color: #53616a;
font-size: 10px;
line-height: 1.45;
}
.legend {
position: absolute;
bottom: 18px;
left: 18px;
z-index: 3;
display: flex;
flex-wrap: wrap;
gap: 11px;
max-width: 420px;
padding: 9px 11px;
border: 1px solid rgba(27, 45, 55, 0.12);
border-radius: 9px;
background: rgba(248, 251, 251, 0.86);
color: #34434d;
font-size: 10px;
backdrop-filter: blur(8px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 17px;
height: 4px;
border-radius: 4px;
}
.swatch.nondom {
background: var(--teal);
}
.swatch.dominated {
height: 3px;
background: var(--gray);
}
.swatch.selected {
background: var(--orange);
}
.plot-panel {
position: absolute;
right: 18px;
bottom: 18px;
z-index: 3;
width: min(455px, calc(100% - 36px));
padding: 13px 13px 9px;
border: 1px solid rgba(27, 45, 55, 0.12);
border-radius: 12px;
background: rgba(248, 251, 251, 0.9);
color: #172631;
box-shadow: 0 8px 30px rgba(20, 35, 40, 0.13);
backdrop-filter: blur(10px);
}
.plot-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 4px;
}
.plot-heading h3 {
margin: 0;
font-size: 12px;
}
.plot-heading span {
color: #63717a;
font-size: 9px;
font-weight: 700;
}
#plot {
display: block;
width: 100%;
height: auto;
overflow: visible;
}
#plot circle {
cursor: pointer;
transition: r 120ms ease;
}
#loading {
position: absolute;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #cbd5d1;
color: #263943;
font-size: 13px;
font-weight: 700;
}
@media (max-width: 820px) {
#app {
grid-template-columns: 1fr;
grid-template-rows: 57% 43%;
}
.stage {
grid-row: 1;
}
.sidebar {
grid-row: 2;
border-top: 1px solid var(--line);
border-right: 0;
}
.sidebar-header {
padding: 12px 16px;
}
.sidebar h1 {
font-size: 19px;
}
.intro,
.plot-panel {
display: none;
}
.sidebar-scroll {
display: grid;
grid-template-columns: 1fr 1.4fr;
}
.section {
padding: 12px 15px;
}
.objective-grid {
gap: 6px;
}
.objective {
grid-template-columns: 27px 1fr;
gap: 7px;
padding: 7px;
}
.objective-icon {
width: 27px;
height: 27px;
}
.objective .direction {
display: none;
}
.notice,
.generator-note {
font-size: 10px;
}
.route-row {
padding: 8px 10px;
}
.route-path {
display: none;
}
.stage-header {
top: 12px;
left: 14px;
}
.stage-header h2 {
font-size: 16px;
}
.selection-card {
top: 62px;
left: 14px;
width: 285px;
padding: 9px 11px;
}
.view-tools {
top: 12px;
right: 12px;
}
.legend {
bottom: 10px;
left: 10px;
}
}
</style>
</head>
<body>
<div id="app">
<aside class="sidebar">
<header class="sidebar-header">
<span class="eyebrow">Low-poly decision atlas</span>
<h1>Route trade-offs</h1>
<p class="intro">
Compare a bounded set of feasible routes using two explicitly stated,
conflicting objectives.
</p>
</header>
<div class="sidebar-scroll">
<section class="section">
<h2 class="section-title">Stated objectives</h2>
<div class="objective-grid">
<div class="objective">
<div class="objective-icon">↔</div>
<div>
<strong>Travel distance</strong>
<small>Geometric route length in kilometres</small>
</div>
<span class="direction">Minimize</span>
</div>
<div class="objective">
<div class="objective-icon">Σ</div>
<div>
<strong>Exposure index</strong>
<small>Sum of fixed segment ratings</small>
</div>
<span class="direction">Minimize</span>
</div>
</div>
</section>
<section class="section">
<h2 class="section-title">How to read the map</h2>
<div class="notice">
<strong>Nondominated</strong> means that no other displayed route is
no worse on both objectives and strictly better on at least one.
It is not a claim of moral, social, or environmental superiority.
The exposure index is a demo quantity, not a safety score.
</div>
</section>
<section class="section">
<h2 class="section-title">Display</h2>
<div class="filter-row">
<button class="button active" id="showAll" type="button">
All feasible routes
</button>
<button class="button" id="showNondominated" type="button">
Nondominated only
</button>
</div>
<p class="generator-note" id="generatorNote"></p>
</section>
<section class="section">
<div class="list-heading">
<h2>Feasible routes</h2>
<span id="routeCount"></span>
</div>
<div class="route-list" id="routeList"></div>
</section>
</div>
<footer class="sidebar-footer">
Drag to orbit · Shift-drag or right-drag to pan · Scroll to zoom ·
Click a route or list item to inspect it.
</footer>
</aside>
<main class="stage" id="stage">
<div id="loading">Loading the low-poly network…</div>
<header class="stage-header">
<span class="eyebrow">Fixed tiny network</span>
<h2>Distance versus exposure</h2>
<p id="mapSubtitle"></p>
</header>
<div class="view-tools">
<button class="button" id="resetView" type="button">Reset view</button>
</div>
<section class="selection-card" aria-live="polite">
<span class="selection-label">Selected for inspection · not a recommendation</span>
<strong id="selectedTitle"></strong>
<div class="selection-stats" id="selectedStats"></div>
<div class="selection-status" id="selectedStatus"></div>
</section>
<div class="legend">
<span class="legend-item">
<span class="swatch nondom"></span> Nondominated in this set
</span>
<span class="legend-item">
<span class="swatch dominated"></span> Dominated
</span>
<span class="legend-item">
<span class="swatch selected"></span> Selected
</span>
</div>
<section class="plot-panel">
<div class="plot-heading">
<h3>Objective plane</h3>
<span>minimize both ↙</span>
</div>
<svg id="plot" viewBox="0 0 480 230" role="img"
aria-label="Scatter plot of route distance and exposure index"></svg>
</section>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Fixed route network and bounded route generator
// -------------------------------------------------------------------------
const nodeData = {
S: { x: -9.0, z: 0.0, label: "START" },
A: { x: -5.0, z: 3.2 },
B: { x: -5.0, z: -3.2 },
C: { x: -1.0, z: 4.0 },
D: { x: -1.0, z: 0.0 },
E: { x: -1.0, z: -3.2 },
F: { x: 3.0, z: 4.0 },
G: { x: 3.0, z: 0.0 },
H: { x: 3.0, z: -3.2 },
T: { x: 9.0, z: 0.0, label: "GOAL" }
};
const edgeData = [
{ from: "S", to: "A", exposure: 4 },
{ from: "S", to: "B", exposure: 4 },
{ from: "S", to: "D", exposure: 14 },
{ from: "A", to: "C", exposure: 4 },
{ from: "A", to: "D", exposure: 5 },
{ from: "A", to: "F", exposure: 12 },
{ from: "B", to: "D", exposure: 5 },
{ from: "B", to: "E", exposure: 4 },
{ from: "B", to: "H", exposure: 9 },
{ from: "C", to: "F", exposure: 4 },
{ from: "C", to: "D", exposure: 4 },
{ from: "D", to: "G", exposure: 7 },
{ from: "D", to: "E", exposure: 4 },
{ from: "E", to: "H", exposure: 4 },
{ from: "E", to: "G", exposure: 7 },
{ from: "F", to: "T", exposure: 4 },
{ from: "G", to: "T", exposure: 6 },
{ from: "H", to: "T", exposure: 5 }
];
const routeNames = {
"S-A-C-F-T": "North ridge",
"S-A-F-T": "Upper express",
"S-A-D-G-T": "Central spine",
"S-A-C-D-G-T": "North switchback",
"S-A-C-D-E-H-T": "Upper–lower weave",
"S-A-C-D-E-G-T": "North-center weave",
"S-A-D-E-H-T": "Upper–lower cross",
"S-A-D-E-G-T": "Central weave",
"S-B-D-G-T": "South-central",
"S-B-D-E-H-T": "South weave",
"S-B-D-E-G-T": "South-center weave",
"S-B-E-H-T": "South ridge",
"S-B-E-G-T": "South-center arc",
"S-B-H-T": "Lower express",
"S-D-G-T": "Center cut",
"S-D-E-H-T": "Lower cross",
"S-D-E-G-T": "Lower-center arc"
};
const adjacency = new Map(
Object.keys(nodeData).map((key) => [key, []])
);
const edgeLookup = new Map();
for (const edge of edgeData) {
adjacency.get(edge.from).push(edge);
edgeLookup.set(`${edge.from}>${edge.to}`, edge);
}
const generatedRoutes = [];
const MAX_SEGMENTS = 6;
const KM_PER_MAP_UNIT = 0.9;
function generateRoutes(node, nodes, edgeRefs) {
if (node === "T") {
generatedRoutes.push({
nodes: [...nodes],
edgeRefs: [...edgeRefs]
});
}
if (nodes.length - 1 >= MAX_SEGMENTS) return;
for (const edge of adjacency.get(node)) {
nodes.push(edge.to);
edgeRefs.push(edge);
generateRoutes(edge.to, nodes, edgeRefs);
edgeRefs.pop();
nodes.pop();
}
}
generateRoutes("S", ["S"], []);
const routes = generatedRoutes.map((route) => {
let distance = 0;
for (let i = 1; i < route.nodes.length; i++) {
const a = nodeData[route.nodes[i - 1]];
const b = nodeData[route.nodes[i]];
distance += Math.hypot(b.x - a.x, b.z - a.z);
}
const pathKey = route.nodes.join("-");
return {
...route,
pathKey,
name: routeNames[pathKey] ?? pathKey,
distanceKm: distance * KM_PER_MAP_UNIT,
exposure: route.edgeRefs.reduce((sum, edge) => sum + edge.exposure, 0)
};
});
routes.sort(
(a, b) =>
a.distanceKm - b.distanceKm ||
a.exposure - b.exposure ||
a.pathKey.localeCompare(b.pathKey)
);
routes.forEach((route, index) => {
route.id = `R${String(index + 1).padStart(2, "0")}`;
});
function dominates(a, b) {
const epsilon = 1e-9;
const noWorse =
a.distanceKm <= b.distanceKm + epsilon &&
a.exposure <= b.exposure + epsilon;
const strictlyBetter =
a.distanceKm < b.distanceKm - epsilon ||
a.exposure < b.exposure - epsilon;
return noWorse && strictlyBetter;
}
for (const route of routes) {
route.dominatedBy = routes
.filter((other) => other !== route && dominates(other, route))
.map((other) => other.id);
route.nondominated = route.dominatedBy.length === 0;
}
const nondominatedRoutes = routes.filter((route) => route.nondominated);
document.getElementById("generatorNote").textContent =
`The generator enumerates every simple S→T path in the fixed network ` +
`using at most ${MAX_SEGMENTS} segments. There are ${routes.length} ` +
`feasible routes; dominance is evaluated only within this displayed set.`;
document.getElementById("routeCount").textContent =
`${routes.length} routes · ${nondominatedRoutes.length} nondominated`;
document.getElementById("mapSubtitle").textContent =
`${routes.length} feasible paths · ${nondominatedRoutes.length} nondominated · two minimization objectives`;
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true });
} catch (error) {
loading.textContent = "WebGL could not be initialized in this browser.";
throw error;
}
renderer.domElement.className = "webgl";
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly route network"
);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd5d1);
scene.fog = new THREE.Fog(0xcbd5d1, 34, 70);
const camera = new THREE.PerspectiveCamera(
42,
stage.clientWidth / stage.clientHeight,
0.1,
150
);
const hemisphere = new THREE.HemisphereLight(0xf6fbff, 0x68705e, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d2, 2.7);
sun.position.set(-10, 22, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const nodePositions = new Map();
for (const [key, data] of Object.entries(nodeData)) {
nodePositions.set(
key,
new THREE.Vector3(data.x, 0, data.z)
);
}
const ground = new THREE.Mesh(
new THREE.BoxGeometry(25, 0.55, 13.5),
new THREE.MeshStandardMaterial({
color: 0xc9d2aa,
roughness: 1,
flatShading: true
})
);
ground.position.y = -0.31;
ground.receiveShadow = true;
scene.add(ground);
// Low-poly terrain patches.
const patchData = [
[-8.8, 4.4, 2.4, 0xa9c394],
[8.6, -4.2, 2.7, 0xb6c991],
[7.7, 4.6, 2.0, 0x9fb98b],
[-7.7, -4.6, 2.2, 0xb4c792],
[0.2, 0.0, 2.3, 0xb9c8a0]
];
for (const [x, z, radius, color] of patchData) {
const patch = new THREE.Mesh(
new THREE.CircleGeometry(radius, 7),
new THREE.MeshStandardMaterial({
color,
roughness: 1,
flatShading: true
})
);
patch.rotation.x = -Math.PI / 2;
patch.rotation.z = 0.3;
patch.position.set(x, -0.015, z);
patch.receiveShadow = true;
scene.add(patch);
}
// Base road network.
const roadMaterial = new THREE.MeshStandardMaterial({
color: 0x9e9279,
roughness: 1,
flatShading: true
});
function createSegmentMesh(a, b, radius, material, radialSegments = 5) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(a, b)
.multiplyScalar(0.5);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
return mesh;
}
for (const edge of edgeData) {
const a = nodePositions.get(edge.from);
const b = nodePositions.get(edge.to);
const road = createSegmentMesh(
a.clone().setY(0.06),
b.clone().setY(0.06),
0.105,
roadMaterial,
6
);
road.receiveShadow = true;
scene.add(road);
}
// Small low-poly buildings beside the network nodes.
const buildingColors = [
0xd7d0bd,
0xc3c8c1,
0xe0c9a8,
0xb8c1c3,
0xcac1cf
];
let buildingIndex = 0;
for (const [key, data] of Object.entries(nodeData)) {
if (key === "S" || key === "T") continue;
const building = new THREE.Mesh(
new THREE.BoxGeometry(
0.55 + (buildingIndex % 2) * 0.18,
0.38 + (buildingIndex % 3) * 0.08,
0.62
),
new THREE.MeshStandardMaterial({
color: buildingColors[buildingIndex % buildingColors.length],
roughness: 0.9,
flatShading: true
})
);
building.position.set(
data.x + 0.52,
0.18,
data.z + (buildingIndex % 2 === 0 ? 0.38 : -0.38)
);
building.rotation.y = (buildingIndex % 3) * 0.22;
building.castShadow = true;
building.receiveShadow = true;
scene.add(building);
buildingIndex++;
}
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.10, 0.55, 5),
new THREE.MeshStandardMaterial({
color: 0x705b43,
roughness: 1,
flatShading: true
})
);
trunk.position.y = 0.25;
trunk.castShadow = true;
group.add(trunk);
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.48, 1.15, 6),
new THREE.MeshStandardMaterial({
color: 0x527b59,
roughness: 1,
flatShading: true
})
);
lower.position.y = 0.95;
lower.castShadow = true;
group.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.34, 0.85, 6),
new THREE.MeshStandardMaterial({
color: 0x668e61,
roughness: 1,
flatShading: true
})
);
upper.position.y = 1.40;
upper.castShadow = true;
group.add(upper);
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
}
[
[-10.6, 5.0, 0.9],
[-8.9, 5.3, 0.75],
[-10.5, -4.9, 0.8],
[-8.8, -5.2, 0.65],
[8.8, 5.2, 0.85],
[10.3, 4.3, 0.65],
[9.0, -5.1, 0.9],
[10.7, -4.3, 0.7],
[-2.2, 5.3, 0.6],
[1.2, -5.2, 0.55]
].forEach((args) => addTree(...args));
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x8d938c,
roughness: 1,
flatShading: true
});
for (const [x, z, scale] of [
[-10.2, 2.6, 0.32],
[10.1, 2.7, 0.28],
[-2.8, -5.2, 0.24],
[5.9, 5.2, 0.25]
]) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(scale, 0),
rockMaterial
);
rock.position.set(x, 0.13, z);
rock.rotation.set(0.3, 0.8, 0.2);
rock.castShadow = true;
scene.add(rock);
}
function makeLabelSprite(text, color = "#edf5f7", scale = 1) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 80;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(17, 29, 38, 0.82)";
context.fillRect(4, 12, 248, 56);
context.strokeStyle = "rgba(255,255,255,0.22)";
context.lineWidth = 2;
context.strokeRect(4, 12, 248, 56);
context.fillStyle = color;
context.font = "700 30px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 128, 40);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
})
);
sprite.scale.set(1.8 * scale, 0.56 * scale, 1);
sprite.renderOrder = 10;
return sprite;
}
// Network node markers.
for (const [key, data] of Object.entries(nodeData)) {
const isEndpoint = key === "S" || key === "T";
const marker = new THREE.Mesh(
new THREE.CylinderGeometry(
isEndpoint ? 0.23 : 0.13,
isEndpoint ? 0.28 : 0.18,
isEndpoint ? 0.30 : 0.18,
6
),
new THREE.MeshStandardMaterial({
color:
key === "S"
? 0x29c7b2
: key === "T"
? 0xffc857
: 0x52616d,
roughness: 0.72,
flatShading: true
})
);
marker.position.set(data.x, 0.13, data.z);
marker.castShadow = true;
scene.add(marker);
if (data.label) {
const label = makeLabelSprite(
data.label,
key === "S" ? "#8df1e4" : "#ffe3a1",
1
);
label.position.set(data.x, 0.75, data.z);
scene.add(label);
} else {
const label = makeLabelSprite(key, "#dbe5eb", 0.43);
label.position.set(data.x, 0.53, data.z + 0.12);
scene.add(label);
}
}
// Route meshes.
const routeMeshes = new Map();
for (const route of routes) {
const material = new THREE.MeshStandardMaterial({
color: 0x8390a2,
roughness: 0.82,
metalness: 0.02,
transparent: true,
opacity: 0.25,
depthWrite: false
});
const meshes = [];
for (let i = 1; i < route.nodes.length; i++) {
const a = nodePositions.get(route.nodes[i - 1]);
const b = nodePositions.get(route.nodes[i]);
const mesh = createSegmentMesh(
a.clone().setY(0.15),
b.clone().setY(0.15),
0.055,
material,
5
);
mesh.userData.routeId = route.id;
mesh.renderOrder = route.nondominated ? 3 : 2;
scene.add(mesh);
meshes.push(mesh);
}
route.material = material;
route.meshes = meshes;
routeMeshes.set(route.id, meshes);
}
// Direction arrows for the selected route only.
const arrowGroup = new THREE.Group();
scene.add(arrowGroup);
const arrowGeometry = new THREE.ConeGeometry(0.13, 0.38, 5);
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xffc857,
roughness: 0.75,
flatShading: true
});
function updateSelectedArrows(route) {
arrowGroup.clear();
for (let i = 1; i < route.nodes.length; i++) {
const a = nodePositions.get(route.nodes[i - 1]);
const b = nodePositions.get(route.nodes[i]);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.position.copy(a).lerp(b, 0.72);
arrow.position.y = 0.24;
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
arrow.castShadow = true;
arrowGroup.add(arrow);
}
}
// -------------------------------------------------------------------------
// UI state and route appearance
// -------------------------------------------------------------------------
let displayMode = "all";
let selectedRoute = nondominatedRoutes[0] ?? routes[0];
let hoveredRouteId = null;
const routeById = new Map(routes.map((route) => [route.id, route]));
function updateRouteAppearance() {
for (const route of routes) {
const isSelected = route.id === selectedRoute.id;
const isHovered = route.id === hoveredRouteId;
const visible = displayMode === "all" || route.nondominated;
if (route.nondominated) {
route.material.color.set(isSelected ? 0xffc857 : 0x29c7b2);
route.material.opacity = isSelected ? 1 : 0.94;
} else {
route.material.color.set(isHovered ? 0xc5ced8 : 0x8390a2);
route.material.opacity = isHovered ? 0.7 : 0.23;
}
route.material.emissive.set(isHovered ? 0x52616d : 0x000000);
route.material.emissiveIntensity = isHovered ? 0.45 : 0;
const thickness = isSelected ? 1.65 : route.nondominated ? 1.0 : 0.58;
for (const mesh of route.meshes) {
mesh.visible = visible;
mesh.scale.set(thickness, 1, thickness);
}
}
}
function updateSelectionPanel() {
document.getElementById("selectedTitle").textContent =
`${selectedRoute.id} · ${selectedRoute.name}`;
document.getElementById("selectedStats").innerHTML =
`<span><strong>${selectedRoute.distanceKm.toFixed(2)} km</strong></span>` +
`<span><strong>${selectedRoute.exposure} exposure</strong></span>`;
const status = document.getElementById("selectedStatus");
if (selectedRoute.nondominated) {
status.textContent =
"Nondominated within the displayed set: no other route is no worse " +
"on both stated objectives and strictly better on at least one.";
} else {
status.textContent =
`Dominated within the displayed set by ${selectedRoute.dominatedBy.join(", ")}: ` +
"the dominating route is no worse on both stated objectives and " +
"strictly better on at least one.";
}
}
function selectRoute(route, scrollIntoView = false) {
selectedRoute = route;
updateRouteAppearance();
updateSelectionPanel();
updateSelectedArrows(route);
renderPlot();
updateRouteListSelection();
if (scrollIntoView) {
document
.querySelector(`.route-row[data-route="${route.id}"]`)
?.scrollIntoView({ behavior: "smooth", block: "nearest" });
}
}
const routeList = document.getElementById("routeList");
const sortedForList = [
...nondominatedRoutes,
...routes.filter((route) => !route.nondominated)
].sort((a, b) => {
if (a.nondominated !== b.nondominated) {
return a.nondominated ? -1 : 1;
}
return (
a.distanceKm - b.distanceKm ||
a.exposure - b.exposure
);
});
for (const route of sortedForList) {
const button = document.createElement("button");
button.type = "button";
button.className = `route-row${route.nondominated ? " nondominated" : ""}`;
button.dataset.route = route.id;
button.setAttribute(
"aria-label",
`${route.id}, ${route.name}, ${route.distanceKm.toFixed(2)} kilometres, ` +
`exposure ${route.exposure}, ${route.nondominated ? "nondominated" : "dominated"}`
);
button.innerHTML = `
<div class="route-top">
<span class="route-name">
${route.name}<span class="route-id">${route.id}</span>
</span>
<span class="badge ${route.nondominated ? "nondominated" : ""}">
${route.nondominated ? "Non-dom." : "Dominated"}
</span>
</div>
<div class="route-metrics">
<span>${route.distanceKm.toFixed(2)} km</span>
<span>Exposure ${route.exposure}</span>
</div>
<div class="route-path">${route.nodes.join(" → ")}</div>
`;
button.addEventListener("click", () => selectRoute(route));
button.addEventListener("mouseenter", () => {
hoveredRouteId = route.id;
updateRouteAppearance();
});
button.addEventListener("mouseleave", () => {
hoveredRouteId = null;
updateRouteAppearance();
});
button.addEventListener("focus", () => {
hoveredRouteId = route.id;
updateRouteAppearance();
});
button.addEventListener("blur", () => {
hoveredRouteId = null;
updateRouteAppearance();
});
routeList.appendChild(button);
}
function updateRouteListSelection() {
for (const row of routeList.querySelectorAll(".route-row")) {
row.classList.toggle("selected", row.dataset.route === selectedRoute.id);
}
}
function setDisplayMode(mode) {
displayMode = mode;
document.getElementById("showAll").classList.toggle("active", mode === "all");
document
.getElementById("showNondominated")
.classList.toggle("active", mode === "nondominated");
for (const row of routeList.querySelectorAll(".route-row")) {
const route = routeById.get(row.dataset.route);
row.hidden = mode === "nondominated" && !route.nondominated;
}
updateRouteAppearance();
}
document.getElementById("showAll").addEventListener("click", () => {
setDisplayMode("all");
});
document.getElementById("showNondominated").addEventListener("click", () => {
setDisplayMode("nondominated");
});
// -------------------------------------------------------------------------
// Two-dimensional objective plot
// -------------------------------------------------------------------------
const plot = document.getElementById("plot");
function renderPlot() {
const width = 480;
const height = 230;
const margin = { left: 55, right: 20, top: 18, bottom: 43 };
const minDistance = Math.min(...routes.map((route) => route.distanceKm));
const maxDistance = Math.max(...routes.map((route) => route.distanceKm));
const minExposure = Math.min(...routes.map((route) => route.exposure));
const maxExposure = Math.max(...routes.map((route) => route.exposure));
const distancePadding = Math.max((maxDistance - minDistance) * 0.12, 0.3);
const exposurePadding = Math.max((maxExposure - minExposure) * 0.12, 1);
const xMin = minDistance - distancePadding;
const xMax = maxDistance + distancePadding;
const yMin = minExposure - exposurePadding;
const yMax = maxExposure + exposurePadding;
const xScale = (value) =>
margin.left +
((value - xMin) / (xMax - xMin)) *
(width - margin.left - margin.right);
const yScale = (value) =>
height -
margin.bottom -
((value - yMin) / (yMax - yMin)) *
(height - margin.top - margin.bottom);
let svg = `
<rect x="0" y="0" width="${width}" height="${height}" fill="transparent"/>
`;
for (let i = 0; i <= 4; i++) {
const x = margin.left +
((width - margin.left - margin.right) * i) / 4;
const y = margin.top +
((height - margin.top - margin.bottom) * i) / 4;
svg += `
<line
x1="${x}" y1="${margin.top}"
x2="${x}" y2="${height - margin.bottom}"
stroke="#cfd8d5" stroke-width="1"/>
<line
x1="${margin.left}" y1="${y}"
x2="${width - margin.right}" y2="${y}"
stroke="#cfd8d5" stroke-width="1"/>
`;
}
svg += `
<line
x1="${margin.left}" y1="${height - margin.bottom}"
x2="${width - margin.right}" y2="${height - margin.bottom}"
stroke="#51616d" stroke-width="1.5"/>
<line
x1="${margin.left}" y1="${margin.top}"
x2="${margin.left}" y2="${height - margin.bottom}"
stroke="#51616d" stroke-width="1.5"/>
<text
x="${width - margin.right}" y="${height - 15}"
text-anchor="end" fill="#53636f" font-size="10" font-weight="700">
Distance (km) →
</text>
<text
x="15" y="${margin.top + 4}"
text-anchor="start" fill="#53636f" font-size="10" font-weight="700"
transform="rotate(-90 15 ${margin.top + 4})">
Exposure index →
</text>
`;
const sortedNondominated = [...nondominatedRoutes].sort(
(a, b) => a.distanceKm - b.distanceKm
);
const linePoints = sortedNondominated
.map(
(route) =>
`${xScale(route.distanceKm)},${yScale(route.exposure)}`
)
.join(" ");
if (linePoints) {
svg += `
<polyline
points="${linePoints}"
fill="none"
stroke="#29a99a"
stroke-width="2"
stroke-dasharray="5 4"
opacity="0.55"/>
`;
}
for (const route of routes) {
const cx = xScale(route.distanceKm);
const cy = yScale(route.exposure);
const selected = route.id === selectedRoute.id;
const fill = selected
? "#ffc857"
: route.nondominated
? "#20b9a7"
: "#8a96a4";
svg += `
<circle
data-plot-route="${route.id}"
cx="${cx}" cy="${cy}" r="${selected ? 7 : 5}"
fill="${fill}"
fill-opacity="${route.nondominated ? 0.96 : 0.58}"
stroke="${selected ? "#5b4210" : "#ffffff"}"
stroke-width="${selected ? 2 : 1.5}">
<title>${route.id} · ${route.name}: ${route.distanceKm.toFixed(2)} km, exposure ${route.exposure}</title>
</circle>
`;
if (route.nondominated || selected) {
svg += `
<text
x="${cx + 9}" y="${cy - 7}"
fill="#31424e" font-size="9" font-weight="800">
${route.id}
</text>
`;
}
}
plot.innerHTML = svg;
for (const circle of plot.querySelectorAll("[data-plot-route]")) {
circle.addEventListener("click", () => {
selectRoute(routeById.get(circle.dataset.plotRoute), true);
});
}
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom
// -------------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 0, 0),
radius: 30,
theta: 0.42,
phi: 0.88
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.target.set(0, 0, 0);
orbit.radius = 30;
orbit.theta = 0.42;
orbit.phi = 0.88;
updateCamera();
}
document.getElementById("resetView").addEventListener("click", resetCamera);
let pointerActive = false;
let pointerMoved = false;
let panning = false;
let lastPointerX = 0;
let lastPointerY = 0;
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
pointerActive = true;
pointerMoved = false;
panning = event.shiftKey || event.button === 2;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerActive) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
if (panning) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, new THREE.Vector3(0, 1, 0))
.normalize();
const panScale = orbit.radius * 0.00125;
orbit.target.addScaledVector(right, -dx * panScale);
orbit.target.addScaledVector(forward, dy * panScale);
orbit.target.x = THREE.MathUtils.clamp(orbit.target.x, -9, 9);
orbit.target.z = THREE.MathUtils.clamp(orbit.target.z, -6, 6);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.32,
1.38
);
}
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerActive) return;
const wasClick = !pointerMoved && !panning;
pointerActive = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (!wasClick) return;
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const candidates = routes.flatMap((route) =>
route.meshes
.filter((mesh) => mesh.visible)
.map((mesh) => mesh)
);
const intersections = raycaster.intersectObjects(candidates, false);
if (intersections.length) {
const routeId = intersections[0].object.userData.routeId;
selectRoute(routeById.get(routeId));
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerActive = false;
panning = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
13,
48
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resizeRenderer() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(stage);
resizeRenderer();
updateCamera();
updateRouteAppearance();
updateSelectionPanel();
updateSelectedArrows(selectedRoute);
updateRouteListSelection();
renderPlot();
loading.remove();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```