Prompt specification
Build or customize the Three.js 3D scene "Observatory courtyard with linked measurements" 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: Observatory courtyard with linked measurements
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/observatory-courtyard-with-linked-measurements-x2335
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Build a compact early modern observatory scene with angle instrument, sighting target, and recording desk. Show how one observation passes through alignment, reading, and written record.
Working Three.js Starter (observatory-courtyard-with-linked-measurements-x2335):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Angle Ledger — An Early Modern Observatory</title>
<style>
:root {
--ink: #332b25;
--muted: #766b5e;
--paper: #efe3c8;
--paper-deep: #ddcba7;
--brass: #b8873e;
--brass-light: #d6b16d;
--line: rgba(72, 58, 42, 0.25);
--shadow: 0 14px 45px rgba(47, 35, 23, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cdbda0;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
header {
position: absolute;
top: 26px;
left: 30px;
max-width: 430px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}
.eyebrow,
.panel-label,
.step-number,
#status-line {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow {
color: #735b39;
margin-bottom: 8px;
}
h1 {
margin: 0;
font-size: clamp(34px, 4.5vw, 62px);
line-height: 0.95;
font-weight: 500;
letter-spacing: -0.045em;
}
header p {
max-width: 360px;
margin: 13px 0 0;
color: #5d5144;
font-size: 14px;
line-height: 1.55;
}
.observation-panel {
position: absolute;
top: 25px;
right: 28px;
width: 278px;
padding: 19px 20px 18px;
border: 1px solid rgba(87, 66, 40, 0.3);
background:
linear-gradient(rgba(255,255,255,0.18), rgba(255,255,255,0)),
rgba(239, 227, 200, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(8px);
}
.observation-panel::before {
content: "";
position: absolute;
inset: 6px;
border: 1px solid rgba(91, 69, 43, 0.16);
pointer-events: none;
}
.panel-label {
color: var(--brass);
}
#phase-title {
min-height: 54px;
margin: 9px 0 7px;
font-size: 25px;
line-height: 1.02;
font-weight: 500;
}
#phase-copy {
min-height: 48px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.readout {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 14px;
margin-top: 17px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
#readout-value {
font-size: 34px;
line-height: 1;
color: #765229;
font-variant-numeric: tabular-nums;
}
#readout-label {
max-width: 86px;
color: var(--muted);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
line-height: 1.35;
letter-spacing: 0.13em;
text-align: right;
text-transform: uppercase;
}
#status-line {
margin-top: 13px;
color: #7f6a4b;
letter-spacing: 0.11em;
}
#camera-hint {
position: absolute;
left: 29px;
bottom: 154px;
color: rgba(53, 43, 37, 0.65);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.timeline {
position: absolute;
left: 50%;
bottom: 22px;
width: min(880px, calc(100% - 44px));
transform: translateX(-50%);
padding: 12px 14px 13px;
border: 1px solid rgba(87, 66, 40, 0.28);
background: rgba(239, 227, 200, 0.93);
box-shadow: var(--shadow);
backdrop-filter: blur(9px);
pointer-events: auto;
}
.transport {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
}
button {
border: 1px solid rgba(74, 55, 35, 0.32);
color: var(--ink);
background: rgba(255, 255, 255, 0.28);
font: inherit;
cursor: pointer;
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.7);
}
button:active {
transform: translateY(1px);
}
#play {
min-width: 78px;
padding: 7px 12px;
color: #f6ead0;
background: #5d4934;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#replay {
width: 34px;
height: 31px;
font-size: 17px;
}
#scrubber {
--progress: 0%;
flex: 1;
height: 4px;
margin: 0 4px;
border-radius: 0;
outline: none;
appearance: none;
background:
linear-gradient(
to right,
#9b733d 0%,
#9b733d var(--progress),
rgba(78, 59, 39, 0.2) var(--progress),
rgba(78, 59, 39, 0.2) 100%
);
cursor: pointer;
}
#scrubber::-webkit-slider-thumb {
width: 13px;
height: 13px;
border: 2px solid #efe3c8;
border-radius: 50%;
appearance: none;
background: #846032;
box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
#scrubber::-moz-range-thumb {
width: 11px;
height: 11px;
border: 2px solid #efe3c8;
border-radius: 50%;
background: #846032;
box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.steps {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.step {
position: relative;
display: grid;
grid-template-columns: 31px 1fr;
align-items: center;
min-height: 48px;
padding: 7px 10px;
overflow: hidden;
text-align: left;
background: rgba(255, 255, 255, 0.13);
}
.step::after {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: var(--step-progress, 0%);
height: 2px;
background: var(--brass);
}
.step.active {
background: rgba(184, 135, 62, 0.15);
}
.step-number {
color: #9a7542;
font-size: 9px;
}
.step-title {
display: block;
font-size: 13px;
}
.step-caption {
display: block;
margin-top: 2px;
color: var(--muted);
font-family: Arial, Helvetica, sans-serif;
font-size: 8px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.world-label {
position: absolute;
left: 0;
top: 0;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 8px;
border: 1px solid rgba(72, 53, 33, 0.25);
color: #493a2d;
background: rgba(239, 227, 200, 0.84);
box-shadow: 0 5px 18px rgba(40, 30, 22, 0.14);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
}
.world-label::after {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--brass);
box-shadow: 0 0 0 3px rgba(184, 135, 62, 0.17);
}
@media (max-width: 760px) {
header {
top: 18px;
left: 18px;
max-width: 58%;
}
header p {
display: none;
}
h1 {
font-size: 34px;
}
.observation-panel {
top: 16px;
right: 16px;
width: 220px;
padding: 14px;
}
#phase-title {
font-size: 20px;
min-height: 40px;
}
#phase-copy {
display: none;
}
.readout {
margin-top: 10px;
padding-top: 9px;
}
#readout-value {
font-size: 28px;
}
#status-line {
font-size: 8px;
}
.timeline {
bottom: 12px;
width: calc(100% - 24px);
}
.step {
grid-template-columns: 1fr;
padding: 7px 9px;
}
.step-number,
.step-caption {
display: none;
}
.step-title {
font-size: 11px;
}
#camera-hint {
display: none;
}
}
@media (max-width: 480px) {
.observation-panel {
top: auto;
bottom: 128px;
width: 190px;
}
#status-line,
#readout-label {
display: none;
}
header {
max-width: 90%;
}
h1 {
font-size: 31px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly early modern observatory"></canvas>
<div class="overlay">
<header>
<div class="eyebrow">Observatory / 1624</div>
<h1>The Angle Ledger</h1>
<p>One sighting, carried from the instrument’s sightline to the observer’s written record.</p>
</header>
<aside class="observation-panel">
<div class="panel-label">Observation 01 · East Beacon</div>
<div id="phase-title">Bring the sightline into agreement</div>
<p id="phase-copy">The observer turns the alidade until the beacon sits exactly within the sighting vanes.</p>
<div class="readout">
<div id="readout-value">—</div>
<div id="readout-label">Bearing not yet fixed</div>
</div>
<div id="status-line">Alignment in progress</div>
</aside>
<div id="camera-hint">Drag to orbit · scroll or pinch to zoom</div>
<div id="label-instrument" class="world-label">Angle instrument</div>
<div id="label-target" class="world-label">Sighting target</div>
<div id="label-desk" class="world-label">Recording desk</div>
<section class="timeline" aria-label="Observation sequence">
<div class="transport">
<button id="play" type="button">Pause</button>
<button id="replay" type="button" aria-label="Replay observation">↺</button>
<input id="scrubber" type="range" min="0" max="1000" value="0" aria-label="Observation timeline">
</div>
<div class="steps">
<button class="step active" type="button" data-phase="0">
<span class="step-number">01</span>
<span>
<span class="step-title">Alignment</span>
<span class="step-caption">Fix the sightline</span>
</span>
</button>
<button class="step" type="button" data-phase="1">
<span class="step-number">02</span>
<span>
<span class="step-title">Reading</span>
<span class="step-caption">Read the divided arc</span>
</span>
</button>
<button class="step" type="button" data-phase="2">
<span class="step-number">03</span>
<span>
<span class="step-title">Written record</span>
<span class="step-caption">Preserve the observation</span>
</span>
</button>
</div>
</section>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera and shared helpers
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbbda2);
scene.fog = new THREE.Fog(0xcbbda2, 22, 43);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const clock = new THREE.Clock();
const Y_AXIS = new THREE.Vector3(0, 1, 0);
const X_AXIS = new THREE.Vector3(1, 0, 0);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
ground: material(0x9f9279),
platform: material(0x9a8a70),
platformTop: material(0xb2a286),
paver: material(0xc0af91),
stone: material(0xb7a68a),
stoneDark: material(0x8f806b),
stoneLight: material(0xd0bea0),
wood: material(0x60412c),
woodLight: material(0x896144),
woodDark: material(0x38281e),
brass: material(0xb7833d, {
metalness: 0.62,
roughness: 0.31
}),
brassLight: material(0xd8b66f, {
metalness: 0.55,
roughness: 0.28
}),
copper: material(0x52766a, {
metalness: 0.28,
roughness: 0.54
}),
ivory: material(0xe5d6b6),
paper: material(0xe8d8b6),
ink: material(0x302923),
red: material(0x9a3f32),
blue: material(0x435868),
charcoal: material(0x33302d),
flame: material(0xffb33d, {
emissive: 0xff7b13,
emissiveIntensity: 2.6
})
};
function addMesh(parent, geometry, mat, position = [0, 0, 0], rotation = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, size, position, mat, rotation = [0, 0, 0]) {
return addMesh(
parent,
new THREE.BoxGeometry(...size),
mat,
position,
rotation
);
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
mat,
segments = 8,
rotation = [0, 0, 0]
) {
return addMesh(
parent,
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat,
position,
rotation
);
}
function addSphere(parent, radius, position, mat, width = 10, height = 7) {
return addMesh(
parent,
new THREE.SphereGeometry(radius, width, height),
mat,
position
);
}
function cylinderBetween(parent, a, b, radius, mat, sides = 6) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = addCylinder(
parent,
radius,
radius,
length,
start.clone().add(end).multiplyScalar(0.5).toArray(),
mat,
sides
);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
return mesh;
}
function clamp01(value) {
return Math.max(0, Math.min(1, value));
}
function smooth01(value) {
const x = clamp01(value);
return x * x * (3 - 2 * x);
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemi = new THREE.HemisphereLight(0xf6e6c4, 0x5b5145, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe6b8, 3.2);
sun.position.set(-8, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9eb5c7, 0.65);
fill.position.set(9, 6, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Observatory terrace and pavilion
// -------------------------------------------------------------------------
addMesh(
scene,
new THREE.PlaneGeometry(100, 100),
M.ground,
[0, -0.31, 0],
[-Math.PI / 2, 0, 0]
);
addCylinder(scene, 7.45, 7.65, 0.48, [0, 0, 0], M.platform, 16);
addCylinder(scene, 7.18, 7.28, 0.10, [0, 0.27, 0], M.platformTop, 16);
addMesh(
scene,
new THREE.TorusGeometry(7.12, 0.075, 6, 64),
M.stoneDark,
[0, 0.33, 0],
[Math.PI / 2, 0, 0]
);
for (let i = 0; i < 18; i++) {
const angle = (i / 18) * Math.PI * 2;
const radius = 6.12;
addBox(
scene,
[1.72, 0.055, 0.58],
[Math.sin(angle) * radius, 0.34, Math.cos(angle) * radius],
i % 2 ? M.paver : M.stoneLight,
[0, angle, 0]
);
}
// Small inlaid compass rose in the terrace.
const rose = new THREE.Group();
rose.position.set(0.15, 0.35, 0.05);
scene.add(rose);
addMesh(
rose,
new THREE.TorusGeometry(1.22, 0.025, 5, 48),
M.brass,
[0, 0, 0],
[Math.PI / 2, 0, 0]
);
for (let i = 0; i < 16; i++) {
const a = (i / 16) * Math.PI * 2;
const length = i % 4 === 0 ? 0.25 : 0.13;
addBox(
rose,
[length, 0.018, 0.035],
[Math.sin(a) * 1.03, 0.01, Math.cos(a) * 1.03],
M.brass,
[0, a, 0]
);
}
// Low columns and connecting rails around the rear of the terrace.
const columnAngles = [2.55, 3.08, 3.61, 4.45, 4.98, 5.51, 6.04];
const columnTops = [];
for (const angle of columnAngles) {
const radius = 6.55;
const x = Math.sin(angle) * radius;
const z = Math.cos(angle) * radius;
addBox(scene, [0.75, 0.16, 0.75], [x, 0.40, z], M.stoneDark, [0, angle, 0]);
addCylinder(scene, 0.24, 0.29, 1.62, [x, 1.23, z], M.stone, 8);
addBox(scene, [0.68, 0.16, 0.68], [x, 2.08, z], M.stoneLight, [0, angle, 0]);
columnTops.push(new THREE.Vector3(x, 2.10, z));
}
for (let i = 0; i < columnTops.length - 1; i++) {
cylinderBetween(
scene,
columnTops[i].toArray(),
columnTops[i + 1].toArray(),
0.105,
M.stoneLight,
6
);
}
// Low-poly domed observatory in the back-left corner.
const pavilion = new THREE.Group();
pavilion.position.set(-4.05, 0.32, -3.65);
scene.add(pavilion);
addCylinder(pavilion, 1.65, 1.78, 2.25, [0, 1.13, 0], M.stone, 10);
addCylinder(pavilion, 1.86, 1.86, 0.18, [0, 2.31, 0], M.stoneLight, 10);
addMesh(
pavilion,
new THREE.SphereGeometry(
1.72,
12,
6,
0,
Math.PI * 2,
0,
Math.PI / 2
),
M.copper,
[0, 2.38, 0]
);
addCylinder(pavilion, 0.06, 0.09, 0.62, [0, 4.08, 0], M.brass, 8);
addSphere(pavilion, 0.13, [0, 4.42, 0], M.brassLight, 8, 6);
// A dark observing slit.
addBox(
pavilion,
[0.18, 1.05, 0.16],
[0.43, 3.10, 1.39],
M.charcoal,
[-0.25, 0, 0]
);
// -------------------------------------------------------------------------
// Sighting target: striped tower and painted bullseye
// -------------------------------------------------------------------------
const targetRoot = new THREE.Group();
targetRoot.position.set(3.5, 0.32, -5.05);
scene.add(targetRoot);
addBox(targetRoot, [1.05, 0.22, 1.05], [0, 0.10, 0], M.stoneDark);
addCylinder(targetRoot, 0.28, 0.38, 2.15, [0, 1.25, 0], M.stone, 8);
addCylinder(targetRoot, 0.39, 0.39, 0.15, [0, 2.34, 0], M.stoneLight, 8);
addCylinder(targetRoot, 0.055, 0.065, 0.75, [0, 2.73, 0], M.woodDark, 7);
for (let i = 0; i < 4; i++) {
addCylinder(
targetRoot,
0.285,
0.305,
0.12,
[0, 0.53 + i * 0.43, 0],
i % 2 ? M.red : M.ivory,
8
);
}
const targetBoard = new THREE.Group();
targetBoard.position.set(0, 2.88, 0);
targetRoot.add(targetBoard);
const targetPosition = new THREE.Vector3(3.5, 3.20, -5.05);
addMesh(
targetBoard,
new THREE.CircleGeometry(0.55, 20),
M.ivory,
[0, 0, 0.025]
);
addMesh(
targetBoard,
new THREE.CircleGeometry(0.41, 20),
M.red,
[0, 0, 0.04]
);
addMesh(
targetBoard,
new THREE.CircleGeometry(0.25, 20),
M.ivory,
[0, 0, 0.055]
);
addMesh(
targetBoard,
new THREE.CircleGeometry(0.11, 16),
M.red,
[0, 0, 0.07]
);
const targetRing = addMesh(
targetBoard,
new THREE.TorusGeometry(0.61, 0.025, 5, 24),
new THREE.MeshBasicMaterial({
color: 0xe6bd63,
transparent: true,
opacity: 0.22
}),
[0, 0, 0.075]
);
// Small wind pennant.
const pennantShape = new THREE.Shape();
pennantShape.moveTo(0, 0);
pennantShape.lineTo(0.67, -0.17);
pennantShape.lineTo(0, -0.36);
pennantShape.closePath();
const pennant = addMesh(
targetRoot,
new THREE.ShapeGeometry(pennantShape),
M.red,
[0.03, 3.14, 0],
[0, 0, 0]
);
pennant.material.side = THREE.DoubleSide;
// -------------------------------------------------------------------------
// Angle instrument: stand, azimuth card, quadrant and sighting alidade
// -------------------------------------------------------------------------
const instrumentRoot = new THREE.Group();
instrumentRoot.position.set(-2.2, 0.32, 0.15);
scene.add(instrumentRoot);
for (let i = 0; i < 3; i++) {
const angle = (i / 3) * Math.PI * 2 + 0.45;
cylinderBetween(
instrumentRoot,
[0, 1.18, 0],
[Math.sin(angle) * 0.78, 0.06, Math.cos(angle) * 0.78],
0.075,
M.wood,
6
);
}
addCylinder(instrumentRoot, 0.16, 0.22, 1.12, [0, 0.66, 0], M.woodDark, 8);
addCylinder(instrumentRoot, 0.32, 0.30, 0.13, [0, 1.28, 0], M.brass, 12);
addBox(instrumentRoot, [0.84, 0.12, 0.58], [0, 1.40, 0], M.woodLight);
// Horizontal azimuth card.
addMesh(
instrumentRoot,
new THREE.TorusGeometry(0.66, 0.035, 6, 40),
M.brass,
[0, 1.48, 0],
[Math.PI / 2, 0, 0]
);
for (let i = 0; i < 24; i++) {
const a = (i / 24) * Math.PI * 2;
const length = i % 6 === 0 ? 0.15 : 0.08;
addBox(
instrumentRoot,
[length, 0.018, 0.026],
[Math.sin(a) * 0.57, 1.50, Math.cos(a) * 0.57],
M.ink,
[0, a, 0]
);
}
const arcGroup = new THREE.Group();
arcGroup.position.y = 2.25;
instrumentRoot.add(arcGroup);
// A quarter-circle graduated limb.
const limb = addMesh(
arcGroup,
new THREE.TorusGeometry(1.08, 0.075, 7, 42, Math.PI / 2),
M.brass,
[0, 0, -0.035]
);
const limbGlowMaterial = new THREE.MeshStandardMaterial({
color: 0xd5a452,
emissive: 0x8a4813,
emissiveIntensity: 0.08,
metalness: 0.45,
roughness: 0.35,
flatShading: true
});
const limbGlow = addMesh(
arcGroup,
new THREE.TorusGeometry(1.085, 0.024, 5, 42, Math.PI / 2),
limbGlowMaterial,
[0, 0, 0.055]
);
cylinderBetween(arcGroup, [0, 0, 0], [1.08, 0, -0.02], 0.035, M.brass, 6);
cylinderBetween(arcGroup, [0, 0, 0], [0, 1.08, -0.02], 0.035, M.brass, 6);
for (let i = 0; i <= 18; i++) {
const a = (i / 18) * (Math.PI / 2);
const major = i % 3 === 0;
addBox(
arcGroup,
[major ? 0.16 : 0.095, 0.026, 0.035],
[Math.cos(a) * 1.02, Math.sin(a) * 1.02, 0.065],
M.ink,
[0, 0, a]
);
}
addCylinder(
arcGroup,
0.19,
0.19,
0.13,
[0, 0, 0],
M.brassLight,
12,
[Math.PI / 2, 0, 0]
);
// Alidade and sighting tube.
const sightRig = new THREE.Group();
arcGroup.add(sightRig);
addBox(sightRig, [2.08, 0.055, 0.065], [0.44, 0, 0.035], M.brassLight);
const sightTube = addCylinder(
sightRig,
0.105,
0.12,
1.12,
[0.56, 0, 0.13],
M.brass,
10,
[0, 0, Math.PI / 2]
);
addCylinder(
sightRig,
0.145,
0.145,
0.08,
[1.12, 0, 0.13],
M.brassLight,
10,
[0, 0, Math.PI / 2]
);
addCylinder(
sightRig,
0.075,
0.09,
0.22,
[-0.08, 0, 0.13],
M.brass,
10,
[0, 0, Math.PI / 2]
);
const lens = addCylinder(
sightRig,
0.095,
0.095,
0.025,
[1.17, 0, 0.13],
M.blue,
12,
[0, 0, Math.PI / 2]
);
// Vertical sighting vanes.
for (const x of [-0.03, 1.03]) {
addBox(sightRig, [0.035, 0.36, 0.18], [x, 0.16, 0.13], M.brassLight);
}
// A small compass pointer attached to the azimuth rotation.
const azimuthPointer = new THREE.Group();
azimuthPointer.position.y = 1.52;
instrumentRoot.add(azimuthPointer);
addBox(azimuthPointer, [1.18, 0.025, 0.045], [0.52, 0, 0], M.red);
// -------------------------------------------------------------------------
// Recording desk and animated ledger
// -------------------------------------------------------------------------
const deskRoot = new THREE.Group();
deskRoot.position.set(2.9, 0.32, 2.7);
scene.add(deskRoot);
addBox(deskRoot, [3.35, 0.18, 1.82], [0, 1.27, 0], M.woodLight);
addBox(deskRoot, [3.48, 0.08, 1.93], [0, 1.16, 0], M.woodDark);
for (const x of [-1.37, 1.37]) {
for (const z of [-0.65, 0.65]) {
addBox(deskRoot, [0.18, 1.12, 0.18], [x, 0.56, z], M.wood);
}
}
addBox(deskRoot, [2.85, 0.09, 0.12], [0, 0.55, 0.58], M.wood);
// Loose papers.
for (let i = 0; i < 3; i++) {
addBox(
deskRoot,
[0.82, 0.012, 0.98],
[-1.05 + i * 0.04, 1.38 + i * 0.012, 0.34 + i * 0.03],
M.paper,
[0, -0.08 + i * 0.04, 0]
);
}
// Open ledger.
const bookRoot = new THREE.Group();
bookRoot.position.set(-0.30, 1.38, -0.02);
deskRoot.add(bookRoot);
addBox(bookRoot, [2.62, 0.055, 1.58], [0, 0, 0], M.woodDark);
addBox(bookRoot, [0.055, 0.08, 1.51], [0, 0.035, 0], M.brass);
const ledgerCanvas = document.createElement("canvas");
ledgerCanvas.width = 768;
ledgerCanvas.height = 512;
const ledgerContext = ledgerCanvas.getContext("2d");
const ledgerTexture = new THREE.CanvasTexture(ledgerCanvas);
ledgerTexture.colorSpace = THREE.SRGBColorSpace;
ledgerTexture.anisotropy = Math.min(renderer.capabilities.getMaxAnisotropy(), 8);
const rightPage = addMesh(
bookRoot,
new THREE.PlaneGeometry(1.27, 1.48),
new THREE.MeshStandardMaterial({
map: ledgerTexture,
roughness: 0.95,
side: THREE.DoubleSide
}),
[0.65, 0.046, 0],
[-Math.PI / 2, 0, 0]
);
// Printed left page with a hand-ruled grid.
const gridCanvas = document.createElement("canvas");
gridCanvas.width = 384;
gridCanvas.height = 512;
const gridContext = gridCanvas.getContext("2d");
gridContext.fillStyle = "#e6d5b2";
gridContext.fillRect(0, 0, 384, 512);
gridContext.strokeStyle = "rgba(64, 49, 34, .25)";
gridContext.lineWidth = 2;
for (let y = 70; y < 500; y += 42) {
gridContext.beginPath();
gridContext.moveTo(22, y);
gridContext.lineTo(362, y);
gridContext.stroke();
}
for (let x = 55; x < 370; x += 55) {
gridContext.beginPath();
gridContext.moveTo(x, 45);
gridContext.lineTo(x, 495);
gridContext.stroke();
}
gridContext.fillStyle = "rgba(50, 41, 33, .72)";
gridContext.font = "20px Georgia";
gridContext.fillText("ALTITUDE TABLE", 34, 30);
const gridTexture = new THREE.CanvasTexture(gridCanvas);
gridTexture.colorSpace = THREE.SRGBColorSpace;
addMesh(
bookRoot,
new THREE.PlaneGeometry(1.27, 1.48),
new THREE.MeshStandardMaterial({
map: gridTexture,
roughness: 0.95,
side: THREE.DoubleSide
}),
[-0.65, 0.046, 0],
[-Math.PI / 2, 0, 0]
);
// Inkwell.
addCylinder(deskRoot, 0.14, 0.19, 0.22, [1.30, 1.47, -0.50], M.charcoal, 10);
addCylinder(deskRoot, 0.085, 0.085, 0.015, [1.30, 1.59, -0.50], M.ink, 10);
// Candle and flame.
const candle = new THREE.Group();
candle.position.set(-1.27, 1.37, -0.54);
deskRoot.add(candle);
addCylinder(candle, 0.13, 0.15, 0.11, [0, 0.055, 0], M.brass, 10);
addCylinder(candle, 0.07, 0.08, 0.43, [0, 0.31, 0], M.ivory, 8);
addCylinder(candle, 0.012, 0.012, 0.09, [0, 0.56, 0], M.charcoal, 5);
const flame = addMesh(
candle,
new THREE.ConeGeometry(0.07, 0.22, 7),
M.flame,
[0, 0.69, 0]
);
const candleLight = new THREE.PointLight(0xffa23a, 1.7, 4.2, 2);
candleLight.position.set(0, 0.74, 0);
candle.add(candleLight);
// Quill, built around a nib at local origin.
const quill = new THREE.Group();
quill.position.set(0.04, 1.49, 0.27);
deskRoot.add(quill);
cylinderBetween(quill, [0, 0, 0], [0.02, 0.58, -0.24], 0.012, M.woodDark, 5);
cylinderBetween(quill, [0, 0, 0], [-0.015, -0.09, 0.015], 0.008, M.ink, 5);
const featherShape = new THREE.Shape();
featherShape.moveTo(0, 0);
featherShape.bezierCurveTo(0.16, 0.22, 0.16, 0.54, 0.02, 0.78);
featherShape.bezierCurveTo(-0.15, 0.52, -0.15, 0.21, 0, 0);
const featherMaterial = M.ivory.clone();
featherMaterial.side = THREE.DoubleSide;
addMesh(
quill,
new THREE.ShapeGeometry(featherShape),
featherMaterial,
[0.02, 0.42, -0.17],
[0.17, 0.08, -0.10]
);
// -------------------------------------------------------------------------
// Observer
// -------------------------------------------------------------------------
function createObserver() {
const root = new THREE.Group();
const upper = new THREE.Group();
upper.position.y = 0.72;
root.add(upper);
const legs = [];
for (const side of [-1, 1]) {
const leg = new THREE.Group();
leg.position.set(side * 0.14, 0.70, 0);
root.add(leg);
addBox(leg, [0.18, 0.62, 0.19], [0, -0.31, 0], M.charcoal);
addBox(leg, [0.22, 0.12, 0.34], [0, -0.60, 0.07], M.woodDark);
legs.push(leg);
}
addCylinder(upper, 0.27, 0.39, 0.78, [0, 0.38, 0], M.blue, 7);
addCylinder(upper, 0.30, 0.27, 0.10, [0, 0.72, 0], M.woodDark, 8);
addSphere(upper, 0.22, [0, 0.98, 0], M.ivory, 10, 7);
addCylinder(upper, 0.31, 0.31, 0.055, [0, 1.15, 0], M.woodDark, 10);
addCylinder(upper, 0.20, 0.23, 0.20, [0, 1.25, 0], M.woodDark, 8);
const arms = [];
for (const side of [-1, 1]) {
const arm = new THREE.Group();
arm.position.set(side * 0.31, 0.65, 0);
upper.add(arm);
cylinderBetween(arm, [0, 0, 0], [side * 0.05, -0.36, 0.03], 0.09, M.blue, 6);
cylinderBetween(arm, [side * 0.05, -0.36, 0.03], [side * 0.08, -0.57, 0.12], 0.075, M.blue, 6);
addSphere(arm, 0.085, [side * 0.08, -0.57, 0.12], M.ivory, 8, 6);
arms.push(arm);
}
return {
root,
upper,
legs,
arms,
rightHand: arms[1].children[arms[1].children.length - 1]
};
}
const observer = createObserver();
scene.add(observer.root);
// The amber token represents the single observation as it changes hands.
const observationToken = addMesh(
scene,
new THREE.IcosahedronGeometry(0.115, 1),
new THREE.MeshStandardMaterial({
color: 0xffc15b,
emissive: 0xd66b15,
emissiveIntensity: 1.5,
roughness: 0.3,
metalness: 0.25,
flatShading: true
})
);
// Sightline.
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const sightLineMaterial = new THREE.LineDashedMaterial({
color: 0xf2bd5b,
dashSize: 0.19,
gapSize: 0.11,
transparent: true,
opacity: 0,
depthTest: true
});
const sightLine = new THREE.Line(lineGeometry, sightLineMaterial);
scene.add(sightLine);
// Small airborne dust gives the warm observatory air some depth.
const dustPositions = new Float32Array(150 * 3);
for (let i = 0; i < 150; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 16;
dustPositions[i * 3 + 1] = 0.5 + Math.random() * 8;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 16;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xf4d8a0,
size: 0.035,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
scene.add(dust);
// -------------------------------------------------------------------------
// Ledger drawing
// -------------------------------------------------------------------------
function drawLedger(progress) {
const ctx = ledgerContext;
const width = ledgerCanvas.width;
const height = ledgerCanvas.height;
ctx.fillStyle = "#e9d9b7";
ctx.fillRect(0, 0, width, height);
ctx.strokeStyle = "rgba(72, 54, 37, .20)";
ctx.lineWidth = 2;
ctx.strokeRect(22, 22, width - 44, height - 44);
ctx.fillStyle = "rgba(61, 46, 33, .82)";
ctx.font = "25px Georgia";
ctx.fillText("FIELD LEDGER", 48, 68);
ctx.font = "17px Arial";
ctx.fillStyle = "rgba(61, 46, 33, .58)";
ctx.fillText("OBSERVATION 01 / EAST BEACON", 49, 103);
ctx.beginPath();
ctx.moveTo(48, 124);
ctx.lineTo(width - 48, 124);
ctx.stroke();
const lines = [
{ y: 192, label: "Bearing", value: "47° 30′" },
{ y: 285, label: "Target", value: "East Beacon" },
{ y: 378, label: "Condition", value: "Clear / steady" }
];
lines.forEach((line, index) => {
const reveal = clamp01(progress * 3 - index);
const fullText = `${line.label.padEnd(12, " ")}${line.value}`;
ctx.fillStyle = "rgba(61, 46, 33, .54)";
ctx.font = "22px Georgia";
ctx.fillText(line.label, 49, line.y);
ctx.fillStyle = "#3b3028";
ctx.font = "25px Georgia";
ctx.fillText(
fullText.slice(line.label.length, line.label.length + Math.ceil((fullText.length - line.label.length) * reveal)),
49 + 178,
line.y
);
ctx.strokeStyle = "rgba(78, 61, 42, .16)";
ctx.beginPath();
ctx.moveTo(48, line.y + 24);
ctx.lineTo(width - 48, line.y + 24);
ctx.stroke();
});
if (progress > 0.91) {
ctx.strokeStyle = "rgba(61, 46, 33, .72)";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(563, 444);
ctx.lineTo(586, 467);
ctx.lineTo(634, 407);
ctx.stroke();
}
ledgerTexture.needsUpdate = true;
}
drawLedger(0);
// -------------------------------------------------------------------------
// Timeline and camera state
// -------------------------------------------------------------------------
const PHASE_0_END = 4.8;
const PHASE_1_END = 8.8;
const TOTAL_TIME = 16.0;
const state = {
elapsed: 0,
playing: true,
lastManualInput: -10000
};
const orbit = {
theta: 0.68,
phi: 0.50,
radius: 15.5,
target: new THREE.Vector3(-0.4, 1.35, 0.1)
};
const autoCamera = {
theta: 0.68,
phi: 0.50,
radius: 15.5,
target: new THREE.Vector3(-0.4, 1.35, 0.1)
};
const playButton = document.querySelector("#play");
const replayButton = document.querySelector("#replay");
const scrubber = document.querySelector("#scrubber");
const stepButtons = [...document.querySelectorAll(".step")];
const phaseTitle = document.querySelector("#phase-title");
const phaseCopy = document.querySelector("#phase-copy");
const readoutValue = document.querySelector("#readout-value");
const readoutLabel = document.querySelector("#readout-label");
const statusLine = document.querySelector("#status-line");
function setPlaying(playing) {
state.playing = playing;
playButton.textContent = playing ? "Pause" : "Play";
}
playButton.addEventListener("click", () => {
if (state.elapsed >= TOTAL_TIME) {
state.elapsed = 0;
setPlaying(true);
} else {
setPlaying(!state.playing);
}
});
replayButton.addEventListener("click", () => {
state.elapsed = 0;
setPlaying(true);
});
scrubber.addEventListener("input", () => {
state.elapsed = Number(scrubber.value) / 1000 * TOTAL_TIME;
setPlaying(false);
});
stepButtons.forEach((button) => {
button.addEventListener("click", () => {
const phase = Number(button.dataset.phase);
state.elapsed = phase === 0 ? 0 : phase === 1 ? PHASE_0_END : PHASE_1_END;
setPlaying(true);
});
});
// Custom camera controls; no external controls module is used.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
state.lastManualInput = performance.now();
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= dx * 0.0055;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.004, 0.22, 1.02);
state.lastManualInput = performance.now();
});
function stopDragging(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
8,
24
);
state.lastManualInput = performance.now();
}, { passive: false });
// -------------------------------------------------------------------------
// Scene animation
// -------------------------------------------------------------------------
const instrumentPivot = new THREE.Vector3(
instrumentRoot.position.x,
instrumentRoot.position.y + 2.25,
instrumentRoot.position.z
);
const targetDelta = targetPosition.clone().sub(instrumentPivot);
const horizontalDistance = Math.hypot(targetDelta.x, targetDelta.z);
const targetAzimuth = Math.atan2(-targetDelta.z, targetDelta.x);
const targetElevation = Math.atan2(targetDelta.y, horizontalDistance);
const observerStart = new THREE.Vector3(-0.72, 0.32, 1.12);
const observerEnd = new THREE.Vector3(1.58, 0.32, 3.43);
const lineStart = new THREE.Vector3();
const lineEnd = new THREE.Vector3();
const currentDirection = new THREE.Vector3();
const handPosition = new THREE.Vector3();
const ledgerPosition = new THREE.Vector3();
let lastPhase = -1;
let lastLedgerProgress = -1;
function updateObserver(recordProgress) {
const walkingProgress = smooth01(recordProgress / 0.34);
observer.root.position.lerpVectors(
observerStart,
observerEnd,
walkingProgress
);
const walkSwing = Math.sin(walkingProgress * Math.PI * 10);
const walking = recordProgress > 0.001 && recordProgress < 0.36;
observer.legs[0].rotation.x = walking ? walkSwing * 0.42 : 0;
observer.legs[1].rotation.x = walking ? -walkSwing * 0.42 : 0;
observer.upper.position.y = 0.72 + (walking ? Math.abs(walkSwing) * 0.025 : 0);
observer.upper.rotation.x = recordProgress > 0.34 ? 0.10 : 0;
if (recordProgress <= 0.001) {
observer.root.rotation.y = -2.05;
} else if (walkingProgress < 0.98) {
observer.root.rotation.y = 0.70;
} else {
observer.root.rotation.y = lerp(
0.70,
1.92,
smooth01((walkingProgress - 0.80) / 0.20)
);
}
observer.arms[0].rotation.x = walking ? -walkSwing * 0.30 : -0.16;
observer.arms[1].rotation.x = walking ? walkSwing * 0.30 : -0.12;
observer.arms[1].rotation.z = recordProgress > 0.34 ? -1.48 : -0.12;
observer.root.updateMatrixWorld(true);
}
function updateLedgerAndQuill(recordProgress) {
const writingProgress = clamp01((recordProgress - 0.38) / 0.46);
if (Math.abs(writingProgress - lastLedgerProgress) > 0.001) {
drawLedger(writingProgress);
lastLedgerProgress = writingProgress;
}
const lineProgress = writingProgress * 3;
let line = Math.min(2, Math.floor(lineProgress));
let withinLine = lineProgress - line;
if (writingProgress <= 0) {
line = 0;
withinLine = 0;
}
if (writingProgress >= 1) {
line = 2;
withinLine = 1;
}
const zPositions = [0.27, -0.14, -0.55];
quill.position.x = 0.04 + withinLine * 1.13;
quill.position.z = zPositions[line];
quill.position.y = 1.50 + Math.sin(writingProgress * Math.PI) * 0.012;
quill.rotation.y = lerp(-0.08, 0.07, withinLine);
}
function updateCamera(phase, recordProgress, now) {
if (phase === 0) {
autoCamera.theta = 0.68;
autoCamera.phi = 0.50;
autoCamera.radius = 15.5;
autoCamera.target.set(-0.4, 1.35, 0.1);
} else if (phase === 1) {
autoCamera.theta = 0.77;
autoCamera.phi = 0.47;
autoCamera.radius = 12.1;
autoCamera.target.set(-1.25, 1.85, 0.05);
} else {
autoCamera.theta = 0.70;
autoCamera.phi = 0.50;
autoCamera.radius = 13.2;
autoCamera.target.set(1.15, 1.20, 1.25);
}
if (now - state.lastManualInput > 2400) {
const damping = 0.022;
orbit.theta = lerp(orbit.theta, autoCamera.theta, damping);
orbit.phi = lerp(orbit.phi, autoCamera.phi, damping);
orbit.radius = lerp(orbit.radius, autoCamera.radius, damping);
orbit.target.lerp(autoCamera.target, damping);
}
const horizontal = Math.cos(orbit.phi) * orbit.radius;
camera.position.set(
orbit.target.x + Math.sin(orbit.theta) * horizontal,
orbit.target.y + Math.sin(orbit.phi) * orbit.radius,
orbit.target.z + Math.cos(orbit.theta) * horizontal
);
camera.lookAt(orbit.target);
}
function updatePhaseUI(phase, recordProgress) {
if (phase !== lastPhase) {
lastPhase = phase;
stepButtons.forEach((button, index) => {
button.classList.toggle("active", index === phase);
button.style.setProperty("--step-progress", index < phase ? "100%" : index === phase ? "45%" : "0%");
});
if (phase === 0) {
phaseTitle.textContent = "Bring the sightline into agreement";
phaseCopy.textContent = "The observer turns the alidade until the beacon sits exactly within the sighting vanes.";
readoutValue.textContent = "—";
readoutLabel.textContent = "Bearing not yet fixed";
statusLine.textContent = "Alignment in progress";
} else if (phase === 1) {
phaseTitle.textContent = "Read the divided arc";
phaseCopy.textContent = "With the target held steady, the observer reads the graduation and confirms the bearing.";
readoutValue.textContent = "47° 30′";
readoutLabel.textContent = "Bearing / east quadrant";
statusLine.textContent = "Observation confirmed";
} else {
phaseTitle.textContent = "Carry the observation to the record";
phaseCopy.textContent = "The same reading is transferred from the instrument to the open field ledger.";
readoutValue.textContent = "47° 30′";
readoutLabel.textContent = "One observation in transit";
statusLine.textContent = "Recording in progress";
}
}
if (phase === 2) {
stepButtons[2].style.setProperty(
"--step-progress",
`${Math.round(recordProgress * 100)}%`
);
if (recordProgress > 0.86) {
readoutLabel.textContent = "Observation preserved";
statusLine.textContent = "Record complete · 47° 30′";
} else if (recordProgress > 0.38) {
readoutLabel.textContent = "Being written to ledger";
statusLine.textContent = "Ink follows the observation";
} else {
readoutLabel.textContent = "One observation in transit";
statusLine.textContent = "Observer moves to the desk";
}
}
}
function updateScene(elapsed) {
let phase = 0;
let recordProgress = 0;
if (elapsed >= PHASE_1_END) {
phase = 2;
recordProgress = clamp01((elapsed - PHASE_1_END) / (TOTAL_TIME - PHASE_1_END));
} else if (elapsed >= PHASE_0_END) {
phase = 1;
}
const alignmentProgress = smooth01(elapsed / PHASE_0_END);
const yaw = lerp(
targetAzimuth - 0.34,
targetAzimuth,
alignmentProgress
);
const elevation = lerp(
-0.23,
targetElevation,
alignmentProgress
);
arcGroup.rotation.y = yaw;
azimuthPointer.rotation.y = yaw;
const localDirection = new THREE.Vector3(
Math.cos(elevation),
Math.sin(elevation),
0
);
sightRig.quaternion.setFromUnitVectors(X_AXIS, localDirection);
currentDirection.copy(localDirection).applyAxisAngle(Y_AXIS, yaw);
lineStart.copy(instrumentPivot);
lineEnd.copy(lineStart).addScaledVector(currentDirection, 8.0);
const positions = sightLine.geometry.attributes.position;
positions.setXYZ(0, lineStart.x, lineStart.y, lineStart.z);
positions.setXYZ(1, lineEnd.x, lineEnd.y, lineEnd.z);
positions.needsUpdate = true;
sightLine.computeLineDistances();
sightLineMaterial.opacity = phase === 0
? 0.24 + alignmentProgress * 0.66
: 0.90;
limbGlowMaterial.emissiveIntensity = phase === 1
? 0.55 + Math.sin(elapsed * 5.0) * 0.20
: 0.08;
targetRing.material.opacity = phase === 1
? 0.50 + Math.sin(elapsed * 3.2) * 0.18
: 0.22;
// The observation token: sightline → instrument → hand → ledger.
if (phase === 0) {
observationToken.position.lerpVectors(lineStart, lineEnd, alignmentProgress);
} else if (phase === 1) {
observationToken.position.copy(instrumentPivot);
observationToken.position.y += Math.sin(elapsed * 4.0) * 0.035;
} else {
updateObserver(recordProgress);
observer.rightHand.getWorldPosition(handPosition);
ledgerPosition.set(0.30, 1.50, 0);
deskRoot.localToWorld(ledgerPosition);
if (recordProgress < 0.08) {
observationToken.position.lerpVectors(
instrumentPivot,
handPosition,
smooth01(recordProgress / 0.08)
);
} else if (recordProgress < 0.34) {
observationToken.position.copy(handPosition);
} else if (recordProgress < 0.48) {
observationToken.position.lerpVectors(
handPosition,
ledgerPosition,
smooth01((recordProgress - 0.34) / 0.14)
);
} else {
observationToken.position.copy(ledgerPosition);
}
}
observationToken.rotation.x += 0.018;
observationToken.rotation.y += 0.026;
if (phase < 2) {
updateObserver(0);
}
updateLedgerAndQuill(recordProgress);
updatePhaseUI(phase, recordProgress);
const flicker = 0.86 + Math.sin(elapsed * 13.7) * 0.09 + Math.sin(elapsed * 21.3) * 0.05;
candleLight.intensity = 1.55 * flicker;
flame.scale.y = 0.93 + flicker * 0.12;
flame.rotation.y = elapsed * 0.7;
dust.rotation.y = elapsed * 0.006;
}
// -------------------------------------------------------------------------
// Projected world labels
// -------------------------------------------------------------------------
const labelElements = {
instrument: document.querySelector("#label-instrument"),
target: document.querySelector("#label-target"),
desk: document.querySelector("#label-desk")
};
const labelAnchors = {
instrument: new THREE.Vector3(-2.2, 3.95, 0.15),
target: new THREE.Vector3(3.5, 4.02, -5.05),
desk: new THREE.Vector3(2.9, 2.40, 2.7)
};
const projected = new THREE.Vector3();
function positionLabel(element, anchor) {
projected.copy(anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.1 &&
projected.y < 1.1;
element.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
positionLabel(labelElements.instrument, labelAnchors.instrument);
positionLabel(labelElements.target, labelAnchors.target);
positionLabel(labelElements.desk, labelAnchors.desk);
}
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
if (state.playing) {
state.elapsed = Math.min(TOTAL_TIME, state.elapsed + dt);
if (state.elapsed >= TOTAL_TIME) {
setPlaying(false);
}
}
const phase = state.elapsed >= PHASE_1_END
? 2
: state.elapsed >= PHASE_0_END
? 1
: 0;
const recordProgress = phase === 2
? clamp01((state.elapsed - PHASE_1_END) / (TOTAL_TIME - PHASE_1_END))
: 0;
updateScene(state.elapsed);
updateCamera(phase, recordProgress, now);
updateLabels();
scrubber.value = Math.round(state.elapsed / TOTAL_TIME * 1000);
scrubber.style.setProperty("--progress", `${state.elapsed / TOTAL_TIME * 100}%`);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
animate();
</script>
</body>
</html>
```