Prompt specification
Build or customize the Three.js 3D scene "Surface roughness reduction 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: Surface roughness reduction model
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/surface-roughness-reduction-model-x0298
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: surface roughness reduction model. Move an abrasive pad over a ridged demonstration surface; show peaks becoming lower through a labeled schematic removal process while collected particles appear beside the path. Return one self-contained HTML file.
Working Three.js Starter (surface-roughness-reduction-model-x0298):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Surface Roughness Reduction Model</title>
<style>
:root {
--ink: #20343a;
--muted: #667579;
--paper: rgba(249, 248, 242, 0.84);
--line: rgba(32, 52, 58, 0.14);
--orange: #d8793d;
--orange-soft: rgba(216, 121, 61, 0.12);
--teal: #2d6d70;
--green: #63846b;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e7df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene canvas.dragging { cursor: grabbing; }
.ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.panel {
background: var(--paper);
border: 1px solid var(--line);
box-shadow: 0 14px 40px rgba(35, 48, 47, 0.09);
backdrop-filter: blur(13px);
-webkit-backdrop-filter: blur(13px);
}
.brand {
position: absolute;
top: 22px;
left: 22px;
width: 316px;
padding: 18px 20px 16px;
border-radius: 4px 18px 18px 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--orange);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 3px;
background: var(--orange);
border-radius: 4px;
}
h1 {
margin: 0;
max-width: 270px;
font-size: clamp(24px, 2.3vw, 34px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 780;
}
.brand p {
margin: 11px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.process {
position: absolute;
top: 202px;
left: 22px;
width: 292px;
padding: 15px;
border-radius: 16px;
}
.panel-title {
display: flex;
justify-content: space-between;
align-items: center;
margin: 1px 3px 12px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel-title span:last-child {
color: var(--orange);
}
.step {
position: relative;
display: grid;
grid-template-columns: 43px 1fr;
gap: 10px;
align-items: center;
min-height: 59px;
padding: 8px;
border: 1px solid transparent;
border-radius: 11px;
transition: background 180ms ease, border-color 180ms ease;
}
.step + .step { margin-top: 3px; }
.step.active {
background: var(--orange-soft);
border-color: rgba(216, 121, 61, 0.25);
}
.step-icon {
display: grid;
place-items: center;
width: 43px;
height: 38px;
border-radius: 9px;
color: var(--teal);
background: rgba(45, 109, 112, 0.08);
border: 1px solid rgba(45, 109, 112, 0.12);
}
.step-icon svg {
width: 34px;
height: 28px;
overflow: visible;
}
.step strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
letter-spacing: 0.08em;
}
.step p {
margin: 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.35;
}
.step-index {
position: absolute;
right: 8px;
top: 7px;
color: rgba(32, 52, 58, 0.32);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
}
.telemetry {
position: absolute;
top: 22px;
right: 22px;
width: 232px;
padding: 17px;
border-radius: 18px 4px 18px 18px;
}
.status {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 15px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 5px rgba(216, 121, 61, 0.11);
animation: pulse 1.5s ease-in-out infinite;
}
.status-dot.done {
background: var(--green);
box-shadow: 0 0 0 5px rgba(99, 132, 107, 0.12);
animation: none;
}
@keyframes pulse {
50% { box-shadow: 0 0 0 8px rgba(216, 121, 61, 0.03); }
}
.metric-head {
display: flex;
align-items: end;
justify-content: space-between;
gap: 12px;
}
.metric-head span {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.metric-head strong {
font-size: 31px;
line-height: 0.9;
letter-spacing: -0.05em;
font-variant-numeric: tabular-nums;
}
.meter {
height: 6px;
margin: 13px 0 17px;
overflow: hidden;
border-radius: 8px;
background: rgba(32, 52, 58, 0.09);
}
.meter > i {
display: block;
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #d8793d, #e0a15f);
transition: width 120ms linear;
}
.data-row {
display: flex;
justify-content: space-between;
align-items: center;
color: var(--muted);
font-size: 10px;
}
.data-row + .data-row { margin-top: 9px; }
.data-row strong {
color: var(--ink);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.pass-meter {
height: 3px;
margin-top: 12px;
overflow: hidden;
background: rgba(32, 52, 58, 0.08);
}
.pass-meter > i {
display: block;
width: 0;
height: 100%;
background: var(--teal);
}
.controls {
position: absolute;
left: 50%;
bottom: 22px;
display: flex;
gap: 8px;
padding: 7px;
border-radius: 15px;
transform: translateX(-50%);
pointer-events: auto;
}
button {
appearance: none;
min-height: 38px;
padding: 0 14px;
border: 1px solid transparent;
border-radius: 9px;
color: var(--ink);
background: transparent;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.02em;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: rgba(32, 52, 58, 0.06);
}
button.primary {
min-width: 88px;
color: #fffaf2;
background: var(--orange);
}
button.primary:hover { background: #c96c35; }
.hint {
position: absolute;
right: 23px;
bottom: 26px;
color: rgba(32, 52, 58, 0.56);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.04em;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.scene-label {
position: absolute;
display: none;
min-width: 124px;
padding: 9px 11px;
transform: translate(-50%, -50%);
border-left: 3px solid var(--orange);
border-radius: 3px 10px 10px 3px;
background: rgba(250, 249, 244, 0.9);
box-shadow: 0 9px 24px rgba(32, 52, 58, 0.12);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
white-space: nowrap;
}
.scene-label b {
display: block;
color: var(--ink);
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-label span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9.5px;
}
.scene-label.teal { border-left-color: var(--teal); }
.scene-label.green { border-left-color: var(--green); }
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: var(--muted);
background: #e9e7df;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
}
@media (max-width: 760px) {
.brand {
top: 12px;
left: 12px;
width: min(300px, calc(100vw - 24px));
padding: 14px 16px;
}
h1 { font-size: 24px; }
.brand p { display: none; }
.process { display: none; }
.telemetry {
top: auto;
right: 12px;
bottom: 70px;
width: 190px;
padding: 13px;
}
.metric-head strong { font-size: 25px; }
.controls {
left: 12px;
right: 12px;
bottom: 12px;
justify-content: center;
transform: none;
}
button { padding: 0 10px; }
.hint { display: none; }
.scene-label { transform: translate(-50%, -50%) scale(0.86); }
}
@media (max-height: 670px) {
.process { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header class="brand panel">
<div class="eyebrow">Tribology / Demonstration</div>
<h1>Surface Roughness<br>Reduction Model</h1>
<p>A low-poly material-removal schematic showing how abrasive contact lowers ridge crests and redirects fragments into a side collector.</p>
</header>
<aside class="process panel">
<div class="panel-title">
<span>Schematic removal</span>
<span>01—03</span>
</div>
<div class="step active" data-step="0">
<div class="step-icon" aria-hidden="true">
<svg viewBox="0 0 40 30">
<path d="M3 23 L9 15 L15 23 L21 15 L27 23 L33 15 L38 20" fill="none" stroke="currentColor" stroke-width="2"/>
<rect x="10" y="3" width="20" height="7" rx="1.5" fill="currentColor" opacity=".72"/>
<path d="M20 11v4" stroke="currentColor" stroke-width="2"/>
</svg>
</div>
<div>
<strong>CONTACT</strong>
<p>Pressure and abrasive grains find the highest ridge crests.</p>
</div>
<span class="step-index">01</span>
</div>
<div class="step" data-step="1">
<div class="step-icon" aria-hidden="true">
<svg viewBox="0 0 40 30">
<path d="M4 24 L11 16 L18 23 L25 15 L31 21 L37 16" fill="none" stroke="currentColor" stroke-width="2"/>
<path d="M21 3l6 5-6 5-6-5z" fill="currentColor"/>
<path d="M22 14l4 3-5 4-4-3z" fill="currentColor" opacity=".65"/>
<path d="M10 8l4 3-4 4-4-3z" fill="currentColor" opacity=".42"/>
</svg>
</div>
<div>
<strong>SHEAR</strong>
<p>Fragments detach where the local peak exceeds the contact plane.</p>
</div>
<span class="step-index">02</span>
</div>
<div class="step" data-step="2">
<div class="step-icon" aria-hidden="true">
<svg viewBox="0 0 40 30">
<path d="M3 25 L10 18 L16 25 L23 18 L29 24 L37 17" fill="none" stroke="currentColor" stroke-width="2"/>
<path d="M21 5l4 3-4 4-4-3z" fill="currentColor"/>
<path d="M31 9l4 3-4 4-4-3z" fill="currentColor" opacity=".65"/>
<path d="M14 4l3 2-3 3-3-2z" fill="currentColor" opacity=".42"/>
</svg>
</div>
<div>
<strong>DEPOSIT</strong>
<p>Removed particles collect beside the nominal abrasive path.</p>
</div>
<span class="step-index">03</span>
</div>
</aside>
<aside class="telemetry panel" aria-live="polite">
<div class="status">
<i id="statusDot" class="status-dot"></i>
<span id="statusText">Cutting pass</span>
</div>
<div class="metric-head">
<span>Normalized Ra</span>
<strong id="roughValue">1.00</strong>
</div>
<div class="meter"><i id="roughFill" style="width:100%"></i></div>
<div class="data-row">
<span>Peak removal</span>
<strong id="cutValue">0%</strong>
</div>
<div class="data-row">
<span>Collected fragments</span>
<strong id="chipValue">0</strong>
</div>
<div class="pass-meter"><i id="progressFill"></i></div>
</aside>
<div class="controls panel">
<button id="toggleBtn" class="primary" type="button">Pause</button>
<button id="replayBtn" type="button">Replay pass</button>
<button id="resetBtn" type="button">Reset view</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</div>
<div id="labels">
<div id="labelPad" class="scene-label">
<b>Abrasive pad</b>
<span>contact pressure + cutting grains</span>
</div>
<div id="labelCut" class="scene-label">
<b id="cutLabelTitle">Sheared crest</b>
<span>high points are removed</span>
</div>
<div id="labelChips" class="scene-label green">
<b>Collected particles</b>
<span>collector beside the path</span>
</div>
<div id="labelShoulder" class="scene-label teal">
<b>Reference shoulder</b>
<span>untouched surface roughness</span>
</div>
</div>
<div id="loading">INITIALIZING SURFACE MODEL…</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e7df);
scene.fog = new THREE.Fog(0xe9e7df, 17, 30);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive 3D surface roughness reduction model");
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(38, window.innerWidth / window.innerHeight, 0.1, 80);
const hemisphere = new THREE.HemisphereLight(0xf9f7ed, 0x6f807b, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d9, 3.1);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d9d7, 1.15);
fillLight.position.set(7, 5, -6);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(36, 36),
new THREE.MeshStandardMaterial({ color: 0xe7e4da, roughness: 1, metalness: 0 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(28, 28, 0xb6bbb2, 0xd0d1c8);
grid.position.y = -0.012;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
const WIDTH = 5.6;
const DEPTH = 8.4;
const BASE_TOP = 0.48;
const RIDGE_HEIGHT = 0.64;
const PAD_WIDTH = 4.2;
const PAD_DEPTH = 1.25;
const PAD_START_Z = 5.5;
const PAD_END_Z = -5.0;
const PASS_DURATION = 12;
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0xaeb4ad,
roughness: 0.94,
metalness: 0.02
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(WIDTH + 0.14, BASE_TOP, DEPTH + 0.14),
baseMaterial
);
base.position.y = BASE_TOP / 2;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const baseEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(base.geometry),
new THREE.LineBasicMaterial({ color: 0x65716e, transparent: true, opacity: 0.45 })
);
baseEdges.position.copy(base.position);
scene.add(baseEdges);
const nx = 35;
const nz = 49;
const vertexCount = (nx + 1) * (nz + 1);
const positions = new Float32Array(vertexCount * 3);
const colors = new Float32Array(vertexCount * 3);
const indices = [];
for (let iz = 0; iz <= nz; iz++) {
for (let ix = 0; ix <= nx; ix++) {
const x = -WIDTH / 2 + (ix / nx) * WIDTH;
const z = -DEPTH / 2 + (iz / nz) * DEPTH;
const i = (iz * (nx + 1) + ix) * 3;
positions[i] = x;
positions[i + 1] = BASE_TOP;
positions[i + 2] = z;
}
}
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const a = iz * (nx + 1) + ix;
const b = a + 1;
const c = a + nx + 1;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const surfaceGeometry = new THREE.BufferGeometry();
surfaceGeometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
surfaceGeometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
surfaceGeometry.setIndex(indices);
const surfaceMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.9,
metalness: 0.015,
flatShading: true
});
const surface = new THREE.Mesh(surfaceGeometry, surfaceMaterial);
surface.castShadow = true;
surface.receiveShadow = true;
scene.add(surface);
const valleyColor = new THREE.Color(0x82999b);
const roughColor = new THREE.Color(0xb8c6c3);
const wornColor = new THREE.Color(0xd9d4c5);
function ridgeProfile(x) {
const period = WIDTH / 7;
const u = ((x + WIDTH / 2) % period) / period;
return 1 - Math.abs(1 - 2 * u);
}
function currentPadZ(progress) {
return THREE.MathUtils.lerp(PAD_START_Z, PAD_END_Z, progress);
}
function updateSurface(progress) {
const padZ = currentPadZ(progress);
const positionAttribute = surfaceGeometry.attributes.position;
const colorAttribute = surfaceGeometry.attributes.color;
for (let iz = 0; iz <= nz; iz++) {
const z = -DEPTH / 2 + (iz / nz) * DEPTH;
const processedZ = THREE.MathUtils.smoothstep(
z,
padZ - PAD_DEPTH * 0.5,
padZ + PAD_DEPTH * 0.5
);
for (let ix = 0; ix <= nx; ix++) {
const x = -WIDTH / 2 + (ix / nx) * WIDTH;
const profile = ridgeProfile(x);
const laneMask = 1 - THREE.MathUtils.smoothstep(Math.abs(x), 1.84, 2.18);
const wear = laneMask * processedZ;
const height = BASE_TOP + profile * RIDGE_HEIGHT * (1 - 0.86 * wear);
const index = iz * (nx + 1) + ix;
positionAttribute.array[index * 3 + 1] = height;
let r = THREE.MathUtils.lerp(valleyColor.r, roughColor.r, profile);
let g = THREE.MathUtils.lerp(valleyColor.g, roughColor.g, profile);
let b = THREE.MathUtils.lerp(valleyColor.b, roughColor.b, profile);
const wearBlend = wear * profile * 0.78;
r = THREE.MathUtils.lerp(r, wornColor.r, wearBlend);
g = THREE.MathUtils.lerp(g, wornColor.g, wearBlend);
b = THREE.MathUtils.lerp(b, wornColor.b, wearBlend);
colorAttribute.array[index * 3] = r;
colorAttribute.array[index * 3 + 1] = g;
colorAttribute.array[index * 3 + 2] = b;
}
}
positionAttribute.needsUpdate = true;
colorAttribute.needsUpdate = true;
surfaceGeometry.computeVertexNormals();
surfaceGeometry.computeBoundingSphere();
}
const pathEdgeMaterial = new THREE.LineDashedMaterial({
color: 0xc97a43,
dashSize: 0.2,
gapSize: 0.13,
transparent: true,
opacity: 0.78
});
for (const x of [-2.25, 2.25]) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, BASE_TOP + RIDGE_HEIGHT + 0.035, -DEPTH / 2),
new THREE.Vector3(x, BASE_TOP + RIDGE_HEIGHT + 0.035, DEPTH / 2)
]);
const line = new THREE.Line(geometry, pathEdgeMaterial);
line.computeLineDistances();
scene.add(line);
}
const tray = new THREE.Group();
const trayMaterial = new THREE.MeshStandardMaterial({
color: 0x30484d,
roughness: 0.83,
metalness: 0.08
});
const wellMaterial = new THREE.MeshStandardMaterial({
color: 0x1e3034,
roughness: 1,
metalness: 0
});
const trayBase = new THREE.Mesh(new THREE.BoxGeometry(1.2, 0.12, 7.65), trayMaterial);
trayBase.position.set(3.55, 0.06, 0);
trayBase.castShadow = true;
trayBase.receiveShadow = true;
tray.add(trayBase);
const trayWell = new THREE.Mesh(new THREE.BoxGeometry(0.96, 0.08, 7.36), wellMaterial);
trayWell.position.set(3.55, 0.15, 0);
trayWell.receiveShadow = true;
tray.add(trayWell);
for (const x of [3.00, 4.10]) {
const rim = new THREE.Mesh(new THREE.BoxGeometry(0.10, 0.24, 7.65), trayMaterial);
rim.position.set(x, 0.19, 0);
rim.castShadow = true;
tray.add(rim);
}
for (const z of [-3.78, 3.78]) {
const end = new THREE.Mesh(new THREE.BoxGeometry(1.2, 0.24, 0.10), trayMaterial);
end.position.set(3.55, 0.19, z);
end.castShadow = true;
tray.add(end);
}
scene.add(tray);
const pad = new THREE.Group();
const abrasiveMaterial = new THREE.MeshStandardMaterial({
color: 0x252c2c,
roughness: 1,
metalness: 0.03,
flatShading: true
});
const backingMaterial = new THREE.MeshStandardMaterial({
color: 0xd9793d,
roughness: 0.72,
metalness: 0.02
});
const capMaterial = new THREE.MeshStandardMaterial({
color: 0x315b61,
roughness: 0.65,
metalness: 0.04
});
const handleMaterial = new THREE.MeshStandardMaterial({
color: 0x263b40,
roughness: 0.7,
metalness: 0.12
});
function addBox(parent, size, position, material) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
addBox(pad, [4.18, 0.18, 1.15], [0, 0.09, 0], abrasiveMaterial);
addBox(pad, [4.28, 0.25, 1.25], [0, 0.305, 0], backingMaterial);
addBox(pad, [3.65, 0.16, 1.0], [0, 0.51, 0], capMaterial);
addBox(pad, [0.18, 0.44, 0.22], [-1.04, 0.78, 0], handleMaterial);
addBox(pad, [0.18, 0.44, 0.22], [1.04, 0.78, 0], handleMaterial);
addBox(pad, [2.35, 0.18, 0.22], [0, 1.02, 0], handleMaterial);
const directionArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, -1),
new THREE.Vector3(0, 0.62, 0.38),
1.15,
0xf5c778,
0.25,
0.16
);
pad.add(directionArrow);
scene.add(pad);
for (let i = 0; i < 3; i++) {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, -1),
new THREE.Vector3(-3.35, 0.035, 3.15 - i * 1.65),
1.05,
0xc97039,
0.24,
0.15
);
scene.add(arrow);
}
const chipCount = 190;
const chipGeometry = new THREE.TetrahedronGeometry(0.075, 0);
const chipMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.78,
metalness: 0,
flatShading: true
});
const chips = new THREE.InstancedMesh(chipGeometry, chipMaterial, chipCount);
chips.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
chips.castShadow = true;
chips.receiveShadow = true;
chips.frustumCulled = false;
scene.add(chips);
const chipPalette = [
new THREE.Color(0xd8a160),
new THREE.Color(0xe8c891),
new THREE.Color(0xb97843),
new THREE.Color(0xf0d7a8)
];
const chipData = [];
let randomSeed = 92017;
function seededRandom() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
for (let i = 0; i < chipCount; i++) {
const threshold = 0.055 + (i / (chipCount - 1)) * 0.91 + (seededRandom() - 0.5) * 0.008;
const normalized = THREE.MathUtils.clamp((threshold - 0.055) / 0.91, 0, 1);
chipData.push({
threshold,
targetX: 3.16 + seededRandom() * 0.76,
targetY: 0.215 + seededRandom() * 0.075,
targetZ: 4.0 - normalized * 7.85 + (seededRandom() - 0.5) * 0.12,
scale: 0.62 + seededRandom() * 0.68,
rx: seededRandom() * Math.PI,
ry: seededRandom() * Math.PI,
rz: seededRandom() * Math.PI
});
chips.setColorAt(i, chipPalette[Math.floor(seededRandom() * chipPalette.length)]);
}
chipData.sort((a, b) => a.threshold - b.threshold);
if (chips.instanceColor) chips.instanceColor.needsUpdate = true;
const chipDummy = new THREE.Object3D();
let visibleChipCount = 0;
function updateChips(progress) {
visibleChipCount = 0;
for (let i = 0; i < chipData.length; i++) {
const chip = chipData[i];
const age = progress - chip.threshold;
if (age < 0) {
chipDummy.position.set(0, -20, 0);
chipDummy.scale.setScalar(0);
chipDummy.updateMatrix();
chips.setMatrixAt(i, chipDummy.matrix);
continue;
}
visibleChipCount++;
const travel = THREE.MathUtils.clamp(age / 0.06, 0, 1);
const eased = 1 - Math.pow(1 - travel, 3);
const sourceZ = THREE.MathUtils.lerp(PAD_START_Z, PAD_END_Z, chip.threshold);
const sourceY = BASE_TOP + 0.08 + RIDGE_HEIGHT * (1 - 0.86 * chip.threshold);
chipDummy.position.set(
THREE.MathUtils.lerp(2.23, chip.targetX, eased),
THREE.MathUtils.lerp(sourceY, chip.targetY, eased) - Math.sin(eased * Math.PI) * 0.17,
THREE.MathUtils.lerp(sourceZ, chip.targetZ, eased)
);
const grow = THREE.MathUtils.smoothstep(age, 0, 0.12);
chipDummy.scale.setScalar(grow * chip.scale);
chipDummy.rotation.set(
chip.rx + age * 8,
chip.ry + age * 11,
chip.rz + age * 7
);
chipDummy.updateMatrix();
chips.setMatrixAt(i, chipDummy.matrix);
}
chips.instanceMatrix.needsUpdate = true;
}
const cameraState = {
radius: window.innerWidth < 700 ? 15.2 : 12.8,
theta: 0.72,
phi: 1.04,
target: new THREE.Vector3(0, 0.52, 0)
};
function resetCamera() {
cameraState.radius = window.innerWidth < 700 ? 15.2 : 12.8;
cameraState.theta = 0.72;
cameraState.phi = 1.04;
cameraState.target.set(0, 0.52, 0);
}
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.classList.add("dragging");
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;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + dy * 0.005, 0.38, 1.38);
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.009,
8.5,
19
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
const labelPad = document.getElementById("labelPad");
const labelCut = document.getElementById("labelCut");
const labelChips = document.getElementById("labelChips");
const labelShoulder = document.getElementById("labelShoulder");
const cutLabelTitle = document.getElementById("cutLabelTitle");
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, offsetX = 0, offsetY = 0, visible = true) {
projected.copy(worldPosition).project(camera);
const onScreen = visible && projected.z > -1 && projected.z < 1;
element.style.display = onScreen ? "block" : "none";
if (!onScreen) 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.left = `${x}px`;
element.style.top = `${y}px`;
}
const roughValue = document.getElementById("roughValue");
const roughFill = document.getElementById("roughFill");
const cutValue = document.getElementById("cutValue");
const chipValue = document.getElementById("chipValue");
const progressFill = document.getElementById("progressFill");
const statusText = document.getElementById("statusText");
const statusDot = document.getElementById("statusDot");
const toggleBtn = document.getElementById("toggleBtn");
const replayBtn = document.getElementById("replayBtn");
const resetBtn = document.getElementById("resetBtn");
const steps = [...document.querySelectorAll(".step")];
let progress = 0;
let running = true;
let lastSurfaceProgress = -1;
function updateHUD() {
const roughness = 1 - 0.84 * progress;
const removal = Math.round(84 * progress);
roughValue.textContent = roughness.toFixed(2);
roughFill.style.width = `${roughness * 100}%`;
cutValue.textContent = `${removal}%`;
chipValue.textContent = `${visibleChipCount}`;
progressFill.style.width = `${progress * 100}%`;
const stage = progress < 0.12 ? 0 : progress < 0.74 ? 1 : 2;
steps.forEach((step, index) => {
step.classList.toggle("active", index === stage);
step.classList.toggle("done", index < stage || progress >= 1);
});
if (progress >= 1) {
statusText.textContent = "Pass complete";
statusDot.classList.add("done");
toggleBtn.textContent = "Run again";
} else if (running) {
statusText.textContent = "Cutting pass";
statusDot.classList.remove("done");
toggleBtn.textContent = "Pause";
} else {
statusText.textContent = "Pass paused";
statusDot.classList.remove("done");
toggleBtn.textContent = "Resume";
}
}
function updateModel() {
const padZ = currentPadZ(progress);
const padY = BASE_TOP + 0.08 + RIDGE_HEIGHT * (1 - 0.86 * progress);
pad.position.set(0, padY, padZ);
updateSurface(progress);
updateChips(progress);
updateHUD();
}
toggleBtn.addEventListener("click", () => {
if (progress >= 1) {
progress = 0;
running = true;
} else {
running = !running;
}
updateModel();
});
replayBtn.addEventListener("click", () => {
progress = 0;
running = true;
updateModel();
});
resetBtn.addEventListener("click", resetCamera);
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
updateModel();
updateCamera();
loading.style.display = "none";
const clock = new THREE.Clock();
const padAnchor = new THREE.Vector3();
const cutAnchor = new THREE.Vector3();
const chipAnchor = new THREE.Vector3(3.55, 0.67, 1.15);
const shoulderAnchor = new THREE.Vector3(-2.48, 1.2, -1.55);
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (running) {
progress = Math.min(1, progress + delta / PASS_DURATION);
if (progress >= 1) running = false;
}
if (Math.abs(progress - lastSurfaceProgress) > 0.00001) {
updateModel();
lastSurfaceProgress = progress;
}
updateCamera();
const padZ = currentPadZ(progress);
padAnchor.set(0, pad.position.y + 1.30, padZ);
placeLabel(labelPad, padAnchor, 20, -8, true);
const cutZ = Math.min(DEPTH / 2 - 0.1, padZ + 1.35);
const cutWear = THREE.MathUtils.smoothstep(
cutZ,
padZ - PAD_DEPTH * 0.5,
padZ + PAD_DEPTH * 0.5
);
cutAnchor.set(0.3, BASE_TOP + RIDGE_HEIGHT * (1 - 0.86 * cutWear) + 0.18, cutZ);
cutLabelTitle.textContent = progress > 0.74 ? "Lowered crest" : "Sheared crest";
placeLabel(labelCut, cutAnchor, -34, -24, progress > 0.14);
placeLabel(labelChips, chipAnchor, 35, -10, visibleChipCount > 4);
placeLabel(labelShoulder, shoulderAnchor, -25, -14, true);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```