Prompt specification
Build or customize the Three.js 3D scene "Enzyme pocket and substrate model" 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: Enzyme pocket and substrate model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/enzyme-pocket-and-substrate-model-x0845
Scene Description Prompt:
Use Three.js from cdnjs to create a simplified enzyme surface with one marked binding pocket and two differently shaped candidate substrates; label shapes schematic and distinguish binding from chemical transformation. Deliver one self-contained HTML file with low-poly forms.
Working Three.js Starter (enzyme-pocket-and-substrate-model-x0845):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Schematic Enzyme Binding and Transformation</title>
<style>
:root {
color-scheme: dark;
--bg: #08131d;
--panel: rgba(14, 29, 41, 0.88);
--border: rgba(167, 203, 218, 0.18);
--text: #edf8fb;
--muted: #9db4bf;
--cyan: #62d9f2;
--green: #57e0ae;
--orange: #ffad58;
--pink: #f27ab4;
}
* {
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;
}
button {
font: inherit;
}
#stage,
#stage canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#stage canvas {
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.hero {
position: absolute;
z-index: 5;
top: 24px;
left: 26px;
max-width: min(470px, calc(100vw - 390px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 42px);
line-height: 1.02;
letter-spacing: -0.04em;
}
.subtitle {
margin: 10px 0 0;
max-width: 430px;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.schematic-badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(10, 25, 35, 0.72);
color: #c9dce3;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.03em;
}
.schematic-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 12px rgba(255, 173, 88, 0.75);
}
.panel {
position: absolute;
z-index: 10;
top: 24px;
right: 24px;
width: 326px;
padding: 18px;
border: 1px solid var(--border);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(16px);
}
.panel h2 {
margin: 0 0 5px;
font-size: 15px;
letter-spacing: -0.01em;
}
.panel-intro {
margin: 0 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.candidate-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-bottom: 14px;
}
.candidate {
position: relative;
min-height: 90px;
padding: 12px;
text-align: left;
color: var(--text);
border: 1px solid var(--border);
border-radius: 14px;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition: 160ms ease;
}
.candidate:hover {
border-color: rgba(98, 217, 242, 0.45);
transform: translateY(-1px);
}
.candidate[aria-pressed="true"] {
border-color: var(--cyan);
background: rgba(98, 217, 242, 0.09);
box-shadow: inset 0 0 0 1px rgba(98, 217, 242, 0.18);
}
.candidate-icon {
display: grid;
place-items: center;
width: 34px;
height: 34px;
margin-bottom: 8px;
border-radius: 10px;
color: #07131c;
font-size: 20px;
font-weight: 900;
}
.candidate[data-candidate="A"] .candidate-icon {
background: var(--cyan);
clip-path: polygon(50% 0, 100% 100%, 0 100%);
border-radius: 0;
}
.candidate[data-candidate="B"] .candidate-icon {
color: #26101c;
background: var(--pink);
}
.candidate strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
}
.candidate small {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.3;
}
.actions {
display: grid;
gap: 8px;
}
.action {
width: 100%;
padding: 11px 13px;
border: 1px solid transparent;
border-radius: 12px;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: 160ms ease;
}
.action.primary {
color: #06131b;
background: var(--cyan);
}
.action.primary:hover:not(:disabled) {
background: #8be7f7;
transform: translateY(-1px);
}
.action.secondary {
color: #ffe0bc;
border-color: rgba(255, 173, 88, 0.38);
background: rgba(255, 173, 88, 0.08);
}
.action.secondary:hover:not(:disabled) {
background: rgba(255, 173, 88, 0.15);
}
.action:disabled {
opacity: 0.36;
cursor: not-allowed;
}
.status {
margin-top: 14px;
padding: 13px;
border: 1px solid var(--border);
border-radius: 13px;
background: rgba(0, 0, 0, 0.15);
}
.status-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 5px;
font-size: 12px;
font-weight: 800;
}
.status-title::before {
content: "";
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: #78909c;
}
.status.bound .status-title::before {
background: var(--green);
box-shadow: 0 0 12px rgba(87, 224, 174, 0.65);
}
.status.transformed .status-title::before {
background: var(--orange);
box-shadow: 0 0 12px rgba(255, 173, 88, 0.7);
}
.status p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.legend {
display: grid;
gap: 8px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--border);
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: #bed0d7;
font-size: 11px;
line-height: 1.35;
}
.legend-icon {
display: grid;
place-items: center;
width: 29px;
height: 23px;
flex: 0 0 auto;
border-radius: 7px;
font-weight: 900;
}
.legend-icon.binding {
color: var(--green);
background: rgba(87, 224, 174, 0.11);
}
.legend-icon.transform {
color: var(--orange);
background: rgba(255, 173, 88, 0.11);
}
.legend-item strong {
color: var(--text);
}
#labels {
position: absolute;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
display: none;
white-space: nowrap;
transform: translate(-50%, -50%);
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
background: rgba(7, 17, 25, 0.78);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.24);
color: #e9f6f9;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.02em;
}
.scene-label.enzyme {
color: #a7d4c6;
}
.scene-label.pocket {
color: #ffb3a6;
border-color: rgba(255, 123, 107, 0.3);
}
.scene-label.candidate-a {
color: var(--cyan);
}
.scene-label.candidate-b {
color: var(--pink);
}
.scene-label.binding {
color: var(--green);
border-color: rgba(87, 224, 174, 0.35);
}
.scene-label.transform {
color: var(--orange);
border-color: rgba(255, 173, 88, 0.4);
}
.scene-label.mismatch {
color: #ff819e;
border-color: rgba(242, 122, 180, 0.38);
}
.hint {
position: absolute;
z-index: 5;
left: 26px;
bottom: 22px;
color: rgba(190, 210, 218, 0.67);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
}
.reset-view {
position: absolute;
z-index: 6;
left: 26px;
bottom: 48px;
padding: 7px 10px;
border: 1px solid var(--border);
border-radius: 8px;
color: #bdd2da;
background: rgba(10, 24, 34, 0.72);
font-size: 10px;
font-weight: 700;
cursor: pointer;
}
@media (max-width: 760px) {
.hero {
top: 15px;
left: 16px;
max-width: calc(100vw - 32px);
}
.subtitle {
max-width: 90%;
font-size: 12px;
}
.schematic-badge {
margin-top: 8px;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
max-height: 42vh;
padding: 13px;
overflow: auto;
border-radius: 16px;
}
.panel-intro,
.legend {
display: none;
}
.candidate-list {
margin-bottom: 9px;
}
.candidate {
min-height: 65px;
padding: 9px;
}
.candidate-icon {
float: left;
width: 28px;
height: 28px;
margin: 0 9px 0 0;
font-size: 15px;
}
.candidate strong,
.candidate small {
padding-top: 2px;
}
.status {
margin-top: 9px;
padding: 10px;
}
.hint,
.reset-view {
display: none;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive low-poly enzyme binding visualization"></div>
<header class="hero">
<div class="eyebrow">Interactive molecular schematic</div>
<h1>Binding is not transformation.</h1>
<p class="subtitle">
Explore one marked enzyme pocket, compare two candidate shapes, and
distinguish reversible binding from an irreversible chemical change.
</p>
<div class="schematic-badge">Shapes are schematic — not chemical structures</div>
</header>
<div id="labels" aria-hidden="true">
<div id="label-enzyme" class="scene-label enzyme">enzyme surface</div>
<div id="label-pocket" class="scene-label pocket">one marked binding pocket</div>
<div id="label-a" class="scene-label candidate-a">candidate A · wedge</div>
<div id="label-b" class="scene-label candidate-b">candidate B · branched</div>
<div id="label-binding" class="scene-label binding">↔ reversible binding</div>
<div id="label-transform" class="scene-label transform">→ chemical transformation</div>
<div id="label-mismatch" class="scene-label mismatch">✕ shape mismatch</div>
</div>
<aside class="panel" aria-label="Simulation controls">
<h2>Choose a candidate</h2>
<p class="panel-intro">
The low-poly geometry is deliberately simplified to show shape complementarity.
</p>
<div class="candidate-list">
<button class="candidate" data-candidate="A" aria-pressed="true">
<span class="candidate-icon" aria-hidden="true"></span>
<strong>Candidate A</strong>
<small>Wedge shape<br>complements the pocket</small>
</button>
<button class="candidate" data-candidate="B" aria-pressed="false">
<span class="candidate-icon" aria-hidden="true">Y</span>
<strong>Candidate B</strong>
<small>Branched shape<br>bulky mismatch</small>
</button>
</div>
<div class="actions">
<button id="bind-button" class="action primary">Bind candidate A</button>
<button id="transform-button" class="action secondary" disabled>
Run chemical transformation
</button>
</div>
<section id="status" class="status" aria-live="polite">
<div id="status-title" class="status-title">Candidate A is not bound</div>
<p id="status-copy">
Binding is shown as a reversible association. No chemical change has occurred.
</p>
</section>
<div class="legend" aria-label="Visual legend">
<div class="legend-item">
<span class="legend-icon binding">↔</span>
<span><strong>Binding:</strong> reversible shape fit at the pocket; enzyme unchanged.</span>
</div>
<div class="legend-item">
<span class="legend-icon transform">→</span>
<span><strong>Transformation:</strong> chemical change; new product fragments form and depart.</span>
</div>
</div>
</aside>
<button id="reset-view" class="reset-view">Reset camera</button>
<div class="hint">Drag to orbit · Scroll or pinch to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08131d);
scene.fog = new THREE.Fog(0x08131d, 8, 15);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
40
);
const cameraTarget = new THREE.Vector3(-0.08, 0.02, 0);
const defaultView = {
azimuth: 0.28,
polar: 1.16,
radius: 7.6
};
const view = { ...defaultView };
function updateCamera() {
const sinPolar = Math.sin(view.polar);
camera.position.set(
cameraTarget.x + view.radius * sinPolar * Math.sin(view.azimuth),
cameraTarget.y + view.radius * Math.cos(view.polar),
cameraTarget.z + view.radius * sinPolar * Math.cos(view.azimuth)
);
camera.lookAt(cameraTarget);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xc7e8ff, 0x183027, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(4, 6, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x55d7ff, 2.0);
rimLight.position.set(-4, 2, -4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff9e61, 13, 8, 2);
warmLight.position.set(3.5, -0.5, 3);
scene.add(warmLight);
const floor = new THREE.Mesh(
new THREE.CircleGeometry(10, 64),
new THREE.MeshStandardMaterial({
color: 0x0c1b26,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.72;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(14, 18, 0x315465, 0x1b3441);
grid.position.y = -1.70;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
// -------------------------------------------------------------------------
// Low-poly enzyme surface
// -------------------------------------------------------------------------
const enzymeGeometry = new THREE.TorusGeometry(1.25, 0.56, 7, 16);
const enzymePositions = enzymeGeometry.attributes.position;
const enzymeColors = [];
for (let i = 0; i < enzymePositions.count; i++) {
let x = enzymePositions.getX(i);
let y = enzymePositions.getY(i);
let z = enzymePositions.getZ(i);
const angle = Math.atan2(y, x);
const distortion =
1 +
0.075 * Math.sin(angle * 3 + 0.7) +
0.035 * Math.sin(angle * 7 - 0.4);
x *= distortion;
y *= distortion;
z += 0.075 * Math.sin(angle * 2 + z * 4);
enzymePositions.setXYZ(i, x, y, z);
const color = new THREE.Color();
color.setHSL(
0.43 + 0.025 * Math.sin(angle * 2),
0.27,
0.30 + 0.055 * (z + 0.56) / 1.12
);
enzymeColors.push(color.r, color.g, color.b);
}
enzymeGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(enzymeColors, 3)
);
enzymeGeometry.computeVertexNormals();
const enzyme = new THREE.Mesh(
enzymeGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.86,
metalness: 0.04
})
);
enzyme.position.set(-0.45, 0.10, 0);
enzyme.castShadow = true;
enzyme.receiveShadow = true;
scene.add(enzyme);
// A handful of low-poly surface knobs make the surface read as an enzyme
// rather than a perfect mathematical ring.
const knobGeometry = new THREE.DodecahedronGeometry(0.15, 0);
const knobMaterial = new THREE.MeshStandardMaterial({
color: 0x315f55,
flatShading: true,
roughness: 0.92
});
for (let i = 0; i < 11; i++) {
const a = (i / 11) * Math.PI * 2 + 0.25;
const knob = new THREE.Mesh(knobGeometry, knobMaterial);
const r = 1.72 + 0.06 * Math.sin(i * 2.3);
knob.position.set(
-0.45 + Math.cos(a) * r,
0.10 + Math.sin(a) * r,
0.04 * Math.sin(i * 1.7)
);
knob.scale.set(1, 0.78, 0.72);
knob.rotation.set(i * 0.31, i * 0.47, i * 0.19);
knob.castShadow = true;
scene.add(knob);
}
// -------------------------------------------------------------------------
// Marked binding pocket
// -------------------------------------------------------------------------
const pocketPosition = new THREE.Vector3(0.10, 0.82, 0.43);
const dockPosition = new THREE.Vector3(0.10, 0.82, 0.78);
const pocketMaterial = new THREE.MeshStandardMaterial({
color: 0x8e3d3d,
emissive: 0xff6c5d,
emissiveIntensity: 0.15,
roughness: 0.95,
side: THREE.DoubleSide
});
const pocket = new THREE.Mesh(
new THREE.CircleGeometry(0.29, 12),
pocketMaterial
);
pocket.position.copy(pocketPosition);
pocket.scale.set(1.08, 0.82, 1);
pocket.receiveShadow = true;
scene.add(pocket);
const pocketRimMaterial = new THREE.MeshStandardMaterial({
color: 0xff7b6b,
emissive: 0xff5f51,
emissiveIntensity: 0.28,
roughness: 0.65,
flatShading: true
});
const pocketRim = new THREE.Mesh(
new THREE.TorusGeometry(0.30, 0.035, 5, 14),
pocketRimMaterial
);
pocketRim.position.copy(pocketPosition);
pocketRim.position.z += 0.012;
pocketRim.scale.set(1.08, 0.82, 1);
scene.add(pocketRim);
// -------------------------------------------------------------------------
// Candidate A: flat triangular wedge
// -------------------------------------------------------------------------
function createTriangularPrismGeometry() {
const geometry = new THREE.BufferGeometry();
const vertices = new Float32Array([
-0.32, -0.19, -0.16,
0.32, -0.19, -0.16,
0.00, 0.29, -0.16,
-0.32, -0.19, 0.16,
0.32, -0.19, 0.16,
0.00, 0.29, 0.16
]);
const indices = [
3, 4, 5,
0, 2, 1,
0, 1, 4,
0, 4, 3,
1, 2, 5,
1, 5, 4,
2, 0, 3,
2, 3, 5
];
geometry.setAttribute(
"position",
new THREE.BufferAttribute(vertices, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const candidateA = new THREE.Group();
candidateA.userData.candidate = "A";
const candidateAMaterial = new THREE.MeshStandardMaterial({
color: 0x62d9f2,
emissive: 0x1a8197,
emissiveIntensity: 0.22,
flatShading: true,
roughness: 0.55,
metalness: 0.08
});
const candidateAMesh = new THREE.Mesh(
createTriangularPrismGeometry(),
candidateAMaterial
);
candidateAMesh.castShadow = true;
candidateA.add(candidateAMesh);
const candidateAEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(candidateAMesh.geometry, 20),
new THREE.LineBasicMaterial({
color: 0x0b3440,
transparent: true,
opacity: 0.8
})
);
candidateA.add(candidateAEdges);
const candidateAHome = new THREE.Vector3(-1.72, 0.16, 0.92);
const candidateAHomeRotation = new THREE.Euler(-0.10, 0.32, -0.36);
const candidateADockRotation = new THREE.Euler(0.02, 0.05, 0.34);
candidateA.position.copy(candidateAHome);
candidateA.rotation.copy(candidateAHomeRotation);
scene.add(candidateA);
// -------------------------------------------------------------------------
// Candidate B: bulky branched low-poly shape
// -------------------------------------------------------------------------
const candidateB = new THREE.Group();
candidateB.userData.candidate = "B";
const candidateBMaterial = new THREE.MeshStandardMaterial({
color: 0xf27ab4,
emissive: 0x762146,
emissiveIntensity: 0.20,
flatShading: true,
roughness: 0.68
});
const candidateBCore = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.25, 0),
candidateBMaterial
);
candidateBCore.castShadow = true;
candidateB.add(candidateBCore);
const armGeometry = new THREE.BoxGeometry(0.22, 0.22, 0.22);
const armPositions = [
[0.32, 0.22, 0.02],
[-0.31, 0.21, -0.02],
[0.02, -0.34, 0.04]
];
for (const [x, y, z] of armPositions) {
const arm = new THREE.Mesh(armGeometry, candidateBMaterial);
arm.position.set(x, y, z);
arm.rotation.set(0.35 * x, 0.28 * y, 0.4 * z);
arm.castShadow = true;
candidateB.add(arm);
}
const candidateBHome = new THREE.Vector3(1.92, 0.28, 0.66);
const candidateBReject = new THREE.Vector3(0.96, 0.82, 0.92);
candidateB.position.copy(candidateBHome);
candidateB.rotation.set(0.12, -0.35, 0.18);
scene.add(candidateB);
// -------------------------------------------------------------------------
// Products produced by the schematic chemical transformation
// -------------------------------------------------------------------------
const productGroup = new THREE.Group();
productGroup.position.copy(dockPosition);
productGroup.visible = false;
scene.add(productGroup);
const productMaterialOne = new THREE.MeshStandardMaterial({
color: 0xffa24f,
emissive: 0x7b3510,
emissiveIntensity: 0.25,
flatShading: true,
roughness: 0.64,
transparent: true,
opacity: 0
});
const productMaterialTwo = new THREE.MeshStandardMaterial({
color: 0xffdb66,
emissive: 0x806013,
emissiveIntensity: 0.22,
flatShading: true,
roughness: 0.66,
transparent: true,
opacity: 0
});
const productOne = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.28, 0),
productMaterialOne
);
productOne.castShadow = true;
productGroup.add(productOne);
const productTwo = new THREE.Mesh(
new THREE.OctahedronGeometry(0.25, 0),
productMaterialTwo
);
productTwo.castShadow = true;
productGroup.add(productTwo);
const bondMaterial = new THREE.MeshStandardMaterial({
color: 0xffe8aa,
emissive: 0x9b5f13,
emissiveIntensity: 0.35,
flatShading: true,
transparent: true,
opacity: 0
});
const productBond = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.5, 6),
bondMaterial
);
productBond.rotation.z = Math.PI / 2;
productGroup.add(productBond);
const transformationArrow = new THREE.ArrowHelper(
new THREE.Vector3(0.82, 0.46, 0.12).normalize(),
new THREE.Vector3(0.32, 0.87, 0.72),
1.15,
0xffad58,
0.24,
0.13
);
transformationArrow.visible = false;
scene.add(transformationArrow);
// Dashed curve used only while a candidate moves toward the pocket.
const bindingCurveGeometry = new THREE.BufferGeometry();
const bindingCurvePositions = new Float32Array(25 * 3);
bindingCurveGeometry.setAttribute(
"position",
new THREE.BufferAttribute(bindingCurvePositions, 3)
);
const bindingCurve = new THREE.Line(
bindingCurveGeometry,
new THREE.LineDashedMaterial({
color: 0x57e0ae,
dashSize: 0.13,
gapSize: 0.08,
transparent: true,
opacity: 0.8
})
);
bindingCurve.visible = false;
scene.add(bindingCurve);
// -------------------------------------------------------------------------
// Interaction state
// -------------------------------------------------------------------------
const state = {
selected: "A",
bound: false,
transformed: false,
bindMix: 0,
transformMix: 0,
attemptStart: -Infinity
};
const candidateButtons = [
document.querySelector('[data-candidate="A"]'),
document.querySelector('[data-candidate="B"]')
];
const bindButton = document.getElementById("bind-button");
const transformButton = document.getElementById("transform-button");
const status = document.getElementById("status");
const statusTitle = document.getElementById("status-title");
const statusCopy = document.getElementById("status-copy");
function updateUI() {
for (const button of candidateButtons) {
button.setAttribute(
"aria-pressed",
String(button.dataset.candidate === state.selected)
);
}
status.classList.toggle("bound", state.bound && !state.transformed);
status.classList.toggle("transformed", state.transformed);
if (state.selected === "B") {
bindButton.textContent = "Test candidate B fit";
transformButton.disabled = true;
transformButton.textContent = "Run chemical transformation";
statusTitle.textContent = "Candidate B is not bound";
statusCopy.textContent =
"The bulky branched shape does not complement this pocket. Testing it demonstrates a shape mismatch, not binding.";
} else if (state.transformed) {
bindButton.textContent = "Release candidate A";
transformButton.disabled = false;
transformButton.textContent = "Reset transformation";
statusTitle.textContent = "Chemical transformation occurred";
statusCopy.textContent =
"The bound shape has changed into two schematic product fragments. The enzyme remains unchanged while the products depart.";
} else if (state.bound) {
bindButton.textContent = "Release candidate A";
transformButton.disabled = false;
transformButton.textContent = "Run chemical transformation";
statusTitle.textContent = "Candidate A is bound";
statusCopy.textContent =
"Binding is shown as a reversible fit at the pocket. No chemical change has occurred yet.";
} else {
bindButton.textContent = "Bind candidate A";
transformButton.disabled = true;
transformButton.textContent = "Run chemical transformation";
statusTitle.textContent = "Candidate A is not bound";
statusCopy.textContent =
"Binding is shown as a reversible association. No chemical change has occurred.";
}
}
function selectCandidate(candidate) {
state.selected = candidate;
state.bound = false;
state.transformed = false;
state.bindMix = 0;
state.transformMix = 0;
state.attemptStart = -Infinity;
updateUI();
}
for (const button of candidateButtons) {
button.addEventListener("click", () => {
selectCandidate(button.dataset.candidate);
});
}
bindButton.addEventListener("click", () => {
if (state.selected === "A") {
state.bound = !state.bound;
if (!state.bound) {
state.transformed = false;
}
} else {
state.attemptStart = performance.now();
}
updateUI();
});
transformButton.addEventListener("click", () => {
if (state.transformed) {
state.transformed = false;
} else if (state.bound && state.selected === "A") {
state.transformed = true;
}
updateUI();
});
updateUI();
// -------------------------------------------------------------------------
// Camera controls implemented directly, without Three.js addons
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let pointerTravel = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
pointerTravel = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
pointerTravel += Math.abs(dx) + Math.abs(dy);
view.azimuth -= dx * 0.006;
view.polar = THREE.MathUtils.clamp(
view.polar - dy * 0.005,
0.42,
1.47
);
updateCamera();
});
function endPointer(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.008,
5.0,
10.5
);
updateCamera();
},
{ passive: false }
);
document.getElementById("reset-view").addEventListener("click", () => {
view.azimuth = defaultView.azimuth;
view.polar = defaultView.polar;
view.radius = defaultView.radius;
updateCamera();
});
// Clicking a candidate in the scene also selects it.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("click", (event) => {
if (pointerTravel > 8) return;
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(
[candidateA, candidateB],
true
);
if (!hits.length) return;
let object = hits[0].object;
while (object && !object.userData.candidate) {
object = object.parent;
}
if (object?.userData.candidate) {
selectCandidate(object.userData.candidate);
}
});
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labels = {
enzyme: document.getElementById("label-enzyme"),
pocket: document.getElementById("label-pocket"),
a: document.getElementById("label-a"),
b: document.getElementById("label-b"),
binding: document.getElementById("label-binding"),
transform: document.getElementById("label-transform"),
mismatch: document.getElementById("label-mismatch")
};
function placeLabel(element, position, offsetX = 0, offsetY = 0) {
const projected = position.clone().project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
projected.x < -1.25 ||
projected.x > 1.25 ||
projected.y < -1.25 ||
projected.y > 1.25
) {
element.style.display = "none";
return;
}
const x =
(projected.x * 0.5 + 0.5) * window.innerWidth + offsetX;
const y =
(-projected.y * 0.5 + 0.5) * window.innerHeight + offsetY;
element.style.display = "block";
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const temp = new THREE.Vector3();
const temp2 = new THREE.Vector3();
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function updateBindingCurve() {
const points = [];
const start = candidateA.position;
const end = dockPosition;
const control = start.clone().lerp(end, 0.5);
control.y += 0.48;
control.z += 0.18;
for (let i = 0; i < 25; i++) {
const t = i / 24;
const inverse = 1 - t;
const x =
inverse * inverse * start.x +
2 * inverse * t * control.x +
t * t * end.x;
const y =
inverse * inverse * start.y +
2 * inverse * t * control.y +
t * t * end.y;
const z =
inverse * inverse * start.z +
2 * inverse * t * control.z +
t * t * end.z;
points.push(new THREE.Vector3(x, y, z));
}
const attribute = bindingCurveGeometry.attributes.position;
points.forEach((point, index) => {
attribute.setXYZ(index, point.x, point.y, point.z);
});
attribute.needsUpdate = true;
bindingCurve.computeLineDistances();
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
// Candidate A docking.
const bindTarget =
state.selected === "A" && state.bound ? 1 : 0;
state.bindMix +=
(bindTarget - state.bindMix) * (1 - Math.pow(0.001, delta));
state.bindMix = THREE.MathUtils.clamp(state.bindMix, 0, 1);
const bindEase = easeInOutCubic(state.bindMix);
candidateA.position.lerpVectors(
candidateAHome,
dockPosition,
bindEase
);
candidateA.rotation.set(
THREE.MathUtils.lerp(
candidateAHomeRotation.x,
candidateADockRotation.x,
bindEase
),
THREE.MathUtils.lerp(
candidateAHomeRotation.y,
candidateADockRotation.y,
bindEase
),
THREE.MathUtils.lerp(
candidateAHomeRotation.z,
candidateADockRotation.z,
bindEase
)
);
// Candidate B tests the pocket and returns after a mismatch.
let attemptActive = false;
if (
state.selected === "B" &&
now - state.attemptStart < 1700
) {
attemptActive = true;
const u = (now - state.attemptStart) / 1700;
if (u < 0.42) {
candidateB.position.lerpVectors(
candidateBHome,
candidateBReject,
easeInOutCubic(u / 0.42)
);
} else {
candidateB.position.lerpVectors(
candidateBReject,
candidateBHome,
easeInOutCubic((u - 0.42) / 0.58)
);
}
candidateB.rotation.z = 0.18 - Math.sin(u * Math.PI) * 0.28;
} else {
candidateB.position.lerp(
candidateBHome,
1 - Math.pow(0.001, delta)
);
candidateB.rotation.z +=
(0.18 - candidateB.rotation.z) *
(1 - Math.pow(0.001, delta));
}
// Chemical transformation animation.
const transformTarget = state.transformed ? 1 : 0;
state.transformMix +=
(transformTarget - state.transformMix) *
(1 - Math.pow(0.002, delta));
state.transformMix = THREE.MathUtils.clamp(
state.transformMix,
0,
1
);
const transformEase = easeInOutCubic(state.transformMix);
productGroup.visible = state.transformMix > 0.01;
candidateA.visible = state.transformMix < 0.48;
productMaterialOne.opacity = Math.min(1, state.transformMix * 1.8);
productMaterialTwo.opacity = Math.min(1, state.transformMix * 1.8);
bondMaterial.opacity = Math.max(
0,
1 - state.transformMix * 2.1
);
const separation = 0.13 + transformEase * 0.56;
productOne.position.set(
-separation,
0.08 + transformEase * 0.08,
0.02
);
productTwo.position.set(
separation,
-0.07 - transformEase * 0.10,
-0.02
);
productOne.rotation.set(
transformEase * 1.8,
transformEase * 2.2,
transformEase * 0.8
);
productTwo.rotation.set(
-transformEase * 1.5,
transformEase * 2.7,
-transformEase * 1.1
);
productBond.scale.y = 0.75 + transformEase * 0.65;
productBond.visible = state.transformMix < 0.52;
transformationArrow.visible = state.transformed;
// Pocket color communicates state without replacing the explicit labels.
if (state.transformed) {
pocketMaterial.color.lerp(
new THREE.Color(0x9b542c),
1 - Math.pow(0.001, delta)
);
pocketRimMaterial.color.lerp(
new THREE.Color(0xffad58),
1 - Math.pow(0.001, delta)
);
pocketRimMaterial.emissive.lerp(
new THREE.Color(0xff7b2f),
1 - Math.pow(0.001, delta)
);
} else if (state.bound) {
pocketMaterial.color.lerp(
new THREE.Color(0x356b59),
1 - Math.pow(0.001, delta)
);
pocketRimMaterial.color.lerp(
new THREE.Color(0x57e0ae),
1 - Math.pow(0.001, delta)
);
pocketRimMaterial.emissive.lerp(
new THREE.Color(0x2dcf91),
1 - Math.pow(0.001, delta)
);
} else {
pocketMaterial.color.lerp(
new THREE.Color(0x8e3d3d),
1 - Math.pow(0.001, delta)
);
pocketRimMaterial.color.lerp(
new THREE.Color(0xff7b6b),
1 - Math.pow(0.001, delta)
);
pocketRimMaterial.emissive.lerp(
new THREE.Color(0xff5f51),
1 - Math.pow(0.001, delta)
);
}
const pulse = 1 + Math.sin(now * 0.003) * 0.025;
pocketRim.scale.set(1.08 * pulse, 0.82 * pulse, 1);
bindingCurve.visible =
state.selected === "A" &&
!state.bound &&
state.bindMix > 0.015;
if (bindingCurve.visible) {
updateBindingCurve();
}
// Project labels.
placeLabel(
labels.enzyme,
new THREE.Vector3(-1.20, 1.67, 0.10),
-25,
0
);
placeLabel(
labels.pocket,
pocketPosition.clone().add(new THREE.Vector3(0, -0.48, 0.06)),
10,
6
);
placeLabel(
labels.a,
candidateA.position.clone().add(new THREE.Vector3(0, -0.43, 0)),
0,
0
);
placeLabel(
labels.b,
candidateB.position.clone().add(new THREE.Vector3(0, -0.49, 0)),
0,
0
);
const bindingVisible =
state.selected === "A" && state.bound && !state.transformed;
if (bindingVisible) {
placeLabel(
labels.binding,
dockPosition.clone().add(new THREE.Vector3(0, 0.49, 0.10)),
8,
-2
);
} else {
labels.binding.style.display = "none";
}
if (state.transformed) {
placeLabel(
labels.transform,
productGroup.position.clone().add(new THREE.Vector3(0.67, 0.58, 0.12)),
16,
0
);
} else {
labels.transform.style.display = "none";
}
if (attemptActive) {
placeLabel(
labels.mismatch,
candidateB.position.clone().add(new THREE.Vector3(0, 0.54, 0)),
22,
-4
);
} else {
labels.mismatch.style.display = "none";
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
// -------------------------------------------------------------------------
// Resize handling
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```