Prompt specification
Build or customize the Three.js 3D scene "Produce boat meeting a riverside loading platform" 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: Produce boat meeting a riverside loading platform
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/produce-boat-meeting-a-riverside-loading-platform-x3090
Scene Description Prompt:
Create a standalone cutaway scene in one HTML file using Three.js from cdnjs. Create a compact Mekong Delta vignette with produce baskets, boat, and platform. Animate transfer between water and land routes while maintaining space for local pedestrian access.
Working Three.js Starter (produce-boat-meeting-a-riverside-loading-platform-x3090):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mekong Delta — Water / Land Exchange</title>
<style>
:root {
--ink: #183b3d;
--muted: #557071;
--water: #2c9ca3;
--land: #d7854c;
--walk: #5d8f61;
--paper: rgba(250, 248, 238, 0.92);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e5;
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;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(24, 59, 61, 0.12);
background: var(--paper);
box-shadow: 0 14px 40px rgba(24, 59, 61, 0.13);
backdrop-filter: blur(12px);
}
.title-panel {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 19px 21px 17px;
border-radius: 16px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--water);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 39px);
font-weight: 500;
line-height: 1.02;
letter-spacing: -0.025em;
}
.subtitle {
margin: 10px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.legend {
display: grid;
gap: 8px;
}
.legend-row {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 9px;
font-size: 12px;
}
.legend-row strong {
font-size: 10px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--water);
}
.dot.land {
background: var(--land);
}
.dot.walk {
background: var(--walk);
}
.legend-row em {
color: var(--muted);
font-style: normal;
font-size: 11px;
}
.status-panel {
left: 22px;
bottom: 22px;
width: min(390px, calc(100vw - 44px));
padding: 14px 16px;
border-radius: 14px;
}
.status-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.status-title strong {
font-size: 12px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
#transferStatus {
color: var(--land);
font-size: 12px;
font-weight: 700;
text-align: right;
}
.status-line {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 12px;
}
.clear-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--walk);
box-shadow: 0 0 0 4px rgba(93, 143, 97, 0.14);
}
.controls {
right: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
align-items: center;
gap: 8px;
max-width: min(560px, calc(100vw - 44px));
padding: 10px;
border-radius: 14px;
}
button {
appearance: none;
border: 1px solid rgba(24, 59, 61, 0.16);
border-radius: 9px;
padding: 9px 12px;
background: #fffdf5;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: transform 140ms ease, background 140ms ease;
}
button:hover {
transform: translateY(-1px);
background: white;
}
button.primary {
border-color: var(--ink);
background: var(--ink);
color: white;
}
.speed {
display: flex;
align-items: center;
gap: 8px;
padding: 0 7px;
color: var(--muted);
font-size: 11px;
}
input[type="range"] {
width: 84px;
accent-color: var(--water);
}
.hint {
position: fixed;
z-index: 9;
top: 24px;
right: 24px;
padding: 9px 12px;
border-radius: 999px;
background: rgba(250, 248, 238, 0.72);
color: rgba(24, 59, 61, 0.65);
font-size: 11px;
pointer-events: none;
}
@media (max-width: 720px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
margin-bottom: 12px;
}
.legend-row em {
display: none;
}
.hint {
display: none;
}
.status-panel {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
.controls {
right: 12px;
bottom: 105px;
max-width: calc(100vw - 24px);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive cutaway of a Mekong Delta produce landing"></canvas>
<section class="panel title-panel">
<p class="eyebrow">Mekong Delta / Exchange Vignette</p>
<h1>Water meets<br>the market.</h1>
<p class="subtitle">
Produce moves from a local boat to a raised landing while a clearly marked
pedestrian route remains open along the bank.
</p>
<div class="legend">
<div class="legend-row">
<span class="dot"></span>
<strong>Water route</strong>
<em>boat arrival</em>
</div>
<div class="legend-row">
<span class="dot land"></span>
<strong>Transfer</strong>
<em>gangway to platform</em>
</div>
<div class="legend-row">
<span class="dot walk"></span>
<strong>Local access</strong>
<em>unobstructed walking lane</em>
</div>
</div>
</section>
<section class="panel status-panel" aria-live="polite">
<div class="status-title">
<strong>Live operation</strong>
<span id="transferStatus">Boat approaching landing</span>
</div>
<div class="status-line">
<span class="clear-dot"></span>
<span>Pedestrian lane clear · 1.2 m reserved</span>
</div>
</section>
<nav class="panel controls" aria-label="Scene controls">
<button id="pauseButton" class="primary">Pause</button>
<button id="resetButton">Reset</button>
<button id="overviewButton">Overview</button>
<button id="transferButton">Focus transfer</button>
<label class="speed">
Speed
<input id="speedControl" type="range" min="0.5" max="2" value="1" step="0.1">
</label>
</nav>
<div class="hint">Drag to orbit · Scroll or pinch to zoom</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,
alpha: false
});
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce8e5");
scene.fog = new THREE.Fog("#dce8e5", 25, 48);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Direct camera controls, implemented without examples or addons.
const controls = {
target: new THREE.Vector3(0, 0.35, 0),
targetGoal: new THREE.Vector3(0, 0.35, 0),
theta: 0.68,
phi: 1.03,
radius: 15.8,
radiusGoal: 15.8,
dragging: false,
pointerX: 0,
pointerY: 0
};
function updateCamera(dt, immediate = false) {
const ease = immediate ? 1 : 1 - Math.exp(-7 * dt);
controls.target.lerp(controls.targetGoal, ease);
controls.radius += (controls.radiusGoal - controls.radius) * ease;
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);
}
updateCamera(0, true);
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(controls.phi - dy * 0.005, 0.45, 1.42);
});
function endDrag(event) {
controls.dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
controls.radiusGoal = THREE.MathUtils.clamp(
controls.radiusGoal + event.deltaY * 0.012,
8.5,
23
);
}, { passive: false });
// Lighting.
scene.add(new THREE.HemisphereLight("#e8fff4", "#82634d", 2.05));
const sun = new THREE.DirectionalLight("#fff0cf", 3.4);
sun.position.set(-8, 14, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#bfe8ec", 1.25);
fill.position.set(9, 6, -8);
scene.add(fill);
const materials = {
baseDark: new THREE.MeshStandardMaterial({ color: "#5d4938", roughness: 1 }),
baseSoil: new THREE.MeshStandardMaterial({ color: "#9e7350", roughness: 1 }),
soilStripe: new THREE.MeshStandardMaterial({ color: "#c29667", roughness: 1 }),
land: new THREE.MeshStandardMaterial({ color: "#879c69", roughness: 0.95 }),
bank: new THREE.MeshStandardMaterial({ color: "#9f8060", roughness: 0.96 }),
water: new THREE.MeshStandardMaterial({
color: "#2c9ca3",
roughness: 0.3,
metalness: 0.02,
transparent: true,
opacity: 0.84
}),
waterEdge: new THREE.MeshStandardMaterial({
color: "#57b9b9",
roughness: 0.35,
transparent: true,
opacity: 0.4
}),
wood: new THREE.MeshStandardMaterial({ color: "#9b6842", roughness: 0.86 }),
woodLight: new THREE.MeshStandardMaterial({ color: "#bf8b59", roughness: 0.82 }),
woodDark: new THREE.MeshStandardMaterial({ color: "#6e4933", roughness: 0.9 }),
bamboo: new THREE.MeshStandardMaterial({ color: "#c6a25f", roughness: 0.78 }),
thatch: new THREE.MeshStandardMaterial({ color: "#bd8b42", roughness: 1 }),
leaf: new THREE.MeshStandardMaterial({ color: "#3d7d52", roughness: 0.9 }),
leafLight: new THREE.MeshStandardMaterial({ color: "#6fa467", roughness: 0.9 }),
stone: new THREE.MeshStandardMaterial({ color: "#a9a18b", roughness: 1 }),
path: new THREE.MeshStandardMaterial({ color: "#d8c49b", roughness: 1 }),
pathEdge: new THREE.MeshStandardMaterial({ color: "#eee0bc", roughness: 1 }),
basket: new THREE.MeshStandardMaterial({ color: "#b88143", roughness: 0.92 }),
basketDark: new THREE.MeshStandardMaterial({ color: "#8a5d35", roughness: 0.95 }),
rope: new THREE.MeshStandardMaterial({ color: "#d7c39c", roughness: 0.9 }),
orange: new THREE.MeshStandardMaterial({ color: "#e98235", roughness: 0.72 }),
green: new THREE.MeshStandardMaterial({ color: "#74a947", roughness: 0.78 }),
red: new THREE.MeshStandardMaterial({ color: "#c64c3c", roughness: 0.76 }),
yellow: new THREE.MeshStandardMaterial({ color: "#e5bb45", roughness: 0.78 }),
shirtBlue: new THREE.MeshStandardMaterial({ color: "#315f6d", roughness: 0.82 }),
shirtRed: new THREE.MeshStandardMaterial({ color: "#a74d40", roughness: 0.82 }),
skin: new THREE.MeshStandardMaterial({ color: "#bd8158", roughness: 0.82 }),
hat: new THREE.MeshStandardMaterial({ color: "#d7b76e", roughness: 0.9 }),
black: new THREE.MeshStandardMaterial({ color: "#263a3b", roughness: 0.8 })
};
function box(w, h, d, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, segments, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(radius, material, x, y, z, parent = scene, detail = 10) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, detail, Math.max(6, detail - 2)),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function torus(radius, tube, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tube, 6, 16),
material
);
mesh.rotation.x = Math.PI / 2;
mesh.position.set(x, y, z);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function group(x = 0, y = 0, z = 0, parent = scene) {
const g = new THREE.Group();
g.position.set(x, y, z);
parent.add(g);
return g;
}
function smooth01(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
// Ground and cutaway foundation.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(200, 200),
new THREE.MeshStandardMaterial({ color: "#d5dfd9", roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.69;
ground.receiveShadow = true;
scene.add(ground);
box(12.25, 0.34, 8.25, materials.baseDark, 0, -0.47, 0);
box(12.08, 0.28, 8.08, materials.baseSoil, 0, -0.21, 0);
box(6.78, 0.72, 8.02, materials.bank, -2.65, 0.18, 0);
box(6.78, 0.12, 8.02, materials.land, -2.65, 0.62, 0);
box(6.79, 0.08, 8.03, materials.soilStripe, -2.65, 0.02, 0);
// River volume and exposed front section.
box(5.30, 0.31, 7.98, materials.water, 3.35, -0.005, 0);
box(5.30, 0.035, 8.01, materials.waterEdge, 3.35, 0.145, 0);
// Bank retaining edge.
box(0.18, 0.58, 8.0, materials.bank, 0.69, 0.28, 0);
box(0.23, 0.09, 8.03, materials.stone, 0.69, 0.57, 0);
// Water flow marks.
const flowMaterial = new THREE.MeshBasicMaterial({
color: "#c4eeee",
transparent: true,
opacity: 0.27,
depthWrite: false
});
const flowMarks = [];
for (let i = 0; i < 23; i++) {
const mark = new THREE.Mesh(
new THREE.PlaneGeometry(0.35 + (i % 4) * 0.13, 0.025),
flowMaterial
);
mark.rotation.x = -Math.PI / 2;
mark.position.set(
1.0 + ((i * 0.71) % 4.7),
0.174,
-3.8 + ((i * 1.27) % 7.6)
);
scene.add(mark);
flowMarks.push({
mesh: mark,
speed: 0.11 + (i % 5) * 0.025,
offset: (i * 0.43) % 1
});
}
// Raised produce platform.
const platform = group(-2.42, 0, -1.37);
const platformTop = 0.98;
for (let i = 0; i < 14; i++) {
box(
0.225,
0.10,
2.12,
i % 2 ? materials.woodLight : materials.wood,
-1.62 + i * 0.247,
0.93,
0,
platform
);
}
for (const x of [-1.52, -0.52, 0.48, 1.48]) {
for (const z of [-0.9, 0.9]) {
cylinder(0.065, 0.075, 0.72, 8, materials.woodDark, x, 0.30, z, platform);
}
}
box(3.45, 0.09, 0.13, materials.woodDark, 0, 0.44, -1.01, platform);
box(3.45, 0.09, 0.13, materials.woodDark, 0, 0.44, 1.01, platform);
// Steps connecting the platform to local land routes.
box(0.9, 0.10, 0.34, materials.woodLight, -4.0, 0.75, -0.16);
box(1.05, 0.10, 0.36, materials.woodLight, -4.0, 0.84, -0.52);
box(1.18, 0.10, 0.38, materials.wood, -4.0, 0.93, -0.88);
// Small thatched market canopy.
const canopy = group(-2.42, 0, -2.02);
for (const x of [-1.35, 1.35]) {
for (const z of [-0.43, 0.43]) {
cylinder(0.045, 0.055, 1.42, 8, materials.bamboo, x, 1.66, z, canopy);
}
}
const roofA = box(3.15, 0.10, 0.90, materials.thatch, 0, 2.36, -0.32, canopy);
roofA.rotation.x = 0.32;
const roofB = box(3.15, 0.10, 0.90, materials.thatch, 0, 2.36, 0.32, canopy);
roofB.rotation.x = -0.32;
box(3.24, 0.07, 0.07, materials.woodDark, 0, 2.57, 0, canopy);
// Floating landing and sloped gangway.
const dock = group(1.20, 0, -0.90);
for (const x of [-0.26, 0.26]) {
box(0.20, 0.23, 1.76, materials.woodDark, x, 0.22, 0, dock);
}
for (let i = 0; i < 7; i++) {
box(0.68, 0.08, 0.205, i % 2 ? materials.wood : materials.woodLight,
0, 0.40, -0.72 + i * 0.24, dock);
}
const gangway = group(0.04, 0.71, -0.90);
const gangwayDeck = box(1.58, 0.09, 0.73, materials.woodLight, 0, 0, 0, gangway);
gangwayDeck.rotation.z = 0.337;
for (const x of [-0.62, 0.62]) {
for (const z of [-0.34, 0.34]) {
cylinder(0.025, 0.03, 0.40, 6, materials.bamboo, x, 0.18, z, gangway);
}
}
// Visible hand rope on the landward gangway.
const ropePoints = [];
for (let i = 0; i <= 8; i++) {
const t = i / 8;
ropePoints.push(new THREE.Vector3(
-0.69 + t * 1.48,
0.99 + t * 0.53,
-0.35
));
}
const ropeCurve = new THREE.CatmullRomCurve3(ropePoints);
const ropeMesh = new THREE.Mesh(
new THREE.TubeGeometry(ropeCurve, 20, 0.014, 5, false),
materials.rope
);
scene.add(ropeMesh);
// Small transfer-direction markers.
const arrowMaterial = new THREE.MeshBasicMaterial({
color: "#f0c66f",
transparent: true,
opacity: 0.82
});
for (const x of [1.72, 2.10]) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.10, 0.27, 3),
arrowMaterial
);
arrow.rotation.z = Math.PI / 2;
arrow.position.set(x, 0.195, -0.90);
scene.add(arrow);
}
// Reserved pedestrian lane, deliberately separated from the transfer.
const pathTiles = [];
for (let i = 0; i < 10; i++) {
const tile = box(
0.48,
0.035,
0.90,
i % 3 === 0 ? materials.pathEdge : materials.path,
-4.65 + i * 0.49,
0.705,
1.78
);
pathTiles.push(tile);
}
// Path edge stones.
for (let i = 0; i < 14; i++) {
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.075 + (i % 2) * 0.015, 0),
materials.stone
);
stone.position.set(-4.9 + i * 0.35, 0.72, 1.20);
stone.scale.y = 0.65;
stone.castShadow = true;
scene.add(stone);
}
// A few simple walking arrows in the clear lane.
const walkArrowMaterial = new THREE.MeshBasicMaterial({
color: "#668f5d",
transparent: true,
opacity: 0.65
});
for (const x of [-3.8, -2.0, -0.55]) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.085, 0.25, 3),
walkArrowMaterial
);
arrow.rotation.z = -Math.PI / 2;
arrow.position.set(x, 0.736, 1.78);
scene.add(arrow);
}
// Procedural woven basket with produce.
function makeBasket(produceColors = ["orange", "green", "red"]) {
const g = group();
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.21, 0.36, 12, 1, true),
materials.basket
);
body.position.y = 0.18;
body.castShadow = true;
body.receiveShadow = true;
g.add(body);
cylinder(0.205, 0.205, 0.025, 12, materials.basketDark, 0, 0.015, 0, g);
torus(0.267, 0.018, materials.basketDark, 0, 0.355, 0, g);
torus(0.238, 0.013, materials.basketDark, 0, 0.11, 0, g);
for (let i = 0; i < 10; i++) {
const angle = (i / 10) * Math.PI * 2;
const strip = box(
0.018,
0.30,
0.018,
materials.basketDark,
Math.sin(angle) * 0.242,
0.18,
Math.cos(angle) * 0.242,
g
);
strip.rotation.y = angle;
}
const positions = [
[-0.10, 0.35, 0.02],
[0.08, 0.35, 0.06],
[0.00, 0.38, -0.11],
[-0.04, 0.34, 0.14]
];
positions.forEach((position, index) => {
const material = materials[produceColors[index % produceColors.length]];
const fruit = sphere(0.085, material, ...position, g, 9);
fruit.scale.y = 0.85;
});
return g;
}
// Static baskets under the canopy.
const staticBaskets = [
[-3.55, 0.99, -1.70, ["red", "yellow", "orange"]],
[-3.18, 0.99, -1.84, ["green", "orange", "yellow"]],
[-2.84, 0.99, -1.66, ["orange", "red", "green"]],
[-3.43, 1.36, -1.75, ["yellow", "orange", "red"]]
];
for (const [x, y, z, colors] of staticBaskets) {
const basket = makeBasket(colors);
basket.position.set(x, y, z);
basket.scale.setScalar(0.84);
}
// Small produce crates.
box(0.72, 0.38, 0.60, materials.woodDark, -1.58, 1.15, -1.85);
for (let i = 0; i < 3; i++) {
const fruit = sphere(0.10, i === 1 ? materials.red : materials.orange,
-1.78 + i * 0.20, 1.39, -1.82);
fruit.scale.y = 0.82;
}
// Boat hull.
const boat = group(2.55, 0.16, 2.40);
const hullShape = new THREE.Shape();
hullShape.moveTo(-0.52, 1.22);
hullShape.lineTo(0.52, 1.22);
hullShape.lineTo(0.52, -1.02);
hullShape.lineTo(0, -1.72);
hullShape.lineTo(-0.52, -1.02);
hullShape.closePath();
const hullGeometry = new THREE.ExtrudeGeometry(hullShape, {
depth: 0.38,
bevelEnabled: true,
bevelSegments: 1,
steps: 1,
bevelSize: 0.045,
bevelThickness: 0.035
});
hullGeometry.rotateX(Math.PI / 2);
const hull = new THREE.Mesh(hullGeometry, materials.woodDark);
hull.position.y = 0.22;
hull.castShadow = true;
hull.receiveShadow = true;
boat.add(hull);
box(0.73, 0.055, 1.78, materials.wood, 0, 0.255, 0.05, boat);
box(0.90, 0.09, 0.18, materials.woodLight, 0, 0.43, 0.55, boat);
box(0.78, 0.08, 0.15, materials.woodLight, 0, 0.42, -0.72, boat);
// Gunwales.
for (const x of [-0.47, 0.47]) {
const rail = box(0.08, 0.10, 2.02, materials.wood, x, 0.47, 0.05, boat);
rail.rotation.x = -0.015;
}
// Stern motor.
box(0.27, 0.48, 0.30, materials.black, 0, 0.39, 1.15, boat);
cylinder(0.035, 0.035, 0.52, 8, materials.black, 0, 0.07, 1.30, boat);
// Boat canopy supports, leaving the cargo visible.
for (const x of [-0.38, 0.38]) {
cylinder(0.025, 0.03, 0.73, 6, materials.bamboo, x, 0.78, 0.45, boat);
}
box(0.92, 0.055, 0.62, materials.thatch, 0, 1.14, 0.46, boat);
// People.
function makePerson({
scale = 1,
shirt = materials.shirtBlue,
hat = false,
skin = materials.skin
} = {}) {
const g = group();
const torso = cylinder(0.19, 0.23, 0.55, 8, shirt, 0, 0.88, 0, g);
torso.scale.z = 0.74;
sphere(0.145, skin, 0, 1.28, 0, g, 10);
const legs = [];
for (const x of [-0.105, 0.105]) {
const pivot = group(x, 0.61, 0, g);
cylinder(0.068, 0.06, 0.52, 7, materials.black, 0, -0.25, 0, pivot);
box(0.14, 0.075, 0.25, materials.black, 0, -0.53, 0.045, pivot);
legs.push(pivot);
}
const arms = [];
for (const x of [-0.255, 0.255]) {
const pivot = group(x, 1.05, 0, g);
cylinder(0.052, 0.045, 0.44, 7, skin, 0, -0.21, 0, pivot);
arms.push(pivot);
}
if (hat) {
const cone = new THREE.Mesh(
new THREE.ConeGeometry(0.29, 0.23, 12),
materials.hat
);
cone.position.y = 1.47;
cone.castShadow = true;
g.add(cone);
}
g.scale.setScalar(scale);
return { group: g, legs, arms };
}
const adult = makePerson({ shirt: materials.shirtBlue });
adult.group.position.set(-3.2, 0.725, 1.56);
const child = makePerson({
scale: 0.70,
shirt: materials.shirtRed
});
child.group.position.set(-1.2, 0.725, 2.01);
const receiver = makePerson({
shirt: materials.shirtRed,
hat: true
});
receiver.group.position.set(-0.86, 0.99, -1.28);
receiver.group.rotation.y = Math.PI / 2;
// Stilt house on the far bank.
const house = group(-4.83, 0, -2.53);
for (const x of [-0.72, 0.72]) {
for (const z of [-0.52, 0.52]) {
cylinder(0.055, 0.065, 0.78, 7, materials.woodDark, x, 0.35, z, house);
}
}
box(1.75, 0.12, 1.35, materials.wood, 0, 0.77, 0, house);
box(1.50, 0.85, 1.08, materials.woodLight, 0, 1.25, 0, house);
box(1.75, 0.09, 1.35, materials.woodDark, 0, 1.73, 0, house);
const houseRoof = new THREE.Mesh(
new THREE.ConeGeometry(1.24, 0.66, 4),
materials.thatch
);
houseRoof.rotation.y = Math.PI / 4;
houseRoof.position.y = 2.07;
houseRoof.castShadow = true;
house.add(houseRoof);
box(0.38, 0.58, 0.03, materials.woodDark, 0.28, 1.21, 0.555, house);
box(0.40, 0.35, 0.03, materials.black, -0.42, 1.33, 0.557, house);
// Palm trees.
function makePalm(x, z, scale = 1) {
const g = group(x, 0.68, z);
g.scale.setScalar(scale);
const trunk = cylinder(0.09, 0.14, 2.15, 7, materials.woodDark, 0, 1.07, 0, g);
trunk.rotation.z = -0.07;
const crown = group(-0.15, 2.15, 0, g);
for (let i = 0; i < 7; i++) {
const frond = group(0, 0, 0, crown);
frond.rotation.y = (i / 7) * Math.PI * 2;
const leaf = box(
0.07,
0.045,
1.12,
i % 2 ? materials.leaf : materials.leafLight,
0,
-0.04,
0.53,
frond
);
leaf.rotation.x = -0.18;
const tip = box(
0.05,
0.035,
0.65,
i % 2 ? materials.leaf : materials.leafLight,
0,
-0.20,
1.23,
frond
);
tip.rotation.x = -0.48;
}
sphere(0.13, materials.bamboo, -0.15, 2.17, 0, g, 8);
return g;
}
makePalm(-5.30, 2.82, 0.95);
makePalm(-5.48, -3.20, 0.80);
makePalm(5.55, -3.12, 0.78);
// Low vegetation clusters.
function makeBush(x, z, scale = 1) {
const g = group(x, 0.68, z);
g.scale.setScalar(scale);
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const leaf = sphere(
0.18 + (i % 2) * 0.04,
i % 2 ? materials.leaf : materials.leafLight,
Math.sin(angle) * 0.18,
0.12 + (i % 2) * 0.05,
Math.cos(angle) * 0.18,
g,
7
);
leaf.scale.y = 0.75;
}
return g;
}
makeBush(-5.50, 0.85, 1.05);
makeBush(-5.40, 3.35, 0.85);
makeBush(5.60, 2.65, 0.85);
makeBush(-0.35, -3.45, 0.72);
// Floating buoys.
for (const [x, z] of [[5.25, 1.75], [4.95, -2.35]]) {
const buoy = group(x, 0.24, z);
const float = sphere(0.14, materials.shirtRed, 0, 0, 0, buoy, 9);
float.scale.y = 1.25;
cylinder(0.025, 0.025, 0.35, 6, materials.woodDark, 0, 0.21, 0, buoy);
box(0.18, 0.11, 0.025, materials.pathEdge, 0, 0.40, 0, buoy);
}
// Canvas-textured signs.
function makeSign(text, width, height, x, y, z, parent = scene) {
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 256;
const context = signCanvas.getContext("2d");
context.fillStyle = "#f3e8c8";
context.fillRect(0, 0, 1024, 256);
context.strokeStyle = "#87663f";
context.lineWidth = 18;
context.strokeRect(18, 18, 988, 220);
context.fillStyle = "#244a4b";
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "700 72px sans-serif";
context.fillText(text, 512, 135);
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(renderer.capabilities.getMaxAnisotropy(), 8);
const g = group(x, y, z, parent);
box(width, height, 0.08, materials.woodDark, 0, 0, 0, g);
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(width * 0.96, height * 0.88),
new THREE.MeshStandardMaterial({ map: texture, roughness: 0.9 })
);
plane.position.z = 0.046;
g.add(plane);
return g;
}
const produceSign = makeSign("PRODUCE LANDING", 2.35, 0.56, -2.42, 1.78, -0.28);
cylinder(0.04, 0.05, 0.85, 7, materials.bamboo, -3.30, 1.33, -0.28);
cylinder(0.04, 0.05, 0.85, 7, materials.bamboo, -1.54, 1.33, -0.28);
const clearSign = makeSign("KEEP LANE CLEAR", 1.75, 0.43, -0.45, 1.38, 1.25);
cylinder(0.035, 0.045, 0.75, 7, materials.bamboo, -0.45, 1.02, 1.25);
// Transfer baskets and their routes.
const transferBaskets = [];
const basketColors = [
["orange", "yellow", "green"],
["red", "orange", "yellow"],
["green", "red", "orange"]
];
for (let i = 0; i < 3; i++) {
const basket = makeBasket(basketColors[i]);
basket.scale.setScalar(0.82);
scene.add(basket);
const localZ = 0.43 - i * 0.43;
const dockZ = -0.90 + localZ;
const destination = new THREE.Vector3(
-1.15 - i * 0.48,
0.99,
-0.55 + (i % 2) * 0.23
);
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(1.20, 0.45, dockZ),
new THREE.Vector3(0.42, 0.62, dockZ),
new THREE.Vector3(-0.50, 0.96, dockZ),
destination
]);
transferBaskets.push({
basket,
localZ,
dockZ,
destination,
curve,
start: 0.40 + i * 0.07,
duration: 0.19
});
}
// UI state.
let playing = true;
let simTime = 0;
let speed = 1;
let lastFrame = performance.now();
const pauseButton = document.querySelector("#pauseButton");
const resetButton = document.querySelector("#resetButton");
const speedControl = document.querySelector("#speedControl");
const transferStatus = document.querySelector("#transferStatus");
pauseButton.addEventListener("click", () => {
playing = !playing;
pauseButton.textContent = playing ? "Pause" : "Play";
pauseButton.classList.toggle("primary", playing);
});
resetButton.addEventListener("click", () => {
simTime = 0;
});
speedControl.addEventListener("input", () => {
speed = Number(speedControl.value);
});
document.querySelector("#overviewButton").addEventListener("click", () => {
controls.targetGoal.set(0, 0.35, 0);
controls.radiusGoal = 15.8;
controls.theta = 0.68;
controls.phi = 1.03;
});
document.querySelector("#transferButton").addEventListener("click", () => {
controls.targetGoal.set(-0.30, 0.58, -0.62);
controls.radiusGoal = 10.7;
controls.theta = 0.80;
controls.phi = 1.10;
});
// Animation.
function updateScene(dt) {
const cycle = (simTime / 10) % 1;
let boatZ;
if (cycle < 0.38) {
boatZ = THREE.MathUtils.lerp(2.40, -0.90, smooth01(cycle / 0.38));
} else if (cycle < 0.78) {
boatZ = -0.90;
} else {
boatZ = THREE.MathUtils.lerp(-0.90, 2.40, smooth01((cycle - 0.78) / 0.22));
}
const bob = Math.sin(simTime * 1.65) * 0.018;
boat.position.z = boatZ;
boat.position.y = 0.16 + bob;
boat.rotation.x = Math.sin(simTime * 1.18) * 0.009;
boat.rotation.z = Math.sin(simTime * 0.91 + 0.4) * 0.007;
for (const item of transferBaskets) {
const q = (cycle - item.start) / item.duration;
const origin = new THREE.Vector3(
boat.position.x - 0.03,
boat.position.y + 0.25,
boat.position.z + item.localZ
);
let position;
if (q < 0) {
position = origin;
} else if (q >= 1) {
position = item.destination.clone();
} else if (q < 0.46) {
const dockPoint = new THREE.Vector3(1.20, 0.45, item.dockZ);
const midpoint = origin.clone().lerp(dockPoint, 0.5);
midpoint.y += 0.54;
const arc = new THREE.QuadraticBezierCurve3(origin, midpoint, dockPoint);
position = arc.getPoint(q / 0.46);
} else {
position = item.curve.getPoint((q - 0.46) / 0.54);
}
item.basket.position.copy(position);
const previous = item.basket.position.clone();
item.basket.rotation.z = Math.sin(simTime * 5 + item.localZ) * 0.025;
item.basket.rotation.x = Math.cos(simTime * 4.2 + item.localZ) * 0.018;
let fade = 1;
if (cycle < 0.025) {
fade = cycle / 0.025;
} else if (cycle > 0.84) {
fade = Math.max(0, (0.93 - cycle) / 0.09);
}
item.basket.scale.setScalar(0.82 * fade);
item.basket.visible = fade > 0.001;
if (previous.x !== item.basket.position.x) {
item.basket.rotation.z += (item.basket.position.x - previous.x) * 0.035;
}
}
// Pedestrians stay entirely on the reserved lane.
const adultProgress = (1 - Math.cos(simTime * 0.24)) * 0.5;
const childProgress = (1 - Math.cos(simTime * 0.19 + 2.2)) * 0.5;
adult.group.position.x = THREE.MathUtils.lerp(-4.55, -0.38, adultProgress);
child.group.position.x = THREE.MathUtils.lerp(-0.45, -4.35, childProgress);
const adultSwing = Math.sin(simTime * 4.1) * 0.42;
const childSwing = Math.sin(simTime * 4.8 + 0.7) * 0.48;
adult.legs[0].rotation.x = adultSwing;
adult.legs[1].rotation.x = -adultSwing;
adult.arms[0].rotation.x = -adultSwing * 0.72;
adult.arms[1].rotation.x = adultSwing * 0.72;
child.legs[0].rotation.x = childSwing;
child.legs[1].rotation.x = -childSwing;
child.arms[0].rotation.x = -childSwing * 0.7;
child.arms[1].rotation.x = childSwing * 0.7;
// Receiving worker reaches toward the gangway.
receiver.arms[0].rotation.x = -0.95 + Math.sin(simTime * 2.3) * 0.12;
receiver.arms[1].rotation.x = -0.35;
// Current streaks.
for (const flow of flowMarks) {
const z = -3.95 + ((flow.mesh.position.z + 3.95 + simTime * flow.speed) % 7.9);
flow.mesh.position.z = z;
flow.mesh.material.opacity = 0.19 + 0.08 * Math.sin(simTime + flow.offset * 9);
}
if (cycle < 0.38) {
transferStatus.textContent = "Boat approaching landing";
} else if (cycle < 0.78) {
transferStatus.textContent = "Unloading to platform";
} else {
transferStatus.textContent = "Boat returning upstream";
}
updateCamera(dt);
}
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - lastFrame) / 1000, 0.05);
lastFrame = now;
if (playing) {
simTime += dt * speed;
}
updateScene(dt);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
requestAnimationFrame(animate);
</script>
</body>
</html>
```