Prompt specification
Build or customize the Three.js 3D scene "Andean road linking storehouse and bridge" 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: Andean road linking storehouse and bridge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/andean-road-linking-storehouse-and-bridge-x2363
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows the Inca road network and chasqui relays. Build a compact mountain route with storage building, terrace path, and suspended crossing. Keep the road continuous through changes in elevation and label reconstructed details. Voxel style.
Working Three.js Starter (andean-road-linking-storehouse-and-bridge-x2363):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inca Road Network — Chasqui Relay Corridor</title>
<style>
:root {
--ink: #20251f;
--paper: #f1ead8;
--gold: #d7a84e;
--rust: #a85232;
--sage: #77846b;
--dark: rgba(26, 30, 25, 0.88);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd3c8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 26px;
left: 28px;
width: min(430px, calc(100vw - 56px));
text-shadow: 0 1px 12px rgba(255, 255, 255, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 7px;
color: #465044;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 2px;
content: "";
background: var(--rust);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3.2vw, 48px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 0.98;
}
.brand p {
max-width: 370px;
margin: 11px 0 0;
color: #4f594e;
font-size: 12px;
line-height: 1.55;
}
.survey-tag {
position: absolute;
top: 28px;
right: 28px;
padding: 9px 12px;
border: 1px solid rgba(39, 47, 38, 0.23);
border-radius: 3px;
background: rgba(239, 235, 219, 0.72);
backdrop-filter: blur(10px);
color: #596154;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.info-card {
position: absolute;
top: 82px;
right: 28px;
width: 218px;
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 4px;
background: var(--dark);
box-shadow: 0 16px 42px rgba(23, 27, 22, 0.18);
color: #f2ead8;
backdrop-filter: blur(12px);
}
.info-card h2 {
margin: 0 0 13px;
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
font-weight: 500;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
padding-bottom: 14px;
border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.stat strong {
display: block;
color: #f5d88e;
font-family: Georgia, "Times New Roman", serif;
font-size: 19px;
font-weight: 500;
}
.stat span {
display: block;
margin-top: 3px;
color: #bfc3b6;
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend {
display: grid;
gap: 9px;
margin-top: 13px;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: #d6d7cd;
font-size: 10px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.scene-label {
position: absolute;
z-index: 4;
min-width: 142px;
padding: 9px 11px 8px;
border: 1px solid rgba(255, 255, 255, 0.22);
border-left: 3px solid var(--gold);
border-radius: 3px;
background: rgba(29, 34, 28, 0.9);
box-shadow: 0 9px 24px rgba(25, 28, 23, 0.2);
color: #f4ecda;
opacity: 0;
transform: translate(-50%, -100%);
transition: opacity 180ms ease;
will-change: left, top;
}
.scene-label::after {
position: absolute;
bottom: -15px;
left: 50%;
width: 1px;
height: 14px;
content: "";
background: rgba(255, 255, 255, 0.65);
}
.scene-label strong {
display: block;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.scene-label span {
display: block;
margin-top: 4px;
color: #bbc1b2;
font-size: 9px;
letter-spacing: 0.025em;
}
.label-qollqa {
border-left-color: #c58948;
}
.label-terrace {
border-left-color: #84936f;
}
.label-bridge {
border-left-color: #d7a84e;
}
.label-relay {
border-left-color: #a85232;
}
.view-switcher {
position: absolute;
bottom: 25px;
left: 50%;
display: flex;
gap: 4px;
padding: 5px;
border: 1px solid rgba(32, 38, 30, 0.15);
border-radius: 5px;
background: rgba(241, 235, 216, 0.86);
box-shadow: 0 12px 32px rgba(31, 35, 28, 0.15);
pointer-events: auto;
transform: translateX(-50%);
backdrop-filter: blur(12px);
}
.view-switcher button {
padding: 9px 12px;
border: 0;
border-radius: 3px;
background: transparent;
color: #4b5449;
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.view-switcher button:hover,
.view-switcher button.active {
background: #30372e;
color: #f3e7ca;
}
.elevation-card {
position: absolute;
bottom: 24px;
left: 28px;
width: 290px;
padding: 12px 14px 10px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 4px;
background: rgba(29, 34, 28, 0.86);
color: #eee6d4;
backdrop-filter: blur(10px);
}
.elevation-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 5px;
}
.elevation-heading strong {
font-size: 9px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.elevation-heading span {
color: #aeb5a7;
font-size: 8px;
}
.elevation-card svg {
display: block;
width: 100%;
height: 65px;
overflow: visible;
}
.profile-labels {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: #aeb5a7;
font-size: 7px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.help {
position: absolute;
right: 28px;
bottom: 27px;
color: rgba(38, 45, 37, 0.76);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-align: right;
text-transform: uppercase;
text-shadow: 0 1px 8px rgba(255, 255, 255, 0.5);
}
@media (max-width: 820px) {
.brand {
top: 18px;
left: 18px;
}
.brand p,
.survey-tag,
.info-card,
.help {
display: none;
}
.view-switcher {
bottom: 14px;
max-width: calc(100vw - 24px);
overflow-x: auto;
}
.view-switcher button {
padding: 9px 10px;
}
.elevation-card {
display: none;
}
.scene-label {
min-width: 115px;
padding: 7px 8px;
}
.scene-label span {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel reconstruction of an Inca mountain road and chasqui relay system"></div>
<div class="hud">
<header class="brand">
<div class="eyebrow">Archaeological reconstruction</div>
<h1>Qhapaq Ñan<br>Relay Corridor</h1>
<p>A continuous highland route linking a qollqa storehouse, terraced retaining walls, a suspended crossing, and chasqui relay stations.</p>
</header>
<div class="survey-tag">Schematic model · interpretive reconstruction</div>
<aside class="info-card">
<h2>Relay network</h2>
<div class="stats">
<div class="stat"><strong>5</strong><span>Relay points</span></div>
<div class="stat"><strong>3</strong><span>Structures</span></div>
<div class="stat"><strong>1</strong><span>Continuous route</span></div>
</div>
<div class="legend">
<div class="legend-item"><span class="swatch" style="background:#b88a51"></span>Qollqa storage</div>
<div class="legend-item"><span class="swatch" style="background:#7d8c69"></span>Terrace system</div>
<div class="legend-item"><span class="swatch" style="background:#d3a54f"></span>Suspended crossing</div>
<div class="legend-item"><span class="swatch" style="background:#a85232"></span>Chasqui relay</div>
</div>
</aside>
<div class="scene-label label-qollqa" id="label-qollqa">
<strong>Qollqa storehouse</strong>
<span>Reconstructed stone walls and stepped thatch roof</span>
</div>
<div class="scene-label label-terrace" id="label-terrace">
<strong>Terrace path</strong>
<span>Reconstructed retaining courses and cultivation beds</span>
</div>
<div class="scene-label label-bridge" id="label-bridge">
<strong>Suspended crossing</strong>
<span>Reconstructed rope span and timber deck</span>
</div>
<div class="scene-label label-relay" id="label-relay">
<strong>Chasqui relay</strong>
<span>Reconstructed courier station and message carrier</span>
</div>
<section class="elevation-card">
<div class="elevation-heading">
<strong>Road elevation</strong>
<span>Continuous grade profile</span>
</div>
<svg id="profile" viewBox="0 0 360 76" preserveAspectRatio="none" aria-label="Road elevation profile">
<defs>
<linearGradient id="profile-fill" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="#d7a84e" stop-opacity="0.35"/>
<stop offset="100%" stop-color="#d7a84e" stop-opacity="0"/>
</linearGradient>
</defs>
<path id="profile-area" fill="url(#profile-fill)"></path>
<path id="profile-line" fill="none" stroke="#e3c273" stroke-width="2"></path>
<path id="profile-bridge" fill="none" stroke="#d47c49" stroke-width="3"></path>
<circle id="profile-dot" r="3.5" fill="#f2ead8" stroke="#a85232" stroke-width="2"></circle>
</svg>
<div class="profile-labels">
<span>Lower valley</span>
<span>Bridge gap</span>
<span>Upper pass</span>
</div>
</section>
<nav class="view-switcher" aria-label="Scene viewpoints">
<button class="active" data-view="overview">Overview</button>
<button data-view="qollqa">Qollqa</button>
<button data-view="terraces">Terraces</button>
<button data-view="bridge">Crossing</button>
</nav>
<div class="help">Drag to orbit · scroll to zoom<br>Shift-drag to pan</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 mount = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd3c8);
scene.fog = new THREE.Fog(0xcbd3c8, 64, 125);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
180
);
const hemisphere = new THREE.HemisphereLight(0xdce7df, 0x4b3e30, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffdfa5, 3.2);
sun.position.set(-18, 32, 20);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -38;
sun.shadow.camera.right = 38;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fb8c8, 0.65);
fill.position.set(22, 15, -24);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, options = {}) {
const key = color + JSON.stringify(options);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.88,
metalness: options.metalness ?? 0,
flatShading: true,
side: options.side ?? THREE.FrontSide,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
})
);
}
return materialCache.get(key);
}
function box(parent, sx, sy, sz, x, y, z, color, options = {}) {
const mesh = new THREE.Mesh(unitBox, material(color, options));
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, a, b, radius, color, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material(color));
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function hash(x, z) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453123;
return value - Math.floor(value);
}
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function smoothstep(edge0, edge1, value) {
const t = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);
}
// -------------------------------------------------------------------------
// Continuous route: lower valley -> storehouse -> terraces -> bridge -> pass
// -------------------------------------------------------------------------
const routePoints = [
new THREE.Vector3(-23.0, 1.00, 6.5),
new THREE.Vector3(-18.0, 1.70, 5.7),
new THREE.Vector3(-13.0, 2.60, 4.4),
new THREE.Vector3(-9.5, 3.35, 2.3),
new THREE.Vector3(-6.0, 4.00, 0.8),
new THREE.Vector3(-2.5, 4.35, 0.0),
new THREE.Vector3(1.5, 4.35, -0.5),
new THREE.Vector3(3.7, 4.00, -0.5),
new THREE.Vector3(4.3, 3.85, -0.5),
new THREE.Vector3(6.5, 3.00, -0.5),
new THREE.Vector3(8.8, 2.20, -0.5),
new THREE.Vector3(10.2, 2.45, -0.8),
new THREE.Vector3(14.0, 3.60, -2.4),
new THREE.Vector3(18.0, 4.90, -4.0),
new THREE.Vector3(23.0, 5.80, -5.5)
];
const route = new THREE.CatmullRomCurve3(
routePoints,
false,
"centripetal",
0.5
);
const routeSamples = route.getSpacedPoints(320);
function nearestRoute(x, z) {
let bestDistance = Infinity;
let bestY = 0;
let bestIndex = 0;
for (let i = 0; i < routeSamples.length; i++) {
const p = routeSamples[i];
const dx = p.x - x;
const dz = p.z - z;
const distance = dx * dx + dz * dz;
if (distance < bestDistance) {
bestDistance = distance;
bestY = p.y;
bestIndex = i;
}
}
return {
distance: Math.sqrt(bestDistance),
y: bestY,
index: bestIndex
};
}
function terrainHeightAt(x, z) {
const nearest = nearestRoute(x, z);
let height = nearest.y - 0.28;
if (nearest.distance > 1.35) {
height =
nearest.y -
0.42 +
Math.floor((nearest.distance - 1.35) / 3.2) * 0.43;
height += (hash(x, z) - 0.5) * 0.24;
height +=
0.75 * Math.exp(-((x + 18) ** 2 / 20 + (z + 8) ** 2 / 15));
height +=
1.2 * Math.exp(-((x - 18) ** 2 / 18 + (z + 8) ** 2 / 14));
height += Math.max(0, Math.abs(z) - 8) * 0.24;
}
// A deep transverse ravine creates the suspended crossing.
const ravineMask =
smoothstep(4.0, 4.65, x) * (1 - smoothstep(8.25, 8.9, x));
const ravineFloor = 0.28 + Math.sin(z * 0.8) * 0.035;
height = THREE.MathUtils.lerp(height, ravineFloor, ravineMask);
return Math.max(0.18, height);
}
function sampleIndexNearX(targetX) {
let bestIndex = 0;
let bestDistance = Infinity;
for (let i = 0; i < routeSamples.length; i++) {
const distance = Math.abs(routeSamples[i].x - targetX);
if (distance < bestDistance) {
bestDistance = distance;
bestIndex = i;
}
}
return bestIndex;
}
// -------------------------------------------------------------------------
// Diorama base, floor, and voxel mountain
// -------------------------------------------------------------------------
box(scene, 49.5, 0.35, 30.5, 0, -0.22, -0.5, 0x4d4b40);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
material(0xcbd3c8, { roughness: 1 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.42;
floor.receiveShadow = true;
scene.add(floor);
const voxelTransforms = [];
const voxelColors = [];
const temporaryObject = new THREE.Object3D();
const temporaryColor = new THREE.Color();
for (let x = -24; x <= 24; x++) {
for (let z = -15; z <= 14; z++) {
const height = terrainHeightAt(x, z);
const nearest = nearestRoute(x, z);
const layerSize = 0.42;
for (let y = 0; y < height - 0.015; y += layerSize) {
const layerHeight = Math.min(layerSize, height - y);
const isTop = y + layerHeight >= height - 0.025;
temporaryObject.position.set(x, y + layerHeight / 2, z);
temporaryObject.scale.set(0.985, Math.max(0.08, layerHeight - 0.022), 0.985);
temporaryObject.rotation.set(0, 0, 0);
temporaryObject.updateMatrix();
voxelTransforms.push(temporaryObject.matrix.clone());
let color;
if (isTop && nearest.distance < 1.45) {
color = new THREE.Color(0x92764f);
} else if (isTop) {
const green = hash(x * 2.1, z * 1.7);
color = new THREE.Color(
green > 0.68 ? 0x69785b : green > 0.3 ? 0x777564 : 0x69685b
);
} else {
color = new THREE.Color(
hash(x + y * 0.31, z - y * 0.17) > 0.5
? 0x746b5b
: 0x625d52
);
}
color.multiplyScalar(0.9 + hash(x + y, z) * 0.15);
voxelColors.push(color);
}
}
}
const terrain = new THREE.InstancedMesh(
unitBox,
material(0xffffff, { roughness: 0.98 }),
voxelTransforms.length
);
voxelTransforms.forEach((matrix, index) => {
terrain.setMatrixAt(index, matrix);
terrain.setColorAt(index, voxelColors[index]);
});
terrain.instanceMatrix.needsUpdate = true;
terrain.instanceColor.needsUpdate = true;
terrain.castShadow = true;
terrain.receiveShadow = true;
scene.add(terrain);
// Voxel river at the bottom of the ravine.
for (let z = -14; z <= 13; z++) {
const riverX = 6.45 + Math.sin(z * 0.52) * 0.22;
const river = box(
scene,
0.9,
0.06,
0.92,
riverX,
0.35,
z,
z % 3 === 0 ? 0x5c8b89 : 0x6e9b95,
{ castShadow: false }
);
river.rotation.y = (hash(z, 4) - 0.5) * 0.12;
}
// -------------------------------------------------------------------------
// Continuous road ribbon and voxel paving
// -------------------------------------------------------------------------
function createRoadRibbon(samples, width = 1.34) {
const positions = [];
const indices = [];
const uvs = [];
for (let i = 0; i < samples.length; i++) {
const previous = samples[Math.max(0, i - 1)];
const next = samples[Math.min(samples.length - 1, i + 1)];
const tangent = new THREE.Vector3().subVectors(next, previous).normalize();
const perpendicular = new THREE.Vector3(tangent.z, 0, -tangent.x).normalize();
const p = samples[i];
const left = p.clone().addScaledVector(perpendicular, width / 2);
const right = p.clone().addScaledVector(perpendicular, -width / 2);
const leftBottom = left.clone().add(new THREE.Vector3(0, -0.28, 0));
const rightBottom = right.clone().add(new THREE.Vector3(0, -0.28, 0));
positions.push(
left.x, left.y, left.z,
right.x, right.y, right.z,
leftBottom.x, leftBottom.y, leftBottom.z,
rightBottom.x, rightBottom.y, rightBottom.z
);
const u = i / (samples.length - 1);
uvs.push(u, 1, u, 0, u, 1, u, 0);
if (i < samples.length - 1) {
const a = i * 4;
const b = a + 1;
const c = a + 4;
const d = a + 5;
indices.push(a, b, c, b, d, c);
indices.push(a, a + 2, c, a + 2, c + 2, c);
indices.push(b, d, a + 1, d, a + 3, a + 1);
indices.push(a + 2, a + 3, c + 2, a + 3, c + 3, c + 2);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
material(0x9c7a4e, {
roughness: 1,
side: THREE.DoubleSide
})
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
createRoadRibbon(routeSamples);
const paverCount = 190;
const pavers = new THREE.InstancedMesh(
unitBox,
material(0xffffff, { roughness: 0.94 }),
paverCount
);
const xAxis = new THREE.Vector3();
const yAxis = new THREE.Vector3();
const zAxis = new THREE.Vector3();
const basis = new THREE.Matrix4();
for (let i = 0; i < paverCount; i++) {
const t = i / (paverCount - 1);
const p = route.getPointAt(t);
const tangent = route.getTangentAt(t).normalize();
xAxis.copy(tangent);
zAxis.set(tangent.z, 0, -tangent.x).normalize();
yAxis.crossVectors(zAxis, xAxis).normalize();
basis.makeBasis(xAxis, yAxis, zAxis);
temporaryObject.position.copy(p).addScaledVector(yAxis, 0.055);
temporaryObject.quaternion.setFromRotationMatrix(basis);
temporaryObject.scale.set(0.52, 0.105, 1.12);
temporaryObject.updateMatrix();
pavers.setMatrixAt(i, temporaryObject.matrix);
temporaryColor.set(i % 4 === 0 ? 0xb18a58 : i % 3 === 0 ? 0x947248 : 0xa17b50);
pavers.setColorAt(i, temporaryColor);
}
pavers.instanceMatrix.needsUpdate = true;
pavers.instanceColor.needsUpdate = true;
pavers.castShadow = true;
pavers.receiveShadow = true;
scene.add(pavers);
// Pale edge lines make the continuous grade easier to read.
for (const side of [-1, 1]) {
const edgePoints = routeSamples.map((p, i) => {
const previous = routeSamples[Math.max(0, i - 1)];
const next = routeSamples[Math.min(routeSamples.length - 1, i + 1)];
const tangent = new THREE.Vector3().subVectors(next, previous).normalize();
const perpendicular = new THREE.Vector3(tangent.z, 0, -tangent.x).normalize();
return p.clone().addScaledVector(perpendicular, side * 0.69).add(new THREE.Vector3(0, 0.105, 0));
});
const edgeGeometry = new THREE.BufferGeometry().setFromPoints(edgePoints);
scene.add(
new THREE.Line(
edgeGeometry,
new THREE.LineBasicMaterial({ color: 0xd1b47b })
)
);
}
// -------------------------------------------------------------------------
// Reconstructed qollqa storehouse
// -------------------------------------------------------------------------
const storeRouteIndex = sampleIndexNearX(-9.5);
const storeRoutePoint = routeSamples[storeRouteIndex];
const storeTangent = route
.getTangentAt(storeRouteIndex / (routeSamples.length - 1))
.normalize();
const storeSide = new THREE.Vector3(
-storeTangent.z,
0,
storeTangent.x
).normalize();
const storeCenter = storeRoutePoint.clone().addScaledVector(storeSide, -2.8);
const storeBase = terrainHeightAt(storeCenter.x, storeCenter.z);
const storehouse = new THREE.Group();
storehouse.position.set(storeCenter.x, storeBase, storeCenter.z);
storehouse.rotation.y = Math.atan2(storeSide.x, storeSide.z);
scene.add(storehouse);
box(storehouse, 4.7, 0.24, 3.35, 0, 0.12, 0, 0x736a5b);
const wallColors = [0x8d816c, 0x988b74, 0x7e7464, 0x92846e];
const wallRows = 5;
const wallHeight = 0.4;
for (let row = 0; row < wallRows; row++) {
const y = 0.25 + row * wallHeight + wallHeight / 2;
const offset = row % 2 === 0 ? 0 : 0.24;
for (let x = -2.15 + offset; x <= 2.15; x += 0.54) {
const inDoor = Math.abs(x) < 0.72 && row < 4;
if (!inDoor) {
box(
storehouse,
0.51,
wallHeight - 0.025,
0.38,
x,
y,
1.57,
wallColors[(row + Math.floor(Math.abs(x))) % wallColors.length]
);
}
box(
storehouse,
0.51,
wallHeight - 0.025,
0.38,
x,
y,
-1.57,
wallColors[(row + 1 + Math.floor(Math.abs(x))) % wallColors.length]
);
}
for (let z = -1.35 + offset; z <= 1.35; z += 0.53) {
box(
storehouse,
0.38,
wallHeight - 0.025,
0.5,
-2.18,
y,
z,
wallColors[(row + 2) % wallColors.length]
);
box(
storehouse,
0.38,
wallHeight - 0.025,
0.5,
2.18,
y,
z,
wallColors[(row + 3) % wallColors.length]
);
}
}
// Door recess and lintel.
box(storehouse, 1.08, 1.62, 0.09, 0, 1.04, 1.62, 0x252820);
box(storehouse, 1.38, 0.25, 0.48, 0, 2.12, 1.58, 0x766b59);
// Stepped voxel thatch roof.
for (const side of [-1, 1]) {
for (let level = 0; level < 6; level++) {
const roofColor = level % 2 === 0 ? 0x8a6037 : 0x765033;
box(
storehouse,
4.9,
0.24,
0.68,
0,
2.45 + level * 0.255,
side * (1.52 - level * 0.285),
roofColor
);
}
}
box(storehouse, 4.9, 0.25, 0.28, 0, 3.86, 0, 0x9b7040);
// Small roof ties.
for (const x of [-1.65, 0, 1.65]) {
box(storehouse, 0.12, 0.18, 3.3, x, 3.93, 0, 0x5c4430);
}
// -------------------------------------------------------------------------
// Reconstructed terrace path and retaining walls
// -------------------------------------------------------------------------
const terraceGroup = new THREE.Group();
scene.add(terraceGroup);
for (let x = -5.7; x <= 2.1; x += 0.82) {
const index = sampleIndexNearX(x);
const p = routeSamples[index];
const tangent = route
.getTangentAt(index / (routeSamples.length - 1))
.normalize();
const side = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
const yaw = -Math.atan2(tangent.z, tangent.x);
const retainingPoint = p.clone().addScaledVector(side, -1.25);
const retaining = box(
terraceGroup,
0.76,
0.64,
0.30,
retainingPoint.x,
p.y - 0.38,
retainingPoint.z,
(Math.floor(x * 3) % 2 === 0) ? 0x766c59 : 0x817461
);
retaining.rotation.y = yaw;
for (let row = 0; row < 3; row++) {
const terracePoint = p
.clone()
.addScaledVector(side, -2.0 - row * 1.15);
const wall = box(
terraceGroup,
0.77,
0.48,
0.28,
terracePoint.x,
p.y - 0.27 - row * 0.38,
terracePoint.z,
row % 2 === 0 ? 0x716753 : 0x80735d
);
wall.rotation.y = yaw;
const bed = box(
terraceGroup,
0.76,
0.16,
0.88,
terracePoint.x + side.x * 0.48,
p.y - 0.02 - row * 0.38,
terracePoint.z + side.z * 0.48,
row === 1 ? 0x73845f : 0x627453
);
bed.rotation.y = yaw;
// Small crop voxels.
for (let crop = 0; crop < 3; crop++) {
const cropPoint = terracePoint
.clone()
.addScaledVector(side, 0.3 + crop * 0.12);
cropPoint.addScaledVector(tangent, (crop - 1) * 0.18);
box(
terraceGroup,
0.09,
0.22,
0.09,
cropPoint.x,
p.y + 0.12 - row * 0.38,
cropPoint.z,
0x8d9a63
);
}
}
}
// -------------------------------------------------------------------------
// Suspended crossing: stone anchors, timber deck, ropes and vertical ties
// -------------------------------------------------------------------------
const bridgeStartIndex = sampleIndexNearX(4.25);
const bridgeEndIndex = sampleIndexNearX(8.85);
const bridgeStart = routeSamples[bridgeStartIndex];
const bridgeEnd = routeSamples[bridgeEndIndex];
const bridgeDirection = new THREE.Vector3()
.subVectors(bridgeEnd, bridgeStart)
.normalize();
const bridgePerpendicular = new THREE.Vector3(
bridgeDirection.z,
0,
-bridgeDirection.x
).normalize();
// Timber deck follows the exact sampled route segment.
for (let i = bridgeStartIndex + 1; i <= bridgeEndIndex; i += 2) {
const p = routeSamples[i];
const previous = routeSamples[Math.max(bridgeStartIndex, i - 1)];
const next = routeSamples[Math.min(bridgeEndIndex, i + 1)];
const tangent = new THREE.Vector3().subVectors(next, previous).normalize();
xAxis.copy(tangent);
zAxis.set(tangent.z, 0, -tangent.x).normalize();
yAxis.crossVectors(zAxis, xAxis).normalize();
basis.makeBasis(xAxis, yAxis, zAxis);
temporaryObject.position.copy(p).addScaledVector(yAxis, 0.04);
temporaryObject.quaternion.setFromRotationMatrix(basis);
temporaryObject.scale.set(0.37, 0.13, 1.28);
temporaryObject.updateMatrix();
const plank = new THREE.Mesh(unitBox, material(0x735037));
plank.position.copy(temporaryObject.position);
plank.quaternion.copy(temporaryObject.quaternion);
plank.scale.copy(temporaryObject.scale);
plank.castShadow = true;
plank.receiveShadow = true;
scene.add(plank);
}
function buildAnchorTower(endpoint) {
const tower = new THREE.Group();
tower.position.copy(endpoint);
scene.add(tower);
for (const side of [-1, 1]) {
const position = bridgePerpendicular.clone().multiplyScalar(side * 0.88);
box(tower, 0.72, 0.30, 0.72, position.x, 0.12, position.z, 0x706759);
box(tower, 0.34, 1.95, 0.38, position.x, 1.18, position.z, 0x817763);
box(tower, 0.52, 0.27, 0.54, position.x, 2.12, position.z, 0x9a8d73);
}
const crossBeam = box(
tower,
0.38,
0.30,
2.15,
0,
2.03,
0,
0x796c57
);
crossBeam.rotation.y = Math.atan2(
bridgePerpendicular.x,
bridgePerpendicular.z
);
}
buildAnchorTower(bridgeStart);
buildAnchorTower(bridgeEnd);
for (const side of [-1, 1]) {
const cablePoints = [];
for (let i = 0; i <= 24; i++) {
const t = i / 24;
const point = bridgeStart.clone().lerp(bridgeEnd, t);
point.y = THREE.MathUtils.lerp(
bridgeStart.y + 2.05,
bridgeEnd.y + 2.05,
t
);
point.y -= 1.03 * 4 * t * (1 - t);
point.addScaledVector(bridgePerpendicular, side * 0.88);
cablePoints.push(point);
}
const cableCurve = new THREE.CatmullRomCurve3(cablePoints);
const cable = new THREE.Mesh(
new THREE.TubeGeometry(cableCurve, 40, 0.038, 5, false),
material(0x45392d)
);
cable.castShadow = true;
scene.add(cable);
// Lower hand rope.
const lowerPoints = cablePoints.map((point) => {
const lower = point.clone();
lower.y -= 0.54;
return lower;
});
const lowerCurve = new THREE.CatmullRomCurve3(lowerPoints);
const lowerRope = new THREE.Mesh(
new THREE.TubeGeometry(lowerCurve, 32, 0.025, 5, false),
material(0x5d4936)
);
scene.add(lowerRope);
// Vertical ties connect the main suspension cable to the deck edge.
for (let i = 0; i <= 16; i++) {
const t = i / 16;
const deckPoint = new THREE.Vector3().lerpVectors(
bridgeStart,
bridgeEnd,
t
);
const samplePosition = THREE.MathUtils.lerp(
bridgeStartIndex,
bridgeEndIndex,
t
);
const nearestSample = routeSamples[Math.round(samplePosition)];
deckPoint.x = nearestSample.x;
deckPoint.z = nearestSample.z;
deckPoint.y = nearestSample.y;
const top = new THREE.Vector3().lerpVectors(
cablePoints[0],
cablePoints[cablePoints.length - 1],
t
);
top.addScaledVector(bridgePerpendicular, side * 0.88);
const bottom = deckPoint
.clone()
.addScaledVector(bridgePerpendicular, side * 0.73)
.add(new THREE.Vector3(0, 0.08, 0));
cylinderBetween(scene, bottom, top, 0.021, 0x544333, 5);
}
}
// -------------------------------------------------------------------------
// Chasqui relay stations and a moving courier
// -------------------------------------------------------------------------
function buildChasqui(scale = 1, runner = false) {
const group = new THREE.Group();
box(group, 0.18, 0.43, 0.18, -0.13, 0.24, 0, 0x3d3c32);
box(group, 0.18, 0.43, 0.18, 0.13, 0.24, 0, 0x3d3c32);
box(group, 0.48, 0.48, 0.28, 0, 0.68, 0, runner ? 0xa84e32 : 0x9e5d39);
box(group, 0.22, 0.42, 0.18, -0.31, 0.62, 0.02, 0x8b583b);
box(group, 0.22, 0.42, 0.18, 0.31, 0.62, 0.02, 0x8b583b);
box(group, 0.29, 0.30, 0.27, 0, 1.05, 0, 0x9c6e4c);
box(group, 0.33, 0.12, 0.30, 0, 1.20, 0, 0x493b2e);
box(group, 0.46, 0.11, 0.31, 0, 0.83, 0, 0xd2a74f);
if (runner) {
box(group, 0.23, 0.25, 0.20, 0, 0.76, -0.22, 0xe0c16c);
}
group.scale.setScalar(scale);
return group;
}
const relayAnchors = [];
const relayTimes = [0.08, 0.23, 0.48, 0.75, 0.93];
relayTimes.forEach((t, index) => {
const p = route.getPointAt(t);
const tangent = route.getTangentAt(t).normalize();
const side = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
if (index % 2 === 0) side.multiplyScalar(-1);
const position = p.clone().addScaledVector(side, 1.45);
position.y = terrainHeightAt(position.x, position.z);
const station = new THREE.Group();
station.position.copy(position);
station.rotation.y = Math.atan2(tangent.x, tangent.z);
scene.add(station);
box(station, 1.2, 0.20, 1.15, 0, 0.10, 0, 0x746957);
box(station, 0.74, 0.16, 0.70, 0, 0.27, 0, 0x8a7d64);
const courier = buildChasqui(0.9, false);
courier.position.set(0, 0.23, 0);
station.add(courier);
// Relay marker and rust-colored pennant.
box(station, 0.12, 1.35, 0.12, -0.48, 0.68, 0, 0x5b4b39);
box(station, 0.45, 0.23, 0.055, -0.25, 1.18, 0, 0xa85232);
relayAnchors.push(position.clone().add(new THREE.Vector3(0, 2.1, 0)));
});
const runningChasqui = buildChasqui(0.72, true);
scene.add(runningChasqui);
// -------------------------------------------------------------------------
// Atmospheric voxel details
// -------------------------------------------------------------------------
const clouds = [
[-17, 11.5, -9, 1.0],
[-8, 13.2, -12, 0.8],
[8, 12.5, -11, 1.1],
[18, 14.0, -8, 0.85],
[23, 10.8, -3, 0.7]
];
clouds.forEach(([x, y, z, scale]) => {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
scene.add(cloud);
box(cloud, 2.8 * scale, 0.55 * scale, 1.2 * scale, 0, 0, 0, 0xe9eee6);
box(cloud, 1.5 * scale, 0.65 * scale, 1.0 * scale, -0.8 * scale, 0.28 * scale, 0, 0xf1f2ea);
box(cloud, 1.4 * scale, 0.55 * scale, 0.9 * scale, 0.85 * scale, 0.22 * scale, 0, 0xe4e9e0);
});
// -------------------------------------------------------------------------
// Elevation profile
// -------------------------------------------------------------------------
const profileArea = document.querySelector("#profile-area");
const profileLine = document.querySelector("#profile-line");
const profileBridge = document.querySelector("#profile-bridge");
const profileDot = document.querySelector("#profile-dot");
function profileX(x) {
return 10 + ((x + 23) / 46) * 340;
}
function profileY(y) {
return 62 - ((y - 1) / 5) * 47;
}
const profilePath = routeSamples.map((p, index) => {
const command = index === 0 ? "M" : "L";
return `${command}${profileX(p.x).toFixed(2)},${profileY(p.y).toFixed(2)}`;
}).join(" ");
profileLine.setAttribute("d", profilePath);
profileArea.setAttribute(
"d",
`${profilePath} L350,70 L10,70 Z`
);
const bridgeProfilePoints = routeSamples.filter((p) => p.x >= 4.25 && p.x <= 8.85);
profileBridge.setAttribute(
"d",
bridgeProfilePoints.map((p, index) => {
const command = index === 0 ? "M" : "L";
return `${command}${profileX(p.x).toFixed(2)},${profileY(p.y).toFixed(2)}`;
}).join(" ")
);
// -------------------------------------------------------------------------
// Custom camera controls: no Three.js addons
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 2.4, -0.5),
desiredTarget: new THREE.Vector3(0, 2.4, -0.5),
radius: 49,
desiredRadius: 49,
azimuth: 0.64,
desiredAzimuth: 0.64,
polar: 1.02,
desiredPolar: 1.02
};
let dragging = false;
let panning = false;
let pointerX = 0;
let pointerY = 0;
let activePointerId = null;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.shiftKey || event.button === 2;
pointerX = event.clientX;
pointerY = event.clientY;
activePointerId = event.pointerId;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (panning) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const forward = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 2)
.setY(0)
.normalize();
const panScale = cameraState.desiredRadius * 0.0012;
cameraState.desiredTarget.addScaledVector(right, -dx * panScale);
cameraState.desiredTarget.addScaledVector(forward, -dy * panScale);
} else {
cameraState.desiredAzimuth -= dx * 0.005;
cameraState.desiredPolar = clamp(
cameraState.desiredPolar - dy * 0.0045,
0.32,
1.43
);
}
});
function stopDragging(event) {
if (activePointerId !== null && event.pointerId === activePointerId) {
dragging = false;
panning = false;
activePointerId = null;
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
8,
75
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraState.desiredAzimuth -= 0.08;
if (event.key === "ArrowRight") cameraState.desiredAzimuth += 0.08;
if (event.key === "ArrowUp") cameraState.desiredPolar = clamp(cameraState.desiredPolar - 0.06, 0.32, 1.43);
if (event.key === "ArrowDown") cameraState.desiredPolar = clamp(cameraState.desiredPolar + 0.06, 0.32, 1.43);
if (event.key === "+" || event.key === "=") cameraState.desiredRadius = clamp(cameraState.desiredRadius - 2, 8, 75);
if (event.key === "-") cameraState.desiredRadius = clamp(cameraState.desiredRadius + 2, 8, 75);
});
const viewpoints = {
overview: {
target: new THREE.Vector3(0, 2.4, -0.5),
radius: 49,
azimuth: 0.64,
polar: 1.02
},
qollqa: {
target: storehouse.position.clone().add(new THREE.Vector3(0, 1.4, 0)),
radius: 14,
azimuth: 0.72,
polar: 1.08
},
terraces: {
target: new THREE.Vector3(-1.2, 3.5, -1.8),
radius: 15,
azimuth: 0.48,
polar: 1.10
},
bridge: {
target: new THREE.Vector3(6.5, 2.6, -0.5),
radius: 15,
azimuth: 0.82,
polar: 1.03
}
};
const viewButtons = [...document.querySelectorAll("[data-view]")];
viewButtons.forEach((button) => {
button.addEventListener("click", () => {
const view = viewpoints[button.dataset.view];
cameraState.desiredTarget.copy(view.target);
cameraState.desiredRadius = view.radius;
cameraState.desiredAzimuth = view.azimuth;
cameraState.desiredPolar = view.polar;
viewButtons.forEach((item) => item.classList.toggle("active", item === button));
});
});
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelAnchors = [
{
element: document.querySelector("#label-qollqa"),
position: storehouse.position.clone().add(new THREE.Vector3(0, 4.65, 0))
},
{
element: document.querySelector("#label-terrace"),
position: new THREE.Vector3(-1.7, 5.6, -2.7)
},
{
element: document.querySelector("#label-bridge"),
position: new THREE.Vector3(6.5, 5.65, -0.5)
},
{
element: document.querySelector("#label-relay"),
position: relayAnchors[2]
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labelAnchors.forEach((label) => {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.16 &&
Math.abs(projected.y) < 1.16;
if (!visible) {
label.element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity = "1";
});
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 7.5);
cameraState.target.lerp(cameraState.desiredTarget, smoothing);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.desiredRadius,
smoothing
);
cameraState.azimuth = THREE.MathUtils.lerp(
cameraState.azimuth,
cameraState.desiredAzimuth,
smoothing
);
cameraState.polar = THREE.MathUtils.lerp(
cameraState.polar,
cameraState.desiredPolar,
smoothing
);
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.polar),
cameraState.target.z + cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(delta);
// The courier continuously follows the same road surface.
const runnerT = (elapsed * 0.018) % 1;
const runnerPoint = route.getPointAt(runnerT);
const runnerTangent = route.getTangentAt(runnerT).normalize();
runningChasqui.position.copy(runnerPoint);
runningChasqui.position.y += 0.10 + Math.abs(Math.sin(elapsed * 8)) * 0.045;
runningChasqui.rotation.y = Math.atan2(runnerTangent.x, runnerTangent.z);
runningChasqui.rotation.z = Math.sin(elapsed * 8) * 0.018;
profileDot.setAttribute("cx", profileX(runnerPoint.x));
profileDot.setAttribute("cy", profileY(runnerPoint.y));
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```