Prompt specification
Build or customize the Three.js 3D scene "Road milestone and pack saddle" 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: Road milestone and pack saddle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/road-milestone-and-pack-saddle-x2305
Scene Description Prompt:
A voxel Persian road-relay exhibit with distance marker, pack saddle, and water vessel; use illustrative labels. Three.js from cdnjs, one HTML file.
Working Three.js Starter (road-milestone-and-pack-saddle-x2305):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#eee6d6" />
<title>Persian Road Relay — Voxel Exhibit</title>
<style>
:root {
--paper: #eee6d6;
--ink: #243d3c;
--muted: #6f776f;
--teal: #247b78;
--clay: #b85e3d;
--gold: #c99b43;
--line: rgba(36, 61, 60, 0.25);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
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%;
outline: none;
touch-action: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--paper);
transition: opacity 0.5s ease, visibility 0.5s ease;
}
#loading span {
padding: 12px 18px;
border: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
letter-spacing: 0.2em;
text-transform: uppercase;
}
body.ready #loading {
opacity: 0;
visibility: hidden;
}
#ui {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.masthead {
position: absolute;
top: clamp(24px, 4vw, 54px);
left: clamp(24px, 4vw, 58px);
width: min(360px, calc(100vw - 48px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 15px;
color: var(--clay);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.23em;
text-transform: uppercase;
}
.eyebrow::before {
width: 34px;
height: 2px;
background: var(--clay);
content: "";
}
h1 {
max-width: 340px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 5.2vw, 70px);
font-weight: 500;
line-height: 0.94;
letter-spacing: -0.045em;
}
.intro {
max-width: 315px;
margin: 18px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
}
.exhibit-note {
position: absolute;
top: clamp(25px, 4vw, 55px);
right: clamp(24px, 4vw, 58px);
padding-left: 15px;
border-left: 2px solid var(--gold);
color: var(--muted);
font-size: 9px;
line-height: 1.75;
letter-spacing: 0.16em;
text-align: right;
text-transform: uppercase;
}
.exhibit-note strong {
display: block;
color: var(--ink);
font-size: 11px;
letter-spacing: 0.08em;
}
#leader-layer {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
}
#leader-layer line {
stroke: rgba(69, 78, 67, 0.58);
stroke-width: 1;
stroke-dasharray: 3 4;
}
#leader-layer circle {
fill: var(--paper);
stroke: var(--clay);
stroke-width: 2;
}
.callout {
position: absolute;
width: 188px;
padding: 11px 13px 12px;
border: 1px solid rgba(36, 61, 60, 0.22);
background: rgba(247, 242, 230, 0.93);
box-shadow: 0 8px 28px rgba(60, 53, 39, 0.08);
transform: translate(-50%, -50%);
transition: opacity 0.15s ease;
backdrop-filter: blur(6px);
}
.callout::after {
position: absolute;
right: -5px;
bottom: -5px;
width: 8px;
height: 8px;
border-right: 1px solid rgba(36, 61, 60, 0.35);
border-bottom: 1px solid rgba(36, 61, 60, 0.35);
background: #f7f2e6;
content: "";
}
.callout .number {
display: block;
margin-bottom: 5px;
color: var(--clay);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.18em;
}
.callout strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
font-weight: 600;
line-height: 1.1;
}
.callout small {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
#focus-nav {
position: absolute;
bottom: 25px;
left: 50%;
display: flex;
gap: 6px;
padding: 5px;
border: 1px solid rgba(36, 61, 60, 0.2);
background: rgba(247, 242, 230, 0.88);
box-shadow: 0 9px 30px rgba(60, 53, 39, 0.09);
transform: translateX(-50%);
pointer-events: auto;
backdrop-filter: blur(10px);
}
.focus-button {
display: flex;
align-items: center;
gap: 9px;
min-height: 38px;
padding: 0 14px;
border: 0;
background: transparent;
color: var(--muted);
cursor: pointer;
font: inherit;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: color 0.2s, background 0.2s;
}
.focus-button b {
color: var(--clay);
font-size: 8px;
letter-spacing: 0.12em;
}
.focus-button:hover,
.focus-button:focus-visible,
.focus-button.active {
background: rgba(36, 123, 120, 0.09);
color: var(--ink);
outline: none;
}
#hint {
position: absolute;
right: clamp(22px, 3vw, 42px);
bottom: 34px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.grain {
position: fixed;
inset: 0;
z-index: 2;
opacity: 0.13;
pointer-events: none;
background-image:
radial-gradient(rgba(35, 48, 42, 0.35) 0.45px, transparent 0.45px);
background-size: 4px 4px;
mix-blend-mode: multiply;
}
@media (max-width: 800px) {
.masthead {
top: 24px;
left: 23px;
}
.intro {
display: none;
}
.exhibit-note {
display: none;
}
h1 {
max-width: 270px;
font-size: 42px;
}
.callout {
width: 128px;
padding: 8px 9px;
}
.callout strong {
font-size: 13px;
}
.callout small {
display: none;
}
.focus-button {
padding: 0 10px;
}
.focus-button span {
display: none;
}
#focus-nav {
bottom: 19px;
}
#hint {
display: none;
}
}
@media (max-height: 580px) {
.masthead {
top: 18px;
}
h1 {
font-size: 38px;
}
.intro {
display: none;
}
.callout small {
display: none;
}
}
</style>
</head>
<body>
<div id="loading"><span>Building the road relay</span></div>
<div class="grain"></div>
<div id="ui">
<header class="masthead">
<div class="eyebrow">Persian Road Relay</div>
<h1>A road measured in days.</h1>
<p class="intro">
An illustrative voxel exhibit of the practical objects that kept a
long road moving: a marker, a balanced load, and a careful measure
of water.
</p>
</header>
<div class="exhibit-note">
Interactive diorama
<strong>3 objects · 1 route</strong>
Illustrative, not to scale
</div>
<svg id="leader-layer" aria-hidden="true"></svg>
<nav id="focus-nav" aria-label="Focus on an exhibit object">
<button class="focus-button" data-focus="marker">
<b>01</b><span>Distance marker</span>
</button>
<button class="focus-button" data-focus="saddle">
<b>02</b><span>Pack saddle</span>
</button>
<button class="focus-button" data-focus="vessel">
<b>03</b><span>Water vessel</span>
</button>
</nav>
<div id="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee6d6);
scene.fog = new THREE.Fog(0xeee6d6, 19, 36);
const camera = new THREE.PerspectiveCamera(
39,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff8e8, 0x8d8069, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.1);
sun.position.set(-6, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8fc7c5, 0.8);
fill.position.set(8, 4, -7);
scene.add(fill);
// ------------------------------------------------------------
// Materials and voxel helpers
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0,
flatShading: true,
...extra
});
const M = {
sand: material(0xd9c59e),
sandLight: material(0xe4d2ad),
sandDark: material(0xc9b187),
sandPale: material(0xeadbbc),
road: material(0xe9dfc8),
stone: material(0xc7b99d),
stoneLight: material(0xd8cbb2),
stoneDark: material(0xaa9c82),
teal: material(0x247b78),
tealDark: material(0x185e5d),
clay: material(0xb85e3d),
clayDark: material(0x91452f),
clayLight: material(0xcd7954),
gold: material(0xc99b43),
wood: material(0x79533a),
woodLight: material(0x9b714d),
leather: material(0x604638),
leatherLight: material(0x82614a),
ink: material(0x243b3a),
water: material(0x2e7775, { roughness: 0.28 }),
leaf: material(0x4f7560),
leafDark: material(0x3e6252),
rug: material(0x963f34)
};
function block(
parent,
mat,
size,
position,
options = {}
) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
if (options.rotation) {
mesh.rotation.set(...options.rotation);
}
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
return function () {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(1427);
// ------------------------------------------------------------
// Museum plinth and landscape
// ------------------------------------------------------------
const world = new THREE.Group();
scene.add(world);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
material(0xeee6d6)
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.53;
floor.receiveShadow = true;
scene.add(floor);
block(world, M.stoneDark, [16.7, 0.5, 10.5], [0, -0.27, 0]);
block(world, M.sandDark, [16.45, 0.12, 10.25], [0, 0.015, 0]);
const routeTiles = new Set([
"-7,-1", "-6,-1", "-5,-1", "-4,-1",
"-3,0", "-2,0", "-1,0",
"0,1", "1,0", "2,0",
"3,-1", "4,-1", "5,-1", "6,-2"
]);
const terrainMaterials = [
M.sand,
M.sandLight,
M.sandDark,
M.sandPale
];
for (let x = -7; x <= 7; x++) {
for (let z = -4; z <= 3; z++) {
const isRoute = routeTiles.has(`${x},${z}`);
let mat = terrainMaterials[Math.floor(random() * terrainMaterials.length)];
if (isRoute) mat = M.road;
block(
world,
mat,
[0.965, 0.075, 0.965],
[x, 0.075, z]
);
if (isRoute && random() > 0.48) {
block(
world,
random() > 0.5 ? M.stoneLight : M.sandPale,
[0.09, 0.016, 0.09],
[x + random() * 0.3, 0.12, z + random() * 0.3],
{ castShadow: false }
);
}
}
}
// Decorative tile border along the front of the exhibit.
for (let i = 0; i < 15; i++) {
const x = -7 + i;
const mat =
i % 4 === 0 ? M.teal :
i % 4 === 1 ? M.gold :
i % 4 === 2 ? M.clay :
M.stoneLight;
block(world, mat, [0.66, 0.055, 0.34], [x, 0.14, 3.68]);
}
// Scattered stones.
for (let i = 0; i < 34; i++) {
const x = -7.5 + random() * 15;
const z = -3.8 + random() * 7.5;
if (Math.abs(x) < 2 && Math.abs(z) < 1.8) continue;
const size = 0.06 + random() * 0.13;
block(
world,
random() > 0.5 ? M.stoneLight : M.sandDark,
[size, size * 0.65, size],
[x, 0.14, z],
{ castShadow: true }
);
}
function cypress(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0.1, z);
tree.scale.setScalar(scale);
world.add(tree);
block(tree, M.wood, [0.18, 1.0, 0.18], [0, 0.5, 0]);
block(tree, M.leafDark, [0.82, 0.8, 0.72], [0, 1.25, 0]);
block(tree, M.leaf, [0.66, 0.72, 0.58], [0, 1.82, 0]);
block(tree, M.leafDark, [0.48, 0.64, 0.43], [0, 2.35, 0]);
block(tree, M.leaf, [0.3, 0.46, 0.29], [0, 2.75, 0]);
}
cypress(-6.75, -3.45, 0.85);
cypress(6.7, -3.55, 0.72);
// Low, abstract garden wall.
for (let i = 0; i < 7; i++) {
block(
world,
i % 3 === 0 ? M.stoneDark : M.stone,
[0.92, 0.65 + (i % 2) * 0.12, 0.48],
[-2.7 + i * 0.9, 0.43, -3.65]
);
}
// ------------------------------------------------------------
// Exhibit 01: distance marker
// ------------------------------------------------------------
const marker = new THREE.Group();
marker.position.set(-4.55, 0.11, -0.72);
marker.userData.exhibit = "marker";
world.add(marker);
block(marker, M.stoneDark, [1.72, 0.18, 1.72], [0, 0.09, 0]);
block(marker, M.stoneLight, [1.42, 0.16, 1.42], [0, 0.25, 0]);
block(marker, M.stone, [1.02, 0.38, 1.02], [0, 0.51, 0]);
const markerLayers = [
M.stoneLight,
M.stone,
M.stoneLight,
M.stone,
M.stoneLight
];
markerLayers.forEach((mat, i) => {
block(
marker,
mat,
[0.84, 0.32, 0.84],
[0, 0.86 + i * 0.34, 0]
);
});
block(marker, M.stoneDark, [1.18, 0.2, 1.18], [0, 2.57, 0]);
block(marker, M.stoneLight, [1.02, 0.2, 1.02], [0, 2.77, 0]);
block(marker, M.tealDark, [0.88, 0.12, 0.88], [0, 2.93, 0]);
// Turquoise inset and a geometric directional motif.
block(marker, M.teal, [0.64, 0.86, 0.075], [0, 1.55, 0.455]);
block(marker, M.gold, [0.13, 0.54, 0.08], [0, 1.56, 0.51]);
block(marker, M.gold, [0.38, 0.13, 0.08], [0.08, 1.55, 0.51]);
block(marker, M.gold, [0.18, 0.18, 0.08], [0.26, 1.55, 0.51]);
block(marker, M.stoneLight, [0.13, 0.13, 0.08], [-0.23, 1.55, 0.51]);
// Side insets.
block(marker, M.tealDark, [0.075, 0.78, 0.58], [0.455, 1.55, 0]);
block(marker, M.tealDark, [0.075, 0.78, 0.58], [-0.455, 1.55, 0]);
// ------------------------------------------------------------
// Exhibit 02: pack saddle
// ------------------------------------------------------------
const saddle = new THREE.Group();
saddle.position.set(0, 0.11, -0.05);
saddle.userData.exhibit = "saddle";
world.add(saddle);
block(saddle, M.stoneDark, [3.45, 0.16, 2.25], [0, 0.08, 0]);
block(saddle, M.sandLight, [3.2, 0.08, 2.0], [0, 0.2, 0]);
// Wooden display trestle.
for (const x of [-0.92, 0.92]) {
block(saddle, M.wood, [0.19, 1.2, 0.22], [x, 0.82, -0.46]);
block(saddle, M.wood, [0.19, 1.2, 0.22], [x, 0.82, 0.46]);
block(saddle, M.woodLight, [0.22, 0.18, 1.18], [x, 1.36, 0]);
}
block(saddle, M.wood, [2.15, 0.17, 0.32], [0, 1.29, 0]);
// Folded textile and blanket.
block(saddle, M.rug, [2.38, 0.18, 1.34], [0, 1.46, 0]);
block(saddle, M.clay, [2.22, 0.19, 1.23], [0, 1.64, 0]);
block(saddle, M.clayDark, [2.22, 0.11, 1.24], [0, 1.76, 0]);
// Pixel-pattern blanket.
for (let i = -4; i <= 4; i++) {
const x = i * 0.23;
const mat = i % 2 === 0 ? M.teal : M.gold;
block(saddle, mat, [0.16, 0.055, 0.8], [x, 1.835, 0]);
}
// Voxel wooden saddle frame.
for (const x of [-0.66, 0.66]) {
block(saddle, M.woodLight, [0.2, 0.72, 0.19], [x, 2.02, -0.34]);
block(saddle, M.woodLight, [0.2, 0.72, 0.19], [x, 2.02, 0.34]);
block(saddle, M.woodLight, [0.22, 0.2, 0.2], [x, 2.4, -0.22]);
block(saddle, M.woodLight, [0.22, 0.2, 0.2], [x, 2.4, 0.22]);
block(saddle, M.woodLight, [0.22, 0.2, 0.65], [x, 2.53, 0]);
}
block(saddle, M.wood, [1.58, 0.15, 0.28], [0, 2.43, 0]);
// Leather straps and panniers.
for (const x of [-1.05, 1.05]) {
block(saddle, M.leather, [0.66, 0.77, 0.9], [x, 1.16, 0]);
block(saddle, M.leatherLight, [0.7, 0.14, 0.94], [x, 1.55, 0]);
block(saddle, M.teal, [0.46, 0.26, 0.045], [x, 1.2, 0.472]);
block(saddle, M.gold, [0.13, 0.13, 0.05], [x, 1.2, 0.501]);
}
block(saddle, M.leather, [0.16, 0.92, 0.16], [-0.78, 1.56, 0.47]);
block(saddle, M.leather, [0.16, 0.92, 0.16], [0.78, 1.56, 0.47]);
block(saddle, M.gold, [0.24, 0.17, 0.1], [0, 1.58, 0.55]);
// ------------------------------------------------------------
// Exhibit 03: voxel water vessel
// ------------------------------------------------------------
const vessel = new THREE.Group();
vessel.position.set(4.55, 0.11, -0.66);
vessel.userData.exhibit = "vessel";
world.add(vessel);
block(vessel, M.stoneDark, [2.18, 0.18, 2.18], [0, 0.09, 0]);
block(vessel, M.stoneLight, [1.78, 0.16, 1.78], [0, 0.26, 0]);
const jugLayers = [
{ y: 0.49, h: 0.3, r: 0.43, mat: M.clayDark },
{ y: 0.79, h: 0.3, r: 0.57, mat: M.clay },
{ y: 1.09, h: 0.3, r: 0.69, mat: M.clayLight },
{ y: 1.39, h: 0.3, r: 0.68, mat: M.teal },
{ y: 1.69, h: 0.3, r: 0.54, mat: M.clay },
{ y: 1.95, h: 0.24, r: 0.37, mat: M.clayLight },
{ y: 2.18, h: 0.26, r: 0.24, mat: M.clay },
{ y: 2.36, h: 0.16, r: 0.31, mat: M.clayDark }
];
const spacing = 0.205;
for (const layer of jugLayers) {
const cells = [];
for (let x = -4; x <= 4; x++) {
for (let z = -4; z <= 4; z++) {
const px = x * spacing;
const pz = z * spacing;
if (Math.hypot(px, pz) <= layer.r) {
cells.push([px, pz]);
}
}
}
cells.forEach(([x, z], index) => {
const mat =
index % 13 === 0 && layer.mat === M.clayLight
? M.clay
: layer.mat;
block(
vessel,
mat,
[spacing, layer.h, spacing],
[x, layer.y, z]
);
});
}
// Square handles.
for (const side of [-1, 1]) {
for (let i = 0; i < 4; i++) {
block(
vessel,
M.clayDark,
[0.18, 0.2, 0.2],
[side * 0.71, 1.5 + i * 0.2, 0]
);
}
block(vessel, M.clayDark, [0.28, 0.18, 0.2], [side * 0.58, 1.52, 0]);
block(vessel, M.clayDark, [0.28, 0.18, 0.2], [side * 0.58, 2.12, 0]);
}
// Open mouth and water surface.
block(vessel, M.ink, [0.44, 0.045, 0.44], [0, 2.42, 0]);
block(vessel, M.water, [0.37, 0.025, 0.37], [0, 2.45, 0]);
// Painted front details.
block(vessel, M.gold, [0.19, 0.19, 0.055], [0, 1.42, 0.715]);
block(vessel, M.stoneLight, [0.07, 0.07, 0.06], [0, 1.42, 0.748]);
block(vessel, M.gold, [0.09, 0.09, 0.05], [-0.28, 1.43, 0.69]);
block(vessel, M.gold, [0.09, 0.09, 0.05], [0.28, 1.43, 0.69]);
// ------------------------------------------------------------
// Selection frames
// ------------------------------------------------------------
function makeSelectionFrame(parent, width, depth) {
const group = new THREE.Group();
const mat = M.teal.clone();
mat.transparent = true;
mat.opacity = 0.72;
const thickness = 0.045;
block(group, mat, [width, thickness, thickness], [0, 0.03, depth / 2]);
block(group, mat, [width, thickness, thickness], [0, 0.03, -depth / 2]);
block(group, mat, [thickness, thickness, depth], [width / 2, 0.03, 0]);
block(group, mat, [thickness, thickness, depth], [-width / 2, 0.03, 0]);
group.visible = false;
parent.add(group);
return group;
}
const selectionFrames = {
marker: makeSelectionFrame(marker, 1.9, 1.9),
saddle: makeSelectionFrame(saddle, 3.55, 2.38),
vessel: makeSelectionFrame(vessel, 2.3, 2.3)
};
// ------------------------------------------------------------
// Projected illustrated labels
// ------------------------------------------------------------
const labelDefinitions = [
{
key: "marker",
number: "01",
title: "Distance marker",
copy: "A stage made visible along the route.",
anchor: new THREE.Vector3(-4.55, 3.08, -0.72),
offset: new THREE.Vector2(-165, -91)
},
{
key: "saddle",
number: "02",
title: "Pack saddle",
copy: "Balanced freight for the relay’s animals.",
anchor: new THREE.Vector3(0, 2.72, -0.05),
offset: new THREE.Vector2(0, -144)
},
{
key: "vessel",
number: "03",
title: "Water vessel",
copy: "Water for people, animals, and the road ahead.",
anchor: new THREE.Vector3(4.55, 2.65, -0.66),
offset: new THREE.Vector2(165, -91)
}
];
const svgNS = "http://www.w3.org/2000/svg";
const leaderLayer = document.getElementById("leader-layer");
labelDefinitions.forEach((definition) => {
const element = document.createElement("div");
element.className = "callout";
element.innerHTML = `
<span class="number">${definition.number}</span>
<strong>${definition.title}</strong>
<small>${definition.copy}</small>
`;
document.getElementById("ui").appendChild(element);
definition.element = element;
const line = document.createElementNS(svgNS, "line");
const circle = document.createElementNS(svgNS, "circle");
circle.setAttribute("r", "4");
leaderLayer.append(line, circle);
definition.line = line;
definition.circle = circle;
});
function updateLabels() {
const mobile = innerWidth < 800;
labelDefinitions.forEach((definition) => {
const projected = definition.anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
definition.element.style.opacity = "0";
definition.line.style.opacity = "0";
definition.circle.style.opacity = "0";
return;
}
const anchorX = (projected.x * 0.5 + 0.5) * innerWidth;
const anchorY = (-projected.y * 0.5 + 0.5) * innerHeight;
const offsetX = mobile ? definition.offset.x * 0.57 : definition.offset.x;
const offsetY = mobile ? definition.offset.y * 0.72 : definition.offset.y;
const halfWidth = mobile ? 64 : 94;
const x = THREE.MathUtils.clamp(
anchorX + offsetX,
halfWidth + 12,
innerWidth - halfWidth - 12
);
const y = THREE.MathUtils.clamp(
anchorY + offsetY,
mobile ? 105 : 125,
innerHeight - 92
);
definition.element.style.left = `${x}px`;
definition.element.style.top = `${y}px`;
definition.element.style.opacity = "1";
definition.line.setAttribute("x1", anchorX);
definition.line.setAttribute("y1", anchorY);
definition.line.setAttribute("x2", x);
definition.line.setAttribute("y2", y);
definition.line.style.opacity = "1";
definition.circle.setAttribute("cx", anchorX);
definition.circle.setAttribute("cy", anchorY);
definition.circle.style.opacity = "1";
});
}
// ------------------------------------------------------------
// Direct camera controls
// ------------------------------------------------------------
const defaultTarget = new THREE.Vector3(0, 1.1, 0);
function getDefaultRadius() {
return innerWidth < 800 ? 16.2 : 14.4;
}
const desired = {
theta: 0.56,
phi: 1.02,
radius: getDefaultRadius(),
target: defaultTarget.clone()
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius,
target: desired.target.clone()
};
const focusPoints = {
marker: {
target: new THREE.Vector3(-4.55, 1.45, -0.72),
radius: 7.7,
theta: 0.62,
phi: 1.03
},
saddle: {
target: new THREE.Vector3(0, 1.55, -0.05),
radius: 7.8,
theta: 0.48,
phi: 1.02
},
vessel: {
target: new THREE.Vector3(4.55, 1.45, -0.66),
radius: 7.7,
theta: 0.48,
phi: 1.03
}
};
const buttons = [...document.querySelectorAll(".focus-button")];
function setActive(key) {
Object.entries(selectionFrames).forEach(([name, frame]) => {
frame.visible = name === key;
});
buttons.forEach((button) => {
button.classList.toggle("active", button.dataset.focus === key);
});
}
function focusExhibit(key) {
const point = focusPoints[key];
if (!point) return;
desired.target.copy(point.target);
desired.radius = point.radius;
desired.theta = point.theta;
desired.phi = point.phi;
setActive(key);
}
function resetView() {
desired.target.copy(defaultTarget);
desired.radius = getDefaultRadius();
desired.theta = 0.56;
desired.phi = 1.02;
setActive(null);
}
buttons.forEach((button) => {
button.addEventListener("click", () => focusExhibit(button.dataset.focus));
});
const pointers = new Map();
let pinchDistance = 0;
let lastPointer = { x: 0, y: 0 };
let pointerTravel = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
lastPointer = { x: event.clientX, y: event.clientY };
pointerTravel = 0;
} else if (pointers.size === 2) {
pinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
pointerTravel += Math.abs(dx) + Math.abs(dy);
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.48,
1.36
);
lastPointer = { x: event.clientX, y: event.clientY };
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (pinchDistance > 0 && distance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * (pinchDistance / distance),
5.5,
21
);
}
pinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
pinchDistance = pointers.size === 2 ? pointerDistance() : 0;
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastPointer = { x: remaining.x, y: remaining.y };
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
5.5,
21
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
// Clicking the exhibit objects focuses their labels.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerup", (event) => {
if (pointerTravel > 8) return;
pointer.x = (event.clientX / innerWidth) * 2 - 1;
pointer.y = -(event.clientY / innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects([marker, saddle, vessel], true);
if (!hits.length) return;
let object = hits[0].object;
while (object && !object.userData.exhibit) {
object = object.parent;
}
if (object?.userData.exhibit) {
focusExhibit(object.userData.exhibit);
}
});
// ------------------------------------------------------------
// Animation and resize
// ------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
function animate() {
const damping = 0.095;
current.theta += (desired.theta - current.theta) * damping;
current.phi += (desired.phi - current.phi) * damping;
current.radius += (desired.radius - current.radius) * damping;
current.target.lerp(desired.target, damping);
spherical.set(current.radius, current.phi, current.theta);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(current.target).add(cameraOffset);
camera.lookAt(current.target);
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
scene.updateMatrixWorld(true);
animate();
requestAnimationFrame(() => document.body.classList.add("ready"));
</script>
</body>
</html>
```