Prompt specification
Build or customize the Three.js 3D scene "Gamla Stan narrow doorway and sloped lane" 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: Gamla Stan narrow doorway and sloped lane
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/gamla-stan-narrow-doorway-and-sloped-lane-x2869
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: Gamla Stan narrow doorway and sloped lane. Build a referenced Stockholm facade fragment with narrow doorway, plastered wall, and gently sloping paving. Show the relationship between compact plot width and pedestrian passage. Return one self-contained HTML file.
Working Three.js Starter (gamla-stan-narrow-doorway-and-sloped-lane-x2869):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gamla Stan — Narrow Threshold, Shared Street</title>
<style>
:root {
--ink: #172026;
--paper: #f3eee4;
--accent: #e7b96d;
--glass: rgba(19, 27, 30, 0.82);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9c4c6;
color: var(--paper);
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; }
.panel {
position: fixed;
z-index: 10;
background: var(--glass);
border: 1px solid rgba(255, 255, 255, 0.12);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-panel {
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
padding: 20px 22px 19px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 10px;
color: var(--accent);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 40px);
font-weight: 400;
line-height: 0.98;
letter-spacing: -0.025em;
}
.subtitle {
max-width: 285px;
margin: 14px 0 0;
color: rgba(243, 238, 228, 0.68);
font-size: 12px;
line-height: 1.55;
}
.toolbar {
top: 22px;
right: 22px;
display: flex;
gap: 8px;
padding: 8px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 2px;
padding: 10px 13px;
background: rgba(255, 255, 255, 0.055);
color: var(--paper);
font: 600 10px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.11em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease;
}
button:hover,
button.active {
border-color: rgba(231, 185, 109, 0.55);
background: rgba(231, 185, 109, 0.12);
}
.metrics {
left: 22px;
bottom: 22px;
display: grid;
grid-template-columns: repeat(3, minmax(90px, 1fr));
width: min(440px, calc(100vw - 44px));
pointer-events: none;
}
.metric {
padding: 14px 16px 13px;
border-right: 1px solid rgba(255, 255, 255, 0.12);
}
.metric:first-child { padding-left: 0; }
.metric:last-child { border-right: 0; }
.metric strong {
display: block;
margin-bottom: 4px;
color: var(--accent);
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 400;
}
.metric span {
color: rgba(243, 238, 228, 0.58);
font-size: 9px;
letter-spacing: 0.12em;
line-height: 1.35;
text-transform: uppercase;
}
.hint {
right: 22px;
bottom: 22px;
max-width: 255px;
padding: 12px 14px;
color: rgba(243, 238, 228, 0.62);
font-size: 10px;
line-height: 1.55;
letter-spacing: 0.04em;
pointer-events: none;
}
.hint b {
color: var(--paper);
font-weight: 600;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #172026;
color: var(--accent);
font-size: 10px;
letter-spacing: 0.22em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 720px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.subtitle { display: none; }
.toolbar {
top: 122px;
right: 12px;
}
.metrics {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
.metric { padding: 11px 9px; }
.metric strong { font-size: 17px; }
.metric span { font-size: 8px; }
.hint { display: none; }
}
</style>
</head>
<body>
<div id="loading">Constructing Stockholm fragment</div>
<section class="panel title-panel">
<div class="eyebrow">Stockholm · Gamla Stan</div>
<h1>Narrow threshold,<br>shared street.</h1>
<p class="subtitle">
An interpretive facade study of compact town plots, a recessed doorway,
and the narrow pedestrian passage between Stockholm’s old buildings.
</p>
</section>
<nav class="panel toolbar" aria-label="Scene controls">
<button id="dimensionButton" class="active" type="button">Dimensions</button>
<button id="resetButton" type="button">Reset view</button>
</nav>
<section class="panel metrics" aria-label="Fragment dimensions">
<div class="metric">
<strong>3.60 m</strong>
<span>Compact plot width</span>
</div>
<div class="metric">
<strong>0.92 m</strong>
<span>Recessed doorway</span>
</div>
<div class="metric">
<strong>2.55 m</strong>
<span>Clear passage</span>
</div>
</section>
<aside class="panel hint">
<b>Drag</b> to orbit · <b>scroll</b> to zoom · <b>shift-drag</b> to pan<br>
<b>Click the doorway</b> to open it · <b>D</b> toggles dimensions
</aside>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive three-dimensional Gamla Stan street scene");
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9c4c6);
scene.fog = new THREE.Fog(0xb9c4c6, 15, 37);
const camera = new THREE.PerspectiveCamera(
55,
window.innerWidth / window.innerHeight,
0.05,
70
);
const target = new THREE.Vector3(-1.35, 2.25, -1.2);
const initialCamera = new THREE.Vector3(2.35, 1.55, 0.65);
camera.position.copy(initialCamera);
camera.lookAt(target);
const hemisphere = new THREE.HemisphereLight(0xd9e7eb, 0x6b5544, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe1b4, 3.25);
sun.position.set(-7, 13, 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 = 35;
sun.shadow.bias = -0.00045;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9db8c5, 0.55);
fill.position.set(8, 7, -6);
scene.add(fill);
let randomSeed = 7319;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function makeCanvasTexture(canvas, repeatX = 1, repeatY = 1) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(repeatX, repeatY);
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function plasterTexture(baseColor) {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 512;
const ctx = canvas.getContext("2d");
ctx.fillStyle = baseColor;
ctx.fillRect(0, 0, 512, 512);
for (let i = 0; i < 720; i++) {
const light = random() > 0.48;
ctx.fillStyle = light
? `rgba(255,245,220,${0.015 + random() * 0.055})`
: `rgba(38,31,24,${0.012 + random() * 0.055})`;
const size = 1 + random() * 5;
ctx.fillRect(random() * 512, random() * 512, size, size);
}
for (let i = 0; i < 42; i++) {
const x = random() * 512;
const y = random() * 512;
const radius = 8 + random() * 48;
const gradient = ctx.createRadialGradient(x, y, 0, x, y, radius);
gradient.addColorStop(0, `rgba(54,43,33,${0.018 + random() * 0.035})`);
gradient.addColorStop(1, "rgba(54,43,33,0)");
ctx.fillStyle = gradient;
ctx.fillRect(x - radius, y - radius, radius * 2, radius * 2);
}
for (let i = 0; i < 30; i++) {
const x = random() * 512;
const width = 2 + random() * 12;
const height = 45 + random() * 220;
const gradient = ctx.createLinearGradient(0, 0, 0, height);
gradient.addColorStop(0, "rgba(45,37,29,0.065)");
gradient.addColorStop(1, "rgba(45,37,29,0)");
ctx.fillStyle = gradient;
ctx.fillRect(x, 0, width, height);
}
const wash = ctx.createLinearGradient(0, 350, 0, 512);
wash.addColorStop(0, "rgba(40,35,29,0)");
wash.addColorStop(1, "rgba(40,35,29,0.11)");
ctx.fillStyle = wash;
ctx.fillRect(0, 350, 512, 162);
return makeCanvasTexture(canvas, 1, 1);
}
function cobbleTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 512;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#494944";
ctx.fillRect(0, 0, 1024, 512);
const rows = 11;
const rowHeight = 512 / rows;
for (let row = 0; row < rows; row++) {
const offset = row % 2 ? -48 : 0;
for (let x = -100 + offset; x < 1024; x += 96) {
const inset = 2 + random() * 2;
const width = 88 + random() * 5;
const height = rowHeight - inset * 2;
const shade = 93 + Math.floor(random() * 42);
const warmth = Math.floor(random() * 11);
ctx.fillStyle = `rgb(${shade + warmth},${shade + 5},${shade - 2})`;
ctx.beginPath();
ctx.roundRect(
x + inset,
row * rowHeight + inset,
width,
height,
4 + random() * 5
);
ctx.fill();
ctx.strokeStyle = "rgba(35,34,31,0.28)";
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = "rgba(255,255,255,0.045)";
ctx.fillRect(x + inset + 3, row * rowHeight + inset + 2, width - 7, 2);
}
}
for (let i = 0; i < 1600; i++) {
ctx.fillStyle = random() > 0.5
? "rgba(255,255,255,0.035)"
: "rgba(0,0,0,0.045)";
ctx.fillRect(random() * 1024, random() * 512, 2, 2);
}
return makeCanvasTexture(canvas, 10, 1.45);
}
function roofTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 512;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#63382d";
ctx.fillRect(0, 0, 512, 512);
for (let row = 0; row < 16; row++) {
for (let col = -1; col < 11; col++) {
const offset = row % 2 ? 14 : 0;
const red = 106 + Math.floor(random() * 42);
const green = 48 + Math.floor(random() * 20);
const blue = 36 + Math.floor(random() * 17);
ctx.fillStyle = `rgb(${red},${green},${blue})`;
ctx.fillRect(col * 48 + offset + 1, row * 32 + 1, 46, 30);
ctx.fillStyle = "rgba(255,180,125,0.08)";
ctx.fillRect(col * 48 + offset + 3, row * 32 + 3, 42, 2);
}
}
return makeCanvasTexture(canvas, 3, 2);
}
function windowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 384;
const ctx = canvas.getContext("2d");
const gradient = ctx.createLinearGradient(0, 0, 0, 384);
gradient.addColorStop(0, "#849ca6");
gradient.addColorStop(0.48, "#3d515b");
gradient.addColorStop(1, "#17252c");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 256, 384);
ctx.fillStyle = "rgba(242,220,182,0.18)";
ctx.fillRect(25, 235, 45, 105);
ctx.fillRect(174, 185, 34, 155);
ctx.fillStyle = "rgba(10,19,23,0.34)";
ctx.beginPath();
ctx.moveTo(0, 320);
ctx.lineTo(75, 205);
ctx.lineTo(105, 235);
ctx.lineTo(150, 160);
ctx.lineTo(256, 300);
ctx.lineTo(256, 384);
ctx.lineTo(0, 384);
ctx.closePath();
ctx.fill();
ctx.fillStyle = "rgba(255,255,255,0.055)";
ctx.fillRect(0, 35, 256, 5);
return makeCanvasTexture(canvas);
}
const cobbleMap = cobbleTexture();
const roofMap = roofTexture();
const glassMap = windowTexture();
const pavingMaterial = new THREE.MeshStandardMaterial({
map: cobbleMap,
color: 0xffffff,
roughness: 0.92,
metalness: 0.02
});
const roofMaterial = new THREE.MeshStandardMaterial({
map: roofMap,
color: 0xffffff,
roughness: 0.88
});
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0x77766e,
roughness: 0.96
});
const darkStoneMaterial = new THREE.MeshStandardMaterial({
color: 0x4a4b47,
roughness: 0.96
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0xd9d3c4,
roughness: 0.77
});
const ironMaterial = new THREE.MeshStandardMaterial({
color: 0x242928,
roughness: 0.58,
metalness: 0.55
});
const brassMaterial = new THREE.MeshStandardMaterial({
color: 0xb99750,
roughness: 0.35,
metalness: 0.7
});
const glassMaterial = new THREE.MeshStandardMaterial({
map: glassMap,
color: 0xffffff,
roughness: 0.29,
metalness: 0.14
});
const FAR_FRONT = -1.2;
const OPPOSITE_FRONT = 1.35;
const LANE_SLOPE = 0.035;
function groundY(x) {
return LANE_SLOPE * (x + 8) - 0.055;
}
function addBox(width, height, depth, material, x, y, z, parent = scene, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const laneGeometry = new THREE.PlaneGeometry(32, OPPOSITE_FRONT - FAR_FRONT, 1, 1);
laneGeometry.rotateX(-Math.PI / 2);
const lanePositions = laneGeometry.attributes.position;
for (let i = 0; i < lanePositions.count; i++) {
const x = lanePositions.getX(i);
lanePositions.setY(i, groundY(x));
}
laneGeometry.computeVertexNormals();
const lane = new THREE.Mesh(laneGeometry, pavingMaterial);
lane.receiveShadow = true;
scene.add(lane);
const underlay = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({ color: 0x66645d, roughness: 1 })
);
underlay.rotation.x = -Math.PI / 2;
underlay.position.y = -0.42;
underlay.receiveShadow = true;
scene.add(underlay);
for (let x = -15.5; x < 16; x += 0.74) {
const curb = addBox(
0.70, 0.14, 0.20,
stoneMaterial,
x, groundY(x) + 0.035, OPPOSITE_FRONT - 0.11,
scene, false
);
curb.rotation.z = Math.atan(LANE_SLOPE);
}
for (let x = -15.5; x < 16; x += 0.9) {
const gutter = addBox(
0.86, 0.025, 0.075,
darkStoneMaterial,
x, groundY(x) + 0.014, FAR_FRONT + 0.08,
scene, false
);
gutter.rotation.z = Math.atan(LANE_SLOPE);
}
function createRoof(x, width, front, depth, wallTop, rise, side = 1) {
const ridgeZ = front - side * depth * 0.5;
const backEaveZ = front - side * depth;
const gableGeometry = new THREE.BufferGeometry();
const vertices = side === 1
? [
x - width / 2, wallTop, 0,
x + width / 2, wallTop, 0,
x, wallTop + rise, 0
]
: [
x + width / 2, wallTop, 0,
x - width / 2, wallTop, 0,
x, wallTop + rise, 0
];
gableGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
gableGeometry.computeVertexNormals();
const gableMaterial = new THREE.MeshStandardMaterial({
color: 0x786f5e,
roughness: 0.95,
side: THREE.DoubleSide
});
const gable = new THREE.Mesh(gableGeometry, gableMaterial);
gable.position.z = front + side * 0.008;
gable.castShadow = true;
gable.receiveShadow = true;
scene.add(gable);
function roofPanel(eaveZ) {
const start = new THREE.Vector3(x, wallTop + rise, ridgeZ);
const end = new THREE.Vector3(x, wallTop, eaveZ);
const direction = end.clone().sub(start);
const length = direction.length();
const panel = new THREE.Mesh(
new THREE.BoxGeometry(width + 0.28, 0.13, length),
roofMaterial
);
panel.position.copy(start).add(end).multiplyScalar(0.5);
panel.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
panel.castShadow = true;
panel.receiveShadow = true;
scene.add(panel);
}
roofPanel(front);
roofPanel(backEaveZ);
const chimney = addBox(
0.52, 1.25, 0.52,
new THREE.MeshStandardMaterial({ color: 0x735c50, roughness: 0.93 }),
x + width * 0.25,
wallTop + rise + 0.22,
ridgeZ + side * 0.35
);
chimney.castShadow = true;
const cap = addBox(
0.64, 0.12, 0.64,
darkStoneMaterial,
chimney.position.x,
chimney.position.y + 0.65,
chimney.position.z
);
cap.castShadow = true;
}
function addWindow(x, y, width, height, front, side = 1, shutters = false) {
const opening = addBox(
width, height, 0.05,
glassMaterial,
x, y, front + side * 0.025,
scene, false
);
opening.receiveShadow = true;
const verticalFrame = 0.055;
const frameDepth = 0.075;
addBox(
verticalFrame, height + 0.10, frameDepth,
frameMaterial,
x - width / 2, y, front + side * 0.06
);
addBox(
verticalFrame, height + 0.10, frameDepth,
frameMaterial,
x + width / 2, y, front + side * 0.06
);
addBox(
width + 0.10, verticalFrame, frameDepth,
frameMaterial,
x, y + height / 2, front + side * 0.06
);
addBox(
width + 0.10, verticalFrame, frameDepth,
frameMaterial,
x, y - height / 2, front + side * 0.06
);
addBox(
0.035, height, 0.085,
frameMaterial,
x, y, front + side * 0.075
);
addBox(
width, 0.035, 0.085,
frameMaterial,
x, y + 0.08, front + side * 0.075
);
addBox(
width + 0.24, 0.10, 0.25,
stoneMaterial,
x, y - height / 2 - 0.065, front + side * 0.10
);
addBox(
width + 0.18, 0.075, 0.15,
frameMaterial,
x, y + height / 2 + 0.07, front + side * 0.07
);
if (shutters) {
const shutterMaterial = new THREE.MeshStandardMaterial({
color: 0x53645f,
roughness: 0.8
});
for (const direction of [-1, 1]) {
const shutterX = x + direction * (width / 2 + width * 0.35);
addBox(
width * 0.38, height, 0.055,
shutterMaterial,
shutterX, y, front + side * 0.085
);
for (let slat = 0; slat < 8; slat++) {
addBox(
width * 0.34, 0.018, 0.018,
ironMaterial,
shutterX,
y - height / 2 + 0.12 + slat * (height - 0.2) / 7,
front + side * 0.12,
scene,
false
);
}
}
}
}
function createBuilding({
x,
width,
height,
color,
front = FAR_FRONT,
side = 1,
roof = true,
door = false
}) {
const depth = 5.6;
const base = 0.15;
const wallTop = base + height;
const bodyCenterZ = front - side * depth / 2;
const wallMap = plasterTexture(color);
const wallMaterial = new THREE.MeshStandardMaterial({
map: wallMap,
color: 0xffffff,
roughness: 0.97
});
const body = addBox(
width, height, depth,
wallMaterial,
x, base + height / 2, bodyCenterZ
);
body.receiveShadow = true;
addBox(
width + 0.025, 0.66, 0.15,
stoneMaterial,
x, 0.43, front + side * 0.045
);
addBox(
width + 0.12, 0.12, 0.22,
frameMaterial,
x, wallTop - 0.06, front + side * 0.07
);
if (roof) {
createRoof(x, width, front, depth, wallTop, 1.55, side);
}
if (door) {
const doorMaterial = new THREE.MeshStandardMaterial({
color: 0x26312d,
roughness: 0.69
});
addBox(
0.93, 2.30, 0.07,
doorMaterial,
x, base + 1.15, front + side * 0.055
);
addBox(
1.12, 0.12, 0.18,
stoneMaterial,
x, base + 2.36, front + side * 0.08
);
}
return { x, width, height, base, wallTop, front, side };
}
const main = createBuilding({
x: -1.4,
width: 3.6,
height: 7.55,
color: "#b69c70"
});
createBuilding({
x: 2.55,
width: 4.3,
height: 7.05,
color: "#c1b49a",
door: true
});
createBuilding({
x: 7.0,
width: 4.2,
height: 7.8,
color: "#9b8c79"
});
createBuilding({
x: -5.45,
width: 4.5,
height: 7.35,
color: "#a97868",
door: true
});
createBuilding({
x: -5.4,
width: 5.2,
height: 7.8,
color: "#8e9b96",
front: OPPOSITE_FRONT,
side: -1
});
createBuilding({
x: -0.8,
width: 3.8,
height: 7.2,
color: "#9b8b72",
front: OPPOSITE_FRONT,
side: -1,
door: true
});
addWindow(-2.48, 1.36, 0.67, 1.18, FAR_FRONT, 1, true);
addWindow(-0.38, 1.36, 0.67, 1.18, FAR_FRONT, 1, true);
addWindow(-2.48, 3.62, 0.73, 1.38, FAR_FRONT, 1, true);
addWindow(-0.38, 3.62, 0.73, 1.38, FAR_FRONT, 1, true);
addWindow(-2.48, 5.68, 0.65, 1.20, FAR_FRONT, 1, false);
addWindow(-0.38, 5.68, 0.65, 1.20, FAR_FRONT, 1, false);
addWindow(-1.42, 6.98, 0.72, 0.70, FAR_FRONT, 1, false);
addWindow(1.48, 1.42, 0.73, 1.24, FAR_FRONT, 1, false);
addWindow(3.58, 1.42, 0.73, 1.24, FAR_FRONT, 1, false);
addWindow(1.48, 3.70, 0.73, 1.30, FAR_FRONT, 1, false);
addWindow(3.58, 3.70, 0.73, 1.30, FAR_FRONT, 1, false);
addWindow(-6.60, 1.48, 0.72, 1.22, FAR_FRONT, 1, false);
addWindow(-4.30, 1.48, 0.72, 1.22, FAR_FRONT, 1, false);
addWindow(-6.60, 3.85, 0.72, 1.26, FAR_FRONT, 1, false);
addWindow(-4.30, 3.85, 0.72, 1.26, FAR_FRONT, 1, false);
const doorX = -1.30;
const doorWidth = 0.92;
const doorHeight = 2.35;
const doorBottom = 0.34;
const doorZ = FAR_FRONT + 0.09;
const openingMaterial = new THREE.MeshStandardMaterial({
color: 0x111716,
roughness: 1
});
addBox(
doorWidth + 0.12,
doorHeight + 0.12,
0.035,
openingMaterial,
doorX,
doorBottom + doorHeight / 2,
FAR_FRONT + 0.016,
scene,
false
);
addBox(
0.13, doorHeight + 0.18, 0.18,
stoneMaterial,
doorX - doorWidth / 2 - 0.07,
doorBottom + doorHeight / 2,
FAR_FRONT + 0.08
);
addBox(
0.13, doorHeight + 0.18, 0.18,
stoneMaterial,
doorX + doorWidth / 2 + 0.07,
doorBottom + doorHeight / 2,
FAR_FRONT + 0.08
);
addBox(
doorWidth + 0.35, 0.16, 0.19,
stoneMaterial,
doorX,
doorBottom + doorHeight + 0.08,
FAR_FRONT + 0.085
);
addBox(
1.22, 0.13, 0.54,
stoneMaterial,
doorX,
groundY(doorX) + 0.035,
FAR_FRONT + 0.29,
scene,
false
);
addBox(
1.10, 0.13, 0.32,
stoneMaterial,
doorX,
groundY(doorX) + 0.12,
FAR_FRONT + 0.17,
scene,
false
);
const doorPivot = new THREE.Group();
doorPivot.position.set(doorX - doorWidth / 2, doorBottom, doorZ);
scene.add(doorPivot);
const doorLeafMaterial = new THREE.MeshStandardMaterial({
color: 0x28332f,
roughness: 0.68
});
const doorLeaf = addBox(
doorWidth,
doorHeight,
0.075,
doorLeafMaterial,
doorWidth / 2,
doorHeight / 2,
0,
doorPivot
);
doorLeaf.userData.isDoor = true;
const panelMaterial = new THREE.MeshStandardMaterial({
color: 0x1d2825,
roughness: 0.72
});
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 2; column++) {
addBox(
0.31,
0.50,
0.022,
panelMaterial,
0.23 + column * 0.44,
0.34 + row * 0.67,
0.048,
doorPivot,
false
);
}
}
addBox(
0.24, 0.035, 0.025,
brassMaterial,
0.73,
1.03,
0.075,
doorPivot,
false
);
const knob = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 14, 10),
brassMaterial
);
knob.position.set(0.75, 1.03, 0.095);
knob.castShadow = true;
doorPivot.add(knob);
const numberCanvas = document.createElement("canvas");
numberCanvas.width = 128;
numberCanvas.height = 128;
const numberContext = numberCanvas.getContext("2d");
numberContext.fillStyle = "#d8c58d";
numberContext.beginPath();
numberContext.arc(64, 64, 52, 0, Math.PI * 2);
numberContext.fill();
numberContext.fillStyle = "#26302d";
numberContext.font = "bold 58px Georgia";
numberContext.textAlign = "center";
numberContext.textBaseline = "middle";
numberContext.fillText("18", 64, 68);
const numberTexture = makeCanvasTexture(numberCanvas);
const numberMaterial = new THREE.MeshStandardMaterial({
map: numberTexture,
transparent: true,
roughness: 0.7
});
const numberPlate = new THREE.Mesh(
new THREE.PlaneGeometry(0.17, 0.17),
numberMaterial
);
numberPlate.position.set(doorX + 0.25, doorBottom + 1.65, FAR_FRONT + 0.105);
scene.add(numberPlate);
const pipeMaterial = new THREE.MeshStandardMaterial({
color: 0x575956,
roughness: 0.58,
metalness: 0.48
});
const drainpipe = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 6.75, 12),
pipeMaterial
);
drainpipe.position.set(0.24, 3.85, FAR_FRONT + 0.13);
drainpipe.castShadow = true;
scene.add(drainpipe);
for (const y of [1.0, 3.8, 6.6]) {
const bracket = addBox(
0.18, 0.04, 0.13,
ironMaterial,
0.16, y, FAR_FRONT + 0.12,
scene,
false
);
bracket.rotation.z = -0.12;
}
const lampX = -0.24;
const lampY = 2.85;
addBox(
0.055, 0.48, 0.055,
ironMaterial,
lampX, lampY - 0.06, FAR_FRONT + 0.14
);
const lampArm = addBox(
0.32, 0.055, 0.055,
ironMaterial,
lampX + 0.13, lampY + 0.15, FAR_FRONT + 0.14
);
const lampGlass = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.12, 0.25, 6),
new THREE.MeshStandardMaterial({
color: 0xd7b56f,
emissive: 0xffbb58,
emissiveIntensity: 1.2,
transparent: true,
opacity: 0.86,
roughness: 0.35
})
);
lampGlass.position.set(lampX + 0.25, lampY - 0.02, FAR_FRONT + 0.18);
scene.add(lampGlass);
const lampCap = new THREE.Mesh(
new THREE.ConeGeometry(0.14, 0.12, 6),
ironMaterial
);
lampCap.position.set(lampX + 0.25, lampY + 0.17, FAR_FRONT + 0.18);
scene.add(lampCap);
const lampLight = new THREE.PointLight(0xffbd68, 8, 3.5, 2);
lampLight.position.set(lampX + 0.25, lampY, FAR_FRONT + 0.32);
scene.add(lampLight);
function makeLabelTexture(text, accent = false) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.fillStyle = accent ? "rgba(231,185,109,0.94)" : "rgba(21,28,30,0.88)";
ctx.beginPath();
ctx.roundRect(4, 4, 760, 152, 15);
ctx.fill();
ctx.strokeStyle = accent ? "rgba(35,38,38,0.4)" : "rgba(255,255,255,0.18)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = accent ? "#25302d" : "#f3eee4";
ctx.font = "600 37px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 384, 82);
return makeCanvasTexture(canvas);
}
function makeLabel(text, position, width = 2.2, accent = false) {
const material = new THREE.SpriteMaterial({
map: makeLabelTexture(text, accent),
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.copy(position);
sprite.scale.set(width, width * 0.208, 1);
sprite.renderOrder = 30;
return sprite;
}
const dimensions = new THREE.Group();
scene.add(dimensions);
const dimensionMaterial = new THREE.LineBasicMaterial({
color: 0xe7b96d,
transparent: true,
opacity: 0.9,
depthTest: false
});
function dimensionLine(points) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, dimensionMaterial);
line.renderOrder = 25;
dimensions.add(line);
return line;
}
const plotLeft = main.x - main.width / 2;
const plotRight = main.x + main.width / 2;
const plotZ = FAR_FRONT + 0.50;
dimensionLine([
new THREE.Vector3(plotLeft, groundY(plotLeft) + 0.075, plotZ),
new THREE.Vector3(plotRight, groundY(plotRight) + 0.075, plotZ)
]);
for (const x of [plotLeft, plotRight]) {
dimensionLine([
new THREE.Vector3(x, groundY(x) + 0.075, plotZ - 0.13),
new THREE.Vector3(x, groundY(x) + 0.075, plotZ + 0.13)
]);
}
dimensions.add(makeLabel(
"3.60 M COMPACT PLOT",
new THREE.Vector3(main.x, groundY(main.x) + 0.36, plotZ),
2.45,
true
));
const doorMeasureZ = FAR_FRONT + 0.73;
dimensionLine([
new THREE.Vector3(doorX - doorWidth / 2, doorBottom + 0.07, doorMeasureZ),
new THREE.Vector3(doorX + doorWidth / 2, doorBottom + 0.07, doorMeasureZ)
]);
for (const x of [doorX - doorWidth / 2, doorX + doorWidth / 2]) {
dimensionLine([
new THREE.Vector3(x, doorBottom + 0.01, doorMeasureZ),
new THREE.Vector3(x, doorBottom + 0.16, doorMeasureZ)
]);
}
dimensions.add(makeLabel(
"0.92 M DOOR",
new THREE.Vector3(doorX + 0.42, doorBottom + 0.39, doorMeasureZ),
1.55
));
const passageX = 0.77;
const passageY = groundY(passageX) + 0.09;
dimensionLine([
new THREE.Vector3(passageX, passageY, FAR_FRONT + 0.03),
new THREE.Vector3(passageX, passageY, OPPOSITE_FRONT - 0.03)
]);
for (const z of [FAR_FRONT + 0.03, OPPOSITE_FRONT - 0.03]) {
dimensionLine([
new THREE.Vector3(passageX - 0.14, passageY, z),
new THREE.Vector3(passageX + 0.14, passageY, z)
]);
}
dimensions.add(makeLabel(
"2.55 M CLEAR PASSAGE",
new THREE.Vector3(passageX, passageY + 0.48, 0.05),
2.65,
true
));
const spherical = new THREE.Spherical().setFromVector3(
initialCamera.clone().sub(target)
);
const initialSpherical = spherical.clone();
function updateCameraFromSpherical() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 1.15, 1.53);
spherical.theta = THREE.MathUtils.clamp(spherical.theta, -0.18, 1.56);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 2.25, 10.5);
spherical.makeSafe();
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(target).add(offset);
camera.lookAt(target);
camera.updateMatrixWorld();
}
updateCameraFromSpherical();
const pointerPositions = new Map();
let pointerDown = false;
let dragDistance = 0;
let lastPointer = null;
let shiftPressed = false;
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
let doorOpenTarget = 0;
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = true;
dragDistance = 0;
lastPointer = { x: event.clientX, y: event.clientY };
pointerPositions.set(event.pointerId, { x: event.clientX, y: event.clientY });
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerPositions.has(event.pointerId)) return;
const previous = pointerPositions.get(event.pointerId);
const previousDistance = pointerPositions.size === 2
? Math.hypot(
[...pointerPositions.values()][0].x - [...pointerPositions.values()][1].x,
[...pointerPositions.values()][0].y - [...pointerPositions.values()][1].y
)
: 0;
pointerPositions.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointerPositions.size === 2) {
const points = [...pointerPositions.values()];
const distance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
if (previousDistance > 0 && distance > 0) {
spherical.radius *= previousDistance / distance;
updateCameraFromSpherical();
}
return;
}
if (!pointerDown || !lastPointer) return;
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
dragDistance += Math.hypot(dx, dy);
lastPointer = { x: event.clientX, y: event.clientY };
if (event.shiftKey || shiftPressed) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const panScale = spherical.radius * 0.0014;
target.addScaledVector(right, -dx * panScale);
target.addScaledVector(up, dy * panScale);
} else {
spherical.theta -= dx * 0.0045;
spherical.phi -= dy * 0.0035;
}
updateCameraFromSpherical();
});
function releasePointer(event) {
pointerPositions.delete(event.pointerId);
if (pointerPositions.size === 0) {
pointerDown = false;
lastPointer = null;
}
if (dragDistance < 5) {
pointerNDC.x = (event.clientX / window.innerWidth) * 2 - 1;
pointerNDC.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObject(doorLeaf, true);
if (hits.length) {
doorOpenTarget = doorOpenTarget === 0 ? -1.15 : 0;
}
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
updateCameraFromSpherical();
},
{ passive: false }
);
window.addEventListener("keydown", event => {
if (event.key === "Shift") shiftPressed = true;
if (event.key.toLowerCase() === "d") {
dimensions.visible = !dimensions.visible;
document.getElementById("dimensionButton").classList.toggle(
"active",
dimensions.visible
);
}
if (event.key.toLowerCase() === "r") {
target.set(-1.35, 2.25, -1.2);
spherical.copy(initialSpherical);
updateCameraFromSpherical();
}
});
window.addEventListener("keyup", event => {
if (event.key === "Shift") shiftPressed = false;
});
document.getElementById("dimensionButton").addEventListener("click", () => {
dimensions.visible = !dimensions.visible;
document.getElementById("dimensionButton").classList.toggle(
"active",
dimensions.visible
);
});
document.getElementById("resetButton").addEventListener("click", () => {
target.set(-1.35, 2.25, -1.2);
spherical.copy(initialSpherical);
updateCameraFromSpherical();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
doorPivot.rotation.y = THREE.MathUtils.lerp(
doorPivot.rotation.y,
doorOpenTarget,
1 - Math.exp(-delta * 8)
);
renderer.render(scene, camera);
if (!loading.classList.contains("hidden")) {
loading.classList.add("hidden");
}
});
</script>
</body>
</html>
```