Prompt specification
Build or customize the Three.js 3D scene "Delivery instructions across a small square" 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: Delivery instructions across a small square
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/delivery-instructions-across-a-small-square-x1339
Scene Description Prompt:
Guide a low-poly parcel carrier through a square using explicit “behind,” “beside,” and “across” landmark references. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (delivery-instructions-across-a-small-square-x1339):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Parcel Path — Landmark Navigation</title>
<style>
:root {
--ink: #18323d;
--muted: #65747a;
--paper: #fffaf0;
--orange: #f26a38;
--orange-dark: #c84720;
--teal: #287c78;
--blue: #436e91;
--line: rgba(24, 50, 61, 0.13);
--shadow: 0 18px 50px rgba(29, 43, 47, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d7d8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.topbar {
position: fixed;
z-index: 20;
top: 20px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.brand {
display: flex;
gap: 12px;
align-items: center;
padding: 11px 15px 11px 11px;
border: 1px solid rgba(255, 255, 255, 0.42);
border-radius: 16px;
background: rgba(255, 250, 240, 0.88);
box-shadow: 0 10px 30px rgba(40, 65, 70, 0.12);
backdrop-filter: blur(14px);
}
.brand-icon {
position: relative;
width: 42px;
height: 42px;
border-radius: 12px;
background: var(--orange);
box-shadow: inset 0 -8px 0 rgba(123, 45, 18, 0.13);
}
.brand-icon::before {
content: "";
position: absolute;
left: 10px;
top: 9px;
width: 22px;
height: 19px;
border: 3px solid var(--paper);
border-radius: 3px;
}
.brand-icon::after {
content: "";
position: absolute;
left: 19px;
top: 9px;
width: 3px;
height: 19px;
background: var(--paper);
}
.brand-copy small {
display: block;
margin-bottom: 2px;
color: var(--orange-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.brand-copy strong {
display: block;
font-size: 18px;
line-height: 1.1;
letter-spacing: -0.02em;
}
.top-actions {
display: flex;
gap: 9px;
pointer-events: auto;
}
.glass-button {
display: inline-flex;
min-height: 43px;
align-items: center;
justify-content: center;
gap: 8px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.48);
border-radius: 13px;
background: rgba(255, 250, 240, 0.9);
box-shadow: 0 10px 28px rgba(40, 65, 70, 0.12);
cursor: pointer;
backdrop-filter: blur(14px);
transition:
transform 160ms ease,
background 160ms ease;
}
.glass-button:hover {
transform: translateY(-2px);
background: #fffaf0;
}
.glass-button:active {
transform: translateY(0);
}
.glass-button.primary {
border-color: transparent;
background: var(--orange);
color: white;
font-weight: 800;
}
.button-icon {
font-size: 17px;
line-height: 1;
}
.guide-panel {
position: fixed;
z-index: 15;
top: 98px;
left: 24px;
width: 365px;
max-height: calc(100vh - 210px);
overflow: auto;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.52);
border-radius: 21px;
background: rgba(255, 250, 240, 0.92);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
}
.panel-kicker {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.step-count {
color: var(--orange-dark);
}
.guide-panel h1 {
margin: 0;
font-size: clamp(25px, 2.3vw, 34px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.relation-row {
display: flex;
align-items: center;
gap: 8px;
margin: 14px 0 10px;
}
.relation-pill {
display: inline-flex;
align-items: center;
gap: 6px;
min-height: 27px;
padding: 0 10px;
border-radius: 999px;
background: #f4e4d6;
color: var(--orange-dark);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.relation-pill::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
}
.guide-text {
min-height: 61px;
margin: 0;
color: #455a62;
font-size: 15px;
line-height: 1.48;
}
.route-notes-title {
display: flex;
align-items: center;
gap: 10px;
margin: 18px 0 9px;
color: #829096;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.route-notes-title::after {
content: "";
flex: 1;
height: 1px;
background: var(--line);
}
.steps {
display: grid;
gap: 5px;
margin: 0;
padding: 0;
list-style: none;
}
.step-button {
display: grid;
grid-template-columns: 28px 1fr auto;
gap: 9px;
width: 100%;
align-items: center;
padding: 8px;
border: 1px solid transparent;
border-radius: 11px;
background: transparent;
text-align: left;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.step-button:hover {
background: rgba(24, 50, 61, 0.045);
transform: translateX(2px);
}
.step-button.active {
border-color: rgba(242, 106, 56, 0.22);
background: rgba(242, 106, 56, 0.09);
}
.step-number {
display: grid;
width: 27px;
height: 27px;
place-items: center;
border-radius: 9px;
background: #e9e7df;
color: #6d7a7f;
font-size: 11px;
font-weight: 900;
}
.step-button.active .step-number {
background: var(--orange);
color: white;
}
.step-name {
display: block;
font-size: 12px;
font-weight: 800;
}
.step-relation {
display: block;
margin-top: 2px;
color: #859096;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.step-arrow {
color: #9ba4a7;
font-size: 15px;
}
.transport {
position: fixed;
z-index: 18;
left: 50%;
bottom: 22px;
display: flex;
width: min(690px, calc(100vw - 48px));
align-items: center;
gap: 12px;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.52);
border-radius: 19px;
background: rgba(255, 250, 240, 0.94);
box-shadow: var(--shadow);
transform: translateX(-50%);
backdrop-filter: blur(18px);
}
.play-button {
flex: 0 0 auto;
display: grid;
width: 46px;
height: 46px;
place-items: center;
border: 0;
border-radius: 14px;
background: var(--orange);
color: white;
box-shadow: 0 7px 18px rgba(242, 106, 56, 0.3);
cursor: pointer;
}
.play-button span {
margin-left: 2px;
font-size: 18px;
}
.track {
min-width: 0;
flex: 1;
}
.track-meta {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 6px;
color: #738187;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
}
.track-meta strong {
color: var(--ink);
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background:
linear-gradient(
to right,
var(--orange) 0%,
var(--orange) var(--progress, 0%),
#dcded9 var(--progress, 0%),
#dcded9 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid var(--paper);
border-radius: 50%;
appearance: none;
background: var(--orange);
box-shadow: 0 2px 8px rgba(24, 50, 61, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid var(--paper);
border-radius: 50%;
background: var(--orange);
box-shadow: 0 2px 8px rgba(24, 50, 61, 0.25);
}
.replay-button {
flex: 0 0 auto;
width: 40px;
height: 40px;
padding: 0;
border: 1px solid var(--line);
border-radius: 12px;
background: #f5f0e6;
cursor: pointer;
}
.speed-button {
flex: 0 0 auto;
min-width: 46px;
height: 40px;
padding: 0 8px;
border: 1px solid var(--line);
border-radius: 12px;
background: #f5f0e6;
font-size: 11px;
font-weight: 900;
cursor: pointer;
}
.world-labels {
position: fixed;
z-index: 8;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px 6px 7px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 999px;
background: rgba(255, 250, 240, 0.88);
box-shadow: 0 7px 20px rgba(29, 43, 47, 0.12);
color: var(--ink);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
transform: translate(-50%, -100%);
transition:
background 180ms ease,
color 180ms ease,
box-shadow 180ms ease;
white-space: nowrap;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 18px;
background: rgba(24, 50, 61, 0.38);
}
.world-label .label-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
}
.world-label.active {
background: var(--orange);
color: white;
box-shadow: 0 9px 24px rgba(242, 106, 56, 0.32);
}
.world-label.active .label-dot {
background: white;
}
#carrier-label {
z-index: 9;
border-color: rgba(242, 106, 56, 0.25);
background: var(--orange);
color: white;
}
#carrier-label .label-dot {
background: white;
}
.compass {
position: fixed;
z-index: 10;
right: 25px;
bottom: 100px;
display: grid;
width: 67px;
height: 67px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.48);
border-radius: 50%;
background: rgba(255, 250, 240, 0.82);
box-shadow: 0 10px 28px rgba(40, 65, 70, 0.13);
pointer-events: none;
backdrop-filter: blur(12px);
}
.compass::before {
content: "N";
position: absolute;
top: 5px;
color: var(--orange-dark);
font-size: 9px;
font-weight: 900;
}
.compass-needle {
width: 2px;
height: 35px;
border-radius: 3px;
background: linear-gradient(to bottom, var(--orange) 0 50%, #879398 50% 100%);
transform-origin: center;
}
.interaction-hint {
position: fixed;
z-index: 9;
right: 24px;
bottom: 30px;
color: rgba(24, 50, 61, 0.72);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
pointer-events: none;
text-shadow: 0 1px 4px rgba(255, 255, 255, 0.8);
}
.loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #fffaf0;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader-box {
display: grid;
justify-items: center;
gap: 14px;
color: var(--muted);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.loader-cube {
width: 32px;
height: 32px;
border: 4px solid #e7dfd1;
border-top-color: var(--orange);
border-radius: 8px;
animation: spin 900ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 780px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.brand {
padding: 8px 11px 8px 8px;
}
.brand-icon {
width: 35px;
height: 35px;
}
.brand-icon::before {
left: 7px;
top: 7px;
width: 19px;
height: 17px;
}
.brand-icon::after {
left: 16px;
top: 7px;
height: 17px;
}
.brand-copy strong {
font-size: 15px;
}
.brand-copy small {
font-size: 8px;
}
.top-actions .button-label {
display: none;
}
.glass-button {
width: 42px;
padding: 0;
}
.guide-panel {
top: auto;
right: 12px;
bottom: 94px;
left: 12px;
width: auto;
max-height: 39vh;
padding: 15px;
border-radius: 17px;
}
.guide-panel h1 {
font-size: 24px;
}
.guide-text {
min-height: 0;
font-size: 13px;
}
.route-notes-title,
.steps {
display: none;
}
.transport {
bottom: 12px;
width: calc(100vw - 24px);
gap: 8px;
padding: 9px;
}
.play-button {
width: 41px;
height: 41px;
}
.speed-button {
display: none;
}
.compass {
right: 15px;
bottom: auto;
top: 78px;
width: 53px;
height: 53px;
}
.compass-needle {
height: 28px;
}
.interaction-hint {
display: none;
}
.world-label {
padding: 5px 7px;
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly square navigation scene"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-icon" aria-hidden="true"></div>
<div class="brand-copy">
<small>Landmark-first navigation</small>
<strong>Parcel Path</strong>
</div>
</div>
<div class="top-actions">
<button class="glass-button" id="view-button" type="button" aria-label="Toggle square overview">
<span class="button-icon">⌖</span>
<span class="button-label">Square view</span>
</button>
<button class="glass-button primary" id="guide-button" type="button" aria-label="Return to guide panel">
<span class="button-icon">☷</span>
<span class="button-label">Route guide</span>
</button>
</div>
</header>
<aside class="guide-panel" id="guide-panel" aria-label="Navigation guide">
<div class="panel-kicker">
<span>Guided delivery</span>
<span class="step-count" id="step-count">01 / 06</span>
</div>
<h1 id="current-title">Leave the market stall</h1>
<div class="relation-row">
<span class="relation-pill" id="current-relation">Beside</span>
</div>
<p class="guide-text" id="current-text" aria-live="polite"></p>
<div class="route-notes-title">Route notes</div>
<ol class="steps" id="steps"></ol>
</aside>
<div class="world-labels" id="world-labels" aria-hidden="true">
<div class="world-label" id="carrier-label" data-world-id="carrier">
<span class="label-dot"></span>
Parcel carrier
</div>
</div>
<div class="transport" aria-label="Route playback controls">
<button class="play-button" id="play-button" type="button" aria-label="Pause route">
<span id="play-icon">Ⅱ</span>
</button>
<div class="track">
<div class="track-meta">
<strong id="route-status">Walking to the clock tower</strong>
<span id="time-label">0:00 / 0:42</span>
</div>
<input
id="timeline"
type="range"
min="0"
max="1000"
value="0"
aria-label="Route progress"
/>
</div>
<button class="replay-button" id="replay-button" type="button" aria-label="Replay route">↺</button>
<button class="speed-button" id="speed-button" type="button" aria-label="Change playback speed">1×</button>
</div>
<div class="compass" aria-hidden="true">
<div class="compass-needle" id="compass-needle"></div>
</div>
<div class="interaction-hint">Drag to orbit · Scroll to zoom</div>
<div class="loading" id="loading">
<div class="loader-box">
<div class="loader-cube"></div>
Building the square
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Scene setup
// ---------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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(0xb9d7d8);
scene.fog = new THREE.Fog(0xb9d7d8, 31, 58);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemi = new THREE.HemisphereLight(0xd9f4ff, 0x8d765a, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d1, 3.1);
sun.position.set(-13, 24, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00025;
scene.add(sun);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
const palette = {
cream: material(0xfff2d7),
sand: material(0xd9bd91),
stone: material(0xb7aa96),
stoneLight: material(0xd8cdbb),
navy: material(0x244653),
teal: material(0x287c78),
tealDark: material(0x1c5a59),
orange: material(0xf26a38),
orangeDark: material(0xc94b24),
red: material(0xc94f44),
green: material(0x598b58),
greenDark: material(0x3f6848),
wood: material(0x8f6747),
yellow: material(0xe8b84c),
white: material(0xfffaf0),
black: material(0x1d2a2e),
water: material(0x61b9c2, {
roughness: 0.22,
metalness: 0.08,
transparent: true,
opacity: 0.86
})
};
function addMesh(geometry, mat, parent = scene, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(w, h, d, mat, parent = scene, x = 0, y = 0, z = 0) {
return addMesh(new THREE.BoxGeometry(w, h, d), mat, parent, x, y, z);
}
function addCylinder(
topRadius,
bottomRadius,
height,
segments,
mat,
parent = scene,
x = 0,
y = 0,
z = 0
) {
return addMesh(
new THREE.CylinderGeometry(topRadius, bottomRadius, height, segments),
mat,
parent,
x,
y,
z
);
}
function textTexture(text, background = "#18323d", foreground = "#fffaf0") {
const c = document.createElement("canvas");
c.width = 512;
c.height = 128;
const ctx = c.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, c.width, c.height);
ctx.fillStyle = foreground;
ctx.font = "900 52px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, c.width / 2, c.height / 2 + 3);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
return texture;
}
// ---------------------------------------------------------------------
// Square ground and paving
// ---------------------------------------------------------------------
const groundBase = addBox(
35,
0.35,
35,
material(0xb8a98f),
scene,
0,
-0.2,
0
);
groundBase.receiveShadow = true;
const plaza = addBox(
29,
0.12,
29,
material(0xe2d4bc),
scene,
0,
0.005,
0
);
plaza.receiveShadow = true;
const grid = new THREE.GridHelper(28, 14, 0x9d927f, 0xb9aa94);
grid.position.y = 0.075;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
const centerInset = addMesh(
new THREE.CircleGeometry(7.8, 48),
material(0xeadfc9),
scene,
0,
0.081,
0
);
centerInset.rotation.x = -Math.PI / 2;
centerInset.castShadow = false;
// ---------------------------------------------------------------------
// Fountain
// ---------------------------------------------------------------------
const fountain = new THREE.Group();
scene.add(fountain);
addCylinder(3.05, 3.25, 0.35, 24, palette.stoneLight, fountain, 0, 0.2, 0);
addCylinder(2.75, 2.95, 0.5, 24, palette.stone, fountain, 0, 0.5, 0);
const water = addCylinder(2.5, 2.5, 0.08, 32, palette.water, fountain, 0, 0.78, 0);
water.castShadow = false;
addCylinder(0.42, 0.72, 1.75, 10, palette.stoneLight, fountain, 0, 1.45, 0);
addCylinder(1.05, 1.05, 0.18, 12, palette.stone, fountain, 0, 2.34, 0);
addCylinder(0.25, 0.4, 1.25, 10, palette.stoneLight, fountain, 0, 3.03, 0);
addMesh(new THREE.SphereGeometry(0.32, 10, 7), palette.water, fountain, 0, 3.78, 0);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const jet = addCylinder(
0.035,
0.055,
0.75,
6,
material(0xbcecf0, { transparent: true, opacity: 0.72 }),
fountain,
Math.cos(angle) * 0.8,
2.7,
Math.sin(angle) * 0.8
);
jet.rotation.z = Math.cos(angle) * 0.35;
jet.rotation.x = Math.sin(angle) * 0.35;
jet.castShadow = false;
}
// ---------------------------------------------------------------------
// Market stall
// ---------------------------------------------------------------------
const market = new THREE.Group();
market.position.set(-11.8, 0, 9.4);
market.rotation.y = 0.16;
scene.add(market);
addBox(4.2, 0.9, 1.5, palette.tealDark, market, 0, 0.48, 0);
addBox(4.4, 0.16, 1.7, palette.cream, market, 0, 0.98, 0);
[-1.75, 1.75].forEach((x) => {
addBox(0.12, 2.7, 0.12, palette.wood, market, x, 1.35, -0.55);
addBox(0.12, 2.7, 0.12, palette.wood, market, x, 1.35, 0.65);
});
for (let i = 0; i < 8; i++) {
const stripe = addBox(
0.53,
0.14,
2.65,
i % 2 === 0 ? palette.red : palette.cream,
market,
-1.86 + i * 0.53,
2.72,
0.05
);
stripe.rotation.x = 0.05;
}
addBox(3.4, 0.8, 0.12, palette.cream, market, 0, 2.14, -0.7);
const marketSign = new THREE.Mesh(
new THREE.PlaneGeometry(2.8, 0.65),
new THREE.MeshBasicMaterial({
map: textTexture("MARKET", "#f26a38", "#fffaf0")
})
);
marketSign.position.set(0, 2.15, -0.625);
market.add(marketSign);
addBox(0.75, 0.42, 0.62, palette.yellow, market, -1.15, 1.27, 0.05);
addBox(0.65, 0.38, 0.62, palette.orange, market, 0.15, 1.25, 0.05);
addBox(0.7, 0.45, 0.62, palette.green, market, 1.25, 1.28, 0.05);
// ---------------------------------------------------------------------
// Clock tower
// ---------------------------------------------------------------------
const tower = new THREE.Group();
tower.position.set(10.6, 0, 8.7);
tower.rotation.y = -2.25;
scene.add(tower);
addBox(3.2, 0.42, 3.2, palette.stone, tower, 0, 0.22, 0);
addBox(2.25, 5.7, 2.25, palette.stoneLight, tower, 0, 3.12, 0);
addBox(2.48, 0.34, 2.48, palette.stone, tower, 0, 5.95, 0);
const roof = addMesh(
new THREE.ConeGeometry(1.8, 1.8, 4),
palette.tealDark,
tower,
0,
7.05,
0
);
roof.rotation.y = Math.PI / 4;
const clockFace = addMesh(
new THREE.CircleGeometry(0.67, 32),
palette.cream,
tower,
0,
4.7,
1.135
);
clockFace.castShadow = false;
const clockRim = addMesh(
new THREE.TorusGeometry(0.69, 0.09, 6, 32),
palette.navy,
tower,
0,
4.7,
1.16
);
const hourHand = addBox(0.07, 0.38, 0.035, palette.navy, tower, -0.08, 4.81, 1.18);
hourHand.rotation.z = -0.55;
const minuteHand = addBox(0.055, 0.5, 0.035, palette.orangeDark, tower, 0.12, 4.78, 1.2);
minuteHand.rotation.z = 0.55;
// ---------------------------------------------------------------------
// Parcel office
// ---------------------------------------------------------------------
const office = new THREE.Group();
office.position.set(-10.8, 0, -8.8);
office.rotation.y = 0.42;
scene.add(office);
addBox(5, 3.25, 3.6, palette.teal, office, 0, 1.63, 0);
addBox(5.25, 0.25, 3.85, palette.cream, office, 0, 3.35, 0);
addBox(4.6, 0.14, 2.6, palette.tealDark, office, 0, 3.54, -0.25);
addBox(1.45, 2.15, 0.12, palette.navy, office, 0, 1.08, 1.84);
addBox(0.08, 2.15, 0.14, palette.cream, office, 0, 1.08, 1.91);
addBox(1.45, 0.08, 0.14, palette.cream, office, 0, 1.08, 1.91);
const officeSign = new THREE.Mesh(
new THREE.PlaneGeometry(3.4, 0.75),
new THREE.MeshBasicMaterial({
map: textTexture("PARCEL OFFICE", "#18323d", "#fffaf0")
})
);
officeSign.position.set(0, 2.65, 1.86);
office.add(officeSign);
[-1.65, 1.65].forEach((x) => {
addBox(0.8, 0.8, 0.1, palette.yellow, office, x, 2.3, 1.86);
});
// ---------------------------------------------------------------------
// Café, perimeter buildings and square furniture
// ---------------------------------------------------------------------
const cafe = new THREE.Group();
cafe.position.set(11.2, 0, -7.3);
cafe.rotation.y = -2.5;
scene.add(cafe);
addBox(4.4, 2.7, 3.1, material(0xd28a5c), cafe, 0, 1.35, 0);
addBox(4.7, 0.22, 3.35, palette.cream, cafe, 0, 2.8, 0);
for (let i = 0; i < 7; i++) {
addBox(
0.62,
0.12,
1.45,
i % 2 ? palette.cream : palette.teal,
cafe,
-1.86 + i * 0.62,
2.28,
1.85
);
}
addBox(3.5, 0.85, 0.12, palette.navy, cafe, 0, 1.35, 1.6);
const cafeSign = new THREE.Mesh(
new THREE.PlaneGeometry(2.5, 0.58),
new THREE.MeshBasicMaterial({
map: textTexture("CAFÉ", "#18323d", "#fffaf0")
})
);
cafeSign.position.set(0, 2.15, 1.64);
cafe.add(cafeSign);
function addPerimeterBuilding(x, z, w, h, d, color, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
addBox(w, h, d, material(color), group, 0, h / 2, 0);
addBox(w + 0.25, 0.25, d + 0.25, palette.cream, group, 0, h + 0.08, 0);
const windowMat = material(0x426c79, { roughness: 0.4 });
const count = Math.max(2, Math.floor(w / 1.6));
for (let i = 0; i < count; i++) {
const wx = -w / 2 + 0.8 + i * ((w - 1.6) / Math.max(1, count - 1));
addBox(0.72, 0.78, 0.08, windowMat, group, wx, h * 0.58, d / 2 + 0.045);
addBox(0.08, 0.82, 0.11, palette.cream, group, wx, h * 0.58, d / 2 + 0.1);
}
return group;
}
addPerimeterBuilding(-6.3, 13.1, 5.3, 4.2, 3.0, 0x9db7a5, Math.PI);
addPerimeterBuilding(-0.4, 13.4, 5.1, 5.0, 3.0, 0xc9896e, Math.PI);
addPerimeterBuilding(5.8, 13.4, 5.0, 3.8, 3.0, 0x879cac, Math.PI);
addPerimeterBuilding(-13.2, -1.8, 3.1, 4.4, 5.2, 0xb8a17b, Math.PI / 2);
addPerimeterBuilding(13.2, 0.8, 3.1, 4.0, 4.7, 0x8fa79e, -Math.PI / 2);
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
addCylinder(0.16, 0.24, 2.05, 7, palette.wood, group, 0, 1.02, 0);
addMesh(
new THREE.DodecahedronGeometry(1.25, 0),
palette.green,
group,
0,
2.75,
0
);
addMesh(
new THREE.DodecahedronGeometry(0.88, 0),
palette.greenDark,
group,
0.72,
2.45,
0.12
);
addMesh(
new THREE.DodecahedronGeometry(0.72, 0),
material(0x73a16a),
group,
-0.65,
2.55,
0.15
);
}
[
[-7.5, 10.8, 1],
[-5.8, -11.2, 0.9],
[5.7, -11.3, 1],
[12.8, 2.1, 0.9],
[-12.9, -3.8, 0.85],
[3.8, 11.5, 0.78]
].forEach((v) => addTree(...v));
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
addBox(2.2, 0.14, 0.62, palette.wood, group, 0, 0.58, 0);
addBox(2.2, 0.72, 0.13, palette.wood, group, 0, 0.94, -0.29);
[-0.82, 0.82].forEach((bx) => {
addBox(0.13, 0.55, 0.55, palette.navy, group, bx, 0.27, 0);
});
}
addBench(-5.8, 2.3, 0.1);
addBench(5.5, 2.2, Math.PI);
addBench(-2.8, -8.1, 0.06);
addBench(3.8, -9.1, Math.PI);
function addLamp(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
addCylinder(0.07, 0.11, 3.35, 8, palette.navy, group, 0, 1.68, 0);
addMesh(new THREE.SphereGeometry(0.22, 8, 6), palette.yellow, group, 0, 3.43, 0);
addCylinder(0.22, 0.27, 0.12, 8, palette.navy, group, 0, 3.62, 0);
}
addLamp(-7.2, 7.6);
addLamp(7.1, 6.4);
addLamp(8.3, -5.5);
addLamp(-4.8, -6.5);
// Low-poly clouds
const clouds = [];
function addCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
addMesh(new THREE.DodecahedronGeometry(0.9, 0), palette.white, group, 0, 0, 0);
addMesh(new THREE.DodecahedronGeometry(0.68, 0), palette.white, group, 0.78, -0.12, 0);
addMesh(new THREE.DodecahedronGeometry(0.58, 0), palette.white, group, -0.76, -0.16, 0.04);
clouds.push({ group, baseX: x });
}
addCloud(-13, 13, -9, 1.3);
addCloud(7, 15, -13, 1.05);
addCloud(16, 12, 4, 0.9);
// ---------------------------------------------------------------------
// Route curve
// ---------------------------------------------------------------------
const routePoints = [
new THREE.Vector3(-10.5, 0, 7.6),
new THREE.Vector3(-7.0, 0, 5.2),
new THREE.Vector3(-2.5, 0, 3.8),
new THREE.Vector3(2.0, 0, 3.8),
new THREE.Vector3(6.2, 0, 5.7),
new THREE.Vector3(8.2, 0, 8.5),
new THREE.Vector3(8.0, 0, 3.0),
new THREE.Vector3(6.0, 0, -5.0),
new THREE.Vector3(1.0, 0, -7.3),
new THREE.Vector3(-4.8, 0, -7.5),
new THREE.Vector3(-8.5, 0, -6.7)
];
const routeCurve = new THREE.CatmullRomCurve3(
routePoints,
false,
"catmullrom",
0.34
);
const sampledRoute = routeCurve.getPoints(300).map(
(p) => new THREE.Vector3(p.x, 0.11, p.z)
);
const routeGeometry = new THREE.BufferGeometry().setFromPoints(sampledRoute);
const dashedRoute = new THREE.Line(
routeGeometry,
new THREE.LineDashedMaterial({
color: 0xf26a38,
dashSize: 0.42,
gapSize: 0.24,
transparent: true,
opacity: 0.62
})
);
dashedRoute.computeLineDistances();
scene.add(dashedRoute);
const traveledRoute = new THREE.Line(
routeGeometry.clone(),
new THREE.LineBasicMaterial({
color: 0xf26a38,
transparent: true,
opacity: 0.92
})
);
scene.add(traveledRoute);
const arrowGeometry = new THREE.ConeGeometry(0.16, 0.43, 3);
for (let i = 1; i < 24; i++) {
const t = i / 24;
const point = routeCurve.getPointAt(t);
const tangent = routeCurve.getTangentAt(t).normalize();
const arrow = addMesh(arrowGeometry, palette.orange, scene, point.x, 0.17, point.z);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
arrow.castShadow = false;
}
const startMarker = addMesh(
new THREE.RingGeometry(0.55, 0.78, 32),
new THREE.MeshBasicMaterial({
color: 0x287c78,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.85
}),
scene,
routePoints[0].x,
0.1,
routePoints[0].z
);
startMarker.rotation.x = -Math.PI / 2;
const endMarker = addMesh(
new THREE.RingGeometry(0.68, 0.95, 32),
new THREE.MeshBasicMaterial({
color: 0xf26a38,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.9
}),
scene,
routePoints.at(-1).x,
0.105,
routePoints.at(-1).z
);
endMarker.rotation.x = -Math.PI / 2;
// Small delivery flag
const flag = new THREE.Group();
flag.position.set(-8.5, 0, -5.75);
scene.add(flag);
addCylinder(0.045, 0.065, 2.5, 7, palette.navy, flag, 0, 1.25, 0);
addBox(0.9, 0.5, 0.07, palette.orange, flag, 0.44, 2.18, 0);
// ---------------------------------------------------------------------
// Low-poly parcel carrier
// ---------------------------------------------------------------------
const carrier = new THREE.Group();
const carrierBody = new THREE.Group();
carrier.add(carrierBody);
scene.add(carrier);
const skin = material(0xc88e65);
const trousers = material(0x244653);
const shirt = material(0xf5d58c);
const vest = material(0xf26a38);
const parcelMat = material(0xc89454);
const tapeMat = material(0xf5d99f);
addBox(0.72, 0.83, 0.44, shirt, carrierBody, 0, 1.48, 0);
addBox(0.76, 0.56, 0.49, vest, carrierBody, 0, 1.53, 0.01);
addBox(0.08, 0.55, 0.51, vest, carrierBody, -0.22, 1.53, 0.01);
addBox(0.08, 0.55, 0.51, vest, carrierBody, 0.22, 1.53, 0.01);
addMesh(new THREE.SphereGeometry(0.31, 10, 7), skin, carrierBody, 0, 2.22, 0.02);
const cap = addCylinder(
0.32,
0.34,
0.2,
10,
palette.navy,
carrierBody,
0,
2.47,
0.01
);
const capBill = addBox(
0.47,
0.07,
0.25,
palette.navy,
carrierBody,
0,
2.4,
0.29
);
capBill.rotation.x = -0.08;
addMesh(new THREE.SphereGeometry(0.035, 6, 5), palette.black, carrierBody, -0.105, 2.25, 0.275);
addMesh(new THREE.SphereGeometry(0.035, 6, 5), palette.black, carrierBody, 0.105, 2.25, 0.275);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.48, 1.86, 0);
rightArm.position.set(0.48, 1.86, 0);
carrierBody.add(leftArm, rightArm);
addCylinder(0.115, 0.135, 0.72, 7, shirt, leftArm, 0, -0.34, 0);
addCylinder(0.115, 0.135, 0.72, 7, shirt, rightArm, 0, -0.34, 0);
addMesh(new THREE.SphereGeometry(0.13, 8, 6), skin, leftArm, 0, -0.74, 0);
addMesh(new THREE.SphereGeometry(0.13, 8, 6), skin, rightArm, 0, -0.74, 0);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.21, 1.08, 0);
rightLeg.position.set(0.21, 1.08, 0);
carrierBody.add(leftLeg, rightLeg);
addCylinder(0.135, 0.16, 0.82, 7, trousers, leftLeg, 0, -0.4, 0);
addCylinder(0.135, 0.16, 0.82, 7, trousers, rightLeg, 0, -0.4, 0);
addBox(0.27, 0.16, 0.43, palette.black, leftLeg, 0, -0.87, 0.08);
addBox(0.27, 0.16, 0.43, palette.black, rightLeg, 0, -0.87, 0.08);
// Parcel backpack and straps
addBox(0.64, 0.72, 0.38, parcelMat, carrierBody, 0, 1.6, -0.42);
addBox(0.12, 0.75, 0.405, tapeMat, carrierBody, 0, 1.6, -0.43);
addBox(0.66, 0.11, 0.41, tapeMat, carrierBody, 0, 1.73, -0.43);
addBox(0.07, 0.72, 0.08, palette.navy, carrierBody, -0.27, 1.65, -0.1);
addBox(0.07, 0.72, 0.08, palette.navy, carrierBody, 0.27, 1.65, -0.1);
const parcelLabel = new THREE.Mesh(
new THREE.PlaneGeometry(0.45, 0.16),
new THREE.MeshBasicMaterial({
map: textTexture("PARCEL", "#fffaf0", "#18323d")
})
);
parcelLabel.position.set(0, 1.55, -0.625);
parcelLabel.rotation.y = Math.PI;
carrierBody.add(parcelLabel);
const carrierRing = addMesh(
new THREE.RingGeometry(0.62, 0.78, 32),
new THREE.MeshBasicMaterial({
color: 0xf26a38,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.66
}),
scene,
0,
0.13,
0
);
carrierRing.rotation.x = -Math.PI / 2;
carrierRing.castShadow = false;
// ---------------------------------------------------------------------
// Interface state
// ---------------------------------------------------------------------
const steps = [
{
at: 0,
jump: 0,
relation: "Beside",
title: "Leave the market stall",
text: "Start beside the striped market awning. The fountain is across the square.",
landmark: "market",
status: "Starting beside the market"
},
{
at: 0.13,
jump: 0.16,
relation: "Across",
title: "Cross toward the clock",
text: "Walk across the square toward the clock tower; keep it beside the route on your right.",
landmark: "clock",
status: "Walking to the clock tower"
},
{
at: 0.29,
jump: 0.33,
relation: "Behind",
title: "Curve around the plaza",
text: "With the market behind you, curve north. The clock tower stays beside you.",
landmark: "market",
status: "Market behind — clock tower beside"
},
{
at: 0.47,
jump: 0.51,
relation: "Beside",
title: "Pass the clock tower",
text: "Pass beside the clock tower and head south, keeping the fountain across your left.",
landmark: "clock",
status: "Passing the clock tower"
},
{
at: 0.63,
jump: 0.67,
relation: "Across",
title: "Follow the east side",
text: "Cross to the east of the fountain, leaving the clock tower behind you.",
landmark: "fountain",
status: "Clock tower behind"
},
{
at: 0.79,
jump: 0.83,
relation: "Beside",
title: "Follow the south edge",
text: "Walk beside the fountain’s south edge. The parcel office is across the square ahead.",
landmark: "office",
status: "Parcel office across the square"
},
{
at: 0.95,
jump: 0.985,
relation: "Behind",
title: "Reach the parcel office",
text: "Stop beside the parcel office, with the fountain behind you.",
landmark: "office",
status: "Delivery point reached"
}
];
const elements = {
stepCount: document.querySelector("#step-count"),
title: document.querySelector("#current-title"),
relation: document.querySelector("#current-relation"),
text: document.querySelector("#current-text"),
status: document.querySelector("#route-status"),
time: document.querySelector("#time-label"),
timeline: document.querySelector("#timeline"),
playButton: document.querySelector("#play-button"),
playIcon: document.querySelector("#play-icon"),
replay: document.querySelector("#replay-button"),
speed: document.querySelector("#speed-button"),
view: document.querySelector("#view-button"),
guide: document.querySelector("#guide-button"),
steps: document.querySelector("#steps"),
panel: document.querySelector("#guide-panel"),
carrierLabel: document.querySelector("#carrier-label"),
compass: document.querySelector("#compass-needle"),
loading: document.querySelector("#loading")
};
const stepButtons = [];
steps.forEach((step, index) => {
const li = document.createElement("li");
const button = document.createElement("button");
button.type = "button";
button.className = "step-button";
button.innerHTML = `
<span class="step-number">${String(index + 1).padStart(2, "0")}</span>
<span>
<span class="step-name">${step.title}</span>
<span class="step-relation">${step.relation} reference</span>
</span>
<span class="step-arrow">›</span>
`;
button.addEventListener("click", () => {
progress = step.jump;
playing = true;
updatePlaybackButton();
updateUI();
});
li.appendChild(button);
elements.steps.appendChild(li);
stepButtons.push(button);
});
const landmarkDefinitions = [
{
id: "market",
title: "Striped market",
position: new THREE.Vector3(-11.8, 3.4, 9.4)
},
{
id: "clock",
title: "Clock tower",
position: new THREE.Vector3(10.6, 8.6, 8.7)
},
{
id: "fountain",
title: "Fountain",
position: new THREE.Vector3(0, 4.25, 0)
},
{
id: "office",
title: "Parcel office",
position: new THREE.Vector3(-10.8, 4.0, -8.8)
}
];
const landmarkLabels = [];
landmarkDefinitions.forEach((landmark) => {
const label = document.createElement("div");
label.className = "world-label";
label.dataset.worldId = landmark.id;
label.innerHTML = `<span class="label-dot"></span>${landmark.title}`;
document.querySelector("#world-labels").appendChild(label);
landmarkLabels.push({ ...landmark, element: label });
});
let progress = 0;
let playing = true;
let speed = 1;
let activeStep = -1;
let overview = false;
const duration = 42;
function setActiveStep(index) {
if (index === activeStep) return;
activeStep = index;
const step = steps[index];
elements.stepCount.textContent = `${String(index + 1).padStart(2, "0")} / ${String(steps.length).padStart(2, "0")}`;
elements.title.textContent = step.title;
elements.relation.textContent = step.relation;
elements.text.textContent = step.text;
elements.status.textContent = step.status;
stepButtons.forEach((button, i) => {
button.classList.toggle("active", i === index);
});
landmarkLabels.forEach((label) => {
label.element.classList.toggle("active", label.id === step.landmark);
});
}
function updatePlaybackButton() {
elements.playIcon.textContent = playing ? "Ⅱ" : "▶";
elements.playButton.setAttribute(
"aria-label",
playing ? "Pause route" : "Play route"
);
}
function updateUI() {
let index = 0;
for (let i = 0; i < steps.length; i++) {
if (progress >= steps[i].at) index = i;
}
setActiveStep(index);
const elapsed = progress * duration;
const minutes = Math.floor(elapsed / 60);
const seconds = Math.floor(elapsed % 60);
elements.time.textContent = `${minutes}:${String(seconds).padStart(2, "0")} / 0:42`;
elements.timeline.value = Math.round(progress * 1000);
elements.timeline.style.setProperty("--progress", `${progress * 100}%`);
}
elements.playButton.addEventListener("click", () => {
if (progress >= 1) progress = 0;
playing = !playing;
updatePlaybackButton();
});
elements.replay.addEventListener("click", () => {
progress = 0;
playing = true;
updatePlaybackButton();
updateUI();
});
elements.speed.addEventListener("click", () => {
speed = speed === 1 ? 1.5 : speed === 1.5 ? 0.75 : 1;
elements.speed.textContent = `${speed}×`;
});
elements.timeline.addEventListener("input", () => {
progress = Number(elements.timeline.value) / 1000;
playing = false;
updatePlaybackButton();
updateUI();
});
elements.view.addEventListener("click", () => {
overview = !overview;
elements.view.querySelector(".button-label").textContent = overview
? "Follow carrier"
: "Square view";
});
elements.guide.addEventListener("click", () => {
elements.panel.scrollIntoView({
behavior: "smooth",
block: "nearest"
});
elements.panel.animate(
[
{ transform: "translateX(0)", opacity: 1 },
{ transform: "translateX(-8px)", opacity: 0.72 },
{ transform: "translateX(0)", opacity: 1 }
],
{ duration: 380, easing: "ease-out" }
);
});
// ---------------------------------------------------------------------
// Direct camera controls: orbit, zoom and follow
// ---------------------------------------------------------------------
let azimuth = -0.65;
let polar = 0.86;
let radius = 15;
let radiusTarget = 15;
const cameraTarget = new THREE.Vector3();
const desiredTarget = new THREE.Vector3();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(polar - dy * 0.0045, 0.38, 1.34);
});
function endDrag(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.style.cursor = "grab";
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radiusTarget = THREE.MathUtils.clamp(
radiusTarget + event.deltaY * 0.012,
7,
37
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
azimuth = -0.65;
polar = 0.86;
radiusTarget = overview ? 29 : 15;
});
// ---------------------------------------------------------------------
// Projected world labels
// ---------------------------------------------------------------------
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, yOffset = 0) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
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 + yOffset;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
progress = Math.min(1, progress + (delta / duration) * speed);
if (progress >= 1) {
playing = false;
updatePlaybackButton();
}
updateUI();
}
const routePoint = routeCurve.getPointAt(progress);
const tangent = routeCurve.getTangentAt(progress).normalize();
carrier.position.copy(routePoint);
carrier.rotation.y = Math.atan2(tangent.x, tangent.z);
const walkPhase = progress * 420;
const stride = Math.sin(walkPhase);
leftLeg.rotation.x = stride * 0.52;
rightLeg.rotation.x = -stride * 0.52;
leftArm.rotation.x = -stride * 0.42;
rightArm.rotation.x = stride * 0.42;
carrierBody.position.y = Math.abs(Math.sin(walkPhase * 2)) * 0.035;
carrierBody.rotation.z = Math.sin(walkPhase) * 0.015;
carrierRing.position.set(routePoint.x, 0.13, routePoint.z);
const pulse = 1 + Math.sin(performance.now() * 0.004) * 0.09;
carrierRing.scale.setScalar(pulse);
carrierRing.material.opacity = 0.5 + Math.sin(performance.now() * 0.004) * 0.12;
const routeCount = Math.floor(progress * (sampledRoute.length - 1));
traveledRoute.geometry.setDrawRange(0, routeCount * 2);
// Camera target and direct orbit
if (overview) {
desiredTarget.set(0, 1, 0);
radiusTarget = 29;
} else {
desiredTarget.set(routePoint.x, 1.25, routePoint.z);
}
const targetBlend = 1 - Math.exp(-delta * 5.5);
cameraTarget.lerp(desiredTarget, targetBlend);
radius += (radiusTarget - radius) * (1 - Math.exp(-delta * 7));
const horizontal = radius * Math.sin(polar);
camera.position.set(
cameraTarget.x + Math.sin(azimuth) * horizontal,
cameraTarget.y + Math.cos(polar) * radius,
cameraTarget.z + Math.cos(azimuth) * horizontal
);
camera.lookAt(cameraTarget);
elements.compass.style.transform = `rotate(${-azimuth * 180 / Math.PI}deg)`;
// Clouds drift slowly
clouds.forEach((cloud, index) => {
cloud.group.position.x =
cloud.baseX + Math.sin(performance.now() * 0.00007 + index) * 1.8;
});
// Landmark labels
landmarkLabels.forEach((label) => {
placeLabel(label.element, label.position);
});
const carrierLabelPosition = carrier.position.clone();
carrierLabelPosition.y += 3.0;
placeLabel(elements.carrierLabel, carrierLabelPosition);
if (firstFrame) {
firstFrame = false;
elements.loading.classList.add("hidden");
setTimeout(() => elements.loading.remove(), 400);
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updatePlaybackButton();
updateUI();
</script>
</body>
</html>
```