Prompt specification
Build or customize the Three.js 3D scene "Arched footbridge parapet and boat clearance" 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: Arched footbridge parapet and boat clearance
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/arched-footbridge-parapet-and-boat-clearance-x2389
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing urban waterways in Song-dynasty China. Build a short stylized bridge arch over a narrow canal. Place a small boat underneath and make the available vertical clearance visible with a simple marker. Stylized solid forms.
Working Three.js Starter (arched-footbridge-parapet-and-boat-clearance-x2389):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Song Dynasty Waterway</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7ccb2;
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 26px;
z-index: 2;
padding: 15px 19px 14px;
color: #3b3023;
background: rgba(244, 232, 201, 0.88);
border: 1px solid rgba(86, 67, 42, 0.38);
box-shadow: 0 7px 22px rgba(55, 43, 28, 0.15);
pointer-events: none;
}
.title-card h1 {
margin: 0 0 4px;
font-size: clamp(20px, 2.4vw, 31px);
font-weight: 500;
letter-spacing: 0.05em;
}
.title-card p {
margin: 0;
color: #776247;
font-size: 12px;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.hint {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 2;
padding: 9px 13px;
color: #544936;
background: rgba(244, 232, 201, 0.82);
border: 1px solid rgba(86, 67, 42, 0.25);
font-size: 12px;
letter-spacing: 0.04em;
pointer-events: none;
}
button {
position: fixed;
right: 22px;
top: 22px;
z-index: 3;
padding: 9px 13px;
color: #493c2b;
background: rgba(244, 232, 201, 0.9);
border: 1px solid rgba(86, 67, 42, 0.4);
font: inherit;
font-size: 12px;
cursor: pointer;
}
button:hover {
background: #f4e8c9;
}
@media (max-width: 650px) {
.title-card {
top: 14px;
left: 14px;
padding: 11px 14px;
}
.hint {
right: 12px;
bottom: 12px;
font-size: 10px;
}
button {
right: 12px;
top: 12px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Stylized Song dynasty canal with an arched stone bridge and small boat"></canvas>
<div class="title-card">
<h1>Song Waterway</h1>
<p>A canal beneath the old city bridge</p>
</div>
<button id="resetView" type="button">Reset view</button>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd7ccb2);
scene.fog = new THREE.Fog(0xd7ccb2, 28, 68);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const world = new THREE.Group();
scene.add(world);
const hemisphere = new THREE.HemisphereLight(0xfff0cf, 0x667462, 2.25);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffe2aa, 3.4);
sunlight.position.set(-12, 21, 15);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -25;
sunlight.shadow.camera.right = 25;
sunlight.shadow.camera.top = 25;
sunlight.shadow.camera.bottom = -25;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 65;
sunlight.shadow.bias = -0.0005;
scene.add(sunlight);
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
flatShading: true,
...extra
});
const mats = {
earth: material(0x9b8968),
bank: material(0xb8a783),
paving: material(0xa99b7c),
water: material(0x467f83, { roughness: 0.65, metalness: 0.05 }),
waterLight: material(0x78a8a4),
waterDark: material(0x376f75),
stone: material(0xc9b58b),
stoneLight: material(0xd6c39b),
stoneDark: material(0x9e8c68),
wood: material(0x684b34),
woodLight: material(0x8a6541),
roof: material(0x35464a),
roofEdge: material(0x253438),
plaster: material(0xd8c7a4),
plasterWarm: material(0xc9a983),
plasterPale: material(0xe1d3b3),
red: material(0xa44735),
lantern: material(0xc85a3b, { emissive: 0x3c1007, emissiveIntensity: 0.25 }),
foliage: material(0x607b4b),
foliageLight: material(0x7c9259),
foliageDark: material(0x465f3e),
bark: material(0x66503a),
cloth: material(0xb68b4f),
sack: material(0xbba675),
marker: material(0xe7653f, { emissive: 0x321007, emissiveIntensity: 0.18 })
};
function addBox(parent, w, h, d, x, y, z, mat, castShadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, radiusTop, radiusBottom, height, x, y, z, mat, segments = 10) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(parent, a, b, width, depth, mat) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(length, width, depth),
mat
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.rotation.z = Math.atan2(direction.y, direction.x);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Canal, embankments and urban ground
// ------------------------------------------------------------
addBox(world, 34, 1.2, 72, 0, -0.72, 0, mats.earth, false);
addBox(world, 7.2, 0.14, 72, 0, -0.05, 0, mats.water, false);
addBox(world, 3.25, 0.72, 72, -5.25, -0.02, 0, mats.bank, false);
addBox(world, 3.25, 0.72, 72, 5.25, -0.02, 0, mats.bank, false);
addBox(world, 0.28, 1.0, 72, -3.69, -0.18, 0, mats.stoneDark);
addBox(world, 0.28, 1.0, 72, 3.69, -0.18, 0, mats.stoneDark);
addBox(world, 2.35, 0.08, 72, -5.3, 0.38, 0, mats.paving, false);
addBox(world, 2.35, 0.08, 72, 5.3, 0.38, 0, mats.paving, false);
// Stone wall seams.
for (let z = -34; z <= 34; z += 4) {
addBox(world, 0.035, 0.95, 0.055, -3.535, -0.18, z, mats.stone, false);
addBox(world, 0.035, 0.95, 0.055, 3.535, -0.18, z, mats.stone, false);
}
// Stylized opaque water strokes.
let seed = 19;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const ripples = [];
for (let i = 0; i < 36; i++) {
const ripple = addBox(
world,
0.45 + random() * 0.95,
0.012,
0.035 + random() * 0.045,
(random() - 0.5) * 6.4,
0.026,
(random() - 0.5) * 69,
random() > 0.45 ? mats.waterLight : mats.waterDark,
false
);
ripple.rotation.y = (random() - 0.5) * 0.35;
ripples.push({ mesh: ripple, speed: 0.25 + random() * 0.55 });
}
// ------------------------------------------------------------
// Main arched stone bridge
// ------------------------------------------------------------
const bridgeShape = new THREE.Shape();
bridgeShape.moveTo(-7, 0);
bridgeShape.lineTo(-7, 4);
bridgeShape.quadraticCurveTo(0, 5.4, 7, 4);
bridgeShape.lineTo(7, 0);
bridgeShape.lineTo(3.15, 0);
bridgeShape.quadraticCurveTo(0, 4.05, -3.15, 0);
bridgeShape.closePath();
const bridgeGeometry = new THREE.ExtrudeGeometry(bridgeShape, {
depth: 4,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.06,
bevelThickness: 0.06,
curveSegments: 32
});
bridgeGeometry.translate(0, 0, -2);
const bridge = new THREE.Mesh(bridgeGeometry, mats.stone);
bridge.castShadow = true;
bridge.receiveShadow = true;
world.add(bridge);
function bridgeTopAt(x) {
const t = (x + 7) / 14;
return 4 + 2.8 * t * (1 - t);
}
function archHeightAt(x) {
const t = THREE.MathUtils.clamp((3.15 - x) / 6.3, 0, 1);
return 8.1 * t * (1 - t);
}
// Slightly darker roadway ribbon following the hump.
const roadVertices = [];
const roadIndices = [];
const roadSteps = 28;
for (let i = 0; i <= roadSteps; i++) {
const x = -6.72 + (13.44 * i) / roadSteps;
const y = bridgeTopAt(x) + 0.045;
roadVertices.push(x, y, -1.48, x, y, 1.48);
if (i < roadSteps) {
const a = i * 2;
roadIndices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
}
const roadGeometry = new THREE.BufferGeometry();
roadGeometry.setAttribute("position", new THREE.Float32BufferAttribute(roadVertices, 3));
roadGeometry.setIndex(roadIndices);
roadGeometry.computeVertexNormals();
const road = new THREE.Mesh(roadGeometry, mats.stoneDark);
road.receiveShadow = true;
world.add(road);
// Individual voussoir stones around the opening.
for (let i = 0; i < 13; i++) {
const t = 0.07 + (i / 12) * 0.86;
const x = 3.15 - 6.3 * t;
const y = 8.1 * t * (1 - t);
const slope = (8.1 * (1 - 2 * t)) / -6.3;
const angle = Math.atan(slope);
for (const side of [-1, 1]) {
const stone = addBox(
world,
0.54,
0.25,
0.085,
x,
y,
side * 2.035,
i % 2 ? mats.stoneLight : mats.stoneDark
);
stone.rotation.z = angle;
}
}
// Parapets on both edges of the bridge.
const postXs = [-6.45, -4.85, -3.25, -1.62, 0, 1.62, 3.25, 4.85, 6.45];
for (const z of [-1.82, 1.82]) {
for (const x of postXs) {
const y = bridgeTopAt(x);
addBox(world, 0.18, 0.78, 0.18, x, y + 0.41, z, mats.stoneLight);
addBox(world, 0.29, 0.11, 0.29, x, y + 0.08, z, mats.stoneDark);
}
for (let i = 0; i < postXs.length - 1; i++) {
const x1 = postXs[i];
const x2 = postXs[i + 1];
const a = new THREE.Vector3(x1, bridgeTopAt(x1) + 0.78, z);
const b = new THREE.Vector3(x2, bridgeTopAt(x2) + 0.78, z);
beamBetween(world, a, b, 0.14, 0.16, mats.stoneLight);
const c = new THREE.Vector3(x1, bridgeTopAt(x1) + 0.16, z);
const d = new THREE.Vector3(x2, bridgeTopAt(x2) + 0.16, z);
beamBetween(world, c, d, 0.1, 0.15, mats.stoneDark);
}
}
// Cross-stone paving marks on the bridge.
for (const x of [-5.4, -3.6, -1.8, 0, 1.8, 3.6, 5.4]) {
const seam = addBox(
world,
0.035,
0.018,
2.92,
x,
bridgeTopAt(x) + 0.064,
0,
mats.stone
);
seam.rotation.z = Math.atan(
(bridgeTopAt(x + 0.01) - bridgeTopAt(x - 0.01)) / 0.02
);
}
// ------------------------------------------------------------
// Small boat beneath the bridge
// ------------------------------------------------------------
const boat = new THREE.Group();
boat.position.set(-0.48, 0, -0.25);
boat.rotation.y = -0.075;
world.add(boat);
const hullShape = new THREE.Shape();
hullShape.moveTo(0, 2.18);
hullShape.lineTo(0.72, 1.18);
hullShape.lineTo(0.69, -1.35);
hullShape.lineTo(0.48, -1.82);
hullShape.lineTo(-0.48, -1.82);
hullShape.lineTo(-0.69, -1.35);
hullShape.lineTo(-0.72, 1.18);
hullShape.closePath();
const hullGeometry = new THREE.ExtrudeGeometry(hullShape, {
depth: 0.45,
bevelEnabled: true,
bevelSize: 0.07,
bevelThickness: 0.06,
bevelSegments: 1
});
hullGeometry.rotateX(Math.PI / 2);
const hull = new THREE.Mesh(hullGeometry, mats.wood);
hull.position.y = 0.25;
hull.castShadow = true;
hull.receiveShadow = true;
boat.add(hull);
addBox(boat, 1.18, 0.055, 2.82, 0, 0.275, -0.18, mats.woodLight);
// Flattened cylindrical woven canopy.
const canopyGeometry = new THREE.CylinderGeometry(0.72, 0.72, 1.42, 12, 1, false);
canopyGeometry.rotateX(Math.PI / 2);
const canopyPositions = canopyGeometry.attributes.position;
for (let i = 0; i < canopyPositions.count; i++) {
canopyPositions.setY(i, canopyPositions.getY(i) * 0.62);
}
canopyGeometry.computeVertexNormals();
const canopy = new THREE.Mesh(canopyGeometry, mats.cloth);
canopy.position.set(0, 0.71, -0.24);
canopy.castShadow = true;
canopy.receiveShadow = true;
boat.add(canopy);
for (const z of [-0.78, -0.24, 0.3]) {
const rib = new THREE.Mesh(
new THREE.TorusGeometry(0.735, 0.025, 6, 16, Math.PI),
mats.woodLight
);
rib.scale.y = 0.62;
rib.position.set(0, 0.71, z);
rib.castShadow = true;
boat.add(rib);
}
addBox(boat, 0.08, 0.08, 1.75, 0, 0.34, 1.38, mats.woodLight);
addBox(boat, 0.08, 0.95, 0.08, 0, 0.63, 1.66, mats.woodLight);
addBox(boat, 0.52, 0.46, 0.55, 0.12, 0.52, 1.5, mats.sack);
// ------------------------------------------------------------
// Vertical clearance marker
// ------------------------------------------------------------
const markerX = 1.7;
const markerZ = 1.45;
const clearance = archHeightAt(markerX);
addCylinder(
world,
0.035,
0.035,
clearance - 0.12,
markerX,
clearance * 0.5 + 0.05,
markerZ,
mats.marker,
8
);
addBox(world, 0.36, 0.055, 0.055, markerX, 0.17, markerZ, mats.marker);
addBox(world, 0.36, 0.055, 0.055, markerX, clearance - 0.08, markerZ, mats.marker);
const topArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.105, 0.2, 8),
mats.marker
);
topArrow.position.set(markerX, clearance - 0.08, markerZ);
world.add(topArrow);
const bottomArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.105, 0.2, 8),
mats.marker
);
bottomArrow.position.set(markerX, 0.2, markerZ);
bottomArrow.rotation.z = Math.PI;
world.add(bottomArrow);
function makeClearanceLabel() {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 176;
const ctx = labelCanvas.getContext("2d");
ctx.fillStyle = "#f1d26b";
ctx.fillRect(8, 8, 496, 160);
ctx.strokeStyle = "#713725";
ctx.lineWidth = 9;
ctx.strokeRect(8, 8, 496, 160);
ctx.fillStyle = "#713725";
ctx.textAlign = "center";
ctx.font = "bold 64px Georgia";
ctx.fillText(clearance.toFixed(1) + " m", 256, 82);
ctx.font = "bold 28px Georgia";
ctx.fillText("CLEARANCE", 256, 132);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(markerX + 0.87, 0.9, markerZ + 0.32);
sprite.scale.set(1.65, 0.57, 1);
sprite.renderOrder = 10;
world.add(sprite);
}
makeClearanceLabel();
// ------------------------------------------------------------
// Song-style buildings
// ------------------------------------------------------------
function createRoof(width, depth, rise, mat) {
const eave = 0;
const w = width / 2;
const d = depth / 2;
const vertices = [
-w, eave + 0.16, -d,
w, eave + 0.16, -d,
-w, eave + 0.16, d,
w, eave + 0.16, d,
0, eave + rise, -d * 0.29,
0, eave + rise, d * 0.29
];
const indices = [
0, 5, 4, 0, 2, 5,
1, 5, 3, 1, 4, 5,
0, 4, 1,
2, 3, 5
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const roof = new THREE.Mesh(geometry, mat);
roof.castShadow = true;
roof.receiveShadow = true;
return roof;
}
function addLantern(parent, x, y, z) {
addBox(parent, 0.08, 0.52, 0.08, x, y + 0.26, z, mats.wood);
addCylinder(parent, 0.18, 0.18, 0.42, x, y - 0.02, z, mats.lantern, 10);
addCylinder(parent, 0.12, 0.12, 0.055, x, y + 0.22, z, mats.roofEdge, 10);
addCylinder(parent, 0.12, 0.12, 0.055, x, y - 0.26, z, mats.roofEdge, 10);
addBox(parent, 0.025, 0.28, 0.025, x, y - 0.02, z + 0.18, mats.woodLight);
}
function createBuilding(x, z, width, depth, height, rotation, wallMat) {
const group = new THREE.Group();
group.position.set(x, 0.43, z);
group.rotation.y = rotation;
world.add(group);
addBox(group, width + 0.2, 0.3, depth + 0.2, 0, 0.05, 0, mats.stoneDark);
addBox(group, width, height, depth, 0, height * 0.5 + 0.12, 0, wallMat);
const roof = createRoof(width + 1.05, depth + 1.0, 1.18, mats.roof);
roof.position.y = height + 0.15;
group.add(roof);
addBox(
group,
0.19,
0.18,
depth * 0.58 + 0.4,
0,
height + 1.38,
0,
mats.roofEdge
);
// Wooden sill and lintel.
addBox(group, width + 0.15, 0.15, 0.16, 0, height - 0.1, depth * 0.5 + 0.03, mats.wood);
// Two front windows with simple latticework.
for (const wx of [-width * 0.25, width * 0.25]) {
addBox(group, 1.05, 1.35, 0.075, wx, height * 0.58, depth * 0.5 + 0.035, mats.wood);
addBox(group, 0.82, 1.12, 0.09, wx, height * 0.58, depth * 0.5 + 0.075, mats.roofEdge);
for (const offset of [-0.27, 0, 0.27]) {
addBox(group, 0.035, 1.12, 0.035, wx + offset, height * 0.58, depth * 0.5 + 0.13, mats.woodLight);
}
for (const offset of [-0.28, 0.28]) {
addBox(group, 0.82, 0.035, 0.035, wx, height * 0.58 + offset, depth * 0.5 + 0.13, mats.woodLight);
}
}
// Central door.
addBox(group, 0.92, 1.75, 0.09, 0, 0.92, depth * 0.5 + 0.05, mats.wood);
addBox(group, 0.7, 1.52, 0.1, 0, 0.87, depth * 0.5 + 0.095, mats.roofEdge);
addBox(group, 0.03, 0.03, 0.035, 0.19, 0.86, depth * 0.5 + 0.16, mats.woodLight);
// Eave beams and lanterns.
addBox(group, width + 0.6, 0.12, 0.12, 0, height + 0.12, depth * 0.5 + 0.3, mats.wood);
addLantern(group, -width * 0.39, height * 0.62, depth * 0.5 + 0.38);
addLantern(group, width * 0.39, height * 0.62, depth * 0.5 + 0.38);
return group;
}
createBuilding(-9.4, -9.0, 5.7, 4.5, 4.1, Math.PI / 2, mats.plaster);
createBuilding(-9.6, 1.0, 5.3, 4.2, 4.8, Math.PI / 2, mats.plasterWarm);
createBuilding(-10.0, 11.7, 5.8, 4.6, 3.9, Math.PI / 2, mats.plasterPale);
createBuilding(-12.0, -21.0, 6.5, 4.8, 4.7, Math.PI / 2, mats.plasterWarm);
createBuilding(9.4, -7.8, 5.6, 4.4, 4.5, -Math.PI / 2, mats.plasterPale);
createBuilding(9.7, 3.6, 5.8, 4.5, 4.0, -Math.PI / 2, mats.plaster);
createBuilding(10.1, 14.0, 5.5, 4.2, 4.9, -Math.PI / 2, mats.plasterWarm);
createBuilding(12.0, -21.5, 6.2, 4.7, 4.1, -Math.PI / 2, mats.plaster);
// ------------------------------------------------------------
// Trees, market stalls and small urban details
// ------------------------------------------------------------
function createTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0.42, z);
tree.scale.setScalar(scale);
world.add(tree);
addCylinder(tree, 0.13, 0.22, 2.9, 0, 1.45, 0, mats.bark, 8);
const crownA = new THREE.Mesh(new THREE.IcosahedronGeometry(1.05, 0), mats.foliage);
crownA.position.set(-0.42, 3.0, 0);
crownA.castShadow = true;
tree.add(crownA);
const crownB = new THREE.Mesh(new THREE.IcosahedronGeometry(1.0, 0), mats.foliageLight);
crownB.position.set(0.48, 3.15, 0.15);
crownB.castShadow = true;
tree.add(crownB);
const crownC = new THREE.Mesh(new THREE.IcosahedronGeometry(0.85, 0), mats.foliageDark);
crownC.position.set(0, 3.65, -0.2);
crownC.castShadow = true;
tree.add(crownC);
const branch = addCylinder(tree, 0.07, 0.11, 1.35, 0.34, 2.45, 0, mats.bark, 7);
branch.rotation.z = -0.55;
}
createTree(-6.7, -15.0, 1.05);
createTree(-6.8, -5.5, 0.85);
createTree(-6.6, 8.5, 0.92);
createTree(-6.8, 18.0, 1.08);
createTree(6.7, -14.0, 0.92);
createTree(6.8, -4.4, 0.78);
createTree(6.6, 9.5, 1.0);
createTree(6.9, 19.0, 0.88);
function createStall(x, z, clothMat, rotation = 0) {
const stall = new THREE.Group();
stall.position.set(x, 0.43, z);
stall.rotation.y = rotation;
world.add(stall);
for (const px of [-0.9, 0.9]) {
for (const pz of [-0.55, 0.55]) {
addBox(stall, 0.08, 1.75, 0.08, px, 0.87, pz, mats.wood);
}
}
const awning = addBox(stall, 2.25, 0.08, 1.5, 0, 1.78, 0, clothMat);
awning.rotation.z = 0.09;
addBox(stall, 1.75, 0.72, 0.75, 0, 0.36, 0, mats.woodLight);
addBox(stall, 0.52, 0.42, 0.52, -0.45, 0.93, 0.05, mats.sack);
addBox(stall, 0.48, 0.38, 0.48, 0.42, 0.91, -0.08, mats.sack);
}
createStall(-6.1, 4.3, mats.red, Math.PI / 2);
createStall(6.15, -0.8, mats.cloth, -Math.PI / 2);
createStall(-6.2, -11.0, mats.cloth, Math.PI / 2);
// Low canal-side bollards.
for (const z of [-8, -3, 6, 12]) {
for (const x of [-4.08, 4.08]) {
addCylinder(world, 0.12, 0.15, 0.56, x, 0.65, z, mats.stoneDark, 8);
addCylinder(world, 0.16, 0.16, 0.09, x, 0.94, z, mats.stoneLight, 8);
}
}
// Distant city wall, framing the canal.
addBox(world, 31, 3.6, 1.0, 0, 1.35, -35, mats.plasterWarm);
addBox(world, 32, 0.25, 1.35, 0, 3.25, -35, mats.roof);
addBox(world, 7.0, 4.2, 1.1, 0, 1.7, -35, mats.stoneDark);
// ------------------------------------------------------------
// Camera controls implemented directly without addons
// ------------------------------------------------------------
const view = {
target: new THREE.Vector3(0, 1.85, 0),
radius: 18,
theta: 0.72,
phi: 1.12
};
const defaultView = {
radius: 18,
theta: 0.72,
phi: 1.12
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
function resetView() {
view.radius = defaultView.radius;
view.theta = defaultView.theta;
view.phi = defaultView.phi;
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(view.phi - dy * 0.005, 0.38, 1.43);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.012,
10,
30
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
document.querySelector("#resetView").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") view.theta += 0.08;
else if (event.key === "ArrowRight") view.theta -= 0.08;
else if (event.key === "ArrowUp") view.phi = Math.max(0.38, view.phi - 0.06);
else if (event.key === "ArrowDown") view.phi = Math.min(1.43, view.phi + 0.06);
else return;
updateCamera();
});
updateCamera();
// ------------------------------------------------------------
// Resize and subtle animation
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
boat.position.y = Math.sin(elapsed * 1.05) * 0.022;
boat.rotation.z = Math.sin(elapsed * 0.72) * 0.008;
for (const ripple of ripples) {
ripple.mesh.position.z += ripple.speed * delta;
if (ripple.mesh.position.z > 35) ripple.mesh.position.z -= 70;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```