Prompt specification
Build or customize the Three.js 3D scene "Alfama tiled doorway and stair corner" 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: Alfama tiled doorway and stair corner
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/alfama-tiled-doorway-and-stair-corner-x2837
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a voxel doorway and stair corner inspired by a referenced fragment of Lisbon's Alfama. Build a compact plaster facade, a recessed entrance, an original geometric tile border, and a short flight of steps meeting sloping paving. Let the cubic construction remain visible in the wall thickness, stair risers, and stepped ground profile. The doorway should remain upright while the street changes elevation beside it. Add a simple iron handrail and one neighboring wall return to frame the corner. Keep the scene a selective architectural study, with no invented claim that its dimensions reproduce a surveyed address.
Working Three.js Starter (alfama-tiled-doorway-and-stair-corner-x2837):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Alfama-Inspired Voxel Stair Corner</title>
<style>
:root {
color-scheme: light;
--ink: #17383d;
--paper: rgba(246, 239, 222, 0.92);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8d6d2;
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;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
ellipse at center,
transparent 48%,
rgba(37, 49, 47, 0.12) 100%
);
z-index: 2;
}
.plate {
position: fixed;
left: clamp(18px, 3vw, 42px);
bottom: clamp(18px, 3vw, 38px);
z-index: 3;
width: min(390px, calc(100vw - 36px));
padding: 18px 20px 17px;
color: var(--ink);
background: var(--paper);
border: 1px solid rgba(23, 56, 61, 0.16);
border-radius: 3px;
box-shadow: 0 12px 35px rgba(35, 49, 48, 0.14);
backdrop-filter: blur(9px);
pointer-events: none;
}
.plate .eyebrow {
margin-bottom: 7px;
color: #a65d43;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.plate h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(24px, 3vw, 34px);
font-weight: 500;
line-height: 1.05;
letter-spacing: -0.025em;
}
.plate p {
margin: 11px 0 0;
font-size: 12px;
line-height: 1.5;
color: rgba(23, 56, 61, 0.76);
}
.controls {
position: fixed;
top: clamp(16px, 2.5vw, 30px);
right: clamp(16px, 2.5vw, 30px);
z-index: 3;
padding: 9px 12px;
color: rgba(23, 56, 61, 0.86);
background: rgba(246, 239, 222, 0.76);
border: 1px solid rgba(23, 56, 61, 0.13);
border-radius: 3px;
font-size: 10px;
letter-spacing: 0.025em;
backdrop-filter: blur(8px);
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 5;
display: grid;
place-items: center;
color: var(--ink);
background: #c8d6d2;
font-size: 12px;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 640px) {
.plate {
padding: 14px 16px;
}
.plate p {
max-width: 310px;
font-size: 11px;
}
.controls {
top: 12px;
right: 12px;
max-width: 215px;
line-height: 1.45;
}
}
</style>
</head>
<body>
<div id="loading">Building the study</div>
<div class="vignette"></div>
<header class="plate">
<div class="eyebrow">Lisbon · Alfama inspiration</div>
<h1>Voxel stair corner</h1>
<p>
A selective architectural study with illustrative dimensions.
It is not presented as a surveyed reconstruction of a specific address.
</p>
</header>
<div class="controls">
Drag to orbit · Shift-drag to pan · Scroll to zoom · Double-click to reset
</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 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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#c8d6d2");
scene.fog = new THREE.Fog("#c8d6d2", 15, 31);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(
"#f6ead2",
"#657877",
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0cf", 3.2);
sun.position.set(-4.5, 11, 7.5);
sun.target.position.set(0, 1.5, 0);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -6;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun, sun.target);
// A cool fill light separates the shaded wall return from the main facade.
const fill = new THREE.DirectionalLight("#b9d8db", 0.8);
fill.position.set(8, 5, -4);
scene.add(fill);
// -------------------------------------------------------------------------
// Shared geometry and material helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const unitCylinder = new THREE.CylinderGeometry(1, 1, 1, 10);
function standard(color, roughness = 0.9, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
...extra
});
}
function makeBox(
width,
height,
depth,
material,
x,
y,
z,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
scene.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(unitCylinder, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.scale.set(radius, length, radius);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
let seed = 72831;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function pick(items) {
return items[Math.floor(random() * items.length)];
}
const plasterPalette = [
standard("#d8b58e"),
standard("#dfbd96"),
standard("#d2aa82"),
standard("#e3c49f"),
standard("#cfa57e"),
standard("#d8b38a")
];
const stonePalette = [
standard("#9b8d78"),
standard("#a89a82"),
standard("#8f806d"),
standard("#b0a18a")
];
const lightStone = standard("#c4b59b", 0.84);
const cutStone = standard("#a9987e", 0.86);
const copingStone = standard("#cbbb9f", 0.82);
const iron = standard("#263a3b", 0.43, { metalness: 0.72 });
const doorMaterial = standard("#254e52", 0.67);
const doorPanelMaterial = standard("#2e5b5e", 0.61);
const interiorMaterial = standard("#182729", 0.95);
const revealMaterial = standard("#b99775", 0.91);
const brass = standard("#b38b48", 0.36, { metalness: 0.72 });
// -------------------------------------------------------------------------
// Original geometric tile texture
// -------------------------------------------------------------------------
function makeTileTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#eee2c5";
ctx.fillRect(0, 0, 256, 256);
ctx.strokeStyle = "#214c52";
ctx.lineWidth = 12;
ctx.strokeRect(7, 7, 242, 242);
ctx.save();
ctx.translate(128, 128);
ctx.rotate(Math.PI / 4);
ctx.fillStyle = "#2b7374";
ctx.fillRect(-43, -43, 86, 86);
ctx.restore();
ctx.fillStyle = "#c96f4d";
ctx.beginPath();
ctx.moveTo(128, 74);
ctx.lineTo(180, 128);
ctx.lineTo(128, 180);
ctx.lineTo(76, 128);
ctx.closePath();
ctx.fill();
ctx.fillStyle = "#f0c76d";
ctx.beginPath();
ctx.moveTo(128, 99);
ctx.lineTo(156, 128);
ctx.lineTo(128, 156);
ctx.lineTo(100, 128);
ctx.closePath();
ctx.fill();
ctx.fillStyle = "#214c52";
ctx.beginPath();
ctx.arc(128, 128, 14, 0, Math.PI * 2);
ctx.fill();
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const tileTexture = makeTileTexture();
const tileMaterial = new THREE.MeshStandardMaterial({
map: tileTexture,
roughness: 0.62,
metalness: 0
});
// -------------------------------------------------------------------------
// Stepped street paving
//
// Each x-column has a level top, while its height rises toward the right.
// The resulting terraced side profile makes the street's slope explicit.
// -------------------------------------------------------------------------
const streetPalette = [
standard("#a9a18f"),
standard("#b1a997"),
standard("#9f9786"),
standard("#b7ae9b"),
standard("#aaa18f")
];
const streetStartX = -7;
const streetColumnWidth = 0.55;
const streetColumnCount = 32;
const streetStartY = 0.42;
const streetRise = 0.035;
const streetStartZ = -1.25;
const streetRowDepth = 0.68;
const streetRowCount = 9;
for (let column = 0; column < streetColumnCount; column++) {
const x = streetStartX + (column + 0.5) * streetColumnWidth;
const top = streetStartY + column * streetRise;
// Continuous terraced sub-base under the individual pavers.
const baseBottom = -0.25;
const baseTop = top - 0.14;
makeBox(
streetColumnWidth,
baseTop - baseBottom,
streetRowCount * streetRowDepth,
standard("#756e60", 0.96),
x,
(baseTop + baseBottom) / 2,
streetStartZ + (streetRowCount * streetRowDepth) / 2,
false,
true
);
for (let row = 0; row < streetRowCount; row++) {
const z =
streetStartZ +
(row + 0.5) * streetRowDepth;
makeBox(
streetColumnWidth - 0.024,
0.16,
streetRowDepth - 0.024,
pick(streetPalette),
x + (random() - 0.5) * 0.006,
top - 0.08,
z + (random() - 0.5) * 0.006,
false,
true
);
}
}
// -------------------------------------------------------------------------
// Foundation and compact plaster facade
// -------------------------------------------------------------------------
function voxelRegion(
x0,
x1,
y0,
y1,
depth,
materials,
targetSize = 0.56,
zCenter = 0
) {
const nx = Math.max(1, Math.ceil((x1 - x0) / targetSize));
const ny = Math.max(1, Math.ceil((y1 - y0) / targetSize));
const cellWidth = (x1 - x0) / nx;
const cellHeight = (y1 - y0) / ny;
for (let ix = 0; ix < nx; ix++) {
for (let iy = 0; iy < ny; iy++) {
const x = x0 + (ix + 0.5) * cellWidth;
const y = y0 + (iy + 0.5) * cellHeight;
const z = zCenter + (random() - 0.5) * 0.012;
makeBox(
Math.max(0.03, cellWidth - 0.011),
Math.max(0.03, cellHeight - 0.011),
depth,
pick(materials),
x,
y,
z,
true,
true
);
}
}
}
// Rough stone foundation below the raised entrance.
voxelRegion(
-3.3,
1.65,
0.45,
1.55,
0.78,
stonePalette,
0.52,
0.02
);
const openingLeft = -1.0;
const openingRight = 0.8;
const landingY = 1.55;
const openingTop = 4.025;
// Left plaster mass.
voxelRegion(
-3.3,
openingLeft,
landingY,
5.65,
0.68,
plasterPalette,
0.56
);
// Narrow right pier.
voxelRegion(
openingRight,
1.65,
landingY,
5.65,
0.68,
plasterPalette,
0.55
);
// Lintel over the recessed opening.
voxelRegion(
openingLeft,
openingRight,
openingTop,
5.65,
0.68,
plasterPalette,
0.56
);
// A simple coping makes the facade's block thickness legible.
makeBox(
5.13,
0.16,
0.78,
copingStone,
-0.825,
5.73,
0
);
// Contrasting surfaces inside the reveal emphasize the wall depth.
makeBox(
0.036,
openingTop - landingY,
0.68,
revealMaterial,
openingLeft + 0.015,
(landingY + openingTop) / 2,
0
);
makeBox(
0.036,
openingTop - landingY,
0.68,
revealMaterial,
openingRight - 0.015,
(landingY + openingTop) / 2,
0
);
makeBox(
openingRight - openingLeft,
0.036,
0.68,
revealMaterial,
(openingLeft + openingRight) / 2,
openingTop - 0.015,
0
);
// -------------------------------------------------------------------------
// Original geometric tile border
// -------------------------------------------------------------------------
const tileSize = 0.225;
const tileVisibleSize = 0.213;
const sideTileCount = 11;
const topTileCount = 8;
for (let i = 0; i < sideTileCount; i++) {
const y = landingY + (i + 0.5) * tileSize;
makeBox(
tileVisibleSize,
tileVisibleSize,
0.035,
tileMaterial,
openingLeft - tileSize / 2,
y,
0.365
);
makeBox(
tileVisibleSize,
tileVisibleSize,
0.035,
tileMaterial,
openingRight + tileSize / 2,
y,
0.365
);
}
for (let i = 0; i < topTileCount; i++) {
makeBox(
tileVisibleSize,
tileVisibleSize,
0.035,
tileMaterial,
openingLeft + (i + 0.5) * tileSize,
openingTop + tileSize / 2,
0.365
);
}
// -------------------------------------------------------------------------
// Recessed entrance and inward-opening door
// -------------------------------------------------------------------------
// Deep interior backing, well behind the front wall plane.
makeBox(
1.8,
2.47,
0.07,
interiorMaterial,
-0.1,
(landingY + openingTop) / 2,
-1.15,
false,
true
);
const interiorFloor = makeBox(
1.75,
0.09,
0.85,
standard("#4a4740"),
-0.1,
landingY - 0.035,
-0.73
);
interiorFloor.receiveShadow = true;
const doorGroup = new THREE.Group();
doorGroup.position.set(-0.91, landingY + 0.02, -0.29);
doorGroup.rotation.y = 0.38;
scene.add(doorGroup);
function doorBox(
width,
height,
depth,
material,
x,
y,
z
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
doorGroup.add(mesh);
return mesh;
}
doorBox(1.56, 2.31, 0.085, doorMaterial, 0.78, 1.155, 0);
doorBox(0.62, 1.63, 0.026, doorPanelMaterial, 0.39, 1.18, 0.055);
doorBox(0.62, 1.63, 0.026, doorPanelMaterial, 1.17, 1.18, 0.055);
doorBox(0.54, 0.33, 0.027, doorPanelMaterial, 0.39, 2.11, 0.055);
doorBox(0.54, 0.33, 0.027, doorPanelMaterial, 1.17, 2.11, 0.055);
const knob = new THREE.Mesh(
new THREE.SphereGeometry(0.047, 12, 8),
brass
);
knob.position.set(1.42, 1.13, 0.095);
knob.castShadow = true;
doorGroup.add(knob);
const entranceLight = new THREE.PointLight(
"#f4b969",
10,
4.5,
2
);
entranceLight.position.set(0.15, 2.75, -0.58);
scene.add(entranceLight);
// -------------------------------------------------------------------------
// Short flight of block-built steps
// -------------------------------------------------------------------------
const stairLeft = -0.875;
const stairRight = 0.675;
const stairCenter = (stairLeft + stairRight) / 2;
const stairWidth = stairRight - stairLeft;
const stairBase = 0.45;
const stairSections = [
{ z0: 0.35, z1: 0.90, top: 1.55 },
{ z0: 0.90, z1: 1.36, top: 1.34 },
{ z0: 1.36, z1: 1.82, top: 1.13 },
{ z0: 1.82, z1: 2.28, top: 0.92 }
];
stairSections.forEach((section, index) => {
const height = section.top - stairBase;
makeBox(
stairWidth,
height,
section.z1 - section.z0,
index === 0 ? copingStone : cutStone,
stairCenter,
stairBase + height / 2,
(section.z0 + section.z1) / 2
);
// Pale nosing strips make each riser and tread legible.
makeBox(
stairWidth + 0.025,
0.065,
0.085,
lightStone,
stairCenter,
section.top - 0.022,
section.z1 - 0.043
);
});
// -------------------------------------------------------------------------
// Simple iron handrail
// -------------------------------------------------------------------------
const railX = 0.735;
const railPosts = [
{ z: 0.50, base: 1.55, top: 2.30 },
{ z: 1.13, base: 1.34, top: 2.11 },
{ z: 1.59, base: 1.13, top: 1.93 },
{ z: 2.05, base: 0.92, top: 1.74 }
];
railPosts.forEach((post) => {
cylinderBetween(
new THREE.Vector3(railX, post.base - 0.025, post.z),
new THREE.Vector3(railX, post.top, post.z),
0.025,
iron
);
});
cylinderBetween(
new THREE.Vector3(railX, 2.30, 0.46),
new THREE.Vector3(railX, 1.62, 2.31),
0.032,
iron
);
// -------------------------------------------------------------------------
// Neighboring wall return, framing the left-hand corner
// -------------------------------------------------------------------------
const returnPalette = [
standard("#cdb58f"),
standard("#d3bb96"),
standard("#c5aa84"),
standard("#d8c29e")
];
for (let column = 0; column < 7; column++) {
const z = 0.35 + (column + 0.5) * 0.50;
const top = 4.38 - column * 0.11;
const bottom = 0.63;
const rows = Math.ceil((top - bottom) / 0.50);
const cellHeight = (top - bottom) / rows;
for (let row = 0; row < rows; row++) {
const y = bottom + (row + 0.5) * cellHeight;
makeBox(
0.55,
cellHeight - 0.009,
0.485,
pick(returnPalette),
-3.575,
y,
z,
true,
true
);
}
makeBox(
0.61,
0.12,
0.51,
copingStone,
-3.575,
top + 0.06,
z
);
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, and reset
// -------------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(-0.15, 2.25, 0.62),
desiredTarget: new THREE.Vector3(-0.15, 2.25, 0.62),
theta: 0.61,
desiredTheta: 0.61,
phi: 1.06,
desiredPhi: 1.06,
radius: 10.7,
desiredRadius: 10.7
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
function resetCamera() {
orbit.desiredTarget.set(-0.15, 2.25, 0.62);
orbit.desiredTheta = 0.61;
orbit.desiredPhi = 1.06;
orbit.desiredRadius = 10.7;
}
let pointerMode = null;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerMode =
event.shiftKey || event.button === 2 ? "pan" : "orbit";
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerMode) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (pointerMode === "orbit") {
orbit.desiredTheta -= dx * 0.006;
orbit.desiredPhi = THREE.MathUtils.clamp(
orbit.desiredPhi - dy * 0.005,
0.48,
1.43
);
} else {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 1);
const panScale = orbit.radius * 0.00115;
orbit.desiredTarget
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
orbit.desiredTarget.y = THREE.MathUtils.clamp(
orbit.desiredTarget.y,
0.7,
5
);
}
});
function endPointer(event) {
pointerMode = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.desiredRadius = THREE.MathUtils.clamp(
orbit.desiredRadius + event.deltaY * 0.008,
5.3,
18
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "r" || event.key === "R") {
resetCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
updateCamera();
renderer.setAnimationLoop(() => {
const easing = 0.12;
orbit.theta +=
(orbit.desiredTheta - orbit.theta) * easing;
orbit.phi +=
(orbit.desiredPhi - orbit.phi) * easing;
orbit.radius +=
(orbit.desiredRadius - orbit.radius) * easing;
orbit.target.lerp(
orbit.desiredTarget,
easing
);
updateCamera();
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```