Prompt specification
Build or customize the Three.js 3D scene "Georgetown canal lock-gate corner" 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: Georgetown canal lock-gate corner
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/georgetown-canal-lock-gate-corner-x2797
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing the canal in Washington's Georgetown neighborhood. Model a referenced C&O Canal lock-gate corner with masonry wall and water channel. Show the hinge location and distinguish the chamber from the adjacent towpath. Low-poly.
Working Three.js Starter (georgetown-canal-lock-gate-corner-x2797):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>C&O Canal — Georgetown Lock-Gate Corner</title>
<style>
:root {
--ink: #24312f;
--paper: rgba(248, 244, 232, 0.94);
--line: rgba(36, 49, 47, 0.24);
--gold: #e5a52e;
--water: #34899a;
--path: #b49a70;
--stone: #9f9b8f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8d5ce;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 12px 32px rgba(30, 43, 39, 0.14);
backdrop-filter: blur(9px);
}
#title-card {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 17px 19px 16px;
border-top: 5px solid var(--gold);
}
#title-card .eyebrow {
margin-bottom: 7px;
color: #68716c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
#title-card h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(23px, 3vw, 31px);
font-weight: 500;
line-height: 1.08;
}
#title-card p {
margin: 9px 0 0;
color: #59645f;
font-size: 12px;
line-height: 1.45;
}
#legend {
top: 18px;
right: 18px;
min-width: 205px;
padding: 13px 15px;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin: 7px 0;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.03em;
}
.swatch {
width: 17px;
height: 10px;
flex: 0 0 auto;
border: 1px solid rgba(0, 0, 0, 0.15);
}
.swatch.water {
background: var(--water);
}
.swatch.path {
background: var(--path);
}
.swatch.stone {
background: var(--stone);
}
.swatch.hinge {
background: var(--gold);
}
#controls {
right: 18px;
bottom: 18px;
display: flex;
gap: 8px;
padding: 8px;
}
button {
appearance: none;
border: 1px solid rgba(36, 49, 47, 0.23);
border-radius: 2px;
background: #fffdf5;
padding: 8px 11px;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
cursor: pointer;
}
button:hover,
button:focus-visible {
background: #f0e8d6;
outline: 2px solid rgba(229, 165, 46, 0.45);
outline-offset: 2px;
}
#hint {
left: 18px;
bottom: 18px;
padding: 10px 13px;
color: #4f5c57;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.05em;
}
#leaders {
position: fixed;
inset: 0;
z-index: 4;
width: 100%;
height: 100%;
pointer-events: none;
overflow: visible;
}
#leaders line {
stroke-width: 1.35;
stroke-linecap: round;
}
#leaders circle {
stroke-width: 1.5;
}
.callout {
position: fixed;
z-index: 5;
min-width: 138px;
max-width: 210px;
padding: 8px 10px 8px 11px;
border-left: 4px solid var(--gold);
background: rgba(250, 247, 237, 0.95);
box-shadow: 0 5px 16px rgba(28, 39, 36, 0.16);
pointer-events: none;
transform: translate(-50%, -50%);
}
.callout strong {
display: block;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.09em;
line-height: 1.2;
text-transform: uppercase;
}
.callout span {
display: block;
margin-top: 3px;
color: #68716d;
font-size: 9px;
line-height: 1.3;
}
#label-hinge {
border-left-color: #e5a52e;
}
#label-gate {
border-left-color: #73553d;
}
#label-chamber {
border-left-color: #34899a;
}
#label-towpath {
border-left-color: #a8875d;
}
#label-wall {
border-left-color: #8d8a80;
}
@media (max-width: 720px) {
#legend {
display: none;
}
#title-card {
width: calc(100vw - 36px);
padding: 13px 15px;
}
#title-card p {
display: none;
}
#hint {
display: none;
}
#controls {
right: 12px;
bottom: 12px;
}
.callout {
min-width: 105px;
max-width: 145px;
padding: 6px 7px;
}
.callout span {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport" aria-label="Interactive low-poly model of a C and O Canal lock gate in Georgetown"></div>
<svg id="leaders" aria-hidden="true"></svg>
<section id="title-card" class="panel">
<div class="eyebrow">Interpretive low-poly reconstruction</div>
<h1>C&O Canal<br>Georgetown Lock</h1>
<p>
A timber miter gate, masonry lock wall, upper chamber, and adjacent
towpath. The gold marker identifies the cast-iron gate hinge.
</p>
</section>
<aside id="legend" class="panel" aria-label="Scene legend">
<div class="legend-row">
<span class="swatch water"></span>
Upper lock chamber
</div>
<div class="legend-row">
<span class="swatch path"></span>
Adjacent dry towpath
</div>
<div class="legend-row">
<span class="swatch stone"></span>
Masonry lock wall
</div>
<div class="legend-row">
<span class="swatch hinge"></span>
Gate hinge location
</div>
</aside>
<div id="hint" class="panel">
DRAG TO ORBIT · WHEEL TO ZOOM · RIGHT-DRAG TO PAN
</div>
<div id="controls" class="panel">
<button id="reset-view" type="button">RESET VIEW</button>
<button id="plan-view" type="button">PLAN VIEW</button>
</div>
<div id="label-hinge" class="callout">
<strong>Gate hinge</strong>
<span>Cast-iron pintle at the masonry corner</span>
</div>
<div id="label-gate" class="callout">
<strong>Miter gate</strong>
<span>Timber leaves with iron reinforcing straps</span>
</div>
<div id="label-chamber" class="callout">
<strong>Lock chamber</strong>
<span>Higher water level behind the closed gate</span>
</div>
<div id="label-towpath" class="callout">
<strong>Adjacent towpath</strong>
<span>Dry pedestrian edge beside the chamber</span>
</div>
<div id="label-wall" class="callout">
<strong>Masonry wall</strong>
<span>Stone coping and gate abutment</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd8d0);
scene.fog = new THREE.Fog(0xcbd8d0, 42, 88);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
160
);
const view = {
target: new THREE.Vector3(-1.5, 0.4, 0),
radius: 37,
theta: 0.69,
phi: 0.86
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.cos(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.sin(view.theta)
);
camera.lookAt(view.target);
camera.updateMatrixWorld();
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xe9f4ed, 0x6e6957, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d4, 3.0);
sun.position.set(-18, 32, 20);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 85;
sun.shadow.bias = -0.00018;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbdd6df, 0.65);
fill.position.set(20, 12, -18);
scene.add(fill);
// Stable pseudo-random values keep the model consistent between reloads.
let randomSeed = 481516;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const materials = {
grass: new THREE.MeshStandardMaterial({
color: 0x7f8e70,
roughness: 1,
flatShading: true
}),
earth: new THREE.MeshStandardMaterial({
color: 0x766e5a,
roughness: 1,
flatShading: true
}),
path: new THREE.MeshStandardMaterial({
color: 0xb69b70,
roughness: 1,
flatShading: true
}),
gravel: new THREE.MeshStandardMaterial({
color: 0xc2ab85,
roughness: 1,
flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0x735039,
roughness: 0.92,
flatShading: true
}),
woodDark: new THREE.MeshStandardMaterial({
color: 0x493326,
roughness: 0.95,
flatShading: true
}),
iron: new THREE.MeshStandardMaterial({
color: 0x252c2c,
roughness: 0.58,
metalness: 0.65,
flatShading: true
}),
hingeGold: new THREE.MeshStandardMaterial({
color: 0xf2b536,
emissive: 0x8a4a00,
emissiveIntensity: 0.75,
roughness: 0.35,
metalness: 0.55
}),
brick: new THREE.MeshStandardMaterial({
color: 0x8c5848,
roughness: 1,
flatShading: true
}),
roof: new THREE.MeshStandardMaterial({
color: 0x4e5552,
roughness: 1,
flatShading: true
}),
window: new THREE.MeshStandardMaterial({
color: 0x9eacb0,
emissive: 0x263437,
emissiveIntensity: 0.18,
roughness: 0.35,
flatShading: true
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x65503b,
roughness: 1,
flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x62795d,
roughness: 1,
flatShading: true
})
};
function makeBox(
width,
height,
depth,
x,
y,
z,
material,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
scene.add(mesh);
return mesh;
}
function makeCylinder(
radiusTop,
radiusBottom,
height,
x,
y,
z,
material,
radialSegments = 8
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Terrain, towpath, and contextual Georgetown forms
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(120, 100),
materials.grass
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.34;
ground.receiveShadow = true;
scene.add(ground);
// Canal bed and banks.
makeBox(
43,
0.42,
8.7,
1.5,
-0.48,
0,
materials.earth,
false,
true
);
// Dry towpath beside the near wall.
makeBox(
40.5,
0.28,
3.55,
1.5,
1.12,
6.52,
materials.path
);
// Sparse gravel on the towpath.
const gravelCount = 210;
const gravel = new THREE.InstancedMesh(
new THREE.DodecahedronGeometry(0.115, 0),
materials.gravel,
gravelCount
);
const dummy = new THREE.Object3D();
for (let i = 0; i < gravelCount; i++) {
dummy.position.set(
-18.2 + random() * 40,
1.275 + random() * 0.025,
4.93 + random() * 3.15
);
dummy.rotation.set(random() * 0.5, random() * Math.PI, random() * 0.5);
const scale = 0.45 + random() * 0.9;
dummy.scale.set(scale, 0.28 + random() * 0.22, scale);
dummy.updateMatrix();
gravel.setMatrixAt(i, dummy.matrix);
}
gravel.receiveShadow = true;
scene.add(gravel);
// Historic-style short safety posts along the towpath edge.
for (let x = -15; x <= 18; x += 6.5) {
makeCylinder(
0.13,
0.18,
0.9,
x,
1.68,
4.92,
materials.iron,
7
);
makeCylinder(
0.19,
0.19,
0.08,
x,
2.16,
4.92,
materials.iron,
8
);
}
// -------------------------------------------------------------------------
// Masonry lock walls
// -------------------------------------------------------------------------
const stoneMatrices = [];
const stoneColors = [];
const stoneColor = new THREE.Color();
function addStoneMatrix(
x,
y,
z,
width,
height,
depth,
rotationY = 0
) {
dummy.position.set(x, y, z);
dummy.rotation.set(0, rotationY, 0);
dummy.scale.set(width, height, depth);
dummy.updateMatrix();
stoneMatrices.push(dummy.matrix.clone());
const shade = 0.73 + random() * 0.22;
stoneColor.setRGB(
shade * (0.91 + random() * 0.07),
shade * (0.89 + random() * 0.06),
shade * (0.81 + random() * 0.06)
);
stoneColors.push(stoneColor.clone());
}
function buildWallX(x0, x1, z, height, thickness) {
const rowHeight = 0.35;
const rows = Math.ceil(height / rowHeight);
for (let row = 0; row < rows; row++) {
let x = x0;
const stagger = row % 2 ? 0.5 : 0;
while (x < x1) {
const length = Math.min(
1.05 + random() * 0.55,
x1 - x
);
if (length > 0.08) {
addStoneMatrix(
x + length / 2,
0.17 + row * 0.37,
z + (random() - 0.5) * 0.035,
length - 0.035,
0.345,
thickness,
(random() - 0.5) * 0.018
);
}
x += length + (stagger && x === x0 ? 0.25 : 0);
}
}
// Continuous coping blocks.
for (let x = x0; x < x1; x += 1.22) {
const length = Math.min(1.18, x1 - x);
addStoneMatrix(
x + length / 2,
height + 0.08,
z,
length - 0.025,
0.17,
thickness + 0.13,
0
);
}
}
function buildWallZ(z0, z1, x, height, thickness) {
const rowHeight = 0.35;
const rows = Math.ceil(height / rowHeight);
for (let row = 0; row < rows; row++) {
let z = z0;
while (z < z1) {
const length = Math.min(1.08 + random() * 0.48, z1 - z);
if (length > 0.08) {
addStoneMatrix(
x,
0.17 + row * 0.37,
z + length / 2,
thickness,
0.345,
length - 0.035,
0
);
}
z += length;
}
}
}
// Far masonry wall, with the highlighted gate hinge on its inner face.
buildWallX(-18.5, 22, -4.03, 1.48, 0.88);
// Near wall is slightly lower so the water channel remains readable.
buildWallX(-18.5, 22, 4.03, 1.18, 0.88);
// Masonry return that forms the historic gate corner.
buildWallZ(-8.1, -4.25, 8.15, 1.48, 0.9);
const stone = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
}),
stoneMatrices.length
);
stoneMatrices.forEach((matrix, i) => {
stone.setMatrixAt(i, matrix);
stone.setColorAt(i, stoneColors[i]);
});
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
// Large dressed-stone gate abutments.
makeBox(
1.55,
2.35,
1.0,
7.45,
1.0,
-3.78,
materials.path
);
makeBox(
1.55,
2.1,
1.0,
7.45,
0.88,
3.78,
materials.path
);
// -------------------------------------------------------------------------
// Low-poly water: higher chamber and lower downstream reach
// -------------------------------------------------------------------------
const waterAnimations = [];
function createWater(x0, x1, z0, z1, baseY, baseHex, variance = 0.035) {
const width = x1 - x0;
const depth = z1 - z0;
const segmentsX = Math.max(8, Math.round(width / 1.45));
const segmentsZ = 5;
let geometry = new THREE.PlaneGeometry(
width,
depth,
segmentsX,
segmentsZ
);
geometry.rotateX(-Math.PI / 2);
geometry = geometry.toNonIndexed();
const positions = geometry.attributes.position;
const colors = [];
const color = new THREE.Color();
for (let i = 0; i < positions.count; i += 3) {
color.setHex(baseHex);
color.offsetHSL(
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.08,
(random() - 0.5) * variance
);
for (let j = 0; j < 3; j++) {
colors.push(color.r, color.g, color.b);
}
}
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.28,
metalness: 0.06,
transparent: true,
opacity: 0.92,
flatShading: true,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set((x0 + x1) / 2, baseY, (z0 + z1) / 2);
mesh.receiveShadow = true;
scene.add(mesh);
waterAnimations.push({
geometry,
phase: random() * Math.PI * 2
});
return mesh;
}
createWater(
-18.35,
6.55,
-3.57,
3.57,
0.13,
0x348b9d,
0.045
);
createWater(
6.55,
22,
-3.57,
3.57,
-0.14,
0x286f7f,
0.04
);
// -------------------------------------------------------------------------
// Timber miter gate and iron hardware
// -------------------------------------------------------------------------
function createGateLeaf(start, end) {
const dx = end.x - start.x;
const dz = end.z - start.z;
const length = Math.hypot(dx, dz);
const group = new THREE.Group();
group.position.set(
(start.x + end.x) / 2,
0,
(start.z + end.z) / 2
);
group.rotation.y = -Math.atan2(dz, dx);
const plankCount = Math.ceil(length / 0.33);
const plankWidth = length / plankCount;
for (let i = 0; i < plankCount; i++) {
const plank = new THREE.Mesh(
new THREE.BoxGeometry(plankWidth - 0.022, 2.18, 0.31),
i % 3 === 0 ? materials.woodDark : materials.wood
);
plank.position.set(
-length / 2 + (i + 0.5) * plankWidth,
1.28,
0
);
plank.castShadow = true;
plank.receiveShadow = true;
group.add(plank);
}
// Horizontal iron straps.
[0.48, 1.95].forEach((y) => {
const strap = new THREE.Mesh(
new THREE.BoxGeometry(length + 0.07, 0.15, 0.39),
materials.iron
);
strap.position.y = y;
strap.castShadow = true;
group.add(strap);
const boltCount = Math.max(3, Math.round(length / 0.85));
for (let i = 0; i < boltCount; i++) {
const bolt = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 6, 4),
materials.iron
);
bolt.position.set(
-length / 2 + ((i + 0.5) * length) / boltCount,
y + 0.115,
0
);
bolt.castShadow = true;
group.add(bolt);
}
});
scene.add(group);
return group;
}
const gateCenter = new THREE.Vector3(5.35, 0, 0);
const farHinge = new THREE.Vector3(7.05, 0, -3.22);
const nearHinge = new THREE.Vector3(7.05, 0, 3.22);
createGateLeaf(farHinge, gateCenter);
createGateLeaf(nearHinge, gateCenter);
// Heavy miter post at the meeting point.
makeBox(
0.55,
2.75,
0.58,
gateCenter.x,
1.26,
gateCenter.z,
materials.woodDark
);
makeBox(
0.75,
0.15,
0.78,
gateCenter.x,
2.48,
gateCenter.z,
materials.iron
);
// The highlighted hinge is a vertical pintle seated on a base plate.
makeCylinder(
0.15,
0.18,
2.72,
farHinge.x,
1.35,
farHinge.z,
materials.iron,
10
);
makeCylinder(
0.31,
0.34,
0.09,
farHinge.x,
0.18,
farHinge.z,
materials.iron,
10
);
const hingeBand = new THREE.Mesh(
new THREE.TorusGeometry(0.23, 0.065, 6, 18),
materials.hingeGold
);
hingeBand.rotation.x = Math.PI / 2;
hingeBand.position.set(farHinge.x, 1.32, farHinge.z);
hingeBand.castShadow = true;
scene.add(hingeBand);
const hingeHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.52, 0.025, 5, 28),
new THREE.MeshBasicMaterial({
color: 0xffbb38,
transparent: true,
opacity: 0.62,
depthWrite: false
})
);
hingeHalo.rotation.x = Math.PI / 2;
hingeHalo.position.set(farHinge.x, 0.28, farHinge.z);
scene.add(hingeHalo);
// Small hovering locator above the hinge.
const hingeMarker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.22),
materials.hingeGold
);
hingeMarker.position.set(farHinge.x, 3.22, farHinge.z);
hingeMarker.castShadow = true;
scene.add(hingeMarker);
// -------------------------------------------------------------------------
// Low-poly neighborhood context
// -------------------------------------------------------------------------
function addTree(x, z, scale = 1) {
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.29, 2.7, 6),
materials.trunk
);
trunk.position.set(x, 1.0, z);
trunk.scale.setScalar(scale);
trunk.castShadow = true;
scene.add(trunk);
const crown = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.65, 0),
materials.leaf
);
crown.position.set(x, 3.0, z);
crown.scale.set(scale * 1.1, scale * 1.25, scale);
crown.rotation.set(random(), random(), random());
crown.castShadow = true;
scene.add(crown);
}
[
[-22, -11, 1.2],
[-17.5, -12.5, 0.9],
[13, -11.5, 1.1],
[18, -13, 1.35],
[25, -9, 0.95],
[29, 9, 1.1]
].forEach((values) => addTree(...values));
function addBuilding(x, z, width, height, depth, brickColor) {
const brickMaterial = materials.brick.clone();
brickMaterial.color.setHex(brickColor);
const building = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
brickMaterial
);
building.position.set(x, height / 2, z);
building.castShadow = true;
building.receiveShadow = true;
scene.add(building);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(width * 0.72, 1.6, 4),
materials.roof
);
roof.position.set(x, height + 0.8, z);
roof.rotation.y = Math.PI / 4;
roof.scale.z = depth / width;
roof.castShadow = true;
scene.add(roof);
const columns = Math.max(2, Math.floor(width / 1.7));
const rows = Math.max(2, Math.floor(height / 1.8));
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const windowMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 0.75, 0.08),
materials.window
);
windowMesh.position.set(
x - width / 2 + ((col + 1) * width) / (columns + 1),
1.25 + row * 1.55,
z + depth / 2 + 0.045
);
scene.add(windowMesh);
}
}
}
addBuilding(-12.5, -15.5, 8.2, 6.5, 5.8, 0x915a48);
addBuilding(-3.2, -16.7, 8.8, 7.3, 5.6, 0xa06950);
addBuilding(7.1, -17.2, 8.2, 6.2, 5.8, 0x815246);
// A simple milestone at the towpath.
makeBox(
0.35,
1.65,
0.32,
-11.4,
2.07,
7.65,
materials.woodDark
);
makeBox(
0.72,
0.62,
0.12,
-11.4,
2.85,
7.65,
materials.wood
);
// -------------------------------------------------------------------------
// Camera controls implemented directly, without addons
// -------------------------------------------------------------------------
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
const panRight = new THREE.Vector3();
const panForward = new THREE.Vector3();
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
panRight.setFromMatrixColumn(camera.matrix, 0);
panForward.setFromMatrixColumn(camera.matrix, 2);
panRight.y = 0;
panForward.y = 0;
panRight.normalize();
panForward.normalize();
const scale = view.radius * 0.0011;
view.target.addScaledVector(panRight, -dx * scale);
view.target.addScaledVector(panForward, dy * scale);
} else {
view.theta -= dx * 0.0052;
view.phi -= dy * 0.0045;
view.phi = THREE.MathUtils.clamp(view.phi, 0.16, 1.34);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
panning = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius *= Math.exp(event.deltaY * 0.001);
view.radius = THREE.MathUtils.clamp(view.radius, 15, 72);
updateCamera();
},
{ passive: false }
);
document.getElementById("reset-view").addEventListener("click", () => {
view.target.set(-1.5, 0.4, 0);
view.radius = 37;
view.theta = 0.69;
view.phi = 0.86;
updateCamera();
});
document.getElementById("plan-view").addEventListener("click", () => {
view.target.set(0, 0.3, 0);
view.radius = 38;
view.theta = 0.08;
view.phi = 0.18;
updateCamera();
});
// -------------------------------------------------------------------------
// Projected HTML annotations and leader lines
// -------------------------------------------------------------------------
const svgNamespace = "http://www.w3.org/2000/svg";
const leaderSvg = document.getElementById("leaders");
const annotations = [
{
element: document.getElementById("label-hinge"),
anchor: new THREE.Vector3(farHinge.x, 2.0, farHinge.z),
offset: new THREE.Vector2(80, -46),
color: "#c27d09"
},
{
element: document.getElementById("label-gate"),
anchor: new THREE.Vector3(6.05, 2.25, 0.05),
offset: new THREE.Vector2(75, 28),
color: "#684b36"
},
{
element: document.getElementById("label-chamber"),
anchor: new THREE.Vector3(-5.0, 0.25, 0.15),
offset: new THREE.Vector2(-65, 42),
color: "#287e91"
},
{
element: document.getElementById("label-towpath"),
anchor: new THREE.Vector3(-8.0, 1.35, 6.45),
offset: new THREE.Vector2(-40, 52),
color: "#9b7748"
},
{
element: document.getElementById("label-wall"),
anchor: new THREE.Vector3(-10.5, 1.5, -4.0),
offset: new THREE.Vector2(-58, -42),
color: "#77746c"
}
];
annotations.forEach((annotation) => {
annotation.line = document.createElementNS(svgNamespace, "line");
annotation.line.setAttribute("stroke", annotation.color);
annotation.line.setAttribute("stroke-opacity", "0.82");
leaderSvg.appendChild(annotation.line);
annotation.dot = document.createElementNS(svgNamespace, "circle");
annotation.dot.setAttribute("r", "3.2");
annotation.dot.setAttribute("fill", annotation.color);
annotation.dot.setAttribute("stroke", "#fffdf4");
leaderSvg.appendChild(annotation.dot);
});
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
annotations.forEach((annotation) => {
projected.copy(annotation.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
annotation.element.style.display = visible ? "block" : "none";
annotation.line.style.display = visible ? "block" : "none";
annotation.dot.style.display = visible ? "block" : "none";
if (!visible) return;
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const labelX = anchorX + annotation.offset.x;
const labelY = anchorY + annotation.offset.y;
annotation.element.style.left = `${labelX}px`;
annotation.element.style.top = `${labelY}px`;
annotation.line.setAttribute("x1", anchorX);
annotation.line.setAttribute("y1", anchorY);
annotation.line.setAttribute("x2", labelX);
annotation.line.setAttribute("y2", labelY);
annotation.dot.setAttribute("cx", anchorX);
annotation.dot.setAttribute("cy", anchorY);
});
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
leaderSvg.setAttribute("viewBox", `0 0 ${width} ${height}`);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Subtle low-poly water motion.
waterAnimations.forEach((water, waterIndex) => {
const position = water.geometry.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.72 + elapsed * 0.82 + water.phase) * 0.018 +
Math.cos(z * 1.23 + elapsed * 0.57) * 0.012;
position.setY(i, wave);
}
position.needsUpdate = true;
water.geometry.computeVertexNormals();
});
const pulse = 1 + Math.sin(elapsed * 2.4) * 0.12;
hingeHalo.scale.set(pulse, pulse, pulse);
hingeHalo.material.opacity = 0.48 + Math.sin(elapsed * 2.4) * 0.15;
hingeMarker.rotation.y = elapsed * 0.85;
hingeMarker.position.y = 3.22 + Math.sin(elapsed * 1.8) * 0.07;
updateAnnotations();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```