Prompt specification
Build or customize the Three.js 3D scene "Island settlement and coastal resource routes" 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: Island settlement and coastal resource routes
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/island-settlement-and-coastal-resource-routes-x2287
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Lapita island settlements and maritime exchange. Build a compact Pacific island settlement scene linking shoreline, gardens, and canoe access. Show daily resource paths and avoid portraying all island societies as one uniform culture. Low-poly.
Working Three.js Starter (island-settlement-and-coastal-resource-routes-x2287):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lapita Island Settlement — Shoreline, Gardens, and Canoe Exchange</title>
<style>
:root {
--ink: #183238;
--muted: #587078;
--panel: rgba(250, 248, 238, 0.92);
--line: rgba(24, 50, 56, 0.16);
--garden: #ef9f45;
--water: #3da6ba;
--shore: #e7684f;
--exchange: #8b70bd;
--shadow: 0 12px 35px rgba(19, 44, 52, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9fd2df;
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;
cursor: pointer;
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.62);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.intro {
position: absolute;
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 18px 19px 16px;
border-radius: 18px;
}
.kicker {
margin-bottom: 7px;
color: #3d7277;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 39px);
font-weight: 500;
line-height: 1.03;
letter-spacing: -0.025em;
}
.intro p {
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.cultural-note {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #315b62;
font-size: 11.5px;
line-height: 1.48;
}
.cultural-note strong { color: var(--ink); }
.top-actions {
position: absolute;
top: 18px;
right: 18px;
display: flex;
gap: 8px;
pointer-events: auto;
}
.small-button {
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 12px;
padding: 10px 13px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
font-size: 12px;
font-weight: 700;
}
.small-button:hover,
.small-button:focus-visible {
background: #fffdf4;
outline: 2px solid rgba(61, 166, 186, 0.35);
outline-offset: 2px;
}
.about {
position: absolute;
top: 70px;
right: 18px;
width: min(380px, calc(100vw - 36px));
padding: 18px;
border-radius: 16px;
color: var(--muted);
font-size: 12.5px;
line-height: 1.58;
}
.about h2 {
margin: 0 0 10px;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
font-weight: 500;
}
.about p { margin: 0 0 11px; }
.about p:last-child { margin-bottom: 0; }
.about strong { color: var(--ink); }
.hidden { display: none !important; }
.legend {
position: absolute;
left: 18px;
bottom: 98px;
width: 248px;
padding: 15px;
border-radius: 16px;
}
.legend h2 {
margin: 0 0 11px;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend label {
display: flex;
align-items: center;
gap: 8px;
margin: 8px 0;
color: #405f66;
font-size: 12px;
cursor: pointer;
}
.legend input {
width: 15px;
height: 15px;
accent-color: #367f83;
}
.route-key {
display: grid;
gap: 7px;
margin: 12px 0;
padding-top: 11px;
border-top: 1px solid var(--line);
}
.route-key div {
display: flex;
align-items: center;
gap: 8px;
color: #405f66;
font-size: 11.5px;
}
.route-key i {
display: block;
width: 23px;
border-top: 3px dotted;
border-radius: 50%;
}
.views {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
margin-top: 11px;
}
.views button {
border: 1px solid var(--line);
border-radius: 9px;
padding: 7px 8px;
background: rgba(255, 255, 255, 0.48);
font-size: 11px;
font-weight: 700;
}
.views button:hover { background: #fffdf4; }
.timeline {
position: absolute;
bottom: 18px;
left: 50%;
display: grid;
grid-template-columns: auto 150px 56px;
align-items: center;
gap: 12px;
min-width: 390px;
padding: 12px 15px;
border-radius: 15px;
transform: translateX(-50%);
}
.play-button {
min-width: 68px;
border: 0;
border-radius: 9px;
padding: 8px 10px;
background: #255e63;
color: white;
font-size: 11px;
font-weight: 800;
}
#timeRange {
width: 150px;
accent-color: #e39a42;
}
#timeLabel {
font-size: 13px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
.timeline-caption {
grid-column: 1 / -1;
margin-top: -7px;
color: var(--muted);
font-size: 10px;
text-align: center;
}
.detail {
position: absolute;
right: 18px;
bottom: 98px;
width: min(330px, calc(100vw - 36px));
padding: 16px;
border-radius: 15px;
}
.detail h2 {
margin: 0 22px 7px 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 500;
}
.detail p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.detail button {
position: absolute;
top: 10px;
right: 11px;
width: 28px;
height: 28px;
border: 0;
border-radius: 50%;
background: rgba(24, 50, 56, 0.08);
font-size: 18px;
line-height: 1;
}
#labels {
position: absolute;
inset: 0;
pointer-events: none;
}
.hotspot {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
border: 0;
padding: 0;
background: transparent;
pointer-events: auto;
transform: translate(-50%, -50%);
white-space: nowrap;
}
.hotspot .dot {
width: 11px;
height: 11px;
border: 2px solid rgba(255, 255, 255, 0.95);
border-radius: 50%;
background: #326f73;
box-shadow: 0 2px 7px rgba(0, 0, 0, 0.28);
}
.hotspot .label-text {
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 8px;
background: rgba(250, 248, 238, 0.88);
box-shadow: 0 4px 13px rgba(22, 47, 53, 0.15);
color: #23474e;
font-size: 10.5px;
font-weight: 750;
}
.hotspot:hover .label-text,
.hotspot:focus-visible .label-text {
background: #fffdf4;
outline: 2px solid rgba(50, 111, 115, 0.3);
}
.hint {
position: absolute;
right: 18px;
bottom: 22px;
color: rgba(24, 50, 56, 0.72);
font-size: 10.5px;
text-shadow: 0 1px 4px rgba(255, 255, 255, 0.8);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #a9d7e2;
color: #285d63;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 0.5s ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 14px 15px;
}
.intro p { font-size: 12px; }
.cultural-note { font-size: 10.5px; }
.top-actions {
top: auto;
right: 10px;
bottom: 103px;
}
.legend { display: none; }
.timeline {
right: 10px;
bottom: 10px;
left: 10px;
min-width: 0;
transform: none;
}
.detail {
right: 10px;
bottom: 157px;
left: 10px;
width: auto;
}
.hint { display: none; }
.hotspot .label-text { font-size: 9.5px; }
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive low-poly Lapita-associated island settlement"></canvas>
<div id="loading">Building the island…</div>
<main id="hud">
<section class="panel intro">
<div class="kicker">Remote Oceania · Interpretive model</div>
<h1>Island, garden, canoe</h1>
<p>
A compact Lapita-associated settlement connecting shoreline foraging,
productive gardens, household spaces, and inter-island canoe travel.
</p>
<div class="cultural-note">
<strong>A composite, not a universal Pacific village.</strong>
Lapita communities had distinct local histories. House forms, crops,
exchange goods, and voyaging practices varied by place and time.
</div>
</section>
<div class="top-actions">
<button class="small-button" id="aboutButton" aria-expanded="false">About</button>
<button class="small-button" id="resetButton">Reset view</button>
</div>
<section class="panel about hidden" id="aboutPanel">
<h2>How to read the model</h2>
<p>
This teaching vignette links three connected systems: garden production
inland, household activity in the center, and marine resources and
exchange along the shore.
</p>
<p>
The animated paths are an explanatory overlay, not a sourced daily
timetable. Crop species, dwellings, clothing, cargo, and canoe details
are deliberately schematic because Lapita settlement life is not
securely reconstructed from any single island.
</p>
<p>
<strong>Exchange cargo is symbolic.</strong> Real goods and movement
varied between communities. A canoe leaving for a neighboring island
demonstrates the maritime connections that linked dispersed settlements.
</p>
<p>
Drag to orbit, scroll or pinch to zoom, and right-drag or Shift-drag to
pan. Select a map label for more context.
</p>
</section>
<section class="panel legend" aria-label="Scene controls">
<h2>Scene layers</h2>
<label><input id="routesToggle" type="checkbox" checked> Resource and sea routes</label>
<label><input id="peopleToggle" type="checkbox" checked> People and canoes</label>
<label><input id="labelsToggle" type="checkbox" checked> Place labels</label>
<div class="route-key" aria-hidden="true">
<div><i style="border-color: var(--garden)"></i> Garden → household</div>
<div><i style="border-color: var(--water)"></i> Water basin → household</div>
<div><i style="border-color: var(--shore)"></i> Household → landing</div>
<div><i style="border-color: var(--exchange)"></i> Inter-island exchange</div>
</div>
<div class="views" aria-label="Camera presets">
<button data-view="overview">Overview</button>
<button data-view="garden">Garden</button>
<button data-view="shore">Shoreline</button>
<button data-view="landing">Canoe landing</button>
</div>
</section>
<section class="panel timeline" aria-label="Illustrative day cycle">
<button class="play-button" id="playButton">Pause</button>
<input id="timeRange" type="range" min="5" max="20" step="0.05" value="9.5"
aria-label="Time of day">
<span id="timeLabel">09:30</span>
<span class="timeline-caption">Illustrative day cycle — not an archaeological timetable</span>
</section>
<section class="panel detail hidden" id="detailCard">
<button id="closeDetail" aria-label="Close detail">×</button>
<h2 id="detailTitle"></h2>
<p id="detailText"></p>
</section>
<div id="labels"></div>
<div class="hint">Drag to orbit · wheel to zoom · right-drag to pan</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
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();
const daySky = new THREE.Color("#a8d9e6");
const duskSky = new THREE.Color("#30475f");
scene.background = daySky.clone();
scene.fog = new THREE.Fog(daySky.clone(), 26, 68);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
140
);
const hemi = new THREE.HemisphereLight("#d9f1f4", "#746d4e", 1.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff0ce", 1.65);
sun.position.set(8, 14, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight("#83bdd0", 0.35);
fill.position.set(-8, 7, -10);
scene.add(fill);
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...extra
});
const mats = {
sand: material("#d9bd79"),
path: material("#c7aa72"),
wood: material("#745039"),
woodLight: material("#9b7148"),
thatch: material("#9b7a43"),
thatchDark: material("#76582f"),
wall: material("#c3a675"),
wallDark: material("#8d7657"),
leaf: material("#527f43", { side: THREE.DoubleSide }),
leafLight: material("#72984f", { side: THREE.DoubleSide }),
trunk: material("#8a6844"),
stone: material("#777d70"),
water: material("#3ca9bc", { roughness: 0.25, metalness: 0.08 }),
crop: material("#5f9148"),
rope: material("#d4c49c"),
cargo: material("#d98450"),
clothBlue: material("#4e8191"),
clothRust: material("#b85e48"),
clothGold: material("#d49b45"),
dark: material("#263e40")
};
// ---------------------------------------------------------------------
// Low-poly ocean
// ---------------------------------------------------------------------
const oceanGeometry = new THREE.PlaneGeometry(90, 90, 44, 44);
oceanGeometry.rotateX(-Math.PI / 2);
const oceanColors = [];
const oceanPos = oceanGeometry.attributes.position;
const oceanBase = new Float32Array(oceanPos.count);
for (let i = 0; i < oceanPos.count; i++) {
const x = oceanPos.getX(i);
const z = oceanPos.getZ(i);
oceanBase[i * 3] = x;
oceanBase[i * 3 + 1] = z;
const n = 0.91 + Math.sin(x * 1.9 + z * 0.7) * 0.025 +
Math.sin(z * 2.3 - x * 0.4) * 0.02;
const c = new THREE.Color("#258ba0").multiplyScalar(n);
oceanColors.push(c.r, c.g, c.b);
}
oceanGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(oceanColors, 3)
);
const ocean = new THREE.Mesh(
oceanGeometry,
material("#ffffff", {
vertexColors: true,
roughness: 0.48,
metalness: 0.04
})
);
ocean.receiveShadow = true;
scene.add(ocean);
// ---------------------------------------------------------------------
// Radial faceted islands
// ---------------------------------------------------------------------
function makeIsland(radius, seed = 0) {
const group = new THREE.Group();
const segments = 38;
const fractions = [0.24, 0.42, 0.60, 0.76, 0.88, 1.0];
const heights = [0.34, 0.29, 0.24, 0.17, 0.09, 0.015];
const colors = [
"#78914b",
"#718b48",
"#7e9951",
"#92a75a",
"#d7bb77",
"#e2c98b"
].map(c => new THREE.Color(c));
const positions = [0, heights[0] * radius / 6, 0];
const vertexColors = [colors[0].r, colors[0].g, colors[0].b];
const indices = [];
for (let ring = 0; ring < fractions.length; ring++) {
const f = fractions[ring];
const h = heights[ring] * radius / 6;
for (let j = 0; j < segments; j++) {
const a = (j / segments) * Math.PI * 2;
const shape =
1 +
0.065 * Math.sin(a * 3 + seed) +
0.045 * Math.cos(a * 5 - seed * 0.7) +
0.025 * Math.sin(a * 8 + seed * 1.4);
const r = radius * f * shape;
const y = h + Math.sin(a * 5 + ring * 0.8 + seed) * 0.009 * radius / 6;
positions.push(
Math.cos(a) * r,
y,
Math.sin(a) * r * 0.93
);
const c = colors[ring].clone();
c.multiplyScalar(0.94 + 0.07 * Math.sin(j * 1.7 + ring));
vertexColors.push(c.r, c.g, c.b);
}
}
const firstRing = 1;
for (let j = 0; j < segments; j++) {
indices.push(0, firstRing + j, firstRing + (j + 1) % segments);
}
for (let ring = 0; ring < fractions.length - 1; ring++) {
const a0 = 1 + ring * segments;
const b0 = a0 + segments;
for (let j = 0; j < segments; j++) {
const jn = (j + 1) % segments;
indices.push(
a0 + j, b0 + j, b0 + jn,
a0 + j, b0 + jn, a0 + jn
);
}
}
const geo = new THREE.BufferGeometry();
geo.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geo.setAttribute("color", new THREE.Float32BufferAttribute(vertexColors, 3));
geo.setIndex(indices.reverse());
geo.computeVertexNormals();
const mesh = new THREE.Mesh(
geo,
material("#ffffff", { vertexColors: true, roughness: 0.96 })
);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return group;
}
const mainIsland = makeIsland(6, 0.7);
scene.add(mainIsland);
const exchangeIsland = makeIsland(2.25, 2.4);
exchangeIsland.position.set(13.1, 0, -4.3);
scene.add(exchangeIsland);
// ---------------------------------------------------------------------
// Palm trees and vegetation
// ---------------------------------------------------------------------
const swayingLeaves = [];
function makePalm(x, z, height = 2.5, rotation = 0, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.10, 0.17, height, 5, 1),
mats.trunk
);
trunk.position.y = height / 2;
trunk.rotation.z = 0.07;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Group();
crown.position.set(0.14, height, 0);
group.add(crown);
const leafGeometry = new THREE.BufferGeometry();
leafGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, 0, 0,
0.62, 0.13, 0,
1.55, -0.05, 0,
0.65, -0.13, 0
], 3)
);
leafGeometry.setIndex([0, 1, 2, 0, 2, 3]);
leafGeometry.computeVertexNormals();
for (let i = 0; i < 7; i++) {
const leaf = new THREE.Mesh(
leafGeometry,
i % 2 ? mats.leaf : mats.leafLight
);
leaf.rotation.y = (i / 7) * Math.PI * 2;
leaf.rotation.z = (i % 2 ? 1 : -1) * 0.08;
leaf.castShadow = true;
crown.add(leaf);
swayingLeaves.push({
mesh: leaf,
base: leaf.rotation.z,
phase: i * 0.7 + rotation
});
}
for (let i = 0; i < 3; i++) {
const coconut = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.11, 0),
mats.wood
);
coconut.position.set(
(i - 1) * 0.11,
-0.08,
(i % 2 ? 0.08 : -0.07)
);
crown.add(coconut);
}
scene.add(group);
return group;
}
[
[-0.5, -3.35, 2.6, 0.2],
[0.35, -3.55, 2.3, 1.2],
[1.1, -3.0, 2.8, 2.1],
[1.75, -2.55, 2.35, 0.7],
[-1.15, -3.0, 2.45, 2.8],
[3.45, -1.85, 2.05, 1.5],
[-3.8, -2.35, 2.2, 0.4],
[3.7, 0.0, 2.0, 2.6],
[-4.2, 0.6, 2.15, 1.8]
].forEach(p => makePalm(...p));
makePalm(13.25, -4.25, 2.45, 0.6, 0.9);
makePalm(14.0, -4.5, 2.15, 2.0, 0.8);
function makeShrub(x, z, s = 0.3) {
const shrub = new THREE.Mesh(
new THREE.DodecahedronGeometry(s, 0),
mats.leaf
);
shrub.position.set(x, 0.26 + s * 0.45, z);
shrub.scale.y = 0.65;
shrub.rotation.set(0.3, Math.random() * 2, 0.2);
shrub.castShadow = true;
scene.add(shrub);
}
makeShrub(-3.65, 1.4, 0.38);
makeShrub(3.4, -2.9, 0.31);
makeShrub(4.0, 1.9, 0.27);
makeShrub(-2.9, 2.0, 0.3);
// ---------------------------------------------------------------------
// Settlement structures with deliberately varied schematic forms
// ---------------------------------------------------------------------
function gableGeometry(width, depth, height) {
const w = width / 2;
const d = depth / 2;
const positions = [
-w, 0, -d, 0, height, -d, w, 0, -d,
-w, 0, d, 0, height, d, w, 0, d
];
const indices = [
0, 2, 1,
3, 4, 5,
0, 1, 4, 0, 4, 3,
1, 2, 5, 1, 5, 4
];
const geo = new THREE.BufferGeometry();
geo.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geo.setIndex(indices);
geo.computeVertexNormals();
return geo;
}
function addBox(parent, size, position, mat) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), mat);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLonghouse(x, z, rotation) {
const group = new THREE.Group();
group.position.set(x, 0.35, z);
group.rotation.y = rotation;
addBox(group, [2.65, 0.16, 1.75], [0, 0.08, 0], mats.wood);
addBox(group, [2.35, 0.78, 1.45], [0, 0.55, 0], mats.wall);
for (let i = 0; i < 5; i++) {
addBox(group, [0.06, 0.80, 1.48], [-1.08 + i * 0.54, 0.55, 0], mats.woodDark);
}
const roof = new THREE.Mesh(
gableGeometry(2.95, 1.95, 0.72),
mats.thatch
);
roof.position.y = 0.94;
roof.castShadow = true;
group.add(roof);
addBox(group, [0.54, 0.64, 0.08], [0, 0.52, 0.77], mats.woodDark);
scene.add(group);
}
function makeRaisedHut(x, z, rotation) {
const group = new THREE.Group();
group.position.set(x, 0.34, z);
group.rotation.y = rotation;
for (const px of [-0.67, 0.67]) {
for (const pz of [-0.48, 0.48]) {
addBox(group, [0.12, 0.55, 0.12], [px, 0.20, pz], mats.wood);
}
}
addBox(group, [1.65, 0.13, 1.25], [0, 0.49, 0], mats.woodLight);
addBox(group, [1.35, 0.68, 1.02], [0, 0.88, 0], mats.wallDark);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(1.12, 0.67, 4),
mats.thatchDark
);
roof.position.y = 1.55;
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.78;
roof.castShadow = true;
group.add(roof);
scene.add(group);
}
function makeOpenPavilion(x, z, rotation) {
const group = new THREE.Group();
group.position.set(x, 0.34, z);
group.rotation.y = rotation;
addBox(group, [2.2, 0.14, 1.55], [0, 0.08, 0], mats.woodLight);
for (const px of [-0.88, 0.88]) {
for (const pz of [-0.55, 0.55]) {
addBox(group, [0.12, 1.12, 0.12], [px, 0.67, pz], mats.wood);
}
}
const roof = new THREE.Mesh(
gableGeometry(2.5, 1.78, 0.58),
mats.thatch
);
roof.position.y = 1.22;
roof.castShadow = true;
group.add(roof);
addBox(group, [1.0, 0.24, 0.5], [0, 0.28, 0], mats.woodDark);
scene.add(group);
}
function makeStoreShelter(x, z, rotation) {
const group = new THREE.Group();
group.position.set(x, 0.34, z);
group.rotation.y = rotation;
addBox(group, [1.5, 0.12, 1.1], [0, 0.06, 0], mats.wood);
for (const px of [-0.56, 0.56]) {
addBox(group, [0.1, 1.0, 0.1], [px, 0.58, -0.34], mats.wood);
addBox(group, [0.1, 1.0, 0.1], [px, 0.58, 0.34], mats.wood);
}
const roof = addBox(
group, [1.85, 0.12, 1.42], [0, 1.10, 0], mats.thatchDark
);
roof.rotation.z = 0.14;
addBox(group, [0.55, 0.42, 0.55], [-0.3, 0.31, 0.02], mats.cargo);
addBox(group, [0.42, 0.35, 0.45], [0.35, 0.27, -0.05], mats.wallDark);
scene.add(group);
}
makeLonghouse(-0.3, 0.25, -0.12);
makeRaisedHut(1.35, -0.05, 0.22);
makeOpenPavilion(0.35, 1.65, -0.28);
makeStoreShelter(2.05, 1.18, 0.36);
// ---------------------------------------------------------------------
// Garden, water basin, landing, and paths
// ---------------------------------------------------------------------
const garden = new THREE.Group();
garden.position.set(-2.55, 0, -0.95);
scene.add(garden);
for (let bed = 0; bed < 3; bed++) {
const x = (bed - 1) * 0.68;
addBox(garden, [0.43, 0.10, 1.65], [x, 0.36, 0], mats.path);
for (let row = 0; row < 6; row++) {
const plant = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.13, 0),
mats.crop
);
plant.position.set(x, 0.49, -0.64 + row * 0.255);
plant.scale.y = 1.2;
plant.rotation.y = row * 0.8;
garden.add(plant);
}
}
for (let i = 0; i < 10; i++) {
const a = i / 10 * Math.PI * 2;
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.035, 0.35, 5),
mats.wood
);
post.position.set(
Math.cos(a) * 1.18,
0.43,
Math.sin(a) * 1.04
);
garden.add(post);
}
const basin = new THREE.Group();
basin.position.set(1.75, 0, -2.2);
scene.add(basin);
const basinWater = new THREE.Mesh(
new THREE.CylinderGeometry(0.38, 0.34, 0.08, 10),
mats.water
);
basinWater.position.y = 0.38;
basin.add(basinWater);
for (let i = 0; i < 9; i++) {
const a = i / 9 * Math.PI * 2;
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.17, 0),
mats.stone
);
rock.position.set(
Math.cos(a) * 0.42,
0.35,
Math.sin(a) * 0.42
);
rock.scale.set(1, 0.8, 0.75);
basin.add(rock);
}
const dock = new THREE.Group();
dock.position.set(5.85, 0, 1.5);
scene.add(dock);
for (let i = 0; i < 9; i++) {
addBox(dock, [0.29, 0.11, 1.02], [-1.18 + i * 0.30, 0.30, 0], mats.woodLight);
}
for (const z of [-0.43, 0.43]) {
for (const x of [-1.05, 0.05, 1.05]) {
addBox(dock, [0.13, 0.82, 0.13], [x, 0.12, z], mats.wood);
}
}
function curve(points) {
return new THREE.CatmullRomCurve3(
points.map(p => new THREE.Vector3(...p)),
false,
"catmullrom",
0.35
);
}
function makeRibbon(pathCurve, width = 0.42) {
const positions = [];
const indices = [];
const segments = 70;
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const p = pathCurve.getPointAt(t);
const tangent = pathCurve.getTangentAt(t);
const side = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
const left = p.clone().addScaledVector(side, width / 2);
const right = p.clone().addScaledVector(side, -width / 2);
positions.push(left.x, left.y + 0.015, left.z);
positions.push(right.x, right.y + 0.015, right.z);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
}
const geo = new THREE.BufferGeometry();
geo.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geo.setIndex(indices);
geo.computeVertexNormals();
const mesh = new THREE.Mesh(geo, mats.path);
mesh.receiveShadow = true;
scene.add(mesh);
}
const gardenPath = curve([
[-3.25, 0.38, -1.15],
[-2.25, 0.39, -0.75],
[-1.2, 0.39, -0.2],
[0.05, 0.39, 0.55],
[0.65, 0.38, 1.15]
]);
const waterPath = curve([
[1.75, 0.38, -2.2],
[1.1, 0.39, -1.15],
[0.62, 0.39, -0.15],
[0.65, 0.39, 0.65]
]);
const shorePath = curve([
[0.8, 0.38, 0.85],
[2.35, 0.29, 1.12],
[3.8, 0.19, 1.35],
[5.15, 0.10, 1.5]
]);
const seaRoute = curve([
[6.65, 0.23, 1.5],
[8.2, 0.23, 0.45],
[10.2, 0.23, -1.75],
[12.55, 0.23, -4.05]
]);
makeRibbon(gardenPath, 0.48);
makeRibbon(waterPath, 0.38);
makeRibbon(shorePath, 0.48);
// ---------------------------------------------------------------------
// Animated resource and exchange routes
// ---------------------------------------------------------------------
const routes = [];
function makeRoute(pathCurve, color, kind, count = 13, sea = false) {
const points = pathCurve.getPoints(110).map(p =>
p.clone().add(new THREE.Vector3(0, sea ? 0.035 : 0.065, 0))
);
const geo = new THREE.BufferGeometry().setFromPoints(points);
const lineMat = new THREE.LineDashedMaterial({
color,
dashSize: sea ? 0.20 : 0.16,
gapSize: sea ? 0.16 : 0.13,
transparent: true,
opacity: 0.78,
depthTest: true
});
const line = new THREE.Line(geo, lineMat);
line.computeLineDistances();
line.renderOrder = 3;
scene.add(line);
const beadGeometry = sea
? new THREE.OctahedronGeometry(0.105, 0)
: new THREE.OctahedronGeometry(0.065, 0);
const beads = [];
for (let i = 0; i < count; i++) {
const bead = new THREE.Mesh(
beadGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
depthTest: true
})
);
scene.add(bead);
beads.push(bead);
}
const route = {
curve: pathCurve,
line,
beads,
kind,
sea,
phase: Math.random() * 0.5
};
routes.push(route);
return route;
}
makeRoute(gardenPath, "#ef9f45", "garden");
makeRoute(waterPath, "#3da6ba", "water");
makeRoute(shorePath, "#e7684f", "shore");
makeRoute(seaRoute, "#a687d4", "exchange", 17, true);
// ---------------------------------------------------------------------
// People: intentionally generic, schematic figures
// ---------------------------------------------------------------------
const people = [];
function makePerson(shirtMat, carrying = null, scale = 1) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.19, 0.48, 6),
shirtMat
);
body.position.y = 0.72;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.13, 1),
material("#9b694d")
);
head.position.y = 1.09;
head.castShadow = true;
group.add(head);
const legGeometry = new THREE.CylinderGeometry(0.055, 0.065, 0.42, 5);
const armGeometry = new THREE.CylinderGeometry(0.045, 0.055, 0.43, 5);
const legs = [];
const arms = [];
for (const side of [-1, 1]) {
const leg = new THREE.Mesh(legGeometry, mats.dark);
leg.position.set(side * 0.09, 0.25, 0);
leg.castShadow = true;
group.add(leg);
legs.push(leg);
const arm = new THREE.Mesh(armGeometry, shirtMat);
arm.position.set(side * 0.21, 0.72, 0);
arm.rotation.z = side * 0.12;
arm.castShadow = true;
group.add(arm);
arms.push(arm);
}
if (carrying === "basket") {
const basket = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.12, 0.20, 8, 1, true),
mats.rope
);
basket.position.set(0.22, 0.57, 0.08);
basket.rotation.z = 0.18;
basket.castShadow = true;
group.add(basket);
}
if (carrying === "jar") {
const jar = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.14, 0),
mats.cargo
);
jar.position.set(0.23, 0.58, 0.06);
jar.scale.set(0.8, 1.15, 0.8);
group.add(jar);
}
group.scale.setScalar(scale);
scene.add(group);
const person = { group, legs, arms };
people.push(person);
return person;
}
const gardener = makePerson(mats.clothRust, "basket");
const waterCarrier = makePerson(mats.clothBlue, "jar");
const shoreWalker = makePerson(mats.clothGold, null, 0.96);
const fisher = makePerson(mats.clothBlue, null, 0.92);
fisher.group.position.set(6.0, 0.36, 1.76);
fisher.group.rotation.y = -Math.PI / 2;
// ---------------------------------------------------------------------
// Canoes
// ---------------------------------------------------------------------
function makeCanoe(withCargo = false) {
const group = new THREE.Group();
const stations = [
[-1.45, 0.025],
[-1.05, 0.28],
[-0.40, 0.39],
[0.50, 0.37],
[1.08, 0.23],
[1.45, 0.02]
];
const positions = [];
for (const [x, w] of stations) {
positions.push(
x, 0.14, -w,
x, 0.14, w,
x, -0.18, 0
);
}
const indices = [];
for (let s = 0; s < stations.length - 1; s++) {
const a = s * 3;
const b = (s + 1) * 3;
indices.push(
a, b, b + 2,
a, b + 2, a + 2,
a + 1, a + 2, b + 2,
a + 1, b + 2, b + 1
);
}
indices.push(0, 2, 1);
const e = (stations.length - 1) * 3;
indices.push(e, e + 1, e + 2);
const hullGeo = new THREE.BufferGeometry();
hullGeo.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
hullGeo.setIndex(indices);
hullGeo.computeVertexNormals();
const hull = new THREE.Mesh(
hullGeo,
material("#745039", { side: THREE.DoubleSide })
);
hull.castShadow = true;
group.add(hull);
addBox(group, [1.55, 0.055, 0.38], [-0.05, 0.09, 0], mats.woodLight);
addBox(group, [0.10, 0.09, 0.72], [-0.45, 0.16, 0], mats.wood);
addBox(group, [0.10, 0.09, 0.66], [0.43, 0.16, 0], mats.wood);
if (withCargo) {
for (let i = 0; i < 3; i++) {
const bundle = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.17, 0),
i % 2 ? mats.cargo : mats.rope
);
bundle.position.set(-0.48 + i * 0.38, 0.27, (i - 1) * 0.08);
bundle.scale.set(1.15, 0.75, 0.85);
bundle.castShadow = true;
group.add(bundle);
}
}
scene.add(group);
return group;
}
const dockedCanoe = makeCanoe(false);
dockedCanoe.position.set(6.65, 0.22, 2.0);
dockedCanoe.rotation.y = 0.06;
const travelingCanoe = makeCanoe(true);
const canoePerson = makePerson(mats.clothRust, null, 0.66);
canoePerson.group.position.set(0.28, 0.11, 0);
canoePerson.group.rotation.y = Math.PI / 2;
travelingCanoe.add(canoePerson.group);
// ---------------------------------------------------------------------
// Clouds and distant land
// ---------------------------------------------------------------------
const clouds = [];
function makeCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
const cloudMat = material("#f5f4e9", {
roughness: 1,
flatShading: true,
transparent: true,
opacity: 0.88
});
const pieces = [
[-0.8, 0, 0, 0.72],
[0, 0.18, 0, 0.92],
[0.85, 0, 0.05, 0.67],
[0.25, -0.12, 0.1, 0.75]
];
for (const [px, py, pz, s] of pieces) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(s, 1),
cloudMat
);
mesh.position.set(px, py, pz);
mesh.scale.y = 0.6;
group.add(mesh);
}
scene.add(group);
clouds.push(group);
}
makeCloud(-10, 7.5, -9, 1.1);
makeCloud(8, 8.8, -15, 1.35);
makeCloud(-18, 9.5, 4, 1.4);
function makeDistantIsland(x, z, radius, height) {
const geo = new THREE.ConeGeometry(radius, height, 10, 1);
const mesh = new THREE.Mesh(geo, material("#547a59"));
mesh.position.set(x, height / 2 - 0.2, z);
mesh.scale.z = 0.55;
scene.add(mesh);
}
makeDistantIsland(-19, -16, 4.2, 2.2);
makeDistantIsland(-24, -20, 2.5, 1.4);
makeDistantIsland(21, 13, 3.2, 1.8);
// ---------------------------------------------------------------------
// Place labels
// ---------------------------------------------------------------------
const labels = [];
function addHotspot(title, position, detail) {
const el = document.createElement("button");
el.className = "hotspot";
el.type = "button";
el.setAttribute("aria-label", `Open information about ${title}`);
el.innerHTML = `
<span class="dot"></span>
<span class="label-text">${title}</span>
`;
el.addEventListener("click", event => {
event.stopPropagation();
document.querySelector("#detailTitle").textContent = title;
document.querySelector("#detailText").textContent = detail;
document.querySelector("#detailCard").classList.remove("hidden");
});
document.querySelector("#labels").appendChild(el);
labels.push({
el,
position: new THREE.Vector3(...position),
visible: true
});
}
addHotspot(
"Household zone",
[0.15, 1.75, 0.35],
"The schematic dwellings occupy a central clearing. Their different forms emphasize that Pacific house architecture was locally varied rather than uniform. Actual Lapita house plans remain uncertain."
);
addHotspot(
"Garden plots",
[-2.55, 0.95, -0.95],
"Raised beds suggest the production of cultivated foods near the settlement. The crops shown are generic placeholders; species and cultivation practices differed across islands and ecological settings."
);
addHotspot(
"Water basin",
[1.75, 0.9, -2.2],
"Water could be stored near a household area before use. This model uses a small catchment as one possible link between inland resources and settlement activities."
);
addHotspot(
"Canoe landing",
[5.25, 0.85, 1.5],
"The landing links household paths to the sea. People could move between shore, garden, and settlement by short, repeated trips rather than living only beside the water."
);
addHotspot(
"Inter-island exchange",
[9.6, 0.65, -0.8],
"The moving canoe represents travel and exchange between neighboring islands. Its bundles are symbolic: actual trade goods, knowledge, and social links cannot be reduced to one universal commodity."
);
// ---------------------------------------------------------------------
// Custom camera controls
// ---------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 0.25, 0),
goalTarget: new THREE.Vector3(0, 0.25, 0),
radius: 17.5,
goalRadius: 17.5,
theta: 0.72,
goalTheta: 0.72,
phi: 1.02,
goalPhi: 1.02
};
let dragging = false;
let dragButton = 0;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
dragging = true;
dragButton = event.button;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
const panning = dragButton === 2 || event.shiftKey;
if (panning) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = orbit.target.clone().sub(camera.position);
forward.y = 0;
forward.normalize();
const scale = orbit.goalRadius * 0.0016;
orbit.goalTarget.addScaledVector(right, -dx * scale);
orbit.goalTarget.addScaledVector(forward, -dy * scale);
orbit.goalTarget.x = THREE.MathUtils.clamp(orbit.goalTarget.x, -8, 11);
orbit.goalTarget.z = THREE.MathUtils.clamp(orbit.goalTarget.z, -8, 8);
} else {
orbit.goalTheta -= dx * 0.006;
orbit.goalPhi = THREE.MathUtils.clamp(
orbit.goalPhi - dy * 0.005,
0.35,
1.38
);
}
});
function endDrag(event) {
dragging = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.goalRadius = THREE.MathUtils.clamp(
orbit.goalRadius * Math.exp(event.deltaY * 0.001),
6.5,
31
);
}, { passive: false });
// Pinch zoom for touch screens.
const activePointers = new Map();
let pinchDistance = 0;
canvas.addEventListener("pointerdown", event => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const [a, b] = [...activePointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", event => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const [a, b] = [...activePointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
orbit.goalRadius = THREE.MathUtils.clamp(
orbit.goalRadius * (pinchDistance / distance),
6.5,
31
);
}
pinchDistance = distance;
}
});
canvas.addEventListener("pointerup", event => {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
});
const presets = {
overview: {
target: [0, 0.25, 0],
radius: 17.5,
theta: 0.72,
phi: 1.02
},
garden: {
target: [-2.1, 0.35, -0.75],
radius: 8.5,
theta: -0.25,
phi: 0.94
},
shore: {
target: [3.6, 0.2, 1.1],
radius: 10.5,
theta: 0.65,
phi: 1.08
},
landing: {
target: [6.0, 0.15, 1.4],
radius: 8.2,
theta: 1.48,
phi: 1.03
}
};
function setView(name) {
const p = presets[name];
orbit.goalTarget.set(...p.target);
orbit.goalRadius = p.radius;
orbit.goalTheta = p.theta;
orbit.goalPhi = p.phi;
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
document.querySelector("#resetButton").addEventListener("click", () => {
setView("overview");
});
document.querySelector("#aboutButton").addEventListener("click", event => {
const panel = document.querySelector("#aboutPanel");
const open = panel.classList.toggle("hidden");
event.currentTarget.setAttribute("aria-expanded", String(!open));
});
document.querySelector("#closeDetail").addEventListener("click", () => {
document.querySelector("#detailCard").classList.add("hidden");
});
// ---------------------------------------------------------------------
// UI state and illustrative time cycle
// ---------------------------------------------------------------------
let dayHour = 9.5;
let playing = true;
const timeRange = document.querySelector("#timeRange");
const timeLabel = document.querySelector("#timeLabel");
const playButton = document.querySelector("#playButton");
function formatTime(hour) {
const h = Math.floor(hour);
const m = Math.floor((hour - h) * 60);
return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}`;
}
function updateTimeUI() {
timeRange.value = dayHour;
timeLabel.textContent = formatTime(dayHour);
}
timeRange.addEventListener("input", event => {
dayHour = Number(event.target.value);
updateTimeUI();
});
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
const routesToggle = document.querySelector("#routesToggle");
const peopleToggle = document.querySelector("#peopleToggle");
const labelsToggle = document.querySelector("#labelsToggle");
function routeStrength(kind, hour) {
if (kind === "garden") {
if (hour < 6 || hour > 18) return 0.16;
return 1;
}
if (kind === "water") {
if (hour < 5 || hour > 19) return 0.18;
return 1;
}
if (kind === "shore") {
if (hour < 5 || hour > 20) return 0.14;
return 1;
}
return 0.72;
}
function movePerson(person, pathCurve, elapsed, speed, offset = 0) {
const f = (elapsed * speed + offset) % 1;
const p = pathCurve.getPointAt(f);
const tangent = pathCurve.getTangentAt(f);
person.group.position.copy(p);
person.group.position.y += 0.035 + Math.abs(Math.sin(elapsed * 7 + offset * 8)) * 0.035;
person.group.rotation.y = Math.atan2(tangent.x, tangent.z);
const swing = Math.sin(elapsed * 7 + offset * 8) * 0.42;
person.legs[0].rotation.x = swing;
person.legs[1].rotation.x = -swing;
person.arms[0].rotation.x = -swing * 0.7;
person.arms[1].rotation.x = swing * 0.7;
}
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
let frame = 0;
const projected = new THREE.Vector3();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
frame++;
if (playing) {
dayHour += dt * 0.08;
if (dayHour > 20) dayHour = 5;
updateTimeUI();
}
// Daylight and sky.
const daylight = THREE.MathUtils.clamp(
Math.sin((dayHour - 5) / 15 * Math.PI),
0,
1
);
scene.background.copy(duskSky).lerp(daySky, daylight);
scene.fog.color.copy(scene.background);
hemi.intensity = 0.38 + daylight * 0.76;
sun.intensity = 0.28 + daylight * 1.42;
sun.position.x = 5 + (dayHour - 5) / 15 * 12;
// Ocean facets.
const positions = oceanGeometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = oceanBase[i * 3];
const z = oceanBase[i * 3 + 1];
const y =
Math.sin(x * 0.42 + elapsed * 0.65) * 0.042 +
Math.cos(z * 0.36 - elapsed * 0.48) * 0.032 +
Math.sin((x + z) * 0.22 + elapsed * 0.32) * 0.018;
positions.setY(i, y);
}
positions.needsUpdate = true;
if (frame % 4 === 0) oceanGeometry.computeVertexNormals();
// Palm movement.
for (const leaf of swayingLeaves) {
leaf.mesh.rotation.z =
leaf.base + Math.sin(elapsed * 0.85 + leaf.phase) * 0.035;
}
// Cloud drift.
for (const cloud of clouds) {
cloud.position.x += dt * 0.07;
if (cloud.position.x > 25) cloud.position.x = -25;
}
// Animated route beads.
for (const route of routes) {
const strength = routeStrength(route.kind, dayHour);
route.line.visible = routesToggle.checked;
route.line.material.opacity = 0.24 + strength * 0.58;
for (let i = 0; i < route.beads.length; i++) {
const bead = route.beads[i];
bead.visible = routesToggle.checked;
const f = (
i / route.beads.length +
elapsed * (route.sea ? 0.035 : 0.055) +
route.phase
) % 1;
bead.position.copy(route.curve.getPointAt(f));
bead.position.y += route.sea ? 0.065 : 0.10;
const pulse = 0.75 + Math.sin(elapsed * 4 + i) * 0.18;
bead.scale.setScalar(pulse);
bead.material.opacity = (0.35 + strength * 0.55) * pulse;
}
}
// Walking figures.
movePerson(gardener, gardenPath, elapsed, 0.027, 0.12);
movePerson(waterCarrier, waterPath, elapsed, 0.021, 0.42);
movePerson(shoreWalker, shorePath, elapsed, 0.025, 0.67);
for (const person of people) {
person.group.visible = peopleToggle.checked;
}
dockedCanoe.visible = peopleToggle.checked;
travelingCanoe.visible = peopleToggle.checked;
// Moving exchange canoe.
const canoeF = (elapsed * 0.024 + 0.19) % 1;
const canoePosition = seaRoute.getPointAt(canoeF);
const canoeTangent = seaRoute.getTangentAt(canoeF);
travelingCanoe.position.copy(canoePosition);
travelingCanoe.position.y += Math.sin(elapsed * 1.4) * 0.025;
travelingCanoe.rotation.y = Math.atan2(-canoeTangent.z, canoeTangent.x);
travelingCanoe.rotation.z = Math.sin(elapsed * 1.1) * 0.025;
travelingCanoe.rotation.x = Math.cos(elapsed * 1.25) * 0.018;
dockedCanoe.position.y = 0.22 + Math.sin(elapsed * 1.2 + 1.4) * 0.018;
dockedCanoe.rotation.z = Math.sin(elapsed * 1.05) * 0.014;
basinWater.rotation.y = elapsed * 0.22;
basinWater.position.y = 0.38 + Math.sin(elapsed * 1.7) * 0.003;
// Smooth custom camera.
const smoothing = 1 - Math.pow(0.001, dt);
orbit.target.lerp(orbit.goalTarget, smoothing);
orbit.radius = THREE.MathUtils.lerp(
orbit.radius, orbit.goalRadius, smoothing
);
orbit.theta = THREE.MathUtils.lerp(
orbit.theta, orbit.goalTheta, smoothing
);
orbit.phi = THREE.MathUtils.lerp(
orbit.phi, orbit.goalPhi, smoothing
);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
// Project labels into screen space.
for (const label of labels) {
projected.copy(label.position).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
const show = labelsToggle.checked && onScreen;
label.el.style.display = show ? "flex" : "none";
if (show) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.el.style.left = `${x}px`;
label.el.style.top = `${y}px`;
}
}
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, 1.8));
});
updateTimeUI();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("done");
setTimeout(() => document.querySelector("#loading").remove(), 600);
});
</script>
</body>
</html>
```