Prompt specification
Build or customize the Three.js 3D scene "Choose bracing locations for an open pavilion" 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: Choose bracing locations for an open pavilion
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/choose-bracing-locations-for-an-open-pavilion-x2228
Scene Description Prompt:
Brace a low-poly pavilion while keeping its doorway open; compare geometric sway under a simplified deformation model. Three.js from cdnjs, one HTML file.
Working Three.js Starter (choose-bracing-locations-for-an-open-pavilion-x2228):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Low-Poly Pavilion — Bracing and Sway Study</title>
<style>
:root {
--bg: #09111d;
--panel: rgba(13, 24, 39, 0.86);
--panel-border: rgba(157, 190, 214, 0.16);
--text: #edf5fb;
--muted: #9eb0c1;
--cyan: #67e2d1;
--orange: #ff966f;
--yellow: #f4c96b;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.panel {
position: absolute;
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 16px;
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
#controls {
top: 18px;
left: 18px;
width: min(340px, calc(100vw - 36px));
padding: 18px;
}
#comparison {
top: 18px;
right: 18px;
width: min(310px, calc(100vw - 36px));
padding: 18px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 24px;
line-height: 1.08;
letter-spacing: -0.035em;
}
h2 {
margin: 0 0 16px;
font-size: 16px;
letter-spacing: -0.02em;
}
.intro {
margin: 10px 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.control-title {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
font-size: 12px;
font-weight: 700;
}
output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
margin: 0 0 16px;
accent-color: var(--cyan);
cursor: pointer;
}
.button-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 36px;
padding: 8px 10px;
border: 1px solid rgba(160, 190, 215, 0.18);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition:
background 140ms ease,
border-color 140ms ease,
transform 140ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.09);
border-color: rgba(160, 190, 215, 0.34);
}
button:active {
transform: translateY(1px);
}
button.active {
color: #06201d;
background: var(--cyan);
border-color: var(--cyan);
}
#gustButton {
grid-column: 1 / -1;
color: #25180b;
background: var(--yellow);
border-color: var(--yellow);
}
.model {
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid rgba(160, 190, 215, 0.12);
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.model strong {
color: var(--text);
}
code {
display: inline-block;
margin-top: 5px;
color: #d6e9f4;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 10px;
}
.stat {
margin-bottom: 15px;
}
.stat-header {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
font-size: 12px;
}
.stat-header strong {
font-size: 16px;
font-variant-numeric: tabular-nums;
}
.unbraced {
color: var(--orange);
}
.braced {
color: var(--cyan);
}
.bar {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.075);
}
.bar span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width 80ms linear;
}
#unbracedBar {
background: linear-gradient(90deg, #d86e56, var(--orange));
}
#bracedBar {
background: linear-gradient(90deg, #3d9f95, var(--cyan));
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 18px;
}
.metric {
padding: 11px;
border: 1px solid rgba(160, 190, 215, 0.12);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.metric span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.metric b {
font-size: 16px;
font-variant-numeric: tabular-nums;
}
.note {
margin: 13px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
#hint {
position: absolute;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid rgba(160, 190, 215, 0.12);
border-radius: 999px;
background: rgba(9, 17, 29, 0.72);
color: var(--muted);
font-size: 10px;
white-space: nowrap;
pointer-events: none;
}
@media (max-width: 760px) {
#controls {
top: 10px;
left: 10px;
width: min(310px, calc(100vw - 20px));
padding: 14px;
}
#comparison {
top: auto;
right: 10px;
bottom: 48px;
width: min(280px, calc(100vw - 20px));
padding: 14px;
}
h1 {
font-size: 20px;
}
.intro,
.model {
display: none;
}
#hint {
bottom: 10px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive comparison of braced and unbraced pavilions"></canvas>
<div class="ui">
<section class="panel" id="controls">
<div class="eyebrow">Structural response study</div>
<h1>Pavilion bracing</h1>
<p class="intro">
Rear and side bracing stiffens the frame while the entire front
doorway remains open. Drag to orbit and scroll to zoom.
</p>
<label class="control-title" for="load">
<span>Lateral load</span>
<output id="loadOutput" for="load">18 kN</output>
</label>
<input
id="load"
type="range"
min="0"
max="30"
step="1"
value="18"
>
<div class="button-grid">
<button id="motionButton" class="active" aria-pressed="true">
Motion on
</button>
<button id="ghostButton" class="active" aria-pressed="true">
Ghost outlines
</button>
<button id="gustButton">Apply wind gust</button>
<button id="resetButton">Reset camera</button>
</div>
<div class="model">
<strong>Simplified cantilever model</strong><br>
Top displacement follows
<code>Δ = FL³ / (3EI)</code>.
The deformed shape uses
<code>δ(y) = Δ(y/H)²</code>.
Bracing provides a 6.5× effective-stiffness multiplier.
</div>
</section>
<section class="panel" id="comparison">
<h2>Geometric sway comparison</h2>
<div class="stat">
<div class="stat-header">
<span class="unbraced">Unbraced</span>
<strong id="unbracedValue">0.0 mm</strong>
</div>
<div class="bar"><span id="unbracedBar"></span></div>
</div>
<div class="stat">
<div class="stat-header">
<span class="braced">Braced</span>
<strong id="bracedValue">0.0 mm</strong>
</div>
<div class="bar"><span id="bracedBar"></span></div>
</div>
<div class="metric-grid">
<div class="metric">
<span>Unbraced drift</span>
<b id="driftValue">0.00%</b>
</div>
<div class="metric">
<span>Sway reduction</span>
<b id="reductionValue">84.6%</b>
</div>
</div>
<p class="note">
Values show current top-frame displacement. Ghost lines mark the
unloaded geometry.
</p>
</section>
<div id="hint">
Drag to orbit · Scroll to zoom · Arrow keys to pan · + / − to zoom
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09111d);
scene.fog = new THREE.Fog(0x09111d, 20, 43);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.8, 0);
let cameraYaw = 0.64;
let cameraPitch = 0.38;
let cameraRadius = 19;
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(
0xbde7ff,
0x182030,
2.2
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2bd, 3.4);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x6fe8dc, 1.5);
rimLight.position.set(10, 6, -8);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0x101b28,
roughness: 0.95,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.14;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(50, 50, 0x304357, 0x1b2a3a);
grid.position.y = -0.125;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
const MODEL = {
height: 3.6,
base: 0.15,
unbracedCompliance: 0.0046,
braceStiffness: 6.5
};
const state = {
load: 18,
animate: true,
showGhost: true,
gustStart: -Infinity
};
function swayShaderCode() {
return `
#include <begin_vertex>
vec3 pavilionWorldPosition =
(modelMatrix * vec4(transformed, 1.0)).xyz;
float pavilionHeight = clamp(
(pavilionWorldPosition.y - ${MODEL.base.toFixed(3)}) /
${MODEL.height.toFixed(3)},
0.0,
1.0
);
pavilionHeight *= pavilionHeight;
// Transpose of the model basis converts world +X into object space.
vec3 pavilionLocalX = normalize(vec3(
modelMatrix[0][0],
modelMatrix[1][0],
modelMatrix[2][0]
));
transformed +=
pavilionLocalX * uSway * pavilionHeight;
`;
}
function makePavilionMaterial(color, options = {}) {
const swayUniform = { value: 0 };
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0.03,
flatShading: options.flatShading ?? true,
vertexColors: options.vertexColors ?? false,
side: options.side ?? THREE.FrontSide
});
material.onBeforeCompile = (shader) => {
shader.uniforms.uSway = swayUniform;
shader.vertexShader =
"uniform float uSway;\n" + shader.vertexShader;
shader.vertexShader = shader.vertexShader.replace(
"#include <begin_vertex>",
swayShaderCode()
);
};
material.customProgramCacheKey = () => "pavilion-sway-v1";
const depthMaterial = new THREE.MeshDepthMaterial({
depthPacking: THREE.RGBADepthPacking
});
depthMaterial.onBeforeCompile = (shader) => {
shader.uniforms.uSway = swayUniform;
shader.vertexShader =
"uniform float uSway;\n" + shader.vertexShader;
shader.vertexShader = shader.vertexShader.replace(
"#include <begin_vertex>",
swayShaderCode()
);
};
depthMaterial.customProgramCacheKey = () => "pavilion-sway-depth-v1";
material.userData.swayUniform = swayUniform;
material.userData.depthMaterial = depthMaterial;
return material;
}
function addMesh(group, geometry, material, position = null) {
const mesh = new THREE.Mesh(geometry, material);
if (position) {
mesh.position.copy(position);
}
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.customDepthMaterial = material.userData.depthMaterial;
group.add(mesh);
return mesh;
}
function addBox(group, size, position, material) {
return addMesh(
group,
new THREE.BoxGeometry(size.x, size.y, size.z),
material,
position
);
}
function addBeamBetween(
group,
start,
end,
radius,
material,
radialSegments = 6
) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(start, end)
.multiplyScalar(0.5);
const mesh = addMesh(
group,
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
),
material,
midpoint
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function makeRoofGeometry() {
const a = 2.75;
const r = 1.25;
const eave = 3.79;
const ridge = 4.96;
const positions = [];
const colors = [];
const palette = [
new THREE.Color(0x536f88),
new THREE.Color(0x48637d),
new THREE.Color(0x607b93),
new THREE.Color(0x526d86),
new THREE.Color(0x3f596f),
new THREE.Color(0x5b7890)
];
function triangle(aPoint, bPoint, cPoint, colorIndex) {
positions.push(...aPoint, ...bPoint, ...cPoint);
const color = palette[colorIndex];
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
const frontLeft = [-a, eave, a];
const frontRight = [a, eave, a];
const backRight = [a, eave, -a];
const backLeft = [-a, eave, -a];
const ridgeLeft = [-r, ridge, 0];
const ridgeRight = [r, ridge, 0];
triangle(frontLeft, frontRight, ridgeRight, 0);
triangle(frontLeft, ridgeRight, ridgeLeft, 1);
triangle(frontRight, backRight, ridgeRight, 2);
triangle(backRight, backLeft, ridgeLeft, 3);
triangle(backRight, ridgeLeft, ridgeRight, 4);
triangle(backLeft, frontLeft, ridgeLeft, 5);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
return geometry;
}
function makeGhost(half, eave) {
const points = [];
const base = MODEL.base;
const top = eave - 0.05;
for (const x of [-half, half]) {
for (const z of [-half, half]) {
points.push(x, base, z, x, top, z);
}
}
points.push(
-half, eave, half,
half, eave, half,
half, eave, half,
half, eave, -half,
half, eave, -half,
-half, eave, -half,
-half, eave, -half,
-half, eave, half,
-1.25, 4.96, 0,
1.25, 4.96, 0
);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(points, 3)
);
const material = new THREE.LineBasicMaterial({
color: 0xb8d3e3,
transparent: true,
opacity: 0.28,
depthTest: false,
depthWrite: false
});
const lines = new THREE.LineSegments(geometry, material);
lines.renderOrder = 10;
return lines;
}
function makePavilion(worldX, braced) {
const group = new THREE.Group();
group.position.x = worldX;
scene.add(group);
const materials = [];
function material(color, options) {
const result = makePavilionMaterial(color, options);
materials.push(result);
return result;
}
const wood = material(
braced ? 0xb98955 : 0xb88859,
{ roughness: 0.82 }
);
const darkWood = material(
braced ? 0x71513a : 0x76533b,
{ roughness: 0.9 }
);
const deck = material(
braced ? 0x92704d : 0x967151,
{ roughness: 0.94 }
);
const deckAlt = material(
braced ? 0xa17c54 : 0xa27b52,
{ roughness: 0.94 }
);
const braces = material(
braced ? 0x54c8b7 : 0xb87655,
{ roughness: 0.56, metalness: 0.08 }
);
const roof = material(
0xffffff,
{
roughness: 0.76,
vertexColors: true,
side: THREE.DoubleSide
}
);
const trim = material(
braced ? 0x376f70 : 0x6d4d45,
{ roughness: 0.68, metalness: 0.05 }
);
const half = 2.15;
const eave = 3.75;
const base = MODEL.base;
// Foundation and low-poly deck planks.
addBox(
group,
new THREE.Vector3(5.25, 0.24, 5.25),
new THREE.Vector3(0, -0.015, 0),
darkWood
);
for (let i = 0; i < 9; i++) {
const x = -2.0 + i * 0.5;
addBox(
group,
new THREE.Vector3(0.46, 0.11, 4.8),
new THREE.Vector3(x, 0.105, 0),
i % 2 === 0 ? deck : deckAlt
);
}
// Four main columns.
for (const x of [-half, half]) {
for (const z of [-half, half]) {
addMesh(
group,
new THREE.CylinderGeometry(0.12, 0.155, MODEL.height, 6),
wood,
new THREE.Vector3(x, base + MODEL.height / 2, z)
);
addBox(
group,
new THREE.Vector3(0.34, 0.13, 0.34),
new THREE.Vector3(x, base + 0.025, z),
trim
);
}
}
// Open perimeter beams. The front center remains a clear doorway.
addBox(
group,
new THREE.Vector3(4.65, 0.23, 0.25),
new THREE.Vector3(0, eave, half),
wood
);
addBox(
group,
new THREE.Vector3(4.65, 0.23, 0.25),
new THREE.Vector3(0, eave, -half),
wood
);
addBox(
group,
new THREE.Vector3(0.25, 0.23, 4.65),
new THREE.Vector3(half, eave, 0),
wood
);
addBox(
group,
new THREE.Vector3(0.25, 0.23, 4.65),
new THREE.Vector3(-half, eave, 0),
wood
);
// High knee braces do not obstruct the doorway.
const kneeLength = 0.82;
const kneeDrop = 0.66;
const corners = [
[-half, half],
[half, half],
[half, -half],
[-half, -half]
];
for (const [x, z] of corners) {
const inwardX = x > 0 ? -kneeLength : kneeLength;
const inwardZ = z > 0 ? -kneeLength : kneeLength;
addBeamBetween(
group,
new THREE.Vector3(x, eave - kneeDrop, z),
new THREE.Vector3(x + inwardX, eave - 0.02, z),
0.065,
braces,
5
);
addBeamBetween(
group,
new THREE.Vector3(x, eave - kneeDrop, z),
new THREE.Vector3(x, eave - 0.02, z + inwardZ),
0.065,
braces,
5
);
}
if (braced) {
// Rear X brace.
addBeamBetween(
group,
new THREE.Vector3(-half + 0.13, base + 0.18, -half - 0.015),
new THREE.Vector3(half - 0.13, eave - 0.18, -half - 0.015),
0.06,
braces,
5
);
addBeamBetween(
group,
new THREE.Vector3(half - 0.13, base + 0.18, -half - 0.015),
new THREE.Vector3(-half + 0.13, eave - 0.18, -half - 0.015),
0.06,
braces,
5
);
// Right-side X brace. The open front bay is untouched.
addBeamBetween(
group,
new THREE.Vector3(half + 0.015, base + 0.18, -half + 0.13),
new THREE.Vector3(half + 0.015, eave - 0.18, half - 0.13),
0.06,
braces,
5
);
addBeamBetween(
group,
new THREE.Vector3(half + 0.015, base + 0.18, half - 0.13),
new THREE.Vector3(half + 0.015, eave - 0.18, -half + 0.13),
0.06,
braces,
5
);
// Rear lower rail for visual stiffness.
addBox(
group,
new THREE.Vector3(4.2, 0.12, 0.12),
new THREE.Vector3(0, 0.72, -half - 0.02),
braces
);
}
// Faceted hip/gable roof.
addMesh(group, makeRoofGeometry(), roof);
// A thin ridge cap.
addBox(
group,
new THREE.Vector3(2.65, 0.1, 0.12),
new THREE.Vector3(0, 4.96, 0),
trim
);
const ghost = makeGhost(half, eave);
ghost.visible = state.showGhost;
group.add(ghost);
group.userData.materials = materials;
group.userData.ghost = ghost;
return group;
}
function roundedRect(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
}
function makeLabel(text, color, worldX, worldY, worldZ, width = 3.4) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
roundedRect(context, 8, 16, 496, 96, 24);
context.fillStyle = "rgba(9, 17, 29, 0.88)";
context.fill();
context.lineWidth = 4;
context.strokeStyle = color;
context.stroke();
context.fillStyle = color;
context.font = "800 40px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false,
fog: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(worldX, worldY, worldZ);
sprite.scale.set(width, width / 4, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
const unbracedPavilion = makePavilion(-4.15, false);
const bracedPavilion = makePavilion(4.15, true);
makeLabel("UNBRACED", "#ff966f", -4.15, 5.72, 0);
makeLabel("BRACED", "#67e2d1", 4.15, 5.72, 0);
const windArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-8.1, 0.25, -5.6),
4.7,
0x67e2d1,
0.58,
0.3
);
scene.add(windArrow);
makeLabel("WIND", "#67e2d1", -5.7, 0.78, -5.6, 2.2);
const loadSlider = document.getElementById("load");
const loadOutput = document.getElementById("loadOutput");
const motionButton = document.getElementById("motionButton");
const ghostButton = document.getElementById("ghostButton");
const gustButton = document.getElementById("gustButton");
const resetButton = document.getElementById("resetButton");
const unbracedValue = document.getElementById("unbracedValue");
const bracedValue = document.getElementById("bracedValue");
const unbracedBar = document.getElementById("unbracedBar");
const bracedBar = document.getElementById("bracedBar");
const driftValue = document.getElementById("driftValue");
const reductionValue = document.getElementById("reductionValue");
loadSlider.addEventListener("input", () => {
state.load = Number(loadSlider.value);
loadOutput.value = `${state.load} kN`;
});
motionButton.addEventListener("click", () => {
state.animate = !state.animate;
motionButton.classList.toggle("active", state.animate);
motionButton.setAttribute("aria-pressed", String(state.animate));
motionButton.textContent = state.animate ? "Motion on" : "Motion off";
});
ghostButton.addEventListener("click", () => {
state.showGhost = !state.showGhost;
ghostButton.classList.toggle("active", state.showGhost);
ghostButton.setAttribute("aria-pressed", String(state.showGhost));
ghostButton.textContent = state.showGhost ? "Ghost outlines" : "Ghost hidden";
unbracedPavilion.userData.ghost.visible = state.showGhost;
bracedPavilion.userData.ghost.visible = state.showGhost;
});
gustButton.addEventListener("click", () => {
state.gustStart = performance.now() / 1000;
state.animate = true;
motionButton.classList.add("active");
motionButton.setAttribute("aria-pressed", "true");
motionButton.textContent = "Motion on";
});
function resetCamera() {
cameraYaw = 0.64;
cameraPitch = 0.38;
cameraRadius =
window.innerWidth / window.innerHeight < 0.85 ? 25 : 19;
updateCamera();
}
resetButton.addEventListener("click", resetCamera);
// Direct camera controls: pointer drag, wheel zoom, keyboard navigation.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraYaw -= deltaX * 0.005;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + deltaY * 0.004,
0.15,
1.12
);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
10,
34
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const panStep = 0.18;
switch (event.key) {
case "ArrowLeft":
cameraTarget.x -= panStep;
break;
case "ArrowRight":
cameraTarget.x += panStep;
break;
case "ArrowUp":
cameraTarget.z -= panStep;
break;
case "ArrowDown":
cameraTarget.z += panStep;
break;
case "+":
case "=":
cameraRadius = Math.max(10, cameraRadius - 1);
break;
case "-":
case "_":
cameraRadius = Math.min(34, cameraRadius + 1);
break;
default:
return;
}
event.preventDefault();
updateCamera();
});
function setPavilionSway(pavilion, sway) {
for (const material of pavilion.userData.materials) {
material.userData.swayUniform.value = sway;
}
}
function updateReadout(unbracedSway, bracedSway) {
const maximumSway =
30 * MODEL.unbracedCompliance;
const unbracedMillimeters = unbracedSway * 1000;
const bracedMillimeters = bracedSway * 1000;
unbracedValue.textContent = `${unbracedMillimeters.toFixed(1)} mm`;
bracedValue.textContent = `${bracedMillimeters.toFixed(1)} mm`;
unbracedBar.style.width =
`${Math.min(100, (unbracedSway / maximumSway) * 100)}%`;
bracedBar.style.width =
`${Math.min(100, (bracedSway / maximumSway) * 100)}%`;
const driftRatio =
(unbracedSway / MODEL.height) * 100;
driftValue.textContent = `${driftRatio.toFixed(2)}%`;
const reduction =
(1 - bracedSway / Math.max(unbracedSway, 0.000001)) * 100;
reductionValue.textContent = unbracedSway > 0.000001
? `${Math.max(0, reduction).toFixed(1)}%`
: "—";
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const now = performance.now() / 1000;
const baselineResponse = state.animate
? 0.94 + 0.06 * Math.sin(elapsed * 1.75)
: 1;
const gustAge = now - state.gustStart;
const gustResponse =
Number.isFinite(gustAge) && gustAge >= 0
? 1 +
0.72 *
Math.exp(-gustAge * 1.55) *
Math.sin(gustAge * 8.2)
: 1;
const response = baselineResponse * gustResponse;
const staticUnbracedSway =
state.load * MODEL.unbracedCompliance;
const unbracedSway = staticUnbracedSway * response;
const bracedSway =
(staticUnbracedSway / MODEL.braceStiffness) * response;
setPavilionSway(unbracedPavilion, unbracedSway);
setPavilionSway(bracedPavilion, bracedSway);
updateReadout(unbracedSway, bracedSway);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
});
animate();
</script>
</body>
</html>
```