Prompt specification
Build or customize the Three.js 3D scene "Casbah doorway and vaulted passage fragment" 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: Casbah doorway and vaulted passage fragment
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/casbah-doorway-and-vaulted-passage-fragment-x2889
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a Casbah doorway and vaulted passage in Algiers. Build a referenced Algiers doorway with thick wall and a short vaulted passage. Keep the entrance scale modest and distinguish public lane from private interior threshold. Voxel style.
Working Three.js Starter (casbah-doorway-and-vaulted-passage-fragment-x2889):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Casbah Threshold — Algiers</title>
<style>
:root {
color-scheme: dark;
--ink: #102b32;
--paper: #f4ead2;
--teal: #28727a;
--sand: #b79768;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d4d8;
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;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
color: var(--paper);
text-shadow: 0 1px 10px rgba(0, 0, 0, 0.38);
}
#title {
position: absolute;
top: 28px;
left: 30px;
max-width: 390px;
}
#eyebrow {
margin-bottom: 7px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.24em;
text-transform: uppercase;
color: #f3d7a1;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 4vw, 54px);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.035em;
}
#subtitle {
margin: 12px 0 0;
max-width: 340px;
font-size: 12px;
line-height: 1.55;
color: rgba(255, 248, 230, 0.82);
}
#legend {
position: absolute;
left: 30px;
bottom: 28px;
display: grid;
gap: 8px;
padding: 13px 15px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 3px;
background: rgba(16, 43, 50, 0.68);
backdrop-filter: blur(10px);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.13);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.swatch {
width: 15px;
height: 7px;
border-radius: 1px;
}
.swatch.lane {
background: #c8bda5;
}
.swatch.threshold {
background: linear-gradient(90deg, #1b2829 50%, #e5dcc5 50%);
}
.swatch.private {
background: #294e53;
border: 1px solid #bd8b50;
}
#controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 2px;
padding: 9px 12px;
color: var(--paper);
background: rgba(16, 43, 50, 0.72);
backdrop-filter: blur(10px);
font: 650 10px/1 Inter, ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(40, 114, 122, 0.9);
transform: translateY(-1px);
}
button.off {
opacity: 0.55;
}
#hint {
position: absolute;
top: 30px;
right: 27px;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.11em;
text-transform: uppercase;
color: rgba(255, 248, 230, 0.68);
}
.guide {
position: absolute;
z-index: 3;
transform: translate(-50%, -100%);
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.34);
border-radius: 2px;
color: #fff9eb;
background: rgba(13, 40, 46, 0.78);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
transition: opacity 120ms ease;
}
.guide::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 20px;
background: linear-gradient(rgba(255, 255, 255, 0.7), transparent);
}
#guides.hidden .guide {
opacity: 0 !important;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #163a40;
background: #d9dfd5;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
#title {
top: 20px;
left: 20px;
}
#subtitle {
display: none;
}
#legend {
left: 16px;
bottom: 16px;
padding: 10px 11px;
}
#controls {
right: 14px;
bottom: 14px;
}
#hint {
display: none;
}
button {
padding: 9px;
}
}
</style>
</head>
<body>
<div id="loading">Assembling the Casbah</div>
<div id="ui">
<header id="title">
<div id="eyebrow">Algiers · Casbah</div>
<h1>Threshold<br>Study</h1>
<p id="subtitle">
A modest Algiers doorway: sunlit public lane, raised tiled threshold,
and a short private barrel-vaulted passage.
</p>
</header>
<div id="hint">Drag · orbit Scroll · zoom R · reset</div>
<div id="legend">
<div class="legend-row">
<span class="swatch lane"></span>
Public lane
</div>
<div class="legend-row">
<span class="swatch threshold"></span>
Raised threshold
</div>
<div class="legend-row">
<span class="swatch private"></span>
Private passage
</div>
</div>
<div id="controls">
<button id="guideButton" type="button">Guides</button>
<button id="resetButton" type="button">Reset</button>
</div>
<div class="guide" id="guide-lane">Public lane</div>
<div class="guide" id="guide-threshold">Private threshold</div>
<div class="guide" id="guide-vault">Vaulted interior</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
// -------------------------------------------------------------------------
// Renderer, camera and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9d4d8);
scene.fog = new THREE.Fog(0xc4d2ce, 19, 39);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive Casbah doorway scene");
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.08,
70
);
const view = {
theta: 0.28,
phi: 1.29,
radius: 13.1,
target: new THREE.Vector3(0, 1.75, -0.65)
};
const defaultView = {
theta: 0.28,
phi: 1.29,
radius: 13.1
};
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);
camera.updateMatrixWorld();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xd8eff4, 0x715b42, 1.75);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2ad, 3.25);
sun.position.set(-7, 12, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.bias = -0.0005;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x9ccbd5, 0.75);
coolFill.position.set(9, 5, -5);
scene.add(coolFill);
const passageLight = new THREE.PointLight(0xffa74f, 18, 7.5, 2);
passageLight.position.set(0.55, 2.25, -3.55);
scene.add(passageLight);
const thresholdBounce = new THREE.PointLight(0xf3b967, 5.5, 4.5, 2);
thresholdBounce.position.set(0, 1.5, -0.8);
scene.add(thresholdBounce);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
function material(color, roughness = 0.92) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
flatShading: true
});
}
const wallMats = [
"#d9ccb0",
"#d2c3a6",
"#e1d5bc",
"#cbbd9f",
"#d7c8aa",
"#cfc19f"
].map((color) => material(color));
const laneMats = [
"#bdb39e",
"#c8bea9",
"#b3a991",
"#d0c6af",
"#c0b49d"
].map((color) => material(color));
const passageMats = [
"#695e4c",
"#756858",
"#5e5749",
"#80725d"
].map((color) => material(color));
const annexMats = [
"#c9d2c7",
"#bfcac0",
"#d8d8c9",
"#b7c3bc"
].map((color) => material(color));
const teal = material("#276b73");
const deepTeal = material("#174b54");
const paleTeal = material("#4f8b8f");
const timber = material("#70452f");
const darkTimber = material("#49362b");
const iron = material("#30383a", 0.72);
const terracotta = material("#a65e3f");
const leaf = material("#58764b");
const leafLight = material("#718b55");
const recess = material("#172b2e", 0.8);
const plaster = material("#d7d2bd");
const gold = material("#c49b5c");
const curtain = material("#693f37");
const glow = new THREE.MeshStandardMaterial({
color: "#ffd17b",
emissive: "#ff982e",
emissiveIntensity: 2.3,
roughness: 0.55
});
const boxGeometry = new THREE.BoxGeometry(1, 1, 1);
const batches = new Map();
const dummy = new THREE.Object3D();
function addBlock(
mat,
width,
height,
depth,
x,
y,
z,
rx = 0,
ry = 0,
rz = 0
) {
dummy.position.set(x, y, z);
dummy.rotation.set(rx, ry, rz);
dummy.scale.set(width, height, depth);
dummy.updateMatrix();
if (!batches.has(mat)) batches.set(mat, []);
batches.get(mat).push(dummy.matrix.clone());
}
function makeBox(
parent,
mat,
width,
height,
depth,
x,
y,
z,
rx = 0,
ry = 0,
rz = 0
) {
const mesh = new THREE.Mesh(boxGeometry, mat);
mesh.position.set(x, y, z);
mesh.rotation.set(rx, ry, rz);
mesh.scale.set(width, height, depth);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function flushBatches() {
for (const [mat, matrices] of batches) {
const mesh = new THREE.InstancedMesh(
boxGeometry,
mat,
matrices.length
);
matrices.forEach((matrix, index) => mesh.setMatrixAt(index, matrix));
mesh.instanceMatrix.setUsage(THREE.StaticDrawUsage);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
scene.add(mesh);
}
}
let seed = 74291;
function random() {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let value = Math.imul(seed ^ (seed >>> 15), 1 | seed);
value = (value + Math.imul(value ^ (value >>> 7), 61 | value)) ^ value;
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
}
function choose(items) {
return items[Math.floor(random() * items.length)];
}
// -------------------------------------------------------------------------
// Public lane
// -------------------------------------------------------------------------
for (let column = 0; column < 18; column++) {
for (let row = 0; row < 18; row++) {
const x = -8.5 + column;
const z = 1.55 + row * 0.76;
const height = 0.075 + random() * 0.025;
addBlock(
choose(laneMats),
0.95,
height,
0.71,
x + (random() - 0.5) * 0.025,
height * 0.5 - 0.018,
z + (random() - 0.5) * 0.025
);
}
}
// A shallow public stair along the left edge of the lane.
for (let step = 0; step < 5; step++) {
const height = 0.16 * (step + 1);
addBlock(
laneMats[step % laneMats.length],
1.55,
height,
0.5,
-4.35,
height * 0.5,
1.55 + step * 0.49
);
}
// -------------------------------------------------------------------------
// Thick main facade
// -------------------------------------------------------------------------
function openingHalfWidth(y) {
const spring = 2.05;
const rise = 1.2;
if (y < spring) return 1.05;
if (y >= spring + rise) return 0;
const t = (y - spring) / rise;
return 1.05 * Math.sqrt(Math.max(0, 1 - t * t));
}
const wallCell = 0.4;
for (let row = 0; row < 14; row++) {
const y = 0.2 + row * wallCell;
for (let column = 0; column < 26; column++) {
const x = -5 + column * wallCell;
// The omitted masonry creates the stepped voxel opening.
if (Math.abs(x) < openingHalfWidth(y)) continue;
addBlock(
choose(wallMats),
0.392,
0.392,
1.86 + random() * 0.07,
x + (random() - 0.5) * 0.008,
y,
-0.46 + (random() - 0.5) * 0.025
);
}
}
// Projecting stone plinth, interrupted at the doorway.
for (let column = 0; column < 26; column++) {
const x = -5 + column * wallCell;
if (Math.abs(x) < 1.3) continue;
addBlock(
choose(passageMats),
0.392,
0.29,
0.18,
x,
0.16,
0.59
);
}
// Stepped roofline and small rooftop blocks.
for (let x = -4.9; x <= 4.9; x += 0.48) {
addBlock(
choose(wallMats),
0.46,
0.34 + (Math.round(x * 10) % 3 === 0 ? 0.12 : 0),
1.95,
x,
5.67,
-0.45
);
}
// -------------------------------------------------------------------------
// Horseshoe-inspired voxel arch and jambs
// -------------------------------------------------------------------------
function addArch(parent, options) {
const {
a,
b,
spring,
z,
count,
width,
height,
depth,
materials,
offset = 0
} = options;
for (let index = 0; index < count; index++) {
const theta = ((index + 0.5) / count) * Math.PI;
const x = a * Math.cos(theta);
const y = spring + b * Math.sin(theta);
const tangentAngle = Math.atan2(
b * Math.cos(theta),
-a * Math.sin(theta)
);
let mat = materials[index % materials.length];
if (offset && index % offset === 0) mat = teal;
makeBox(
parent,
mat,
width,
height,
depth,
x,
y,
z,
0,
0,
tangentAngle
);
}
}
addArch(scene, {
a: 1.16,
b: 1.15,
spring: 2.07,
z: 0.68,
count: 15,
width: 0.31,
height: 0.29,
depth: 0.28,
materials: [plaster, material("#c3b18e"), plaster]
});
makeBox(scene, plaster, 0.28, 2.08, 0.28, -1.23, 1.04, 0.68);
makeBox(scene, plaster, 0.28, 2.08, 0.28, 1.23, 1.04, 0.68);
makeBox(scene, teal, 0.3, 0.31, 0.32, 0, 3.28, 0.69);
// Small geometric zellige-like motif above the modest entrance.
const motif = [
[0, 0, teal],
[-0.15, 0.15, gold],
[0.15, 0.15, gold],
[0, 0.3, paleTeal],
[-0.3, 0.3, plaster],
[0.3, 0.3, plaster]
];
for (const [x, y, mat] of motif) {
makeBox(scene, mat, 0.12, 0.12, 0.1, x, 3.72 + y, 0.64);
}
// -------------------------------------------------------------------------
// Facade windows with Casbah-blue joinery
// -------------------------------------------------------------------------
function addWindow(x, y, shutters = true) {
makeBox(scene, recess, 0.8, 1.02, 0.08, x, y, 0.56);
makeBox(scene, teal, 0.09, 1.15, 0.12, x - 0.45, y, 0.65);
makeBox(scene, teal, 0.09, 1.15, 0.12, x + 0.45, y, 0.65);
makeBox(scene, teal, 0.99, 0.09, 0.12, x, y + 0.57, 0.65);
makeBox(scene, teal, 0.99, 0.09, 0.12, x, y - 0.57, 0.65);
makeBox(scene, plaster, 1.12, 0.13, 0.28, x, y - 0.68, 0.68);
if (shutters) {
makeBox(scene, paleTeal, 0.31, 0.94, 0.1, x - 0.63, y, 0.7, 0, 0.12, 0);
makeBox(scene, paleTeal, 0.31, 0.94, 0.1, x + 0.63, y, 0.7, 0, -0.12, 0);
}
for (let bar = -1; bar <= 1; bar++) {
makeBox(scene, iron, 0.035, 0.91, 0.045, x + bar * 0.2, y, 0.63);
}
}
addWindow(-3.25, 2.72);
addWindow(3.25, 2.72);
// -------------------------------------------------------------------------
// Flanking buildings and narrow lane walls
// -------------------------------------------------------------------------
function buildAnnex(xStart, columns, rows, frontOffset) {
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = xStart + 0.225 + column * 0.45;
const y = 0.2 + row * 0.4;
addBlock(
choose(annexMats),
0.442,
0.392,
1.74,
x,
y,
frontOffset + (random() - 0.5) * 0.025
);
}
}
}
buildAnnex(-8.85, 8, 15, -0.46);
buildAnnex(5.25, 8, 14, -0.52);
// Return walls extending into the public lane.
for (const side of [-1, 1]) {
for (let depth = 0; depth < 8; depth++) {
const z = 1.25 + depth * 0.65;
for (let row = 0; row < 11; row++) {
addBlock(
choose(annexMats),
0.95,
0.38,
0.625,
side * 6.05,
0.2 + row * 0.38,
z
);
}
}
}
// Distant stepped Casbah silhouettes.
const distantMats = [
material("#91a7a4"),
material("#a6b4aa"),
material("#839b99")
];
for (let building = 0; building < 13; building++) {
const x = -14 + building * 2.3;
const height = 3.8 + random() * 3.7;
const width = 1.8 + random() * 0.55;
addBlock(
choose(distantMats),
width,
height,
3.2,
x,
height * 0.5,
-10.5 - random() * 2
);
addBlock(
choose(distantMats),
width * 0.62,
0.7 + random() * 0.9,
1.5,
x + 0.2,
height + 0.35,
-10.8
);
}
// -------------------------------------------------------------------------
// Raised threshold: the transition between public and private
// -------------------------------------------------------------------------
for (let row = 0; row < 2; row++) {
for (let column = 0; column < 8; column++) {
const x = -1.05 + column * 0.3;
const mat = (row + column) % 2 === 0 ? recess : plaster;
makeBox(
scene,
mat,
0.285,
0.15,
0.27,
x,
0.115,
0.34 + row * 0.3
);
}
}
makeBox(scene, passageMats[1], 2.42, 0.12, 0.25, 0, 0.035, 0.97);
// -------------------------------------------------------------------------
// Short private barrel-vaulted passage
// -------------------------------------------------------------------------
// Dark passage floor.
for (let depth = 0; depth < 10; depth++) {
const z = 0.12 - depth * 0.52;
for (let column = 0; column < 5; column++) {
const x = -0.92 + column * 0.46;
addBlock(
choose(passageMats),
0.445,
0.13,
0.5,
x,
0.065,
z
);
}
}
// Passage side walls and the thick masonry reveal.
for (const side of [-1, 1]) {
for (let depth = 0; depth < 10; depth++) {
const z = 0.12 - depth * 0.52;
for (let row = 0; row < 6; row++) {
addBlock(
choose(passageMats),
0.28,
0.35,
0.5,
side * 1.22,
0.18 + row * 0.35,
z
);
}
}
}
// Long block-by-block barrel vault.
for (let segment = 0; segment < 16; segment++) {
const theta = ((segment + 0.5) / 16) * Math.PI;
const x = 1.12 * Math.cos(theta);
const y = 2.08 + 1.08 * Math.sin(theta);
const tangentAngle = Math.atan2(
1.08 * Math.cos(theta),
-1.12 * Math.sin(theta)
);
addBlock(
choose(passageMats),
0.3,
0.3,
5.15,
x,
y,
-2.12,
0,
0,
tangentAngle
);
}
// Successive transverse vault ribs.
const ribZ = [0.33, -1.12, -2.62, -4.12];
for (const z of ribZ) {
addArch(scene, {
a: 1.045,
b: 1.005,
spring: 2.08,
z,
count: 15,
width: 0.34,
height: 0.14,
depth: 0.18,
materials: [material("#81735d"), material("#716653")]
});
}
// Private interior at the end of the passage.
makeBox(scene, material("#393d36"), 2.5, 3.4, 0.22, 0, 1.7, -5.08);
makeBox(scene, deepTeal, 1.42, 2.36, 0.1, 0, 1.32, -4.94);
makeBox(scene, teal, 1.57, 0.1, 0.13, 0, 2.55, -4.9);
makeBox(scene, teal, 0.1, 2.48, 0.13, -0.77, 1.3, -4.9);
makeBox(scene, teal, 0.1, 2.48, 0.13, 0.77, 1.3, -4.9);
// A partially drawn textile screen signals the private interior.
makeBox(scene, iron, 1.65, 0.055, 0.08, 0.42, 2.72, -3.82);
for (let panel = 0; panel < 5; panel++) {
makeBox(
scene,
curtain,
0.15,
2.45,
0.07,
0.28 + panel * 0.17,
1.45,
-3.82
);
}
// -------------------------------------------------------------------------
// Open blue-green door, hinged inward
// -------------------------------------------------------------------------
const doorPivot = new THREE.Group();
doorPivot.position.set(1.06, 0.19, -0.25);
doorPivot.rotation.y = -1.17;
scene.add(doorPivot);
for (let board = 0; board < 6; board++) {
makeBox(
doorPivot,
board % 2 === 0 ? deepTeal : teal,
0.295,
2.46,
0.12,
-(board + 0.5) * 0.305,
1.23,
0
);
}
makeBox(doorPivot, darkTimber, 1.87, 0.13, 0.16, -0.915, 0.25, 0);
makeBox(doorPivot, darkTimber, 1.87, 0.13, 0.16, -0.915, 2.18, 0);
makeBox(doorPivot, darkTimber, 1.87, 0.13, 0.16, -0.915, 1.28, 0);
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 4; column++) {
makeBox(
doorPivot,
iron,
0.055,
0.055,
0.045,
-(0.25 + column * 0.43),
0.55 + row * 0.64,
0.085
);
}
}
// -------------------------------------------------------------------------
// Hanging lantern
// -------------------------------------------------------------------------
const lantern = new THREE.Group();
lantern.position.set(0.65, 2.18, -3.15);
scene.add(lantern);
makeBox(lantern, iron, 0.045, 0.48, 0.045, 0, 0.43, 0);
makeBox(lantern, iron, 0.29, 0.055, 0.29, 0, 0.2, 0);
makeBox(lantern, iron, 0.29, 0.055, 0.29, 0, -0.2, 0);
makeBox(lantern, glow, 0.19, 0.32, 0.19, 0, 0, 0);
for (const x of [-0.12, 0.12]) {
for (const z of [-0.12, 0.12]) {
makeBox(lantern, iron, 0.035, 0.42, 0.035, x, 0, z);
}
}
makeBox(lantern, iron, 0.08, 0.12, 0.08, 0, -0.27, 0);
// -------------------------------------------------------------------------
// Voxel planters and rooftop greenery
// -------------------------------------------------------------------------
function makePlanter(x, y, z, scale = 1) {
makeBox(scene, terracotta, 0.52 * scale, 0.24 * scale, 0.52 * scale, x, y + 0.12 * scale, z);
makeBox(scene, terracotta, 0.43 * scale, 0.22 * scale, 0.43 * scale, x, y + 0.31 * scale, z);
makeBox(scene, darkTimber, 0.1 * scale, 0.55 * scale, 0.1 * scale, x, y + 0.65 * scale, z);
makeBox(scene, leaf, 0.4 * scale, 0.35 * scale, 0.4 * scale, x - 0.15 * scale, y + 0.86 * scale, z);
makeBox(scene, leafLight, 0.34 * scale, 0.34 * scale, 0.33 * scale, x + 0.18 * scale, y + 1.02 * scale, z - 0.04 * scale);
makeBox(scene, leaf, 0.28 * scale, 0.28 * scale, 0.3 * scale, x, y + 1.22 * scale, z + 0.08 * scale);
}
makePlanter(-1.72, 0, 1.2, 0.86);
makePlanter(1.75, 0, 1.38, 0.76);
makePlanter(-2.2, 5.82, -0.6, 0.55);
makePlanter(2.25, 5.82, -0.8, 0.52);
// -------------------------------------------------------------------------
// Build all static instanced masonry
// -------------------------------------------------------------------------
flushBatches();
// -------------------------------------------------------------------------
// Custom camera controls — no addons
// -------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
let activePointer = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointer = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
view.theta -= dx * 0.0052;
view.phi = THREE.MathUtils.clamp(view.phi - dy * 0.0042, 0.76, 1.48);
updateCamera();
});
function releasePointer(event) {
if (event.pointerId !== activePointer) return;
dragging = false;
activePointer = null;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.012,
6.4,
20
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
let changed = true;
switch (event.key) {
case "ArrowLeft":
view.theta += 0.08;
break;
case "ArrowRight":
view.theta -= 0.08;
break;
case "ArrowUp":
view.phi = THREE.MathUtils.clamp(view.phi - 0.055, 0.76, 1.48);
break;
case "ArrowDown":
view.phi = THREE.MathUtils.clamp(view.phi + 0.055, 0.76, 1.48);
break;
case "r":
case "R":
view.theta = defaultView.theta;
view.phi = defaultView.phi;
view.radius = defaultView.radius;
break;
default:
changed = false;
}
if (changed) {
event.preventDefault();
updateCamera();
}
});
$("#resetButton").addEventListener("click", () => {
view.theta = defaultView.theta;
view.phi = defaultView.phi;
view.radius = defaultView.radius;
updateCamera();
});
const guides = [
{
element: $("#guide-lane"),
position: new THREE.Vector3(-3.15, 0.38, 3.45)
},
{
element: $("#guide-threshold"),
position: new THREE.Vector3(0, 0.42, 0.7)
},
{
element: $("#guide-vault"),
position: new THREE.Vector3(0, 2.35, -2.9)
}
];
$("#guideButton").addEventListener("click", () => {
const hidden = $("#guides")?.classList.toggle("hidden");
const button = $("#guideButton");
button.classList.toggle("off", Boolean(hidden));
});
// The guides container is the UI root; use its class directly.
$("#guideButton").addEventListener("click", () => {
const hidden = $("#ui").classList.toggle("hide-guides");
$("#guideButton").classList.toggle("off", hidden);
});
function updateGuides() {
const width = window.innerWidth;
const height = window.innerHeight;
const hidden = $("#ui").classList.contains("hide-guides");
for (const guide of guides) {
const projected = guide.position.clone().project(camera);
const visible =
!hidden &&
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.05 &&
projected.x < 1.05 &&
projected.y > -1.05 &&
projected.y < 1.05;
guide.element.style.opacity = visible ? "1" : "0";
guide.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
guide.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = camera.aspect < 0.8 ? 49 : 42;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let firstFrame = true;
renderer.setAnimationLoop(() => {
const time = clock.getElapsedTime();
// Very subtle lantern breathing.
passageLight.intensity = 17.5 + Math.sin(time * 6.2) * 0.65;
thresholdBounce.intensity = 5.2 + Math.sin(time * 4.1 + 1.2) * 0.25;
updateGuides();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
$("#loading").classList.add("done");
setTimeout(() => $("#loading")?.remove(), 550);
}
});
</script>
</body>
</html>
```