Prompt specification
Build or customize the Three.js 3D scene "Ordered and amorphous network blocks" 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: Ordered and amorphous network blocks
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ordered-and-amorphous-network-blocks-x1949
Scene Description Prompt:
Ordered and amorphous network blocks. Build one repeating network and one irregular connected network using the same visual atom types; distinguish crystalline order from amorphous structure without equating disorder with liquid flow. Please build this with Three.js from cdnjs in one self-contained HTML file, using a 3D cutaway.
Working Three.js Starter (ordered-and-amorphous-network-blocks-x1949):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ordered and Amorphous Network Blocks</title>
<style>
:root {
color-scheme: dark;
--background: #07111c;
--panel: rgba(10, 24, 37, 0.84);
--panel-border: rgba(161, 211, 232, 0.18);
--text: #edf7fb;
--muted: #91aab8;
--cyan: #54d8e8;
--coral: #ff7484;
--line: rgba(156, 207, 228, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, #142b3c 0%, #091722 44%, #050b12 100%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hero {
position: fixed;
z-index: 4;
top: 28px;
left: 30px;
width: min(520px, calc(100vw - 390px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: #a9d6e3;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 1px;
content: "";
background: var(--cyan);
box-shadow: 0 0 12px rgba(84, 216, 232, 0.7);
}
h1 {
max-width: 500px;
margin: 0;
font-size: clamp(28px, 3.2vw, 49px);
font-weight: 540;
line-height: 1.04;
letter-spacing: -0.045em;
text-wrap: balance;
}
.hero p {
max-width: 490px;
margin: 16px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.65;
}
.panel {
position: fixed;
z-index: 5;
top: 28px;
right: 28px;
width: 304px;
padding: 19px;
overflow: hidden;
border: 1px solid var(--panel-border);
border-radius: 17px;
background: var(--panel);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.26),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.panel-title {
margin-bottom: 13px;
color: #d7edf5;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-bottom: 17px;
}
.atom-key {
display: flex;
align-items: center;
gap: 9px;
min-height: 42px;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.atom-dot {
flex: 0 0 auto;
width: 13px;
height: 13px;
border-radius: 50%;
}
.atom-dot.a {
width: 16px;
height: 16px;
background: var(--coral);
box-shadow: 0 0 15px rgba(255, 116, 132, 0.35);
}
.atom-dot.b {
background: var(--cyan);
box-shadow: 0 0 15px rgba(84, 216, 232, 0.35);
}
.atom-key strong {
display: block;
font-size: 12px;
font-weight: 700;
}
.atom-key small {
display: block;
margin-top: 1px;
color: var(--muted);
font-size: 10px;
}
.comparison {
display: grid;
gap: 8px;
margin-bottom: 17px;
}
.comparison-row {
display: grid;
grid-template-columns: 27px 1fr;
gap: 9px;
align-items: start;
padding-top: 10px;
border-top: 1px solid var(--line);
}
.comparison-row .number {
color: #638092;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
}
.comparison-row strong {
display: block;
margin-bottom: 3px;
color: #dcecf2;
font-size: 12px;
font-weight: 700;
}
.comparison-row small {
display: block;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 38px;
padding: 9px 10px;
border: 1px solid rgba(155, 207, 226, 0.2);
border-radius: 10px;
background: rgba(121, 177, 198, 0.07);
color: #cfe5ed;
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(84, 216, 232, 0.5);
background: rgba(84, 216, 232, 0.11);
color: #ffffff;
}
button:active {
transform: translateY(1px);
}
button.active {
border-color: rgba(84, 216, 232, 0.48);
background: rgba(84, 216, 232, 0.15);
color: #e9fbff;
}
#resetButton {
grid-column: 1 / -1;
}
.readout {
display: flex;
align-items: center;
gap: 8px;
margin-top: 13px;
color: #89a6b5;
font-size: 10px;
line-height: 1.4;
}
.readout-dot {
width: 6px;
height: 6px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px rgba(84, 216, 232, 0.8);
}
.scene-label {
position: fixed;
z-index: 3;
display: grid;
grid-template-columns: 28px auto;
grid-template-rows: auto auto;
column-gap: 8px;
min-width: 185px;
padding: 10px 13px;
border: 1px solid rgba(157, 208, 226, 0.18);
border-radius: 11px;
background: rgba(7, 18, 29, 0.72);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
pointer-events: none;
transform: translate(-50%, -100%);
backdrop-filter: blur(9px);
-webkit-backdrop-filter: blur(9px);
}
.scene-label .index {
grid-row: 1 / 3;
align-self: center;
color: #607d8d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
}
.scene-label strong {
color: #e5f3f7;
font-size: 12px;
font-weight: 700;
}
.scene-label small {
margin-top: 2px;
color: #8ba7b6;
font-size: 9.5px;
letter-spacing: 0.02em;
}
.bottom-note {
position: fixed;
z-index: 4;
bottom: 23px;
left: 50%;
width: min(690px, calc(100vw - 48px));
padding: 12px 16px;
border: 1px solid rgba(159, 205, 223, 0.15);
border-radius: 12px;
background: rgba(7, 17, 28, 0.78);
color: #91aab8;
font-size: 11px;
line-height: 1.5;
text-align: center;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.bottom-note strong {
margin-right: 7px;
color: #dceff5;
font-weight: 700;
}
.controls-hint {
position: fixed;
z-index: 4;
bottom: 26px;
left: 28px;
color: #708b9a;
font-size: 10px;
line-height: 1.5;
pointer-events: none;
}
@media (max-width: 900px) {
.hero {
top: 20px;
left: 20px;
width: calc(100vw - 40px);
}
.hero p {
max-width: 520px;
}
.panel {
top: auto;
right: 16px;
bottom: 82px;
width: min(304px, calc(100vw - 32px));
}
.controls-hint {
display: none;
}
.bottom-note {
bottom: 15px;
width: calc(100vw - 30px);
}
}
@media (max-width: 560px) {
h1 {
font-size: 29px;
}
.hero p {
display: none;
}
.panel {
padding: 14px;
}
.legend,
.comparison {
margin-bottom: 12px;
}
.comparison-row {
padding-top: 7px;
}
.scene-label {
min-width: 150px;
padding: 8px 10px;
}
.scene-label strong {
font-size: 10px;
}
.scene-label small {
font-size: 8px;
}
.bottom-note {
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D comparison of crystalline and amorphous networks"></canvas>
<header class="hero">
<div class="eyebrow">Network morphology / 3D materials</div>
<h1>Order is not the only way to be connected.</h1>
<p>
Two solid network blocks use the same atoms and bonds. One follows a
repeating rule; the other remains connected without long-range order.
</p>
</header>
<aside class="panel" aria-label="Visualization controls">
<div class="panel-title">Shared visual language</div>
<div class="legend">
<div class="atom-key">
<span class="atom-dot a"></span>
<span>
<strong>Atom type A</strong>
<small>Larger / coral</small>
</span>
</div>
<div class="atom-key">
<span class="atom-dot b"></span>
<span>
<strong>Atom type B</strong>
<small>Smaller / cyan</small>
</span>
</div>
</div>
<div class="comparison">
<div class="comparison-row">
<span class="number">01</span>
<span>
<strong>Repeating network</strong>
<small>
A periodic arrangement produces the same local coordination
throughout the crystalline block.
</small>
</span>
</div>
<div class="comparison-row">
<span class="number">02</span>
<span>
<strong>Irregular connected network</strong>
<small>
Non-periodic positions and coordination form a continuous
amorphous network.
</small>
</span>
</div>
</div>
<div class="controls">
<button id="cutawayButton" class="active" aria-pressed="true">
Cutaway: on
</button>
<button id="bondsButton" class="active" aria-pressed="true">
Bonds: on
</button>
<button id="resetButton">Reset camera</button>
</div>
<div class="readout">
<span class="readout-dot"></span>
<span id="cutStatus">
Front–upper–right octant removed to expose the interior.
</span>
</div>
</aside>
<div id="orderedLabel" class="scene-label">
<span class="index">01</span>
<strong>Repeating network</strong>
<small>Crystalline · periodic coordination</small>
</div>
<div id="amorphousLabel" class="scene-label">
<span class="index">02</span>
<strong>Irregular connected network</strong>
<small>Amorphous · non-periodic topology</small>
</div>
<div class="controls-hint">
Drag to orbit<br />
Wheel to zoom · Shift-drag to pan
</div>
<div class="bottom-note">
<strong>Static solid networks.</strong>
No particle motion is depicted. “Amorphous” describes spatial and
topological disorder, not a liquid or flowing state.
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111c);
scene.fog = new THREE.FogExp2(0x07111c, 0.022);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, -0.45, 0);
const spherical = {
radius: 18.8,
theta: 0.78,
phi: 1.08
};
function updateCamera() {
const sinPhi = Math.sin(spherical.phi);
const cosPhi = Math.cos(spherical.phi);
camera.position.set(
target.x + spherical.radius * sinPhi * Math.sin(spherical.theta),
target.y + spherical.radius * cosPhi,
target.z + spherical.radius * sinPhi * Math.cos(spherical.theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetCamera() {
target.set(0, -0.45, 0);
spherical.theta = 0.78;
spherical.phi = 1.08;
const aspect = window.innerWidth / window.innerHeight;
spherical.radius = aspect < 0.8 ? 31 : aspect < 1.2 ? 24 : 18.8;
updateCamera();
}
resetCamera();
// -------------------------------------------------------------------------
// Lighting and ground
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc9efff, 0x111b27, 1.75));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x65d8ee, 1.35);
rimLight.position.set(-9, 4, -7);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff7d8e, 18, 22, 2);
warmLight.position.set(5, 1, 6);
scene.add(warmLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0x07121c,
roughness: 0.96,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -3.55;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(46, 46, 0x31566b, 0x173043);
grid.position.y = -3.535;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
// -------------------------------------------------------------------------
// Shared visual materials
// -------------------------------------------------------------------------
const atomGeometry = new THREE.SphereGeometry(1, 20, 14);
const atomMaterials = [
new THREE.MeshPhysicalMaterial({
color: 0xff7484,
roughness: 0.25,
metalness: 0.08,
clearcoat: 0.8,
clearcoatRoughness: 0.18,
emissive: 0x3d080f,
emissiveIntensity: 0.32
}),
new THREE.MeshPhysicalMaterial({
color: 0x54d8e8,
roughness: 0.23,
metalness: 0.1,
clearcoat: 0.8,
clearcoatRoughness: 0.18,
emissive: 0x073840,
emissiveIntensity: 0.32
})
];
const atomRadii = [0.145, 0.108];
const bondGeometry = new THREE.CylinderGeometry(1, 1, 1, 7, 1, false);
const bondMaterial = new THREE.MeshStandardMaterial({
color: 0xb8d0dc,
roughness: 0.42,
metalness: 0.18,
transparent: true,
opacity: 0.76
});
const shellMaterial = new THREE.LineBasicMaterial({
color: 0x8eb4c4,
transparent: true,
opacity: 0.28
});
const removedEdgeMaterial = new THREE.LineDashedMaterial({
color: 0x80dceb,
transparent: true,
opacity: 0.58,
dashSize: 0.12,
gapSize: 0.085
});
const cutGridMaterial = new THREE.LineBasicMaterial({
color: 0x74a8b9,
transparent: true,
opacity: 0.28
});
const allBondMeshes = [];
const dummy = new THREE.Object3D();
const up = new THREE.Vector3(0, 1, 0);
const midpoint = new THREE.Vector3();
const direction = new THREE.Vector3();
const quaternion = new THREE.Quaternion();
// -------------------------------------------------------------------------
// Deterministic random number generator
// -------------------------------------------------------------------------
function makeRandom(seed) {
let state = seed >>> 0;
return function random() {
state += 0x6d2b79f5;
let t = state;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function shuffle(values, random) {
for (let i = values.length - 1; i > 0; i--) {
const j = Math.floor(random() * (i + 1));
[values[i], values[j]] = [values[j], values[i]];
}
return values;
}
// -------------------------------------------------------------------------
// Network data
// -------------------------------------------------------------------------
const HALF_SIZE = 2.78;
function removedOctant(point) {
return point.x > 0 && point.y > 0 && point.z > 0;
}
function makeOrderedPoints() {
const points = [];
const n = 6;
const spacing = 0.96;
for (let z = 0; z < n; z++) {
for (let y = 0; y < n; y++) {
for (let x = 0; x < n; x++) {
points.push({
x: (x - (n - 1) / 2) * spacing,
y: (y - (n - 1) / 2) * spacing,
z: (z - (n - 1) / 2) * spacing,
type: (x + y + z) % 2
});
}
}
}
return points;
}
function makeOrderedEdges(points) {
const n = 6;
const index = (x, y, z) => x + n * y + n * n * z;
const edges = [];
for (let z = 0; z < n; z++) {
for (let y = 0; y < n; y++) {
for (let x = 0; x < n; x++) {
const a = index(x, y, z);
if (x + 1 < n) edges.push([a, index(x + 1, y, z)]);
if (y + 1 < n) edges.push([a, index(x, y + 1, z)]);
if (z + 1 < n) edges.push([a, index(x, y, z + 1)]);
}
}
}
return edges;
}
function makeAmorphousPoints(count, seed) {
const random = makeRandom(seed);
const points = [];
const extent = 2.55;
const minimumDistanceSquared = 0.42 * 0.42;
let attempts = 0;
while (points.length < count && attempts < 30000) {
attempts++;
const candidate = {
x: (random() * 2 - 1) * extent,
y: (random() * 2 - 1) * extent,
z: (random() * 2 - 1) * extent
};
let valid = true;
for (const point of points) {
const dx = candidate.x - point.x;
const dy = candidate.y - point.y;
const dz = candidate.z - point.z;
if (dx * dx + dy * dy + dz * dz < minimumDistanceSquared) {
valid = false;
break;
}
}
if (valid) points.push(candidate);
}
// Use exactly the same total count of A and B atoms as the ordered network.
const typePool = [
...Array(count / 2).fill(0),
...Array(count / 2).fill(1)
];
shuffle(typePool, random);
for (let i = 0; i < points.length; i++) {
points[i].type = typePool[i];
}
return points;
}
function makeConnectedEdges(points) {
const count = points.length;
const edgeKeys = new Set();
const edges = [];
function addEdge(a, b) {
const low = Math.min(a, b);
const high = Math.max(a, b);
const key = `${low}:${high}`;
if (!edgeKeys.has(key)) {
edgeKeys.add(key);
edges.push([low, high]);
}
}
// Prim's algorithm guarantees a connected minimum spanning tree.
const inTree = new Uint8Array(count);
const bestDistance = new Float64Array(count);
const parent = new Int32Array(count);
bestDistance.fill(Infinity);
parent.fill(-1);
bestDistance[0] = 0;
for (let step = 0; step < count; step++) {
let selected = -1;
let selectedDistance = Infinity;
for (let i = 0; i < count; i++) {
if (!inTree[i] && bestDistance[i] < selectedDistance) {
selected = i;
selectedDistance = bestDistance[i];
}
}
if (selected === -1) break;
inTree[selected] = 1;
if (parent[selected] !== -1) {
addEdge(selected, parent[selected]);
}
for (let i = 0; i < count; i++) {
if (inTree[i]) continue;
const dx = points[selected].x - points[i].x;
const dy = points[selected].y - points[i].y;
const dz = points[selected].z - points[i].z;
const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (distance < bestDistance[i]) {
bestDistance[i] = distance;
parent[i] = selected;
}
}
}
// Add short local connections to create a richer 3D coordination network.
for (let i = 0; i < count; i++) {
const neighbors = [];
for (let j = 0; j < count; j++) {
if (i === j) continue;
const dx = points[i].x - points[j].x;
const dy = points[i].y - points[j].y;
const dz = points[i].z - points[j].z;
const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
neighbors.push({ j, distance });
}
neighbors.sort((a, b) => a.distance - b.distance);
for (let k = 0; k < Math.min(5, neighbors.length); k++) {
if (neighbors[k].distance <= 1.5) {
addEdge(i, neighbors[k].j);
}
}
}
return edges;
}
const orderedFullPoints = makeOrderedPoints();
const orderedCutPoints = orderedFullPoints.filter(
point => !removedOctant(point)
);
const orderedFullEdges = makeOrderedEdges(orderedFullPoints);
const orderedCutIndex = new Map(
orderedCutPoints.map((point, index) => [point, index])
);
const orderedCutEdges = orderedFullEdges
.map(([a, b]) => [orderedCutIndex.get(orderedFullPoints[a]), orderedCutIndex.get(orderedFullPoints[b])])
.filter(([a, b]) => a !== undefined && b !== undefined);
const amorphousFullPoints = makeAmorphousPoints(216, 0x4a19e2d7);
const amorphousCutPoints = amorphousFullPoints.filter(
point => !removedOctant(point)
);
const amorphousFullEdges = makeConnectedEdges(amorphousFullPoints);
const amorphousCutEdges = makeConnectedEdges(amorphousCutPoints);
// -------------------------------------------------------------------------
// Instanced atom and bond rendering
// -------------------------------------------------------------------------
function makeNetwork(points, edges) {
const group = new THREE.Group();
const typeA = [];
const typeB = [];
for (const point of points) {
(point.type === 0 ? typeA : typeB).push(point);
}
function makeAtomMesh(pointArray, material, radius) {
if (pointArray.length === 0) return;
const mesh = new THREE.InstancedMesh(
atomGeometry,
material,
pointArray.length
);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
for (let i = 0; i < pointArray.length; i++) {
const point = pointArray[i];
dummy.position.set(point.x, point.y, point.z);
dummy.quaternion.identity();
dummy.scale.setScalar(radius);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
}
mesh.instanceMatrix.needsUpdate = true;
group.add(mesh);
}
makeAtomMesh(typeA, atomMaterials[0], atomRadii[0]);
makeAtomMesh(typeB, atomMaterials[1], atomRadii[1]);
if (edges.length > 0) {
const bondMesh = new THREE.InstancedMesh(
bondGeometry,
bondMaterial,
edges.length
);
bondMesh.castShadow = true;
bondMesh.frustumCulled = false;
for (let i = 0; i < edges.length; i++) {
const [aIndex, bIndex] = edges[i];
const a = points[aIndex];
const b = points[bIndex];
midpoint.set(
(a.x + b.x) * 0.5,
(a.y + b.y) * 0.5,
(a.z + b.z) * 0.5
);
direction.set(
b.x - a.x,
b.y - a.y,
b.z - a.z
);
const length = direction.length();
quaternion.setFromUnitVectors(up, direction.normalize());
dummy.position.copy(midpoint);
dummy.quaternion.copy(quaternion);
dummy.scale.set(0.022, length, 0.022);
dummy.updateMatrix();
bondMesh.setMatrixAt(i, dummy.matrix);
}
bondMesh.instanceMatrix.needsUpdate = true;
group.add(bondMesh);
allBondMeshes.push(bondMesh);
}
return group;
}
// -------------------------------------------------------------------------
// Block shell and visible cut surfaces
// -------------------------------------------------------------------------
function makeCutGrid(orientation) {
const vertices = [];
const h = HALF_SIZE;
const step = 0.4;
for (let t = 0; t <= h + 0.001; t += step) {
if (orientation === "x") {
vertices.push(
0, t, 0, 0, t, h,
0, 0, t, 0, h, t
);
} else if (orientation === "y") {
vertices.push(
t, 0, 0, t, 0, h,
0, 0, t, h, 0, t
);
} else {
vertices.push(
t, 0, 0, t, h, 0,
0, t, 0, h, t, 0
);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
return new THREE.LineSegments(geometry, cutGridMaterial);
}
function makeCutSurfaces(accentColor) {
const group = new THREE.Group();
const h = HALF_SIZE;
const material = new THREE.MeshBasicMaterial({
color: accentColor,
transparent: true,
opacity: 0.095,
side: THREE.DoubleSide,
depthWrite: false
});
const xFace = new THREE.Mesh(
new THREE.PlaneGeometry(h, h),
material
);
xFace.rotation.y = Math.PI / 2;
xFace.position.set(0, h / 2, h / 2);
xFace.renderOrder = -1;
group.add(xFace);
const yFace = new THREE.Mesh(
new THREE.PlaneGeometry(h, h),
material
);
yFace.rotation.x = Math.PI / 2;
yFace.position.set(h / 2, 0, h / 2);
yFace.renderOrder = -1;
group.add(yFace);
const zFace = new THREE.Mesh(
new THREE.PlaneGeometry(h, h),
material
);
zFace.position.set(h / 2, h / 2, 0);
zFace.renderOrder = -1;
group.add(zFace);
group.add(
makeCutGrid("x"),
makeCutGrid("y"),
makeCutGrid("z")
);
// Dashed edges outline the removed corner.
const removedEdges = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, h, h, h, h, h,
h, 0, h, h, h, h,
h, h, 0, h, h, h
], 3)
),
removedEdgeMaterial
);
removedEdges.computeLineDistances();
group.add(removedEdges);
return group;
}
function makeBlock(centerX, fullPoints, cutPoints, fullEdges, cutEdges, accent) {
const root = new THREE.Group();
root.position.set(centerX, -0.35, 0);
const fullNetwork = makeNetwork(fullPoints, fullEdges);
const cutNetwork = makeNetwork(cutPoints, cutEdges);
root.add(fullNetwork, cutNetwork);
const shellGeometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(
HALF_SIZE * 2,
HALF_SIZE * 2,
HALF_SIZE * 2
)
);
const shell = new THREE.LineSegments(shellGeometry, shellMaterial);
root.add(shell);
// Very faint full-volume skin, used only when the cutaway is disabled.
const glass = new THREE.Mesh(
new THREE.BoxGeometry(
HALF_SIZE * 2,
HALF_SIZE * 2,
HALF_SIZE * 2
),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.025,
side: THREE.DoubleSide,
depthWrite: false
})
);
root.add(glass);
const cutSurfaces = makeCutSurfaces(accent);
root.add(cutSurfaces);
return {
root,
fullNetwork,
cutNetwork,
cutSurfaces,
glass
};
}
const orderedBlock = makeBlock(
-3.9,
orderedFullPoints,
orderedCutPoints,
orderedFullEdges,
orderedCutEdges,
0x74cfe2
);
const amorphousBlock = makeBlock(
3.9,
amorphousFullPoints,
amorphousCutPoints,
amorphousFullEdges,
amorphousCutEdges,
0xe18ba3
);
scene.add(orderedBlock.root, amorphousBlock.root);
// -------------------------------------------------------------------------
// UI state
// -------------------------------------------------------------------------
const cutawayButton = document.querySelector("#cutawayButton");
const bondsButton = document.querySelector("#bondsButton");
const resetButton = document.querySelector("#resetButton");
const cutStatus = document.querySelector("#cutStatus");
let cutawayEnabled = true;
let bondsEnabled = true;
function updateCutaway() {
for (const block of [orderedBlock, amorphousBlock]) {
block.fullNetwork.visible = !cutawayEnabled;
block.cutNetwork.visible = cutawayEnabled;
block.cutSurfaces.visible = cutawayEnabled;
block.glass.visible = !cutawayEnabled;
}
cutawayButton.textContent = cutawayEnabled ? "Cutaway: on" : "Cutaway: off";
cutawayButton.classList.toggle("active", cutawayEnabled);
cutawayButton.setAttribute("aria-pressed", String(cutawayEnabled));
cutStatus.textContent = cutawayEnabled
? "Front–upper–right octant removed to expose the interior."
: "Complete network volumes restored.";
}
function updateBonds() {
for (const bondMesh of allBondMeshes) {
bondMesh.visible = bondsEnabled;
}
bondsButton.textContent = bondsEnabled ? "Bonds: on" : "Bonds: off";
bondsButton.classList.toggle("active", bondsEnabled);
bondsButton.setAttribute("aria-pressed", String(bondsEnabled));
}
cutawayButton.addEventListener("click", () => {
cutawayEnabled = !cutawayEnabled;
updateCutaway();
});
bondsButton.addEventListener("click", () => {
bondsEnabled = !bondsEnabled;
updateBonds();
});
resetButton.addEventListener("click", resetCamera);
updateCutaway();
updateBonds();
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, wheel zoom, and touch pinch
// -------------------------------------------------------------------------
const pointers = new Map();
let lastPointer = null;
let pinchDistance = 0;
let interactionMode = "orbit";
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
lastPointer = {
x: event.clientX,
y: event.clientY
};
interactionMode =
event.shiftKey || event.button === 2 ? "pan" : "orbit";
} else if (pointers.size === 2) {
interactionMode = "pinch";
pinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2) {
const nextDistance = pointerDistance();
if (pinchDistance > 0 && nextDistance > 0) {
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * (pinchDistance / nextDistance),
9,
42
);
pinchDistance = nextDistance;
updateCamera();
}
return;
}
if (!lastPointer) return;
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
if (interactionMode === "pan") {
camera.updateMatrixWorld();
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(
camera.quaternion
);
const panScale = spherical.radius * 0.0014;
target.addScaledVector(right, -dx * panScale);
target.addScaledVector(up, dy * panScale);
target.x = THREE.MathUtils.clamp(target.x, -8, 8);
target.y = THREE.MathUtils.clamp(target.y, -3, 4);
target.z = THREE.MathUtils.clamp(target.z, -7, 7);
} else {
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.005,
0.32,
1.47
);
}
lastPointer = {
x: event.clientX,
y: event.clientY
};
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastPointer = { x: remaining.x, y: remaining.y };
interactionMode = "orbit";
} else if (pointers.size === 0) {
lastPointer = null;
pinchDistance = 0;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
9,
42
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("contextmenu", event => event.preventDefault());
window.addEventListener("keydown", event => {
const tag = document.activeElement?.tagName;
if (tag === "BUTTON" || tag === "INPUT") return;
let handled = true;
switch (event.key) {
case "ArrowLeft":
spherical.theta += 0.08;
break;
case "ArrowRight":
spherical.theta -= 0.08;
break;
case "ArrowUp":
spherical.phi = Math.max(0.32, spherical.phi - 0.06);
break;
case "ArrowDown":
spherical.phi = Math.min(1.47, spherical.phi + 0.06);
break;
case "+":
case "=":
spherical.radius = Math.max(9, spherical.radius - 1);
break;
case "-":
case "_":
spherical.radius = Math.min(42, spherical.radius + 1);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
// -------------------------------------------------------------------------
// Projected DOM labels
// -------------------------------------------------------------------------
const orderedLabel = document.querySelector("#orderedLabel");
const amorphousLabel = document.querySelector("#amorphousLabel");
const orderedLabelPosition = new THREE.Vector3(-3.9, 3.25, 0);
const amorphousLabelPosition = new THREE.Vector3(3.9, 3.25, 0);
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
element.hidden = !visible;
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// -------------------------------------------------------------------------
// 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, 1.8));
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
function animate() {
requestAnimationFrame(animate);
positionLabel(orderedLabel, orderedLabelPosition);
positionLabel(amorphousLabel, amorphousLabelPosition);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```