Prompt specification
Build or customize the Three.js 3D scene "Commuter transferring from ferry to street" 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: Commuter transferring from ferry to street
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/commuter-transferring-from-ferry-to-street-x2930
Scene Description Prompt:
Voxel commuters leave a Lagos Marina-inspired ferry landing through a waiting area toward the street, separate from service traffic. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (commuter-transferring-from-ferry-to-street-x2930):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Lagos Marina Voxel Commuters</title>
<style>
:root {
color-scheme: dark;
--ink: #ecfbff;
--muted: #a9c8d2;
--panel: rgba(6, 24, 35, 0.82);
--line: rgba(173, 228, 238, 0.22);
--accent: #42d6c7;
--service: #ffc44d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071923;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 19px;
border: 1px solid var(--line);
border-radius: 18px;
color: var(--ink);
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 29px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.chip {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 999px;
color: #d9eef2;
background: rgba(255, 255, 255, 0.035);
font-size: 11px;
font-weight: 700;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px currentColor;
}
.dot.service {
background: var(--service);
}
.controls {
position: fixed;
z-index: 20;
right: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
}
button {
min-height: 40px;
padding: 0 14px;
border: 1px solid rgba(173, 228, 238, 0.26);
border-radius: 11px;
color: var(--ink);
background: rgba(6, 24, 35, 0.86);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(12px);
}
button:hover {
border-color: var(--accent);
background: rgba(10, 43, 56, 0.94);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.hint {
position: fixed;
z-index: 10;
left: 22px;
bottom: 22px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--muted);
background: rgba(6, 24, 35, 0.7);
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(10px);
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
color: #d9f8ff;
background: #071923;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 0.45s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.hud {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
.subtitle {
margin-bottom: 10px;
}
.controls {
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
button {
padding: 0 11px;
}
}
</style>
</head>
<body>
<section class="hud">
<div class="eyebrow">Lagos · Marina Landing</div>
<h1>Passenger flow, clearly separated.</h1>
<p class="subtitle">
Voxel commuters leave the ferry, cross the sheltered waiting area,
and continue toward the street while service vehicles remain on
their dedicated lane.
</p>
<div class="legend">
<span class="chip"><span class="dot"></span>Public passengers</span>
<span class="chip"><span class="dot service"></span>Service traffic only</span>
</div>
</section>
<div class="controls">
<button id="pauseButton" type="button">Pause flow</button>
<button id="trafficButton" type="button">Hide service traffic</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<div class="hint">
Drag to orbit · Wheel to zoom · Shift/right-drag to pan · Double-click to reset
</div>
<div id="loading">Building Marina…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x8bc8d5);
scene.fog = new THREE.Fog(0x8bc8d5, 32, 68);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xd9f7ff, 0x526b61, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.3);
sun.position.set(-11, 20, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00035;
scene.add(sun);
// ------------------------------------------------------------
// Reusable voxel geometry
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function standardMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(
parent,
sx,
sy,
sz,
x,
y,
z,
color,
castShadow = true,
receiveShadow = true
) {
const material =
color && color.isMaterial ? color : standardMaterial(color);
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function textTexture(text, background = "#0b6b68", foreground = "#ffffff") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(255,255,255,0.12)";
ctx.fillRect(0, 0, canvas.width, 18);
ctx.fillRect(0, canvas.height - 18, canvas.width, 18);
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "800 74px Arial, sans-serif";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 4, 930);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function label(
parent,
text,
width,
height,
x,
y,
z,
background = "#0b6b68",
foreground = "#ffffff"
) {
const material = new THREE.MeshBasicMaterial({
map: textTexture(text, background, foreground),
side: THREE.DoubleSide,
transparent: true
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function arrow(parent, x, z, color = 0x22a99b, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.655, z);
group.scale.setScalar(scale);
const left = box(
group,
0.17,
0.025,
0.95,
-0.22,
0,
0.16,
color,
false,
true
);
left.rotation.y = -0.58;
const right = box(
group,
0.17,
0.025,
0.95,
0.22,
0,
0.16,
color,
false,
true
);
right.rotation.y = 0.58;
parent.add(group);
return group;
}
// ------------------------------------------------------------
// Water, island, streets, and separation infrastructure
// ------------------------------------------------------------
box(scene, 70, 0.28, 54, 0, -0.36, 8, 0x287f9b, false, true);
// Slightly varied water tiles create a broad voxel-like surface.
const waterTileColors = [0x2b879f, 0x2e8ca3, 0x267995];
for (let i = 0; i < 30; i++) {
const x = -25 + (i % 6) * 9.2;
const z = -7 + Math.floor(i / 6) * 9.1;
box(
scene,
8.7,
0.015,
8.5,
x,
-0.205,
z,
waterTileColors[i % waterTileColors.length],
false,
false
);
}
// Main terminal island.
box(scene, 19, 1.0, 13.4, 0, 0, -4.2, 0xc8c0ad, false, true);
box(scene, 19.25, 0.08, 13.65, 0, 0.54, -4.2, 0xe7dfcd, false, true);
// Rear street.
box(scene, 19.0, 0.06, 2.8, 0, 0.615, -8.75, 0x3d4850, false, true);
box(scene, 19.0, 0.22, 0.22, 0, 0.64, -7.22, 0xf5ead7, false, true);
box(scene, 19.0, 0.22, 0.22, 0, 0.64, -10.26, 0xf5ead7, false, true);
for (let x = -8; x <= 8; x += 2.4) {
box(scene, 1.25, 0.018, 0.08, x, 0.655, -8.75, 0xf4d976, false, true);
}
// Pedestrian forecourt and promenade.
box(scene, 5.2, 0.04, 9.0, -2.8, 0.62, -1.5, 0xd7cdb8, false, true);
box(scene, 0.17, 0.035, 9.1, -5.48, 0.655, -1.5, 0x39aa9d, false, true);
box(scene, 0.17, 0.035, 9.1, -0.12, 0.655, -1.5, 0x39aa9d, false, true);
// Street-side footway where passengers arrive.
box(scene, 18.7, 0.04, 1.12, 0, 0.62, -6.56, 0xeee3cf, false, true);
// Dedicated service lane on the east side.
box(scene, 3.3, 0.06, 9.35, 6.1, 0.615, -2.35, 0x454d51, false, true);
for (let z = -5.9; z < 1.8; z += 1.8) {
box(scene, 0.12, 0.018, 0.85, 6.1, 0.655, z, 0xf4d976, false, true);
}
// Raised divider physically separates service traffic from passengers.
box(scene, 0.44, 0.36, 8.0, 4.15, 0.73, -2.6, 0xe4d8c0, false, true);
for (const z of [-5.6, -2.8, 0.0]) {
box(scene, 0.95, 0.55, 1.15, 4.15, 0.84, z, 0x8fa48c, false, true);
box(scene, 0.72, 0.55, 0.72, 4.15, 1.27, z, 0x3e8f61, false, true);
box(scene, 0.42, 0.32, 0.43, 4.1, 1.65, z - 0.06, 0x55aa68, false, true);
}
// Safety bollards along the service-lane edge.
for (let z = -6.1; z <= 1.2; z += 1.15) {
box(scene, 0.17, 0.58, 0.17, 3.57, 0.88, z, 0xf0b947, false, true);
box(scene, 0.19, 0.10, 0.19, 3.57, 1.02, z, 0x34434a, false, true);
}
const serviceRoadLabel = label(
scene,
"SERVICE ONLY",
3.2,
0.8,
6.1,
0.67,
-4.8,
"#454d51",
"#f4d976"
);
serviceRoadLabel.rotation.x = -Math.PI / 2;
// ------------------------------------------------------------
// Dock and ferry
// ------------------------------------------------------------
const dock = new THREE.Group();
scene.add(dock);
box(dock, 4.8, 0.52, 2.25, -2.8, 0.31, 3.35, 0xb9b09e, false, true);
box(dock, 4.8, 0.08, 2.25, -2.8, 0.61, 3.35, 0xe0d7c3, false, true);
box(dock, 4.4, 0.045, 0.34, -2.8, 0.67, 2.48, 0xf3bf3d, false, true);
// Dock railings.
for (const x of [-5.12, -0.48]) {
for (let z = 2.62; z <= 4.2; z += 0.52) {
box(dock, 0.10, 0.72, 0.10, x, 0.98, z, 0x536b70, false, true);
}
box(dock, 0.09, 0.09, 1.95, x, 1.31, 3.35, 0x536b70, false, true);
}
for (const x of [-4.85, -0.75]) {
box(dock, 0.26, 0.58, 0.26, x, 0.88, 2.85, 0xf0b947, false, true);
box(dock, 0.34, 0.11, 0.34, x, 1.08, 2.85, 0x34434a, false, true);
}
const ferry = new THREE.Group();
ferry.position.set(-2.8, 0, 6.1);
scene.add(ferry);
box(ferry, 6.5, 0.76, 2.9, 0, -0.16, 0.1, 0x153e52, false, true);
box(ferry, 5.95, 0.48, 2.75, 0, 0.36, 0.16, 0xf0eee2, false, true);
box(ferry, 6.1, 0.10, 2.85, 0, 0.63, 0.12, 0xe6dfcc, false, true);
box(ferry, 5.2, 0.17, 2.45, 0, 0.10, 0.15, 0x159d9b, false, true);
// Lower, narrower bow blocks.
box(ferry, 4.6, 0.72, 0.85, 0, -0.17, -1.55, 0x153e52, false, true);
box(ferry, 4.2, 0.43, 0.72, 0, 0.34, -1.58, 0xf0eee2, false, true);
box(ferry, 4.2, 0.10, 0.72, 0, 0.61, -1.58, 0xe6dfcc, false, true);
// Cabin toward the rear of the vessel.
box(ferry, 5.35, 1.32, 1.95, 0, 1.30, 0.70, 0xf5f1df, false, true);
box(ferry, 5.55, 0.18, 2.08, 0, 2.02, 0.70, 0x198f88, false, true);
const ferryWindow = new THREE.MeshStandardMaterial({
color: 0x245d72,
roughness: 0.28,
metalness: 0.12
});
for (const x of [-2.70, 2.70]) {
for (let z = 0.0; z <= 1.42; z += 0.46) {
box(ferry, 0.06, 0.48, 0.29, x, 1.40, z, ferryWindow, false, false);
}
}
box(ferry, 4.85, 0.47, 0.06, 0, 1.43, 1.70, ferryWindow, false, false);
box(ferry, 0.08, 1.35, 0.08, 0, 2.72, 0.75, 0x3d5358, false, true);
box(ferry, 0.44, 0.20, 0.44, 0, 3.36, 0.75, 0xf0b947, false, true);
// Ferry side safety rails.
for (const x of [-3.18, 3.18]) {
for (let z = -1.25; z <= 1.25; z += 0.5) {
box(ferry, 0.07, 0.42, 0.07, x, 0.88, z, 0x486268, false, true);
}
box(ferry, 0.08, 0.07, 2.65, x, 1.06, 0, 0x486268, false, true);
}
// Landing ramp.
const ramp = box(scene, 2.4, 0.16, 1.05, -2.8, 0.59, 4.24, 0x677c7d, false, true);
ramp.rotation.x = -0.04;
// ------------------------------------------------------------
// Waiting area
// ------------------------------------------------------------
const terminal = new THREE.Group();
scene.add(terminal);
box(terminal, 6.9, 0.10, 3.65, -2.8, 0.63, 0, 0xeadfca, false, true);
box(terminal, 6.9, 0.05, 0.20, -2.8, 0.70, -1.79, 0x29a89c, false, true);
box(terminal, 6.9, 0.05, 0.20, -2.8, 0.70, 1.79, 0x29a89c, false, true);
// Columns.
for (const x of [-6.0, 0.4]) {
for (const z of [-1.42, 1.42]) {
box(terminal, 0.22, 2.42, 0.22, x, 1.89, z, 0xe4d8c0, false, true);
box(terminal, 0.42, 0.18, 0.42, x, 3.12, z, 0x167b78, false, true);
}
}
// Slatted roof keeps the passenger flow visible from above.
for (let i = 0; i < 6; i++) {
box(
terminal,
7.2,
0.18,
0.39,
-2.8,
3.17,
-1.45 + i * 0.58,
i % 2 === 0 ? 0x237f79 : 0x2c958b,
false,
true
);
}
box(terminal, 0.20, 0.24, 3.9, -6.35, 3.12, 0, 0x166c69, false, true);
box(terminal, 0.20, 0.24, 3.9, 0.75, 3.12, 0, 0x166c69, false, true);
// Main sign.
box(terminal, 5.15, 0.78, 0.18, -2.8, 2.92, 1.82, 0x0c6d69, false, true);
label(terminal, "LAGOS MARINA · FERRY", 4.95, 0.62, -2.8, 2.93, 1.925);
// Low rear wall and side panels.
box(terminal, 6.5, 1.05, 0.15, -2.8, 1.08, -1.73, 0xd7ccb7, false, true);
box(terminal, 0.15, 1.05, 3.4, 0.62, 1.08, 0, 0xd7ccb7, false, true);
box(terminal, 0.15, 1.05, 3.4, -6.22, 1.08, 0, 0xd7ccb7, false, true);
// Waiting benches.
function bench(parent, x, z, color = 0x9a6548) {
const group = new THREE.Group();
group.position.set(x, 0.69, z);
box(group, 1.65, 0.16, 0.58, 0, 0.54, 0, color, false, true);
box(group, 1.65, 0.58, 0.12, 0, 0.91, 0.25, color, false, true);
box(group, 0.16, 0.54, 0.42, -0.62, 0.27, 0, 0x53636a, false, true);
box(group, 0.16, 0.54, 0.42, 0.62, 0.27, 0, 0x53636a, false, true);
parent.add(group);
}
bench(terminal, -5.0, -0.75);
bench(terminal, -0.55, -0.75, 0x4d7772);
// Ticket kiosk.
box(terminal, 0.88, 1.38, 0.88, -0.02, 1.34, 0.48, 0x267e78, false, true);
box(terminal, 0.92, 0.38, 0.06, -0.02, 1.51, 0.94, 0x183f4a, false, true);
box(terminal, 1.04, 0.13, 1.02, -0.02, 2.08, 0.48, 0xf0b947, false, true);
label(terminal, "TICKETS", 0.78, 0.23, -0.02, 1.80, 0.935, "#267e78");
// Pedestrian direction arrows.
arrow(scene, -2.8, -4.35, 0x179b91, 1.0);
arrow(scene, -2.8, -2.6, 0x179b91, 0.86);
const streetSign = new THREE.Group();
streetSign.position.set(-6.55, 0, -5.75);
box(streetSign, 0.12, 2.05, 0.12, 0, 1.02, 0, 0x596d70, false, true);
box(streetSign, 1.52, 0.58, 0.12, 0, 2.0, 0, 0x16827c, false, true);
label(streetSign, "TO STREET ↑", 1.40, 0.42, 0, 2.0, 0.075);
scene.add(streetSign);
// ------------------------------------------------------------
// Landscaping and waterfront details
// ------------------------------------------------------------
function palm(parent, x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.58, z);
group.scale.setScalar(scale);
for (let i = 0; i < 6; i++) {
const trunk = box(
group,
0.34 - i * 0.025,
0.42,
0.34 - i * 0.025,
i * 0.035,
0.21 + i * 0.39,
0,
i % 2 ? 0x8f6847 : 0xa07951,
false,
true
);
trunk.rotation.z = -0.025;
}
const crownY = 2.56;
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const leaf = box(
group,
0.42,
0.13,
2.15,
Math.sin(angle) * 0.73,
crownY,
Math.cos(angle) * 0.73,
i % 2 ? 0x31885b : 0x3b9863,
false,
true
);
leaf.rotation.y = angle;
leaf.rotation.x = 0.13;
}
box(group, 0.42, 0.42, 0.42, 0, crownY - 0.12, 0, 0x5b7946, false, true);
parent.add(group);
}
palm(scene, -8.0, -4.7, 0.92);
palm(scene, 8.1, -4.9, 0.88);
palm(scene, -7.9, 1.0, 0.75);
palm(scene, 8.0, 0.7, 0.74);
// Waterfront railing, leaving the ferry ramp open.
for (const [x, width] of [[-7.3, 2.4], [1.25, 4.8], [7.6, 2.2]]) {
box(scene, width, 0.08, 0.08, x, 1.08, 2.35, 0x536b70, false, true);
box(scene, width, 0.07, 0.07, x, 0.81, 2.35, 0x536b70, false, true);
const count = Math.max(2, Math.floor(width / 0.75));
for (let i = 0; i <= count; i++) {
const px = x - width / 2 + (i / count) * width;
box(scene, 0.08, 0.64, 0.08, px, 0.91, 2.35, 0x536b70, false, true);
}
}
// Lamps, bins, and street furniture.
function streetLamp(x, z) {
box(scene, 0.13, 3.55, 0.13, x, 2.35, z, 0x465c63, false, true);
box(scene, 0.13, 0.13, 1.0, x, 4.03, z + 0.43, 0x465c63, false, true);
box(scene, 0.45, 0.17, 0.66, x, 3.95, z + 0.85, 0xffd98a, false, true);
}
streetLamp(-8.0, -6.5);
streetLamp(3.0, -6.5);
box(scene, 0.62, 0.82, 0.62, -7.3, 1.0, -6.3, 0x2b7d68, false, true);
box(scene, 0.70, 0.12, 0.70, -7.3, 1.45, -6.3, 0x163f3a, false, true);
// ------------------------------------------------------------
// Service traffic
// ------------------------------------------------------------
const serviceGroup = new THREE.Group();
scene.add(serviceGroup);
function makeServiceVan() {
const group = new THREE.Group();
const yellow = 0xf5b83b;
const white = 0xf4f0df;
box(group, 1.82, 1.05, 3.05, 0, 0.94, 0, yellow, false, true);
box(group, 1.66, 0.82, 1.18, 0, 1.70, -0.77, white, false, true);
box(group, 1.60, 0.48, 0.06, 0, 1.74, -1.39, 0x244d5d, false, false);
box(group, 0.05, 0.44, 0.66, -0.85, 1.73, -0.75, 0x244d5d, false, false);
box(group, 0.05, 0.44, 0.66, 0.85, 1.73, -0.75, 0x244d5d, false, false);
for (const x of [-0.96, 0.96]) {
for (const z of [-0.96, 0.96]) {
box(group, 0.20, 0.50, 0.50, x, 0.44, z, 0x253237, false, true);
}
}
box(group, 1.78, 0.12, 0.10, 0, 0.58, -1.56, 0xf4f0df, false, true);
box(group, 0.34, 0.17, 0.28, 0, 2.22, -0.75, 0xf08b32, false, true);
box(group, 1.52, 0.27, 0.04, 0, 1.13, -1.54, 0xffffff, false, false);
label(group, "SERVICE", 1.36, 0.22, 0, 1.13, -1.565, "#f5b83b", "#163f49");
group.position.set(6.1, 0.63, -2.6);
serviceGroup.add(group);
return group;
}
function makeServicePickup() {
const group = new THREE.Group();
const orange = 0xd8643f;
box(group, 1.8, 0.55, 3.2, 0, 0.78, 0, orange, false, true);
box(group, 1.68, 0.75, 1.25, 0, 1.37, -0.55, 0xe9e5d7, false, true);
box(group, 1.60, 0.42, 0.06, 0, 1.42, -1.19, 0x244d5d, false, false);
box(group, 1.72, 0.12, 1.1, 0, 1.81, 0.63, orange, false, true);
for (const x of [-0.95, 0.95]) {
for (const z of [-1.0, 1.0]) {
box(group, 0.20, 0.50, 0.50, x, 0.44, z, 0x253237, false, true);
}
}
box(group, 0.32, 0.17, 0.26, 0, 1.99, -0.55, 0xf0b947, false, true);
group.position.set(-5, 0.63, -8.75);
group.rotation.y = -Math.PI / 2;
serviceGroup.add(group);
return group;
}
const serviceVan = makeServiceVan();
const servicePickup = makeServicePickup();
// ------------------------------------------------------------
// Voxel commuters
// ------------------------------------------------------------
const shirts = [
0xee655f,
0x2777c8,
0xf2bb38,
0x35a99d,
0xf2eee0,
0x8b62bc,
0xdc774d,
0x386f62
];
const trousers = [0x263a4a, 0x3e4f61, 0x263b45, 0x68564a, 0x5e6470];
const skins = [0x6d3e29, 0x8d5737, 0xb8794e, 0xd49a6d, 0xe8b78f];
const hairs = [0x201a17, 0x35251c, 0x503526, 0x171719];
function createCommuter(index) {
const person = new THREE.Group();
const shirt = shirts[index % shirts.length];
const pants = trousers[(index * 3) % trousers.length];
const skin = skins[(index * 5) % skins.length];
const hair = hairs[(index * 7) % hairs.length];
const scale = 0.91 + ((index * 13) % 7) * 0.025;
person.scale.setScalar(scale);
// Torso.
box(person, 0.48, 0.66, 0.30, 0, 0.96, 0, shirt, false, true);
box(person, 0.50, 0.10, 0.32, 0, 0.66, 0, shirt, false, true);
// Head and face, facing toward negative Z.
box(person, 0.38, 0.38, 0.36, 0, 1.48, 0, skin, false, true);
box(person, 0.40, 0.11, 0.38, 0, 1.68, 0.005, hair, false, true);
box(person, 0.055, 0.055, 0.025, -0.08, 1.49, -0.19, 0x182027, false, false);
box(person, 0.055, 0.055, 0.025, 0.08, 1.49, -0.19, 0x182027, false, false);
// Some commuters wear a head wrap.
if (index % 7 === 0) {
box(person, 0.43, 0.16, 0.41, 0, 1.65, 0.015, 0xdc6b4f, false, true);
box(person, 0.27, 0.33, 0.11, 0.10, 1.48, 0.23, 0xdc6b4f, false, true);
}
// Legs with pivot groups for walking.
const legL = new THREE.Group();
const legR = new THREE.Group();
legL.position.set(-0.12, 0.66, 0);
legR.position.set(0.12, 0.66, 0);
person.add(legL, legR);
box(legL, 0.18, 0.57, 0.20, 0, -0.285, 0, pants, false, true);
box(legR, 0.18, 0.57, 0.20, 0, -0.285, 0, pants, false, true);
box(legL, 0.20, 0.11, 0.30, 0, -0.57, -0.045, 0x263036, false, true);
box(legR, 0.20, 0.11, 0.30, 0, -0.57, -0.045, 0x263036, false, true);
// Arms with pivot groups.
const armL = new THREE.Group();
const armR = new THREE.Group();
armL.position.set(-0.32, 1.20, 0);
armR.position.set(0.32, 1.20, 0);
person.add(armL, armR);
box(armL, 0.15, 0.49, 0.18, 0, -0.245, 0, shirt, false, true);
box(armR, 0.15, 0.49, 0.18, 0, -0.245, 0, shirt, false, true);
box(armL, 0.15, 0.14, 0.17, 0, -0.52, 0, skin, false, true);
box(armR, 0.15, 0.14, 0.17, 0, -0.52, 0, skin, false, true);
// Bags and backpacks distinguish some passengers.
if (index % 3 === 0) {
box(person, 0.39, 0.47, 0.18, 0, 1.03, 0.24, index % 2 ? 0x244c67 : 0xb5563e, false, true);
box(person, 0.25, 0.08, 0.05, 0, 1.12, 0.35, 0x25373d, false, true);
} else if (index % 5 === 0) {
box(armR, 0.31, 0.36, 0.18, 0.03, -0.59, 0, 0xd2a75c, false, true);
box(armR, 0.22, 0.06, 0.06, 0.03, -0.38, 0, 0x755a36, false, true);
}
scene.add(person);
return {
group: person,
legL,
legR,
armL,
armR,
phase: index * 1.37,
speed: 1.14 + (index % 6) * 0.075,
route: createPassengerRoute((index % 5 - 2) * 0.16 + (index % 2) * 0.04),
progress: (index / 22) * 0.94
};
}
function createPassengerRoute(offset) {
const points = [
new THREE.Vector3(-2.8 + offset, 0.59, 4.62),
new THREE.Vector3(-2.8 + offset * 0.85, 0.60, 3.28),
new THREE.Vector3(-2.8 + offset * 0.72, 0.64, 2.35),
new THREE.Vector3(-2.8 + offset * 0.58, 0.69, 0.95),
new THREE.Vector3(-2.8 + offset * 0.44, 0.64, -2.20),
new THREE.Vector3(-2.8 + offset * 0.32, 0.64, -6.38)
];
const distances = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const distance = points[i].distanceTo(points[i + 1]);
distances.push(distance);
total += distance;
}
return { points, distances, total };
}
function sampleRoute(route, progress) {
let distance = THREE.MathUtils.clamp(progress, 0, 1) * route.total;
let segment = 0;
while (
segment < route.distances.length - 1 &&
distance > route.distances[segment]
) {
distance -= route.distances[segment];
segment++;
}
const a = route.points[segment];
const b = route.points[segment + 1];
const t = distance / route.distances[segment];
const position = a.clone().lerp(b, t);
const direction = b.clone().sub(a).normalize();
// Default face direction is -Z.
const yaw = Math.atan2(-direction.x, -direction.z);
return { position, yaw };
}
const commuters = Array.from({ length: 22 }, (_, i) => createCommuter(i));
// ------------------------------------------------------------
// Marina background: boats, shoreline, and skyline
// ------------------------------------------------------------
const floatingBoats = [];
function makeBoat(x, z, color, rotation = 0, scale = 1) {
const group = new THREE.Group();
group.position.set(x, -0.05, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
box(group, 2.3, 0.55, 0.92, 0, 0.12, 0, color, false, true);
box(group, 1.65, 0.44, 0.78, 0, 0.59, 0.04, 0xf0ead8, false, true);
box(group, 0.10, 3.5, 0.10, 0, 2.1, 0.05, 0x65757a, false, true);
box(group, 0.08, 1.7, 1.10, 0.03, 2.28, 0.25, 0xf6f0dd, false, true);
scene.add(group);
floatingBoats.push({ group, phase: x * 0.2 + z * 0.1 });
}
makeBoat(6.7, 10.6, 0x1b8f91, -0.22, 0.95);
makeBoat(12.0, 12.4, 0xd9694d, 0.18, 0.78);
makeBoat(-11.3, 12.8, 0xe6b943, 0.36, 0.88);
// Far shore and low Lagos-inspired skyline.
box(scene, 42, 0.45, 2.3, 0, -0.03, 18.0, 0xc6b99b, false, true);
const skylineColors = [
0xb9c8c2,
0xe2d5bd,
0x8da9a8,
0xd9c29f,
0x91aaa3,
0xeadfc7
];
for (let i = 0; i < 18; i++) {
const x = -19 + i * 2.25;
const height = 1.3 + ((i * 7) % 5) * 0.72;
const width = 1.45 + (i % 3) * 0.28;
const depth = 1.3 + (i % 2) * 0.45;
box(
scene,
width,
height,
depth,
x,
0.22 + height / 2,
18.0,
skylineColors[i % skylineColors.length],
false,
true
);
if (i % 3 === 0) {
box(scene, width * 0.55, 0.55, depth * 0.55, x, height + 0.42, 18, 0x617f7e, false, true);
}
}
// Water glints.
const glints = [];
for (let i = 0; i < 34; i++) {
const mesh = box(
scene,
0.55 + Math.random() * 1.15,
0.025,
0.09,
-20 + Math.random() * 40,
-0.185,
-3 + Math.random() * 24,
0x9bdce0,
false,
false
);
glints.push({ mesh, speed: 0.08 + Math.random() * 0.10 });
}
// ------------------------------------------------------------
// Custom camera controls — no addon modules
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(-0.6, 1.0, -1.2),
radius: 29,
theta: 0.68,
phi: 0.83
};
const defaultCamera = {
target: controls.target.clone(),
radius: controls.radius,
theta: controls.theta,
phi: controls.phi
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.target.copy(defaultCamera.target);
controls.radius = defaultCamera.radius;
controls.theta = defaultCamera.theta;
controls.phi = defaultCamera.phi;
updateCamera();
}
updateCamera();
let drag = null;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.button === 2 || event.shiftKey
};
});
canvas.addEventListener("pointermove", (event) => {
if (!drag || drag.id !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.pan) {
const forward = camera.getWorldDirection(new THREE.Vector3());
const right = forward.clone().cross(new THREE.Vector3(0, 1, 0)).normalize();
const up = right.clone().cross(forward).normalize();
const scale = controls.radius * 0.00145;
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(up, dy * scale);
} else {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.005,
0.30,
1.35
);
}
updateCamera();
});
function endDrag(event) {
if (drag && drag.id === event.pointerId) drag = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
13,
45
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
// ------------------------------------------------------------
// UI controls and animation
// ------------------------------------------------------------
let paused = false;
let serviceVisible = true;
let simulationTime = 0;
let lastTime = performance.now();
const pauseButton = document.getElementById("pauseButton");
const trafficButton = document.getElementById("trafficButton");
const resetButton = document.getElementById("resetButton");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume flow" : "Pause flow";
});
trafficButton.addEventListener("click", () => {
serviceVisible = !serviceVisible;
serviceGroup.visible = serviceVisible;
trafficButton.textContent = serviceVisible
? "Hide service traffic"
: "Show service traffic";
});
resetButton.addEventListener("click", resetCamera);
function updateCommuters(dt, time) {
for (const person of commuters) {
person.progress += (person.speed * dt) / person.route.total;
if (person.progress >= 1) {
person.progress = 0;
person.route = createPassengerRoute(
(Math.random() - 0.5) * 0.72
);
}
const sample = sampleRoute(person.route, person.progress);
person.group.position.copy(sample.position);
person.group.rotation.y = sample.yaw;
const stride = Math.sin(time * 8.3 + person.phase) * 0.52;
person.legL.rotation.x = stride;
person.legR.rotation.x = -stride;
person.armL.rotation.x = -stride * 0.78;
person.armR.rotation.x = stride * 0.78;
person.group.position.y += Math.abs(Math.sin(time * 8.3 + person.phase)) * 0.025;
}
}
function updateServiceTraffic(time) {
// Vertical service van shuttles within its dedicated lane.
const phase = (time * 0.095) % 2;
const travel = phase <= 1 ? phase : 2 - phase;
serviceVan.position.z = THREE.MathUtils.lerp(1.25, -6.55, travel);
serviceVan.rotation.y = phase <= 1 ? 0 : Math.PI;
// Separate service pickup travels along the rear street.
servicePickup.position.x = -8.6 + ((time * 1.55) % 17.2);
}
function animate(now) {
const dt = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (!paused) {
simulationTime += dt;
updateCommuters(dt, simulationTime);
updateServiceTraffic(simulationTime);
}
// Gentle ferry motion.
ferry.position.y = Math.sin(simulationTime * 0.82) * 0.025;
ferry.rotation.z = Math.sin(simulationTime * 0.56) * 0.003;
// Bobbing marina boats.
for (const boat of floatingBoats) {
boat.group.position.y = -0.05 + Math.sin(simulationTime * 0.75 + boat.phase) * 0.055;
boat.group.rotation.z = Math.sin(simulationTime * 0.61 + boat.phase) * 0.018;
}
// Moving water highlights.
for (const glint of glints) {
glint.mesh.position.x += glint.speed * dt;
if (glint.mesh.position.x > 21) glint.mesh.position.x = -21;
}
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));
});
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```