Prompt specification
Build or customize the Three.js 3D scene "Plan a shelter from recovered components" 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: Plan a shelter from recovered components
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/plan-a-shelter-from-recovered-components-x2184
Scene Description Prompt:
Assemble a low-poly schematic shelter from reclaimed parts, checking dimensions, missing connections, and remaining inventory. One HTML file using Three.js from cdnjs.
Working Three.js Starter (plan-a-shelter-from-recovered-components-x2184):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Reclaimed Shelter — Assembly Check</title>
<style>
:root {
--bg: #e7ebe4;
--paper: #f7f8f3;
--paper-strong: #ffffff;
--ink: #192620;
--muted: #68736d;
--line: #d9ded7;
--green: #28624f;
--green-soft: #e1eee7;
--orange: #bf673e;
--orange-soft: #f5e7de;
--red: #c84d39;
--red-soft: #f8e2de;
--shadow: 0 18px 48px rgba(29, 44, 36, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: grid;
grid-template-columns: minmax(0, 1fr) 370px;
width: 100%;
height: 100vh;
}
#stage {
position: relative;
min-width: 0;
overflow: hidden;
isolation: isolate;
background:
radial-gradient(circle at 38% 30%, rgba(255, 255, 255, 0.85), transparent 42%),
var(--bg);
}
#stage canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
.topbar {
position: absolute;
z-index: 10;
top: 20px;
left: 22px;
right: 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.brand,
.top-actions {
pointer-events: auto;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 42px;
height: 42px;
flex: 0 0 auto;
border: 1px solid rgba(25, 38, 32, 0.22);
border-radius: 12px;
background: rgba(247, 248, 243, 0.82);
box-shadow: 0 8px 20px rgba(29, 44, 36, 0.08);
backdrop-filter: blur(12px);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--green);
}
.brand-mark::before {
left: 10px;
right: 10px;
top: 15px;
height: 3px;
transform: skewY(-13deg);
}
.brand-mark::after {
left: 12px;
right: 12px;
top: 25px;
height: 3px;
transform: skewY(13deg);
opacity: 0.48;
}
.brand-title {
margin: 0;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.brand-subtitle {
margin: 3px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.04em;
}
.top-actions {
display: flex;
align-items: center;
gap: 9px;
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 7px;
height: 35px;
padding: 0 12px;
border: 1px solid rgba(25, 38, 32, 0.13);
border-radius: 999px;
background: rgba(247, 248, 243, 0.78);
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.status-pill::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(40, 98, 79, 0.12);
}
.button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 37px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--paper-strong);
box-shadow: 0 4px 12px rgba(29, 44, 36, 0.05);
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
opacity 160ms ease;
}
.button:hover {
transform: translateY(-1px);
border-color: #b9c5bc;
}
.button:active {
transform: translateY(0);
}
.button.primary {
border-color: var(--green);
background: var(--green);
color: white;
}
.button.primary:hover {
background: #205440;
}
.button:disabled {
cursor: default;
opacity: 0.45;
transform: none;
}
.viewer-title {
position: absolute;
z-index: 4;
top: 92px;
left: 26px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 8px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.viewer-title h1 {
margin: 0;
font-size: clamp(27px, 3.4vw, 48px);
font-weight: 780;
letter-spacing: -0.045em;
line-height: 0.98;
}
.viewer-title p:last-child {
margin: 11px 0 0;
color: var(--muted);
font-size: 12px;
}
.summary-pills {
position: absolute;
z-index: 4;
left: 26px;
bottom: 82px;
display: flex;
flex-wrap: wrap;
gap: 7px;
max-width: calc(100% - 190px);
pointer-events: none;
}
.summary-pill {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 31px;
padding: 0 10px;
border: 1px solid rgba(25, 38, 32, 0.12);
border-radius: 9px;
background: rgba(247, 248, 243, 0.82);
color: var(--muted);
font-size: 10px;
font-weight: 760;
letter-spacing: 0.04em;
backdrop-filter: blur(12px);
}
.summary-pill strong {
color: var(--ink);
font-size: 11px;
}
.summary-pill.bad strong {
color: var(--red);
}
.summary-pill.good strong {
color: var(--green);
}
.toolbar {
position: absolute;
z-index: 7;
right: 20px;
bottom: 20px;
display: flex;
gap: 6px;
padding: 6px;
border: 1px solid rgba(25, 38, 32, 0.13);
border-radius: 14px;
background: rgba(247, 248, 243, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.tool-button {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border: 0;
border-radius: 9px;
background: transparent;
cursor: pointer;
transition: background 160ms ease, color 160ms ease;
}
.tool-button:hover {
background: rgba(40, 98, 79, 0.09);
}
.tool-button.active {
color: white;
background: var(--green);
}
.tool-button svg {
width: 18px;
height: 18px;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.help {
position: absolute;
z-index: 4;
left: 26px;
bottom: 26px;
color: rgba(25, 38, 32, 0.56);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.025em;
pointer-events: none;
}
#labels {
position: absolute;
z-index: 3;
inset: 0;
pointer-events: none;
transition: opacity 160ms ease;
}
#labels.hidden {
opacity: 0;
}
.dimension-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
padding: 5px 8px;
border: 1px solid rgba(25, 38, 32, 0.12);
border-radius: 7px;
background: rgba(247, 248, 243, 0.9);
box-shadow: 0 5px 14px rgba(29, 44, 36, 0.08);
color: var(--ink);
font-size: 10px;
font-weight: 820;
letter-spacing: 0.04em;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.dimension-label.bad {
border-color: rgba(200, 77, 57, 0.4);
color: var(--red);
}
.toast {
position: absolute;
z-index: 20;
left: 50%;
bottom: 24px;
transform: translate(-50%, 20px);
padding: 10px 14px;
border-radius: 10px;
background: var(--ink);
color: white;
box-shadow: var(--shadow);
font-size: 12px;
font-weight: 700;
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.panel {
position: relative;
z-index: 12;
overflow-y: auto;
border-left: 1px solid rgba(25, 38, 32, 0.1);
background: var(--paper);
box-shadow: -14px 0 40px rgba(29, 44, 36, 0.07);
scrollbar-width: thin;
scrollbar-color: #c4cdc5 transparent;
}
.panel-header {
position: sticky;
z-index: 4;
top: 0;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 20px 20px 16px;
border-bottom: 1px solid var(--line);
background: rgba(247, 248, 243, 0.94);
backdrop-filter: blur(12px);
}
.panel-header h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.025em;
}
.panel-header p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
}
.status-badge {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 58px;
height: 25px;
padding: 0 8px;
border-radius: 999px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.status-badge.good {
color: var(--green);
background: var(--green-soft);
}
.status-badge.bad {
color: var(--red);
background: var(--red-soft);
}
.check-section {
padding: 18px 20px;
border-bottom: 1px solid var(--line);
transition: background 180ms ease;
}
.check-section.flash {
background: #edf5ef;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.section-heading h3 {
margin: 0;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-number {
margin-right: 7px;
color: var(--muted);
font-weight: 650;
}
.text-button {
padding: 0;
border: 0;
background: transparent;
color: var(--green);
font-size: 11px;
font-weight: 800;
cursor: pointer;
}
.text-button:hover {
text-decoration: underline;
}
.dimension-summary {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 13px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--paper-strong);
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.dimension-summary .dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--green);
}
.dimension-summary.bad {
border-color: rgba(200, 77, 57, 0.24);
color: #8e4133;
background: var(--red-soft);
}
.dimension-summary.bad .dot {
background: var(--red);
}
.metric-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
min-height: 39px;
border-bottom: 1px solid #e7ebe5;
}
.metric-row:last-of-type {
border-bottom: 0;
}
.metric-name {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
}
.metric-name i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--green);
}
.metric-row.bad .metric-name i {
background: var(--red);
}
.metric-value {
display: flex;
align-items: baseline;
gap: 4px;
white-space: nowrap;
}
.metric-value b {
font-size: 12px;
}
.metric-value small {
color: var(--muted);
font-size: 9px;
}
.slider-control {
margin-top: 13px;
}
.slider-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.slider-label output {
color: var(--ink);
font-weight: 820;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 999px;
appearance: none;
background: #d9dfd8;
cursor: pointer;
accent-color: var(--green);
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid var(--paper);
border-radius: 50%;
appearance: none;
background: var(--green);
box-shadow: 0 0 0 1px var(--green);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid var(--paper);
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 1px var(--green);
}
.progress-track {
height: 6px;
overflow: hidden;
border-radius: 999px;
background: #e0e5df;
}
.progress-bar {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--green);
transition: width 280ms ease, background 280ms ease;
}
.progress-bar.bad {
background: var(--orange);
}
.connection-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 38px;
border-bottom: 1px solid #e7ebe5;
font-size: 11px;
}
.connection-row:last-of-type {
border-bottom: 0;
}
.connection-name {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-weight: 650;
}
.connection-name i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
}
.connection-name i.missing {
background: var(--red);
}
.connection-count {
color: var(--ink);
font-weight: 800;
}
.connection-count em {
margin-left: 4px;
color: var(--red);
font-size: 9px;
font-style: normal;
font-weight: 800;
text-transform: uppercase;
}
.connection-message {
margin: 11px 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.install-button {
width: 100%;
margin-top: 11px;
}
.inventory-table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
.inventory-table th {
padding: 0 0 8px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.11em;
text-align: right;
text-transform: uppercase;
}
.inventory-table th:first-child {
text-align: left;
}
.inventory-table td {
padding: 9px 0;
border-top: 1px solid #e7ebe5;
text-align: right;
font-weight: 750;
}
.inventory-table td:first-child {
text-align: left;
}
.part-name {
display: block;
color: var(--ink);
font-size: 10px;
font-weight: 780;
}
.part-spec {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 550;
}
.stock-number {
color: var(--green);
font-weight: 850;
}
.stock-number.short {
color: var(--red);
}
.stock-summary {
margin: 12px 0 0;
padding: 10px 11px;
border-radius: 9px;
background: var(--green-soft);
color: var(--green);
font-size: 10px;
font-weight: 750;
line-height: 1.5;
}
.stock-summary.short {
background: var(--red-soft);
color: #8e4133;
}
.panel-footer {
padding: 15px 20px 22px;
color: var(--muted);
font-size: 9px;
line-height: 1.55;
}
@media (max-width: 900px) {
body {
overflow: auto;
}
#app {
display: block;
height: auto;
}
#stage {
height: 68vh;
min-height: 520px;
}
.panel {
overflow: visible;
border-top: 1px solid rgba(25, 38, 32, 0.1);
border-left: 0;
}
.panel-header {
position: relative;
}
}
@media (max-width: 600px) {
#stage {
height: 62vh;
min-height: 460px;
}
.topbar {
top: 13px;
left: 13px;
right: 13px;
}
.brand-subtitle,
.status-pill {
display: none;
}
.brand-mark {
width: 38px;
height: 38px;
}
.brand-title {
font-size: 11px;
}
.viewer-title {
top: 72px;
left: 16px;
}
.viewer-title h1 {
font-size: 30px;
}
.summary-pills {
left: 14px;
bottom: 72px;
max-width: calc(100% - 28px);
}
.help {
left: 15px;
bottom: 16px;
}
.toolbar {
right: 12px;
bottom: 12px;
}
.tool-button {
width: 34px;
height: 34px;
}
.toast {
bottom: 60px;
width: max-content;
max-width: calc(100% - 24px);
text-align: center;
}
}
</style>
</head>
<body>
<div id="app">
<main id="stage">
<div id="labels">
<div class="dimension-label" id="labelWidth">4800 mm</div>
<div class="dimension-label" id="labelDepth">3600 mm</div>
<div class="dimension-label" id="labelHeight">2700 mm</div>
</div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="brand-title">Reclaim / Field Office</p>
<p class="brand-subtitle">Assembly system · Shelter 04</p>
</div>
</div>
<div class="top-actions">
<span class="status-pill">Live model</span>
<button class="button" id="exportBtn" type="button">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true">
<path d="M12 3v12m0 0 4-4m-4 4-4-4M5 19h14"/>
</svg>
Export check
</button>
</div>
</header>
<div class="viewer-title">
<p class="eyebrow">Courtyard / 04</p>
<h1>Reclaimed shelter</h1>
<p id="modelSubtitle">Schematic assembly · 4.8 × 3.6 × 2.7 m</p>
</div>
<div class="summary-pills">
<div class="summary-pill" id="summaryFitPill">
<strong id="summaryFit">Within stock</strong> dimensions
</div>
<div class="summary-pill" id="summaryIssuesPill">
<strong id="summaryIssues">8 missing</strong> connections
</div>
<div class="summary-pill">
<strong id="summaryStock">18</strong> parts left
</div>
</div>
<div class="help">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<div class="toolbar" aria-label="View controls">
<button class="tool-button" id="fitBtn" type="button" title="Fit model in view" aria-label="Fit model in view">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M8 3H3v5M16 3h5v5M21 16v5h-5M8 21H3v-5"/>
<circle cx="12" cy="12" r="3"/>
</svg>
</button>
<button class="tool-button" id="explodeBtn" type="button" title="Toggle exploded view" aria-label="Toggle exploded view" aria-pressed="false">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="m12 3 8 4-8 4-8-4 8-4Z"/>
<path d="m4 12 8 4 8-4M4 17l8 4 8-4"/>
</svg>
</button>
<button class="tool-button active" id="labelsBtn" type="button" title="Toggle dimensions" aria-label="Toggle dimensions" aria-pressed="true">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 7h16M4 17h16M8 4v6M16 14v6"/>
<path d="m8 7 3 3-3 3M16 14l-3 3 3 3"/>
</svg>
</button>
<button class="tool-button active" id="issuesBtn" type="button" title="Toggle missing connections" aria-label="Toggle missing connections" aria-pressed="true">
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="12" cy="12" r="8"/>
<path d="M12 8v5M12 16.5v.5"/>
</svg>
</button>
</div>
<div class="toast" id="toast" role="status"></div>
</main>
<aside class="panel">
<div class="panel-header">
<div>
<h2>Assembly check</h2>
<p>Shelter 04 · Reclaimed inventory</p>
</div>
<button class="text-button" id="checkBtn" type="button">Run check</button>
</div>
<section class="check-section" id="dimensionSection">
<div class="section-heading">
<h3><span class="section-number">01</span> Dimensions</h3>
<span class="status-badge good" id="fitBadge">Pass</span>
</div>
<div class="dimension-summary" id="dimensionSummary">
<span class="dot"></span>
<span id="dimensionMessage">All primary members clear the available stock lengths.</span>
</div>
<div class="metric-row" id="widthMetric">
<span class="metric-name"><i></i>Clear span</span>
<span class="metric-value">
<b id="widthValue">4800</b>
<small>/ 4800 mm</small>
</span>
</div>
<div class="metric-row" id="depthMetric">
<span class="metric-name"><i></i>Frame depth</span>
<span class="metric-value">
<b id="depthValue">3600</b>
<small>/ 3800 mm</small>
</span>
</div>
<div class="metric-row" id="heightMetric">
<span class="metric-name"><i></i>Post height</span>
<span class="metric-value">
<b id="heightValue">2700</b>
<small>/ 3000 mm</small>
</span>
</div>
<div class="slider-control">
<label class="slider-label" for="widthInput">
<span>Target clear span</span>
<output id="widthOut">4.8 m</output>
</label>
<input id="widthInput" type="range" min="3.2" max="5.8" step="0.1" value="4.8">
</div>
<div class="slider-control">
<label class="slider-label" for="depthInput">
<span>Target frame depth</span>
<output id="depthOut">3.6 m</output>
</label>
<input id="depthInput" type="range" min="2.4" max="4.8" step="0.1" value="3.6">
</div>
<div class="slider-control">
<label class="slider-label" for="heightInput">
<span>Target post height</span>
<output id="heightOut">2.7 m</output>
</label>
<input id="heightInput" type="range" min="2.2" max="3.6" step="0.1" value="2.7">
</div>
</section>
<section class="check-section" id="connectionSection">
<div class="section-heading">
<h3><span class="section-number">02</span> Connections</h3>
<span class="status-badge bad" id="connectionBadge">8 missing</span>
</div>
<div class="progress-track" aria-label="Connection completion">
<div class="progress-bar bad" id="connectionBar"></div>
</div>
<div class="connection-row">
<span class="connection-name"><i></i>Base anchors</span>
<span class="connection-count">4 / 4</span>
</div>
<div class="connection-row">
<span class="connection-name"><i class="missing"></i>Frame brackets</span>
<span class="connection-count" id="bracketCount">8 / 10 <em>2 missing</em></span>
</div>
<div class="connection-row">
<span class="connection-name"><i class="missing"></i>M10 fasteners</span>
<span class="connection-count" id="boltCount">18 / 24 <em>6 missing</em></span>
</div>
<p class="connection-message" id="connectionMessage">
Two corner brackets and six M10 fasteners are not yet connected.
</p>
<button class="button primary install-button" id="installBtn" type="button">
Install 8 available fittings
</button>
</section>
<section class="check-section" id="inventorySection">
<div class="section-heading">
<h3><span class="section-number">03</span> Remaining inventory</h3>
<span class="status-badge good" id="inventoryBadge">18 left</span>
</div>
<table class="inventory-table">
<thead>
<tr>
<th>Reclaimed part</th>
<th>In use</th>
<th>Left</th>
</tr>
</thead>
<tbody id="inventoryBody"></tbody>
</table>
<div class="stock-summary" id="stockSummary">
18 usable pieces remain. Eight are reserved for the unresolved connections.
</div>
</section>
<div class="panel-footer">
Schematic dimensions are nominal. Verify reclaimed members, connector condition,
ground bearing, and local wind and site requirements before assembly.
</div>
</aside>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const stage = $("stage");
const state = {
width: 4.8,
depth: 3.6,
height: 2.7,
missingBrackets: 2,
missingBolts: 6,
showIssues: true,
showLabels: true,
exploded: false,
explodeAmount: 0
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7ebe4);
scene.fog = new THREE.Fog(0xe7ebe4, 14, 29);
const camera = new THREE.PerspectiveCamera(
40,
stage.clientWidth / stage.clientHeight,
0.05,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
stage.insertBefore(renderer.domElement, stage.firstChild);
const hemisphere = new THREE.HemisphereLight(0xf5fbff, 0x71806f, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff7e8, 3.3);
keyLight.position.set(6, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d8d4, 1.15);
fillLight.position.set(-7, 5, -5);
scene.add(fillLight);
const materials = {
wood: new THREE.MeshStandardMaterial({
color: 0x9c704a,
roughness: 0.88,
flatShading: true
}),
woodLight: new THREE.MeshStandardMaterial({
color: 0xc39a69,
roughness: 0.9,
flatShading: true
}),
woodDark: new THREE.MeshStandardMaterial({
color: 0x654936,
roughness: 0.92,
flatShading: true
}),
woodEnd: new THREE.MeshStandardMaterial({
color: 0x7e593c,
roughness: 0.94,
flatShading: true
}),
steel: new THREE.MeshStandardMaterial({
color: 0x3d5b59,
roughness: 0.58,
metalness: 0.28,
flatShading: true
}),
steelDark: new THREE.MeshStandardMaterial({
color: 0x263d3d,
roughness: 0.52,
metalness: 0.38,
flatShading: true
}),
sheet: new THREE.MeshStandardMaterial({
color: 0x7f9189,
roughness: 0.76,
metalness: 0.08,
flatShading: true
}),
sheetLight: new THREE.MeshStandardMaterial({
color: 0x9aa79e,
roughness: 0.8,
flatShading: true
}),
issue: new THREE.MeshStandardMaterial({
color: 0xe2573e,
emissive: 0x6b1008,
emissiveIntensity: 0.7,
roughness: 0.48,
flatShading: true
}),
concrete: new THREE.MeshStandardMaterial({
color: 0xd8ddd5,
roughness: 0.96,
flatShading: true
})
};
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x26352e,
transparent: true,
opacity: 0.24
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xe1e6de,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(28, 28, 0x8f9d93, 0xaab5ac);
grid.position.y = 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
const pad = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), materials.concrete);
pad.receiveShadow = true;
scene.add(pad);
let shelterRoot = null;
let partsGroup = null;
let issuesGroup = null;
let dimensionRoot = null;
const labelPositions = {
width: new THREE.Vector3(),
depth: new THREE.Vector3(),
height: new THREE.Vector3()
};
const cameraControl = {
target: new THREE.Vector3(0, 1.1, 0),
radius: 10,
theta: 0.72,
phi: 1.05,
pointer: null
};
function disposeGroup(group) {
if (!group) return;
group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
group.clear();
}
function addBox(parent, size, position, material, options = {}) {
const geometry = new THREE.BoxGeometry(...size);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
mesh.userData.basePosition = mesh.position.clone();
mesh.userData.explode = new THREE.Vector3(...(options.explode || [0, 0, 0]));
parent.add(mesh);
if (options.edges !== false) {
const edgeGeometry = new THREE.EdgesGeometry(geometry, 28);
const edges = new THREE.LineSegments(edgeGeometry, edgeMaterial);
mesh.add(edges);
}
return mesh;
}
function addCylinder(parent, radius, length, position, material, options = {}) {
const geometry = new THREE.CylinderGeometry(radius, radius, length, 6);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
if (options.rotation) mesh.rotation.set(...options.rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.basePosition = mesh.position.clone();
mesh.userData.explode = new THREE.Vector3(...(options.explode || [0, 0, 0]));
parent.add(mesh);
return mesh;
}
function addIssueMarker(position, explode, phase) {
const marker = new THREE.Group();
marker.position.set(...position);
marker.userData.isIssue = true;
marker.userData.phase = phase;
marker.userData.basePosition = marker.position.clone();
marker.userData.explode = new THREE.Vector3(...explode);
const core = new THREE.Mesh(
new THREE.OctahedronGeometry(0.065, 0),
materials.issue
);
core.castShadow = true;
marker.add(core);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.12, 0.013, 5, 18),
materials.issue
);
ring.rotation.x = Math.PI / 2;
marker.add(ring);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.008, 0.008, 0.28, 5),
materials.issue
);
stem.position.y = 0.15;
marker.add(stem);
issuesGroup.add(marker);
}
function createDimensionLines() {
if (dimensionRoot) {
scene.remove(dimensionRoot);
disposeGroup(dimensionRoot);
}
dimensionRoot = new THREE.Group();
scene.add(dimensionRoot);
const W = state.width;
const D = state.depth;
const H = state.height;
const widthPass = W >= 3.6 && W <= 4.8;
const depthPass = D >= 2.8 && D <= 3.8;
const heightPass = H >= 2.4 && H <= 3.0;
const widthColor = widthPass ? 0x28624f : 0xc84d39;
const depthColor = depthPass ? 0x28624f : 0xc84d39;
const heightColor = heightPass ? 0x28624f : 0xc84d39;
function line(points, color) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(...point))
);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.86
});
const object = new THREE.LineSegments(geometry, material);
dimensionRoot.add(object);
}
const wz = D / 2 + 0.67;
line([
[-W / 2, 0.035, wz], [W / 2, 0.035, wz],
[-W / 2, 0.035, wz - 0.13], [-W / 2, 0.035, wz + 0.13],
[W / 2, 0.035, wz - 0.13], [W / 2, 0.035, wz + 0.13]
], widthColor);
const dx = W / 2 + 0.67;
line([
[dx, 0.035, -D / 2], [dx, 0.035, D / 2],
[dx - 0.13, 0.035, -D / 2], [dx + 0.13, 0.035, -D / 2],
[dx - 0.13, 0.035, D / 2], [dx + 0.13, 0.035, D / 2]
], depthColor);
const hx = -W / 2 - 0.54;
const hz = -D / 2;
line([
[hx, 0.04, hz], [hx, H, hz],
[hx - 0.12, 0.04, hz], [hx + 0.12, 0.04, hz],
[hx - 0.12, H, hz], [hx + 0.12, H, hz]
], heightColor);
labelPositions.width.set(0, 0.12, wz);
labelPositions.depth.set(dx, 0.12, 0);
labelPositions.height.set(hx, H / 2, hz);
$("labelWidth").textContent = `${Math.round(W * 1000)} mm`;
$("labelDepth").textContent = `${Math.round(D * 1000)} mm`;
$("labelHeight").textContent = `${Math.round(H * 1000)} mm`;
$("labelWidth").classList.toggle("bad", !widthPass);
$("labelDepth").classList.toggle("bad", !depthPass);
$("labelHeight").classList.toggle("bad", !heightPass);
}
function buildShelter() {
if (shelterRoot) {
scene.remove(shelterRoot);
disposeGroup(shelterRoot);
}
shelterRoot = new THREE.Group();
partsGroup = new THREE.Group();
issuesGroup = new THREE.Group();
shelterRoot.add(partsGroup, issuesGroup);
scene.add(shelterRoot);
const W = state.width;
const D = state.depth;
const H = state.height;
pad.scale.set(W + 1.35, 0.055, D + 1.35);
pad.position.set(0, 0.027, 0);
const corners = [
[-W / 2, -D / 2],
[W / 2, -D / 2],
[-W / 2, D / 2],
[W / 2, D / 2]
];
// Reclaimed pallet cradles at each corner.
for (const [x, z] of corners) {
addBox(
partsGroup,
[0.74, 0.10, 0.74],
[x, 0.09, z],
materials.woodDark,
{ explode: [0, -0.08, 0] }
);
for (const offset of [-0.23, 0, 0.23]) {
addBox(
partsGroup,
[0.74, 0.045, 0.14],
[x, 0.16, z + offset],
materials.wood,
{ explode: [0, -0.08, 0] }
);
}
}
// Four vertical posts.
const postBottom = 0.22;
const postHeight = H - postBottom;
for (const [x, z] of corners) {
addBox(
partsGroup,
[0.14, postHeight, 0.14],
[x, postBottom + postHeight / 2, z],
materials.wood,
{
explode: [
Math.sign(x) * 0.48,
0.12,
Math.sign(z) * 0.28
]
}
);
}
// Three cross beams and two side rails.
for (const z of [-D / 2, 0, D / 2]) {
addBox(
partsGroup,
[W + 0.28, 0.16, 0.12],
[0, H + 0.08, z],
materials.woodDark,
{ explode: [0, 0.2, Math.sign(z || 1) * 0.34] }
);
}
for (const x of [-W / 2, W / 2]) {
addBox(
partsGroup,
[0.12, 0.16, D + 0.28],
[x, H + 0.08, 0],
materials.woodDark,
{ explode: [Math.sign(x) * 0.44, 0.2, 0] }
);
}
// Reclaimed pallet roof panels.
const roofColumns = Math.ceil(W / 1.6);
const roofRows = Math.ceil(D / 1.2);
const panelWidth = Math.min(1.6, W / roofColumns);
const panelDepth = Math.min(1.2, D / roofRows);
for (let row = 0; row < roofRows; row++) {
for (let column = 0; column < roofColumns; column++) {
const x = -W / 2 + (column + 0.5) * (W / roofColumns);
const z = -D / 2 + (row + 0.5) * (D / roofRows);
addBox(
partsGroup,
[Math.max(0.2, panelWidth - 0.025), 0.07, Math.max(0.2, panelDepth - 0.025)],
[x, H + 0.205, z],
(row + column) % 2 ? materials.woodLight : materials.wood,
{ explode: [0, 1.15, 0] }
);
for (const strip of [-0.31, 0.31]) {
addBox(
partsGroup,
[Math.max(0.15, panelWidth * 0.82), 0.012, 0.012],
[x, H + 0.246, z + strip * panelDepth],
materials.woodEnd,
{
edges: false,
explode: [0, 1.15, 0]
}
);
}
}
}
// Four reclaimed sheet panels: two at the rear and two along the left side.
const rearSheetWidth = Math.min(1.8, (W - 0.28) / 2);
const sideSheetDepth = Math.min(1.2, (D - 0.28) / 2);
const wallHeight = 1.25;
const wallCenter = 0.22 + wallHeight / 2;
for (const side of [-1, 1]) {
addBox(
partsGroup,
[rearSheetWidth, wallHeight, 0.045],
[side * (rearSheetWidth / 2 + 0.07), wallCenter, -D / 2 + 0.025],
side < 0 ? materials.sheet : materials.sheetLight,
{ explode: [0, 0.1, -0.72] }
);
}
for (const side of [-1, 1]) {
addBox(
partsGroup,
[0.045, wallHeight, sideSheetDepth],
[-W / 2 + 0.025, wallCenter, side * (sideSheetDepth / 2 + 0.07)],
side < 0 ? materials.sheetLight : materials.sheet,
{ explode: [-0.72, 0.1, 0] }
);
}
// Installed L-brackets at the frame corners and mid-span joints.
const bracketLocations = [
[-W / 2, H + 0.02, -D / 2],
[W / 2, H + 0.02, -D / 2],
[-W / 2, H + 0.02, D / 2],
[W / 2, H + 0.02, D / 2],
[-W / 2, H + 0.02, 0],
[W / 2, H + 0.02, 0]
];
for (const [x, y, z] of bracketLocations) {
addBox(
partsGroup,
[0.19, 0.055, 0.065],
[x, y, z],
materials.steel,
{ explode: [Math.sign(x || 1) * 0.18, 0.32, Math.sign(z || 1) * 0.15] }
);
addBox(
partsGroup,
[0.065, 0.19, 0.065],
[x, y - 0.07, z],
materials.steel,
{ explode: [Math.sign(x || 1) * 0.18, 0.32, Math.sign(z || 1) * 0.15] }
);
}
// A selection of installed bolts, including the visible front and rear joints.
const boltPositions = [];
for (const [x, z] of corners) {
boltPositions.push([x, 0.24, z + (z > 0 ? 0.09 : -0.09)]);
boltPositions.push([x, H - 0.12, z + (z > 0 ? 0.09 : -0.09)]);
}
for (const z of [-D / 2, 0, D / 2]) {
boltPositions.push([-W / 2 - 0.09, H + 0.08, z]);
boltPositions.push([W / 2 + 0.09, H + 0.08, z]);
}
for (const z of [-D / 2, D / 2]) {
boltPositions.push([-W / 2 - 0.09, 0.65, z]);
boltPositions.push([W / 2 + 0.09, 0.65, z]);
}
for (const [x, y, z] of boltPositions.slice(0, 18)) {
addCylinder(
partsGroup,
0.028,
0.03,
[x, y, z],
materials.steelDark,
{
rotation: [Math.PI / 2, 0, 0],
explode: [Math.sign(x || 1) * 0.13, 0.18, Math.sign(z || 1) * 0.1]
}
);
}
// Missing brackets.
if (state.missingBrackets > 0) {
addIssueMarker(
[-W / 2, H + 0.04, D / 2],
[-0.18, 0.55, 0.15],
0
);
addIssueMarker(
[W / 2, H + 0.04, -D / 2],
[0.18, 0.55, -0.15],
1.2
);
}
// Missing M10 fasteners.
if (state.missingBolts > 0) {
const missingPositions = [
[-W / 2, 0.43, D / 2 + 0.13],
[W / 2, 0.43, D / 2 + 0.13],
[-W / 2, H - 0.1, D / 2 + 0.13],
[W / 2, H - 0.1, D / 2 + 0.13],
[-W / 2, 0.7, -D / 2 - 0.1],
[W / 2, 0.7, -D / 2 - 0.1]
];
missingPositions.forEach((position, index) => {
addIssueMarker(
position,
[Math.sign(position[0] || 1) * 0.18, 0.24, Math.sign(position[2] || 1) * 0.16],
index * 0.55
);
});
}
issuesGroup.visible = state.showIssues;
createDimensionLines();
}
function getDimensionChecks() {
return [
{
key: "width",
value: state.width,
min: 3.6,
max: 4.8,
label: "Clear span",
stock: "4800 mm"
},
{
key: "depth",
value: state.depth,
min: 2.8,
max: 3.8,
label: "Frame depth",
stock: "3800 mm"
},
{
key: "height",
value: state.height,
min: 2.4,
max: 3.0,
label: "Post height",
stock: "3000 mm"
}
];
}
function getInventory() {
const roofRequired = Math.ceil(state.width / 1.6) * Math.ceil(state.depth / 1.2);
return [
{
name: "Ridge posts",
spec: "3000 × 120 × 120 mm",
total: 6,
used: 4
},
{
name: "Cross beams",
spec: "4800 × 140 × 90 mm",
total: 4,
used: 3
},
{
name: "Side rails",
spec: "3800 × 100 × 80 mm",
total: 4,
used: 2
},
{
name: "Roof pallet panels",
spec: "1600 × 1200 × 25 mm",
total: 12,
used: roofRequired
},
{
name: "Wall sheets",
spec: "1800 × 1200 × 4 mm",
total: 6,
used: 4
},
{
name: "Pallet cradles",
spec: "1200 × 800 × 180 mm",
total: 4,
used: 4
},
{
name: "Corner brackets",
spec: "180 × 90 mm",
total: 10,
used: 10 - state.missingBrackets
},
{
name: "M10 bolt sets",
spec: "M10 × 70 mm",
total: 24,
used: 24 - state.missingBolts
}
];
}
function updateUI() {
const checks = getDimensionChecks();
const allPass = checks.every((check) => check.value >= check.min && check.value <= check.max);
$("widthOut").textContent = `${state.width.toFixed(1)} m`;
$("depthOut").textContent = `${state.depth.toFixed(1)} m`;
$("heightOut").textContent = `${state.height.toFixed(1)} m`;
$("widthValue").textContent = Math.round(state.width * 1000);
$("depthValue").textContent = Math.round(state.depth * 1000);
$("heightValue").textContent = Math.round(state.height * 1000);
for (const check of checks) {
const pass = check.value >= check.min && check.value <= check.max;
$(`${check.key}Metric`).classList.toggle("bad", !pass);
}
$("fitBadge").textContent = allPass ? "Pass" : "Review";
$("fitBadge").className = `status-badge ${allPass ? "good" : "bad"}`;
$("dimensionSummary").classList.toggle("bad", !allPass);
const failures = [];
for (const check of checks) {
if (check.value > check.max) {
failures.push(
`${check.label} exceeds ${check.stock} by ${Math.round((check.value - check.max) * 1000)} mm`
);
} else if (check.value < check.min) {
failures.push(`${check.label} is below the ${Math.round(check.min * 1000)} mm design minimum`);
}
}
$("dimensionMessage").textContent = allPass
? "All primary members clear the available stock lengths."
: failures.join(". ") + ".";
$("summaryFit").textContent = allPass ? "Within stock" : "Outside stock";
$("summaryFitPill").className = `summary-pill ${allPass ? "good" : "bad"}`;
$("modelSubtitle").textContent =
`Schematic assembly · ${state.width.toFixed(1)} × ${state.depth.toFixed(1)} × ${state.height.toFixed(1)} m`;
const missing = state.missingBrackets + state.missingBolts;
const bracketInstalled = 10 - state.missingBrackets;
const boltsInstalled = 24 - state.missingBolts;
const completion = ((bracketInstalled + boltsInstalled) / 34) * 100;
$("connectionBadge").textContent = missing ? `${missing} missing` : "Complete";
$("connectionBadge").className = `status-badge ${missing ? "bad" : "good"}`;
$("connectionBar").style.width = `${completion}%`;
$("connectionBar").classList.toggle("bad", missing > 0);
$("bracketCount").innerHTML = missing
? `${bracketInstalled} / 10 <em>${state.missingBrackets} missing</em>`
: "10 / 10";
$("boltCount").innerHTML = missing
? `${boltsInstalled} / 24 <em>${state.missingBolts} missing</em>`
: "24 / 24";
$("connectionMessage").textContent = missing
? `${state.missingBrackets} corner bracket${state.missingBrackets === 1 ? "" : "s"} and ${state.missingBolts} M10 fastener${state.missingBolts === 1 ? "" : "s"} are not yet connected.`
: "All base anchors, frame brackets, and M10 fasteners are installed.";
$("installBtn").disabled = missing === 0;
$("installBtn").textContent = missing
? `Install ${missing} available fitting${missing === 1 ? "" : "s"}`
: "All fittings installed";
$("summaryIssues").textContent = missing ? `${missing} missing` : "0 missing";
$("summaryIssuesPill").className = `summary-pill ${missing ? "bad" : "good"}`;
const inventory = getInventory();
let remaining = 0;
let shortage = 0;
$("inventoryBody").innerHTML = inventory.map((item) => {
const left = Math.max(0, item.total - item.used);
remaining += left;
shortage += Math.max(0, item.used - item.total);
const usedClass = item.used > item.total ? "stock-number short" : "";
const leftClass = left === 0 ? "stock-number" : "stock-number";
return `
<tr>
<td>
<span class="part-name">${item.name}</span>
<span class="part-spec">${item.spec}</span>
</td>
<td class="${usedClass}">${item.used}</td>
<td class="${leftClass}">${left}</td>
</tr>
`;
}).join("");
$("inventoryBadge").textContent = `${remaining} left`;
$("summaryStock").textContent = remaining;
const stockSummary = $("stockSummary");
stockSummary.classList.toggle("short", shortage > 0);
if (shortage > 0) {
stockSummary.textContent =
`${remaining} usable pieces remain, but the target dimensions require ${shortage} additional roof panels.`;
} else if (missing > 0) {
stockSummary.textContent =
`${remaining} usable pieces remain. ${missing} are reserved for the unresolved connections.`;
} else {
stockSummary.textContent =
`${remaining} usable pieces remain after completing all ${missing === 0 ? "known" : "scheduled"} connections.`;
}
}
function updateCamera() {
const spherical = new THREE.Spherical(
cameraControl.radius,
cameraControl.phi,
cameraControl.theta
);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(cameraControl.target).add(offset);
camera.lookAt(cameraControl.target);
}
function fitView() {
cameraControl.target.set(0, state.height * 0.42, 0);
cameraControl.radius = Math.max(
state.width * 1.45,
state.depth * 1.8,
state.height * 2.8
) + 2.2;
cameraControl.theta = 0.72;
cameraControl.phi = 1.05;
updateCamera();
}
function showToast(message) {
const toast = $("toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(showToast.timeout);
showToast.timeout = setTimeout(() => toast.classList.remove("show"), 2400);
}
function handleDimensionInput() {
state.width = Number($("widthInput").value);
state.depth = Number($("depthInput").value);
state.height = Number($("heightInput").value);
buildShelter();
updateUI();
}
$("widthInput").addEventListener("input", handleDimensionInput);
$("depthInput").addEventListener("input", handleDimensionInput);
$("heightInput").addEventListener("input", handleDimensionInput);
$("fitBtn").addEventListener("click", fitView);
$("explodeBtn").addEventListener("click", () => {
state.exploded = !state.exploded;
$("explodeBtn").classList.toggle("active", state.exploded);
$("explodeBtn").setAttribute("aria-pressed", String(state.exploded));
});
$("labelsBtn").addEventListener("click", () => {
state.showLabels = !state.showLabels;
$("labels").classList.toggle("hidden", !state.showLabels);
$("labelsBtn").classList.toggle("active", state.showLabels);
$("labelsBtn").setAttribute("aria-pressed", String(state.showLabels));
});
$("issuesBtn").addEventListener("click", () => {
state.showIssues = !state.showIssues;
if (issuesGroup) issuesGroup.visible = state.showIssues;
$("issuesBtn").classList.toggle("active", state.showIssues);
$("issuesBtn").setAttribute("aria-pressed", String(state.showIssues));
});
$("installBtn").addEventListener("click", () => {
const installed = state.missingBrackets + state.missingBolts;
if (!installed) return;
state.missingBrackets = 0;
state.missingBolts = 0;
buildShelter();
updateUI();
showToast(`${installed} reclaimed fittings installed — connections complete.`);
});
$("checkBtn").addEventListener("click", () => {
document.querySelectorAll(".check-section").forEach((section) => {
section.classList.add("flash");
});
setTimeout(() => {
document.querySelectorAll(".check-section").forEach((section) => {
section.classList.remove("flash");
});
}, 650);
showToast("Assembly check complete.");
});
$("exportBtn").addEventListener("click", () => {
const checks = getDimensionChecks().map((check) => ({
...check,
pass: check.value >= check.min && check.value <= check.max
}));
const report = {
project: "Reclaimed courtyard shelter 04",
generatedAt: new Date().toISOString(),
dimensionsMeters: {
width: state.width,
depth: state.depth,
height: state.height
},
dimensionChecks: checks,
connections: {
installedBrackets: 10 - state.missingBrackets,
totalBrackets: 10,
installedBolts: 24 - state.missingBolts,
totalBolts: 24,
unresolved: state.missingBrackets + state.missingBolts
},
inventory: getInventory().map((item) => ({
...item,
remaining: Math.max(0, item.total - item.used)
}))
};
const blob = new Blob([JSON.stringify(report, null, 2)], {
type: "application/json"
});
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "shelter-04-assembly-check.json";
document.body.appendChild(link);
link.click();
link.remove();
URL.revokeObjectURL(url);
showToast("Assembly report exported.");
});
// Camera controls implemented directly, without Three.js addons.
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
cameraControl.pointer = {
id: event.pointerId,
button: event.button,
x: event.clientX,
y: event.clientY
};
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
const pointer = cameraControl.pointer;
if (!pointer || pointer.id !== event.pointerId) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
const panning = pointer.button === 2 || event.shiftKey;
if (panning) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const panScale = cameraControl.radius * 0.00155;
cameraControl.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
} else {
cameraControl.theta -= dx * 0.006;
cameraControl.phi = THREE.MathUtils.clamp(
cameraControl.phi - dy * 0.005,
0.24,
Math.PI - 0.24
);
}
updateCamera();
});
function endPointer(event) {
if (cameraControl.pointer?.id === event.pointerId) {
cameraControl.pointer = null;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraControl.radius = THREE.MathUtils.clamp(
cameraControl.radius * Math.exp(event.deltaY * 0.001),
4.5,
24
);
updateCamera();
},
{ passive: false }
);
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
function positionLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
for (const [key, elementId] of [
["width", "labelWidth"],
["depth", "labelDepth"],
["height", "labelHeight"]
]) {
const projected = labelPositions[key].clone().project(camera);
const element = $(elementId);
const visible =
state.showLabels &&
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.1 &&
projected.x < 1.1 &&
projected.y > -1.1 &&
projected.y < 1.1;
element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const targetExplode = state.exploded ? 1 : 0;
state.explodeAmount += (targetExplode - state.explodeAmount) * 0.09;
if (shelterRoot) {
shelterRoot.traverse((object) => {
if (
object.isMesh &&
object.userData.basePosition &&
object.userData.explode
) {
const targetPosition = object.userData.basePosition
.clone()
.addScaledVector(object.userData.explode, state.explodeAmount);
object.position.lerp(targetPosition, 0.2);
}
});
issuesGroup.traverse((object) => {
if (!object.userData.isIssue) return;
const targetPosition = object.userData.basePosition
.clone()
.addScaledVector(object.userData.explode, state.explodeAmount);
object.position.lerp(targetPosition, 0.2);
const pulse = 1 + Math.sin(elapsed * 4.2 + object.userData.phase) * 0.11;
object.scale.setScalar(pulse);
object.rotation.y = elapsed * 0.7 + object.userData.phase;
});
}
updateCamera();
positionLabels();
renderer.render(scene, camera);
}
buildShelter();
updateUI();
fitView();
resize();
animate();
</script>
</body>
</html>
```