Prompt specification
Build or customize the Three.js 3D scene "Coastal railing maintenance exhibit" 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: Coastal railing maintenance exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/coastal-railing-maintenance-exhibit-x1943
Scene Description Prompt:
Compose a fictional railing with coating defects, moisture exposure markers, and an enlarged corrosion inset; explain factors qualitatively without predicting service life from appearance. Build this with Three.js from cdnjs as a voxel scene in one self-contained HTML file.
Working Three.js Starter (coastal-railing-maintenance-exhibit-x1943):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fictional Railing — Qualitative Corrosion Study</title>
<style>
:root {
color-scheme: dark;
--bg: #071017;
--panel: rgba(10, 20, 28, 0.86);
--panel-strong: rgba(10, 20, 28, 0.95);
--line: rgba(166, 203, 216, 0.18);
--text: #e7f0f2;
--muted: #9eb2ba;
--cyan: #46d8e5;
--coral: #ff8168;
--amber: #ffc85a;
--coat: #7d9eaa;
--rust: #bd6639;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#viewport canvas:active {
cursor: grabbing;
}
#label-layer {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.annotation {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
width: max-content;
max-width: 230px;
padding: 7px 10px 7px 7px;
transform: translate(-50%, -100%);
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(6, 14, 20, 0.88);
box-shadow: 0 8px 26px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(8px);
font-size: 11px;
line-height: 1.3;
letter-spacing: 0.015em;
white-space: nowrap;
transition: opacity 120ms linear;
}
.annotation-key {
display: grid;
place-items: center;
width: 22px;
height: 22px;
flex: 0 0 22px;
border-radius: 5px;
color: #071017;
font-size: 11px;
font-weight: 900;
}
.annotation.a .annotation-key {
background: var(--coral);
}
.annotation.b .annotation-key {
background: var(--cyan);
}
.annotation.c .annotation-key {
background: var(--amber);
}
.annotation.d .annotation-key {
background: var(--rust);
}
.panel {
position: fixed;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
}
#intro {
top: 22px;
left: 22px;
width: min(520px, calc(100vw - 44px));
padding: 17px 19px 16px;
pointer-events: auto;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--amber);
box-shadow: 0 0 14px rgba(255, 200, 90, 0.7);
}
h1 {
margin: 0;
max-width: 480px;
font-size: clamp(21px, 2.5vw, 31px);
font-weight: 720;
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
max-width: 465px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.toolbar {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 13px;
}
.toolbar button {
min-height: 31px;
padding: 6px 10px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 255, 255, 0.035);
color: var(--text);
cursor: pointer;
font-size: 11px;
transition:
background 140ms ease,
border-color 140ms ease;
}
.toolbar button:hover,
.toolbar button:focus-visible {
border-color: rgba(166, 203, 216, 0.42);
background: rgba(255, 255, 255, 0.08);
outline: none;
}
#legend {
top: 22px;
right: 22px;
width: 225px;
padding: 14px 15px;
pointer-events: auto;
}
.panel-title {
margin: 0 0 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 10px 1fr;
gap: 9px;
align-items: start;
margin-top: 9px;
color: #c9d6da;
font-size: 11px;
line-height: 1.35;
}
.swatch {
width: 9px;
height: 9px;
margin-top: 3px;
border-radius: 2px;
}
.swatch.coating {
background: var(--coat);
}
.swatch.rust {
background: var(--rust);
}
.swatch.moisture {
background: var(--cyan);
}
.swatch.amber {
background: var(--amber);
}
#notes {
left: 22px;
bottom: 22px;
width: min(440px, calc(100vw - 44px));
padding: 16px 17px;
pointer-events: auto;
}
#notes ul {
display: grid;
gap: 7px;
margin: 10px 0 12px;
padding-left: 17px;
color: #c9d6da;
font-size: 11px;
line-height: 1.45;
}
#notes strong {
color: var(--text);
font-weight: 700;
}
.caution {
padding: 9px 10px;
border-left: 3px solid var(--amber);
background: rgba(255, 200, 90, 0.07);
color: #d9e1e3;
font-size: 10.5px;
line-height: 1.45;
}
#control-hint {
right: 22px;
bottom: 22px;
padding: 9px 12px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.02em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #071017;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
#loading.ready {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
#legend {
display: none;
}
#intro {
padding: 13px 14px;
}
.subtitle {
max-width: 390px;
}
#notes {
max-height: 43vh;
overflow: auto;
}
#control-hint {
display: none;
}
}
@media (max-width: 560px) {
#intro {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
}
h1 {
font-size: 21px;
}
.subtitle {
font-size: 11px;
}
#notes {
left: 10px;
bottom: 10px;
width: calc(100vw - 20px);
padding: 12px 13px;
}
#notes ul {
font-size: 10.5px;
}
.annotation {
max-width: 175px;
font-size: 9.5px;
}
}
</style>
</head>
<body>
<main id="viewport" aria-label="Interactive voxel scene of a fictional railing with coating defects and a corrosion inset"></main>
<div id="label-layer" aria-hidden="true">
<div class="annotation a" id="label-a">
<span class="annotation-key">A</span>
<span>Coating blister / local breach</span>
</div>
<div class="annotation b" id="label-b">
<span class="annotation-key">B</span>
<span>Persistent moisture pathway</span>
</div>
<div class="annotation c" id="label-c">
<span class="annotation-key">C</span>
<span>Illustrative corrosion enlargement</span>
</div>
<div class="annotation d" id="label-d">
<span class="annotation-key">D</span>
<span>Joint crevice used for inset</span>
</div>
</div>
<header class="panel" id="intro">
<div class="eyebrow">
<span class="status-dot"></span>
Fictional specimen R-17 · qualitative study
</div>
<h1>Coating condition, wetting paths, and a magnified corrosion section</h1>
<p class="subtitle">
A voxel visualization of an imagined railing. Surface features are deliberately
exaggerated to make their relationship legible; the scene is not based on
measured field data.
</p>
<div class="toolbar" aria-label="Camera controls">
<button type="button" id="reset-view">Reset view</button>
<button type="button" id="focus-railing">Focus railing</button>
<button type="button" id="focus-inset">Focus inset</button>
</div>
</header>
<aside class="panel" id="legend">
<h2 class="panel-title">Visual key</h2>
<div class="legend-row">
<span class="swatch coating"></span>
<span>Intact or locally disrupted coating</span>
</div>
<div class="legend-row">
<span class="swatch rust"></span>
<span>Stylized exposed and oxidized substrate</span>
</div>
<div class="legend-row">
<span class="swatch moisture"></span>
<span>Moisture exposure marker</span>
</div>
<div class="legend-row">
<span class="swatch amber"></span>
<span>Inspection callout and inset boundary</span>
</div>
</aside>
<aside class="panel" id="notes">
<h2 class="panel-title">Qualitative reading</h2>
<ul>
<li>
<strong>Coating condition:</strong> blisters and missing patches indicate
possible local barrier disruption, but do not quantify adhesion or the
fraction of coating that remains.
</li>
<li>
<strong>Moisture pathways:</strong> drips, lower-rail wetting, and joints
can retain water or contaminants where drainage and drying are limited.
</li>
<li>
<strong>Corrosion interface:</strong> the inset shows a stylized coating /
substrate relationship, not a measured pit depth, corrosion rate, or
cross-section.
</li>
<li>
<strong>Relevant context:</strong> material grade, coating age and history,
salt exposure, temperature, crevice geometry, inspection records, and
measurements would all affect interpretation.
</li>
</ul>
<div class="caution">
<strong>No service-life prediction:</strong> appearance alone cannot establish
remaining safe life, a failure date, or the probability of failure. Those
conclusions require inspection history, quantitative measurements, and
engineering evaluation.
</div>
</aside>
<div class="panel" id="control-hint">
Drag to orbit · scroll / pinch to zoom · arrow keys to rotate · R to reset
</div>
<div id="loading">Building voxel study…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const loading = document.getElementById("loading");
// ---------------------------------------------------------------------
// Renderer, scene, camera, and direct camera controls
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071017);
scene.fog = new THREE.Fog(0x071017, 15, 34);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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",
"Orbitable voxel visualization of a fictional railing"
);
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xb9e9ff, 0x182126, 2.0);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffefcf, 3.0);
keyLight.position.set(-4.5, 9, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
keyLight.target.position.set(1.2, 1.5, 0);
scene.add(keyLight, keyLight.target);
const rimLight = new THREE.DirectionalLight(0x4ccce8, 1.25);
rimLight.position.set(8, 4, -6);
scene.add(rimLight);
const defaultRadius = window.innerWidth < 700 ? 21 : 11.5;
const desired = {
target: new THREE.Vector3(1.15, 1.72, 0),
theta: 0.18,
phi: 1.12,
radius: defaultRadius
};
const current = {
target: desired.target.clone(),
theta: desired.theta,
phi: desired.phi,
radius: desired.radius
};
function applyCamera() {
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x +
current.radius * sinPhi * Math.sin(current.theta),
current.target.y +
current.radius * Math.cos(current.phi),
current.target.z +
current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
}
function setView({ target, theta, phi, radius }) {
if (target) desired.target.set(...target);
if (theta !== undefined) desired.theta = theta;
if (phi !== undefined) desired.phi = phi;
if (radius !== undefined) desired.radius = radius;
}
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.38,
1.48
);
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
pointerId = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
5,
30
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") desired.theta += step;
if (event.key === "ArrowRight") desired.theta -= step;
if (event.key === "ArrowUp") {
desired.phi = Math.max(0.38, desired.phi - step);
}
if (event.key === "ArrowDown") {
desired.phi = Math.min(1.48, desired.phi + step);
}
if (event.key.toLowerCase() === "r") {
setView({
target: [1.15, 1.72, 0],
theta: 0.18,
phi: 1.12,
radius: window.innerWidth < 700 ? 21 : 11.5
});
}
});
document.getElementById("reset-view").addEventListener("click", () => {
setView({
target: [1.15, 1.72, 0],
theta: 0.18,
phi: 1.12,
radius: window.innerWidth < 700 ? 21 : 11.5
});
});
document.getElementById("focus-railing").addEventListener("click", () => {
setView({
target: [-0.2, 1.62, 0],
theta: 0.12,
phi: 1.08,
radius: window.innerWidth < 700 ? 12 : 7.6
});
});
document.getElementById("focus-inset").addEventListener("click", () => {
setView({
target: [5.15, 1.8, 0],
theta: 0.08,
phi: 1.06,
radius: window.innerWidth < 700 ? 9 : 6.4
});
});
// ---------------------------------------------------------------------
// Materials and instanced voxel geometry
// ---------------------------------------------------------------------
const material = {
steel: new THREE.MeshStandardMaterial({
color: 0x536f7a,
roughness: 0.74,
metalness: 0.28
}),
steelLight: new THREE.MeshStandardMaterial({
color: 0x6d8993,
roughness: 0.68,
metalness: 0.24
}),
steelDark: new THREE.MeshStandardMaterial({
color: 0x3d5964,
roughness: 0.8,
metalness: 0.25
}),
insetCoat: new THREE.MeshStandardMaterial({
color: 0x7898a3,
roughness: 0.62,
metalness: 0.2
}),
rust: new THREE.MeshStandardMaterial({
color: 0xb95f35,
roughness: 0.96,
metalness: 0.05
}),
rustBright: new THREE.MeshStandardMaterial({
color: 0xe08a4f,
roughness: 0.92,
metalness: 0.03
}),
rustDark: new THREE.MeshStandardMaterial({
color: 0x733b29,
roughness: 1,
metalness: 0.02
}),
substrate: new THREE.MeshStandardMaterial({
color: 0x3d3936,
roughness: 0.96,
metalness: 0.08
}),
moisture: new THREE.MeshStandardMaterial({
color: 0x35d8e7,
emissive: 0x0c6370,
emissiveIntensity: 0.5,
roughness: 0.28,
metalness: 0,
transparent: true,
opacity: 0.76,
depthWrite: false
}),
markerA: new THREE.MeshStandardMaterial({
color: 0xff8168,
emissive: 0x6f1e12,
emissiveIntensity: 0.7
}),
markerB: new THREE.MeshStandardMaterial({
color: 0x46d8e5,
emissive: 0x0a5963,
emissiveIntensity: 0.8
}),
markerC: new THREE.MeshStandardMaterial({
color: 0xffc85a,
emissive: 0x72500a,
emissiveIntensity: 0.65
}),
markerD: new THREE.MeshStandardMaterial({
color: 0xc97946,
emissive: 0x4d210d,
emissiveIntensity: 0.55
}),
floorA: new THREE.MeshStandardMaterial({
color: 0x111f27,
roughness: 0.98,
metalness: 0
}),
floorB: new THREE.MeshStandardMaterial({
color: 0x142630,
roughness: 0.98,
metalness: 0
}),
floorStage: new THREE.MeshStandardMaterial({
color: 0x1b3038,
roughness: 0.95,
metalness: 0.02
}),
frame: new THREE.MeshStandardMaterial({
color: 0x253b45,
roughness: 0.55,
metalness: 0.38
})
};
const buckets = new Map();
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function voxel(x, y, z, sx, sy, sz, mat, ry = 0) {
if (!buckets.has(mat)) {
buckets.set(mat, []);
}
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(0, ry, 0)
);
const position = new THREE.Vector3(x, y, z);
const scale = new THREE.Vector3(sx, sy, sz);
matrix.compose(position, quaternion, scale);
buckets.get(mat).push(matrix);
}
let seed = 417;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function chooseSteel() {
const r = random();
if (r < 0.16) return material.steelLight;
if (r < 0.29) return material.steelDark;
return material.steel;
}
function addMarker(x, y, z, mat) {
voxel(x, y, z, 0.025, 0.34, 0.025, mat);
voxel(x, y + 0.22, z, 0.16, 0.16, 0.16, mat);
voxel(x, y + 0.22, z + 0.085, 0.08, 0.08, 0.025, material.frame);
}
// ---------------------------------------------------------------------
// Voxel floor and raised inspection stage
// ---------------------------------------------------------------------
for (let x = -8; x <= 8; x += 1) {
for (let z = -5; z <= 5; z += 1) {
const mat = random() > 0.82 ? material.floorB : material.floorA;
voxel(x, -0.16, z, 0.96, 0.12, 0.96, mat);
}
}
for (let x = -3; x <= 3; x += 0.5) {
for (let z = -1; z <= 1; z += 0.5) {
voxel(x, -0.055, z, 0.46, 0.08, 0.46, material.floorStage);
}
}
for (let x = 4; x <= 6; x += 0.5) {
for (let z = -1; z <= 1; z += 0.5) {
voxel(x, -0.055, z, 0.46, 0.08, 0.46, material.floorStage);
}
}
// ---------------------------------------------------------------------
// Fictional railing: posts, segmented rails, and balusters
// ---------------------------------------------------------------------
const postX = [-2.4, 0, 2.4];
for (const x of postX) {
for (let layer = 0; layer < 17; layer += 1) {
voxel(
x,
0.1 + layer * 0.18,
0,
0.21,
0.18,
0.21,
chooseSteel()
);
}
// Layered base plate and anchor blocks.
voxel(x, 0.015, 0, 0.48, 0.12, 0.46, material.steelDark);
voxel(x - 0.17, 0.09, 0, 0.08, 0.08, 0.08, material.rustDark);
voxel(x + 0.17, 0.09, 0, 0.08, 0.08, 0.08, material.rustDark);
voxel(x, 0.09, 0.17, 0.08, 0.08, 0.08, material.rustDark);
voxel(x, 0.09, -0.17, 0.08, 0.08, 0.08, material.rustDark);
}
function addSegmentedRail(y) {
for (let x = -2.7; x <= 2.71; x += 0.18) {
voxel(x, y, 0, 0.176, 0.19, 0.22, chooseSteel());
}
}
addSegmentedRail(3.15);
addSegmentedRail(1.25);
for (const span of [
[-2.4, 0],
[0, 2.4]
]) {
for (let x = span[0] + 0.29; x < span[1]; x += 0.38) {
for (let y = 0.32; y <= 2.91; y += 0.28) {
voxel(x, y, 0, 0.13, 0.275, 0.13, chooseSteel());
}
}
}
// ---------------------------------------------------------------------
// Coating blister A: a stylized raised coating island and exposed edge
// ---------------------------------------------------------------------
for (let ix = -2; ix <= 2; ix += 1) {
for (let iy = -1; iy <= 1; iy += 1) {
if (Math.abs(ix) + Math.abs(iy) > 3) continue;
const mat =
ix === 0 && iy === 0
? material.rustBright
: random() > 0.25
? material.rust
: material.rustDark;
voxel(
1.02 + ix * 0.075,
3.15 + iy * 0.075,
0.135,
0.072,
0.072,
0.055,
mat
);
}
}
// A small lifted coating flap.
voxel(
1.02,
3.285,
0.19,
0.17,
0.045,
0.055,
material.steelLight,
-0.12
);
// ---------------------------------------------------------------------
// Moisture exposure B: lower-rail wetting and short vertical drips
// ---------------------------------------------------------------------
for (let ix = -3; ix <= 3; ix += 1) {
for (let iy = -1; iy <= 1; iy += 1) {
if (Math.abs(ix) + Math.abs(iy) > 3) continue;
voxel(
-1.24 + ix * 0.08,
1.25 + iy * 0.08,
0.135,
0.075,
0.075,
0.045,
material.moisture
);
}
}
for (let i = 0; i < 5; i += 1) {
voxel(
-1.39 + i * 0.075,
1.05 - (i % 2) * 0.09,
0.145,
0.055,
0.13,
0.035,
material.moisture
);
}
// ---------------------------------------------------------------------
// Joint crevice D: local oxidation around the lower-rail connection
// ---------------------------------------------------------------------
for (let ix = -2; ix <= 2; ix += 1) {
for (let iy = -1; iy <= 1; iy += 1) {
if (Math.abs(ix) + Math.abs(iy) > 3) continue;
const mat =
Math.abs(ix) + Math.abs(iy) === 3
? material.rustBright
: material.rustDark;
voxel(
ix * 0.07,
1.25 + iy * 0.07,
0.145,
0.068,
0.068,
0.05,
mat
);
}
}
// ---------------------------------------------------------------------
// Enlarged corrosion inset C: a framed, stylized coating/substrate section
// ---------------------------------------------------------------------
const insetX = 5.15;
const insetY = 1.78;
// Backing plate and block-built frame.
voxel(insetX, insetY, -0.24, 3.02, 3.02, 0.10, material.frame);
voxel(insetX - 1.48, insetY, -0.13, 0.12, 3.0, 0.20, material.frame);
voxel(insetX + 1.48, insetY, -0.13, 0.12, 3.0, 0.20, material.frame);
voxel(insetX, insetY + 1.46, -0.13, 3.0, 0.12, 0.20, material.frame);
voxel(insetX, insetY - 1.46, -0.13, 3.0, 0.12, 0.20, material.frame);
// Irregular stylized corrosion field.
const rustCells = new Set();
for (let col = 2; col <= 7; col += 1) {
for (let row = 1; row <= 6; row += 1) {
const inside =
(col === 2 && row >= 3 && row <= 5) ||
(col === 3 && row >= 2 && row <= 6) ||
(col === 4 && row >= 2 && row <= 6) ||
(col === 5 && row >= 3 && row <= 6) ||
(col === 6 && row >= 4 && row <= 5) ||
(col === 7 && row === 4);
if (inside) rustCells.add(`${col},${row}`);
}
}
const cell = 0.30;
for (let col = 0; col < 8; col += 1) {
for (let row = 0; row < 8; row += 1) {
const x = insetX + (col - 3.5) * cell;
const y = insetY + (3.5 - row) * cell;
const isRust = rustCells.has(`${col},${row}`);
// Continuous substrate.
voxel(
x,
y,
0,
0.285,
0.285,
0.22,
material.substrate
);
if (isRust) {
const mat =
random() > 0.73
? material.rustBright
: random() > 0.42
? material.rust
: material.rustDark;
voxel(x, y, 0.15, 0.27, 0.27, 0.13, mat);
// A few brighter pixels suggest exposed oxide, still not depth data.
if (random() > 0.64) {
voxel(
x + (random() - 0.5) * 0.08,
y + (random() - 0.5) * 0.08,
0.235,
0.075,
0.075,
0.045,
material.rustBright
);
}
} else {
// Thin surviving coating tiles.
voxel(
x,
y,
0.145,
0.275,
0.275,
0.075,
material.insetCoat
);
}
}
}
// Moisture indicator along the lower-left portion of the inset.
for (let i = 0; i < 6; i += 1) {
voxel(
insetX - 0.98 + i * 0.17,
insetY - 1.27,
0.23,
0.13,
0.11,
0.07,
material.moisture
);
}
voxel(
insetX - 0.72,
insetY - 1.45,
0.23,
0.09,
0.25,
0.06,
material.moisture
);
// Lifted coating tile at the edge of the damaged zone.
voxel(
insetX + 0.72,
insetY + 0.91,
0.34,
0.28,
0.055,
0.25,
material.insetCoat,
-0.18
);
// Connector from the actual joint defect to the enlarged section.
const connectorCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0.08, 1.28, 0.19),
new THREE.Vector3(1.55, 1.30, 0.22),
new THREE.Vector3(2.75, 1.45, 0.10),
new THREE.Vector3(3.63, 1.72, -0.06)
]);
const connectorGeometry = new THREE.BufferGeometry().setFromPoints(
connectorCurve.getPoints(72)
);
const connectorMaterial = new THREE.LineDashedMaterial({
color: 0xffc85a,
transparent: true,
opacity: 0.58,
dashSize: 0.12,
gapSize: 0.09
});
const connector = new THREE.Line(connectorGeometry, connectorMaterial);
connector.computeLineDistances();
scene.add(connector);
// Small voxel junction markers on the connector.
voxel(0.08, 1.28, 0.19, 0.11, 0.11, 0.11, material.markerC);
voxel(3.63, 1.72, -0.06, 0.11, 0.11, 0.11, material.markerC);
// ---------------------------------------------------------------------
// Callout pins
// ---------------------------------------------------------------------
addMarker(1.02, 3.49, 0.23, material.markerA);
addMarker(-1.24, 1.64, 0.25, material.markerB);
addMarker(insetX, 3.53, 0.28, material.markerC);
addMarker(0, 1.62, 0.27, material.markerD);
// ---------------------------------------------------------------------
// Commit all voxel buckets into efficient instanced meshes
// ---------------------------------------------------------------------
for (const [mat, matrices] of buckets.entries()) {
const mesh = new THREE.InstancedMesh(
unitBox,
mat,
matrices.length
);
matrices.forEach((matrix, index) => {
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = !mat.transparent;
mesh.receiveShadow = true;
scene.add(mesh);
}
// ---------------------------------------------------------------------
// Projected HTML annotations
// ---------------------------------------------------------------------
const annotations = [
{
element: document.getElementById("label-a"),
point: new THREE.Vector3(1.02, 3.82, 0.23),
dx: 0,
dy: -4
},
{
element: document.getElementById("label-b"),
point: new THREE.Vector3(-1.24, 1.98, 0.25),
dx: -34,
dy: 8
},
{
element: document.getElementById("label-c"),
point: new THREE.Vector3(insetX, 3.87, 0.28),
dx: 0,
dy: -4
},
{
element: document.getElementById("label-d"),
point: new THREE.Vector3(0, 1.95, 0.27),
dx: 42,
dy: 8
}
];
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
for (const annotation of annotations) {
projected.copy(annotation.point).project(camera);
const x = (projected.x * 0.5 + 0.5) * width + annotation.dx;
const y = (-projected.y * 0.5 + 0.5) * height + annotation.dy;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -120 &&
x < width + 120 &&
y > -50 &&
y < height + 50;
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
annotation.element.style.opacity = visible ? "1" : "0";
}
}
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 560 ? 55 : 42;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
applyCamera();
renderer.setAnimationLoop(() => {
current.target.lerp(desired.target, 0.12);
current.theta += (desired.theta - current.theta) * 0.12;
current.phi += (desired.phi - current.phi) * 0.12;
current.radius += (desired.radius - current.radius) * 0.12;
applyCamera();
updateAnnotations();
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
loading.classList.add("ready");
setTimeout(() => loading.remove(), 300);
});
</script>
</body>
</html>
```