Prompt specification
Build or customize the Three.js 3D scene "Equilibrium museum exchange station" 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: Equilibrium museum exchange station
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/equilibrium-museum-exchange-station-x1935
Scene Description Prompt:
Build a voxel equilibrium exhibit with continuously exchanging token conveyors and steady populations, explicitly labeling the chemical analogy. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (equilibrium-museum-exchange-station-x1935):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Equilibrium — Dynamic Chemical Analogy</title>
<style>
:root {
--bg: #07101d;
--panel: rgba(10, 20, 36, 0.82);
--line: rgba(148, 184, 214, 0.2);
--text: #edf7ff;
--muted: #91a8bd;
--cyan: #22d3ee;
--green: #34d399;
--orange: #ffb347;
--violet: #a78bfa;
--pink: #f472b6;
}
* {
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;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
pointer-events: auto;
border: 1px solid var(--line);
background: var(--panel);
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.34),
inset 0 1px 0 rgba(255, 255, 255, 0.045);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.title-panel {
top: 24px;
left: 24px;
width: min(440px, calc(100vw - 48px));
padding: 19px 21px 18px;
border-left: 3px solid var(--cyan);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 37px);
line-height: 0.98;
letter-spacing: -0.045em;
text-transform: uppercase;
}
.title-panel p {
margin: 11px 0 0;
max-width: 390px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.data-panel {
top: 24px;
right: 24px;
width: 330px;
padding: 18px;
}
.data-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.data-heading strong {
color: var(--green);
font-size: 10px;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.chip {
padding: 4px 7px;
border: 1px solid rgba(52, 211, 153, 0.28);
color: var(--green);
background: rgba(52, 211, 153, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.equation {
margin: 5px 0 9px;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 25px;
font-weight: 700;
letter-spacing: 0.02em;
text-align: center;
}
.equation .arrow {
color: var(--cyan);
padding: 0 7px;
}
.analogy-copy {
margin: 0 0 15px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
text-align: center;
}
.population-title {
margin: 14px 0 8px;
color: #c8d8e6;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.population-row {
display: grid;
grid-template-columns: 17px 1fr 34px;
align-items: center;
gap: 8px;
margin: 7px 0;
font-size: 11px;
}
.species {
width: 10px;
height: 10px;
justify-self: center;
box-shadow: 0 0 10px color-mix(in srgb, currentColor 45%, transparent);
}
.meter {
height: 5px;
overflow: hidden;
background: rgba(255, 255, 255, 0.075);
}
.meter span {
display: block;
width: 100%;
height: 100%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.count {
color: #dceaf5;
font-family: "SFMono-Regular", Consolas, monospace;
text-align: right;
}
.flux {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 15px;
}
.flux-cell {
padding: 10px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.025);
}
.flux-cell span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.flux-cell strong {
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 16px;
}
.equal-note {
margin-top: 11px;
padding: 9px 10px;
border: 1px solid rgba(52, 211, 153, 0.2);
background: rgba(52, 211, 153, 0.055);
color: #b9f3d9;
font-size: 10px;
line-height: 1.45;
text-align: center;
}
.legend-panel {
bottom: 25px;
left: 24px;
padding: 14px 16px;
}
.legend {
display: flex;
gap: 14px;
flex-wrap: wrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #c9d9e6;
font-size: 10px;
font-weight: 700;
}
.legend-item i {
width: 10px;
height: 10px;
display: inline-block;
box-shadow: 0 0 9px currentColor;
}
.legend-note {
margin-top: 9px;
color: #718ba1;
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.controls {
position: absolute;
right: 24px;
bottom: 25px;
display: flex;
gap: 7px;
pointer-events: auto;
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 0;
outline: none;
background: rgba(10, 20, 36, 0.88);
color: #d8e7f3;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition:
border-color 160ms ease,
color 160ms ease,
background 160ms ease;
}
button:hover {
border-color: rgba(34, 211, 238, 0.6);
color: white;
background: rgba(17, 35, 55, 0.95);
}
button:focus-visible {
box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.25);
}
#status {
position: absolute;
left: 50%;
bottom: 25px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
border: 1px solid rgba(52, 211, 153, 0.26);
background: rgba(8, 25, 28, 0.84);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.28);
color: #bdf5da;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px var(--green);
animation: breathe 1.8s ease-in-out infinite;
}
#status.paused .status-dot {
background: var(--orange);
box-shadow: 0 0 12px var(--orange);
animation: none;
}
#camera-hint {
position: absolute;
left: 50%;
top: 23px;
transform: translateX(-50%);
padding: 7px 10px;
color: rgba(178, 200, 218, 0.66);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#labels-layer {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
min-width: 145px;
padding: 8px 10px;
border: 1px solid rgba(148, 184, 214, 0.25);
background: rgba(7, 16, 29, 0.83);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
color: #dceaf5;
font-size: 9px;
line-height: 1.35;
letter-spacing: 0.08em;
text-transform: uppercase;
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
backdrop-filter: blur(8px);
}
.world-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 15px;
background: rgba(148, 184, 214, 0.4);
}
.world-label strong {
display: block;
margin-bottom: 3px;
color: white;
font-size: 10px;
}
.world-label.forward {
border-color: rgba(255, 179, 71, 0.42);
}
.world-label.forward strong {
color: var(--orange);
}
.world-label.reverse {
border-color: rgba(34, 211, 238, 0.42);
}
.world-label.reverse strong {
color: var(--cyan);
}
.world-label.exchange {
border-color: rgba(52, 211, 153, 0.44);
}
.world-label.exchange strong {
color: var(--green);
}
@keyframes breathe {
0%,
100% {
opacity: 0.45;
transform: scale(0.85);
}
50% {
opacity: 1;
transform: scale(1.12);
}
}
@media (max-width: 820px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
max-width: 360px;
}
.title-panel p,
#camera-hint,
.legend-panel {
display: none;
}
.data-panel {
top: auto;
right: 12px;
bottom: 66px;
width: 292px;
padding: 13px;
}
.population-title,
.population-row,
.equal-note {
display: none;
}
.equation {
font-size: 20px;
}
.controls {
right: 12px;
bottom: 12px;
}
#status {
left: 12px;
bottom: 62px;
transform: none;
max-width: calc(100vw - 326px);
overflow: hidden;
text-overflow: ellipsis;
}
.world-label {
display: none !important;
}
}
</style>
</head>
<body>
<div id="hud">
<section class="panel title-panel">
<div class="eyebrow">Interactive process exhibit</div>
<h1>Voxel<br />Equilibrium</h1>
<p>
Two continuously circulating token conveyors exchange matter in both
directions. The populations remain constant even as individual cubes
keep moving.
</p>
</section>
<section class="panel data-panel">
<div class="data-heading">
<strong>Chemical analogy</strong>
<span class="chip">Dynamic equilibrium</span>
</div>
<div class="equation">
A + B <span class="arrow">⇌</span> C + D
</div>
<p class="analogy-copy">
Each conveyor represents a reaction pathway. Equal forward and reverse
flux produces no net change in population.
</p>
<div class="population-title">Steady populations</div>
<div class="population-row">
<i class="species" style="color:#ffb347;background:#ffb347"></i>
<div class="meter" style="color:#ffb347"><span></span></div>
<b class="count">16</b>
</div>
<div class="population-row">
<i class="species" style="color:#a78bfa;background:#a78bfa"></i>
<div class="meter" style="color:#a78bfa"><span></span></div>
<b class="count">16</b>
</div>
<div class="population-row">
<i class="species" style="color:#22d3ee;background:#22d3ee"></i>
<div class="meter" style="color:#22d3ee"><span></span></div>
<b class="count">16</b>
</div>
<div class="population-row">
<i class="species" style="color:#34d399;background:#34d399"></i>
<div class="meter" style="color:#34d399"><span></span></div>
<b class="count">16</b>
</div>
<div class="flux">
<div class="flux-cell">
<span>Forward flux</span>
<strong style="color:#ffb347">8.0 tok/s</strong>
</div>
<div class="flux-cell">
<span>Reverse flux</span>
<strong style="color:#22d3ee">8.0 tok/s</strong>
</div>
</div>
<div class="equal-note">
Forward flux = reverse flux<br />
<strong>Active exchange, zero net population change.</strong>
</div>
</section>
<section class="panel legend-panel">
<div class="legend">
<div class="legend-item">
<i style="color:#ffb347;background:#ffb347"></i> A
</div>
<div class="legend-item">
<i style="color:#a78bfa;background:#a78bfa"></i> B
</div>
<div class="legend-item">
<i style="color:#22d3ee;background:#22d3ee"></i> C
</div>
<div class="legend-item">
<i style="color:#34d399;background:#34d399"></i> D
</div>
</div>
<div class="legend-note">Token model · not a quantum chemistry simulation</div>
</section>
<div id="camera-hint">Drag to orbit · scroll to zoom · double-click to reset</div>
<div id="status">
<i class="status-dot"></i>
<span id="status-text">At equilibrium · exchange active · populations constant</span>
</div>
<div class="controls">
<button id="pause-button" type="button">Pause</button>
<button id="labels-button" type="button">Hide labels</button>
<button id="reset-button" type="button">Reset view</button>
</div>
<div id="labels-layer">
<div class="world-label" id="label-left">
<strong>Reactant side</strong>
A + B
</div>
<div class="world-label" id="label-right">
<strong>Product side</strong>
C + D
</div>
<div class="world-label forward" id="label-forward">
<strong>Forward conveyor</strong>
A + B move right →
</div>
<div class="world-label reverse" id="label-reverse">
<strong>Reverse conveyor</strong>
← C + D move left
</div>
<div class="world-label exchange" id="label-exchange">
<strong>Exchange zone</strong>
Equal flux · no net change
</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07101d);
scene.fog = new THREE.FogExp2(0x07101d, 0.024);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0x9ddcff, 0x111522, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.4);
keyLight.position.set(7, 12, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x22d3ee, 24, 13, 2);
cyanLight.position.set(0, 5.2, 0.2);
scene.add(cyanLight);
const orangeLight = new THREE.PointLight(0xffb347, 19, 11, 2);
orangeLight.position.set(-4, 4.9, 2.2);
scene.add(orangeLight);
const greenLight = new THREE.PointLight(0x34d399, 18, 10, 2);
greenLight.position.set(4, 3.2, -0.8);
scene.add(greenLight);
const world = new THREE.Group();
scene.add(world);
const COLORS = {
A: 0xffb347,
B: 0xa78bfa,
C: 0x22d3ee,
D: 0x34d399,
cyan: 0x22d3ee,
green: 0x34d399,
orange: 0xffb347,
violet: 0xa78bfa,
metal: 0x182a3b,
dark: 0x0b1522,
pale: 0xb8d3e5
};
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.58,
metalness: options.metalness ?? 0.22,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
}
function addBox(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = world,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x66859d, opacity = 0.45) {
const edges = new THREE.EdgesGeometry(mesh.geometry);
const lines = new THREE.LineSegments(
edges,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
lines.position.copy(mesh.position);
lines.rotation.copy(mesh.rotation);
mesh.parent.add(lines);
return lines;
}
// -------------------------------------------------------------------------
// Platform and background
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
standardMaterial(0x07101a, { roughness: 0.9, metalness: 0.05 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.03;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(38, 38, 0x1b3a4b, 0x102333);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.4;
scene.add(grid);
const baseMaterial = standardMaterial(0x101d2a, {
roughness: 0.42,
metalness: 0.68
});
const sideMaterial = standardMaterial(0x14283a, {
roughness: 0.38,
metalness: 0.72
});
const trimMaterial = standardMaterial(0x1a6071, {
roughness: 0.32,
metalness: 0.75,
emissive: 0x0b3440,
emissiveIntensity: 0.55
});
addBox(14.5, 0.42, 5.1, baseMaterial, 0, 0.2, 0.25);
addBox(13.7, 0.25, 4.45, sideMaterial, 0, 0.52, 0.1);
addBox(13.9, 0.07, 0.09, trimMaterial, 0, 0.67, 2.33, world, false);
addBox(13.9, 0.07, 0.09, trimMaterial, 0, 0.67, -2.13, world, false);
// Small pedestal feet reinforce the voxel/block construction.
for (const x of [-6.2, 6.2]) {
for (const z of [-1.75, 2.15]) {
addBox(0.75, 0.55, 0.75, baseMaterial, x, 0.28, z);
}
}
// -------------------------------------------------------------------------
// Reactant and product reservoirs
// -------------------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(0.34, 0.34, 0.34);
const speciesMaterials = {
A: standardMaterial(COLORS.A, {
roughness: 0.38,
metalness: 0.15,
emissive: COLORS.A,
emissiveIntensity: 0.28
}),
B: standardMaterial(COLORS.B, {
roughness: 0.38,
metalness: 0.15,
emissive: COLORS.B,
emissiveIntensity: 0.28
}),
C: standardMaterial(COLORS.C, {
roughness: 0.38,
metalness: 0.15,
emissive: COLORS.C,
emissiveIntensity: 0.28
}),
D: standardMaterial(COLORS.D, {
roughness: 0.38,
metalness: 0.15,
emissive: COLORS.D,
emissiveIntensity: 0.28
})
};
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0x8ed7ee,
transparent: true,
opacity: 0.055,
roughness: 0.2,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
});
function makeReservoir(x, accentColor) {
const group = new THREE.Group();
group.position.set(x, 0, -0.35);
world.add(group);
addBox(3.75, 0.2, 3.15, baseMaterial, 0, 0.73, 0, group);
addBox(3.3, 3.2, 2.8, glassMaterial, 0, 2.38, 0, group, false);
const glass = group.children[group.children.length - 1];
addEdges(glass, accentColor, 0.48);
const frameMaterial = standardMaterial(0x385167, {
roughness: 0.35,
metalness: 0.8
});
// Corner columns.
for (const px of [-1.65, 1.65]) {
for (const pz of [-1.4, 1.4]) {
addBox(0.1, 3.3, 0.1, frameMaterial, px, 2.4, pz, group);
}
}
// Top and bottom frame rails.
for (const py of [0.8, 4.0]) {
addBox(3.4, 0.1, 0.1, frameMaterial, 0, py, -1.4, group);
addBox(3.4, 0.1, 0.1, frameMaterial, 0, py, 1.4, group);
addBox(0.1, 0.1, 2.8, frameMaterial, -1.65, py, 0, group);
addBox(0.1, 0.1, 2.8, frameMaterial, 1.65, py, 0, group);
}
const accent = standardMaterial(accentColor, {
roughness: 0.3,
metalness: 0.6,
emissive: accentColor,
emissiveIntensity: 0.6
});
addBox(3.1, 0.05, 0.06, accent, 0, 0.9, 1.43, group, false);
addBox(3.1, 0.05, 0.06, accent, 0, 3.94, 1.43, group, false);
// Dividing shelf.
addBox(2.9, 0.08, 2.45, sideMaterial, 0, 2.33, 0, group);
return group;
}
makeReservoir(-4.15, COLORS.orange);
makeReservoir(4.15, COLORS.green);
function addPopulationVoxels(x, typeA, typeB) {
const positionsA = [];
const positionsB = [];
for (let row = 0; row < 2; row++) {
for (let column = 0; column < 8; column++) {
const px = -1.22 + column * 0.348;
const py = 1.22 + row * 0.7;
positionsA.push([px, py, 0.48]);
positionsB.push([px, py + 1.4, -0.52]);
}
}
for (const [px, py, pz] of positionsA) {
const mesh = new THREE.Mesh(cubeGeometry, speciesMaterials[typeA]);
mesh.position.set(x + px, py, pz - 0.35);
mesh.castShadow = true;
mesh.receiveShadow = true;
world.add(mesh);
}
for (const [px, py, pz] of positionsB) {
const mesh = new THREE.Mesh(cubeGeometry, speciesMaterials[typeB]);
mesh.position.set(x + px, py, pz - 0.35);
mesh.castShadow = true;
mesh.receiveShadow = true;
world.add(mesh);
}
}
addPopulationVoxels(-4.15, "A", "B");
addPopulationVoxels(4.15, "C", "D");
// -------------------------------------------------------------------------
// Conveyor geometry and paths
// -------------------------------------------------------------------------
const beltTop = 4.48;
const tokenHeight = 4.76;
const beltMaterial = standardMaterial(0x0d1824, {
roughness: 0.62,
metalness: 0.45
});
const railMaterial = standardMaterial(0x476176, {
roughness: 0.3,
metalness: 0.85
});
function pathLength(path) {
let length = 0;
for (let i = 0; i < path.length; i++) {
const a = path[i];
const b = path[(i + 1) % path.length];
length += Math.hypot(b[0] - a[0], b[1] - a[1]);
}
return length;
}
function pointOnPath(path, distance) {
const total = pathLength(path);
for (let i = 0; i < path.length; i++) {
const a = path[i];
const b = path[(i + 1) % path.length];
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
if (distance <= length || i === path.length - 1) {
const t = length === 0 ? 0 : distance / length;
return {
x: a[0] + dx * t,
z: a[1] + dz * t,
tangentX: dx / length,
tangentZ: dz / length
};
}
distance -= length;
}
}
function buildBelt(path, accentColor) {
const accent = standardMaterial(accentColor, {
roughness: 0.3,
metalness: 0.55,
emissive: accentColor,
emissiveIntensity: 0.8
});
for (let i = 0; i < path.length; i++) {
const a = path[i];
const b = path[(i + 1) % path.length];
const midX = (a[0] + b[0]) / 2;
const midZ = (a[1] + b[1]) / 2;
const dx = Math.abs(b[0] - a[0]);
const dz = Math.abs(b[1] - a[1]);
if (dx > dz) {
addBox(dx, 0.16, 0.72, beltMaterial, midX, beltTop, midZ);
addBox(dx, 0.065, 0.055, accent, midX, beltTop + 0.1, midZ - 0.37, world, false);
addBox(dx, 0.065, 0.055, accent, midX, beltTop + 0.1, midZ + 0.37, world, false);
} else {
addBox(0.72, 0.16, dz, beltMaterial, midX, beltTop, midZ);
addBox(0.055, 0.065, dz, accent, midX - 0.37, beltTop + 0.1, midZ, world, false);
addBox(0.055, 0.065, dz, accent, midX + 0.37, beltTop + 0.1, midZ, world, false);
}
}
// Visible square supports.
for (const [x, z] of path) {
addBox(0.13, 3.65, 0.13, railMaterial, x, 2.43, z);
addBox(0.38, 0.12, 0.38, beltMaterial, x, 0.73, z);
}
}
const forwardPath = [
[-6.15, 2.15],
[6.15, 2.15],
[6.15, 1.03],
[-6.15, 1.03]
];
const reversePath = [
[5.65, 0.32],
[-5.65, 0.32],
[-5.65, -1.48],
[5.65, -1.48]
];
buildBelt(forwardPath, COLORS.orange);
buildBelt(reversePath, COLORS.cyan);
// Voxel-style directional arrows on the visible straight runs.
function makeArrow(x, z, direction, color) {
const group = new THREE.Group();
group.position.set(x, beltTop + 0.15, z);
group.rotation.y = direction > 0 ? 0 : Math.PI;
world.add(group);
const material = standardMaterial(color, {
roughness: 0.3,
metalness: 0.4,
emissive: color,
emissiveIntensity: 1.2
});
addBox(0.48, 0.045, 0.08, material, 0, 0, 0, group, false);
const headA = addBox(
0.25,
0.045,
0.08,
material,
0.2,
0,
0.13,
group,
false
);
headA.rotation.y = Math.PI / 4;
const headB = addBox(
0.25,
0.045,
0.08,
material,
0.2,
0,
-0.13,
group,
false
);
headB.rotation.y = -Math.PI / 4;
}
for (const x of [-3.8, 0, 3.8]) {
makeArrow(x, 2.15, 1, COLORS.orange);
makeArrow(x, 0.32, -1, COLORS.cyan);
}
// -------------------------------------------------------------------------
// Exchange gate
// -------------------------------------------------------------------------
const gateMaterial = standardMaterial(0x34d399, {
roughness: 0.28,
metalness: 0.65,
emissive: 0x34d399,
emissiveIntensity: 1.1
});
const gateFrameMaterial = standardMaterial(0x42637a, {
roughness: 0.3,
metalness: 0.82
});
for (const z of [-0.12, 2.58]) {
addBox(0.16, 1.3, 0.16, gateFrameMaterial, 0, 5.07, z);
}
addBox(0.16, 0.16, 2.85, gateFrameMaterial, 0, 5.72, 1.23);
addBox(0.08, 1.05, 0.08, gateMaterial, 0, 5.02, -0.12, world, false);
addBox(0.08, 1.05, 0.08, gateMaterial, 0, 5.02, 2.58, world, false);
const scanner = addBox(
0.48,
0.12,
0.48,
standardMaterial(0x8fffcf, {
roughness: 0.2,
metalness: 0.3,
emissive: 0x8fffcf,
emissiveIntensity: 3
}),
0,
5.1,
1.23,
world,
false
);
const gateCore = addBox(
0.18,
0.18,
2.1,
standardMaterial(0x34d399, {
transparent: true,
opacity: 0.16,
emissive: 0x34d399,
emissiveIntensity: 1.5
}),
0,
4.95,
1.23,
world,
false
);
// -------------------------------------------------------------------------
// Moving token conveyors
// -------------------------------------------------------------------------
const tokenGeometry = new THREE.BoxGeometry(0.31, 0.31, 0.31);
const tokenOutlineGeometry = new THREE.EdgesGeometry(tokenGeometry);
const movingTokens = [];
function makeMovingToken(type, path, index, count) {
const group = new THREE.Group();
world.add(group);
const core = new THREE.Mesh(tokenGeometry, speciesMaterials[type]);
core.castShadow = true;
core.receiveShadow = true;
group.add(core);
const outline = new THREE.LineSegments(
tokenOutlineGeometry,
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.34
})
);
group.add(outline);
movingTokens.push({
group,
path,
type,
index,
offset: (index / count) * pathLength(path),
previousX: 0,
firstFrame: true
});
}
for (let i = 0; i < 16; i++) {
makeMovingToken(i % 2 === 0 ? "A" : "B", forwardPath, i, 16);
makeMovingToken(i % 2 === 0 ? "C" : "D", reversePath, i, 16);
}
// -------------------------------------------------------------------------
// Ambient voxel particles
// -------------------------------------------------------------------------
const dustMaterial = standardMaterial(0x5c8ca5, {
roughness: 0.8,
metalness: 0,
emissive: 0x153749,
emissiveIntensity: 0.4
});
const dust = [];
for (let i = 0; i < 38; i++) {
const size = 0.025 + Math.random() * 0.055;
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size, size, size),
dustMaterial
);
mesh.position.set(
(Math.random() - 0.5) * 23,
0.6 + Math.random() * 9,
(Math.random() - 0.5) * 15
);
world.add(mesh);
dust.push({
mesh,
speed: 0.1 + Math.random() * 0.18,
phase: Math.random() * Math.PI * 2,
baseY: mesh.position.y
});
}
// -------------------------------------------------------------------------
// Direct camera controls — no Three.js addons
// -------------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 2.35, 0),
radius: 17.6,
theta: 0.29,
phi: 1.08
};
const initialOrbit = {
radius: orbit.radius,
theta: orbit.theta,
phi: orbit.phi
};
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);
}
function resetCamera() {
orbit.radius = initialOrbit.radius;
orbit.theta = initialOrbit.theta;
orbit.phi = initialOrbit.phi;
updateCamera();
}
updateCamera();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.theta -= dx * 0.0052;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.0045,
0.45,
1.42
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("pointerleave", endDrag);
renderer.domElement.style.cursor = "grab";
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
10.5,
27
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// HUD interaction and projected labels
// -------------------------------------------------------------------------
const pauseButton = document.getElementById("pause-button");
const labelsButton = document.getElementById("labels-button");
const resetButton = document.getElementById("reset-button");
const status = document.getElementById("status");
const statusText = document.getElementById("status-text");
let running = true;
let labelsEnabled = true;
pauseButton.addEventListener("click", () => {
running = !running;
pauseButton.textContent = running ? "Pause" : "Resume";
status.classList.toggle("paused", !running);
statusText.textContent = running
? "At equilibrium · exchange active · populations constant"
: "Paused · populations remain steady · conveyor motion suspended";
});
labelsButton.addEventListener("click", () => {
labelsEnabled = !labelsEnabled;
labelsButton.textContent = labelsEnabled ? "Hide labels" : "Show labels";
document
.getElementById("labels-layer")
.classList.toggle("labels-disabled", !labelsEnabled);
});
resetButton.addEventListener("click", resetCamera);
const labels = [
{
element: document.getElementById("label-left"),
position: new THREE.Vector3(-4.15, 4.18, -0.35)
},
{
element: document.getElementById("label-right"),
position: new THREE.Vector3(4.15, 4.18, -0.35)
},
{
element: document.getElementById("label-forward"),
position: new THREE.Vector3(-2.75, 5.08, 2.15)
},
{
element: document.getElementById("label-reverse"),
position: new THREE.Vector3(2.75, 5.08, 0.32)
},
{
element: document.getElementById("label-exchange"),
position: new THREE.Vector3(0, 5.9, 1.23)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible =
labelsEnabled &&
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
label.element.style.visibility = visible ? "visible" : "hidden";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let simulationTime = 0;
let exchangePulse = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (running) {
simulationTime += delta;
exchangePulse *= Math.pow(0.025, delta);
}
const conveyorSpeed = 1.12;
for (const token of movingTokens) {
const distance =
(token.offset + simulationTime * conveyorSpeed) % pathLength(token.path);
const point = pointOnPath(token.path, distance);
if (
!token.firstFrame &&
((token.previousX < 0 && point.x >= 0) ||
(token.previousX > 0 && point.x <= 0))
) {
exchangePulse = Math.min(1, exchangePulse + 0.32);
}
token.previousX = point.x;
token.firstFrame = false;
token.group.position.set(
point.x,
tokenHeight + Math.sin(simulationTime * 3.2 + token.index) * 0.018,
point.z
);
token.group.rotation.y =
Math.atan2(point.tangentZ, point.tangentX) +
Math.sin(simulationTime * 1.5 + token.index) * 0.045;
}
const pulse = Math.sin(simulationTime * 3.3) * 0.5 + 0.5;
const gateIntensity = 1.1 + pulse * 0.7 + exchangePulse * 4;
gateMaterial.emissiveIntensity = gateIntensity;
gateCore.material.emissiveIntensity = 1.2 + exchangePulse * 4;
scanner.material.emissiveIntensity = 2.4 + exchangePulse * 4;
cyanLight.intensity = 22 + exchangePulse * 18;
scanner.position.y = 4.72 + ((simulationTime * 0.8) % 1) * 0.95;
scanner.rotation.y = simulationTime * 1.7;
gateCore.scale.y = 1 + exchangePulse * 0.65;
for (const particle of dust) {
particle.mesh.position.y =
particle.baseY + Math.sin(simulationTime * particle.speed + particle.phase) * 0.22;
particle.mesh.rotation.x += delta * 0.12;
particle.mesh.rotation.y += delta * 0.16;
}
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```