Prompt specification
Build or customize the Three.js 3D scene "Choose One All-Season Connection" 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: Choose One All-Season Connection
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/choose-one-all-season-connection-x2140
Scene Description Prompt:
Choose one all-season connection. Create a small infrastructure planning puzzle with a fixed budget and seasonal closures. Compare which destinations remain connected under each candidate link. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (choose-one-all-season-connection-x2140):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Four-Season Link — Infrastructure Puzzle</title>
<style>
:root {
--bg: #0c1521;
--panel: #111d2b;
--panel-2: #172638;
--line: #2b4055;
--text: #eef5f7;
--muted: #9eb0bd;
--mint: #55e0bd;
--gold: #ffc857;
--coral: #ff8f70;
--red: #ff647c;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button {
font: inherit;
}
#app {
display: grid;
grid-template-columns: 400px minmax(0, 1fr);
height: 100vh;
min-height: 620px;
}
aside {
position: relative;
z-index: 2;
overflow-y: auto;
padding: 24px 22px 30px;
background:
linear-gradient(180deg, rgba(25, 43, 61, 0.96), rgba(13, 24, 36, 0.98)),
var(--panel);
border-right: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #3a5268 transparent;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 12px;
color: var(--mint);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
content: "";
background: var(--mint);
}
h1 {
margin: 0;
font-size: 34px;
line-height: 1.02;
letter-spacing: -0.045em;
}
.intro {
margin: 12px 0 20px;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.objective {
padding: 15px;
background: rgba(85, 224, 189, 0.07);
border: 1px solid rgba(85, 224, 189, 0.23);
border-radius: 14px;
}
.objective strong {
display: block;
margin-bottom: 5px;
color: #dffff4;
font-size: 13px;
}
.objective p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.budget {
margin: 18px 0;
}
.budget-line {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 8px;
font-size: 12px;
color: var(--muted);
}
.budget-line strong {
color: var(--text);
font-size: 15px;
}
.budget-track {
height: 7px;
overflow: hidden;
background: #26394b;
border-radius: 999px;
}
#budget-fill {
width: 0;
height: 100%;
background: linear-gradient(90deg, #42c9aa, #8cebd3);
border-radius: inherit;
transition: width 180ms ease;
}
.section-label {
margin: 21px 0 9px;
color: #c9d6de;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.season-tabs {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
}
.season-tab {
padding: 9px 4px;
cursor: pointer;
color: var(--muted);
background: #172638;
border: 1px solid var(--line);
border-radius: 9px;
font-size: 11px;
font-weight: 700;
transition: 150ms ease;
}
.season-tab:hover {
color: var(--text);
border-color: #4d677d;
}
.season-tab.active {
color: #08151e;
background: #dff7f2;
border-color: #dff7f2;
}
.candidate-list {
display: grid;
gap: 9px;
}
.candidate-card {
position: relative;
width: 100%;
padding: 13px;
cursor: pointer;
color: var(--text);
text-align: left;
background: #142334;
border: 1px solid #2b4054;
border-radius: 12px;
transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}
.candidate-card:hover {
transform: translateY(-1px);
background: #172a3c;
border-color: #4a6277;
}
.candidate-card.selected {
background: color-mix(in srgb, var(--route) 9%, #142334);
border-color: var(--route);
box-shadow: inset 3px 0 0 var(--route);
}
.candidate-top {
display: grid;
grid-template-columns: 10px 1fr auto;
gap: 10px;
align-items: center;
}
.route-swatch {
width: 9px;
height: 31px;
background: var(--route);
border-radius: 999px;
box-shadow: 0 0 14px color-mix(in srgb, var(--route) 45%, transparent);
}
.candidate-card strong {
display: block;
margin-bottom: 2px;
font-size: 14px;
}
.candidate-card small {
display: block;
color: var(--muted);
font-size: 11px;
}
.cost {
color: var(--route);
font-size: 13px;
font-weight: 800;
}
.season-track {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 4px;
margin-top: 11px;
}
.season-cell {
padding: 4px 0;
color: #728492;
text-align: center;
background: #0f1c2a;
border-radius: 5px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
.season-cell.open {
color: #9cebd8;
background: rgba(85, 224, 189, 0.12);
}
.card-note {
margin-top: 9px;
color: #8295a3;
font-size: 10px;
line-height: 1.4;
}
.current-plan {
min-height: 112px;
margin-top: 10px;
padding: 14px;
background: #0e1a27;
border: 1px solid #263a4e;
border-radius: 12px;
}
.plan-top {
display: flex;
justify-content: space-between;
gap: 10px;
align-items: center;
}
.plan-top strong {
font-size: 13px;
}
.status-pill {
padding: 5px 8px;
border-radius: 999px;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-pill.open {
color: #b8f8e9;
background: rgba(85, 224, 189, 0.14);
}
.status-pill.closed {
color: #ffc0c9;
background: rgba(255, 100, 124, 0.15);
}
.plan-copy {
margin: 10px 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.destination-chips {
display: flex;
flex-wrap: wrap;
gap: 5px;
}
.destination-chip {
padding: 4px 7px;
color: #aee9da;
background: rgba(85, 224, 189, 0.09);
border-radius: 5px;
font-size: 9px;
}
.destination-chip.missing {
color: #ffacb9;
background: rgba(255, 100, 124, 0.1);
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 12px;
}
.primary,
.secondary {
padding: 11px 13px;
cursor: pointer;
border-radius: 9px;
font-size: 12px;
font-weight: 800;
transition: 150ms ease;
}
.primary {
color: #07151c;
background: var(--mint);
border: 1px solid var(--mint);
}
.primary:hover:not(:disabled) {
background: #83ebcf;
transform: translateY(-1px);
}
.primary:disabled {
cursor: default;
opacity: 0.55;
}
.secondary {
color: var(--muted);
background: transparent;
border: 1px solid #3a5065;
}
.secondary:hover {
color: var(--text);
border-color: #71899d;
}
#feedback {
margin-top: 10px;
padding: 11px 12px;
border-radius: 9px;
font-size: 11px;
line-height: 1.5;
}
#feedback.success {
color: #c7f8e9;
background: rgba(85, 224, 189, 0.11);
border: 1px solid rgba(85, 224, 189, 0.3);
}
#feedback.failure {
color: #ffd0d7;
background: rgba(255, 100, 124, 0.1);
border: 1px solid rgba(255, 100, 124, 0.3);
}
.comparison-wrap {
overflow-x: auto;
border: 1px solid var(--line);
border-radius: 11px;
}
table {
width: 100%;
min-width: 365px;
border-collapse: collapse;
background: #0e1a27;
font-size: 10px;
}
th,
td {
padding: 8px 6px;
text-align: center;
border-bottom: 1px solid #233749;
}
th {
color: #8498a8;
background: #142335;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
th:first-child,
td:first-child {
width: 98px;
text-align: left;
padding-left: 9px;
}
tr:last-child td {
border-bottom: 0;
}
td.current-season {
background: rgba(255, 255, 255, 0.045);
box-shadow: inset 0 0 0 1px rgba(223, 247, 242, 0.12);
}
.row-route {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 5px;
border-radius: 50%;
}
.cell-score {
font-weight: 900;
}
.cell-score.ok {
color: #86e8cf;
}
.cell-score.off {
color: #ff8999;
}
.cell-names {
margin-top: 3px;
color: #8fa2af;
font-size: 8px;
letter-spacing: 0.03em;
}
.cut {
margin-top: 3px;
color: #e87889;
font-size: 8px;
}
.table-note {
margin: 8px 2px 0;
color: #718594;
font-size: 10px;
line-height: 1.45;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #101d2a;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.map-hud {
position: absolute;
z-index: 3;
top: 20px;
left: 20px;
right: 20px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 14px;
pointer-events: none;
}
.map-title,
.hud-chip {
background: rgba(8, 18, 28, 0.76);
border: 1px solid rgba(151, 187, 205, 0.2);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(10px);
}
.map-title {
padding: 12px 14px;
border-radius: 12px;
}
.map-title small {
display: block;
margin-bottom: 3px;
color: var(--mint);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.map-title strong {
font-size: 15px;
}
.hud-right {
display: flex;
gap: 7px;
}
.hud-chip {
padding: 9px 11px;
border-radius: 9px;
font-size: 10px;
font-weight: 700;
}
.hud-chip span {
color: var(--muted);
}
.map-footer {
position: absolute;
z-index: 3;
right: 18px;
bottom: 16px;
left: 18px;
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 16px;
pointer-events: none;
}
.legend,
.controls-hint {
padding: 10px 12px;
color: #b8c7d0;
background: rgba(8, 18, 28, 0.75);
border: 1px solid rgba(151, 187, 205, 0.18);
border-radius: 10px;
backdrop-filter: blur(10px);
font-size: 10px;
line-height: 1.55;
}
.legend div {
display: flex;
align-items: center;
gap: 7px;
}
.legend i {
display: inline-block;
width: 18px;
height: 4px;
border-radius: 99px;
}
.controls-hint {
color: #91a5b3;
text-align: right;
}
@media (max-width: 880px) {
body {
overflow: auto;
}
#app {
display: flex;
flex-direction: column;
height: auto;
min-height: 100vh;
}
#stage {
order: -1;
height: 58vh;
min-height: 430px;
}
aside {
overflow: visible;
border-right: 0;
border-top: 1px solid var(--line);
}
.map-hud {
top: 12px;
left: 12px;
right: 12px;
}
.hud-right {
flex-direction: column;
align-items: flex-end;
}
.map-footer {
right: 10px;
bottom: 10px;
left: 10px;
}
.controls-hint {
display: none;
}
}
</style>
</head>
<body>
<main id="app">
<aside>
<div class="eyebrow">Northvale Grid · Planning Brief 07</div>
<h1>One link.<br>Four seasons.</h1>
<p class="intro">
Harbor is the only settlement outside the existing all-season road
network. Choose one new connection and make sure it remains reliable
through winter, spring, summer, and autumn.
</p>
<div class="objective">
<strong>Your objective</strong>
<p>
Spend no more than 4 credits and keep all five destinations connected
to Base in every season.
</p>
</div>
<div class="budget">
<div class="budget-line">
<span>Selected connection cost</span>
<strong id="budget-amount">— / 4</strong>
</div>
<div class="budget-track"><div id="budget-fill"></div></div>
</div>
<div class="section-label">Preview season</div>
<div class="season-tabs" id="season-tabs"></div>
<div class="section-label">Candidate connections</div>
<div class="candidate-list" id="candidate-list"></div>
<div class="current-plan" id="current-plan"></div>
<div class="actions">
<button class="primary" id="commit-button">Commit this link</button>
<button class="secondary" id="reset-button" hidden>Reset</button>
</div>
<div id="feedback" aria-live="polite" hidden></div>
<div class="section-label">Route comparison</div>
<div class="comparison-wrap">
<table>
<thead>
<tr>
<th>Candidate</th>
<th>Win</th>
<th>Spr</th>
<th>Sum</th>
<th>Aut</th>
</tr>
</thead>
<tbody id="comparison-body"></tbody>
</table>
</div>
<p class="table-note">
Each cell shows the reachable destinations out of five and their
abbreviations. Existing roads remain open year-round.
</p>
</aside>
<section id="stage" aria-label="Interactive 3D infrastructure map">
<div class="map-hud">
<div class="map-title">
<small>Northvale Infrastructure Map</small>
<strong id="map-season">Winter preview</strong>
</div>
<div class="hud-right">
<div class="hud-chip"><span>Budget</span> 4 credits</div>
<div class="hud-chip" id="map-selection"><span>Plan</span> Not selected</div>
</div>
</div>
<div class="map-footer">
<div class="legend">
<div><i style="background:#d6b884"></i> Existing all-season road</div>
<div><i style="background:#55e0bd"></i> Selected candidate</div>
<div><i style="background:#ff647c"></i> Seasonal closure</div>
</div>
<div class="controls-hint">
Drag to orbit · Wheel to zoom<br>
Right-drag to pan · Click a colored link
</div>
</div>
</section>
</main>
<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.getElementById("stage");
const seasons = [
{
id: "winter",
name: "Winter",
short: "WIN",
sky: 0x101c2c,
fog: 0x101c2c,
ground: 0xdbe7e8,
water: 0x568ca5,
foliage: 0xc9dce0,
sun: 0xc9e7ff,
ambient: 0x9ebbd0
},
{
id: "spring",
name: "Spring",
short: "SPR",
sky: 0x182b35,
fog: 0x182b35,
ground: 0x76a86c,
water: 0x3d91a4,
foliage: 0xd9a8c5,
sun: 0xffead0,
ambient: 0xb4d7d0
},
{
id: "summer",
name: "Summer",
short: "SUM",
sky: 0x102b37,
fog: 0x102b37,
ground: 0x719f57,
water: 0x319bb0,
foliage: 0x3d8d52,
sun: 0xffe5ae,
ambient: 0xa9d6c0
},
{
id: "autumn",
name: "Autumn",
short: "AUT",
sky: 0x292329,
fog: 0x292329,
ground: 0x9c8757,
water: 0x477e89,
foliage: 0xcf713e,
sun: 0xffc98c,
ambient: 0xd2b49a
}
];
const nodes = {
base: { name: "Base", x: -6.0, z: 0.0, labelY: 1.75 },
grove: { name: "Grove", x: -3.3, z: -3.0, labelY: 1.50 },
ridge: { name: "Ridge", x: 0.6, z: -3.5, labelY: 1.75 },
summit: { name: "Summit", x: 5.0, z: -4.5, labelY: 2.10 },
falls: { name: "Falls", x: -2.5, z: 4.0, labelY: 1.45 },
harbor: { name: "Harbor", x: 5.0, z: 3.4, labelY: 1.55 }
};
const destinationIds = ["grove", "ridge", "summit", "falls", "harbor"];
const fixedEdges = [
["base", "grove"],
["grove", "ridge"],
["ridge", "summit"],
["grove", "falls"]
];
const candidates = [
{
id: "tunnel",
name: "North Tunnel",
from: "falls",
to: "harbor",
path: ["falls", [0.4, 4.6], [2.8, 3.4], "harbor"],
cost: 4,
color: "#55e0bd",
open: ["winter", "spring", "summer", "autumn"],
note: "All-season rock tunnel · no scheduled closures"
},
{
id: "bridge",
name: "River Swing",
from: "grove",
to: "harbor",
path: ["grove", [-0.6, -0.4], [2.2, 1.2], "harbor"],
cost: 3,
color: "#ffc857",
open: ["spring", "autumn"],
note: "Seasonal lift bridge · closed by ice and floodwater"
},
{
id: "pass",
name: "Goat Pass",
from: "summit",
to: "harbor",
path: ["summit", [5.3, -0.5], "harbor"],
cost: 3,
color: "#ff8f70",
open: ["spring", "summer"],
note: "Highland road · closed by snow and rockfall"
}
];
const candidateById = Object.fromEntries(
candidates.map(candidate => [candidate.id, candidate])
);
const abbreviations = {
grove: "G",
ridge: "R",
summit: "S",
falls: "F",
harbor: "H"
};
let currentSeason = "winter";
let selectedCandidate = null;
let committed = false;
let success = false;
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101c2c);
scene.fog = new THREE.Fog(0x101c2c, 22, 42);
const camera = new THREE.PerspectiveCamera(43, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb9d9ef, 0x344236, 1.75);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe4bd, 2.4);
sun.position.set(-7, 14, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x71b8d7, 0.65);
rimLight.position.set(9, 5, -9);
scene.add(rimLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xdbe7e8,
roughness: 0.94,
flatShading: true
});
const islandSideMaterial = new THREE.MeshStandardMaterial({
color: 0x5c665e,
roughness: 1,
flatShading: true
});
const island = new THREE.Mesh(
new THREE.CylinderGeometry(10.2, 8.8, 0.9, 16),
[islandSideMaterial, groundMaterial, islandSideMaterial]
);
island.position.y = -0.55;
island.receiveShadow = true;
scene.add(island);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x568ca5,
roughness: 0.36,
metalness: 0.08,
flatShading: true
});
const water = new THREE.Mesh(new THREE.CircleGeometry(60, 64), waterMaterial);
water.rotation.x = -Math.PI / 2;
water.position.y = -1.08;
water.receiveShadow = true;
scene.add(water);
const shoreline = new THREE.Mesh(
new THREE.TorusGeometry(10.05, 0.11, 5, 48),
new THREE.MeshStandardMaterial({ color: 0xd6c394, roughness: 1 })
);
shoreline.rotation.x = Math.PI / 2;
shoreline.position.y = -0.05;
scene.add(shoreline);
const foliageMaterials = [];
const snowCaps = [];
const flowers = [];
function makeLabel(text, color = "#dff7f2", width = 3.1) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, 512, 128);
const x = 12;
const y = 18;
const w = 488;
const h = 92;
const r = 22;
context.beginPath();
context.moveTo(x + r, y);
context.lineTo(x + w - r, y);
context.quadraticCurveTo(x + w, y, x + w, y + r);
context.lineTo(x + w, y + h - r);
context.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
context.lineTo(x + r, y + h);
context.quadraticCurveTo(x, y + h, x, y + h - r);
context.lineTo(x, y + r);
context.quadraticCurveTo(x, y, x + r, y);
context.closePath();
context.fillStyle = "rgba(8, 19, 29, 0.88)";
context.fill();
context.strokeStyle = color;
context.lineWidth = 4;
context.stroke();
context.fillStyle = "#f2f8fa";
context.font = "700 38px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 20;
return sprite;
}
function cylinderBetween(a, b, radius, material, radialSegments = 6) {
const start = new THREE.Vector3(a.x, a.y, a.z);
const end = new THREE.Vector3(b.x, b.y, b.z);
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function addMesh(group, geometry, material, x, y, z, rotationY = 0) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.rotation.y = rotationY;
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x76543d,
roughness: 1,
flatShading: true
});
const foliageMaterial = new THREE.MeshStandardMaterial({
color: 0x3d8d52,
roughness: 1,
flatShading: true
});
foliageMaterials.push(foliageMaterial);
addMesh(
group,
new THREE.CylinderGeometry(0.11, 0.15, 0.75, 5),
trunkMaterial,
0,
0.38,
0
);
addMesh(
group,
new THREE.ConeGeometry(0.48, 0.9, 6),
foliageMaterial,
0,
0.92,
0
);
addMesh(
group,
new THREE.ConeGeometry(0.34, 0.72, 6),
foliageMaterial,
0,
1.35,
0
);
scene.add(group);
return group;
}
function makeMountain(x, z, height, radius) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const mountainMaterial = new THREE.MeshStandardMaterial({
color: 0x69746e,
roughness: 1,
flatShading: true
});
addMesh(
group,
new THREE.ConeGeometry(radius, height, 5),
mountainMaterial,
0,
height / 2,
0
);
const snowMaterial = new THREE.MeshStandardMaterial({
color: 0xf2f7f6,
roughness: 1,
flatShading: true
});
const cap = addMesh(
group,
new THREE.ConeGeometry(radius * 0.39, height * 0.37, 5),
snowMaterial,
0,
height * 0.815,
0
);
cap.visible = false;
snowCaps.push(cap);
scene.add(group);
}
function makeFlower(x, z, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
flatShading: true
});
addMesh(
group,
new THREE.ConeGeometry(0.09, 0.22, 4),
material,
0,
0.11,
0
);
group.visible = false;
flowers.push(group);
scene.add(group);
}
function makeNodeModels() {
const cream = new THREE.MeshStandardMaterial({
color: 0xe8dcc2,
roughness: 0.85,
flatShading: true
});
const dark = new THREE.MeshStandardMaterial({
color: 0x354957,
roughness: 0.82,
flatShading: true
});
const teal = new THREE.MeshStandardMaterial({
color: 0x4da9a6,
roughness: 0.72,
flatShading: true
});
const rock = new THREE.MeshStandardMaterial({
color: 0x6e7774,
roughness: 1,
flatShading: true
});
const orange = new THREE.MeshStandardMaterial({
color: 0xe99b62,
roughness: 0.8,
flatShading: true
});
for (const node of Object.values(nodes)) {
const marker = new THREE.Mesh(
new THREE.CylinderGeometry(0.57, 0.64, 0.22, 6),
new THREE.MeshStandardMaterial({
color: 0x314b5c,
roughness: 0.82,
flatShading: true
})
);
marker.position.set(node.x, 0.08, node.z);
marker.receiveShadow = true;
scene.add(marker);
const label = makeLabel(node.name.toUpperCase(), "#7fe2c7", 2.55);
label.position.set(node.x, node.labelY, node.z);
scene.add(label);
}
// Base depot
addMesh(scene, new THREE.BoxGeometry(1.15, 0.75, 0.9), cream, -6, 0.47, 0);
addMesh(
scene,
new THREE.ConeGeometry(0.88, 0.48, 4),
dark,
-6,
1.05,
0,
Math.PI / 4
);
addMesh(scene, new THREE.BoxGeometry(0.24, 0.48, 0.24), orange, -5.7, 1.25, 0.24);
// Grove
makeTree(-3.8, -3.35, 0.8);
makeTree(-2.85, -3.45, 0.7);
makeTree(-3.6, -2.55, 0.58);
// Ridge rocks
addMesh(scene, new THREE.DodecahedronGeometry(0.52, 0), rock, 0.3, 0.35, -3.2);
addMesh(scene, new THREE.DodecahedronGeometry(0.35, 0), rock, 1.0, 0.26, -3.85);
// Summit flag and mountain
addMesh(scene, new THREE.CylinderGeometry(0.045, 0.055, 1.25, 6), cream, 5.0, 0.72, -4.5);
addMesh(scene, new THREE.BoxGeometry(0.72, 0.38, 0.055), orange, 5.34, 1.13, -4.5);
makeMountain(5.8, -5.15, 2.15, 1.2);
// Falls cliff and waterfall
addMesh(scene, new THREE.BoxGeometry(1.25, 0.7, 0.9), rock, -3.15, 0.36, 4.25);
addMesh(scene, new THREE.BoxGeometry(0.56, 0.7, 0.08), teal, -2.67, 0.38, 4.25);
addMesh(scene, new THREE.BoxGeometry(0.8, 0.11, 0.55), teal, -2.3, 0.06, 4.25);
// Harbor pier and sail
addMesh(scene, new THREE.BoxGeometry(1.3, 0.13, 0.55), cream, 5.35, 0.13, 3.55);
addMesh(scene, new THREE.CylinderGeometry(0.035, 0.045, 1.1, 6), cream, 5.75, 0.65, 3.55);
const sailGeometry = new THREE.BufferGeometry();
sailGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[0, 0, 0, 0.78, 0, 0, 0, 0.68, 0],
3
)
);
sailGeometry.computeVertexNormals();
const sail = new THREE.Mesh(
sailGeometry,
new THREE.MeshStandardMaterial({
color: 0xf1e9d6,
side: THREE.DoubleSide,
roughness: 0.8,
flatShading: true
})
);
sail.position.set(5.75, 0.75, 3.55);
scene.add(sail);
// Scenery
makeTree(-8.0, 1.5, 1.05);
makeTree(-7.6, -2.4, 0.9);
makeTree(-1.3, 6.1, 0.8);
makeTree(0.0, 6.8, 0.65);
makeTree(7.1, 0.7, 0.9);
makeTree(7.3, -1.5, 0.7);
makeTree(2.8, 6.1, 0.72);
makeMountain(-7.9, -4.6, 2.4, 1.35);
makeMountain(7.5, 5.4, 1.7, 1.0);
[
[-7.3, 2.5, 0xff8f9f],
[-6.7, 2.7, 0xffd166],
[-4.7, 5.5, 0xe99be0],
[0.6, 5.6, 0xffe28a],
[2.0, 5.9, 0xff9ca8],
[6.8, 2.1, 0xf4cf75]
].forEach(args => makeFlower(...args));
}
makeNodeModels();
const roadMaterial = new THREE.MeshStandardMaterial({
color: 0xd6b884,
roughness: 0.95,
flatShading: true
});
for (const [fromId, toId] of fixedEdges) {
const from = nodes[fromId];
const to = nodes[toId];
const road = cylinderBetween(
{ x: from.x, y: 0.09, z: from.z },
{ x: to.x, y: 0.09, z: to.z },
0.13,
roadMaterial,
6
);
scene.add(road);
}
const candidateMeshes = [];
const routeVisuals = {};
function resolvePath(path) {
return path.map(item => {
if (typeof item === "string") {
const node = nodes[item];
return { x: node.x, z: node.z };
}
return { x: item[0], z: item[1] };
});
}
for (const candidate of candidates) {
const group = new THREE.Group();
const path = resolvePath(candidate.path);
const material = new THREE.MeshStandardMaterial({
color: candidate.color,
emissive: candidate.color,
emissiveIntensity: 0.12,
roughness: 0.55,
metalness: 0.06,
transparent: true,
opacity: 0.5,
depthWrite: true
});
for (let i = 0; i < path.length - 1; i++) {
const a = path[i];
const b = path[i + 1];
const mesh = cylinderBetween(
{ x: a.x, y: 0.17, z: a.z },
{ x: b.x, y: 0.17, z: b.z },
candidate.id === "tunnel" ? 0.18 : 0.16,
material,
6
);
mesh.userData.candidateId = candidate.id;
candidateMeshes.push(mesh);
group.add(mesh);
}
const midpoint = path[Math.floor(path.length / 2)];
const label = makeLabel(
`${candidate.name.toUpperCase()} · ${candidate.cost}c`,
candidate.color,
candidate.id === "tunnel" ? 3.15 : 2.9
);
label.position.set(midpoint.x, 0.86, midpoint.z);
group.add(label);
const closure = new THREE.Group();
closure.position.set(midpoint.x, 0.28, midpoint.z);
const closureMaterial = new THREE.MeshBasicMaterial({ color: 0xff526f });
const bar1 = new THREE.Mesh(
new THREE.BoxGeometry(0.92, 0.09, 0.14),
closureMaterial
);
bar1.rotation.y = Math.PI / 4;
const bar2 = new THREE.Mesh(
new THREE.BoxGeometry(0.92, 0.09, 0.14),
closureMaterial
);
bar2.rotation.y = -Math.PI / 4;
closure.add(bar1, bar2);
closure.visible = false;
group.add(closure);
scene.add(group);
routeVisuals[candidate.id] = {
group,
material,
label,
closure
};
}
const pulseRing = new THREE.Mesh(
new THREE.TorusGeometry(0.92, 0.055, 6, 28),
new THREE.MeshBasicMaterial({
color: 0x55e0bd,
transparent: true,
opacity: 0.75,
depthWrite: false
})
);
pulseRing.rotation.x = Math.PI / 2;
pulseRing.position.set(nodes.harbor.x, 0.27, nodes.harbor.z);
pulseRing.visible = false;
scene.add(pulseRing);
// -------------------------------------------------------------------------
// Graph logic
// -------------------------------------------------------------------------
function reachableDestinations(candidate, seasonId) {
const adjacency = new Map(Object.keys(nodes).map(id => [id, []]));
function addEdge(a, b) {
adjacency.get(a).push(b);
adjacency.get(b).push(a);
}
fixedEdges.forEach(([a, b]) => addEdge(a, b));
if (candidate && candidate.open.includes(seasonId)) {
addEdge(candidate.from, candidate.to);
}
const visited = new Set(["base"]);
const queue = ["base"];
while (queue.length) {
const current = queue.shift();
for (const neighbor of adjacency.get(current)) {
if (!visited.has(neighbor)) {
visited.add(neighbor);
queue.push(neighbor);
}
}
}
return destinationIds.filter(id => visited.has(id));
}
// -------------------------------------------------------------------------
// Interface
// -------------------------------------------------------------------------
const seasonTabs = document.getElementById("season-tabs");
const candidateList = document.getElementById("candidate-list");
const comparisonBody = document.getElementById("comparison-body");
const currentPlan = document.getElementById("current-plan");
const budgetAmount = document.getElementById("budget-amount");
const budgetFill = document.getElementById("budget-fill");
const commitButton = document.getElementById("commit-button");
const resetButton = document.getElementById("reset-button");
const feedback = document.getElementById("feedback");
const mapSeason = document.getElementById("map-season");
const mapSelection = document.getElementById("map-selection");
seasonTabs.innerHTML = seasons.map(season => `
<button
class="season-tab${season.id === currentSeason ? " active" : ""}"
data-season="${season.id}"
aria-pressed="${season.id === currentSeason}"
>
${season.short}
</button>
`).join("");
candidateList.innerHTML = candidates.map(candidate => `
<button
class="candidate-card"
data-candidate="${candidate.id}"
style="--route:${candidate.color}"
aria-pressed="false"
>
<div class="candidate-top">
<span class="route-swatch"></span>
<div>
<strong>${candidate.name}</strong>
<small>${nodes[candidate.from].name} → ${nodes[candidate.to].name}</small>
</div>
<span class="cost">${candidate.cost} cr</span>
</div>
<div class="season-track">
${seasons.map(season => `
<span
class="season-cell${candidate.open.includes(season.id) ? " open" : ""}"
title="${season.name}: ${candidate.open.includes(season.id) ? "Open" : "Closed"}"
>
${season.short}
</span>
`).join("")}
</div>
<div class="card-note">${candidate.note}</div>
</button>
`).join("");
function updateSeasonButtons() {
document.querySelectorAll(".season-tab").forEach(button => {
const active = button.dataset.season === currentSeason;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
}
function updateRouteStyles() {
for (const candidate of candidates) {
const visual = routeVisuals[candidate.id];
const selected = candidate.id === selectedCandidate;
const open = candidate.open.includes(currentSeason);
const color = new THREE.Color(candidate.color);
if (selected && open) {
visual.material.color.copy(color);
visual.material.emissive.copy(color);
visual.material.emissiveIntensity = 0.72;
visual.material.opacity = 1;
} else if (selected && !open) {
visual.material.color.set(0xa85a69);
visual.material.emissive.set(0xff3f61);
visual.material.emissiveIntensity = 0.34;
visual.material.opacity = 0.44;
} else if (!selected && open) {
visual.material.color.copy(color);
visual.material.emissive.copy(color);
visual.material.emissiveIntensity = 0.13;
visual.material.opacity = 0.52;
} else {
visual.material.color.set(0x6f6470);
visual.material.emissive.set(0xff3f61);
visual.material.emissiveIntensity = 0.05;
visual.material.opacity = 0.17;
}
visual.label.material.opacity = selected ? 0.98 : 0.58;
visual.closure.visible = !open;
}
if (selectedCandidate) {
const candidate = candidateById[selectedCandidate];
pulseRing.visible = true;
pulseRing.material.color.set(success ? 0x79f0bb : candidate.color);
} else {
pulseRing.visible = false;
}
}
function updateCurrentPlan() {
if (!selectedCandidate) {
currentPlan.innerHTML = `
<div class="plan-top">
<strong>No connection selected</strong>
<span class="status-pill">Choose one</span>
</div>
<p class="plan-copy">
Select a candidate card or click a colored route on the map.
</p>
`;
return;
}
const candidate = candidateById[selectedCandidate];
const connected = reachableDestinations(candidate, currentSeason);
const missing = destinationIds.filter(id => !connected.includes(id));
const open = candidate.open.includes(currentSeason);
const season = seasons.find(s => s.id === currentSeason);
currentPlan.innerHTML = `
<div class="plan-top">
<strong>${candidate.name}</strong>
<span class="status-pill ${open ? "open" : "closed"}">
${open ? "Open" : "Closed"} in ${season.name}
</span>
</div>
<p class="plan-copy">
${
open
? "This connection is operational in the preview season."
: "This connection is unavailable in the preview season."
}
</p>
<div class="destination-chips">
${connected.map(id => `
<span class="destination-chip">${nodes[id].name}</span>
`).join("")}
${missing.map(id => `
<span class="destination-chip missing">${nodes[id].name} cut off</span>
`).join("")}
</div>
`;
}
function renderComparison() {
comparisonBody.innerHTML = candidates.map(candidate => {
const cells = seasons.map(season => {
const connected = reachableDestinations(candidate, season.id);
const missing = destinationIds.filter(id => !connected.includes(id));
const current = season.id === currentSeason;
const shortNames = connected.map(id => abbreviations[id]).join(" · ");
return `
<td class="${current ? "current-season" : ""}"
title="Connected: ${connected.map(id => nodes[id].name).join(", ")}">
<div class="cell-score ${missing.length ? "off" : "ok"}">
${connected.length}/5
</div>
<div class="cell-names">${shortNames}</div>
${
missing.length
? `<div class="cut">${missing.map(id => nodes[id].name).join(", ")} cut off</div>`
: ""
}
</td>
`;
}).join("");
return `
<tr>
<td>
<span class="row-route" style="background:${candidate.color}"></span>
${candidate.name}
</td>
${cells}
</tr>
`;
}).join("");
}
function updateBudget() {
if (!selectedCandidate) {
budgetAmount.textContent = "— / 4";
budgetFill.style.width = "0%";
return;
}
const candidate = candidateById[selectedCandidate];
budgetAmount.textContent = `${candidate.cost} / 4`;
budgetFill.style.width = `${Math.min(100, candidate.cost / 4 * 100)}%`;
}
function updateMapHUD() {
const season = seasons.find(s => s.id === currentSeason);
mapSeason.textContent = `${season.name} preview`;
mapSelection.innerHTML = selectedCandidate
? `<span>Plan</span> ${candidateById[selectedCandidate].name}`
: `<span>Plan</span> Not selected`;
}
function clearFeedback() {
feedback.hidden = true;
feedback.className = "";
feedback.textContent = "";
}
function selectCandidate(id) {
if (committed && id !== selectedCandidate) {
committed = false;
success = false;
commitButton.disabled = false;
resetButton.hidden = true;
clearFeedback();
}
selectedCandidate = id;
document.querySelectorAll(".candidate-card").forEach(button => {
const active = button.dataset.candidate === id;
button.classList.toggle("selected", active);
button.setAttribute("aria-pressed", String(active));
});
updateBudget();
updateCurrentPlan();
updateRouteStyles();
updateMapHUD();
renderComparison();
}
function commitPlan() {
if (!selectedCandidate) {
feedback.hidden = false;
feedback.className = "failure";
feedback.textContent = "Select a connection before committing the plan.";
return;
}
const candidate = candidateById[selectedCandidate];
if (candidate.cost > 4) {
feedback.hidden = false;
feedback.className = "failure";
feedback.textContent =
`${candidate.name} costs ${candidate.cost} credits, exceeding the fixed budget of 4.`;
return;
}
const allSeasonsWork = seasons.every(season =>
reachableDestinations(candidate, season.id).length === destinationIds.length
);
if (!allSeasonsWork) {
const closedSeasons = seasons
.filter(season => !candidate.open.includes(season.id))
.map(season => season.name);
feedback.hidden = false;
feedback.className = "failure";
feedback.textContent =
`${candidate.name} fits the budget, but it closes in ${closedSeasons.join(" and ")}. ` +
`The connection must remain available in every season.`;
return;
}
committed = true;
success = true;
commitButton.disabled = true;
resetButton.hidden = false;
feedback.hidden = false;
feedback.className = "success";
feedback.textContent =
`${candidate.name} stays open in all four seasons and costs exactly ` +
`${candidate.cost} credits. Every destination remains connected to Base.`;
updateRouteStyles();
}
seasonTabs.addEventListener("click", event => {
const button = event.target.closest("[data-season]");
if (!button) return;
currentSeason = button.dataset.season;
updateSeasonButtons();
updateCurrentPlan();
updateRouteStyles();
updateMapHUD();
renderComparison();
});
candidateList.addEventListener("click", event => {
const button = event.target.closest("[data-candidate]");
if (button) selectCandidate(button.dataset.candidate);
});
commitButton.addEventListener("click", commitPlan);
resetButton.addEventListener("click", () => {
committed = false;
success = false;
selectedCandidate = null;
commitButton.disabled = false;
resetButton.hidden = true;
clearFeedback();
document.querySelectorAll(".candidate-card").forEach(button => {
button.classList.remove("selected");
button.setAttribute("aria-pressed", "false");
});
updateBudget();
updateCurrentPlan();
updateRouteStyles();
updateMapHUD();
renderComparison();
});
// -------------------------------------------------------------------------
// Seasonal presentation
// -------------------------------------------------------------------------
function applySeason() {
const season = seasons.find(s => s.id === currentSeason);
scene.background.setHex(season.sky);
scene.fog.color.setHex(season.fog);
groundMaterial.color.setHex(season.ground);
waterMaterial.color.setHex(season.water);
sun.color.setHex(season.sun);
hemisphere.color.setHex(season.ambient);
foliageMaterials.forEach(material => material.color.setHex(season.foliage));
snowCaps.forEach(cap => cap.visible = currentSeason === "winter");
flowers.forEach(flower => flower.visible = currentSeason === "spring");
}
// -------------------------------------------------------------------------
// Custom camera controls: orbit, zoom, and pan
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0, 0),
radius: 19,
phi: 0.90,
theta: 0.58,
desiredRadius: 19,
desiredPhi: 0.90,
desiredTheta: 0.58
};
const pointers = new Map();
let drag = null;
let pinchDistance = 0;
let pinchStartRadius = 19;
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function updateCamera() {
controls.radius +=
(controls.desiredRadius - controls.radius) * 0.12;
controls.phi +=
(controls.desiredPhi - controls.phi) * 0.12;
controls.theta +=
(controls.desiredTheta - controls.theta) * 0.12;
const spherical = new THREE.Spherical(
controls.radius,
controls.phi,
controls.theta
);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
}
function candidateAtPointer(event) {
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 hits = raycaster.intersectObjects(candidateMeshes, false);
return hits.length ? hits[0].object.userData.candidateId : null;
}
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
startX: event.clientX,
startY: event.clientY,
button: event.button,
moved: false
};
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
pinchStartRadius = controls.desiredRadius;
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) {
const hovered = candidateAtPointer(event);
renderer.domElement.style.cursor = hovered ? "pointer" : "grab";
return;
}
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
controls.desiredRadius = THREE.MathUtils.clamp(
pinchStartRadius * pinchDistance / distance,
10,
28
);
}
return;
}
if (!drag || drag.id !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
const totalDistance = Math.hypot(
event.clientX - drag.startX,
event.clientY - drag.startY
);
if (totalDistance > 5) drag.moved = true;
if (drag.button === 2 || event.shiftKey) {
camera.updateMatrixWorld();
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3()
.subVectors(controls.target, camera.position);
forward.y = 0;
forward.normalize();
const scale = controls.desiredRadius * 0.0015;
controls.target
.addScaledVector(right, -dx * scale)
.addScaledVector(forward, -dy * scale);
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -5, 5);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -5, 5);
} else {
controls.desiredTheta -= dx * 0.006;
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi - dy * 0.005,
0.28,
1.34
);
}
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointerup", event => {
if (drag && drag.id === event.pointerId && !drag.moved && event.button === 0) {
const candidateId = candidateAtPointer(event);
if (candidateId) selectCandidate(candidateId);
}
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (pointers.size === 0) drag = null;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", event => {
pointers.delete(event.pointerId);
drag = null;
pinchDistance = 0;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius + event.deltaY * 0.012,
10,
28
);
}, { passive: false });
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
applySeason();
updateSeasonButtons();
updateCurrentPlan();
updateRouteStyles();
updateBudget();
updateMapHUD();
renderComparison();
resize();
updateCamera();
renderer.setAnimationLoop(() => {
updateCamera();
if (pulseRing.visible) {
const pulse = 1 + Math.sin(performance.now() * 0.004) * 0.09;
pulseRing.scale.setScalar(pulse);
pulseRing.material.opacity = 0.55 + Math.sin(performance.now() * 0.004) * 0.18;
}
renderer.render(scene, camera);
});
</script>
</body>
</html>
```