Prompt specification
Build or customize the Three.js 3D scene "Coral-stone doorway detail on a base" 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: Coral-stone doorway detail on a base
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/coral-stone-doorway-detail-on-a-base-x2393
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: Coral-stone doorway detail on a base. Model a referenced coral-stone doorway fragment with shallow carved details and visible wall thickness. Identify the selected coastal tradition without treating all Swahili towns as identical. Return one self-contained HTML file.
Working Three.js Starter (coral-stone-doorway-detail-on-a-base-x2393):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#d8cfc1" />
<title>Coral Threshold — Lamu, Kenya</title>
<style>
:root {
--ink: #29231e;
--muted: #6f6256;
--paper: rgba(250, 246, 238, 0.9);
--line: rgba(54, 43, 34, 0.16);
--accent: #a85535;
--shadow: 0 18px 48px rgba(48, 38, 28, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8cfc1;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#stage canvas {
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#stage canvas.dragging {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 24px;
padding: 22px 26px;
pointer-events: none;
}
.brand {
pointer-events: auto;
max-width: 430px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 26px;
height: 2px;
background: currentColor;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 56px);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.035em;
text-wrap: balance;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
letter-spacing: 0.02em;
}
.toolbar {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
pointer-events: auto;
}
.tool-button {
min-height: 38px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 24px rgba(48, 38, 28, 0.08);
backdrop-filter: blur(12px);
cursor: pointer;
transition:
transform 160ms ease,
background 160ms ease,
border-color 160ms ease;
}
.tool-button:hover {
transform: translateY(-1px);
border-color: rgba(168, 85, 53, 0.4);
background: rgba(255, 253, 248, 0.96);
}
.tool-button[aria-pressed="false"] {
color: #8b7d70;
}
.info-panel {
position: fixed;
z-index: 10;
left: 24px;
bottom: 24px;
width: min(360px, calc(100vw - 48px));
padding: 19px 20px 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
transition:
transform 240ms ease,
opacity 240ms ease;
}
.info-panel.collapsed {
transform: translateY(calc(100% - 48px));
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 12px;
}
.panel-kicker {
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel-heading strong {
display: block;
margin-top: 3px;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 500;
}
.panel-rule {
width: 31px;
height: 1px;
background: rgba(54, 43, 34, 0.3);
}
.info-panel p {
margin: 0;
color: #5e5248;
font-size: 12.5px;
line-height: 1.58;
}
.detail-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.detail {
padding: 9px 10px;
border: 1px solid rgba(54, 43, 34, 0.1);
border-radius: 10px;
background: rgba(255, 255, 255, 0.38);
}
.detail span {
display: block;
color: #9b5738;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.detail b {
display: block;
margin-top: 3px;
font-size: 11px;
font-weight: 650;
}
.panel-footnote {
margin-top: 12px !important;
color: #87786a !important;
font-size: 10.5px !important;
}
.controls-hint {
position: fixed;
z-index: 8;
right: 25px;
bottom: 25px;
display: flex;
align-items: center;
gap: 11px;
color: rgba(48, 39, 31, 0.66);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
pointer-events: none;
}
.mouse-icon {
position: relative;
width: 18px;
height: 27px;
border: 1.5px solid currentColor;
border-radius: 10px;
}
.mouse-icon::after {
content: "";
position: absolute;
top: 5px;
left: 50%;
width: 2px;
height: 5px;
border-radius: 2px;
background: currentColor;
transform: translateX(-50%);
}
.annotation {
position: fixed;
z-index: 7;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(60, 47, 37, 0.15);
border-radius: 999px;
background: rgba(252, 249, 243, 0.88);
color: #4d4035;
box-shadow: 0 7px 20px rgba(48, 38, 28, 0.09);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 160ms ease;
}
.annotation::before {
content: "";
width: 6px;
height: 6px;
border: 2px solid #b15e3b;
border-radius: 50%;
background: #fffaf1;
box-shadow: 0 0 0 3px rgba(177, 94, 59, 0.12);
}
body.labels-off .annotation {
opacity: 0 !important;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #d8cfc1;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader-inner {
text-align: center;
}
.loader-mark {
width: 38px;
height: 38px;
margin: 0 auto 14px;
border: 2px solid rgba(73, 57, 45, 0.15);
border-top-color: #a85535;
border-radius: 50%;
animation: spin 900ms linear infinite;
}
.loader-inner span {
color: #77685b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 760px) {
.topbar {
padding: 16px;
}
.brand {
max-width: 62vw;
}
h1 {
font-size: 34px;
}
.subtitle {
font-size: 11px;
}
.toolbar {
max-width: 125px;
}
.tool-button {
min-height: 34px;
padding: 0 11px;
font-size: 10px;
}
.info-panel {
left: 14px;
bottom: 14px;
width: calc(100vw - 28px);
padding: 15px 16px;
}
.info-panel.collapsed {
transform: translateY(calc(100% - 43px));
}
.detail-grid {
display: none;
}
.panel-footnote {
margin-top: 8px !important;
}
.controls-hint {
display: none;
}
.annotation {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Voxel architectural study</div>
<h1>Coral Threshold</h1>
<p class="subtitle">A doorway fragment associated with Lamu, Kenya</p>
</div>
<nav class="toolbar" aria-label="Scene controls">
<button class="tool-button" id="detail-view" type="button">Focus detail</button>
<button class="tool-button" id="reset-view" type="button">Reset view</button>
<button class="tool-button" id="toggle-labels" type="button" aria-pressed="true">
Labels
</button>
<button class="tool-button" id="toggle-notes" type="button" aria-expanded="true">
Notes
</button>
</nav>
</header>
<aside class="info-panel" id="info-panel">
<div class="panel-heading">
<div>
<div class="panel-kicker">Selected coastal tradition</div>
<strong>Lamu · Swahili coastal architecture</strong>
</div>
<span class="panel-rule"></span>
</div>
<p>
This study interprets the coral-stone masonry, shaded threshold, and carved
timber doors associated with the historic island fabric of Lamu. Lamu is
identified as a specific coastal tradition—not as a stand-in for every
Swahili town.
</p>
<div class="detail-grid">
<div class="detail">
<span>Masonry</span>
<b>Honey coral-rag blocks</b>
</div>
<div class="detail">
<span>Relief</span>
<b>Shallow geometric band</b>
</div>
<div class="detail">
<span>Threshold</span>
<b>Recessed carved leaves</b>
</div>
<div class="detail">
<span>Fragment</span>
<b>Visible wall thickness</b>
</div>
</div>
<p class="panel-footnote">
Interpretive voxel reconstruction · individual blocks, surface pits, jamb
reveals, and door hardware are simplified for legibility.
</p>
</aside>
<div class="annotation" id="annotation-relief">Shallow carved frieze</div>
<div class="annotation" id="annotation-thickness">Exposed wall thickness</div>
<div class="annotation" id="annotation-threshold">Recessed timber threshold</div>
<div class="controls-hint" aria-hidden="true">
<span class="mouse-icon"></span>
<span>Drag to orbit · Scroll to zoom</span>
</div>
<div id="loading">
<div class="loader-inner">
<div class="loader-mark"></div>
<span>Assembling the fragment</span>
</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 stage = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8cfc1);
scene.fog = new THREE.Fog(0xd8cfc1, 15, 29);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Interactive voxel model of a Lamu coral-stone doorway");
renderer.domElement.tabIndex = 0;
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 2.9, 0);
const view = {
theta: 0.48,
phi: 1.13,
radius: 11.7
};
const defaultView = { ...view };
function updateCamera() {
const horizontal = view.radius * Math.sin(view.phi);
camera.position.set(
target.x + Math.sin(view.theta) * horizontal,
target.y + Math.cos(view.phi) * view.radius,
target.z + Math.cos(view.theta) * horizontal
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff5e8, 0x6e5b49, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe4bd, 3.6);
sun.position.set(7, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -4;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfd7e7, 1.0);
fill.position.set(-7, 5, 4);
scene.add(fill);
const warmBounce = new THREE.PointLight(0xd98b58, 0.55, 15, 2);
warmBounce.position.set(-3, 3.5, 4);
scene.add(warmBounce);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xcfc4b3,
roughness: 1
});
const ground = new THREE.Mesh(new THREE.PlaneGeometry(40, 40), groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.225;
ground.receiveShadow = true;
scene.add(ground);
const dummy = new THREE.Object3D();
const colorHelper = new THREE.Color();
function addInstancedBoxes(items, material, name) {
if (!items.length) return null;
const mesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
material,
items.length
);
mesh.name = name;
mesh.castShadow = true;
mesh.receiveShadow = true;
items.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.rotation.set(0, item.ry || 0, 0);
dummy.scale.set(item.sx, item.sy, item.sz);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (item.color !== undefined) {
colorHelper.set(item.color);
mesh.setColorAt(index, colorHelper);
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
scene.add(mesh);
return mesh;
}
function box(x, y, z, sx, sy, sz, color, materialOptions = {}) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: materialOptions.roughness ?? 0.88,
metalness: materialOptions.metalness ?? 0
});
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(sx, sy, sz),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
let randomSeed = 731947;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const instanceMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92,
metalness: 0
});
// Base: a stepped archaeological-display plinth with a tiled upper bed.
box(0, -0.045, 0, 9.6, 0.36, 2.85, 0x655c52);
box(0, 0.17, 0, 9.35, 0.12, 2.62, 0xa99479);
const sandTiles = [];
const tileColors = [0xc5b292, 0xd2c0a0, 0xbba98b, 0xcbbb9d, 0xd7c6a8];
for (let xIndex = 0; xIndex < 19; xIndex++) {
for (let zIndex = 0; zIndex < 6; zIndex++) {
sandTiles.push({
x: (xIndex - 9) * 0.49 + (random() - 0.5) * 0.025,
y: 0.255 + random() * 0.006,
z: (zIndex - 2.5) * 0.43 + (random() - 0.5) * 0.025,
sx: 0.475,
sy: 0.045,
sz: 0.405,
color: tileColors[Math.floor(random() * tileColors.length)]
});
}
}
addInstancedBoxes(sandTiles, instanceMaterial, "Sand bed voxels");
// Dark mortar backing gives the individual coral blocks a visible joint.
const mortarMaterial = new THREE.MeshStandardMaterial({
color: 0x8e715b,
roughness: 1
});
box(-2.81, 3.33, -0.265, 2.54, 6.1, 0.18, 0x8e715b, {
roughness: 1
});
box(2.81, 3.33, -0.265, 2.54, 6.1, 0.18, 0x8e715b, {
roughness: 1
});
box(0, 5.49, -0.265, 3.06, 1.18, 0.18, 0x8e715b, {
roughness: 1
});
// Irregular coral-rag masonry with a deliberately incomplete upper edge.
const wallBlocks = [];
const coralColors = [
0xc99b72,
0xd0a47d,
0xbe8d66,
0xd8ad86,
0xc5956d,
0xb9825f,
0xd6a77e
];
const columns = 16;
const rows = 13;
const blockWidth = 0.51;
const blockHeight = 0.47;
const wallBottom = 0.28;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const isOpening = column >= 5 && column <= 10 && row < 9;
const chippedTopLeft = row >= 11 && column <= 1;
const chippedTopRight = row >= 11 && column >= 14;
const higherChipLeft = row === 12 && column <= 3;
const higherChipRight = row === 12 && column >= 12;
const isolatedChip = row === 12 && column === 8;
if (isOpening || chippedTopLeft || chippedTopRight || higherChipLeft || higherChipRight || isolatedChip) {
continue;
}
wallBlocks.push({
x: (column - 7.5) * blockWidth + (random() - 0.5) * 0.014,
y: wallBottom + blockHeight * 0.5 + row * blockHeight,
z: (random() - 0.5) * 0.035,
sx: 0.492 + random() * 0.012,
sy: 0.448 + random() * 0.012,
sz: 0.69 + random() * 0.055,
color: coralColors[Math.floor(random() * coralColors.length)]
});
}
}
addInstancedBoxes(wallBlocks, instanceMaterial, "Coral-stone wall blocks");
// Small exposed aggregate pits across the facade.
const pores = [];
for (let i = 0; i < 125; i++) {
const column = Math.floor(random() * columns);
const row = Math.floor(random() * rows);
if (column >= 5 && column <= 10 && row < 9) continue;
const x = (column - 7.5) * blockWidth + (random() - 0.5) * 0.31;
const y = wallBottom + row * blockHeight + 0.12 + random() * 0.2;
const size = 0.025 + random() * 0.047;
pores.push({
x,
y,
z: 0.367 + random() * 0.005,
sx: size,
sy: size * (0.65 + random() * 0.5),
sz: 0.018,
color: random() > 0.32 ? 0x9d7256 : 0xe0b98f
});
}
addInstancedBoxes(pores, instanceMaterial, "Coral surface pores");
// The opening is dark and recessed, making the stone reveal legible.
box(0, 2.4, -0.37, 3.04, 4.22, 0.11, 0x211915);
// Recessed timber threshold slab.
box(0, 0.315, 0.05, 3.12, 0.1, 0.88, 0x9b8065);
// Carved coral-stone door surround.
const stoneTrim = [];
const stoneDark = 0x966d50;
const stoneLight = 0xe1b78c;
for (const side of [-1, 1]) {
const jambX = side * 1.61;
for (let y = 0.43; y < 4.5; y += 0.255) {
stoneTrim.push({
x: jambX,
y,
z: 0.407,
sx: 0.145,
sy: 0.225,
sz: 0.095,
color: random() > 0.28 ? 0xd6a67d : 0xc08b64
});
}
// Repeated shallow diamond motifs along the jamb.
for (let y = 0.7; y < 4.3; y += 0.58) {
stoneTrim.push({
x: jambX,
y,
z: 0.459,
sx: 0.115,
sy: 0.115,
sz: 0.027,
color: stoneDark
});
for (const [dx, dy] of [[-0.068, -0.068], [0.068, -0.068], [-0.068, 0.068], [0.068, 0.068]]) {
stoneTrim.push({
x: jambX + dx,
y: y + dy,
z: 0.474,
sx: 0.055,
sy: 0.055,
sz: 0.035,
color: stoneLight
});
}
}
}
// Lintel and a narrow upper frieze.
for (let x = -1.8; x <= 1.81; x += 0.24) {
stoneTrim.push({
x,
y: 4.56,
z: 0.414,
sx: 0.215,
sy: 0.19,
sz: 0.11,
color: random() > 0.3 ? 0xd4a47b : 0xbe8b64
});
}
for (let x = -2.1; x <= 2.11; x += 0.24) {
stoneTrim.push({
x,
y: 5.08,
z: 0.405,
sx: 0.215,
sy: 0.28,
sz: 0.105,
color: random() > 0.35 ? 0xd7a67e : 0xc3926c
});
}
// Inlaid-looking shallow diamonds over the lintel.
for (let x = -1.44; x <= 1.45; x += 0.48) {
stoneTrim.push({
x,
y: 5.08,
z: 0.469,
sx: 0.15,
sy: 0.15,
sz: 0.026,
color: stoneDark
});
for (const [dx, dy] of [[-0.087, 0], [0.087, 0], [0, -0.087], [0, 0.087]]) {
stoneTrim.push({
x: x + dx,
y: 5.08 + dy,
z: 0.483,
sx: 0.064,
sy: 0.064,
sz: 0.03,
color: stoneLight
});
}
}
addInstancedBoxes(stoneTrim, instanceMaterial, "Shallow carved stone details");
// Carved timber doors, set well behind the facade.
const woodBase = new THREE.MeshStandardMaterial({
color: 0x3c2118,
roughness: 0.78
});
box(-0.765, 2.36, -0.055, 1.46, 4.12, 0.18, 0x3c2118);
box(0.765, 2.36, -0.055, 1.46, 4.12, 0.18, 0x392018);
const woodTrim = [];
const woodHighlight = 0x653a27;
const woodMid = 0x4d2b1e;
const woodDark = 0x281712;
for (const side of [-1, 1]) {
const centerX = side * 0.765;
// Fine vertical plank divisions.
for (const offset of [-0.51, -0.17, 0.17, 0.51]) {
woodTrim.push({
x: centerX + offset,
y: 2.36,
z: 0.052,
sx: 0.026,
sy: 3.98,
sz: 0.035,
color: woodDark
});
}
// Two raised panel frames per leaf.
for (const panelY of [1.17, 3.18]) {
const panelHeight = panelY > 2 ? 1.5 : 1.3;
const panelWidth = 1.05;
woodTrim.push({
x: centerX,
y: panelY + panelHeight * 0.5,
z: 0.074,
sx: panelWidth,
sy: 0.07,
sz: 0.075,
color: woodHighlight
});
woodTrim.push({
x: centerX,
y: panelY - panelHeight * 0.5,
z: 0.074,
sx: panelWidth,
sy: 0.07,
sz: 0.075,
color: woodHighlight
});
woodTrim.push({
x: centerX - panelWidth * 0.5,
y: panelY,
z: 0.074,
sx: 0.07,
sy: panelHeight,
sz: 0.075,
color: woodMid
});
woodTrim.push({
x: centerX + panelWidth * 0.5,
y: panelY,
z: 0.074,
sx: 0.07,
sy: panelHeight,
sz: 0.075,
color: woodMid
});
for (const dx of [-0.42, 0.42]) {
for (const dy of [-panelHeight * 0.39, panelHeight * 0.39]) {
woodTrim.push({
x: centerX + dx,
y: panelY + dy,
z: 0.095,
sx: 0.075,
sy: 0.075,
sz: 0.055,
color: 0x7c6747
});
}
}
}
// Pixel diamond carving at the meeting line.
for (const [dx, dy] of [[0, 0], [-0.075, -0.075], [0.075, -0.075], [-0.075, 0.075], [0.075, 0.075]]) {
woodTrim.push({
x: centerX + dx,
y: 2.31 + dy,
z: 0.112,
sx: dx === 0 && dy === 0 ? 0.12 : 0.07,
sy: dx === 0 && dy === 0 ? 0.12 : 0.07,
sz: 0.055,
color: dx === 0 && dy === 0 ? 0x7b5a37 : 0x9b7848
});
}
}
addInstancedBoxes(woodTrim, instanceMaterial, "Carved timber door details");
// Square metal handles and central seam.
const hardware = [
{ x: -0.15, y: 2.18, z: 0.135, sx: 0.16, sy: 0.22, sz: 0.07, color: 0x8c6a37 },
{ x: 0.15, y: 2.18, z: 0.135, sx: 0.16, sy: 0.22, sz: 0.07, color: 0x8c6a37 },
{ x: 0, y: 2.36, z: 0.115, sx: 0.035, sy: 4.0, sz: 0.04, color: 0x1e110d }
];
addInstancedBoxes(hardware, instanceMaterial, "Door hardware");
// Detached blocks and fragments placed on the display bed.
const fallen = [
{ x: -3.35, y: 0.43, z: 0.93, sx: 0.48, sy: 0.29, sz: 0.42, ry: 0.16, color: 0xc99b72 },
{ x: -2.91, y: 0.39, z: 0.69, sx: 0.36, sy: 0.22, sz: 0.34, ry: -0.34, color: 0xd3a57e },
{ x: 3.24, y: 0.41, z: 0.82, sx: 0.44, sy: 0.27, sz: 0.38, ry: -0.2, color: 0xbc8a64 },
{ x: 3.67, y: 0.36, z: 1.02, sx: 0.3, sy: 0.18, sz: 0.29, ry: 0.43, color: 0xd4aa83 },
{ x: 2.84, y: 0.34, z: 1.08, sx: 0.26, sy: 0.14, sz: 0.24, ry: 0.12, color: 0xb98561 }
];
addInstancedBoxes(fallen, instanceMaterial, "Fallen coral fragments");
// Small chips reinforce the fragment reading without overwhelming it.
const chips = [];
for (let i = 0; i < 28; i++) {
const side = random() > 0.5 ? 1 : -1;
chips.push({
x: side * (2.55 + random() * 1.55),
y: 0.315,
z: 0.75 + random() * 0.48,
sx: 0.07 + random() * 0.1,
sy: 0.045 + random() * 0.06,
sz: 0.07 + random() * 0.09,
ry: random() * Math.PI,
color: random() > 0.5 ? 0xb98a67 : 0xd4a57e
});
}
addInstancedBoxes(chips, instanceMaterial, "Small coral chips");
// Direct camera controls, implemented without external control modules.
const pointers = new Map();
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
renderer.domElement.classList.add("dragging");
if (pointers.size === 1) {
previousX = event.clientX;
previousY = event.clientY;
} else if (pointers.size === 2) {
const values = [...pointers.values()];
previousPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(view.phi - dy * 0.005, 0.72, 1.43);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0) {
view.radius = THREE.MathUtils.clamp(
view.radius * (previousPinchDistance / distance),
7.6,
17.5
);
updateCamera();
}
previousPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (!pointers.size) renderer.domElement.classList.remove("dragging");
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.007,
7.6,
17.5
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#reset-view").addEventListener("click", () => {
view.theta = defaultView.theta;
view.phi = defaultView.phi;
view.radius = defaultView.radius;
updateCamera();
});
document.querySelector("#detail-view").addEventListener("click", () => {
view.theta = 0.38;
view.phi = 1.19;
view.radius = 8.9;
target.set(0, 3.0, 0);
updateCamera();
});
const labelsButton = document.querySelector("#toggle-labels");
labelsButton.addEventListener("click", () => {
const enabled = labelsButton.getAttribute("aria-pressed") !== "true";
labelsButton.setAttribute("aria-pressed", String(enabled));
document.body.classList.toggle("labels-off", !enabled);
});
const notesButton = document.querySelector("#toggle-notes");
const infoPanel = document.querySelector("#info-panel");
notesButton.addEventListener("click", () => {
const expanded = notesButton.getAttribute("aria-expanded") !== "true";
notesButton.setAttribute("aria-expanded", String(expanded));
infoPanel.classList.toggle("collapsed", !expanded);
});
const annotations = [
{
element: document.querySelector("#annotation-relief"),
position: new THREE.Vector3(-0.48, 5.08, 0.54)
},
{
element: document.querySelector("#annotation-thickness"),
position: new THREE.Vector3(4.03, 2.5, 0.12)
},
{
element: document.querySelector("#annotation-threshold"),
position: new THREE.Vector3(0.62, 0.43, 0.57)
}
];
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
annotations.forEach((annotation) => {
projected.copy(annotation.position).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible = projected.z > -1 && projected.z < 1;
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
annotation.element.style.visibility = visible ? "visible" : "hidden";
});
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
updateAnnotations();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.querySelector("#loading").classList.add("hidden");
setTimeout(() => document.querySelector("#loading")?.remove(), 600);
}
}
animate();
</script>
</body>
</html>
```