Prompt specification
Build or customize the Three.js 3D scene "Arch versus beam classroom sandbox" 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: Arch versus beam classroom sandbox
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/arch-versus-beam-classroom-sandbox-x0392
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: arch versus beam classroom sandbox. Create interchangeable toy bridges spanning identical gaps; users compare support layouts and symbolic load paths, with clear labels separating educational diagrams from certified strength simulations. Return one self-contained HTML file.
Working Three.js Starter (arch-versus-beam-classroom-sandbox-x0392):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#173a35" />
<title>Span Lab — Arch vs Beam Classroom Sandbox</title>
<style>
:root {
--paper: #f7f4ea;
--paper-2: #eee9dc;
--ink: #173a35;
--muted: #61736e;
--line: #d9d6ca;
--teal: #269d91;
--teal-dark: #19766e;
--blue: #5274b7;
--coral: #ed745d;
--gold: #e6ae4f;
--green: #55a779;
--white: #fffefa;
--shadow: 0 14px 36px rgba(28, 50, 45, 0.11);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, select { font: inherit; }
button {
border: 0;
cursor: pointer;
}
button:focus-visible,
select:focus-visible {
outline: 3px solid rgba(38, 157, 145, 0.28);
outline-offset: 2px;
}
.app-header {
height: 70px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 22px;
background: var(--ink);
color: var(--white);
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 42px;
height: 42px;
flex: 0 0 auto;
display: grid;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 12px;
background: rgba(255, 255, 255, 0.08);
}
.brand-mark svg { width: 29px; height: 29px; }
.brand-copy { min-width: 0; }
.brand-title {
display: flex;
align-items: center;
gap: 10px;
font-weight: 800;
letter-spacing: 0.02em;
line-height: 1.05;
}
.brand-title span {
padding: 3px 7px;
border-radius: 5px;
color: #ccebe5;
background: rgba(75, 181, 167, 0.18);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.brand-subtitle {
margin-top: 4px;
color: #b9cac5;
font-size: 12px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.header-actions {
display: flex;
align-items: center;
gap: 8px;
}
.header-button {
min-height: 38px;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 0 13px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 9px;
color: #e9f1ee;
background: rgba(255, 255, 255, 0.06);
font-size: 12px;
font-weight: 700;
transition: background 150ms ease, border-color 150ms ease;
}
.header-button:hover {
background: rgba(255, 255, 255, 0.12);
border-color: rgba(255, 255, 255, 0.25);
}
.header-button.active {
color: #143a34;
background: #bce7de;
border-color: #bce7de;
}
.button-icon {
font-size: 16px;
line-height: 1;
}
.workspace {
height: calc(100% - 70px);
display: grid;
grid-template-columns: 350px minmax(0, 1fr);
}
.sidebar {
position: relative;
z-index: 4;
overflow-y: auto;
padding: 18px;
background: var(--paper);
border-right: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #bfc8c2 transparent;
}
.eyebrow {
margin: 0 0 7px;
color: var(--teal-dark);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.sidebar-intro h1 {
margin: 0;
font-size: 23px;
line-height: 1.1;
letter-spacing: -0.035em;
}
.sidebar-intro > p {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.education-note {
display: flex;
gap: 10px;
margin: 15px 0 18px;
padding: 12px;
border: 1px solid #badbd4;
border-radius: 12px;
background: #e7f4ef;
}
.note-icon {
width: 27px;
height: 27px;
flex: 0 0 auto;
display: grid;
place-items: center;
border-radius: 8px;
color: var(--white);
background: var(--teal);
font-size: 15px;
font-weight: 900;
}
.education-note strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.education-note p {
margin: 0;
color: #456a62;
font-size: 11px;
line-height: 1.45;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 17px 1px 9px;
color: #667871;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.station-card {
margin-bottom: 11px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--white);
box-shadow: 0 4px 12px rgba(31, 55, 49, 0.04);
transition: border-color 150ms ease, box-shadow 150ms ease;
}
.station-card.active {
border-color: #6eb8ae;
box-shadow: 0 0 0 2px rgba(38, 157, 145, 0.11), var(--shadow);
}
.station-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.station-name {
display: flex;
align-items: center;
gap: 9px;
font-size: 14px;
font-weight: 850;
}
.station-key {
width: 26px;
height: 26px;
display: grid;
place-items: center;
border-radius: 8px;
color: var(--white);
background: var(--ink);
font-size: 12px;
}
.station-card[data-station="B"] .station-key { background: #48658e; }
.load-total {
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.field-label {
display: block;
margin-bottom: 6px;
color: #6c7d76;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.type-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px;
padding: 4px;
border-radius: 10px;
background: #eeece4;
}
.type-button {
min-height: 34px;
border-radius: 7px;
color: #61716c;
background: transparent;
font-size: 12px;
font-weight: 800;
}
.type-button.active {
color: var(--ink);
background: var(--white);
box-shadow: 0 2px 7px rgba(31, 55, 49, 0.12);
}
.support-row {
display: grid;
grid-template-columns: 92px 1fr;
align-items: center;
gap: 10px;
margin-top: 12px;
}
.support-row .field-label { margin: 0; }
.support-select {
width: 100%;
min-height: 34px;
padding: 0 30px 0 10px;
border: 1px solid #d6d6cd;
border-radius: 8px;
color: var(--ink);
background: #faf9f4;
font-size: 11px;
font-weight: 700;
}
.load-row {
display: grid;
grid-template-columns: 36px 1fr 36px;
align-items: center;
gap: 8px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px dashed #deddd4;
}
.load-button {
width: 36px;
height: 34px;
border: 1px solid #d9d8cf;
border-radius: 8px;
color: var(--ink);
background: #f6f4ed;
font-size: 19px;
font-weight: 650;
}
.load-button:hover { background: #ebe8de; }
.load-readout {
text-align: center;
}
.load-readout span {
display: block;
color: #83908b;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.load-readout strong {
display: block;
margin-top: 2px;
font-size: 13px;
}
.compare-panel {
padding: 13px;
border: 1px solid #d7ded8;
border-radius: 13px;
background: #eef3ee;
}
.compare-panel p {
margin: 0;
color: #536c64;
font-size: 11px;
line-height: 1.52;
}
.compare-panel strong { color: var(--ink); }
.panel-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 11px;
}
.small-button {
min-height: 34px;
padding: 7px 9px;
border: 1px solid #cad6cf;
border-radius: 8px;
color: var(--ink);
background: rgba(255, 255, 255, 0.72);
font-size: 10px;
font-weight: 800;
}
.small-button:hover { background: var(--white); }
.legend {
display: grid;
gap: 8px;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: #61736d;
font-size: 10px;
}
.legend-swatch {
width: 17px;
height: 7px;
flex: 0 0 auto;
border-radius: 10px;
}
.legend-swatch.structure { background: var(--teal); }
.legend-swatch.load { background: var(--gold); }
.legend-swatch.path { background: var(--coral); }
.legend-swatch.support { background: var(--green); }
.strength-panel {
margin-top: 16px;
padding: 14px;
border: 1px solid #d5d7d1;
border-radius: 13px;
background: #e8e8e1;
}
.strength-panel .eyebrow { color: #6d736f; }
.strength-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
}
.strength-title h3 {
margin: 0;
font-size: 13px;
}
.not-included {
padding: 4px 7px;
border-radius: 6px;
color: #7b625b;
background: #f4ded7;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.strength-panel p {
margin: 0;
color: #66706c;
font-size: 10px;
line-height: 1.5;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #dfe7e4;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.stage-badge {
position: absolute;
z-index: 3;
top: 17px;
left: 18px;
display: flex;
align-items: center;
gap: 9px;
max-width: calc(100% - 36px);
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 10px;
color: #274b44;
background: rgba(255, 254, 250, 0.87);
box-shadow: 0 7px 22px rgba(35, 63, 56, 0.09);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.badge-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(38, 157, 145, 0.15);
}
.scene-hint {
position: absolute;
z-index: 3;
top: 18px;
right: 18px;
padding: 8px 11px;
border-radius: 9px;
color: #4f6962;
background: rgba(255, 254, 250, 0.74);
font-size: 10px;
font-weight: 700;
pointer-events: none;
}
.label-layer {
position: absolute;
z-index: 2;
inset: 0;
pointer-events: none;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -100%);
white-space: nowrap;
will-change: left, top;
}
.station-label {
display: grid;
grid-template-columns: auto auto;
align-items: center;
gap: 6px;
padding: 6px 8px 6px 6px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 9px;
color: #294943;
background: rgba(255, 254, 250, 0.9);
box-shadow: 0 6px 16px rgba(31, 58, 51, 0.1);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
}
.station-label small {
grid-column: 1 / -1;
color: #71817c;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.04em;
}
.label-key {
width: 20px;
height: 20px;
display: grid;
place-items: center;
border-radius: 6px;
color: white;
background: var(--ink);
font-size: 9px;
}
.load-label {
padding: 3px 6px;
border-radius: 6px;
color: #5c481d;
background: rgba(255, 230, 166, 0.94);
box-shadow: 0 3px 9px rgba(87, 66, 26, 0.12);
font-size: 9px;
font-weight: 900;
}
.dimension-label {
padding: 5px 9px;
border-radius: 6px;
color: #516961;
background: rgba(255, 254, 250, 0.79);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stage-footer {
position: absolute;
z-index: 3;
right: 18px;
bottom: 17px;
left: 18px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 14px;
pointer-events: none;
}
.scene-legend {
display: flex;
flex-wrap: wrap;
gap: 8px 13px;
max-width: 520px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 10px;
color: #526b63;
background: rgba(255, 254, 250, 0.83);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 750;
}
.scene-legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.scene-legend i {
width: 14px;
height: 5px;
border-radius: 8px;
}
.zoom-controls {
display: flex;
gap: 5px;
pointer-events: auto;
}
.zoom-button {
width: 34px;
height: 34px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 9px;
color: var(--ink);
background: rgba(255, 254, 250, 0.9);
box-shadow: 0 5px 14px rgba(31, 58, 51, 0.09);
font-size: 18px;
font-weight: 700;
}
.toast {
position: absolute;
z-index: 5;
left: 50%;
bottom: 78px;
max-width: calc(100% - 40px);
padding: 9px 13px;
border-radius: 9px;
color: white;
background: rgba(23, 58, 53, 0.92);
box-shadow: var(--shadow);
transform: translate(-50%, 12px);
opacity: 0;
pointer-events: none;
transition: opacity 160ms ease, transform 160ms ease;
font-size: 11px;
font-weight: 750;
text-align: center;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 980px) {
.workspace { grid-template-columns: 315px minmax(0, 1fr); }
.sidebar { padding: 14px; }
.brand-subtitle { display: none; }
.scene-hint { display: none; }
}
@media (max-width: 760px) {
html, body { overflow: auto; }
.app-header {
height: auto;
min-height: 64px;
padding: 10px 13px;
}
.brand-title span { display: none; }
.header-button { padding: 0 10px; }
.header-button .button-label { display: none; }
.workspace {
height: auto;
display: flex;
flex-direction: column-reverse;
}
.stage {
height: 58vh;
min-height: 420px;
}
.sidebar {
overflow: visible;
border-right: 0;
border-top: 1px solid var(--line);
}
.station-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.station-card { margin-bottom: 0; }
.stage-footer { align-items: flex-end; }
.scene-legend { max-width: calc(100% - 92px); }
}
@media (max-width: 540px) {
.station-grid { grid-template-columns: 1fr; }
.brand-mark { width: 36px; height: 36px; }
.brand-title { font-size: 14px; }
.stage { min-height: 390px; }
.stage-badge { left: 10px; top: 10px; padding: 8px 9px; }
.stage-footer { left: 10px; right: 10px; bottom: 10px; }
.scene-legend { gap: 6px 9px; padding: 8px; }
}
</style>
</head>
<body>
<header class="app-header">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 32 32" fill="none">
<path d="M3 23h26M5 22V13m22 9V13M6 15c6-9 14-9 20 0" stroke="#ccebe5" stroke-width="2.2" stroke-linecap="round"/>
<path d="M8 15v7m5-11v11m6-11v11m5-7v7" stroke="#7ed0c2" stroke-width="1.5" stroke-linecap="round"/>
</svg>
</div>
<div class="brand-copy">
<div class="brand-title">
SPAN LAB
<span>Classroom sandbox</span>
</div>
<div class="brand-subtitle">Interchangeable toy bridges · symbolic load paths · no strength claims</div>
</div>
</div>
<div class="header-actions">
<button id="toggle-paths" class="header-button active" type="button" aria-pressed="true">
<span class="button-icon">⌁</span>
<span id="path-button-label" class="button-label">Load paths on</span>
</button>
<button id="reset-view" class="header-button" type="button">
<span class="button-icon">⌖</span>
<span class="button-label">Reset view</span>
</button>
</div>
</header>
<main class="workspace">
<aside class="sidebar" aria-label="Bridge sandbox controls">
<div class="sidebar-intro">
<p class="eyebrow">Bridge comparison studio</p>
<h1>Same span.<br>Different support story.</h1>
<p>Swap arch and beam kits, change the supports, then place toy loads to compare qualitative load-transfer routes.</p>
</div>
<div class="education-note">
<div class="note-icon">i</div>
<div>
<strong>Educational diagram</strong>
<p>Paths show route and direction only. They are not stress, reaction, deflection, or safe-load calculations.</p>
</div>
</div>
<div class="section-label">
<span>Interchangeable gaps</span>
<span id="total-load">2 toy units</span>
</div>
<div class="station-grid">
<article id="station-A" class="station-card active" data-station="A">
<div class="station-head">
<div class="station-name">
<span class="station-key">A</span>
<span>Gap A</span>
</div>
<span id="load-A" class="load-total">1 unit</span>
</div>
<span class="field-label">Bridge kit</span>
<div class="type-switch" role="group" aria-label="Gap A bridge type">
<button class="type-button active" data-target="A" data-type="arch" type="button">Arch</button>
<button class="type-button" data-target="A" data-type="beam" type="button">Beam</button>
</div>
<div class="support-row">
<label class="field-label" for="support-A">Supports</label>
<select id="support-A" class="support-select" data-target="A">
<option value="ends">End supports only</option>
<option value="pier">Ends + center pier</option>
</select>
</div>
<div class="load-row">
<button class="load-button" data-target="A" data-delta="-1" type="button" aria-label="Remove one toy unit from Gap A">−</button>
<div class="load-readout">
<span>Toy load</span>
<strong id="load-readout-A">1 unit</strong>
</div>
<button class="load-button" data-target="A" data-delta="1" type="button" aria-label="Add one toy unit to Gap A">+</button>
</div>
</article>
<article id="station-B" class="station-card" data-station="B">
<div class="station-head">
<div class="station-name">
<span class="station-key">B</span>
<span>Gap B</span>
</div>
<span id="load-B" class="load-total">1 unit</span>
</div>
<span class="field-label">Bridge kit</span>
<div class="type-switch" role="group" aria-label="Gap B bridge type">
<button class="type-button" data-target="B" data-type="arch" type="button">Arch</button>
<button class="type-button active" data-target="B" data-type="beam" type="button">Beam</button>
</div>
<div class="support-row">
<label class="field-label" for="support-B">Supports</label>
<select id="support-B" class="support-select" data-target="B">
<option value="ends">End supports only</option>
<option value="pier" selected>Ends + center pier</option>
</select>
</div>
<div class="load-row">
<button class="load-button" data-target="B" data-delta="-1" type="button" aria-label="Remove one toy unit from Gap B">−</button>
<div class="load-readout">
<span>Toy load</span>
<strong id="load-readout-B">1 unit</strong>
</div>
<button class="load-button" data-target="B" data-delta="1" type="button" aria-label="Add one toy unit to Gap B">+</button>
</div>
</article>
</div>
<div class="section-label"><span>Comparison notes</span></div>
<div class="compare-panel">
<p id="compare-summary"></p>
<div class="panel-actions">
<button id="swap-kits" class="small-button" type="button">⇄ Swap bridge kits</button>
<button id="match-supports" class="small-button" type="button">Match support layouts</button>
</div>
</div>
<div class="section-label"><span>Model key</span></div>
<div class="legend">
<div class="legend-item"><i class="legend-swatch structure"></i>Bridge structure</div>
<div class="legend-item"><i class="legend-swatch load"></i>Toy load unit</div>
<div class="legend-item"><i class="legend-swatch path"></i>Symbolic load path</div>
<div class="legend-item"><i class="legend-swatch support"></i>Symbolic support transfer</div>
</div>
<div class="strength-panel">
<p class="eyebrow">Separate analysis section</p>
<div class="strength-title">
<h3>Certified strength simulation</h3>
<span class="not-included">Not included</span>
</div>
<p>This sandbox does not calculate stress, strain, buckling, reactions, factor of safety, code compliance, or safe working load. All lengths and loads are arbitrary teaching units.</p>
</div>
<button id="reset-demo" class="small-button" style="width:100%; margin-top:10px" type="button">Reset classroom setup</button>
</aside>
<section id="stage" class="stage" aria-label="Interactive three-dimensional bridge model">
<canvas id="scene" aria-label="Low-poly arch and beam bridge comparison. Drag to orbit, scroll to zoom, and click a bridge deck to add a toy load."></canvas>
<div class="stage-badge">
<i class="badge-dot"></i>
Educational model · no strength calculations
</div>
<div class="scene-hint">Drag to orbit · scroll to zoom · click a deck</div>
<div id="label-layer" class="label-layer"></div>
<div class="stage-footer">
<div class="scene-legend" aria-label="Scene legend">
<span><i style="background:#269d91"></i>Structure</span>
<span><i style="background:#e6ae4f"></i>Toy unit</span>
<span><i style="background:#ed745d"></i>Load route</span>
<span><i style="background:#55a779"></i>Support</span>
<span>Routes are symbolic, not force values</span>
</div>
<div class="zoom-controls">
<button id="zoom-out" class="zoom-button" type="button" aria-label="Zoom out">−</button>
<button id="zoom-in" class="zoom-button" type="button" aria-label="Zoom in">+</button>
</div>
</div>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
</section>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const canvas = document.querySelector("#scene");
const labelLayer = document.querySelector("#label-layer");
const toastElement = document.querySelector("#toast");
const renderer = new THREE.WebGLRenderer({
canvas,
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe7e4);
scene.fog = new THREE.Fog(0xdfe7e4, 32, 66);
const camera = new THREE.PerspectiveCamera(35, 1, 0.1, 100);
const clock = new THREE.Clock();
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x65746d, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4db, 3.15);
keyLight.position.set(-9, 15, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -16;
keyLight.shadow.camera.right = 16;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9dfff, 1.05);
fillLight.position.set(12, 8, -9);
scene.add(fillLight);
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0xd7dfda, roughness: 0.96, flatShading: true
}),
base: new THREE.MeshStandardMaterial({
color: 0xf2ecdc, roughness: 0.88, flatShading: true
}),
baseAlt: new THREE.MeshStandardMaterial({
color: 0xe7e0cf, roughness: 0.9, flatShading: true
}),
recess: new THREE.MeshStandardMaterial({
color: 0x78928c, roughness: 0.95, flatShading: true
}),
recessB: new THREE.MeshStandardMaterial({
color: 0x81969a, roughness: 0.95, flatShading: true
}),
stone: new THREE.MeshStandardMaterial({
color: 0xb9b0a0, roughness: 0.92, flatShading: true
}),
cap: new THREE.MeshStandardMaterial({
color: 0x8eaaa3, roughness: 0.82, flatShading: true
}),
archA: new THREE.MeshStandardMaterial({
color: 0x269d91, roughness: 0.73, flatShading: true
}),
archB: new THREE.MeshStandardMaterial({
color: 0x21877e, roughness: 0.76, flatShading: true
}),
beam: new THREE.MeshStandardMaterial({
color: 0x5274b7, roughness: 0.72, flatShading: true
}),
beamDark: new THREE.MeshStandardMaterial({
color: 0x435f9a, roughness: 0.78, flatShading: true
}),
deckA: new THREE.MeshStandardMaterial({
color: 0xe0b86e, roughness: 0.87, flatShading: true
}),
deckB: new THREE.MeshStandardMaterial({
color: 0xd4a75d, roughness: 0.88, flatShading: true
}),
load1: new THREE.MeshStandardMaterial({
color: 0xf0c45e, roughness: 0.72, flatShading: true
}),
load2: new THREE.MeshStandardMaterial({
color: 0xeea64f, roughness: 0.72, flatShading: true
}),
load3: new THREE.MeshStandardMaterial({
color: 0xe98a50, roughness: 0.72, flatShading: true
}),
path: new THREE.MeshBasicMaterial({
color: 0xed745d, transparent: true, opacity: 0.94
}),
pulse: new THREE.MeshBasicMaterial({ color: 0xffd4c9 }),
reaction: new THREE.MeshBasicMaterial({ color: 0x55a779 }),
edge: new THREE.LineBasicMaterial({
color: 0x60756e, transparent: true, opacity: 0.18
}),
ruler: new THREE.LineBasicMaterial({
color: 0x78908a, transparent: true, opacity: 0.55
}),
selection: new THREE.LineBasicMaterial({
color: 0x269d91, transparent: true, opacity: 0.95
})
};
const slotX = [-2.1, -1.05, 0, 1.05, 2.1];
const deckTop = 3.27;
const pathEnabled = { value: true };
const stations = {
A: {
id: "A",
z: -3.2,
type: "arch",
support: "ends",
slots: [0, 0, 1, 0, 0],
root: new THREE.Group(),
bridgeGroup: new THREE.Group(),
supportGroup: new THREE.Group(),
loadGroup: new THREE.Group(),
pathGroup: new THREE.Group(),
interactive: [],
loadLabels: [],
pulses: [],
label: null
},
B: {
id: "B",
z: 3.2,
type: "beam",
support: "pier",
slots: [0, 1, 0, 0, 0],
root: new THREE.Group(),
bridgeGroup: new THREE.Group(),
supportGroup: new THREE.Group(),
loadGroup: new THREE.Group(),
pathGroup: new THREE.Group(),
interactive: [],
loadLabels: [],
pulses: [],
label: null
}
};
Object.values(stations).forEach((station) => {
station.root.position.z = station.z;
station.root.add(
station.bridgeGroup,
station.supportGroup,
station.loadGroup,
station.pathGroup
);
scene.add(station.root);
});
function addBox(parent, size, position, material, withEdges = false) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (withEdges) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
materials.edge
);
edges.renderOrder = 2;
mesh.add(edges);
}
return mesh;
}
function clearGroup(group) {
for (const child of [...group.children]) {
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
group.remove(child);
}
}
function makeLineLoop(points, material, parent) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(...point))
);
const line = new THREE.LineLoop(geometry, material);
parent.add(line);
return line;
}
function buildBase() {
const base = new THREE.Group();
scene.add(base);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
materials.ground
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.73;
floor.receiveShadow = true;
scene.add(floor);
// Two identical 7 × 3.6 unit openings are formed by separate base slabs.
addBox(base, [7.5, 0.65, 13], [-7.25, -0.325, 0], materials.base, true);
addBox(base, [7.5, 0.65, 13], [7.25, -0.325, 0], materials.base, true);
addBox(base, [7, 0.65, 2.8], [0, -0.325, 0], materials.baseAlt, true);
addBox(base, [7, 0.65, 1.5], [0, -0.325, -5.75], materials.baseAlt, true);
addBox(base, [7, 0.65, 1.5], [0, -0.325, 5.75], materials.baseAlt, true);
addBox(base, [7, 0.12, 3.6], [0, -0.63, -3.2], materials.recess, true);
addBox(base, [7, 0.12, 3.6], [0, -0.63, 3.2], materials.recessB, true);
makeLineLoop([
[-3.5, -0.555, -5],
[3.5, -0.555, -5],
[3.5, -0.555, -1.4],
[-3.5, -0.555, -1.4]
], materials.ruler, base);
makeLineLoop([
[-3.5, -0.555, 1.4],
[3.5, -0.555, 1.4],
[3.5, -0.555, 5],
[-3.5, -0.555, 5]
], materials.ruler, base);
// Dimension line and ruler ticks are geometric annotations, not analysis.
const dimensionPoints = [
new THREE.Vector3(-3.5, 0.055, 6.15),
new THREE.Vector3(3.5, 0.055, 6.15),
new THREE.Vector3(-3.5, 0.055, 5.95),
new THREE.Vector3(-3.5, 0.055, 6.35),
new THREE.Vector3(3.5, 0.055, 5.95),
new THREE.Vector3(3.5, 0.055, 6.35)
];
const dimensionGeometry = new THREE.BufferGeometry().setFromPoints(dimensionPoints);
base.add(new THREE.LineSegments(dimensionGeometry, materials.ruler));
const tickPoints = [];
for (let x = -10; x <= 10; x += 0.5) {
const length = Number.isInteger(x) ? 0.24 : 0.13;
tickPoints.push(
new THREE.Vector3(x, 0.055, 6.35),
new THREE.Vector3(x, 0.055, 6.35 - length)
);
}
const tickGeometry = new THREE.BufferGeometry().setFromPoints(tickPoints);
base.add(new THREE.LineSegments(tickGeometry, materials.ruler));
}
function buildSupports(station) {
clearGroup(station.supportGroup);
for (const x of [-3.42, 3.42]) {
addBox(
station.supportGroup,
[0.68, 2.45, 3.05],
[x, 1.225, 0],
materials.stone,
true
);
addBox(
station.supportGroup,
[0.88, 0.22, 3.25],
[x, 2.56, 0],
materials.cap,
true
);
}
if (station.support === "pier") {
addBox(
station.supportGroup,
[0.56, 2.45, 2.5],
[0, 1.225, 0],
materials.stone,
true
);
addBox(
station.supportGroup,
[0.78, 0.22, 2.7],
[0, 2.56, 0],
materials.cap,
true
);
}
}
function buildBridge(station) {
clearGroup(station.bridgeGroup);
const structureMaterial = station.type === "arch"
? materials.archA
: materials.beam;
// Nine separate deck planks keep the toy-block character.
for (let i = 0; i < 9; i++) {
const x = -2.8 + i * 0.7;
const plank = addBox(
station.bridgeGroup,
[0.68, 0.22, 3.0],
[x, 3.15, 0],
i % 2 === 0 ? materials.deckA : materials.deckB,
true
);
plank.userData = { kind: "deck", station: station.id };
station.interactive.push(plank);
}
// Low-poly side rails.
for (const z of [-1.48, 1.48]) {
addBox(
station.bridgeGroup,
[6.5, 0.10, 0.10],
[0, 3.84, z],
structureMaterial
);
for (const x of [-3, -1.5, 0, 1.5, 3]) {
addBox(
station.bridgeGroup,
[0.10, 0.55, 0.10],
[x, 3.54, z],
structureMaterial
);
}
}
if (station.type === "beam") {
for (const z of [-0.76, 0.76]) {
addBox(
station.bridgeGroup,
[6.35, 0.32, 0.34],
[0, 2.88, z],
materials.beam,
true
);
}
for (const x of [-2.45, 0, 2.45]) {
addBox(
station.bridgeGroup,
[0.18, 0.18, 2.75],
[x, 2.88, 0],
materials.beamDark
);
}
} else {
const radius = 2.95;
const segmentCount = 11;
for (let i = 0; i < segmentCount; i++) {
const angle = Math.PI - (i / (segmentCount - 1)) * Math.PI;
const x = radius * Math.cos(angle);
const y = 2.45 + 0.4 * Math.sin(angle);
const tangentAngle = Math.atan2(
0.4 * Math.cos(angle),
-radius * Math.sin(angle)
);
const block = addBox(
station.bridgeGroup,
[0.68, 0.4, 2.72],
[x, y, 0],
i % 2 === 0 ? materials.archA : materials.archB,
true
);
block.rotation.z = tangentAngle;
}
}
}
function clearLoadLabels(station) {
station.loadLabels.forEach((label) => label.element.remove());
station.loadLabels = [];
}
function buildLoads(station) {
clearGroup(station.loadGroup);
clearLoadLabels(station);
const loadMaterials = [materials.load1, materials.load2, materials.load3];
station.slots.forEach((value, slotIndex) => {
for (let level = 0; level < value; level++) {
const cube = addBox(
station.loadGroup,
[0.62, 0.38, 0.68],
[slotX[slotIndex], deckTop + 0.19 + level * 0.42, 0],
loadMaterials[Math.min(level, 2)],
true
);
cube.userData = {
kind: "load",
station: station.id,
slot: slotIndex
};
station.interactive.push(cube);
}
if (value > 0) {
const label = document.createElement("div");
label.className = "scene-label load-label";
label.textContent = `${value}u`;
labelLayer.appendChild(label);
station.loadLabels.push({
element: label,
position: new THREE.Vector3(
slotX[slotIndex],
deckTop + value * 0.42 + 0.22,
station.z
)
});
}
});
}
function archHeightAt(x) {
const radius = 2.95;
const normalized = THREE.MathUtils.clamp(x / radius, -1, 1);
return 2.45 + 0.4 * Math.sqrt(1 - normalized * normalized);
}
function createPathCurve(points) {
const curve = new THREE.CurvePath();
for (let i = 0; i < points.length - 1; i++) {
curve.add(new THREE.LineCurve3(points[i], points[i + 1]));
}
return curve;
}
function buildPaths(station) {
clearGroup(station.pathGroup);
station.pulses = [];
const supportXs = station.support === "pier"
? [-3.42, 0, 3.42]
: [-3.42, 3.42];
station.slots.forEach((value, slotIndex) => {
if (value === 0) return;
const x = slotX[slotIndex];
const z = 0.42;
const loadTop = deckTop + value * 0.42 + 0.18;
const points = [
new THREE.Vector3(x, loadTop, z),
new THREE.Vector3(x, deckTop + 0.03, z)
];
if (station.type === "beam") {
const nearestSupport = supportXs.reduce((best, supportX) =>
Math.abs(supportX - x) < Math.abs(best - x) ? supportX : best
);
points.push(new THREE.Vector3(x, 2.88, z));
points.push(new THREE.Vector3(nearestSupport, 2.88, z));
points.push(new THREE.Vector3(nearestSupport, 0.08, z));
} else {
const radius = 2.95;
const startAngle = Math.acos(
THREE.MathUtils.clamp(x / radius, -1, 1)
);
points.push(new THREE.Vector3(x, archHeightAt(x), z));
for (let i = 0; i <= 12; i++) {
const t = i / 12;
const angle = x >= 0
? startAngle * (1 - t)
: startAngle + (Math.PI - startAngle) * t;
points.push(new THREE.Vector3(
radius * Math.cos(angle),
2.45 + 0.4 * Math.sin(angle),
z
));
}
points.push(new THREE.Vector3(
points[points.length - 1].x,
0.08,
z
));
}
const curve = createPathCurve(points);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, Math.max(48, points.length * 8), 0.038, 6, false),
materials.path
);
tube.renderOrder = 4;
station.pathGroup.add(tube);
const up = new THREE.Vector3(0, 1, 0);
for (const t of [0.17, 0.47, 0.77]) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.105, 0.27, 8),
materials.path
);
arrow.position.copy(curve.getPointAt(t));
const tangent = curve.getTangentAt(t).normalize();
arrow.quaternion.setFromUnitVectors(up, tangent);
arrow.renderOrder = 5;
station.pathGroup.add(arrow);
}
const pulse = new THREE.Mesh(
new THREE.SphereGeometry(0.082, 10, 8),
materials.pulse
);
pulse.renderOrder = 6;
station.pathGroup.add(pulse);
station.pulses.push({ mesh: pulse, curve, offset: station.pulses.length * 0.19 });
});
// Green arrows indicate a qualitative support-transfer direction.
for (const x of supportXs) {
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 1.68, 7),
materials.reaction
);
shaft.position.set(x, 0.93, -1.66);
shaft.renderOrder = 4;
station.pathGroup.add(shaft);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.11, 0.28, 8),
materials.reaction
);
arrow.position.set(x, 1.9, -1.66);
arrow.renderOrder = 5;
station.pathGroup.add(arrow);
}
station.pathGroup.visible = pathEnabled.value;
}
function rebuildStation(station) {
station.interactive = [];
clearGroup(station.bridgeGroup);
clearGroup(station.supportGroup);
clearGroup(station.loadGroup);
clearGroup(station.pathGroup);
clearLoadLabels(station);
buildSupports(station);
buildBridge(station);
buildLoads(station);
buildPaths(station);
updateStationLabel(station);
}
function updateStationLabel(station) {
if (!station.label) {
station.label = document.createElement("div");
station.label.className = "scene-label station-label";
labelLayer.appendChild(station.label);
}
const supportText = station.support === "pier"
? "end supports + center pier"
: "end supports only";
station.label.innerHTML = `
<span class="label-key">${station.id}</span>
<span>${station.type.toUpperCase()}</span>
<small>${supportText}</small>
`;
}
const dimensionLabel = document.createElement("div");
dimensionLabel.className = "scene-label dimension-label";
dimensionLabel.textContent = "Identical 7-unit gap";
labelLayer.appendChild(dimensionLabel);
const dimensionPosition = new THREE.Vector3(0, 0.15, 6.55);
const selectionGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-3.35, 3.31, -1.63),
new THREE.Vector3(3.35, 3.31, -1.63),
new THREE.Vector3(3.35, 3.31, 1.63),
new THREE.Vector3(-3.35, 3.31, 1.63)
]);
const selectionRectangle = new THREE.LineLoop(
selectionGeometry,
materials.selection
);
selectionRectangle.position.z = stations.A.z;
selectionRectangle.renderOrder = 8;
scene.add(selectionRectangle);
class OrbitControls {
constructor(cameraObject, domElement) {
this.camera = cameraObject;
this.domElement = domElement;
this.target = new THREE.Vector3(0, 1.25, 0);
this.goal = { yaw: 0.62, pitch: 0.72, radius: 29.5 };
this.current = { ...this.goal };
this.pointers = new Map();
this.gestureMoved = 0;
this.multiTouch = false;
this.pinchDistance = 0;
this.bindEvents();
}
bindEvents() {
const element = this.domElement;
element.addEventListener("pointerdown", (event) => {
element.setPointerCapture(event.pointerId);
this.pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (this.pointers.size === 1) {
this.gestureMoved = 0;
this.multiTouch = false;
} else {
this.multiTouch = true;
this.pinchDistance = this.getPinchDistance();
}
});
element.addEventListener("pointermove", (event) => {
const previous = this.pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (this.pointers.size === 1) {
this.goal.yaw -= dx * 0.006;
this.goal.pitch = THREE.MathUtils.clamp(
this.goal.pitch + dy * 0.005,
0.28,
1.22
);
this.gestureMoved += Math.hypot(dx, dy);
} else if (this.pointers.size === 2) {
const nextDistance = this.getPinchDistance();
if (this.pinchDistance > 0 && nextDistance > 0) {
this.goal.radius = THREE.MathUtils.clamp(
this.goal.radius * (this.pinchDistance / nextDistance),
16,
43
);
}
this.pinchDistance = nextDistance;
}
});
element.addEventListener("pointerup", (event) => {
const shouldPick =
this.pointers.size === 1 &&
!this.multiTouch &&
this.gestureMoved < 6 &&
event.button === 0;
this.pointers.delete(event.pointerId);
if (shouldPick) pickScene(event);
if (this.pointers.size === 0) {
this.multiTouch = false;
this.gestureMoved = 0;
}
});
element.addEventListener("pointercancel", (event) => {
this.pointers.delete(event.pointerId);
if (this.pointers.size === 0) {
this.multiTouch = false;
this.gestureMoved = 0;
}
});
element.addEventListener("wheel", (event) => {
event.preventDefault();
this.goal.radius = THREE.MathUtils.clamp(
this.goal.radius + event.deltaY * 0.018,
16,
43
);
}, { passive: false });
element.addEventListener("contextmenu", (event) => event.preventDefault());
}
getPinchDistance() {
const values = [...this.pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
reset() {
this.goal = { yaw: 0.62, pitch: 0.72, radius: 29.5 };
}
update() {
const smoothing = 0.13;
this.current.yaw += (this.goal.yaw - this.current.yaw) * smoothing;
this.current.pitch += (this.goal.pitch - this.current.pitch) * smoothing;
this.current.radius += (this.goal.radius - this.current.radius) * smoothing;
const horizontalRadius = Math.cos(this.current.pitch) * this.current.radius;
this.camera.position.set(
this.target.x + Math.sin(this.current.yaw) * horizontalRadius,
this.target.y + Math.sin(this.current.pitch) * this.current.radius,
this.target.z + Math.cos(this.current.yaw) * horizontalRadius
);
this.camera.lookAt(this.target);
this.camera.updateMatrixWorld();
}
}
const controls = new OrbitControls(camera, canvas);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pickScene(event) {
const rect = canvas.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 objects = Object.values(stations).flatMap((station) => station.interactive);
const hit = raycaster.intersectObjects(objects, false)[0];
if (!hit) return;
const data = hit.object.userData;
const station = stations[data.station];
selectStation(station.id);
if (data.kind === "load") {
station.slots[data.slot] = Math.max(0, station.slots[data.slot] - 1);
rebuildStation(station);
updateUI();
showToast(`Removed one toy unit from Gap ${station.id}`);
return;
}
const localPoint = station.root.worldToLocal(hit.point.clone());
let nearestIndex = 0;
let nearestDistance = Infinity;
slotX.forEach((x, index) => {
const distance = Math.abs(localPoint.x - x);
if (distance < nearestDistance) {
nearestDistance = distance;
nearestIndex = index;
}
});
if (station.slots[nearestIndex] < 3) {
station.slots[nearestIndex] += 1;
rebuildStation(station);
updateUI();
showToast(`Added 1 toy unit to Gap ${station.id}`);
} else {
showToast("That deck slot already has the maximum 3 toy units");
}
}
function selectStation(id) {
Object.entries(stations).forEach(([stationId, station]) => {
document.querySelector(`#station-${stationId}`).classList.toggle(
"active",
stationId === id
);
station.label.classList.toggle("active", stationId === id);
});
selectionRectangle.position.z = stations[id].z;
}
function totalUnits(station) {
return station.slots.reduce((sum, value) => sum + value, 0);
}
function updateUI() {
let combinedTotal = 0;
Object.values(stations).forEach((station) => {
const total = totalUnits(station);
combinedTotal += total;
document.querySelectorAll(
`.type-button[data-target="${station.id}"]`
).forEach((button) => {
button.classList.toggle("active", button.dataset.type === station.type);
button.setAttribute(
"aria-pressed",
String(button.dataset.type === station.type)
);
});
document.querySelector(`#support-${station.id}`).value = station.support;
document.querySelector(`#load-${station.id}`).textContent =
`${total} ${total === 1 ? "unit" : "units"}`;
document.querySelector(`#load-readout-${station.id}`).textContent =
`${total} ${total === 1 ? "unit" : "units"}`;
});
document.querySelector("#total-load").textContent =
`${combinedTotal} toy ${combinedTotal === 1 ? "unit" : "units"}`;
const a = stations.A;
const b = stations.B;
const aSupport = a.support === "pier"
? "end supports plus a center pier"
: "end supports only";
const bSupport = b.support === "pier"
? "end supports plus a center pier"
: "end supports only";
let summary = `<strong>Gap A</strong> uses an <strong>${a.type}</strong> with ${aSupport}. ` +
`<strong>Gap B</strong> uses a <strong>${b.type}</strong> with ${bSupport}. `;
if (a.support !== b.support) {
summary += "The center post adds a support-transfer point in the drawing, but no force value is calculated.";
} else {
summary += "Both drawings have the same support layout, so their routes can be compared directly.";
}
document.querySelector("#compare-summary").innerHTML = summary;
}
let toastTimer;
function showToast(message) {
toastElement.textContent = message;
toastElement.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toastElement.classList.remove("show");
}, 1800);
}
function addUnit(station) {
const index = station.slots.findIndex((value) => value < 3);
if (index === -1) {
showToast("Gap " + station.id + " already has 15 toy units");
return;
}
station.slots[index] += 1;
rebuildStation(station);
updateUI();
}
function removeUnit(station) {
const index = [...station.slots].reverse().findIndex((value) => value > 0);
if (index === -1) {
showToast("Gap " + station.id + " has no toy units to remove");
return;
}
const actualIndex = station.slots.length - 1 - index;
station.slots[actualIndex] -= 1;
rebuildStation(station);
updateUI();
}
document.querySelectorAll(".type-button").forEach((button) => {
button.addEventListener("click", () => {
const station = stations[button.dataset.target];
station.type = button.dataset.type;
selectStation(station.id);
rebuildStation(station);
updateUI();
});
});
document.querySelectorAll(".support-select").forEach((select) => {
select.addEventListener("change", () => {
const station = stations[select.dataset.target];
station.support = select.value;
selectStation(station.id);
rebuildStation(station);
updateUI();
});
});
document.querySelectorAll(".load-button").forEach((button) => {
button.addEventListener("click", () => {
const station = stations[button.dataset.target];
selectStation(station.id);
if (Number(button.dataset.delta) > 0) addUnit(station);
else removeUnit(station);
});
});
document.querySelectorAll(".station-card").forEach((card) => {
card.addEventListener("click", (event) => {
if (!event.target.closest("button, select")) {
selectStation(card.dataset.station);
}
});
});
document.querySelector("#swap-kits").addEventListener("click", () => {
const type = stations.A.type;
stations.A.type = stations.B.type;
stations.B.type = type;
rebuildStation(stations.A);
rebuildStation(stations.B);
updateUI();
showToast("Swapped the arch and beam kits");
});
document.querySelector("#match-supports").addEventListener("click", () => {
stations.B.support = stations.A.support;
rebuildStation(stations.B);
updateUI();
showToast("Gap B now matches Gap A’s support layout");
});
document.querySelector("#toggle-paths").addEventListener("click", () => {
pathEnabled.value = !pathEnabled.value;
Object.values(stations).forEach((station) => {
station.pathGroup.visible = pathEnabled.value;
});
const button = document.querySelector("#toggle-paths");
button.classList.toggle("active", pathEnabled.value);
button.setAttribute("aria-pressed", String(pathEnabled.value));
document.querySelector("#path-button-label").textContent =
pathEnabled.value ? "Load paths on" : "Load paths off";
});
document.querySelector("#reset-view").addEventListener("click", () => {
controls.reset();
showToast("View reset");
});
document.querySelector("#zoom-in").addEventListener("click", () => {
controls.goal.radius = THREE.MathUtils.clamp(
controls.goal.radius - 2.2,
16,
43
);
});
document.querySelector("#zoom-out").addEventListener("click", () => {
controls.goal.radius = THREE.MathUtils.clamp(
controls.goal.radius + 2.2,
16,
43
);
});
document.querySelector("#reset-demo").addEventListener("click", () => {
stations.A.type = "arch";
stations.A.support = "ends";
stations.A.slots = [0, 0, 1, 0, 0];
stations.B.type = "beam";
stations.B.support = "pier";
stations.B.slots = [0, 1, 0, 0, 0];
pathEnabled.value = true;
Object.values(stations).forEach((station) => {
station.pathGroup.visible = true;
rebuildStation(station);
});
const pathButton = document.querySelector("#toggle-paths");
pathButton.classList.add("active");
pathButton.setAttribute("aria-pressed", "true");
document.querySelector("#path-button-label").textContent = "Load paths on";
controls.reset();
selectStation("A");
updateUI();
showToast("Classroom setup reset");
});
function updateOverlay(element, position) {
const projected = position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
element.style.display = visible ? "" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * stage.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * stage.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateOverlays() {
Object.values(stations).forEach((station) => {
updateOverlay(
station.label,
new THREE.Vector3(0, 4.42, station.z)
);
station.loadLabels.forEach((loadLabel) => {
updateOverlay(loadLabel.element, loadLabel.position);
});
});
updateOverlay(dimensionLabel, dimensionPosition);
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
buildBase();
Object.values(stations).forEach(rebuildStation);
updateUI();
selectStation("A");
resize();
if (stage.clientWidth / stage.clientHeight < 1.15) {
controls.goal.radius = 35;
controls.current.radius = 35;
}
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
controls.update();
Object.values(stations).forEach((station) => {
station.pulses.forEach((pulse, index) => {
const t = (elapsed * 0.14 + pulse.offset + index * 0.07) % 1;
pulse.mesh.position.copy(pulse.curve.getPointAt(t));
});
});
updateOverlays();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```