Prompt specification
Build or customize the Three.js 3D scene "Surface treatment comparison exhibit" 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 treatment comparison exhibit
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/surface-treatment-comparison-exhibit-x0300
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: surface treatment comparison exhibit. Create interchangeable material panels and abrasive representations; users compare grain size, contact area, and visible roughness indicators in a qualitative model with its assumptions displayed. Return one self-contained HTML file.
Working Three.js Starter (surface-treatment-comparison-exhibit-x0300):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#101719" />
<title>Surface Lab — Treatment Comparison Exhibit</title>
<style>
:root {
--bg: #101719;
--panel: #151f22;
--panel-2: #1b282c;
--line: rgba(226, 237, 237, 0.11);
--text: #e8eeee;
--muted: #92a2a6;
--accent: #f0834a;
--accent-2: #f4b16a;
--gallery: #e8e4da;
--gallery-dark: #cfc9be;
--good: #77b89b;
--radius: 12px;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
width: 100%;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
height: 100vh;
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
button:focus-visible,
input:focus-visible,
summary:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
.app-header {
height: 72px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: #101719;
position: relative;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
min-width: 0;
}
.brand-mark {
width: 38px;
height: 38px;
position: relative;
flex: 0 0 auto;
transform: rotate(-7deg);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
inset: 3px 11px 13px 2px;
background: var(--accent);
clip-path: polygon(0 0, 100% 14%, 74% 100%, 12% 83%);
}
.brand-mark::after {
inset: 12px 2px 3px 14px;
background: #d8e3e2;
clip-path: polygon(13% 0, 100% 11%, 88% 87%, 0 100%);
opacity: 0.9;
}
.brand-title {
font-size: 13px;
font-weight: 780;
letter-spacing: 0.14em;
line-height: 1.25;
}
.brand-subtitle {
margin-top: 4px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.header-meta {
display: flex;
align-items: center;
gap: 10px;
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 8px;
border: 1px solid var(--line);
border-radius: 999px;
padding: 8px 12px;
color: #b9c6c7;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.status-pill::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(240, 131, 74, 0.12);
}
.workspace {
height: calc(100vh - 72px);
display: grid;
grid-template-columns: 294px minmax(420px, 1fr) 316px;
min-height: 0;
}
.sidebar {
min-height: 0;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #34464b transparent;
background: var(--panel);
}
.controls-sidebar {
border-right: 1px solid var(--line);
}
.analysis-sidebar {
border-left: 1px solid var(--line);
}
.sidebar-section {
padding: 21px 20px;
border-bottom: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 15px;
}
.section-heading h2,
.section-heading h3 {
margin: 0;
font-size: 11px;
line-height: 1.2;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.section-number {
color: var(--accent);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.section-note {
margin: -7px 0 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.slot-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.slot-tab {
border: 1px solid var(--line);
background: #111a1d;
border-radius: 8px;
padding: 10px 7px;
cursor: pointer;
text-align: left;
transition: 160ms ease;
}
.slot-tab:hover {
border-color: rgba(240, 131, 74, 0.45);
}
.slot-tab.is-active {
border-color: var(--accent);
background: rgba(240, 131, 74, 0.1);
}
.slot-tab strong {
display: block;
font-size: 15px;
line-height: 1;
}
.slot-tab span {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.palette {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.swatch-button {
min-height: 59px;
border: 1px solid var(--line);
background: #111a1d;
border-radius: 9px;
padding: 9px;
cursor: grab;
text-align: left;
transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}
.swatch-button:hover {
transform: translateY(-1px);
border-color: rgba(240, 131, 74, 0.5);
}
.swatch-button:active {
cursor: grabbing;
}
.swatch-button.is-selected {
border-color: var(--accent);
background: rgba(240, 131, 74, 0.09);
}
.swatch-chip {
display: block;
width: 100%;
height: 17px;
margin-bottom: 7px;
border-radius: 4px;
background:
linear-gradient(135deg, rgba(255,255,255,.35), transparent 48%),
var(--swatch);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);
}
.swatch-name {
display: block;
color: #dbe3e3;
font-size: 10px;
font-weight: 650;
line-height: 1.2;
}
.swatch-meta {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.control-row + .control-row {
margin-top: 21px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
font-size: 11px;
}
.control-label span:first-child {
color: #cbd5d5;
font-weight: 650;
}
.control-value {
color: var(--accent-2);
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0;
border-radius: 99px;
accent-color: var(--accent);
cursor: pointer;
}
.range-limits {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #67797e;
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.transfer-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.action-button {
border: 1px solid var(--line);
border-radius: 8px;
padding: 10px 8px;
background: #111a1d;
color: #cbd5d5;
font-size: 10px;
font-weight: 650;
cursor: pointer;
transition: 150ms ease;
}
.action-button:hover {
border-color: rgba(240, 131, 74, 0.48);
color: #fff;
background: rgba(240, 131, 74, 0.07);
}
.scene-shell {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: var(--gallery);
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.scene-shell.is-drop-target::after {
content: "DROP TO FIT ACTIVE SPECIMEN";
position: absolute;
inset: 18px;
z-index: 6;
display: grid;
place-items: center;
border: 2px dashed var(--accent);
border-radius: 12px;
background: rgba(16, 23, 25, 0.55);
color: white;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.15em;
pointer-events: none;
}
.scene-top {
position: absolute;
z-index: 4;
top: 20px;
left: 22px;
right: 22px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.scene-kicker {
color: #59676a;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.scene-kicker h1 {
margin: 7px 0 0;
max-width: 390px;
color: #1b2729;
font-size: clamp(17px, 2vw, 27px);
font-weight: 540;
line-height: 1.08;
letter-spacing: -0.035em;
}
.scene-actions {
display: flex;
gap: 7px;
pointer-events: auto;
}
.scene-button {
min-width: 38px;
height: 36px;
padding: 0 11px;
border: 1px solid rgba(24, 37, 40, 0.15);
border-radius: 8px;
background: rgba(248, 246, 240, 0.75);
color: #304044;
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 760;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
.scene-button:hover,
.scene-button.is-active {
color: #111a1d;
background: #f5f1e9;
border-color: rgba(240, 131, 74, 0.75);
}
.world-labels {
position: absolute;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
min-width: 120px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 9px;
background: rgba(22, 31, 33, 0.88);
box-shadow: 0 8px 30px rgba(24, 31, 31, 0.12);
color: white;
transform: translate(-50%, -100%);
backdrop-filter: blur(7px);
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -13px;
width: 1px;
height: 13px;
background: rgba(22, 31, 33, 0.48);
}
.label-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.label-id {
color: var(--accent-2);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.label-score {
color: #c9d4d4;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.label-name {
margin-top: 5px;
font-size: 10px;
font-weight: 650;
}
.scene-bottom {
position: absolute;
z-index: 4;
left: 22px;
right: 22px;
bottom: 18px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.scene-hint {
color: #627174;
font-size: 9px;
line-height: 1.5;
letter-spacing: 0.04em;
}
.scene-hint strong {
color: #344447;
}
.legend {
display: flex;
align-items: center;
gap: 8px;
color: #56666a;
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-ramp {
width: 100px;
height: 6px;
border-radius: 99px;
background: linear-gradient(90deg, #78a994, #d7b66e, #d16843);
}
.active-badge {
position: absolute;
z-index: 5;
left: 22px;
bottom: 48px;
display: inline-flex;
align-items: center;
gap: 7px;
color: #334346;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.active-badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
}
.comparison-header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.comparison-header h2 {
margin: 0;
font-size: 16px;
letter-spacing: -0.02em;
}
.comparison-header p {
margin: 4px 0 0;
color: var(--muted);
font-size: 10px;
}
.tiny-tag {
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 5px;
color: var(--muted);
font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
text-transform: uppercase;
}
.comparison-list {
display: grid;
gap: 8px;
}
.compare-row {
width: 100%;
display: grid;
grid-template-columns: 28px minmax(0, 1fr) 34px;
align-items: center;
gap: 10px;
padding: 11px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: #111a1d;
cursor: pointer;
text-align: left;
transition: 150ms ease;
}
.compare-row:hover {
border-color: rgba(240, 131, 74, 0.42);
}
.compare-row.is-active {
border-color: var(--accent);
background: rgba(240, 131, 74, 0.08);
}
.row-id {
color: var(--accent-2);
font: 800 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.row-body {
min-width: 0;
}
.row-name {
display: block;
overflow: hidden;
color: #e4ebeb;
font-size: 10px;
font-weight: 680;
text-overflow: ellipsis;
white-space: nowrap;
}
.row-meta {
display: block;
margin-top: 4px;
color: var(--muted);
font: 8px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.mini-track {
height: 3px;
margin-top: 7px;
overflow: hidden;
border-radius: 99px;
background: #2b393d;
}
.mini-fill {
display: block;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #78a994, #d7b66e, #d16843);
}
.rough-value {
text-align: right;
color: #dce5e5;
font: 800 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.selected-readout {
display: grid;
grid-template-columns: 94px 1fr;
gap: 15px;
align-items: center;
}
.rough-dial {
--pct: 40%;
width: 94px;
height: 94px;
display: grid;
place-items: center;
border-radius: 50%;
background: conic-gradient(var(--accent) var(--pct), #2a383c 0);
position: relative;
}
.rough-dial::before {
content: "";
position: absolute;
inset: 8px;
border-radius: 50%;
background: var(--panel);
}
.dial-content {
position: relative;
text-align: center;
}
.dial-number {
display: block;
font: 800 23px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.dial-unit {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 7px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.metric-list {
display: grid;
gap: 10px;
}
.metric-item {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
}
.metric-item span:first-child {
color: var(--muted);
font-size: 9px;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.metric-item strong {
color: #edf2f2;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.secondary-metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 16px;
}
.secondary-metric {
padding: 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: #111a1d;
}
.secondary-metric span {
display: block;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.secondary-metric strong {
display: block;
margin-top: 6px;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.formula {
padding: 12px;
border: 1px solid rgba(240, 131, 74, 0.24);
border-radius: 9px;
background: rgba(240, 131, 74, 0.055);
}
.formula-label {
color: var(--accent-2);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.formula code {
display: block;
margin-top: 8px;
color: #dce6e6;
font: 10px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: normal;
}
.formula p {
margin: 9px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.5;
}
.assumption-list {
margin: 0;
padding: 0;
list-style: none;
display: grid;
gap: 10px;
}
.assumption-list li {
position: relative;
padding-left: 15px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.assumption-list li::before {
content: "";
position: absolute;
left: 0;
top: 6px;
width: 5px;
height: 5px;
background: var(--accent);
transform: rotate(45deg);
}
details {
border: 1px solid var(--line);
border-radius: 9px;
overflow: hidden;
}
summary {
padding: 11px 12px;
color: #cad5d5;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
list-style: none;
background: #111a1d;
}
summary::-webkit-details-marker {
display: none;
}
summary::after {
content: "+";
float: right;
color: var(--accent);
font-size: 13px;
}
details[open] summary::after {
content: "−";
}
.details-body {
padding: 12px;
border-top: 1px solid var(--line);
}
.input-list {
display: grid;
gap: 8px;
}
.input-row {
display: flex;
justify-content: space-between;
gap: 10px;
color: var(--muted);
font-size: 9px;
}
.input-row strong {
color: #d7e0e0;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 1120px) {
.workspace {
grid-template-columns: 260px minmax(380px, 1fr) 280px;
}
.sidebar-section {
padding-left: 16px;
padding-right: 16px;
}
.palette {
grid-template-columns: 1fr;
}
}
@media (max-width: 900px) {
body {
height: auto;
overflow: auto;
}
.app-header {
position: sticky;
top: 0;
}
.header-meta .status-pill:first-child {
display: none;
}
.workspace {
height: auto;
display: flex;
flex-direction: column;
}
.scene-shell {
order: -1;
height: 60vh;
min-height: 470px;
}
.sidebar {
overflow: visible;
}
.controls-sidebar {
border-right: 0;
border-top: 1px solid var(--line);
}
.analysis-sidebar {
border-left: 0;
border-top: 1px solid var(--line);
}
.palette {
grid-template-columns: repeat(4, 1fr);
}
.scene-bottom {
align-items: flex-start;
}
.legend {
display: none;
}
}
@media (max-width: 590px) {
.app-header {
height: 64px;
padding: 0 14px;
}
.brand-subtitle {
display: none;
}
.brand-title {
font-size: 11px;
}
.header-meta {
display: none;
}
.workspace {
min-height: calc(100vh - 64px);
}
.scene-shell {
height: 57vh;
min-height: 410px;
}
.scene-top {
top: 14px;
left: 14px;
right: 14px;
}
.scene-kicker h1 {
max-width: 210px;
font-size: 17px;
}
.scene-button {
width: 35px;
padding: 0;
overflow: hidden;
color: transparent;
position: relative;
}
.scene-button::first-letter {
color: #304044;
}
.palette {
grid-template-columns: 1fr 1fr;
}
.scene-bottom {
left: 14px;
right: 14px;
bottom: 12px;
}
.active-badge {
left: 14px;
}
.world-label {
min-width: 96px;
padding: 6px 7px;
}
.label-name {
font-size: 8px;
}
}
</style>
</head>
<body>
<header class="app-header">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="brand-title">SURFACE LAB / TREATMENT COMPARISON</div>
<div class="brand-subtitle">Interchangeable material study · Exhibit 03</div>
</div>
</div>
<div class="header-meta">
<div class="status-pill">Qualitative model</div>
<div class="status-pill">Not a process prediction</div>
</div>
</header>
<main class="workspace">
<aside class="sidebar controls-sidebar" aria-label="Specimen controls">
<section class="sidebar-section">
<div class="section-heading">
<h2>Active specimen</h2>
<span class="section-number">01</span>
</div>
<div class="slot-tabs" id="slotTabs">
<button class="slot-tab is-active" data-slot="0" type="button">
<strong>A</strong><span>Specimen</span>
</button>
<button class="slot-tab" data-slot="1" type="button">
<strong>B</strong><span>Specimen</span>
</button>
<button class="slot-tab" data-slot="2" type="button">
<strong>C</strong><span>Specimen</span>
</button>
</div>
</section>
<section class="sidebar-section">
<div class="section-heading">
<h2>Material panel</h2>
<span class="section-number">02</span>
</div>
<p class="section-note">Click a finish or drag it onto the active specimen.</p>
<div class="palette" id="finishPalette"></div>
</section>
<section class="sidebar-section">
<div class="section-heading">
<h2>Abrasive media</h2>
<span class="section-number">03</span>
</div>
<p class="section-note">Media geometry and color are representative, not to scale.</p>
<div class="palette" id="abrasivePalette"></div>
</section>
<section class="sidebar-section">
<div class="section-heading">
<h2>Process inputs</h2>
<span class="section-number">04</span>
</div>
<div class="control-row">
<label class="control-label" for="grainRange">
<span>Grain size</span>
<output class="control-value" id="grainValue">28 μm</output>
</label>
<input id="grainRange" type="range" min="5" max="150" step="1" value="28" />
<div class="range-limits"><span>5 μm</span><span>150 μm</span></div>
</div>
<div class="control-row">
<label class="control-label" for="contactRange">
<span>Effective contact</span>
<output class="control-value" id="contactValue">58%</output>
</label>
<input id="contactRange" type="range" min="5" max="100" step="1" value="58" />
<div class="range-limits"><span>SPARSE</span><span>DENSE</span></div>
</div>
</section>
<section class="sidebar-section">
<div class="section-heading">
<h2>Interchange</h2>
<span class="section-number">05</span>
</div>
<div class="transfer-actions">
<button class="action-button" id="swapButton" type="button">⇄ Swap panels</button>
<button class="action-button" id="copyButton" type="button">Copy → next</button>
</div>
</section>
</aside>
<section class="scene-shell" id="sceneShell" aria-label="Interactive 3D comparison exhibit">
<div id="viewport"></div>
<div class="scene-top">
<div class="scene-kicker">
Live material model
<h1>Three specimens.<br />One controlled comparison.</h1>
</div>
<div class="scene-actions">
<button class="scene-button" id="rotateButton" type="button" aria-label="Toggle automatic rotation">Auto</button>
<button class="scene-button" id="resetButton" type="button" aria-label="Reset camera">Reset</button>
</div>
</div>
<div class="world-labels" id="worldLabels"></div>
<div class="active-badge" id="activeBadge">Editing specimen A</div>
<div class="scene-bottom">
<div class="scene-hint">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom · <strong>Click a panel</strong> to edit
</div>
<div class="legend">
<span>Visible roughness</span>
<span>Low</span>
<span class="legend-ramp"></span>
<span>High</span>
</div>
</div>
</section>
<aside class="sidebar analysis-sidebar" aria-label="Qualitative analysis">
<section class="sidebar-section">
<div class="comparison-header">
<div>
<h2>Comparison</h2>
<p>Relative visible-roughness index</p>
</div>
<span class="tiny-tag">0–100</span>
</div>
<div class="comparison-list" id="comparisonList"></div>
</section>
<section class="sidebar-section">
<div class="section-heading">
<h2>Selected readout</h2>
<span class="section-number" id="selectedNumber">A</span>
</div>
<div class="selected-readout">
<div class="rough-dial" id="roughDial">
<div class="dial-content">
<span class="dial-number" id="roughNumber">42</span>
<span class="dial-unit">Roughness</span>
</div>
</div>
<div class="metric-list">
<div class="metric-item">
<span>Grain</span><strong id="metricGrain">28 μm</strong>
</div>
<div class="metric-item">
<span>Contact</span><strong id="metricContact">58%</strong>
</div>
<div class="metric-item">
<span>Finish</span><strong id="metricFinish">Brushed 304</strong>
</div>
<div class="metric-item">
<span>Media</span><strong id="metricAbrasive">Glass bead</strong>
</div>
</div>
</div>
<div class="secondary-metrics">
<div class="secondary-metric">
<span>Cut potential</span>
<strong id="cutPotential">39 / 100</strong>
</div>
<div class="secondary-metric">
<span>Uniformity</span>
<strong id="uniformity">62 / 100</strong>
</div>
</div>
</section>
<section class="sidebar-section">
<div class="section-heading">
<h2>Qualitative model</h2>
<span class="section-number">FORM</span>
</div>
<div class="formula">
<div class="formula-label">Visible roughness proxy</div>
<code>R = clamp(0.18 + 0.42F + G(0.10 + 0.42S) + (1−C)(0.08 + 0.15S) − 0.05CP)</code>
<p>
F: finish baseline · S: abrasive scar · G: normalized grain ·
C: normalized contact · P: polishing response.
</p>
</div>
</section>
<section class="sidebar-section">
<details open>
<summary>Model inputs</summary>
<div class="details-body">
<div class="input-list">
<div class="input-row"><span>Finish baseline</span><strong id="inputFinish">0.22</strong></div>
<div class="input-row"><span>Abrasive scar</span><strong id="inputScar">0.28</strong></div>
<div class="input-row"><span>Polishing response</span><strong id="inputPolish">0.32</strong></div>
<div class="input-row"><span>Grain normalized</span><strong id="inputGrain">0.16</strong></div>
<div class="input-row"><span>Contact normalized</span><strong id="inputContact">0.56</strong></div>
</div>
</div>
</details>
</section>
<section class="sidebar-section">
<details open>
<summary>Assumptions & limits</summary>
<div class="details-body">
<ul class="assumption-list">
<li>All values are qualitative visual proxies; the roughness index is not an Ra measurement.</li>
<li>Grain is normalized over 5–150 μm. Force, speed, angle, and substrate thickness are not modeled.</li>
<li>Contact represents an effective footprint percentage, not applied pressure or true contact mechanics.</li>
<li>Particle size, shape, and count are illustrative. The render uses a fixed seed for repeatable comparison.</li>
<li>Compare presets only under the same model assumptions; do not use these values for process certification.</li>
</ul>
</div>
</details>
</section>
</aside>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const treatments = {
brushed: {
name: "Brushed 304",
short: "BRUSHED 304",
color: "#aeb8bf",
metalness: 0.86,
roughness: 0.31,
baseline: 0.22,
response: 0.72,
texture: "brushed"
},
blasted: {
name: "Blasted Al",
short: "BLASTED AL",
color: "#909da4",
metalness: 0.78,
roughness: 0.58,
baseline: 0.56,
response: 0.48,
texture: "blast"
},
anodized: {
name: "Anodized Al",
short: "ANODIZED AL",
color: "#3f7489",
metalness: 0.72,
roughness: 0.36,
baseline: 0.35,
response: 0.81,
texture: "anodized"
},
powder: {
name: "Powder coat",
short: "POWDER COAT",
color: "#d3c2a9",
metalness: 0.12,
roughness: 0.46,
baseline: 0.43,
response: 0.62,
texture: "powder"
}
};
const abrasives = {
bead: {
name: "Glass bead",
color: "#8ca8b6",
shape: "ico",
hardness: 0.45,
scar: 0.28,
polish: 0.32,
meta: "ROUND / LOW SCAR"
},
alumina: {
name: "Alumina",
color: "#d58c39",
shape: "octa",
hardness: 0.78,
scar: 0.62,
polish: 0.18,
meta: "ANGULAR / MED SCAR"
},
carbide: {
name: "Silicon carbide",
color: "#3d464e",
shape: "tetra",
hardness: 0.98,
scar: 0.82,
polish: 0.08,
meta: "SHARP / HIGH SCAR"
},
ceramic: {
name: "Ceramic media",
color: "#d8c6a2",
shape: "ico",
hardness: 0.70,
scar: 0.45,
polish: 0.40,
meta: "DENSE / CONTROLLED"
}
};
const specimens = [
{ finish: "brushed", abrasive: "bead", grain: 28, contact: 58 },
{ finish: "blasted", abrasive: "alumina", grain: 82, contact: 36 },
{ finish: "anodized", abrasive: "carbide", grain: 120, contact: 72 }
];
const viewport = document.getElementById("viewport");
const sceneShell = document.getElementById("sceneShell");
const worldLabels = document.getElementById("worldLabels");
const comparisonList = document.getElementById("comparisonList");
const grainRange = document.getElementById("grainRange");
const contactRange = document.getElementById("contactRange");
let activeSpecimen = 0;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e8e4da");
scene.fog = new THREE.Fog("#e8e4da", 18, 42);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
viewport.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.42, 0);
let yaw = 0.13;
let pitch = 0.20;
let desiredYaw = yaw;
let desiredPitch = pitch;
let zoom = 1;
let desiredZoom = zoom;
let autoRotate = false;
const ambient = new THREE.HemisphereLight("#f8fbfa", "#8e8171", 2.0);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight("#fff7e9", 3.1);
keyLight.position.set(-5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight("#c8e2ea", 1.45);
rimLight.position.set(8, 5, -5);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({ color: "#ddd8ce", roughness: 0.95, metalness: 0 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.035;
floor.receiveShadow = true;
scene.add(floor);
const backWall = new THREE.Mesh(
new THREE.PlaneGeometry(40, 18),
new THREE.MeshStandardMaterial({ color: "#e4e0d7", roughness: 1 })
);
backWall.position.set(0, 8, -6.5);
backWall.receiveShadow = true;
scene.add(backWall);
const seam = new THREE.Mesh(
new THREE.BoxGeometry(18, 0.025, 0.04),
new THREE.MeshStandardMaterial({ color: "#c4beb3", roughness: 1 })
);
seam.position.set(0, 0.006, -3.1);
scene.add(seam);
const geometryCache = {
ico: new THREE.IcosahedronGeometry(1, 0),
octa: new THREE.OctahedronGeometry(1, 0),
tetra: new THREE.TetrahedronGeometry(1, 0)
};
const materialCache = new Map();
function getAbrasiveMaterial(type) {
if (!materialCache.has(type)) {
materialCache.set(type, new THREE.MeshStandardMaterial({
color: abrasives[type].color,
roughness: 0.72,
metalness: type === "carbide" ? 0.42 : 0.08,
flatShading: true
}));
}
return materialCache.get(type);
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (1664525 * value + 1013904223) >>> 0;
return value / 4294967296;
};
}
function makeFinishTexture(treatment, seed = 12) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 512;
const ctx = canvas.getContext("2d");
const random = seededRandom(seed);
const base = treatment.color;
ctx.fillStyle = base;
ctx.fillRect(0, 0, 512, 512);
const gradient = ctx.createLinearGradient(0, 0, 512, 512);
gradient.addColorStop(0, "rgba(255,255,255,0.16)");
gradient.addColorStop(0.45, "rgba(255,255,255,0)");
gradient.addColorStop(1, "rgba(20,30,32,0.14)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 512, 512);
if (treatment.texture === "brushed") {
for (let i = 0; i < 260; i++) {
const y = random() * 512;
const x = random() * 512;
const length = 40 + random() * 310;
ctx.strokeStyle = random() > 0.5
? `rgba(255,255,255,${0.025 + random() * 0.07})`
: `rgba(25,34,37,${0.025 + random() * 0.055})`;
ctx.lineWidth = 0.4 + random() * 1.1;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(Math.min(512, x + length), y + (random() - 0.5) * 1.3);
ctx.stroke();
}
} else if (treatment.texture === "blast") {
for (let i = 0; i < 3300; i++) {
const x = random() * 512;
const y = random() * 512;
const radius = 0.35 + random() * 2.2;
ctx.fillStyle = random() > 0.48
? `rgba(240,247,246,${0.025 + random() * 0.11})`
: `rgba(20,28,31,${0.025 + random() * 0.12})`;
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
ctx.fill();
}
} else if (treatment.texture === "anodized") {
for (let i = 0; i < 85; i++) {
const x = random() * 512;
ctx.strokeStyle = `rgba(225,242,245,${0.015 + random() * 0.045})`;
ctx.lineWidth = 0.5 + random() * 1.4;
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x + (random() - 0.5) * 7, 512);
ctx.stroke();
}
for (let i = 0; i < 800; i++) {
ctx.fillStyle = `rgba(10,35,44,${random() * 0.035})`;
ctx.fillRect(random() * 512, random() * 512, 1, 1);
}
} else {
for (let i = 0; i < 2300; i++) {
const x = random() * 512;
const y = random() * 512;
const radius = 0.4 + random() * 1.5;
ctx.fillStyle = random() > 0.5
? `rgba(255,255,255,${0.025 + random() * 0.07})`
: `rgba(63,49,34,${0.02 + random() * 0.07})`;
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
ctx.fill();
}
}
const vignette = ctx.createRadialGradient(256, 240, 70, 256, 256, 370);
vignette.addColorStop(0, "rgba(255,255,255,0)");
vignette.addColorStop(1, "rgba(18,26,28,0.12)");
ctx.fillStyle = vignette;
ctx.fillRect(0, 0, 512, 512);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const specimenObjects = [];
const panelWidth = 2.02;
const panelHeight = 1.38;
function createSpecimen(index, xPosition) {
const root = new THREE.Group();
root.position.x = xPosition;
scene.add(root);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(2.13, 2.23, 0.14, 8),
new THREE.MeshStandardMaterial({ color: "#d0c9bd", roughness: 0.91, metalness: 0 })
);
platform.position.y = 0.025;
platform.receiveShadow = true;
platform.castShadow = true;
root.add(platform);
const stem = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 1.05, 0.18),
new THREE.MeshStandardMaterial({ color: "#263236", roughness: 0.56, metalness: 0.48 })
);
stem.position.set(0, 0.65, -0.14);
stem.castShadow = true;
root.add(stem);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(1.12, 0.08, 0.68),
new THREE.MeshStandardMaterial({ color: "#29373b", roughness: 0.62, metalness: 0.34 })
);
foot.position.set(0, 0.17, 0);
foot.castShadow = true;
root.add(foot);
const frameMaterial = new THREE.MeshStandardMaterial({
color: "#293438",
roughness: 0.45,
metalness: 0.62
});
const frame = new THREE.Mesh(
new THREE.BoxGeometry(panelWidth + 0.16, panelHeight + 0.16, 0.16),
frameMaterial
);
frame.position.set(0, 1.82, -0.035);
frame.castShadow = true;
frame.receiveShadow = true;
frame.userData.specimenIndex = index;
root.add(frame);
const sideMaterial = new THREE.MeshStandardMaterial({
color: treatments.brushed.color,
roughness: 0.31,
metalness: 0.86
});
const frontMaterial = new THREE.MeshStandardMaterial({
color: "#ffffff",
roughness: 0.31,
metalness: 0.86
});
const panel = new THREE.Mesh(
new THREE.BoxGeometry(panelWidth, panelHeight, 0.16),
[sideMaterial, sideMaterial, sideMaterial, sideMaterial, frontMaterial, sideMaterial]
);
panel.position.set(0, 1.82, 0.035);
panel.castShadow = true;
panel.receiveShadow = true;
panel.userData.specimenIndex = index;
root.add(panel);
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(frame.geometry),
new THREE.LineBasicMaterial({ color: "#f0834a", transparent: true, opacity: 0.25 })
);
outline.position.copy(frame.position);
root.add(outline);
const patchMaterial = new THREE.MeshBasicMaterial({
color: "#ef9b53",
transparent: true,
opacity: 0.13,
depthWrite: false,
side: THREE.DoubleSide
});
const patch = new THREE.Mesh(new THREE.CircleGeometry(1, 28), patchMaterial);
patch.position.set(0.19, 1.69, 0.123);
root.add(patch);
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.97, 1, 28),
new THREE.MeshBasicMaterial({
color: "#d77a42",
transparent: true,
opacity: 0.35,
depthWrite: false,
side: THREE.DoubleSide
})
);
ring.position.copy(patch.position);
ring.position.z += 0.002;
root.add(ring);
const particleGroup = new THREE.Group();
root.add(particleGroup);
const label = document.createElement("div");
label.className = "world-label";
worldLabels.appendChild(label);
const object = {
root,
platform,
frame,
panel,
sideMaterial,
frontMaterial,
outline,
patch,
ring,
particleGroup,
label,
texture: null
};
specimenObjects.push(object);
return object;
}
createSpecimen(0, -3.28);
createSpecimen(1, 0);
createSpecimen(2, 3.28);
function calculateModel(state) {
const finish = treatments[state.finish];
const abrasive = abrasives[state.abrasive];
const G = THREE.MathUtils.clamp((state.grain - 5) / 145, 0, 1);
const C = THREE.MathUtils.clamp((state.contact - 5) / 95, 0, 1);
const roughness = THREE.MathUtils.clamp(
0.18 +
0.42 * finish.baseline +
G * (0.10 + 0.42 * abrasive.scar) +
(1 - C) * (0.08 + 0.15 * abrasive.scar) -
0.05 * C * abrasive.polish,
0.02,
0.99
);
const uniformity = THREE.MathUtils.clamp(
0.20 +
0.47 * C +
(1 - G) * 0.17 +
finish.response * 0.12 -
G * abrasive.scar * 0.08,
0.05,
0.99
);
const cutPotential = THREE.MathUtils.clamp(
Math.pow(G, 0.72) * abrasive.hardness * (0.25 + 0.75 * C),
0.01,
0.99
);
return { G, C, roughness, uniformity, cutPotential };
}
function roughnessName(value) {
if (value < 0.29) return "Smooth";
if (value < 0.49) return "Satin";
if (value < 0.7) return "Textured";
return "Coarse";
}
function regenerateParticles(object, state, index) {
while (object.particleGroup.children.length) {
object.particleGroup.remove(object.particleGroup.children[0]);
}
const random = seededRandom(1800 + index * 97 + state.grain * 3 + state.contact * 7);
const count = Math.round(7 + state.contact * 0.65);
const size = 0.022 + (state.grain / 150) * 0.053;
const material = getAbrasiveMaterial(state.abrasive);
const geometry = geometryCache[abrasives[state.abrasive].shape];
for (let i = 0; i < count; i++) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random());
const x = 0.19 + Math.cos(angle) * radius * 0.69;
const y = 1.69 + Math.sin(angle) * radius * 0.40;
const particle = new THREE.Mesh(geometry, material);
const individualSize = size * (0.70 + random() * 0.65);
particle.scale.set(
individualSize * (0.78 + random() * 0.45),
individualSize * (0.78 + random() * 0.45),
individualSize * (0.60 + random() * 0.50)
);
particle.position.set(x, y, 0.145 + random() * 0.055);
particle.rotation.set(random() * Math.PI, random() * Math.PI, random() * Math.PI);
particle.castShadow = true;
particle.receiveShadow = true;
object.particleGroup.add(particle);
}
}
function updateSpecimen(index) {
const state = specimens[index];
const object = specimenObjects[index];
const treatment = treatments[state.finish];
if (object.texture) object.texture.dispose();
object.texture = makeFinishTexture(treatment, 44 + index * 31);
object.frontMaterial.map = object.texture;
object.frontMaterial.roughness = treatment.roughness;
object.frontMaterial.metalness = treatment.metalness;
object.frontMaterial.needsUpdate = true;
object.sideMaterial.color.set(treatment.color);
object.sideMaterial.roughness = treatment.roughness;
object.sideMaterial.metalness = treatment.metalness;
object.outline.material.opacity = index === activeSpecimen ? 0.95 : 0.16;
object.outline.material.color.set(index === activeSpecimen ? "#f0834a" : "#5c686a");
const patchRadius = 0.30 + Math.sqrt(state.contact / 100) * 0.64;
object.patch.scale.set(patchRadius, patchRadius * 0.58, 1);
object.ring.scale.set(patchRadius, patchRadius * 0.58, 1);
object.patch.material.opacity = index === activeSpecimen ? 0.17 : 0.09;
object.ring.material.opacity = index === activeSpecimen ? 0.44 : 0.18;
regenerateParticles(object, state, index);
const model = calculateModel(state);
object.label.innerHTML = `
<div class="label-top">
<span class="label-id">${String.fromCharCode(65 + index)}</span>
<span class="label-score">R ${Math.round(model.roughness * 100)}</span>
</div>
<div class="label-name">${treatment.name}</div>
`;
}
function renderPalettes() {
const finishPalette = document.getElementById("finishPalette");
const abrasivePalette = document.getElementById("abrasivePalette");
finishPalette.innerHTML = Object.entries(treatments).map(([id, treatment]) => `
<button
class="swatch-button"
type="button"
draggable="true"
data-kind="finish"
data-id="${id}"
style="--swatch:${treatment.color}"
>
<span class="swatch-chip"></span>
<span class="swatch-name">${treatment.name}</span>
<span class="swatch-meta">Finish baseline ${treatment.baseline.toFixed(2)}</span>
</button>
`).join("");
abrasivePalette.innerHTML = Object.entries(abrasives).map(([id, abrasive]) => `
<button
class="swatch-button"
type="button"
draggable="true"
data-kind="abrasive"
data-id="${id}"
style="--swatch:${abrasive.color}"
>
<span class="swatch-chip"></span>
<span class="swatch-name">${abrasive.name}</span>
<span class="swatch-meta">${abrasive.meta}</span>
</button>
`).join("");
finishPalette.addEventListener("click", (event) => {
const button = event.target.closest("[data-kind='finish']");
if (!button) return;
specimens[activeSpecimen].finish = button.dataset.id;
updateSpecimen(activeSpecimen);
renderControls();
renderAnalysis();
});
abrasivePalette.addEventListener("click", (event) => {
const button = event.target.closest("[data-kind='abrasive']");
if (!button) return;
specimens[activeSpecimen].abrasive = button.dataset.id;
updateSpecimen(activeSpecimen);
renderControls();
renderAnalysis();
});
document.querySelectorAll(".swatch-button").forEach((button) => {
button.addEventListener("dragstart", (event) => {
event.dataTransfer.setData("text/plain", JSON.stringify({
kind: button.dataset.kind,
id: button.dataset.id
}));
event.dataTransfer.effectAllowed = "copy";
});
});
}
function renderControls() {
const state = specimens[activeSpecimen];
document.querySelectorAll(".slot-tab").forEach((button) => {
button.classList.toggle("is-active", Number(button.dataset.slot) === activeSpecimen);
});
document.querySelectorAll("[data-kind='finish']").forEach((button) => {
button.classList.toggle(
"is-selected",
button.dataset.kind === "finish" && button.dataset.id === state.finish
);
});
document.querySelectorAll("[data-kind='abrasive']").forEach((button) => {
button.classList.toggle(
"is-selected",
button.dataset.kind === "abrasive" && button.dataset.id === state.abrasive
);
});
grainRange.value = state.grain;
contactRange.value = state.contact;
document.getElementById("grainValue").textContent = `${state.grain} μm`;
document.getElementById("contactValue").textContent = `${state.contact}%`;
document.getElementById("activeBadge").textContent =
`Editing specimen ${String.fromCharCode(65 + activeSpecimen)}`;
}
function renderAnalysis() {
const state = specimens[activeSpecimen];
const model = calculateModel(state);
const finish = treatments[state.finish];
const abrasive = abrasives[state.abrasive];
comparisonList.innerHTML = specimens.map((item, index) => {
const itemModel = calculateModel(item);
const percent = Math.round(itemModel.roughness * 100);
return `
<button
class="compare-row ${index === activeSpecimen ? "is-active" : ""}"
type="button"
data-compare-slot="${index}"
>
<span class="row-id">${String.fromCharCode(65 + index)}</span>
<span class="row-body">
<span class="row-name">${treatments[item.finish].name} · ${abrasives[item.abrasive].name}</span>
<span class="row-meta">${item.grain} μm · ${item.contact}% contact · ${roughnessName(itemModel.roughness)}</span>
<span class="mini-track">
<span class="mini-fill" style="width:${percent}%"></span>
</span>
</span>
<span class="rough-value">${percent}</span>
</button>
`;
}).join("");
const roughnessPercent = Math.round(model.roughness * 100);
document.getElementById("roughNumber").textContent = roughnessPercent;
document.getElementById("roughDial").style.setProperty("--pct", `${roughnessPercent}%`);
document.getElementById("metricGrain").textContent = `${state.grain} μm`;
document.getElementById("metricContact").textContent = `${state.contact}%`;
document.getElementById("metricFinish").textContent = finish.name;
document.getElementById("metricAbrasive").textContent = abrasive.name;
document.getElementById("cutPotential").textContent = `${Math.round(model.cutPotential * 100)} / 100`;
document.getElementById("uniformity").textContent = `${Math.round(model.uniformity * 100)} / 100`;
document.getElementById("selectedNumber").textContent = String.fromCharCode(65 + activeSpecimen);
document.getElementById("inputFinish").textContent = finish.baseline.toFixed(2);
document.getElementById("inputScar").textContent = abrasive.scar.toFixed(2);
document.getElementById("inputPolish").textContent = abrasive.polish.toFixed(2);
document.getElementById("inputGrain").textContent = model.G.toFixed(2);
document.getElementById("inputContact").textContent = model.C.toFixed(2);
}
function setActiveSpecimen(index) {
activeSpecimen = index;
specimenObjects.forEach((_, specimenIndex) => updateSpecimen(specimenIndex));
renderControls();
renderAnalysis();
}
document.getElementById("slotTabs").addEventListener("click", (event) => {
const button = event.target.closest("[data-slot]");
if (!button) return;
setActiveSpecimen(Number(button.dataset.slot));
});
comparisonList.addEventListener("click", (event) => {
const button = event.target.closest("[data-compare-slot]");
if (!button) return;
setActiveSpecimen(Number(button.dataset.compareSlot));
});
grainRange.addEventListener("input", () => {
specimens[activeSpecimen].grain = Number(grainRange.value);
updateSpecimen(activeSpecimen);
renderControls();
renderAnalysis();
});
contactRange.addEventListener("input", () => {
specimens[activeSpecimen].contact = Number(contactRange.value);
updateSpecimen(activeSpecimen);
renderControls();
renderAnalysis();
});
document.getElementById("swapButton").addEventListener("click", () => {
const next = (activeSpecimen + 1) % specimens.length;
const temporary = specimens[activeSpecimen];
specimens[activeSpecimen] = specimens[next];
specimens[next] = temporary;
specimenObjects.forEach((_, index) => updateSpecimen(index));
renderControls();
renderAnalysis();
});
document.getElementById("copyButton").addEventListener("click", () => {
const next = (activeSpecimen + 1) % specimens.length;
specimens[next] = { ...specimens[activeSpecimen] };
specimenObjects.forEach((_, index) => updateSpecimen(index));
renderControls();
renderAnalysis();
});
sceneShell.addEventListener("dragover", (event) => {
event.preventDefault();
event.dataTransfer.dropEffect = "copy";
sceneShell.classList.add("is-drop-target");
});
sceneShell.addEventListener("dragleave", (event) => {
if (!sceneShell.contains(event.relatedTarget)) {
sceneShell.classList.remove("is-drop-target");
}
});
sceneShell.addEventListener("drop", (event) => {
event.preventDefault();
sceneShell.classList.remove("is-drop-target");
try {
const payload = JSON.parse(event.dataTransfer.getData("text/plain"));
if (payload.kind === "finish" && treatments[payload.id]) {
specimens[activeSpecimen].finish = payload.id;
}
if (payload.kind === "abrasive" && abrasives[payload.id]) {
specimens[activeSpecimen].abrasive = payload.id;
}
updateSpecimen(activeSpecimen);
renderControls();
renderAnalysis();
} catch (error) {
console.warn("Unable to apply dropped material.", error);
}
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerDown = true;
pointerMoved = false;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.abs(dx) + Math.abs(dy) > 3) pointerMoved = true;
if (pointerMoved) {
desiredYaw -= dx * 0.006;
desiredPitch = THREE.MathUtils.clamp(desiredPitch + dy * 0.0045, 0.06, 0.66);
}
previousX = event.clientX;
previousY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (pointerDown && !pointerMoved) {
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(specimenObjects.map((item) => item.panel), false);
if (hits.length) setActiveSpecimen(hits[0].object.userData.specimenIndex);
}
pointerDown = false;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
desiredZoom = THREE.MathUtils.clamp(
desiredZoom * Math.exp(event.deltaY * 0.001),
0.72,
1.68
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
desiredYaw = 0.13;
desiredPitch = 0.20;
desiredZoom = 1;
});
document.getElementById("resetButton").addEventListener("click", () => {
desiredYaw = 0.13;
desiredPitch = 0.20;
desiredZoom = 1;
});
document.getElementById("rotateButton").addEventListener("click", (event) => {
autoRotate = !autoRotate;
event.currentTarget.classList.toggle("is-active", autoRotate);
});
function resizeRenderer() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(viewport);
renderPalettes();
specimenObjects.forEach((_, index) => updateSpecimen(index));
renderControls();
renderAnalysis();
resizeRenderer();
const projected = new THREE.Vector3();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (autoRotate) desiredYaw += delta * 0.13;
yaw += (desiredYaw - yaw) * 0.09;
pitch += (desiredPitch - pitch) * 0.09;
zoom += (desiredZoom - zoom) * 0.09;
const fitFactor = Math.max(1, 1.12 / camera.aspect);
const radius = 10.5 * zoom * fitFactor;
const horizontal = Math.sin(yaw) * Math.cos(pitch) * radius;
const vertical = Math.sin(pitch) * radius;
const depth = Math.cos(yaw) * Math.cos(pitch) * radius;
camera.position.set(
cameraTarget.x + horizontal,
cameraTarget.y + vertical,
cameraTarget.z + depth
);
camera.lookAt(cameraTarget);
specimenObjects.forEach((object, index) => {
projected.set(object.root.position.x, 2.74, 0);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
object.label.style.display = visible ? "block" : "none";
object.label.style.left = `${(projected.x * 0.5 + 0.5) * viewport.clientWidth}px`;
object.label.style.top = `${(-projected.y * 0.5 + 0.5) * viewport.clientHeight}px`;
object.label.style.opacity = visible ? "1" : "0";
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```