Prompt specification
Build or customize the Three.js 3D scene "Stone Town carved-door threshold study" 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: Stone Town carved-door threshold study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/stone-town-carved-door-threshold-study-x2957
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a carved doorway in Zanzibar's Stone Town. Build a referenced Zanzibar doorway fragment with layered timber relief and stone wall. Use a selected documented tradition and simplify ornament without treating every local door as identical. Voxel style.
Acceptance checks: Use only these documented references: UNESCO Stone Town of Zanzibar (https://whc.unesco.org/en/list/173/) for coralline ragstone, timber and carved double doors; and The Metropolitan Museum of Art, Carved door, Zanzibar-based artist (https://www.metmuseum.org/art/collection/search/930571), for a documented timber-and-brass example. Cite them as text in an in-scene panel. Keep decorative simplifications visually comparable and labeled as schematic. Do not add unsupported attribution.
Return a single complete HTML document. It must work in a sandbox that allows scripts, with the cdnjs Three.js r160 module and inline CSS. Use procedural geometry and local button handlers; no native form submission, pointer lock, remote assets, or runtime network requests besides Three.js.
Working Three.js Starter (stone-town-carved-door-threshold-study-x2957):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zanzibar Stone Town — Voxel Doorway Study</title>
<style>
:root {
color-scheme: light;
--ink: #29231d;
--paper: rgba(246, 239, 219, 0.94);
--line: rgba(70, 54, 37, 0.28);
--accent: #8b572d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d4cdbb;
color: var(--ink);
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 18px;
left: 18px;
max-width: min(390px, calc(100vw - 36px));
padding: 15px 17px 14px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 8px 24px rgba(54, 43, 30, 0.13);
pointer-events: none;
}
.eyebrow {
margin: 0 0 6px;
color: var(--accent);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(1.45rem, 3vw, 2.15rem);
font-weight: 600;
line-height: 1.04;
}
.subtitle {
margin: 8px 0 0;
font-size: 0.88rem;
line-height: 1.4;
}
.reference-panel {
position: fixed;
top: 18px;
right: 18px;
width: min(390px, calc(100vw - 36px));
max-height: calc(100vh - 118px);
overflow: auto;
padding: 15px 17px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 8px 24px rgba(54, 43, 30, 0.13);
font-size: 0.78rem;
line-height: 1.42;
}
.reference-panel h2 {
margin: 0 0 9px;
font-size: 0.78rem;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.reference-panel p {
margin: 0 0 10px;
}
.reference-panel p:last-child {
margin-bottom: 0;
}
.reference-panel a {
color: inherit;
overflow-wrap: anywhere;
text-decoration-thickness: 1px;
text-underline-offset: 2px;
}
.note {
padding-top: 9px;
border-top: 1px solid var(--line);
color: #5d4a35;
font-style: italic;
}
.controls {
position: fixed;
left: 50%;
bottom: 17px;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 7px;
width: max-content;
max-width: calc(100vw - 28px);
padding: 8px;
border: 1px solid var(--line);
border-radius: 5px;
background: var(--paper);
box-shadow: 0 8px 24px rgba(54, 43, 30, 0.15);
transform: translateX(-50%);
}
button {
appearance: none;
border: 1px solid rgba(64, 47, 31, 0.34);
border-radius: 3px;
padding: 8px 11px;
background: #f2e7ce;
color: #34271c;
font: inherit;
font-size: 0.77rem;
font-weight: 700;
cursor: pointer;
}
button:hover,
button:focus-visible {
background: #e4c995;
outline: 2px solid rgba(104, 70, 35, 0.32);
outline-offset: 1px;
}
button[aria-pressed="false"] {
background: rgba(242, 231, 206, 0.64);
color: #746552;
}
.hint {
position: fixed;
left: 18px;
bottom: 22px;
padding: 7px 10px;
border-radius: 3px;
background: rgba(246, 239, 219, 0.82);
color: #51463a;
font-size: 0.72rem;
pointer-events: none;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 760px) {
.title-card {
top: 10px;
left: 10px;
max-width: calc(100vw - 20px);
padding: 11px 13px;
}
.title-card .subtitle {
display: none;
}
.reference-panel {
top: auto;
right: 10px;
bottom: 78px;
width: min(360px, calc(100vw - 20px));
max-height: 40vh;
padding: 11px 13px;
}
.controls {
bottom: 10px;
padding: 6px;
}
button {
padding: 7px 9px;
font-size: 0.71rem;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel model of a selected Zanzibar carved doorway tradition"></main>
<header class="title-card">
<p class="eyebrow">Stone Town · interpretive fragment</p>
<h1>Carved Timber & Brass</h1>
<p class="subtitle">A selected Zanzibar-based carved-door tradition, reduced to layered timber relief, brass accents, and coralline-ragstone masonry.</p>
</header>
<aside class="reference-panel" id="referencePanel" aria-label="In-scene reference panel">
<h2>In-scene source panel</h2>
<p><strong>Selected documented tradition:</strong> carved timber with brass ornament, based on the timber-and-brass example catalogued by The Metropolitan Museum of Art.</p>
<p><strong>UNESCO, Stone Town of Zanzibar</strong> (<a href="https://whc.unesco.org/en/list/173/">https://whc.unesco.org/en/list/173/</a>) — coralline ragstone, timber and carved double doors.</p>
<p><strong>The Metropolitan Museum of Art, Carved door, Zanzibar-based artist</strong> (<a href="https://www.metmuseum.org/art/collection/search/930571">https://www.metmuseum.org/art/collection/search/930571</a>) — documented timber-and-brass example.</p>
<p class="note">Schematic interpretation: ornament is deliberately simplified into a rectilinear voxel vocabulary. This fragment does not claim to portray an identified building or treat every local Zanzibar doorway as identical.</p>
</aside>
<nav class="controls" aria-label="Model controls">
<button type="button" data-view="front">Front</button>
<button type="button" data-view="three">Three-quarter</button>
<button type="button" data-view="detail">Door detail</button>
<button type="button" data-view="label">Label</button>
<button type="button" id="carvingToggle" aria-pressed="true">Carving: on</button>
<button type="button" id="labelToggle" aria-pressed="true">Scene label: on</button>
</nav>
<div class="hint">Drag to orbit · wheel to zoom · buttons frame selected views</div>
<p class="sr-only" id="accessibleSceneDescription">
This procedural Three.js scene presents a schematic voxel fragment of a Zanzibar carved timber-and-brass double doorway set into a coralline-ragstone wall. Relief is geometric and simplified. The documented references are UNESCO, Stone Town of Zanzibar, https://whc.unesco.org/en/list/173/, and The Metropolitan Museum of Art, Carved door, Zanzibar-based artist, https://www.metmuseum.org/art/collection/search/930571.
</p>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const mount = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd4cdbb);
scene.fog = new THREE.Fog(0xd4cdbb, 22, 43);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Voxel Zanzibar carved doorway with stone wall, timber relief, and brass details"
);
mount.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff4dd, 0x685c4b, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.25);
sun.position.set(-7, 13, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -5;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7c8d1, 0.9);
fill.position.set(9, 7, -8);
scene.add(fill);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xb9ad94,
roughness: 0.96,
metalness: 0
});
const ground = new THREE.Mesh(new THREE.PlaneGeometry(60, 40), groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.08;
ground.receiveShadow = true;
scene.add(ground);
const stoneMaterials = [
new THREE.MeshStandardMaterial({ color: 0xb8ad97, roughness: 0.96 }),
new THREE.MeshStandardMaterial({ color: 0xc6b99d, roughness: 0.98 }),
new THREE.MeshStandardMaterial({ color: 0xa99f8b, roughness: 0.95 }),
new THREE.MeshStandardMaterial({ color: 0xd0c2a5, roughness: 0.97 }),
new THREE.MeshStandardMaterial({ color: 0x9e9886, roughness: 0.94 }),
new THREE.MeshStandardMaterial({ color: 0xbdb19a, roughness: 0.99 })
];
const fleckMaterial = new THREE.MeshStandardMaterial({
color: 0x807866,
roughness: 1
});
const mortarMaterial = new THREE.MeshStandardMaterial({
color: 0x5f5a50,
roughness: 1
});
const woodDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x321913,
roughness: 0.78
});
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x5b2c1d,
roughness: 0.7
});
const woodRaisedMaterial = new THREE.MeshStandardMaterial({
color: 0x7c4227,
roughness: 0.66
});
const woodHighlightMaterial = new THREE.MeshStandardMaterial({
color: 0x955637,
roughness: 0.62
});
const woodEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x25130f,
roughness: 0.84
});
const brassMaterial = new THREE.MeshStandardMaterial({
color: 0xb48732,
roughness: 0.3,
metalness: 0.76
});
const brassLightMaterial = new THREE.MeshStandardMaterial({
color: 0xd2ab52,
roughness: 0.25,
metalness: 0.72
});
const recessMaterial = new THREE.MeshStandardMaterial({
color: 0x17130f,
roughness: 1
});
function box(parent, material, x, y, z, width, height, depth, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomState = 81473;
function random() {
randomState = (randomState * 1664525 + 1013904223) >>> 0;
return randomState / 4294967296;
}
function chooseStone() {
return stoneMaterials[Math.floor(random() * stoneMaterials.length)];
}
function stoneWallRegion(x0, x1, y0, y1) {
let y = y0;
while (y < y1 - 0.02) {
const rowHeight = Math.min(1.06, y1 - y);
let x = x0;
while (x < x1 - 0.05) {
let blockWidth = Math.min(1.2 + random() * 0.68, x1 - x);
if (x1 - x - blockWidth < 0.48) blockWidth = x1 - x;
const visibleWidth = Math.max(0.08, blockWidth - 0.055);
const depth = 0.84 + random() * 0.27;
const z = (random() - 0.5) * 0.09;
const material = chooseStone();
box(
scene,
material,
x + visibleWidth * 0.5,
y + rowHeight * 0.5,
z,
visibleWidth,
rowHeight - 0.055,
depth
);
if (random() > 0.43) {
const front = z + depth * 0.5 + 0.013;
const fleckCount = 1 + Math.floor(random() * 3);
for (let f = 0; f < fleckCount; f++) {
box(
scene,
fleckMaterial,
x + 0.13 + random() * Math.max(0.08, visibleWidth - 0.26),
y + 0.12 + random() * Math.max(0.08, rowHeight - 0.24),
front,
0.055 + random() * 0.11,
0.035 + random() * 0.07,
0.025,
false
);
}
}
x += blockWidth;
}
y += rowHeight;
}
}
// Dark backing and recessed opening.
box(scene, mortarMaterial, -5.30, 4.72, -0.13, 5.50, 9.44, 0.88);
box(scene, mortarMaterial, 5.30, 4.72, -0.13, 5.50, 9.44, 0.88);
box(scene, mortarMaterial, 0, 8.50, -0.13, 5.50, 1.88, 0.88);
box(scene, recessMaterial, 0, 3.55, -0.34, 4.95, 7.15, 0.18);
// Individually voxelized coralline-ragstone blocks.
stoneWallRegion(-8.05, -2.57, 0, 9.46);
stoneWallRegion(2.57, 8.05, 0, 9.46);
stoneWallRegion(-2.57, 2.57, 7.56, 9.46);
// Projecting stone jambs and threshold steps.
box(scene, stoneMaterials[3], -2.61, 3.62, 0.33, 0.34, 7.32, 1.13);
box(scene, stoneMaterials[1], 2.61, 3.62, 0.33, 0.34, 7.32, 1.13);
box(scene, stoneMaterials[0], 0, 0.06, 0.43, 5.72, 0.20, 1.72);
box(scene, stoneMaterials[2], 0, -0.02, 1.12, 6.08, 0.14, 0.72);
// Dark timber door recess.
box(scene, woodEdgeMaterial, 0, 3.55, -0.12, 4.78, 7.18, 0.18);
// Timber structural frame around the leaves.
box(scene, woodMaterial, -2.34, 3.62, 0.13, 0.24, 7.18, 0.48);
box(scene, woodMaterial, 2.34, 3.62, 0.13, 0.24, 7.18, 0.48);
box(scene, woodRaisedMaterial, 0, 7.18, 0.13, 4.92, 0.27, 0.48);
box(scene, woodEdgeMaterial, 0, 6.98, 0.14, 4.72, 0.12, 0.44);
const carvingGroup = new THREE.Group();
carvingGroup.name = "Layered timber relief";
scene.add(carvingGroup);
function makeLeaf(centerX) {
box(scene, woodDarkMaterial, centerX, 3.53, -0.005, 2.13, 6.72, 0.19);
// Individual vertical boards.
for (let p = 0; p < 4; p++) {
const plankX = centerX - 0.79 + p * 0.525;
const plankMaterial = p % 2 === 0 ? woodMaterial : woodDarkMaterial;
box(scene, plankMaterial, plankX, 3.53, 0.105, 0.485, 6.52, 0.095);
}
// Horizontal rails.
const railYs = [0.38, 2.95, 3.35, 6.52];
for (const railY of railYs) {
box(scene, woodRaisedMaterial, centerX, railY, 0.175, 2.15, 0.23, 0.18);
box(scene, woodEdgeMaterial, centerX, railY - 0.125, 0.18, 2.13, 0.055, 0.17);
}
// Raised panel borders.
const upperCenterY = 4.94;
const lowerCenterY = 1.66;
for (const side of [-1, 1]) {
box(
carvingGroup,
woodRaisedMaterial,
centerX + side * 0.86,
upperCenterY,
0.245,
0.11,
2.68,
0.12
);
box(
carvingGroup,
woodRaisedMaterial,
centerX + side * 0.86,
lowerCenterY,
0.245,
0.11,
1.83,
0.12
);
}
for (const borderY of [3.60, 6.28, 0.75, 2.57]) {
const width = borderY > 3 ? 1.83 : 1.83;
box(
carvingGroup,
woodRaisedMaterial,
centerX,
borderY,
0.245,
width,
0.11,
0.12
);
}
// Small vertical relief marks create a second carved layer.
for (const side of [-1, 1]) {
for (let i = 0; i < 4; i++) {
box(
carvingGroup,
woodHighlightMaterial,
centerX + side * 0.72,
4.07 + i * 0.51,
0.305,
0.13,
0.29,
0.095
);
}
}
}
makeLeaf(-1.105);
makeLeaf(1.105);
function drawPixelMotif(centerX, centerY, pattern, cellSize) {
const rows = pattern.length;
const cols = pattern[0].length;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
if (pattern[row][col] !== "1") continue;
const x = centerX + (col - (cols - 1) * 0.5) * cellSize;
const y = centerY + ((rows - 1) * 0.5 - row) * cellSize;
// Broad dark underlayer.
box(
carvingGroup,
woodEdgeMaterial,
x,
y,
0.275,
cellSize * 0.92,
cellSize * 0.92,
0.095
);
// Smaller, brighter raised timber layer.
box(
carvingGroup,
(row + col) % 3 === 0 ? woodHighlightMaterial : woodRaisedMaterial,
x,
y,
0.345,
cellSize * 0.60,
cellSize * 0.60,
0.09
);
}
}
}
const upperMotif = [
"0011100",
"0111110",
"1101011",
"1101011",
"1111111",
"0111110",
"0011100"
];
const lowerMotif = [
"100000001",
"110000011",
"111001111",
"110000011",
"100000001"
];
drawPixelMotif(-1.105, 4.94, upperMotif, 0.20);
drawPixelMotif(1.105, 4.94, upperMotif, 0.20);
drawPixelMotif(-1.105, 1.66, lowerMotif, 0.17);
drawPixelMotif(1.105, 1.66, lowerMotif, 0.17);
// Central brass seam.
box(scene, brassMaterial, 0, 3.53, 0.34, 0.055, 6.40, 0.065);
box(scene, brassLightMaterial, 0.018, 3.53, 0.378, 0.018, 6.26, 0.025, false);
// Brass studs on rails.
for (const leafX of [-1.105, 1.105]) {
for (const railY of [0.38, 2.95, 3.35, 6.52]) {
for (const offset of [-0.76, 0.76]) {
box(
scene,
railY === 3.35 ? brassLightMaterial : brassMaterial,
leafX + offset,
railY,
0.335,
0.105,
0.105,
0.075
);
}
}
}
// Stepped, voxel-like brass handles.
function makeHandle(x) {
box(scene, brassMaterial, x, 3.20, 0.385, 0.42, 0.075, 0.09);
box(scene, brassMaterial, x, 2.98, 0.385, 0.42, 0.075, 0.09);
box(scene, brassMaterial, x - 0.17, 3.09, 0.385, 0.075, 0.30, 0.09);
box(scene, brassMaterial, x + 0.17, 3.09, 0.385, 0.075, 0.30, 0.09);
box(scene, brassLightMaterial, x, 3.09, 0.445, 0.12, 0.12, 0.055);
}
makeHandle(-0.39);
makeHandle(0.39);
// Brass details on the carved timber lintel.
for (let i = -4; i <= 4; i++) {
box(scene, i % 2 === 0 ? brassMaterial : brassLightMaterial, i * 0.49, 7.18, 0.395, 0.115, 0.115, 0.065);
}
// A mounted interpretive panel, drawn locally with CanvasTexture.
const sceneLabelGroup = new THREE.Group();
sceneLabelGroup.name = "Mounted interpretive label";
scene.add(sceneLabelGroup);
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 1024;
labelCanvas.height = 1152;
const labelContext = labelCanvas.getContext("2d");
labelContext.fillStyle = "#e8dec3";
labelContext.fillRect(0, 0, 1024, 1152);
labelContext.strokeStyle = "#493526";
labelContext.lineWidth = 14;
labelContext.strokeRect(22, 22, 980, 1108);
labelContext.strokeStyle = "#9d7745";
labelContext.lineWidth = 4;
labelContext.strokeRect(43, 43, 938, 1066);
function wrappedLines(context, text, x, y, maxWidth, lineHeight) {
const words = text.split(" ");
const lines = [];
let line = "";
for (const word of words) {
const test = line ? `${line} ${word}` : word;
if (context.measureText(test).width > maxWidth && line) {
lines.push(line);
line = word;
} else {
line = test;
}
}
if (line) lines.push(line);
lines.forEach((entry, index) => context.fillText(entry, x, y + index * lineHeight));
return y + lines.length * lineHeight;
}
labelContext.textBaseline = "alphabetic";
labelContext.fillStyle = "#6f4528";
labelContext.font = "800 29px system-ui, sans-serif";
labelContext.fillText("ZANZIBAR · SCHEMATIC VOXEL STUDY", 64, 92);
labelContext.fillStyle = "#30241c";
labelContext.font = "700 48px Georgia, serif";
labelContext.fillText("Carved Timber + Brass", 64, 151);
labelContext.strokeStyle = "#8d6a45";
labelContext.lineWidth = 3;
labelContext.beginPath();
labelContext.moveTo(64, 181);
labelContext.lineTo(960, 181);
labelContext.stroke();
labelContext.fillStyle = "#7a4c2c";
labelContext.font = "800 25px system-ui, sans-serif";
labelContext.fillText("SELECTED DOCUMENTED TRADITION", 64, 226);
labelContext.fillStyle = "#342a22";
labelContext.font = "27px system-ui, sans-serif";
let labelY = wrappedLines(
labelContext,
"Carved timber with brass ornament, based on the timber-and-brass example catalogued by The Metropolitan Museum of Art.",
64,
266,
890,
36
);
labelY += 18;
labelContext.fillStyle = "#7a4c2c";
labelContext.font = "800 25px system-ui, sans-serif";
labelContext.fillText("SIMPLIFIED, NOT REPRESENTATIVE OF EVERY DOOR", 64, labelY);
labelY += 38;
labelContext.fillStyle = "#4f4034";
labelContext.font = "italic 25px system-ui, sans-serif";
labelY = wrappedLines(
labelContext,
"Ornament is reduced to a rectilinear voxel vocabulary. This fragment is not an identified building and does not claim that all Zanzibar doors share one design.",
64,
labelY,
890,
34
);
labelY += 24;
labelContext.fillStyle = "#7a4c2c";
labelContext.font = "800 25px system-ui, sans-serif";
labelContext.fillText("DOCUMENTED REFERENCES", 64, labelY);
labelY += 42;
labelContext.fillStyle = "#342a22";
labelContext.font = "700 27px system-ui, sans-serif";
labelContext.fillText("UNESCO, Stone Town of Zanzibar", 64, labelY);
labelY += 35;
labelContext.font = "24px system-ui, sans-serif";
labelContext.fillText("Coralline ragstone; timber and carved double doors.", 64, labelY);
labelY += 32;
labelContext.fillStyle = "#70441f";
labelContext.font = "22px system-ui, sans-serif";
labelContext.fillText("https://whc.unesco.org/en/list/173/", 64, labelY);
labelY += 56;
labelContext.fillStyle = "#342a22";
labelContext.font = "700 27px system-ui, sans-serif";
labelY = wrappedLines(
labelContext,
"The Metropolitan Museum of Art, Carved door, Zanzibar-based artist",
64,
labelY,
890,
34
);
labelY += 8;
labelContext.font = "24px system-ui, sans-serif";
labelContext.fillText("Documented timber-and-brass example.", 64, labelY);
labelY += 32;
labelContext.fillStyle = "#70441f";
labelContext.font = "22px system-ui, sans-serif";
labelContext.fillText(
"https://www.metmuseum.org/art/collection/search/930571",
64,
labelY
);
labelContext.strokeStyle = "#8d6a45";
labelContext.lineWidth = 3;
labelContext.beginPath();
labelContext.moveTo(64, 1030);
labelContext.lineTo(960, 1030);
labelContext.stroke();
labelContext.fillStyle = "#4f4034";
labelContext.font = "italic 23px system-ui, sans-serif";
labelContext.fillText("Procedural geometry · no photographic texture assets", 64, 1070);
const labelTexture = new THREE.CanvasTexture(labelCanvas);
labelTexture.colorSpace = THREE.SRGBColorSpace;
labelTexture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
box(sceneLabelGroup, woodEdgeMaterial, -5.16, 4.34, 0.575, 4.86, 5.48, 0.14);
const labelPlane = new THREE.Mesh(
new THREE.PlaneGeometry(4.64, 5.22),
new THREE.MeshBasicMaterial({
map: labelTexture,
toneMapped: false
})
);
labelPlane.position.set(-5.16, 4.34, 0.655);
labelPlane.receiveShadow = true;
sceneLabelGroup.add(labelPlane);
const labelFrameMaterial = new THREE.MeshStandardMaterial({
color: 0x6d3c22,
roughness: 0.72
});
box(sceneLabelGroup, labelFrameMaterial, -5.16, 6.96, 0.69, 4.90, 0.12, 0.12);
box(sceneLabelGroup, labelFrameMaterial, -5.16, 1.72, 0.69, 4.90, 0.12, 0.12);
box(sceneLabelGroup, labelFrameMaterial, -7.56, 4.34, 0.69, 0.12, 5.36, 0.12);
box(sceneLabelGroup, labelFrameMaterial, -2.76, 4.34, 0.69, 0.12, 5.36, 0.12);
// Direct camera controls implemented without external addons.
const cameraState = {
theta: -0.42,
phi: 1.26,
radius: 15.8,
target: new THREE.Vector3(0, 3.55, 0)
};
const cameraSpherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
let cameraTween = null;
function applyCamera() {
cameraSpherical.set(
cameraState.radius,
THREE.MathUtils.clamp(cameraState.phi, 0.38, 1.49),
cameraState.theta
);
cameraOffset.setFromSpherical(cameraSpherical);
camera.position.copy(cameraState.target).add(cameraOffset);
camera.lookAt(cameraState.target);
}
const views = {
front: {
theta: 0,
phi: 1.43,
radius: 16.2,
target: new THREE.Vector3(0, 3.6, 0)
},
three: {
theta: -0.48,
phi: 1.25,
radius: 15.6,
target: new THREE.Vector3(0, 3.55, 0)
},
detail: {
theta: -0.18,
phi: 1.43,
radius: 9.2,
target: new THREE.Vector3(0, 3.48, 0)
},
label: {
theta: 0.02,
phi: 1.42,
radius: 8.8,
target: new THREE.Vector3(-5.15, 4.28, 0.25)
}
};
function moveToView(name) {
const view = views[name];
if (!view) return;
cameraTween = {
start: performance.now(),
duration: 720,
fromTheta: cameraState.theta,
fromPhi: cameraState.phi,
fromRadius: cameraState.radius,
fromTarget: cameraState.target.clone(),
toTheta: view.theta,
toPhi: view.phi,
toRadius: view.radius,
toTarget: view.target.clone()
};
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => moveToView(button.dataset.view));
});
const carvingToggle = document.getElementById("carvingToggle");
carvingToggle.addEventListener("click", () => {
carvingGroup.visible = !carvingGroup.visible;
carvingToggle.setAttribute("aria-pressed", String(carvingGroup.visible));
carvingToggle.textContent = carvingGroup.visible ? "Carving: on" : "Carving: off";
});
const labelToggle = document.getElementById("labelToggle");
labelToggle.addEventListener("click", () => {
sceneLabelGroup.visible = !sceneLabelGroup.visible;
labelToggle.setAttribute("aria-pressed", String(sceneLabelGroup.visible));
labelToggle.textContent = sceneLabelGroup.visible ? "Scene label: on" : "Scene label: off";
});
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraTween = null;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.38,
1.49
);
applyCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("pointerleave", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTween = null;
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.2,
24
);
applyCamera();
},
{ passive: false }
);
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
applyCamera();
function animate(now) {
requestAnimationFrame(animate);
if (cameraTween) {
const raw = THREE.MathUtils.clamp(
(now - cameraTween.start) / cameraTween.duration,
0,
1
);
const eased = raw < 0.5
? 4 * raw * raw * raw
: 1 - Math.pow(-2 * raw + 2, 3) / 2;
cameraState.theta = THREE.MathUtils.lerp(
cameraTween.fromTheta,
cameraTween.toTheta,
eased
);
cameraState.phi = THREE.MathUtils.lerp(
cameraTween.fromPhi,
cameraTween.toPhi,
eased
);
cameraState.radius = THREE.MathUtils.lerp(
cameraTween.fromRadius,
cameraTween.toRadius,
eased
);
cameraState.target.lerpVectors(
cameraTween.fromTarget,
cameraTween.toTarget,
eased
);
if (raw >= 1) cameraTween = null;
applyCamera();
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```