Prompt specification
Build or customize the Three.js 3D scene "Support spacing comparison" 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: Support spacing comparison
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/support-spacing-comparison-x0230
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing shelf supports and brackets. Display two identical shelves with differently spaced brackets and symbolic loads; use clearly exaggerated deflection guides to compare support arrangements without claiming engineering design accuracy. Low-poly.
Working Three.js Starter (support-spacing-comparison-x0230):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shelf Support & Bracket Study</title>
<style>
:root {
--ink: #203744;
--muted: #60747d;
--paper: #edf1ec;
--panel: rgba(250, 252, 248, 0.91);
--line: rgba(32, 55, 68, 0.15);
--slate: #355668;
--coral: #df6557;
--amber: #efa800;
--blue: #6f91a3;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.hero {
position: fixed;
top: 24px;
left: 28px;
z-index: 10;
max-width: 440px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--slate);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
background: var(--coral);
}
h1 {
margin: 0;
font-size: clamp(27px, 3.2vw, 46px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 850;
}
.subtitle {
margin: 11px 0 0;
max-width: 400px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.controls {
position: fixed;
top: 24px;
right: 26px;
z-index: 20;
display: flex;
gap: 8px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 10px;
padding: 10px 13px;
background: var(--panel);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 5px 18px rgba(32, 55, 68, 0.07);
backdrop-filter: blur(10px);
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fff;
}
button:focus-visible {
outline: 3px solid rgba(223, 101, 87, 0.28);
outline-offset: 2px;
}
#station-labels {
position: fixed;
inset: 0;
z-index: 8;
pointer-events: none;
overflow: hidden;
}
.station-card {
position: absolute;
top: 0;
left: 0;
width: 226px;
padding: 12px 14px 13px;
border: 1px solid rgba(32, 55, 68, 0.12);
border-radius: 13px;
background: rgba(250, 252, 248, 0.94);
box-shadow: 0 10px 30px rgba(32, 55, 68, 0.09);
backdrop-filter: blur(12px);
will-change: transform;
}
.station-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
border-radius: 13px 0 0 13px;
background: var(--card-accent);
}
.station-top {
display: flex;
align-items: center;
gap: 9px;
}
.station-letter {
display: grid;
place-items: center;
width: 29px;
height: 29px;
border-radius: 8px;
background: var(--card-accent);
color: white;
font-size: 14px;
font-weight: 900;
}
.station-title {
margin: 0;
font-size: 13px;
font-weight: 850;
letter-spacing: -0.01em;
}
.station-note {
margin: 7px 0 0 38px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.045em;
text-transform: uppercase;
}
.legend {
position: fixed;
left: 26px;
bottom: 26px;
z-index: 15;
width: 235px;
padding: 15px 16px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel);
box-shadow: 0 10px 30px rgba(32, 55, 68, 0.08);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 10px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 8px;
color: var(--muted);
font-size: 11px;
line-height: 1.25;
}
.swatch {
flex: 0 0 auto;
width: 19px;
height: 11px;
border-radius: 3px;
}
.swatch.bracket {
background: var(--slate);
}
.swatch.load {
background: var(--coral);
}
.swatch.guide {
height: 0;
border-top: 3px solid var(--amber);
border-radius: 0;
}
.swatch.reference {
height: 0;
border-top: 2px dashed var(--blue);
border-radius: 0;
}
.disclaimer {
position: fixed;
right: 26px;
bottom: 26px;
z-index: 15;
width: min(440px, calc(100vw - 310px));
padding: 14px 16px;
border: 1px solid rgba(223, 101, 87, 0.22);
border-radius: 13px;
background: rgba(253, 247, 241, 0.93);
color: #674b45;
box-shadow: 0 10px 30px rgba(32, 55, 68, 0.07);
backdrop-filter: blur(12px);
pointer-events: none;
font-size: 11px;
line-height: 1.45;
}
.disclaimer strong {
display: block;
margin-bottom: 3px;
color: #7f4c43;
font-size: 10px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.hint {
position: fixed;
left: 50%;
bottom: 28px;
z-index: 12;
transform: translateX(-50%);
padding: 7px 11px;
border-radius: 999px;
background: rgba(32, 55, 68, 0.76);
color: #fff;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 900px) {
.hero {
top: 18px;
left: 18px;
max-width: 330px;
}
.controls {
top: 18px;
right: 18px;
}
.subtitle {
display: none;
}
.legend {
left: 18px;
bottom: 18px;
width: 205px;
}
.disclaimer {
right: 18px;
bottom: 18px;
width: calc(100vw - 260px);
}
.hint {
display: none;
}
}
@media (max-width: 650px) {
h1 {
max-width: 230px;
font-size: 29px;
}
.controls {
flex-direction: column;
}
button {
padding: 8px 10px;
font-size: 10px;
}
.station-card {
width: 176px;
padding: 9px 10px 10px;
}
.station-title {
font-size: 10px;
}
.station-note {
margin-left: 0;
margin-top: 6px;
font-size: 8px;
}
.legend {
display: none;
}
.disclaimer {
left: 18px;
right: 18px;
bottom: 18px;
width: auto;
font-size: 10px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive 3D comparison of two shelves with different bracket spacing"
></canvas>
<header class="hero">
<div class="eyebrow">Low-poly structural schematic</div>
<h1>Shelf support<br>& bracket study</h1>
<p class="subtitle">
Two identical shelves, the same symbolic loads, and different bracket
spacing. Deflection guides are deliberately exaggerated for visual
comparison only.
</p>
</header>
<nav class="controls" aria-label="Scene controls">
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-guides" type="button" aria-pressed="true">
Hide guides
</button>
</nav>
<div id="station-labels" aria-hidden="true">
<div class="station-card" id="label-a" style="--card-accent: #df6557">
<div class="station-top">
<span class="station-letter">A</span>
<h2 class="station-title">Wider bracket spacing</h2>
</div>
<p class="station-note">Same shelf · same load symbols</p>
</div>
<div class="station-card" id="label-b" style="--card-accent: #4d8291">
<div class="station-top">
<span class="station-letter">B</span>
<h2 class="station-title">Tighter bracket spacing</h2>
</div>
<p class="station-note">Same shelf · same load symbols</p>
</div>
</div>
<aside class="legend" aria-label="Visualization legend">
<div class="legend-title">Visual key</div>
<div class="legend-row">
<span class="swatch bracket"></span>
Shelf bracket / support
</div>
<div class="legend-row">
<span class="swatch load"></span>
Identical symbolic load
</div>
<div class="legend-row">
<span class="swatch guide"></span>
Exaggerated deflection guide
</div>
<div class="legend-row">
<span class="swatch reference"></span>
Undeformed reference line
</div>
</aside>
<aside class="disclaimer">
<strong>Conceptual comparison — not design guidance</strong>
The apparent sag is illustrative and deliberately exaggerated. It is not
calculated from material, load, connection, or building-code properties.
Do not use this visualization for structural design.
</aside>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera, and direct camera controls
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9eee9);
scene.fog = new THREE.Fog(0xe9eee9, 22, 42);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
target: new THREE.Vector3(0, 1.45, 0),
theta: 0.46,
phi: 1.10,
radius: 19.0
};
const defaultOrbit = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.005,
0.62,
1.38
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
13,
28
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#reset-view").addEventListener("click", () => {
orbit.theta = defaultOrbit.theta;
orbit.phi = defaultOrbit.phi;
orbit.radius = defaultOrbit.radius;
updateCamera();
});
// -------------------------------------------------------------------------
// Lighting and environment
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xffffff,
0x82948b,
2.0
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d8, 3.1);
keyLight.position.set(7, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbdd8ff, 1.15);
fillLight.position.set(-10, 7, -8);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 32),
new THREE.MeshStandardMaterial({
color: 0xdfe6df,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.19;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(40, 40, 0xaebdb4, 0xc4d0c8);
grid.position.y = -0.175;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
// -------------------------------------------------------------------------
// Shared materials
// -------------------------------------------------------------------------
const materials = {
woodTop: new THREE.MeshStandardMaterial({
color: 0xd9a45b,
roughness: 0.86,
metalness: 0,
flatShading: true
}),
woodSide: new THREE.MeshStandardMaterial({
color: 0xb8783d,
roughness: 0.9,
metalness: 0,
flatShading: true
}),
bracket: new THREE.MeshStandardMaterial({
color: 0x315366,
roughness: 0.66,
metalness: 0.12,
flatShading: true
}),
bracketLight: new THREE.MeshStandardMaterial({
color: 0x58798a,
roughness: 0.63,
metalness: 0.1,
flatShading: true
}),
accent: new THREE.MeshStandardMaterial({
color: 0x6e9bab,
roughness: 0.6,
metalness: 0.08,
flatShading: true
}),
platform: new THREE.MeshStandardMaterial({
color: 0xc8d3cc,
roughness: 0.95,
metalness: 0,
flatShading: true
}),
platformEdge: new THREE.MeshStandardMaterial({
color: 0xaebdb5,
roughness: 0.95,
metalness: 0,
flatShading: true
}),
load: new THREE.MeshStandardMaterial({
color: 0xdf6557,
roughness: 0.75,
metalness: 0,
flatShading: true
}),
loadStripe: new THREE.MeshStandardMaterial({
color: 0xf7e8cf,
roughness: 0.9,
metalness: 0,
flatShading: true
}),
guide: new THREE.MeshStandardMaterial({
color: 0xefa800,
emissive: 0x6b3d00,
emissiveIntensity: 0.18,
roughness: 0.55,
metalness: 0,
flatShading: true
})
};
const shelfMaterials = [
materials.woodSide,
materials.woodSide,
materials.woodTop,
materials.woodSide,
materials.woodSide,
materials.woodSide
];
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderBetween(
parent,
start,
end,
radius,
material,
radialSegments = 6
) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextSprite(text, accent = "#355668") {
const textCanvas = document.createElement("canvas");
textCanvas.width = 512;
textCanvas.height = 128;
const context = textCanvas.getContext("2d");
context.clearRect(0, 0, 512, 128);
context.fillStyle = "rgba(247, 250, 246, 0.95)";
context.beginPath();
context.roundRect(4, 4, 504, 120, 22);
context.fill();
context.strokeStyle = "rgba(53, 86, 104, 0.18)";
context.lineWidth = 3;
context.stroke();
context.fillStyle = accent;
context.font = "800 35px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(textCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(2.1, 0.525, 1);
return sprite;
}
// -------------------------------------------------------------------------
// Shelf geometry
// -------------------------------------------------------------------------
const SHELF_LENGTH = 7.4;
const SHELF_DEPTH = 1.65;
const SHELF_Y = 3.25;
const SHELF_THICKNESS = 0.22;
const SHELF_SEGMENTS = 18;
const LOAD_POSITIONS = [-2.35, 0, 2.35];
/**
* Illustrative only: this is a deliberately exaggerated drawing curve,
* not a structural or finite-element calculation.
*/
function makeDeflectionFunction(supportPositions, amplitude) {
const left = supportPositions[0];
const right = supportPositions[1];
const midpoint = (left + right) / 2;
const halfSpan = (right - left) / 2;
const leftEnd = -SHELF_LENGTH / 2;
const rightEnd = SHELF_LENGTH / 2;
return (x) => {
if (x < left) {
const u = THREE.MathUtils.clamp(
(x - leftEnd) / (left - leftEnd),
0,
1
);
return -amplitude * 0.22 * 4 * u * (1 - u);
}
if (x > right) {
const u = THREE.MathUtils.clamp(
(rightEnd - x) / (rightEnd - right),
0,
1
);
return -amplitude * 0.22 * 4 * u * (1 - u);
}
const normalized = (x - midpoint) / halfSpan;
return -amplitude * (1 - normalized * normalized);
};
}
function buildShelf(parent, supportPositions, amplitude) {
const deflection = makeDeflectionFunction(
supportPositions,
amplitude
);
const segmentLength = SHELF_LENGTH / SHELF_SEGMENTS;
for (let index = 0; index < SHELF_SEGMENTS; index += 1) {
const x =
-SHELF_LENGTH / 2 +
segmentLength * (index + 0.5);
const y = SHELF_Y + deflection(x);
const epsilon = 0.01;
const slope =
(deflection(x + epsilon) - deflection(x - epsilon)) /
(2 * epsilon);
const segment = new THREE.Mesh(
new THREE.BoxGeometry(
segmentLength + 0.025,
SHELF_THICKNESS,
SHELF_DEPTH
),
shelfMaterials
);
segment.position.set(x, y - SHELF_THICKNESS / 2, 0);
segment.rotation.z = Math.atan(slope);
segment.castShadow = true;
segment.receiveShadow = true;
parent.add(segment);
}
return deflection;
}
// -------------------------------------------------------------------------
// Bracket and support geometry
// -------------------------------------------------------------------------
function buildBracket(parent, x) {
const bracketGroup = new THREE.Group();
bracketGroup.position.x = x;
parent.add(bracketGroup);
// Vertical support post.
addBox(
bracketGroup,
new THREE.Vector3(0.16, 2.66, 0.16),
new THREE.Vector3(0, 1.45, -0.56),
materials.bracket
);
// Foot plate.
addBox(
bracketGroup,
new THREE.Vector3(0.48, 0.10, 0.42),
new THREE.Vector3(0, 0.18, -0.56),
materials.bracketLight
);
// Horizontal shelf arm.
addBox(
bracketGroup,
new THREE.Vector3(0.18, 0.16, 1.32),
new THREE.Vector3(0, 2.87, 0.08),
materials.bracket
);
// Small upper pad directly below the shelf.
addBox(
bracketGroup,
new THREE.Vector3(0.30, 0.10, 0.80),
new THREE.Vector3(0, 2.98, 0.06),
materials.accent
);
// Diagonal brace.
addCylinderBetween(
bracketGroup,
new THREE.Vector3(0, 2.02, -0.56),
new THREE.Vector3(0, 2.79, 0.57),
0.055,
materials.bracketLight,
5
);
// Low-poly bolt heads.
const boltGeometry = new THREE.CylinderGeometry(
0.07,
0.07,
0.05,
8
);
for (const y of [1.08, 2.45]) {
const bolt = new THREE.Mesh(boltGeometry, materials.accent);
bolt.rotation.x = Math.PI / 2;
bolt.position.set(0, y, -0.455);
bracketGroup.add(bolt);
}
// Small marker on the front edge identifying the support location.
addBox(
bracketGroup,
new THREE.Vector3(0.12, 0.12, 0.11),
new THREE.Vector3(0, SHELF_Y - 0.04, 0.84),
materials.accent
);
}
function buildSupportDimension(parent, supportPositions) {
const y = 0.145;
const z = 1.19;
const [left, right] = supportPositions;
const points = [
left, y, z,
right, y, z,
left, y, z - 0.12,
left, y, z + 0.12,
right, y, z - 0.12,
right, y, z + 0.12
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(points, 3)
);
const line = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color: 0x355668,
transparent: true,
opacity: 0.85
})
);
parent.add(line);
const label = makeTextSprite("BRACKET SPAN");
label.position.set(0, 0.42, 1.28);
parent.add(label);
}
// -------------------------------------------------------------------------
// Symbolic loads
// -------------------------------------------------------------------------
function buildLoad(parent, x, contactY) {
const loadGroup = new THREE.Group();
loadGroup.position.x = x;
parent.add(loadGroup);
// Downward arrow shaft.
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.46, 6),
materials.load
);
shaft.position.set(0, contactY + 0.38, 0);
shaft.castShadow = true;
loadGroup.add(shaft);
// Downward arrow head.
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.12, 0.24, 6),
materials.load
);
arrowHead.rotation.z = Math.PI;
arrowHead.position.set(0, contactY + 0.12, 0);
arrowHead.castShadow = true;
loadGroup.add(arrowHead);
// Symbolic load block.
const block = addBox(
loadGroup,
new THREE.Vector3(0.62, 0.54, 0.62),
new THREE.Vector3(0, contactY + 0.94, 0),
materials.load
);
block.rotation.y = 0.08;
// Cream identification band.
addBox(
loadGroup,
new THREE.Vector3(0.64, 0.12, 0.035),
new THREE.Vector3(0, contactY + 0.94, 0.316),
materials.loadStripe,
false
);
}
// -------------------------------------------------------------------------
// Exaggerated deflection guides
// -------------------------------------------------------------------------
function buildGuides(parent, deflection) {
const guideGroup = new THREE.Group();
parent.add(guideGroup);
const curvePoints = [];
for (let index = 0; index <= 54; index += 1) {
const x =
-SHELF_LENGTH / 2 +
(SHELF_LENGTH * index) / 54;
curvePoints.push(
new THREE.Vector3(
x,
SHELF_Y + deflection(x) + 0.075,
0.91
)
);
}
// Low-poly tube makes the conceptual guide highly visible.
const curve = new THREE.CatmullRomCurve3(curvePoints);
const guideTube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 54, 0.025, 5, false),
materials.guide
);
guideTube.castShadow = true;
guideGroup.add(guideTube);
// Straight undeformed reference.
const referenceGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(
-SHELF_LENGTH / 2,
SHELF_Y + 0.075,
0.94
),
new THREE.Vector3(
SHELF_LENGTH / 2,
SHELF_Y + 0.075,
0.94
)
]);
const reference = new THREE.Line(
referenceGeometry,
new THREE.LineDashedMaterial({
color: 0x6f91a3,
dashSize: 0.19,
gapSize: 0.13,
transparent: true,
opacity: 0.95
})
);
reference.computeLineDistances();
guideGroup.add(reference);
// Exaggerated vertical sag indicator at midspan.
const topY = SHELF_Y + 0.075;
const bottomY = SHELF_Y + deflection(0) + 0.075;
addCylinderBetween(
guideGroup,
new THREE.Vector3(0, bottomY, 1.01),
new THREE.Vector3(0, topY, 1.01),
0.018,
materials.guide,
5
);
const topArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.085, 0.22, 5),
materials.guide
);
topArrow.position.set(0, topY + 0.08, 1.01);
guideGroup.add(topArrow);
const bottomArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.085, 0.22, 5),
materials.guide
);
bottomArrow.rotation.z = Math.PI;
bottomArrow.position.set(0, bottomY - 0.08, 1.01);
guideGroup.add(bottomArrow);
return guideGroup;
}
// -------------------------------------------------------------------------
// Build the two identical shelf stations
// -------------------------------------------------------------------------
function buildStation({
positionX,
supports,
amplitude,
accent
}) {
const station = new THREE.Group();
station.position.x = positionX;
scene.add(station);
// Raised display platform.
addBox(
station,
new THREE.Vector3(8.15, 0.18, 3.35),
new THREE.Vector3(0, 0.02, 0),
materials.platform
);
addBox(
station,
new THREE.Vector3(8.15, 0.08, 0.10),
new THREE.Vector3(0, 0.07, 1.68),
materials.platformEdge,
false
);
supports.forEach((supportX) => {
buildBracket(station, supportX);
});
buildSupportDimension(station, supports);
const deflection = buildShelf(station, supports, amplitude);
LOAD_POSITIONS.forEach((loadX) => {
buildLoad(
station,
loadX,
SHELF_Y + deflection(loadX) + 0.03
);
});
const guides = buildGuides(station, deflection);
// Colored station identifier on the platform edge.
const stationMarker = new THREE.Mesh(
new THREE.BoxGeometry(0.62, 0.05, 0.15),
new THREE.MeshStandardMaterial({
color: accent,
roughness: 0.75,
flatShading: true
})
);
stationMarker.position.set(-3.42, 0.15, 1.62);
station.add(stationMarker);
return {
group: station,
guides,
labelAnchor: new THREE.Vector3(0, 4.72, 0)
};
}
const stationA = buildStation({
positionX: -4.25,
supports: [-2.65, 2.65],
amplitude: 0.72,
accent: 0xdf6557
});
const stationB = buildStation({
positionX: 4.25,
supports: [-1.45, 1.45],
amplitude: 0.27,
accent: 0x4d8291
});
// -------------------------------------------------------------------------
// HTML label projection
// -------------------------------------------------------------------------
const labelA = document.querySelector("#label-a");
const labelB = document.querySelector("#label-b");
const projectedPosition = new THREE.Vector3();
function positionLabel(element, station) {
projectedPosition.copy(station.labelAnchor);
station.group.localToWorld(projectedPosition);
projectedPosition.project(camera);
const x = (projectedPosition.x * 0.5 + 0.5) * window.innerWidth;
const y =
(-projectedPosition.y * 0.5 + 0.5) * window.innerHeight;
const visible = projectedPosition.z < 1;
element.style.opacity = visible ? "1" : "0";
element.style.transform =
`translate(-50%, -100%) translate(${x}px, ${y}px)`;
}
// -------------------------------------------------------------------------
// Guide toggle
// -------------------------------------------------------------------------
let guidesVisible = true;
const guideButton = document.querySelector("#toggle-guides");
guideButton.addEventListener("click", () => {
guidesVisible = !guidesVisible;
stationA.guides.visible = guidesVisible;
stationB.guides.visible = guidesVisible;
guideButton.textContent = guidesVisible
? "Hide guides"
: "Show guides";
guideButton.setAttribute(
"aria-pressed",
String(guidesVisible)
);
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
renderer.setAnimationLoop(() => {
positionLabel(labelA, stationA);
positionLabel(labelB, stationB);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```