Prompt specification
Build or customize the Three.js 3D scene "Workshop shelf planning exhibit" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Workshop shelf planning exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/workshop-shelf-planning-exhibit-x0232
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring shelf supports and brackets. Create a configurable shelf wall with bracket sockets and weighted display blocks; a simplified stability indicator responds to unsupported spans and explains its illustrative assumptions beside the model. Voxel style.
Working Three.js Starter (workshop-shelf-planning-exhibit-x0232):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Span — Shelf Stability Lab</title>
<style>
:root {
--ink: #202b2e;
--muted: #6c7675;
--paper: #f5f2e9;
--panel: #fbfaf5;
--line: #d8d7cf;
--teal: #188b72;
--amber: #dc9838;
--red: #dc5b4e;
--orange: #e87842;
--blue: #386f88;
--radius: 14px;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
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-rows: 68px minmax(0, 1fr);
height: 100%;
}
header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(251, 250, 245, 0.96);
z-index: 5;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 30px;
height: 30px;
flex: 0 0 auto;
}
.brand-mark i {
position: absolute;
display: block;
background: var(--ink);
}
.brand-mark i:nth-child(1) {
left: 2px;
top: 5px;
width: 7px;
height: 22px;
}
.brand-mark i:nth-child(2) {
left: 10px;
top: 12px;
width: 7px;
height: 15px;
}
.brand-mark i:nth-child(3) {
left: 18px;
top: 2px;
width: 7px;
height: 25px;
}
.brand-mark i:nth-child(4) {
left: 8px;
top: 9px;
width: 16px;
height: 6px;
background: var(--orange);
}
.brand-copy {
display: flex;
align-items: baseline;
gap: 10px;
min-width: 0;
}
.brand-copy strong {
font-size: 15px;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.brand-copy span {
color: var(--muted);
font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
white-space: nowrap;
}
.header-actions {
display: flex;
align-items: center;
gap: 10px;
}
.chip {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
background: #fff;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
white-space: nowrap;
}
.chip::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(24, 139, 114, 0.12);
}
.ghost-button {
border: 1px solid var(--line);
border-radius: 9px;
padding: 8px 11px;
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.ghost-button:hover {
background: #ecebe4;
}
main {
display: grid;
grid-template-columns: minmax(0, 1fr) 360px;
min-height: 0;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e9e7df;
isolation: isolate;
}
.viewport canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
.viewport canvas:active {
cursor: grabbing;
}
.view-top {
position: absolute;
z-index: 2;
top: 20px;
left: 22px;
right: 22px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.scene-title {
display: grid;
gap: 4px;
}
.eyebrow {
color: #6d7775;
font: 750 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-title h1 {
margin: 0;
font-size: clamp(20px, 2.2vw, 32px);
line-height: 1;
letter-spacing: -0.035em;
}
.view-index {
display: grid;
place-items: center;
width: 46px;
height: 46px;
border: 1px solid rgba(32, 43, 46, 0.16);
background: rgba(251, 250, 245, 0.74);
backdrop-filter: blur(8px);
color: #596462;
font: 750 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.view-bottom {
position: absolute;
z-index: 2;
left: 22px;
right: 22px;
bottom: 18px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: 520px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid rgba(32, 43, 46, 0.12);
background: rgba(251, 250, 245, 0.78);
backdrop-filter: blur(8px);
color: #596462;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.legend i {
width: 8px;
height: 8px;
background: var(--swatch);
}
.view-help {
color: #596462;
font: 700 9px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
text-align: right;
text-transform: uppercase;
}
aside {
min-height: 0;
overflow-y: auto;
border-left: 1px solid var(--line);
background: var(--panel);
scrollbar-width: thin;
scrollbar-color: #c8c8c0 transparent;
}
.side-section {
padding: 22px 22px 24px;
border-bottom: 1px solid var(--line);
}
.side-section:last-child {
border-bottom: 0;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 20px;
}
.section-heading h2 {
margin: 0;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section-number {
color: #919996;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.control {
display: block;
margin-bottom: 20px;
}
.control:last-child {
margin-bottom: 0;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
color: #485451;
font-size: 11px;
font-weight: 700;
}
.control-label output {
color: var(--ink);
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 7px 0;
border-radius: 0;
appearance: none;
background: #d9d9d1;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid var(--panel);
border-radius: 0;
appearance: none;
background: var(--ink);
box-shadow: 0 0 0 1px var(--ink);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 2px solid var(--panel);
border-radius: 0;
background: var(--ink);
box-shadow: 0 0 0 1px var(--ink);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #969d99;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.segmented {
display: grid;
grid-template-columns: repeat(3, 1fr);
border: 1px solid var(--line);
background: #efeee8;
padding: 3px;
gap: 3px;
}
.segmented button {
min-height: 34px;
border: 0;
border-radius: 5px;
background: transparent;
color: #727c79;
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.03em;
}
.segmented button.active {
background: var(--ink);
color: white;
box-shadow: 0 2px 7px rgba(32, 43, 46, 0.15);
}
.check-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 18px;
padding-top: 17px;
border-top: 1px solid var(--line);
color: #596462;
font-size: 11px;
font-weight: 700;
}
.check-row input {
accent-color: var(--teal);
width: 16px;
height: 16px;
}
.status-card {
padding: 16px;
border: 1px solid var(--line);
border-radius: var(--radius);
background: #f2f1eb;
}
.status-top {
display: grid;
grid-template-columns: 92px 1fr;
align-items: center;
gap: 16px;
}
.gauge {
--gauge-color: var(--teal);
position: relative;
display: grid;
place-items: center;
width: 92px;
height: 92px;
border-radius: 50%;
background: conic-gradient(var(--gauge-color) 0deg, #d8d9d2 0deg);
}
.gauge::after {
content: "";
position: absolute;
inset: 9px;
border-radius: 50%;
background: #f2f1eb;
}
.gauge-copy {
position: relative;
z-index: 1;
display: grid;
text-align: center;
}
.gauge-copy strong {
font: 850 23px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: -0.06em;
}
.gauge-copy span {
margin-top: 4px;
color: #7d8582;
font: 800 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-copy .eyebrow {
margin-bottom: 7px;
}
.status-title {
margin: 0 0 7px;
font-size: 19px;
letter-spacing: -0.025em;
}
.status-description {
margin: 0;
color: #697371;
font-size: 11px;
line-height: 1.55;
}
.metric-list {
display: grid;
gap: 0;
margin-top: 16px;
border-top: 1px solid var(--line);
}
.metric {
display: grid;
grid-template-columns: 1fr auto;
gap: 12px;
align-items: center;
min-height: 42px;
border-bottom: 1px solid var(--line);
}
.metric:last-child {
border-bottom: 0;
}
.metric span {
color: #707a77;
font-size: 10px;
font-weight: 700;
}
.metric strong {
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.assumption-list {
display: grid;
gap: 13px;
margin: 0;
padding: 0;
list-style: none;
}
.assumption-list li {
position: relative;
padding-left: 20px;
color: #66716e;
font-size: 11px;
line-height: 1.55;
}
.assumption-list li::before {
content: "";
position: absolute;
left: 1px;
top: 7px;
width: 7px;
height: 7px;
background: var(--orange);
}
.assumption-list strong {
color: #374542;
}
.disclaimer {
margin-top: 18px;
padding: 12px;
border-left: 3px solid var(--orange);
background: #f1eee6;
color: #68716e;
font-size: 10px;
line-height: 1.55;
}
@media (max-width: 900px) {
html,
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100%;
grid-template-rows: 62px auto;
}
header {
padding: 0 16px;
}
.brand-copy span,
.chip {
display: none;
}
main {
display: block;
}
.viewport {
height: 62vh;
min-height: 460px;
}
aside {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.view-help {
display: none;
}
}
@media (max-width: 480px) {
.view-top {
top: 15px;
left: 15px;
right: 15px;
}
.view-index {
width: 40px;
height: 40px;
}
.side-section {
padding: 20px 17px;
}
.status-top {
grid-template-columns: 82px 1fr;
}
.gauge {
width: 82px;
height: 82px;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</div>
<div class="brand-copy">
<strong>Voxel Span</strong>
<span>SHELF STABILITY LAB / 01</span>
</div>
</div>
<div class="header-actions">
<span class="chip">Live illustrative model</span>
<button class="ghost-button" id="resetButton" type="button">Reset</button>
</div>
</header>
<main>
<section class="viewport" id="viewport" aria-label="Interactive three-dimensional shelf wall">
<div class="view-top">
<div class="scene-title">
<div class="eyebrow">Configurable socket wall</div>
<h1>Support the display.</h1>
</div>
<div class="view-index">3D</div>
</div>
<div class="view-bottom">
<div class="legend" aria-hidden="true">
<span><i style="--swatch:#344b50"></i>Bracket</span>
<span><i style="--swatch:#e87842"></i>Active socket</span>
<span><i style="--swatch:#188b72"></i>Clear span</span>
<span><i style="--swatch:#dc5b4e"></i>Load vector</span>
</div>
<div class="view-help">
Drag to orbit · Wheel to zoom<br />
Shift/right drag to pan · Double-click to reset
</div>
</div>
</section>
<aside>
<section class="side-section">
<div class="section-heading">
<h2>Tune the wall</h2>
<span class="section-number">01 / CONFIG</span>
</div>
<label class="control">
<span class="control-label">
Shelf levels
<output id="shelfValue">3 levels</output>
</span>
<input id="shelfCount" type="range" min="2" max="5" step="1" value="3" />
<span class="range-ends"><span>02</span><span>05</span></span>
</label>
<label class="control">
<span class="control-label">
Shelf span
<output id="spanValue">2.8 m</output>
</span>
<input id="span" type="range" min="2" max="4.6" step="0.1" value="2.8" />
<span class="range-ends"><span>2.0 m</span><span>4.6 m</span></span>
</label>
<label class="control">
<span class="control-label">
Brackets per shelf
<output id="bracketValue">3</output>
</span>
<input id="bracketCount" type="range" min="2" max="4" step="1" value="3" />
<span class="range-ends"><span>02</span><span>04</span></span>
</label>
<label class="control">
<span class="control-label">
Mass per display block
<output id="massValue">8 kg</output>
</span>
<input id="mass" type="range" min="2" max="16" step="1" value="8" />
<span class="range-ends"><span>2 kg</span><span>16 kg</span></span>
</label>
<label class="control">
<span class="control-label">
Blocks per shelf
<output id="blockValue">4</output>
</span>
<input id="blockCount" type="range" min="2" max="5" step="1" value="4" />
<span class="range-ends"><span>02</span><span>05</span></span>
</label>
<div class="control">
<div class="control-label">
Load pattern
<output id="patternValue">Even</output>
</div>
<div class="segmented" id="patternButtons" role="group" aria-label="Load pattern">
<button class="active" data-pattern="even" type="button">Even</button>
<button data-pattern="clustered" type="button">Clustered</button>
<button data-pattern="edge" type="button">Edge pair</button>
</div>
</div>
<label class="check-row">
<span>Show load vectors</span>
<input id="showLoads" type="checkbox" checked />
</label>
</section>
<section class="side-section">
<div class="section-heading">
<h2>Stability check</h2>
<span class="section-number">02 / READOUT</span>
</div>
<div class="status-card">
<div class="status-top">
<div class="gauge" id="gauge">
<div class="gauge-copy">
<strong id="reserveValue">—</strong>
<span>Reserve</span>
</div>
</div>
<div class="status-copy">
<div class="eyebrow" id="statusEyebrow">Checking model</div>
<h3 class="status-title" id="statusTitle">Balanced</h3>
<p class="status-description" id="statusDescription">
Brackets are spaced to support the current display arrangement.
</p>
</div>
</div>
<div class="metric-list">
<div class="metric">
<span>Largest clear span</span>
<strong id="clearSpanMetric">—</strong>
</div>
<div class="metric">
<span>Outer overhang</span>
<strong id="overhangMetric">—</strong>
</div>
<div class="metric">
<span>Bending utilization</span>
<strong id="bendingMetric">—</strong>
</div>
<div class="metric">
<span>Bracket utilization</span>
<strong id="reactionMetric">—</strong>
</div>
</div>
</div>
</section>
<section class="side-section">
<div class="section-heading">
<h2>Model assumptions</h2>
<span class="section-number">03 / SCOPE</span>
</div>
<ul class="assumption-list">
<li>
Each shelf is treated as a <strong>straight beam with simple supports</strong>
at the selected bracket sockets.
</li>
<li>
Shelf self-weight is <strong id="selfWeightAssumption">8 kg/m</strong>.
Display blocks are applied as <strong>point loads</strong>.
</li>
<li>
Clear spans and outer overhangs are checked independently.
The illustrative limits are <strong>180 N·m bending</strong>,
<strong>520 N bracket reaction</strong>, and a preferred
<strong>1.8 m clear span</strong>.
</li>
<li>
The model omits <strong>deflection, connection strength, wall anchoring,
buckling, dynamic loads, and seismic effects</strong>.
</li>
</ul>
<div class="disclaimer">
This is a visual teaching model, not a structural calculation or a
certification of safe installation.
</div>
</section>
</aside>
</main>
</div>
<noscript>This interactive scene requires JavaScript.</noscript>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const viewport = $("#viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.15;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional voxel shelf wall with brackets and weighted blocks"
);
viewport.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e9e7df");
scene.fog = new THREE.Fog("#e9e7df", 15, 30);
const camera = new THREE.OrthographicCamera(-5, 5, 5, -5, 0.1, 100);
const hemisphere = new THREE.HemisphereLight("#fffaf0", "#7e8b87", 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#fff3da", 3.5);
keyLight.position.set(5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -2;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#b7d1db", 1.2);
fillLight.position.set(-6, 5, 4);
scene.add(fillLight);
const materials = {
ground: new THREE.MeshStandardMaterial({
color: "#dedbd0",
roughness: 0.96,
metalness: 0
}),
wall: new THREE.MeshStandardMaterial({
color: "#c9c6bb",
roughness: 0.92
}),
rail: new THREE.MeshStandardMaterial({
color: "#2b4145",
roughness: 0.68,
metalness: 0.12
}),
socket: new THREE.MeshStandardMaterial({
color: "#68716f",
roughness: 0.82
}),
shelf: new THREE.MeshStandardMaterial({
color: "#c58c55",
roughness: 0.84
}),
shelfEdge: new THREE.MeshStandardMaterial({
color: "#8d603a",
roughness: 0.88
}),
bracket: new THREE.MeshStandardMaterial({
color: "#344b50",
roughness: 0.58,
metalness: 0.18
}),
connector: new THREE.MeshStandardMaterial({
color: "#e87842",
roughness: 0.62,
metalness: 0.08
}),
load: new THREE.MeshStandardMaterial({
color: "#dc5b4e",
roughness: 0.74
}),
blocks: [
new THREE.MeshStandardMaterial({ color: "#386f88", roughness: 0.78 }),
new THREE.MeshStandardMaterial({ color: "#d7904d", roughness: 0.78 }),
new THREE.MeshStandardMaterial({ color: "#63856a", roughness: 0.78 }),
new THREE.MeshStandardMaterial({ color: "#b85d55", roughness: 0.78 }),
new THREE.MeshStandardMaterial({ color: "#77719a", roughness: 0.78 })
]
};
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 48, "#c3c2b9", "#d1d0c7");
grid.position.y = -0.018;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
const wallGroup = new THREE.Group();
const shelfGroup = new THREE.Group();
const bracketGroup = new THREE.Group();
const blockGroup = new THREE.Group();
const annotationGroup = new THREE.Group();
const loadGroup = new THREE.Group();
scene.add(
wallGroup,
shelfGroup,
bracketGroup,
blockGroup,
annotationGroup,
loadGroup
);
const defaults = {
shelfCount: 3,
span: 2.8,
bracketCount: 3,
mass: 8,
blockCount: 4,
pattern: "even",
showLoads: true
};
let currentConfig = { ...defaults };
let currentAnalysis = null;
const cameraState = {
yaw: 0.62,
targetYaw: 0.62,
pitch: 0.43,
targetPitch: 0.43,
zoom: 0.98,
targetZoom: 0.98,
target: new THREE.Vector3(0, 1.95, 0),
dragging: false,
panning: false,
lastX: 0,
lastY: 0
};
function makeBox(parent, size, position, material, castShadow = true) {
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 = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function clearGroup(group) {
group.traverse((object) => {
if (object.geometry) {
object.geometry.dispose();
}
if (object.userData.ownMaterial && object.material) {
const list = Array.isArray(object.material)
? object.material
: [object.material];
list.forEach((material) => {
if (material.map) material.map.dispose();
material.dispose();
});
}
});
group.clear();
}
function createBlockLabel(mass, accent) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "#f6f1e5";
context.fillRect(0, 0, 256, 128);
context.strokeStyle = accent;
context.lineWidth = 9;
context.strokeRect(5, 5, 246, 118);
context.textAlign = "center";
context.fillStyle = "#202b2e";
context.font = "800 52px ui-monospace, monospace";
context.fillText(`${mass} kg`, 128, 65);
context.fillStyle = "#69726f";
context.font = "700 18px ui-monospace, monospace";
context.fillText("POINT LOAD", 128, 98);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.95,
transparent: false
});
material.userData.ownMaterial = true;
return material;
}
function createSprite(text, background = "#2b4145", foreground = "#ffffff") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, 512, 128);
context.strokeStyle = foreground;
context.globalAlpha = 0.3;
context.lineWidth = 5;
context.strokeRect(7, 7, 498, 114);
context.globalAlpha = 1;
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "800 34px ui-monospace, monospace";
context.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.52, 0.38, 1);
sprite.renderOrder = 20;
sprite.userData.ownMaterial = true;
return sprite;
}
function getConfig() {
return {
shelfCount: Number($("#shelfCount").value),
span: Number($("#span").value),
bracketCount: Number($("#bracketCount").value),
mass: Number($("#mass").value),
blockCount: Number($("#blockCount").value),
pattern: currentConfig.pattern,
showLoads: $("#showLoads").checked
};
}
function getSupportPositions(span, count) {
const margin = Math.min(0.35, span * 0.14);
const innerWidth = span - margin * 2;
if (count === 1) return [0];
return Array.from({ length: count }, (_, index) => {
return -innerWidth / 2 + (innerWidth * index) / (count - 1);
});
}
function getBlockPositions(config) {
const { span, blockCount, pattern } = config;
const positions = [];
if (pattern === "clustered") {
const normalized = [-0.4, -0.28, -0.16, -0.04, 0.08];
for (let i = 0; i < blockCount; i++) {
positions.push(normalized[i] * span);
}
} else if (pattern === "edge") {
const normalized = [-0.38, 0.38, -0.2, 0.2, 0];
for (let i = 0; i < blockCount; i++) {
positions.push(normalized[i] * span);
}
} else {
for (let i = 0; i < blockCount; i++) {
const t = blockCount === 1 ? 0.5 : i / (blockCount - 1);
positions.push((t - 0.5) * span * 0.76);
}
}
return positions;
}
function analyzeShelf(config, supports, blockPositions) {
const gravity = 9.81;
const shelfLinearMass = 8;
const uniformLoad = shelfLinearMass * gravity;
const pointLoads = blockPositions.map(
(position) => ({ position, force: config.mass * gravity })
);
const reactions = supports.map(() => 0);
const segmentResults = [];
let maxMoment = 0;
let governingMomentSegment = null;
for (let i = 0; i < supports.length - 1; i++) {
const left = supports[i];
const right = supports[i + 1];
const length = right - left;
let moment = (uniformLoad * length * length) / 8;
reactions[i] += (uniformLoad * length) / 2;
reactions[i + 1] += (uniformLoad * length) / 2;
for (const load of pointLoads) {
const isInside =
load.position > left + 0.000001 &&
load.position < right - 0.000001;
if (!isInside) continue;
const a = load.position - left;
const b = right - load.position;
moment += (load.force * a * b) / length;
reactions[i] += (load.force * b) / length;
reactions[i + 1] += (load.force * a) / length;
}
segmentResults.push({
left,
right,
length,
moment
});
if (moment > maxMoment) {
maxMoment = moment;
governingMomentSegment = segmentResults[segmentResults.length - 1];
}
}
const leftEdge = -config.span / 2;
const rightEdge = config.span / 2;
const leftOverhang = supports[0] - leftEdge;
const rightOverhang = rightEdge - supports[supports.length - 1];
let leftMoment = (uniformLoad * leftOverhang * leftOverhang) / 2;
let rightMoment = (uniformLoad * rightOverhang * rightOverhang) / 2;
for (const load of pointLoads) {
if (load.position < supports[0]) {
leftMoment += load.force * (supports[0] - load.position);
reactions[0] += load.force;
} else if (load.position > supports[supports.length - 1]) {
rightMoment += load.force * (load.position - supports[supports.length - 1]);
reactions[reactions.length - 1] += load.force;
} else {
const nearest = supports.findIndex(
(support) => Math.abs(support - load.position) < 0.000001
);
if (nearest >= 0) {
reactions[nearest] += load.force;
}
}
}
maxMoment = Math.max(maxMoment, leftMoment, rightMoment);
const clearSpans = segmentResults.map((segment) => segment.length);
const maxClearSpan = Math.max(...clearSpans);
const maxOverhang = Math.max(leftOverhang, rightOverhang);
const maxReaction = Math.max(...reactions);
const momentLimit = 180;
const reactionLimit = 520;
const preferredClearSpan = 1.8;
const momentUtilization = maxMoment / momentLimit;
const reactionUtilization = maxReaction / reactionLimit;
const spanUtilization = maxClearSpan / preferredClearSpan;
const overallUtilization = Math.max(
momentUtilization,
reactionUtilization,
spanUtilization
);
const governingClearSegment = segmentResults.reduce((largest, segment) => {
return segment.length > largest.length ? segment : largest;
}, segmentResults[0]);
return {
reactions,
segmentResults,
governingClearSegment,
maxMoment,
maxReaction,
maxClearSpan,
maxOverhang,
leftOverhang,
rightOverhang,
momentLimit,
reactionLimit,
preferredClearSpan,
momentUtilization,
reactionUtilization,
spanUtilization,
overallUtilization,
uniformLoad
};
}
function getStatus(utilization) {
if (utilization <= 0.75) {
return {
title: "Balanced",
eyebrow: "Support is adequate",
color: "#188b72",
description:
"The current brackets and clear spans remain inside the illustrative limits."
};
}
if (utilization <= 1) {
return {
title: "Near limit",
eyebrow: "Low reserve",
color: "#dc9838",
description:
"The model is still below its limit, but adding load or increasing the span could make it unstable."
};
}
return {
title: "Unsupported",
eyebrow: "Limit exceeded",
color: "#dc5b4e",
description:
"At least one support, span, or bracket reaction exceeds the illustrative threshold."
};
}
function buildWall(config) {
const baseY = 0.72;
const levelGap = 1.03;
const wallHeight = baseY + (config.shelfCount - 1) * levelGap + 0.72;
const wallWidth = 5.5;
makeBox(
wallGroup,
[wallWidth, wallHeight, 0.12],
[0, wallHeight / 2, -0.42],
materials.wall
);
makeBox(
wallGroup,
[0.16, wallHeight + 0.08, 0.22],
[-wallWidth / 2 - 0.03, wallHeight / 2, -0.31],
materials.rail
);
makeBox(
wallGroup,
[0.16, wallHeight + 0.08, 0.22],
[wallWidth / 2 + 0.03, wallHeight / 2, -0.31],
materials.rail
);
makeBox(
wallGroup,
[wallWidth + 0.2, 0.13, 0.22],
[0, wallHeight + 0.02, -0.31],
materials.rail
);
const columns = 19;
const rows = Math.floor((wallHeight - 0.35) / 0.25) + 1;
const socketGeometry = new THREE.BoxGeometry(0.068, 0.068, 0.045);
const sockets = new THREE.InstancedMesh(
socketGeometry,
materials.socket,
columns * rows
);
const matrix = new THREE.Matrix4();
let instance = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = -2.4 + (4.8 * column) / (columns - 1);
const y = 0.25 + row * 0.25;
matrix.makeTranslation(x, y, -0.337);
sockets.setMatrixAt(instance, matrix);
instance++;
}
}
sockets.instanceMatrix.needsUpdate = true;
sockets.receiveShadow = true;
wallGroup.add(sockets);
}
function buildBrackets(config, supports) {
const baseY = 0.72;
const levelGap = 1.03;
for (let level = 0; level < config.shelfCount; level++) {
const shelfY = baseY + level * levelGap;
for (const x of supports) {
makeBox(
bracketGroup,
[0.17, 0.38, 0.08],
[x, shelfY - 0.22, -0.285],
materials.bracket
);
makeBox(
bracketGroup,
[0.12, 0.12, 0.13],
[x, shelfY - 0.105, -0.235],
materials.connector
);
makeBox(
bracketGroup,
[0.13, 0.11, 0.65],
[x, shelfY - 0.11, 0.065],
materials.bracket
);
makeBox(
bracketGroup,
[0.16, 0.14, 0.12],
[x, shelfY - 0.105, 0.335],
materials.connector
);
}
}
}
function buildShelves(config) {
const baseY = 0.72;
const levelGap = 1.03;
for (let level = 0; level < config.shelfCount; level++) {
const shelfY = baseY + level * levelGap;
makeBox(
shelfGroup,
[config.span, 0.11, 0.72],
[0, shelfY, 0],
materials.shelf
);
makeBox(
shelfGroup,
[config.span, 0.12, 0.045],
[0, shelfY - 0.005, 0.355],
materials.shelfEdge
);
}
}
function buildBlocks(config, blockPositions) {
const baseY = 0.72;
const levelGap = 1.03;
for (let level = 0; level < config.shelfCount; level++) {
const shelfY = baseY + level * levelGap;
blockPositions.forEach((x, index) => {
const width = Math.min(0.38, 0.18 + config.mass * 0.012);
const height = 0.27 + (index % 3) * 0.08;
const depth = 0.43;
const colorMaterial = materials.blocks[index % materials.blocks.length];
const accent = `#${colorMaterial.color.getHexString()}`;
const block = makeBox(
blockGroup,
[width, height, depth],
[x, shelfY + 0.055 + height / 2, 0.065],
colorMaterial
);
const labelMaterial = createBlockLabel(config.mass, accent);
const label = new THREE.Mesh(
new THREE.PlaneGeometry(width * 0.76, width * 0.38),
labelMaterial
);
label.position.set(
x,
shelfY + 0.055 + height * 0.53,
0.065 + depth / 2 + 0.002
);
label.userData.ownMaterial = true;
blockGroup.add(label);
const cap = makeBox(
blockGroup,
[width * 0.66, 0.035, depth * 0.62],
[x, shelfY + 0.055 + height + 0.018, 0.065],
colorMaterial
);
cap.scale.y = 0.9;
});
}
}
function buildLoadVectors(config, blockPositions) {
if (!config.showLoads) return;
const topShelfY =
0.72 + (config.shelfCount - 1) * 1.03;
blockPositions.forEach((x) => {
const topY = topShelfY + 0.055 + 0.27 + 0.08;
makeBox(
loadGroup,
[0.028, 0.34, 0.028],
[x, topY + 0.34, 0.065],
materials.load,
false
);
makeBox(
loadGroup,
[0.11, 0.055, 0.11],
[x, topY + 0.12, 0.065],
materials.load,
false
);
makeBox(
loadGroup,
[0.075, 0.055, 0.075],
[x, topY + 0.175, 0.065],
materials.load,
false
);
makeBox(
loadGroup,
[0.04, 0.055, 0.04],
[x, topY + 0.23, 0.065],
materials.load,
false
);
});
}
function buildAnnotation(analysis, status) {
const segment = analysis.governingClearSegment;
const firstShelfY = 0.72;
const color = new THREE.Color(status.color);
const lineMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92,
depthTest: false
});
const annotation = makeBox(
annotationGroup,
[segment.length, 0.028, 0.035],
[
(segment.left + segment.right) / 2,
firstShelfY - 0.3,
0.49
],
lineMaterial,
false
);
annotation.renderOrder = 15;
for (const x of [segment.left, segment.right]) {
const tick = makeBox(
annotationGroup,
[0.032, 0.16, 0.035],
[x, firstShelfY - 0.3, 0.49],
lineMaterial,
false
);
tick.renderOrder = 15;
}
const label = createSprite(
`${segment.length.toFixed(2)} M CLEAR`,
status.color,
"#ffffff"
);
label.position.set(
(segment.left + segment.right) / 2,
firstShelfY - 0.54,
0.54
);
annotationGroup.add(label);
}
function updateReadout(analysis) {
const status = getStatus(analysis.overallUtilization);
const reserve = Math.max(
0,
Math.min(100, Math.round((1 - analysis.overallUtilization) * 100))
);
const gauge = $("#gauge");
gauge.style.background = `conic-gradient(
${status.color} 0deg,
${status.color} ${reserve * 3.6}deg,
#d8d9d2 ${reserve * 3.6}deg
)`;
gauge.style.setProperty("--gauge-color", status.color);
$("#reserveValue").textContent = `${reserve}%`;
$("#statusTitle").textContent = status.title;
$("#statusEyebrow").textContent = status.eyebrow;
$("#statusEyebrow").style.color = status.color;
$("#statusDescription").textContent = status.description;
$("#clearSpanMetric").textContent =
`${analysis.maxClearSpan.toFixed(2)} m`;
$("#overhangMetric").textContent =
`${analysis.maxOverhang.toFixed(2)} m`;
$("#bendingMetric").textContent =
`${Math.round(analysis.momentUtilization * 100)}% · ${analysis.maxMoment.toFixed(0)} N·m`;
$("#reactionMetric").textContent =
`${Math.round(analysis.reactionUtilization * 100)}% · ${analysis.maxReaction.toFixed(0)} N`;
$("#bendingMetric").style.color =
analysis.momentUtilization > 1 ? status.color : "#202b2e";
$("#reactionMetric").style.color =
analysis.reactionUtilization > 1 ? status.color : "#202b2e";
return status;
}
function updateOutputs() {
$("#shelfValue").textContent = `${currentConfig.shelfCount} levels`;
$("#spanValue").textContent = `${currentConfig.span.toFixed(1)} m`;
$("#bracketValue").textContent = `${currentConfig.bracketCount}`;
$("#massValue").textContent = `${currentConfig.mass} kg`;
$("#blockValue").textContent = `${currentConfig.blockCount}`;
const patternNames = {
even: "Even",
clustered: "Clustered",
edge: "Edge pair"
};
$("#patternValue").textContent = patternNames[currentConfig.pattern];
}
function updateModel() {
currentConfig = getConfig();
updateOutputs();
clearGroup(wallGroup);
clearGroup(shelfGroup);
clearGroup(bracketGroup);
clearGroup(blockGroup);
clearGroup(annotationGroup);
clearGroup(loadGroup);
const supports = getSupportPositions(
currentConfig.span,
currentConfig.bracketCount
);
const blockPositions = getBlockPositions(currentConfig);
currentAnalysis = analyzeShelf(
currentConfig,
supports,
blockPositions
);
const status = updateReadout(currentAnalysis);
buildWall(currentConfig);
buildBrackets(currentConfig, supports);
buildShelves(currentConfig);
buildBlocks(currentConfig, blockPositions);
buildLoadVectors(currentConfig, blockPositions);
buildAnnotation(currentAnalysis, status);
const desiredTargetY =
0.72 + ((currentConfig.shelfCount - 1) * 1.03) / 2;
cameraState.target.y = desiredTargetY;
}
[
"#shelfCount",
"#span",
"#bracketCount",
"#mass",
"#blockCount"
].forEach((selector) => {
$(selector).addEventListener("input", updateModel);
});
$("#showLoads").addEventListener("change", updateModel);
$("#patternButtons").addEventListener("click", (event) => {
const button = event.target.closest("button[data-pattern]");
if (!button) return;
currentConfig.pattern = button.dataset.pattern;
document
.querySelectorAll("#patternButtons button")
.forEach((item) => item.classList.toggle("active", item === button));
updateModel();
});
$("#resetButton").addEventListener("click", () => {
$("#shelfCount").value = defaults.shelfCount;
$("#span").value = defaults.span;
$("#bracketCount").value = defaults.bracketCount;
$("#mass").value = defaults.mass;
$("#blockCount").value = defaults.blockCount;
$("#showLoads").checked = defaults.showLoads;
currentConfig.pattern = defaults.pattern;
document
.querySelectorAll("#patternButtons button")
.forEach((item) => {
item.classList.toggle("active", item.dataset.pattern === defaults.pattern);
});
updateModel();
resetCamera();
});
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
const aspect = width / Math.max(height, 1);
const viewHeight = currentConfig.shelfCount >= 5 ? 7.7 : 6.6;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
function resetCamera() {
cameraState.targetYaw = 0.62;
cameraState.targetPitch = 0.43;
cameraState.targetZoom = 0.98;
cameraState.target.set(
0,
0.72 + ((currentConfig.shelfCount - 1) * 1.03) / 2,
0
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
cameraState.dragging = true;
cameraState.panning =
event.button === 2 || event.button === 1 || event.shiftKey;
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!cameraState.dragging) return;
const dx = event.clientX - cameraState.lastX;
const dy = event.clientY - cameraState.lastY;
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
if (cameraState.panning) {
const right = new THREE.Vector3(
Math.cos(cameraState.yaw),
0,
-Math.sin(cameraState.yaw)
);
const panScale = 0.006 / cameraState.zoom;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.y += dy * panScale;
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y,
0.6,
4.2
);
} else {
cameraState.targetYaw -= dx * 0.008;
cameraState.targetPitch = THREE.MathUtils.clamp(
cameraState.targetPitch + dy * 0.006,
0.16,
0.95
);
}
});
function endDrag(event) {
cameraState.dragging = false;
cameraState.panning = false;
if (
event &&
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetZoom = THREE.MathUtils.clamp(
cameraState.targetZoom * Math.exp(-event.deltaY * 0.001),
0.58,
2.1
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
function animate() {
requestAnimationFrame(animate);
cameraState.yaw +=
(cameraState.targetYaw - cameraState.yaw) * 0.12;
cameraState.pitch +=
(cameraState.targetPitch - cameraState.pitch) * 0.12;
cameraState.zoom +=
(cameraState.targetZoom - cameraState.zoom) * 0.12;
const radius = 10;
const horizontal = radius * Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x +
horizontal * Math.sin(cameraState.yaw),
cameraState.target.y + radius * Math.sin(cameraState.pitch),
cameraState.target.z +
horizontal * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
renderer.render(scene, camera);
}
updateModel();
resize();
animate();
</script>
</body>
</html>
```