Prompt specification
Build or customize the Three.js 3D scene "Visitor passing between two Berlin courtyards" 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: Visitor passing between two Berlin courtyards
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/visitor-passing-between-two-berlin-courtyards-x2814
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing the connected courtyards of Berlin's Hackesche Höfe. Create a compact referenced courtyard vignette with shop entrance, passage, and planted seating. Animate a route through the opening while leaving private doorways separate. Voxel style.
Working Three.js Starter (visitor-passing-between-two-berlin-courtyards-x2814):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hackesche Höfe — Voxel Courtyard Vignette</title>
<style>
:root {
--ink: #252c2b;
--paper: rgba(248, 244, 235, 0.92);
--accent: #d99d36;
--teal: #397b78;
--muted: #77736a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7e0d3;
color: var(--ink);
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:active {
cursor: grabbing;
}
.title-card {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 17px 19px 16px;
background: var(--paper);
border: 1px solid rgba(37, 44, 43, 0.13);
box-shadow: 0 12px 35px rgba(49, 39, 29, 0.11);
backdrop-filter: blur(10px);
}
.eyebrow {
margin-bottom: 7px;
color: #9a583d;
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 39px);
font-weight: 500;
line-height: 1.02;
letter-spacing: -0.025em;
}
.subtitle {
margin: 9px 0 0;
max-width: 330px;
color: #5e5c56;
font-size: 12px;
line-height: 1.5;
}
.legend {
position: fixed;
z-index: 10;
top: 22px;
right: 22px;
width: 224px;
padding: 14px 16px;
background: var(--paper);
border: 1px solid rgba(37, 44, 43, 0.13);
box-shadow: 0 12px 35px rgba(49, 39, 29, 0.1);
backdrop-filter: blur(10px);
}
.legend-title {
margin-bottom: 10px;
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 8px 0;
color: #55544f;
font-size: 11px;
}
.swatch {
width: 18px;
height: 8px;
flex: 0 0 auto;
border-radius: 1px;
}
.swatch.route {
background: repeating-linear-gradient(
90deg,
var(--accent) 0 4px,
transparent 4px 7px
);
}
.swatch.passage {
background: var(--teal);
}
.swatch.private {
background: #756b61;
}
.swatch.seating {
background: #65815d;
}
.controls {
position: fixed;
z-index: 10;
left: 22px;
bottom: 20px;
display: flex;
align-items: center;
gap: 9px;
flex-wrap: wrap;
}
button {
appearance: none;
border: 1px solid rgba(37, 44, 43, 0.18);
padding: 9px 12px;
background: rgba(248, 244, 235, 0.94);
color: var(--ink);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
cursor: pointer;
transition:
background 140ms ease,
transform 140ms ease;
}
button:hover {
background: #fffaf0;
transform: translateY(-1px);
}
.hint {
padding: 9px 11px;
background: rgba(248, 244, 235, 0.78);
color: #66635c;
font: 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.pin {
position: fixed;
z-index: 5;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
transform: translate(-50%, -100%);
background: rgba(249, 246, 237, 0.92);
border: 1px solid rgba(37, 44, 43, 0.18);
box-shadow: 0 4px 12px rgba(42, 34, 27, 0.09);
color: #3d423f;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
white-space: nowrap;
pointer-events: none;
}
.pin::before {
content: "";
width: 7px;
height: 7px;
background: var(--pin-color, var(--accent));
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7);
}
.pin::after {
content: "";
position: absolute;
left: 50%;
bottom: -7px;
width: 1px;
height: 7px;
background: rgba(37, 44, 43, 0.4);
}
.loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #e7e0d3;
color: #5e5c56;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.loading.hidden {
display: none;
}
@media (max-width: 760px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle {
display: none;
}
.legend {
top: 113px;
right: 12px;
width: 182px;
padding: 11px 12px;
}
.legend-row {
margin: 6px 0;
}
.controls {
left: 12px;
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="loading" class="loading">Building the courtyards…</div>
<header class="title-card">
<div class="eyebrow">Berlin · Connected Courtyards</div>
<h1>Hackesche Höfe</h1>
<p class="subtitle">
A compact voxel study of the sequence of courtyards, with a public route
from a small courtyard shop through the central passage to planted seating.
</p>
</header>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Spatial key</div>
<div class="legend-row">
<span class="swatch route"></span>
Animated public route
</div>
<div class="legend-row">
<span class="swatch passage"></span>
Open connecting passage
</div>
<div class="legend-row">
<span class="swatch private"></span>
Separate private doorways
</div>
<div class="legend-row">
<span class="swatch seating"></span>
Planted seating courts
</div>
</aside>
<div class="pin" id="pin-shop" style="--pin-color:#397b78">HOF SHOP</div>
<div class="pin" id="pin-passage" style="--pin-color:#397b78">PASSAGE</div>
<div class="pin" id="pin-private" style="--pin-color:#756b61">PRIVATE</div>
<div class="pin" id="pin-seating" style="--pin-color:#65815d">PLANTED SEATING</div>
<div class="controls">
<button id="replay" type="button">REPLAY ROUTE</button>
<button id="reset" type="button">RESET VIEW</button>
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e7e0d3");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.7));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-15, 15, 15, -15, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.2, -0.4);
let azimuth = 0.64;
let elevation = 0.63;
let viewSize = 17.2;
const hemisphere = new THREE.HemisphereLight(
"#fff6df",
"#766a60",
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0cf", 3.1);
sun.position.set(-13, 24, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#c9dce3", 0.75);
fill.position.set(14, 9, -12);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
base: standard("#b7a88f"),
edge: standard("#d4c5a7"),
brickRed: standard("#9d4e3b"),
brickOrange: standard("#b96645"),
brickOchre: standard("#bd8650"),
plaster: standard("#d0a56d"),
cream: standard("#eee0c5"),
stone: standard("#c6b89c"),
darkStone: standard("#81786d"),
timber: standard("#51483e"),
teal: standard("#397b78"),
tealDark: standard("#285d5b"),
privateDoor: standard("#71685e"),
privateFrame: standard("#948675"),
route: new THREE.MeshBasicMaterial({ color: "#dba13d" }),
routeGlow: new THREE.MeshBasicMaterial({ color: "#ffd26c" }),
soil: standard("#4e3f31"),
pot: standard("#9b6548"),
potLight: standard("#b67c59"),
leaf: standard("#58754c"),
leafLight: standard("#718c5d"),
leafDark: standard("#405b3d"),
trunk: standard("#66503b"),
water: standard("#579ba2", {
roughness: 0.28,
metalness: 0.08
}),
glass: standard("#344b50", {
roughness: 0.42,
metalness: 0.12
}),
glassLit: standard("#d6b76b", {
roughness: 0.6,
emissive: "#8f6423",
emissiveIntensity: 0.35
}),
metal: standard("#393d39", { roughness: 0.7, metalness: 0.35 }),
fabric: standard("#eee2cb"),
coral: standard("#d66f52"),
blue: standard("#4d7289"),
skin: standard("#d9ae83"),
lamp: new THREE.MeshBasicMaterial({ color: "#ffe6a4" })
};
function box(w, h, d, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextPanel(
text,
width,
height,
bg = "#eee0c5",
fg = "#344644"
) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = fg;
ctx.globalAlpha = 0.35;
ctx.lineWidth = 5;
ctx.strokeRect(7, 7, canvas.width - 14, canvas.height - 14);
ctx.globalAlpha = 1;
const fontSize = text.length > 10 ? 42 : 55;
ctx.fillStyle = fg;
ctx.font = `700 ${fontSize}px ui-monospace, monospace`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 3);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.magFilter = THREE.NearestFilter;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
})
);
return mesh;
}
let seed = 19;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
// -------------------------------------------------------------------------
// Courtyard base and paving
// -------------------------------------------------------------------------
box(26, 0.9, 18, M.base, 0, -0.48, 0);
box(26.3, 0.16, 18.3, M.edge, 0, -0.78, 0);
const pavingGeometry = new THREE.BoxGeometry(1.08, 0.08, 1.08);
const pavingMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
vertexColors: true
});
const paving = new THREE.InstancedMesh(
pavingGeometry,
pavingMaterial,
23 * 15
);
paving.receiveShadow = true;
const matrix = new THREE.Matrix4();
const pavingColors = ["#c8bda4", "#d0c4aa", "#c2b79f", "#d7ccb4"];
let pavingIndex = 0;
for (let ix = 0; ix < 23; ix++) {
for (let iz = 0; iz < 15; iz++) {
const x = -11.5 + ix * 1.15;
const z = -7.45 + iz * 1.07;
matrix.makeTranslation(x, 0.045, z);
paving.setMatrixAt(pavingIndex, matrix);
paving.setColorAt(
pavingIndex,
new THREE.Color(pavingColors[Math.floor(random() * pavingColors.length)])
);
pavingIndex++;
}
}
paving.instanceMatrix.needsUpdate = true;
if (paving.instanceColor) paving.instanceColor.needsUpdate = true;
scene.add(paving);
// -------------------------------------------------------------------------
// Courtyard buildings
// -------------------------------------------------------------------------
const northZ = -6.8;
// North façade, with a ground-level shop opening.
box(3.3, 6.4, 0.72, M.brickRed, -9.15, 3.2, northZ);
box(7.9, 6.4, 0.72, M.brickOrange, -0.75, 3.2, northZ);
box(7.6, 6.4, 0.72, M.brickOchre, 7.0, 3.2, northZ);
box(2.8, 2.7, 0.72, M.brickRed, -6.1, 5.05, northZ);
// West and east perimeter façades.
box(0.72, 6.4, 13.6, M.brickRed, -10.8, 3.2, 0);
box(0.72, 6.4, 13.6, M.brickOchre, 10.8, 3.2, 0);
// Low cutaway walls on the street side keep the interiors visible.
box(6.3, 1.05, 0.58, M.brickRed, -7.65, 0.525, 6.8);
box(7.4, 1.05, 0.58, M.brickOchre, 7.1, 0.525, 6.8);
// Central divider with a generous public passage.
const dividerX = 1.2;
box(0.72, 5.4, 5.5, M.brickOrange, dividerX, 2.7, -4.05);
box(0.72, 5.4, 4.6, M.brickOrange, dividerX, 2.7, 4.5);
box(0.72, 1.8, 3.5, M.brickOrange, dividerX, 4.5, 0.45);
// Stepped voxel arch around the opening.
box(0.9, 3.6, 0.28, M.cream, dividerX, 1.8, -1.33);
box(0.9, 3.6, 0.28, M.cream, dividerX, 1.8, 2.23);
box(0.9, 0.42, 0.46, M.cream, dividerX, 2.85, -1.08);
box(0.9, 0.42, 0.46, M.cream, dividerX, 2.85, 1.98);
box(0.9, 0.42, 0.46, M.cream, dividerX, 3.25, -0.82);
box(0.9, 0.42, 0.46, M.cream, dividerX, 3.25, 1.72);
// Cornices and pilasters.
box(3.45, 0.22, 0.9, M.cream, -9.15, 6.35, northZ);
box(8.05, 0.22, 0.9, M.cream, -0.75, 6.35, northZ);
box(7.75, 0.22, 0.9, M.cream, 7.0, 6.35, northZ);
box(0.9, 0.22, 13.75, M.cream, -10.8, 6.35, 0);
box(0.9, 0.22, 13.75, M.cream, 10.8, 6.35, 0);
for (const x of [-10.35, -4.7, 3.2, 10.35]) {
box(0.22, 6.1, 0.18, M.cream, x, 3.05, -6.36);
}
// Chimneys and stepped roof details.
for (const [x, z, h] of [
[-8.9, -7.0, 1.2],
[-1.7, -7.0, 0.9],
[6.6, -7.0, 1.4],
[10.7, -3.2, 1.1],
[-10.7, 3.2, 1.0]
]) {
box(0.75, h, 0.72, M.brickRed, x, 6.4 + h / 2, z);
box(0.88, 0.14, 0.84, M.darkStone, x, 6.4 + h, z);
}
// -------------------------------------------------------------------------
// Windows
// -------------------------------------------------------------------------
function northWindow(x, y, lit = false) {
const z = -6.36;
box(1.08, 1.34, 0.12, M.cream, x, y, z);
box(0.79, 1.06, 0.14, lit ? M.glassLit : M.glass, x, y, z + 0.09);
box(0.075, 1.08, 0.08, M.cream, x, y, z + 0.17);
box(0.8, 0.075, 0.08, M.cream, x, y, z + 0.17);
box(1.25, 0.12, 0.32, M.stone, x, y - 0.73, z + 0.07);
}
function westWindow(z, y, lit = false) {
const x = -10.36;
box(0.12, 1.34, 1.08, M.cream, x, y, z);
box(0.14, 1.06, 0.79, lit ? M.glassLit : M.glass, x + 0.09, y, z);
box(0.08, 1.08, 0.075, M.cream, x + 0.17, y, z);
box(0.08, 0.075, 0.8, M.cream, x + 0.17, y, z);
box(0.32, 0.12, 1.25, M.stone, x + 0.07, y - 0.73, z);
}
function eastWindow(z, y, lit = false) {
const x = 10.36;
box(0.12, 1.34, 1.08, M.cream, x, y, z);
box(0.14, 1.06, 0.79, lit ? M.glassLit : M.glass, x - 0.09, y, z);
box(0.08, 1.08, 0.075, M.cream, x - 0.17, y, z);
box(0.08, 0.075, 0.8, M.cream, x - 0.17, y, z);
box(0.32, 0.12, 1.25, M.stone, x - 0.07, y - 0.73, z);
}
for (const [x, y, lit] of [
[-9.3, 4.7, true],
[-9.3, 2.0, false],
[-3.7, 4.7, true],
[-3.7, 2.0, false],
[-1.3, 4.7, false],
[-1.3, 2.0, true],
[1.1, 4.7, false],
[4.0, 4.7, true],
[4.0, 2.0, false],
[6.5, 4.7, false],
[6.5, 2.0, true],
[9.2, 4.7, true]
]) {
northWindow(x, y, lit);
}
for (const [z, y, lit] of [
[-5.1, 4.7, false],
[-2.6, 4.7, true],
[-0.1, 4.7, false],
[2.5, 4.7, true],
[5.1, 4.7, false],
[-3.8, 2.0, true],
[0.8, 2.0, false],
[4.4, 2.0, true]
]) {
westWindow(z, y, lit);
}
for (const [z, y, lit] of [
[-5.0, 4.7, true],
[-2.4, 4.7, false],
[0.2, 4.7, true],
[2.8, 4.7, false],
[5.4, 4.7, true],
[-4.0, 2.0, false],
[1.0, 2.0, true],
[4.6, 2.0, false]
]) {
eastWindow(z, y, lit);
}
// -------------------------------------------------------------------------
// Shop entrance
// -------------------------------------------------------------------------
// Dark recessed shop interior.
box(2.8, 3.55, 0.2, M.timber, -6.1, 1.78, -6.58);
// Door and display window.
box(1.08, 2.72, 0.18, M.tealDark, -6.75, 1.38, -6.36);
box(0.76, 0.86, 0.1, M.glassLit, -6.75, 1.83, -6.24);
box(0.08, 0.28, 0.1, M.cream, -6.19, 1.25, -6.22);
box(1.28, 2.35, 0.16, M.teal, -5.35, 1.2, -6.35);
box(1.04, 1.97, 0.12, M.glass, -5.35, 1.22, -6.23);
box(0.08, 2.0, 0.08, M.cream, -5.35, 1.22, -6.14);
box(1.06, 0.08, 0.08, M.cream, -5.35, 1.22, -6.14);
// Frame and a striped voxel awning.
box(0.18, 3.55, 0.3, M.teal, -7.48, 1.78, -6.34);
box(0.18, 3.55, 0.3, M.teal, -4.72, 1.78, -6.34);
box(3.12, 0.16, 1.08, M.cream, -6.1, 3.18, -6.0);
for (let i = 0; i < 6; i++) {
box(
0.51,
0.13,
1.12,
i % 2 === 0 ? M.coral : M.cream,
-7.39 + i * 0.52,
3.31,
-6.0
);
}
const shopSign = makeTextPanel("HOF SHOP", 2.45, 0.48, "#e8d8b8", "#315c59");
shopSign.position.set(-6.1, 3.75, -6.22);
scene.add(shopSign);
// -------------------------------------------------------------------------
// Separate private doorways
// -------------------------------------------------------------------------
function privateDoor(x) {
const z = -6.35;
box(1.32, 2.72, 0.16, M.privateFrame, x, 1.38, z);
box(1.06, 2.5, 0.18, M.privateDoor, x, 1.27, z + 0.08);
box(0.76, 0.86, 0.08, M.glass, x, 1.93, z + 0.19);
box(0.11, 0.11, 0.1, M.cream, x + 0.34, 1.17, z + 0.22);
const plaque = makeTextPanel("PRIVATE", 0.88, 0.23, "#d9cbb1", "#655b50");
plaque.position.set(x, 2.84, z + 0.19);
scene.add(plaque);
// Planters and a low rail physically separate these entrances.
box(1.28, 0.44, 0.68, M.pot, x, 0.24, -5.55);
box(1.08, 0.08, 0.5, M.soil, x, 0.49, -5.55);
box(0.5, 0.48, 0.45, M.leafDark, x - 0.29, 0.72, -5.55);
box(0.44, 0.38, 0.4, M.leaf, x + 0.26, 0.67, -5.54);
box(0.12, 0.76, 0.12, M.metal, x - 0.73, 0.42, -5.12);
box(0.12, 0.76, 0.12, M.metal, x + 0.73, 0.42, -5.12);
box(1.58, 0.08, 0.08, M.metal, x, 0.73, -5.12);
}
privateDoor(5.15);
privateDoor(8.05);
// -------------------------------------------------------------------------
// Passage details
// -------------------------------------------------------------------------
// Gold threshold visually identifies the public opening.
box(0.88, 0.055, 3.02, M.route, dividerX, 0.125, 0.45);
const passageSign = makeTextPanel("PASSAGE", 1.8, 0.48, "#397b78", "#f5e9cf");
passageSign.position.set(1.61, 4.05, 0.45);
passageSign.rotation.y = Math.PI / 2;
scene.add(passageSign);
// Voxel lanterns beside the arch.
for (const z of [-1.18, 2.08]) {
box(0.15, 0.3, 0.15, M.metal, 1.73, 3.1, z);
box(0.22, 0.34, 0.22, M.lamp, 1.82, 2.87, z);
box(0.3, 0.08, 0.3, M.metal, 1.82, 3.06, z);
}
// -------------------------------------------------------------------------
// Planters, trees, benches, fountain and café furniture
// -------------------------------------------------------------------------
function planter(w, d, x, z, light = false) {
box(w, 0.46, d, light ? M.potLight : M.pot, x, 0.25, z);
box(w - 0.16, 0.08, d - 0.16, M.soil, x, 0.51, z);
const count = Math.max(2, Math.floor((w * d) / 0.7));
for (let i = 0; i < count; i++) {
const sx = x + (random() - 0.5) * (w - 0.45);
const sz = z + (random() - 0.5) * (d - 0.45);
const size = 0.28 + random() * 0.28;
const shrub = box(
size,
size * (0.75 + random() * 0.35),
size,
random() > 0.5 ? M.leaf : M.leafLight,
sx,
0.62 + size * 0.35,
sz
);
shrub.rotation.y = random() * 0.35;
}
}
function voxelTree(x, z, scale = 1) {
box(0.35 * scale, 2.3 * scale, 0.35 * scale, M.trunk,
x, 1.15 * scale, z);
const clusters = [
[0, 2.55, 0, 1.75, 1.4, 1.55],
[-0.65, 2.25, 0.12, 1.2, 1.05, 1.25],
[0.63, 2.32, -0.18, 1.28, 1.15, 1.2],
[0.1, 3.15, 0.1, 1.25, 0.85, 1.15]
];
clusters.forEach((c, i) => {
box(
c[3] * scale,
c[4] * scale,
c[5] * scale,
i % 2 ? M.leaf : M.leafLight,
x + c[0] * scale,
c[1] * scale,
z + c[2] * scale
);
});
}
function plantedBench(x, z, mirrored = false) {
const backX = x + (mirrored ? 0.46 : -0.46);
// Integrated planter behind the bench.
box(0.72, 0.58, 3.0, M.pot, backX, 0.31, z);
box(0.56, 0.08, 2.78, M.soil, backX, 0.63, z);
for (const dz of [-1.05, -0.35, 0.4, 1.08]) {
box(
0.48,
0.48,
0.52,
dz > 0 ? M.leaf : M.leafLight,
backX,
0.88,
z + dz
);
}
// Seat and legs.
box(0.78, 0.18, 2.42, M.timber, x, 0.68, z);
box(0.15, 0.5, 2.42, M.timber, backX, 1.0, z);
box(0.18, 0.48, 0.18, M.metal, x, 0.27, z - 0.88);
box(0.18, 0.48, 0.18, M.metal, x, 0.27, z + 0.88);
}
planter(1.4, 0.8, -8.45, -5.25, true);
planter(1.25, 0.78, -3.7, -5.3);
planter(1.5, 0.8, 7.9, -5.15, true);
planter(1.2, 0.75, 9.65, 3.0);
planter(2.0, 1.25, -8.55, 3.3, true);
voxelTree(-8.55, 3.3, 0.88);
planter(2.0, 1.25, 8.8, -3.2, true);
voxelTree(8.8, -3.2, 0.9);
plantedBench(-9.15, -0.85, false);
plantedBench(8.85, 0.55, true);
// Small voxel fountain, recalling the courtyard water feature.
box(3.2, 0.18, 2.45, M.stone, -6.15, 0.16, -1.55);
box(2.72, 0.12, 1.97, M.water, -6.15, 0.28, -1.55);
box(0.72, 0.52, 0.72, M.cream, -6.15, 0.48, -1.55);
box(0.38, 0.38, 0.38, M.water, -6.15, 0.84, -1.55);
box(2.98, 0.12, 0.16, M.cream, -6.15, 0.36, -2.65);
box(2.98, 0.12, 0.16, M.cream, -6.15, 0.36, -0.45);
// Café table and chairs in the second courtyard.
box(1.02, 0.13, 1.02, M.cream, 6.35, 0.94, 2.45);
box(0.18, 0.82, 0.18, M.metal, 6.35, 0.48, 2.45);
box(0.62, 0.08, 0.62, M.metal, 6.35, 0.08, 2.45);
function chair(x, z, rotation) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.rotation.y = rotation;
scene.add(g);
box(0.58, 0.11, 0.58, M.teal, 0, 0.53, 0, g);
box(0.58, 0.62, 0.1, M.teal, 0, 0.83, -0.25, g);
box(0.09, 0.46, 0.09, M.metal, -0.22, 0.26, -0.22, g);
box(0.09, 0.46, 0.09, M.metal, 0.22, 0.26, -0.22, g);
box(0.09, 0.46, 0.09, M.metal, -0.22, 0.26, 0.22, g);
box(0.09, 0.46, 0.09, M.metal, 0.22, 0.26, 0.22, g);
}
chair(5.55, 2.45, Math.PI / 2);
chair(7.15, 2.45, -Math.PI / 2);
chair(6.35, 3.25, 0);
// Small planting islands frame the street-side cutaway.
planter(1.4, 0.78, -4.9, 6.55);
planter(1.4, 0.78, 3.75, 6.55, true);
// -------------------------------------------------------------------------
// Public route: shop → courtyard → passage → planted seating
// -------------------------------------------------------------------------
const routePoints = [
new THREE.Vector3(-6.15, 0.13, -4.85),
new THREE.Vector3(-5.55, 0.13, -4.1),
new THREE.Vector3(-3.95, 0.13, -3.45),
new THREE.Vector3(-2.35, 0.13, -2.8),
new THREE.Vector3(-0.55, 0.13, -1.65),
new THREE.Vector3(0.45, 0.13, -0.2),
new THREE.Vector3(1.2, 0.13, 0.45),
new THREE.Vector3(2.4, 0.13, 0.45),
new THREE.Vector3(3.85, 0.13, 0.45),
new THREE.Vector3(5.25, 0.13, 0.75),
new THREE.Vector3(6.25, 0.13, 1.15)
];
const routeCurve = new THREE.CatmullRomCurve3(
routePoints,
false,
"catmullrom",
0.35
);
// Dashed route made from small cubes.
const routeDots = [];
for (let i = 0; i <= 150; i += 3) {
const p = routeCurve.getPointAt(i / 150);
const dot = box(
0.14,
0.055,
0.14,
M.route,
p.x,
0.14,
p.z
);
dot.castShadow = false;
routeDots.push(dot);
}
// Animated voxel visitor.
const walker = new THREE.Group();
scene.add(walker);
box(0.18, 0.4, 0.2, M.blue, -0.11, 0.24, 0, walker);
box(0.18, 0.4, 0.2, M.blue, 0.11, 0.24, 0, walker);
box(0.48, 0.54, 0.32, M.coral, 0, 0.66, 0, walker);
box(0.34, 0.34, 0.34, M.skin, 0, 1.08, 0, walker);
box(0.38, 0.1, 0.38, M.timber, 0, 1.29, 0, walker);
box(0.16, 0.25, 0.17, M.timber, 0.28, 0.59, 0, walker);
const pulse = new THREE.Group();
walker.add(pulse);
for (const x of [-0.36, 0.36]) {
for (const z of [-0.36, 0.36]) {
const marker = box(
0.11,
0.035,
0.11,
M.routeGlow,
x,
0.02,
z,
pulse
);
marker.castShadow = false;
}
}
let routeTime = 0;
const routeDuration = 15.5;
// -------------------------------------------------------------------------
// World-space labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("pin-shop"),
position: new THREE.Vector3(-6.1, 4.18, -6.12)
},
{
element: document.getElementById("pin-passage"),
position: new THREE.Vector3(1.75, 4.62, 0.45)
},
{
element: document.getElementById("pin-private"),
position: new THREE.Vector3(6.6, 3.25, -6.12)
},
{
element: document.getElementById("pin-seating"),
position: new THREE.Vector3(8.85, 1.75, 0.55)
}
];
// -------------------------------------------------------------------------
// Camera controls implemented directly, without addons
// -------------------------------------------------------------------------
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function updateCamera() {
const distance = 34;
const horizontal = Math.cos(elevation) * distance;
camera.position.set(
cameraTarget.x + Math.sin(azimuth) * horizontal,
cameraTarget.y + Math.sin(elevation) * distance,
cameraTarget.z + Math.cos(azimuth) * horizontal
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetView() {
azimuth = 0.64;
elevation = 0.63;
viewSize = 17.2;
resize();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
azimuth -= dx * 0.006;
elevation = THREE.MathUtils.clamp(
elevation + dy * 0.0045,
0.38,
1.08
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
viewSize = THREE.MathUtils.clamp(
viewSize + event.deltaY * 0.012,
11.5,
23
);
resize();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("replay").addEventListener("click", () => {
routeTime = 0;
});
document.getElementById("reset").addEventListener("click", resetView);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve the whole diorama on narrow screens.
const fitFactor = Math.max(1, 1.55 / aspect);
const verticalSize = viewSize * fitFactor;
camera.left = -verticalSize * aspect;
camera.right = verticalSize * aspect;
camera.top = verticalSize;
camera.bottom = -verticalSize;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.7));
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
projected.copy(label.position).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -100 &&
x < window.innerWidth + 100 &&
y > 0 &&
y < window.innerHeight;
label.element.style.display = visible ? "flex" : "none";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
routeTime = (routeTime + delta / routeDuration) % 1;
const t = routeTime;
const point = routeCurve.getPointAt(t);
const tangent = routeCurve.getTangentAt(t);
walker.position.copy(point);
walker.rotation.y = Math.atan2(tangent.x, tangent.z);
const pulseScale = 1 + Math.sin(performance.now() * 0.006) * 0.13;
pulse.scale.setScalar(pulseScale);
pulse.rotation.y += delta * 0.6;
// Slightly brighten the nearest route cubes.
for (let i = 0; i < routeDots.length; i++) {
const dotDistance = Math.abs(i / (routeDots.length - 1) - t);
const isNear = dotDistance < 0.045;
routeDots[i].material = isNear ? M.routeGlow : M.route;
routeDots[i].scale.setScalar(isNear ? 1.35 : 1);
}
updateLabels();
renderer.render(scene, camera);
}
document.getElementById("loading").classList.add("hidden");
animate();
</script>
</body>
</html>
```