Prompt specification
Build or customize the Three.js 3D scene "Protect a manuscript during a journey" 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: Protect a manuscript during a journey
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/protect-a-manuscript-during-a-journey-x2400
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Timbuktu's manuscript scholarship and trade. Let users pack an illustrative manuscript for transport through a trade route scene. Show protection, carrying space, and handover stages without inventing a documented individual's itinerary. Low-poly.
Working Three.js Starter (protect-a-manuscript-during-a-journey-x2400):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#243b39">
<title>The Packed Book — Timbuktu</title>
<style>
:root {
--ink: #203431;
--muted: #66736c;
--paper: #f4ead6;
--paper-2: #eadcc1;
--accent: #bb633d;
--accent-dark: #87452d;
--green: #355d52;
--line: rgba(32, 52, 49, 0.16);
--shadow: 0 18px 60px rgba(38, 37, 29, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7c7a7;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#world {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
padding: 7px 11px;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 999px;
color: #f8f1df;
background: rgba(31, 53, 49, 0.82);
box-shadow: 0 6px 20px rgba(34, 35, 29, 0.15);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -100%);
opacity: 0;
transition: opacity 220ms ease;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 18px;
background: rgba(31, 53, 49, 0.6);
}
.intro {
position: fixed;
z-index: 5;
top: 24px;
left: 24px;
max-width: 430px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent-dark);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 420px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 4vw, 49px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
text-wrap: balance;
}
.intro-copy {
max-width: 390px;
margin: 13px 0 0;
color: #344b46;
font-size: 13px;
line-height: 1.55;
}
.composite-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(32, 52, 49, 0.16);
border-radius: 999px;
color: #304943;
background: rgba(248, 239, 219, 0.72);
backdrop-filter: blur(8px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.composite-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
}
#panel {
position: fixed;
z-index: 10;
top: 24px;
right: 24px;
bottom: 24px;
width: min(390px, calc(100vw - 48px));
display: flex;
flex-direction: column;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.52);
border-radius: 24px;
background: rgba(247, 238, 219, 0.94);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(1.1);
}
.panel-top {
padding: 20px 20px 13px;
border-bottom: 1px solid var(--line);
}
.panel-kicker {
margin-bottom: 13px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
#stages {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.stage-button {
position: relative;
min-width: 0;
padding: 11px 5px 10px;
border: 1px solid var(--line);
border-radius: 12px;
color: var(--muted);
background: rgba(255, 255, 255, 0.25);
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
transition:
color 180ms ease,
border-color 180ms ease,
background 180ms ease,
transform 180ms ease;
}
.stage-button:hover:not(:disabled) {
transform: translateY(-1px);
border-color: rgba(32, 52, 49, 0.34);
}
.stage-button.active {
color: #fff8ea;
border-color: var(--green);
background: var(--green);
}
.stage-button.done:not(.active) {
color: var(--green);
border-color: rgba(53, 93, 82, 0.34);
background: rgba(53, 93, 82, 0.08);
}
.stage-button:disabled {
opacity: 0.42;
cursor: not-allowed;
}
#content {
flex: 1;
min-height: 0;
overflow: auto;
padding: 22px 20px 18px;
scrollbar-width: thin;
scrollbar-color: rgba(32, 52, 49, 0.25) transparent;
}
#content h2 {
margin: 0 0 9px;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
font-weight: 500;
line-height: 1.06;
letter-spacing: -0.025em;
}
.stage-copy {
margin: 0 0 19px;
color: #58665f;
font-size: 12px;
line-height: 1.58;
}
.section-label {
margin: 19px 0 9px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.choice-grid {
display: grid;
gap: 8px;
}
.choice-grid.compact {
grid-template-columns: repeat(3, 1fr);
}
.choice {
width: 100%;
padding: 12px;
border: 1px solid var(--line);
border-radius: 14px;
color: var(--ink);
background: rgba(255, 255, 255, 0.33);
text-align: left;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.choice:hover {
transform: translateY(-1px);
border-color: rgba(32, 52, 49, 0.38);
}
.choice.selected {
border-color: var(--accent);
background: rgba(187, 99, 61, 0.1);
box-shadow: inset 0 0 0 1px rgba(187, 99, 61, 0.12);
}
.choice-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 4px;
font-size: 12px;
font-weight: 800;
}
.choice-title::after {
content: "";
width: 8px;
height: 8px;
flex: 0 0 auto;
border: 1px solid rgba(32, 52, 49, 0.4);
border-radius: 50%;
}
.choice.selected .choice-title::after {
border-color: var(--accent);
background: var(--accent);
box-shadow: 0 0 0 3px rgba(187, 99, 61, 0.13);
}
.choice-copy {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.42;
}
.unit-badge {
display: inline-block;
margin-top: 8px;
padding: 4px 7px;
border-radius: 999px;
color: #7d4b31;
background: rgba(187, 99, 61, 0.1);
font-size: 9px;
font-weight: 800;
}
.cargo-grid .choice-title::after {
border-radius: 3px;
}
.cargo-grid .choice.selected .choice-title::after {
border-radius: 3px;
}
.meter {
height: 9px;
overflow: hidden;
border-radius: 999px;
background: rgba(32, 52, 49, 0.1);
}
.meter > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--green);
transition:
width 260ms ease,
background 200ms ease;
}
.meter.over > span {
background: #a54031;
}
.meter-label {
display: flex;
justify-content: space-between;
margin: 7px 0 15px;
color: var(--muted);
font-size: 10px;
}
.manifest {
display: grid;
gap: 6px;
margin-top: 13px;
}
.manifest-row {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 8px 10px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.32);
color: #4c5d56;
font-size: 10px;
}
.manifest-row strong {
color: var(--ink);
}
.note {
margin-top: 17px;
padding: 12px 13px;
border-left: 3px solid var(--accent);
border-radius: 0 11px 11px 0;
color: #5a6258;
background: rgba(255, 255, 255, 0.29);
font-size: 10px;
line-height: 1.52;
}
.route-status {
display: flex;
align-items: center;
gap: 11px;
margin: 17px 0;
padding: 13px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.3);
}
.route-status-icon {
width: 30px;
height: 30px;
display: grid;
flex: 0 0 auto;
place-items: center;
border-radius: 50%;
color: #fff8ea;
background: var(--green);
font-size: 15px;
}
.route-status strong {
display: block;
margin-bottom: 2px;
font-size: 11px;
}
.route-status span {
color: var(--muted);
font-size: 10px;
}
.panel-footer {
padding: 14px 20px 19px;
border-top: 1px solid var(--line);
background: rgba(244, 234, 214, 0.72);
}
#summary {
min-height: 28px;
margin-bottom: 9px;
color: #59665f;
font-size: 10px;
line-height: 1.4;
}
#summary.warning {
color: #93402f;
font-weight: 750;
}
#primary {
width: 100%;
padding: 13px 16px;
border: 0;
border-radius: 13px;
color: #fff8ea;
background: var(--accent);
box-shadow: 0 8px 20px rgba(126, 64, 37, 0.2);
cursor: pointer;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.055em;
text-transform: uppercase;
transition:
transform 160ms ease,
background 160ms ease,
opacity 160ms ease;
}
#primary:hover:not(:disabled) {
transform: translateY(-1px);
background: var(--accent-dark);
}
#primary:disabled {
opacity: 0.48;
cursor: not-allowed;
box-shadow: none;
}
#restart {
width: 100%;
margin-top: 8px;
padding: 8px;
border: 0;
color: var(--muted);
background: transparent;
cursor: pointer;
font-size: 10px;
font-weight: 750;
}
.world-hint {
position: fixed;
z-index: 4;
left: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.36);
border-radius: 999px;
color: #334b45;
background: rgba(246, 237, 217, 0.76);
backdrop-filter: blur(9px);
pointer-events: none;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
}
.world-hint span {
width: 7px;
height: 7px;
border: 1px solid var(--green);
border-radius: 50%;
}
#reset-camera {
position: fixed;
z-index: 5;
right: 438px;
bottom: 24px;
width: 38px;
height: 38px;
border: 1px solid rgba(255, 255, 255, 0.42);
border-radius: 50%;
color: var(--ink);
background: rgba(246, 237, 217, 0.83);
box-shadow: 0 8px 24px rgba(36, 38, 30, 0.12);
cursor: pointer;
font-size: 17px;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #d7c7a7;
font-family: Georgia, serif;
font-size: 20px;
}
@media (max-width: 800px) {
.intro {
top: 13px;
left: 15px;
right: 15px;
}
h1 {
max-width: 290px;
font-size: 31px;
}
.intro-copy {
display: none;
}
.composite-badge {
margin-top: 8px;
padding: 5px 8px;
font-size: 8px;
}
#panel {
top: auto;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: min(57vh, 570px);
border-right: 0;
border-bottom: 0;
border-left: 0;
border-radius: 22px 22px 0 0;
}
.panel-top {
padding: 12px 15px 10px;
}
.panel-kicker {
display: none;
}
#content {
padding: 16px 15px 13px;
}
#content h2 {
font-size: 22px;
}
.panel-footer {
padding: 10px 15px 13px;
}
.world-hint {
display: none;
}
#reset-camera {
right: 16px;
bottom: calc(min(57vh, 570px) + 14px);
}
}
</style>
</head>
<body>
<canvas
id="world"
tabindex="0"
aria-label="Interactive low-poly scene of manuscript scholarship and trade in Timbuktu. Drag to orbit and use the mouse wheel to zoom."
></canvas>
<div id="labels" aria-hidden="true">
<div class="world-label" id="label-court">Timbuktu learning court</div>
<div class="world-label" id="label-load">Shared caravan load</div>
<div class="world-label" id="label-route">Schematic trade route</div>
<div class="world-label" id="label-waypoint">Generic receiving waypoint</div>
</div>
<header class="intro">
<div class="eyebrow">Manuscripts in motion · Timbuktu</div>
<h1>The Packed Book</h1>
<p class="intro-copy">
Explore an illustrative manuscript through a learning court and a
mixed-cargo trade landscape. Protect the packet, fit it into carrying
space, and complete a generic handover.
</p>
<div class="composite-badge">Composite scenario · not a named itinerary</div>
</header>
<aside id="panel" aria-label="Manuscript packing controls">
<div class="panel-top">
<div class="panel-kicker">Interactive field exercise</div>
<nav id="stages" aria-label="Packing stages">
<button class="stage-button active" data-stage="0">1 · Protect</button>
<button class="stage-button" data-stage="1">2 · Carry</button>
<button class="stage-button" data-stage="2" disabled>3 · Hand over</button>
</nav>
</div>
<div id="content"></div>
<div class="panel-footer">
<div id="summary"></div>
<button id="primary"></button>
<button id="restart" hidden>Start a new packing</button>
</div>
</aside>
<div class="world-hint"><span></span> Drag to orbit · scroll to zoom</div>
<button id="reset-camera" title="Reset camera" aria-label="Reset camera">↺</button>
<div id="loading">Preparing the learning court…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// State and descriptive data
// -------------------------------------------------------------------------
const protectionOptions = {
textile: {
label: "Woven protective wrap",
copy: "A flexible textile layer around the folio block.",
size: 1
},
cover: {
label: "Stiffened leather cover",
copy: "A firm cover intended to reduce abrasion and bending.",
size: 1
},
combined: {
label: "Wrap and fitted cover",
copy: "More layers, but a larger packet and more carrying space.",
size: 2
}
};
const carrierOptions = {
satchel: {
label: "Satchel",
copy: "Compact personal carrier.",
capacity: 3
},
basket: {
label: "Reed basket",
copy: "Ventilated shared carrier.",
capacity: 6
},
coffer: {
label: "Wooden coffer",
copy: "Largest and most protective shared carrier.",
capacity: 10
}
};
const cargoOptions = {
textile: {
label: "Textile roll",
size: 2
},
grain: {
label: "Grain sack",
size: 3
},
vessel: {
label: "Sealed vessel",
size: 2
}
};
const handoverOptions = {
sealed: {
label: "Hand over sealed",
copy: "The recipient receives the protected packet and opens it later."
},
checked: {
label: "Check at destination",
copy: "The binding and outer layers are inspected at the receiving point."
},
catalogued: {
label: "Record on arrival",
copy: "A descriptive record is created with the generic handover."
}
};
const state = {
stage: 0,
protection: "textile",
carrier: "basket",
cargo: new Set(["textile"]),
handover: "sealed",
packed: false,
travelling: false,
arrived: false,
handing: false,
handed: false,
routeProgress: 0
};
const $ = (selector) => document.querySelector(selector);
const content = $("#content");
const summary = $("#summary");
const primary = $("#primary");
const restart = $("#restart");
// -------------------------------------------------------------------------
// Renderer, camera and custom camera controls
// -------------------------------------------------------------------------
const canvas = $("#world");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd7c7a7);
scene.fog = new THREE.Fog(0xd7c7a7, 23, 54);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
target: new THREE.Vector3(-8.4, 1.1, 2.2),
desiredTarget: new THREE.Vector3(-8.4, 1.1, 2.2),
yaw: 0.62,
desiredYaw: 0.62,
pitch: 1.02,
desiredPitch: 1.02,
radius: 8.2,
desiredRadius: 8.2
};
function updateCamera() {
cameraState.target.lerp(cameraState.desiredTarget, 0.075);
cameraState.yaw +=
(cameraState.desiredYaw - cameraState.yaw) * 0.09;
cameraState.pitch +=
(cameraState.desiredPitch - cameraState.pitch) * 0.09;
cameraState.radius +=
(cameraState.desiredRadius - cameraState.radius) * 0.09;
const sinPhi = Math.sin(cameraState.pitch);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.yaw),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.pitch),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
let dragging = false;
let dragX = 0;
let dragY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
dragX = event.clientX;
dragY = event.clientY;
cameraState.desiredYaw -= dx * 0.006;
cameraState.desiredPitch = THREE.MathUtils.clamp(
cameraState.desiredPitch + dy * 0.005,
0.36,
1.36
);
});
function stopDragging() {
dragging = false;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
4.2,
24
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
cameraState.desiredYaw += 0.12;
}
if (event.key === "ArrowRight") {
cameraState.desiredYaw -= 0.12;
}
if (event.key === "ArrowUp") {
cameraState.desiredPitch = Math.max(
0.36,
cameraState.desiredPitch - 0.08
);
}
if (event.key === "ArrowDown") {
cameraState.desiredPitch = Math.min(
1.36,
cameraState.desiredPitch + 0.08
);
}
if (event.key === "+" || event.key === "=") {
cameraState.desiredRadius = Math.max(
4.2,
cameraState.desiredRadius - 0.6
);
}
if (event.key === "-") {
cameraState.desiredRadius = Math.min(
24,
cameraState.desiredRadius + 0.6
);
}
});
// -------------------------------------------------------------------------
// Lighting and reusable low-poly helpers
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf7e9cb, 0x76543c, 2.1);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xffe5b2, 3.2);
sunLight.position.set(-9, 15, 8);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -24;
sunLight.shadow.camera.right = 24;
sunLight.shadow.camera.top = 20;
sunLight.shadow.camera.bottom = -20;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 45;
sunLight.shadow.bias = -0.00035;
scene.add(sunLight);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
earth: material(0xc17c4d),
earthLight: material(0xd59a68),
earthPale: material(0xdba877),
earthDark: material(0x9e5e3c),
sand: material(0xcaa979),
sandLight: material(0xe2c594),
path: material(0xa97046),
wood: material(0x684431),
woodLight: material(0x8e5b38),
darkWood: material(0x3f3026),
reed: material(0xb89050),
reedDark: material(0x7e6039),
parchment: material(0xe8d4a5),
page: material(0xf1dfb9),
ink: material(0x392d27),
leather: material(0x73422b),
leatherLight: material(0x9c603b),
cloth: material(0x365d5b),
clothRed: material(0xa44f37),
clothGold: material(0xc29245),
blue: material(0x446d7a),
black: material(0x252723),
skin: material(0x9a6746),
robe: material(0x536a5e),
robeBlue: material(0x3f5968),
white: material(0xe9dfc6),
green: material(0x62784d),
camel: material(0xb7834f),
camelDark: material(0x8e5f3b),
camelLight: material(0xd1a069),
iron: material(0x4e5047, { metalness: 0.25 })
};
function mesh(parent, geometry, mat, x = 0, y = 0, z = 0) {
const object = new THREE.Mesh(geometry, mat);
object.position.set(x, y, z);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(parent, w, h, d, mat, x = 0, y = 0, z = 0) {
return mesh(
parent,
new THREE.BoxGeometry(w, h, d),
mat,
x,
y,
z
);
}
function cylinder(
parent,
top,
bottom,
height,
segments,
mat,
x = 0,
y = 0,
z = 0
) {
return mesh(
parent,
new THREE.CylinderGeometry(top, bottom, height, segments),
mat,
x,
y,
z
);
}
function dodeca(parent, radius, mat, x = 0, y = 0, z = 0) {
return mesh(
parent,
new THREE.DodecahedronGeometry(radius, 0),
mat,
x,
y,
z
);
}
function cylinderBetween(parent, a, b, radius, mat, segments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const object = cylinder(
parent,
radius,
radius,
length,
segments,
mat
);
object.position.copy(a).add(b).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return object;
}
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
}
}
// -------------------------------------------------------------------------
// Terrain, sun and route
// -------------------------------------------------------------------------
let seed = 41;
function random() {
seed = (seed * 9301 + 49297) % 233280;
return seed / 233280;
}
const groundGeometry = new THREE.PlaneGeometry(52, 32, 22, 14);
groundGeometry.rotateX(-Math.PI / 2);
const groundPositions = groundGeometry.attributes.position;
for (let i = 0; i < groundPositions.count; i++) {
groundPositions.setY(i, (random() - 0.5) * 0.12);
}
groundGeometry.computeVertexNormals();
const ground = mesh(
scene,
groundGeometry,
M.sand,
0,
-0.07,
0
);
ground.castShadow = false;
const sun = mesh(
scene,
new THREE.SphereGeometry(1.15, 10, 7),
new THREE.MeshBasicMaterial({ color: 0xffe4a8 }),
-15,
13,
-18
);
sun.castShadow = false;
const routeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-3.9, 0.08, 0.5),
new THREE.Vector3(-1.1, 0.09, -0.35),
new THREE.Vector3(2.5, 0.1, 0.0),
new THREE.Vector3(6.0, 0.11, -0.45),
new THREE.Vector3(10.7, 0.12, 1.55)
]);
const routeMesh = mesh(
scene,
new THREE.TubeGeometry(routeCurve, 90, 0.055, 5, false),
M.path,
0,
0,
0
);
routeMesh.castShadow = false;
const routeArrowMaterial = material(0xe0b262);
const routeUp = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < 11; i++) {
const t = 0.06 + (i / 10) * 0.84;
const point = routeCurve.getPointAt(t);
const tangent = routeCurve.getTangentAt(t).normalize();
const arrow = mesh(
scene,
new THREE.ConeGeometry(0.09, 0.28, 3),
routeArrowMaterial,
point.x,
point.y + 0.07,
point.z
);
arrow.quaternion.setFromUnitVectors(routeUp, tangent);
arrow.castShadow = false;
}
// A handful of low-poly scrub plants for scale.
for (let i = 0; i < 35; i++) {
const x = -18 + random() * 38;
const z = -10 + random() * 20;
if (x > -14 && x < -3 && z > -5 && z < 5) continue;
const shrub = new THREE.Group();
shrub.position.set(x, 0, z);
const size = 0.2 + random() * 0.28;
for (let j = 0; j < 3; j++) {
const leaf = mesh(
shrub,
new THREE.ConeGeometry(size, size * 3, 4),
M.green,
(random() - 0.5) * 0.25,
size * 1.2,
(random() - 0.5) * 0.25
);
leaf.rotation.z = (random() - 0.5) * 0.5;
}
scene.add(shrub);
}
// -------------------------------------------------------------------------
// Timbuktu-inspired learning court and earthen architecture
// -------------------------------------------------------------------------
const city = new THREE.Group();
scene.add(city);
const cityPlatform = box(
city,
15,
0.18,
10,
M.earthPale,
-9.3,
0.01,
-1.1
);
cityPlatform.castShadow = false;
function addBuilding(parent, x, z, w, h, d, wallMat) {
const group = new THREE.Group();
group.position.set(x, 0, z);
parent.add(group);
box(group, w, h, d, wallMat, 0, h / 2, 0);
box(group, w + 0.14, 0.18, d + 0.14, M.earthLight, 0, h + 0.05, 0);
const parapetHeight = 0.28;
box(
group,
w * 0.24,
parapetHeight,
0.16,
wallMat,
-w * 0.31,
h + 0.26,
d / 2
);
box(
group,
w * 0.24,
parapetHeight,
0.16,
wallMat,
w * 0.31,
h + 0.26,
d / 2
);
const door = box(
group,
0.62,
1.22,
0.08,
M.darkWood,
0,
0.61,
d / 2 + 0.045
);
door.castShadow = false;
for (const side of [-1, 1]) {
const window = box(
group,
0.35,
0.48,
0.055,
M.black,
side * w * 0.29,
h * 0.61,
d / 2 + 0.045
);
window.castShadow = false;
}
// Small triangular roof forms add silhouette without implying a specific monument.
if (w > 3.2) {
const roof = mesh(
group,
new THREE.ConeGeometry(w * 0.47, 0.75, 4),
M.earthDark,
0,
h + 0.43,
0
);
roof.rotation.y = Math.PI / 4;
roof.scale.z = d / w;
}
return group;
}
addBuilding(city, -13.0, -2.8, 4.1, 3.1, 3.5, M.earth);
addBuilding(city, -8.6, -4.6, 4.4, 3.8, 3.7, M.earthLight);
addBuilding(city, -4.8, -3.1, 3.4, 2.7, 3.0, M.earthDark);
addBuilding(city, -12.2, -6.0, 3.6, 2.6, 3.2, M.earthPale);
addBuilding(city, -6.3, -7.1, 4.8, 2.9, 3.1, M.earth);
const minaret = new THREE.Group();
minaret.position.set(-14.1, 0, -5.2);
city.add(minaret);
cylinder(minaret, 0.34, 0.53, 4.8, 6, M.earth, 0, 2.4, 0);
cylinder(minaret, 0.48, 0.48, 0.38, 6, M.earthDark, 0, 4.55, 0);
cylinder(minaret, 0.42, 0.42, 0.7, 6, M.earthLight, 0, 5.05, 0);
dodeca(minaret, 0.22, M.earthDark, 0, 5.52, 0);
// Scholar's desk and open manuscript.
const desk = new THREE.Group();
desk.position.set(-9.1, 0, 2.65);
scene.add(desk);
box(desk, 3.1, 0.16, 1.25, M.woodLight, 0, 0.93, 0);
box(desk, 0.16, 0.92, 0.16, M.darkWood, -1.32, 0.45, -0.42);
box(desk, 0.16, 0.92, 0.16, M.darkWood, 1.32, 0.45, -0.42);
box(desk, 0.16, 0.92, 0.16, M.darkWood, -1.32, 0.45, 0.42);
box(desk, 0.16, 0.92, 0.16, M.darkWood, 1.32, 0.45, 0.42);
const openBook = new THREE.Group();
openBook.position.set(-9.25, 1.06, 2.65);
scene.add(openBook);
box(openBook, 0.54, 0.055, 0.66, M.page, -0.29, 0, 0);
box(openBook, 0.54, 0.055, 0.66, M.page, 0.29, 0, 0);
box(openBook, 0.045, 0.065, 0.68, M.leather, 0, -0.01, 0);
for (const side of [-1, 1]) {
for (let line = 0; line < 5; line++) {
box(
openBook,
0.34,
0.009,
0.018,
M.ink,
side * 0.29,
0.035,
-0.21 + line * 0.1
);
}
}
// Reed pen and ink vessel.
const reedPen = cylinder(
desk,
0.012,
0.018,
0.72,
5,
M.reedDark,
0.62,
1.08,
0.12
);
reedPen.rotation.z = Math.PI / 2.6;
cylinder(desk, 0.09, 0.1, 0.14, 8, M.black, 1.03, 1.08, 0.1);
// Low wooden shelf filled with manuscript boxes and volumes.
const shelf = new THREE.Group();
shelf.position.set(-10.7, 0, 0.75);
scene.add(shelf);
box(shelf, 3.0, 0.12, 0.62, M.darkWood, 0, 0.17, 0);
box(shelf, 3.0, 0.12, 0.62, M.darkWood, 0, 1.7, 0);
box(shelf, 0.14, 1.65, 0.62, M.darkWood, -1.45, 0.9, 0);
box(shelf, 0.14, 1.65, 0.62, M.darkWood, 1.45, 0.9, 0);
box(shelf, 3.0, 1.55, 0.1, M.wood, 0, 0.9, -0.27);
for (let row = 0; row < 2; row++) {
for (let i = 0; i < 7; i++) {
const mat = [M.leather, M.cloth, M.clothRed, M.blue, M.clothGold][
(i + row) % 5
];
const volume = box(
shelf,
0.2 + random() * 0.1,
0.44 + random() * 0.14,
0.3,
mat,
-1.05 + i * 0.35,
0.45 + row * 0.78,
0.02
);
volume.rotation.z = (random() - 0.5) * 0.08;
}
}
function createScholar(parent, x, z, robeMaterial, facing = 1) {
const person = new THREE.Group();
person.position.set(x, 0, z);
person.rotation.y = facing;
parent.add(person);
cylinder(person, 0.21, 0.37, 0.95, 6, robeMaterial, 0, 0.48, 0);
dodeca(person, 0.2, M.skin, 0, 1.13, 0);
cylinder(person, 0.21, 0.23, 0.16, 6, robeMaterial, 0, 1.28, 0);
cylinderBetween(
person,
new THREE.Vector3(-0.17, 0.8, 0),
new THREE.Vector3(-0.28, 0.55, 0.38),
0.075,
robeMaterial
);
cylinderBetween(
person,
new THREE.Vector3(0.17, 0.8, 0),
new THREE.Vector3(0.27, 0.58, 0.42),
0.075,
robeMaterial
);
return person;
}
createScholar(scene, -9.4, 1.55, M.robeBlue, 0);
createScholar(scene, -7.55, 3.18, M.robe, Math.PI);
// Stool and a second writing surface.
cylinder(scene, 0.3, 0.34, 0.48, 7, M.wood, -7.75, 0.24, 3.8);
box(scene, 1.2, 0.12, 0.72, M.woodLight, -7.65, 0.54, 3.8);
box(scene, 0.42, 0.05, 0.52, M.parchment, -7.65, 0.64, 3.8);
// -------------------------------------------------------------------------
// Illustrative protected manuscript packet
// -------------------------------------------------------------------------
const packet = new THREE.Group();
scene.add(packet);
function rebuildPacket() {
clearGroup(packet);
const pages = box(packet, 0.78, 0.13, 0.54, M.page, 0, 0.08, 0);
if (state.protection === "textile") {
box(packet, 0.92, 0.18, 0.65, M.cloth, 0, 0.08, 0);
box(packet, 0.12, 0.195, 0.67, M.clothRed, 0, 0.085, 0);
box(packet, 0.25, 0.06, 0.18, M.clothGold, 0, 0.195, 0);
}
if (state.protection === "cover") {
box(packet, 0.84, 0.045, 0.59, M.leather, 0, 0, 0);
box(packet, 0.84, 0.045, 0.59, M.leatherLight, 0, 0.165, 0);
box(packet, 0.11, 0.055, 0.61, M.clothRed, 0, 0.165, 0);
}
if (state.protection === "combined") {
box(packet, 0.94, 0.055, 0.67, M.cloth, 0, -0.01, 0);
box(packet, 0.82, 0.045, 0.58, M.leather, 0, 0.035, 0);
box(packet, 0.8, 0.04, 0.56, M.leatherLight, 0, 0.18, 0);
box(packet, 0.1, 0.06, 0.6, M.clothGold, 0, 0.19, 0);
}
packet.traverse((object) => {
if (object.isMesh) {
object.castShadow = true;
object.receiveShadow = true;
}
});
}
rebuildPacket();
// -------------------------------------------------------------------------
// Low-poly pack camel
// -------------------------------------------------------------------------
const camel = new THREE.Group();
scene.add(camel);
box(camel, 1.9, 0.72, 0.78, M.camel, -0.05, 1.38, 0);
dodeca(camel, 0.4, M.camelDark, -0.3, 1.87, 0).scale.set(
1.1,
0.75,
0.9
);
dodeca(camel, 0.33, M.camelLight, 0.18, 1.8, 0).scale.set(
0.9,
0.65,
0.85
);
cylinderBetween(
camel,
new THREE.Vector3(0.65, 1.55, 0),
new THREE.Vector3(1.02, 2.43, 0),
0.22,
M.camel
);
box(camel, 0.62, 0.32, 0.32, M.camelLight, 1.28, 2.48, 0);
box(camel, 0.38, 0.22, 0.28, M.camelDark, 1.64, 2.4, 0);
box(camel, 0.16, 0.14, 0.28, M.camelLight, 1.26, 2.72, 0);
for (const x of [-0.62, 0.55]) {
for (const z of [-0.28, 0.28]) {
cylinderBetween(
camel,
new THREE.Vector3(x, 0.08, z),
new THREE.Vector3(x + (x < 0 ? 0.08 : -0.05), 1.16, z),
0.095,
M.camelDark
);
box(camel, 0.27, 0.12, 0.22, M.darkWood, x, 0.08, z);
}
}
cylinderBetween(
camel,
new THREE.Vector3(-0.95, 1.55, 0),
new THREE.Vector3(-1.25, 0.75, 0),
0.035,
M.camelDark
);
box(camel, 1.35, 0.09, 1.08, M.clothRed, -0.2, 1.78, 0);
box(camel, 0.85, 0.14, 0.78, M.darkWood, -0.2, 1.86, 0);
const loadGroup = new THREE.Group();
camel.add(loadGroup);
let packetAnchor = new THREE.Vector3(-0.25, 1.72, 0.72);
function buildLoad() {
clearGroup(loadGroup);
if (state.carrier === "basket") {
const basket = new THREE.Group();
basket.position.set(-0.25, 1.66, 0.74);
loadGroup.add(basket);
const body = mesh(
basket,
new THREE.CylinderGeometry(0.46, 0.35, 0.62, 8, 1, true),
M.reed
);
body.material.side = THREE.DoubleSide;
const rim = mesh(
basket,
new THREE.TorusGeometry(0.46, 0.045, 5, 8),
M.reedDark
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.31;
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
box(
basket,
0.035,
0.6,
0.035,
M.reedDark,
Math.cos(angle) * 0.39,
0,
Math.sin(angle) * 0.39
);
}
const lid = box(
basket,
0.9,
0.055,
0.68,
M.reed,
0,
0.38,
-0.18
);
lid.rotation.x = -0.65;
packetAnchor.set(-0.25, 1.82, 0.74);
}
if (state.carrier === "coffer") {
const coffer = new THREE.Group();
coffer.position.set(-0.22, 1.48, 0.73);
loadGroup.add(coffer);
box(coffer, 1.08, 0.16, 0.76, M.wood, 0, -0.25, 0);
box(coffer, 1.08, 0.58, 0.09, M.woodLight, 0, 0, -0.33);
box(coffer, 0.09, 0.58, 0.76, M.woodLight, -0.5, 0, 0);
box(coffer, 0.09, 0.58, 0.76, M.woodLight, 0.5, 0, 0);
box(coffer, 1.08, 0.58, 0.09, M.woodLight, 0, 0, 0.33);
box(coffer, 0.12, 0.07, 0.82, M.iron, 0, 0.08, 0);
packetAnchor.set(-0.22, 1.83, 0.73);
}
if (state.carrier === "satchel") {
const satchel = new THREE.Group();
satchel.position.set(-0.22, 1.34, 0.72);
loadGroup.add(satchel);
box(satchel, 0.86, 0.52, 0.34, M.leather, 0, 0, 0);
const flap = box(
satchel,
0.88,
0.24,
0.37,
M.leatherLight,
0,
0.18,
0.03
);
flap.rotation.x = 0.12;
const strap = box(
satchel,
0.08,
0.95,
0.06,
M.leather,
0.22,
0.38,
0.02
);
strap.rotation.z = -0.35;
packetAnchor.set(-0.22, 1.68, 0.72);
}
let cargoIndex = 0;
for (const id of state.cargo) {
const cargo = new THREE.Group();
cargo.position.set(
-0.62 + cargoIndex * 0.58,
1.54,
-0.72
);
loadGroup.add(cargo);
if (id === "textile") {
const roll = cylinder(
cargo,
0.19,
0.19,
0.86,
8,
M.clothBlue || M.blue
);
roll.rotation.z = Math.PI / 2;
const band = cylinder(cargo, 0.205, 0.205, 0.08, 8, M.clothGold);
band.rotation.z = Math.PI / 2;
}
if (id === "grain") {
const sack = dodeca(cargo, 0.39, M.parchment);
sack.scale.set(1.1, 0.9, 0.85);
box(cargo, 0.08, 0.72, 0.08, M.woodLight, 0, 0.08, 0);
}
if (id === "vessel") {
cylinder(cargo, 0.17, 0.25, 0.55, 8, M.clothRed, 0, 0, 0);
cylinder(cargo, 0.13, 0.18, 0.18, 8, M.leatherLight, 0, 0.32, 0);
box(cargo, 0.35, 0.045, 0.35, M.cloth, 0, 0.43, 0);
}
cargoIndex++;
}
}
buildLoad();
function setPacketOnCamel() {
if (packet.parent !== camel) {
camel.add(packet);
}
packet.position.copy(packetAnchor);
packet.rotation.set(0, 0, 0);
packet.scale.set(1, 1, 1);
}
function setPacketOnDesk() {
scene.attach(packet);
packet.position.set(-7.75, 1.06, 2.68);
packet.rotation.set(0, -0.12, 0);
packet.scale.set(1, 1, 1);
}
// -------------------------------------------------------------------------
// Generic receiving waypoint and market canopy
// -------------------------------------------------------------------------
const waypoint = new THREE.Group();
waypoint.position.set(11.1, 0, 3.05);
scene.add(waypoint);
const canopy = new THREE.Group();
waypoint.add(canopy);
box(canopy, 2.9, 0.1, 1.8, M.cloth, 0, 2.42, 0);
for (const x of [-1.25, 1.25]) {
for (const z of [-0.7, 0.7]) {
box(canopy, 0.1, 2.4, 0.1, M.wood, x, 1.2, z);
}
}
// Receiving table.
const receiveTable = new THREE.Group();
receiveTable.position.set(10.65, 0, 2.05);
scene.add(receiveTable);
box(receiveTable, 1.8, 0.14, 0.95, M.woodLight, 0, 1.0, 0);
box(receiveTable, 0.13, 1.0, 0.13, M.darkWood, -0.72, 0.5, -0.34);
box(receiveTable, 0.13, 1.0, 0.13, M.darkWood, 0.72, 0.5, -0.34);
box(receiveTable, 0.13, 1.0, 0.13, M.darkWood, -0.72, 0.5, 0.34);
box(receiveTable, 0.13, 1.0, 0.13, M.darkWood, 0.72, 0.5, 0.34);
const receiver = createScholar(
scene,
10.7,
1.32,
M.robeBlue,
0
);
receiver.scale.setScalar(1.04);
addBuilding(waypoint, 1.7, 1.4, 4.0, 3.0, 3.4, M.earthDark);
// Small generic wares under the canopy.
cylinder(waypoint, 0.22, 0.3, 0.5, 8, M.leather, -0.75, 0.25, 0.2);
box(waypoint, 0.75, 0.42, 0.52, M.clothRed, 0.45, 0.21, 0.2);
cylinder(waypoint, 0.25, 0.32, 0.6, 8, M.reed, -0.15, 0.3, 0.7);
// A simple arrival record appears after handover.
const receipt = new THREE.Group();
receipt.position.set(10.7, 1.09, 1.85);
receipt.visible = false;
scene.add(receipt);
box(receipt, 0.58, 0.025, 0.38, M.white, 0, 0, 0);
for (let i = 0; i < 3; i++) {
box(receipt, 0.35, 0.012, 0.018, M.ink, -0.03, 0.022, -0.08 + i * 0.07);
}
cylinder(receipt, 0.055, 0.055, 0.025, 8, M.clothRed, 0.19, 0.028, 0.08);
// -------------------------------------------------------------------------
// World labels
// -------------------------------------------------------------------------
const worldLabels = [
{
element: $("#label-court"),
position: new THREE.Vector3(-9.0, 3.0, 2.2),
stages: [0]
},
{
element: $("#label-load"),
position: new THREE.Vector3(-3.7, 3.0, 0.6),
stages: [1]
},
{
element: $("#label-route"),
position: new THREE.Vector3(3.6, 1.25, -0.2),
stages: [2]
},
{
element: $("#label-waypoint"),
position: new THREE.Vector3(10.8, 3.0, 2.1),
stages: [2]
}
];
function updateWorldLabels() {
for (const label of worldLabels) {
const projected = label.position.clone().project(camera);
const visible =
label.stages.includes(state.stage) &&
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
label.element.style.opacity = visible ? "1" : "0";
if (visible) {
label.element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
}
// -------------------------------------------------------------------------
// UI and scenario progression
// -------------------------------------------------------------------------
function usedSpace() {
const manuscriptSize = protectionOptions[state.protection].size;
let cargoSize = 0;
for (const id of state.cargo) {
cargoSize += cargoOptions[id].size;
}
return manuscriptSize + cargoSize;
}
function updateStageButtons() {
document.querySelectorAll(".stage-button").forEach((button) => {
const index = Number(button.dataset.stage);
button.classList.toggle("active", index === state.stage);
button.classList.toggle("done", index < state.stage);
button.disabled = index === 2 && !state.packed;
});
}
function resetCamera() {
cameraState.desiredYaw = 0.62;
cameraState.desiredPitch = 1.02;
if (state.stage === 0) {
cameraState.desiredTarget.set(-8.4, 1.1, 2.2);
cameraState.desiredRadius = 8.2;
} else if (state.stage === 1) {
cameraState.desiredTarget.set(-3.7, 1.55, 0.7);
cameraState.desiredRadius = 8;
} else {
cameraState.desiredTarget.set(10.6, 1.35, 2.0);
cameraState.desiredRadius = 9;
}
}
function showStage(index) {
if (index === 2 && !state.packed) return;
state.stage = index;
state.travelling = false;
if (index === 0) {
setPacketOnDesk();
openBook.visible = true;
cameraState.desiredTarget.set(-8.4, 1.1, 2.2);
cameraState.desiredRadius = 8.2;
}
if (index === 1) {
state.packed = false;
state.arrived = false;
state.handing = false;
state.handed = false;
receipt.visible = false;
openBook.visible = false;
camel.position.copy(routeCurve.getPointAt(0));
buildLoad();
setPacketOnCamel();
cameraState.desiredTarget.set(-3.7, 1.55, 0.7);
cameraState.desiredRadius = 8;
}
if (index === 2) {
state.arrived = false;
state.handing = false;
state.handed = false;
state.routeProgress = 0;
receipt.visible = false;
openBook.visible = false;
camel.position.copy(routeCurve.getPointAt(0));
buildLoad();
setPacketOnCamel();
state.travelling = true;
state.travelStart = performance.now();
cameraState.desiredTarget.set(-3.7, 1.5, 0.7);
cameraState.desiredRadius = 8.6;
}
updateStageButtons();
renderPanel();
}
function renderPanel() {
updateStageButtons();
if (state.stage === 0) {
const options = Object.entries(protectionOptions)
.map(
([id, option]) => `
<button
class="choice ${state.protection === id ? "selected" : ""}"
data-protection="${id}"
aria-pressed="${state.protection === id}"
>
<span class="choice-title">${option.label}</span>
<span class="choice-copy">${option.copy}</span>
<span class="unit-badge">${option.size} space unit${
option.size === 1 ? "" : "s"
}</span>
</button>
`
)
.join("");
content.innerHTML = `
<div class="eyebrow">Stage 1 of 3 · Protection</div>
<h2>Choose a protective layer</h2>
<p class="stage-copy">
Copying, commentary, teaching, and storage depended on protecting
manuscripts from bending, abrasion, and handling. Build an
illustrative packet around an unknown folio group.
</p>
<div class="section-label">Protective packet</div>
<div class="choice-grid">${options}</div>
<div class="note">
The object on the desk is an illustrative composite packet, not a
facsimile of a particular Timbuktu manuscript. The open folio
evokes scholarly reading and copying without identifying a book
or owner.
</div>
`;
content.querySelectorAll("[data-protection]").forEach((button) => {
button.addEventListener("click", () => {
state.protection = button.dataset.protection;
state.packed = false;
rebuildPacket();
if (state.stage === 0) {
setPacketOnDesk();
}
renderPanel();
});
});
summary.textContent =
`${protectionOptions[state.protection].label} · ` +
`${protectionOptions[state.protection].size} illustrative space unit` +
`${protectionOptions[state.protection].size === 1 ? "" : "s"}`;
primary.textContent = "Place protected packet in carrier";
primary.disabled = false;
primary.onclick = () => showStage(1);
}
if (state.stage === 1) {
const carriers = Object.entries(carrierOptions)
.map(
([id, option]) => `
<button
class="choice ${state.carrier === id ? "selected" : ""}"
data-carrier="${id}"
aria-pressed="${state.carrier === id}"
>
<span class="choice-title">${option.label}</span>
<span class="choice-copy">${option.copy}</span>
<span class="unit-badge">${option.capacity} units</span>
</button>
`
)
.join("");
const cargo = Object.entries(cargoOptions)
.map(
([id, option]) => `
<button
class="choice ${state.cargo.has(id) ? "selected" : ""}"
data-cargo="${id}"
aria-pressed="${state.cargo.has(id)}"
>
<span class="choice-title">${option.label}</span>
<span class="choice-copy">Shared trade cargo</span>
<span class="unit-badge">${option.size} units</span>
</button>
`
)
.join("");
const used = usedSpace();
const capacity = carrierOptions[state.carrier].capacity;
const percentage = Math.min(100, (used / capacity) * 100);
const over = used > capacity;
content.innerHTML = `
<div class="eyebrow">Stage 2 of 3 · Carrying space</div>
<h2>Fit the packet into a shared load</h2>
<p class="stage-copy">
Books could accompany other goods. Choose a carrier and decide
which illustrative trade cargo shares the available space.
</p>
<div class="section-label">Carrying space</div>
<div class="choice-grid compact">${carriers}</div>
<div class="section-label">Add or remove shared cargo</div>
<div class="choice-grid compact cargo-grid">${cargo}</div>
<div class="section-label">Load manifest</div>
<div class="meter ${over ? "over" : ""}">
<span style="width:${percentage}%"></span>
</div>
<div class="meter-label">
<span>${used} units occupied</span>
<span>${capacity} units available</span>
</div>
<div class="manifest">
<div class="manifest-row">
<span>Protected manuscript packet</span>
<strong>${
protectionOptions[state.protection].size
} unit${protectionOptions[state.protection].size === 1 ? "" : "s"}</strong>
</div>
${[...state.cargo]
.map(
(id) => `
<div class="manifest-row">
<span>${cargoOptions[id].label}</span>
<strong>${cargoOptions[id].size} units</strong>
</div>
`
)
.join("")}
</div>
<div class="note">
These abstract space units are an instructional comparison, not
historical weights or measurements. The camel represents a shared
mixed-cargo trade setting rather than a documented traveler.
</div>
`;
content.querySelectorAll("[data-carrier]").forEach((button) => {
button.addEventListener("click", () => {
state.carrier = button.dataset.carrier;
state.packed = false;
buildLoad();
setPacketOnCamel();
renderPanel();
});
});
content.querySelectorAll("[data-cargo]").forEach((button) => {
button.addEventListener("click", () => {
const id = button.dataset.cargo;
if (state.cargo.has(id)) {
state.cargo.delete(id);
} else {
state.cargo.add(id);
}
state.packed = false;
buildLoad();
setPacketOnCamel();
renderPanel();
});
});
summary.textContent = over
? `The load exceeds this carrier by ${used - capacity} space units.`
: `${capacity - used} space units remain in the ${
carrierOptions[state.carrier].label.toLowerCase()
}.`;
summary.classList.toggle("warning", over);
primary.textContent = "Seal pack and begin route";
primary.disabled = over;
primary.onclick = () => {
if (usedSpace() > carrierOptions[state.carrier].capacity) return;
state.packed = true;
showStage(2);
};
}
if (state.stage === 2) {
const methods = Object.entries(handoverOptions)
.map(
([id, option]) => `
<button
class="choice ${state.handover === id ? "selected" : ""}"
data-handover="${id}"
aria-pressed="${state.handover === id}"
>
<span class="choice-title">${option.label}</span>
<span class="choice-copy">${option.copy}</span>
</button>
`
)
.join("");
const statusText = state.handed
? "The packet and its record are now at the receiving table."
: state.handing
? "The packet is being placed with the receiving scribe."
: state.arrived
? "The caravan has reached the generic waypoint."
: "The caravan is following a schematic trade landscape.";
content.innerHTML = `
<div class="eyebrow">Stage 3 of 3 · Handover</div>
<h2>Complete a generic handover</h2>
<p class="stage-copy">
The protected packet crosses a schematic route and reaches an
unnamed receiving point. Choose how the receiving scribe should
handle it.
</p>
<div class="route-status">
<div class="route-status-icon">${
state.handed ? "✓" : state.arrived ? "◆" : "→"
}</div>
<div>
<strong>${statusText}</strong>
<span>${
state.handed
? "Composite arrival recorded"
: state.arrived
? "Ready for inspection or transfer"
: "Illustrative route · not a historical itinerary"
}</span>
</div>
</div>
<div class="section-label">Handover method</div>
<div class="choice-grid">${methods}</div>
<div class="note">
No named individual, institution, manuscript, or exact historical
route is identified. The scene demonstrates relationships among
scholarly preservation, shared carrying capacity, and handover.
</div>
`;
content.querySelectorAll("[data-handover]").forEach((button) => {
button.addEventListener("click", () => {
state.handover = button.dataset.handover;
renderPanel();
});
});
summary.textContent = state.handed
? `Recorded method: ${handoverOptions[state.handover].label}.`
: "A generic receiving point is used for every scenario.";
primary.textContent = state.handed
? "Handover recorded"
: state.handing
? "Placing packet at receiving table…"
: state.arrived
? "Complete handover"
: "Traveling on schematic route…";
primary.disabled =
!state.arrived || state.handed || state.handing;
primary.onclick = () => {
if (!state.arrived || state.handed || state.handing) return;
beginHandover();
};
}
restart.hidden = !state.handed;
}
function beginHandover() {
state.handing = true;
state.handed = false;
receipt.visible = false;
scene.attach(packet);
handoverAnimation = {
progress: 0,
startPosition: packet.position.clone(),
endPosition: new THREE.Vector3(10.64, 1.16, 2.08),
startQuaternion: packet.quaternion.clone()
};
cameraState.desiredTarget.set(10.6, 1.35, 2.0);
cameraState.desiredRadius = 8.5;
renderPanel();
}
document.querySelectorAll(".stage-button").forEach((button) => {
button.addEventListener("click", () => {
showStage(Number(button.dataset.stage));
});
});
restart.addEventListener("click", () => {
state.stage = 0;
state.protection = "textile";
state.carrier = "basket";
state.cargo = new Set(["textile"]);
state.handover = "sealed";
state.packed = false;
state.travelling = false;
state.arrived = false;
state.handing = false;
state.handed = false;
state.routeProgress = 0;
receipt.visible = false;
rebuildPacket();
buildLoad();
showStage(0);
});
$("#reset-camera").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
let handoverAnimation = null;
let lastTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (state.travelling) {
const raw = THREE.MathUtils.clamp(
(now - state.travelStart) / 6500,
0,
1
);
const eased = raw * raw * (3 - 2 * raw);
state.routeProgress = eased;
const point = routeCurve.getPointAt(eased);
const tangent = routeCurve.getTangentAt(eased).normalize();
camel.position.copy(point);
camel.rotation.y = -Math.atan2(tangent.z, tangent.x);
cameraState.desiredTarget.copy(point);
cameraState.desiredTarget.y += 1.45;
if (raw >= 1) {
state.travelling = false;
state.arrived = true;
cameraState.desiredTarget.set(10.6, 1.35, 2.0);
cameraState.desiredRadius = 8.5;
renderPanel();
}
}
if (handoverAnimation) {
handoverAnimation.progress = Math.min(
1,
handoverAnimation.progress + delta * 0.75
);
const t = handoverAnimation.progress;
const eased = t * t * (3 - 2 * t);
packet.position.lerpVectors(
handoverAnimation.startPosition,
handoverAnimation.endPosition,
eased
);
packet.position.y += Math.sin(t * Math.PI) * 0.48;
packet.quaternion.slerpQuaternions(
handoverAnimation.startQuaternion,
new THREE.Quaternion(),
eased
);
if (t >= 1) {
packet.position.copy(handoverAnimation.endPosition);
packet.quaternion.identity();
receipt.visible = true;
state.handing = false;
state.handed = true;
handoverAnimation = null;
renderPanel();
}
}
// A subtle pulse on the generic route marker.
if (state.stage === 2) {
const routeMarker = worldLabels[2];
routeMarker.position.y = 1.25 + Math.sin(now * 0.002) * 0.08;
}
updateCamera();
updateWorldLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
renderPanel();
updateCamera();
updateWorldLabels();
$("#loading").remove();
requestAnimationFrame(animate);
</script>
</body>
</html>
```