Prompt specification
Build or customize the Three.js 3D scene "Ferry passengers walking past market stalls" 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: Ferry passengers walking past market stalls
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ferry-passengers-walking-past-market-stalls-x2834
Scene Description Prompt:
Voxel ferry passengers browse Helsinki Market Square stalls while the boarding path remains clear. One HTML file using Three.js from cdnjs.
Working Three.js Starter (ferry-passengers-walking-past-market-stalls-x2834):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Helsinki — Market Square Ferry</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9bcfe1;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
max-width: min(390px, calc(100vw - 48px));
padding: 16px 18px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 14px;
background: rgba(17, 43, 54, 0.82);
color: white;
box-shadow: 0 12px 35px rgba(20, 45, 55, 0.2);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 5px;
color: #a8e5d7;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 3vw, 30px);
line-height: 1;
letter-spacing: -0.04em;
}
.subtitle {
margin-top: 7px;
color: rgba(255, 255, 255, 0.76);
font-size: 13px;
}
.views {
position: absolute;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid rgba(255, 255, 255, 0.48);
border-radius: 10px;
padding: 10px 13px;
background: rgba(17, 43, 54, 0.8);
color: white;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 8px 22px rgba(20, 45, 55, 0.14);
backdrop-filter: blur(10px);
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: rgba(24, 64, 76, 0.92);
}
.status {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
padding: 12px 15px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 12px;
background: rgba(239, 255, 246, 0.92);
color: #164c3b;
box-shadow: 0 10px 28px rgba(20, 45, 55, 0.16);
font-size: 12px;
font-weight: 850;
letter-spacing: 0.04em;
}
.status-dot {
width: 10px;
height: 10px;
border-radius: 2px;
background: #25a36f;
box-shadow: 0 0 0 0 rgba(37, 163, 111, 0.4);
animation: pulse 1.8s infinite;
}
.controls {
position: absolute;
left: 24px;
bottom: 24px;
padding: 10px 13px;
border-radius: 10px;
background: rgba(17, 43, 54, 0.72);
color: rgba(255, 255, 255, 0.84);
font-size: 11px;
backdrop-filter: blur(8px);
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #9bcfe1;
color: #173e4c;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@keyframes pulse {
70% {
box-shadow: 0 0 0 8px rgba(37, 163, 111, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(37, 163, 111, 0);
}
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
padding: 13px 14px;
}
.subtitle {
display: none;
}
.views {
top: 14px;
right: 14px;
}
button {
padding: 9px 10px;
font-size: 11px;
}
.status {
right: 14px;
bottom: 14px;
}
.controls {
left: 14px;
bottom: 14px;
max-width: calc(100vw - 205px);
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Helsinki · Finland</div>
<h1>Market Square Ferry</h1>
<div class="subtitle">Voxel passengers browse the stalls while the quay route stays open.</div>
</section>
<nav class="views" aria-label="Camera views">
<button id="square-view" type="button">Market</button>
<button id="ferry-view" type="button">Ferry</button>
</nav>
<div class="controls">Drag to orbit · Wheel to zoom · Right-drag to pan</div>
<div class="status">
<span class="status-dot"></span>
BOARDING PATH CLEAR
</div>
</div>
<div id="loading" class="loading">Building Helsinki…</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 loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9bcfe1);
scene.fog = new THREE.Fog(0x9bcfe1, 38, 88);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
140
);
const hemisphere = new THREE.HemisphereLight(0xc9edff, 0x8c775f, 2.25);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xfff0cf, 3.2);
sunlight.position.set(-13, 24, 15);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -31;
sunlight.shadow.camera.right = 31;
sunlight.shadow.camera.top = 31;
sunlight.shadow.camera.bottom = -31;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 72;
sunlight.shadow.bias = -0.00035;
sunlight.shadow.normalBias = 0.025;
scene.add(sunlight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
function material(color, roughness = 0.82, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
function box(parent, w, h, d, x, y, z, mat, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const M = {
navy: material(0x164c68),
darkNavy: material(0x10384b),
white: material(0xf5f2df),
cream: material(0xffefd0),
red: material(0xc7443e),
green: material(0x287b65),
paleGreen: material(0xa9d2a3),
stone: material(0xc7c2b1),
lightStone: material(0xe1dac7),
darkStone: material(0x7b827f),
roof: material(0x507568),
roofDark: material(0x365b55),
wood: material(0x95633d),
darkWood: material(0x5a3c29),
metal: material(0x778991, 0.42, 0.35),
darkMetal: material(0x344850, 0.48, 0.4),
window: new THREE.MeshStandardMaterial({
color: 0x91d5e6,
roughness: 0.2,
metalness: 0.1,
emissive: 0x173d47,
emissiveIntensity: 0.45
}),
path: material(0x91afb0),
pathEdge: material(0xf3c44e),
rope: material(0x59463a),
orange: material(0xe87938),
yellow: material(0xf4c74d),
black: material(0x20272a)
};
const tileMaterials = [
material(0xc9c2ae),
material(0xd2cbb8),
material(0xbfbba9),
material(0xd8cfb8),
material(0xc7c3b4)
];
let seed = 1834;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function makeSign(text, subtitle, width, height, bg = "#174d5c", fg = "#fff4d8") {
const signCanvas = document.createElement("canvas");
signCanvas.width = 768;
signCanvas.height = 192;
const ctx = signCanvas.getContext("2d");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, signCanvas.width, signCanvas.height);
ctx.strokeStyle = fg;
ctx.lineWidth = 8;
ctx.strokeRect(10, 10, signCanvas.width - 20, signCanvas.height - 20);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = fg;
ctx.font = "900 62px monospace";
ctx.fillText(text, 384, subtitle ? 75 : 98);
if (subtitle) {
ctx.globalAlpha = 0.78;
ctx.font = "700 25px monospace";
ctx.fillText(subtitle, 384, 137);
}
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
})
);
}
// Water and harbor ground.
const water = new THREE.Mesh(
new THREE.PlaneGeometry(110, 110),
new THREE.MeshStandardMaterial({
color: 0x4d9fba,
roughness: 0.42,
metalness: 0.08
})
);
water.rotation.x = -Math.PI / 2;
water.position.set(0, -0.78, -28);
water.receiveShadow = true;
scene.add(water);
box(scene, 32, 1.1, 24, 0, -0.55, 4.5, M.stone);
box(scene, 32.25, 0.22, 0.62, 0, -0.18, -7.55, M.darkStone);
for (let x = -15; x <= 15; x += 2) {
for (let z = -6.5; z <= 15; z += 2) {
const tile = tileMaterials[Math.floor(random() * tileMaterials.length)];
box(scene, 1.93, 0.08, 1.93, x, 0.015, z, tile, false);
}
}
// Reserved boarding route: every pedestrian remains to the left of it.
box(scene, 3.25, 0.14, 22.5, 8, 0.11, 3, M.path, false);
box(scene, 0.12, 0.04, 22.3, 6.47, 0.2, 3, M.pathEdge, false);
box(scene, 0.12, 0.04, 22.3, 9.53, 0.2, 3, M.pathEdge, false);
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xffd45b,
emissive: 0x8e5b08,
emissiveIntensity: 0.18,
roughness: 0.7
});
function addArrow(z) {
box(scene, 0.22, 0.045, 0.85, 8, 0.215, z + 0.16, arrowMaterial, false);
box(scene, 0.52, 0.045, 0.24, 8, 0.215, z - 0.34, arrowMaterial, false);
box(scene, 0.28, 0.045, 0.24, 8, 0.215, z - 0.2, arrowMaterial, false);
}
[12, 8, 4, 0, -4].forEach(addArrow);
for (const z of [11, 6, 1, -4]) {
for (const x of [6.13, 9.87]) {
box(scene, 0.22, 0.95, 0.22, x, 0.62, z, M.darkMetal);
box(scene, 0.34, 0.12, 0.34, x, 1.13, z, M.yellow);
}
}
for (const [x, z, length] of [
[6.13, 8.5, 4.7],
[6.13, 3.5, 4.7],
[6.13, -1.5, 4.7],
[9.87, 8.5, 4.7],
[9.87, 3.5, 4.7],
[9.87, -1.5, 4.7]
]) {
box(scene, 0.07, 0.07, length, x, 0.87, z, M.rope);
}
// Quay sign beside, not inside, the boarding route.
const quaySign = makeSign("ALUSTA", "FERRY BOARDING", 2.7, 0.78, "#1c5960", "#ffe59a");
quaySign.position.set(11.35, 2.35, 10.5);
scene.add(quaySign);
box(scene, 0.18, 2.05, 0.18, 11.35, 1.18, 10.42, M.darkMetal);
// Market stalls.
const stalls = [];
function addProduce(group, type, accent) {
const crateMaterial = material(0x70462f);
const productColors = {
berries: [0xba3f50, 0xd75b49, 0x74354d],
fish: [0xb9d2d4, 0x8daeb4, 0xd7e2dc],
bread: [0xd89c4d, 0xb96b35, 0xe5b56d],
coffee: [0x5f3827, 0x7c4b31, 0x3e2923],
flowers: [0xef6e83, 0xf3cf51, 0x8c72c5],
greens: [0x4d925d, 0x74b56c, 0x2f754f]
};
const colors = productColors[type] || productColors.greens;
for (let crate = -1; crate <= 1; crate++) {
const x = crate * 1.28;
box(group, 1.08, 0.28, 0.92, x, 1.18, 0.45, crateMaterial);
for (let a = 0; a < 3; a++) {
for (let b = 0; b < 2; b++) {
const color = colors[(a + b + crate + 5) % colors.length];
const productMaterial = material(color, 0.66);
const product = box(
group,
type === "flowers" ? 0.15 : 0.2,
type === "flowers" ? 0.19 : 0.18,
type === "flowers" ? 0.15 : 0.2,
x - 0.3 + a * 0.3,
1.42,
0.27 + b * 0.28,
productMaterial
);
if (type === "flowers") {
box(group, 0.045, 0.28, 0.045, product.position.x, 1.33, product.position.z, M.green);
}
}
}
}
box(group, 1.35, 0.1, 0.12, 0, 1.08, 1.0, accent);
}
function createStall(name, subtitle, x, z, roofColor, type) {
const group = new THREE.Group();
group.position.set(x, 0.06, z);
scene.add(group);
const canopyMaterial = material(roofColor);
const creamMaterial = material(0xf2e7ca);
box(group, 4.65, 0.12, 3.45, 0, 0.05, 0, M.darkWood);
for (const px of [-2.02, 2.02]) {
for (const pz of [-1.4, 1.4]) {
box(group, 0.13, 2.75, 0.13, px, 1.48, pz, M.wood);
}
}
box(group, 4.1, 0.82, 1.55, 0, 0.56, 0.42, roofColor);
box(group, 4.35, 0.15, 1.75, 0, 1.02, 0.42, M.lightStone);
for (let i = 0; i < 8; i++) {
const stripeX = -2.0125 + i * 0.575;
const stripeMaterial = i % 2 === 0 ? canopyMaterial : creamMaterial;
box(group, 0.575, 0.16, 3.55, stripeX, 3.0, 0, stripeMaterial);
box(group, 0.575, 0.38, 0.12, stripeX, 2.78, 1.72, stripeMaterial);
}
const sign = makeSign(
name,
subtitle,
3.45,
0.67,
name === "K-MARKET" ? "#17654f" : "#8c342f",
"#fff1cf"
);
sign.position.set(0, 2.43, 1.8);
group.add(sign);
addProduce(group, type, canopyMaterial);
// Crates and a folded table beside the counter.
box(group, 0.72, 0.48, 0.72, -2.45, 0.32, -0.25, M.wood);
box(group, 0.72, 0.48, 0.72, -2.45, 0.8, -0.25, M.wood);
box(group, 0.62, 0.38, 0.62, 2.45, 0.27, 0.8, M.darkWood);
const stall = { name, x, z, group, type };
stalls.push(stall);
return stall;
}
createStall("K-MARKET", "PAIKALLISIA TUOTTEITA", -10, -2.8, 0x24785f, "greens");
createStall("KALA", "TUOREITA LOKOJA", -5, -2.8, 0x477a9b, "fish");
createStall("LEIPÄ", "TÄYTETTÄ LEIPÄÄ", 0, -2.8, 0xb66a38, "bread");
createStall("KAHVI", "HELSINGIN KAHVI", -10, 2.0, 0x8b4038, "coffee");
createStall("PUHDAS", "LAPSIEN KIRPPIS", -5, 2.0, 0x6a5f9a, "berries");
createStall("KUKAT", "KESÄKUKAT", 0, 2.0, 0xb84d67, "flowers");
// Voxel Helsinki Cathedral in the distance.
const cathedral = new THREE.Group();
cathedral.position.set(-13.4, 0, -6.1);
scene.add(cathedral);
box(cathedral, 6.3, 0.45, 8.0, 0, 0.18, -0.4, M.darkStone);
box(cathedral, 5.15, 3.05, 6.5, 0, 1.8, -0.7, M.lightStone);
for (let i = 0; i < 6; i++) {
box(
cathedral,
5.35 - i * 0.66,
0.32,
6.7 - i * 0.72,
0,
3.48 + i * 0.3,
-0.7,
i % 2 === 0 ? M.roof : M.roofDark
);
}
for (const x of [-2.15, 2.15]) {
box(cathedral, 1.35, 4.7, 1.45, x, 2.65, 2.35, M.lightStone);
box(cathedral, 1.6, 0.35, 1.65, x, 5.08, 2.35, M.darkStone);
for (let i = 0; i < 4; i++) {
box(
cathedral,
1.38 - i * 0.25,
0.34,
1.48 - i * 0.25,
x,
5.42 + i * 0.29,
2.35,
i % 2 === 0 ? M.roof : M.roofDark
);
}
}
box(cathedral, 2.45, 4.35, 2.45, 0, 2.47, -0.2, M.lightStone);
box(cathedral, 2.8, 0.38, 2.8, 0, 4.77, -0.2, M.darkStone);
for (let i = 0; i < 5; i++) {
box(
cathedral,
2.5 - i * 0.39,
0.32,
2.5 - i * 0.39,
0,
5.15 + i * 0.28,
-0.2,
i % 2 === 0 ? M.roof : M.roofDark
);
}
for (let i = 0; i < 6; i++) {
box(cathedral, 0.26, 1.9, 0.26, -1.8 + i * 0.72, 1.18, 2.72, M.stone);
}
for (let i = 0; i < 4; i++) {
box(cathedral, 4.4 - i * 0.35, 0.22, 0.75, 0, 0.17 + i * 0.2, 3.6, M.lightStone);
}
// Ferry.
const ferry = new THREE.Group();
ferry.position.set(8, 0, -13.4);
scene.add(ferry);
box(ferry, 5.55, 1.35, 10.6, 0, 0.42, 0, M.darkNavy);
box(ferry, 5.92, 0.45, 10.85, 0, 1.22, 0, M.white);
box(ferry, 5.2, 0.42, 10.25, 0, 1.55, 0, M.navy);
for (let i = 0; i < 3; i++) {
const width = 5.55 - i * 1.45;
const depth = 1.1 - i * 0.22;
box(ferry, width, 0.75, depth, 0, 0.33 + i * 0.27, -5.05 - i * 0.5, M.darkNavy);
}
box(ferry, 4.35, 1.85, 7.6, 0, 2.53, 0.7, M.white);
box(ferry, 4.58, 0.2, 7.85, 0, 3.52, 0.7, M.navy);
box(ferry, 3.55, 0.9, 2.8, 0, 4.05, -1.3, M.white);
box(ferry, 3.78, 0.18, 3.05, 0, 4.57, -1.3, M.navy);
for (const x of [-2.2, 2.2]) {
for (const z of [-2.35, -0.78, 0.79, 2.36, 3.9]) {
box(ferry, 0.055, 0.64, 0.86, x, 2.68, z, M.window, false);
}
}
for (let i = 0; i < 5; i++) {
box(ferry, 0.72, 0.62, 0.055, -1.45 + i * 0.725, 2.69, -3.13, M.window, false);
}
for (const x of [-1.9, 1.9]) {
box(ferry, 0.08, 0.72, 0.08, x, 3.9, -1.3, M.darkMetal);
}
box(ferry, 0.85, 1.65, 0.85, 0, 5.18, -1.55, M.red);
box(ferry, 0.95, 0.22, 0.95, 0, 6.04, -1.55, M.darkNavy);
box(ferry, 0.13, 4.15, 0.13, 0, 5.72, -0.15, M.darkMetal);
box(ferry, 1.8, 1.05, 0.045, 1.0, 6.72, -0.15, M.white);
box(ferry, 0.22, 1.03, 0.06, 0.8, 6.72, -0.12, M.window);
box(ferry, 1.78, 0.22, 0.06, 0.8, 6.72, -0.1, M.window);
box(ferry, 1.45, 0.4, 0.62, -2.85, 2.55, 0.9, M.orange);
box(ferry, 0.18, 0.2, 1.1, -2.85, 3.25, 0.9, M.darkMetal);
const ferrySign = makeSign("CITY FERRY", "HELSINKI", 3.35, 0.72, "#164c68", "#ffe8ad");
ferrySign.position.set(0, 2.78, 4.53);
ferry.add(ferrySign);
box(scene, 3.15, 0.16, 1.25, 8, 0.23, -8.35, M.darkMetal);
box(scene, 2.8, 0.08, 1.1, 8, 0.34, -8.4, M.path);
// Trees, lamps, and market furniture.
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
group.scale.setScalar(scale);
scene.add(group);
box(group, 0.55, 0.65, 0.55, 0, 0.33, 0, M.darkStone);
box(group, 0.28, 1.65, 0.28, 0, 1.35, 0, M.wood);
box(group, 1.6, 1.05, 1.45, 0, 2.35, 0, M.green);
box(group, 1.05, 0.85, 1.05, -0.25, 3.08, 0.05, M.paleGreen);
box(group, 0.85, 0.72, 0.8, 0.55, 2.95, -0.25, M.green);
}
createTree(4.1, 10.3, 1.1);
createTree(-14.3, 9.5, 0.9);
createTree(13.7, 5.3, 0.8);
function createLamp(x, z) {
box(scene, 0.45, 0.24, 0.45, x, 0.23, z, M.darkMetal);
box(scene, 0.12, 3.4, 0.12, x, 1.85, z, M.darkMetal);
box(scene, 0.62, 0.18, 0.62, x, 3.58, z, M.darkMetal);
box(scene, 0.42, 0.58, 0.42, x, 3.93, z, M.yellow);
box(scene, 0.58, 0.16, 0.58, x, 4.29, z, M.darkMetal);
}
createLamp(-14, 5.7);
createLamp(-2.6, 11.1);
createLamp(11.3, 4.2);
// Simple benches.
for (const [x, z] of [[-12, 7], [2.7, 7.1]]) {
box(scene, 2.6, 0.18, 0.65, x, 0.58, z, M.wood);
box(scene, 2.6, 0.65, 0.16, x, 1.0, z - 0.28, M.wood);
box(scene, 0.18, 0.6, 0.55, x - 0.95, 0.3, z, M.darkMetal);
box(scene, 0.18, 0.6, 0.55, x + 0.95, 0.3, z, M.darkMetal);
}
// Voxel passengers.
const skinMaterials = [
material(0xe7b28e),
material(0xc88764),
material(0x8f5b43),
material(0xf0c6a3),
material(0x684536)
];
const coatMaterials = [
material(0xd95d4f),
material(0x377d91),
material(0xe4b947),
material(0x6a5c9c),
material(0x4d8b68),
material(0xe07c42),
material(0x425c76),
material(0xc95583)
];
const hairMaterials = [
material(0x2b2522),
material(0x593b29),
material(0xa66d35),
material(0xc3a277)
];
const people = [];
function createPerson(x, z, options = {}) {
const root = new THREE.Group();
root.position.set(x, 0.12, z);
root.scale.setScalar(options.scale || 1);
scene.add(root);
const skin = skinMaterials[Math.floor(random() * skinMaterials.length)];
const coat = coatMaterials[Math.floor(random() * coatMaterials.length)];
const hair = hairMaterials[Math.floor(random() * hairMaterials.length)];
const torso = box(root, 0.57, 0.73, 0.36, 0, 1.05, 0, coat);
box(root, 0.63, 0.09, 0.4, 0, 0.76, 0, M.darkMetal);
box(root, 0.22, 0.15, 0.23, 0, 1.49, 0, skin);
const head = new THREE.Group();
head.position.set(0, 1.73, 0);
root.add(head);
box(head, 0.43, 0.43, 0.42, 0, 0, 0, skin);
box(head, 0.46, 0.16, 0.44, 0, 0.18, -0.015, hair);
box(head, 0.045, 0.055, 0.025, -0.11, 0.015, 0.222, M.black, false);
box(head, 0.045, 0.055, 0.025, 0.11, 0.015, 0.222, M.black, false);
box(head, 0.1, 0.035, 0.025, 0, -0.1, 0.224, M.darkWood, false);
if (random() > 0.45) {
box(head, 0.51, 0.1, 0.48, 0, 0.25, 0, random() > 0.5 ? M.navy : coat);
box(head, 0.32, 0.23, 0.1, 0, 0.17, 0.25, random() > 0.5 ? M.navy : coat);
}
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.37, 1.34, 0);
rightArm.position.set(0.37, 1.34, 0);
root.add(leftArm, rightArm);
box(leftArm, 0.17, 0.56, 0.2, 0, -0.25, 0, coat);
box(rightArm, 0.17, 0.56, 0.2, 0, -0.25, 0, coat);
box(leftArm, 0.18, 0.17, 0.2, 0, -0.57, 0, skin);
box(rightArm, 0.18, 0.17, 0.2, 0, -0.57, 0, skin);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.16, 0.72, 0);
rightLeg.position.set(0.16, 0.72, 0);
root.add(leftLeg, rightLeg);
box(leftLeg, 0.21, 0.56, 0.24, 0, -0.27, 0, M.darkNavy);
box(rightLeg, 0.21, 0.56, 0.24, 0, -0.27, 0, M.darkNavy);
box(leftLeg, 0.24, 0.16, 0.38, 0, -0.59, 0.07, M.black);
box(rightLeg, 0.24, 0.16, 0.38, 0, -0.59, 0.07, M.black);
if (random() > 0.38) {
const bagMaterial = coatMaterials[Math.floor(random() * coatMaterials.length)];
box(root, 0.32, 0.37, 0.18, 0.48, 0.48, 0.03, bagMaterial);
box(root, 0.035, 0.32, 0.035, 0.48, 0.8, 0.03, M.rope);
} else {
box(root, 0.36, 0.26, 0.25, 0.5, 0.72, 0.03, M.wood);
}
const person = {
root,
head,
leftArm,
rightArm,
leftLeg,
rightLeg,
torso,
x,
z,
phase: random() * Math.PI * 2,
speed: 0.11 + random() * 0.05,
mode: options.mode || "browser",
target: options.target || null,
baseYaw: options.yaw || 0,
walking: options.mode === "walker"
};
people.push(person);
return person;
}
// Shoppers stand in front of stalls, never in the boarding corridor.
const browserData = [
[-10.0, -0.42, 0],
[-8.85, -0.48, 0],
[-5.15, -0.40, 1],
[-0.35, -0.43, 2],
[-10.35, 4.40, 3],
[-6.0, 4.37, 4],
[-0.05, 4.42, 5]
];
browserData.forEach(([x, z, stallIndex], index) => {
const stall = stalls[stallIndex];
const yaw = Math.atan2(stall.x - x, stall.z - z);
createPerson(x, z, {
mode: "browser",
target: stall,
yaw,
scale: 0.88 + random() * 0.16
});
});
// A few passengers stroll through the front market lane.
for (let i = 0; i < 4; i++) {
createPerson(-11 + i * 2.8, 7.15 + (i % 2) * 0.4, {
mode: "walker",
scale: 0.88 + random() * 0.18
});
}
// One family, kept well clear of the quay route.
createPerson(-7.2, 1.15, {
mode: "browser",
target: stalls[1],
yaw: Math.PI,
scale: 0.72
});
// Water highlights.
const waterHighlights = [];
const highlightMaterial = new THREE.MeshBasicMaterial({
color: 0xbbe8ec,
transparent: true,
opacity: 0.45,
depthWrite: false
});
for (let i = 0; i < 26; i++) {
const glint = box(
scene,
0.8 + random() * 1.8,
0.025,
0.08,
-22 + random() * 44,
-0.72,
-9 - random() * 28,
highlightMaterial,
false
);
glint.userData.speed = 0.08 + random() * 0.13;
glint.userData.baseX = glint.position.x;
waterHighlights.push(glint);
}
// Blocky clouds.
const clouds = [];
for (let i = 0; i < 7; i++) {
const cloud = new THREE.Group();
cloud.position.set(-30 + i * 10, 15 + random() * 5, -28 - random() * 15);
scene.add(cloud);
box(cloud, 3.8, 0.9, 1.5, 0, 0, 0, M.white, false);
box(cloud, 2.3, 1.25, 1.3, -0.9, 0.45, 0, M.white, false);
box(cloud, 2.0, 1.0, 1.25, 1.1, 0.32, 0, M.white, false);
cloud.userData.speed = 0.14 + random() * 0.12;
clouds.push(cloud);
}
// Custom camera controls implemented without external addons.
const controls = {
theta: 0.62,
phi: 0.94,
radius: 28,
goalTheta: 0.62,
goalPhi: 0.94,
goalRadius: 28,
target: new THREE.Vector3(0, 1.1, 1.5),
goalTarget: new THREE.Vector3(0, 1.1, 1.5),
dragging: false,
panning: false,
lastX: 0,
lastY: 0
};
function updateCamera(delta, immediate = false) {
const ease = immediate ? 1 : 1 - Math.exp(-delta * 10);
controls.theta += (controls.goalTheta - controls.theta) * ease;
controls.phi += (controls.goalPhi - controls.phi) * ease;
controls.radius += (controls.goalRadius - controls.radius) * ease;
controls.target.lerp(controls.goalTarget, ease);
controls.phi = THREE.MathUtils.clamp(controls.phi, 0.35, 1.38);
controls.radius = THREE.MathUtils.clamp(controls.radius, 10, 45);
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);
}
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.panning = event.button === 2 || event.shiftKey;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
if (controls.panning) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const amount = controls.radius * 0.0014;
controls.goalTarget.addScaledVector(right, -dx * amount);
controls.goalTarget.addScaledVector(forward, -dy * amount);
controls.goalTarget.x = THREE.MathUtils.clamp(controls.goalTarget.x, -12, 13);
controls.goalTarget.z = THREE.MathUtils.clamp(controls.goalTarget.z, -13, 13);
} else {
controls.goalTheta -= dx * 0.006;
controls.goalPhi -= dy * 0.005;
}
});
function endPointer(event) {
controls.dragging = false;
controls.panning = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.goalRadius *= Math.exp(event.deltaY * 0.001);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") controls.goalTheta += 0.12;
if (event.key === "ArrowRight") controls.goalTheta -= 0.12;
if (event.key === "ArrowUp") controls.goalPhi = Math.max(0.35, controls.goalPhi - 0.08);
if (event.key === "ArrowDown") controls.goalPhi = Math.min(1.38, controls.goalPhi + 0.08);
if (event.key === "+" || event.key === "=") controls.goalRadius = Math.max(10, controls.goalRadius - 2);
if (event.key === "-" || event.key === "_") controls.goalRadius = Math.min(45, controls.goalRadius + 2);
});
document.querySelector("#square-view").addEventListener("click", () => {
controls.goalTarget.set(0, 1.1, 1.5);
controls.goalRadius = 28;
controls.goalTheta = 0.62;
controls.goalPhi = 0.94;
});
document.querySelector("#ferry-view").addEventListener("click", () => {
controls.goalTarget.set(8, 1.6, -5.5);
controls.goalRadius = 22;
controls.goalTheta = 0.35;
controls.goalPhi = 1.03;
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
for (const person of people) {
if (person.mode === "walker") {
const phase = elapsed * person.speed + person.phase;
const u = 0.5 - 0.5 * Math.cos(phase);
const direction = Math.sin(phase) >= 0 ? 1 : -1;
person.root.position.x = THREE.MathUtils.lerp(-11.8, 3.5, u);
person.root.position.z = 7.15 + Math.sin(phase * 2.1) * 0.25;
person.root.rotation.y = direction * Math.PI * 0.5;
const stride = Math.sin(elapsed * 8.2 + person.phase);
person.leftLeg.rotation.x = stride * 0.58;
person.rightLeg.rotation.x = -stride * 0.58;
person.leftArm.rotation.x = -stride * 0.42;
person.rightArm.rotation.x = stride * 0.42;
person.head.rotation.y = Math.sin(elapsed * 0.8 + person.phase) * 0.08;
} else {
const browse = Math.sin(elapsed * 1.25 + person.phase);
const smallMove = Math.sin(elapsed * 0.55 + person.phase);
person.root.position.x = person.x + smallMove * 0.09;
person.root.position.z = person.z + browse * 0.055;
person.root.rotation.y = person.baseYaw + Math.sin(elapsed * 0.45 + person.phase) * 0.07;
person.leftArm.rotation.x = Math.sin(elapsed * 1.1 + person.phase) * 0.1;
person.rightArm.rotation.x = -0.82 + browse * 0.18;
person.leftLeg.rotation.x = smallMove * 0.03;
person.rightLeg.rotation.x = -smallMove * 0.03;
person.head.rotation.y = Math.sin(elapsed * 0.65 + person.phase) * 0.18;
person.head.rotation.x = Math.sin(elapsed * 0.8 + person.phase) * 0.055;
}
}
for (const glint of waterHighlights) {
glint.position.x += glint.userData.speed * delta;
if (glint.position.x > 23) glint.position.x = -23;
}
for (const cloud of clouds) {
cloud.position.x += cloud.userData.speed * delta;
if (cloud.position.x > 37) cloud.position.x = -37;
}
arrowMaterial.emissiveIntensity = 0.16 + Math.sin(elapsed * 2.2) * 0.07;
updateCamera(delta);
renderer.render(scene, camera);
}
updateCamera(0, true);
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```