Prompt specification
Build or customize the Three.js 3D scene "Jordaan stoop and canal-side bicycle rail" 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: Jordaan stoop and canal-side bicycle rail
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/jordaan-stoop-and-canal-side-bicycle-rail-x2801
Scene Description Prompt:
A voxel Amsterdam Jordaan stoop and canal-side bicycle rail, separating raised doorway from public path. Three.js from cdnjs, one HTML file.
Working Three.js Starter (jordaan-stoop-and-canal-side-bicycle-rail-x2801):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jordaan Canal Stoop</title>
<style>
:root {
color-scheme: dark;
--ink: #f5f0e7;
--muted: rgba(245, 240, 231, 0.68);
--line: rgba(255, 255, 255, 0.16);
--accent: #ffca68;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a9cbd1;
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;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 2;
width: min(390px, calc(100vw - 48px));
padding: 18px 20px 17px;
color: var(--ink);
background: rgba(24, 35, 39, 0.84);
border: 1px solid var(--line);
border-radius: 4px;
box-shadow: 0 18px 50px rgba(15, 31, 35, 0.22);
backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 2px;
background: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 4vw, 42px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.title-card p {
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 3;
display: flex;
align-items: center;
gap: 10px;
padding: 8px;
color: var(--ink);
background: rgba(24, 35, 39, 0.82);
border: 1px solid var(--line);
border-radius: 4px;
box-shadow: 0 12px 35px rgba(15, 31, 35, 0.22);
backdrop-filter: blur(12px);
}
.controls span {
padding: 0 8px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
button {
min-width: 72px;
padding: 9px 12px;
color: var(--ink);
background: rgba(255, 255, 255, 0.08);
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 2px;
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.15);
border-color: rgba(255, 255, 255, 0.3);
}
.corner-note {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 2;
color: rgba(245, 240, 231, 0.8);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
line-height: 1.7;
text-transform: uppercase;
text-shadow: 0 1px 8px rgba(0, 0, 0, 0.35);
pointer-events: none;
}
@media (max-width: 680px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.title-card p {
max-width: 280px;
}
.controls {
right: 14px;
bottom: 14px;
}
.controls span {
display: none;
}
.corner-note {
display: none;
}
}
</style>
</head>
<body>
<div class="title-card">
<div class="eyebrow">Amsterdam · Jordaan</div>
<h1>Canal-side<br>voxel stoop</h1>
<p>
A raised brick doorway, narrow gabled frontage, and practical bicycle rail
overlooking the public canal path.
</p>
</div>
<div class="corner-note">
Drag to orbit · Scroll to zoom<br>
Arrow keys to rotate · R to reset
</div>
<div class="controls">
<span>Explore</span>
<button id="reset" 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";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xa9cbd1);
scene.fog = new THREE.Fog(0xa9cbd1, 31, 66);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const clock = new THREE.Clock();
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
...options
});
const M = {
base: material(0x4d5555),
path: material(0x8b8c86),
mortar: material(0x665149),
brick: material(0xffffff),
darkBrick: material(0x7d4539),
stone: material(0xd7cbb4),
paleStone: material(0xe4dccb),
trim: material(0xe8e1d2),
iron: material(0x182c2d, {
metalness: 0.55,
roughness: 0.46
}),
glass: material(0x24444c, {
metalness: 0.18,
roughness: 0.28
}),
warmGlass: material(0xc9a565, {
emissive: 0x8f5b16,
emissiveIntensity: 0.16,
roughness: 0.35
}),
door: material(0x244842),
doorInset: material(0x183b36),
gold: material(0xd6a84d, {
metalness: 0.65,
roughness: 0.35
}),
water: material(0x326e7b, {
metalness: 0.18,
roughness: 0.32
}),
waterLight: material(0x4d8790, {
metalness: 0.1,
roughness: 0.45
}),
waterDark: material(0x255b68, {
roughness: 0.48
}),
boat: material(0x493b34),
boatTrim: material(0xd9c59d),
redBike: material(0xb64b3b, {
metalness: 0.25,
roughness: 0.4
}),
blueBike: material(0x337b87, {
metalness: 0.25,
roughness: 0.4
}),
rubber: material(0x172021, {
roughness: 0.72
}),
lamp: material(0xffd995, {
emissive: 0xffad3c,
emissiveIntensity: 1.6,
roughness: 0.4
}),
foliage: material(0x536d45),
trunk: material(0x594638)
};
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function box(
width,
height,
depth,
x,
y,
z,
mat,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function barBetween(
start,
end,
thickness,
depth,
mat,
parent = scene
) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const length = direction.length();
const mesh = new THREE.Mesh(unitBox, mat);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.set(length, thickness, depth);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function instances(items, mat, parent = scene) {
const mesh = new THREE.InstancedMesh(unitBox, mat, items.length);
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3();
const position = new THREE.Vector3();
items.forEach((item, index) => {
position.set(item.x, item.y, item.z);
scale.set(item.sx, item.sy, item.sz);
quaternion.setFromAxisAngle(
new THREE.Vector3(0, 1, 0),
item.ry || 0
);
matrix.compose(position, quaternion, scale);
mesh.setMatrixAt(index, matrix);
if (item.color !== undefined) {
mesh.setColorAt(index, new THREE.Color(item.color));
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 1937;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xd9eff2,
0x6f5846,
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe5b5, 3.3);
sun.position.set(-10, 17, -9);
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 = 45;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9cc9d4, 0.7);
fill.position.set(12, 8, 7);
scene.add(fill);
// ------------------------------------------------------------
// Diorama base, canal, and public path
// ------------------------------------------------------------
box(26, 1.15, 14, 0, -1.23, -2, M.base);
// Canal water
box(26, 0.08, 4.25, 0, -0.55, -6.78, M.water, scene, false);
const waterTiles = [];
for (let i = 0; i < 52; i++) {
waterTiles.push({
x: -12.5 + random() * 25,
y: -0.495,
z: -8.7 + random() * 3.65,
sx: 0.7 + random() * 2.2,
sy: 0.012,
sz: 0.06 + random() * 0.13,
color: random() > 0.5 ? 0x4d8790 : 0x255b68
});
}
instances(waterTiles, material(0xffffff), scene);
// Quay edge
box(26, 0.76, 0.32, 0, -0.28, -4.82, M.stone);
box(26, 0.1, 0.42, 0, 0.06, -4.82, M.paleStone);
// Public canal path
box(26, 0.3, 2.48, 0, -0.15, -3.58, M.path);
const cobbles = [];
const cobblePalette = [
0x8a8b85,
0x96968f,
0x7f827d,
0x9d9b91,
0x8d918b
];
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 41; col++) {
const offset = row % 2 ? 0.16 : 0;
cobbles.push({
x: -12.8 + col * 0.63 + offset,
y: 0.018 + random() * 0.012,
z: -4.46 + row * 0.61,
sx: 0.58,
sy: 0.045,
sz: 0.55,
color: cobblePalette[Math.floor(random() * cobblePalette.length)]
});
}
}
instances(cobbles, material(0xffffff));
// Narrow sidewalk between the row and the canal-side path
box(26, 0.3, 2.3, 0, -0.15, -1.2, M.path);
const apronTiles = [];
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 30; col++) {
apronTiles.push({
x: -12.2 + col * 0.83,
y: 0.018,
z: -2.2 + row * 0.56,
sx: 0.77,
sy: 0.045,
sz: 0.5,
color: row % 2 ? 0x85867f : 0x92928a
});
}
}
instances(apronTiles, material(0xffffff));
// ------------------------------------------------------------
// Main narrow Jordaan house
// ------------------------------------------------------------
const mainX = 0;
const houseFront = 0.5;
const houseZ = 2.5;
box(
5.8,
8.8,
4,
mainX,
4.4,
houseZ,
M.mortar
);
// Individual voxel bricks
const brickColors = [
0x9a4f3e,
0x87483a,
0xa85843,
0x934b3b,
0xaa6049,
0x7f4539
];
const bricks = [];
for (let row = 0; row < 31; row++) {
const shift = row % 2 ? 0.26 : 0;
for (let col = -1; col < 12; col++) {
const x = -2.86 + col * 0.52 + shift;
if (x < -2.92 || x > 2.92) continue;
bricks.push({
x,
y: 0.16 + row * 0.275,
z: 0.455,
sx: 0.49,
sy: 0.235,
sz: 0.09,
color: brickColors[Math.floor(random() * brickColors.length)]
});
}
}
instances(bricks, M.brick);
// Stone base course
box(5.92, 0.48, 0.15, 0, 0.24, 0.42, M.stone);
box(5.92, 0.09, 0.17, 0, 0.48, 0.40, M.paleStone);
// Stepped neck gable
const gableTiers = [
{ w: 5.8, h: 1.0, y: 9.3 },
{ w: 5.0, h: 0.9, y: 10.25 },
{ w: 4.2, h: 0.8, y: 11.1 },
{ w: 3.4, h: 0.7, y: 11.85 },
{ w: 2.6, h: 0.6, y: 12.5 }
];
gableTiers.forEach((tier, index) => {
box(
tier.w,
tier.h,
4,
0,
tier.y,
houseZ,
index % 2 ? M.darkBrick : M.mortar
);
box(
tier.w + 0.07,
0.09,
0.13,
0,
tier.y + tier.h * 0.5 - 0.03,
0.43,
M.paleStone
);
});
box(3.02, 0.16, 4.2, 0, 12.88, 2.48, M.iron);
box(0.22, 0.68, 0.22, 0, 13.22, 0.48, M.stone);
box(0.34, 0.12, 0.34, 0, 13.57, 0.48, M.paleStone);
// ------------------------------------------------------------
// Windows
// ------------------------------------------------------------
function windowUnit(x, y, width, height, shutters = true) {
box(
width,
height,
0.09,
x,
y,
0.39,
M.glass
);
const frame = M.trim;
const side = 0.12;
box(side, height + 0.18, 0.14, x - width / 2, y, 0.31, frame);
box(side, height + 0.18, 0.14, x + width / 2, y, 0.31, frame);
box(width + 0.18, side, 0.14, x, y - height / 2, 0.31, frame);
box(width + 0.18, side, 0.14, x, y + height / 2, 0.31, frame);
box(0.065, height, 0.15, x, y, 0.30, frame);
box(width, 0.065, 0.15, x, y, 0.30, frame);
if (shutters) {
box(
width * 0.38,
height + 0.04,
0.11,
x - width / 2 - width * 0.23,
y,
0.33,
M.iron
);
box(
width * 0.38,
height + 0.04,
0.11,
x + width / 2 + width * 0.23,
y,
0.33,
M.iron
);
}
}
windowUnit(-1.72, 5.25, 1.12, 1.95);
windowUnit(1.72, 5.25, 1.12, 1.95);
windowUnit(-1.72, 7.75, 1.08, 1.55);
windowUnit(1.72, 7.75, 1.08, 1.55);
windowUnit(0, 10.22, 0.78, 1.08, false);
// Small ground-floor side windows
windowUnit(-1.95, 2.85, 0.64, 1.28, false);
windowUnit(1.95, 2.85, 0.64, 1.28, false);
// ------------------------------------------------------------
// Raised doorway and stoop
// ------------------------------------------------------------
// Landing
box(3.35, 1.2, 1.3, 0, 0.6, -0.15, M.darkBrick);
box(3.42, 0.12, 1.38, 0, 1.2, -0.15, M.paleStone);
// Four blocky steps
const stepDepth = 0.32;
for (let i = 0; i < 4; i++) {
const height = 0.96 - i * 0.24;
const z = -0.81 - (i + 0.5) * stepDepth;
box(3.28, height, stepDepth, 0, height / 2, z, M.darkBrick);
box(
3.34,
0.055,
0.065,
0,
height + 0.018,
z - stepDepth / 2 + 0.015,
M.paleStone
);
// Stepped side cheeks
box(0.19, height, stepDepth, -1.69, height / 2, z, M.stone);
box(0.19, height, stepDepth, 1.69, height / 2, z, M.stone);
}
// Landing cheek walls
box(0.19, 1.2, 1.3, -1.69, 0.6, -0.15, M.stone);
box(0.19, 1.2, 1.3, 1.69, 0.6, -0.15, M.stone);
box(0.25, 0.11, 1.36, -1.69, 1.25, -0.15, M.paleStone);
box(0.25, 0.11, 1.36, 1.69, 1.25, -0.15, M.paleStone);
// Door frame
box(0.16, 3.35, 0.18, -0.83, 2.78, 0.30, M.trim);
box(0.16, 3.35, 0.18, 0.83, 2.78, 0.30, M.trim);
box(1.82, 0.16, 0.18, 0, 4.42, 0.30, M.trim);
// Door
box(1.48, 3.15, 0.11, 0, 2.78, 0.21, M.door);
box(1.24, 1.12, 0.07, 0, 2.03, 0.13, M.doorInset);
box(1.24, 1.12, 0.07, 0, 3.46, 0.13, M.doorInset);
box(0.07, 0.4, 0.09, 0, 3.5, 0.08, M.door);
box(0.07, 0.4, 0.09, 0, 2.04, 0.08, M.door);
box(0.44, 0.14, 0.11, 0, 2.77, 0.08, M.gold);
box(0.12, 0.12, 0.12, 0.48, 2.72, 0.02, M.gold);
// Fanlight
box(1.38, 0.34, 0.09, 0, 4.28, 0.19, M.warmGlass);
box(0.06, 0.34, 0.12, 0, 4.28, 0.14, M.trim);
box(0.36, 0.05, 0.12, -0.34, 4.28, 0.14, M.trim);
box(0.36, 0.05, 0.12, 0.34, 4.28, 0.14, M.trim);
// Door lamps
[-1.13, 1.13].forEach((x) => {
box(0.12, 0.52, 0.12, x, 3.3, 0.25, M.iron);
box(0.28, 0.36, 0.27, x, 3.62, 0.17, M.lamp);
box(0.34, 0.08, 0.32, x, 3.83, 0.17, M.iron);
box(0.34, 0.08, 0.32, x, 3.41, 0.17, M.iron);
});
// Small house-number plaque
box(0.34, 0.26, 0.08, 1.18, 3.05, 0.07, M.gold);
// ------------------------------------------------------------
// Neighboring canal house, kept subdued
// ------------------------------------------------------------
box(4.2, 8.35, 4, 5.1, 4.175, 2.5, M.darkBrick);
box(4.28, 0.42, 0.13, 5.1, 0.21, 0.43, M.stone);
for (let row = 0; row < 13; row++) {
box(
4.08,
0.025,
0.05,
5.1,
0.55 + row * 0.58,
0.43,
M.mortar
);
}
windowUnit(4.1, 3.05, 0.9, 1.55, false);
windowUnit(6.15, 3.05, 0.9, 1.55, false);
windowUnit(4.1, 5.5, 0.9, 1.55, false);
windowUnit(6.15, 5.5, 0.9, 1.55, false);
windowUnit(5.1, 7.55, 1.25, 1.55, false);
// Roof cap and simple stepped top
box(4.35, 0.18, 4.15, 5.1, 8.48, 2.5, M.iron);
box(3.8, 0.7, 3.8, 5.1, 8.9, 2.5, M.darkBrick);
box(3.15, 0.6, 3.6, 5.1, 9.48, 2.5, M.darkBrick);
box(3.35, 0.14, 3.75, 5.1, 9.84, 2.5, M.paleStone);
// ------------------------------------------------------------
// Canal-side bicycle rail
// ------------------------------------------------------------
const railZ = -2.52;
const railLeft = -10.8;
const railRight = 10.8;
const railGapLeft = -1.88;
const railGapRight = 1.88;
function railSegment(left, right) {
const length = right - left;
const center = (left + right) * 0.5;
box(length, 0.095, 0.095, center, 0.88, railZ, M.iron);
box(length, 0.065, 0.065, center, 0.35, railZ, M.iron);
const postCount = Math.max(2, Math.round(length / 2.05));
for (let i = 0; i <= postCount; i++) {
const x = left + (length * i) / postCount;
box(0.095, 0.98, 0.095, x, 0.49, railZ, M.iron);
box(0.22, 0.07, 0.22, x, 0.035, railZ, M.iron);
}
}
railSegment(railLeft, railGapLeft);
railSegment(railGapRight, railRight);
// Short return sections around the stoop opening
box(0.09, 0.98, 0.09, railGapLeft, 0.49, railZ, M.iron);
box(0.09, 0.98, 0.09, railGapRight, 0.49, railZ, M.iron);
// ------------------------------------------------------------
// Voxel bicycles
// ------------------------------------------------------------
function makeBicycle(colorMaterial) {
const bike = new THREE.Group();
const rearHub = new THREE.Vector3(-0.72, 0.53, 0);
const frontHub = new THREE.Vector3(0.72, 0.53, 0);
const crank = new THREE.Vector3(-0.04, 0.45, 0);
const seatJoint = new THREE.Vector3(-0.29, 1.08, 0);
const headJoint = new THREE.Vector3(0.49, 1.02, 0);
// Pixel-like wheels
[rearHub, frontHub].forEach((hub) => {
const radius = 0.48;
const segments = 12;
for (let i = 0; i < segments; i++) {
const a = (i / segments) * Math.PI * 2;
const b = ((i + 1) / segments) * Math.PI * 2;
const p1 = [
hub.x + Math.cos(a) * radius,
hub.y + Math.sin(a) * radius,
0
];
const p2 = [
hub.x + Math.cos(b) * radius,
hub.y + Math.sin(b) * radius,
0
];
barBetween(p1, p2, 0.085, 0.09, M.rubber, bike);
}
// Spokes
for (let i = 0; i < 4; i++) {
const angle = (i / 4) * Math.PI;
const end = [
hub.x + Math.cos(angle) * radius * 0.78,
hub.y + Math.sin(angle) * radius * 0.78,
0
];
barBetween(
[hub.x, hub.y, 0],
end,
0.026,
0.032,
M.iron,
bike
);
}
});
// Frame
barBetween(
[-0.72, 0.53, 0],
[-0.29, 1.08, 0],
0.075,
0.075,
colorMaterial,
bike
);
barBetween(
[-0.29, 1.08, 0],
[-0.04, 0.45, 0],
0.075,
0.075,
colorMaterial,
bike
);
barBetween(
[-0.04, 0.45, 0],
[-0.72, 0.53, 0],
0.075,
0.075,
colorMaterial,
bike
);
barBetween(
[-0.29, 1.08, 0],
[0.49, 1.02, 0],
0.075,
0.075,
colorMaterial,
bike
);
barBetween(
[0.49, 1.02, 0],
[-0.04, 0.45, 0],
0.075,
0.075,
colorMaterial,
bike
);
barBetween(
[0.49, 1.02, 0],
[0.72, 0.53, 0],
0.075,
0.075,
colorMaterial,
bike
);
// Fork, bars, saddle, and pedals
barBetween(
[0.49, 1.02, 0],
[0.58, 1.31, 0],
0.065,
0.065,
M.iron,
bike
);
box(0.07, 0.07, 0.48, 0.58, 1.32, 0, M.iron, bike);
box(0.37, 0.08, 0.2, -0.32, 1.16, 0, M.rubber, bike);
box(0.08, 0.34, 0.08, -0.04, 0.43, 0, M.iron, bike);
box(0.32, 0.055, 0.12, -0.04, 0.27, 0.12, M.iron, bike);
box(0.32, 0.055, 0.12, -0.04, 0.27, -0.12, M.iron, bike);
return bike;
}
const redBike = makeBicycle(M.redBike);
redBike.position.set(-4.25, 0, -2.84);
redBike.rotation.y = -0.035;
scene.add(redBike);
const blueBike = makeBicycle(M.blueBike);
blueBike.position.set(2.85, 0, -2.85);
blueBike.rotation.y = 0.025;
scene.add(blueBike);
// ------------------------------------------------------------
// Canal details
// ------------------------------------------------------------
// Mooring bollards
[-10, -7, -3.5, 1.8, 6.4, 10.5].forEach((x) => {
box(0.22, 0.58, 0.22, x, 0.29, -4.48, M.iron);
box(0.32, 0.09, 0.32, x, 0.59, -4.48, M.iron);
});
// Blocky canal lamp
function canalLamp(x) {
box(0.42, 0.12, 0.42, x, 0.06, -4.38, M.iron);
box(0.13, 3.4, 0.13, x, 1.72, -4.38, M.iron);
box(0.48, 0.14, 0.48, x, 3.48, -4.38, M.iron);
box(0.34, 0.52, 0.34, x, 3.83, -4.38, M.lamp);
box(0.48, 0.12, 0.48, x, 4.15, -4.38, M.iron);
box(0.26, 0.15, 0.26, x, 4.29, -4.38, M.iron);
}
canalLamp(-7.8);
canalLamp(8.7);
// Small canal boat
const boat = new THREE.Group();
boat.position.set(-6.8, 0, -6.85);
boat.rotation.y = -0.07;
scene.add(boat);
box(3.7, 0.34, 1.18, 0, -0.43, 0, M.boat, boat);
box(3.25, 0.13, 1.25, 0, -0.22, 0, M.boatTrim, boat);
box(0.78, 0.08, 0.84, 0.52, -0.12, 0, M.boatTrim, boat);
box(0.55, 0.1, 0.58, 0.52, -0.05, 0, M.iron, boat);
box(1.15, 0.68, 0.92, -0.55, 0.08, 0, M.boatTrim, boat);
box(1.02, 0.38, 0.95, -0.55, 0.08, 0, M.glass, boat);
box(1.23, 0.1, 1.0, -0.55, 0.47, 0, M.iron, boat);
box(0.68, 0.09, 0.12, -0.55, 0.65, 0, M.boatTrim, boat);
box(0.09, 0.38, 0.09, -0.55, 0.49, 0, M.iron, boat);
// Small voxel tree in a distant canal-edge planter
box(1.25, 0.38, 1.25, 10.7, 0.19, -4.25, M.stone);
box(0.24, 1.75, 0.24, 10.7, 1.05, -4.25, M.trunk);
box(1.25, 0.9, 1.2, 10.7, 2.15, -4.25, M.foliage);
box(0.88, 0.72, 0.92, 10.35, 2.77, -4.1, M.foliage);
box(1.05, 0.65, 0.85, 11.1, 2.72, -4.38, M.foliage);
// ------------------------------------------------------------
// Custom camera controls
// ------------------------------------------------------------
const defaultView = {
target: new THREE.Vector3(0.3, 4.4, -1.15),
radius: 24.5,
theta: -2.52,
phi: 1.06
};
const view = {
target: defaultView.target.clone(),
radius: defaultView.radius,
theta: defaultView.theta,
phi: defaultView.phi
};
function clampView() {
view.radius = THREE.MathUtils.clamp(view.radius, 10, 36);
view.phi = THREE.MathUtils.clamp(view.phi, 0.38, 1.43);
}
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
function resetView() {
view.target.copy(defaultView.target);
view.radius = defaultView.radius;
view.theta = defaultView.theta;
view.phi = defaultView.phi;
updateCamera();
}
const pointers = new Map();
let pinchDistance = 0;
function currentPinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
if (pointers.size === 2) {
pinchDistance = currentPinchDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
view.theta -= dx * 0.006;
view.phi -= dy * 0.005;
clampView();
} else if (pointers.size === 2) {
const nextDistance = currentPinchDistance();
if (pinchDistance > 0 && nextDistance > 0) {
view.radius *= pinchDistance / nextDistance;
clampView();
}
pinchDistance = nextDistance;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = pointers.size === 2 ? currentPinchDistance() : 0;
if (pointers.size === 0) {
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius *= Math.exp(event.deltaY * 0.001);
clampView();
updateCamera();
},
{ passive: false }
);
addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
view.theta -= 0.08;
break;
case "ArrowRight":
view.theta += 0.08;
break;
case "ArrowUp":
view.phi += 0.05;
break;
case "ArrowDown":
view.phi -= 0.05;
break;
case "+":
case "=":
view.radius *= 0.92;
break;
case "-":
case "_":
view.radius *= 1.08;
break;
case "r":
case "R":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
clampView();
updateCamera();
}
});
document.getElementById("reset").addEventListener("click", resetView);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
renderer.setSize(innerWidth, innerHeight);
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
updateCamera();
renderer.setAnimationLoop(() => {
const time = clock.getElapsedTime();
// Barely perceptible canal movement.
boat.position.y = Math.sin(time * 0.72) * 0.022;
boat.rotation.z = Math.sin(time * 0.51) * 0.0025;
renderer.render(scene, camera);
});
</script>
</body>
</html>
```