Prompt specification
Build or customize the Three.js 3D scene "Material-structure comparison explorer" 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: Material-structure comparison explorer
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/material-structure-comparison-explorer-x1952
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring glass and ceramic microstructures. Let viewers switch between ordered and disordered network models and inspect connectivity; separate structural representation from unsupported predictions of exact hardness, toughness, or melting temperature. Low-poly.
Working Three.js Starter (material-structure-comparison-explorer-x1952):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Network Studio — Glass & Ceramic Microstructures</title>
<style>
:root {
color-scheme: dark;
--bg: #07111b;
--panel: rgba(10, 22, 34, 0.88);
--panel-solid: #0c1b29;
--line: rgba(156, 190, 215, 0.16);
--text: #edf7ff;
--muted: #91a8ba;
--accent: #68e1cf;
--accent-2: #72b7ff;
--warning: #f0bd68;
--danger: #ff7d7d;
--radius: 16px;
}
* {
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;
}
body {
position: relative;
}
body::after {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
content: "";
background:
radial-gradient(circle at 63% 42%, transparent 20%, rgba(1, 7, 13, 0.18) 68%),
linear-gradient(180deg, rgba(6, 15, 25, 0.05), rgba(1, 7, 12, 0.30));
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.topbar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
min-height: 70px;
padding: 14px 20px;
pointer-events: none;
background: linear-gradient(180deg, rgba(4, 12, 20, 0.82), transparent);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
pointer-events: auto;
}
.brand-mark {
position: relative;
width: 34px;
height: 34px;
border: 1px solid rgba(104, 225, 207, 0.44);
border-radius: 10px;
background: rgba(104, 225, 207, 0.08);
transform: rotate(45deg);
}
.brand-mark::before,
.brand-mark::after {
position: absolute;
content: "";
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 14px rgba(104, 225, 207, 0.55);
}
.brand-mark::before {
width: 6px;
height: 6px;
top: 6px;
left: 6px;
}
.brand-mark::after {
width: 6px;
height: 6px;
right: 6px;
bottom: 6px;
background: var(--accent-2);
}
.brand-copy {
transform: translateY(-1px);
}
.brand-copy strong {
display: block;
font-size: 14px;
font-weight: 760;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.brand-copy span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.06em;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.scope-chip,
.icon-button,
.panel-button {
border: 1px solid var(--line);
border-radius: 999px;
color: var(--text);
background: rgba(9, 22, 34, 0.74);
font: inherit;
backdrop-filter: blur(12px);
}
.scope-chip {
padding: 8px 12px;
color: #b8c9d6;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.10em;
text-transform: uppercase;
}
.scope-chip::before {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 8px;
border-radius: 50%;
background: var(--warning);
content: "";
box-shadow: 0 0 10px rgba(240, 189, 104, 0.45);
}
.icon-button,
.panel-button {
cursor: pointer;
transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
}
.icon-button:hover,
.panel-button:hover {
border-color: rgba(104, 225, 207, 0.45);
background: rgba(24, 47, 62, 0.9);
}
.panel-button {
padding: 8px 12px;
font-size: 11px;
font-weight: 700;
}
#panel {
position: fixed;
top: 78px;
left: 18px;
bottom: 18px;
z-index: 8;
width: min(350px, calc(100vw - 36px));
overflow: auto;
padding: 18px;
border: 1px solid var(--line);
border-radius: var(--radius);
background: var(--panel);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.30);
backdrop-filter: blur(18px) saturate(125%);
scrollbar-width: thin;
scrollbar-color: #29475b transparent;
transition: transform 220ms ease, opacity 220ms ease;
}
body.panel-collapsed #panel {
opacity: 0;
pointer-events: none;
transform: translateX(calc(-100% - 30px));
}
.panel-title {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 17px;
}
.eyebrow {
margin: 0 0 5px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1,
h2,
h3,
p {
margin-top: 0;
}
.panel-title h1 {
margin-bottom: 4px;
font-size: 21px;
line-height: 1.15;
letter-spacing: -0.025em;
}
.panel-title p {
margin-bottom: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.live-badge {
flex: 0 0 auto;
padding: 5px 7px;
border: 1px solid rgba(104, 225, 207, 0.25);
border-radius: 6px;
color: var(--accent);
background: rgba(104, 225, 207, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.section {
padding: 15px 0;
border-top: 1px solid var(--line);
}
.section:first-of-type {
border-top: 0;
padding-top: 0;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
color: #c8d8e4;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-label small {
color: #71899a;
font-size: 9px;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: none;
}
.system-grid {
display: grid;
gap: 8px;
}
.system-card {
display: grid;
grid-template-columns: 35px 1fr;
align-items: center;
gap: 10px;
width: 100%;
padding: 10px;
border: 1px solid var(--line);
border-radius: 11px;
color: var(--text);
background: rgba(255, 255, 255, 0.025);
font: inherit;
text-align: left;
cursor: pointer;
transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}
.system-card:hover {
transform: translateX(2px);
border-color: rgba(114, 183, 255, 0.36);
}
.system-card.active {
border-color: rgba(104, 225, 207, 0.48);
background: rgba(104, 225, 207, 0.075);
}
.system-icon {
position: relative;
width: 31px;
height: 31px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.04);
}
.system-icon i {
position: absolute;
width: 8px;
height: 8px;
border-radius: 50%;
box-shadow: 0 0 10px currentColor;
}
.system-icon i:nth-child(1) {
top: 6px;
left: 6px;
color: var(--warning);
background: currentColor;
}
.system-icon i:nth-child(2) {
right: 6px;
bottom: 6px;
color: var(--danger);
background: currentColor;
}
.system-icon i:nth-child(3) {
top: 10px;
right: 5px;
width: 6px;
height: 6px;
color: var(--accent-2);
background: currentColor;
}
.system-card strong {
display: block;
margin-bottom: 2px;
font-size: 12px;
}
.system-card small {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px;
padding: 4px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(0, 0, 0, 0.12);
}
.segmented button {
padding: 8px 6px;
border: 0;
border-radius: 7px;
color: var(--muted);
background: transparent;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: color 150ms ease, background 150ms ease;
}
.segmented button.active {
color: #07131c;
background: var(--accent);
box-shadow: 0 4px 16px rgba(104, 225, 207, 0.16);
}
.model-description {
margin: 10px 0 0;
padding: 10px 11px;
border-left: 2px solid var(--accent-2);
color: #9db2c2;
background: rgba(114, 183, 255, 0.045);
font-size: 11px;
line-height: 1.5;
}
.switches {
display: grid;
gap: 8px;
}
.switch-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 27px;
color: #b8c9d6;
font-size: 11px;
cursor: pointer;
}
.switch {
position: relative;
flex: 0 0 auto;
width: 34px;
height: 19px;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch-track {
position: absolute;
inset: 0;
border: 1px solid #365063;
border-radius: 999px;
background: #102331;
transition: 150ms ease;
}
.switch-track::after {
position: absolute;
top: 3px;
left: 3px;
width: 11px;
height: 11px;
border-radius: 50%;
background: #7990a2;
content: "";
transition: 150ms ease;
}
.switch input:checked + .switch-track {
border-color: rgba(104, 225, 207, 0.5);
background: rgba(104, 225, 207, 0.16);
}
.switch input:checked + .switch-track::after {
left: 18px;
background: var(--accent);
box-shadow: 0 0 10px rgba(104, 225, 207, 0.5);
}
.stats-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.stat {
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.stat strong {
display: block;
margin-bottom: 3px;
font-size: 18px;
font-variant-numeric: tabular-nums;
}
.stat span {
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.micro-note {
margin: 8px 1px 0;
color: #71899a;
font-size: 9px;
line-height: 1.45;
}
.profile {
display: grid;
gap: 6px;
}
.profile-row {
display: grid;
grid-template-columns: 22px 1fr 30px;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 9px;
}
.profile-bar {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.055);
}
.profile-bar i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--accent-2), var(--accent));
}
.profile-row b {
color: #b6c8d5;
font-weight: 700;
text-align: right;
}
.selection-card {
min-height: 112px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.selection-empty {
display: grid;
place-items: center;
min-height: 86px;
color: #8299aa;
font-size: 11px;
line-height: 1.55;
text-align: center;
}
.selection-empty span {
display: block;
margin-bottom: 6px;
color: var(--accent);
font-size: 20px;
}
.selected-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 8px;
}
.selected-heading strong {
font-size: 14px;
}
.coord-pill {
padding: 4px 7px;
border-radius: 999px;
color: var(--accent);
background: rgba(104, 225, 207, 0.09);
font-size: 9px;
font-weight: 800;
text-transform: uppercase;
}
.selection-role {
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
}
.neighbors {
display: flex;
flex-wrap: wrap;
gap: 5px;
}
.neighbor-chip {
padding: 4px 7px;
border: 1px solid rgba(114, 183, 255, 0.25);
border-radius: 999px;
color: #bcd3e5;
background: rgba(114, 183, 255, 0.06);
font: inherit;
font-size: 9px;
cursor: pointer;
}
.neighbor-chip:hover {
border-color: var(--accent);
color: var(--text);
}
.focus-button {
margin-top: 9px;
padding: 5px 8px;
border: 1px solid var(--line);
border-radius: 6px;
color: #b8c9d6;
background: transparent;
font: inherit;
font-size: 9px;
cursor: pointer;
}
.focus-button:hover {
color: var(--accent);
border-color: rgba(104, 225, 207, 0.38);
}
.prediction-note {
margin-bottom: 0;
padding: 12px;
border: 1px solid rgba(240, 189, 104, 0.18);
border-radius: 11px;
background: rgba(240, 189, 104, 0.045);
}
.prediction-note strong {
display: block;
margin-bottom: 5px;
color: var(--warning);
font-size: 9px;
letter-spacing: 0.10em;
text-transform: uppercase;
}
.prediction-note p {
margin-bottom: 0;
color: #9aacb9;
font-size: 10px;
line-height: 1.5;
}
.legend {
position: fixed;
right: 20px;
bottom: 18px;
z-index: 5;
display: flex;
align-items: center;
gap: 13px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
color: #a8bdca;
background: rgba(8, 20, 31, 0.72);
backdrop-filter: blur(12px);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-dot {
width: 8px;
height: 8px;
border-radius: 50%;
box-shadow: 0 0 8px currentColor;
}
.legend-line {
width: 15px;
height: 2px;
border-radius: 2px;
background: #8ba6ba;
}
.hint {
position: fixed;
top: 83px;
right: 20px;
z-index: 4;
color: rgba(184, 205, 220, 0.65);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.07em;
text-align: right;
text-transform: uppercase;
pointer-events: none;
}
#tooltip {
position: fixed;
z-index: 20;
display: none;
padding: 6px 9px;
border: 1px solid rgba(114, 183, 255, 0.28);
border-radius: 7px;
color: #e7f4ff;
background: rgba(5, 15, 24, 0.92);
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
font-size: 10px;
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 760px) {
.topbar {
min-height: 60px;
padding: 10px 12px;
}
.brand-copy span,
.scope-chip {
display: none;
}
.brand-copy strong {
font-size: 11px;
}
#panel {
top: auto;
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
max-height: 53vh;
padding: 15px;
}
body.panel-collapsed #panel {
opacity: 0;
transform: translateY(calc(100% + 20px));
}
.hint {
top: 65px;
right: 12px;
max-width: 170px;
}
.legend {
right: 10px;
bottom: 10px;
gap: 9px;
padding: 8px 10px;
}
}
@media (prefers-reduced-motion: reduce) {
* {
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive 3D microstructure network"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<strong>Network Studio</strong>
<span id="sceneTitle">Silica glass · disordered tetrahedral network</span>
</div>
</div>
<div class="top-actions">
<div class="scope-chip">Structural model only</div>
<button id="panelToggle" class="panel-button" aria-expanded="true" aria-controls="panel">
Controls
</button>
</div>
</header>
<aside id="panel" aria-label="Microstructure controls">
<div class="panel-title">
<div>
<p class="eyebrow">Low-poly microstructure explorer</p>
<h1 id="modelTitle">Silica glass network</h1>
<p>Switch network families and compare idealized connectivity.</p>
</div>
<span class="live-badge">3D</span>
</div>
<section class="section">
<div class="section-label">
Network family
<small>composition</small>
</div>
<div class="system-grid">
<button class="system-card active" data-system="glass" aria-pressed="true">
<span class="system-icon" aria-hidden="true"><i></i><i></i><i></i></span>
<span>
<strong>Silica glass</strong>
<small>Si–O network with oxygen bridges</small>
</span>
</button>
<button class="system-card" data-system="ceramic" aria-pressed="false">
<span class="system-icon" aria-hidden="true"><i></i><i></i><i></i></span>
<span>
<strong>Silicon carbide ceramic</strong>
<small>Bipartite Si–C tetrahedral network</small>
</span>
</button>
</div>
</section>
<section class="section">
<div class="section-label">
Network arrangement
<small>topology / geometry</small>
</div>
<div class="segmented" role="group" aria-label="Network arrangement">
<button data-arrangement="ordered" aria-pressed="false">Ordered</button>
<button class="active" data-arrangement="disordered" aria-pressed="true">Disordered</button>
</div>
<p id="modelDescription" class="model-description"></p>
</section>
<section class="section">
<div class="section-label">Display</div>
<div class="switches">
<label class="switch-row">
<span>Show bonds</span>
<span class="switch">
<input id="toggleBonds" type="checkbox" checked />
<span class="switch-track"></span>
</span>
</label>
<label class="switch-row">
<span>Show model boundary</span>
<span class="switch">
<input id="toggleBoundary" type="checkbox" checked />
<span class="switch-track"></span>
</span>
</label>
<label class="switch-row">
<span>Auto-orbit camera</span>
<span class="switch">
<input id="toggleRotate" type="checkbox" />
<span class="switch-track"></span>
</span>
</label>
<button id="resetView" class="neighbor-chip" style="justify-self: start">
Reset camera
</button>
</div>
</section>
<section class="section">
<div class="section-label">
Model-derived topology
<small>finite network only</small>
</div>
<div class="stats-grid">
<div class="stat">
<strong id="statsNodes">—</strong>
<span>Atoms in model</span>
</div>
<div class="stat">
<strong id="statsBonds">—</strong>
<span>Bond edges</span>
</div>
<div class="stat">
<strong id="statsDegree">—</strong>
<span>Mean degree</span>
</div>
<div class="stat">
<strong id="statsComponents">—</strong>
<span>Components</span>
</div>
</div>
<p class="micro-note">
Counts describe this generated finite graph. They are not measured bulk-material values.
</p>
</section>
<section class="section">
<div class="section-label">
Coordination profile
<small>neighbors per atom</small>
</div>
<div id="coordProfile" class="profile"></div>
</section>
<section class="section">
<div class="section-label">
Connectivity inspector
<small>click an atom</small>
</div>
<div id="selectionContent" class="selection-card">
<div class="selection-empty">
<div>
<span>⌖</span>
Select a low-poly atom to isolate its first-shell connectivity.
</div>
</div>
</div>
</section>
<section class="section">
<div class="prediction-note">
<strong>Property predictions intentionally omitted</strong>
<p>
This scene represents composition, geometry, and graph connectivity only.
It does not estimate hardness, toughness, melting temperature, or other
mechanical/thermal properties. Those require validated constitutive
models, experimental data, and calibration beyond this schematic network.
</p>
</div>
</section>
</aside>
<div class="hint">Drag to orbit · wheel to zoom<br />click an atom to inspect</div>
<div id="legend" class="legend"></div>
<div id="tooltip"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const canvas = $("#scene");
const tooltip = $("#tooltip");
const state = {
system: "glass",
arrangement: "disordered",
showBonds: true,
showBoundary: true,
autoRotate: false,
selected: -1
};
const COLORS = {
Si: 0xf3c969,
O: 0xff7474,
C: 0x65d7ff,
bond: 0x91aabd,
selected: 0xffffff
};
const renderer = new THREE.WebGLRenderer({
canvas,
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111b);
scene.fog = new THREE.FogExp2(0x07111b, 0.038);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
theta: 0.72,
phi: 1.05,
radius: 7.25,
target: new THREE.Vector3()
};
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);
}
const hemisphere = new THREE.HemisphereLight(0xb9e7ff, 0x17202c, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(4.5, 7, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x55d9d0, 20, 15, 2);
rimLight.position.set(-4, 1.5, -3);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb85c, 13, 12, 2);
warmLight.position.set(3, -1.5, -4);
scene.add(warmLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x08131f,
roughness: 0.96,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.62;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 48, 0x2d5269, 0x152b3b);
grid.position.y = -2.60;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
const atomGeometry = new THREE.IcosahedronGeometry(1, 0);
const bridgeGeometry = new THREE.OctahedronGeometry(1, 0);
const bondGeometry = new THREE.CylinderGeometry(1, 1, 1, 5, 1, false);
let networkGroup = null;
let boundaryGroup = null;
let atoms = [];
let atomMeshes = [];
let bondMeshes = [];
let adjacency = [];
function mulberry32(seed) {
return function random() {
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;
};
}
function hashSeed(system, arrangement) {
const text = `${system}-${arrangement}`;
let hash = 2166136261;
for (let i = 0; i < text.length; i++) {
hash ^= text.charCodeAt(i);
hash = Math.imul(hash, 16777619);
}
return hash >>> 0;
}
function shuffle(array, random) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
function makeOrderedModel() {
const nx = 4;
const ny = 4;
const nz = 3;
const spacing = 1.0;
const nodes = [];
const index = new Map();
for (let x = 0; x < nx; x++) {
for (let y = 0; y < ny; y++) {
for (let z = 0; z < nz; z++) {
const parity = (x + y + z) % 2;
const node = {
position: new THREE.Vector3(
(x - (nx - 1) / 2) * spacing,
(y - (ny - 1) / 2) * spacing,
(z - (nz - 1) / 2) * spacing
),
parity,
bipartition: parity
};
const id = nodes.length;
nodes.push(node);
index.set(`${x},${y},${z}`, id);
}
}
}
const offsets = [
[1, 1, 1],
[1, -1, -1],
[-1, 1, -1],
[-1, -1, 1]
];
const edges = [];
for (let x = 0; x < nx; x++) {
for (let y = 0; y < ny; y++) {
for (let z = 0; z < nz; z++) {
if ((x + y + z) % 2 !== 0) continue;
const a = index.get(`${x},${y},${z}`);
for (const [dx, dy, dz] of offsets) {
const xx = x + dx;
const yy = y + dy;
const zz = z + dz;
if (
xx < 0 || xx >= nx ||
yy < 0 || yy >= ny ||
zz < 0 || zz >= nz
) continue;
const b = index.get(`${xx},${yy},${zz}`);
edges.push([a, b]);
}
}
}
}
return { nodes, edges };
}
function makeDisorderedModel(random) {
const half = 24;
const count = half * 2;
let edges = null;
function connected(edgeList) {
const graph = Array.from({ length: count }, () => []);
edgeList.forEach(([a, b]) => {
graph[a].push(b);
graph[b].push(a);
});
const seen = new Set([0]);
const queue = [0];
while (queue.length) {
const current = queue.pop();
for (const neighbor of graph[current]) {
if (!seen.has(neighbor)) {
seen.add(neighbor);
queue.push(neighbor);
}
}
}
return seen.size === count;
}
for (let attempt = 0; attempt < 200; attempt++) {
const aStubs = [];
const bStubs = [];
for (let i = 0; i < half; i++) {
for (let k = 0; k < 4; k++) {
aStubs.push(i);
bStubs.push(i + half);
}
}
shuffle(aStubs, random);
shuffle(bStubs, random);
const seenPairs = new Set();
const candidate = [];
for (let i = 0; i < aStubs.length; i++) {
const a = aStubs[i];
const b = bStubs[i];
const key = `${a}:${b}`;
if (seenPairs.has(key)) {
candidate.length = 0;
break;
}
seenPairs.add(key);
candidate.push([a, b]);
}
if (candidate.length === aStubs.length && connected(candidate)) {
edges = candidate;
break;
}
}
if (!edges) {
throw new Error("Could not construct a connected regular test network.");
}
const nodes = Array.from({ length: count }, (_, i) => ({
position: new THREE.Vector3(
(random() - 0.5) * 2.8,
(random() - 0.5) * 2.8,
(random() - 0.5) * 2.8
),
bipartition: i < half ? 0 : 1
}));
const adjacencyLocal = Array.from({ length: count }, () => []);
edges.forEach(([a, b]) => {
adjacencyLocal[a].push(b);
adjacencyLocal[b].push(a);
});
const targetLength = 1.55;
for (let iteration = 0; iteration < 320; iteration++) {
const forces = Array.from(
{ length: count },
() => new THREE.Vector3()
);
for (const [a, b] of edges) {
const delta = new THREE.Vector3().subVectors(
nodes[b].position,
nodes[a].position
);
const distance = Math.max(delta.length(), 0.001);
delta.multiplyScalar(1 / distance);
const force = delta.multiplyScalar(
(distance - targetLength) * 0.038
);
forces[a].add(force);
forces[b].sub(force);
}
for (let i = 0; i < count; i++) {
for (let j = i + 1; j < count; j++) {
const delta = new THREE.Vector3().subVectors(
nodes[i].position,
nodes[j].position
);
const distance = delta.length();
if (distance < 0.82) {
if (distance < 0.001) {
delta.set(
random() - 0.5,
random() - 0.5,
random() - 0.5
);
}
const safeDistance = Math.max(delta.length(), 0.001);
delta.multiplyScalar(1 / safeDistance);
const push = delta.multiplyScalar(
(0.82 - safeDistance) * 0.018
);
forces[i].sub(push);
forces[j].add(push);
}
}
}
for (let i = 0; i < count; i++) {
const p = nodes[i].position;
const f = forces[i];
p.addScaledVector(f, 0.82);
p.x += (random() - 0.5) * 0.006;
p.y += (random() - 0.5) * 0.006;
p.z += (random() - 0.5) * 0.006;
if (p.length() > 3.6) p.setLength(3.6);
}
if (iteration % 18 === 17) {
const center = new THREE.Vector3();
nodes.forEach((node) => center.add(node.position));
center.multiplyScalar(1 / count);
nodes.forEach((node) => node.position.sub(center));
let squared = 0;
edges.forEach(([a, b]) => {
squared += nodes[a].position.distanceToSquared(nodes[b].position);
});
const rms = Math.sqrt(squared / edges.length);
const scale = targetLength / Math.max(rms, 0.001);
nodes.forEach((node) => node.position.multiplyScalar(scale));
}
}
const center = new THREE.Vector3();
nodes.forEach((node) => center.add(node.position));
center.multiplyScalar(1 / count);
nodes.forEach((node) => node.position.sub(center));
let extent = 0;
nodes.forEach((node) => {
extent = Math.max(extent, node.position.length());
});
if (extent > 2.45) {
const scale = 2.45 / extent;
nodes.forEach((node) => node.position.multiplyScalar(scale));
}
return { nodes, edges };
}
function makeModel() {
const random = mulberry32(hashSeed(state.system, state.arrangement));
const model =
state.arrangement === "ordered"
? makeOrderedModel()
: makeDisorderedModel(random);
model.nodes.forEach((node, i) => {
if (state.system === "ceramic") {
node.type = node.bipartition === 0 ? "Si" : "C";
} else {
node.type = "Si";
}
node.id = i;
});
return { ...model, random };
}
function disposeNetwork(group) {
if (!group) return;
group.traverse((object) => {
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach((material) => material.dispose());
}
if (object.userData.ownedGeometry && object.geometry) {
object.geometry.dispose();
}
});
scene.remove(group);
}
function addAtom(type, position, role) {
const index = atoms.length;
const count = atoms.filter((atom) => atom.type === type).length + 1;
const label = `${type}-${String(count).padStart(2, "0")}`;
const radius = type === "O" ? 0.125 : 0.185;
const geometry = type === "O" ? bridgeGeometry : atomGeometry;
const material = new THREE.MeshStandardMaterial({
color: COLORS[type],
roughness: state.system === "glass" ? 0.28 : 0.64,
metalness: state.system === "glass" ? 0.04 : 0.10,
flatShading: true,
transparent: true,
opacity: state.system === "glass" ? 0.90 : 1.0
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(position);
mesh.scale.setScalar(radius);
mesh.castShadow = type !== "O";
mesh.receiveShadow = true;
mesh.userData.atomIndex = index;
mesh.userData.baseScale = radius;
mesh.userData.baseColor = new THREE.Color(COLORS[type]);
mesh.userData.baseOpacity = material.opacity;
networkGroup.add(mesh);
atomMeshes.push(mesh);
atoms.push({
index,
type,
label,
role,
position: position.clone(),
degree: 0
});
return index;
}
function addBond(a, b) {
const start = atoms[a].position;
const end = atoms[b].position;
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const material = new THREE.MeshStandardMaterial({
color: COLORS.bond,
roughness: 0.72,
metalness: 0.04,
flatShading: true,
transparent: true,
opacity: 0.78
});
const mesh = new THREE.Mesh(bondGeometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.scale.set(0.028, length, 0.028);
mesh.userData.baseColor = new THREE.Color(COLORS.bond);
mesh.userData.baseOpacity = 0.78;
mesh.visible = state.showBonds;
networkGroup.add(mesh);
bondMeshes.push(mesh);
atoms[a].degree++;
atoms[b].degree++;
}
function addBoundary() {
boundaryGroup = new THREE.Group();
const box = new THREE.Box3();
atoms.forEach((atom) => box.expandByPoint(atom.position));
box.expandByScalar(0.34);
const center = box.getCenter(new THREE.Vector3());
const size = box.getSize(new THREE.Vector3());
const boxGeometry = new THREE.BoxGeometry(size.x, size.y, size.z);
boxGeometry.translate(center.x, center.y, center.z);
const edgesGeometry = new THREE.EdgesGeometry(boxGeometry);
const edgeMaterial = new THREE.LineBasicMaterial({
color: state.system === "glass" ? 0x65cfc7 : 0xdfb567,
transparent: true,
opacity: 0.19,
depthWrite: false
});
const edges = new THREE.LineSegments(edgesGeometry, edgeMaterial);
edges.userData.ownedGeometry = true;
boundaryGroup.add(edges);
const volumeGeometry = new THREE.BoxGeometry(size.x, size.y, size.z);
volumeGeometry.translate(center.x, center.y, center.z);
const volumeMaterial = new THREE.MeshBasicMaterial({
color: state.system === "glass" ? 0x50bdb9 : 0xd9a84d,
transparent: true,
opacity: 0.018,
side: THREE.BackSide,
depthWrite: false
});
const volume = new THREE.Mesh(volumeGeometry, volumeMaterial);
volume.userData.ownedGeometry = true;
boundaryGroup.add(volume);
boundaryGroup.visible = state.showBoundary;
networkGroup.add(boundaryGroup);
}
function buildNetwork() {
disposeNetwork(networkGroup);
atoms = [];
atomMeshes = [];
bondMeshes = [];
networkGroup = new THREE.Group();
networkGroup.position.x = window.innerWidth > 760 ? 0.85 : 0;
scene.add(networkGroup);
const model = makeModel();
const centralAtomIndices = [];
model.nodes.forEach((node) => {
centralAtomIndices.push(
addAtom(
node.type,
node.position,
state.system === "glass"
? "Silicon network center"
: "Tetrahedral network site"
)
);
});
if (state.system === "glass") {
model.edges.forEach(([a, b], edgeIndex) => {
const start = model.nodes[a].position;
const end = model.nodes[b].position;
const oxygenPosition = start.clone().add(end).multiplyScalar(0.5);
if (state.arrangement === "disordered") {
const direction = end.clone().sub(start).normalize();
const randomVector = new THREE.Vector3(
model.random() - 0.5,
model.random() - 0.5,
model.random() - 0.5
);
randomVector.addScaledVector(
direction,
-randomVector.dot(direction)
);
if (randomVector.lengthSq() < 0.001) {
randomVector.cross(direction);
}
randomVector.normalize();
oxygenPosition.addScaledVector(
randomVector,
(model.random() - 0.5) * 0.14
);
}
const oxygenIndex = addAtom(
"O",
oxygenPosition,
"Two-coordinated oxygen bridge"
);
centralAtomIndices.push(oxygenIndex);
addBond(centralAtomIndices[a], oxygenIndex);
addBond(oxygenIndex, centralAtomIndices[b]);
});
} else {
model.edges.forEach(([a, b]) => {
addBond(centralAtomIndices[a], centralAtomIndices[b]);
});
}
adjacency = atoms.map(() => []);
bondMeshes.forEach((bond, index) => {
// Atom ordering follows construction: Si sites, then O sites for glass.
// Bond adjacency is reconstructed from positions and shared labels below.
});
// Rebuild adjacency robustly from the rendered bond endpoints.
adjacency = atoms.map(() => []);
const bondedAtomPairs = [];
if (state.system === "glass") {
model.edges.forEach(([a, b], edgeIndex) => {
bondedAtomPairs.push([
centralAtomIndices[a],
centralAtomIndices[edgeIndex + model.nodes.length]
]);
bondedAtomPairs.push([
centralAtomIndices[edgeIndex + model.nodes.length],
centralAtomIndices[b]
]);
});
} else {
model.edges.forEach(([a, b]) => {
bondedAtomPairs.push([centralAtomIndices[a], centralAtomIndices[b]]);
});
}
bondedAtomPairs.forEach(([a, b]) => {
adjacency[a].push(b);
adjacency[b].push(a);
atoms[a].degree++;
atoms[b].degree++;
});
// The first pass above already incremented degree; normalize it here.
atoms.forEach((atom, i) => {
atom.degree = adjacency[i].length;
});
addBoundary();
orbit.target.copy(networkGroup.position);
updateCamera();
state.selected = -1;
applySelection();
updateStatistics();
updateInspector();
updateUI();
}
function connectedComponentCount() {
const seen = new Set();
let count = 0;
for (let i = 0; i < atoms.length; i++) {
if (seen.has(i)) continue;
count++;
const queue = [i];
seen.add(i);
while (queue.length) {
const current = queue.pop();
for (const neighbor of adjacency[current]) {
if (!seen.has(neighbor)) {
seen.add(neighbor);
queue.push(neighbor);
}
}
}
}
return count;
}
function updateStatistics() {
const totalDegree = adjacency.reduce(
(sum, neighbors) => sum + neighbors.length,
0
);
$("#statsNodes").textContent = atoms.length;
$("#statsBonds").textContent = bondMeshes.length;
$("#statsDegree").textContent = (
totalDegree / Math.max(atoms.length, 1)
).toFixed(2);
$("#statsComponents").textContent = connectedComponentCount();
const counts = new Map();
atoms.forEach((atom) => {
counts.set(atom.degree, (counts.get(atom.degree) || 0) + 1);
});
const degrees = [...counts.keys()].sort((a, b) => a - b);
const maximum = Math.max(...counts.values(), 1);
$("#coordProfile").innerHTML = degrees
.map((degree) => {
const count = counts.get(degree);
const width = (count / maximum) * 100;
return `
<div class="profile-row">
<span>${degree}-fold</span>
<div class="profile-bar">
<i style="width:${width}%"></i>
</div>
<b>${count}</b>
</div>
`;
})
.join("");
}
function updateUI() {
$$("[data-system]").forEach((button) => {
const active = button.dataset.system === state.system;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
$$("[data-arrangement]").forEach((button) => {
const active = button.dataset.arrangement === state.arrangement;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
const isGlass = state.system === "glass";
$("#modelTitle").textContent = isGlass
? "Silica glass network"
: "Silicon carbide ceramic";
$("#sceneTitle").textContent =
`${isGlass ? "Silica glass" : "Silicon carbide ceramic"} · ` +
`${state.arrangement} network`;
if (isGlass) {
$("#modelDescription").textContent =
state.arrangement === "ordered"
? "Idealized corner-sharing tetrahedral arrangement. This is a schematic finite topology, not a named silica crystal phase."
: "Schematic randomized Si–O connectivity with relaxed coordinates. Oxygen atoms remain two-coordinated bridges.";
$("#legend").innerHTML = `
<span class="legend-item">
<i class="legend-dot" style="color:${cssColor(COLORS.Si)};background:${cssColor(COLORS.Si)}"></i>
Si
</span>
<span class="legend-item">
<i class="legend-dot" style="color:${cssColor(COLORS.O)};background:${cssColor(COLORS.O)}"></i>
O
</span>
<span class="legend-item"><i class="legend-line"></i>Bond</span>
`;
} else {
$("#modelDescription").textContent =
state.arrangement === "ordered"
? "Idealized diamond-type tetrahedral Si–C topology. Boundary sites have fewer displayed neighbors."
: "Schematic randomized bipartite Si–C connectivity with relaxed coordinates; it is not a calibrated amorphous SiC model.";
$("#legend").innerHTML = `
<span class="legend-item">
<i class="legend-dot" style="color:${cssColor(COLORS.Si)};background:${cssColor(COLORS.Si)}"></i>
Si
</span>
<span class="legend-item">
<i class="legend-dot" style="color:${cssColor(COLORS.C)};background:${cssColor(COLORS.C)}"></i>
C
</span>
<span class="legend-item"><i class="legend-line"></i>Bond</span>
`;
}
}
function cssColor(hex) {
return `#${hex.toString(16).padStart(6, "0")}`;
}
function applySelection() {
const selected = state.selected;
const neighborSet = new Set(
selected >= 0 ? adjacency[selected] || [] : []
);
const incidentBonds = new Set();
if (selected >= 0) {
bondMeshes.forEach((mesh, index) => {
const a = mesh.userData.atomA;
const b = mesh.userData.atomB;
if (a === selected || b === selected) {
incidentBonds.add(index);
}
});
}
atomMeshes.forEach((mesh, index) => {
const material = mesh.material;
const base = mesh.userData.baseColor;
const baseScale = mesh.userData.baseScale;
material.emissive.set(0x000000);
if (selected < 0) {
material.color.copy(base);
material.opacity = mesh.userData.baseOpacity;
material.depthWrite = true;
mesh.scale.setScalar(baseScale);
} else if (index === selected) {
material.color.copy(base).lerp(new THREE.Color(0xffffff), 0.20);
material.emissive.copy(base).multiplyScalar(0.42);
material.opacity = 1;
material.depthWrite = true;
mesh.scale.setScalar(baseScale * 1.22);
} else if (neighborSet.has(index)) {
material.color.copy(base);
material.emissive.copy(base).multiplyScalar(0.13);
material.opacity = 0.98;
material.depthWrite = true;
mesh.scale.setScalar(baseScale * 1.06);
} else {
material.color.copy(base).lerp(new THREE.Color(0x162330), 0.72);
material.opacity = 0.14;
material.depthWrite = false;
mesh.scale.setScalar(baseScale * 0.91);
}
});
bondMeshes.forEach((mesh, index) => {
const material = mesh.material;
const base = mesh.userData.baseColor;
if (selected < 0) {
material.color.copy(base);
material.emissive.set(0x000000);
material.opacity = mesh.userData.baseOpacity;
material.depthWrite = true;
} else if (incidentBonds.has(index)) {
material.color.set(0xd9f4ff);
material.emissive.set(0x6ebbd1);
material.emissiveIntensity = 0.32;
material.opacity = 1;
material.depthWrite = true;
} else {
material.color.copy(base).lerp(new THREE.Color(0x152432), 0.78);
material.emissive.set(0x000000);
material.opacity = 0.11;
material.depthWrite = false;
}
});
}
function updateInspector() {
const container = $("#selectionContent");
if (state.selected < 0) {
container.innerHTML = `
<div class="selection-empty">
<div>
<span>⌖</span>
Select a low-poly atom to isolate its first-shell connectivity.
</div>
</div>
`;
return;
}
const atom = atoms[state.selected];
const neighbors = adjacency[state.selected] || [];
const chips = neighbors.length
? neighbors
.map(
(index) =>
`<button class="neighbor-chip" data-neighbor="${index}">${atoms[index].label}</button>`
)
.join("")
: `<span class="micro-note">No displayed bonds at this boundary site.</span>`;
container.innerHTML = `
<div class="selected-heading">
<strong>${atom.label}</strong>
<span class="coord-pill">${atom.degree} neighbors</span>
</div>
<div class="selection-role">${atom.role}</div>
<div class="neighbors">${chips}</div>
<button class="focus-button" id="focusSelected">Focus this atom</button>
`;
}
function selectAtom(index) {
state.selected = index;
applySelection();
updateInspector();
}
function focusSelected() {
if (state.selected < 0 || !networkGroup) return;
const localPosition = atomMeshes[state.selected].position;
orbit.target.copy(networkGroup.position).add(localPosition);
orbit.radius = 4.15;
updateCamera();
}
// Direct camera controls implemented without Three.js addons.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerStart = new THREE.Vector2();
let pointerPrevious = new THREE.Vector2();
let pointerMoved = false;
function setPointerFromEvent(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickAtom(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(atomMeshes, false);
return hits.length ? hits[0].object.userData.atomIndex : -1;
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerDown = true;
pointerMoved = false;
pointerStart.set(event.clientX, event.clientY);
pointerPrevious.copy(pointerStart);
canvas.setPointerCapture(event.pointerId);
tooltip.style.display = "none";
});
canvas.addEventListener("pointermove", (event) => {
if (pointerDown) {
const deltaX = event.clientX - pointerPrevious.x;
const deltaY = event.clientY - pointerPrevious.y;
if (
Math.abs(event.clientX - pointerStart.x) +
Math.abs(event.clientY - pointerStart.y) > 5
) {
pointerMoved = true;
}
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.006,
0.20,
Math.PI - 0.20
);
pointerPrevious.set(event.clientX, event.clientY);
updateCamera();
return;
}
const index = pickAtom(event);
if (index >= 0) {
const atom = atoms[index];
tooltip.textContent = `${atom.label} · ${atom.degree} neighbors`;
tooltip.style.display = "block";
tooltip.style.left = `${event.clientX + 13}px`;
tooltip.style.top = `${event.clientY + 13}px`;
canvas.style.cursor = "pointer";
} else {
tooltip.style.display = "none";
canvas.style.cursor = "grab";
}
});
function endPointer(event) {
if (!pointerDown) return;
pointerDown = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (!pointerMoved) {
const index = pickAtom(event);
selectAtom(index >= 0 ? index : -1);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("pointerleave", () => {
if (!pointerDown) tooltip.style.display = "none";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
3.3,
13
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
orbit.theta -= 0.10;
break;
case "ArrowRight":
orbit.theta += 0.10;
break;
case "ArrowUp":
orbit.phi = Math.max(0.20, orbit.phi - 0.08);
break;
case "ArrowDown":
orbit.phi = Math.min(Math.PI - 0.20, orbit.phi + 0.08);
break;
case "+":
case "=":
orbit.radius = Math.max(3.3, orbit.radius - 0.45);
break;
case "-":
orbit.radius = Math.min(13, orbit.radius + 0.45);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
$$("[data-system]").forEach((button) => {
button.addEventListener("click", () => {
if (state.system === button.dataset.system) return;
state.system = button.dataset.system;
buildNetwork();
});
});
$$("[data-arrangement]").forEach((button) => {
button.addEventListener("click", () => {
if (state.arrangement === button.dataset.arrangement) return;
state.arrangement = button.dataset.arrangement;
buildNetwork();
});
});
$("#toggleBonds").addEventListener("change", (event) => {
state.showBonds = event.target.checked;
bondMeshes.forEach((mesh) => {
mesh.visible = state.showBonds;
});
});
$("#toggleBoundary").addEventListener("change", (event) => {
state.showBoundary = event.target.checked;
if (boundaryGroup) boundaryGroup.visible = state.showBoundary;
});
$("#toggleRotate").addEventListener("change", (event) => {
state.autoRotate = event.target.checked;
});
$("#resetView").addEventListener("click", () => {
if (!networkGroup) return;
orbit.target.copy(networkGroup.position);
orbit.radius = window.innerWidth <= 760 ? 6.8 : 7.25;
orbit.theta = 0.72;
orbit.phi = 1.05;
updateCamera();
});
$("#selectionContent").addEventListener("click", (event) => {
const neighbor = event.target.closest("[data-neighbor]");
if (neighbor) {
selectAtom(Number(neighbor.dataset.neighbor));
}
if (event.target.closest("#focusSelected")) {
focusSelected();
}
});
$("#panelToggle").addEventListener("click", () => {
const collapsed = document.body.classList.toggle("panel-collapsed");
$("#panelToggle").setAttribute("aria-expanded", String(!collapsed));
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
if (networkGroup) {
networkGroup.position.x = width > 760 ? 0.85 : 0;
orbit.target.x = networkGroup.position.x;
updateCamera();
}
}
window.addEventListener("resize", resize);
buildNetwork();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.autoRotate && !pointerDown) {
orbit.theta += delta * 0.11;
updateCamera();
}
if (state.selected >= 0 && atomMeshes[state.selected]) {
const mesh = atomMeshes[state.selected];
const pulse = 1.22 + Math.sin(performance.now() * 0.006) * 0.055;
mesh.scale.setScalar(mesh.userData.baseScale * pulse);
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```