Prompt specification
Build or customize the Three.js 3D scene "Effervescent tablet surface-area analogy 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: Effervescent tablet surface-area analogy exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/effervescent-tablet-surface-area-analogy-exhibit-x1991
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: effervescent tablet surface-area analogy exhibit. Compose whole and fragmented inert tablet models beside a qualitative reaction-area display; label the demonstration conceptual and avoid prescribing any experimental chemical procedure.
Working Three.js Starter (effervescent-tablet-surface-area-analogy-exhibit-x1991):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#07110f">
<title>Effervescent Surface-Area Analogy — Conceptual Exhibit</title>
<style>
:root {
color-scheme: dark;
--ink: #edf8f4;
--muted: #9db5ae;
--line: rgba(182, 231, 216, 0.18);
--panel: rgba(9, 27, 24, 0.76);
--amber: #ffc879;
--mint: #66efd0;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07110f;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
body {
overscroll-behavior: none;
}
#viewport,
#labels {
position: fixed;
inset: 0;
}
#viewport {
z-index: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
canvas:focus-visible {
outline: 2px solid var(--mint);
outline-offset: -4px;
}
#labels {
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
min-width: 130px;
padding: 9px 11px 10px;
transform: translate(-50%, -100%);
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(6, 22, 19, 0.82);
box-shadow: 0 12px 34px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(9px);
-webkit-backdrop-filter: blur(9px);
text-align: center;
white-space: nowrap;
opacity: 0;
transition: opacity 180ms ease;
}
.scene-label.visible {
opacity: 1;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 15px;
background: linear-gradient(var(--line), transparent);
}
.scene-label strong,
.scene-label small,
.scene-label span {
display: block;
}
.scene-label strong {
margin-top: 2px;
font-size: 14px;
letter-spacing: 0.02em;
}
.scene-label small {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.02em;
}
.label-kicker {
color: var(--mint);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.panel-mini-label {
min-width: 100px;
padding: 6px 9px;
border-color: rgba(182, 231, 216, 0.12);
background: rgba(5, 18, 16, 0.72);
}
.panel-mini-label strong {
font-size: 10px;
letter-spacing: 0.15em;
}
.panel-mini-label small {
font-size: 9px;
}
.panel-foot-label {
min-width: 270px;
background: rgba(6, 22, 19, 0.68);
}
.intro {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 19px 17px;
border: 1px solid var(--line);
border-radius: 16px;
background:
linear-gradient(135deg, rgba(16, 48, 41, 0.9), rgba(7, 24, 21, 0.8));
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--mint);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 2px;
background: var(--mint);
box-shadow: 0 0 12px rgba(102, 239, 208, 0.5);
}
h1 {
margin: 11px 0 9px;
font-size: clamp(25px, 3.1vw, 40px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 730;
}
h1 span {
color: #a9c8bf;
font-weight: 520;
}
.intro p {
margin: 0;
color: #bdd0ca;
font-size: 12px;
line-height: 1.55;
}
.concept-strip {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 7px 9px;
border: 1px solid rgba(255, 200, 121, 0.25);
border-radius: 7px;
color: #ffe0ae;
background: rgba(255, 200, 121, 0.07);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.concept-strip::before {
content: "";
width: 6px;
height: 6px;
border-radius: 1px;
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 200, 121, 0.5);
}
.controls {
position: fixed;
z-index: 12;
top: 22px;
right: 22px;
display: flex;
align-items: center;
gap: 9px;
}
.control-hint {
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(7, 25, 22, 0.7);
color: var(--muted);
font-size: 9px;
line-height: 1.35;
letter-spacing: 0.04em;
text-align: right;
backdrop-filter: blur(10px);
}
button {
appearance: none;
border: 1px solid rgba(102, 239, 208, 0.32);
border-radius: 9px;
padding: 10px 12px;
color: #dffbf3;
background: rgba(13, 47, 39, 0.82);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
cursor: pointer;
backdrop-filter: blur(10px);
}
button:hover {
border-color: rgba(102, 239, 208, 0.72);
background: rgba(18, 65, 53, 0.9);
}
button:focus-visible {
outline: 2px solid var(--mint);
outline-offset: 2px;
}
.legend {
position: fixed;
z-index: 10;
right: 22px;
bottom: 66px;
width: 225px;
padding: 12px 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(7, 25, 22, 0.72);
color: var(--muted);
font-size: 9px;
line-height: 1.45;
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin: 5px 0;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
flex: 0 0 auto;
}
.swatch.amber {
background: var(--amber);
box-shadow: 0 0 9px rgba(255, 200, 121, 0.5);
}
.swatch.mint {
background: var(--mint);
box-shadow: 0 0 9px rgba(102, 239, 208, 0.5);
}
.legend strong {
color: #d8ebe5;
}
footer {
position: fixed;
z-index: 10;
left: 22px;
right: 22px;
bottom: 16px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 10px 13px;
border-top: 1px solid var(--line);
color: #91aaa2;
background: linear-gradient(90deg, rgba(7, 17, 15, 0.92), rgba(7, 17, 15, 0.42));
font-size: 9px;
line-height: 1.4;
letter-spacing: 0.035em;
pointer-events: none;
}
footer strong {
color: #cce2da;
font-weight: 700;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: var(--mint);
background: #07110f;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 720px) {
.intro {
top: 12px;
left: 12px;
width: min(315px, calc(100vw - 24px));
padding: 14px 15px;
}
h1 {
font-size: 25px;
}
.intro p {
display: none;
}
.concept-strip {
margin-top: 10px;
font-size: 8px;
}
.controls {
top: auto;
right: 12px;
bottom: 66px;
}
.control-hint {
display: none;
}
.legend {
right: 12px;
bottom: 112px;
width: 195px;
}
footer {
left: 12px;
right: 12px;
bottom: 10px;
}
footer span:last-child {
display: none;
}
.scene-label {
min-width: 104px;
padding: 7px 8px;
}
.scene-label strong {
font-size: 11px;
}
.scene-label small {
font-size: 8px;
}
.label-kicker {
font-size: 7px;
}
.panel-foot-label {
min-width: 200px;
}
}
@media (prefers-reduced-motion: reduce) {
.scene-label {
transition: none;
}
}
</style>
</head>
<body>
<main id="viewport" aria-label="Interactive conceptual voxel exhibit"></main>
<div id="labels" aria-hidden="true"></div>
<section class="intro">
<div class="eyebrow">Conceptual exhibit · 01</div>
<h1>Effervescent<br><span>surface-area analogy</span></h1>
<p>
Inert voxel forms compare one connected tablet with the same general
form divided into pieces. Additional boundaries visually suggest
greater exposed surface.
</p>
<div class="concept-strip">Conceptual demonstration · not a procedure</div>
</section>
<div class="controls">
<div class="control-hint">
Drag to orbit · wheel/pinch to zoom<br>
Shift-drag/right-drag to pan
</div>
<button id="resetView" type="button">Reset view</button>
</div>
<aside class="legend" aria-label="Display legend">
<strong>Qualitative display</strong>
<div class="legend-row">
<span class="swatch amber"></span>
<span>Outer boundary of the whole form</span>
</div>
<div class="legend-row">
<span class="swatch mint"></span>
<span>Outer plus newly exposed internal boundaries</span>
</div>
<div style="margin-top:8px;color:#718b83">
Brighter is qualitative; no numerical scale, rate, or yield is implied.
</div>
</aside>
<footer>
<span>
<strong>Schematic only.</strong>
Models contain no active substance. No reactants, quantities, timing,
or experimental procedure are shown.
</span>
<span>Inert models · relative surface exposure · not to scale</span>
</footer>
<div id="loading">Loading conceptual exhibit…</div>
<p id="sceneDescription" class="sr-only">
A dark interactive Three.js exhibit containing a whole voxel tablet,
an identical-looking tablet divided into separate voxel pieces, and a
qualitative panel comparing outer and internal exposed boundaries.
</p>
<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 labelLayer = document.getElementById("labels");
const resetButton = document.getElementById("resetView");
const loading = document.getElementById("loading");
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.8));
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.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional conceptual tablet surface-area exhibit"
);
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07110f);
scene.fog = new THREE.FogExp2(0x07110f, 0.032);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
// Desired and current values provide damping without using an addon.
const home = {
radius: 15.3,
theta: 0.34,
phi: 1.12,
target: new THREE.Vector3(0.42, 1.62, 0)
};
const desired = {
radius: home.radius,
theta: home.theta,
phi: home.phi,
target: home.target.clone()
};
const current = {
radius: home.radius,
theta: home.theta,
phi: home.phi,
target: home.target.clone()
};
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);
}
applyCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc7fff0, 0x101615, 1.35));
const keyLight = new THREE.DirectionalLight(0xfff0d5, 3.2);
keyLight.position.set(-5.5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const amberLight = new THREE.PointLight(0xffb95e, 18, 7, 2);
amberLight.position.set(-3.3, 2.6, 2.4);
scene.add(amberLight);
const mintLight = new THREE.PointLight(0x50e9c5, 22, 7, 2);
mintLight.position.set(-0.1, 2.4, 2.3);
scene.add(mintLight);
const panelLight = new THREE.PointLight(0x8dffe5, 12, 8, 2);
panelLight.position.set(4.1, 3.6, 2.2);
scene.add(panelLight);
// -------------------------------------------------------------------------
// Stage
// -------------------------------------------------------------------------
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0a1715,
roughness: 0.92,
metalness: 0.08
});
const floor = new THREE.Mesh(
new THREE.BoxGeometry(25, 0.18, 18),
floorMaterial
);
floor.position.set(0, -0.09, 0);
floor.receiveShadow = true;
scene.add(floor);
const backWall = new THREE.Mesh(
new THREE.BoxGeometry(25, 8, 0.18),
new THREE.MeshStandardMaterial({
color: 0x081512,
roughness: 1,
metalness: 0
})
);
backWall.position.set(0, 3.85, -4.25);
backWall.receiveShadow = true;
scene.add(backWall);
const grid = new THREE.GridHelper(24, 48, 0x285047, 0x14322c);
grid.position.y = 0.015;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
function addOutlinedBox(
width,
height,
depth,
x,
y,
z,
material,
edgeColor = 0x36564d,
edgeOpacity = 0.55
) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color: edgeColor,
transparent: true,
opacity: edgeOpacity
})
);
edges.position.copy(mesh.position);
scene.add(edges);
return mesh;
}
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x10231f,
roughness: 0.76,
metalness: 0.16
});
const platformTopMaterial = new THREE.MeshStandardMaterial({
color: 0x142c27,
roughness: 0.7,
metalness: 0.12
});
function addPlatform(x, width = 3.08, depth = 2.68) {
addOutlinedBox(
width,
0.18,
depth,
x,
0.09,
0.28,
platformMaterial,
0x3e6258,
0.6
);
addOutlinedBox(
width - 0.13,
0.035,
depth - 0.13,
x,
0.195,
0.28,
platformTopMaterial,
0x466e63,
0.38
);
}
addPlatform(-3.18);
addPlatform(-0.02);
// Small pixel markers reinforce the voxel-exhibit language.
const markerGeometry = new THREE.BoxGeometry(0.08, 0.025, 0.08);
const amberMarkerMaterial = new THREE.MeshStandardMaterial({
color: 0xffc879,
emissive: 0xff9f3e,
emissiveIntensity: 0.55
});
const mintMarkerMaterial = new THREE.MeshStandardMaterial({
color: 0x66efd0,
emissive: 0x2ed9b5,
emissiveIntensity: 0.6
});
for (let i = 0; i < 6; i++) {
const marker = new THREE.Mesh(
markerGeometry,
i < 3 ? amberMarkerMaterial : mintMarkerMaterial
);
marker.position.set(-4.45 + i * 0.15, 0.23, -0.72);
scene.add(marker);
}
// -------------------------------------------------------------------------
// Voxel tablet geometry
// -------------------------------------------------------------------------
const voxelSize = 0.096;
const voxelStep = 0.103;
const layerStep = 0.09;
const diskRadius = 9.55;
function fragmentGroup(ix, iz) {
let angle = Math.atan2(iz, ix);
if (angle < 0) angle += Math.PI * 2;
return Math.min(4, Math.floor((angle / (Math.PI * 2)) * 5));
}
function hashNoise(value) {
const x = Math.sin(value * 12.9898) * 43758.5453123;
return x - Math.floor(x);
}
function collectVoxels() {
const records = [];
for (let ix = -10; ix <= 10; ix++) {
for (let iz = -10; iz <= 10; iz++) {
if (Math.hypot(ix, iz) > diskRadius) continue;
for (let layer = 0; layer < 3; layer++) {
records.push({
x: ix * voxelStep,
y: layer * layerStep,
z: iz * voxelStep,
ix,
iz,
layer,
group: fragmentGroup(ix, iz)
});
}
}
}
return records;
}
const voxelRecords = collectVoxels();
const voxelGeometry = new THREE.BoxGeometry(
voxelSize,
voxelSize,
voxelSize
);
const voxelMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.7,
metalness: 0.03
});
const dummy = new THREE.Object3D();
const ivory = new THREE.Color(0xe9e4cf);
const ivoryCool = new THREE.Color(0xd4ded3);
const ivoryWarm = new THREE.Color(0xf1e5c5);
const scoreColor = new THREE.Color(0x76a89c);
const fleckColor = new THREE.Color(0x74bbaa);
function voxelColor(record, index) {
const noise = hashNoise(index + record.ix * 7.1 + record.iz * 11.7);
const color = ivory.clone();
if (noise > 0.72) {
color.lerp(ivoryCool, 0.35);
} else if (noise < 0.2) {
color.lerp(ivoryWarm, 0.5);
}
if (record.layer === 2 && record.ix === 0) {
color.lerp(scoreColor, 0.72);
} else if (record.layer === 2 && noise > 0.975) {
color.lerp(fleckColor, 0.78);
}
return color;
}
function createVoxelMesh(records, offset = new THREE.Vector3()) {
const mesh = new THREE.InstancedMesh(
voxelGeometry,
voxelMaterial,
records.length
);
mesh.castShadow = true;
mesh.receiveShadow = true;
records.forEach((record, index) => {
dummy.position.set(
record.x + offset.x,
record.y + offset.y,
record.z + offset.z
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, voxelColor(record, index));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
return mesh;
}
// One connected tablet.
const wholeTablet = new THREE.Group();
wholeTablet.position.set(-3.18, 0.255, 0.28);
wholeTablet.add(createVoxelMesh(voxelRecords));
scene.add(wholeTablet);
// The same voxel population divided into five separated pieces.
const fragmentedTablet = new THREE.Group();
fragmentedTablet.position.set(-0.02, 0.255, 0.28);
for (let group = 0; group < 5; group++) {
const records = voxelRecords.filter((record) => record.group === group);
const centerAngle = ((group + 0.5) / 5) * Math.PI * 2;
const offset = new THREE.Vector3(
Math.cos(centerAngle) * 0.47,
(group % 2) * 0.012,
Math.sin(centerAngle) * 0.47
);
fragmentedTablet.add(createVoxelMesh(records, offset));
}
scene.add(fragmentedTablet);
// -------------------------------------------------------------------------
// Qualitative reaction-area display
// -------------------------------------------------------------------------
const panelX = 3.76;
const panelY = 2.68;
const panelZ = -0.82;
const panelWidth = 4.48;
const panelHeight = 3.72;
addOutlinedBox(
panelWidth,
panelHeight,
0.17,
panelX,
panelY,
panelZ,
new THREE.MeshStandardMaterial({
color: 0x0b1d1a,
roughness: 0.68,
metalness: 0.25
}),
0x4c8d7e,
0.65
);
addOutlinedBox(
0.48,
0.9,
0.44,
panelX,
0.46,
panelZ - 0.06,
platformMaterial,
0x3e6258,
0.5
);
addOutlinedBox(
2.1,
0.12,
0.92,
panelX,
0.08,
panelZ - 0.06,
platformMaterial,
0x3e6258,
0.5
);
const separator = new THREE.Mesh(
new THREE.BoxGeometry(0.018, 2.58, 0.018),
new THREE.MeshStandardMaterial({
color: 0x36584f,
emissive: 0x17362e,
emissiveIntensity: 0.45
})
);
separator.position.set(panelX, 2.47, panelZ + 0.103);
scene.add(separator);
const tileGeometry = new THREE.BoxGeometry(0.064, 0.064, 0.018);
const tileZ = panelZ + 0.104;
const wholeBrightMaterial = new THREE.MeshStandardMaterial({
color: 0xffca78,
emissive: 0xff9b3f,
emissiveIntensity: 0.95,
roughness: 0.46,
metalness: 0.05
});
const wholeDimMaterial = new THREE.MeshStandardMaterial({
color: 0x4b4334,
emissive: 0x241b10,
emissiveIntensity: 0.2,
roughness: 0.84
});
const fragmentedBrightMaterial = new THREE.MeshStandardMaterial({
color: 0x66efd0,
emissive: 0x28d8b2,
emissiveIntensity: 1.05,
roughness: 0.44,
metalness: 0.05
});
const fragmentedDimMaterial = new THREE.MeshStandardMaterial({
color: 0x1b3c35,
emissive: 0x0a2821,
emissiveIntensity: 0.3,
roughness: 0.84
});
function createTileSet(records, material) {
const mesh = new THREE.InstancedMesh(
tileGeometry,
material,
records.length
);
records.forEach((record, index) => {
dummy.position.set(record.x, record.y, tileZ);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
scene.add(mesh);
return mesh;
}
function buildComparisonGrid(centerX, fragmented = false) {
const bright = [];
const dim = [];
const radius = 8.25;
const gridCenterY = 2.48;
const inside = (x, z) => Math.hypot(x, z) <= radius;
for (let ix = -9; ix <= 9; ix++) {
for (let iz = -9; iz <= 9; iz++) {
if (!inside(ix, iz)) continue;
const record = {
x: centerX + ix * 0.082,
y: gridCenterY + iz * 0.082
};
const neighbors = [
[ix + 1, iz],
[ix - 1, iz],
[ix, iz + 1],
[ix, iz - 1]
];
const hasOuterBoundary = neighbors.some(
([nx, nz]) => !inside(nx, nz)
);
const hasInternalBoundary = neighbors.some(
([nx, nz]) =>
inside(nx, nz) && fragmentGroup(nx, nz) !== fragmentGroup(ix, iz)
);
if (hasOuterBoundary || (fragmented && hasInternalBoundary)) {
bright.push(record);
} else {
dim.push(record);
}
}
}
return { bright, dim };
}
const wholeGrid = buildComparisonGrid(panelX - 1.02);
const fragmentedGrid = buildComparisonGrid(panelX + 1.02, true);
createTileSet(wholeGrid.bright, wholeBrightMaterial);
createTileSet(wholeGrid.dim, wholeDimMaterial);
createTileSet(fragmentedGrid.bright, fragmentedBrightMaterial);
createTileSet(fragmentedGrid.dim, fragmentedDimMaterial);
// -------------------------------------------------------------------------
// Screen-space labels, projected from Three.js world positions
// -------------------------------------------------------------------------
const labels = [];
function addLabel(html, position, extraClass = "") {
const element = document.createElement("div");
element.className = `scene-label ${extraClass}`.trim();
element.innerHTML = html;
labelLayer.appendChild(element);
labels.push({
element,
position: new THREE.Vector3(...position)
});
}
addLabel(
`
<span class="label-kicker">Inert model</span>
<strong>Whole</strong>
<small>one connected form</small>
`,
[-3.18, 1.37, 0.28]
);
addLabel(
`
<span class="label-kicker">Inert model</span>
<strong>Fragmented</strong>
<small>same general form, divided</small>
`,
[-0.02, 1.37, 0.28]
);
addLabel(
`
<span class="label-kicker">Qualitative display</span>
<strong>Reaction-area comparison</strong>
<small>relative exposed boundary</small>
`,
[3.76, 4.86, -0.63]
);
addLabel(
`
<strong>WHOLE</strong>
<small>outer boundary</small>
`,
[2.74, 3.46, -0.61],
"panel-mini-label"
);
addLabel(
`
<strong>FRAGMENTED</strong>
<small>outer + internal boundaries</small>
`,
[4.78, 3.46, -0.61],
"panel-mini-label"
);
addLabel(
`
<small>Brighter = relatively more surface exposed · no numerical scale</small>
`,
[3.76, 1.0, -0.61],
"panel-foot-label"
);
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
if (!visible) {
label.element.classList.remove("visible");
continue;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.classList.add("visible");
}
}
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom, keyboard, and touch
// -------------------------------------------------------------------------
const pointers = new Map();
let pointerMode = "orbit";
let lastPinchDistance = 0;
let lastMidpoint = { x: 0, y: 0 };
const canvas = renderer.domElement;
function pointerDistance() {
const points = [...pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
function pointerMidpoint() {
const points = [...pointers.values()];
if (points.length < 2) return { x: 0, y: 0 };
return {
x: (points[0].x + points[1].x) * 0.5,
y: (points[0].y + points[1].y) * 0.5
};
}
function panCamera(dx, dy) {
const scale = desired.radius * 0.00135;
const right = new THREE.Vector3(
Math.cos(desired.theta),
0,
-Math.sin(desired.theta)
);
desired.target.addScaledVector(right, -dx * scale);
desired.target.y += dy * scale;
desired.target.y = THREE.MathUtils.clamp(
desired.target.y,
0.35,
4.2
);
desired.target.x = THREE.MathUtils.clamp(
desired.target.x,
-5,
6
);
desired.target.z = THREE.MathUtils.clamp(
desired.target.z,
-4,
4
);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.focus({ preventScroll: true });
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
pointerMode =
event.shiftKey || event.button === 2 ? "pan" : "orbit";
} else if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
lastMidpoint = pointerMidpoint();
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size === 1) {
if (pointerMode === "pan") {
panCamera(dx, dy);
} else {
desired.theta -= dx * 0.0056;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.0047,
0.38,
1.46
);
}
} else if (pointers.size >= 2) {
const distance = pointerDistance();
const midpoint = pointerMidpoint();
if (lastPinchDistance > 0 && distance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * (lastPinchDistance / distance),
7,
28
);
}
panCamera(
midpoint.x - lastMidpoint.x,
midpoint.y - lastMidpoint.y
);
lastPinchDistance = distance;
lastMidpoint = midpoint;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
lastPinchDistance = 0;
pointerMode = "orbit";
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
7,
28
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
desired.theta -= 0.09;
break;
case "ArrowRight":
desired.theta += 0.09;
break;
case "ArrowUp":
desired.phi = Math.max(0.38, desired.phi - 0.07);
break;
case "ArrowDown":
desired.phi = Math.min(1.46, desired.phi + 0.07);
break;
case "+":
case "=":
desired.radius = Math.max(7, desired.radius - 0.8);
break;
case "-":
case "_":
desired.radius = Math.min(28, desired.radius + 0.8);
break;
case "Home":
resetView();
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
function resetView() {
desired.radius = home.radius;
desired.theta = home.theta;
desired.phi = home.phi;
desired.target.copy(home.target);
}
resetButton.addEventListener("click", resetView);
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const portrait = width / height < 0.85;
camera.aspect = width / height;
camera.fov = portrait ? 48 : 38;
camera.updateProjectionMatrix();
renderer.setPixelRatio(
Math.min(window.devicePixelRatio || 1, portrait ? 1.5 : 1.8)
);
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
let firstFrame = true;
function animate(time) {
requestAnimationFrame(animate);
const damping = reducedMotion ? 1 : 0.105;
current.radius +=
(desired.radius - current.radius) * damping;
current.theta +=
(desired.theta - current.theta) * damping;
current.phi +=
(desired.phi - current.phi) * damping;
current.target.lerp(desired.target, damping);
applyCamera();
if (!reducedMotion) {
const pulse = 1 + Math.sin(time * 0.00125) * 0.08;
wholeBrightMaterial.emissiveIntensity = 0.92 * pulse;
fragmentedBrightMaterial.emissiveIntensity = 1.02 * pulse;
}
renderer.render(scene, camera);
updateLabels();
if (firstFrame) {
firstFrame = false;
loading.remove();
}
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```