Prompt specification
Build or customize the Three.js 3D scene "Grassmarket stone shopfront and stair entrance" 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: Grassmarket stone shopfront and stair entrance
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/grassmarket-stone-shopfront-and-stair-entrance-x2825
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts the Grassmarket beneath Edinburgh's castle ridge. Build a referenced Edinburgh stone facade fragment with shopfront and stair entrance. Show the contrast between a level public walkway and rising access toward adjoining streets. Voxel style.
Working Three.js Starter (grassmarket-stone-shopfront-and-stair-entrance-x2825):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Grassmarket — Castle Ridge, Edinburgh</title>
<style>
:root {
color-scheme: dark;
--ink: #f3eee4;
--muted: #c4c7c1;
--glass: rgba(22, 31, 34, 0.82);
--line: rgba(255, 255, 255, 0.18);
--level: #e3b85d;
--rise: #72b8c7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #adc3c8;
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: 22px;
left: 22px;
z-index: 5;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 16px;
color: var(--ink);
background: var(--glass);
border: 1px solid var(--line);
border-radius: 12px;
backdrop-filter: blur(12px);
box-shadow: 0 14px 40px rgba(18, 24, 25, 0.16);
pointer-events: none;
}
.eyebrow {
margin: 0 0 8px;
color: #e3b85d;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 40px);
font-weight: 600;
line-height: 0.98;
letter-spacing: -0.025em;
}
#title-card p {
margin: 11px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#controls {
position: fixed;
top: 22px;
right: 22px;
z-index: 6;
display: flex;
gap: 8px;
}
button {
min-height: 38px;
padding: 0 13px;
color: #f4f1e9;
font: inherit;
font-size: 12px;
font-weight: 700;
background: rgba(22, 31, 34, 0.86);
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 8px;
cursor: pointer;
backdrop-filter: blur(10px);
}
button:hover,
button.active {
color: #172023;
background: #e8d6a7;
}
#legend {
position: fixed;
left: 22px;
bottom: 22px;
z-index: 5;
display: grid;
gap: 8px;
max-width: calc(100vw - 44px);
padding: 13px 15px;
color: #e9ece7;
background: var(--glass);
border: 1px solid var(--line);
border-radius: 10px;
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.035em;
}
.swatch {
width: 23px;
height: 7px;
border-radius: 2px;
}
.swatch.level {
background: var(--level);
}
.swatch.rise {
background: var(--rise);
}
.swatch.stone {
background: #bca887;
}
#help {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 5;
padding: 9px 12px;
color: rgba(245, 244, 237, 0.86);
font-size: 11px;
background: rgba(22, 31, 34, 0.76);
border: 1px solid var(--line);
border-radius: 8px;
backdrop-filter: blur(10px);
pointer-events: none;
}
.tag {
position: fixed;
z-index: 4;
padding: 7px 10px;
color: #172023;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.105em;
white-space: nowrap;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 5px;
box-shadow: 0 6px 16px rgba(20, 25, 27, 0.16);
transform: translate(-50%, -50%);
pointer-events: none;
}
#tag-level {
background: var(--level);
}
#tag-rise {
color: white;
background: #397f8c;
}
#tag-castle {
color: white;
background: rgba(33, 43, 47, 0.82);
border-color: rgba(255, 255, 255, 0.3);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #f4f0e6;
background: #25383d;
font-size: 13px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 0.45s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
#title-card p {
display: none;
}
#controls {
top: auto;
right: 12px;
bottom: 66px;
}
#legend {
left: 12px;
bottom: 12px;
}
#help {
display: none;
}
.tag {
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel view of Edinburgh's Grassmarket"></canvas>
<section id="title-card">
<p class="eyebrow">Edinburgh Old Town · Interpretive voxel study</p>
<h1>The Grassmarket<br>below the castle</h1>
<p>
A referenced stone frontage, an active level public walkway, and the
steep stair connection toward the High Street. This is an urban
character study rather than a surveyed reconstruction.
</p>
</section>
<div id="controls">
<button id="reset" type="button">Reset view</button>
<button id="rotate" type="button">Auto orbit</button>
</div>
<div id="legend">
<div class="legend-item">
<span class="swatch level"></span>
Level public walkway
</div>
<div class="legend-item">
<span class="swatch rise"></span>
Rising access to adjoining streets
</div>
<div class="legend-item">
<span class="swatch stone"></span>
Edinburgh sandstone frontage
</div>
</div>
<div id="help">Drag to orbit · Shift/right-drag to pan · Scroll to zoom · R to reset</div>
<div id="tag-level" class="tag">LEVEL PUBLIC WALKWAY</div>
<div id="tag-rise" class="tag">RISING ACCESS · HIGH STREET</div>
<div id="tag-castle" class="tag">EDINBURGH CASTLE RIDGE</div>
<div id="loading">Building the Grassmarket…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene and camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.06;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaec6cb);
scene.fog = new THREE.Fog(0xaec6cb, 44, 84);
const camera = new THREE.OrthographicCamera(-20, 20, 16, -16, 0.1, 120);
const world = new THREE.Group();
scene.add(world);
const hemisphere = new THREE.HemisphereLight(0xd7ebf2, 0x6b5a47, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3b4, 3.7);
sun.position.set(-14, 27, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -35;
sun.shadow.camera.right = 35;
sun.shadow.camera.top = 32;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00045;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ebfd4, 0.65);
fill.position.set(18, 12, -20);
scene.add(fill);
// -------------------------------------------------------------------------
// Utilities
// -------------------------------------------------------------------------
let seed = 1846;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function range(min, max) {
return min + random() * (max - min);
}
function pick(values) {
return values[Math.floor(random() * values.length)];
}
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0
})
);
}
return materialCache.get(color);
}
function block(
x,
y,
z,
width,
height,
depth,
color,
parent = world,
material = null
) {
const mesh = new THREE.Mesh(
unitBox,
material || getMaterial(color)
);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(x = 0, y = 0, z = 0, parent = world) {
const g = new THREE.Group();
g.position.set(x, y, z);
parent.add(g);
return g;
}
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x274652,
roughness: 0.28,
metalness: 0.12
});
const warmGlassMaterial = new THREE.MeshStandardMaterial({
color: 0x8b6b3f,
emissive: 0xffb65e,
emissiveIntensity: 0.62,
roughness: 0.36
});
const slateMaterial = new THREE.MeshStandardMaterial({
color: 0x35444b,
roughness: 0.86
});
function makeSign(
text,
width,
height,
x,
y,
z,
parent = world,
background = "#253b32",
foreground = "#f2d48b",
subtitle = ""
) {
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 256;
const ctx = signCanvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, 1024, 256);
ctx.strokeStyle = foreground;
ctx.lineWidth = 7;
ctx.strokeRect(13, 13, 998, 230);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.font = `700 ${subtitle ? 72 : 88}px Georgia, serif`;
ctx.fillText(text, 512, subtitle ? 105 : 132, 940);
if (subtitle) {
ctx.font = "500 30px sans-serif";
ctx.fillText(subtitle, 512, 184, 900);
}
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true
})
);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function addMasonryFront(
cx,
frontZ,
width,
height,
parent = world,
palette = [0xb7a17e, 0xc3ad89, 0xa9906e, 0xbea986]
) {
const course = 0.48;
const brickWidth = 1.08;
for (let row = 0; row < Math.floor(height / course); row++) {
const y = 0.24 + row * course;
const offset = row % 2 === 0 ? 0 : brickWidth * 0.5;
let x = cx - width / 2 - offset;
while (x < cx + width / 2) {
const bw = Math.min(brickWidth, cx + width / 2 - x);
if (bw < 0.15) break;
block(
x + bw / 2,
y,
frontZ + 0.045,
bw - 0.035,
course - 0.035,
0.14,
pick(palette),
parent
);
x += bw;
}
}
}
function addWindow(
x,
y,
z,
width = 1.05,
height = 1.55,
warm = false,
parent = world
) {
block(
x,
y,
z + 0.16,
width + 0.22,
height + 0.22,
0.15,
0x30393b,
parent
);
block(
x,
y,
z + 0.255,
width,
height,
0.04,
0xffffff,
parent,
warm ? warmGlassMaterial : glassMaterial
);
block(
x - width / 2 - 0.08,
y,
z + 0.31,
0.13,
height + 0.27,
0.16,
0xd0b98d,
parent
);
block(
x + width / 2 + 0.08,
y,
z + 0.31,
0.13,
height + 0.27,
0.16,
0xd0b98d,
parent
);
block(
x,
y + height / 2 + 0.08,
z + 0.31,
width + 0.28,
0.13,
0.16,
0xd0b98d,
parent
);
block(
x,
y + height / 2 - 0.08,
z + 0.32,
width + 0.28,
0.13,
0.16,
0xd0b98d,
parent
);
block(
x,
y,
z + 0.345,
0.075,
height,
0.09,
0xcab58e,
parent
);
block(
x,
y - 0.1,
z + 0.35,
width,
0.075,
0.09,
0xcab58e,
parent
);
}
function addSteppedGable(
cx,
frontZ,
width,
baseY,
levels,
parent = world,
color = 0xb49d79
) {
const inset = width / (levels * 2);
for (let i = 0; i < levels; i++) {
const currentWidth = width - i * inset * 2;
block(
cx,
baseY + i * 0.46,
frontZ - 0.05,
currentWidth,
0.46,
0.55,
i % 2 ? 0xc0aa82 : color,
parent
);
}
block(
cx,
baseY + levels * 0.46 + 0.11,
frontZ - 0.05,
Math.max(0.45, width - levels * inset * 2),
0.25,
0.62,
0x38464c,
parent,
slateMaterial
);
}
function addChimney(x, y, z, parent = world) {
block(x, y + 0.65, z, 0.72, 1.3, 0.72, 0x9f8768, parent);
block(x, y + 1.34, z, 0.9, 0.18, 0.88, 0x756e62, parent);
block(x - 0.18, y + 1.58, z, 0.24, 0.32, 0.24, 0x9c8061, parent);
block(x + 0.18, y + 1.58, z, 0.24, 0.32, 0.24, 0x9c8061, parent);
}
// -------------------------------------------------------------------------
// Ground and level Grassmarket walkway
// -------------------------------------------------------------------------
block(0, -0.62, -4, 37, 1.2, 35, 0x67584a);
block(0, 0.015, 2.1, 34.5, 0.16, 14.5, 0x88877d);
block(-16.9, 0.17, 2.1, 0.45, 0.36, 14.5, 0xa8a292);
block(16.9, 0.17, 2.1, 0.45, 0.36, 14.5, 0xa8a292);
const cobbleGeometry = new THREE.BoxGeometry(0.73, 0.09, 0.47);
const cobbleMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const cobbleCount = 44 * 29;
const cobbles = new THREE.InstancedMesh(
cobbleGeometry,
cobbleMaterial,
cobbleCount
);
cobbles.receiveShadow = true;
cobbles.castShadow = false;
const dummy = new THREE.Object3D();
const cobbleColor = new THREE.Color();
let cobbleIndex = 0;
for (let iz = 0; iz < 29; iz++) {
for (let ix = 0; ix < 44; ix++) {
dummy.position.set(
-16.1 + ix * 0.75 + range(-0.035, 0.035),
0.13 + range(-0.008, 0.008),
-4.65 + iz * 0.49 + range(-0.025, 0.025)
);
dummy.rotation.y = range(-0.025, 0.025);
dummy.updateMatrix();
cobbles.setMatrixAt(cobbleIndex, dummy.matrix);
const value = range(0.66, 0.87);
cobbleColor.setRGB(value, value * 0.96, value * 0.86);
cobbles.setColorAt(cobbleIndex, cobbleColor);
cobbleIndex++;
}
}
cobbles.instanceMatrix.needsUpdate = true;
if (cobbles.instanceColor) cobbles.instanceColor.needsUpdate = true;
world.add(cobbles);
// -------------------------------------------------------------------------
// Main Edinburgh sandstone facade fragment
// -------------------------------------------------------------------------
const facade = group();
block(-5, 3.5, -7, 12, 7, 4, 0xb6a17f, facade);
addMasonryFront(-5, -5, 12, 7, facade);
addSteppedGable(-5, -4.87, 12, 7.03, 6, facade);
block(-5, 3.04, -4.78, 12.2, 0.18, 0.25, 0xd1ba8e, facade);
block(-5, 6.02, -4.77, 12.2, 0.17, 0.25, 0xcab18a, facade);
block(-5, 0.23, -4.78, 12.2, 0.22, 0.25, 0xb19b78, facade);
addWindow(-9.0, 4.57, -4.78, 1.05, 1.58, false, facade);
addWindow(-5.15, 4.57, -4.78, 1.1, 1.58, true, facade);
addWindow(-1.25, 4.57, -4.78, 1.05, 1.58, false, facade);
addWindow(-5.0, 8.02, -4.82, 0.72, 0.92, true, facade);
addChimney(-9.1, 9.8, -7.25, facade);
addChimney(-0.8, 9.8, -7.25, facade);
// Shopfront recess.
block(
-7.55,
1.4,
-4.73,
5.85,
2.35,
0.22,
0x263c34,
facade
);
// Large display window.
block(
-8.05,
1.37,
-4.56,
2.82,
1.72,
0.08,
0xffffff,
facade,
warmGlassMaterial
);
block(-8.05, 1.37, -4.49, 0.085, 1.72, 0.1, 0x2e453a, facade);
block(-8.05, 1.37, -4.48, 2.82, 0.085, 0.1, 0x2e453a, facade);
block(-9.53, 1.37, -4.48, 0.12, 1.9, 0.12, 0x2e453a, facade);
block(-6.57, 1.37, -4.48, 0.12, 1.9, 0.12, 0x2e453a, facade);
block(-8.05, 2.36, -4.48, 2.98, 0.12, 0.12, 0x2e453a, facade);
// Shop door.
block(-5.0, 1.37, -4.54, 1.25, 2.06, 0.11, 0x24443a, facade);
block(-5.0, 1.55, -4.46, 0.83, 1.22, 0.05, 0x36594b, facade);
block(-5.0, 0.91, -4.44, 1.34, 0.14, 0.12, 0x152d27, facade);
block(-4.58, 1.45, -4.39, 0.075, 0.3, 0.08, 0xd5b767, facade);
makeSign(
"GRASSMARKET GROCER",
5.7,
0.72,
-7.55,
2.86,
-4.53,
facade,
"#203a31",
"#efd38a",
"TEAS · DAILY BREAD · LOCAL GOODS"
);
// Low shop canopy.
block(-7.55, 2.35, -4.23, 6.08, 0.16, 0.67, 0x314c3d, facade);
for (let i = 0; i < 7; i++) {
block(
-10.1 + i * 0.85,
2.26,
-3.9,
0.42,
0.08,
0.12,
0xb9934f,
facade
);
}
// Hanging sign.
block(-10.0, 2.55, -3.72, 0.08, 0.62, 0.08, 0x263b32, facade);
block(-10.0, 2.48, -3.4, 0.09, 0.85, 0.09, 0x263b32, facade);
makeSign(
"GROCER",
1.55,
0.62,
-10.0,
1.93,
-3.34,
facade,
"#203a31",
"#efd38a"
);
// A separate recessed display on the main facade.
block(
-1.75,
1.55,
-4.72,
1.45,
1.7,
0.17,
0x253b37,
facade
);
block(
-1.75,
1.55,
-4.57,
1.12,
1.38,
0.06,
0xffffff,
facade,
warmGlassMaterial
);
block(-1.75, 1.55, -4.5, 0.07, 1.4, 0.08, 0x4b4a3e, facade);
// Raised stair entrance.
block(0.3, 1.93, -4.72, 1.48, 1.73, 0.19, 0x243934, facade);
block(0.3, 1.93, -4.57, 1.15, 1.48, 0.07, 0x315247, facade);
block(0.3, 2.72, -4.48, 1.58, 0.14, 0.16, 0xcbb488, facade);
block(-0.52, 1.93, -4.48, 0.14, 1.72, 0.16, 0xcbb488, facade);
block(1.12, 1.93, -4.48, 0.14, 1.72, 0.16, 0xcbb488, facade);
block(0.82, 1.87, -4.39, 0.08, 0.28, 0.08, 0xd7b866, facade);
makeSign(
"CASTLE LANE",
1.7,
0.39,
0.3,
3.13,
-4.48,
facade,
"#303b39",
"#e8d7ac"
);
for (let i = 0; i < 5; i++) {
const top = (i + 1) * 0.245;
const z = -2.8 - i * 0.43;
block(
0.3,
top / 2,
z,
1.92,
top,
0.43,
i % 2 ? 0xa99b86 : 0xb9aa94,
facade
);
block(
-0.75,
top + 0.48,
z,
0.09,
0.96,
0.09,
0x313c3d,
facade
);
block(
1.35,
top + 0.48,
z,
0.09,
0.96,
0.09,
0x313c3d,
facade
);
}
block(0.3, 0.59, -4.88, 2.04, 1.18, 0.48, 0xa89882, facade);
// -------------------------------------------------------------------------
// Adjoining old-town frontages
// -------------------------------------------------------------------------
const leftBlock = group();
block(-13.45, 4.35, -7.35, 4.45, 8.7, 4.7, 0xa58e6c, leftBlock);
addMasonryFront(-13.45, -5, 4.45, 8.7, leftBlock, [
0xae9876,
0xbca580,
0x9e8767
]);
addSteppedGable(-13.45, -4.92, 4.45, 8.73, 5, leftBlock, 0xa38c69);
addWindow(-13.45, 6.55, -4.82, 0.86, 1.35, false, leftBlock);
addWindow(-13.45, 3.98, -4.82, 0.92, 1.5, true, leftBlock);
addWindow(-13.45, 1.45, -4.82, 0.8, 1.45, false, leftBlock);
addChimney(-12.1, 11.0, -7.4, leftBlock);
const rightBlock = group();
block(4.85, 4.15, -7.25, 6.45, 8.3, 4.5, 0xb29b77, rightBlock);
addMasonryFront(4.85, -5, 6.45, 8.3, rightBlock, [
0xbba47f,
0xc4ad88,
0xa8906d
]);
addSteppedGable(4.85, -4.92, 6.45, 8.33, 5, rightBlock);
addWindow(3.2, 6.55, -4.82, 0.92, 1.4, false, rightBlock);
addWindow(6.35, 6.55, -4.82, 0.92, 1.4, true, rightBlock);
addWindow(4.8, 8.05, -4.86, 0.72, 0.95, true, rightBlock);
addWindow(3.2, 3.93, -4.82, 0.9, 1.5, false, rightBlock);
addWindow(6.35, 3.93, -4.82, 0.9, 1.5, false, rightBlock);
// Ground-floor bookshop.
block(4.85, 1.3, -4.72, 4.8, 2.15, 0.2, 0x233d3a, rightBlock);
block(3.75, 1.35, -4.55, 2.15, 1.55, 0.07, 0xffffff, rightBlock, warmGlassMaterial);
block(3.75, 1.35, -4.48, 0.08, 1.55, 0.1, 0x2d4942, rightBlock);
block(6.0, 1.35, -4.52, 1.12, 1.96, 0.1, 0x315046, rightBlock);
makeSign(
"OLD TOWN BOOKS",
4.7,
0.61,
4.85,
2.67,
-4.48,
rightBlock,
"#263b38",
"#ead399",
"PRINTS · MAPS · SECONDHAND BOOKS"
);
addChimney(7.6, 10.85, -7.5, rightBlock);
// -------------------------------------------------------------------------
// High Street connection: a steep, clearly rising route
// -------------------------------------------------------------------------
const risingStreet = group();
for (let i = 0; i < 16; i++) {
const top = (i + 1) * 0.42;
const z = 1.0 - i * 0.75;
block(
10.6,
top / 2,
z,
5.55,
top,
0.77,
i % 3 === 0 ? 0x918d82 : 0xa09b8e,
risingStreet
);
block(
7.79,
top + 0.035,
z + 0.32,
0.14,
0.07,
0.55,
0xc0b6a0,
risingStreet
);
block(
13.41,
top + 0.035,
z + 0.32,
0.14,
0.07,
0.55,
0xc0b6a0,
risingStreet
);
}
// Stone side walls reinforce the steep section.
for (let i = 0; i < 13; i++) {
const top = (i + 1) * 0.84;
const z = 0.65 - i * 0.95;
block(
7.55,
top / 2,
z,
0.42,
top,
0.95,
0x958773,
risingStreet
);
block(
13.65,
top / 2,
z,
0.42,
top,
0.95,
0x958773,
risingStreet
);
}
block(10.6, 6.57, -11.35, 6.6, 0.3, 4.3, 0x9e998e, risingStreet);
// A fragment of the adjoining elevated street.
const upperStreetFacade = group();
block(12.65, 10.1, -15.5, 6.35, 6.8, 4, 0xb39c78, upperStreetFacade);
addMasonryFront(12.65, -13.5, 6.35, 6.8, upperStreetFacade);
addWindow(10.85, 8.0, -13.31, 0.9, 1.4, false, upperStreetFacade);
addWindow(13.45, 8.0, -13.31, 0.9, 1.4, true, upperStreetFacade);
addWindow(11.85, 11.0, -13.31, 0.8, 1.25, false, upperStreetFacade);
addWindow(14.25, 11.0, -13.31, 0.8, 1.25, true, upperStreetFacade);
addSteppedGable(12.65, -13.42, 6.35, 13.52, 4, upperStreetFacade);
// Wayfinding sign at the foot of the rise.
block(10.65, 1.28, 1.22, 0.12, 2.56, 0.12, 0x35403f, risingStreet);
makeSign(
"HIGH STREET ↑",
2.3,
0.55,
10.65,
2.35,
1.3,
risingStreet,
"#31545a",
"#f1e4bd"
);
// -------------------------------------------------------------------------
// Castle rock ridge and fortress silhouette
// -------------------------------------------------------------------------
const ridge = group();
const rockColors = [0x6c746d, 0x747a70, 0x5f6862, 0x7d8074];
for (let layer = 0; layer < 4; layer++) {
for (let ix = -3; ix <= 3; ix++) {
for (let iz = 0; iz < 3; iz++) {
const h = range(2.7, 4.5) + layer * 0.55;
const x = ix * 3.15 + range(-0.25, 0.25);
const z = -15.4 - iz * 2.85 + range(-0.25, 0.25);
block(
x,
h / 2,
z,
range(3.0, 3.45),
h,
range(2.8, 3.35),
pick(rockColors),
ridge
);
}
}
}
const castle = group();
block(1.1, 13.7, -19.0, 15.2, 4.9, 4.0, 0x929388, castle);
block(1.0, 16.65, -19.0, 7.2, 4.5, 5.1, 0x8b8d83, castle);
block(-5.35, 14.65, -18.7, 3.35, 6.8, 4.1, 0x99998b, castle);
block(7.55, 14.65, -18.7, 3.35, 6.8, 4.1, 0x99988b, castle);
// Battlements.
for (let i = 0; i < 11; i++) {
const x = -5.7 + i * 1.38;
block(x, 16.25, -16.94, 0.68, 0.62, 0.5, 0xa09e90, castle);
}
for (let i = 0; i < 6; i++) {
const x = -2.1 + i * 1.15;
block(x, 19.0, -16.43, 0.62, 0.62, 0.55, 0xa09e90, castle);
}
block(-5.35, 18.1, -16.62, 3.6, 0.52, 3.9, 0xa09e90, castle);
block(7.55, 18.1, -16.62, 3.6, 0.52, 3.9, 0xa09e90, castle);
// Sparse dark windows in the fortress.
for (let i = 0; i < 6; i++) {
block(-4.7 + i * 2.25, 14.7, -16.94, 0.33, 0.7, 0.1, 0x3c4645, castle);
}
block(-0.8, 17.15, -16.39, 0.46, 0.9, 0.1, 0x384342, castle);
block(2.75, 17.15, -16.39, 0.46, 0.9, 0.1, 0x384342, castle);
// Saltire-inspired block flag.
block(1.0, 21.05, -19.1, 0.08, 3.2, 0.08, 0x4d514d, castle);
block(1.7, 21.65, -19.1, 1.3, 0.83, 0.08, 0x285b87, castle);
block(1.7, 21.65, -19.03, 0.82, 0.14, 0.08, 0xf0eee3, castle);
block(1.7, 21.65, -19.02, 0.14, 0.72, 0.08, 0xf0eee3, castle);
// -------------------------------------------------------------------------
// Street furniture, market activity and trees
// -------------------------------------------------------------------------
function addLamp(x, z) {
const lamp = group(x, 0.16, z);
block(0, 0.12, 0, 0.42, 0.24, 0.42, 0x323a39, lamp);
block(0, 1.42, 0, 0.13, 2.62, 0.13, 0x2d3535, lamp);
block(0, 2.74, 0, 0.39, 0.12, 0.39, 0x303838, lamp);
block(
0,
2.42,
0,
0.38,
0.52,
0.38,
0xffffff,
lamp,
warmGlassMaterial
);
block(0, 2.75, 0, 0.52, 0.12, 0.52, 0x2d3434, lamp);
block(0, 2.94, 0, 0.31, 0.27, 0.31, 0x2d3434, lamp);
block(0, 3.11, 0, 0.13, 0.14, 0.13, 0x2d3434, lamp);
}
addLamp(-12.7, -3.7);
addLamp(-5.4, -3.7);
addLamp(3.9, -3.65);
addLamp(8.0, 4.7);
addLamp(-13.7, 6.9);
function addBollard(x, z) {
const bollard = group(x, 0.16, z);
block(0, 0.37, 0, 0.25, 0.74, 0.25, 0x303b3b, bollard);
block(0, 0.76, 0, 0.3, 0.13, 0.3, 0x47504d, bollard);
block(0, 0.63, 0, 0.27, 0.07, 0.27, 0xc3aa70, bollard);
}
[-14.4, -10.4, -2.2, 2.2, 6.4, 14.5].forEach((x) => {
addBollard(x, -3.65);
});
function addBench(x, z, rotation = 0) {
const bench = group(x, 0.16, z);
bench.rotation.y = rotation;
block(0, 0.57, 0, 2.5, 0.16, 0.66, 0x795d3f, bench);
block(0, 1.0, -0.29, 2.5, 0.64, 0.14, 0x795d3f, bench);
block(-0.88, 0.28, 0, 0.16, 0.56, 0.58, 0x343b38, bench);
block(0.88, 0.28, 0, 0.16, 0.56, 0.58, 0x343b38, bench);
}
addBench(-11.7, 4.8);
addBench(5.2, 5.8, Math.PI);
function addPlanterTree(x, z) {
const tree = group(x, 0.16, z);
block(0, 0.3, 0, 1.55, 0.6, 1.55, 0x827765, tree);
block(0, 0.65, 0, 1.3, 0.16, 1.3, 0x5e5448, tree);
block(0, 1.75, 0, 0.31, 2.35, 0.31, 0x69523c, tree);
block(-0.43, 2.65, 0, 1.3, 1.15, 1.2, 0x657c55, tree);
block(0.45, 2.8, -0.15, 1.35, 1.2, 1.2, 0x718963, tree);
block(0, 3.22, 0.1, 1.45, 1.05, 1.25, 0x7b916a, tree);
block(-0.12, 3.88, -0.08, 0.92, 0.72, 0.9, 0x879d72, tree);
}
addPlanterTree(-14.3, 0.4);
addPlanterTree(2.9, 7.7);
addPlanterTree(12.1, 6.9);
// A compact market stall.
const stall = group(-8.7, 0.16, 2.5);
block(0, 0.85, 0, 3.25, 0.22, 1.55, 0x80603d, stall);
block(-1.42, 0.42, 0, 0.15, 0.84, 1.35, 0x5a4937, stall);
block(1.42, 0.42, 0, 0.15, 0.84, 1.35, 0x5a4937, stall);
for (let i = 0; i < 6; i++) {
block(
-1.75 + i * 0.7,
2.35,
0,
0.7,
0.13,
2.0,
i % 2 ? 0xead9bb : 0x8e493e,
stall
);
}
block(-1.55, 1.37, 0, 0.11, 2.4, 0.11, 0x5a4937, stall);
block(1.55, 1.37, 0, 0.11, 2.4, 0.11, 0x5a4937, stall);
for (let i = 0; i < 9; i++) {
block(
-1.2 + (i % 3) * 0.75,
1.08,
-0.35 + Math.floor(i / 3) * 0.35,
0.45,
0.3,
0.3,
pick([0xb65035, 0xd0a43e, 0x6f8b45]),
stall
);
}
// -------------------------------------------------------------------------
// Voxel pedestrians
// -------------------------------------------------------------------------
function addPerson(x, z, coatColor, skinColor, heading = 0, baseY = 0.17) {
const person = group(x, baseY, z);
person.rotation.y = heading;
block(-0.12, 0.34, 0, 0.17, 0.68, 0.2, 0x28343a, person);
block(0.12, 0.34, 0, 0.17, 0.68, 0.2, 0x28343a, person);
block(0, 0.91, 0, 0.52, 0.7, 0.31, coatColor, person);
block(-0.34, 0.94, 0, 0.15, 0.55, 0.17, coatColor, person);
block(0.34, 0.94, 0, 0.15, 0.55, 0.17, coatColor, person);
block(0, 1.48, 0, 0.31, 0.34, 0.29, skinColor, person);
block(0, 1.66, -0.015, 0.33, 0.12, 0.31, 0x463c32, person);
block(-0.19, 1.12, 0, 0.13, 0.32, 0.22, coatColor, person);
block(0.19, 1.12, 0, 0.13, 0.32, 0.22, coatColor, person);
return person;
}
addPerson(-5.8, 0.5, 0x9c4f43, 0xc8906c, 0.2);
addPerson(-4.95, 0.8, 0x405e68, 0x8e6047, -0.3);
addPerson(-1.9, 3.4, 0x5a6852, 0xd2a17c, 1.25);
addPerson(3.0, 0.1, 0x6b5a7d, 0xb77f5e, -0.6);
addPerson(7.1, 3.9, 0xad7c32, 0xe0b28a, 0.8);
addPerson(-12.4, 6.8, 0x3c4e5b, 0xc99270, -1.1);
addPerson(-10.8, 6.1, 0x86514c, 0x8c5b42, 0.9);
// A pedestrian part-way up the steep route.
addPerson(
9.9,
-3.9,
0x3c6873,
0xd0a07a,
0.12,
2.52
);
// -------------------------------------------------------------------------
// Sky details
// -------------------------------------------------------------------------
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xe7ece8,
roughness: 1
});
function addCloud(x, y, z, scale) {
const cloud = group(x, y, z);
block(0, 0, 0, 4.3 * scale, 0.62 * scale, 1.0 * scale, 0xffffff, cloud, cloudMaterial);
block(-1.5 * scale, 0.32 * scale, 0, 2.0 * scale, 0.85 * scale, 0.9 * scale, 0xffffff, cloud, cloudMaterial);
block(1.6 * scale, 0.25 * scale, 0, 2.5 * scale, 0.75 * scale, 0.9 * scale, 0xffffff, cloud, cloudMaterial);
block(0.45 * scale, 0.62 * scale, 0, 2.0 * scale, 0.75 * scale, 0.85 * scale, 0xffffff, cloud, cloudMaterial);
}
addCloud(-12, 16.2, -28, 1.15);
addCloud(8, 18.0, -31, 1.4);
addCloud(20, 14.8, -27, 0.85);
// -------------------------------------------------------------------------
// Custom camera controls — no addons or example modules
// -------------------------------------------------------------------------
const target = new THREE.Vector3(0, 3.4, -3.6);
let theta = 0.56;
let phi = 1.03;
let cameraRadius = 32;
let zoom = 1;
let autoRotate = false;
let dragging = false;
let panMode = false;
let lastX = 0;
let lastY = 0;
const rightVector = new THREE.Vector3();
const forwardVector = new THREE.Vector3();
function updateCamera() {
cameraRadius = 32;
camera.position.set(
target.x + cameraRadius * Math.sin(phi) * Math.sin(theta),
target.y + cameraRadius * Math.cos(phi),
target.z + cameraRadius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetView() {
theta = 0.56;
phi = 1.03;
zoom = 1;
target.set(0, 3.4, -3.6);
updateCamera();
resize();
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panMode = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panMode) {
rightVector.set(Math.cos(theta), 0, -Math.sin(theta));
forwardVector.set(Math.sin(theta), 0, Math.cos(theta));
const panScale = 0.035 / zoom;
target.addScaledVector(rightVector, -dx * panScale);
target.addScaledVector(forwardVector, -dy * panScale);
} else {
theta -= dx * 0.005;
phi = THREE.MathUtils.clamp(phi - dy * 0.004, 0.45, 1.42);
}
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.2
);
resize();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
});
document.querySelector("#reset").addEventListener("click", resetView);
const rotateButton = document.querySelector("#rotate");
rotateButton.addEventListener("click", () => {
autoRotate = !autoRotate;
rotateButton.classList.toggle("active", autoRotate);
rotateButton.textContent = autoRotate ? "Pause orbit" : "Auto orbit";
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const verticalSize = Math.max(31, 39 / aspect);
camera.left = (-verticalSize * aspect) / 2;
camera.right = (verticalSize * aspect) / 2;
camera.top = verticalSize / 2;
camera.bottom = -verticalSize / 2;
camera.zoom = zoom;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resetView();
// -------------------------------------------------------------------------
// Projected labels and render loop
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function positionTag(element, worldPosition) {
projected.copy(worldPosition).project(camera);
if (projected.z < -1 || projected.z > 1) {
element.style.display = "none";
return;
}
element.style.display = "block";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
const levelPosition = new THREE.Vector3(7.0, 0.55, 5.8);
const risePosition = new THREE.Vector3(10.7, 4.6, -3.4);
const castlePosition = new THREE.Vector3(1.0, 20.8, -19.1);
renderer.setAnimationLoop(() => {
if (autoRotate && !dragging) {
theta += 0.00125;
updateCamera();
}
positionTag(document.querySelector("#tag-level"), levelPosition);
positionTag(document.querySelector("#tag-rise"), risePosition);
positionTag(document.querySelector("#tag-castle"), castlePosition);
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```