Prompt specification
Build or customize the Three.js 3D scene "Gion Shirakawa lane and watercourse slice" 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: Gion Shirakawa lane and watercourse slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/gion-shirakawa-lane-and-watercourse-slice-x3003
Scene Description Prompt:
A voxel Kyoto Gion Shirakawa lane, with a narrow canal, small bridge, planting, and local building proportions. Three.js from cdnjs, one HTML file.
Working Three.js Starter (gion-shirakawa-lane-and-watercourse-slice-x3003):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Gion Shirakawa</title>
<style>
:root {
color-scheme: light;
font-family: Georgia, "Times New Roman", serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8cfbd;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at center, transparent 52%, rgba(45, 33, 25, 0.17) 100%);
mix-blend-mode: multiply;
}
.title-card {
position: fixed;
top: 24px;
left: 26px;
padding: 16px 19px 14px;
color: #302a24;
background: rgba(243, 236, 219, 0.86);
border: 1px solid rgba(75, 57, 42, 0.28);
box-shadow: 0 8px 28px rgba(43, 32, 24, 0.12);
backdrop-filter: blur(8px);
pointer-events: none;
user-select: none;
}
.title-card h1 {
margin: 0;
font-size: clamp(22px, 3vw, 38px);
font-weight: 500;
letter-spacing: 0.13em;
line-height: 1;
}
.title-card p {
margin: 9px 0 0;
font-family: system-ui, sans-serif;
font-size: 10px;
letter-spacing: 0.2em;
text-transform: uppercase;
opacity: 0.7;
}
.controls {
position: fixed;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
padding: 9px 14px;
color: #f4ecdc;
background: rgba(43, 38, 33, 0.78);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 2px;
font-family: system-ui, sans-serif;
font-size: 11px;
letter-spacing: 0.04em;
white-space: nowrap;
pointer-events: none;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.16);
}
.reset {
position: fixed;
right: 22px;
top: 22px;
padding: 9px 12px;
color: #eee4d4;
background: rgba(43, 38, 33, 0.78);
border: 1px solid rgba(255, 255, 255, 0.14);
font: 11px system-ui, sans-serif;
letter-spacing: 0.08em;
cursor: pointer;
}
.reset:hover {
background: rgba(57, 48, 40, 0.94);
}
@media (max-width: 600px) {
.title-card {
top: 14px;
left: 14px;
padding: 12px 14px;
}
.title-card p {
display: none;
}
.reset {
top: 14px;
right: 14px;
}
.controls {
bottom: 12px;
max-width: calc(100vw - 20px);
overflow: hidden;
text-overflow: ellipsis;
}
}
</style>
</head>
<body>
<div class="title-card">
<h1>GION</h1>
<p>Voxel Shirakawa Lane · Kyoto</p>
</div>
<button class="reset" id="reset">RESET VIEW</button>
<div class="controls">
Drag: orbit · Right-drag / Shift-drag: pan · Wheel: zoom · Double-click: reset
</div>
<div class="vignette"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8cfbd);
scene.fog = new THREE.Fog(0xd8cfbd, 28, 66);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
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;
renderer.shadowMap.autoUpdate = false;
renderer.shadowMap.needsUpdate = true;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
120
);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const mat = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.85,
metalness: options.metalness ?? 0,
flatShading: true,
...options
});
const materials = {
foundation: mat(0x746d5d),
soil: mat(0x5f594b),
roadBase: mat(0x777264),
pavement: mat(0x8b8577),
stone: mat(0x8d897d),
stoneDark: mat(0x69685f),
stoneLight: mat(0xa6a092),
plasterCream: mat(0xd7c8aa),
plasterWarm: mat(0xc7b38f),
plasterGrey: mat(0xbab8a9),
plasterPink: mat(0xc5aa98),
wood: mat(0x49392e),
woodLight: mat(0x75523b),
woodRed: mat(0x6b302b),
roof: mat(0x343b3d),
roofBlue: mat(0x39464a),
roofEdge: mat(0x252c2d),
paper: mat(0xe5d8b6, {
emissive: 0x3b2c18,
emissiveIntensity: 0.08
}),
paperGlow: mat(0xf0c984, {
emissive: 0xff9e3d,
emissiveIntensity: 0.45
}),
indigo: mat(0x334b58),
moss: mat(0x5d7046),
bamboo: mat(0x71824b),
bambooDark: mat(0x495d34),
leafGreen: mat(0x637b48),
leafLight: mat(0x849459),
blossom: mat(0xd7a2a1),
blossomLight: mat(0xe6b9b3),
maple: mat(0xa34f37),
mapleLight: mat(0xc26b43),
water: mat(0x527f7e, {
roughness: 0.22,
metalness: 0.12,
transparent: true,
opacity: 0.92
}),
ripple: new THREE.MeshBasicMaterial({
color: 0xc8dfd3,
transparent: true,
opacity: 0.32,
depthWrite: false
}),
planter: mat(0x756b59),
soilDark: mat(0x40392e)
};
const boxGeometry = new THREE.BoxGeometry(1, 1, 1);
function box(parent, size, position, material, rotation = [0, 0, 0], castShadow = true) {
const mesh = new THREE.Mesh(boxGeometry, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 481516;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const range = (a, b) => a + (b - a) * random();
// -------------------------------------------------------------------------
// Ground, paving, and canal
// -------------------------------------------------------------------------
box(scene, [31, 1.0, 44], [0, -1.1, 0], materials.foundation);
box(scene, [19, 0.65, 44], [-4, -0.25, 0], materials.soil);
box(scene, [7, 0.65, 44], [12, -0.25, 0], materials.soil);
box(scene, [8, 0.1, 44], [1.5, 0.08, 0], materials.roadBase);
box(scene, [1.8, 0.1, 44], [9.4, 0.08, 0], materials.stone);
box(scene, [3.0, 0.1, 44], [7, -0.53, 0], materials.soilDark);
// Instanced voxel paving.
const pavingColumns = 7;
const pavingRows = 40;
const paving = new THREE.InstancedMesh(
boxGeometry,
materials.pavement,
pavingColumns * pavingRows
);
const dummy = new THREE.Object3D();
const pavingColor = new THREE.Color();
let pavingIndex = 0;
for (let row = 0; row < pavingRows; row++) {
for (let column = 0; column < pavingColumns; column++) {
const offset = row % 2 === 0 ? 0 : 0.18;
dummy.position.set(
-1.5 + column * 1 + offset,
0.16 + range(-0.008, 0.008),
-20 + row + range(-0.02, 0.02)
);
dummy.scale.set(0.93, 0.07, 0.92);
dummy.rotation.set(0, range(-0.008, 0.008), 0);
dummy.updateMatrix();
paving.setMatrixAt(pavingIndex, dummy.matrix);
const shade = range(0.82, 1.05);
pavingColor.setRGB(
0.49 * shade,
0.47 * shade,
0.42 * shade
);
paving.setColorAt(pavingIndex++, pavingColor);
}
}
paving.receiveShadow = true;
scene.add(paving);
// Canal water.
const water = box(
scene,
[3.0, 0.07, 43.6],
[7, -0.27, 0],
materials.water,
[0, 0, 0],
false
);
// Individual canal-bank stones, batched into two instanced meshes.
const bankBlocks = [];
for (let z = -21; z <= 21; z += 1.05) {
bankBlocks.push([5.48, -0.15, z]);
bankBlocks.push([8.52, -0.15, z]);
}
const banks = new THREE.InstancedMesh(
boxGeometry,
materials.stone,
bankBlocks.length
);
bankBlocks.forEach((position, index) => {
dummy.position.set(
position[0],
position[1],
position[2] + range(-0.025, 0.025)
);
dummy.scale.set(0.32, range(0.54, 0.61), range(0.93, 1.02));
dummy.rotation.set(0, range(-0.018, 0.018), 0);
dummy.updateMatrix();
banks.setMatrixAt(index, dummy.matrix);
});
banks.castShadow = true;
banks.receiveShadow = true;
scene.add(banks);
box(scene, [0.4, 0.16, 44], [5.5, 0.17, 0], materials.stoneLight);
box(scene, [0.4, 0.16, 44], [8.5, 0.17, 0], materials.stoneLight);
// -------------------------------------------------------------------------
// Small arched stone bridge
// -------------------------------------------------------------------------
const bridge = new THREE.Group();
scene.add(bridge);
const bridgeSegments = 9;
const bridgeStart = 4.65;
const bridgeWidth = 0.56;
const bridgeHeights = [];
for (let i = 0; i < bridgeSegments; i++) {
const t = (i + 0.5) / bridgeSegments;
const x = bridgeStart + i * bridgeWidth;
const y = 0.24 + Math.sin(t * Math.PI) * 0.46;
bridgeHeights.push(y);
box(
bridge,
[bridgeWidth + 0.025, 0.24, 2.25],
[x, y, 0],
i % 2 ? materials.stoneLight : materials.stone
);
const railY = y + 0.78;
box(
bridge,
[bridgeWidth + 0.07, 0.16, 0.15],
[x, railY, -1.1],
materials.stoneDark
);
box(
bridge,
[bridgeWidth + 0.07, 0.16, 0.15],
[x, railY, 1.1],
materials.stoneDark
);
if (i % 2 === 0) {
box(
bridge,
[0.18, 0.86, 0.18],
[x, y + 0.38, -1.1],
materials.stone
);
box(
bridge,
[0.18, 0.86, 0.18],
[x, y + 0.38, 1.1],
materials.stone
);
}
}
// -------------------------------------------------------------------------
// Traditional low-rise machiya-style buildings
// -------------------------------------------------------------------------
function verticalSignTexture(text, background = "#d8c9a8", foreground = "#302924") {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 512;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = foreground;
context.lineWidth = 5;
context.strokeRect(8, 8, 112, 496);
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "bold 64px serif";
const characters = [...text];
const spacing = 112;
const start = 256 - ((characters.length - 1) * spacing) / 2;
characters.forEach((character, index) => {
context.fillText(character, 64, start + index * spacing);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function addLatticePanel(group, x, y, z, width, height, dark = false) {
const panelMaterial = dark ? materials.woodLight : materials.paper;
box(
group,
[width, height, 0.075],
[x, y, z],
panelMaterial
);
box(
group,
[0.065, height + 0.08, 0.13],
[x - width / 2, y, z - 0.015],
materials.wood
);
box(
group,
[0.065, height + 0.08, 0.13],
[x + width / 2, y, z - 0.015],
materials.wood
);
box(
group,
[0.055, height, 0.12],
[x, y, z - 0.025],
materials.wood
);
box(
group,
[width + 0.07, 0.07, 0.13],
[x, y - height / 2, z - 0.015],
materials.wood
);
box(
group,
[width + 0.07, 0.07, 0.13],
[x, y + height / 2, z - 0.015],
materials.wood
);
if (!dark) {
box(
group,
[width, 0.045, 0.12],
[x, y, z - 0.02],
materials.wood
);
}
}
function addRoof(group, width, depth, roofMaterial, height) {
box(
group,
[width + 0.95, 0.27, depth + 0.95],
[0, height + 0.17, 0],
materials.roofEdge
);
const layers = [
{ z: 0, y: height + 0.92, depth: depth * 0.22 },
{ z: depth * 0.24, y: height + 0.72, depth: depth * 0.27 },
{ z: -depth * 0.24, y: height + 0.72, depth: depth * 0.27 },
{ z: depth * 0.49, y: height + 0.49, depth: depth * 0.31 },
{ z: -depth * 0.49, y: height + 0.49, depth: depth * 0.31 }
];
layers.forEach((layer, layerIndex) => {
box(
group,
[width + 0.65 - layerIndex * 0.08, 0.28, layer.depth],
[0, layer.y, layer.z],
roofMaterial
);
// Sparse raised seams preserve the voxel-tile appearance without
// creating an excessive number of separate objects.
for (let seam = -3; seam <= 3; seam++) {
box(
group,
[0.035, 0.045, layer.depth * 0.93],
[seam * width * 0.14, layer.y + 0.16, layer.z],
materials.roofEdge,
[0, 0, 0],
false
);
}
});
box(
group,
[width + 0.34, 0.25, 0.34],
[0, height + 1.12, 0],
materials.roofEdge
);
}
function makeBuilding(options) {
const {
x,
z,
rotation,
width = 5.7,
depth = 6.0,
height = 6.5,
wall = materials.plasterCream,
roof = materials.roof,
sign = null,
awning = false
} = options;
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
box(
group,
[width + 0.25, 0.28, depth + 0.25],
[0, 0.14, 0],
materials.stoneDark
);
box(
group,
[width, height, depth],
[0, height / 2 + 0.18, 0],
wall
);
// Structural timber posts and floor bands.
for (const side of [-1, 1]) {
box(
group,
[0.18, height + 0.1, 0.18],
[side * (width / 2 - 0.08), height / 2 + 0.18, -depth / 2 - 0.02],
materials.wood
);
box(
group,
[0.18, height + 0.1, 0.18],
[side * (width / 2 - 0.08), height / 2 + 0.18, depth / 2 + 0.02],
materials.wood
);
}
box(
group,
[width + 0.12, 0.18, 0.17],
[0, 3.05, -depth / 2 - 0.07],
materials.wood
);
box(
group,
[width + 0.12, 0.18, 0.17],
[0, height - 0.05, -depth / 2 - 0.07],
materials.wood
);
box(
group,
[0.17, 0.17, depth + 0.1],
[width / 2 + 0.01, 3.05, 0],
materials.wood
);
box(
group,
[0.17, 0.17, depth + 0.1],
[-width / 2 - 0.01, 3.05, 0],
materials.wood
);
const front = -depth / 2 - 0.09;
const usable = width - 0.65;
const panelWidth = usable / 3;
for (let index = 0; index < 3; index++) {
const panelX = -usable / 2 + panelWidth * (index + 0.5);
addLatticePanel(
group,
panelX,
1.45,
front,
panelWidth - 0.16,
1.95,
index === 0
);
addLatticePanel(
group,
panelX,
height * 0.66,
front,
panelWidth - 0.16,
height * 0.28,
false
);
}
// Recessed doorway and indigo noren.
box(
group,
[1.12, 2.35, 0.12],
[-usable / 2 + panelWidth * 0.5, 1.2, front - 0.02],
materials.wood
);
for (let flap = 0; flap < 3; flap++) {
box(
group,
[0.31, 0.68, 0.06],
[
-usable / 2 + panelWidth * 0.5 - 0.34 + flap * 0.34,
2.05,
front - 0.12
],
materials.indigo
);
}
if (awning) {
box(
group,
[width * 0.72, 0.11, 0.72],
[0, 2.78, front - 0.31],
materials.wood,
[0.12, 0, 0]
);
}
addRoof(group, width, depth, roof, height);
if (sign) {
const texture = verticalSignTexture(sign.text, sign.bg, sign.fg);
const signMaterial = new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.9
});
const signMesh = new THREE.Mesh(
new THREE.PlaneGeometry(0.62, 2.15),
signMaterial
);
signMesh.position.set(width * 0.37, 1.65, front - 0.08);
signMesh.rotation.y = Math.PI;
signMesh.castShadow = true;
group.add(signMesh);
}
return group;
}
// West-side row: fronts face the lane.
makeBuilding({
x: -5.4,
z: -15.0,
rotation: -Math.PI / 2,
width: 5.3,
depth: 6.0,
height: 6.3,
wall: materials.plasterCream,
roof: materials.roof,
sign: { text: "小料理", bg: "#d8c9a8" }
});
makeBuilding({
x: -5.8,
z: -8.8,
rotation: -Math.PI / 2,
width: 6.1,
depth: 6.5,
height: 7.1,
wall: materials.plasterWarm,
roof: materials.roofBlue,
awning: true
});
makeBuilding({
x: -5.2,
z: -2.2,
rotation: -Math.PI / 2,
width: 5.4,
depth: 5.6,
height: 6.0,
wall: materials.plasterGrey,
roof: materials.roof
});
makeBuilding({
x: -5.7,
z: 4.3,
rotation: -Math.PI / 2,
width: 6.0,
depth: 6.4,
height: 7.0,
wall: materials.plasterPink,
roof: materials.roofBlue,
sign: { text: "茶房", bg: "#c8b998" },
awning: true
});
makeBuilding({
x: -5.2,
z: 11.1,
rotation: -Math.PI / 2,
width: 5.7,
depth: 5.9,
height: 6.4,
wall: materials.plasterCream,
roof: materials.roof
});
makeBuilding({
x: -5.6,
z: 17.3,
rotation: -Math.PI / 2,
width: 5.2,
depth: 6.0,
height: 6.7,
wall: materials.plasterWarm,
roof: materials.roof
});
// East-side row beyond the canal.
makeBuilding({
x: 13.0,
z: -14.1,
rotation: Math.PI / 2,
width: 5.6,
depth: 5.2,
height: 6.8,
wall: materials.plasterGrey,
roof: materials.roofBlue,
sign: { text: "祇園", bg: "#d2bd91" }
});
makeBuilding({
x: 12.7,
z: -7.8,
rotation: Math.PI / 2,
width: 5.1,
depth: 4.6,
height: 6.2,
wall: materials.plasterCream,
roof: materials.roof,
awning: true
});
makeBuilding({
x: 13.2,
z: 3.7,
rotation: Math.PI / 2,
width: 6.0,
depth: 5.5,
height: 7.0,
wall: materials.plasterWarm,
roof: materials.roof
});
makeBuilding({
x: 12.9,
z: 10.3,
rotation: Math.PI / 2,
width: 5.5,
depth: 5.0,
height: 6.5,
wall: materials.plasterPink,
roof: materials.roofBlue,
sign: { text: "料理", bg: "#d4c5a5" }
});
makeBuilding({
x: 13.3,
z: 16.8,
rotation: Math.PI / 2,
width: 5.0,
depth: 5.3,
height: 6.9,
wall: materials.plasterGrey,
roof: materials.roof
});
// -------------------------------------------------------------------------
// Planting and street details
// -------------------------------------------------------------------------
function planter(x, z, width = 1.25, depth = 0.9) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(
group,
[width, 0.42, depth],
[0, 0.21, 0],
materials.planter
);
box(
group,
[width - 0.18, 0.06, depth - 0.18],
[0, 0.44, 0],
materials.soilDark
);
return group;
}
function bambooCluster(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
for (let stem = 0; stem < 6; stem++) {
const stemX = range(-0.48, 0.48);
const stemZ = range(-0.38, 0.38);
const height = range(3.0, 5.2);
const lean = range(-0.07, 0.07);
const rotation = [0, range(-0.2, 0.2), lean];
box(
group,
[0.09, height, 0.09],
[stemX, height / 2 + 0.35, stemZ],
stem % 2 ? materials.bamboo : materials.bambooDark,
rotation
);
for (let band = 1; band <= 4; band++) {
const bandY = 0.35 + height * band / 5;
box(
group,
[0.115, 0.055, 0.115],
[
stemX + Math.sin(lean) * bandY * -1,
bandY,
stemZ
],
materials.bambooDark,
rotation,
false
);
}
for (let leaf = 0; leaf < 5; leaf++) {
const leafY = range(1.8, height);
const side = random() > 0.5 ? 1 : -1;
box(
group,
[0.72, 0.035, 0.18],
[
stemX + side * 0.34,
leafY,
stemZ + range(-0.25, 0.25)
],
leaf % 2 ? materials.leafGreen : materials.leafLight,
[range(-0.35, 0.35), range(-0.5, 0.5), range(-0.4, 0.4)]
);
}
}
}
function voxelTree(x, z, blossomTree = true) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(group, [0.46, 1.8, 0.46], [0, 1.1, 0], materials.wood);
box(group, [0.31, 1.2, 0.31], [0.12, 2.3, 0.02], materials.woodLight);
box(
group,
[1.15, 0.2, 0.2],
[0.42, 2.35, 0],
materials.wood,
[0, 0, 0.34]
);
box(
group,
[0.95, 0.18, 0.18],
[-0.34, 2.7, 0.1],
materials.wood,
[0.2, 0.5, -0.2]
);
const leafMaterials = blossomTree
? [materials.blossom, materials.blossomLight]
: [materials.maple, materials.mapleLight];
for (let i = 0; i < 34; i++) {
const angle = random() * Math.PI * 2;
const radius = range(0.3, 1.7);
const leafX = Math.cos(angle) * radius;
const leafZ = Math.sin(angle) * radius * 0.8;
const leafY = range(2.65, 4.3) - radius * 0.12;
const size = range(0.42, 0.92);
box(
group,
[size, size * range(0.65, 1), size],
[leafX, leafY, leafZ],
leafMaterials[i % leafMaterials.length],
[range(-0.16, 0.16), range(-0.4, 0.4), range(-0.16, 0.16)]
);
}
}
function shrubPlanter(x, z, width = 1.4, depth = 0.8) {
const group = planter(x, z, width, depth);
for (let i = 0; i < 9; i++) {
box(
group,
[range(0.35, 0.62), range(0.32, 0.65), range(0.35, 0.58)],
[
range(-width * 0.38, width * 0.38),
range(0.58, 0.85),
range(-depth * 0.28, depth * 0.28)
],
i % 3 ? materials.leafGreen : materials.leafLight,
[0, range(-0.5, 0.5), range(-0.15, 0.15)]
);
}
}
function stoneLantern(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(group, [0.56, 0.16, 0.56], [0, 0.08, 0], materials.stoneDark);
box(group, [0.22, 1.0, 0.22], [0, 0.63, 0], materials.stone);
box(group, [0.58, 0.16, 0.58], [0, 1.19, 0], materials.stoneLight);
box(group, [0.42, 0.5, 0.42], [0, 1.52, 0], materials.paperGlow);
box(group, [0.58, 0.15, 0.58], [0, 1.83, 0], materials.stone);
box(group, [0.34, 0.16, 0.34], [0, 1.96, 0], materials.stoneDark);
}
// Canal-side bamboo.
bambooCluster(8.95, -16.2, 0.9);
bambooCluster(8.95, -10.0, 1.0);
bambooCluster(8.95, 7.1, 0.92);
bambooCluster(8.95, 13.4, 1.05);
// Potted trees.
const cherryPot = planter(-1.7, 7.7, 1.55, 1.25);
const maplePot = planter(9.45, -6.5, 1.45, 1.2);
// Trees are positioned relative to their pots.
const cherry = new THREE.Group();
cherry.position.set(-1.7, 0.48, 7.7);
scene.add(cherry);
const maple = new THREE.Group();
maple.position.set(9.45, 0.48, -6.5);
scene.add(maple);
function populateTree(group, blossomTree) {
box(group, [0.42, 1.8, 0.42], [0, 1.05, 0], materials.wood);
box(group, [0.28, 1.1, 0.28], [0.12, 2.15, 0], materials.woodLight);
box(group, [1.05, 0.18, 0.18], [0.35, 2.2, 0], materials.wood, [0, 0, 0.35]);
box(group, [0.9, 0.16, 0.16], [-0.28, 2.55, 0.08], materials.wood, [0.2, 0.5, -0.2]);
const leafMaterials = blossomTree
? [materials.blossom, materials.blossomLight]
: [materials.maple, materials.mapleLight];
for (let i = 0; i < 36; i++) {
const angle = random() * Math.PI * 2;
const radius = range(0.25, 1.55);
const size = range(0.42, 0.9);
box(
group,
[size, size * range(0.65, 1), size],
[
Math.cos(angle) * radius,
range(2.45, 4.05) - radius * 0.1,
Math.sin(angle) * radius * 0.78
],
leafMaterials[i % 2],
[range(-0.16, 0.16), range(-0.4, 0.4), range(-0.16, 0.16)]
);
}
}
populateTree(cherry, true);
populateTree(maple, false);
shrubPlanter(4.85, -4.8, 1.0, 0.65);
shrubPlanter(4.8, 5.9, 1.05, 0.72);
shrubPlanter(9.5, 14.4, 1.2, 0.75);
shrubPlanter(-2.0, -11.0, 0.85, 0.7);
stoneLantern(5.0, -0.8);
stoneLantern(8.95, 1.15);
// Small square floating leaves.
for (let i = 0; i < 15; i++) {
box(
scene,
[range(0.12, 0.27), 0.018, range(0.12, 0.28)],
[range(5.8, 8.15), -0.215, range(-19, 19)],
i % 3 === 0 ? materials.blossom : materials.leafGreen,
[0, range(-0.5, 0.5), 0],
false
);
}
// Drain grates and utility covers.
for (const z of [-12.5, -4.2, 8.8, 15.5]) {
box(
scene,
[0.72, 0.04, 0.55],
[4.85, 0.225, z],
materials.stoneDark
);
for (let slot = -2; slot <= 2; slot++) {
box(
scene,
[0.055, 0.045, 0.46],
[4.85 + slot * 0.12, 0.25, z],
materials.roadBase,
[0, 0, 0],
false
);
}
}
// -------------------------------------------------------------------------
// Water ripples
// -------------------------------------------------------------------------
const ripples = [];
for (let i = 0; i < 30; i++) {
const ripple = box(
scene,
[range(0.25, 0.85), 0.012, 0.025],
[range(5.8, 8.1), -0.22, range(-21, 21)],
materials.ripple,
[0, range(-0.08, 0.08), 0],
false
);
ripple.userData.speed = range(0.22, 0.52);
ripple.userData.baseX = ripple.position.x;
ripple.userData.phase = random() * Math.PI * 2;
ripples.push(ripple);
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf3ead5, 0x5e6252, 1.75);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffe0ae, 3.1);
sunlight.position.set(-13, 24, 12);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -24;
sunlight.shadow.camera.right = 24;
sunlight.shadow.camera.top = 26;
sunlight.shadow.camera.bottom = -26;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 65;
sunlight.shadow.normalBias = 0.035;
sunlight.shadow.bias = -0.00015;
scene.add(sunlight);
const fillLight = new THREE.DirectionalLight(0x91a9b1, 0.48);
fillLight.position.set(14, 9, -18);
scene.add(fillLight);
const bridgeGlow = new THREE.PointLight(0xffa64c, 2.0, 7, 2);
bridgeGlow.position.set(7.2, 1.6, 1.4);
scene.add(bridgeGlow);
// -------------------------------------------------------------------------
// Direct camera controls, implemented without Three.js addons
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(1.0, 2.0, -0.5),
theta: 0.62,
phi: 1.04,
radius: 31
};
const initialControls = {
target: controls.target.clone(),
theta: controls.theta,
phi: controls.phi,
radius: controls.radius
};
function updateCamera() {
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);
}
function resetView() {
controls.target.copy(initialControls.target);
controls.theta = initialControls.theta;
controls.phi = initialControls.phi;
controls.radius = initialControls.radius;
updateCamera();
}
let dragging = false;
let dragMode = "orbit";
let previousX = 0;
let previousY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
dragging = true;
dragMode =
event.button === 2 || event.shiftKey || event.ctrlKey
? "pan"
: "orbit";
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;
previousX = event.clientX;
previousY = event.clientY;
if (dragMode === "orbit") {
controls.theta -= dx * 0.0055;
controls.phi -= dy * 0.0045;
controls.phi = THREE.MathUtils.clamp(
controls.phi,
0.34,
1.46
);
} else {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const scale = controls.radius * 0.0016;
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(forward, -dy * scale);
controls.target.x = THREE.MathUtils.clamp(
controls.target.x,
-7,
10
);
controls.target.z = THREE.MathUtils.clamp(
controls.target.z,
-18,
18
);
controls.target.y = THREE.MathUtils.clamp(
controls.target.y,
1.1,
4.0
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.radius *= Math.exp(event.deltaY * 0.001);
controls.radius = THREE.MathUtils.clamp(
controls.radius,
8,
52
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
water.material.opacity = 0.9 + Math.sin(elapsed * 0.7) * 0.025;
for (const ripple of ripples) {
ripple.position.z += ripple.userData.speed * 0.016;
if (ripple.position.z > 21.5) {
ripple.position.z = -21.5;
}
ripple.position.x =
ripple.userData.baseX +
Math.sin(elapsed * 0.8 + ripple.userData.phase) * 0.08;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
animate();
</script>
</body>
</html>
```