Prompt specification
Build or customize the Three.js 3D scene "Two Boats Share One Landing" 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: Two Boats Share One Landing
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-boats-share-one-landing-x3562
Scene Description Prompt:
Two voxel boats share a narrow landing under turn-taking rules, with passengers waiting visibly. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (two-boats-share-one-landing-x3562):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One Slip — Two Voxel Boats</title>
<style>
:root {
--ink: #17333d;
--muted: #60767c;
--paper: rgba(255, 255, 255, 0.88);
--line: rgba(23, 51, 61, 0.13);
--coral: #ef6b57;
--blue: #3389c6;
--green: #35a56f;
--amber: #e4a83d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cce8e8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
max-width: 360px;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.72);
color: #41636b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(53, 165, 111, 0.14);
content: "";
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 52px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.subtitle {
max-width: 315px;
margin: 12px 0 0;
color: #506a71;
font-size: 13px;
line-height: 1.5;
}
.panel {
position: absolute;
top: 24px;
right: 24px;
width: min(310px, calc(100vw - 48px));
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 18px;
background: var(--paper);
box-shadow:
0 18px 50px rgba(38, 77, 84, 0.14),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 15px 16px;
border-bottom: 1px solid var(--line);
}
.panel-title {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.live {
display: flex;
align-items: center;
gap: 6px;
color: #638087;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
}
.live::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
content: "";
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.4;
transform: scale(0.8);
}
}
.boat-row {
display: grid;
grid-template-columns: 38px 1fr auto;
gap: 11px;
align-items: center;
padding: 13px 16px;
border-bottom: 1px solid var(--line);
transition: background 180ms ease;
}
.boat-row.active {
background: rgba(53, 165, 111, 0.08);
}
.boat-icon {
display: grid;
width: 34px;
height: 34px;
place-items: center;
border-radius: 10px;
color: white;
font-size: 12px;
font-weight: 850;
box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.1);
}
.boat-a .boat-icon {
background: var(--coral);
}
.boat-b .boat-icon {
background: var(--blue);
}
.boat-name {
font-size: 13px;
font-weight: 750;
}
.boat-detail {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.state-pill {
padding: 5px 8px;
border-radius: 999px;
background: #edf2f2;
color: #71868b;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.active .state-pill {
background: #d8f3e7;
color: #267a54;
}
.landing-status {
padding: 14px 16px 15px;
}
.status-line {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
font-size: 11px;
}
.status-line strong {
font-size: 11px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.signal-copy {
color: var(--muted);
text-align: right;
}
.progress {
height: 5px;
margin-top: 12px;
overflow: hidden;
border-radius: 99px;
background: #dfe8e8;
}
.progress > div {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #38a873, #79d0a3);
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 12px;
padding: 10px 13px;
background: rgba(255, 255, 255, 0.86);
color: var(--ink);
box-shadow: 0 8px 24px rgba(38, 77, 84, 0.1);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(12px);
}
button:hover {
background: white;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.hint {
position: absolute;
bottom: 26px;
left: 27px;
display: flex;
align-items: center;
gap: 9px;
color: rgba(23, 51, 61, 0.67);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
}
.mouse {
position: relative;
width: 18px;
height: 25px;
border: 1.5px solid currentColor;
border-radius: 9px;
}
.mouse::before {
position: absolute;
top: 4px;
left: 7px;
width: 2px;
height: 5px;
border-radius: 2px;
background: currentColor;
content: "";
}
#labels {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
z-index: 3;
transform: translate(-50%, -100%);
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 9px;
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 7px 20px rgba(34, 67, 75, 0.13);
color: var(--ink);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.05em;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.world-label::after {
position: absolute;
bottom: -5px;
left: 50%;
width: 8px;
height: 8px;
transform: translateX(-50%) rotate(45deg);
background: rgba(255, 255, 255, 0.88);
content: "";
}
.world-label.a {
border-bottom: 3px solid var(--coral);
}
.world-label.b {
border-bottom: 3px solid var(--blue);
}
.world-label.landing {
border-bottom: 3px solid var(--green);
}
@media (max-width: 700px) {
.brand {
top: 18px;
left: 18px;
}
.subtitle,
.hint {
display: none;
}
.panel {
top: auto;
right: 14px;
bottom: 14px;
width: 250px;
}
.panel-head,
.landing-status {
padding: 10px 12px;
}
.boat-row {
padding: 9px 12px;
}
.controls {
top: 132px;
right: 14px;
bottom: auto;
flex-direction: column;
}
button {
padding: 8px 10px;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div id="labels"></div>
<div id="ui">
<header class="brand">
<div class="eyebrow">Canal 07 · shared landing</div>
<h1>One slip.<br />Two boats.</h1>
<p class="subtitle">
A turn-taking berth keeps the narrow landing safe while passengers
wait and move ashore.
</p>
</header>
<aside class="panel">
<div class="panel-head">
<span class="panel-title">Landing control</span>
<span class="live">Live</span>
</div>
<div class="boat-row boat-a" id="row-a">
<div class="boat-icon">A</div>
<div>
<div class="boat-name">Marmalade</div>
<div class="boat-detail">3 passengers aboard</div>
</div>
<div class="state-pill" id="state-a">Priority</div>
</div>
<div class="boat-row boat-b" id="row-b">
<div class="boat-icon">B</div>
<div>
<div class="boat-name">Blue Finch</div>
<div class="boat-detail">3 passengers aboard</div>
</div>
<div class="state-pill" id="state-b">Holding</div>
</div>
<div class="landing-status">
<div class="status-line">
<strong>Single landing</strong>
<span class="signal-copy" id="signal-copy">Entry authorized</span>
</div>
<div class="progress">
<div id="progress"></div>
</div>
</div>
</aside>
<div class="controls">
<button id="pause" type="button">Pause</button>
<button id="restart" type="button">Restart</button>
<button id="camera-reset" type="button">Reset view</button>
</div>
<div class="hint">
<span class="mouse"></span>
Drag to orbit · Scroll to zoom
</div>
</div>
<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, 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(0xcce8e8);
scene.fog = new THREE.Fog(0xcce8e8, 38, 76);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemi = new THREE.HemisphereLight(0xe9ffff, 0x657a6e, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.2);
sun.position.set(-12, 22, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.0006;
scene.add(sun);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function groupAt(x = 0, y = 0, z = 0, parent = scene) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
return group;
}
function smooth(t) {
t = THREE.MathUtils.clamp(t, 0, 1);
return t * t * (3 - 2 * t);
}
function lerp(a, b, t) {
return THREE.MathUtils.lerp(a, b, t);
}
// ------------------------------------------------------------
// Water and shoreline
// ------------------------------------------------------------
const water = new THREE.Mesh(
new THREE.PlaneGeometry(70, 46),
new THREE.MeshStandardMaterial({
color: 0x5bb8c3,
roughness: 0.32,
metalness: 0.08,
transparent: true,
opacity: 0.94
})
);
water.rotation.x = -Math.PI / 2;
water.receiveShadow = true;
scene.add(water);
const ripples = [];
for (let i = 0; i < 34; i++) {
const ripple = box(
0.8 + Math.random() * 1.8,
0.018,
0.07 + Math.random() * 0.07,
0xa6e0df,
-28 + Math.random() * 40,
0.025,
-13 + Math.random() * 26,
scene
);
ripple.castShadow = false;
ripple.receiveShadow = false;
ripple.userData.speed = 0.12 + Math.random() * 0.2;
ripple.userData.offset = Math.random() * 20;
ripples.push(ripple);
}
// Right-hand land mass.
box(17, 1.35, 34, 0x9eaa78, 20.5, 0.45, 0);
box(17, 0.22, 34, 0x789461, 20.5, 1.2, 0);
box(0.45, 1.9, 34, 0x7d8f7d, 12.05, 0.62, 0);
// Stone path from landing to the terminal.
for (let i = 0; i < 9; i++) {
box(
0.88,
0.055,
1.45,
i % 2 ? 0xd6c6a0 : 0xcabb95,
12.55 + i * 0.88,
1.34,
0
);
}
// Voxel terminal building.
const building = groupAt(16.2, 1.33, -6.2);
box(6.4, 3.6, 5.1, 0xf1e6c9, 0, 1.8, 0, building);
box(6.8, 0.35, 5.5, 0x54777b, 0, 3.72, 0, building);
box(5.6, 0.35, 4.3, 0x45666a, 0, 4.05, 0, building);
box(1.25, 2.25, 0.12, 0x42646b, 1.25, 1.13, 2.59, building);
box(1.35, 0.12, 0.2, 0xf5cc67, 1.25, 2.28, 2.68, building);
box(1.25, 1.15, 0.12, 0x8dc4cb, -1.7, 2.05, 2.59, building);
box(0.12, 1.15, 1.4, 0x8dc4cb, 3.24, 2.05, -0.7, building);
// Rooftop details.
box(1.2, 0.8, 1.1, 0xc97159, -1.3, 4.55, -0.4, building);
box(0.22, 1.1, 0.22, 0x526f70, 1.7, 4.65, 0.8, building);
function makeTree(x, z, scale = 1) {
const tree = groupAt(x, 1.32, z);
tree.scale.setScalar(scale);
box(0.42, 2.2, 0.42, 0x77543d, 0, 1.1, 0, tree);
box(2.1, 1.35, 1.9, 0x50795d, 0, 2.55, 0, tree);
box(1.45, 1.15, 1.5, 0x628c65, -0.45, 3.25, 0.1, tree);
box(1.35, 0.95, 1.4, 0x6e966b, 0.55, 3.2, -0.12, tree);
}
makeTree(15.3, 6.7, 1.05);
makeTree(21.8, 8.6, 1.2);
makeTree(25.2, -11.3, 0.95);
makeTree(16.3, -12.6, 1.15);
// Small shoreline crates and bollards.
for (let i = 0; i < 4; i++) {
box(
0.8,
0.8,
0.8,
i % 2 ? 0xb88b58 : 0xceaa6f,
13.7 + i * 0.88,
1.72,
2.35
);
}
for (const z of [-3.1, 3.1]) {
box(0.32, 0.85, 0.32, 0x405b5c, 12.75, 1.72, z);
box(0.5, 0.25, 0.5, 0x405b5c, 12.75, 2.2, z);
}
// ------------------------------------------------------------
// Shared narrow landing
// ------------------------------------------------------------
const dock = groupAt(0, 0, 0);
for (let i = 0; i < 14; i++) {
box(
0.55,
0.25,
2.4,
i % 2 ? 0xb58b60 : 0xc69a6d,
4.3 + i * 0.55,
0.76,
0,
dock
);
}
// Support posts.
for (const x of [4.7, 6.7, 8.8, 11.0]) {
for (const z of [-0.88, 0.88]) {
box(0.24, 1.25, 0.24, 0x725947, x, 0.23, z, dock);
box(0.34, 0.18, 0.34, 0x5c493d, x, 0.83, z, dock);
}
}
// Low edge curbs make the one-boat width obvious.
box(7.8, 0.13, 0.16, 0x87694e, 7.8, 0.94, -1.12, dock);
box(7.8, 0.13, 0.16, 0x87694e, 7.8, 0.94, 1.12, dock);
// Signal mast.
box(0.18, 3.1, 0.18, 0x3f5558, 4.1, 1.65, -1.38, dock);
box(0.58, 1.5, 0.5, 0x33484d, 4.1, 3.15, -1.38, dock);
const redMaterial = new THREE.MeshStandardMaterial({
color: 0x793b36,
emissive: 0x000000,
roughness: 0.5
});
const amberMaterial = new THREE.MeshStandardMaterial({
color: 0x806b38,
emissive: 0x000000,
roughness: 0.5
});
const greenMaterial = new THREE.MeshStandardMaterial({
color: 0x285f49,
emissive: 0x000000,
roughness: 0.5
});
function signalBulb(material, y) {
const bulb = new THREE.Mesh(
new THREE.BoxGeometry(0.3, 0.3, 0.12),
material
);
bulb.position.set(4.1, y, -1.1);
bulb.castShadow = true;
dock.add(bulb);
return bulb;
}
signalBulb(redMaterial, 3.62);
signalBulb(amberMaterial, 3.18);
signalBulb(greenMaterial, 2.74);
// A little "1" sign beside the berth.
box(0.18, 1.4, 0.18, 0x455d5e, 4.45, 1.5, 1.35, dock);
box(0.72, 0.88, 0.15, 0xf3ead4, 4.45, 2.38, 1.35, dock);
box(0.12, 0.42, 0.04, 0x3a5356, 4.45, 2.39, 1.45, dock);
// Channel buoys.
for (const x of [-10.5, -5.5, -0.5, 2.8]) {
box(0.42, 0.3, 0.42, 0xf4e4b6, x, 0.2, 3.28);
box(0.22, 0.65, 0.22, 0xe56f54, x, 0.62, 3.28);
box(0.32, 0.18, 0.32, 0xf4e4b6, x, 0.94, 3.28);
}
for (const x of [-9.5, -5.5, -1.5]) {
box(0.38, 0.28, 0.38, 0xe8e2c3, x, 0.19, 0.82);
box(0.18, 0.5, 0.18, 0x4d8eb8, x, 0.55, 0.82);
}
// ------------------------------------------------------------
// Voxel people
// ------------------------------------------------------------
function makePerson(shirt, skin = 0xd9a477, scale = 1) {
const person = groupAt(0, 0, 0);
person.scale.setScalar(scale);
box(0.15, 0.34, 0.16, 0x334b54, -0.1, 0.17, 0, person);
box(0.15, 0.34, 0.16, 0x334b54, 0.1, 0.17, 0, person);
box(0.42, 0.43, 0.27, shirt, 0, 0.54, 0, person);
box(0.29, 0.29, 0.28, skin, 0, 0.9, 0, person);
box(0.31, 0.1, 0.3, 0x493a34, 0, 1.03, 0, person);
box(0.07, 0.07, 0.08, skin, 0.15, 0.9, 0, person);
person.userData.seed = Math.random() * Math.PI * 2;
return person;
}
const queuePeople = [];
const queueShirts = [0x7f6bb1, 0xe2a13f, 0x4a9b76, 0xd9695a, 0x4b83b5];
for (let i = 0; i < queuePeople.length; i++) {
const person = makePerson(queueShirts[i], 0xd9a477, 0.82);
person.position.set(5.1 + i * 0.78, 0.9, 0.18);
person.rotation.y = Math.PI;
scene.add(person);
queuePeople.push(person);
}
// A second small group waits farther back on the landing.
for (let i = 0; i < 2; i++) {
const person = makePerson(i ? 0xe79c3f : 0x546fa0, 0x8e6047, 0.78);
person.position.set(9.65 + i * 0.65, 0.9, -0.62);
person.rotation.y = Math.PI;
scene.add(person);
queuePeople.push(person);
}
// ------------------------------------------------------------
// Voxel boats
// ------------------------------------------------------------
function makeBoat(id, color, accent, waitX) {
const boat = groupAt(waitX, 0, -3.25);
boat.userData.id = id;
boat.userData.wait = new THREE.Vector3(waitX, 0, -3.25);
boat.userData.lane = new THREE.Vector3(waitX, 0, 2.08);
boat.userData.dock = new THREE.Vector3(6.8, 0, 2.08);
boat.userData.exit = new THREE.Vector3(-13.2, 0, 2.08);
boat.userData.paxGroups = [];
boat.userData.color = color;
// Layered, block-built hull.
box(4.05, 0.5, 1.62, color, 0, 0.31, 0, boat);
box(0.62, 0.45, 1.3, color, 2.0, 0.29, 0, boat);
box(0.36, 0.38, 0.92, color, 2.47, 0.25, 0, boat);
box(4.25, 0.15, 1.76, 0xead8b2, 0.03, 0.64, 0, boat);
// Bow bumper and stern.
box(0.28, 0.22, 1.15, 0x354b4f, 2.65, 0.28, 0, boat);
box(0.35, 0.42, 1.55, accent, -2.0, 0.33, 0, boat);
// Cabin and roof.
box(1.45, 1.05, 1.2, 0xf2ead5, -0.72, 1.2, 0, boat);
box(1.62, 0.18, 1.37, accent, -0.72, 1.8, 0, boat);
box(0.62, 0.37, 0.04, 0x325d69, -0.72, 1.38, 0.62, boat);
box(0.04, 0.37, 0.72, 0x325d69, -0.02, 1.38, 0, boat);
// Windows and chimney.
box(0.36, 0.38, 0.38, 0x405b60, -1.08, 2.02, -0.25, boat);
box(0.16, 0.4, 0.16, 0x3b4e50, -0.36, 2.02, 0.27, boat);
// Deck details.
box(0.7, 0.18, 0.5, 0xd7b575, 1.32, 0.8, 0.18, boat);
box(0.08, 0.48, 0.08, 0x445d60, -1.82, 1.02, -0.5, boat);
box(0.38, 0.24, 0.05, accent, -1.66, 1.22, -0.5, boat);
// Side fenders.
for (const x of [-1.35, 0.15, 1.45]) {
box(0.32, 0.28, 0.18, 0x35484c, x, 0.48, -0.86, boat);
}
// Pixel-like wake.
const wakeMaterial = new THREE.MeshBasicMaterial({
color: 0xe8ffff,
transparent: true,
opacity: 0.42,
depthWrite: false
});
for (let i = 0; i < 4; i++) {
const wake = new THREE.Mesh(
new THREE.BoxGeometry(0.55 + i * 0.24, 0.015, 0.09),
wakeMaterial
);
wake.position.set(-2.45 - i * 0.42, 0.04, (i % 2 ? 1 : -1) * 0.28);
boat.add(wake);
}
scene.add(boat);
return boat;
}
const boatA = makeBoat("A", 0xe96d58, 0xf1b84f, -7.4);
const boatB = makeBoat("B", 0x318bc3, 0xf1d06c, -2.15);
const boats = [boatA, boatB];
function removePassengers(boat) {
for (const person of boat.userData.paxGroups) {
person.removeFromParent();
}
boat.userData.paxGroups.length = 0;
}
function ensurePassengers(boat) {
removePassengers(boat);
const shirts = [0x8c6ab5, 0xe0a140, 0x4c9a77];
const xs = [0.35, 0.9, 1.42];
for (let i = 0; i < 3; i++) {
const person = makePerson(shirts[i], 0xd5a078, 0.72);
person.position.set(xs[i], 0.76, -0.3);
person.rotation.y = Math.PI / 2;
person.userData.localX = xs[i];
boat.add(person);
boat.userData.paxGroups.push(person);
}
}
ensurePassengers(boatA);
ensurePassengers(boatB);
// ------------------------------------------------------------
// DOM world labels, projected without addons
// ------------------------------------------------------------
const labelsRoot = document.querySelector("#labels");
function makeWorldLabel(text, className, anchor) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.textContent = text;
labelsRoot.appendChild(element);
return { element, anchor };
}
const labelA = makeWorldLabel(
"A · MARMALADE",
"a",
() => boatA.localToWorld(new THREE.Vector3(0, 2.7, 0))
);
const labelB = makeWorldLabel(
"B · BLUE FINCH",
"b",
() => boatB.localToWorld(new THREE.Vector3(0, 2.7, 0))
);
const landingLabel = makeWorldLabel(
"7 WAITING · SINGLE BERTH",
"landing",
() => new THREE.Vector3(7.3, 2.7, 0)
);
function updateLabels() {
const labels = [labelA, labelB, landingLabel];
for (const label of labels) {
const projected = label.anchor().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
label.element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
// ------------------------------------------------------------
// Turn-taking simulation
// ------------------------------------------------------------
const phaseOrder = ["prepare", "approach", "dock", "clear", "return"];
const cycleDuration = 26;
const simulation = {
time: 0,
turn: 0,
previousPhase: "",
running: true,
worldTime: 0
};
const walkers = [];
function selectedBoat() {
return simulation.turn === 0 ? boatA : boatB;
}
function otherBoat() {
return simulation.turn === 0 ? boatB : boatA;
}
function beginDisembark(boat) {
const boatId = boat.userData.id;
boat.userData.paxGroups.forEach((person, index) => {
const world = person.getWorldPosition(new THREE.Vector3());
scene.add(person);
person.position.copy(world);
const localX = person.userData.localX;
person.userData.walk = {
start: simulation.worldTime + index * 0.72,
duration: 3.25,
path: [
world.clone(),
new THREE.Vector3(6.8 + localX, 0.9, 1.22),
new THREE.Vector3(10.45 + index * 0.18, 0.9, 0.12),
new THREE.Vector3(11.8, 0.9, 0.05)
]
};
walkers.push(person);
});
if (boatId === "A") {
stateAText = "3 passengers disembarking";
} else {
stateBText = "3 passengers disembarking";
}
}
let stateAText = "3 passengers aboard";
let stateBText = "3 passengers aboard";
function moveSelectedBoat(phase, t) {
const boat = selectedBoat();
const wait = boat.userData.wait;
const lane = boat.userData.lane;
const dockPosition = boat.userData.dock;
const exit = boat.userData.exit;
let x = wait.x;
let z = wait.z;
let yaw = 0;
if (phase === "prepare") {
const u = smooth(t / 3);
x = lerp(wait.x, lane.x, u);
z = lerp(wait.z, lane.z, u);
yaw = -Math.atan2(lane.z - wait.z, lane.x - wait.x) * u;
} else if (phase === "approach") {
const u = smooth((t - 3) / 7);
x = lerp(lane.x, dockPosition.x, u);
z = lane.z;
} else if (phase === "dock") {
x = dockPosition.x;
z = dockPosition.z;
} else if (phase === "clear") {
const u = smooth((t - 17) / 5);
x = lerp(dockPosition.x, exit.x, u);
z = dockPosition.z;
} else if (phase === "return") {
const u = smooth((t - 22) / 4);
x = lerp(exit.x, wait.x, u);
z = lerp(exit.z, wait.z, u);
yaw = Math.atan2(exit.z - wait.z, wait.x - exit.x) * u;
}
boat.position.x = x;
boat.position.z = z;
boat.rotation.y = yaw;
}
function updateSimulation(dt) {
if (simulation.running) {
simulation.time += dt;
simulation.worldTime += dt;
}
if (simulation.time >= cycleDuration) {
simulation.time -= cycleDuration;
simulation.turn = 1 - simulation.turn;
simulation.previousPhase = "";
}
const phaseIndex = Math.min(
phaseOrder.length - 1,
Math.floor(simulation.time / (cycleDuration / phaseOrder.length))
);
const phase = phaseOrder[phaseIndex];
const phaseLength = cycleDuration / phaseOrder.length;
const phaseTime = simulation.time - phaseIndex * phaseLength;
moveSelectedBoat(phase, phaseTime);
if (phase !== simulation.previousPhase) {
if (phase === "prepare") {
ensurePassengers(selectedBoat());
if (selectedBoat() === boatA) stateAText = "Entering shared lane";
else stateBText = "Entering shared lane";
}
if (phase === "approach") {
if (selectedBoat() === boatA) stateAText = "Approaching berth";
else stateBText = "Approaching berth";
}
if (phase === "dock") {
beginDisembark(selectedBoat());
if (selectedBoat() === boatA) stateAText = "At the landing";
else stateBText = "At the landing";
}
if (phase === "clear") {
if (selectedBoat() === boatA) stateAText = "Clearing the berth";
else stateBText = "Clearing the berth";
}
simulation.previousPhase = phase;
}
const current = selectedBoat();
const waiting = otherBoat();
if (waiting === boatA) stateAText = "Waiting for clearance";
else stateBText = "Waiting for clearance";
if (current === boatA && phase === "dock") stateAText = "3 passengers disembarking";
if (current === boatB && phase === "dock") stateBText = "3 passengers disembarking";
updateSignal(phase);
updateInterface(phase, phaseTime / phaseLength);
}
function updateSignal(phase) {
redMaterial.color.setHex(0x793b36);
redMaterial.emissive.setHex(0x000000);
amberMaterial.color.setHex(0x806b38);
amberMaterial.emissive.setHex(0x000000);
greenMaterial.color.setHex(0x285f49);
greenMaterial.emissive.setHex(0x000000);
if (phase === "prepare") {
amberMaterial.color.setHex(0xe7ae42);
amberMaterial.emissive.setHex(0x6c3e05);
amberMaterial.emissiveIntensity = 0.8;
} else if (phase === "approach" || phase === "dock") {
greenMaterial.color.setHex(0x42bf79);
greenMaterial.emissive.setHex(0x168348);
greenMaterial.emissiveIntensity = 0.9;
} else {
redMaterial.color.setHex(0xe85b4b);
redMaterial.emissive.setHex(0x7d1712);
redMaterial.emissiveIntensity = 0.75;
}
}
const rowA = document.querySelector("#row-a");
const rowB = document.querySelector("#row-b");
const stateA = document.querySelector("#state-a");
const stateB = document.querySelector("#state-b");
const signalCopy = document.querySelector("#signal-copy");
const progress = document.querySelector("#progress");
function updateInterface(phase, phaseProgress) {
const aSelected = simulation.turn === 0;
rowA.classList.toggle("active", aSelected);
rowB.classList.toggle("active", !aSelected);
stateA.textContent = aSelected ? "Priority" : "Holding";
stateB.textContent = !aSelected ? "Priority" : "Holding";
document.querySelector(".boat-a .boat-detail").textContent = stateAText;
document.querySelector(".boat-b .boat-detail").textContent = stateBText;
const names = {
prepare: "Entry authorized",
approach: "Approach clear",
dock: "Landing occupied",
clear: "Exit clear",
return: "Landing vacant"
};
signalCopy.textContent = names[phase];
progress.style.width = `${Math.round(phaseProgress * 100)}%`;
const color =
phase === "dock"
? "#35a56f"
: phase === "prepare"
? "#e4a83d"
: "#ef6b57";
progress.style.background = color;
}
function updateWalkers() {
for (let i = walkers.length - 1; i >= 0; i--) {
const person = walkers[i];
const walk = person.userData.walk;
const age = simulation.worldTime - walk.start;
if (age < 0) continue;
const u = THREE.MathUtils.clamp(age / walk.duration, 0, 1);
const path = walk.path;
if (u < 0.28) {
person.position.lerpVectors(path[0], path[1], smooth(u / 0.28));
} else if (u < 0.72) {
person.position.lerpVectors(path[1], path[2], smooth((u - 0.28) / 0.44));
} else {
person.position.lerpVectors(path[2], path[3], smooth((u - 0.72) / 0.28));
}
person.rotation.y = u < 0.72 ? Math.PI : 0;
if (u >= 1) {
person.visible = false;
walkers.splice(i, 1);
}
}
}
function resetSimulation() {
simulation.time = 0;
simulation.turn = 0;
simulation.previousPhase = "";
simulation.worldTime = 0;
walkers.length = 0;
for (const boat of boats) {
boat.position.copy(boat.userData.wait);
boat.rotation.set(0, 0, 0);
ensurePassengers(boat);
}
stateAText = "3 passengers aboard";
stateBText = "3 passengers aboard";
updateSimulation(0);
}
// ------------------------------------------------------------
// Custom orbit camera controls
// ------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0.5, 0.8, 0),
theta: 2.38,
phi: 0.93,
radius: 31
};
function updateCamera() {
const horizontal = orbit.radius * Math.cos(orbit.phi);
camera.position.set(
orbit.target.x + horizontal * Math.cos(orbit.theta),
orbit.target.y + orbit.radius * Math.sin(orbit.phi),
orbit.target.z + horizontal * Math.sin(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.target.set(0.5, 0.8, 0);
orbit.theta = 2.38;
orbit.phi = 0.93;
orbit.radius = 31;
updateCamera();
}
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.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.0045,
0.42,
1.35
);
});
function stopDragging() {
dragging = false;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
17,
48
);
},
{ passive: false }
);
document.querySelector("#camera-reset").addEventListener("click", resetCamera);
document.querySelector("#restart").addEventListener("click", resetSimulation);
const pauseButton = document.querySelector("#pause");
pauseButton.addEventListener("click", () => {
simulation.running = !simulation.running;
pauseButton.textContent = simulation.running ? "Pause" : "Resume";
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
updateSimulation(dt);
updateWalkers();
for (const ripple of ripples) {
ripple.position.x += ripple.userData.speed * dt;
ripple.position.y = 0.025 + Math.sin(simulation.worldTime * 1.7 + ripple.userData.offset) * 0.008;
if (ripple.position.x > 13) {
ripple.position.x = -28;
}
}
boatA.position.y = Math.sin(simulation.worldTime * 2.1) * 0.035;
boatB.position.y = Math.sin(simulation.worldTime * 2.1 + 1.7) * 0.035;
boatA.rotation.z = Math.sin(simulation.worldTime * 1.45) * 0.012;
boatB.rotation.z = Math.sin(simulation.worldTime * 1.45 + 1.4) * 0.012;
for (const person of queuePeople) {
person.position.y = 0.9 + Math.sin(simulation.worldTime * 2 + person.userData.seed) * 0.012;
}
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
resetCamera();
resetSimulation();
animate();
</script>
</body>
</html>
```