Prompt specification
Build or customize the Three.js 3D scene "Window glass and ceramic tile gallery" 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: Window glass and ceramic tile gallery
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/window-glass-and-ceramic-tile-gallery-x1951
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows glass and ceramic microstructures. Compose everyday objects beside structural insets and crack-path illustrations; distinguish material class, surface defects, and loading conditions rather than declaring all brittle solids identical. Voxel style.
Working Three.js Starter (window-glass-and-ceramic-tile-gallery-x1951):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fracture Atlas — Glass & Ceramic Microstructures</title>
<style>
:root {
color-scheme: dark;
--bg: #071116;
--panel: rgba(10, 24, 31, 0.82);
--line: rgba(151, 224, 231, 0.17);
--text: #e8f5f4;
--muted: #8fa8ab;
--glass: #66dce2;
--ceramic: #e6c58d;
--defect: #ff6f61;
--load: #ffc65a;
}
* { 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;
}
#stage, #labels {
position: fixed;
inset: 0;
}
#stage { z-index: 0; }
#stage canvas { display: block; touch-action: none; }
#labels { z-index: 2; pointer-events: none; }
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
}
#masthead {
top: 20px;
left: 20px;
width: 330px;
padding: 18px 20px 17px;
border-radius: 4px 18px 18px 18px;
}
.eyebrow {
color: var(--glass);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 6px;
font-size: clamp(24px, 3vw, 36px);
line-height: 0.98;
letter-spacing: -0.045em;
}
#masthead p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#controls {
top: 20px;
right: 20px;
width: 276px;
padding: 15px;
border-radius: 18px 4px 18px 18px;
}
.control-heading {
margin: 0 0 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.control-heading:not(:first-child) { margin-top: 15px; }
.button-row {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
button {
appearance: none;
border: 1px solid rgba(160, 211, 214, 0.18);
border-radius: 7px;
padding: 7px 9px;
background: rgba(255, 255, 255, 0.035);
color: #b9ccce;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
cursor: pointer;
transition: 150ms ease;
}
button:hover {
border-color: rgba(102, 220, 226, 0.55);
color: white;
background: rgba(102, 220, 226, 0.08);
}
button.active {
border-color: var(--glass);
color: #061418;
background: var(--glass);
box-shadow: 0 0 18px rgba(102, 220, 226, 0.15);
}
.load-row button[data-load="compression"].active {
border-color: var(--load);
background: var(--load);
}
.load-row button[data-load="bending"].active {
border-color: var(--ceramic);
background: var(--ceramic);
}
#readout {
left: 20px;
bottom: 20px;
width: 355px;
padding: 17px 19px;
border-radius: 18px 18px 18px 4px;
}
#readout h2 {
margin: 5px 0 7px;
font-size: 20px;
letter-spacing: -0.025em;
}
#readout p {
margin: 0;
color: #a8bdbe;
font-size: 11.5px;
line-height: 1.55;
}
.facts {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.fact { min-width: 0; }
.fact span {
display: block;
margin-bottom: 3px;
color: #637c80;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.fact strong {
display: block;
color: #dbe8e8;
font-size: 9.5px;
line-height: 1.35;
}
#legend {
right: 20px;
bottom: 20px;
width: 276px;
padding: 15px;
border-radius: 18px 18px 4px 18px;
}
.legend-row {
display: grid;
grid-template-columns: 22px 1fr;
gap: 8px;
align-items: start;
margin-bottom: 9px;
}
.legend-row:last-of-type { margin-bottom: 0; }
.swatch {
width: 18px;
height: 18px;
margin-top: 1px;
border-radius: 4px;
}
.swatch.glass {
border: 1px solid rgba(165, 245, 247, 0.8);
background: rgba(102, 220, 226, 0.28);
box-shadow: inset 0 0 0 4px rgba(102, 220, 226, 0.06);
}
.swatch.ceramic {
border: 1px solid #b28f57;
background:
linear-gradient(90deg, transparent 45%, rgba(60, 42, 20, 0.35) 46% 54%, transparent 55%),
linear-gradient(transparent 45%, rgba(60, 42, 20, 0.35) 46% 54%, transparent 55%),
#d6b47d;
}
.swatch.defect {
border: 1px solid #ff9b90;
background: var(--defect);
transform: rotate(8deg);
}
.swatch.load {
position: relative;
background: var(--load);
}
.swatch.load::after {
content: "";
position: absolute;
left: 4px;
top: 8px;
width: 8px;
height: 2px;
background: #071116;
box-shadow: 6px -3px 0 -0.5px #071116;
}
.legend-row b {
display: block;
margin-bottom: 2px;
font-size: 10px;
}
.legend-row small {
display: block;
color: #80999c;
font-size: 9.5px;
line-height: 1.35;
}
.legend-note {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #647e81;
font-size: 8.5px;
line-height: 1.45;
}
#hint {
position: fixed;
z-index: 4;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
color: rgba(190, 214, 215, 0.56);
font-size: 8.5px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
}
.world-label {
position: absolute;
left: 0;
top: 0;
display: flex;
gap: 8px;
align-items: flex-start;
max-width: 245px;
padding: 7px 10px;
border: 1px solid rgba(102, 220, 226, 0.26);
border-radius: 7px;
background: rgba(5, 16, 21, 0.8);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
opacity: 0;
transition: opacity 120ms ease;
will-change: transform;
}
.world-label::before {
content: "";
width: 6px;
height: 6px;
margin-top: 3px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--glass);
box-shadow: 0 0 10px rgba(102, 220, 226, 0.6);
}
.world-label.ceramic {
border-color: rgba(230, 197, 141, 0.28);
}
.world-label.ceramic::before {
background: var(--ceramic);
box-shadow: 0 0 10px rgba(230, 197, 141, 0.45);
}
.world-label b {
display: block;
color: #dbe9e9;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.world-label small {
display: block;
margin-top: 2px;
color: #7f989b;
font-size: 8px;
line-height: 1.35;
}
.world-label.coupon {
padding: 5px 7px;
border-radius: 5px;
}
.world-label.coupon b { font-size: 7.5px; }
.world-label.coupon small { font-size: 7px; }
@media (max-width: 900px) {
#masthead { width: 280px; }
#legend { display: none; }
#controls { width: 230px; }
#readout { width: 310px; }
}
@media (max-width: 650px) {
#masthead {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 12px 14px;
}
#masthead p { display: none; }
h1 { font-size: 24px; }
#controls {
top: 91px;
right: 10px;
width: 200px;
padding: 11px;
}
#readout {
left: 10px;
bottom: 10px;
width: calc(100vw - 20px);
padding: 12px 14px;
}
#readout p { font-size: 10.5px; }
.facts { gap: 4px; }
#hint { display: none; }
.world-label { transform: scale(0.8); }
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels"></div>
<header id="masthead" class="panel">
<div class="eyebrow">Material atlas / 01</div>
<h1>Brittle,<br>not identical.</h1>
<p>Glass and ceramics can both fracture abruptly—but their microstructure,
surface flaws, and loading modes determine where and how failure begins.</p>
</header>
<section id="controls" class="panel">
<div class="control-heading">View collection</div>
<div class="button-row" id="viewButtons">
<button data-view="all" class="active">All</button>
<button data-view="glass">Glass</button>
<button data-view="ceramic">Ceramic</button>
<button data-view="defects">Defects</button>
<button data-view="cracks">Crack paths</button>
</div>
<div class="control-heading">Load focus</div>
<div class="button-row load-row" id="loadButtons">
<button data-load="all" class="active">Compare</button>
<button data-load="tension">Tension</button>
<button data-load="compression">Compression</button>
<button data-load="bending">Bending</button>
</div>
</section>
<section id="readout" class="panel">
<div id="readoutEyebrow" class="eyebrow">Case 01 / Glass</div>
<h2 id="readoutTitle">Tension + edge chip</h2>
<p id="readoutBody">
An amorphous silica network has no grain boundaries. A sharp surface chip
concentrates tensile stress and becomes the origin of a fast-running crack.
</p>
<div class="facts">
<div class="fact">
<span>Class</span>
<strong id="factClass">Amorphous network</strong>
</div>
<div class="fact">
<span>Loading</span>
<strong id="factLoad">Mode I tension</strong>
</div>
<div class="fact">
<span>Driver</span>
<strong id="factDriver">Edge flaw</strong>
</div>
</div>
</section>
<section id="legend" class="panel">
<div class="control-heading">Visual key</div>
<div class="legend-row">
<div class="swatch glass"></div>
<div>
<b>Glass</b>
<small>Continuous amorphous network; transparent cyan.</small>
</div>
</div>
<div class="legend-row">
<div class="swatch ceramic"></div>
<div>
<b>Ceramic</b>
<small>Crystalline grains and pores; opaque sand tone.</small>
</div>
</div>
<div class="legend-row">
<div class="swatch defect"></div>
<div>
<b>Surface defect</b>
<small>Coral chip or pore marker; dark void = cavity.</small>
</div>
</div>
<div class="legend-row">
<div class="swatch load"></div>
<div>
<b>Load direction</b>
<small>Amber arrows show the applied boundary condition.</small>
</div>
</div>
<div class="legend-note">
Crack paths are qualitative teaching diagrams, not scale or strength predictions.
Click a specimen to inspect its case.
</div>
</section>
<div id="hint">Drag to orbit · scroll to zoom · right-drag to pan · click a specimen</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* --------------------------------------------------------------------------
Renderer, scene and direct camera controls
--------------------------------------------------------------------------- */
const stage = document.querySelector("#stage");
const labelLayer = document.querySelector("#labels");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071116);
scene.fog = new THREE.Fog(0x071116, 22, 43);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
theta: -0.015,
phi: 1.055,
radius: 18.7,
target: new THREE.Vector3(0.65, 1.15, 0),
fit: true
};
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);
}
updateCamera();
const pointerState = {
down: false,
button: 0,
x: 0,
y: 0,
startX: 0,
startY: 0,
distance: 0
};
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
pointerState.down = true;
pointerState.button = event.button;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
pointerState.startX = event.clientX;
pointerState.startY = event.clientY;
pointerState.distance = 0;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerState.down) return;
const dx = event.clientX - pointerState.x;
const dy = event.clientY - pointerState.y;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
pointerState.distance += Math.abs(dx) + Math.abs(dy);
if (pointerState.button === 2 || event.shiftKey) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(forward, camera.up).normalize();
const panScale = orbit.radius * 0.00125;
orbit.target.addScaledVector(right, -dx * panScale);
orbit.target.addScaledVector(forward, dy * panScale);
orbit.target.x = THREE.MathUtils.clamp(orbit.target.x, -9, 10);
orbit.target.y = THREE.MathUtils.clamp(orbit.target.y, 0.2, 3.5);
orbit.target.z = THREE.MathUtils.clamp(orbit.target.z, -3, 3);
} else {
orbit.theta -= dx * 0.0052;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.0045, 0.55, 1.38);
}
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
pointerState.down = false;
canvas.releasePointerCapture(event.pointerId);
if (pointerState.distance < 5) {
inspectAt(event.clientX, event.clientY);
}
});
canvas.addEventListener("pointercancel", () => {
pointerState.down = false;
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
10.5,
34
);
orbit.fit = false;
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", () => {
orbit.theta = -0.015;
orbit.phi = 1.055;
orbit.target.set(0.65, 1.15, 0);
orbit.fit = true;
fitCameraToViewport();
updateCamera();
});
function fitCameraToViewport() {
if (!orbit.fit) return;
const required = 20.5 /
(2 * Math.tan(THREE.MathUtils.degToRad(camera.fov * 0.5)) * camera.aspect);
orbit.radius = Math.max(18.7, required);
}
/* --------------------------------------------------------------------------
Lighting and materials
--------------------------------------------------------------------------- */
scene.add(new THREE.HemisphereLight(0x8fdce2, 0x152027, 1.7));
const keyLight = new THREE.DirectionalLight(0xe8ffff, 3.0);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4fb8c4, 1.5);
rimLight.position.set(8, 6, -7);
scene.add(rimLight);
const cyanLight = new THREE.PointLight(0x45dce5, 10, 10, 2);
cyanLight.position.set(-5, 3.8, 4);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xffb949, 8, 9, 2);
amberLight.position.set(7, 3.8, 3);
scene.add(amberLight);
const materials = {
glass: new THREE.MeshPhysicalMaterial({
color: 0x67dde2,
emissive: 0x08282b,
emissiveIntensity: 0.65,
roughness: 0.16,
metalness: 0,
transmission: 0.12,
thickness: 0.4,
ior: 1.5,
transparent: true,
opacity: 0.62,
depthWrite: false,
side: THREE.DoubleSide
}),
glassBright: new THREE.MeshStandardMaterial({
color: 0x9af6f4,
emissive: 0x1f777b,
emissiveIntensity: 0.7,
roughness: 0.3,
transparent: true,
opacity: 0.85
}),
ceramic: new THREE.MeshStandardMaterial({
color: 0xe2c590,
roughness: 0.78,
metalness: 0
}),
ceramicLight: new THREE.MeshStandardMaterial({
color: 0xf0d9aa,
roughness: 0.72,
metalness: 0
}),
ceramicDark: new THREE.MeshStandardMaterial({
color: 0xa17b4d,
roughness: 0.9,
metalness: 0
}),
metal: new THREE.MeshStandardMaterial({
color: 0x31454a,
roughness: 0.38,
metalness: 0.78
}),
dark: new THREE.MeshStandardMaterial({
color: 0x10242b,
roughness: 0.78,
metalness: 0.15
}),
darker: new THREE.MeshStandardMaterial({
color: 0x08171d,
roughness: 0.86,
metalness: 0.08
}),
floor: new THREE.MeshStandardMaterial({
color: 0x0b1a20,
roughness: 0.92,
metalness: 0.08
}),
wall: new THREE.MeshStandardMaterial({
color: 0x091820,
roughness: 1,
metalness: 0
}),
defect: new THREE.MeshStandardMaterial({
color: 0xff6f61,
emissive: 0x7c1712,
emissiveIntensity: 0.7,
roughness: 0.44
}),
void: new THREE.MeshStandardMaterial({
color: 0x020506,
roughness: 1,
metalness: 0
}),
load: new THREE.MeshStandardMaterial({
color: 0xffc65a,
emissive: 0x6d3b06,
emissiveIntensity: 0.55,
roughness: 0.4
}),
coffee: new THREE.MeshStandardMaterial({
color: 0x21150f,
roughness: 0.25,
metalness: 0.05
})
};
const grainMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.82,
metalness: 0,
vertexColors: true
});
/* --------------------------------------------------------------------------
Geometry helpers
--------------------------------------------------------------------------- */
const roots = [];
const interactiveRoots = [];
const labelEntries = [];
function box(parent, sx, sy, sz, x, y, z, material, outlined = false) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(sx, sy, sz), material);
mesh.position.set(x, y, z);
mesh.castShadow = !material.transparent;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlined) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color: material === materials.glass ? 0x8ef1ef : 0x6f8587,
transparent: true,
opacity: 0.42
})
);
mesh.add(edges);
}
return mesh;
}
function voxelMesh(parent, positions, sx, sy, sz, material, colors = null) {
const geometry = new THREE.BoxGeometry(1, 1, 1);
const mesh = new THREE.InstancedMesh(geometry, material, positions.length);
const dummy = new THREE.Object3D();
positions.forEach((position, index) => {
dummy.position.set(position[0], position[1], position[2]);
dummy.scale.set(sx, sy, sz);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (colors) {
mesh.setColorAt(index, colors[index]);
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = !material.transparent;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function lineSegments(parent, segments, material) {
const positions = [];
for (const segment of segments) {
positions.push(
segment[0][0], segment[0][1], segment[0][2],
segment[1][0], segment[1][1], segment[1][2]
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
const lines = new THREE.LineSegments(geometry, material);
parent.add(lines);
return lines;
}
function register(root, metadata) {
root.userData = { ...root.userData, ...metadata };
roots.push(root);
interactiveRoots.push(root);
return root;
}
function platform(parent, x = 0, z = 0, width = 2.4, depth = 1.9) {
box(parent, width, 0.18, depth, x, 0.14, z, materials.dark, true);
box(parent, width - 0.16, 0.025, depth - 0.16, x, 0.245, z, materials.darker);
}
function addArrow(parent, tip, direction, length = 0.55) {
const group = new THREE.Group();
parent.add(group);
const dir = new THREE.Vector3(...direction).normalize();
const perp = new THREE.Vector3(-dir.y, dir.x, 0).normalize();
const tipVector = new THREE.Vector3(...tip);
const shaftLength = Math.max(0.12, length - 0.12);
const shaftCenter = tipVector.clone().addScaledVector(dir, -shaftLength * 0.5);
const shaft = box(
group,
shaftLength,
0.075,
0.075,
shaftCenter.x,
shaftCenter.y,
shaftCenter.z,
materials.load
);
shaft.rotation.z = Math.atan2(dir.y, dir.x);
const headCenter = tipVector.clone().addScaledVector(dir, -0.055);
box(group, 0.105, 0.105, 0.105, tipVector.x, tipVector.y, tipVector.z, materials.load);
box(
group,
0.09,
0.09,
0.09,
headCenter.x + perp.x * 0.095,
headCenter.y + perp.y * 0.095,
headCenter.z,
materials.load
);
box(
group,
0.09,
0.09,
0.09,
headCenter.x - perp.x * 0.095,
headCenter.y - perp.y * 0.095,
headCenter.z,
materials.load
);
}
function voxelPath(parent, points, z = 0.35, size = 0.075) {
const positions = [];
for (let index = 0; index < points.length - 1; index++) {
const a = points[index];
const b = points[index + 1];
const dx = b[0] - a[0];
const dy = b[1] - a[1];
const length = Math.hypot(dx, dy);
const count = Math.max(1, Math.ceil(length / (size * 0.88)));
for (let step = 0; step <= count; step++) {
const t = step / count;
positions.push([
a[0] + dx * t,
a[1] + dy * t,
z
]);
}
}
return voxelMesh(parent, positions, size, size, size, materials.defect);
}
function addWorldLabel(position, title, subtitle, tone = "glass", follow = null, coupon = false) {
const element = document.createElement("div");
element.className = `world-label ${tone}${coupon ? " coupon" : ""}`;
element.innerHTML = `<span><b>${title}</b><small>${subtitle}</small></span>`;
labelLayer.appendChild(element);
labelEntries.push({
element,
position: new THREE.Vector3(...position),
follow
});
}
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
/* --------------------------------------------------------------------------
Diorama shell
--------------------------------------------------------------------------- */
box(scene, 21.5, 0.18, 6.5, 0.6, -0.02, 0, materials.floor, true);
box(scene, 22, 6.4, 0.2, 0.6, 3.05, -3.45, materials.wall);
const grid = new THREE.GridHelper(20, 40, 0x31565d, 0x183139);
grid.position.set(0.6, 0.075, 0);
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
[-3.55, 1.0, 5.25].forEach((x) => {
box(scene, 0.025, 0.018, 5.6, x, 0.09, 0, materials.glassBright);
for (const z of [-2.65, 2.65]) {
box(scene, 0.24, 0.035, 0.24, x, 0.105, z, materials.glassBright);
}
});
/* --------------------------------------------------------------------------
01 — Everyday objects
--------------------------------------------------------------------------- */
const glassCupRoot = register(new THREE.Group(), {
materialClass: "glass",
content: "everyday",
info: {
eyebrow: "Everyday / Silica glass",
title: "Chipped drinking glass",
body: "The tumbler makes the surface-defect problem intuitive: a tiny edge chip is not cosmetic. Under hand pressure it concentrates stress, so the crack starts at the rim rather than in the bulk material.",
class: "Amorphous network",
load: "Local tension",
driver: "Rim chip"
}
});
glassCupRoot.position.set(-7.0, 0, 0.05);
scene.add(glassCupRoot);
platform(glassCupRoot, 0, 0, 2.35, 1.95);
const glassCupVoxels = [];
for (let layer = 0; layer < 8; layer++) {
for (let ix = -3; ix <= 3; ix++) {
for (let iz = -3; iz <= 3; iz++) {
const isPerimeter = Math.abs(ix) === 3 || Math.abs(iz) === 3;
const isSolidBase = layer < 2;
if (!isPerimeter && !isSolidBase) continue;
if (layer === 7 && ix === 3 && iz === 3) continue;
glassCupVoxels.push([ix * 0.24, 0.36 + layer * 0.24, iz * 0.24]);
}
}
}
voxelMesh(glassCupRoot, glassCupVoxels, 0.208, 0.208, 0.208, materials.glass);
const glassCupChip = register(new THREE.Group(), {
materialClass: "glass",
content: "defect",
isDefect: true,
info: {
eyebrow: "Surface defect / Glass",
title: "Rim chip = crack initiator",
body: "The coral cluster marks a missing rim voxel. Its sharp geometry raises the local stress intensity, making this location much more likely to initiate fracture than the smooth glass wall.",
class: "Surface chip",
load: "Local tension",
driver: "Stress concentration"
}
});
glassCupChip.position.set(-6.28, 2.02, 0.84);
scene.add(glassCupChip);
box(glassCupChip, 0.13, 0.10, 0.13, 0, 0, 0, materials.defect);
box(glassCupChip, 0.09, 0.08, 0.10, 0.14, -0.09, 0.03, materials.defect);
box(glassCupChip, 0.08, 0.08, 0.09, -0.09, 0.10, 0.02, materials.defect);
const ceramicMugRoot = register(new THREE.Group(), {
materialClass: "ceramic",
content: "everyday",
info: {
eyebrow: "Everyday / Porcelain ceramic",
title: "Porcelain mug",
body: "The mug retains the familiar silhouette of a crystalline ceramic body. Its opaque grains scatter light, while small pores can remain as hidden initiation sites if the glaze or surface is breached.",
class: "Crystalline body",
load: "Thermal + hand load",
driver: "Pore / glaze flaw"
}
});
ceramicMugRoot.position.set(-4.68, 0, 0.12);
scene.add(ceramicMugRoot);
platform(ceramicMugRoot, 0, 0, 2.25, 1.95);
const mugVoxels = [];
for (let layer = 0; layer < 8; layer++) {
for (let ix = -2; ix <= 2; ix++) {
for (let iz = -2; iz <= 2; iz++) {
const isPerimeter = Math.abs(ix) === 2 || Math.abs(iz) === 2;
const isSolidBase = layer < 2;
if (!isPerimeter && !isSolidBase) continue;
mugVoxels.push([ix * 0.26, 0.35 + layer * 0.24, iz * 0.26]);
}
}
}
voxelMesh(ceramicMugRoot, mugVoxels, 0.225, 0.225, 0.225, materials.ceramic);
for (let layer = 2; layer <= 6; layer++) {
mugVoxels.length = 0;
mugVoxels.push([0.78, 0.35 + layer * 0.24, 0]);
mugVoxels.push([1.13, 0.35 + layer * 0.24, 0]);
}
voxelMesh(ceramicMugRoot, mugVoxels, 0.225, 0.225, 0.225, materials.ceramic);
box(ceramicMugRoot, 0.46, 0.225, 0.225, 0.955, 0.83, 0, materials.ceramic);
box(ceramicMugRoot, 0.46, 0.225, 0.225, 0.955, 1.79, 0, materials.ceramic);
const coffeeVoxels = [];
for (let ix = -1; ix <= 1; ix++) {
for (let iz = -1; iz <= 1; iz++) {
coffeeVoxels.push([ix * 0.18, 1.66, iz * 0.18]);
}
}
voxelMesh(ceramicMugRoot, coffeeVoxels, 0.17, 0.035, 0.17, materials.coffee);
const mugPore = register(new THREE.Group(), {
materialClass: "ceramic",
content: "defect",
isDefect: true,
info: {
eyebrow: "Surface defect / Ceramic",
title: "Surface-connected pore",
body: "A dark void marks a pore exposed at the surface. The coral squares identify its location, not the pore itself. Under bending or impact, this discontinuity can become a local crack starter.",
class: "Surface pore",
load: "Bending / impact",
driver: "Pore edge"
}
});
mugPore.position.set(-4.78, 1.08, 0.665);
scene.add(mugPore);
box(mugPore, 0.095, 0.095, 0.045, 0, 0, 0, materials.void);
box(mugPore, 0.065, 0.045, 0.04, 0.095, 0, 0.015, materials.defect);
box(mugPore, 0.065, 0.045, 0.04, -0.095, 0, 0.015, materials.defect);
box(mugPore, 0.045, 0.065, 0.04, 0, 0.095, 0.015, materials.defect);
box(mugPore, 0.045, 0.065, 0.04, 0, -0.095, 0.015, materials.defect);
/* --------------------------------------------------------------------------
02 — Microstructure samples
--------------------------------------------------------------------------- */
const glassMicroRoot = register(new THREE.Group(), {
materialClass: "glass",
content: "microstructure",
info: {
eyebrow: "Microstructure / Glass",
title: "Amorphous network",
body: "The cyan nodes form a continuous, irregular network with no repeating grain cells. There is no grain boundary to arrest a crack, so a flaw can guide a very sharp fracture path.",
class: "Non-crystalline",
load: "Path depends on flaw",
driver: "Continuous network"
}
});
glassMicroRoot.position.set(-2.63, 0, -0.35);
scene.add(glassMicroRoot);
platform(glassMicroRoot, 0, 0, 2.55, 1.85);
box(glassMicroRoot, 2.3, 2.3, 0.22, 0, 1.83, 0, materials.metal, true);
box(glassMicroRoot, 2.08, 2.08, 0.06, 0, 1.83, 0.135, materials.darker);
const random = mulberry32(134);
const glassNodes = [];
for (let index = 0; index < 24; index++) {
glassNodes.push([
(random() - 0.5) * 1.76,
1.83 + (random() - 0.5) * 1.76,
0.21
]);
}
voxelMesh(glassMicroRoot, glassNodes, 0.105, 0.105, 0.105, materials.glassBright);
const networkSegments = [];
for (let i = 0; i < glassNodes.length; i++) {
const nearest = glassNodes
.map((node, index) => ({
index,
distance: Math.hypot(
node[0] - glassNodes[i][0],
node[1] - glassNodes[i][1]
)
}))
.filter(entry => entry.index !== i)
.sort((a, b) => a.distance - b.distance)
.slice(0, 2);
for (const entry of nearest) {
networkSegments.push([glassNodes[i], glassNodes[entry.index]]);
}
}
lineSegments(glassMicroRoot, networkSegments, new THREE.LineBasicMaterial({
color: 0x65dce1,
transparent: true,
opacity: 0.44
}));
const microGlassChip = register(new THREE.Group(), {
materialClass: "glass",
content: "defect",
isDefect: true,
info: {
eyebrow: "Surface defect / Glass",
title: "Edge-connected flaw",
body: "A flaw connected to the surface is especially influential in glass. The uninterrupted network means there is no internal boundary to blunt or divert the crack once it starts.",
class: "Edge chip",
load: "Tension / bending",
driver: "Sharp radius"
}
});
microGlassChip.position.set(-3.72, 2.61, -0.08);
scene.add(microGlassChip);
box(microGlassChip, 0.12, 0.12, 0.12, 0, 0, 0, materials.defect);
box(microGlassChip, 0.09, 0.09, 0.09, 0.13, 0.09, 0, materials.defect);
box(microGlassChip, 0.09, 0.09, 0.09, 0.11, -0.11, 0, materials.defect);
const ceramicMicroRoot = register(new THREE.Group(), {
materialClass: "ceramic",
content: "microstructure",
info: {
eyebrow: "Microstructure / Ceramic",
title: "Crystalline grain mosaic",
body: "The ceramic section is divided into differently oriented grains. Grain boundaries and pores can deflect, blunt, or link cracks, so the final path is less directly controlled by one continuous flaw.",
class: "Polycrystalline",
load: "Grain-dependent",
driver: "Grain boundary + pore"
}
});
ceramicMicroRoot.position.set(-0.22, 0, -0.35);
scene.add(ceramicMicroRoot);
platform(ceramicMicroRoot, 0, 0, 2.55, 1.85);
box(ceramicMicroRoot, 2.3, 2.3, 0.22, 0, 1.83, 0, materials.metal, true);
box(ceramicMicroRoot, 2.08, 2.08, 0.06, 0, 1.83, 0.135, materials.darker);
const grainPositions = [];
const grainColors = [];
for (let iy = 0; iy < 9; iy++) {
for (let ix = 0; ix < 9; ix++) {
grainPositions.push([
(ix - 4) * 0.22 + (random() - 0.5) * 0.018,
1.83 + (iy - 4) * 0.22 + (random() - 0.5) * 0.018,
0.205
]);
const color = new THREE.Color();
color.setHSL(
0.105 + (random() - 0.5) * 0.025,
0.34 + random() * 0.14,
0.52 + random() * 0.16
);
grainColors.push(color);
}
}
voxelMesh(ceramicMicroRoot, grainPositions, 0.202, 0.202, 0.095, grainMaterial, grainColors);
[
[-0.38, 2.17], [0.36, 1.72], [-0.13, 1.35], [0.55, 2.42]
].forEach(([x, y]) => {
box(ceramicMicroRoot, 0.105, 0.105, 0.045, x, y, 0.27, materials.void);
});
const microCeramicPore = register(new THREE.Group(), {
materialClass: "ceramic",
content: "defect",
isDefect: true,
info: {
eyebrow: "Surface defect / Ceramic",
title: "Micro-pore cluster",
body: "The pore cluster is a stress concentrator in a crystalline body. Its effect depends on whether it is surface-connected, whether it intersects a grain boundary, and whether the local stress is tensile.",
class: "Pore cluster",
load: "Tensile / shear",
driver: "Reduced section"
}
});
microCeramicPore.position.set(-0.6, 2.17, -0.08);
scene.add(microCeramicPore);
box(microCeramicPore, 0.11, 0.11, 0.08, 0, 0, 0, materials.defect);
box(microCeramicPore, 0.07, 0.07, 0.07, 0.12, 0.09, 0, materials.defect);
box(microCeramicPore, 0.07, 0.07, 0.07, 0.10, -0.10, 0, materials.defect);
/* --------------------------------------------------------------------------
03 — Structural insets
--------------------------------------------------------------------------- */
const glassPaneRoot = register(new THREE.Group(), {
materialClass: "glass",
content: "structure",
load: "bending",
info: {
eyebrow: "Structural inset / Glass pane",
title: "Framed panel in bending",
body: "A framed glass panel may look continuous, but it is still a brittle, flaw-sensitive system. Bending stretches one face while compressing the other, so the tensile face and its edge quality control initiation.",
class: "Glass laminate",
load: "Out-of-plane bending",
driver: "Tensile-face flaw"
}
});
glassPaneRoot.position.set(1.77, 0, -0.82);
scene.add(glassPaneRoot);
platform(glassPaneRoot, 0, 0, 2.85, 1.75);
const paneVoxels = [];
for (let iy = -4; iy <= 4; iy++) {
for (let ix = -3; ix <= 3; ix++) {
paneVoxels.push([ix * 0.34, 2.08 + iy * 0.31, 0]);
}
}
voxelMesh(glassPaneRoot, paneVoxels, 0.316, 0.286, 0.17, materials.glass);
box(glassPaneRoot, 0.16, 3.28, 0.30, -1.28, 2.08, 0, materials.metal, true);
box(glassPaneRoot, 0.16, 3.28, 0.30, 1.28, 2.08, 0, materials.metal, true);
box(glassPaneRoot, 2.72, 0.16, 0.30, 0, 0.52, 0, materials.metal, true);
box(glassPaneRoot, 2.72, 0.16, 0.30, 0, 3.64, 0, materials.metal, true);
box(glassPaneRoot, 0.46, 0.16, 0.65, -0.83, 0.49, 0, materials.metal);
box(glassPaneRoot, 0.46, 0.16, 0.65, 0.83, 0.49, 0, materials.metal);
addArrow(glassPaneRoot, [0, 3.88, 0.05], [0, -1], 0.62);
const paneChip = register(new THREE.Group(), {
materialClass: "glass",
content: "defect",
isDefect: true,
info: {
eyebrow: "Structural flaw / Glass",
title: "Frame-adjacent chip",
body: "A defect close to a frame or contact point is consequential because the frame can constrain local deformation. The red marker identifies a sharp edge flaw rather than the load itself.",
class: "Edge chip",
load: "Bending tension",
driver: "Constraint + flaw"
}
});
paneChip.position.set(3.02, 2.52, -0.64);
scene.add(paneChip);
box(paneChip, 0.14, 0.11, 0.11, 0, 0, 0, materials.defect);
box(paneChip, 0.08, 0.08, 0.08, 0.12, 0.09, 0.02, materials.defect);
box(paneChip, 0.08, 0.08, 0.08, 0.10, -0.10, 0.02, materials.defect);
const ceramicLinerRoot = register(new THREE.Group(), {
materialClass: "ceramic",
content: "structure",
load: "compression",
info: {
eyebrow: "Structural inset / Technical ceramic",
title: "Ceramic liner in compression",
body: "The ceramic liner is loaded mainly in compression. Grain structure and bearing area matter, but a large pore can still trigger local shear even though the gross compressive stress is favorable.",
class: "Technical ceramic",
load: "Compressive bearing",
driver: "Pore-assisted shear"
}
});
ceramicLinerRoot.position.set(4.48, 0, 0.43);
scene.add(ceramicLinerRoot);
platform(ceramicLinerRoot, 0, 0, 2.65, 1.8);
box(ceramicLinerRoot, 2.36, 2.36, 0.22, 0, 1.9, 0, materials.metal, true);
box(ceramicLinerRoot, 2.12, 2.12, 0.055, 0, 1.9, 0.135, materials.darker);
const linerPositions = [];
const linerColors = [];
for (let iy = 0; iy < 8; iy++) {
for (let ix = 0; ix < 8; ix++) {
linerPositions.push([
(ix - 3.5) * 0.255,
1.9 + (iy - 3.5) * 0.255,
0.205
]);
const color = new THREE.Color();
color.setHSL(0.105, 0.36, 0.55 + random() * 0.14);
linerColors.push(color);
}
}
voxelMesh(ceramicLinerRoot, linerPositions, 0.235, 0.235, 0.12, grainMaterial, linerColors);
[-0.94, 0.94].forEach((x) => {
[-0.94, 0.94].forEach((y) => {
box(ceramicLinerRoot, 0.17, 0.17, 0.15, x, 1.9 + y, 0.30, materials.metal, true);
});
});
addArrow(ceramicLinerRoot, [0, 3.37, 0.08], [0, -1], 0.55);
addArrow(ceramicLinerRoot, [0, 0.45, 0.08], [0, 1], 0.35);
const linerPore = register(new THREE.Group(), {
materialClass: "ceramic",
content: "defect",
isDefect: true,
info: {
eyebrow: "Structural defect / Ceramic",
title: "Bearing-side pore",
body: "The pore reduces the local load-carrying area and can distort stress around its rim. Under compression, a flaw often activates in shear rather than opening in Mode I.",
class: "Bulk pore",
load: "Local shear",
driver: "Stress concentration"
}
});
linerPore.position.set(4.78, 1.42, 0.70);
scene.add(linerPore);
box(linerPore, 0.13, 0.13, 0.07, 0, 0, 0, materials.void);
box(linerPore, 0.07, 0.07, 0.05, 0.11, 0, 0.01, materials.defect);
box(linerPore, 0.07, 0.07, 0.05, -0.11, 0, 0.01, materials.defect);
box(linerPore, 0.07, 0.07, 0.05, 0, 0.11, 0.01, materials.defect);
box(linerPore, 0.07, 0.07, 0.05, 0, -0.11, 0.01, materials.defect);
/* --------------------------------------------------------------------------
04 — Crack-path atlas
--------------------------------------------------------------------------- */
function makeCoupon(x, materialClass, load, title, subtitle, info) {
const root = register(new THREE.Group(), {
materialClass,
content: "cracks",
load,
info
});
root.position.set(x, 0, 0.58);
scene.add(root);
platform(root, 0, 0, 1.65, 1.45);
box(root, 0.28, 0.52, 0.25, 0, 0.52, 0, materials.metal);
box(root, 1.38, 2.08, 0.18, 0, 1.68, 0, materials.darker, true);
const specimenPositions = [];
const columnCount = materialClass === "glass" ? 5 : 6;
const rowCount = 7;
for (let iy = 0; iy < rowCount; iy++) {
for (let ix = 0; ix < columnCount; ix++) {
specimenPositions.push([
(ix - (columnCount - 1) / 2) * 0.235,
1.68 + (iy - (rowCount - 1) / 2) * 0.235,
0.13
]);
}
}
voxelMesh(
root,
specimenPositions,
0.215,
0.215,
materialClass === "glass" ? 0.12 : 0.16,
materialClass === "glass" ? materials.glass : materials.ceramic
);
const borderMaterial = materialClass === "glass"
? materials.glassBright
: materials.ceramicLight;
box(root, 1.43, 0.06, 0.12, 0, 0.67, 0.18, borderMaterial);
box(root, 1.43, 0.06, 0.12, 0, 2.69, 0.18, borderMaterial);
box(root, 0.06, 2.08, 0.12, -0.71, 1.68, 0.18, borderMaterial);
box(root, 0.06, 2.08, 0.12, 0.71, 1.68, 0.18, borderMaterial);
const focusMaterial = new THREE.MeshStandardMaterial({
color: 0xffd879,
emissive: 0x6d3b06,
emissiveIntensity: 0.8,
transparent: true,
opacity: 0.9
});
const focusFrame = new THREE.Group();
focusFrame.visible = false;
root.add(focusFrame);
box(focusFrame, 1.56, 0.055, 0.08, 0, 3.04, 0.27, focusMaterial);
box(focusFrame, 1.56, 0.055, 0.08, 0, 0.30, 0.27, focusMaterial);
box(focusFrame, 0.055, 2.80, 0.08, -0.78, 1.67, 0.27, focusMaterial);
box(focusFrame, 0.055, 2.80, 0.08, 0.78, 1.67, 0.27, focusMaterial);
root.userData.focusFrame = focusFrame;
addWorldLabel(
[x, 3.22, 0.58],
title,
subtitle,
materialClass,
root,
true
);
return root;
}
const tensionCoupon = makeCoupon(
6.25,
"glass",
"tension",
"Glass / Tension",
"edge flaw → branched Mode I",
{
eyebrow: "Case 01 / Glass",
title: "Tension + edge chip",
body: "An amorphous silica network has no grain boundaries. A sharp surface chip concentrates tensile stress and becomes the origin of a fast-running crack.",
class: "Amorphous network",
load: "Mode I tension",
driver: "Edge flaw"
}
);
addArrow(tensionCoupon, [-1.16, 1.68, 0.34], [-1, 0], 0.58);
addArrow(tensionCoupon, [1.16, 1.68, 0.34], [1, 0], 0.58);
box(tensionCoupon, 0.13, 0.13, 0.08, -0.68, 1.67, 0.31, materials.defect);
voxelPath(tensionCoupon, [
[-0.67, 1.67],
[-0.46, 1.73],
[-0.26, 1.62],
[-0.06, 1.75],
[0.16, 1.68],
[0.37, 1.83],
[0.66, 1.78]
]);
voxelPath(tensionCoupon, [
[-0.08, 1.74],
[0.10, 1.98],
[0.32, 2.06]
], 0.36, 0.066);
const compressionCoupon = makeCoupon(
8.08,
"ceramic",
"compression",
"Ceramic / Compression",
"pore → local shear kink",
{
eyebrow: "Case 02 / Ceramic",
title: "Compression can still cause shear",
body: "Grain boundaries and pores govern local behavior. Compression often closes pre-existing cracks, but a large pore can nucleate a diagonal shear path despite a favorable gross load.",
class: "Polycrystalline",
load: "Compression + shear",
driver: "Pore / grain boundary"
}
);
addArrow(compressionCoupon, [0, 3.10, 0.34], [0, -1], 0.57);
addArrow(compressionCoupon, [0, 0.28, 0.34], [0, 1], 0.25);
box(compressionCoupon, 0.14, 0.14, 0.08, 0.02, 1.67, 0.31, materials.void);
voxelPath(compressionCoupon, [
[-0.31, 1.22],
[-0.15, 1.40],
[0.02, 1.67],
[0.13, 1.83],
[0.34, 2.08]
]);
voxelPath(compressionCoupon, [
[-0.02, 1.67],
[-0.28, 1.83],
[-0.42, 2.01]
], 0.36, 0.062);
const bendingCoupon = makeCoupon(
9.91,
"ceramic",
"bending",
"Ceramic / Bending",
"tensile face opens pore",
{
eyebrow: "Case 03 / Ceramic",
title: "Bending separates tension from compression",
body: "The lower tensile face opens a surface-connected pore while the upper compressive face remains comparatively intact. Failure therefore depends on which side of the specimen is actually in tension.",
class: "Polycrystalline",
load: "Three-point bending",
driver: "Tensile-face pore"
}
);
addArrow(bendingCoupon, [0, 3.12, 0.34], [0, -1], 0.58);
box(bendingCoupon, 0.34, 0.16, 0.42, -0.47, 0.68, 0.02, materials.metal);
box(bendingCoupon, 0.34, 0.16, 0.42, 0.47, 0.68, 0.02, materials.metal);
box(bendingCoupon, 0.13, 0.13, 0.08, 0, 0.80, 0.31, materials.void);
voxelPath(bendingCoupon, [
[0, 0.79],
[-0.09, 1.02],
[0.04, 1.23],
[-0.07, 1.46],
[0.10, 1.70],
[0.05, 1.98]
]);
voxelPath(bendingCoupon, [
[-0.04, 1.25],
[-0.28, 1.39],
[-0.42, 1.58]
], 0.36, 0.062);
/* --------------------------------------------------------------------------
World labels
--------------------------------------------------------------------------- */
addWorldLabel(
[-6.05, 3.08, 0.1],
"01 / Everyday",
"glass tumbler · ceramic mug",
"glass"
);
addWorldLabel(
[-1.45, 3.43, -0.25],
"02 / Microstructure",
"amorphous network · grain mosaic",
"glass"
);
addWorldLabel(
[3.08, 4.05, -0.42],
"03 / Structural insets",
"framed pane · compression liner",
"ceramic"
);
addWorldLabel(
[8.05, 3.72, 0.62],
"04 / Crack-path atlas",
"same class of brittleness, different initiation",
"ceramic"
);
/* --------------------------------------------------------------------------
Readout, filtering and interaction
--------------------------------------------------------------------------- */
const readout = {
eyebrow: document.querySelector("#readoutEyebrow"),
title: document.querySelector("#readoutTitle"),
body: document.querySelector("#readoutBody"),
class: document.querySelector("#factClass"),
load: document.querySelector("#factLoad"),
driver: document.querySelector("#factDriver")
};
const viewButtons = [...document.querySelectorAll("#viewButtons button")];
const loadButtons = [...document.querySelectorAll("#loadButtons button")];
const state = {
view: "all",
load: "all"
};
function updateReadout(info) {
readout.eyebrow.textContent = info.eyebrow;
readout.title.textContent = info.title;
readout.body.textContent = info.body;
readout.class.textContent = info.class;
readout.load.textContent = info.load;
readout.driver.textContent = info.driver;
}
function applyFilter() {
for (const root of roots) {
const data = root.userData;
let visible = true;
if (state.view === "glass") {
visible = data.materialClass === "glass";
} else if (state.view === "ceramic") {
visible = data.materialClass === "ceramic";
} else if (state.view === "defects") {
visible = Boolean(data.isDefect);
} else if (state.view === "cracks") {
visible = data.content === "cracks";
}
if (
state.load !== "all" &&
data.content === "cracks" &&
data.load !== state.load
) {
visible = false;
}
root.visible = visible;
if (data.focusFrame) {
data.focusFrame.visible =
state.load !== "all" &&
data.load === state.load &&
(state.view === "all" || state.view === "cracks");
}
}
}
function syncButtons() {
viewButtons.forEach(button => {
button.classList.toggle("active", button.dataset.view === state.view);
});
loadButtons.forEach(button => {
button.classList.toggle("active", button.dataset.load === state.load);
});
}
viewButtons.forEach(button => {
button.addEventListener("click", () => {
state.view = button.dataset.view;
if (state.view !== "all" && state.view !== "cracks") {
state.load = "all";
}
applyFilter();
syncButtons();
});
});
loadButtons.forEach(button => {
button.addEventListener("click", () => {
state.load = button.dataset.load;
state.view = "all";
if (state.load === "tension") {
updateReadout(tensionCoupon.userData.info);
} else if (state.load === "compression") {
updateReadout(compressionCoupon.userData.info);
} else if (state.load === "bending") {
updateReadout(bendingCoupon.userData.info);
} else {
updateReadout(tensionCoupon.userData.info);
}
applyFilter();
syncButtons();
});
});
const raycaster = new THREE.Raycaster();
const normalizedPointer = new THREE.Vector2();
function inspectAt(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
normalizedPointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
normalizedPointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(normalizedPointer, camera);
const visibleRoots = interactiveRoots.filter(root => root.visible);
const hits = raycaster.intersectObjects(visibleRoots, true);
if (!hits.length) return;
let object = hits[0].object;
while (object && !object.userData.info) {
object = object.parent;
}
if (object?.userData?.info) {
updateReadout(object.userData.info);
}
}
applyFilter();
syncButtons();
updateReadout(tensionCoupon.userData.info);
/* --------------------------------------------------------------------------
Resize and render loop
--------------------------------------------------------------------------- */
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
fitCameraToViewport();
updateCamera();
}
window.addEventListener("resize", onResize);
onResize();
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const entry of labelEntries) {
const followedRootHidden = entry.follow && !entry.follow.visible;
projected.copy(entry.position).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.05 &&
projected.y < 1.05;
entry.element.style.opacity = onScreen && !followedRootHidden ? "1" : "0";
if (onScreen && !followedRootHidden) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
entry.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -50%)`;
}
}
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```