Prompt specification
Build or customize the Three.js 3D scene "Molecular shape and fit 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: Molecular shape and fit exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/molecular-shape-and-fit-exhibit-x1963
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: molecular shape and fit exhibit. Compose a set of schematic molecular models beside matching geometric cavities; label the fit analogy illustrative rather than a complete account of chemical recognition. Return one self-contained HTML file.
Working Three.js Starter (molecular-shape-and-fit-exhibit-x1963):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="An interactive voxel exhibit illustrating molecular shape and geometric fit."
/>
<title>Molecular Form & Fit — Voxel Exhibit</title>
<style>
:root {
--ink: #253139;
--muted: #65716f;
--paper: #f6f3eb;
--line: rgba(37, 49, 57, 0.16);
--accent: #df6b59;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e5e9e3;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.masthead {
position: absolute;
top: 28px;
left: 30px;
max-width: 440px;
}
.kicker {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #65716f;
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.kicker::before {
width: 24px;
height: 3px;
content: "";
background: var(--accent);
}
h1 {
margin: 0;
font-size: clamp(30px, 4.1vw, 60px);
font-weight: 780;
line-height: 0.94;
letter-spacing: -0.055em;
text-transform: uppercase;
}
.subtitle {
margin: 13px 0 0;
max-width: 390px;
color: #566361;
font-size: 14px;
line-height: 1.5;
}
.disclaimer {
position: absolute;
top: 28px;
right: 30px;
width: min(390px, calc(100vw - 60px));
padding: 15px 17px 16px;
border: 1px solid rgba(37, 49, 57, 0.14);
border-left: 4px solid var(--accent);
border-radius: 10px;
background: rgba(248, 246, 239, 0.9);
box-shadow: 0 10px 30px rgba(49, 60, 58, 0.08);
backdrop-filter: blur(10px);
}
.disclaimer strong {
display: block;
margin-bottom: 5px;
font: 800 11px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.disclaimer p {
margin: 0;
color: #5d6866;
font-size: 12px;
line-height: 1.45;
}
.legend {
position: absolute;
left: 30px;
bottom: 30px;
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
max-width: 420px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(248, 246, 239, 0.82);
backdrop-filter: blur(8px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #5c6866;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
}
.swatch {
width: 10px;
height: 10px;
border: 1px solid rgba(0, 0, 0, 0.14);
border-radius: 2px;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.info-card {
position: absolute;
right: 30px;
bottom: 30px;
width: min(360px, calc(100vw - 60px));
padding: 18px 19px 17px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(248, 246, 239, 0.92);
box-shadow: 0 14px 38px rgba(49, 60, 58, 0.1);
backdrop-filter: blur(10px);
}
.info-topline {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
color: #697472;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.info-card h2 {
margin: 0 0 7px;
font-size: 24px;
letter-spacing: -0.025em;
}
.info-card p {
margin: 0;
color: #596562;
font-size: 13px;
line-height: 1.5;
}
.info-card .analogy-note {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #7a6257;
font-size: 11px;
}
.controls {
position: absolute;
bottom: 30px;
left: 50%;
display: flex;
align-items: center;
gap: 12px;
transform: translateX(-50%);
pointer-events: auto;
}
.controls span {
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(248, 246, 239, 0.75);
color: #697472;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.09em;
white-space: nowrap;
}
button {
padding: 10px 13px;
border: 1px solid rgba(37, 49, 57, 0.2);
border-radius: 7px;
background: #263238;
color: #f8f5ec;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: #3a4a50;
transform: translateY(-1px);
}
button:focus-visible {
outline: 3px solid rgba(223, 107, 89, 0.45);
outline-offset: 2px;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e5e9e3;
color: #52605d;
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.masthead {
top: 20px;
left: 20px;
}
.disclaimer {
top: 20px;
right: 20px;
width: 300px;
}
.legend {
display: none;
}
.info-card {
right: 20px;
bottom: 76px;
}
.controls {
bottom: 20px;
}
}
@media (max-width: 650px) {
.masthead {
max-width: calc(100vw - 40px);
}
.subtitle {
max-width: 280px;
font-size: 12px;
}
.disclaimer {
top: auto;
right: 14px;
bottom: 150px;
width: calc(100vw - 28px);
padding: 10px 12px;
}
.disclaimer p {
font-size: 10px;
}
.info-card {
right: 14px;
bottom: 76px;
width: calc(100vw - 28px);
padding: 13px 14px;
}
.info-card h2 {
font-size: 19px;
}
.info-card p {
font-size: 11px;
}
.info-card .analogy-note {
display: none;
}
.controls {
bottom: 16px;
}
.controls span {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive three-dimensional molecular shape and fit exhibit"></main>
<div class="overlay">
<header class="masthead">
<div class="kicker">Voxel exhibit · shape complementarity</div>
<h1>Molecular<br />Form & Fit</h1>
<p class="subtitle">
Schematic molecular forms are placed beside geometric recesses to
introduce the idea of shape complementarity.
</p>
</header>
<aside class="disclaimer" role="note">
<strong>Illustrative fit analogy</strong>
<p>
This is a shape-and-fit analogy—not a complete account of chemical
recognition. Real recognition also depends on chemistry, charge,
flexibility, dynamics, and solvent.
</p>
</aside>
<div class="legend" aria-label="Atom color legend">
<div class="legend-item">
<span class="swatch" style="background:#303b40"></span>Carbon
</div>
<div class="legend-item">
<span class="swatch" style="background:#ee6c5b"></span>Oxygen
</div>
<div class="legend-item">
<span class="swatch" style="background:#4f7cac"></span>Nitrogen
</div>
<div class="legend-item">
<span class="swatch" style="background:#e2b24d"></span>Other
</div>
<div class="legend-item">
<span class="swatch" style="background:#5ba89c"></span>Element
</div>
</div>
<section class="info-card" aria-live="polite" aria-atomic="true">
<div class="info-topline">
<span id="pair-number">Pair 01 / 03</span>
<span id="pair-tag">Selected</span>
</div>
<h2 id="pair-title">Angular complement</h2>
<p id="pair-description">
A compact, bent arrangement can meet a recess with similar angles.
Color identifies atom types; the geometry is deliberately schematic.
</p>
<p class="analogy-note">
Shape is one variable in recognition—not a complete binding rule.
</p>
</section>
<div class="controls">
<span>Drag to orbit · Scroll to zoom · Click a pair</span>
<button id="reset-view" type="button">Reset view</button>
</div>
</div>
<div id="loading">Building voxel exhibit…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const container = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe5e9e3);
scene.fog = new THREE.Fog(0xe5e9e3, 24, 43);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
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.03;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional voxel exhibit. Drag to orbit, scroll to zoom, and click an exhibit pair."
);
container.appendChild(renderer.domElement);
const ambient = new THREE.HemisphereLight(0xf7fbff, 0x8b9187, 2.25);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xfff4df, 3.6);
keyLight.position.set(-8, 15, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -18;
keyLight.shadow.camera.right = 18;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc8e3ff, 1.25);
fillLight.position.set(11, 8, 4);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffc5aa, 0.85);
rimLight.position.set(0, 7, -12);
scene.add(rimLight);
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0xdce2db,
roughness: 0.94,
metalness: 0,
}),
wall: new THREE.MeshStandardMaterial({
color: 0xd7ddd6,
roughness: 0.95,
metalness: 0,
}),
platform: new THREE.MeshStandardMaterial({
color: 0xf3f0e7,
roughness: 0.82,
metalness: 0,
}),
platformEdge: new THREE.MeshStandardMaterial({
color: 0xb7c0b9,
roughness: 0.72,
metalness: 0.02,
}),
cavityBack: new THREE.MeshStandardMaterial({
color: 0x303a3d,
roughness: 0.82,
metalness: 0.02,
}),
bond: new THREE.MeshStandardMaterial({
color: 0xd1d7d2,
roughness: 0.62,
metalness: 0.05,
}),
carbon: new THREE.MeshStandardMaterial({
color: 0x303b40,
roughness: 0.58,
metalness: 0.04,
}),
oxygen: new THREE.MeshStandardMaterial({
color: 0xee6c5b,
roughness: 0.56,
metalness: 0.02,
}),
nitrogen: new THREE.MeshStandardMaterial({
color: 0x4f7cac,
roughness: 0.57,
metalness: 0.02,
}),
gold: new THREE.MeshStandardMaterial({
color: 0xe2b24d,
roughness: 0.58,
metalness: 0.03,
}),
teal: new THREE.MeshStandardMaterial({
color: 0x5ba89c,
roughness: 0.58,
metalness: 0.02,
}),
ivory: new THREE.MeshStandardMaterial({
color: 0xf0eadb,
roughness: 0.65,
metalness: 0,
}),
};
const atomMaterials = {
"#303b40": materials.carbon,
"#ee6c5b": materials.oxygen,
"#4f7cac": materials.nitrogen,
"#e2b24d": materials.gold,
"#5ba89c": materials.teal,
"#f0eadb": materials.ivory,
};
const interactiveMeshes = [];
const stationXs = [-7.5, 0, 7.5];
const cellSize = 0.46;
const centerY = 1.55;
const specs = [
{
title: "Angular complement",
shortTitle: "ANGULAR",
tag: "Shape",
accent: 0xdf6b59,
cavityColor: 0xd8ccb8,
cells: [
[0, 0],
[1, 1],
[2, 0],
],
bonds: [
[0, 1],
[1, 2],
],
colors: ["#f0eadb", "#ee6c5b", "#4f7cac"],
description:
"A compact, bent arrangement can meet a recess with similar angles. Color identifies atom types; the geometry is deliberately schematic.",
},
{
title: "Hooked complement",
shortTitle: "HOOKED",
tag: "Asymmetry",
accent: 0x4f8f83,
cavityColor: 0xd6cfbd,
cells: [
[0, 0],
[1, 0],
[2, 0],
[2, 1],
[2, 2],
[3, 2],
],
bonds: [
[0, 1],
[1, 2],
[2, 3],
[3, 4],
[4, 5],
],
colors: [
"#4f7cac",
"#303b40",
"#ee6c5b",
"#e2b24d",
"#5ba89c",
"#303b40",
],
description:
"An asymmetric profile can favor a corresponding orientation. The model suggests a possible fit, not a guaranteed binding outcome.",
},
{
title: "Loop complement",
shortTitle: "LOOP",
tag: "Enclosure",
accent: 0x4f7cac,
cavityColor: 0xdfd3bd,
cells: [
[0, 0],
[1, 0],
[2, 0],
[2, 1],
[2, 2],
[1, 2],
[0, 2],
[0, 1],
],
bonds: [
[0, 1],
[1, 2],
[2, 3],
[3, 4],
[4, 5],
[5, 6],
[6, 7],
[7, 0],
],
colors: [
"#5ba89c",
"#ee6c5b",
"#4f7cac",
"#e2b24d",
"#303b40",
"#ee6c5b",
"#5ba89c",
"#4f7cac",
],
description:
"A ring-like footprint can complement a hollow or pocket. Real molecular recognition is three-dimensional, flexible, and chemically specific.",
},
];
// -------------------------------------------------------------------------
// Architectural setting
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(44, 32),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.set(0, -0.015, 1);
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(40, 40, 0x9eaaa3, 0xb8c1ba);
grid.position.set(0, 0.005, 0);
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
const wall = new THREE.Mesh(
new THREE.PlaneGeometry(34, 10),
materials.wall
);
wall.position.set(0, 4.85, -6.35);
wall.receiveShadow = true;
scene.add(wall);
for (const x of stationXs) {
const seam = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 7.2, 0.05),
new THREE.MeshStandardMaterial({
color: 0xb6c0b8,
roughness: 0.9,
})
);
seam.position.set(x + 3.35, 4.6, -6.3);
scene.add(seam);
}
// -------------------------------------------------------------------------
// Canvas-based labels; no external fonts or image assets are required.
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeTextTexture(
text,
{
width = 1024,
height = 160,
background = "rgba(248,246,239,0.94)",
color = "#253139",
border = "rgba(37,49,57,0.16)",
accent = null,
fontSize = 58,
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
if (background) {
roundedRect(ctx, 5, 5, width - 10, height - 10, 28);
ctx.fillStyle = background;
ctx.fill();
if (border) {
ctx.strokeStyle = border;
ctx.lineWidth = 3;
ctx.stroke();
}
}
if (accent) {
ctx.fillStyle = accent;
roundedRect(ctx, 24, 24, 12, height - 48, 5);
ctx.fill();
}
ctx.fillStyle = color;
ctx.font = `800 ${fontSize}px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(
text,
width / 2 + (accent ? 7 : 0),
height / 2 + 2,
width - 70
);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
return texture;
}
function makeTextSprite(text, options = {}) {
const {
worldWidth = 3,
worldHeight = 0.45,
depthTest = false,
...textureOptions
} = options;
const texture = makeTextTexture(text, textureOptions);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest,
toneMapped: false,
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.renderOrder = 10;
return sprite;
}
function makeWallSign(title, subtitle, accent, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = 1536;
canvas.height = 420;
const ctx = canvas.getContext("2d");
ctx.fillStyle = options.background || "#29363b";
roundedRect(ctx, 4, 4, 1528, 412, 34);
ctx.fill();
ctx.fillStyle = accent;
roundedRect(ctx, 35, 34, 15, 350, 7);
ctx.fill();
ctx.fillStyle = "#f8f5ec";
ctx.font = "800 102px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText(title, 88, 150, 1370);
ctx.fillStyle = "rgba(248,245,236,0.68)";
ctx.font = "600 36px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
ctx.fillText(subtitle, 92, 285, 1360);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
toneMapped: false,
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(options.worldWidth || 10.6, 2.9),
material
);
mesh.position.set(0, 5.25, -6.27);
scene.add(mesh);
return mesh;
}
makeWallSign(
"MOLECULAR FORM / FIT",
"SCHEMATIC SHAPE-COMPLEMENTARITY STUDY",
"#df6b59"
);
const caveatTexture = makeTextTexture(
"ILLUSTRATIVE ANALOGY ONLY • NOT A COMPLETE ACCOUNT OF CHEMICAL RECOGNITION",
{
width: 1536,
height: 180,
background: "rgba(37,49,57,0.92)",
color: "#f8f5ec",
border: null,
accent: "#df6b59",
fontSize: 43,
}
);
const caveatSign = new THREE.Mesh(
new THREE.PlaneGeometry(12.2, 1.35),
new THREE.MeshBasicMaterial({
map: caveatTexture,
transparent: true,
toneMapped: false,
})
);
caveatSign.position.set(0, 3.45, -6.25);
scene.add(caveatSign);
// -------------------------------------------------------------------------
// Exhibit construction helpers
// -------------------------------------------------------------------------
function addBox(
parent,
size,
position,
material,
stationIndex = null
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
if (stationIndex !== null) {
mesh.userData.stationIndex = stationIndex;
interactiveMeshes.push(mesh);
}
parent.add(mesh);
return mesh;
}
function addBond(parent, start, end, stationIndex) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(start, end)
.multiplyScalar(0.5);
const bond = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.065, length, 10),
materials.bond
);
bond.position.copy(midpoint);
bond.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
bond.castShadow = true;
bond.receiveShadow = true;
bond.userData.stationIndex = stationIndex;
interactiveMeshes.push(bond);
parent.add(bond);
}
function makePlaque(spec, index) {
const texture = makeTextTexture(
`${String(index + 1).padStart(2, "0")} / ${spec.shortTitle}`,
{
width: 1024,
height: 220,
background: "rgba(248,246,239,0.96)",
color: "#253139",
border: "rgba(37,49,57,0.18)",
accent: `#${new THREE.Color(spec.accent).getHexString()}`,
fontSize: 61,
}
);
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(2.65, 0.55),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
toneMapped: false,
})
);
plaque.position.set(0, 0.48, 2.09);
plaque.rotation.x = -0.42;
plaque.renderOrder = 4;
return plaque;
}
function createStation(spec, index, x) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const accentMaterial = new THREE.MeshStandardMaterial({
color: spec.accent,
roughness: 0.68,
metalness: 0.02,
});
const platformMaterial = new THREE.MeshStandardMaterial({
color: spec.cavityColor,
roughness: 0.84,
metalness: 0,
});
addBox(
group,
[6.45, 0.36, 4.55],
[0, 0.18, 0],
materials.platform,
index
);
addBox(
group,
[6.47, 0.075, 0.13],
[0, 0.39, 2.255],
accentMaterial,
index
);
addBox(
group,
[6.46, 0.055, 4.56],
[0, 0.015, 0],
materials.platformEdge,
index
);
// A faint square pad visually anchors the floating schematic model.
const padMaterial = new THREE.MeshStandardMaterial({
color: spec.accent,
roughness: 0.8,
metalness: 0,
transparent: true,
opacity: 0.16,
});
addBox(
group,
[2.05, 0.035, 1.32],
[-1.45, 0.395, 0.18],
padMaterial,
index
);
const modelGroup = new THREE.Group();
modelGroup.position.set(-1.45, 0, 0.39);
group.add(modelGroup);
const cavityGroup = new THREE.Group();
cavityGroup.position.set(1.25, 0, 0);
group.add(cavityGroup);
const shapeWidth =
Math.max(...spec.cells.map((cell) => cell[0])) + 1;
const shapeHeight =
Math.max(...spec.cells.map((cell) => cell[1])) + 1;
const modelPositions = [];
spec.cells.forEach((cell, cellIndex) => {
const localX =
(cell[0] - (shapeWidth - 1) / 2) * cellSize;
const localY =
centerY + (cell[1] - (shapeHeight - 1) / 2) * cellSize;
const position = new THREE.Vector3(localX, localY, 0);
modelPositions.push(position);
const material =
atomMaterials[spec.colors[cellIndex]] || materials.ivory;
addBox(
modelGroup,
[cellSize * 0.72, cellSize * 0.72, cellSize * 0.72],
[localX, localY, 0],
material,
index
);
});
spec.bonds.forEach(([a, b]) => {
addBond(modelGroup, modelPositions[a], modelPositions[b], index);
});
// The cavity is an extruded voxel block with an empty region matching
// the model's footprint. A dark backing makes the negative space legible.
const padding = 1;
const outerWidth = shapeWidth + padding * 2;
const outerHeight = shapeHeight + padding * 2;
const holeSet = new Set(
spec.cells.map(([gx, gy]) => `${gx + padding},${gy + padding}`)
);
addBox(
cavityGroup,
[outerWidth * cellSize + 0.08, outerHeight * cellSize + 0.08, 0.08],
[0, centerY, -0.31],
materials.cavityBack,
index
);
const cavityMaterial = new THREE.MeshStandardMaterial({
color: spec.cavityColor,
roughness: 0.87,
metalness: 0,
});
for (let gy = 0; gy < outerHeight; gy++) {
for (let gx = 0; gx < outerWidth; gx++) {
if (holeSet.has(`${gx},${gy}`)) continue;
const localX = (gx - (outerWidth - 1) / 2) * cellSize;
const localY =
centerY + (gy - (outerHeight - 1) / 2) * cellSize;
addBox(
cavityGroup,
[cellSize * 0.945, cellSize * 0.945, 0.48],
[localX, localY, 0.015],
cavityMaterial,
index
);
}
}
const titleSprite = makeTextSprite(
`${String(index + 1).padStart(2, "0")} ${spec.shortTitle}`,
{
worldWidth: 3.25,
worldHeight: 0.48,
background: "rgba(248,246,239,0.93)",
color: "#253139",
accent: `#${new THREE.Color(spec.accent).getHexString()}`,
fontSize: 60,
}
);
titleSprite.position.set(0, 3.62, -0.1);
group.add(titleSprite);
const modelLabel = makeTextSprite("SCHEMATIC MODEL", {
worldWidth: 2.38,
worldHeight: 0.34,
background: "rgba(248,246,239,0.84)",
color: "#52605d",
fontSize: 49,
});
modelLabel.position.set(-1.45, 2.89, 0.1);
group.add(modelLabel);
const cavityLabel = makeTextSprite("GEOMETRIC CAVITY", {
worldWidth: 2.58,
worldHeight: 0.34,
background: "rgba(248,246,239,0.84)",
color: "#52605d",
fontSize: 49,
});
cavityLabel.position.set(1.25, 2.89, 0.1);
group.add(cavityLabel);
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-0.48, 0.95, 1.18),
0.52,
spec.accent,
0.16,
0.11
);
group.add(arrow);
group.add(makePlaque(spec, index));
}
specs.forEach((spec, index) => {
createStation(spec, index, stationXs[index]);
});
// Selection outline.
const selectionOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(6.55, 0.39, 4.65)),
new THREE.LineBasicMaterial({
color: specs[0].accent,
transparent: true,
opacity: 0.9,
})
);
selectionOutline.position.set(stationXs[0], 0.2, 0);
selectionOutline.renderOrder = 6;
scene.add(selectionOutline);
// -------------------------------------------------------------------------
// Selection and information panel
// -------------------------------------------------------------------------
let selectedStation = 0;
const pairNumber = document.getElementById("pair-number");
const pairTag = document.getElementById("pair-tag");
const pairTitle = document.getElementById("pair-title");
const pairDescription = document.getElementById("pair-description");
function selectStation(index) {
selectedStation = index;
const spec = specs[index];
selectionOutline.position.x = stationXs[index];
selectionOutline.material.color.set(spec.accent);
pairNumber.textContent = `Pair ${String(index + 1).padStart(2, "0")} / 03`;
pairTag.textContent = spec.tag;
pairTitle.textContent = spec.title;
pairDescription.textContent = spec.description;
}
selectStation(0);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard, and reset
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 1.7, -0.25),
radius: 18.5,
desiredRadius: 18.5,
theta: 0.27,
desiredTheta: 0.27,
phi: 1.13,
desiredPhi: 1.13,
userZoomed: false,
};
function fittedRadius() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.7) return 31;
if (aspect < 1.15) return 25;
return 18.5;
}
function updateCamera(delta = 1) {
const smoothing = 1 - Math.exp(-8 * delta);
controls.theta +=
(controls.desiredTheta - controls.theta) * smoothing;
controls.phi +=
(controls.desiredPhi - controls.phi) * smoothing;
controls.radius +=
(controls.desiredRadius - controls.radius) * smoothing;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetView() {
controls.desiredTheta = 0.27;
controls.desiredPhi = 1.13;
controls.desiredRadius = fittedRadius();
controls.userZoomed = false;
}
document
.getElementById("reset-view")
.addEventListener("click", resetView);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let activePointerId = null;
let lastPointerX = 0;
let lastPointerY = 0;
let dragDistance = 0;
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function stationUnderPointer(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactiveMeshes, false);
return hits.length ? hits[0].object.userData.stationIndex : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
activePointerId = event.pointerId;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
dragDistance = 0;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging && event.pointerId === activePointerId) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
controls.desiredTheta = THREE.MathUtils.clamp(
controls.desiredTheta - dx * 0.005,
-0.9,
0.9
);
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi - dy * 0.0045,
0.62,
1.42
);
} else if (event.pointerType !== "touch") {
const hit = stationUnderPointer(event);
renderer.domElement.style.cursor =
hit === null ? "grab" : "pointer";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
dragging = false;
activePointerId = null;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (dragDistance < 6) {
const hit = stationUnderPointer(event);
if (hit !== null) selectStation(hit);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
activePointerId = null;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius + event.deltaY * 0.012,
11,
34
);
controls.userZoomed = true;
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const key = event.key;
if (key === "ArrowLeft") {
controls.desiredTheta = THREE.MathUtils.clamp(
controls.desiredTheta - 0.09,
-0.9,
0.9
);
} else if (key === "ArrowRight") {
controls.desiredTheta = THREE.MathUtils.clamp(
controls.desiredTheta + 0.09,
-0.9,
0.9
);
} else if (key === "ArrowUp") {
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi - 0.06,
0.62,
1.42
);
} else if (key === "ArrowDown") {
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi + 0.06,
0.62,
1.42
);
} else if (key.toLowerCase() === "r") {
resetView();
}
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
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);
if (!controls.userZoomed) {
controls.desiredRadius = fittedRadius();
}
}
window.addEventListener("resize", resize);
controls.desiredRadius = fittedRadius();
controls.radius = controls.desiredRadius;
updateCamera(1);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
updateCamera(delta);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
renderer.render(scene, camera);
loading.classList.add("hidden");
animate();
</script>
</body>
</html>
```