Prompt specification
Build or customize the Three.js 3D scene "Boat supplies entering a Paraty 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: Boat supplies entering a Paraty street
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/boat-supplies-entering-a-paraty-street-x2686
Scene Description Prompt:
Unload a small boat onto a handcart in Paraty, separating pedestrian and cargo routes through a narrow voxel quay entrance. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (boat-supplies-entering-a-paraty-street-x2686):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Paraty Cargo Quay</title>
<style>
:root {
--ink: #18343a;
--paper: rgba(255, 250, 240, 0.92);
--pedestrian: #d97855;
--cargo: #287f88;
--accent: #f2b544;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9ed4dc;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.55);
background: var(--paper);
box-shadow: 0 14px 40px rgba(23, 58, 65, 0.15);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title {
top: 22px;
left: 22px;
max-width: 370px;
padding: 18px 20px 17px;
border-radius: 3px 18px 18px 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--cargo);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cargo);
box-shadow: 0 0 0 4px rgba(40, 127, 136, 0.13);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 39px);
font-weight: 850;
line-height: 0.98;
letter-spacing: -0.045em;
}
#title p {
margin: 11px 0 0;
max-width: 310px;
color: rgba(24, 52, 58, 0.72);
font-size: 13px;
line-height: 1.5;
}
#status {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 7px 10px;
border-radius: 7px;
background: rgba(40, 127, 136, 0.09);
color: var(--cargo);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#status::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
content: "";
animation: blink 1.4s ease-in-out infinite;
}
@keyframes blink {
50% {
opacity: 0.25;
}
}
#legend {
bottom: 22px;
left: 22px;
width: 245px;
padding: 15px 17px;
border-radius: 16px 16px 16px 3px;
}
.legend-title {
margin-bottom: 11px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 9px;
font-size: 12px;
font-weight: 700;
}
.swatch {
width: 24px;
height: 9px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.legend-note {
margin-top: 12px;
padding-top: 10px;
border-top: 1px solid rgba(24, 52, 58, 0.12);
color: rgba(24, 52, 58, 0.64);
font-size: 11px;
line-height: 1.45;
}
#controls {
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border-radius: 14px;
}
button {
border: 0;
border-radius: 9px;
padding: 10px 13px;
background: var(--ink);
color: #fffaf0;
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
cursor: pointer;
transition: transform 0.15s ease, background 0.15s ease;
}
button:hover {
background: var(--cargo);
transform: translateY(-1px);
}
button.secondary {
background: rgba(24, 52, 58, 0.09);
color: var(--ink);
}
#help {
position: fixed;
right: 23px;
bottom: 83px;
z-index: 9;
color: rgba(255, 255, 255, 0.95);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
text-align: right;
text-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #a9d7dc;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 0.45s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 680px) {
#title {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
padding: 14px 16px;
}
#title p {
display: none;
}
#status {
margin-top: 10px;
}
#legend {
bottom: 12px;
left: 12px;
width: 205px;
}
.legend-note {
display: none;
}
#controls {
right: 12px;
bottom: 12px;
}
#help {
display: none;
}
button {
padding: 10px;
}
}
</style>
</head>
<body>
<div id="loading">Building Paraty quay…</div>
<section id="title" class="panel">
<div class="eyebrow">Brazilian waterfront</div>
<h1>Paraty<br />Cargo Quay</h1>
<p>
A small fishing boat is unloading into a handcart while visitors use a
protected pedestrian lane through the narrow colonial gateway.
</p>
<div id="status">Unloading from boat</div>
</section>
<section id="legend" class="panel">
<div class="legend-title">Separated quay routes</div>
<div class="legend-row">
<span class="swatch" style="background: var(--pedestrian)"></span>
Pedestrian lane
</div>
<div class="legend-row">
<span class="swatch" style="background: var(--cargo)"></span>
Cargo and cart lane
</div>
<div class="legend-note">
The central bollard line keeps foot traffic clear of working cargo.
</div>
</section>
<div id="help">DRAG TO ORBIT · SCROLL TO ZOOM · R TO RESET</div>
<div id="controls" class="panel">
<button id="pause">Pause</button>
<button id="reset" class="secondary">Reset view</button>
</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(0xa8d9df);
scene.fog = new THREE.Fog(0xa8d9df, 18, 43);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xdaf6ff, 0x8a7656, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe1aa, 3.2);
sun.position.set(-9, 17, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 48;
sun.shadow.bias = -0.0003;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ecad4, 0.65);
fill.position.set(12, 7, -12);
scene.add(fill);
const FLOOR = 0.73;
const materials = new Map();
const geometries = new Map();
function material(color) {
if (!materials.has(color)) {
materials.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0
})
);
}
return materials.get(color);
}
function boxGeometry(w, h, d) {
const key = `${w}|${h}|${d}`;
if (!geometries.has(key)) {
geometries.set(key, new THREE.BoxGeometry(w, h, d));
}
return geometries.get(key);
}
function box(
parent,
w,
h,
d,
x,
y,
z,
color,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(boxGeometry(w, h, d), material(color));
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function beamBetween(parent, a, b, width, color) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = box(
parent,
width,
width * 0.42,
length,
(a.x + b.x) / 2,
(a.y + b.y) / 2,
(a.z + b.z) / 2,
color
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.clone().normalize()
);
return mesh;
}
function makeTextSign(text, background, foreground, width = 1.5) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 144;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "rgba(255,255,255,.25)";
ctx.lineWidth = 8;
ctx.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
ctx.fillStyle = foreground;
ctx.font = "800 48px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, width * 144 / 512),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
})
);
return mesh;
}
// ------------------------------------------------------------
// Ocean and quay
// ------------------------------------------------------------
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x238ca0,
roughness: 0.3,
metalness: 0.08,
transparent: true,
opacity: 0.96
});
const water = new THREE.Mesh(
new THREE.BoxGeometry(36, 0.24, 30),
waterMaterial
);
water.position.set(0, -0.14, 1);
water.receiveShadow = true;
scene.add(water);
// Voxel wave fragments.
const waves = [];
const waveMaterial = new THREE.MeshBasicMaterial({
color: 0xb9edf0,
transparent: true,
opacity: 0.4,
depthWrite: false
});
for (let i = 0; i < 54; i++) {
const w = 0.35 + Math.random() * 1.8;
const wave = new THREE.Mesh(
new THREE.BoxGeometry(w, 0.025, 0.055 + Math.random() * 0.07),
waveMaterial
);
wave.position.set(
-15 + Math.random() * 30,
0.015 + Math.random() * 0.025,
0.7 + Math.random() * 13
);
wave.userData.baseX = wave.position.x;
wave.userData.phase = Math.random() * Math.PI * 2;
wave.userData.speed = 0.35 + Math.random() * 0.5;
scene.add(wave);
waves.push(wave);
}
// Main raised stone quay.
box(scene, 20, 1.4, 13, 0, 0.08, -6.5, 0x7b8076);
box(scene, 19.9, 0.12, 12.9, 0, 0.76, -6.5, 0xa2a396);
// Irregular cobbles using instancing.
const cobbleData = [];
for (let row = 0; row < 15; row++) {
for (let col = 0; col < 22; col++) {
cobbleData.push({
x: -9.2 + col * 0.87 + (Math.random() - 0.5) * 0.08,
z: -0.45 - row * 0.83 - (Math.random() - 0.5) * 0.08,
tint: Math.random()
});
}
}
const cobbles = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.78, 0.075, 0.72),
new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 0.96 }),
cobbleData.length
);
const dummy = new THREE.Object3D();
const cobblePalette = [
new THREE.Color(0xaaa99a),
new THREE.Color(0xb5b09f),
new THREE.Color(0x92998f),
new THREE.Color(0xc0b6a1),
new THREE.Color(0x9ca49b)
];
cobbleData.forEach((tile, index) => {
dummy.position.set(tile.x, 0.84, tile.z);
dummy.rotation.y = (Math.random() - 0.5) * 0.08;
dummy.updateMatrix();
cobbles.setMatrixAt(index, dummy.matrix);
cobbles.setColorAt(
index,
cobblePalette[Math.floor(tile.tint * cobblePalette.length)]
);
});
cobbles.receiveShadow = true;
scene.add(cobbles);
// Two strongly differentiated lanes through the gateway.
box(scene, 1.28, 0.045, 12.7, -1.05, 0.9, -6.35, 0xc77757);
box(scene, 1.48, 0.045, 12.7, 1.05, 0.9, -6.35, 0x3c8790);
box(scene, 0.13, 0.09, 12.7, 0, 0.93, -6.35, 0xf0d19a);
// Lane edge markings.
for (let z = -0.8; z > -12.5; z -= 1.15) {
box(scene, 0.08, 0.035, 0.52, -1.67, 0.94, z, 0xf1b18e);
box(scene, 0.08, 0.035, 0.52, 1.78, 0.94, z, 0x9dd3d1);
}
// Directional floor arrows.
function floorArrow(x, z, color, cargo = false) {
box(scene, 0.08, 0.035, 0.62, x - 0.17, 0.945, z + 0.12, color);
box(scene, 0.08, 0.035, 0.62, x + 0.17, 0.945, z + 0.12, color);
box(scene, 0.08, 0.035, 0.34, x - 0.09, 0.945, z - 0.23, color);
box(scene, 0.08, 0.035, 0.34, x + 0.09, 0.945, z - 0.23, color);
if (cargo) {
box(scene, 0.42, 0.035, 0.08, x, 0.945, z - 0.45, color);
}
}
[-2.2, -5.3, -8.4].forEach((z) => floorArrow(-1.05, z, 0xffc9a9));
[-1.6, -4.7, -7.8].forEach((z) =>
floorArrow(1.05, z, 0xb5e0df, true)
);
// Central safety bollards.
for (let z = -0.7; z > -12.3; z -= 1.6) {
box(scene, 0.18, 0.58, 0.18, 0, 1.19, z, 0x304c50);
box(scene, 0.24, 0.09, 0.24, 0, 1.5, z, 0xf1b544);
}
// Quay edge and fenders.
box(scene, 19.8, 0.23, 0.25, 0, 0.57, 0.02, 0x656e68);
for (let x = -8; x <= 8; x += 2.4) {
box(scene, 0.35, 0.62, 0.32, x, 0.3, 0.16, 0x303d3e);
}
// ------------------------------------------------------------
// Colonial voxel buildings
// ------------------------------------------------------------
function addWindow(group, x, y, z, width = 0.72, height = 0.9) {
box(group, width + 0.18, height + 0.18, 0.12, x, y, z, 0xf3eee0);
box(group, width, height, 0.14, x, y, z + 0.055, 0x315f6b);
box(group, 0.045, height, 0.17, x, y, z + 0.09, 0xf1e7d4);
box(group, width, 0.045, 0.17, x, y, z + 0.09, 0xf1e7d4);
box(group, 0.17, height + 0.1, 0.14, x - width / 2 - 0.15, y, z + 0.015, 0x487e70);
box(group, 0.17, height + 0.1, 0.14, x + width / 2 + 0.15, y, z + 0.015, 0x487e70);
}
function makeBuilding(x, z, w, d, h, bodyColor, trimColor) {
const group = new THREE.Group();
group.position.set(x, FLOOR, z);
scene.add(group);
box(group, w, h, d, 0, h / 2, 0, bodyColor);
box(group, w + 0.08, 0.3, d + 0.08, 0, 0.15, 0, trimColor);
box(group, w + 0.08, 0.16, d + 0.08, 0, h - 0.08, 0, trimColor);
// Stepped terracotta roof.
for (let i = 0; i < 5; i++) {
const roofW = w + 0.55 - i * 0.48;
const roofD = d + 0.55 - i * 0.48;
box(
group,
roofW,
0.23,
roofD,
0,
h + 0.12 + i * 0.2,
0,
i % 2 === 0 ? 0xb9583f : 0xc76749
);
}
box(group, 0.62, 1.05, 0.62, w * 0.27, h + 0.85, -d * 0.18, 0x9d4f3c);
const front = d / 2 + 0.055;
// Central doorway.
box(group, 1.08, 1.9, 0.14, -w * 0.13, 0.95, front, 0xf4eddd);
box(group, 0.82, 1.68, 0.17, -w * 0.13, 0.84, front + 0.04, 0x3c665d);
box(group, 0.06, 0.08, 0.07, -w * 0.13 + 0.27, 0.87, front + 0.15, 0xe6b54d);
const floors = h > 5 ? 2 : 1;
for (let row = 0; row < floors; row++) {
const wy = 2.5 + row * 2.0;
const windowXs = w > 3.8 ? [-w * 0.31, w * 0.28] : [0];
windowXs.forEach((wx) => {
addWindow(group, wx, wy, front);
});
if (row === 1 && floors === 2) {
box(group, w * 0.65, 0.14, 0.62, 0, wy - 0.68, front + 0.24, 0xf2e8d6);
for (let rail = -2; rail <= 2; rail++) {
box(
group,
0.055,
0.45,
0.055,
rail * 0.28,
wy - 0.43,
front + 0.51,
0x365d5b
);
}
}
}
return group;
}
makeBuilding(-4.8, -2.55, 4.35, 5.05, 4.75, 0xf0e4c8, 0xc96d50);
makeBuilding(4.8, -2.55, 4.35, 5.05, 4.75, 0xe6d3ac, 0x4f8174);
makeBuilding(-7.9, -8.55, 3.45, 4.2, 5.65, 0xe8b46d, 0x376f72);
makeBuilding(-3.9, -10.8, 3.65, 4.3, 4.85, 0xf1ddbd, 0xb55e45);
makeBuilding(0.25, -12.2, 3.15, 3.7, 5.8, 0xefe9d8, 0x527b70);
makeBuilding(7.85, -9.15, 3.5, 4.3, 5.4, 0xd9d5b6, 0xbd6048);
makeBuilding(5.65, -7.15, 3.65, 4.45, 4.1, 0xb7c5b3, 0x47766f);
// Warehouse loading door.
box(scene, 1.55, 2.35, 0.16, 5.65, FLOOR + 1.18, -4.89, 0x334b4c);
for (let i = 0; i < 6; i++) {
box(scene, 1.5, 0.035, 0.19, 5.65, FLOOR + 0.35 + i * 0.34, -4.78, 0x506764);
}
// Narrow voxel gateway.
const gate = new THREE.Group();
scene.add(gate);
box(gate, 0.62, 3.55, 0.82, -2.18, FLOOR + 1.775, -0.18, 0x8c8c7d);
box(gate, 0.62, 3.55, 0.82, 2.18, FLOOR + 1.775, -0.18, 0x8c8c7d);
box(gate, 0.76, 0.32, 0.94, -2.18, FLOOR + 3.5, -0.18, 0xa6a18d);
box(gate, 0.76, 0.32, 0.94, 2.18, FLOOR + 3.5, -0.18, 0xa6a18d);
box(gate, 4.98, 0.46, 0.94, 0, FLOOR + 3.92, -0.18, 0x9c9987);
box(gate, 4.25, 0.33, 0.8, 0, FLOOR + 4.3, -0.18, 0xaba591);
box(gate, 3.45, 0.25, 0.69, 0, FLOOR + 4.59, -0.18, 0xb8af98);
const pedestrianSign = makeTextSign(
"← PEDESTRES",
"#d97855",
"#fff9e9",
1.56
);
pedestrianSign.position.set(-1.02, FLOOR + 3.1, 0.3);
gate.add(pedestrianSign);
const cargoSign = makeTextSign(
"CARGA →",
"#287f88",
"#fff9e9",
1.42
);
cargoSign.position.set(1.06, FLOOR + 3.1, 0.3);
gate.add(cargoSign);
// ------------------------------------------------------------
// Tropical plants and distant scenery
// ------------------------------------------------------------
function makePalm(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, FLOOR, z);
group.scale.setScalar(scale);
scene.add(group);
for (let i = 0; i < 7; i++) {
const segment = box(
group,
0.28,
0.75,
0.28,
Math.sin(i * 0.18) * 0.05,
0.35 + i * 0.62,
0,
i % 2 ? 0x856846 : 0x947451
);
segment.rotation.z = Math.sin(i * 0.4) * 0.03;
}
const crownY = 4.55;
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const leaf = box(
group,
0.42,
0.12,
2.25,
Math.sin(angle) * 0.75,
crownY + Math.cos(angle) * 0.1,
Math.cos(angle) * 0.75,
i % 2 ? 0x397958 : 0x4b8a5e
);
leaf.rotation.y = angle;
leaf.rotation.x = (i % 2 ? 1 : -1) * 0.2;
}
box(group, 0.55, 0.42, 0.55, 0, crownY - 0.2, 0, 0x2f684e);
}
makePalm(-8.8, -5.7, 0.9);
makePalm(8.7, -6.3, 1.0);
makePalm(-8.4, -11.3, 0.78);
makePalm(8.2, -12.3, 0.9);
// Distant stepped mountains.
box(scene, 30, 4.2, 5.5, 0, 0.5, -22, 0x5f8e84);
box(scene, 24, 3.3, 4.7, -1.5, 2.2, -21, 0x719b87);
box(scene, 17, 2.7, 4.1, -2.7, 3.7, -20.6, 0x83a18a);
box(scene, 9, 1.8, 3.4, -4.3, 5.0, -20.2, 0x9aaa8c);
box(scene, 19, 2.6, 4.5, 10.5, 1.7, -21, 0x688f83);
// ------------------------------------------------------------
// Voxel people
// ------------------------------------------------------------
function makeWorker(shirtColor = 0xe56c45, hatColor = 0xf0c45a) {
const group = new THREE.Group();
const skin = 0xb97851;
const legL = new THREE.Group();
const legR = new THREE.Group();
legL.position.set(-0.14, 0.47, 0);
legR.position.set(0.14, 0.47, 0);
group.add(legL, legR);
box(legL, 0.19, 0.47, 0.22, 0, -0.235, 0, 0x294754);
box(legR, 0.19, 0.47, 0.22, 0, -0.235, 0, 0x294754);
box(legL, 0.22, 0.13, 0.34, 0, -0.43, 0.05, 0x243238);
box(legR, 0.22, 0.13, 0.34, 0, -0.43, 0.05, 0x243238);
box(group, 0.5, 0.58, 0.34, 0, 0.77, 0, shirtColor);
box(group, 0.54, 0.1, 0.37, 0, 0.49, 0, 0xead9b6);
const armL = new THREE.Group();
const armR = new THREE.Group();
armL.position.set(-0.34, 1.0, 0);
armR.position.set(0.34, 1.0, 0);
group.add(armL, armR);
box(armL, 0.15, 0.46, 0.17, 0, -0.23, 0, shirtColor);
box(armR, 0.15, 0.46, 0.17, 0, -0.23, 0, shirtColor);
box(armL, 0.16, 0.15, 0.17, 0, -0.49, 0, skin);
box(armR, 0.16, 0.15, 0.17, 0, -0.49, 0, skin);
box(group, 0.39, 0.4, 0.38, 0, 1.25, 0, skin);
box(group, 0.48, 0.12, 0.47, 0, 1.47, 0, hatColor);
box(group, 0.55, 0.07, 0.5, 0, 1.42, 0.04, hatColor);
box(group, 0.07, 0.06, 0.08, -0.09, 1.27, 0.205, 0x263e43);
box(group, 0.07, 0.06, 0.08, 0.09, 1.27, 0.205, 0x263e43);
group.userData = { legL, legR, armL, armR };
return group;
}
function animateWorker(worker, moving, carrying = false, phase = 0) {
const { legL, legR, armL, armR } = worker.userData;
const swing = moving ? Math.sin(phase) * 0.55 : 0;
legL.rotation.x = swing;
legR.rotation.x = -swing;
if (carrying) {
armL.rotation.x = -1.08;
armR.rotation.x = -1.08;
} else if (moving) {
armL.rotation.x = -swing * 0.7;
armR.rotation.x = swing * 0.7;
} else {
armL.rotation.x = 0;
armR.rotation.x = 0;
}
}
// ------------------------------------------------------------
// Small fishing boat
// ------------------------------------------------------------
const boat = new THREE.Group();
boat.position.set(3.65, 0, 3.65);
boat.rotation.y = -0.16;
scene.add(boat);
box(boat, 1.55, 0.46, 3.05, 0, 0.24, 0, 0x215c73);
box(boat, 1.95, 0.38, 3.55, 0, 0.53, 0, 0x267b88);
box(boat, 1.57, 0.16, 2.92, 0, 0.77, 0, 0xba8b55);
box(boat, 0.16, 0.42, 3.22, -0.9, 0.89, 0.02, 0xe5d7b8);
box(boat, 0.16, 0.42, 3.22, 0.9, 0.89, 0.02, 0xe5d7b8);
box(boat, 1.6, 0.42, 0.19, 0, 0.89, 1.64, 0xe5d7b8);
box(boat, 1.25, 0.38, 0.48, 0, 0.88, -1.79, 0xe5d7b8);
box(boat, 0.75, 0.32, 0.34, 0, 0.9, -2.03, 0xe5d7b8);
box(boat, 1.55, 0.13, 0.27, 0, 0.99, 0.66, 0x744f3c);
box(boat, 1.48, 0.13, 0.26, 0, 0.99, -0.83, 0x744f3c);
// Red-painted prow and small equipment.
box(boat, 1.12, 0.22, 0.16, 0, 0.98, -1.88, 0xb84e3d);
box(boat, 0.38, 0.32, 0.43, 0.53, 0.97, 0.1, 0x3f5960);
box(boat, 0.1, 1.4, 0.1, -0.55, 1.55, 0.35, 0x735742);
box(boat, 0.55, 0.28, 0.42, -0.47, 2.19, 0.35, 0xf0d9aa);
// Mooring rope.
beamBetween(
scene,
new THREE.Vector3(3.05, 0.8, 2.55),
new THREE.Vector3(1.7, 0.92, 0.12),
0.035,
0x745744
);
// Narrow plank from the boat to the quay.
beamBetween(
scene,
new THREE.Vector3(2.93, 0.82, 2.63),
new THREE.Vector3(1.52, 0.76, 1.27),
0.72,
0xa8794d
);
// ------------------------------------------------------------
// Crates and handcart
// ------------------------------------------------------------
function makeCrate() {
const group = new THREE.Group();
box(group, 0.78, 0.58, 0.78, 0, 0, 0, 0x9b6a3f);
box(group, 0.82, 0.08, 0.12, 0, 0.2, 0.42, 0xc09057);
box(group, 0.82, 0.08, 0.12, 0, -0.2, 0.42, 0xc09057);
box(group, 0.12, 0.62, 0.82, 0.42, 0, 0, 0xc09057);
box(group, 0.12, 0.62, 0.82, -0.42, 0, 0, 0xc09057);
return group;
}
const handCrate = makeCrate();
scene.add(handCrate);
const cart = new THREE.Group();
cart.position.set(1.15, FLOOR, 0.45);
scene.add(cart);
box(cart, 1.55, 0.18, 1.85, 0, 0.72, 0, 0x8e633f);
box(cart, 1.65, 0.12, 1.95, 0, 0.82, 0, 0xa8794c);
box(cart, 1.45, 0.16, 0.12, 0, 1.01, -0.82, 0x6c503b);
box(cart, 0.13, 0.16, 1.76, -0.74, 1.0, 0, 0x6c503b);
box(cart, 0.13, 0.16, 1.76, 0.74, 1.0, 0, 0x6c503b);
// Handcart handles.
box(cart, 0.13, 0.13, 1.35, -0.58, 0.83, 1.35, 0x6c503b);
box(cart, 0.13, 0.13, 1.35, 0.58, 0.83, 1.35, 0x6c503b);
// Low-sided wooden wheels.
const wheelGeometry = new THREE.CylinderGeometry(0.41, 0.41, 0.19, 12);
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0x334246,
roughness: 0.9
});
[-0.88, 0.88].forEach((x) => {
const wheel = new THREE.Mesh(wheelGeometry, wheelMaterial);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(x, 0.43, 0.02);
wheel.castShadow = true;
wheel.receiveShadow = true;
cart.add(wheel);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.11, 0.23, 10),
material(0xbc9c67)
);
hub.rotation.z = Math.PI / 2;
hub.position.copy(wheel.position);
cart.add(hub);
});
box(cart, 1.85, 0.12, 0.14, 0, 0.45, 0, 0x455355);
const cartCrate = makeCrate();
cartCrate.position.set(0, 1.15, -0.05);
cartCrate.visible = false;
cart.add(cartCrate);
const loader = makeWorker(0xe7673e, 0xf3c75c);
scene.add(loader);
// Pedestrians use the protected terracotta lane.
const pedestrian1 = makeWorker(0x4f8585, 0xe3c9a4);
const pedestrian2 = makeWorker(0xf1d8ae, 0x8f6653);
scene.add(pedestrian1, pedestrian2);
// A small local boat farther out.
const distantBoat = new THREE.Group();
distantBoat.position.set(-7.5, 0.1, 8.2);
distantBoat.rotation.y = 0.5;
scene.add(distantBoat);
box(distantBoat, 1.15, 0.35, 2.8, 0, 0.2, 0, 0xd6a452);
box(distantBoat, 0.08, 2.3, 0.08, 0, 1.3, 0, 0x5f5347);
box(distantBoat, 0.75, 0.9, 0.04, 0.35, 1.5, 0, 0xf5eddb);
// ------------------------------------------------------------
// Animation paths
// ------------------------------------------------------------
const carryCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(3.65, 0.91, 3.04),
new THREE.Vector3(2.83, 0.86, 2.48),
new THREE.Vector3(1.9, 0.8, 1.78),
new THREE.Vector3(1.15, FLOOR, 1.17)
],
false,
"catmullrom",
0.25
);
const cartCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(1.15, FLOOR, 0.45),
new THREE.Vector3(1.15, FLOOR, -1.25),
new THREE.Vector3(1.15, FLOOR, -4.75),
new THREE.Vector3(1.55, FLOOR, -6.12),
new THREE.Vector3(4.65, FLOOR, -6.58)
],
false,
"catmullrom",
0.3
);
const tempPoint = new THREE.Vector3();
const tempTangent = new THREE.Vector3();
let simulationTime = 0;
let running = true;
function updateCargoAnimation(time) {
const phase = time % 10;
const status = document.getElementById("status");
if (phase < 1) {
// Lift the crate out of the boat.
const u = phase / 1;
const p = carryCurve.getPointAt(0, tempPoint);
loader.position.copy(p);
loader.rotation.y = Math.PI;
animateWorker(loader, false, true, 0);
handCrate.visible = true;
cartCrate.visible = false;
handCrate.position.set(p.x, 0.91 + u * 0.34, p.z - 0.1);
handCrate.rotation.y = 0.08;
status.textContent = "Unloading from boat";
} else if (phase < 4) {
// Carry the crate across the plank.
const u = (phase - 1) / 3;
const p = carryCurve.getPointAt(u, tempPoint);
const tangent = carryCurve.getTangentAt(u, tempTangent).normalize();
loader.position.copy(p);
loader.rotation.y = Math.atan2(tangent.x, tangent.z);
animateWorker(loader, true, true, time * 9);
handCrate.visible = true;
cartCrate.visible = false;
handCrate.position.set(
p.x + tangent.x * 0.47,
p.y + 1.02,
p.z + tangent.z * 0.47
);
handCrate.rotation.y = loader.rotation.y;
status.textContent = "Carrying across the plank";
} else if (phase < 5) {
// Lower the crate onto the cart.
const u = (phase - 4);
const p = carryCurve.getPointAt(1, tempPoint);
const tangent = carryCurve.getTangentAt(1, tempTangent).normalize();
loader.position.copy(p);
loader.rotation.y = Math.atan2(tangent.x, tangent.z);
animateWorker(loader, false, true, 0);
const from = new THREE.Vector3(
p.x + tangent.x * 0.47,
p.y + 1.02,
p.z + tangent.z * 0.47
);
const to = new THREE.Vector3(1.15, FLOOR + 1.15, 0.4);
handCrate.position.lerpVectors(from, to, u);
handCrate.rotation.y = loader.rotation.y;
handCrate.visible = true;
cartCrate.visible = false;
status.textContent = "Loading the handcart";
} else {
// Push the loaded cart through the cargo side of the gateway.
const u = THREE.MathUtils.clamp((phase - 5) / 4.45, 0, 1);
const p = cartCurve.getPointAt(u, tempPoint);
const tangent = cartCurve.getTangentAt(u, tempTangent).normalize();
cart.position.copy(p);
cart.rotation.y = Math.atan2(-tangent.x, -tangent.z);
loader.position.set(
p.x - tangent.x * 1.18,
FLOOR,
p.z - tangent.z * 1.18
);
loader.rotation.y = Math.atan2(tangent.x, tangent.z);
animateWorker(loader, true, false, time * 8);
handCrate.visible = false;
cartCrate.visible = true;
status.textContent = "Cargo moving through the quay";
}
}
function updatePedestrians(time) {
const specs = [
{ worker: pedestrian1, offset: 0.7, speed: 0.62, shirt: pedestrian1 },
{ worker: pedestrian2, offset: 5.2, speed: 0.52, shirt: pedestrian2 }
];
specs.forEach((spec, index) => {
const distance = (time * spec.speed + spec.offset) % 11.8;
const z = 0.25 - distance;
spec.worker.position.set(
-1.05 + (index === 0 ? -0.08 : 0.08),
FLOOR + Math.abs(Math.sin(time * 6 + index)) * 0.025,
z
);
spec.worker.rotation.y = Math.PI;
animateWorker(spec.worker, true, false, time * 8 + index * 2);
});
}
// ------------------------------------------------------------
// Direct camera controls — no external control modules
// ------------------------------------------------------------
const initialCamera = {
theta: 0.57,
phi: 1.02,
radius: 18.2,
target: new THREE.Vector3(0, 1.25, -0.65)
};
const cameraState = {
theta: initialCamera.theta,
phi: initialCamera.phi,
radius: initialCamera.radius,
target: initialCamera.target.clone()
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = initialCamera.theta;
cameraState.phi = initialCamera.phi;
cameraState.radius = initialCamera.radius;
cameraState.target.copy(initialCamera.target);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let activePointer = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointer = event.pointerId;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.4,
1.38
);
});
function stopDragging(event) {
if (event && activePointer !== null && event.pointerId !== activePointer) {
return;
}
dragging = false;
activePointer = null;
renderer.domElement.style.cursor = "grab";
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9.5,
28
);
},
{ passive: false }
);
renderer.domElement.style.cursor = "grab";
document.getElementById("reset").addEventListener("click", resetCamera);
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
running = !running;
pauseButton.textContent = running ? "Pause" : "Resume";
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetCamera();
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (running) simulationTime += delta;
boat.position.y = Math.sin(simulationTime * 1.25) * 0.055;
boat.rotation.z = Math.sin(simulationTime * 0.82) * 0.012;
distantBoat.position.y = 0.1 + Math.sin(simulationTime * 0.9 + 1.5) * 0.045;
waves.forEach((wave) => {
wave.position.x =
wave.userData.baseX +
Math.sin(simulationTime * wave.userData.speed + wave.userData.phase) *
0.12;
});
updateCargoAnimation(simulationTime);
updatePedestrians(simulationTime);
updateCamera();
renderer.render(scene, camera);
}
updateCargoAnimation(0);
updatePedestrians(0);
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
animate();
</script>
</body>
</html>
```