Prompt specification
Build or customize the Three.js 3D scene "Compare supported and unsupported openings" 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: Compare supported and unsupported openings
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-supported-and-unsupported-openings-x2176
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows brick bonding and masonry load paths. Let users widen an opening in a simplified wall diagram. Show a schematic load path and flag missing lintel support without presenting the visualization as structural certification. Voxel style.
Working Three.js Starter (compare-supported-and-unsupported-openings-x2176):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Masonry Lab</title>
<style>
:root {
--bg: #080d18;
--panel: rgba(13, 21, 37, 0.88);
--panel-border: rgba(142, 183, 229, 0.16);
--text: #edf5ff;
--muted: #91a5bf;
--cyan: #62dcff;
--gold: #ffd166;
--green: #49e3ae;
--red: #ff5577;
--orange: #ee9b58;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 20;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 3px;
transform: rotate(-3deg);
}
.brand-mark i {
display: block;
border-radius: 2px;
background: var(--orange);
box-shadow: 0 0 16px rgba(238, 155, 88, 0.22);
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(8) {
background: var(--cyan);
}
.brand-mark i:nth-child(5),
.brand-mark i:nth-child(6) {
opacity: 0.48;
}
.brand h1 {
margin: 0;
font-size: clamp(18px, 2.2vw, 27px);
letter-spacing: -0.04em;
line-height: 1.05;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.educational-badge {
padding: 8px 11px;
border: 1px solid rgba(255, 209, 102, 0.3);
border-radius: 999px;
background: rgba(255, 209, 102, 0.08);
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.panel,
.status-card {
position: fixed;
z-index: 20;
border: 1px solid var(--panel-border);
background: var(--panel);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px);
}
.panel {
top: 96px;
left: 20px;
width: 316px;
padding: 18px;
border-radius: 18px;
}
.section-label {
margin-bottom: 11px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.opening-readout {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 14px;
margin-bottom: 11px;
}
.opening-readout strong {
font-size: 36px;
line-height: 1;
letter-spacing: -0.055em;
}
.opening-readout strong small {
margin-left: 3px;
color: var(--muted);
font-size: 15px;
font-weight: 600;
letter-spacing: 0;
}
.opening-readout span {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
text-align: right;
}
input[type="range"] {
--pct: 25%;
width: 100%;
height: 7px;
margin: 7px 0 11px;
border-radius: 999px;
appearance: none;
background:
linear-gradient(
90deg,
var(--cyan) 0,
var(--cyan) var(--pct),
#253248 var(--pct),
#253248 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 20px;
height: 20px;
border: 3px solid #08101d;
border-radius: 5px;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(98, 220, 255, 0.4), 0 0 18px rgba(98, 220, 255, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 15px;
height: 15px;
border: 3px solid #08101d;
border-radius: 5px;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(98, 220, 255, 0.4), 0 0 18px rgba(98, 220, 255, 0.3);
}
.range-labels {
display: flex;
justify-content: space-between;
color: #73859d;
font-size: 10px;
}
.presets {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 12px;
}
.preset,
.small-button {
border: 1px solid rgba(142, 183, 229, 0.16);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
color: #c9d8ea;
padding: 8px 9px;
font-size: 11px;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
color 150ms ease;
}
.preset:hover,
.preset.active,
.small-button:hover {
border-color: rgba(98, 220, 255, 0.45);
background: rgba(98, 220, 255, 0.09);
color: #fff;
}
.preset.alert:hover,
.preset.alert.active {
border-color: rgba(255, 85, 119, 0.48);
background: rgba(255, 85, 119, 0.1);
color: #ff9bb1;
}
.divider {
height: 1px;
margin: 17px 0;
background: rgba(142, 183, 229, 0.11);
}
.stat-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.stat {
padding: 10px;
border: 1px solid rgba(142, 183, 229, 0.1);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.stat span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stat strong {
font-size: 15px;
}
.toggles {
display: grid;
gap: 9px;
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
color: #c9d8ea;
font-size: 12px;
cursor: pointer;
}
.toggle input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch {
position: relative;
width: 35px;
height: 20px;
border-radius: 999px;
background: #2a3548;
transition: background 150ms ease;
}
.switch::after {
position: absolute;
top: 3px;
left: 3px;
width: 14px;
height: 14px;
border-radius: 50%;
background: #91a5bf;
content: "";
transition:
transform 150ms ease,
background 150ms ease;
}
.toggle input:checked + .switch {
background: rgba(98, 220, 255, 0.32);
}
.toggle input:checked + .switch::after {
transform: translateX(15px);
background: var(--cyan);
}
.bond-demo {
display: flex;
align-items: center;
gap: 13px;
}
.mini-bond {
width: 86px;
flex: 0 0 86px;
padding: 6px;
overflow: hidden;
border: 1px solid rgba(238, 155, 88, 0.25);
border-radius: 8px;
background: #101827;
}
.mini-row {
display: flex;
height: 11px;
margin-top: -1px;
transform: skewY(-4deg);
}
.mini-row:nth-child(even) {
transform: translateX(-13px) skewY(-4deg);
}
.mini-row i {
display: block;
width: 27px;
height: 11px;
border: 1px solid #4e251d;
background: #b96543;
}
.bond-copy strong {
display: block;
margin-bottom: 4px;
font-size: 12px;
}
.bond-copy span {
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.status-card {
top: 96px;
right: 20px;
width: 306px;
padding: 17px;
border-radius: 18px;
transition:
border-color 180ms ease,
background 180ms ease;
}
.status-card[data-state="safe"] {
border-color: rgba(73, 227, 174, 0.3);
}
.status-card[data-state="danger"] {
border-color: rgba(255, 85, 119, 0.55);
background: rgba(40, 15, 28, 0.9);
}
.status-heading {
display: flex;
align-items: center;
gap: 10px;
}
.status-dot {
width: 11px;
height: 11px;
flex: 0 0 11px;
border-radius: 3px;
background: var(--green);
box-shadow: 0 0 18px rgba(73, 227, 174, 0.6);
}
[data-state="danger"] .status-dot {
background: var(--red);
box-shadow: 0 0 18px rgba(255, 85, 119, 0.65);
}
.status-heading strong {
font-size: 13px;
letter-spacing: 0.04em;
}
.status-card p {
margin: 11px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.legend {
display: grid;
gap: 8px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid rgba(142, 183, 229, 0.1);
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: #aebed1;
font-size: 10px;
}
.swatch {
width: 19px;
height: 6px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 9px rgba(98, 220, 255, 0.35);
}
.swatch.brick {
background: var(--orange);
box-shadow: none;
}
.swatch.lintel {
background: var(--gold);
box-shadow: 0 0 9px rgba(255, 209, 102, 0.35);
}
.swatch.support {
background: var(--green);
box-shadow: 0 0 9px rgba(73, 227, 174, 0.35);
}
.swatch.danger {
background: var(--red);
box-shadow: 0 0 9px rgba(255, 85, 119, 0.35);
}
.labels {
position: fixed;
z-index: 12;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
padding: 6px 9px;
border: 1px solid rgba(142, 183, 229, 0.2);
border-radius: 7px;
background: rgba(7, 13, 24, 0.82);
color: #dce9f8;
font-size: 10px;
font-weight: 650;
line-height: 1.25;
white-space: nowrap;
transform: translate(-50%, -50%);
backdrop-filter: blur(7px);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.22);
}
.world-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 13px;
background: rgba(142, 183, 229, 0.35);
content: "";
}
.world-label strong {
color: var(--cyan);
}
.world-label.warning {
border-color: rgba(255, 85, 119, 0.6);
color: #ffb1c1;
background: rgba(50, 10, 25, 0.92);
font-weight: 850;
letter-spacing: 0.05em;
}
.world-label.warning strong {
color: var(--red);
}
.bottom-note {
position: fixed;
z-index: 25;
right: 20px;
bottom: 16px;
left: 20px;
padding: 10px 14px;
border: 1px solid rgba(255, 209, 102, 0.18);
border-radius: 11px;
background: rgba(10, 15, 27, 0.87);
color: #c5bfa9;
font-size: 10px;
line-height: 1.45;
text-align: center;
backdrop-filter: blur(12px);
pointer-events: none;
}
.bottom-note strong {
color: var(--gold);
}
.camera-help {
position: fixed;
z-index: 10;
right: 20px;
bottom: 75px;
color: rgba(193, 210, 230, 0.55);
font-size: 9px;
letter-spacing: 0.04em;
text-align: right;
pointer-events: none;
}
@media (max-width: 760px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.brand p {
display: none;
}
.educational-badge {
padding: 7px 8px;
font-size: 8px;
}
.status-card {
top: 72px;
right: 10px;
width: 225px;
padding: 12px;
}
.status-card p,
.legend {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 66px;
left: 10px;
width: auto;
max-height: 39vh;
padding: 13px;
overflow-y: auto;
border-radius: 14px;
}
.opening-readout strong {
font-size: 28px;
}
.bond-demo,
.camera-help {
display: none;
}
.divider {
margin: 12px 0;
}
.bottom-note {
right: 10px;
bottom: 9px;
left: 10px;
padding: 8px 10px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<h1>Voxel Masonry Lab</h1>
<p>Bonding, openings & schematic load paths</p>
</div>
</div>
<div class="educational-badge">Educational schematic</div>
</header>
<aside class="panel" aria-label="Masonry controls">
<div class="section-label">Opening width</div>
<div class="opening-readout">
<strong><span id="widthValue">3.2</span><small>m</small></strong>
<span>Drag to widen</span>
</div>
<label for="openingWidth" class="section-label" style="margin-bottom: 4px;">
Clear opening
</label>
<input
id="openingWidth"
type="range"
min="0.8"
max="9.6"
step="0.1"
value="3.2"
aria-label="Opening width in metres"
/>
<div class="range-labels">
<span>0.8 m</span>
<span>9.6 m</span>
</div>
<div class="presets">
<button class="preset" data-width="2.4">2.4 m</button>
<button class="preset" data-width="5.0">5.0 m</button>
<button class="preset alert" data-width="9.6">Wide / alert</button>
</div>
<div class="divider"></div>
<div class="section-label">Schematic values</div>
<div class="stat-grid">
<div class="stat">
<span>Side pier</span>
<strong id="bearingValue">3.40 m</strong>
</div>
<div class="stat">
<span>Lintel length</span>
<strong id="lintelValue">4.60 m</strong>
</div>
<div class="stat">
<span>Bond pattern</span>
<strong>Running bond</strong>
</div>
<div class="stat">
<span>Model threshold</span>
<strong>0.30 m / side</strong>
</div>
</div>
<div class="divider"></div>
<div class="section-label">Display</div>
<div class="toggles">
<label class="toggle">
<span>Schematic load path</span>
<input id="showPaths" type="checkbox" checked />
<span class="switch" aria-hidden="true"></span>
</label>
<label class="toggle">
<span>World labels</span>
<input id="showLabels" type="checkbox" checked />
<span class="switch" aria-hidden="true"></span>
</label>
</div>
<div class="divider"></div>
<div class="section-label">Brick bond</div>
<div class="bond-demo">
<div class="mini-bond" aria-hidden="true">
<div class="mini-row"><i></i><i></i><i></i></div>
<div class="mini-row"><i></i><i></i><i></i></div>
<div class="mini-row"><i></i><i></i><i></i></div>
</div>
<div class="bond-copy">
<strong>Alternating half-lap</strong>
<span>
Successive voxel courses are offset, exposing the running-bond
relationship around the opening.
</span>
</div>
</div>
</aside>
<aside class="status-card" id="statusCard" data-state="safe" aria-live="polite">
<div class="status-heading">
<span class="status-dot"></span>
<strong id="statusTitle">LINTEL SUPPORT PRESENT</strong>
</div>
<p id="statusDetail">
Both sides meet the schematic 0.30 m side-pier threshold.
</p>
<div class="legend">
<div class="legend-item"><i class="swatch brick"></i> Masonry bond</div>
<div class="legend-item"><i class="swatch lintel"></i> Lintel / beam</div>
<div class="legend-item"><i class="swatch support"></i> Bearing support</div>
<div class="legend-item"><i class="swatch"></i> Schematic load path</div>
<div class="legend-item"><i class="swatch danger"></i> Missing support</div>
</div>
</aside>
<div class="labels" id="labels">
<div class="world-label" id="openingLabel"></div>
<div class="world-label" id="lintelLabel"></div>
<div class="world-label" id="supportLabel"></div>
<div class="world-label" id="loadLabel">Applied load ↓</div>
<div class="world-label warning" id="warningLabel">MISSING LINTEL SUPPORT</div>
</div>
<div class="camera-help">
Drag to orbit · Wheel / pinch to zoom · Arrow keys to rotate
</div>
<div class="bottom-note">
<strong>Conceptual teaching visualization only.</strong>
The alert and dimensions are illustrative, not structural analysis, design,
certification, or a substitute for assessment by a qualified engineer.
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants for the deliberately simplified teaching model
// -------------------------------------------------------------------------
const WALL_WIDTH = 10;
const WALL_HEIGHT = 3.56;
const WALL_THICKNESS = 0.64;
const BRICK_LENGTH = 0.92;
const COURSE_HEIGHT = 0.22;
const OPENING_HEIGHT = 2.20;
const LINTEL_DEPTH = 0.26;
const MIN_SCHEMATIC_BEARING = 0.30;
const NOMINAL_BEARING_LENGTH = 0.65;
const COLORS = {
background: 0x080d18,
grid: 0x243754,
ground: 0x0d1524,
brick: [
0xb96543,
0xc8754c,
0xa95438,
0xd17d54,
0xb96040,
0xc36a46
],
mortar: 0x2a2026,
foundation: 0x44516a,
lintel: 0xf0b75e,
lintelDanger: 0xff617d,
support: 0x49e3ae,
load: 0xffd166,
path: 0x62dcff,
danger: 0xff5577
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(COLORS.background);
scene.fog = new THREE.Fog(COLORS.background, 18, 34);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
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;
document.querySelector("#scene").appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional masonry wall schematic"
);
// -------------------------------------------------------------------------
// Lighting and environment
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xb7d8ff, 0x24172b, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d6, 3.2);
sun.position.set(5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -6;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0005;
scene.add(sun);
const cyanLight = new THREE.PointLight(0x4ccfff, 24, 15, 2);
cyanLight.position.set(-5, 4, 4);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xff9f50, 18, 12, 2);
amberLight.position.set(5, 3, -1);
scene.add(amberLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({
color: COLORS.ground,
roughness: 0.95,
metalness: 0.03
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.36;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(
32,
32,
COLORS.grid,
0x142039
);
grid.position.y = -0.345;
grid.material.transparent = true;
grid.material.opacity = 0.45;
scene.add(grid);
// Decorative distant voxel blocks add depth without affecting the model.
const backdropGroup = new THREE.Group();
const backdropMaterial = new THREE.MeshStandardMaterial({
color: 0x142039,
roughness: 0.85,
metalness: 0.08
});
const backdropPositions = [
[-7.4, 0.25, -5.3, 1.2, 1.2, 1.2],
[-6.3, 0.55, -5.8, 0.8, 2.0, 0.8],
[6.6, 0.45, -5.8, 1.6, 1.6, 1.0],
[7.8, 0.15, -4.8, 0.8, 0.8, 0.8],
[4.8, 0.1, -6.4, 0.7, 0.7, 0.7]
];
for (const [x, y, z, sx, sy, sz] of backdropPositions) {
const block = new THREE.Mesh(
new THREE.BoxGeometry(sx, sy, sz),
backdropMaterial
);
block.position.set(x, y, z);
block.rotation.y = (x + z) * 0.08;
backdropGroup.add(block);
}
scene.add(backdropGroup);
// -------------------------------------------------------------------------
// Foundation
// -------------------------------------------------------------------------
const foundationGroup = new THREE.Group();
scene.add(foundationGroup);
for (let i = 0; i < 12; i++) {
const block = new THREE.Mesh(
new THREE.BoxGeometry(0.81, 0.30, 1.18),
new THREE.MeshStandardMaterial({
color: i % 3 === 0 ? 0x4b5972 : COLORS.foundation,
roughness: 0.88
})
);
block.position.set(-4.58 + i * 0.835, -0.17, 0);
block.castShadow = true;
block.receiveShadow = true;
foundationGroup.add(block);
}
// -------------------------------------------------------------------------
// Dynamic model groups
// -------------------------------------------------------------------------
const wallGroup = new THREE.Group();
const pathGroup = new THREE.Group();
scene.add(wallGroup, pathGroup);
let openingWidth = Number(
document.querySelector("#openingWidth").value
);
let currentState = {
supported: true,
sidePier: 0,
supportLength: 0,
openingLeft: 0,
openingRight: 0,
lintelLength: 0
};
let routes = [];
const anchors = {
opening: new THREE.Vector3(),
lintel: new THREE.Vector3(),
support: new THREE.Vector3(),
load: new THREE.Vector3(-3.8, 4.45, 0.75),
warning: new THREE.Vector3()
};
function clearGroup(group) {
group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach((material) => material.dispose());
}
});
group.clear();
}
function hashColor(row, index, side) {
const value = Math.abs(
Math.sin(row * 91.17 + index * 47.31 + side * 13.7)
);
return COLORS.brick[Math.floor(value * COLORS.brick.length) % COLORS.brick.length];
}
function makeBox(
width,
height,
depth,
color,
position,
options = {}
) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0.02,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.copy(position);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
return mesh;
}
// -------------------------------------------------------------------------
// Rebuild the masonry wall, lintel, and schematic supports
// -------------------------------------------------------------------------
function rebuildWall() {
clearGroup(wallGroup);
routes = [];
const halfWall = WALL_WIDTH / 2;
const openingHalf = openingWidth / 2;
const openingLeft = -openingHalf;
const openingRight = openingHalf;
const sidePier = (WALL_WIDTH - openingWidth) / 2;
const supported = sidePier >= MIN_SCHEMATIC_BEARING - 1e-6;
const supportLength = supported
? Math.min(NOMINAL_BEARING_LENGTH, sidePier)
: 0;
const lintelLength = openingWidth + NOMINAL_BEARING_LENGTH * 2;
currentState = {
supported,
sidePier,
supportLength,
openingLeft,
openingRight,
lintelLength
};
const brickEntries = [];
const openingRows = Math.round(OPENING_HEIGHT / COURSE_HEIGHT);
const totalRows = 15;
for (let row = 0; row < totalRows; row++) {
const bottom =
row < openingRows
? row * COURSE_HEIGHT
: OPENING_HEIGHT +
LINTEL_DEPTH +
(row - openingRows) * COURSE_HEIGHT;
const offset = row % 2 === 0 ? 0 : BRICK_LENGTH / 2;
let cursor = -halfWall - offset;
let brickIndex = 0;
while (cursor < halfWall) {
let start = Math.max(cursor, -halfWall);
let end = Math.min(cursor + BRICK_LENGTH, halfWall);
if (end > start) {
const clipped = [];
if (row < openingRows) {
if (end <= openingLeft || start >= openingRight) {
clipped.push([start, end]);
} else {
if (start < openingLeft) {
clipped.push([start, Math.min(end, openingLeft)]);
}
if (end > openingRight) {
clipped.push([Math.max(start, openingRight), end]);
}
}
} else {
clipped.push([start, end]);
}
for (const [segmentStart, segmentEnd] of clipped) {
const length = segmentEnd - segmentStart;
if (length <= 0.035) continue;
brickEntries.push({
x: (segmentStart + segmentEnd) / 2,
y: bottom + COURSE_HEIGHT / 2,
z: 0,
sx: Math.max(0.03, length - 0.025),
sy: COURSE_HEIGHT - 0.013,
sz: WALL_THICKNESS,
color: hashColor(row, brickIndex, cursor)
});
}
}
cursor += BRICK_LENGTH;
brickIndex++;
}
}
// One instanced mesh keeps the many small voxel bricks inexpensive.
const brickGeometry = new THREE.BoxGeometry(1, 1, 1);
const brickMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88,
metalness: 0.015
});
const bricks = new THREE.InstancedMesh(
brickGeometry,
brickMaterial,
brickEntries.length
);
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion();
const position = new THREE.Vector3();
const scale = new THREE.Vector3();
brickEntries.forEach((brick, index) => {
position.set(brick.x, brick.y, brick.z);
scale.set(brick.sx, brick.sy, brick.sz);
matrix.compose(position, quaternion, scale);
bricks.setMatrixAt(index, matrix);
bricks.setColorAt(index, new THREE.Color(brick.color));
});
bricks.instanceMatrix.needsUpdate = true;
if (bricks.instanceColor) bricks.instanceColor.needsUpdate = true;
bricks.castShadow = true;
bricks.receiveShadow = true;
wallGroup.add(bricks);
// Blocky lintel made from adjacent voxel segments.
const lintelColor = supported
? COLORS.lintel
: COLORS.lintelDanger;
const lintelSegmentCount = Math.max(
5,
Math.ceil(lintelLength / 0.70)
);
const lintelSegmentLength =
lintelLength / lintelSegmentCount;
for (let i = 0; i < lintelSegmentCount; i++) {
const x =
-lintelLength / 2 +
lintelSegmentLength * (i + 0.5);
const segment = makeBox(
Math.max(0.02, lintelSegmentLength - 0.018),
LINTEL_DEPTH,
0.78,
lintelColor,
new THREE.Vector3(
x,
OPENING_HEIGHT + LINTEL_DEPTH / 2,
0
),
{
roughness: 0.58,
emissive: supported ? 0x6a3908 : 0x6b1022,
emissiveIntensity: supported ? 0.18 : 0.42
}
);
wallGroup.add(segment);
}
// Green bearing blocks are intentionally omitted when the side pier
// falls below the teaching model's illustrative threshold.
if (supported) {
const supportLeftCenter =
openingLeft - supportLength / 2;
const supportRightCenter =
openingRight + supportLength / 2;
for (const x of [supportLeftCenter, supportRightCenter]) {
const support = makeBox(
supportLength,
0.18,
0.82,
COLORS.support,
new THREE.Vector3(x, OPENING_HEIGHT - 0.09, 0),
{
roughness: 0.48,
emissive: 0x0b6f51,
emissiveIntensity: 0.42
}
);
wallGroup.add(support);
}
} else {
// Pixel X markers identify the omitted support locations.
for (const x of [openingLeft - 0.10, openingRight + 0.10]) {
for (let i = 0; i < 5; i++) {
const offset = (i - 2) * 0.052;
const diagonalA = makeBox(
0.065,
0.065,
0.065,
COLORS.danger,
new THREE.Vector3(
x + offset,
OPENING_HEIGHT + LINTEL_DEPTH / 2 + offset,
0.48
),
{
emissive: COLORS.danger,
emissiveIntensity: 1.2,
castShadow: false
}
);
const diagonalB = makeBox(
0.065,
0.065,
0.065,
COLORS.danger,
new THREE.Vector3(
x + offset,
OPENING_HEIGHT + LINTEL_DEPTH / 2 - offset,
0.48
),
{
emissive: COLORS.danger,
emissiveIntensity: 1.2,
castShadow: false
}
);
wallGroup.add(diagonalA, diagonalB);
}
}
}
rebuildPaths();
updateInterface();
updateAnchors();
}
// -------------------------------------------------------------------------
// Voxel-style routes and animated flow packets
// -------------------------------------------------------------------------
function addRoute(points, color, speed = 1.45, width = 0.055) {
const vectors = points.map((point) => new THREE.Vector3(...point));
const lengths = [];
let totalLength = 0;
for (let i = 0; i < vectors.length - 1; i++) {
const length = vectors[i].distanceTo(vectors[i + 1]);
lengths.push(length);
totalLength += length;
const midpoint = vectors[i]
.clone()
.add(vectors[i + 1])
.multiplyScalar(0.5);
const direction = vectors[i + 1]
.clone()
.sub(vectors[i])
.normalize();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 1.25,
transparent: true,
opacity: 0.82,
roughness: 0.35,
metalness: 0.05
});
const segment = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
material
);
segment.position.copy(midpoint);
segment.scale.set(width, length, width);
segment.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
segment.castShadow = false;
pathGroup.add(segment);
}
const packet = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.13, 0.13),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
packet.castShadow = false;
pathGroup.add(packet);
routes.push({
vectors,
lengths,
totalLength,
packet,
speed,
offset: routes.length * 0.41
});
}
function addLoadArrow(x) {
const arrowMaterial = new THREE.MeshStandardMaterial({
color: COLORS.load,
emissive: COLORS.load,
emissiveIntensity: 0.8,
roughness: 0.4
});
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(0.065, 1.05, 0.065),
arrowMaterial
);
shaft.position.set(x, 4.38, 0.52);
pathGroup.add(shaft);
// Three decreasing bars form a pixel arrowhead.
const headWidths = [0.42, 0.28, 0.14];
for (let i = 0; i < headWidths.length; i++) {
const head = new THREE.Mesh(
new THREE.BoxGeometry(headWidths[i], 0.07, 0.07),
arrowMaterial
);
head.position.set(x, 3.78 - i * 0.09, 0.52);
pathGroup.add(head);
}
}
function rebuildPaths() {
clearGroup(pathGroup);
routes = [];
const { supported, supportLength, openingLeft, openingRight } =
currentState;
// Distributed applied loads.
addLoadArrow(-3.8);
addLoadArrow(0);
addLoadArrow(3.8);
// Central route from the applied load to the lintel.
addRoute(
[
[0, 5.02, 0.48],
[0, 3.56, 0.48],
[0, 2.34, 0.48]
],
COLORS.load,
1.7,
0.06
);
// Outer compression routes through the masonry piers.
addRoute(
[
[-3.8, 3.56, 0.48],
[-3.8, -0.03, 0.48]
],
COLORS.path,
1.35
);
addRoute(
[
[3.8, 3.56, 0.48],
[3.8, -0.03, 0.48]
],
COLORS.path,
1.35
);
if (supported) {
const leftX = openingLeft - supportLength / 2;
const rightX = openingRight + supportLength / 2;
addRoute(
[
[0, 2.34, 0.48],
[leftX, 2.34, 0.48],
[leftX, -0.03, 0.48]
],
COLORS.path,
1.55
);
addRoute(
[
[0, 2.34, 0.48],
[rightX, 2.34, 0.48],
[rightX, -0.03, 0.48]
],
COLORS.path,
1.55
);
} else {
// The route reaches the lintel but does not continue down through
// an omitted bearing block.
addRoute(
[
[0, 2.34, 0.48],
[openingLeft - 0.10, 2.34, 0.48]
],
COLORS.danger,
1.55,
0.065
);
addRoute(
[
[0, 2.34, 0.48],
[openingRight + 0.10, 2.34, 0.48]
],
COLORS.danger,
1.55,
0.065
);
}
}
function updateRoutePackets(elapsed) {
for (const route of routes) {
let distance =
(elapsed * route.speed + route.offset) % route.totalLength;
for (let i = 0; i < route.lengths.length; i++) {
if (distance <= route.lengths[i]) {
const t =
route.lengths[i] === 0
? 0
: distance / route.lengths[i];
route.packet.position.lerpVectors(
route.vectors[i],
route.vectors[i + 1],
t
);
break;
}
distance -= route.lengths[i];
}
}
}
// -------------------------------------------------------------------------
// Interface and labels
// -------------------------------------------------------------------------
const widthInput = document.querySelector("#openingWidth");
const widthValue = document.querySelector("#widthValue");
const bearingValue = document.querySelector("#bearingValue");
const lintelValue = document.querySelector("#lintelValue");
const statusCard = document.querySelector("#statusCard");
const statusTitle = document.querySelector("#statusTitle");
const statusDetail = document.querySelector("#statusDetail");
const showPaths = document.querySelector("#showPaths");
const showLabels = document.querySelector("#showLabels");
const openingLabel = document.querySelector("#openingLabel");
const lintelLabel = document.querySelector("#lintelLabel");
const supportLabel = document.querySelector("#supportLabel");
const warningLabel = document.querySelector("#warningLabel");
function updateSliderFill() {
const min = Number(widthInput.min);
const max = Number(widthInput.max);
const percent = ((openingWidth - min) / (max - min)) * 100;
widthInput.style.setProperty("--pct", `${percent}%`);
}
function updateInterface() {
const { supported, sidePier, lintelLength } = currentState;
widthValue.textContent = openingWidth.toFixed(1);
bearingValue.textContent = `${sidePier.toFixed(2)} m`;
lintelValue.textContent = `${lintelLength.toFixed(2)} m`;
statusCard.dataset.state = supported ? "safe" : "danger";
if (supported) {
statusTitle.textContent = "LINTEL SUPPORT PRESENT";
statusDetail.textContent =
"Both sides meet the illustrative 0.30 m side-pier threshold in this teaching model.";
} else {
statusTitle.textContent = "MISSING LINTEL SUPPORT";
statusDetail.textContent =
`The remaining ${sidePier.toFixed(2)} m side pier is below the model's 0.30 m threshold. Bearing blocks are omitted and the load path is interrupted.`;
}
document.querySelectorAll(".preset").forEach((button) => {
button.classList.toggle(
"active",
Math.abs(Number(button.dataset.width) - openingWidth) < 0.01
);
});
updateSliderFill();
}
function updateAnchors() {
const {
supported,
supportLength,
openingLeft,
openingRight
} = currentState;
anchors.opening.set(0, 1.02, 0.72);
anchors.lintel.set(0, 2.77, 0.78);
if (supported) {
anchors.support.set(
openingRight + supportLength / 2,
2.22,
0.82
);
} else {
anchors.support.set(openingRight + 0.10, 2.22, 0.82);
}
anchors.warning.set(0, 3.12, 0.95);
openingLabel.innerHTML =
`Opening <strong>${openingWidth.toFixed(1)} m</strong>`;
lintelLabel.innerHTML = "Lintel / beam";
supportLabel.innerHTML = supported
? `Schematic bearing <strong>${currentState.sidePier.toFixed(2)} m</strong>`
: `Pier <strong>${currentState.sidePier.toFixed(2)} m</strong>`;
warningLabel.style.display = supported ? "none" : "";
}
function placeLabel(element, worldPosition, visible = true) {
if (!visible || !showLabels.checked) {
element.style.display = "none";
return;
}
const projected = worldPosition.clone().project(camera);
if (projected.z < -1 || projected.z > 1) {
element.style.display = "none";
return;
}
const x = (projected.x * 0.5 + 0.5) * renderer.domElement.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * renderer.domElement.clientHeight;
element.style.display = "";
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateWorldLabels() {
placeLabel(openingLabel, anchors.opening);
placeLabel(lintelLabel, anchors.lintel);
placeLabel(supportLabel, anchors.support);
placeLabel(
document.querySelector("#loadLabel"),
anchors.load
);
placeLabel(
warningLabel,
anchors.warning,
!currentState.supported
);
}
widthInput.addEventListener("input", () => {
openingWidth = Number(widthInput.value);
rebuildWall();
});
document.querySelectorAll(".preset").forEach((button) => {
button.addEventListener("click", () => {
openingWidth = Number(button.dataset.width);
widthInput.value = openingWidth;
rebuildWall();
});
});
showPaths.addEventListener("change", () => {
pathGroup.visible = showPaths.checked;
});
showLabels.addEventListener("change", updateWorldLabels);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, wheel zoom, pinch zoom, keyboard access
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.78, 0);
let cameraYaw = 0.48;
let cameraPitch = 0.34;
let cameraRadius = window.innerWidth < 760 ? 19.5 : 15.2;
let initialRadius = cameraRadius;
const pointers = new Map();
let previousPinchDistance = 0;
function updateCamera() {
const horizontalRadius =
Math.cos(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontalRadius,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontalRadius
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraYaw = 0.48;
cameraPitch = 0.34;
cameraRadius = window.innerWidth < 760 ? 19.5 : 15.2;
initialRadius = cameraRadius;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(
a.x - b.x,
a.y - b.y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
if (pointers.size === 1) {
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.005,
0.10,
1.12
);
pointer.x = event.clientX;
pointer.y = event.clientY;
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0 && distance > 0) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (previousPinchDistance / distance),
9,
28
);
}
previousPinchDistance = distance;
pointer.x = event.clientX;
pointer.y = event.clientY;
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
9,
28
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraYaw += 0.08;
break;
case "ArrowRight":
cameraYaw -= 0.08;
break;
case "ArrowUp":
cameraPitch = Math.min(1.12, cameraPitch + 0.06);
break;
case "ArrowDown":
cameraPitch = Math.max(0.1, cameraPitch - 0.06);
break;
case "+":
case "=":
cameraRadius = Math.max(9, cameraRadius - 0.6);
break;
case "-":
cameraRadius = Math.min(28, cameraRadius + 0.6);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateRoutePackets(elapsed);
// A subtle breathing effect on the applied-load arrows.
pathGroup.children.forEach((child, index) => {
if (child.material && child.material.emissiveIntensity !== undefined) {
if (index % 3 === 0) {
child.material.emissiveIntensity =
0.72 + Math.sin(elapsed * 3 + index) * 0.15;
}
}
});
updateCamera();
updateWorldLabels();
renderer.render(scene, camera);
}
resize();
rebuildWall();
updateCamera();
animate();
</script>
</body>
</html>
```