Prompt specification
Build or customize the Three.js 3D scene "Fastener selection classroom 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: Fastener selection classroom exhibit
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/fastener-selection-classroom-exhibit-x0320
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing washers and contact pressure. Create interchangeable panel samples and load-spreading parts; users compare simplified contact diagrams and choose assemblies that visibly support the intended broad surface instead of a point. Low-poly.
Working Three.js Starter (fastener-selection-classroom-exhibit-x0320):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bolt Lab — Contact Pressure & Load Spreading</title>
<style>
:root {
color-scheme: dark;
--bg: #07111a;
--panel: #0d1b27;
--panel-2: #122536;
--line: #24394a;
--text: #edf6fa;
--muted: #91a8b8;
--cyan: #57dfca;
--cyan-soft: rgba(87, 223, 202, 0.13);
--amber: #ffc25c;
--red: #ff6b72;
--green: #66e3a4;
--radius: 14px;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
select,
input {
font: inherit;
}
button {
color: inherit;
}
.app {
height: 100vh;
display: grid;
grid-template-rows: 68px minmax(0, 1fr);
}
header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: rgba(7, 17, 26, 0.96);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 37px;
height: 37px;
display: grid;
place-items: center;
border: 1px solid rgba(87, 223, 202, 0.5);
border-radius: 10px;
color: var(--cyan);
background: var(--cyan-soft);
font-size: 21px;
font-weight: 800;
box-shadow: 0 0 22px rgba(87, 223, 202, 0.08);
}
.brand h1 {
margin: 0;
font-size: 16px;
letter-spacing: 0.02em;
}
.brand p {
margin: 3px 0 0;
color: var(--muted);
font-size: 11px;
}
.header-actions {
display: flex;
align-items: center;
gap: 8px;
}
.pill {
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
font-size: 11px;
white-space: nowrap;
}
.pill.dot::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px var(--cyan);
}
.ghost-button,
.primary-button,
.secondary-button {
border: 1px solid var(--line);
border-radius: 9px;
background: var(--panel-2);
cursor: pointer;
transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}
.ghost-button {
padding: 8px 11px;
color: var(--muted);
font-size: 12px;
}
.ghost-button:hover,
.secondary-button:hover {
border-color: #456074;
background: #172d40;
}
.ghost-button:active,
.secondary-button:active,
.primary-button:active {
transform: translateY(1px);
}
.layout {
min-height: 0;
display: grid;
grid-template-columns: 286px minmax(420px, 1fr) 344px;
}
.controls,
.analysis {
min-height: 0;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #2b465b transparent;
background: var(--panel);
}
.controls {
border-right: 1px solid var(--line);
}
.analysis {
border-left: 1px solid var(--line);
}
.panel-section {
padding: 18px;
border-bottom: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.section-heading h2 {
margin: 0;
color: #dceaf1;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-index {
color: #536e81;
font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.helper {
margin: -3px 0 13px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.sample-grid {
display: grid;
gap: 7px;
}
.sample-button {
width: 100%;
display: grid;
grid-template-columns: 32px 1fr auto;
align-items: center;
gap: 10px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: #0a1722;
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.sample-button:hover {
border-color: #3c596d;
background: #102230;
}
.sample-button.active {
border-color: rgba(87, 223, 202, 0.68);
background: var(--cyan-soft);
}
.sample-swatch {
width: 30px;
height: 30px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 7px;
background:
linear-gradient(135deg, rgba(255,255,255,.2), transparent 45%),
var(--swatch);
box-shadow: inset 0 0 8px rgba(0,0,0,.22);
}
.sample-name {
display: block;
font-size: 12px;
font-weight: 650;
}
.sample-meta {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.sample-check {
color: var(--cyan);
opacity: 0;
font-weight: 800;
}
.sample-button.active .sample-check {
opacity: 1;
}
.assembly-list {
display: grid;
gap: 7px;
}
.assembly-button {
width: 100%;
display: grid;
grid-template-columns: 34px 1fr;
align-items: center;
gap: 10px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: #0a1722;
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.assembly-button:hover {
border-color: #3c596d;
background: #102230;
}
.assembly-button.active {
border-color: rgba(87, 223, 202, 0.68);
background: var(--cyan-soft);
}
.part-icon {
width: 32px;
height: 32px;
display: grid;
place-items: center;
border: 1px solid #334c60;
border-radius: 8px;
color: #b8cad5;
background: #102331;
font-size: 18px;
}
.assembly-button.active .part-icon {
color: var(--cyan);
border-color: rgba(87, 223, 202, 0.45);
}
.part-name {
display: block;
font-size: 12px;
font-weight: 650;
}
.part-detail {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.field {
margin-top: 13px;
}
.field:first-child {
margin-top: 0;
}
.field-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
color: #a9bdca;
font-size: 11px;
}
.field-value {
color: var(--text);
font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
select {
width: 100%;
padding: 9px 30px 9px 10px;
border: 1px solid var(--line);
border-radius: 9px;
outline: none;
color: var(--text);
background: #0a1722;
font-size: 12px;
}
select:focus {
border-color: var(--cyan);
}
input[type="range"] {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
.range-limits {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: #617c90;
font-size: 9px;
}
.info-box {
margin-top: 12px;
padding: 10px;
border-left: 2px solid var(--cyan);
border-radius: 0 8px 8px 0;
color: var(--muted);
background: rgba(87, 223, 202, 0.055);
font-size: 10px;
line-height: 1.5;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 35%, rgba(38, 77, 96, 0.22), transparent 44%),
#08131e;
}
#three-host,
#three-host canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#three-host canvas {
touch-action: none;
cursor: grab;
}
#three-host canvas.dragging {
cursor: grabbing;
}
.scene-title {
position: absolute;
top: 18px;
left: 18px;
z-index: 3;
pointer-events: none;
}
.scene-title .eyebrow {
color: var(--cyan);
font: 700 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.scene-title h2 {
margin: 5px 0 0;
font-size: 17px;
font-weight: 650;
}
.scene-title p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
}
.scene-tools {
position: absolute;
top: 18px;
right: 18px;
z-index: 5;
}
.labels {
position: absolute;
inset: 0;
z-index: 2;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
display: none;
max-width: 190px;
padding: 6px 8px;
border: 1px solid rgba(95, 130, 151, 0.4);
border-radius: 7px;
color: #dce9ef;
background: rgba(7, 17, 26, 0.82);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
backdrop-filter: blur(6px);
font: 600 9px ui-monospace, SFMono-Regular, Menlo, monospace;
line-height: 1.35;
transform: translate(-50%, -50%);
white-space: nowrap;
}
.scene-label::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 8px var(--cyan);
}
.scene-label.pressure::before {
background: var(--amber);
box-shadow: 0 0 8px var(--amber);
}
.legend {
position: absolute;
left: 18px;
bottom: 18px;
z-index: 4;
width: 230px;
padding: 10px 12px;
border: 1px solid rgba(95, 130, 151, 0.28);
border-radius: 10px;
color: var(--muted);
background: rgba(7, 17, 26, 0.78);
backdrop-filter: blur(8px);
pointer-events: none;
}
.legend-title {
margin-bottom: 7px;
color: #d7e5eb;
font-size: 10px;
font-weight: 700;
}
.legend-gradient {
height: 6px;
border-radius: 999px;
background: linear-gradient(90deg, #57dfca, #ffc25c, #ff6b72);
}
.legend-scale {
display: flex;
justify-content: space-between;
margin-top: 5px;
font-size: 9px;
}
.legend-dash {
display: inline-block;
width: 18px;
margin-right: 6px;
border-top: 1px dashed var(--amber);
vertical-align: middle;
}
.camera-help {
position: absolute;
right: 18px;
bottom: 18px;
z-index: 4;
padding: 7px 9px;
border: 1px solid rgba(95, 130, 151, 0.22);
border-radius: 8px;
color: #7891a3;
background: rgba(7, 17, 26, 0.68);
font-size: 9px;
pointer-events: none;
}
.verdict {
padding: 17px 18px;
border-bottom: 1px solid var(--line);
background: linear-gradient(145deg, rgba(87, 223, 202, 0.09), transparent 65%);
}
.verdict.warn {
background: linear-gradient(145deg, rgba(255, 194, 92, 0.1), transparent 65%);
}
.verdict.danger {
background: linear-gradient(145deg, rgba(255, 107, 114, 0.1), transparent 65%);
}
.verdict-top {
display: flex;
align-items: center;
gap: 10px;
}
.verdict-icon {
width: 34px;
height: 34px;
display: grid;
place-items: center;
flex: 0 0 auto;
border: 1px solid rgba(87, 223, 202, 0.4);
border-radius: 9px;
color: var(--cyan);
background: rgba(87, 223, 202, 0.09);
font-size: 17px;
font-weight: 800;
}
.verdict.warn .verdict-icon {
color: var(--amber);
border-color: rgba(255, 194, 92, 0.4);
background: rgba(255, 194, 92, 0.09);
}
.verdict.danger .verdict-icon {
color: var(--red);
border-color: rgba(255, 107, 114, 0.4);
background: rgba(255, 107, 114, 0.09);
}
.verdict h2 {
margin: 0;
font-size: 15px;
line-height: 1.25;
}
.verdict p {
margin: 10px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.metric-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 13px;
}
.metric {
padding: 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(7, 17, 26, 0.45);
}
.metric span {
display: block;
color: #6f899b;
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 4px;
color: #e7f2f6;
font: 700 12px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.compare-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 11px;
}
.compare-actions {
display: flex;
gap: 5px;
}
.tiny-button {
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 6px;
color: var(--muted);
background: #0a1722;
cursor: pointer;
font-size: 9px;
}
.tiny-button:hover {
color: var(--text);
border-color: #456074;
}
.compare-card {
margin-bottom: 9px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 11px;
background: #0a1722;
}
.compare-card.current {
border-color: rgba(87, 223, 202, 0.42);
}
.compare-card.chosen {
box-shadow: inset 0 0 0 1px rgba(87, 223, 202, 0.22);
}
.compare-card-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 9px 10px;
border-bottom: 1px solid var(--line);
}
.compare-card-head strong {
font-size: 11px;
}
.compare-card-head span {
color: var(--muted);
font-size: 9px;
}
.diagram {
padding: 6px;
background: #07131d;
}
.diagram svg {
display: block;
width: 100%;
height: auto;
}
.compare-metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
padding: 8px;
}
.compare-metrics div {
min-width: 0;
}
.compare-metrics span {
display: block;
color: #627d90;
font-size: 7px;
text-transform: uppercase;
}
.compare-metrics strong {
display: block;
overflow: hidden;
margin-top: 2px;
color: #dceaf1;
font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
text-overflow: ellipsis;
white-space: nowrap;
}
.use-button {
width: calc(100% - 16px);
margin: 0 8px 8px;
padding: 7px;
border: 1px solid var(--line);
border-radius: 7px;
color: #a9c0cd;
background: #102331;
cursor: pointer;
font-size: 10px;
}
.use-button:hover {
color: var(--text);
border-color: #49677b;
}
.recommendation {
padding: 17px 18px 20px;
}
.recommendation-box {
margin-top: 10px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: #0a1722;
}
.recommendation-box strong {
display: block;
font-size: 12px;
}
.recommendation-box p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.recommendation-box button {
margin-top: 9px;
}
.primary-button,
.secondary-button {
padding: 9px 11px;
font-size: 11px;
font-weight: 650;
}
.primary-button {
width: 100%;
margin-top: 12px;
border-color: var(--cyan);
color: #05201c;
background: var(--cyan);
}
.primary-button:hover {
background: #78ead8;
}
.primary-button:disabled {
border-color: #263b4a;
color: #617787;
background: #162735;
cursor: not-allowed;
}
.secondary-button {
width: 100%;
margin-top: 8px;
}
.disclaimer {
margin: 13px 0 0;
color: #627c8e;
font-size: 9px;
line-height: 1.5;
}
.toast {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 100;
padding: 10px 14px;
border: 1px solid rgba(87, 223, 202, 0.5);
border-radius: 9px;
color: #dffbf6;
background: rgba(10, 31, 39, 0.96);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
font-size: 12px;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 1100px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100vh;
grid-template-rows: 68px auto;
}
.layout {
grid-template-columns: 270px minmax(430px, 1fr);
}
.analysis {
grid-column: 1 / -1;
display: grid;
grid-template-columns: 1fr 1fr;
border-top: 1px solid var(--line);
border-left: 0;
}
.analysis > .verdict {
grid-row: span 2;
}
.recommendation {
border-left: 1px solid var(--line);
}
}
@media (max-width: 760px) {
.app {
display: block;
}
header {
height: 64px;
padding: 0 13px;
}
.header-actions .pill {
display: none;
}
.layout {
display: flex;
flex-direction: column;
}
.controls,
.analysis {
overflow: visible;
border: 0;
}
.viewport {
order: -1;
min-height: 560px;
}
.analysis {
display: block;
}
.recommendation {
border-left: 0;
}
.scene-title h2 {
font-size: 14px;
}
.legend {
width: 205px;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-mark">B</div>
<div>
<h1>Bolt Lab</h1>
<p>Contact pressure, washers & broad-surface support</p>
</div>
</div>
<div class="header-actions">
<span class="pill dot">Low-poly live model</span>
<button id="resetCamera" class="ghost-button" type="button">Reset view</button>
</div>
</header>
<main class="layout">
<aside class="controls" aria-label="Assembly controls">
<section class="panel-section">
<div class="section-heading">
<h2>Panel sample</h2>
<span class="section-index">01</span>
</div>
<p class="helper">Swap the substrate to see how bearing pressure and local deflection respond.</p>
<div id="sampleGrid" class="sample-grid"></div>
</section>
<section class="panel-section">
<div class="section-heading">
<h2>Load-spreading assembly</h2>
<span class="section-index">02</span>
</div>
<p class="helper">Choose the hardware that transfers the bolt load into the panel.</p>
<div id="assemblyGrid" class="assembly-list"></div>
</section>
<section class="panel-section">
<div class="section-heading">
<h2>Design intent</h2>
<span class="section-index">03</span>
</div>
<div class="field">
<label class="field-label" for="boltSelect">
Fastener
<span class="field-value" id="boltValue">M10</span>
</label>
<select id="boltSelect">
<option value="M8">M8 bolt</option>
<option value="M10" selected>M10 bolt</option>
<option value="M12">M12 bolt</option>
</select>
</div>
<div class="field">
<label class="field-label" for="loadRange">
Applied load
<span class="field-value" id="loadValue">3.2 kN</span>
</label>
<input id="loadRange" type="range" min="0.5" max="10" value="3.2" step="0.1">
<div class="range-limits">
<span>0.5 kN</span>
<span>10 kN</span>
</div>
</div>
<div class="field">
<label class="field-label" for="targetSelect">
Required support zone
<span class="field-value">dashed outline</span>
</label>
<select id="targetSelect">
<option value="t60">60 × 60 mm — compact zone</option>
<option value="t100" selected>100 × 100 mm — typical zone</option>
<option value="t140">140 × 120 mm — broad zone</option>
</select>
</div>
<div class="info-box">
The dashed rectangle is the intended support zone. Compare it with the actual pressure footprint instead of relying on bolt diameter alone.
</div>
</section>
</aside>
<section class="viewport" id="viewport" aria-label="Interactive three-dimensional assembly">
<div id="three-host"></div>
<div class="scene-title">
<div class="eyebrow">Live assembly / front load case</div>
<h2 id="sceneTitle">Square spreader on plywood</h2>
<p id="sceneSubtitle">3.2 kN · M10 · 100 × 100 mm required zone</p>
</div>
<div class="scene-tools">
<button id="showPressure" class="ghost-button" type="button">Pressure: on</button>
</div>
<div id="labels" class="labels" aria-hidden="true">
<div id="labelPanel" class="scene-label"></div>
<div id="labelPressure" class="scene-label pressure"></div>
<div id="labelAssembly" class="scene-label"></div>
</div>
<div class="legend">
<div class="legend-title">Indicative contact pressure</div>
<div class="legend-gradient"></div>
<div class="legend-scale">
<span>low</span>
<span>near limit</span>
<span>high</span>
</div>
<div style="margin-top:8px">
<span class="legend-dash"></span>Required support zone
</div>
</div>
<div class="camera-help">Drag to orbit · wheel to zoom · R resets</div>
</section>
<aside class="analysis" aria-label="Assembly analysis and comparison">
<section id="verdict" class="verdict">
<div class="verdict-top">
<div id="verdictIcon" class="verdict-icon">✓</div>
<div>
<div class="eyebrow" style="color:#7893a5;font-size:8px;letter-spacing:.12em">CURRENT VERDICT</div>
<h2 id="verdictTitle">Broad support achieved</h2>
</div>
</div>
<p id="verdictReason"></p>
<div class="metric-row">
<div class="metric">
<span>Contact area</span>
<strong id="metricArea">—</strong>
</div>
<div class="metric">
<span>Peak pressure</span>
<strong id="metricPressure">—</strong>
</div>
<div class="metric">
<span>Deflection</span>
<strong id="metricDeflection">—</strong>
</div>
</div>
</section>
<section class="panel-section">
<div class="compare-header">
<div class="section-heading" style="margin:0">
<h2>Contact comparison</h2>
</div>
<div class="compare-actions">
<button id="pinReference" class="tiny-button" type="button">Pin B as A</button>
<button id="swapReference" class="tiny-button" type="button">Swap A/B</button>
</div>
</div>
<article id="cardA" class="compare-card">
<div class="compare-card-head">
<strong>A · Reference</strong>
<span id="nameA">Wide washer</span>
</div>
<div id="diagramA" class="diagram"></div>
<div id="metricsA" class="compare-metrics"></div>
<button id="useA" class="use-button" type="button">Use assembly A</button>
</article>
<article id="cardB" class="compare-card current">
<div class="compare-card-head">
<strong>B · Current</strong>
<span id="nameB">Square spreader</span>
</div>
<div id="diagramB" class="diagram"></div>
<div id="metricsB" class="compare-metrics"></div>
<button id="useB" class="use-button" type="button">Use assembly B</button>
</article>
</section>
<section class="recommendation">
<div class="section-heading">
<h2>Recommended assembly</h2>
<span class="section-index">04</span>
</div>
<div class="recommendation-box">
<strong id="recommendationTitle">Front + backing plates</strong>
<p id="recommendationReason"></p>
<button id="tryRecommended" class="secondary-button" type="button">Try recommendation</button>
</div>
<button id="chooseAssembly" class="primary-button" type="button">Choose this assembly</button>
<p class="disclaimer">
Educational visualization only. Values are simplified, illustrative estimates—not a substitute for
material testing, joint design, creep checks, or a structural engineer’s calculation.
</p>
</section>
</aside>
</main>
</div>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const SCALE = 8.8 / 240;
const PANEL_WIDTH = 8.8;
const PANEL_HEIGHT = 8.4;
const samples = {
ply12: {
id: "ply12",
name: "12 mm plywood",
short: "Plywood 12",
thickness: 12,
allowable: 4.0,
compliance: 1.1,
color: "#a77642",
note: "Thin, flexible sheet"
},
ply18: {
id: "ply18",
name: "18 mm plywood",
short: "Plywood 18",
thickness: 18,
allowable: 6.5,
compliance: 0.7,
color: "#ba8952",
note: "Stiffer wood sheet"
},
steel3: {
id: "steel3",
name: "3 mm steel plate",
short: "Steel 3",
thickness: 3,
allowable: 28,
compliance: 0.08,
color: "#8296a2",
note: "Strong bearing material"
},
hdpe10: {
id: "hdpe10",
name: "10 mm HDPE",
short: "HDPE 10",
thickness: 10,
allowable: 2.2,
compliance: 1.3,
color: "#55746a",
note: "Low bearing strength; creep risk"
},
comp12: {
id: "comp12",
name: "12 mm composite panel",
short: "Composite 12",
thickness: 12,
allowable: 8.0,
compliance: 0.65,
color: "#657b73",
note: "Stable engineered sheet"
}
};
const assemblies = {
direct: {
id: "direct",
name: "Bolt head only",
detail: "Point-like contact",
icon: "◆",
width: 0,
height: 0,
concentration: 4.0,
deflectionFactor: 9.0
},
washer: {
id: "washer",
name: "Standard washer",
detail: "Narrow annular footprint",
icon: "◎",
width: 36,
height: 36,
concentration: 1.35,
deflectionFactor: 5.0
},
wide: {
id: "wide",
name: "Wide washer",
detail: "Larger annular footprint",
icon: "⬡",
width: 72,
height: 72,
concentration: 1.15,
deflectionFactor: 2.4
},
square: {
id: "square",
name: "Square spreader",
detail: "Broad front-side support",
icon: "▣",
width: 140,
height: 140,
concentration: 1.12,
deflectionFactor: 0.8
},
sandwich: {
id: "sandwich",
name: "Front + backing plates",
detail: "Broad load path through panel",
icon: "▤",
width: 120,
height: 120,
concentration: 1.08,
deflectionFactor: 0.45
}
};
const bolts = {
M8: { label: "M8", diameter: 8, hole: 9 },
M10: { label: "M10", diameter: 10, hole: 11 },
M12: { label: "M12", diameter: 12, hole: 14 }
};
const targets = {
t60: { id: "t60", label: "60 × 60 mm", width: 60, height: 60, min: 60 },
t100: { id: "t100", label: "100 × 100 mm", width: 100, height: 100, min: 100 },
t140: { id: "t140", label: "140 × 120 mm", width: 140, height: 120, min: 120 }
};
const state = {
sample: "ply18",
assembly: "square",
bolt: "M10",
load: 3.2,
target: "t100",
pressureVisible: true,
reference: {
sample: "ply18",
assembly: "wide",
bolt: "M10",
load: 3.2
},
chosen: null
};
let toastTimer;
function showToast(message) {
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2200);
}
function currentSnapshot() {
return {
sample: state.sample,
assembly: state.assembly,
bolt: state.bolt,
load: state.load
};
}
function readSnapshot(snapshot) {
return {
sample: snapshot.sample,
assembly: snapshot.assembly,
bolt: snapshot.bolt,
load: snapshot.load
};
}
function washerDimensions(assemblyId, boltId) {
const bolt = bolts[boltId];
if (assemblyId === "washer") {
const outer = bolt.diameter + 26;
return {
outer,
inner: bolt.hole,
area: Math.PI / 4 * (outer * outer - bolt.hole * bolt.hole)
};
}
if (assemblyId === "wide") {
const outer = bolt.diameter + 62;
return {
outer,
inner: bolt.hole,
area: Math.PI / 4 * (outer * outer - bolt.hole * bolt.hole)
};
}
return null;
}
function computeMetrics(snapshot) {
const sample = samples[snapshot.sample];
const assembly = assemblies[snapshot.assembly];
const bolt = bolts[snapshot.bolt];
const target = targets[state.target];
const loadN = snapshot.load * 1000;
let area = 0;
let footprintWidth = assembly.width;
let footprintHeight = assembly.height;
if (snapshot.assembly === "direct") {
area = Math.PI / 4 * bolt.hole * bolt.hole;
footprintWidth = bolt.diameter;
footprintHeight = bolt.diameter;
} else if (snapshot.assembly === "washer" || snapshot.assembly === "wide") {
const washer = washerDimensions(snapshot.assembly, snapshot.bolt);
area = washer.area;
footprintWidth = washer.outer;
footprintHeight = washer.outer;
} else if (snapshot.assembly === "square") {
area = 140 * 140;
} else {
area = Math.min(140 * 140, 120 * 120);
}
const concentration =
snapshot.assembly === "square" && sample.compliance > 0.9
? 1.35
: assembly.concentration;
const effectiveArea = Math.max(1, area / concentration);
const pressure = loadN / effectiveArea;
const pressureOK = pressure <= sample.allowable;
const targetArea = target.width * target.height;
const broad =
footprintWidth >= target.min &&
footprintHeight >= target.min &&
area >= targetArea * 0.55;
const diameterFactor = Math.pow(12 / bolt.diameter, 1.4);
const deflection =
snapshot.load *
sample.compliance *
assembly.deflectionFactor *
diameterFactor;
const visualSag = Math.min(0.48, deflection * 0.025);
let title;
let reason;
let tone;
if (!broad) {
tone = "danger";
title = "Narrow bearing area";
reason =
`The assembly contacts only about ${Math.round(footprintWidth)} × ${Math.round(footprintHeight)} mm. ` +
`That does not cover the intended ${target.label} support zone, so the load remains concentrated rather than broadly supported.`;
} else if (!pressureOK) {
tone = "danger";
title = "Broad area, excessive pressure";
reason =
`The footprint covers the intended zone, but the estimated peak pressure exceeds the ` +
`${sample.name} bearing limit. Use a larger or stiffer spreading system, or a stronger panel.`;
} else if (sample.id === "hdpe10") {
tone = "warn";
title = "Broad area; creep check needed";
reason =
"The load is spread over the intended area and the simplified pressure estimate is acceptable. " +
"HDPE can creep under sustained preload, so a rigid backing plate and long-term service checks are important.";
} else {
tone = "safe";
title = "Broad support achieved";
reason =
`The contact footprint covers the intended ${target.label} zone, and the estimated peak pressure ` +
`is below the indicative limit for ${sample.name}.`;
}
return {
sample,
assembly,
bolt,
target,
area,
footprintWidth,
footprintHeight,
pressure,
pressureOK,
broad,
deflection,
visualSag,
title,
reason,
tone
};
}
function recommendedAssembly() {
const sample = samples[state.sample];
const target = targets[state.target];
if (target.min <= 72) {
const wide = computeMetrics({
sample: state.sample,
assembly: "wide",
bolt: state.bolt,
load: state.load
});
if (wide.broad && wide.pressureOK) {
return {
id: "wide",
title: "Wide washer",
reason: "A wide washer is the smallest assembly that covers this compact support zone while keeping the panel within its simplified bearing limit."
};
}
}
if (sample.id === "steel3" || sample.id === "comp12") {
return {
id: "square",
title: "Square spreader",
reason: "The selected panel can carry local bearing well, so a rigid square spreader gives the clearest broad front-side footprint with less hardware."
};
}
return {
id: "sandwich",
title: "Front + backing plates",
reason: "Front and rear plates create a broad load path through the panel and are less sensitive to local bending than a single washer or front-only plate."
};
}
function formatArea(area) {
if (area >= 10000) {
return `${(area / 1000).toFixed(1)}k`;
}
return Math.round(area).toLocaleString();
}
function formatPressure(pressure) {
if (pressure >= 100) {
return `${Math.round(pressure)} MPa`;
}
return `${pressure.toFixed(pressure < 10 ? 2 : 1)} MPa`;
}
function createControlButtons() {
$("#sampleGrid").innerHTML = Object.values(samples).map(sample => `
<button class="sample-button" type="button" data-sample="${sample.id}">
<span class="sample-swatch" style="--swatch:${sample.color}"></span>
<span>
<span class="sample-name">${sample.name}</span>
<span class="sample-meta">${sample.note}</span>
</span>
<span class="sample-check">✓</span>
</button>
`).join("");
$("#assemblyGrid").innerHTML = Object.values(assemblies).map(assembly => `
<button class="assembly-button" type="button" data-assembly="${assembly.id}">
<span class="part-icon">${assembly.icon}</span>
<span>
<span class="part-name">${assembly.name}</span>
<span class="part-detail">${assembly.detail}</span>
</span>
</button>
`).join("");
$("#sampleGrid").addEventListener("click", event => {
const button = event.target.closest("[data-sample]");
if (!button) return;
state.sample = button.dataset.sample;
updateAll();
});
$("#assemblyGrid").addEventListener("click", event => {
const button = event.target.closest("[data-assembly]");
if (!button) return;
state.assembly = button.dataset.assembly;
updateAll();
});
}
function syncControls() {
$$("[data-sample]").forEach(button => {
const active = button.dataset.sample === state.sample;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
$$("[data-assembly]").forEach(button => {
const active = button.dataset.assembly === state.assembly;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
$("#boltSelect").value = state.bolt;
$("#loadRange").value = state.load;
$("#targetSelect").value = state.target;
$("#boltValue").textContent = state.bolt;
$("#loadValue").textContent = `${state.load.toFixed(1)} kN`;
}
function pressureColor(ratio) {
const low = new THREE.Color("#57dfca");
const mid = new THREE.Color("#ffc25c");
const high = new THREE.Color("#ff6b72");
if (ratio < 0.55) return low;
if (ratio < 1) return mid.clone().lerp(high, (ratio - 0.55) / 0.45);
return high;
}
function createPanel(sample, metrics) {
const group = new THREE.Group();
const depth = sample.thickness * SCALE;
const geometry = new THREE.BoxGeometry(
PANEL_WIDTH,
PANEL_HEIGHT,
depth,
12,
10,
1
);
const positions = geometry.attributes.position;
const colors = [];
const baseColor = new THREE.Color(sample.color);
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const z = positions.getZ(i);
const sag = metrics.visualSag *
Math.exp(-(x * x + y * y) / (2 * 1.45 * 1.45));
positions.setZ(i, z - sag);
const variation = 0.92 + 0.08 * Math.sin(x * 1.8 + y * 0.7);
const color = baseColor.clone().multiplyScalar(variation);
colors.push(color.r, color.g, color.b);
}
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: sample.id === "steel3" ? 0.42 : 0.82,
metalness: sample.id === "steel3" ? 0.58 : 0.03,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.z = -depth / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
const outlineMaterial = new THREE.LineBasicMaterial({
color: 0x9db2be,
transparent: true,
opacity: 0.36
});
const corners = [
[-PANEL_WIDTH / 2, -PANEL_HEIGHT / 2, depth / 2],
[ PANEL_WIDTH / 2, -PANEL_HEIGHT / 2, depth / 2],
[ PANEL_WIDTH / 2, PANEL_HEIGHT / 2, depth / 2],
[-PANEL_WIDTH / 2, PANEL_HEIGHT / 2, depth / 2],
[-PANEL_WIDTH / 2, -PANEL_HEIGHT / 2, -depth / 2],
[ PANEL_WIDTH / 2, -PANEL_HEIGHT / 2, -depth / 2],
[ PANEL_WIDTH / 2, PANEL_HEIGHT / 2, -depth / 2],
[-PANEL_WIDTH / 2, PANEL_HEIGHT / 2, -depth / 2]
];
const edgePairs = [
[0,1], [1,2], [2,3], [3,0],
[4,5], [5,6], [6,7], [7,4],
[0,4], [1,5], [2,6], [3,7]
];
const edgePositions = [];
for (const [a, b] of edgePairs) {
edgePositions.push(...corners[a], ...corners[b]);
}
const edgeGeometry = new THREE.BufferGeometry();
edgeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(edgePositions, 3)
);
const edges = new THREE.LineSegments(edgeGeometry, outlineMaterial);
edges.position.z = -depth / 2;
group.add(edges);
const gridPositions = [];
const yStep = PANEL_HEIGHT / 10;
const xStep = PANEL_WIDTH / 12;
for (let row = 0; row <= 10; row++) {
const y = -PANEL_HEIGHT / 2 + row * yStep;
for (let col = 0; col < 12; col++) {
const x1 = -PANEL_WIDTH / 2 + col * xStep;
const x2 = x1 + xStep;
for (const x of [x1, x2]) {
const sag1 = metrics.visualSag * Math.exp(-(x * x + y * y) / (2 * 1.45 * 1.45));
const sag2 = metrics.visualSag * Math.exp(-(x2 * x2 + y * y) / (2 * 1.45 * 1.45));
gridPositions.push(x, y, depth / 2 - sag1);
gridPositions.push(x2, y, depth / 2 - sag2);
}
}
}
for (let col = 0; col <= 12; col++) {
const x = -PANEL_WIDTH / 2 + col * xStep;
for (let row = 0; row < 10; row++) {
const y1 = -PANEL_HEIGHT / 2 + row * yStep;
const y2 = y1 + yStep;
const sag1 = metrics.visualSag * Math.exp(-(x * x + y1 * y1) / (2 * 1.45 * 1.45));
const sag2 = metrics.visualSag * Math.exp(-(x * x + y2 * y2) / (2 * 1.45 * 1.45));
gridPositions.push(x, y1, depth / 2 - sag1);
gridPositions.push(x, y2, depth / 2 - sag2);
}
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: sample.id === "steel3" ? 0xb4c5ce : 0x684e35,
transparent: true,
opacity: sample.id === "steel3" ? 0.11 : 0.13
})
);
grid.position.z = -depth / 2;
group.add(grid);
return group;
}
function createWasher(outer, inner, material) {
const shape = new THREE.Shape();
shape.absarc(0, 0, outer, 0, Math.PI * 2, false);
const hole = new THREE.Path();
hole.absarc(0, 0, inner, 0, Math.PI * 2, true);
shape.holes.push(hole);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.14,
bevelEnabled: false,
curveSegments: 24
});
geometry.computeVertexNormals();
return new THREE.Mesh(geometry, material);
}
function createAssembly(snapshot, metrics) {
const group = new THREE.Group();
const sample = samples[snapshot.sample];
const bolt = bolts[snapshot.bolt];
const panelDepth = sample.thickness * SCALE;
const metal = new THREE.MeshStandardMaterial({
color: 0x9eafb8,
metalness: 0.85,
roughness: 0.28,
flatShading: true
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x52636e,
metalness: 0.78,
roughness: 0.36,
flatShading: true
});
const washerMaterial = new THREE.MeshStandardMaterial({
color: 0xb7c6cc,
metalness: 0.8,
roughness: 0.25,
transparent: true,
opacity: 0.74,
depthWrite: false,
side: THREE.DoubleSide,
flatShading: true
});
const plateMaterial = new THREE.MeshStandardMaterial({
color: 0x728792,
metalness: 0.72,
roughness: 0.38,
transparent: true,
opacity: 0.57,
depthWrite: false,
side: THREE.DoubleSide,
flatShading: true
});
const shaftRadius = Math.max(0.13, bolt.diameter * 0.5 * SCALE);
const headRadius = Math.max(0.42, bolt.diameter * 0.82 * SCALE);
const hasBacking = snapshot.assembly === "sandwich";
const shaftLength = panelDepth + (hasBacking ? 1.45 : 1.05);
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(shaftRadius, shaftRadius, shaftLength, 12),
darkMetal
);
shaft.rotation.x = Math.PI / 2;
shaft.position.z = hasBacking ? -0.15 : 0.12;
shaft.castShadow = true;
group.add(shaft);
const head = new THREE.Mesh(
new THREE.CylinderGeometry(headRadius, headRadius, 0.38, 6),
metal
);
head.rotation.x = Math.PI / 2;
head.castShadow = true;
group.add(head);
const nut = new THREE.Mesh(
new THREE.CylinderGeometry(headRadius * 0.9, headRadius * 0.9, 0.34, 6),
metal
);
nut.rotation.x = Math.PI / 2;
nut.castShadow = true;
group.add(nut);
let frontZ = 0.02;
if (snapshot.assembly === "square" || snapshot.assembly === "sandwich") {
const plateSize = 140 * SCALE;
const plate = new THREE.Mesh(
new THREE.BoxGeometry(plateSize, plateSize, 0.25, 1, 1, 1),
plateMaterial
);
plate.position.z = 0.125;
plate.castShadow = true;
group.add(plate);
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(plate.geometry),
new THREE.LineBasicMaterial({
color: 0xc4d5dc,
transparent: true,
opacity: 0.62
})
);
outline.position.copy(plate.position);
group.add(outline);
frontZ = 0.25;
}
if (snapshot.assembly === "washer" || snapshot.assembly === "wide" || snapshot.assembly === "sandwich") {
const washerSpec = snapshot.assembly === "sandwich"
? washerDimensions("wide", snapshot.bolt)
: washerDimensions(snapshot.assembly, snapshot.bolt);
const outer = washerSpec.outer * SCALE / 2;
const inner = Math.max(0.18, washerSpec.inner * SCALE / 2);
const washer = createWasher(outer, inner, washerMaterial);
washer.position.z = frontZ;
washer.castShadow = true;
group.add(washer);
frontZ += 0.14;
}
head.position.z = frontZ + 0.19;
if (hasBacking) {
const backingSize = 120 * SCALE;
const backing = new THREE.Mesh(
new THREE.BoxGeometry(backingSize, backingSize, 0.26, 1, 1, 1),
plateMaterial
);
backing.position.z = -panelDepth - 0.13;
backing.castShadow = true;
group.add(backing);
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(backing.geometry),
new THREE.LineBasicMaterial({
color: 0xc4d5dc,
transparent: true,
opacity: 0.62
})
);
outline.position.copy(backing.position);
group.add(outline);
nut.position.z = -panelDepth - 0.45;
} else {
nut.position.z = -panelDepth - 0.22;
}
const arrowOrigin = new THREE.Vector3(0, 3.05, 2.2);
const arrowLength = 1.35 + snapshot.load * 0.25;
const arrowColor = metrics.pressureOK ? 0xffc25c : 0xff6b72;
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, -1),
arrowOrigin,
arrowLength,
arrowColor,
0.38,
0.22
);
group.add(arrow);
return group;
}
function createAnnulusPatch(inner, outer, metrics) {
const geometry = new THREE.RingGeometry(inner, outer, 32);
const positions = geometry.attributes.position;
const colors = [];
const ratio = metrics.pressure / metrics.sample.allowable;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const r = Math.sqrt(x * x + y * y);
const t = THREE.MathUtils.clamp((r - inner) / Math.max(0.001, outer - inner), 0, 1);
const color = pressureColor(ratio * (0.8 + t * 0.35));
colors.push(color.r, color.g, color.b);
}
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
return new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.82,
side: THREE.DoubleSide,
depthWrite: false
})
);
}
function createRectPatch(width, height, metrics, rear = false) {
const geometry = new THREE.PlaneGeometry(width, height, 10, 10);
const positions = geometry.attributes.position;
const colors = [];
const ratio = metrics.pressure / metrics.sample.allowable;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i) / (width / 2);
const y = positions.getY(i) / (height / 2);
const distance = Math.min(1, Math.sqrt(x * x + y * y) / Math.sqrt(2));
const localRatio = ratio * (1 - distance * 0.62);
const color = pressureColor(localRatio);
colors.push(color.r, color.g, color.b);
}
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.72,
side: THREE.DoubleSide,
depthWrite: false
})
);
if (rear) mesh.rotation.y = Math.PI;
return mesh;
}
function createPressureVisualization(snapshot, metrics) {
const group = new THREE.Group();
const sample = samples[snapshot.sample];
const bolt = bolts[snapshot.bolt];
const panelDepth = sample.thickness * SCALE;
const frontZ = -metrics.visualSag + 0.014;
if (snapshot.assembly === "direct") {
const geometry = new THREE.CircleGeometry(0.17, 16);
const color = pressureColor(metrics.pressure / sample.allowable);
const colors = [];
for (let i = 0; i < geometry.attributes.position.count; i++) {
colors.push(color.r, color.g, color.b);
}
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
const patch = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide,
depthWrite: false
})
);
patch.position.z = frontZ;
group.add(patch);
} else if (snapshot.assembly === "washer" || snapshot.assembly === "wide") {
const washer = washerDimensions(snapshot.assembly, snapshot.bolt);
const patch = createAnnulusPatch(
washer.inner * SCALE / 2,
washer.outer * SCALE / 2,
metrics
);
patch.position.z = frontZ;
group.add(patch);
} else if (snapshot.assembly === "square") {
const patch = createRectPatch(140 * SCALE, 140 * SCALE, metrics);
patch.position.z = frontZ;
group.add(patch);
} else {
const frontPatch = createRectPatch(140 * SCALE, 140 * SCALE, metrics);
frontPatch.position.z = frontZ;
group.add(frontPatch);
const rearPatch = createRectPatch(120 * SCALE, 120 * SCALE, metrics, true);
rearPatch.position.z = -panelDepth - 0.014;
group.add(rearPatch);
}
const target = targets[state.target];
const targetWidth = target.width * SCALE;
const targetHeight = target.height * SCALE;
const z = frontZ + 0.035;
const targetGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-targetWidth / 2, -targetHeight / 2, z),
new THREE.Vector3( targetWidth / 2, -targetHeight / 2, z),
new THREE.Vector3( targetWidth / 2, targetHeight / 2, z),
new THREE.Vector3(-targetWidth / 2, targetHeight / 2, z),
new THREE.Vector3(-targetWidth / 2, -targetHeight / 2, z)
]);
const targetOutline = new THREE.Line(
targetGeometry,
new THREE.LineDashedMaterial({
color: 0xffc25c,
dashSize: 0.15,
gapSize: 0.1,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
targetOutline.computeLineDistances();
targetOutline.renderOrder = 12;
group.add(targetOutline);
return group;
}
// ----- Three.js scene -----
const host = $("#three-host");
const viewport = $("#viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08131e);
scene.fog = new THREE.Fog(0x08131e, 16, 32);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
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.05;
host.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb8d7e8, 0x18232a, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(5, 8, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x57dfca, 1.5);
rimLight.position.set(-7, 2, -6);
scene.add(rimLight);
const fillLight = new THREE.DirectionalLight(0xffc25c, 0.6);
fillLight.position.set(5, -4, 5);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x09151f,
roughness: 0.98,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -4.34;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 24, 0x284353, 0x182e3c);
grid.position.y = -4.32;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
let panelGroup = null;
let assemblyGroup = null;
let pressureGroup = null;
const orbit = {
theta: 0.32,
phi: 1.31,
radius: 13.4,
target: new THREE.Vector3(0, 0.15, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.theta = 0.32;
orbit.phi = 1.31;
orbit.radius = 13.4;
orbit.target.set(0, 0.15, 0);
updateCamera();
}
let dragging = false;
let previousPointer = { x: 0, y: 0 };
let pointerMoved = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerMoved = 0;
previousPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
pointerMoved += Math.abs(dx) + Math.abs(dy);
previousPointer = { x: event.clientX, y: event.clientY };
orbit.theta -= dx * 0.008;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.006, 0.62, 2.05);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(orbit.radius + event.deltaY * 0.009, 8.5, 20);
updateCamera();
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") resetCamera();
});
function disposeGroup(group) {
if (!group) return;
group.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material) ? object.material : [object.material];
materials.forEach(material => material.dispose());
}
});
scene.remove(group);
}
function rebuildScene() {
disposeGroup(panelGroup);
disposeGroup(assemblyGroup);
disposeGroup(pressureGroup);
const snapshot = currentSnapshot();
const metrics = computeMetrics(snapshot);
panelGroup = createPanel(samples[state.sample], metrics);
assemblyGroup = createAssembly(snapshot, metrics);
pressureGroup = createPressureVisualization(snapshot, metrics);
pressureGroup.visible = state.pressureVisible;
scene.add(panelGroup, assemblyGroup, pressureGroup);
$("#labelPanel").textContent = `${samples[state.sample].name.toUpperCase()} · ${samples[state.sample].thickness} mm`;
$("#labelPressure").textContent = `CONTACT · ${formatArea(metrics.area)} mm²`;
$("#labelAssembly").textContent = `${assemblies[state.assembly].name.toUpperCase()} · ${state.load.toFixed(1)} kN`;
}
function projectLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const rect = viewport.getBoundingClientRect();
element.style.left = `${(projected.x * 0.5 + 0.5) * rect.width}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * rect.height}px`;
}
function updateLabels() {
const metrics = computeMetrics(currentSnapshot());
projectLabel($("#labelPanel"), new THREE.Vector3(-3.55, 3.55, -metrics.visualSag));
projectLabel($("#labelPressure"), new THREE.Vector3(2.65, -2.05, -metrics.visualSag));
projectLabel($("#labelAssembly"), new THREE.Vector3(0.05, 3.05, 0.55));
}
function resizeRenderer() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
if (!width || !height) return;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resizeRenderer).observe(viewport);
// ----- Simplified contact diagrams -----
function svgHexPoints(cx, cy, radius) {
return Array.from({ length: 6 }, (_, index) => {
const angle = Math.PI / 6 + index * Math.PI / 3;
return `${cx + Math.cos(angle) * radius},${cy + Math.sin(angle) * radius}`;
}).join(" ");
}
function renderDiagram(snapshot, uid) {
const metrics = computeMetrics(snapshot);
const assembly = assemblies[snapshot.assembly];
const bolt = bolts[snapshot.bolt];
const target = targets[state.target];
const sample = samples[snapshot.sample];
const centerX = 78;
const centerY = 82;
const panelLeft = 18;
const panelTop = 20;
const panelSize = 120;
const pxPerMm = panelSize / 240;
const targetW = target.width * pxPerMm;
const targetH = target.height * pxPerMm;
const footprintW = metrics.footprintWidth * pxPerMm;
const footprintH = metrics.footprintHeight * pxPerMm;
let pressureShape = "";
let hardware = "";
if (snapshot.assembly === "direct") {
pressureShape = `
<circle cx="${centerX}" cy="${centerY}" r="7" fill="#ff6b72" opacity=".9"/>
<circle cx="${centerX}" cy="${centerY}" r="12" fill="none" stroke="#ff6b72" opacity=".28"/>
`;
hardware = `
<polygon points="${svgHexPoints(centerX, centerY, 8)}" fill="#d7e1e5" stroke="#536976"/>
`;
} else if (snapshot.assembly === "washer" || snapshot.assembly === "wide") {
const washer = washerDimensions(snapshot.assembly, snapshot.bolt);
const outer = washer.outer * pxPerMm;
const inner = washer.inner * pxPerMm;
pressureShape = `
<circle cx="${centerX}" cy="${centerY}" r="${outer}" fill="none"
stroke="#ffc25c" stroke-width="${Math.max(3, outer - inner)}" opacity=".82"/>
`;
hardware = `
<circle cx="${centerX}" cy="${centerY}" r="${outer}" fill="none" stroke="#d7e4e9" stroke-width="2"/>
<circle cx="${centerX}" cy="${centerY}" r="${inner}" fill="#0a1722" stroke="#718b9a"/>
`;
} else {
pressureShape = `
<rect x="${centerX - footprintW / 2}" y="${centerY - footprintH / 2}"
width="${footprintW}" height="${footprintH}" rx="5"
fill="url(#${uid}Gradient)" opacity=".9"/>
`;
hardware = `
<rect x="${centerX - footprintW / 2}" y="${centerY - footprintH / 2}"
width="${footprintW}" height="${footprintH}" rx="4"
fill="rgba(180,205,215,.12)" stroke="#d7e4e9" stroke-width="2"/>
`;
}
const panelThickness = Math.max(3, sample.thickness * 0.28);
const sectionX = 218;
const frontHardware = snapshot.assembly === "square" || snapshot.assembly === "sandwich"
? `<rect x="${sectionX}" y="77" width="33" height="10" rx="2" fill="#91a5af" opacity=".75"/>`
: `<rect x="${sectionX}" y="79" width="17" height="6" rx="2" fill="#91a5af" opacity=".75"/>`;
const rearHardware = snapshot.assembly === "sandwich"
? `<rect x="${sectionX - panelThickness - 24}" y="77" width="24" height="10" rx="2" fill="#91a5af" opacity=".65"/>`
: "";
return `
<svg viewBox="0 0 300 160" role="img" aria-label="Simplified contact pressure diagram">
<defs>
<radialGradient id="${uid}Gradient">
<stop offset="0%" stop-color="#57dfca"/>
<stop offset="55%" stop-color="#72cfaa"/>
<stop offset="100%" stop-color="#ffc25c"/>
</radialGradient>
<marker id="${uid}Arrow" markerWidth="6" markerHeight="6" refX="5" refY="3" orient="auto">
<path d="M0,0 L6,3 L0,6 Z" fill="#ffc25c"/>
</marker>
</defs>
<rect x="0" y="0" width="300" height="160" rx="7" fill="#08141e"/>
<text x="18" y="12" fill="#718b9c" font-size="7" letter-spacing="1">FRONT VIEW</text>
<text x="187" y="12" fill="#718b9c" font-size="7" letter-spacing="1">SECTION</text>
<rect x="${panelLeft}" y="${panelTop}" width="${panelSize}" height="${panelSize}"
rx="3" fill="${sample.color}" opacity=".28" stroke="#486171"/>
<rect x="${centerX - targetW / 2}" y="${centerY - targetH / 2}"
width="${targetW}" height="${targetH}" rx="2"
fill="none" stroke="#ffc25c" stroke-width="1" stroke-dasharray="4 3"/>
${pressureShape}
${hardware}
<polygon points="${svgHexPoints(centerX, centerY, 6)}" fill="#465b67" stroke="#d8e3e8" stroke-width="1"/>
<text x="${centerX}" y="150" text-anchor="middle" fill="#829cac" font-size="7">
${Math.round(metrics.footprintWidth)} × ${Math.round(metrics.footprintHeight)} mm footprint
</text>
<rect x="${sectionX - panelThickness / 2}" y="24" width="${panelThickness}" height="112"
fill="${sample.color}" opacity=".55" stroke="#76909f"/>
<line x1="${sectionX - 44}" y1="82" x2="${sectionX + 51}" y2="82"
stroke="#c7d5da" stroke-width="3"/>
${frontHardware}
${rearHardware}
<rect x="${sectionX - 1}" y="79" width="3" height="6" fill="#ffc25c" opacity=".85"/>
<line x1="284" y1="60" x2="238" y2="60" stroke="#ffc25c" stroke-width="2"
marker-end="url(#${uid}Arrow)"/>
<text x="284" y="51" text-anchor="end" fill="#ffc25c" font-size="7">LOAD</text>
<text x="18" y="115" fill="#718b9c" font-size="7">dashed = required zone</text>
<text x="18" y="128" fill="#718b9c" font-size="7">color = contact pressure</text>
<text x="187" y="150" fill="#718b9c" font-size="7">${sample.short} · ${bolt.label}</text>
</svg>
`;
}
function comparisonMetrics(metrics) {
return `
<div>
<span>Area mm²</span>
<strong>${formatArea(metrics.area)}</strong>
</div>
<div>
<span>Pressure</span>
<strong>${formatPressure(metrics.pressure)}</strong>
</div>
<div>
<span>Broad?</span>
<strong style="color:${metrics.broad ? "#66e3a4" : "#ff7b80"}">${metrics.broad ? "YES" : "NO"}</strong>
</div>
`;
}
function sameSnapshot(a, b) {
return a &&
b &&
a.sample === b.sample &&
a.assembly === b.assembly &&
a.bolt === b.bolt &&
a.load === b.load;
}
function renderComparisonCards() {
const reference = state.reference;
const current = currentSnapshot();
const referenceMetrics = computeMetrics(reference);
const currentMetrics = computeMetrics(current);
$("#nameA").textContent = `${assemblies[reference.assembly].name} · ${samples[reference.sample].short}`;
$("#nameB").textContent = `${assemblies[current.assembly].name} · ${samples[current.sample].short}`;
$("#diagramA").innerHTML = renderDiagram(reference, "pressureA");
$("#diagramB").innerHTML = renderDiagram(current, "pressureB");
$("#metricsA").innerHTML = comparisonMetrics(referenceMetrics);
$("#metricsB").innerHTML = comparisonMetrics(currentMetrics);
$("#cardA").classList.toggle("chosen", sameSnapshot(state.chosen, reference));
$("#cardB").classList.toggle("chosen", sameSnapshot(state.chosen, current));
}
// ----- UI and state updates -----
function updateAnalysis(metrics) {
const verdict = $("#verdict");
verdict.className = `verdict ${metrics.tone === "safe" ? "" : metrics.tone}`;
$("#verdictIcon").textContent = metrics.tone === "safe" ? "✓" : metrics.tone === "warn" ? "!" : "×";
$("#verdictTitle").textContent = metrics.title;
$("#verdictReason").textContent = metrics.reason;
$("#metricArea").textContent = `${formatArea(metrics.area)} mm²`;
$("#metricPressure").textContent = formatPressure(metrics.pressure);
$("#metricDeflection").textContent = `≈ ${metrics.deflection.toFixed(1)} mm`;
const recommendation = recommendedAssembly();
$("#recommendationTitle").textContent = recommendation.title;
$("#recommendationReason").textContent = recommendation.reason;
const choose = $("#chooseAssembly");
choose.disabled = !(metrics.broad && metrics.pressureOK);
choose.textContent = state.chosen && sameSnapshot(state.chosen, currentSnapshot())
? "Assembly selected ✓"
: "Choose this assembly";
}
function updateSceneText(metrics) {
$("#sceneTitle").textContent = `${assemblies[state.assembly].name} on ${samples[state.sample].short.toLowerCase()}`;
$("#sceneSubtitle").textContent =
`${state.load.toFixed(1)} kN · ${state.bolt} · ${targets[state.target].label} required zone`;
}
function updateAll() {
syncControls();
const snapshot = currentSnapshot();
const metrics = computeMetrics(snapshot);
rebuildScene();
updateAnalysis(metrics);
updateSceneText(metrics);
renderComparisonCards();
}
function applySnapshot(snapshot) {
state.sample = snapshot.sample;
state.assembly = snapshot.assembly;
state.bolt = snapshot.bolt;
state.load = snapshot.load;
updateAll();
}
// ----- Events -----
$("#boltSelect").addEventListener("change", event => {
state.bolt = event.target.value;
updateAll();
});
$("#loadRange").addEventListener("input", event => {
state.load = Number(event.target.value);
updateAll();
});
$("#targetSelect").addEventListener("change", event => {
state.target = event.target.value;
updateAll();
});
$("#resetCamera").addEventListener("click", resetCamera);
$("#showPressure").addEventListener("click", () => {
state.pressureVisible = !state.pressureVisible;
if (pressureGroup) pressureGroup.visible = state.pressureVisible;
$("#showPressure").textContent = `Pressure: ${state.pressureVisible ? "on" : "off"}`;
});
$("#pinReference").addEventListener("click", () => {
state.reference = readSnapshot(currentSnapshot());
renderComparisonCards();
showToast("Current assembly pinned as reference A.");
});
$("#swapReference").addEventListener("click", () => {
const current = currentSnapshot();
const oldReference = readSnapshot(state.reference);
state.reference = current;
applySnapshot(oldReference);
showToast("Reference A and current B swapped.");
});
$("#useA").addEventListener("click", () => {
applySnapshot(state.reference);
showToast("Reference assembly A applied.");
});
$("#useB").addEventListener("click", () => {
updateAll();
showToast("Current assembly B applied.");
});
$("#tryRecommended").addEventListener("click", () => {
const recommendation = recommendedAssembly();
state.assembly = recommendation.id;
updateAll();
showToast(`${recommendation.title} applied.`);
});
$("#chooseAssembly").addEventListener("click", () => {
const metrics = computeMetrics(currentSnapshot());
if (!metrics.broad || !metrics.pressureOK) {
showToast("This assembly does not yet satisfy the current support target.");
return;
}
state.chosen = currentSnapshot();
updateAnalysis(metrics);
renderComparisonCards();
showToast("Assembly selected for the intended support zone.");
});
// ----- Boot -----
createControlButtons();
updateAll();
resizeRenderer();
updateCamera();
renderer.setAnimationLoop(() => {
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```