Prompt specification
Build or customize the Three.js 3D scene "Song urban street and water junction" 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: Song urban street and water junction
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/song-urban-street-and-water-junction-x2391
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows urban waterways in Song-dynasty China. Build a compact referenced Chinese urban scene where a street bridge crosses a working canal. Show distinct boat and pedestrian routes without copying an entire historical painting. Low-poly.
Working Three.js Starter (song-urban-street-and-water-junction-x2391):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>汴河市井 — Song Canal Quarter</title>
<style>
:root {
color-scheme: dark;
--ink: #17201d;
--paper: #eee5cf;
--muted: #b8c0b4;
--gold: #d7a955;
--water: #63c8c4;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #aebbb5;
font-family: Georgia, "Noto Serif CJK SC", "Songti SC", serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
color: var(--paper);
text-shadow: 0 1px 8px rgba(0, 0, 0, .48);
}
.title-panel {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 19px 21px 17px;
border: 1px solid rgba(238, 229, 207, .27);
border-left: 3px solid var(--gold);
background:
linear-gradient(135deg, rgba(22, 31, 28, .88), rgba(22, 31, 28, .66));
box-shadow: 0 16px 45px rgba(0, 0, 0, .18);
backdrop-filter: blur(8px);
}
.eyebrow {
margin-bottom: 8px;
color: var(--gold);
font: 600 10px/1.3 system-ui, sans-serif;
letter-spacing: .2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(29px, 4vw, 43px);
font-weight: 500;
letter-spacing: .13em;
}
.subtitle {
margin: 6px 0 15px;
color: #d6d8cd;
font: 12px/1.45 system-ui, sans-serif;
letter-spacing: .04em;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 10px 18px;
padding-top: 12px;
border-top: 1px solid rgba(238, 229, 207, .16);
font: 11px/1.35 system-ui, sans-serif;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 24px;
height: 3px;
border-radius: 4px;
box-shadow: 0 0 8px currentColor;
}
.swatch.boat { color: var(--water); background: var(--water); }
.swatch.walk { color: #f2bd62; background: #f2bd62; }
.credit {
position: absolute;
left: 24px;
bottom: 22px;
max-width: min(540px, calc(100vw - 48px));
padding: 11px 14px;
border-left: 2px solid rgba(215, 169, 85, .8);
background: rgba(19, 27, 24, .68);
color: #d7d8cf;
font: 11px/1.55 system-ui, sans-serif;
backdrop-filter: blur(7px);
}
.credit strong {
color: var(--paper);
font-weight: 600;
}
.controls-panel {
position: absolute;
right: 24px;
bottom: 22px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
pointer-events: auto;
}
.hint {
padding: 8px 11px;
border: 1px solid rgba(238, 229, 207, .2);
background: rgba(19, 27, 24, .68);
color: #d7d8cf;
font: 10px/1.45 system-ui, sans-serif;
letter-spacing: .035em;
backdrop-filter: blur(7px);
}
.buttons { display: flex; gap: 8px; }
button {
border: 1px solid rgba(238, 229, 207, .27);
padding: 8px 11px;
background: rgba(19, 27, 24, .78);
color: var(--paper);
font: 11px/1 system-ui, sans-serif;
cursor: pointer;
backdrop-filter: blur(7px);
}
button:hover {
border-color: var(--gold);
color: #ffe0a1;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #aebbb5;
color: #26312d;
font-size: 13px;
letter-spacing: .18em;
transition: opacity .65s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading-mark {
width: 42px;
height: 42px;
margin: 0 auto 14px;
border: 2px solid rgba(38, 49, 45, .25);
border-top-color: #26312d;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 650px) {
.title-panel { top: 14px; left: 14px; width: calc(100vw - 28px); }
.credit { left: 14px; bottom: 14px; max-width: calc(100vw - 28px); }
.controls-panel { right: 14px; bottom: 112px; }
.hint { display: none; }
.subtitle { margin-bottom: 10px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly Song dynasty canal district"></canvas>
<div class="hud">
<section class="title-panel">
<div class="eyebrow">Northern Song China · interpretive reconstruction</div>
<h1>汴河市井</h1>
<div class="subtitle">A compact bridge-and-canal quarter: working boats below, a street crossing above.</div>
<div class="legend" aria-label="Route legend">
<span><i class="swatch boat"></i> Canal traffic route</span>
<span><i class="swatch walk"></i> Pedestrian street route</span>
</div>
</section>
<div class="credit">
<strong>Visual reference:</strong> bridge, shopfront, boat and street motifs associated with
Northern Song urban imagery, including <em>Along the River During the Qingming Festival</em>.
This is an interpretive low-poly study, not a reproduction of the painting.
</div>
<div class="controls-panel">
<div class="hint">Drag: orbit · Shift/right-drag: pan · Wheel/pinch: zoom · R: reset</div>
<div class="buttons">
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-motion" type="button">Pause motion</button>
</div>
</div>
</div>
<div id="loading">
<div>
<div class="loading-mark"></div>
BUILDING THE CANAL QUARTER
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8c4bd);
scene.fog = new THREE.FogExp2(0xb8c4bd, 0.0165);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
const view = {
target: new THREE.Vector3(0, 1.55, 0),
radius: 29,
theta: 0.76,
phi: 1.04
};
function updateCamera() {
const s = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * s * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * s * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemi = new THREE.HemisphereLight(0xe6efe7, 0x665d4c, 1.75);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe7bd, 3.2);
sun.position.set(-13, 22, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9db9bd, 0.55);
fill.position.set(18, 9, -15);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) => new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
const M = {
earth: material(0x737966),
road: material(0x817c6d),
stone: material(0x777b70),
stoneLight: material(0x9a9b89),
stoneDark: material(0x5e665f),
timber: material(0x684936),
timberLight: material(0x88603d),
plaster: [
material(0xd9cfb5),
material(0xc9bda2),
material(0xe1d6bd),
material(0xb8ae96)
],
roof: [
material(0x3f4c49, { side: THREE.DoubleSide }),
material(0x4c5350, { side: THREE.DoubleSide }),
material(0x555956, { side: THREE.DoubleSide })
],
paper: material(0xc8b98d),
door: material(0x49382c),
foliage: [
material(0x526c4f),
material(0x667b56),
material(0x435f48)
],
bamboo: material(0x8c794e),
rope: material(0x8c774e),
red: material(0xa83e2f),
redLight: material(0xc85636, {
emissive: 0x48170d,
emissiveIntensity: 0.45
}),
ceramic: material(0x485d61),
ceramicLight: material(0x7c8273),
sail: material(0xc6b78b),
sack: material(0xa89267),
black: material(0x252d2a)
};
function box(w, h, d, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, segments, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 9137;
function rand() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
// -------------------------------------------------------------------------
// Ground, canal and stone embankments
// -------------------------------------------------------------------------
box(48, 0.8, 44, M.earth, 0, -0.72, 0);
// Separate land masses leave an open channel through the middle.
box(48, 0.5, 20.4, M.earth, 0, -0.18, 13.35);
box(48, 0.5, 20.4, M.earth, 0, -0.18, -13.35);
// Roads on either bank.
box(46, 0.09, 1.8, M.road, 0, 0.12, 9.15);
box(46, 0.09, 1.8, M.road, 0, 0.12, -9.15);
// Canal walls and narrow waterside paths.
for (const side of [-1, 1]) {
box(46, 0.72, 0.38, M.stoneDark, 0, 0.34, side * 3.14);
box(46, 0.14, 1.0, M.stone, 0, 0.75, side * 3.72);
box(46, 0.09, 0.08, M.stoneLight, 0, 0.84, side * 3.30);
// Individual capstones provide a restrained low-poly rhythm.
for (let x = -22; x <= 22; x += 2.2) {
box(1.95, 0.16, 0.52, M.stoneLight, x, 0.77, side * 3.18);
}
}
// Animated canal water.
const waterGeometry = new THREE.PlaneGeometry(46, 6, 46, 12);
waterGeometry.rotateX(-Math.PI / 2);
const waterMaterial = material(0x397f7c, {
roughness: 0.32,
metalness: 0.12,
transparent: true,
opacity: 0.94,
side: THREE.DoubleSide
});
const water = new THREE.Mesh(waterGeometry, waterMaterial);
water.position.y = 0.055;
water.receiveShadow = true;
scene.add(water);
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0x9dd8ce,
transparent: true,
opacity: 0.32,
depthWrite: false
});
const ripples = [];
for (let i = 0; i < 26; i++) {
const ripple = new THREE.Mesh(
new THREE.PlaneGeometry(0.65 + rand() * 1.25, 0.025),
rippleMaterial
);
ripple.rotation.x = -Math.PI / 2;
ripple.position.set(
-22 + rand() * 44,
0.13,
-2.65 + rand() * 5.3
);
scene.add(ripple);
ripples.push(ripple);
}
// -------------------------------------------------------------------------
// Main masonry arch bridge
// -------------------------------------------------------------------------
const bridgeGroup = new THREE.Group();
scene.add(bridgeGroup);
// The lower contour is a quadratic arch opening. Extruding the shape
// creates a solid masonry bridge rather than a decorative facade.
const bridgeShape = new THREE.Shape();
bridgeShape.moveTo(-5.4, 0);
bridgeShape.lineTo(-5.4, 3.65);
bridgeShape.lineTo(5.4, 3.65);
bridgeShape.lineTo(5.4, 0);
bridgeShape.lineTo(3.2, 0);
bridgeShape.quadraticCurveTo(0, 5.0, -3.2, 0);
bridgeShape.closePath();
const bridgeGeometry = new THREE.ExtrudeGeometry(bridgeShape, {
depth: 4.2,
bevelEnabled: true,
bevelSegments: 1,
steps: 1,
bevelSize: 0.07,
bevelThickness: 0.07,
curveSegments: 14
});
bridgeGeometry.rotateY(Math.PI / 2);
const bridgeBody = new THREE.Mesh(bridgeGeometry, M.stone);
bridgeBody.position.x = -2.1;
bridgeBody.castShadow = true;
bridgeBody.receiveShadow = true;
bridgeGroup.add(bridgeBody);
box(4.3, 0.16, 10.8, M.stoneLight, 0, 3.73, 0, bridgeGroup);
// Masonry arch trim on both visible sides.
for (const side of [-1, 1]) {
for (let i = 0; i <= 10; i++) {
const t = i / 10;
const z = -3.2 + 6.4 * t;
const y = 10 * t * (1 - t);
const dy = 10 - 20 * t;
const dz = 6.4;
const block = box(
0.13,
0.38,
0.67,
i % 2 ? M.stoneLight : M.stone,
side * 2.17,
y + 0.18,
z,
bridgeGroup
);
block.rotation.x = -Math.atan2(dy, dz);
}
}
// Stepped approaches at both ends.
const stairPoints = [];
for (const side of [-1, 1]) {
for (let i = 0; i < 9; i++) {
const height = 3.8 * (1 - (i + 1) / 10);
const z = side * (5.55 + i * 0.34);
box(
4.12,
height,
0.38,
i % 2 ? M.stone : M.stoneLight,
0,
height / 2,
z,
bridgeGroup
);
}
}
// Bridge parapets.
for (const side of [-1, 1]) {
for (let z = -4.8; z <= 4.81; z += 1.2) {
box(0.22, 0.68, 0.24, M.stoneLight, side * 2.0, 4.15, z, bridgeGroup);
}
box(0.14, 0.14, 10.1, M.stoneLight, side * 2.0, 4.48, 0, bridgeGroup);
}
// Lantern posts at the bridge corners.
for (const side of [-1, 1]) {
for (const z of [-5.05, 5.05]) {
cylinder(0.055, 0.065, 1.25, 6, M.timber, side * 2.25, 4.45, z, bridgeGroup);
const lantern = new THREE.Mesh(
new THREE.SphereGeometry(0.23, 8, 6),
M.redLight
);
lantern.position.set(side * 2.25, 5.12, z);
lantern.scale.set(0.82, 1.15, 0.82);
lantern.castShadow = true;
bridgeGroup.add(lantern);
}
}
// -------------------------------------------------------------------------
// Canvas-generated shop signs and banners
// -------------------------------------------------------------------------
function signTexture(text, vertical = false) {
const c = document.createElement("canvas");
c.width = vertical ? 128 : 512;
c.height = vertical ? 512 : 160;
const ctx = c.getContext("2d");
ctx.fillStyle = vertical ? "#a5402d" : "#493126";
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = "#c9a45e";
ctx.lineWidth = vertical ? 7 : 6;
ctx.strokeRect(9, 9, c.width - 18, c.height - 18);
ctx.fillStyle = "#ead9a9";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = vertical
? '700 88px "Songti SC", "Noto Serif CJK SC", serif'
: '600 76px "Songti SC", "Noto Serif CJK SC", serif';
if (vertical) {
const chars = [...text];
const step = (c.height - 70) / chars.length;
chars.forEach((char, i) => {
ctx.fillText(char, c.width / 2, 44 + step * (i + 0.35));
});
} else {
ctx.fillText(text, c.width / 2, c.height / 2 + 4);
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
return texture;
}
// -------------------------------------------------------------------------
// Low-poly Chinese roofs and shop houses
// -------------------------------------------------------------------------
function addRoof(group, w, d, h, roofMaterial) {
const xValues = [-w / 2, -w * 0.34, 0, w * 0.34, w / 2];
const positions = [];
const eaveLift = x => {
const edge = Math.abs(x) / (w / 2);
return edge > 0.8 ? 0.28 * ((edge - 0.8) / 0.2) : 0;
};
for (const side of [-1, 1]) {
for (let i = 0; i < xValues.length - 1; i++) {
const x0 = xValues[i];
const x1 = xValues[i + 1];
const e0 = eaveLift(x0);
const e1 = eaveLift(x1);
const z = side * (d / 2 + 0.25);
positions.push(
x0, e0, z,
x1, e1, z,
0, h, 0,
x1, e1, z,
x0, e0, z,
0, h, 0
);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const roof = new THREE.Mesh(geometry, roofMaterial);
roof.castShadow = true;
roof.receiveShadow = true;
group.add(roof);
// End gables close the roof silhouette.
for (const side of [-1, 1]) {
const gableGeometry = new THREE.BufferGeometry();
gableGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
side * w / 2, 0, -d / 2,
side * w / 2, h, 0,
side * w / 2, 0, d / 2
], 3)
);
gableGeometry.computeVertexNormals();
const gable = new THREE.Mesh(gableGeometry, roofMaterial);
gable.castShadow = true;
group.add(gable);
}
// Ridge and eave timbers.
const ridge = cylinder(0.07, 0.07, w + 0.12, 6, M.stoneDark, 0, h + 0.02, 0, group);
ridge.rotation.z = Math.PI / 2;
box(w + 0.45, 0.12, 0.13, M.timber, 0, 0.05, d / 2 + 0.25, group);
box(w + 0.45, 0.12, 0.13, M.timber, 0, 0.05, -d / 2 - 0.25, group);
}
function addWindow(group, x, y, z, w = 0.82, h = 0.72) {
box(w, h, 0.08, M.timber, x, y, z, group);
box(w - 0.14, h - 0.14, 0.09, M.paper, x, y, z + 0.015, group);
for (let i = 1; i < 4; i++) {
box(0.035, h - 0.12, 0.04, M.timber, x - w / 2 + i * w / 4, y, z + 0.08, group);
}
box(w - 0.12, 0.035, 0.04, M.timber, x, y, z + 0.08, group);
}
function makeBuilding({
x,
z,
w = 4,
d = 4,
h = 2.8,
sign = "酒肆",
north = false,
variant = 0
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = north ? Math.PI : 0;
scene.add(group);
const plaster = M.plaster[variant % M.plaster.length];
const roofMat = M.roof[variant % M.roof.length];
const front = d / 2 + 0.035;
box(w + 0.2, 0.22, d + 0.16, M.stone, 0, 0.12, 0, group);
box(w, h, d, plaster, 0, h / 2 + 0.2, 0, group);
// Visible timber frame.
for (const px of [-w / 2 + 0.12, -w * 0.25, 0, w * 0.25, w / 2 - 0.12]) {
box(0.12, h - 0.1, 0.12, M.timber, px, h / 2 + 0.2, front + 0.035, group);
}
box(w + 0.06, 0.13, 0.13, M.timber, 0, 0.72, front + 0.05, group);
box(w + 0.06, 0.13, 0.13, M.timber, 0, h - 0.04, front + 0.05, group);
// Door and paper lattice windows.
box(0.84, 1.55, 0.09, M.door, 0, 0.99, front + 0.045, group);
box(0.05, 1.55, 0.04, M.timberLight, 0, 0.99, front + 0.11, group);
addWindow(group, -w * 0.28, 1.68, front + 0.04);
addWindow(group, w * 0.28, 1.68, front + 0.04);
addRoof(group, w + 0.72, d + 0.5, 0.92, roofMat);
group.children[group.children.length - 5].position.y = h + 0.2;
// Horizontal shop board.
const boardWidth = Math.min(2.45, w * 0.72);
const signMap = signTexture(sign);
const board = new THREE.Mesh(
new THREE.PlaneGeometry(boardWidth, 0.62),
new THREE.MeshBasicMaterial({ map: signMap })
);
board.position.set(0, h * 0.77, front + 0.16);
group.add(board);
// Narrow cloth banner beside some doors.
if (variant % 2 === 0) {
const bannerMap = signTexture(sign.slice(0, 1), true);
const banner = new THREE.Mesh(
new THREE.PlaneGeometry(0.4, 1.45),
new THREE.MeshBasicMaterial({
map: bannerMap,
side: THREE.DoubleSide
})
);
banner.position.set(w * 0.39, 1.42, front + 0.17);
group.add(banner);
}
// Small red lantern at one corner.
if (variant % 3 === 0) {
cylinder(0.04, 0.04, 0.85, 6, M.timber, -w * 0.43, h * 0.71, front + 0.23, group);
const lantern = new THREE.Mesh(
new THREE.SphereGeometry(0.18, 8, 6),
M.redLight
);
lantern.position.set(-w * 0.43, h * 0.71 - 0.48, front + 0.23);
lantern.scale.set(0.8, 1.2, 0.8);
group.add(lantern);
}
return group;
}
const northBuildings = [
{ x: -16.0, sign: "茶坊", w: 4.0, d: 4.0, h: 2.9 },
{ x: -10.8, sign: "脚店", w: 3.8, d: 4.2, h: 3.2 },
{ x: -5.6, sign: "香饮", w: 4.1, d: 4.0, h: 2.8 },
{ x: 5.6, sign: "布帛", w: 4.0, d: 4.1, h: 3.0 },
{ x: 10.8, sign: "酒肆", w: 4.2, d: 4.0, h: 3.4 },
{ x: 16.0, sign: "解库", w: 4.0, d: 4.2, h: 2.7 }
];
const southBuildings = [
{ x: -16.2, sign: "米行", w: 4.2, d: 4.0, h: 2.8 },
{ x: -10.8, sign: "舟子", w: 3.9, d: 4.1, h: 3.1 },
{ x: -5.5, sign: "杂货", w: 4.1, d: 4.0, h: 2.7 },
{ x: 5.6, sign: "茶坊", w: 4.0, d: 4.0, h: 3.0 },
{ x: 10.7, sign: "面馆", w: 4.2, d: 4.0, h: 2.9 },
{ x: 16.1, sign: "药材", w: 4.0, d: 4.2, h: 3.3 }
];
northBuildings.forEach((b, i) => makeBuilding({
...b,
z: 13.0 + (i % 2) * 0.4,
north: true,
variant: i
}));
southBuildings.forEach((b, i) => makeBuilding({
...b,
z: -13.0 - (i % 2) * 0.4,
north: false,
variant: i + 1
}));
// -------------------------------------------------------------------------
// Trees, wall, props and market details
// -------------------------------------------------------------------------
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.12, 0.2, 2.2, 6, M.bamboo, 0, 1.1, 0, group);
const clusters = [
[-0.35, 2.35, 0.1, 0.92],
[0.42, 2.5, -0.12, 0.82],
[0.05, 3.0, 0.08, 0.98],
[0.02, 2.45, -0.4, 0.72]
];
clusters.forEach((c, i) => {
const leaf = new THREE.Mesh(
new THREE.IcosahedronGeometry(c[3], 0),
M.foliage[i % M.foliage.length]
);
leaf.position.set(c[0], c[1], c[2]);
leaf.scale.set(1.1, 0.85, 0.95);
leaf.rotation.set(rand(), rand(), rand());
leaf.castShadow = true;
group.add(leaf);
});
}
makeTree(-20, 7.8, 1.1);
makeTree(-7.8, 7.1, 0.8);
makeTree(13.7, 7.4, 0.95);
makeTree(20.3, 7.2, 1.15);
makeTree(-19.5, -7.3, 1.05);
makeTree(8.0, -7.5, 0.85);
makeTree(20.0, -7.1, 1.0);
// A low distant wall adds depth without dominating the compact district.
box(43, 1.4, 0.7, M.stoneDark, 0, 0.7, 21.0);
for (let x = -21; x <= 21; x += 1.55) {
box(0.62, 0.42, 0.82, M.stone, x, 1.58, 21.0);
}
// Cargo, baskets and crates beside the road.
function crate(x, z, size = 0.65, rotation = 0) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.rotation.y = rotation;
scene.add(g);
box(size, size * 0.72, size, M.timberLight, 0, size * 0.36, 0, g);
box(size + 0.04, 0.055, size + 0.04, M.timber, 0, size * 0.5, 0, g);
box(0.05, size * 0.72, size + 0.035, M.timber, 0, size * 0.36, 0, g);
}
crate(-7.7, -10.3, 0.65, 0.1);
crate(-6.85, -10.4, 0.52, -0.14);
crate(7.2, 10.1, 0.62, -0.08);
function basket(x, z) {
cylinder(0.32, 0.22, 0.45, 8, M.bamboo, x, 0.25, z);
cylinder(0.34, 0.34, 0.07, 8, M.rope, x, 0.48, z);
}
basket(-8.1, -10.0);
basket(8.0, 9.9);
for (let i = 0; i < 7; i++) {
const sack = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.34, 0),
M.sack
);
sack.position.set(6.6 + (i % 3) * 0.45, 0.31, 10.45 + Math.floor(i / 3) * 0.38);
sack.scale.set(0.8, 1.15, 0.75);
sack.rotation.y = rand() * Math.PI;
sack.castShadow = true;
scene.add(sack);
}
// Mooring posts.
for (let x = -20; x <= 20; x += 5) {
cylinder(0.09, 0.12, 0.95, 6, M.timber, x, 0.48, 3.5);
cylinder(0.09, 0.12, 0.95, 6, M.timber, x, 0.48, -3.5);
}
// -------------------------------------------------------------------------
// Distinct route graphics
// -------------------------------------------------------------------------
// Boat route.
const boatRouteGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-22, 0.17, -0.65),
new THREE.Vector3(22, 0.17, -0.65)
]);
const boatRoute = new THREE.Line(
boatRouteGeometry,
new THREE.LineDashedMaterial({
color: 0x70e1da,
dashSize: 0.65,
gapSize: 0.35,
transparent: true,
opacity: 0.9
})
);
boatRoute.computeLineDistances();
scene.add(boatRoute);
// Small directional arrows moving along the water route.
const routeArrows = [];
for (let i = 0; i < 6; i++) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.15, 0.48, 3),
new THREE.MeshBasicMaterial({
color: 0x9ef4ea,
transparent: true,
opacity: 0.9
})
);
arrow.rotation.z = -Math.PI / 2;
arrow.position.set(-19 + i * 7, 0.21, -0.65);
scene.add(arrow);
routeArrows.push(arrow);
}
// Pedestrian polyline follows the road, steps, bridge deck, and opposite road.
const pedestrianPath = [];
pedestrianPath.push(new THREE.Vector3(-10, 0.19, 9.15));
pedestrianPath.push(new THREE.Vector3(-2.2, 0.19, 9.15));
pedestrianPath.push(new THREE.Vector3(0, 0.19, 8.45));
for (let i = 8; i >= 0; i--) {
const height = 3.8 * (1 - (i + 1) / 10);
pedestrianPath.push(
new THREE.Vector3(0, height + 0.08, 5.55 + i * 0.34)
);
}
pedestrianPath.push(new THREE.Vector3(0, 3.88, 4.7));
pedestrianPath.push(new THREE.Vector3(0, 3.88, -4.7));
for (let i = 0; i < 9; i++) {
const height = 3.8 * (1 - (i + 1) / 10);
pedestrianPath.push(
new THREE.Vector3(0, height + 0.08, -(5.55 + i * 0.34))
);
}
pedestrianPath.push(new THREE.Vector3(0, 0.19, -9.15));
pedestrianPath.push(new THREE.Vector3(9.5, 0.19, -9.15));
const pedestrianRoute = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(pedestrianPath),
new THREE.LineDashedMaterial({
color: 0xf4bd61,
dashSize: 0.35,
gapSize: 0.18,
transparent: true,
opacity: 0.95
})
);
pedestrianRoute.computeLineDistances();
scene.add(pedestrianRoute);
// Cumulative lengths for moving pedestrians.
const pathSegments = [];
let totalPathLength = 0;
for (let i = 0; i < pedestrianPath.length - 1; i++) {
const a = pedestrianPath[i];
const b = pedestrianPath[i + 1];
const length = a.distanceTo(b);
pathSegments.push({ a, b, length, start: totalPathLength });
totalPathLength += length;
}
function samplePedestrianPath(distance) {
const d = ((distance % totalPathLength) + totalPathLength) % totalPathLength;
for (const segment of pathSegments) {
if (d <= segment.start + segment.length) {
const t = (d - segment.start) / segment.length;
const point = segment.a.clone().lerp(segment.b, t);
const direction = segment.b.clone().sub(segment.a).normalize();
return { point, direction };
}
}
const last = pathSegments[pathSegments.length - 1];
return {
point: last.b.clone(),
direction: last.b.clone().sub(last.a).normalize()
};
}
// -------------------------------------------------------------------------
// Pedestrians
// -------------------------------------------------------------------------
function makePerson(index) {
const group = new THREE.Group();
const robeColors = [
0x566d72,
0x8b5c43,
0x6d7452,
0xa08a62,
0x4f5961,
0x8c7354
];
const robeMaterial = material(robeColors[index % robeColors.length]);
const skinMaterial = material(0xc59d76);
const robe = cylinder(0.14, 0.27, 0.72, 6, robeMaterial, 0, 0.58, 0, group);
robe.scale.z = 0.85;
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.135, 7, 5),
skinMaterial
);
head.position.y = 1.06;
head.castShadow = true;
group.add(head);
const hat = cylinder(0.09, 0.19, 0.16, 7, M.bamboo, 0, 1.18, 0, group);
hat.castShadow = true;
const legLeft = box(0.075, 0.38, 0.09, M.black, -0.085, 0.22, 0, group);
const legRight = box(0.075, 0.38, 0.09, M.black, 0.085, 0.22, 0, group);
const armLeft = box(0.075, 0.48, 0.085, robeMaterial, -0.19, 0.64, 0, group);
const armRight = box(0.075, 0.48, 0.085, robeMaterial, 0.19, 0.64, 0, group);
armLeft.rotation.z = -0.12;
armRight.rotation.z = 0.12;
group.scale.setScalar(0.86 + (index % 3) * 0.08);
scene.add(group);
return { group, legLeft, legRight, phase: index * 0.137, speed: 0.55 + (index % 4) * 0.055 };
}
const pedestrians = Array.from({ length: 8 }, (_, i) => makePerson(i));
// -------------------------------------------------------------------------
// Working canal boat
// -------------------------------------------------------------------------
function makeBoat() {
const group = new THREE.Group();
scene.add(group);
const length = 4.5;
const width = 1.55;
const hullShape = new THREE.Shape();
hullShape.moveTo(-length / 2, -width / 2);
hullShape.lineTo(length * 0.31, -width / 2);
hullShape.lineTo(length / 2, 0);
hullShape.lineTo(length * 0.31, width / 2);
hullShape.lineTo(-length / 2, width / 2);
hullShape.closePath();
const hullGeometry = new THREE.ExtrudeGeometry(hullShape, {
depth: 0.45,
bevelEnabled: true,
bevelSize: 0.09,
bevelThickness: 0.08,
bevelSegments: 1
});
hullGeometry.rotateX(-Math.PI / 2);
const hull = new THREE.Mesh(hullGeometry, M.timber);
hull.position.y = 0.16;
hull.castShadow = true;
hull.receiveShadow = true;
group.add(hull);
box(3.25, 0.09, 1.12, M.timberLight, -0.15, 0.65, 0, group);
// Rounded woven cargo canopy.
const canopy = cylinder(
0.61,
0.61,
1.65,
8,
M.sail,
-0.48,
1.04,
0,
group
);
canopy.rotation.z = Math.PI / 2;
canopy.scale.z = 0.85;
for (let x = -1.1; x <= 0.2; x += 0.43) {
const hoop = new THREE.Mesh(
new THREE.TorusGeometry(0.61, 0.025, 4, 8),
M.rope
);
hoop.rotation.y = Math.PI / 2;
hoop.position.set(x, 1.04, 0);
group.add(hoop);
}
// Cargo and a boatman's pole.
const cargo = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.38, 0),
M.sack
);
cargo.position.set(1.25, 0.92, 0.05);
cargo.scale.set(1.05, 0.85, 0.9);
cargo.castShadow = true;
group.add(cargo);
const pole = cylinder(0.025, 0.035, 3.2, 5, M.bamboo, 1.55, 1.45, -0.55, group);
pole.rotation.z = -0.18;
return group;
}
const movingBoat = makeBoat();
movingBoat.position.set(-12, 0, -0.65);
const mooredBoat = makeBoat();
mooredBoat.position.set(14.2, 0, 1.45);
mooredBoat.rotation.y = Math.PI;
mooredBoat.scale.setScalar(0.85);
// -------------------------------------------------------------------------
// Subtle chimney smoke
// -------------------------------------------------------------------------
const smokeMaterial = new THREE.MeshStandardMaterial({
color: 0xc9cec4,
transparent: true,
opacity: 0.2,
roughness: 1,
depthWrite: false
});
const smoke = [];
const smokeOrigins = [
new THREE.Vector3(-10.8, 4.7, -14.4),
new THREE.Vector3(10.8, 4.7, 15.1),
new THREE.Vector3(-16.0, 4.2, 15.0)
];
smokeOrigins.forEach((origin, sourceIndex) => {
for (let i = 0; i < 5; i++) {
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.28 + i * 0.03, 0),
smokeMaterial.clone()
);
puff.userData.base = origin.clone();
puff.userData.offset = i * 0.55;
puff.userData.source = sourceIndex;
scene.add(puff);
smoke.push(puff);
}
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan and zoom without addons
// -------------------------------------------------------------------------
const pointers = new Map();
let gesture = null;
const clamp = THREE.MathUtils.clamp;
function panCamera(dx, dy) {
const right = new THREE.Vector3(
Math.cos(view.theta),
0,
-Math.sin(view.theta)
);
const forward = new THREE.Vector3(
-Math.sin(view.theta),
0,
-Math.cos(view.theta)
);
const amount = view.radius * 0.00135;
view.target.addScaledVector(right, -dx * amount);
view.target.addScaledVector(forward, dy * amount);
view.target.x = clamp(view.target.x, -18, 18);
view.target.z = clamp(view.target.z, -14, 14);
}
function pointerPair() {
const values = [...pointers.values()];
if (values.length < 2) return null;
return {
distance: Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y),
centerX: (values[0].x + values[1].x) / 2,
centerY: (values[0].y + values[1].y) / 2
};
}
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
gesture = {
type: event.button === 2 || event.shiftKey ? "pan" : "orbit",
lastX: event.clientX,
lastY: event.clientY
};
} else if (pointers.size === 2) {
gesture = { type: "pinch", pair: pointerPair() };
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && gesture) {
const dx = event.clientX - gesture.lastX;
const dy = event.clientY - gesture.lastY;
if (gesture.type === "orbit") {
view.theta -= dx * 0.005;
view.phi = clamp(view.phi - dy * 0.0042, 0.34, 1.43);
} else {
panCamera(dx, dy);
}
gesture.lastX = event.clientX;
gesture.lastY = event.clientY;
} else if (pointers.size >= 2 && gesture?.type === "pinch") {
const pair = pointerPair();
if (pair && gesture.pair) {
const zoomRatio = gesture.pair.distance / Math.max(1, pair.distance);
view.radius = clamp(view.radius * zoomRatio, 12, 48);
panCamera(pair.centerX - gesture.pair.centerX, pair.centerY - gesture.pair.centerY);
}
gesture.pair = pair;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
gesture = null;
} else if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
gesture = {
type: "orbit",
lastX: remaining.x,
lastY: remaining.y
};
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
view.radius = clamp(
view.radius * Math.exp(event.deltaY * 0.001),
12,
48
);
}, { passive: false });
function resetView() {
view.target.set(0, 1.55, 0);
view.radius = 29;
view.theta = 0.76;
view.phi = 1.04;
}
document.querySelector("#reset-view").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") resetView();
if (event.key === "+" || event.key === "=") {
view.radius = clamp(view.radius - 1.5, 12, 48);
}
if (event.key === "-") {
view.radius = clamp(view.radius + 1.5, 12, 48);
}
if (event.key === "ArrowLeft") view.theta += 0.08;
if (event.key === "ArrowRight") view.theta -= 0.08;
if (event.key === "ArrowUp") view.phi = clamp(view.phi - 0.05, 0.34, 1.43);
if (event.key === "ArrowDown") view.phi = clamp(view.phi + 0.05, 0.34, 1.43);
});
// -------------------------------------------------------------------------
// UI and animation
// -------------------------------------------------------------------------
let motionEnabled = true;
let simulationTime = 0;
const motionButton = document.querySelector("#toggle-motion");
motionButton.addEventListener("click", () => {
motionEnabled = !motionEnabled;
motionButton.textContent = motionEnabled ? "Pause motion" : "Resume motion";
});
const clock = new THREE.Clock();
let frame = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (motionEnabled) simulationTime += delta;
frame++;
updateCamera();
// Low-frequency wave deformation.
const position = waterGeometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const x = position.getX(i);
const z = position.getZ(i);
const wave =
Math.sin(x * 0.52 + simulationTime * 1.15) * 0.032 +
Math.cos(z * 1.4 - simulationTime * 0.82) * 0.021;
position.setY(i, wave);
}
position.needsUpdate = true;
if (frame % 2 === 0) {
waterGeometry.computeVertexNormals();
}
ripples.forEach((ripple, i) => {
ripple.position.x += delta * (0.2 + (i % 3) * 0.08);
if (ripple.position.x > 23) ripple.position.x = -23;
ripple.material.opacity = 0.2 + Math.sin(simulationTime * 1.7 + i) * 0.08;
});
// The cargo boat travels through the working lane.
movingBoat.position.x = ((simulationTime * 1.65 + 10) % 44) - 22;
movingBoat.position.y = 0.02 + Math.sin(simulationTime * 1.9) * 0.018;
movingBoat.rotation.z = Math.sin(simulationTime * 1.15) * 0.012;
movingBoat.rotation.y = Math.sin(simulationTime * 0.65) * 0.018;
mooredBoat.position.y = 0.015 + Math.sin(simulationTime * 1.35 + 2) * 0.012;
routeArrows.forEach((arrow, i) => {
arrow.position.x = ((simulationTime * 1.65 + i * 7.2 + 8) % 44) - 22;
arrow.position.y = 0.20 + Math.sin(simulationTime * 3 + i) * 0.015;
arrow.material.opacity = 0.65 + Math.sin(simulationTime * 2.5 + i) * 0.2;
});
// Pedestrians follow the street-and-bridge route.
pedestrians.forEach((person, i) => {
const distance = simulationTime * person.speed + person.phase * totalPathLength;
const sample = samplePedestrianPath(distance);
const stride = Math.sin(simulationTime * 5.5 + i * 1.7);
person.group.position.copy(sample.point);
person.group.position.y += Math.abs(stride) * 0.018;
person.group.rotation.y = Math.atan2(sample.direction.x, sample.direction.z);
person.legLeft.rotation.x = stride * 0.32;
person.legRight.rotation.x = -stride * 0.32;
});
// Smoke rises and expands slowly.
smoke.forEach((puff, i) => {
const age = (simulationTime * 0.19 + puff.userData.offset) % 2.8;
const origin = puff.userData.base;
puff.position.set(
origin.x + Math.sin(age * 1.7 + i) * age * 0.11,
origin.y + age * 0.72,
origin.z + age * 0.16
);
const scale = 0.6 + age * 0.35;
puff.scale.setScalar(scale);
puff.material.opacity = Math.max(0, 0.19 * (1 - age / 2.8));
});
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
});
setTimeout(() => {
document.querySelector("#loading").classList.add("hidden");
}, 550);
</script>
</body>
</html>
```