Prompt specification
Build or customize the Three.js 3D scene "Food digestion enzyme gallery" 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: Food digestion enzyme gallery
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/food-digestion-enzyme-gallery-x0847
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Compose enlarged schematic enzyme stations processing different food-molecule models; identify illustrative substrates and products while avoiding literal lock-and-key claims for all real enzyme behavior.
Working Three.js Starter (food-digestion-enzyme-gallery-x0847):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Food-Enzyme Stations</title>
<style>
:root {
color-scheme: dark;
--bg: #07111e;
--panel: #0b1828;
--panel-2: #102238;
--line: #24415e;
--text: #e8f4ff;
--muted: #8fa8bf;
--cyan: #63e6d7;
}
* {
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 {
display: grid;
grid-template-columns: minmax(0, 1fr) 340px;
}
button {
font: inherit;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 45% 35%, #122942 0, #081522 46%, #050c15 100%);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#labels {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
width: 210px;
padding: 8px 10px;
transform: translate(-50%, -100%);
border: 1px solid rgba(111, 205, 218, 0.26);
border-radius: 8px;
background: rgba(5, 15, 27, 0.88);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.28);
text-align: center;
backdrop-filter: blur(8px);
will-change: left, top;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 14px;
background: linear-gradient(var(--cyan), transparent);
}
.world-label strong {
display: block;
color: var(--station-color, var(--cyan));
font-size: 11px;
letter-spacing: 0.13em;
}
.world-label small {
display: block;
margin-top: 3px;
color: #bed1e2;
font-size: 9px;
line-height: 1.3;
}
.world-label .status {
display: block;
margin-top: 5px;
color: #839bb0;
font-size: 8px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.world-label .status::before {
content: "";
display: inline-block;
width: 5px;
height: 5px;
margin-right: 5px;
border-radius: 50%;
background: var(--station-color, var(--cyan));
box-shadow: 0 0 8px var(--station-color, var(--cyan));
vertical-align: 1px;
}
#hud {
position: absolute;
z-index: 5;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.title-block {
max-width: 560px;
padding: 13px 15px;
border: 1px solid rgba(108, 178, 207, 0.2);
border-radius: 10px;
background: rgba(5, 14, 25, 0.76);
backdrop-filter: blur(10px);
}
.eyebrow {
margin-bottom: 5px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(19px, 2.3vw, 29px);
line-height: 1.08;
letter-spacing: -0.025em;
}
.subtitle {
margin-top: 7px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.toolbar {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 6px;
pointer-events: auto;
}
.toolbar button {
min-height: 34px;
padding: 7px 10px;
border: 1px solid #294760;
border-radius: 7px;
background: rgba(9, 24, 40, 0.9);
color: #cde4f5;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.toolbar button:hover {
border-color: var(--cyan);
background: #102a40;
transform: translateY(-1px);
}
.toolbar button:focus-visible,
.station-card:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
#legend {
position: absolute;
z-index: 4;
left: 20px;
bottom: 16px;
display: flex;
flex-wrap: wrap;
gap: 10px 14px;
max-width: calc(100% - 40px);
padding: 8px 11px;
border: 1px solid rgba(108, 178, 207, 0.17);
border-radius: 8px;
background: rgba(5, 14, 25, 0.76);
color: #91a9bd;
font-size: 9px;
pointer-events: none;
backdrop-filter: blur(8px);
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 5px;
white-space: nowrap;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
#loading {
position: absolute;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #07111e;
color: var(--cyan);
font-size: 13px;
letter-spacing: 0.08em;
}
aside {
position: relative;
z-index: 10;
min-height: 0;
overflow-y: auto;
padding: 20px 16px;
border-left: 1px solid #1d3349;
background:
linear-gradient(180deg, rgba(15, 35, 55, 0.96), rgba(7, 18, 31, 0.98));
box-shadow: -18px 0 50px rgba(0, 0, 0, 0.18);
}
aside h2 {
margin: 0 0 5px;
font-size: 16px;
letter-spacing: -0.01em;
}
.panel-intro {
margin: 0 0 15px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
#station-list {
display: grid;
gap: 9px;
}
.station-card {
width: 100%;
padding: 12px;
border: 1px solid #203a53;
border-radius: 9px;
background: rgba(13, 32, 51, 0.78);
color: var(--text);
text-align: left;
cursor: pointer;
transition:
border-color 150ms ease,
transform 150ms ease,
background 150ms ease;
}
.station-card:hover,
.station-card.active {
border-color: var(--card-color);
background: rgba(18, 42, 64, 0.92);
transform: translateX(-2px);
}
.station-card .card-head {
display: flex;
align-items: center;
gap: 8px;
}
.station-card .number {
display: grid;
width: 24px;
height: 24px;
place-items: center;
border-radius: 5px;
background: var(--card-color);
color: #07111e;
font-size: 10px;
font-weight: 900;
}
.station-card strong {
font-size: 11px;
letter-spacing: 0.09em;
}
.station-card p {
margin: 8px 0 0;
color: #b3c8d9;
font-size: 10px;
line-height: 1.5;
}
.station-card .arrow {
margin: 0 5px;
color: var(--card-color);
}
.note {
margin-top: 16px;
padding: 12px;
border: 1px solid #2a4b61;
border-radius: 9px;
background: rgba(10, 29, 43, 0.75);
}
.note h3 {
margin: 0 0 7px;
color: #f4d58a;
font-size: 11px;
letter-spacing: 0.04em;
}
.note p {
margin: 0;
color: #9eb4c6;
font-size: 10px;
line-height: 1.55;
}
.controls-note {
margin-top: 14px;
color: #7890a6;
font-size: 9px;
line-height: 1.6;
}
kbd {
padding: 1px 4px;
border: 1px solid #304a61;
border-radius: 3px;
background: #10263b;
color: #bcd4e7;
font: inherit;
}
@media (max-width: 820px) {
body {
grid-template-columns: 1fr;
grid-template-rows: minmax(0, 1fr) 245px;
}
aside {
padding: 12px 14px;
border-top: 1px solid #1d3349;
border-left: 0;
}
#station-list {
grid-template-columns: repeat(4, minmax(190px, 1fr));
overflow-x: auto;
padding-bottom: 5px;
}
.note {
display: none;
}
.panel-intro {
margin-bottom: 8px;
}
#hud {
top: 10px;
left: 10px;
right: 10px;
}
.title-block {
padding: 10px 11px;
}
.subtitle {
display: none;
}
.toolbar {
max-width: 150px;
}
.toolbar button {
min-height: 30px;
padding: 5px 7px;
font-size: 10px;
}
#legend {
left: 10px;
bottom: 9px;
max-width: calc(100% - 20px);
}
.world-label {
width: 165px;
padding: 6px 7px;
}
.world-label small {
font-size: 8px;
}
}
@media (max-width: 520px) {
body {
grid-template-rows: minmax(0, 1fr) 220px;
}
#hud {
align-items: flex-start;
}
.title-block {
max-width: 190px;
}
h1 {
font-size: 16px;
}
.eyebrow {
font-size: 8px;
}
.toolbar {
max-width: 126px;
}
.toolbar button {
font-size: 9px;
}
#legend {
display: none;
}
}
</style>
</head>
<body>
<main id="viewport">
<div id="loading">Loading the voxel enzyme laboratory…</div>
<div id="hud">
<section class="title-block">
<div class="eyebrow">Conceptual food-processing schematic</div>
<h1>Voxel Enzyme Stations</h1>
<div class="subtitle">
Enlarged, non-literal models of food molecules moving through
illustrative active sites.
</div>
</section>
<nav class="toolbar" aria-label="Scene controls">
<button id="pause" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
<button id="next" type="button">Next station</button>
<button id="reset" type="button">Reset view</button>
</nav>
</div>
<div id="labels" aria-hidden="true"></div>
<div id="legend" aria-label="Molecular model legend">
<span class="legend-item">
<i class="swatch" style="background:#e8c36a"></i>carbon-like nodes
</span>
<span class="legend-item">
<i class="swatch" style="background:#ff6b6b"></i>oxygen-like nodes
</span>
<span class="legend-item">
<i class="swatch" style="background:#edf7ff"></i>hydrogen-like nodes
</span>
<span class="legend-item">
<i class="swatch" style="background:#5f7488"></i>bonds / scaffold
</span>
<span class="legend-item">Drag: orbit · wheel: zoom · right-drag: pan</span>
</div>
</main>
<aside>
<h2>Station guide</h2>
<p class="panel-intro">
Select a card to focus its station. The moving cube assemblies are
symbolic molecular models rather than chemically exact structures.
</p>
<div id="station-list">
<button class="station-card" type="button" data-station="0" style="--card-color:#f5bd58">
<span class="card-head">
<span class="number">01</span>
<strong>AMYLASE</strong>
</span>
<p>
Illustrative substrate: starch-like polymer<br />
<span class="arrow">→</span> maltose-like fragments
</p>
</button>
<button class="station-card" type="button" data-station="1" style="--card-color:#69d8ff">
<span class="card-head">
<span class="number">02</span>
<strong>LACTASE</strong>
</span>
<p>
Illustrative substrate: lactose-like disaccharide<br />
<span class="arrow">→</span> glucose-like + galactose-like units
</p>
</button>
<button class="station-card" type="button" data-station="2" style="--card-color:#d996ff">
<span class="card-head">
<span class="number">03</span>
<strong>SUCRASE</strong>
</span>
<p>
Illustrative substrate: sucrose-like disaccharide<br />
<span class="arrow">→</span> glucose-like + fructose-like units
</p>
</button>
<button class="station-card" type="button" data-station="3" style="--card-color:#ff8f70">
<span class="card-head">
<span class="number">04</span>
<strong>LIPASE</strong>
</span>
<p>
Illustrative substrate: triglyceride-like lipid<br />
<span class="arrow">→</span> glycerol-like + fatty-acid chains
</p>
</button>
</div>
<section class="note">
<h3>Important biological caveat</h3>
<p>
Enzymes are not universal literal lock-and-key molds. Recognition and
catalysis depend on flexible three-dimensional shape, charge, polarity,
solvent conditions, and reaction chemistry. These broad, open pockets
and product models are teaching devices, not structural claims about
every real enzyme or reaction.
</p>
</section>
<div class="controls-note">
Click a scene station or guide card to zoom in.
<br />
<kbd>Space</kbd> pauses animation; <kbd>R</kbd> resets the camera.
<br />
On touch screens, use one finger to orbit and two fingers to zoom/pan.
</div>
</aside>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const labelsLayer = document.getElementById("labels");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111e);
scene.fog = new THREE.Fog(0x07111e, 19, 42);
const camera = new THREE.OrthographicCamera(-12, 12, 8, -8, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xbdeeff, 0x172033, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -18;
keyLight.shadow.camera.right = 18;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 38;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58bfff, 1.4);
rimLight.position.set(10, 7, -10);
scene.add(rimLight);
const warmLight = new THREE.DirectionalLight(0xffc878, 0.7);
warmLight.position.set(-11, 4, -5);
scene.add(warmLight);
const unitCube = new THREE.BoxGeometry(1, 1, 1);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.72,
metalness: options.metalness ?? 0.04,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
const materials = {
carbon: material(0xe8c36a, { roughness: 0.62 }),
oxygen: material(0xff6b6b, { roughness: 0.58 }),
hydrogen: material(0xedf7ff, { roughness: 0.8 }),
bond: material(0x61788a, { roughness: 0.8 }),
darkBond: material(0x30485b, { roughness: 0.88 }),
belt: material(0x142c3d, { roughness: 0.9 }),
beltEdge: material(0x31546b, { roughness: 0.75 }),
frame: material(0x24465c, { roughness: 0.65, metalness: 0.22 }),
floor: material(0x0a1927, { roughness: 0.96 })
};
function block(parent, position, size, mat, castShadow = true) {
const mesh = new THREE.Mesh(unitCube, mat);
mesh.position.set(position[0], position[1], position[2]);
mesh.scale.set(size[0], size[1], size[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function atom(parent, x, y, z, mat, size = 0.16) {
return block(parent, [x, y, z], [size, size, size], mat);
}
function bond(parent, a, b, mat = materials.bond, width = 0.065) {
const start = new THREE.Vector3(a[0], a[1], a[2]);
const end = new THREE.Vector3(b[0], b[1], b[2]);
const direction = end.clone().sub(start);
const length = direction.length();
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const mesh = new THREE.Mesh(unitCube, mat);
mesh.position.copy(midpoint);
mesh.scale.set(width, length, width);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function sugarRing(parent, center, radius, oxygenIndices = [0, 4]) {
const points = [
[0, -radius],
[radius * 0.866, -radius * 0.5],
[radius * 0.866, radius * 0.5],
[0, radius],
[-radius * 0.866, radius * 0.5],
[-radius * 0.866, -radius * 0.5]
];
const worldPoints = points.map((p) => [
center[0] + p[0],
center[1] + p[1],
center[2]
]);
worldPoints.forEach((p, index) => {
const mat = oxygenIndices.includes(index)
? materials.oxygen
: materials.carbon;
atom(parent, p[0], p[1], p[2], mat, 0.155);
});
for (let i = 0; i < worldPoints.length; i++) {
bond(
parent,
worldPoints[i],
worldPoints[(i + 1) % worldPoints.length],
materials.bond,
0.06
);
}
[1, 2, 3].forEach((index) => {
if (oxygenIndices.includes(index)) return;
const p = worldPoints[index];
const outward = new THREE.Vector3(
p[0] - center[0],
p[1] - center[1],
0
).normalize();
const h = [
p[0] + outward.x * 0.23,
p[1] + outward.y * 0.23,
p[2]
];
atom(parent, h[0], h[1], h[2], materials.hydrogen, 0.105);
bond(parent, p, h, materials.darkBond, 0.04);
});
return worldPoints;
}
function makeSingleSugar(type = "glucose") {
const group = new THREE.Group();
const oxygenIndices =
type === "fructose" ? [0, 3] :
type === "galactose" ? [1, 4] :
[0, 4];
sugarRing(group, [0, 0, 0], 0.37, oxygenIndices);
return group;
}
function makeDisaccharide(type) {
const group = new THREE.Group();
const firstOxygen =
type === "sucrose" ? [0, 4] :
type === "lactose" ? [1, 4] :
[0, 4];
const secondOxygen =
type === "sucrose" ? [0, 3] :
type === "lactose" ? [0, 4] :
[1, 4];
const left = sugarRing(group, [-0.36, 0.02, 0], 0.32, firstOxygen);
const right = sugarRing(group, [0.36, -0.02, 0], 0.32, secondOxygen);
bond(group, left[1], right[4], materials.darkBond, 0.055);
return group;
}
function makeStarchLike() {
const group = new THREE.Group();
const points = [
[-0.9, 0.0, 0],
[-0.58, 0.13, 0],
[-0.25, -0.02, 0],
[0.08, 0.1, 0],
[0.42, -0.03, 0],
[0.75, 0.12, 0],
[-0.25, -0.02, 0],
[-0.25, 0.38, 0],
[-0.52, 0.68, 0],
[0.08, 0.1, 0],
[0.42, 0.52, 0],
[0.75, 0.82, 0]
];
const unique = [...new Map(points.map((p) => [p.join(","), p])).values()];
unique.forEach((p, i) => {
atom(
group,
p[0],
p[1],
p[2],
i % 5 === 3 ? materials.oxygen : materials.carbon,
0.15
);
});
[
[0, 1], [1, 2], [2, 3], [3, 4], [4, 5],
[2, 6], [6, 7], [7, 8],
[3, 9], [9, 10], [10, 11]
].forEach(([a, b]) => bond(group, points[a], points[b]));
return group;
}
function makeMaltoseLike() {
const group = new THREE.Group();
const left = sugarRing(group, [-0.28, 0, 0], 0.26, [0, 4]);
const right = sugarRing(group, [0.28, 0, 0], 0.26, [0, 4]);
bond(group, left[1], right[4], materials.darkBond, 0.045);
return group;
}
function makeGlycerolLike() {
const group = new THREE.Group();
const a = [-0.25, -0.12, 0];
const b = [0.25, -0.12, 0];
const c = [0, 0.28, 0];
atom(group, ...a, materials.carbon, 0.15);
atom(group, ...b, materials.carbon, 0.15);
atom(group, ...c, materials.carbon, 0.15);
atom(group, -0.52, -0.12, 0, materials.oxygen, 0.12);
atom(group, 0.52, -0.12, 0, materials.oxygen, 0.12);
bond(group, a, b);
bond(group, a, c);
bond(group, b, c);
bond(group, a, [-0.52, -0.12, 0]);
bond(group, b, [0.52, -0.12, 0]);
return group;
}
function makeFattyAcidLike() {
const group = new THREE.Group();
for (let row = 0; row < 3; row++) {
const y = (row - 1) * 0.34;
const points = [
[-0.72, y, 0],
[-0.42, y + 0.04, 0],
[-0.1, y - 0.02, 0],
[0.22, y + 0.03, 0],
[0.54, y - 0.01, 0],
[0.82, y + 0.02, 0]
];
points.forEach((p, index) => {
atom(
group,
p[0],
p[1],
p[2],
index === points.length - 1
? materials.oxygen
: materials.carbon,
0.115
);
});
for (let i = 0; i < points.length - 1; i++) {
bond(group, points[i], points[i + 1], materials.darkBond, 0.042);
}
}
return group;
}
function makeTriglycerideLike() {
const group = new THREE.Group();
const centerA = [-0.22, -0.08, 0];
const centerB = [0.22, -0.08, 0];
const centerC = [0, 0.28, 0];
[centerA, centerB, centerC].forEach((p) =>
atom(group, p[0], p[1], p[2], materials.carbon, 0.15)
);
bond(group, centerA, centerB);
bond(group, centerA, centerC);
bond(group, centerB, centerC);
const tails = [
[
[-0.48, 0.12, 0],
[-0.76, 0.42, 0],
[-1.02, 0.72, 0]
],
[
[0.48, 0.12, 0],
[0.76, 0.42, 0],
[1.02, 0.72, 0]
],
[
[0, 0.55, 0],
[0.28, 0.86, 0],
[0.56, 1.14, 0]
]
];
const roots = [centerA, centerB, centerC];
tails.forEach((tail, tailIndex) => {
const chain = [roots[tailIndex], ...tail];
chain.forEach((p, index) => {
atom(
group,
p[0],
p[1],
p[2],
index === 1 ? materials.oxygen : materials.carbon,
index === 1 ? 0.12 : 0.135
);
});
for (let i = 0; i < chain.length - 1; i++) {
bond(group, chain[i], chain[i + 1]);
}
});
return group;
}
const stationDefinitions = [
{
name: "AMYLASE",
substrate: "starch-like polymer",
product: "maltose-like fragments",
color: 0xf5bd58,
x: -7.5,
offset: 0,
makeSubstrate: makeStarchLike,
makeProducts: [makeMaltoseLike, makeMaltoseLike]
},
{
name: "LACTASE",
substrate: "lactose-like disaccharide",
product: "glucose-like + galactose-like units",
color: 0x69d8ff,
x: -2.5,
offset: 2.25,
makeSubstrate: () => makeDisaccharide("lactose"),
makeProducts: [
() => makeSingleSugar("glucose"),
() => makeSingleSugar("galactose")
]
},
{
name: "SUCRASE",
substrate: "sucrose-like disaccharide",
product: "glucose-like + fructose-like units",
color: 0xd996ff,
x: 2.5,
offset: 4.5,
makeSubstrate: () => makeDisaccharide("sucrose"),
makeProducts: [
() => makeSingleSugar("glucose"),
() => makeSingleSugar("fructose")
]
},
{
name: "LIPASE",
substrate: "triglyceride-like lipid",
product: "glycerol-like + fatty-acid chains",
color: 0xff8f70,
x: 7.5,
offset: 6.75,
makeSubstrate: makeTriglycerideLike,
makeProducts: [makeGlycerolLike, makeFattyAcidLike]
}
];
// Ground and tiled conveyor.
block(scene, [0, -0.2, 0], [32, 0.25, 17], materials.floor, false);
const grid = new THREE.GridHelper(40, 40, 0x1a3950, 0x10283b);
grid.position.y = -0.055;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
for (let x = -11.8; x <= 11.8; x += 0.52) {
block(
scene,
[x, 0.87, 0],
[0.45, 0.18, 2.25],
materials.belt,
false
);
}
block(scene, [0, 0.95, -1.22], [24.3, 0.14, 0.15], materials.beltEdge);
block(scene, [0, 0.95, 1.22], [24.3, 0.14, 0.15], materials.beltEdge);
block(scene, [0, 0.58, -1.22], [24.3, 0.1, 0.12], materials.frame);
block(scene, [0, 0.58, 1.22], [24.3, 0.1, 0.12], materials.frame);
for (let x = -10.5; x <= 10.5; x += 2.5) {
block(scene, [x, 0.37, -0.85], [0.18, 0.7, 0.18], materials.frame);
block(scene, [x, 0.37, 0.85], [0.18, 0.7, 0.18], materials.frame);
}
const hitTargets = [];
const stationElements = [];
const cards = [...document.querySelectorAll(".station-card")];
function makeEnzyme(station) {
const group = new THREE.Group();
group.position.x = station.x;
scene.add(group);
const baseColor = new THREE.Color(station.color);
const pale = baseColor.clone().lerp(new THREE.Color(0xffffff), 0.72);
const mid = baseColor.clone().lerp(new THREE.Color(0xffffff), 0.48);
const deep = baseColor.clone().lerp(new THREE.Color(0x0b2638), 0.48);
const shellMats = [
material(pale, { roughness: 0.64 }),
material(mid, { roughness: 0.7 }),
material(deep, { roughness: 0.78 })
];
const activeMat = material(station.color, {
roughness: 0.48,
emissive: station.color,
emissiveIntensity: 0.2
});
// A deliberately open, irregular cavity: not an exact-fit lock.
for (let ix = -4; ix <= 4; ix++) {
for (let iy = 0; iy <= 5; iy++) {
for (let iz = -2; iz <= 1; iz++) {
const dx = ix / 3.7;
const dy = (iy - 2.8) / 2.9;
const dz = (iz + 0.4) / 1.8;
const inside = dx * dx + dy * dy + dz * dz < 0.95;
const inOpenCavity =
iy < 3 &&
iz >= 0 &&
Math.abs(ix) <= 2;
if (!inside || inOpenCavity) continue;
const shade = (ix + iy + iz + 9) % 5;
const mat = shade === 0 ? shellMats[2] :
shade < 3 ? shellMats[0] :
shellMats[1];
block(
group,
[ix * 0.49, 1.42 + iy * 0.49, -1.18 + iz * 0.49],
[0.48, 0.48, 0.48],
mat
);
}
}
}
// Colored groups around the broad pocket communicate chemical variety.
const activeMarkers = [
[-0.88, 1.72, -0.28],
[-0.48, 1.49, -0.18],
[0.52, 1.50, -0.19],
[0.91, 1.77, -0.30],
[-0.30, 2.12, -0.18],
[0.30, 2.18, -0.18]
];
activeMarkers.forEach((p, index) => {
block(group, p, [0.24, 0.24, 0.24], activeMat, false);
if (index % 2 === 0) {
block(
group,
[p[0], p[1] - 0.18, p[2]],
[0.13, 0.13, 0.13],
materials.oxygen,
false
);
}
});
// Structural station frame behind the enlarged enzyme.
block(group, [-2.05, 2.35, -2.05], [0.16, 3.6, 0.16], materials.frame);
block(group, [2.05, 2.35, -2.05], [0.16, 3.6, 0.16], materials.frame);
block(group, [0, 4.16, -2.05], [4.25, 0.16, 0.16], materials.frame);
block(group, [0, 0.18, -1.08], [4.8, 0.26, 3.3], materials.frame);
const statusLampMat = material(station.color, {
emissive: station.color,
emissiveIntensity: 0.75
});
block(group, [0, 4.39, -1.82], [0.22, 0.22, 0.22], statusLampMat, false);
const light = new THREE.PointLight(station.color, 0.25, 4.2, 2);
light.position.set(0, 2.0, 0.3);
group.add(light);
const hitbox = new THREE.Mesh(
new THREE.BoxGeometry(4.8, 5.4, 4.2),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
})
);
hitbox.position.set(station.x, 2.2, -0.3);
hitbox.userData.stationIndex = station.index;
scene.add(hitbox);
hitTargets.push(hitbox);
return { activeMat, statusLampMat, light };
}
stationDefinitions.forEach((station, index) => {
station.index = index;
const enzyme = makeEnzyme(station);
station.substrateModel = station.makeSubstrate();
station.productModels = station.makeProducts.map((makeProduct) => makeProduct()).map((model) => {
model.userData.baseScale = model.userData.baseScale ?? 1;
scene.add(model);
return model;
});
scene.add(station.substrateModel);
const label = document.createElement("div");
label.className = "world-label";
label.style.setProperty("--station-color", `#${station.color.toString(16).padStart(6, "0")}`);
label.innerHTML = `
<strong>${station.name}</strong>
<small>${station.substrate} → ${station.product}</small>
<span class="status">substrate approaching</span>
`;
labelsLayer.appendChild(label);
station.label = label;
station.statusElement = label.querySelector(".status");
station.labelPosition = new THREE.Vector3(station.x, 5.25, -1.35);
station.enzyme = enzyme;
stationElements.push(station);
});
// Deterministic floating voxel dust in the background.
let randomSeed = 918273;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const dustMaterial = new THREE.MeshBasicMaterial({
color: 0x2b6683,
transparent: true,
opacity: 0.35
});
for (let i = 0; i < 48; i++) {
const size = 0.045 + random() * 0.065;
const dust = block(
scene,
[
-15 + random() * 30,
0.6 + random() * 8,
-7 + random() * 5
],
[size, size, size],
dustMaterial,
false
);
dust.userData.drift = 0.08 + random() * 0.12;
dust.userData.baseY = dust.position.y;
dust.userData.phase = random() * Math.PI * 2;
}
const sceneDust = scene.children.filter((object) => object.userData.drift);
// Camera state and direct, addon-free controls.
const cameraTarget = new THREE.Vector3(0, 2.05, 0);
let azimuth = 0.34;
let polar = 1.03;
let cameraTween = null;
let viewportWidth = 1;
let viewportHeight = 1;
function updateCamera() {
const radius = 24;
camera.position.set(
cameraTarget.x + radius * Math.sin(polar) * Math.sin(azimuth),
cameraTarget.y + radius * Math.cos(polar),
cameraTarget.z + radius * Math.sin(polar) * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resize() {
viewportWidth = Math.max(1, viewport.clientWidth);
viewportHeight = Math.max(1, viewport.clientHeight);
const aspect = viewportWidth / viewportHeight;
const halfHeight = Math.max(7.2, 12.7 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(viewportWidth, viewportHeight, false);
updateCamera();
}
new ResizeObserver(resize).observe(viewport);
resize();
function panCamera(dx, dy) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const worldPerPixel =
(camera.right - camera.left) / camera.zoom / viewportWidth;
cameraTarget.addScaledVector(right, -dx * worldPerPixel);
cameraTarget.addScaledVector(up, dy * worldPerPixel);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -12, 12);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, -1, 8);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -8, 8);
}
function focusStation(index) {
const station = stationDefinitions[index];
cameraTween = {
startTime: performance.now(),
duration: 650,
startTarget: cameraTarget.clone(),
endTarget: new THREE.Vector3(station.x, 2.15, -0.1),
startZoom: camera.zoom,
endZoom: 1.62
};
cards.forEach((card, cardIndex) => {
card.classList.toggle("active", cardIndex === index);
});
}
function resetCamera() {
cameraTween = {
startTime: performance.now(),
duration: 650,
startTarget: cameraTarget.clone(),
endTarget: new THREE.Vector3(0, 2.05, 0),
startZoom: camera.zoom,
endZoom: 1
};
cards.forEach((card) => card.classList.remove("active"));
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const activePointers = new Map();
let gestureMoved = false;
let previousPinchDistance = 0;
function selectStationAt(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(hitTargets, false)[0];
if (hit) {
focusStation(hit.object.userData.stationIndex);
}
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button
});
cameraTween = null;
if (activePointers.size === 1) {
gestureMoved = false;
} else {
gestureMoved = true;
previousPinchDistance = getPinchDistance();
}
});
function getPinchDistance() {
const values = [...activePointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = activePointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (activePointers.size >= 2) {
const distance = getPinchDistance();
if (previousPinchDistance > 0 && distance > 0) {
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * (distance / previousPinchDistance),
0.65,
3.2
);
camera.updateProjectionMatrix();
}
previousPinchDistance = distance;
gestureMoved = true;
return;
}
if (Math.abs(dx) + Math.abs(dy) > 1) {
gestureMoved = true;
}
if (previous.button === 2 || event.shiftKey) {
panCamera(dx, dy);
} else {
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(polar - dy * 0.005, 0.42, 1.42);
}
});
function endPointer(event) {
const wasSingle = activePointers.size === 1;
activePointers.delete(event.pointerId);
if (wasSingle && !gestureMoved && event.button !== 2) {
selectStationAt(event.clientX, event.clientY);
}
previousPinchDistance = getPinchDistance();
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTween = null;
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
3.2
);
camera.updateProjectionMatrix();
},
{ passive: false }
);
cards.forEach((card) => {
card.addEventListener("click", () => {
focusStation(Number(card.dataset.station));
});
});
let paused = false;
let elapsed = 0;
let lastTime = performance.now();
let focusIndex = 0;
const pauseButton = document.getElementById("pause");
const replayButton = document.getElementById("replay");
const nextButton = document.getElementById("next");
const resetButton = document.getElementById("reset");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
replayButton.addEventListener("click", () => {
elapsed = 0;
});
nextButton.addEventListener("click", () => {
focusIndex = (focusIndex + 1) % stationDefinitions.length;
focusStation(focusIndex);
});
resetButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
const clamp01 = (value) => THREE.MathUtils.clamp(value, 0, 1);
const smooth = (value) => {
const t = clamp01(value);
return t * t * (3 - 2 * t);
};
function updateStationModels(time) {
const cycleLength = 9;
stationElements.forEach((station) => {
const rawTime = time - station.offset;
const phase = ((rawTime % cycleLength) + cycleLength) % cycleLength;
const p = phase / cycleLength;
let status = "substrate approaching";
let activity = 0.12;
if (p >= 0.34 && p < 0.52) {
status = "recognition at active site";
activity = 0.55;
} else if (p >= 0.52 && p < 0.64) {
status = "schematic chemical transformation";
activity = 1;
} else if (p >= 0.64) {
status = "illustrative products released";
activity = 0.25;
}
station.statusElement.textContent = status;
station.enzyme.activeMat.emissiveIntensity =
0.16 + activity * (0.55 + Math.sin(time * 4 + station.index) * 0.16);
station.enzyme.statusLampMat.emissiveIntensity =
0.45 + activity * 1.15;
station.enzyme.light.intensity =
0.08 + activity * 1.7;
const substrate = station.substrateModel;
substrate.visible = p < 0.535;
if (substrate.visible) {
const approach = smooth(p / 0.52);
substrate.position.set(
station.x - 2.45 * (1 - approach),
1.56 + Math.sin(time * 2 + station.index) * 0.035 + approach * 0.17,
0.28 - approach * 0.43
);
substrate.rotation.set(
0.04 * Math.sin(time + station.index),
time * 0.28 + station.index * 0.8,
0.06 * Math.sin(time * 1.4 + station.index)
);
}
station.productModels.forEach((product, productIndex) => {
product.visible = p >= 0.535;
if (!product.visible) return;
const release = clamp01((p - 0.535) / 0.465);
const travel = smooth(release);
const arc = Math.sin(Math.PI * Math.min(release * 1.35, 1));
const lateralOffset = productIndex === 0 ? -0.08 : 0.12;
product.position.set(
station.x +
0.12 +
travel * (2.18 + productIndex * 0.2),
1.69 + arc * (0.48 + productIndex * 0.05),
-0.13 + travel * 0.64 + lateralOffset
);
product.rotation.set(
0.08 * Math.sin(time * 1.3 + productIndex),
time * 0.34 + productIndex * 1.4,
0.08 * Math.sin(time + productIndex)
);
const fadeScale =
release > 0.86
? 1 - (release - 0.86) / 0.14
: 1;
product.scale.setScalar(
Math.max(0.001, product.userData.baseScale * fadeScale)
);
});
});
}
function updateLabels() {
stationElements.forEach((station) => {
const projected = station.labelPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.3 &&
Math.abs(projected.y) < 1.3;
station.label.style.opacity = visible ? "1" : "0";
station.label.style.left =
`${(projected.x * 0.5 + 0.5) * viewportWidth}px`;
station.label.style.top =
`${(-projected.y * 0.5 + 0.5) * viewportHeight}px`;
});
}
function animate(now) {
const dt = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (!paused) {
elapsed += dt;
}
if (cameraTween) {
const t = clamp01(
(now - cameraTween.startTime) / cameraTween.duration
);
const eased = smooth(t);
cameraTarget.lerpVectors(
cameraTween.startTarget,
cameraTween.endTarget,
eased
);
camera.zoom = THREE.MathUtils.lerp(
cameraTween.startZoom,
cameraTween.endZoom,
eased
);
camera.updateProjectionMatrix();
if (t >= 1) cameraTween = null;
}
updateCamera();
updateStationModels(elapsed);
sceneDust.forEach((dust) => {
dust.position.y =
dust.userData.baseY +
Math.sin(elapsed * dust.userData.drift + dust.userData.phase) * 0.16;
dust.rotation.y += dt * 0.15;
});
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
loading.remove();
requestAnimationFrame(animate);
</script>
</body>
</html>
```