Prompt specification
Build or customize the Three.js 3D scene "Original River-Rail Market Hub" 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: Original River-Rail Market Hub
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/original-river-rail-market-hub-x2103
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: original river-rail market hub. Build a compact hub linking boat, rail, and handcart routes around a market. Make transfer points and storage buffers visible with a few tracked shipments. Return one self-contained HTML file.
Working Three.js Starter (original-river-rail-market-hub-x2103):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tide & Track — River–Rail Market Hub</title>
<style>
:root {
--ink: #15353a;
--muted: #5d7776;
--panel: rgba(248, 246, 233, 0.88);
--line: rgba(21, 53, 58, 0.14);
--river: #16a7b8;
--rail: #e76f3c;
--cart: #a6539d;
--gold: #efb84d;
--shadow: 0 16px 50px rgba(29, 67, 68, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bdd7d1;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
pointer-events: auto;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
color: #456866;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #42b88d;
box-shadow: 0 0 0 4px rgba(66, 184, 141, 0.18);
}
h1 {
margin: 0;
font-size: clamp(26px, 4vw, 48px);
line-height: 0.95;
letter-spacing: -0.055em;
font-weight: 900;
text-transform: uppercase;
}
.brand p {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.04em;
}
.panel {
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.52);
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(1.15);
-webkit-backdrop-filter: blur(16px) saturate(1.15);
}
.tracker {
position: absolute;
top: 24px;
right: 24px;
width: 292px;
border-radius: 18px;
overflow: hidden;
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 15px 17px 12px;
border-bottom: 1px solid var(--line);
}
.panel-title {
font-size: 11px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.pulse {
display: inline-flex;
align-items: center;
gap: 6px;
color: #398f71;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
}
.pulse::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
animation: pulse 1.5s infinite;
}
@keyframes pulse {
50% { opacity: 0.35; transform: scale(0.75); }
}
.shipment {
padding: 13px 17px;
border-bottom: 1px solid var(--line);
}
.shipment:last-child { border-bottom: 0; }
.shipment-top,
.shipment-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.shipment-id {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.02em;
}
.route-chip {
width: 8px;
height: 8px;
border-radius: 2px;
box-shadow: 0 0 0 3px rgba(0,0,0,0.04);
}
.route-chip.river { background: var(--river); }
.route-chip.rail { background: var(--rail); }
.route-chip.cart { background: var(--cart); }
.shipment-status {
color: var(--muted);
font-size: 10px;
font-weight: 750;
text-transform: uppercase;
letter-spacing: 0.06em;
}
.shipment-bottom {
margin-top: 9px;
color: var(--muted);
font-size: 10px;
}
.bar {
height: 4px;
margin-top: 7px;
overflow: hidden;
border-radius: 5px;
background: rgba(21, 53, 58, 0.1);
}
.bar > span {
display: block;
height: 100%;
width: 0;
border-radius: inherit;
transition: width 0.25s linear;
}
.shipment.river .bar > span { background: var(--river); }
.shipment.rail .bar > span { background: var(--rail); }
.shipment.cart .bar > span { background: var(--cart); }
.inspector {
position: absolute;
left: 26px;
bottom: 25px;
width: 284px;
padding: 15px 17px;
border-radius: 16px;
pointer-events: auto;
}
.inspector-label {
margin-bottom: 5px;
color: #78908d;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.inspector h2 {
margin: 0 0 5px;
font-size: 17px;
letter-spacing: -0.02em;
}
.inspector p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.controls {
position: absolute;
left: 50%;
bottom: 24px;
display: flex;
gap: 7px;
padding: 7px;
border-radius: 15px;
transform: translateX(-50%);
pointer-events: auto;
}
button {
min-height: 36px;
padding: 0 13px;
border: 0;
border-radius: 10px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
cursor: pointer;
transition: background 0.18s, color 0.18s, transform 0.18s;
}
button:hover {
background: rgba(21, 53, 58, 0.08);
}
button:active { transform: translateY(1px); }
button.active,
button.primary {
background: var(--ink);
color: #f8f6e9;
}
.legend {
position: absolute;
right: 24px;
bottom: 25px;
display: flex;
gap: 13px;
padding: 11px 14px;
border-radius: 13px;
pointer-events: auto;
font-size: 10px;
font-weight: 750;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 15px;
height: 3px;
border-radius: 4px;
}
.legend .r { background: var(--river); }
.legend .t { background: var(--rail); }
.legend .h { background: var(--cart); }
#labelLayer {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
}
#labelLayer.hidden { display: none; }
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(255,255,255,0.55);
border-radius: 8px;
background: rgba(248, 246, 233, 0.88);
box-shadow: 0 7px 18px rgba(22, 62, 65, 0.14);
color: #214348;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -100%);
will-change: left, top;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 12px;
background: rgba(33, 67, 72, 0.45);
}
.world-label i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--dot, var(--gold));
}
.hint {
position: absolute;
right: 25px;
top: 314px;
color: rgba(31, 70, 73, 0.68);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-align: right;
}
@media (max-width: 900px) {
.brand { top: 17px; left: 17px; }
.tracker { top: 15px; right: 15px; width: 245px; }
.inspector { left: 15px; bottom: 76px; width: 245px; }
.controls { bottom: 14px; }
.legend { display: none; }
.hint { display: none; }
.brand p { display: none; }
}
@media (max-width: 620px) {
.brand h1 { font-size: 25px; }
.brand .eyebrow { font-size: 8px; }
.tracker {
top: auto;
right: 12px;
bottom: 69px;
width: 210px;
}
.shipment { padding: 9px 12px; }
.shipment-bottom { display: none; }
.inspector { display: none; }
.controls {
width: calc(100% - 24px);
justify-content: center;
overflow-x: auto;
}
button { padding: 0 10px; white-space: nowrap; }
.view-btn { display: none; }
}
</style>
</head>
<body>
<div class="ui">
<header class="brand">
<div class="eyebrow"><span class="live-dot"></span> Interchange operating normally</div>
<h1>Tide & Track</h1>
<p>River–rail market hub · Dock 04 / Yard 02</p>
</header>
<aside class="panel tracker" aria-label="Tracked shipments">
<div class="panel-head">
<span class="panel-title">Shipment pulse</span>
<span class="pulse">Live</span>
</div>
<div class="shipment river">
<div class="shipment-top">
<span class="shipment-id"><i class="route-chip river"></i> SHP–041</span>
<span class="shipment-status" id="status-river">Loading</span>
</div>
<div class="shipment-bottom"><span>West slip → Quay</span><span id="pct-river">0%</span></div>
<div class="bar"><span id="bar-river"></span></div>
</div>
<div class="shipment rail">
<div class="shipment-top">
<span class="shipment-id"><i class="route-chip rail"></i> SHP–118</span>
<span class="shipment-status" id="status-rail">Loading</span>
</div>
<div class="shipment-bottom"><span>Platform → East buffer</span><span id="pct-rail">0%</span></div>
<div class="bar"><span id="bar-rail"></span></div>
</div>
<div class="shipment cart">
<div class="shipment-top">
<span class="shipment-id"><i class="route-chip cart"></i> SHP–226</span>
<span class="shipment-status" id="status-cart">Loading</span>
</div>
<div class="shipment-bottom"><span>Rail platform → Dock</span><span id="pct-cart">0%</span></div>
<div class="bar"><span id="bar-cart"></span></div>
</div>
</aside>
<section class="panel inspector" id="inspector">
<div class="inspector-label">Transfer point</div>
<h2 id="inspectorTitle">Select a beacon</h2>
<p id="inspectorText">Click a glowing transfer marker to inspect its exchange role.</p>
</section>
<nav class="panel controls" aria-label="Scene controls">
<button id="pauseBtn">Pause</button>
<button id="routeBtn" class="active">Routes</button>
<button id="labelBtn" class="active">Labels</button>
<button id="allBtn" class="active view-btn">All</button>
<button class="view-btn" data-view="river">River</button>
<button class="view-btn" data-view="rail">Rail</button>
<button id="resetBtn">Reset view</button>
</nav>
<div class="panel legend" aria-label="Route legend">
<span><i class="r"></i> River</span>
<span><i class="t"></i> Rail</span>
<span><i class="h"></i> Handcart</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom<br>Select a transfer beacon</div>
</div>
<div id="labelLayer"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = id => document.getElementById(id);
const clamp = THREE.MathUtils.clamp;
// ─────────────────────────────────────────────────────────────
// Renderer, atmosphere, and camera
// ─────────────────────────────────────────────────────────────
const scene = new THREE.Scene();
scene.background = new THREE.Color("#bdd7d1");
scene.fog = new THREE.Fog("#bdd7d1", 31, 55);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(37, innerWidth / innerHeight, 0.1, 100);
const hemi = new THREE.HemisphereLight("#e9fff7", "#7f8065", 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff0c9", 3.2);
sun.position.set(-13, 23, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 23;
sun.shadow.camera.bottom = -23;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.0008;
scene.add(sun);
const fill = new THREE.DirectionalLight("#9dd8dd", 0.65);
fill.position.set(12, 8, -15);
scene.add(fill);
const view = {
yaw: 0.72,
pitch: 0.62,
radius: 27,
target: new THREE.Vector3(0, 0.3, -0.5)
};
const goal = {
yaw: view.yaw,
pitch: view.pitch,
radius: view.radius,
target: view.target.clone()
};
function updateCamera() {
const cp = Math.cos(view.pitch);
camera.position.set(
view.target.x + view.radius * Math.sin(view.yaw) * cp,
view.target.y + view.radius * Math.sin(view.pitch),
view.target.z + view.radius * Math.cos(view.yaw) * cp
);
camera.lookAt(view.target);
}
// ─────────────────────────────────────────────────────────────
// Shared voxel geometry and static instanced builder
// ─────────────────────────────────────────────────────────────
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const staticBoxes = [];
const materialCache = new Map();
function v(x, y, z, sx, sy, sz, color, ry = 0) {
staticBoxes.push({ x, y, z, sx, sy, sz, color: new THREE.Color(color), ry });
}
function flushStaticVoxels() {
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.82,
metalness: 0.02
});
const mesh = new THREE.InstancedMesh(cubeGeometry, material, staticBoxes.length);
const dummy = new THREE.Object3D();
staticBoxes.forEach((b, i) => {
dummy.position.set(b.x, b.y, b.z);
dummy.rotation.set(0, b.ry, 0);
dummy.scale.set(b.sx, b.sy, b.sz);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
mesh.setColorAt(i, b.color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
scene.add(mesh);
}
function getMaterial(color, emissive = false) {
const key = color + (emissive ? "-glow" : "");
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: emissive ? 0.4 : 0.76,
metalness: emissive ? 0.08 : 0.02,
emissive: emissive ? color : 0x000000,
emissiveIntensity: emissive ? 1.15 : 0
}));
}
return materialCache.get(key);
}
function box(parent, x, y, z, sx, sy, sz, color, emissive = false) {
const mesh = new THREE.Mesh(cubeGeometry, getMaterial(color, emissive));
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
let s = seed >>> 0;
return () => {
s = (s * 1664525 + 1013904223) >>> 0;
return s / 4294967296;
};
}
const random = seededRandom(4027);
// ─────────────────────────────────────────────────────────────
// Terrain, quay, rail infrastructure
// ─────────────────────────────────────────────────────────────
v(0, -0.72, -3.6, 28, 1.35, 13.3, "#b6aa87");
v(0, -0.83, 5.75, 28, 0.65, 5.6, "#1f6975");
const paving = ["#c8bd99", "#beb48e", "#d1c6a3", "#b9af8b"];
for (let x = -12; x <= 12; x += 2) {
for (let z = -9; z <= 2; z += 2) {
v(x, 0.015, z, 1.95, 0.08, 1.95, paving[Math.floor(random() * paving.length)]);
}
}
// River-facing quay wall.
for (let x = -13.5; x < 14; x += 1) {
v(x, 0.02, 2.88, 0.96, 0.9, 0.62, x % 2 < 1 ? "#756e59" : "#81775f");
}
v(0, 0.48, 2.82, 28, 0.16, 0.8, "#d5c9a5");
// Rail bed and sleepers.
v(0, 0.07, -6.58, 27, 0.16, 2.1, "#817f70");
for (let x = -13; x <= 13; x += 0.82) {
v(x, 0.17, -6.58, 0.28, 0.16, 1.75, "#665244");
}
v(0, 0.29, -6.95, 27, 0.12, 0.11, "#49575a");
v(0, 0.29, -6.22, 27, 0.12, 0.11, "#49575a");
// Rail platform.
v(-5.7, 0.22, -5.15, 8.2, 0.4, 1.72, "#c9b98f");
v(-5.7, 0.45, -5.93, 8.2, 0.12, 0.18, "#efb84d");
// Small river–rail station.
v(-7.2, 1.2, -8.65, 4.7, 2.35, 2.25, "#b95f49");
v(-7.2, 2.48, -8.65, 5.2, 0.28, 2.75, "#315a5b");
v(-8.42, 1.38, -7.48, 0.65, 0.72, 0.08, "#f4d981");
v(-6.0, 1.38, -7.48, 0.65, 0.72, 0.08, "#f4d981");
v(-7.2, 0.73, -7.47, 1.05, 1.45, 0.1, "#314d4c");
v(-8.95, 1.05, -7.32, 0.18, 2.05, 0.18, "#f1e1b7");
v(-9.92, 0.1, -7.32, 2.3, 0.2, 0.7, "#d4c49a");
// ─────────────────────────────────────────────────────────────
// Market stalls, warehouses, crates, people, and vegetation
// ─────────────────────────────────────────────────────────────
function staticCrate(x, y, z, color, s = 0.7) {
v(x, y + s * 0.5, z, s, s, s, color);
v(x, y + s * 0.5, z + s * 0.51, s * 1.02, s * 0.12, 0.035, "#f1d68b");
v(x + s * 0.51, y + s * 0.5, z, 0.035, s * 1.01, s * 0.15, "#70523b");
}
function stall(x, z, roof, accent) {
v(x, 0.57, z, 2.15, 1.02, 1.05, "#8a5b3e");
v(x, 0.58, z + 0.54, 2.18, 0.75, 0.1, accent);
v(x - 0.98, 1.42, z - 0.48, 0.12, 2.0, 0.12, "#644736");
v(x + 0.98, 1.42, z - 0.48, 0.12, 2.0, 0.12, "#644736");
v(x - 0.98, 1.42, z + 0.48, 0.12, 2.0, 0.12, "#644736");
v(x + 0.98, 1.42, z + 0.48, 0.12, 2.0, 0.12, "#644736");
for (let i = 0; i < 4; i++) {
v(x - 0.83 + i * 0.55, 2.38, z, 0.55, 0.2, 1.65, i % 2 ? accent : roof);
}
v(x, 1.16, z + 0.42, 0.42, 0.26, 0.25, "#e7b44a");
v(x + 0.42, 1.18, z + 0.38, 0.34, 0.3, 0.28, "#bd5948");
v(x - 0.47, 1.15, z + 0.4, 0.3, 0.25, 0.3, "#6ba05d");
}
stall(-3.0, -2.65, "#d76047", "#f1d27b");
stall(0.0, -3.05, "#287f78", "#efb84d");
stall(3.05, -2.65, "#6f5b9d", "#efd7a1");
stall(-3.05, 0.30, "#e4a83e", "#d55d4e");
stall(0.25, 0.55, "#d85f4e", "#f2d997");
stall(3.05, 0.25, "#3f8b81", "#e8b54d");
// Open-front warehouse.
v(7.0, 0.12, -4.15, 5.25, 0.28, 4.25, "#8d8065");
v(7.0, 1.35, -6.05, 5.25, 2.45, 0.32, "#d18451");
v(4.5, 1.35, -4.15, 0.32, 2.45, 4.2, "#d18451");
v(9.5, 1.35, -4.15, 0.32, 2.45, 4.2, "#d18451");
v(7.0, 2.68, -4.15, 5.7, 0.3, 4.65, "#355f61");
v(7.0, 1.1, -1.99, 2.05, 1.95, 0.12, "#334747");
v(7.0, 2.15, -1.79, 3.1, 0.18, 0.78, "#e9b84e");
for (let x = 5.25; x < 9; x += 0.72) {
v(x, 2.33, -1.35, 0.22, 0.18, 0.6, "#f0d89b");
}
// Storage buffer shed.
v(-9.15, 0.12, -2.05, 4.2, 0.24, 3.5, "#8d8068");
v(-9.15, 2.55, -2.05, 4.65, 0.25, 3.9, "#65767a");
v(-11.12, 1.25, -2.05, 0.2, 2.35, 3.5, "#8a7257");
v(-7.18, 1.25, -2.05, 0.2, 2.35, 3.5, "#8a7257");
v(-9.15, 1.35, -3.7, 4.2, 2.4, 0.18, "#8a7257");
const crateColors = ["#bd664d", "#d49a48", "#5d8f72", "#567f9b", "#9a715f"];
for (let i = 0; i < 12; i++) {
const x = -10.7 + (i % 4) * 0.82;
const z = -3.0 + Math.floor(i / 4) * 1.05;
staticCrate(x, 0.25, z, crateColors[i % crateColors.length], 0.66);
}
for (let i = 0; i < 7; i++) {
staticCrate(5.5 + (i % 3) * 0.9, 0.28, -5.45 + Math.floor(i / 3) * 0.9, crateColors[i % 5], 0.72);
}
staticCrate(-10.15, 1.15, -2.85, "#d49a48", 0.68);
staticCrate(-9.25, 1.15, -2.85, "#567f9b", 0.68);
staticCrate(-8.35, 1.15, -2.85, "#bd664d", 0.68);
// Quay crane and loading apron.
v(10.15, 1.75, 2.32, 0.38, 3.5, 0.38, "#e7ad3f");
v(9.0, 3.43, 2.32, 3.05, 0.28, 0.3, "#e7ad3f");
v(10.9, 3.0, 2.32, 0.8, 0.6, 0.7, "#536b69");
v(7.75, 2.27, 2.32, 0.08, 2.25, 0.08, "#394d4d");
v(7.75, 1.12, 2.32, 0.38, 0.22, 0.3, "#394d4d");
v(8.55, 0.08, 2.35, 4.4, 0.16, 1.8, "#b79c6d");
// Voxel people.
function person(x, z, shirt, skin = "#c58f68") {
v(x - 0.11, 0.28, z, 0.16, 0.48, 0.2, "#384a4a");
v(x + 0.11, 0.28, z, 0.16, 0.48, 0.2, "#384a4a");
v(x, 0.73, z, 0.48, 0.62, 0.3, shirt);
v(x, 1.19, z, 0.31, 0.31, 0.31, skin);
}
person(-4.0, -2.0, "#cf604a");
person(-1.1, -2.2, "#317b78");
person(2.0, -1.7, "#6f5b9d");
person(4.0, 0.7, "#d9a543");
person(-2.1, 0.9, "#467e9d");
person(1.2, 1.0, "#d06455");
person(-7.0, -4.6, "#3e8173");
person(8.0, 1.3, "#b96b48");
person(-10.7, -0.6, "#755d8e");
function tree(x, z, s = 1) {
v(x, 0.8 * s, z, 0.28 * s, 1.6 * s, 0.28 * s, "#76573d");
v(x, 1.9 * s, z, 1.35 * s, 1.25 * s, 1.25 * s, "#4f8063");
v(x - 0.48 * s, 2.55 * s, z + 0.1 * s, 0.9 * s, 0.8 * s, 0.9 * s, "#65936d");
v(x + 0.42 * s, 1.9 * s, z - 0.2 * s, 0.95 * s, 0.9 * s, 0.9 * s, "#3f7058");
}
tree(11.7, -8.2, 1.15);
tree(-12.0, -7.5, 0.95);
tree(11.8, -0.2, 0.85);
tree(-12.0, 1.2, 0.75);
// Handcart road.
const cartPoints = [
new THREE.Vector3(-5.6, 0.13, -4.72),
new THREE.Vector3(-3.8, 0.13, -4.38),
new THREE.Vector3(-2.0, 0.13, -2.25),
new THREE.Vector3(0.0, 0.13, -0.78),
new THREE.Vector3(2.3, 0.13, -0.15),
new THREE.Vector3(5.0, 0.13, 1.28),
new THREE.Vector3(8.2, 0.13, 2.32)
];
const cartCurve = new THREE.CatmullRomCurve3(cartPoints, false, "catmullrom", 0.25);
function roadSegment(a, b, color) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const count = Math.max(1, Math.floor(length / 0.52));
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const x = THREE.MathUtils.lerp(a.x, b.x, t);
const z = THREE.MathUtils.lerp(a.z, b.z, t);
v(x, 0.10, z, length / count + 0.03, 0.09, 1.08, color, -Math.atan2(dz, dx));
}
}
for (let i = 0; i < cartPoints.length - 1; i++) {
roadSegment(cartPoints[i], cartPoints[i + 1], i % 2 ? "#d0c19b" : "#c7b891");
}
flushStaticVoxels();
// ─────────────────────────────────────────────────────────────
// Animated water surface
// ─────────────────────────────────────────────────────────────
const waterMaterial = new THREE.ShaderMaterial({
uniforms: {
uTime: { value: 0 },
uDeep: { value: new THREE.Color("#287d8c") },
uShallow: { value: new THREE.Color("#65b6b3") }
},
vertexShader: `
uniform float uTime;
varying vec2 vUv;
varying float vWave;
void main() {
vUv = uv;
vec3 p = position;
float wave = sin(p.x * 1.35 + uTime * 1.1) * 0.035
+ sin(p.y * 2.0 - uTime * 0.8) * 0.025;
p.z += wave;
vWave = wave;
gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
}
`,
fragmentShader: `
uniform float uTime;
uniform vec3 uDeep;
uniform vec3 uShallow;
varying vec2 vUv;
varying float vWave;
void main() {
float band = sin(vUv.x * 92.0 + uTime * 1.5) * 0.5 + 0.5;
band = smoothstep(0.91, 1.0, band) * 0.18;
float depthMix = smoothstep(0.0, 1.0, vUv.y) * 0.28;
vec3 color = mix(uDeep, uShallow, depthMix + vWave * 2.0);
color += band;
gl_FragColor = vec4(color, 1.0);
}
`
});
const water = new THREE.Mesh(new THREE.PlaneGeometry(28, 5.5, 64, 16), waterMaterial);
water.rotation.x = -Math.PI / 2;
water.position.set(0, -0.24, 5.72);
scene.add(water);
const ripples = [];
const rippleMaterial = new THREE.MeshBasicMaterial({
color: "#e2f0d9",
transparent: true,
opacity: 0.32,
depthWrite: false
});
for (let i = 0; i < 22; i++) {
const r = new THREE.Mesh(cubeGeometry, rippleMaterial.clone());
r.position.set(-13 + random() * 26, -0.14, 3.35 + random() * 4.7);
r.scale.set(0.35 + random() * 1.1, 0.018, 0.035);
r.userData.speed = 0.18 + random() * 0.35;
scene.add(r);
ripples.push(r);
}
// ─────────────────────────────────────────────────────────────
// Route lines
// ─────────────────────────────────────────────────────────────
const routeGroup = new THREE.Group();
scene.add(routeGroup);
function addRoute(points, color, dashSize, gapSize) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
dashSize,
gapSize,
transparent: true,
opacity: 0.88,
depthTest: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
line.renderOrder = 4;
routeGroup.add(line);
return line;
}
addRoute(
Array.from({ length: 80 }, (_, i) => new THREE.Vector3(-12.5 + i * 0.32, 0.04, 5.25)),
"#25c1ca", 0.48, 0.28
);
addRoute(
Array.from({ length: 80 }, (_, i) => new THREE.Vector3(-12.5 + i * 0.32, 0.38, -6.58)),
"#f07a43", 0.48, 0.28
);
addRoute(cartCurve.getPoints(100).map(p => p.clone().setY(0.2)), "#b968b1", 0.42, 0.22);
// ─────────────────────────────────────────────────────────────
// Transfer beacons
// ─────────────────────────────────────────────────────────────
const transferHits = [];
const transfers = [];
function makeTransfer(x, z, color, name, detail) {
const padY = 0.22;
for (let i = 0; i < 8; i++) {
const a = i * Math.PI / 4;
v(x + Math.cos(a) * 0.72, padY, z + Math.sin(a) * 0.72, 0.28, 0.12, 0.28, color, -a);
}
const group = new THREE.Group();
group.position.set(x, 0, z);
box(group, 0, 0.78, 0, 0.12, 1.55, 0.12, "#3c5353");
const glow = box(group, 0, 1.61, 0, 0.28, 0.28, 0.28, color, true);
box(group, 0, 1.25, 0, 0.5, 0.08, 0.5, color);
const hit = new THREE.Mesh(
cubeGeometry,
new THREE.MeshBasicMaterial({ transparent: true, opacity: 0, depthWrite: false })
);
hit.position.set(x, 0.9, z);
hit.scale.set(1.5, 2, 1.5);
hit.userData = { name, detail, color };
scene.add(hit);
transferHits.push(hit);
scene.add(group);
transfers.push({ group, glow });
}
makeTransfer(-5.55, -4.72, "#eea83e", "Rail platform", "Flat-cart interchange: rail crates are broken down here before market delivery.");
makeTransfer(0.0, -0.78, "#b65aa7", "Market crossdock", "The central exchange connects the rail platform, riverside quay, and six market bays.");
makeTransfer(8.25, 2.32, "#20aeb9", "Quay exchange", "River cargo lands here for direct transfer to handcart storage along the market spine.");
makeTransfer(-9.1, -0.55, "#df704d", "West buffer", "Short-term storage holds overflow freight while dock and market capacity is assessed.");
// ─────────────────────────────────────────────────────────────
// Dynamic cargo, boat, rail shuttle, and handcart
// ─────────────────────────────────────────────────────────────
function dynamicCrate(parent, x, y, z, color, s = 1) {
const g = new THREE.Group();
g.position.set(x, y, z);
box(g, 0, s * 0.5, 0, s, s, s, color);
box(g, 0, s * 0.5, s * 0.51, s * 1.02, s * 0.12, 0.035, "#f4d67e");
box(g, s * 0.51, s * 0.5, 0, 0.035, s * 1.01, s * 0.15, "#70523b");
parent.add(g);
return g;
}
function shipmentBeacon(parent, x, y, z, color) {
const g = new THREE.Group();
g.position.set(x, y, z);
box(g, 0, 0.26, 0, 0.04, 0.52, 0.04, "#f4edcf");
const top = box(g, 0, 0.58, 0, 0.18, 0.18, 0.18, color, true);
parent.add(g);
return top;
}
// River vessel.
const boat = new THREE.Group();
scene.add(boat);
box(boat, 0, -0.03, 0, 2.9, 0.46, 1.3, "#304a4b");
box(boat, 0, 0.18, 0, 2.7, 0.18, 1.18, "#d36c4c");
box(boat, -0.12, 0.35, 0, 2.25, 0.16, 1.08, "#d5b873");
box(boat, 0.9, 0.83, 0, 0.8, 1.0, 0.93, "#eee1b5");
box(boat, 0.9, 1.05, 0.48, 0.48, 0.36, 0.06, "#416e76");
box(boat, 0.9, 1.48, 0, 1.05, 0.18, 1.2, "#365d61");
box(boat, 1.2, 1.18, 0, 0.12, 0.62, 0.12, "#3b5556");
dynamicCrate(boat, -0.52, 0.43, 0.05, "#e7b346", 0.62);
dynamicCrate(boat, -1.05, 0.43, -0.12, "#b95b4e", 0.52);
const riverBeacon = shipmentBeacon(boat, -0.53, 1.05, 0.08, "#f4c85c");
const wakeMaterial = new THREE.MeshBasicMaterial({
color: "#d9f0dc",
transparent: true,
opacity: 0.35,
depthWrite: false
});
const wake = [];
for (let i = 0; i < 5; i++) {
const m = new THREE.Mesh(cubeGeometry, wakeMaterial.clone());
m.position.set(-1.8 - i * 0.38, -0.12, (i % 2 ? 1 : -1) * (0.32 + i * 0.08));
m.scale.set(0.7, 0.02, 0.06);
boat.add(m);
wake.push(m);
}
// Rail shuttle.
const railShuttle = new THREE.Group();
scene.add(railShuttle);
box(railShuttle, 0, 0.48, 0, 2.65, 0.25, 1.12, "#6b5846");
box(railShuttle, 0, 0.64, 0, 2.5, 0.12, 1.02, "#d2ad65");
box(railShuttle, 0.92, 1.08, 0, 0.72, 0.92, 0.98, "#d66745");
box(railShuttle, 0.92, 1.33, 0.5, 0.43, 0.33, 0.06, "#365d65");
box(railShuttle, 1.04, 1.7, 0, 0.24, 0.35, 0.22, "#344c4d");
dynamicCrate(railShuttle, -0.62, 0.7, 0.03, "#5a9873", 0.64);
dynamicCrate(railShuttle, -1.2, 0.7, -0.03, "#4d8198", 0.56);
const railBeacon = shipmentBeacon(railShuttle, -0.62, 1.32, 0.05, "#63db9a");
// Handcart.
const handcart = new THREE.Group();
scene.add(handcart);
box(handcart, 0, 0.63, 0, 1.38, 0.18, 0.95, "#b36d43");
box(handcart, -0.68, 0.84, 0, 0.1, 0.62, 0.8, "#76513b");
box(handcart, -0.9, 1.13, 0, 0.08, 0.08, 0.95, "#684a38");
box(handcart, 0.12, 0.38, 0.5, 0.36, 0.36, 0.16, "#354749");
box(handcart, 0.12, 0.38, -0.5, 0.36, 0.36, 0.16, "#354749");
dynamicCrate(handcart, 0.1, 0.73, 0, "#c45b76", 0.68);
const cartBeacon = shipmentBeacon(handcart, 0.1, 1.4, 0, "#e582be");
// ─────────────────────────────────────────────────────────────
// World-space labels
// ─────────────────────────────────────────────────────────────
const labels = [];
function addLabel(text, position, color) {
const el = document.createElement("div");
el.className = "world-label";
el.style.setProperty("--dot", color);
el.innerHTML = `<i></i><span>${text}</span>`;
$("labelLayer").appendChild(el);
labels.push({ el, position: new THREE.Vector3(...position) });
}
addLabel("Rail platform", [-5.55, 2.05, -4.72], "#eea83e");
addLabel("Market crossdock", [0, 2.15, -0.78], "#b65aa7");
addLabel("Quay exchange", [8.25, 2.05, 2.32], "#20aeb9");
addLabel("West buffer", [-9.1, 1.95, -0.55], "#df704d");
addLabel("River channel", [-10.5, 0.55, 5.25], "#25c1ca");
function updateLabels() {
if ($("labelLayer").classList.contains("hidden")) return;
const width = innerWidth;
const height = innerHeight;
labels.forEach(label => {
const p = label.position.clone().project(camera);
const visible = p.z > -1 && p.z < 1 && Math.abs(p.x) < 1.15 && Math.abs(p.y) < 1.15;
label.el.style.display = visible ? "flex" : "none";
if (visible) {
label.el.style.left = `${(p.x * 0.5 + 0.5) * width}px`;
label.el.style.top = `${(-p.y * 0.5 + 0.5) * height}px`;
}
});
}
// ─────────────────────────────────────────────────────────────
// Direct orbit controls: drag, wheel, and touch
// ─────────────────────────────────────────────────────────────
const canvas = renderer.domElement;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let dragDistance = 0;
canvas.addEventListener("contextmenu", e => e.preventDefault());
canvas.addEventListener("pointerdown", e => {
dragging = true;
dragDistance = 0;
pointerX = e.clientX;
pointerY = e.clientY;
canvas.setPointerCapture(e.pointerId);
});
canvas.addEventListener("pointermove", e => {
if (!dragging) return;
const dx = e.clientX - pointerX;
const dy = e.clientY - pointerY;
pointerX = e.clientX;
pointerY = e.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
goal.yaw -= dx * 0.006;
goal.pitch = clamp(goal.pitch + dy * 0.005, 0.28, 1.18);
});
canvas.addEventListener("pointerup", e => {
dragging = false;
if (dragDistance < 6) selectTransfer(e);
});
canvas.addEventListener("wheel", e => {
e.preventDefault();
goal.radius = clamp(goal.radius + e.deltaY * 0.022, 13, 42);
}, { passive: false });
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function selectTransfer(e) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((e.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((e.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(transferHits, false);
if (!hits.length) return;
const data = hits[0].object.userData;
$("inspectorTitle").textContent = data.name;
$("inspectorText").textContent = data.detail;
transfers.forEach(t => t.glow.material.emissiveIntensity = 0.65);
hits[0].object.material.color.set(data.color);
hits[0].object.material.opacity = 0.001;
}
// ─────────────────────────────────────────────────────────────
// Interface controls
// ─────────────────────────────────────────────────────────────
let paused = false;
$("pauseBtn").addEventListener("click", () => {
paused = !paused;
$("pauseBtn").textContent = paused ? "Resume" : "Pause";
$("pauseBtn").classList.toggle("active", paused);
});
$("routeBtn").addEventListener("click", () => {
routeGroup.visible = !routeGroup.visible;
$("routeBtn").classList.toggle("active", routeGroup.visible);
});
$("labelBtn").addEventListener("click", () => {
$("labelLayer").classList.toggle("hidden");
$("labelBtn").classList.toggle("active", !$("labelLayer").classList.contains("hidden"));
});
function setView(name) {
document.querySelectorAll(".view-btn").forEach(b => b.classList.remove("active"));
const active = [...document.querySelectorAll(".view-btn")].find(b => b.dataset.view === name);
if (active) active.classList.add("active");
if (name === "river") {
goal.target.set(0, 0.1, 4.3);
goal.radius = 20;
goal.yaw = 0.86;
goal.pitch = 0.5;
} else if (name === "rail") {
goal.target.set(-3.5, 0.4, -5.2);
goal.radius = 19;
goal.yaw = 0.68;
goal.pitch = 0.54;
} else {
goal.target.set(0, 0.3, -0.5);
goal.radius = 27;
goal.yaw = 0.72;
goal.pitch = 0.62;
}
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
$("allBtn").addEventListener("click", () => setView("all"));
$("resetBtn").addEventListener("click", () => setView("all"));
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// ─────────────────────────────────────────────────────────────
// Shipment telemetry
// ─────────────────────────────────────────────────────────────
function updateShipment(mode, progress) {
const pct = Math.round(progress * 100);
$(`pct-${mode}`).textContent = `${pct}%`;
$(`bar-${mode}`).style.width = `${pct}%`;
const status = progress < 0.12 ? "Loading" : progress < 0.84 ? "In transit" : "Transferring";
$(`status-${mode}`).textContent = status;
}
// ─────────────────────────────────────────────────────────────
// Animation loop
// ─────────────────────────────────────────────────────────────
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) elapsed += dt;
waterMaterial.uniforms.uTime.value = elapsed;
// Boat travels west-to-east along the river.
const riverProgress = (elapsed * 0.032 + 0.12) % 1;
boat.position.set(-11.5 + riverProgress * 23, 0, 5.25 + Math.sin(elapsed * 0.7) * 0.12);
boat.rotation.y = Math.sin(elapsed * 0.55) * 0.018;
wake.forEach((w, i) => {
w.material.opacity = 0.34 - i * 0.05;
w.scale.x = 0.75 + Math.sin(elapsed * 3 - i) * 0.12;
});
riverBeacon.rotation.y = elapsed * 1.4;
// Rail shuttle runs between the west platform and east buffer.
const railProgress = (elapsed * 0.043 + 0.23) % 1;
railShuttle.position.set(-10.8 + railProgress * 21.6, 0, -6.58);
railBeacon.rotation.y = -elapsed * 1.8;
// Handcart follows the market spine.
const cartProgress = (elapsed * 0.058 + 0.06) % 1;
const cp = cartCurve.getPointAt(cartProgress);
const tangent = cartCurve.getTangentAt(cartProgress);
handcart.position.copy(cp);
handcart.position.y = 0.02 + Math.sin(elapsed * 6) * 0.018;
handcart.rotation.y = -Math.atan2(tangent.z, tangent.x);
cartBeacon.rotation.y = elapsed * 2;
// Transfer beacons breathe gently.
transfers.forEach((t, i) => {
const pulse = 1 + Math.sin(elapsed * 3.2 + i * 1.7) * 0.09;
t.glow.scale.setScalar(pulse);
if (t.glow.material.emissiveIntensity < 1) {
t.glow.material.emissiveIntensity = 1.15 + Math.sin(elapsed * 3.2 + i) * 0.35;
}
});
// River glints drift downstream.
ripples.forEach(r => {
r.position.x += dt * r.userData.speed;
if (r.position.x > 14) r.position.x = -14;
r.material.opacity = 0.12 + 0.16 * (0.5 + 0.5 * Math.sin(elapsed * 1.8 + r.position.z));
});
updateShipment("river", riverProgress);
updateShipment("rail", railProgress);
updateShipment("cart", cartProgress);
// Smooth direct camera controls.
const smoothing = 1 - Math.pow(0.001, dt);
view.yaw = THREE.MathUtils.lerp(view.yaw, goal.yaw, smoothing);
view.pitch = THREE.MathUtils.lerp(view.pitch, goal.pitch, smoothing);
view.radius = THREE.MathUtils.lerp(view.radius, goal.radius, smoothing);
view.target.lerp(goal.target, smoothing);
updateCamera();
camera.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
}
updateCamera();
animate();
</script>
</body>
</html>
```