Prompt specification
Build or customize the Three.js 3D scene "Square frame and diagonal brace" 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: Square frame and diagonal brace
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/square-frame-and-diagonal-brace-x2225
Scene Description Prompt:
Compare stylized square frames with and without a diagonal brace, exposing their joints. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (square-frame-and-diagonal-brace-x2225):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Square Frame Joint Study</title>
<style>
:root {
--ink: #18313a;
--muted: #60747b;
--paper: #dfe7e9;
--accent: #c96c42;
--gold: #d7aa55;
}
* {
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;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
header {
position: absolute;
top: 28px;
left: 32px;
max-width: 520px;
}
.kicker {
margin-bottom: 8px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 42px);
font-weight: 720;
letter-spacing: -0.045em;
line-height: 1.02;
}
header p {
max-width: 450px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.specs {
position: absolute;
top: 30px;
right: 32px;
display: grid;
grid-template-columns: repeat(2, minmax(90px, 1fr));
gap: 1px;
overflow: hidden;
border: 1px solid rgba(24, 49, 58, 0.13);
border-radius: 12px;
background: rgba(24, 49, 58, 0.08);
box-shadow: 0 12px 35px rgba(30, 52, 60, 0.08);
backdrop-filter: blur(10px);
}
.spec {
min-width: 105px;
padding: 12px 14px;
background: rgba(244, 248, 248, 0.74);
}
.spec span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.spec strong {
font-size: 13px;
font-weight: 720;
}
.model-label {
position: absolute;
z-index: 4;
min-width: 158px;
padding: 10px 13px 11px;
border: 1px solid rgba(24, 49, 58, 0.12);
border-radius: 10px;
background: rgba(244, 248, 248, 0.84);
box-shadow: 0 10px 30px rgba(25, 48, 56, 0.09);
backdrop-filter: blur(12px);
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
}
.model-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 17px;
background: rgba(24, 49, 58, 0.28);
}
.model-label .index {
display: block;
margin-bottom: 4px;
color: var(--accent);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.model-label strong {
display: block;
font-size: 14px;
letter-spacing: 0.03em;
}
.model-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.legend {
position: absolute;
bottom: 26px;
left: 32px;
display: flex;
flex-wrap: wrap;
gap: 18px;
align-items: center;
padding: 10px 13px;
border: 1px solid rgba(24, 49, 58, 0.12);
border-radius: 10px;
background: rgba(244, 248, 248, 0.78);
backdrop-filter: blur(10px);
}
.legend-item {
display: flex;
gap: 7px;
align-items: center;
color: var(--muted);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.04em;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
.swatch.frame {
background: #31505c;
}
.swatch.gusset {
background: var(--accent);
}
.swatch.pin {
border-radius: 50%;
background: var(--gold);
}
.controls {
position: absolute;
right: 32px;
bottom: 30px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 760px) {
header {
top: 18px;
left: 18px;
max-width: calc(100% - 36px);
}
header p,
.specs {
display: none;
}
.legend {
left: 18px;
bottom: 18px;
gap: 11px;
}
.controls {
right: 18px;
bottom: 20px;
max-width: 130px;
text-align: right;
line-height: 1.5;
}
.model-label {
min-width: 125px;
padding: 8px 10px;
}
.model-label small {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive comparison of two square structural frames"></canvas>
<div class="hud">
<header>
<div class="kicker">Structural detail / 01</div>
<h1>Square frame joint study</h1>
<p>
The same exposed corner-gusset assembly is shown without and with a
pinned diagonal brace, revealing the added load path and center joint.
</p>
</header>
<aside class="specs">
<div class="spec">
<span>Frame size</span>
<strong>4.4 × 4.4</strong>
</div>
<div class="spec">
<span>Joint type</span>
<strong>Pin + gusset</strong>
</div>
</aside>
<div class="model-label" id="label-a">
<span class="index">Frame A / 01</span>
<strong>UNBRACED</strong>
<small>Four exposed corner joints</small>
</div>
<div class="model-label" id="label-b">
<span class="index">Frame B / 02</span>
<strong>DIAGONALLY BRACED</strong>
<small>Added center pivot connection</small>
</div>
<div class="legend">
<div class="legend-item">
<span class="swatch frame"></span>
Frame member
</div>
<div class="legend-item">
<span class="swatch gusset"></span>
Exposed gusset
</div>
<div class="legend-item">
<span class="swatch pin"></span>
Pivot hardware
</div>
</div>
<div class="controls">Drag to orbit · Scroll to zoom · Double-click to reset</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.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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(0xdfe7e9);
scene.fog = new THREE.Fog(0xdfe7e9, 17, 34);
const camera = new THREE.PerspectiveCamera(34, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.05, 0);
const hemi = new THREE.HemisphereLight(0xf8fcff, 0x657171, 2.2);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff4df, 3.3);
key.position.set(-4, 9, 10);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -11;
key.shadow.camera.right = 11;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -8;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 35;
key.shadow.bias = -0.0003;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0xc8e4ff, 1.35);
fill.position.set(7, 3, 6);
scene.add(fill);
const rim = new THREE.DirectionalLight(0xffb77c, 1.05);
rim.position.set(1, 5, -8);
scene.add(rim);
const materials = {
frame: new THREE.MeshStandardMaterial({
color: 0x31505c,
metalness: 0.78,
roughness: 0.27
}),
web: new THREE.MeshStandardMaterial({
color: 0x233d49,
metalness: 0.72,
roughness: 0.31
}),
edge: new THREE.MeshStandardMaterial({
color: 0x78919a,
metalness: 0.9,
roughness: 0.2
}),
gusset: new THREE.MeshStandardMaterial({
color: 0xc96c42,
metalness: 0.62,
roughness: 0.3
}),
pin: new THREE.MeshStandardMaterial({
color: 0xd7aa55,
metalness: 0.86,
roughness: 0.2
}),
dark: new THREE.MeshStandardMaterial({
color: 0x182a31,
metalness: 0.76,
roughness: 0.26
}),
foot: new THREE.MeshStandardMaterial({
color: 0x29444f,
metalness: 0.72,
roughness: 0.34
})
};
function mesh(geometry, material, parent, position = [0, 0, 0]) {
const object = new THREE.Mesh(geometry, material);
object.position.set(...position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function createIBeam(length) {
const group = new THREE.Group();
mesh(
new THREE.BoxGeometry(length, 0.25, 0.16),
materials.web,
group,
[0, 0, -0.015]
);
mesh(
new THREE.BoxGeometry(length, 0.075, 0.36),
materials.frame,
group,
[0, 0.1375, 0]
);
mesh(
new THREE.BoxGeometry(length, 0.075, 0.36),
materials.frame,
group,
[0, -0.1375, 0]
);
mesh(
new THREE.BoxGeometry(length * 0.94, 0.022, 0.012),
materials.edge,
group,
[0, 0, 0.071]
);
return group;
}
function createGusset(parent, x, y, inwardX, inwardY) {
const size = 0.74;
const shape = new THREE.Shape();
shape.moveTo(0, 0);
shape.lineTo(inwardX * size, 0);
shape.lineTo(0, inwardY * size);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.07,
bevelEnabled: true,
bevelSegments: 2,
steps: 1,
bevelSize: 0.025,
bevelThickness: 0.018
});
const plate = mesh(geometry, materials.gusset, parent, [x, y, 0.25]);
const rivetGeometry = new THREE.CylinderGeometry(0.052, 0.052, 0.055, 16);
rivetGeometry.rotateX(Math.PI / 2);
mesh(
rivetGeometry,
materials.pin,
parent,
[x + inwardX * size * 0.57, y, 0.365]
);
mesh(
rivetGeometry,
materials.pin,
parent,
[x, y + inwardY * size * 0.57, 0.365]
);
return plate;
}
function createPin(parent, x, y, z = 0.36) {
const washer = mesh(
new THREE.TorusGeometry(0.137, 0.027, 10, 32),
materials.pin,
parent,
[x, y, z]
);
const shaftGeometry = new THREE.CylinderGeometry(
0.088,
0.088,
0.2,
20
);
shaftGeometry.rotateX(Math.PI / 2);
mesh(shaftGeometry, materials.dark, parent, [x, y, z + 0.045]);
const headGeometry = new THREE.CylinderGeometry(
0.153,
0.153,
0.1,
6
);
headGeometry.rotateX(Math.PI / 2);
mesh(headGeometry, materials.pin, parent, [x, y, z + 0.165]);
const capGeometry = new THREE.CylinderGeometry(
0.047,
0.047,
0.012,
20
);
capGeometry.rotateX(Math.PI / 2);
mesh(capGeometry, materials.dark, parent, [x, y, z + 0.22]);
return washer;
}
function createFoot(parent, x) {
mesh(
new THREE.BoxGeometry(0.62, 0.18, 0.72),
materials.foot,
parent,
[x, -2.47, 0]
);
const boltGeometry = new THREE.CylinderGeometry(0.07, 0.07, 0.04, 6);
for (const z of [-0.22, 0.22]) {
mesh(
boltGeometry,
materials.pin,
parent,
[x, -2.365, z]
);
}
}
function createFrame(centerX, braced) {
const group = new THREE.Group();
group.position.x = centerX;
scene.add(group);
const side = 2.2;
const memberLength = 4.4;
const top = createIBeam(memberLength);
top.position.y = side;
group.add(top);
const bottom = createIBeam(memberLength);
bottom.position.y = -side;
group.add(bottom);
const left = createIBeam(memberLength);
left.rotation.z = Math.PI / 2;
left.position.x = -side;
group.add(left);
const right = createIBeam(memberLength);
right.rotation.z = Math.PI / 2;
right.position.x = side;
group.add(right);
const corners = [
{ x: -side, y: side, ix: 1, iy: -1 },
{ x: side, y: side, ix: -1, iy: -1 },
{ x: side, y: -side, ix: -1, iy: 1 },
{ x: -side, y: -side, ix: 1, iy: 1 }
];
for (const corner of corners) {
createGusset(group, corner.x, corner.y, corner.ix, corner.iy);
createPin(group, corner.x, corner.y);
}
createFoot(group, -side);
createFoot(group, side);
if (braced) {
const fullLength = Math.hypot(side * 2, side * 2);
const centerGap = 0.34;
const segmentLength = (fullLength - centerGap) * 0.5;
const segmentOffset = segmentLength * 0.5;
const angle = Math.atan2(side * 2, side * 2);
const segmentA = createIBeam(segmentLength);
segmentA.rotation.z = angle;
segmentA.position.set(
-side + Math.cos(angle) * segmentOffset,
-side + Math.sin(angle) * segmentOffset,
-0.12
);
group.add(segmentA);
const segmentB = createIBeam(segmentLength);
segmentB.rotation.z = angle;
segmentB.position.set(
side - Math.cos(angle) * segmentOffset,
side - Math.sin(angle) * segmentOffset,
-0.12
);
group.add(segmentB);
const hubGeometry = new THREE.CylinderGeometry(
0.315,
0.315,
0.09,
32
);
hubGeometry.rotateX(Math.PI / 2);
mesh(hubGeometry, materials.gusset, group, [0, 0, 0.09]);
mesh(
new THREE.TorusGeometry(0.245, 0.034, 12, 36),
materials.pin,
group,
[0, 0, 0.15]
);
const centerShaft = new THREE.CylinderGeometry(
0.125,
0.125,
0.18,
24
);
centerShaft.rotateX(Math.PI / 2);
mesh(centerShaft, materials.dark, group, [0, 0, 0.2]);
const centerHead = new THREE.CylinderGeometry(
0.205,
0.205,
0.11,
6
);
centerHead.rotateX(Math.PI / 2);
mesh(centerHead, materials.pin, group, [0, 0, 0.305]);
const centerCap = new THREE.CylinderGeometry(
0.06,
0.06,
0.014,
20
);
centerCap.rotateX(Math.PI / 2);
mesh(centerCap, materials.dark, group, [0, 0, 0.367]);
}
return group;
}
createFrame(-3.4, false);
createFrame(3.4, true);
const floor = mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xd6dfe1,
metalness: 0.02,
roughness: 0.9
}),
scene,
[0, -2.575, 0]
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
const grid = new THREE.GridHelper(40, 40, 0x91a3a8, 0x91a3a8);
grid.position.y = -2.568;
grid.material.opacity = 0.18;
grid.material.transparent = true;
grid.material.depthWrite = false;
scene.add(grid);
const labelA = document.querySelector("#label-a");
const labelB = document.querySelector("#label-b");
const anchorA = new THREE.Vector3(-3.4, 2.95, 0);
const anchorB = new THREE.Vector3(3.4, 2.95, 0);
let baseRadius = 14;
let radius = 16;
let targetRadius = 14;
let theta = -0.1;
let targetTheta = -0.1;
let phi = 1.34;
let targetPhi = 1.34;
let userAdjusted = false;
const pointers = new Map();
let dragging = false;
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
function getBaseRadius() {
const verticalFov = THREE.MathUtils.degToRad(camera.fov);
const requiredRadius =
12.3 / (2 * Math.tan(verticalFov * 0.5) * camera.aspect);
return Math.max(13.8, requiredRadius * 1.08);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
baseRadius = getBaseRadius();
if (!userAdjusted) {
targetRadius = baseRadius;
}
}
function updateCamera() {
const damping = 0.095;
theta += (targetTheta - theta) * damping;
phi += (targetPhi - phi) * damping;
radius += (targetRadius - radius) * damping;
const sinPhi = Math.sin(phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
function pinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
} else {
dragging = false;
previousPinchDistance = pinchDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1 && dragging) {
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
targetTheta -= deltaX * 0.006;
targetPhi = THREE.MathUtils.clamp(
targetPhi - deltaY * 0.006,
0.72,
1.76
);
previousX = event.clientX;
previousY = event.clientY;
userAdjusted = true;
} else if (pointers.size >= 2) {
const distance = pinchDistance();
if (previousPinchDistance > 0 && distance > 0) {
targetRadius = THREE.MathUtils.clamp(
targetRadius * (previousPinchDistance / distance),
baseRadius * 0.65,
baseRadius * 1.8
);
userAdjusted = true;
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
dragging = false;
} else if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
previousX = remaining.x;
previousY = remaining.y;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
targetRadius = THREE.MathUtils.clamp(
targetRadius * Math.exp(event.deltaY * 0.001),
baseRadius * 0.65,
baseRadius * 1.8
);
userAdjusted = true;
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
targetTheta = -0.1;
targetPhi = 1.34;
targetRadius = baseRadius;
userAdjusted = false;
});
function updateLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y - 16}px`;
}
window.addEventListener("resize", resize);
resize();
targetRadius = baseRadius;
radius = baseRadius * 1.12;
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabel(labelA, anchorA);
updateLabel(labelB, anchorB);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```