Prompt specification
Build or customize the Three.js 3D scene "Slip-plane deformation 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: Slip-plane deformation model
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/slip-plane-deformation-model-x1958
Scene Description Prompt:
Animate a metallic-lattice cutaway with one row slipping past another, labeled as qualitative plastic deformation. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (slip-plane-deformation-model-x1958):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Metallic Lattice — Qualitative Plastic Deformation</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(9, 19, 30, 0.78);
--border: rgba(151, 202, 229, 0.16);
--text: #e8f3fa;
--muted: #91a8b9;
--cyan: #55c4e6;
--amber: #ffae45;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 64% 38%, rgba(40, 91, 121, 0.24), transparent 38%),
radial-gradient(circle at 18% 80%, rgba(18, 74, 94, 0.13), transparent 34%),
linear-gradient(135deg, #07101a 0%, #0a1724 52%, #060d16 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body::after {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
background: radial-gradient(ellipse at center, transparent 48%, rgba(1, 5, 10, 0.52));
z-index: 2;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.header {
position: fixed;
z-index: 5;
top: 30px;
left: 34px;
pointer-events: none;
max-width: 520px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
color: #a7c6d9;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 1px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(85, 196, 230, 0.7);
}
h1 {
margin: 10px 0 6px;
font-size: clamp(29px, 3.4vw, 48px);
line-height: 1;
letter-spacing: -0.045em;
font-weight: 720;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
max-width: 460px;
}
.tag {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 6px 9px;
border: 1px solid rgba(255, 174, 69, 0.27);
border-radius: 999px;
background: rgba(255, 174, 69, 0.07);
color: #ffc57f;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.tag::before {
content: "";
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 9px rgba(255, 174, 69, 0.8);
}
.controls {
position: fixed;
z-index: 6;
top: 30px;
right: 32px;
display: flex;
gap: 8px;
padding: 6px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(7, 16, 26, 0.66);
backdrop-filter: blur(14px);
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.18);
}
button {
appearance: none;
border: 1px solid transparent;
border-radius: 8px;
padding: 9px 12px;
background: transparent;
color: #bcd0de;
font: inherit;
font-size: 12px;
font-weight: 650;
cursor: pointer;
transition: 160ms ease;
}
button:hover {
color: white;
background: rgba(134, 191, 218, 0.1);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
button.primary {
min-width: 76px;
color: #09121a;
background: #b9dceb;
}
button.primary:hover {
background: #e1f5ff;
}
.panel {
position: fixed;
z-index: 5;
left: 34px;
bottom: 30px;
width: min(390px, calc(100vw - 68px));
padding: 19px 20px 17px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(18px);
box-shadow: 0 22px 60px rgba(0, 0, 0, 0.28);
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 15px;
}
.status {
display: inline-flex;
align-items: center;
gap: 8px;
color: #b9cbd8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 174, 69, 0.8);
}
.status.retained .status-dot {
background: #61e6a4;
box-shadow: 0 0 10px rgba(97, 230, 164, 0.8);
}
.displacement {
color: #8fa9ba;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 11px;
white-space: nowrap;
}
.displacement strong {
color: #f3c17e;
font-weight: 700;
}
.progress {
height: 3px;
margin-bottom: 16px;
overflow: hidden;
border-radius: 10px;
background: rgba(164, 200, 220, 0.12);
}
#progress-fill {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #e29438, #ffd18b);
box-shadow: 0 0 12px rgba(255, 174, 69, 0.5);
}
.panel h2 {
margin: 0 0 6px;
font-size: 18px;
letter-spacing: -0.025em;
font-weight: 680;
}
.panel p {
margin: 0;
color: #91a8b9;
font-size: 12px;
line-height: 1.62;
}
.panel-note {
display: flex;
gap: 9px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(145, 185, 207, 0.12);
color: #7792a5;
font-size: 10px;
line-height: 1.5;
}
.panel-note::before {
content: "i";
display: grid;
place-items: center;
flex: 0 0 17px;
height: 17px;
border: 1px solid rgba(130, 175, 200, 0.25);
border-radius: 50%;
color: #9bb8c9;
font-family: Georgia, serif;
font-weight: bold;
}
.legend {
position: fixed;
z-index: 5;
right: 32px;
bottom: 30px;
width: 220px;
padding: 15px 16px;
border: 1px solid var(--border);
border-radius: 14px;
background: rgba(7, 16, 26, 0.65);
backdrop-filter: blur(14px);
pointer-events: none;
}
.legend-title {
margin-bottom: 11px;
color: #7894a7;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 10px;
margin-top: 9px;
color: #a8becc;
font-size: 11px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
background: #aebbc7;
box-shadow: 0 0 8px rgba(174, 187, 199, 0.28);
}
.swatch.mobile {
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 174, 69, 0.65);
}
.swatch.fixed {
background: var(--cyan);
box-shadow: 0 0 10px rgba(85, 196, 230, 0.65);
}
.swatch.plane {
width: 18px;
height: 0;
border-radius: 0;
border-top: 1px dashed var(--amber);
box-shadow: none;
}
.scene-label {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
pointer-events: none;
white-space: nowrap;
filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.6));
}
.scene-label .anchor {
width: 7px;
height: 7px;
flex: 0 0 7px;
border: 2px solid currentColor;
border-radius: 50%;
background: #07101a;
box-shadow: 0 0 9px currentColor;
}
.scene-label .copy {
display: flex;
flex-direction: column;
gap: 2px;
padding: 6px 8px;
border-left: 1px solid currentColor;
background: rgba(5, 12, 20, 0.6);
backdrop-filter: blur(7px);
}
.scene-label b {
font-size: 9px;
letter-spacing: 0.13em;
}
.scene-label small {
color: #8ea6b6;
font-size: 9px;
letter-spacing: 0;
}
.scene-label.mobile {
color: var(--amber);
}
.scene-label.fixed {
color: var(--cyan);
}
.scene-label.plane {
color: #e5b66f;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #07101a;
color: #91a8b9;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.header {
top: 19px;
left: 18px;
max-width: calc(100vw - 36px);
}
h1 {
font-size: 30px;
}
.subtitle {
max-width: 300px;
font-size: 12px;
}
.controls {
top: auto;
right: 14px;
bottom: 14px;
}
.panel {
left: 14px;
bottom: 72px;
width: calc(100vw - 28px);
padding: 15px 16px;
}
.panel p,
.panel-note {
display: none;
}
.legend {
display: none;
}
.scene-label {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="header">
<div class="eyebrow">Metallic lattice · cutaway</div>
<h1>Plastic deformation</h1>
<p class="subtitle">
A single atomic row slips past a fixed row across a highlighted slip plane.
The final displacement remains after the motion stops.
</p>
<div class="tag">Qualitative model</div>
</header>
<div class="controls" aria-label="Animation controls">
<button id="pause" class="primary" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
<button id="reset-view" type="button">Reset view</button>
</div>
<section class="panel" aria-label="Explanation">
<div class="status-row">
<div id="status" class="status">
<span class="status-dot"></span>
<span id="status-text">Elastic loading</span>
</div>
<div class="displacement">
slip <strong id="displacement">0.00 a</strong>
</div>
</div>
<div class="progress" aria-hidden="true">
<span id="progress-fill"></span>
</div>
<h2 id="phase-title">Neighbors begin to load</h2>
<p id="phase-copy">
The highlighted row advances across the slip plane. Near-neighbor bonds
stretch, break and reform while the blue row remains fixed.
</p>
<div class="panel-note">
Single-plane, single-row schematic. “a” denotes one lattice spacing;
geometry and timescales are not to scale.
</div>
</section>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Reading the cutaway</div>
<div class="legend-item"><span class="swatch mobile"></span>Mobile slip row</div>
<div class="legend-item"><span class="swatch fixed"></span>Fixed reference row</div>
<div class="legend-item"><span class="swatch"></span>Surrounding lattice</div>
<div class="legend-item"><span class="swatch plane"></span>Slip plane</div>
</aside>
<div id="label-mobile" class="scene-label mobile">
<span class="anchor"></span>
<span class="copy">
<b>MOBILE ROW</b>
<small>slides by one lattice spacing</small>
</span>
</div>
<div id="label-fixed" class="scene-label fixed">
<span class="anchor"></span>
<span class="copy">
<b>FIXED ROW</b>
<small>reference plane</small>
</span>
</div>
<div id="label-plane" class="scene-label plane">
<span class="anchor"></span>
<span class="copy">
<b>SLIP PLANE</b>
<small>relative shear occurs here</small>
</span>
</div>
<div id="loading">Loading metallic lattice…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
const pauseButton = document.getElementById("pause");
const replayButton = document.getElementById("replay");
const resetViewButton = document.getElementById("reset-view");
const status = document.getElementById("status");
const statusText = document.getElementById("status-text");
const phaseTitle = document.getElementById("phase-title");
const phaseCopy = document.getElementById("phase-copy");
const displacementText = document.getElementById("displacement");
const progressFill = document.getElementById("progress-fill");
const mobileLabel = document.getElementById("label-mobile");
const fixedLabel = document.getElementById("label-fixed");
const planeLabel = document.getElementById("label-plane");
const SPACING = 1.55;
const ROWS = 6;
const COLS = 9;
const DEPTHS = 3;
const FIXED_ROW = 2;
const MOBILE_ROW = 3;
const SLIP_START = 0.9;
const SLIP_END = 4.4;
const TOTAL_TIME = 6.4;
const scene = new THREE.Scene();
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Animated metallic atomic lattice showing one row slipping past another"
);
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.45, 0);
const cameraState = {
yaw: 0.22,
pitch: 0.28,
zoom: 1
};
const hemi = new THREE.HemisphereLight(0xdcefff, 0x152332, 1.65);
scene.add(hemi);
const ambient = new THREE.AmbientLight(0x7893aa, 0.42);
scene.add(ambient);
const key = new THREE.DirectionalLight(0xffffff, 3.8);
key.position.set(5, 10, 8);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -12;
key.shadow.camera.right = 12;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -10;
key.shadow.camera.near = 1;
key.shadow.camera.far = 35;
key.shadow.bias = -0.00035;
scene.add(key);
const rim = new THREE.DirectionalLight(0x65bfff, 1.65);
rim.position.set(-8, 5, -7);
scene.add(rim);
const warm = new THREE.PointLight(0xffad58, 42, 28, 2);
warm.position.set(6, 3, 6);
scene.add(warm);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 20),
new THREE.ShadowMaterial({
color: 0x000711,
opacity: 0.38
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -3.38;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(28, 28, 0x315a70, 0x183747);
grid.position.y = -3.365;
grid.material.transparent = true;
grid.material.opacity = 0.16;
grid.material.depthWrite = false;
scene.add(grid);
const normalMaterial = new THREE.MeshStandardMaterial({
color: 0xaab8c5,
metalness: 0.92,
roughness: 0.24,
emissive: 0x0b1720,
emissiveIntensity: 0.18
});
const fixedMaterial = new THREE.MeshStandardMaterial({
color: 0x52bddc,
metalness: 0.78,
roughness: 0.25,
emissive: 0x063746,
emissiveIntensity: 0.34
});
const mobileMaterial = new THREE.MeshStandardMaterial({
color: 0xffad43,
metalness: 0.76,
roughness: 0.21,
emissive: 0x512000,
emissiveIntensity: 0.42
});
const atomGeometry = new THREE.SphereGeometry(0.34, 22, 16);
const atoms = [];
const atomMap = new Map();
function atomKey(row, col, depth) {
return `${row}:${col}:${depth}`;
}
function baseX(row, col) {
const staggeredOffset = row % 2 === 1 ? SPACING * 0.5 : 0;
return (col - (COLS - 1) / 2) * SPACING + staggeredOffset;
}
for (let row = 0; row < ROWS; row++) {
for (let col = 0; col < COLS; col++) {
for (let depth = 0; depth < DEPTHS; depth++) {
// The upper front slice is removed to reveal the interior.
if (depth === DEPTHS - 1 && row >= 4) continue;
const atom = {
id: atomMap.size,
row,
col,
depth,
x: baseX(row, col),
y: (row - 2) * 1.3,
z: (depth - 1) * 1.55,
type: row === MOBILE_ROW
? "mobile"
: row === FIXED_ROW
? "fixed"
: "normal"
};
atomMap.set(atomKey(row, col, depth), atom);
atoms.push(atom);
}
}
}
function createAtomInstances(list, material) {
const mesh = new THREE.InstancedMesh(atomGeometry, material, list.length);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
const matrix = new THREE.Matrix4();
list.forEach((atom, index) => {
matrix.makeTranslation(atom.x, atom.y, atom.z);
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
scene.add(mesh);
return mesh;
}
const normalAtoms = atoms.filter((atom) => atom.type === "normal");
const fixedAtoms = atoms.filter((atom) => atom.type === "fixed");
const mobileAtoms = atoms.filter((atom) => atom.type === "mobile");
createAtomInstances(normalAtoms, normalMaterial);
createAtomInstances(fixedAtoms, fixedMaterial);
const mobileMesh = createAtomInstances(mobileAtoms, mobileMaterial);
mobileMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
const bonds = [];
function addBond(a, b) {
if (!a || !b) return;
bonds.push({ a, b });
}
// Bonds along each atomic row.
for (let row = 0; row < ROWS; row++) {
for (let col = 0; col < COLS - 1; col++) {
for (let depth = 0; depth < DEPTHS; depth++) {
addBond(
atomMap.get(atomKey(row, col, depth)),
atomMap.get(atomKey(row, col + 1, depth))
);
}
}
}
// Bonds through the depth of the cutaway.
for (let row = 0; row < ROWS; row++) {
for (let col = 0; col < COLS; col++) {
for (let depth = 0; depth < DEPTHS - 1; depth++) {
addBond(
atomMap.get(atomKey(row, col, depth)),
atomMap.get(atomKey(row, col, depth + 1))
);
}
}
}
// Closest diagonal neighbors. Extra candidates allow bonds to be exchanged
// as the mobile row advances past the stationary row.
for (let row = 0; row < ROWS - 1; row++) {
for (let col = 0; col < COLS; col++) {
for (let depth = 0; depth < DEPTHS; depth++) {
const lower = atomMap.get(atomKey(row, col, depth));
if (!lower) continue;
const candidates = row % 2 === 0
? [col - 1, col, col + 1]
: [col, col + 1, col + 2];
for (const upperCol of candidates) {
addBond(
lower,
atomMap.get(atomKey(row + 1, upperCol, depth))
);
}
}
}
}
const staticBonds = bonds.filter(
(bond) => bond.a.row !== MOBILE_ROW && bond.b.row !== MOBILE_ROW
);
const dynamicBonds = bonds.filter(
(bond) => bond.a.row === MOBILE_ROW || bond.b.row === MOBILE_ROW
);
const staticBondMaterial = new THREE.MeshStandardMaterial({
color: 0x647b8c,
metalness: 0.72,
roughness: 0.4,
transparent: true,
opacity: 0.76
});
const dynamicBondMaterial = new THREE.MeshStandardMaterial({
color: 0xb88749,
metalness: 0.7,
roughness: 0.35,
transparent: true,
opacity: 0.88
});
const bondGeometry = new THREE.CylinderGeometry(
0.052,
0.052,
1,
8,
1,
false
);
const staticBondMesh = new THREE.InstancedMesh(
bondGeometry,
staticBondMaterial,
staticBonds.length
);
const dynamicBondMesh = new THREE.InstancedMesh(
bondGeometry,
dynamicBondMaterial,
dynamicBonds.length
);
staticBondMesh.frustumCulled = false;
dynamicBondMesh.frustumCulled = false;
dynamicBondMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(staticBondMesh, dynamicBondMesh);
const tempA = new THREE.Vector3();
const tempB = new THREE.Vector3();
const tempDirection = new THREE.Vector3();
const tempMidpoint = new THREE.Vector3();
const tempQuaternion = new THREE.Quaternion();
const tempScale = new THREE.Vector3();
const tempMatrix = new THREE.Matrix4();
const yAxis = new THREE.Vector3(0, 1, 0);
function getAtomPosition(atom, displacement, target) {
target.set(
atom.x + (atom.row === MOBILE_ROW ? displacement : 0),
atom.y,
atom.z
);
return target;
}
function setBondInstance(mesh, index, a, b, visible = true) {
tempDirection.subVectors(b, a);
const length = tempDirection.length();
if (!visible || length < 0.0001) {
tempMatrix.compose(
tempMidpoint.set(0, -100, 0),
tempQuaternion.identity(),
tempScale.set(0.0001, 0.0001, 0.0001)
);
} else {
tempDirection.multiplyScalar(1 / length);
tempQuaternion.setFromUnitVectors(yAxis, tempDirection);
tempMidpoint.addVectors(a, b).multiplyScalar(0.5);
tempScale.set(1, length, 1);
tempMatrix.compose(tempMidpoint, tempQuaternion, tempScale);
}
mesh.setMatrixAt(index, tempMatrix);
}
staticBonds.forEach((bond, index) => {
getAtomPosition(bond.a, 0, tempA);
getAtomPosition(bond.b, 0, tempB);
setBondInstance(staticBondMesh, index, tempA, tempB, true);
});
staticBondMesh.instanceMatrix.needsUpdate = true;
function updateDynamicGeometry(displacement) {
mobileAtoms.forEach((atom, index) => {
tempMatrix.makeTranslation(
atom.x + displacement,
atom.y,
atom.z
);
mobileMesh.setMatrixAt(index, tempMatrix);
});
mobileMesh.instanceMatrix.needsUpdate = true;
dynamicBonds.forEach((bond, index) => {
getAtomPosition(bond.a, displacement, tempA);
getAtomPosition(bond.b, displacement, tempB);
const length = tempA.distanceTo(tempB);
const connectedToMobile =
bond.a.row === MOBILE_ROW || bond.b.row === MOBILE_ROW;
// Overstretched bonds disappear as the row exchanges neighbors.
const visible = length <= (connectedToMobile ? 2.15 : 2.8);
setBondInstance(dynamicBondMesh, index, tempA, tempB, visible);
});
dynamicBondMesh.instanceMatrix.needsUpdate = true;
}
// The highlighted slip plane lies between the fixed and mobile rows.
const slipPlane = new THREE.Mesh(
new THREE.PlaneGeometry(15.4, 4.7),
new THREE.MeshBasicMaterial({
color: 0xffad43,
transparent: true,
opacity: 0.035,
side: THREE.DoubleSide,
depthWrite: false
})
);
slipPlane.rotation.x = -Math.PI / 2;
slipPlane.position.y = 0.65;
scene.add(slipPlane);
const slipBorderPoints = [
new THREE.Vector3(-7.7, 0.665, -2.35),
new THREE.Vector3(7.7, 0.665, -2.35),
new THREE.Vector3(7.7, 0.665, 2.35),
new THREE.Vector3(-7.7, 0.665, 2.35),
new THREE.Vector3(-7.7, 0.665, -2.35)
];
const slipBorderMaterial = new THREE.LineDashedMaterial({
color: 0xffb653,
transparent: true,
opacity: 0.48,
dashSize: 0.22,
gapSize: 0.14
});
const slipBorder = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(slipBorderPoints),
slipBorderMaterial
);
slipBorder.computeLineDistances();
scene.add(slipBorder);
// Hatch marks identify the removed front slice of the cutaway.
const hatchPositions = [];
for (let x = -6.2; x < 6.2; x += 1.15) {
hatchPositions.push(
x, 1.95, 1.59,
Math.min(x + 1.0, 6.2), 2.62, 1.59
);
hatchPositions.push(
x, 2.62, 1.59,
Math.min(x + 1.0, 6.2), 3.29, 1.59
);
hatchPositions.push(
x, 3.29, 1.59,
Math.min(x + 1.0, 6.2), 3.96, 1.59
);
}
const hatchGeometry = new THREE.BufferGeometry();
hatchGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(hatchPositions, 3)
);
const hatch = new THREE.LineSegments(
hatchGeometry,
new THREE.LineBasicMaterial({
color: 0x4f8ba6,
transparent: true,
opacity: 0.2
})
);
scene.add(hatch);
const cutBorder = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-6.2, 1.95, 1.59),
new THREE.Vector3(6.2, 1.95, 1.59),
new THREE.Vector3(6.2, 4.55, 1.59),
new THREE.Vector3(-6.2, 4.55, 1.59),
new THREE.Vector3(-6.2, 1.95, 1.59)
]),
new THREE.LineDashedMaterial({
color: 0x5594ae,
transparent: true,
opacity: 0.38,
dashSize: 0.15,
gapSize: 0.1
})
);
cutBorder.computeLineDistances();
scene.add(cutBorder);
const slipArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-6.45, 1.82, 2.25),
2.85,
0xffae45,
0.42,
0.22
);
slipArrow.line.material.transparent = true;
slipArrow.line.material.opacity = 0.88;
slipArrow.line.material.depthTest = false;
slipArrow.cone.material.transparent = true;
slipArrow.cone.material.opacity = 0.9;
slipArrow.cone.material.depthTest = false;
slipArrow.renderOrder = 5;
scene.add(slipArrow);
const animation = {
elapsed: 0,
playing: true,
completed: false,
phase: "",
lastDisplacement: -1
};
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
if (reducedMotion) {
animation.playing = false;
pauseButton.textContent = "Play";
}
function smoothStep(t) {
const x = THREE.MathUtils.clamp(t, 0, 1);
return x * x * x * (x * (x * 6 - 15) + 10);
}
function displacementAt(time) {
if (time <= SLIP_START) return 0;
if (time >= SLIP_END) return SPACING;
const progress = (time - SLIP_START) / (SLIP_END - SLIP_START);
return SPACING * smoothStep(progress);
}
function setPhase(phase) {
if (animation.phase === phase) return;
animation.phase = phase;
if (phase === "ready") {
status.classList.remove("retained");
statusText.textContent = "Elastic loading";
phaseTitle.textContent = "Neighbors begin to load";
phaseCopy.textContent =
"The highlighted row advances across the slip plane. Near-neighbor bonds stretch, break and reform while the blue row remains fixed.";
} else if (phase === "slip") {
status.classList.remove("retained");
statusText.textContent = "Slip in progress";
phaseTitle.textContent = "Rows exchange neighbors";
phaseCopy.textContent =
"The mobile row passes the fixed row. As it moves, stretched connections disappear and shorter connections form with new neighboring atoms.";
} else {
status.classList.add("retained");
statusText.textContent = "Plastic offset retained";
phaseTitle.textContent = "The deformation remains";
phaseCopy.textContent =
"When the applied motion stops, the row stays displaced. This retained shear is the qualitative signature of plastic deformation.";
}
}
function replay() {
animation.elapsed = 0;
animation.playing = true;
animation.completed = false;
animation.phase = "";
pauseButton.textContent = "Pause";
updateDynamicGeometry(0);
}
pauseButton.addEventListener("click", () => {
if (animation.completed) {
replay();
return;
}
animation.playing = !animation.playing;
pauseButton.textContent = animation.playing ? "Pause" : "Resume";
});
replayButton.addEventListener("click", replay);
function resetCamera() {
cameraState.yaw = 0.22;
cameraState.pitch = 0.28;
cameraState.zoom = 1;
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
resetViewButton.addEventListener("click", resetCamera);
// Custom camera interaction; no examples or addon modules are used.
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.yaw -= deltaX * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.004,
0.08,
0.85
);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.55
);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
function updateCamera() {
const radius = 20;
const horizontalRadius = Math.cos(cameraState.pitch) * radius;
camera.position.set(
cameraTarget.x + Math.sin(cameraState.yaw) * horizontalRadius,
cameraTarget.y + Math.sin(cameraState.pitch) * radius,
cameraTarget.z + Math.cos(cameraState.yaw) * horizontalRadius
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve the lattice width on narrow screens.
const frustumHeight = Math.max(10.4, 16.2 / aspect);
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const mobileAnchor = new THREE.Vector3();
const fixedAnchor = new THREE.Vector3();
const planeAnchor = new THREE.Vector3(-6.2, 0.65, 2.45);
const projected = new THREE.Vector3();
const mobileEnd = mobileAtoms.find(
(atom) => atom.col === COLS - 1 && atom.depth === DEPTHS - 1
);
const fixedEnd = fixedAtoms.find(
(atom) => atom.col === COLS - 1 && atom.depth === DEPTHS - 1
);
function placeLabel(element, worldPosition, reverse = false) {
projected.copy(worldPosition).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.transform = reverse
? "translate(-100%, -50%)"
: "translate(0, -50%)";
}
function updateLabels(displacement) {
mobileAnchor.set(
mobileEnd.x + displacement,
mobileEnd.y,
mobileEnd.z + 0.46
);
fixedAnchor.set(
fixedEnd.x + 0.15,
fixedEnd.y,
fixedEnd.z + 0.46
);
placeLabel(mobileLabel, mobileAnchor, true);
placeLabel(fixedLabel, fixedAnchor, true);
placeLabel(planeLabel, planeAnchor, false);
}
updateDynamicGeometry(0);
setPhase("ready");
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (animation.playing && !animation.completed) {
animation.elapsed += delta;
if (animation.elapsed >= TOTAL_TIME) {
animation.elapsed = TOTAL_TIME;
animation.completed = true;
animation.playing = false;
pauseButton.textContent = "Replay";
}
}
const displacement = displacementAt(animation.elapsed);
const progress = THREE.MathUtils.clamp(
animation.elapsed / TOTAL_TIME,
0,
1
);
if (animation.completed) {
setPhase("retained");
} else if (animation.elapsed >= SLIP_START) {
setPhase("slip");
} else {
setPhase("ready");
}
if (
Math.abs(displacement - animation.lastDisplacement) > 0.0001 ||
animation.lastDisplacement < 0
) {
updateDynamicGeometry(displacement);
animation.lastDisplacement = displacement;
}
const slipActivity =
animation.elapsed > SLIP_START && animation.elapsed < SLIP_END
? Math.sin(
Math.PI *
(animation.elapsed - SLIP_START) /
(SLIP_END - SLIP_START)
)
: 0;
mobileMaterial.emissiveIntensity = 0.42 + slipActivity * 0.65;
fixedMaterial.emissiveIntensity = 0.34 + slipActivity * 0.18;
slipPlane.material.opacity = 0.035 + slipActivity * 0.055;
slipBorderMaterial.opacity = 0.48 + slipActivity * 0.35;
slipArrow.line.material.opacity = 0.64 + slipActivity * 0.36;
slipArrow.cone.material.opacity = 0.68 + slipActivity * 0.32;
displacementText.textContent = `${(displacement / SPACING).toFixed(2)} a`;
progressFill.style.width = `${progress * 100}%`;
updateCamera();
renderer.render(scene, camera);
updateLabels(displacement);
}
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```