Prompt specification
Build or customize the Three.js 3D scene "Timber shelter with braced wall bays" 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: Timber shelter with braced wall bays
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/timber-shelter-with-braced-wall-bays-x2227
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Create a small timber shelter with repeated wall bays, roof beams, and diagonal braces. Highlight the connected path from roof loads through braced frames to footings.
Working Three.js Starter (timber-shelter-with-braced-wall-bays-x2227):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Timber Shelter — Connected Load Path</title>
<style>
:root {
--ink: #173238;
--muted: #607276;
--panel: rgba(250, 252, 248, 0.88);
--line: rgba(23, 50, 56, 0.13);
--cyan: #11bfd1;
--amber: #f4a83a;
--coral: #ef5b68;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe9e7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage,
#stage canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.75);
box-shadow:
0 14px 40px rgba(38, 63, 62, 0.12),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 17px;
border-radius: 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #527075;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 23px;
height: 2px;
background: var(--cyan);
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.intro p {
margin: 11px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.legend {
left: 22px;
bottom: 22px;
width: min(390px, calc(100vw - 44px));
padding: 15px 17px;
border-radius: 15px;
}
.legend-title {
margin-bottom: 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
color: #64777a;
}
.legend-row {
display: grid;
grid-template-columns: 18px 1fr;
gap: 9px;
align-items: start;
margin: 7px 0;
font-size: 11px;
line-height: 1.35;
}
.swatch {
width: 17px;
height: 5px;
margin-top: 5px;
border-radius: 4px;
background: var(--cyan);
box-shadow: 0 0 9px color-mix(in srgb, var(--cyan), transparent 35%);
}
.swatch.amber {
background: var(--amber);
box-shadow: 0 0 9px color-mix(in srgb, var(--amber), transparent 35%);
}
.swatch.coral {
background: var(--coral);
box-shadow: 0 0 9px color-mix(in srgb, var(--coral), transparent 35%);
}
.route-strip {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 5px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #38575c;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.route-strip b {
color: #8a999a;
font-size: 11px;
}
.controls {
right: 22px;
bottom: 22px;
display: flex;
gap: 8px;
padding: 8px;
border-radius: 14px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 9px;
padding: 10px 13px;
background: rgba(255, 255, 255, 0.68);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease,
border-color 160ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(23, 50, 56, 0.25);
background: white;
}
button:active {
transform: translateY(0);
}
.hint {
position: fixed;
z-index: 8;
top: 24px;
right: 24px;
padding: 9px 12px;
border-radius: 999px;
background: rgba(250, 252, 248, 0.72);
border: 1px solid rgba(255, 255, 255, 0.75);
color: #637579;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.callout {
position: fixed;
z-index: 7;
pointer-events: none;
transform: translate(-50%, calc(-100% - 12px));
padding: 7px 10px 7px 12px;
border-left: 3px solid var(--cyan);
border-radius: 0 8px 8px 0;
background: rgba(250, 252, 248, 0.9);
box-shadow: 0 7px 22px rgba(31, 56, 57, 0.12);
white-space: nowrap;
}
.callout::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 13px;
background: rgba(23, 50, 56, 0.35);
}
.callout strong {
display: block;
color: #19373d;
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.callout small {
display: block;
margin-top: 2px;
color: #6d7f82;
font-size: 9px;
}
.callout.amber {
border-left-color: var(--amber);
}
.callout.coral {
border-left-color: var(--coral);
}
.callout.hidden {
display: none;
}
@media (max-width: 720px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.intro p {
display: none;
}
.legend {
left: 12px;
bottom: 76px;
width: calc(100vw - 24px);
padding: 11px 13px;
}
.legend-title,
.legend-row:nth-of-type(2) {
display: none;
}
.route-strip {
margin-top: 7px;
padding-top: 7px;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
justify-content: stretch;
}
button {
flex: 1;
padding: 10px 8px;
font-size: 9px;
}
.hint {
display: none;
}
.callout {
transform: translate(-50%, calc(-100% - 8px));
padding: 5px 7px;
}
.callout small {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section class="panel intro">
<div class="eyebrow">Structural study / 01</div>
<h1>Timber shelter<br>connected load path</h1>
<p>
Three repeated wall bays support a gabled roof. Cyan marks applied roof
actions, amber traces gravity through the rafter and post, and coral
shows the diagonal-brace route into the rear footing.
</p>
</section>
<aside class="panel legend">
<div class="legend-title">Load-path key</div>
<div class="legend-row">
<span class="swatch"></span>
<span><strong>Roof load</strong> — applied gravity and lateral action</span>
</div>
<div class="legend-row">
<span class="swatch amber"></span>
<span><strong>Gravity route</strong> — rafter → eave → post → footing</span>
</div>
<div class="legend-row">
<span class="swatch coral"></span>
<span><strong>Brace route</strong> — frame action → diagonal → footing</span>
</div>
<div class="route-strip">
<span>Load</span><b>→</b>
<span>Rafter</span><b>→</b>
<span>Braced frame</span><b>→</b>
<span>Footing</span>
</div>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<nav class="panel controls" aria-label="Scene controls">
<button id="flowButton" type="button">Pause flow</button>
<button id="focusButton" type="button">Focus route</button>
<button id="resetButton" type="button">Overview</button>
</nav>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional timber shelter and load path"
);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe9e7);
scene.fog = new THREE.Fog(0xdfe9e7, 19, 40);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemi = new THREE.HemisphereLight(0xeaf7ff, 0x6c735e, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4dd, 3.1);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
sun.shadow.bias = -0.0002;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xb8e5ef, 0.65);
rim.position.set(9, 6, -10);
scene.add(rim);
// -------------------------------------------------------------------------
// Shared geometry and materials
// -------------------------------------------------------------------------
const V = (x, y, z) => new THREE.Vector3(x, y, z);
const Y_AXIS = V(0, 1, 0);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const unitCylinder = new THREE.CylinderGeometry(1, 1, 1, 8);
const coneGeometry = new THREE.ConeGeometry(1, 1, 7);
const wood = new THREE.MeshStandardMaterial({
color: 0x8a5a38,
roughness: 0.88,
metalness: 0,
flatShading: true
});
const woodLight = new THREE.MeshStandardMaterial({
color: 0xb27747,
roughness: 0.82,
metalness: 0,
flatShading: true
});
const woodDark = new THREE.MeshStandardMaterial({
color: 0x67442f,
roughness: 0.92,
metalness: 0,
flatShading: true
});
const concrete = new THREE.MeshStandardMaterial({
color: 0xa8aaa1,
roughness: 0.95,
flatShading: true
});
const slabMaterial = new THREE.MeshStandardMaterial({
color: 0xc9c5b4,
roughness: 0.94,
flatShading: true
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x364347,
roughness: 0.52,
metalness: 0.72,
flatShading: true
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x70939a,
roughness: 0.38,
metalness: 0.06,
transparent: true,
opacity: 0.14,
depthWrite: false,
side: THREE.DoubleSide
});
const pathCyan = new THREE.MeshBasicMaterial({
color: 0x11bfd1,
toneMapped: false
});
const pathAmber = new THREE.MeshBasicMaterial({
color: 0xf4a83a,
toneMapped: false
});
const pathCoral = new THREE.MeshBasicMaterial({
color: 0xef5b68,
toneMapped: false
});
const shelter = new THREE.Group();
scene.add(shelter);
function beamBetween(a, b, width, depth, material = wood) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
mesh.scale.set(width, length, depth);
mesh.castShadow = true;
mesh.receiveShadow = true;
shelter.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(unitCylinder, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
mesh.scale.set(radius, length, radius);
shelter.add(mesh);
return mesh;
}
function coneAt(position, direction, material, radius = 0.1, height = 0.24) {
const mesh = new THREE.Mesh(coneGeometry, material);
mesh.position.copy(position);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.clone().normalize());
mesh.scale.set(radius, height, radius);
shelter.add(mesh);
return mesh;
}
function arrowBetween(a, b, material, radius = 0.032, headRadius = 0.11) {
const direction = new THREE.Vector3().subVectors(b, a);
const totalLength = direction.length();
const headLength = Math.min(0.27, totalLength * 0.34);
const headBase = b.clone().addScaledVector(direction.clone().normalize(), -headLength);
cylinderBetween(a, headBase, radius, material);
const cone = coneAt(
b.clone().addScaledVector(direction.clone().normalize(), -headLength / 2),
direction,
material,
headRadius,
headLength
);
return cone;
}
function nodeAt(position, material, radius = 0.075) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, 1),
material
);
mesh.position.copy(position);
shelter.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Low-poly site
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0xd9e4df,
roughness: 1,
flatShading: true
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.36;
ground.receiveShadow = true;
scene.add(ground);
const diorama = new THREE.Mesh(
new THREE.CylinderGeometry(9.4, 10.1, 0.46, 12),
new THREE.MeshStandardMaterial({
color: 0xaab79e,
roughness: 1,
flatShading: true
})
);
diorama.position.y = -0.25;
diorama.receiveShadow = true;
scene.add(diorama);
const slab = new THREE.Mesh(
new THREE.BoxGeometry(8.7, 0.18, 5.35),
slabMaterial
);
slab.position.set(0, -0.09, 0);
slab.receiveShadow = true;
scene.add(slab);
// Sparse faceted rocks around the site.
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x8b9586,
roughness: 1,
flatShading: true
});
const rockPositions = [
[-7.1, -0.02, 3.1, 0.45],
[-6.4, -0.03, 4.0, 0.28],
[6.6, -0.03, 3.7, 0.38],
[7.4, -0.02, 2.8, 0.23],
[5.9, -0.03, -4.5, 0.31],
[-5.4, -0.03, -5.1, 0.36]
];
for (const [x, y, z, s] of rockPositions) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(s, 0),
rockMaterial
);
rock.position.set(x, y, z);
rock.scale.y = 0.65;
rock.rotation.set(0.2, x * 0.7, 0.1);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// -------------------------------------------------------------------------
// Shelter geometry
// -------------------------------------------------------------------------
const xs = [-3.6, -1.2, 1.2, 3.6];
const zs = [-1.9, 1.9];
const postBottom = 0.3;
const eaveY = 3.05;
const ridgeY = 4.2;
// Individual concrete footings.
for (const x of xs) {
for (const z of zs) {
const footing = new THREE.Mesh(
new THREE.BoxGeometry(0.7, 0.36, 0.7),
concrete
);
footing.position.set(x, 0.12, z);
footing.castShadow = true;
footing.receiveShadow = true;
shelter.add(footing);
}
}
// Eight timber posts.
for (const x of xs) {
for (const z of zs) {
beamBetween(
V(x, postBottom, z),
V(x, eaveY, z),
0.23,
0.23,
wood
);
}
}
// Long eave beams / top plates.
beamBetween(
V(-3.95, eaveY, -1.9),
V(3.95, eaveY, -1.9),
0.25,
0.25,
woodLight
);
beamBetween(
V(-3.95, eaveY, 1.9),
V(3.95, eaveY, 1.9),
0.25,
0.25,
woodLight
);
// End-wall top beam and base tie.
beamBetween(
V(-3.6, eaveY, -1.95),
V(-3.6, eaveY, 1.95),
0.24,
0.24,
woodLight
);
beamBetween(
V(3.6, eaveY, -1.95),
V(3.6, eaveY, 1.95),
0.24,
0.24,
woodLight
);
beamBetween(
V(3.6, 0.43, -1.95),
V(3.6, 0.43, 1.95),
0.16,
0.16,
woodDark
);
// Rear base plates create three readable wall bays.
for (let i = 0; i < xs.length - 1; i++) {
beamBetween(
V(xs[i], 0.43, -1.9),
V(xs[i + 1], 0.43, -1.9),
0.14,
0.14,
woodDark
);
}
// Ridge beam.
beamBetween(
V(-3.95, ridgeY, 0),
V(3.95, ridgeY, 0),
0.24,
0.24,
woodLight
);
// Repeated rafters form the gable.
for (const x of xs) {
beamBetween(
V(x, ridgeY, 0),
V(x, eaveY, -2.04),
0.18,
0.18,
wood
);
beamBetween(
V(x, ridgeY, 0),
V(x, eaveY, 2.04),
0.18,
0.18,
wood
);
}
// Longitudinal roof purlins.
beamBetween(
V(-4.0, 3.735, -0.94),
V(4.0, 3.735, -0.94),
0.15,
0.15,
woodDark
);
beamBetween(
V(-4.0, 3.735, 0.94),
V(4.0, 3.735, 0.94),
0.15,
0.15,
woodDark
);
// Three X-braced rear-wall bays.
for (let i = 0; i < xs.length - 1; i++) {
const left = xs[i];
const right = xs[i + 1];
beamBetween(
V(left, 0.48, -1.78),
V(right, 2.96, -1.78),
0.115,
0.115,
woodDark
);
beamBetween(
V(left, 2.96, -1.78),
V(right, 0.48, -1.78),
0.115,
0.115,
woodDark
);
}
// X-braced right-end frame, shown most clearly by the camera.
beamBetween(
V(3.66, 0.48, -1.82),
V(3.66, 2.96, 1.82),
0.13,
0.13,
woodDark
);
beamBetween(
V(3.66, 2.96, -1.82),
V(3.66, 0.48, 1.82),
0.13,
0.13,
woodDark
);
// Octagonal bolt heads emphasize repeated frame connections.
const boltGeometry = new THREE.CylinderGeometry(0.052, 0.052, 0.045, 8);
for (const x of xs) {
for (const z of zs) {
for (const y of [0.5, 2.83]) {
const bolt = new THREE.Mesh(boltGeometry, darkMetal);
bolt.rotation.x = Math.PI / 2;
bolt.position.set(x, y, z + Math.sign(z) * 0.125);
bolt.castShadow = true;
shelter.add(bolt);
}
}
}
// -------------------------------------------------------------------------
// Translucent, faceted roof panels
// -------------------------------------------------------------------------
function roofPanel(x0, x1, zNear, zFar, yNear, yFar) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
x0, yNear, zNear,
x1, yNear, zNear,
x1, yFar, zFar,
x0, yFar, zFar
],
3
)
);
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
const panel = new THREE.Mesh(geometry, roofMaterial);
panel.renderOrder = 2;
shelter.add(panel);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0x49666d,
transparent: true,
opacity: 0.32
})
);
edges.renderOrder = 3;
shelter.add(edges);
}
const roofStart = -4.05;
const roofEnd = 4.05;
const roofStep = (roofEnd - roofStart) / 3;
for (let i = 0; i < 3; i++) {
const x0 = roofStart + i * roofStep;
const x1 = x0 + roofStep;
roofPanel(x0, x1, 0, 2.13, 4.31, 3.14);
roofPanel(x0, x1, 0, -2.13, 4.31, 3.14);
}
// -------------------------------------------------------------------------
// Connected highlighted load paths
// -------------------------------------------------------------------------
// Applied roof actions at the ridge.
for (const x of [-1.2, 1.2, 3.6]) {
arrowBetween(
V(x, 4.98, 0),
V(x, 4.29, 0),
pathCyan,
0.035,
0.13
);
}
// Slightly outward offsets keep the paths visible against the timber.
const gravityPoints = [
V(3.76, 4.25, 0),
V(3.76, 3.08, 1.96),
V(3.76, 0.32, 1.96)
];
const bracePoints = [
V(3.79, 4.25, 0),
V(3.79, 3.08, 1.96),
V(3.79, 0.47, -1.96),
V(3.79, 0.31, -1.96)
];
function highlightedSegment(a, b, material, radius, arrowPositions) {
cylinderBetween(a, b, radius, material);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const unit = direction.clone().normalize();
for (const t of arrowPositions) {
coneAt(
a.clone().addScaledVector(direction, t),
unit,
material,
radius * 3.1,
0.23
);
}
return length;
}
// Amber gravity path: ridge → rafter → eave → front post → footing.
highlightedSegment(
gravityPoints[0],
gravityPoints[1],
pathAmber,
0.037,
[0.38, 0.76]
);
highlightedSegment(
gravityPoints[1],
gravityPoints[2],
pathAmber,
0.037,
[0.38, 0.76]
);
// Coral lateral path: eave → diagonal brace → rear base → rear footing.
highlightedSegment(
bracePoints[1],
bracePoints[2],
pathCoral,
0.043,
[0.30, 0.65, 0.90]
);
highlightedSegment(
bracePoints[2],
bracePoints[3],
pathCoral,
0.043,
[0.48]
);
// Branch nodes.
nodeAt(gravityPoints[1], pathAmber, 0.085);
nodeAt(bracePoints[1], pathCoral, 0.09);
nodeAt(bracePoints[2], pathCoral, 0.08);
// Footing endpoint rings.
function footingRing(position, material) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.255, 0.028, 6, 20),
material
);
ring.rotation.x = Math.PI / 2;
ring.position.copy(position);
shelter.add(ring);
return ring;
}
const amberRing = footingRing(V(3.6, 0.31, 1.9), pathAmber);
const coralRing = footingRing(V(3.6, 0.31, -1.9), pathCoral);
// Animated pulse positions.
const pulseGeometry = new THREE.SphereGeometry(0.09, 10, 8);
const gravityPulse = new THREE.Mesh(
pulseGeometry,
new THREE.MeshBasicMaterial({
color: 0xffe19a,
toneMapped: false
})
);
const bracePulse = new THREE.Mesh(
pulseGeometry,
new THREE.MeshBasicMaterial({
color: 0xff9ca4,
toneMapped: false
})
);
shelter.add(gravityPulse, bracePulse);
function polylineData(points) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
return { lengths, total };
}
function samplePolyline(points, data, t) {
let distance = ((t % 1) + 1) % 1 * data.total;
for (let i = 0; i < data.lengths.length; i++) {
if (distance <= data.lengths[i]) {
const localT = distance / data.lengths[i];
return points[i].clone().lerp(points[i + 1], localT);
}
distance -= data.lengths[i];
}
return points[points.length - 1].clone();
}
const gravityData = polylineData(gravityPoints);
const braceData = polylineData(bracePoints);
// -------------------------------------------------------------------------
// HTML labels projected from 3D anchor points
// -------------------------------------------------------------------------
function createCallout(title, subtitle, position, colorClass = "") {
const element = document.createElement("div");
element.className = `callout ${colorClass}`;
element.innerHTML = `
<strong>${title}</strong>
<small>${subtitle}</small>
`;
document.body.appendChild(element);
return { element, position };
}
const callouts = [
createCallout(
"Roof load",
"applied gravity + lateral action",
V(3.6, 5.02, 0)
),
createCallout(
"Repeated wall bay",
"posts · plates · diagonal braces",
V(-2.4, 3.28, 1.92)
),
createCallout(
"Gravity route",
"rafter → post → near footing",
V(3.82, 2.03, 1.97),
"amber"
),
createCallout(
"X-braced frame",
"diagonal transfers lateral action",
V(3.83, 1.36, 0.02),
"coral"
),
createCallout(
"Spread footing",
"final transfer into the ground",
V(3.6, 0.27, 1.92),
"amber"
)
];
const projected = new THREE.Vector3();
function updateCallouts() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const callout of callouts) {
projected.copy(callout.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
callout.element.classList.toggle("hidden", !visible);
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
callout.element.style.left = `${x}px`;
callout.element.style.top = `${y}px`;
}
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pinch and wheel zoom
// -------------------------------------------------------------------------
const overview = {
theta: 0.76,
phi: 1.03,
radius: 14.2,
target: V(0, 1.65, 0)
};
const focused = {
theta: 1.03,
phi: 1.12,
radius: 8.7,
target: V(2.72, 2.08, 0.12)
};
const currentView = {
theta: overview.theta,
phi: overview.phi,
radius: overview.radius,
target: overview.target.clone()
};
const goalView = {
theta: overview.theta,
phi: overview.phi,
radius: overview.radius,
target: overview.target.clone()
};
function setGoal(view) {
goalView.theta = view.theta;
goalView.phi = view.phi;
goalView.radius = view.radius;
goalView.target.copy(view.target);
}
const pointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
goalView.theta -= dx * 0.006;
goalView.phi = THREE.MathUtils.clamp(
goalView.phi - dy * 0.005,
0.38,
1.45
);
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0) {
const scale = previousPinchDistance / Math.max(distance, 1);
goalView.radius = THREE.MathUtils.clamp(
goalView.radius * scale,
6.2,
24
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
goalView.radius = THREE.MathUtils.clamp(
goalView.radius * Math.exp(event.deltaY * 0.001),
6.2,
24
);
},
{ passive: false }
);
document.querySelector("#resetButton").addEventListener("click", () => {
setGoal(overview);
});
document.querySelector("#focusButton").addEventListener("click", () => {
setGoal(focused);
});
let flowRunning = true;
const flowButton = document.querySelector("#flowButton");
function toggleFlow() {
flowRunning = !flowRunning;
flowButton.textContent = flowRunning ? "Pause flow" : "Play flow";
}
flowButton.addEventListener("click", toggleFlow);
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
toggleFlow();
}
if (event.key.toLowerCase() === "r") {
setGoal(overview);
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let flowTime = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
// Smooth camera damping.
currentView.theta += (goalView.theta - currentView.theta) * 0.1;
currentView.phi += (goalView.phi - currentView.phi) * 0.1;
currentView.radius += (goalView.radius - currentView.radius) * 0.1;
currentView.target.lerp(goalView.target, 0.1);
const spherical = new THREE.Spherical(
currentView.radius,
currentView.phi,
currentView.theta
);
camera.position.setFromSpherical(spherical).add(currentView.target);
camera.lookAt(currentView.target);
if (flowRunning) {
flowTime += dt;
gravityPulse.position.copy(
samplePolyline(gravityPoints, gravityData, flowTime * 0.19)
);
bracePulse.position.copy(
samplePolyline(bracePoints, braceData, flowTime * 0.16 + 0.46)
);
const pulseScale = 1 + Math.sin(flowTime * 7) * 0.12;
gravityPulse.scale.setScalar(pulseScale);
bracePulse.scale.setScalar(pulseScale);
amberRing.material.opacity = 1;
coralRing.material.opacity = 1;
}
updateCallouts();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```