Prompt specification
Build or customize the Three.js 3D scene "Chasqui relay handover on a mountain path" 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: Chasqui relay handover on a mountain path
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/chasqui-relay-handover-on-a-mountain-path-x2362
Scene Description Prompt:
Make a cutaway Three.js scene in a self-contained HTML file using cdnjs: Chasqui relay handover on a mountain path. Create a historically informed Inca relay vignette with two runners and a roadside stop. Show message transfer without inventing a specific named message or exact journey time.
Working Three.js Starter (chasqui-relay-handover-on-a-mountain-path-x2362):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Chasqui Relay Handover — Interpretive Inca Road Cutaway</title>
<style>
:root {
--ink: #29251f;
--muted: #686052;
--paper: rgba(250, 246, 236, 0.92);
--line: rgba(70, 58, 43, 0.2);
--gold: #aa7935;
--red: #8d4435;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d2c4;
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;
outline: none;
}
.title-card,
.info-card,
.controls {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 12px 35px rgba(51, 42, 30, 0.12);
backdrop-filter: blur(12px);
}
.title-card {
top: 22px;
left: 22px;
width: min(430px, calc(100vw - 44px));
padding: 18px 20px 16px;
border-radius: 4px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--red);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3.3vw, 42px);
font-weight: 500;
line-height: 1.02;
letter-spacing: -0.025em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.info-card {
left: 22px;
bottom: 22px;
width: min(350px, calc(100vw - 44px));
padding: 16px 18px;
border-radius: 4px;
font-size: 12px;
line-height: 1.52;
}
.info-card h2 {
margin: 0 0 9px;
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.info-card p { margin: 7px 0 0; }
.info-card strong { font-weight: 750; }
.note {
margin-top: 12px !important;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
}
.controls {
top: 22px;
right: 22px;
display: flex;
gap: 7px;
padding: 7px;
border-radius: 4px;
}
button {
border: 1px solid rgba(67, 55, 41, 0.22);
border-radius: 3px;
padding: 8px 11px;
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 700;
}
button:hover { background: #fffdf7; }
button:active { transform: translateY(1px); }
#label-layer {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
max-width: 220px;
padding: 7px 9px;
border: 1px solid rgba(57, 46, 33, 0.18);
border-radius: 3px;
background: rgba(253, 249, 240, 0.88);
box-shadow: 0 4px 14px rgba(45, 37, 27, 0.08);
color: #3d352b;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.035em;
line-height: 1.25;
white-space: nowrap;
will-change: transform;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -8px;
width: 1px;
height: 8px;
background: rgba(57, 46, 33, 0.45);
}
.scene-label.red { border-left: 3px solid var(--red); }
.scene-label.gold { border-left: 3px solid var(--gold); }
.scene-label.gray { border-left: 3px solid #6d6d62; }
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #d8d2c4;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 0.4s ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
.subtitle { font-size: 11px; }
.controls {
top: auto;
right: 12px;
bottom: 12px;
}
.info-card {
left: 12px;
bottom: 63px;
width: calc(100vw - 24px);
max-height: 34vh;
overflow: auto;
padding: 12px 14px;
}
.info-card p { font-size: 11px; }
.note { font-size: 10px; }
}
</style>
</head>
<body>
<div id="loading">Preparing the relay landscape…</div>
<header class="title-card">
<p class="eyebrow">Qhapaq Ñan · Interpretive cutaway</p>
<h1>Chasqui relay handover</h1>
<p class="subtitle">
Two couriers exchange a generic knotted-cord dispatch beside a
mountain relay shelter.
</p>
</header>
<aside class="info-card">
<h2>Historical reading</h2>
<p>
<strong>Chasquis</strong> relayed oral reports and knotted-cord
records along imperial roads. The small thatched roadside stop
evokes a <strong>chaskiwasi</strong>, a relay shelter used along
Andean routes.
</p>
<p>
The terraced road, stone edging, shelter, clothing, vegetation,
and terrain are simplified interpretive forms rather than a
reconstruction of a particular site.
</p>
<p class="note">
The dispatch is intentionally unnamed. The animation demonstrates a
handover only; its timing does not represent an exact journey
duration or a dated historical event.
</p>
</aside>
<nav class="controls" aria-label="Scene controls">
<button id="pause" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
<button id="reset" type="button">Reset view</button>
</nav>
<div id="label-layer" aria-hidden="true">
<div class="scene-label red" id="label-arriving">Chasqui arriving</div>
<div class="scene-label red" id="label-departing">Chasqui departing</div>
<div class="scene-label gold" id="label-stop">Roadside relay shelter</div>
<div class="scene-label gold" id="label-dispatch">Generic knotted-cord dispatch</div>
<div class="scene-label gray" id="label-road">Stone road and retaining edge</div>
<div class="scene-label gray" id="label-section">Mountain cutaway</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(0xd8d2c4);
scene.fog = new THREE.Fog(0xd8d2c4, 42, 88);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
140
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf8f0dc, 0x655b4d, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffedca, 3.1);
sun.position.set(-13, 25, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9c1c8, 0.75);
fill.position.set(15, 9, -16);
scene.add(fill);
// -------------------------------------------------------------------------
// Deterministic procedural helpers
// -------------------------------------------------------------------------
let randomSeed = 82741;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function smooth01(value) {
const t = clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
function makeCanvasTexture(draw, size = 256) {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = size;
const context = canvas.getContext("2d");
draw(context, size);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const roadTexture = makeCanvasTexture((context, size) => {
context.fillStyle = "#807765";
context.fillRect(0, 0, size, size);
for (let i = 0; i < 1500; i++) {
const x = random() * size;
const y = random() * size;
const r = 0.5 + random() * 2.1;
const shade = 75 + Math.floor(random() * 70);
context.fillStyle = `rgba(${shade},${shade - 5},${shade - 13},0.42)`;
context.beginPath();
context.ellipse(x, y, r, r * 0.65, random() * Math.PI, 0, Math.PI * 2);
context.fill();
}
});
roadTexture.repeat.set(2, 24);
const thatchTexture = makeCanvasTexture((context, size) => {
context.fillStyle = "#9b713b";
context.fillRect(0, 0, size, size);
for (let i = 0; i < 950; i++) {
const x = random() * size;
const y = random() * size;
const length = 5 + random() * 24;
context.strokeStyle = random() > 0.5
? "rgba(66,43,24,0.30)"
: "rgba(224,178,102,0.28)";
context.lineWidth = 0.5 + random() * 1.2;
context.beginPath();
context.moveTo(x, y);
context.lineTo(x + (random() - 0.5) * 5, y + length);
context.stroke();
}
});
thatchTexture.repeat.set(3, 2);
// -------------------------------------------------------------------------
// Mountain block and cutaway faces
// -------------------------------------------------------------------------
const TERRAIN = {
minX: -17,
maxX: 17,
minZ: -12,
maxZ: 12,
bottom: -3.4
};
function terrainHeight(x, z) {
const westernMassif =
3.3 * Math.exp(-(
((x + 2) / 13) ** 2 +
((z - 3) / 6.5) ** 2
));
const easternMassif =
3.15 * Math.exp(-(
((x - 9) / 10) ** 2 +
((z - 2) / 7) ** 2
));
const baseSlope = 0.105 * (x + 17);
const smallRise =
0.22 * Math.exp(-(
((x + 9) / 4) ** 2 +
((z + 8) / 3) ** 2
));
return Math.max(-0.08, baseSlope + westernMassif + easternMassif + smallRise);
}
function buildTerrainTop() {
const nx = 82;
const nz = 58;
const positions = [];
const colors = [];
const indices = [];
const lowColor = new THREE.Color(0x777252);
const midColor = new THREE.Color(0x8b805b);
const highColor = new THREE.Color(0x9c8b65);
for (let j = 0; j <= nz; j++) {
const z = lerp(TERRAIN.minZ, TERRAIN.maxZ, j / nz);
for (let i = 0; i <= nx; i++) {
const x = lerp(TERRAIN.minX, TERRAIN.maxX, i / nx);
const y = terrainHeight(x, z);
positions.push(x, y, z);
const normalized = clamp((y - 0.2) / 5.8, 0, 1);
const color = lowColor.clone()
.lerp(midColor, clamp(normalized * 1.6, 0, 1))
.lerp(highColor, clamp((normalized - 0.45) * 1.8, 0, 1));
const variation = (random() - 0.5) * 0.065;
color.offsetHSL(variation * 0.12, variation * 0.3, variation);
colors.push(color.r, color.g, color.b);
}
}
for (let j = 0; j < nz; j++) {
for (let i = 0; i < nx; i++) {
const a = j * (nx + 1) + i;
const b = a + 1;
const c = a + nx + 1;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
metalness: 0
});
const terrain = new THREE.Mesh(geometry, material);
terrain.receiveShadow = true;
terrain.castShadow = true;
scene.add(terrain);
}
buildTerrainTop();
const strata = [
{ bottom: -3.4, top: -2.45, color: 0x65594b },
{ bottom: -2.45, top: -1.55, color: 0x796a55 },
{ bottom: -1.55, top: -0.65, color: 0x8b765a },
{ bottom: -0.65, top: 0.30, color: 0x9b8260 },
{ bottom: 0.30, top: 1.35, color: 0x8c775c },
{ bottom: 1.35, top: 2.55, color: 0x79664f },
{ bottom: 2.55, top: 4.00, color: 0x8c795e },
{ bottom: 4.00, top: 7.00, color: 0xa18c69 }
];
function pushQuad(positions, indices, a, b, c, d) {
const start = positions.length / 3;
positions.push(...a, ...b, ...c, ...d);
indices.push(start, start + 1, start + 2);
indices.push(start, start + 2, start + 3);
}
function buildSectionWall(axis, fixed, start, end, outwardSign) {
strata.forEach((band) => {
const positions = [];
const indices = [];
const segments = 70;
for (let i = 0; i < segments; i++) {
const a = lerp(start, end, i / segments);
const b = lerp(start, end, (i + 1) / segments);
let topA, topB;
if (axis === "z") {
topA = terrainHeight(a, fixed);
topB = terrainHeight(b, fixed);
} else {
topA = terrainHeight(fixed, a);
topB = terrainHeight(fixed, b);
}
const lowerA = band.bottom;
const lowerB = band.bottom;
const upperA = Math.min(band.top, topA);
const upperB = Math.min(band.top, topB);
if (upperA <= lowerA || upperB <= lowerB) continue;
let p0, p1, p2, p3;
if (axis === "z") {
p0 = [a, lowerA, fixed];
p1 = [b, lowerB, fixed];
p2 = [b, upperB, fixed];
p3 = [a, upperA, fixed];
} else {
p0 = [fixed, lowerA, a];
p1 = [fixed, lowerB, b];
p2 = [fixed, upperB, b];
p3 = [fixed, upperA, a];
}
if (outwardSign < 0) {
pushQuad(positions, indices, p3, p2, p1, p0);
} else {
pushQuad(positions, indices, p0, p1, p2, p3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: band.color,
roughness: 1,
side: THREE.DoubleSide
})
);
mesh.receiveShadow = true;
scene.add(mesh);
});
}
buildSectionWall(
"z", TERRAIN.maxZ,
TERRAIN.minX, TERRAIN.maxX, 1
);
buildSectionWall(
"z", TERRAIN.minZ,
TERRAIN.minX, TERRAIN.maxX, -1
);
buildSectionWall(
"x", TERRAIN.maxX,
TERRAIN.minZ, TERRAIN.maxZ, 1
);
buildSectionWall(
"x", TERRAIN.minX,
TERRAIN.minZ, TERRAIN.maxZ, -1
);
const baseSlab = new THREE.Mesh(
new THREE.BoxGeometry(34, 0.34, 24),
new THREE.MeshStandardMaterial({
color: 0x51483e,
roughness: 1
})
);
baseSlab.position.set(0, -3.48, 0);
baseSlab.receiveShadow = true;
scene.add(baseSlab);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
new THREE.MeshStandardMaterial({
color: 0xd8d2c4,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -3.68;
floor.receiveShadow = true;
scene.add(floor);
// -------------------------------------------------------------------------
// Mountain road: ribbon, retaining face, and stone edging
// -------------------------------------------------------------------------
function pathZ(x) {
return 7 - 0.34 * x + 1.9 * Math.sin(0.31 * x);
}
function pathTangent(x) {
const derivative = -0.34 + 1.9 * 0.31 * Math.cos(0.31 * x);
const length = Math.hypot(1, derivative);
return new THREE.Vector2(1 / length, derivative / length);
}
function pathPoint(x) {
return new THREE.Vector2(x, pathZ(x));
}
const pathSamples = [];
for (let i = 0; i <= 190; i++) {
pathSamples.push(pathPoint(lerp(-14.5, 14.5, i / 190)));
}
function buildRoadRibbon(width, offset, heightOffset, material) {
const positions = [];
const uvs = [];
const indices = [];
const count = 210;
for (let i = 0; i <= count; i++) {
const x = lerp(-14.5, 14.5, i / count);
const center = pathPoint(x);
const tangent = pathTangent(x);
const side = new THREE.Vector2(-tangent.y, tangent.x).normalize();
for (const edge of [-1, 1]) {
const lateral = offset + edge * width * 0.5;
const px = center.x + side.x * lateral;
const pz = center.y + side.y * lateral;
const py = terrainHeight(px, pz) + heightOffset;
positions.push(px, py, pz);
uvs.push(edge === -1 ? 0 : 1, i / count);
}
if (i < count) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, c, b, b, c, d);
}
}
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);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const roadMaterial = new THREE.MeshStandardMaterial({
map: roadTexture,
color: 0xb3a58a,
roughness: 1,
side: THREE.DoubleSide
});
buildRoadRibbon(1.48, 0, 0.075, roadMaterial);
const drainMaterial = new THREE.MeshStandardMaterial({
color: 0x4d4b42,
roughness: 1,
side: THREE.DoubleSide
});
buildRoadRibbon(0.11, 0.61, 0.086, drainMaterial);
function buildRetainingFace() {
const positions = [];
const indices = [];
const count = 190;
for (let i = 0; i < count; i++) {
const x1 = lerp(-14.5, 14.5, i / count);
const x2 = lerp(-14.5, 14.5, (i + 1) / count);
const c1 = pathPoint(x1);
const c2 = pathPoint(x2);
const t1 = pathTangent(x1);
const t2 = pathTangent(x2);
const s1 = new THREE.Vector2(-t1.y, t1.x).normalize();
const s2 = new THREE.Vector2(-t2.y, t2.x).normalize();
const p1 = c1.clone().addScaledVector(s1, 0.79);
const p2 = c2.clone().addScaledVector(s2, 0.79);
const y1 = terrainHeight(p1.x, p1.y);
const y2 = terrainHeight(p2.x, p2.y);
pushQuad(
positions,
indices,
[p1.x, y1 + 0.05, p1.y],
[p2.x, y2 + 0.05, p2.y],
[p2.x, y2 - 0.65, p2.y],
[p1.x, y1 - 0.65, p1.y]
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const wall = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0x776c5c,
roughness: 1,
side: THREE.DoubleSide
})
);
wall.castShadow = true;
wall.receiveShadow = true;
scene.add(wall);
}
buildRetainingFace();
const stoneGeometry = new THREE.BoxGeometry(1, 1, 1);
const stoneMaterials = [
new THREE.MeshStandardMaterial({ color: 0x817665, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x6e685c, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x958873, roughness: 1 })
];
for (let x = -14; x < 14.4; x += 0.78) {
const center = pathPoint(x);
const tangent = pathTangent(x);
const side = new THREE.Vector2(-tangent.y, tangent.x).normalize();
const point = center.clone().addScaledVector(side, 0.78);
const stone = new THREE.Mesh(
stoneGeometry,
stoneMaterials[Math.floor(random() * stoneMaterials.length)]
);
stone.scale.set(
0.40 + random() * 0.20,
0.22 + random() * 0.13,
0.23 + random() * 0.08
);
stone.position.set(
point.x,
terrainHeight(point.x, point.y) + 0.14,
point.y
);
stone.rotation.y = -Math.atan2(tangent.y, tangent.x);
stone.rotation.z = (random() - 0.5) * 0.06;
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
}
// -------------------------------------------------------------------------
// Roadside relay shelter
// -------------------------------------------------------------------------
function buildShelter() {
const stationX = 0.9;
const center = pathPoint(stationX);
const tangent = pathTangent(stationX);
const side = new THREE.Vector2(-tangent.y, tangent.x).normalize();
const offset = center.clone().addScaledVector(side, -3.0);
const shelter = new THREE.Group();
shelter.position.set(
offset.x,
terrainHeight(offset.x, offset.y),
offset.y
);
shelter.rotation.y = -Math.atan2(tangent.y, tangent.x);
scene.add(shelter);
const stoneMat = new THREE.MeshStandardMaterial({
color: 0x817665,
roughness: 1
});
const timberMat = new THREE.MeshStandardMaterial({
color: 0x67462e,
roughness: 0.9
});
const caneMat = new THREE.MeshStandardMaterial({
color: 0x9a8058,
roughness: 1
});
const platform = new THREE.Mesh(
new THREE.BoxGeometry(4.5, 0.30, 3.5),
stoneMat
);
platform.position.y = 0.12;
platform.castShadow = true;
platform.receiveShadow = true;
shelter.add(platform);
const backWall = new THREE.Mesh(
new THREE.BoxGeometry(3.7, 1.35, 0.22),
caneMat
);
backWall.position.set(0, 0.92, -1.38);
backWall.castShadow = true;
shelter.add(backWall);
for (const sideX of [-1.78, 1.78]) {
const wall = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 1.1, 2.6),
stoneMat
);
wall.position.set(sideX, 0.73, -0.05);
wall.castShadow = true;
wall.receiveShadow = true;
shelter.add(wall);
}
for (const x of [-1.65, 1.65]) {
for (const z of [-1.28, 1.28]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.12, 2.2, 8),
timberMat
);
post.position.set(x, 1.42, z);
post.castShadow = true;
shelter.add(post);
}
}
const roofMaterial = new THREE.MeshStandardMaterial({
map: thatchTexture,
color: 0xc39b59,
roughness: 1,
side: THREE.DoubleSide
});
function roofPlane(points) {
const positions = points.flat();
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
const roof = new THREE.Mesh(geometry, roofMaterial);
roof.castShadow = true;
roof.receiveShadow = true;
shelter.add(roof);
}
roofPlane([
[-2.25, 2.52, -1.82],
[ 2.25, 2.52, -1.82],
[ 2.25, 3.42, 0.00],
[-2.25, 3.42, 0.00]
]);
roofPlane([
[-2.25, 3.42, 0.00],
[ 2.25, 3.42, 0.00],
[ 2.25, 2.52, 1.82],
[-2.25, 2.52, 1.82]
]);
const ridge = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 4.65, 10),
timberMat
);
ridge.rotation.z = Math.PI / 2;
ridge.position.set(0, 3.44, 0);
ridge.castShadow = true;
shelter.add(ridge);
for (const z of [-1.82, 1.82]) {
const eave = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 4.65, 8),
timberMat
);
eave.rotation.z = Math.PI / 2;
eave.position.set(0, 2.49, z);
shelter.add(eave);
}
// Woven gable infill at both ends.
for (const x of [-1.78, 1.78]) {
const shape = new THREE.Shape();
shape.moveTo(-1.35, 0);
shape.lineTo(1.35, 0);
shape.lineTo(0, 0.92);
shape.closePath();
const gable = new THREE.Mesh(
new THREE.ShapeGeometry(shape),
caneMat
);
gable.rotation.y = Math.PI / 2;
gable.position.set(x, 2.47, 0);
shelter.add(gable);
}
return shelter;
}
const shelter = buildShelter();
// -------------------------------------------------------------------------
// Sparse highland vegetation and stones
// -------------------------------------------------------------------------
function distanceToPath(x, z) {
let minimum = Infinity;
for (const sample of pathSamples) {
const dx = sample.x - x;
const dz = sample.y - z;
minimum = Math.min(minimum, dx * dx + dz * dz);
}
return Math.sqrt(minimum);
}
const tuftCount = 145;
const tuftGeometry = new THREE.ConeGeometry(0.18, 0.62, 5);
const tuftMaterial = new THREE.MeshStandardMaterial({
color: 0x77734c,
roughness: 1
});
const tufts = new THREE.InstancedMesh(tuftGeometry, tuftMaterial, tuftCount);
const dummy = new THREE.Object3D();
for (let i = 0; i < tuftCount; i++) {
let x, z;
do {
x = lerp(TERRAIN.minX + 0.5, TERRAIN.maxX - 0.5, random());
z = lerp(TERRAIN.minZ + 0.5, TERRAIN.maxZ - 0.5, random());
} while (distanceToPath(x, z) < 1.35);
dummy.position.set(x, terrainHeight(x, z) + 0.26, z);
dummy.rotation.set(
(random() - 0.5) * 0.18,
random() * Math.PI * 2,
(random() - 0.5) * 0.18
);
dummy.scale.set(
0.75 + random() * 0.85,
0.55 + random() * 1.05,
0.75 + random() * 0.85
);
dummy.updateMatrix();
tufts.setMatrixAt(i, dummy.matrix);
}
tufts.castShadow = true;
tufts.receiveShadow = true;
scene.add(tufts);
const rockCount = 70;
const rockGeometry = new THREE.DodecahedronGeometry(0.22, 0);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x766f62,
roughness: 1
});
const rocks = new THREE.InstancedMesh(rockGeometry, rockMaterial, rockCount);
for (let i = 0; i < rockCount; i++) {
let x, z;
do {
x = lerp(TERRAIN.minX + 0.4, TERRAIN.maxX - 0.4, random());
z = lerp(TERRAIN.minZ + 0.4, TERRAIN.maxZ - 0.4, random());
} while (distanceToPath(x, z) < 1.08);
dummy.position.set(x, terrainHeight(x, z) + 0.12, z);
dummy.rotation.set(random(), random(), random());
dummy.scale.set(
0.6 + random() * 1.6,
0.45 + random() * 1.0,
0.6 + random() * 1.5
);
dummy.updateMatrix();
rocks.setMatrixAt(i, dummy.matrix);
}
rocks.castShadow = true;
rocks.receiveShadow = true;
scene.add(rocks);
// -------------------------------------------------------------------------
// Stylized chasquis
// -------------------------------------------------------------------------
function createRunner({
tunic = 0x8e3e32,
sash = 0xc28a39,
skin = 0x9a694b,
hair = 0x29221d,
pouch = 0x6d4a31
} = {}) {
const root = new THREE.Group();
root.scale.setScalar(1.12);
const tunicMaterial = new THREE.MeshStandardMaterial({
color: tunic,
roughness: 1
});
const sashMaterial = new THREE.MeshStandardMaterial({
color: sash,
roughness: 0.9
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: skin,
roughness: 0.9
});
const hairMaterial = new THREE.MeshStandardMaterial({
color: hair,
roughness: 1
});
const pouchMaterial = new THREE.MeshStandardMaterial({
color: pouch,
roughness: 1
});
const body = new THREE.Group();
root.add(body);
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.43, 0.84, 9),
tunicMaterial
);
torso.position.y = 1.25;
torso.castShadow = true;
body.add(torso);
const belt = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.045, 6, 16),
sashMaterial
);
belt.rotation.x = Math.PI / 2;
belt.position.y = 1.08;
body.add(belt);
const shoulderWrap = new THREE.Mesh(
new THREE.TorusGeometry(0.29, 0.043, 6, 16),
sashMaterial
);
shoulderWrap.rotation.x = Math.PI / 2;
shoulderWrap.position.y = 1.59;
body.add(shoulderWrap);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.10, 0.12, 0.20, 8),
skinMaterial
);
neck.position.y = 1.76;
body.add(neck);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.255, 12, 10),
skinMaterial
);
head.position.y = 1.99;
head.castShadow = true;
body.add(head);
const headband = new THREE.Mesh(
new THREE.TorusGeometry(0.245, 0.025, 6, 18),
sashMaterial
);
headband.rotation.x = Math.PI / 2;
headband.position.y = 2.07;
body.add(headband);
const hairCap = new THREE.Mesh(
new THREE.SphereGeometry(
0.259,
12,
7,
0,
Math.PI * 2,
0,
Math.PI * 0.38
),
hairMaterial
);
hairCap.position.y = 2.00;
hairCap.rotation.z = -0.12;
body.add(hairCap);
const nose = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.17, 7),
skinMaterial
);
nose.rotation.z = -Math.PI / 2;
nose.position.set(0.235, 1.99, 0);
body.add(nose);
const legPivots = [];
const armPivots = [];
function makeLimb(parent, length, radius, material) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius * 0.85, radius, length, 8),
material
);
mesh.position.y = -length / 2;
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
for (const z of [-0.18, 0.18]) {
const hip = new THREE.Group();
hip.position.set(0, 0.91, z);
root.add(hip);
makeLimb(hip, 0.43, 0.11, skinMaterial);
const knee = new THREE.Group();
knee.position.y = -0.43;
hip.add(knee);
makeLimb(knee, 0.43, 0.09, skinMaterial);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 0.12, 0.17),
pouchMaterial
);
foot.position.set(0.08, -0.45, 0);
foot.castShadow = true;
knee.add(foot);
legPivots.push({ hip, knee, side: z > 0 ? 1 : -1 });
}
for (const z of [-0.42, 0.42]) {
const shoulder = new THREE.Group();
shoulder.position.set(0, 1.58, z);
root.add(shoulder);
makeLimb(shoulder, 0.38, 0.085, tunicMaterial);
const elbow = new THREE.Group();
elbow.position.y = -0.38;
shoulder.add(elbow);
makeLimb(elbow, 0.37, 0.07, skinMaterial);
const hand = new THREE.Mesh(
new THREE.SphereGeometry(0.085, 8, 7),
skinMaterial
);
hand.position.y = -0.39;
elbow.add(hand);
armPivots.push({ shoulder, elbow, side: z > 0 ? 1 : -1 });
}
const backPouch = new THREE.Mesh(
new THREE.BoxGeometry(0.20, 0.32, 0.34),
pouchMaterial
);
backPouch.position.set(-0.37, 1.11, 0);
backPouch.castShadow = true;
body.add(backPouch);
const pouchStrap = new THREE.Mesh(
new THREE.TorusGeometry(0.31, 0.027, 5, 18, Math.PI * 1.3),
sashMaterial
);
pouchStrap.rotation.y = Math.PI / 2;
pouchStrap.rotation.z = -0.55;
pouchStrap.position.set(0, 1.3, 0);
body.add(pouchStrap);
scene.add(root);
return { root, body, legPivots, armPivots };
}
const arrivingRunner = createRunner({
tunic: 0x8d4133,
sash: 0xc69845,
pouch: 0x65452f
});
const departingRunner = createRunner({
tunic: 0x465c55,
sash: 0xb87539,
hair: 0x33251c,
pouch: 0x7a5333
});
function poseRunner(runner, phase, intensity) {
runner.legPivots.forEach((leg, index) => {
const wave = Math.sin(phase + index * Math.PI);
leg.hip.rotation.z = wave * 0.57 * intensity;
leg.knee.rotation.z = Math.max(0, -wave) * 0.35 * intensity;
});
runner.armPivots.forEach((arm, index) => {
const wave = Math.sin(phase + index * Math.PI + Math.PI);
arm.shoulder.rotation.z = wave * 0.48 * intensity;
arm.elbow.rotation.z = -0.15 * intensity;
});
}
function placeRunner(runner, x, bob = 0) {
const center = pathPoint(x);
const tangent = pathTangent(x);
runner.root.position.set(
center.x,
terrainHeight(center.x, center.y) + 0.08 + bob,
center.y
);
runner.root.rotation.y = -Math.atan2(tangent.y, tangent.x);
runner.root.updateMatrixWorld(true);
}
// -------------------------------------------------------------------------
// Generic knotted-cord dispatch
// -------------------------------------------------------------------------
function createDispatch() {
const group = new THREE.Group();
group.scale.setScalar(0.92);
const cloth = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.15, 0.40, 10),
new THREE.MeshStandardMaterial({
color: 0xb99966,
roughness: 1
})
);
cloth.rotation.z = Math.PI / 2;
cloth.castShadow = true;
group.add(cloth);
const cordMaterial = new THREE.MeshStandardMaterial({
color: 0x6b3328,
roughness: 1
});
for (let i = 0; i < 6; i++) {
const z = -0.12 + i * 0.048;
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.18, 0.02, z),
new THREE.Vector3(-0.04, 0.18 - i * 0.018, z),
new THREE.Vector3(0.16, -0.03, z + 0.025)
]);
const cord = new THREE.Mesh(
new THREE.TubeGeometry(curve, 14, 0.018, 5, false),
cordMaterial
);
cord.castShadow = true;
group.add(cord);
const knot = new THREE.Mesh(
new THREE.SphereGeometry(0.044, 7, 6),
cordMaterial
);
knot.position.set(-0.03 + (i % 2) * 0.04, 0.09, z);
knot.scale.y = 1.35;
group.add(knot);
}
const tie = new THREE.Mesh(
new THREE.TorusGeometry(0.154, 0.022, 6, 14),
new THREE.MeshStandardMaterial({
color: 0x8d4435,
roughness: 1
})
);
tie.rotation.y = Math.PI / 2;
group.add(tie);
scene.add(group);
return group;
}
const dispatch = createDispatch();
function handWorld(runner, armIndex) {
runner.root.updateMatrixWorld(true);
return runner.armPivots[armIndex].elbow.localToWorld(
new THREE.Vector3(0, -0.39, 0)
);
}
// -------------------------------------------------------------------------
// Camera controls implemented directly, without addons
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 1.3, 0),
radius: innerWidth < 700 ? 38 : 29,
theta: 0.64,
phi: 0.52,
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y +
controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.radius = innerWidth < 700 ? 38 : 29;
controls.theta = 0.64;
controls.phi = 0.52;
controls.target.set(0, 1.3, 0);
updateCamera();
}
updateCamera();
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const deltaX = event.clientX - controls.lastX;
const deltaY = event.clientY - controls.lastY;
controls.theta -= deltaX * 0.006;
controls.phi = clamp(controls.phi + deltaY * 0.005, 0.23, 1.18);
controls.lastX = event.clientX;
controls.lastY = event.clientY;
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("pointerleave", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
controls.radius = clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
16,
58
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Labels projected without CSS2DRenderer
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("label-arriving"),
anchor: () => arrivingRunner.root.position.clone().add(
new THREE.Vector3(0, 3.05, 0)
)
},
{
element: document.getElementById("label-departing"),
anchor: () => departingRunner.root.position.clone().add(
new THREE.Vector3(0, 3.05, 0)
)
},
{
element: document.getElementById("label-stop"),
anchor: () => shelter.position.clone().add(
new THREE.Vector3(0, 4.25, 0)
)
},
{
element: document.getElementById("label-dispatch"),
anchor: () => dispatch.position.clone().add(
new THREE.Vector3(0, 0.65, 0)
)
},
{
element: document.getElementById("label-road"),
anchor: () => {
const x = -8.0;
const center = pathPoint(x);
return new THREE.Vector3(
center.x,
terrainHeight(center.x, center.y) + 0.8,
center.y
);
}
},
{
element: document.getElementById("label-section"),
anchor: () => new THREE.Vector3(-10.5, -1.1, 12.15)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
for (const label of labels) {
projected.copy(label.anchor()).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.transform =
`translate(-50%, -100%) translate(${x}px, ${y}px)`;
}
}
// -------------------------------------------------------------------------
// Relay animation
// -------------------------------------------------------------------------
let animationTime = 0;
let paused = false;
let previousTime = performance.now();
const APPROACH_END = 3.4;
const TRANSFER_END = 5.1;
const DEPARTURE_END = 11.8;
function updateRelay(time) {
let arrivingX;
let departingX;
let arrivingIntensity = 0;
let departingIntensity = 0;
if (time < APPROACH_END) {
const t = smooth01(time / APPROACH_END);
arrivingX = lerp(-4.8, -0.78, t);
departingX = 0.78;
arrivingIntensity = 1;
} else if (time < TRANSFER_END) {
arrivingX = -0.78;
departingX = 0.78;
} else if (time < DEPARTURE_END) {
const t = smooth01((time - TRANSFER_END) / (DEPARTURE_END - TRANSFER_END));
arrivingX = -0.78;
departingX = lerp(0.78, 6.2, t);
departingIntensity = 1;
} else {
arrivingX = -0.78;
departingX = 6.2;
}
const runPhase = time * 8.2;
poseRunner(arrivingRunner, runPhase, arrivingIntensity);
poseRunner(departingRunner, runPhase + 0.7, departingIntensity);
// The visible-side arms are used for the dispatch.
const arrivingArm = arrivingRunner.armPivots[1];
const departingArm = departingRunner.armPivots[1];
if (time < APPROACH_END) {
arrivingArm.shoulder.rotation.z = 0.46;
arrivingArm.elbow.rotation.z = -0.25;
} else if (time < TRANSFER_END) {
const t = smooth01((time - APPROACH_END) / (TRANSFER_END - APPROACH_END));
arrivingArm.shoulder.rotation.z = lerp(0.46, 0.86, t);
arrivingArm.elbow.rotation.z = lerp(-0.25, -0.04, t);
departingArm.shoulder.rotation.z = lerp(0.10, -0.78, t);
departingArm.elbow.rotation.z = -0.08;
} else {
arrivingArm.shoulder.rotation.z = 0.20;
departingArm.shoulder.rotation.z = -0.66;
departingArm.elbow.rotation.z = -0.05;
}
const bob = Math.abs(Math.sin(runPhase)) * 0.055 * arrivingIntensity;
placeRunner(arrivingRunner, arrivingX, bob);
const departingBob =
Math.abs(Math.sin(runPhase + 0.7)) * 0.055 * departingIntensity;
placeRunner(departingRunner, departingX, departingBob);
const arrivingHand = handWorld(arrivingRunner, 1);
const departingHand = handWorld(departingRunner, 1);
dispatch.visible = true;
if (time < APPROACH_END) {
dispatch.position.copy(arrivingHand);
dispatch.rotation.set(0.15, 0.2, -0.12);
} else if (time < TRANSFER_END) {
const t = smooth01((time - APPROACH_END) / (TRANSFER_END - APPROACH_END));
dispatch.position.lerpVectors(arrivingHand, departingHand, t);
dispatch.position.y += Math.sin(t * Math.PI) * 0.22;
dispatch.rotation.y = lerp(0.2, -0.18, t);
dispatch.rotation.z = lerp(-0.12, 0.1, t);
} else {
dispatch.position.copy(departingHand);
dispatch.rotation.set(0.05, -0.15, 0.08);
}
}
// -------------------------------------------------------------------------
// UI and resize
// -------------------------------------------------------------------------
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
document.getElementById("replay").addEventListener("click", () => {
animationTime = 0;
});
document.getElementById("reset").addEventListener("click", resetCamera);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) animationTime += delta;
updateRelay(animationTime);
updateLabels();
renderer.render(scene, camera);
}
updateRelay(0);
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```