Prompt specification
Build or customize the Three.js 3D scene "Pedestrian crossing a small Gion canal bridge" 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: Pedestrian crossing a small Gion canal bridge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pedestrian-crossing-a-small-gion-canal-bridge-x3002
Scene Description Prompt:
A voxel pedestrian crosses Kyoto's Gion Shirakawa canal beside a willow and traditional facade; water continues beneath. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (pedestrian-crossing-a-small-gion-canal-bridge-x3002):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gion Shirakawa — Voxel Kyoto</title>
<style>
:root {
color-scheme: light;
--ink: #233532;
--paper: rgba(249, 247, 237, 0.88);
--line: rgba(35, 53, 50, 0.16);
--accent: #a9473d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe5e3;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 45%, rgba(39, 57, 54, 0.13) 100%),
linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent 22%);
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 10;
width: min(350px, calc(100vw - 48px));
padding: 19px 21px 17px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 15px 45px rgba(39, 57, 54, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 8px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 43px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
margin: 12px 0 0;
color: rgba(35, 53, 50, 0.68);
font-family: Georgia, "Times New Roman", serif;
font-size: 14px;
font-style: italic;
}
.coords {
display: flex;
align-items: center;
gap: 8px;
margin-top: 16px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: rgba(35, 53, 50, 0.54);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.coords::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
content: "";
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 20;
display: flex;
align-items: center;
gap: 12px;
}
.hint {
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 3px;
background: rgba(249, 247, 237, 0.76);
color: rgba(35, 53, 50, 0.66);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(10px);
pointer-events: none;
}
button {
height: 36px;
padding: 0 14px;
border: 1px solid rgba(35, 53, 50, 0.25);
border-radius: 3px;
background: var(--ink);
color: #fffdf4;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
transition: transform 160ms ease, background 160ms ease;
}
button:hover {
background: #39504b;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #e3ebe8;
color: var(--ink);
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
visibility: hidden;
opacity: 0;
}
.loading-mark {
text-align: center;
}
.loading-mark span {
display: block;
margin-bottom: 12px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
}
.loading-mark strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 28px;
font-weight: 500;
}
@media (max-width: 640px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px 17px;
}
.subtitle,
.coords {
display: none;
}
.hint {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<div id="loading">
<div class="loading-mark">
<span>Building Shirakawa</span>
<strong>京都 · 祇園</strong>
</div>
</div>
<div class="title-card">
<p class="eyebrow">Voxel Kyoto · Gion District</p>
<h1>Shirakawa<br />Canal</h1>
<p class="subtitle">A quiet crossing beneath the willows.</p>
<div class="coords">35.0037° N / 135.7752° E</div>
</div>
<div class="vignette"></div>
<div class="controls">
<div class="hint">Drag to orbit · Wheel to zoom · Right-drag to pan</div>
<button id="reset-view" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.querySelector("#loading");
const resetButton = document.querySelector("#reset-view");
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7e5);
scene.fog = new THREE.Fog(0xdce7e5, 22, 62);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute("aria-label", "Interactive voxel Kyoto canal scene");
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf4fbff, 0x8c7962, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d7, 3.1);
sun.position.set(10, 17, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d8df, 0.65);
fill.position.set(-9, 7, -8);
scene.add(fill);
// ---------------------------------------------------------------------
// Materials and voxel helpers
// ---------------------------------------------------------------------
const standard = (color, roughness = 0.82, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const materials = {
plaster: standard(0xe8dfca),
plasterLight: standard(0xf1e9d6),
plasterShadow: standard(0xd8cbb5),
wood: standard(0x49372f),
darkWood: standard(0x302923),
roof: standard(0x394746),
roofLight: standard(0x485756),
roofEdge: standard(0x293536),
stone: standard(0x99998d),
stoneLight: standard(0xb3b0a1),
stoneDark: standard(0x747a73),
paving: standard(0xc2bbaa),
pavingAlt: standard(0xb3ad9f),
riverbed: standard(0x315d5b),
water: new THREE.MeshStandardMaterial({
color: 0x4f9997,
roughness: 0.25,
metalness: 0.08,
transparent: true,
opacity: 0.76,
depthWrite: false
}),
ripple: new THREE.MeshBasicMaterial({
color: 0xc8eeea,
transparent: true,
opacity: 0.18,
depthWrite: false,
side: THREE.DoubleSide
}),
trunk: standard(0x655044),
trunkLight: standard(0x78604d),
leaf: standard(0x668a52),
leafLight: standard(0x7e9d5d),
leafDark: standard(0x4c7049),
leafYellow: standard(0x91a764),
lantern: new THREE.MeshStandardMaterial({
color: 0xc84e3f,
emissive: 0x6b160f,
emissiveIntensity: 0.55,
roughness: 0.7
}),
lamp: new THREE.MeshStandardMaterial({
color: 0xffdf9c,
emissive: 0xffa94d,
emissiveIntensity: 1.8,
roughness: 0.5
}),
shoji: new THREE.MeshStandardMaterial({
color: 0xe9dbb5,
emissive: 0x6e5c35,
emissiveIntensity: 0.16,
roughness: 0.9
}),
curtain: standard(0x3b7774),
coat: standard(0x507d7a),
coatDark: standard(0x365d5c),
scarf: standard(0xa7473e),
trousers: standard(0x2e3b43),
skin: standard(0xd4a078),
hair: standard(0x252724),
shoe: standard(0x252827),
bag: standard(0xb68555),
petal: new THREE.MeshBasicMaterial({ color: 0xf0b9b6 }),
koi: standard(0xe3834c),
koiPale: standard(0xe8d7b8),
moss: standard(0x60714b)
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const rippleGeometry = new THREE.PlaneGeometry(1, 1);
function box(parent, material, x, y, z, width, height, depth) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beam(parent, material, start, end, thickness, depth = thickness) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.set(thickness, direction.length(), depth);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 1949;
function random(min = 0, max = 1) {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6D2B79F5) | 0;
let t = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
const pick = array => array[Math.floor(random() * array.length)];
// ---------------------------------------------------------------------
// Canal, embankments and paving
// ---------------------------------------------------------------------
box(scene, materials.riverbed, 0, -0.18, 0, 4.55, 0.22, 92);
const water = new THREE.Mesh(
new THREE.PlaneGeometry(4.5, 92),
materials.water
);
water.rotation.x = -Math.PI / 2;
water.position.y = 0.08;
water.renderOrder = 1;
scene.add(water);
for (const side of [-1, 1]) {
box(
scene,
materials.stoneDark,
side * 6.9,
0.37,
0,
8.8,
0.74,
92
);
for (let z = -45; z <= 45; z += 1.35) {
const wallMaterial = random() > 0.72 ? materials.stoneLight : materials.stone;
box(
scene,
wallMaterial,
side * 2.42,
0.37,
z,
0.38,
0.76,
1.25
);
box(
scene,
materials.stoneLight,
side * 2.42,
0.79,
z,
0.48,
0.15,
1.31
);
}
for (let z = -44; z <= 44; z += 1.28) {
box(
scene,
random() > 0.5 ? materials.paving : materials.pavingAlt,
side * 3.3,
0.81,
z,
1.35,
0.16,
1.17
);
}
}
const ripples = [];
for (let i = 0; i < 72; i++) {
const material = materials.ripple.clone();
const ripple = new THREE.Mesh(rippleGeometry, material);
const x = random(-2.05, 2.05);
const z = random(-40, 40);
const width = random(0.22, 0.95);
const length = random(0.025, 0.065);
ripple.rotation.x = -Math.PI / 2;
ripple.position.set(x, 0.105 + random(0, 0.012), z);
ripple.scale.set(width, length, 1);
ripple.renderOrder = 2;
scene.add(ripple);
ripples.push({
mesh: ripple,
x,
phase: random(0, Math.PI * 2),
speed: random(0.45, 1.15),
baseOpacity: random(0.08, 0.23)
});
}
// ---------------------------------------------------------------------
// Traditional machiya facade
// ---------------------------------------------------------------------
function addMachiya(z, index) {
const group = new THREE.Group();
scene.add(group);
const facadeMaterial = index % 2 === 0
? materials.plaster
: materials.plasterLight;
// Raised foundation and main building mass.
box(group, materials.stoneDark, -5.25, 1.0, z, 4.05, 0.38, 4.15);
box(group, facadeMaterial, -5.25, 3.12, z, 3.8, 4.5, 4.02);
// Canal-facing lower facade.
box(group, materials.darkWood, -3.29, 1.8, z, 0.13, 1.9, 3.62);
for (let slat = 0; slat < 7; slat++) {
box(
group,
materials.wood,
-3.19,
1.8,
z - 1.55 + slat * 0.52,
0.08,
1.9,
0.075
);
}
// Upper shoji panels.
const panelWidth = 3.3;
const panelZ = z - panelWidth / 2;
for (let panel = 0; panel < 3; panel++) {
const centerZ = panelZ + 0.55 + panel * 1.1;
box(
group,
materials.shoji,
-3.28,
4.25,
centerZ,
0.07,
1.5,
0.94
);
for (let lattice = 0; lattice < 4; lattice++) {
box(
group,
materials.wood,
-3.225,
4.25,
centerZ - 0.36 + lattice * 0.24,
0.045,
1.5,
0.035
);
}
for (let lattice = 0; lattice < 5; lattice++) {
box(
group,
materials.wood,
-3.22,
3.61 + lattice * 0.32,
centerZ,
0.05,
0.035,
0.96
);
}
}
// Structural timber.
box(group, materials.darkWood, -3.16, 3.12, z, 0.18, 0.22, 4.02);
box(group, materials.wood, -3.14, 2.45, z - 1.92, 0.16, 4.35, 0.18);
box(group, materials.wood, -3.14, 2.45, z + 1.92, 0.16, 4.35, 0.18);
// A small fabric noren over one doorway.
if (index === 1 || index === 3) {
box(group, materials.curtain, -3.08, 3.08, z + 0.85, 0.05, 0.62, 0.78);
box(
group,
materials.shoji,
-3.055,
3.08,
z + 0.85,
0.025,
0.58,
0.035
);
}
// Terraced voxel roof, sloping away from the canal.
for (let row = 0; row < 8; row++) {
const roofMaterial = row % 3 === 0 ? materials.roofLight : materials.roof;
box(
group,
roofMaterial,
-2.93 - row * 0.51,
5.31 + row * 0.075,
z,
0.57,
0.19,
4.82
);
}
box(group, materials.roofEdge, -6.72, 5.84, z, 0.28, 0.28, 4.95);
// Small visible roof-tile ends along the eave.
for (let tile = 0; tile < 11; tile++) {
box(
group,
tile % 2 ? materials.roofLight : materials.roof,
-2.68,
5.34,
z - 2.28 + tile * 0.46,
0.20,
0.23,
0.19
);
}
// Box planters and stones at the facade.
box(group, materials.wood, -2.83, 1.08, z + 2.16, 0.62, 0.52, 0.55);
box(group, materials.moss, -2.83, 1.39, z + 2.16, 0.52, 0.12, 0.46);
box(group, materials.stoneDark, -2.9, 0.96, z - 2.25, 0.62, 0.3, 0.46);
}
[-9.0, -4.7, -0.4, 3.9].forEach((z, i) => addMachiya(z, i));
// ---------------------------------------------------------------------
// Willow beside the crossing
// ---------------------------------------------------------------------
const willow = new THREE.Group();
willow.position.set(4.85, 0.8, 3.15);
scene.add(willow);
box(scene, materials.stoneDark, 4.85, 0.91, 3.15, 1.05, 0.22, 1.05);
box(scene, materials.moss, 4.85, 1.04, 3.15, 0.72, 0.08, 0.72);
beam(willow, materials.trunk, [0, 0, 0], [0.12, 1.65, 0.02], 0.48, 0.43);
beam(willow, materials.trunk, [0.12, 1.55, 0.02], [-0.16, 3.05, 0.05], 0.4, 0.34);
beam(willow, materials.trunkLight, [-0.16, 2.9, 0.05], [-0.4, 4.05, 0.02], 0.29, 0.28);
const branchData = [
{ start: [-0.32, 3.65, 0.02], end: [-2.0, 4.75, 0.15] },
{ start: [-0.3, 3.72, 0.02], end: [1.25, 4.85, 0.42] },
{ start: [-0.35, 3.8, 0.02], end: [0.15, 5.12, -1.55] },
{ start: [-0.35, 3.8, 0.02], end: [0.45, 4.85, 1.75] },
{ start: [-0.35, 3.86, 0.02], end: [-1.3, 5.0, -1.18] },
{ start: [-0.25, 3.8, 0.02], end: [-0.55, 5.2, 0.4] }
];
const leafMaterials = [
materials.leaf,
materials.leafLight,
materials.leafDark,
materials.leafYellow
];
for (const branch of branchData) {
beam(willow, materials.trunkLight, branch.start, branch.end, 0.17, 0.16);
const [ex, ey, ez] = branch.end;
for (let cube = 0; cube < 7; cube++) {
const size = random(0.42, 0.85);
box(
willow,
pick(leafMaterials),
ex + random(-0.65, 0.65),
ey + random(-0.22, 0.38),
ez + random(-0.62, 0.62),
size,
size * random(0.65, 1.0),
size
);
}
// Hanging strands give the willow its characteristic silhouette.
for (let strand = 0; strand < 5; strand++) {
const sx = ex + random(-0.7, 0.7);
const sz = ez + random(-0.7, 0.7);
const sy = ey - random(0.05, 0.35);
const bottom = sy - random(1.15, 2.4);
beam(
willow,
materials.trunkLight,
[sx, sy, sz],
[sx + 0.08, bottom, sz + 0.04],
0.045,
0.045
);
for (let leaf = 0; leaf < 4; leaf++) {
const t = (leaf + 1) / 5;
box(
willow,
pick(leafMaterials),
sx + 0.08 * t + random(-0.09, 0.09),
sy + (bottom - sy) * t,
sz + random(-0.08, 0.08),
random(0.13, 0.25),
random(0.16, 0.3),
random(0.13, 0.24)
);
}
}
}
// ---------------------------------------------------------------------
// Stone footbridge
// ---------------------------------------------------------------------
const bridgeZ = 3.2;
for (let i = 0; i < 7; i++) {
const x = -2.7 + i * 0.9;
const arch = Math.sin((i / 6) * Math.PI);
const y = 0.8 + arch * 0.17;
box(
scene,
i % 2 ? materials.stoneLight : materials.stone,
x,
y,
bridgeZ,
0.88,
0.38,
1.72
);
box(
scene,
materials.stoneDark,
x,
y - 0.24,
bridgeZ,
0.90,
0.10,
1.78
);
}
box(scene, materials.stoneDark, -3.36, 0.67, bridgeZ, 0.72, 0.58, 1.9);
box(scene, materials.stoneDark, 3.36, 0.67, bridgeZ, 0.72, 0.58, 1.9);
box(scene, materials.stone, -3.5, 0.91, bridgeZ, 0.55, 0.18, 1.9);
box(scene, materials.stone, 3.5, 0.91, bridgeZ, 0.55, 0.18, 1.9);
// A smaller crossing in the distance emphasizes the continuing canal.
for (let i = 0; i < 5; i++) {
box(
scene,
materials.stone,
-1.45 + i * 0.72,
0.87 + Math.sin((i / 4) * Math.PI) * 0.1,
-17.5,
0.69,
0.25,
1.25
);
}
// ---------------------------------------------------------------------
// Voxel pedestrian
// ---------------------------------------------------------------------
const pedestrian = new THREE.Group();
pedestrian.position.set(-2.35, 1, bridgeZ);
scene.add(pedestrian);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(0, 0.86, -0.11);
rightLeg.position.set(0, 0.86, 0.11);
pedestrian.add(leftLeg, rightLeg);
for (const leg of [leftLeg, rightLeg]) {
box(leg, materials.trousers, 0, -0.31, 0, 0.21, 0.64, 0.23);
box(leg, materials.shoe, 0.07, -0.69, 0, 0.39, 0.17, 0.25);
}
box(pedestrian, materials.coat, 0, 1.2, 0, 0.56, 0.86, 0.49);
box(pedestrian, materials.coatDark, -0.295, 1.18, 0, 0.08, 0.78, 0.44);
box(pedestrian, materials.coatDark, 0, 1.23, -0.255, 0.48, 0.73, 0.055);
box(pedestrian, materials.skin, 0, 1.73, 0, 0.18, 0.2, 0.2);
box(pedestrian, materials.skin, 0, 1.99, 0, 0.45, 0.45, 0.43);
box(pedestrian, materials.hair, -0.08, 2.14, 0, 0.47, 0.18, 0.45);
box(pedestrian, materials.hair, -0.21, 2.01, 0, 0.08, 0.35, 0.43);
box(pedestrian, materials.hair, 0, 2.02, 0.215, 0.42, 0.39, 0.06);
box(pedestrian, materials.skin, 0.235, 2.0, 0.085, 0.035, 0.045, 0.045);
box(pedestrian, materials.skin, 0.235, 2.0, -0.085, 0.035, 0.045, 0.045);
box(pedestrian, materials.skin, 0.265, 1.97, 0, 0.055, 0.065, 0.075);
box(pedestrian, materials.scarf, 0.04, 1.68, 0, 0.49, 0.13, 0.48);
box(pedestrian, materials.scarf, -0.26, 1.45, 0.12, 0.09, 0.42, 0.11);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(0, 1.49, -0.31);
rightArm.position.set(0, 1.49, 0.31);
pedestrian.add(leftArm, rightArm);
box(leftArm, materials.coat, 0, -0.25, 0, 0.22, 0.54, 0.19);
box(rightArm, materials.coat, 0, -0.25, 0, 0.22, 0.54, 0.19);
box(leftArm, materials.skin, 0, -0.56, 0, 0.16, 0.16, 0.16);
box(rightArm, materials.skin, 0, -0.56, 0, 0.16, 0.16, 0.16);
box(pedestrian, materials.bag, -0.14, 0.98, -0.36, 0.34, 0.4, 0.18);
box(pedestrian, materials.wood, 0.02, 1.34, -0.33, 0.035, 0.62, 0.035);
// ---------------------------------------------------------------------
// Lanterns, background trees and small details
// ---------------------------------------------------------------------
function addLantern(x, z) {
const group = new THREE.Group();
group.position.set(x, 0.8, z);
scene.add(group);
box(group, materials.darkWood, 0, 0.9, 0, 0.13, 1.8, 0.13);
box(group, materials.stoneDark, 0, 0.06, 0, 0.38, 0.12, 0.38);
box(group, materials.darkWood, 0, 1.84, 0, 0.48, 0.09, 0.48);
box(group, materials.lantern, 0, 2.08, 0, 0.34, 0.43, 0.34);
box(group, materials.lamp, 0, 2.08, 0.18, 0.25, 0.3, 0.025);
box(group, materials.darkWood, 0, 2.34, 0, 0.47, 0.08, 0.47);
const light = new THREE.PointLight(0xff9b58, 1.25, 4.5, 2);
light.position.set(0, 2.05, 0.3);
group.add(light);
}
addLantern(3.45, 7.2);
addLantern(-2.95, -6.5);
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0.8, z);
tree.scale.setScalar(scale);
scene.add(tree);
beam(tree, materials.trunk, [0, 0, 0], [0.1, 2.6, 0], 0.35);
beam(tree, materials.trunk, [0.08, 1.8, 0], [-0.85, 3.0, 0.1], 0.19);
beam(tree, materials.trunk, [0.08, 2.0, 0], [0.95, 3.2, -0.2], 0.18);
for (let i = 0; i < 15; i++) {
box(
tree,
pick(leafMaterials),
random(-1.2, 1.2),
random(2.7, 4.0),
random(-1.1, 1.1),
random(0.55, 1.1),
random(0.5, 0.95),
random(0.55, 1.1)
);
}
}
addTree(7.1, -9.0, 1.15);
addTree(-7.2, -13.0, 1.25);
addTree(7.3, -24, 1.4);
addTree(-7.7, -27, 1.3);
// Reeds and moss at the water's edge.
for (let i = 0; i < 30; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = side * random(2.62, 3.45);
const z = random(-24, 18);
box(
scene,
random() > 0.5 ? materials.leafDark : materials.moss,
x,
random(1.0, 1.45),
z,
random(0.09, 0.18),
random(0.45, 0.95),
random(0.08, 0.16)
);
}
// Koi visible beneath the translucent water.
const fish = [];
for (let i = 0; i < 3; i++) {
const group = new THREE.Group();
group.position.set(random(-1.5, 1.5), -0.015, random(-14, 13));
scene.add(group);
box(group, i === 1 ? materials.koiPale : materials.koi, 0, 0, 0, 0.58, 0.09, 0.18);
box(group, materials.koi, -0.37, 0, 0, 0.22, 0.075, 0.12);
box(group, materials.koi, 0.05, 0, 0.13, 0.18, 0.06, 0.1);
fish.push({
group,
speed: random(0.12, 0.25),
phase: random(0, Math.PI * 2),
originZ: group.position.z,
direction: random() > 0.5 ? 1 : -1
});
}
// Drifting petals.
const petals = [];
for (let i = 0; i < 34; i++) {
const petal = new THREE.Mesh(unitBox, materials.petal);
petal.scale.set(0.08, 0.025, 0.12);
petal.position.set(random(-5, 6), random(1.5, 8), random(-13, 8));
petal.rotation.set(random(0, 3), random(0, 3), random(0, 3));
scene.add(petal);
petals.push({
mesh: petal,
speed: random(0.16, 0.38),
phase: random(0, Math.PI * 2),
drift: random(0.08, 0.24)
});
}
// ---------------------------------------------------------------------
// Custom camera controls — no external controls addon
// ---------------------------------------------------------------------
const defaultView = {
target: new THREE.Vector3(0, 1.4, 1.2),
radius: 18.5,
theta: 0.77,
phi: 0.92
};
const orbit = {
target: defaultView.target.clone(),
radius: defaultView.radius,
theta: defaultView.theta,
phi: defaultView.phi
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetView() {
orbit.target.copy(defaultView.target);
orbit.radius = defaultView.radius;
orbit.theta = defaultView.theta;
orbit.phi = defaultView.phi;
updateCamera();
}
resetButton.addEventListener("click", resetView);
const pointer = {
active: false,
id: null,
x: 0,
y: 0,
button: 0
};
renderer.domElement.addEventListener("pointerdown", event => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.button = event.button;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.button === 0 && !event.shiftKey) {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.005, 0.3, 1.42);
} else {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const scale = orbit.radius * 0.00125;
orbit.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
orbit.target.x = THREE.MathUtils.clamp(orbit.target.x, -7, 7);
orbit.target.y = THREE.MathUtils.clamp(orbit.target.y, 0.5, 4.5);
orbit.target.z = THREE.MathUtils.clamp(orbit.target.z, -14, 14);
}
});
function endPointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
8,
34
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
// Walk across the stone bridge and loop.
const crossing = (elapsed % 13) / 13;
pedestrian.position.x = -2.35 + crossing * 4.7;
const path = THREE.MathUtils.clamp(
(pedestrian.position.x + 3.15) / 6.3,
0,
1
);
const deckTop = 0.99 + Math.sin(path * Math.PI) * 0.16;
const walkPhase = elapsed * 8.2;
pedestrian.position.y = deckTop + Math.abs(Math.sin(walkPhase)) * 0.022;
pedestrian.position.z = bridgeZ;
leftLeg.rotation.z = Math.sin(walkPhase) * 0.46;
rightLeg.rotation.z = -Math.sin(walkPhase) * 0.46;
leftArm.rotation.z = -Math.sin(walkPhase) * 0.34;
rightArm.rotation.z = Math.sin(walkPhase) * 0.34;
pedestrian.rotation.z = Math.sin(walkPhase * 2) * 0.012;
// Reflected ripples drift gently across the canal.
for (const ripple of ripples) {
ripple.mesh.position.x =
ripple.x + Math.sin(elapsed * ripple.speed + ripple.phase) * 0.11;
ripple.mesh.material.opacity =
ripple.baseOpacity *
(0.62 + Math.sin(elapsed * ripple.speed * 1.7 + ripple.phase) * 0.3);
}
// Petals fall around the willow and facade.
for (const petal of petals) {
petal.mesh.position.y -= delta * petal.speed;
petal.mesh.position.x +=
Math.sin(elapsed * 0.7 + petal.phase) * delta * petal.drift;
petal.mesh.rotation.x += delta * 0.7;
petal.mesh.rotation.z += delta * 0.45;
if (petal.mesh.position.y < 0.9) {
petal.mesh.position.y = random(6.8, 8.2);
petal.mesh.position.x = random(-5, 6);
petal.mesh.position.z = random(-13, 8);
}
}
// Koi swim slowly beneath the surface.
for (const koi of fish) {
koi.group.position.z +=
Math.cos(elapsed * koi.speed + koi.phase) * delta * 0.22 *
koi.direction;
koi.group.position.x +=
Math.sin(elapsed * koi.speed * 0.7 + koi.phase) * delta * 0.07;
koi.group.rotation.y =
Math.sin(elapsed * koi.speed + koi.phase) * 0.22;
if (koi.group.position.z > 15) koi.group.position.z = -15;
if (koi.group.position.z < -15) koi.group.position.z = 15;
}
updateCamera();
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
});
updateCamera();
renderer.render(scene, camera);
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```