Prompt specification
Build or customize the Three.js 3D scene "Flat Bracket With a Marked Fold Line" 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: Flat Bracket With a Marked Fold Line
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/flat-bracket-with-a-marked-fold-line-x2073
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: flat bracket with a marked fold line. Model a thin rectangular sheet with a fold line and two hole positions. Show its flat pattern and identify which face will rotate during bending. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (flat-bracket-with-a-marked-fold-line-x2073):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Three.js — Bracket Bend Study</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: #0d1a2b;
--panel-2: #11233a;
--line: rgba(157, 190, 221, 0.16);
--text: #edf5ff;
--muted: #91a8bf;
--cyan: #46dfd0;
--orange: #ffad4d;
--yellow: #ffd166;
--blue: #648ab3;
}
* {
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;
}
.app {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: 70px minmax(0, 1fr);
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(7, 17, 31, 0.88);
z-index: 2;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
border: 2px solid var(--cyan);
border-radius: 8px;
position: relative;
transform: rotate(-8deg);
flex: none;
}
.brand-mark::after {
content: "";
position: absolute;
top: 4px;
bottom: 4px;
left: 50%;
border-left: 2px dashed var(--yellow);
}
.brand h1 {
margin: 0;
font-size: 15px;
line-height: 1.1;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 12px;
white-space: nowrap;
}
.top-status {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 12px;
white-space: nowrap;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 16px rgba(70, 223, 208, 0.7);
}
.workspace {
min-height: 0;
display: grid;
grid-template-columns: minmax(0, 1fr) 360px;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 38%, rgba(46, 87, 120, 0.18), transparent 42%),
#07111f;
}
#sceneHost {
position: absolute;
inset: 0;
}
#sceneHost canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#sceneHost canvas:active {
cursor: grabbing;
}
.scene-heading {
position: absolute;
top: 22px;
left: 24px;
pointer-events: none;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.scene-heading h2 {
margin: 7px 0 4px;
font-size: clamp(21px, 2.5vw, 32px);
font-weight: 650;
letter-spacing: -0.03em;
}
.scene-heading p {
margin: 0;
color: var(--muted);
font-size: 12px;
}
.scene-tools {
position: absolute;
top: 22px;
right: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
max-width: 360px;
}
.tool-button {
border: 1px solid var(--line);
border-radius: 9px;
padding: 8px 11px;
color: var(--text);
background: rgba(13, 26, 43, 0.82);
backdrop-filter: blur(12px);
cursor: pointer;
font-size: 12px;
transition: 160ms ease;
}
.tool-button:hover {
border-color: rgba(70, 223, 208, 0.5);
background: rgba(20, 42, 63, 0.95);
}
.tool-button.active {
border-color: var(--cyan);
color: var(--cyan);
box-shadow: inset 0 0 0 1px rgba(70, 223, 208, 0.12);
}
.angle-panel {
position: absolute;
left: 24px;
bottom: 24px;
width: min(330px, calc(100% - 48px));
padding: 15px 16px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(10, 23, 39, 0.84);
backdrop-filter: blur(15px);
}
.angle-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.angle-row label {
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#angleValue {
color: var(--yellow);
font-size: 19px;
font-weight: 750;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
accent-color: var(--orange);
cursor: pointer;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #6f879f;
font-size: 10px;
}
.gesture-hint {
position: absolute;
right: 22px;
bottom: 24px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 9px;
color: var(--muted);
background: rgba(10, 23, 39, 0.76);
font-size: 11px;
pointer-events: none;
}
.sidebar {
min-height: 0;
overflow-y: auto;
padding: 20px;
border-left: 1px solid var(--line);
background: #091524;
scrollbar-width: thin;
scrollbar-color: #28445f transparent;
}
.card {
margin-bottom: 14px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 13px;
background: linear-gradient(145deg, rgba(17, 35, 58, 0.92), rgba(11, 25, 42, 0.92));
}
.card h3 {
margin: 6px 0 12px;
font-size: 15px;
letter-spacing: -0.01em;
}
.card p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#flatCanvas {
display: block;
width: 100%;
height: 205px;
margin-top: 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: #091524;
}
.mini-legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 11px;
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
}
.swatch.fixed {
background: var(--blue);
}
.swatch.moving {
background: var(--orange);
}
.swatch.fold {
width: 15px;
height: 2px;
border-radius: 0;
background: repeating-linear-gradient(
90deg,
var(--yellow) 0 4px,
transparent 4px 7px
);
}
.face-list {
display: grid;
gap: 11px;
}
.face-row {
display: grid;
grid-template-columns: 34px 1fr;
gap: 11px;
align-items: start;
}
.face-number {
width: 31px;
height: 31px;
display: grid;
place-items: center;
border-radius: 8px;
color: #07111f;
font-size: 12px;
font-weight: 900;
}
.face-number.fixed {
background: var(--blue);
color: white;
}
.face-number.moving {
background: var(--orange);
}
.face-row strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
}
.face-row span {
display: block;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.callout {
margin-top: 14px;
padding: 11px 12px;
border-left: 3px solid var(--orange);
border-radius: 0 8px 8px 0;
background: rgba(255, 173, 77, 0.08);
color: #ffd9aa;
font-size: 11px;
line-height: 1.5;
}
.steps {
display: grid;
gap: 9px;
counter-reset: step;
}
.step {
display: grid;
grid-template-columns: 25px 1fr;
gap: 9px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.step::before {
counter-increment: step;
content: counter(step);
width: 22px;
height: 22px;
display: grid;
place-items: center;
border: 1px solid rgba(70, 223, 208, 0.3);
border-radius: 50%;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
}
@media (max-width: 900px) {
html,
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100%;
grid-template-rows: 70px auto;
}
.workspace {
grid-template-columns: 1fr;
}
.viewport {
height: 68vh;
min-height: 520px;
}
.sidebar {
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
}
.scene-tools {
top: auto;
right: 16px;
bottom: 114px;
max-width: 260px;
}
.gesture-hint {
display: none;
}
.top-status {
display: none;
}
}
@media (max-width: 560px) {
.topbar {
padding: 0 16px;
}
.brand p {
display: none;
}
.scene-heading {
top: 17px;
left: 17px;
}
.scene-heading p {
max-width: 220px;
}
.angle-panel {
left: 16px;
bottom: 16px;
width: calc(100% - 32px);
}
.scene-tools {
right: 16px;
bottom: 108px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Bend Study / Flat Bracket</h1>
<p>Interactive Three.js sheet-metal visualization</p>
</div>
</div>
<div class="top-status">
<span class="status-dot"></span>
<span>THIN SHEET · 2 HOLES · 1 FOLD AXIS</span>
</div>
</header>
<div class="workspace">
<section class="viewport" aria-label="Interactive three-dimensional bracket scene">
<div id="sceneHost"></div>
<div class="scene-heading">
<div class="eyebrow">Main viewport</div>
<h2>Flat bracket, ready to bend</h2>
<p>Drag to orbit · Scroll to zoom · Use the controls to bend the flap</p>
</div>
<div class="scene-tools">
<button class="tool-button active" id="flatButton" type="button">Flat</button>
<button class="tool-button" id="bendButton" type="button">Bend 70°</button>
<button class="tool-button" id="animateButton" type="button">Animate</button>
<button class="tool-button" id="resetButton" type="button">Reset view</button>
</div>
<div class="angle-panel">
<div class="angle-row">
<label for="bendRange">Rotating-face angle</label>
<output id="angleValue" for="bendRange">0°</output>
</div>
<input
id="bendRange"
type="range"
min="0"
max="70"
step="1"
value="0"
aria-label="Bend angle of the rotating face"
/>
<div class="range-labels">
<span>0° / FLAT</span>
<span>70° / BENT</span>
</div>
</div>
<div class="gesture-hint">Mouse drag: orbit · Wheel: zoom</div>
</section>
<aside class="sidebar">
<section class="card">
<div class="eyebrow">Orthographic flat pattern</div>
<h3>Unfolded sheet</h3>
<p>The inset always shows the original flat pattern and the two hole positions.</p>
<canvas
id="flatCanvas"
aria-label="Top view of the bracket's flat pattern, fold line, and two holes"
></canvas>
<div class="mini-legend">
<span class="legend-item"><i class="swatch fixed"></i>Fixed face</span>
<span class="legend-item"><i class="swatch moving"></i>Rotating face</span>
<span class="legend-item"><i class="swatch fold"></i>Fold line</span>
</div>
</section>
<section class="card">
<div class="eyebrow">Kinematic definition</div>
<h3>Which face rotates?</h3>
<div class="face-list">
<div class="face-row">
<div class="face-number fixed">A</div>
<div>
<strong>Fixed face / base</strong>
<span>The blue half remains flat against the reference plane.</span>
</div>
</div>
<div class="face-row">
<div class="face-number moving">B</div>
<div>
<strong>Rotating face / flap</strong>
<span>The orange half rotates around the dashed fold axis.</span>
</div>
</div>
</div>
<div class="callout">
<strong>Face B is the moving face.</strong> Holes H1 and H2 are attached to it,
so both holes travel with the flap during the bend.
</div>
</section>
<section class="card">
<div class="eyebrow">How to read it</div>
<h3>Scene notation</h3>
<div class="steps">
<div class="step">The yellow dashed line is the physical fold axis.</div>
<div class="step">The yellow arc shows the flap's rotation path.</div>
<div class="step">The cyan rings identify through-hole positions H1 and H2.</div>
<div class="step">The sheet is modeled with a visible finite thickness.</div>
</div>
</section>
</aside>
</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 COLORS = {
fixed: 0x648ab3,
fixedSide: 0x304b69,
moving: 0xffad4d,
movingSide: 0xb66b24,
cyan: 0x46dfd0,
yellow: 0xffd166,
floor: 0x081522,
grid: 0x25415b
};
const SHEET = {
fixedWidth: 4,
movingWidth: 4,
height: 3.2,
thickness: 0.14,
holeRadius: 0.23,
holeXs: [1.35, 3.05]
};
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeLabelTexture(text, accent = "#46dfd0") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 10, 752, 108, 22);
ctx.fillStyle = "rgba(7, 17, 31, 0.92)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(24, 34, 8, 60);
ctx.fillStyle = "#edf5ff";
ctx.font = "700 49px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2 + 4, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
function makeTextPlane(text, width, height, accent) {
const texture = makeLabelTexture(text, accent);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
mesh.renderOrder = 4;
return mesh;
}
function makeSprite(text, accent = "#46dfd0", width = 0.48, height = 0.26) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 128;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 8, 8, 240, 112, 28);
ctx.fillStyle = "rgba(7, 17, 31, 0.94)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = "#edf5ff";
ctx.font = "800 52px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 8;
return sprite;
}
function createPlateGeometry(x0, x1, holeXs = []) {
const shape = new THREE.Shape();
const halfHeight = SHEET.height / 2;
shape.moveTo(x0, -halfHeight);
shape.lineTo(x1, -halfHeight);
shape.lineTo(x1, halfHeight);
shape.lineTo(x0, halfHeight);
shape.closePath();
for (const holeX of holeXs) {
const hole = new THREE.Path();
hole.absarc(holeX, 0, SHEET.holeRadius, 0, Math.PI * 2, true);
shape.holes.push(hole);
}
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: SHEET.thickness,
bevelEnabled: false,
curveSegments: 64
});
geometry.translate(0, 0, -SHEET.thickness / 2);
geometry.computeVertexNormals();
return geometry;
}
function createPlateMaterials(faceColor, sideColor) {
return [
new THREE.MeshStandardMaterial({
color: faceColor,
roughness: 0.48,
metalness: 0.32
}),
new THREE.MeshStandardMaterial({
color: sideColor,
roughness: 0.58,
metalness: 0.28
})
];
}
function createHoleRing(x) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(SHEET.holeRadius, 0.032, 12, 64),
new THREE.MeshBasicMaterial({ color: COLORS.cyan })
);
ring.position.set(x, 0, SHEET.thickness / 2 + 0.025);
ring.renderOrder = 5;
return ring;
}
function createFoldLine() {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -SHEET.height / 2, SHEET.thickness / 2 + 0.025),
new THREE.Vector3(0, SHEET.height / 2, SHEET.thickness / 2 + 0.025)
]);
const material = new THREE.LineDashedMaterial({
color: COLORS.yellow,
dashSize: 0.19,
gapSize: 0.12,
linewidth: 1
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
line.renderOrder = 6;
return line;
}
// ---------------------------------------------------------------
// Main perspective scene
// ---------------------------------------------------------------
const sceneHost = document.getElementById("sceneHost");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Perspective view of a thin sheet-metal bracket bending around a marked fold line"
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(COLORS.floor, 18, 38);
const camera = new THREE.PerspectiveCamera(39, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0.2, 0.85, 0);
const defaultCamera = {
radius: 13.5,
theta: 0.58,
phi: 1.03
};
const orbit = { ...defaultCamera };
function updateCamera() {
orbit.phi = THREE.MathUtils.clamp(orbit.phi, 0.38, 1.42);
orbit.radius = THREE.MathUtils.clamp(orbit.radius, 8, 24);
const spherical = new THREE.Spherical(orbit.radius, orbit.phi, orbit.theta);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xc9e9ff, 0x142033, 2.15));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(COLORS.cyan, 1.25);
rimLight.position.set(-7, 4, -6);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({
color: COLORS.floor,
roughness: 0.92,
metalness: 0.08
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, COLORS.grid, COLORS.grid);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
const sheetRoot = new THREE.Group();
sheetRoot.position.y = 0.16;
sheetRoot.rotation.x = -Math.PI / 2;
scene.add(sheetRoot);
const fixedGeometry = createPlateGeometry(-SHEET.fixedWidth, 0);
const movingGeometry = createPlateGeometry(
0,
SHEET.movingWidth,
SHEET.holeXs
);
const fixedMesh = new THREE.Mesh(
fixedGeometry,
createPlateMaterials(COLORS.fixed, COLORS.fixedSide)
);
fixedMesh.castShadow = true;
fixedMesh.receiveShadow = true;
sheetRoot.add(fixedMesh);
const fixedEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(fixedGeometry, 24),
new THREE.LineBasicMaterial({
color: 0xa9c4df,
transparent: true,
opacity: 0.55
})
);
sheetRoot.add(fixedEdges);
const movingPivot = new THREE.Group();
sheetRoot.add(movingPivot);
const movingMesh = new THREE.Mesh(
movingGeometry,
createPlateMaterials(COLORS.moving, COLORS.movingSide)
);
movingMesh.castShadow = true;
movingMesh.receiveShadow = true;
movingPivot.add(movingMesh);
const movingEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(movingGeometry, 24),
new THREE.LineBasicMaterial({
color: 0xffdfad,
transparent: true,
opacity: 0.72
})
);
movingPivot.add(movingEdges);
const fixedLabel = makeTextPlane("FIXED · BASE", 2.5, 0.42, "#8db8e3");
fixedLabel.position.set(-2.05, 1.03, SHEET.thickness / 2 + 0.035);
sheetRoot.add(fixedLabel);
const movingLabel = makeTextPlane("ROTATING FACE", 2.65, 0.42, "#ffad4d");
movingLabel.position.set(2.05, 1.03, SHEET.thickness / 2 + 0.035);
movingPivot.add(movingLabel);
sheetRoot.add(createFoldLine());
const foldLabel = makeSprite("FOLD AXIS", "#ffd166", 1.35, 0.34);
foldLabel.position.set(0, 2.03, 0.12);
sheetRoot.add(foldLabel);
SHEET.holeXs.forEach((x, index) => {
movingPivot.add(createHoleRing(x));
const label = makeSprite(`H${index + 1}`, "#46dfd0", 0.42, 0.26);
label.position.set(x, 0.48, 0.14);
movingPivot.add(label);
});
// Rotation-path arc, positioned just outside the near sheet edge.
const arcSegments = 64;
const arcPositions = new Float32Array((arcSegments + 1) * 3);
const arcGeometry = new THREE.BufferGeometry();
arcGeometry.setAttribute(
"position",
new THREE.BufferAttribute(arcPositions, 3)
);
const arc = new THREE.Line(
arcGeometry,
new THREE.LineBasicMaterial({
color: COLORS.yellow,
transparent: true,
opacity: 0.95
})
);
arc.frustumCulled = false;
arc.renderOrder = 7;
sheetRoot.add(arc);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.11, 0.32, 18),
new THREE.MeshBasicMaterial({ color: COLORS.yellow })
);
arrow.renderOrder = 7;
sheetRoot.add(arrow);
const arcUp = new THREE.Vector3(0, 1, 0);
const arcTangent = new THREE.Vector3();
function updateArc(angleRadians) {
const radius = 2.45;
const edgeY = -1.82;
for (let i = 0; i <= arcSegments; i++) {
const a = angleRadians * (i / arcSegments);
arcPositions[i * 3] = Math.cos(a) * radius;
arcPositions[i * 3 + 1] = edgeY;
arcPositions[i * 3 + 2] = Math.sin(a) * radius;
}
arcGeometry.attributes.position.needsUpdate = true;
const endpointA = angleRadians;
arrow.position.set(
Math.cos(endpointA) * radius,
edgeY,
Math.sin(endpointA) * radius
);
arcTangent.set(-Math.sin(endpointA), 0, Math.cos(endpointA)).normalize();
arrow.quaternion.setFromUnitVectors(arcUp, arcTangent);
const visible = angleRadians > 0.025;
arc.visible = visible;
arrow.visible = visible;
}
// ---------------------------------------------------------------
// Orthographic flat-pattern inset
// ---------------------------------------------------------------
const flatCanvas = document.getElementById("flatCanvas");
const flatRenderer = new THREE.WebGLRenderer({
canvas: flatCanvas,
antialias: true
});
flatRenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
flatRenderer.outputColorSpace = THREE.SRGBColorSpace;
flatRenderer.toneMapping = THREE.ACESFilmicToneMapping;
flatRenderer.toneMappingExposure = 1.15;
const flatScene = new THREE.Scene();
flatScene.background = new THREE.Color(0x091524);
const flatCamera = new THREE.OrthographicCamera(-5, 5, 3, -3, 0.1, 100);
flatCamera.position.set(0, 0, 10);
flatCamera.lookAt(0, 0, 0);
flatScene.add(new THREE.HemisphereLight(0xd9efff, 0x16243a, 2.3));
const flatLight = new THREE.DirectionalLight(0xffffff, 2.8);
flatLight.position.set(3, 5, 8);
flatScene.add(flatLight);
const flatFixedMesh = new THREE.Mesh(
createPlateGeometry(-SHEET.fixedWidth, 0),
createPlateMaterials(COLORS.fixed, COLORS.fixedSide)
);
flatScene.add(flatFixedMesh);
const flatMovingMesh = new THREE.Mesh(
createPlateGeometry(0, SHEET.movingWidth, SHEET.holeXs),
createPlateMaterials(COLORS.moving, COLORS.movingSide)
);
flatScene.add(flatMovingMesh);
const flatFixedLabel = makeTextPlane("FIXED · BASE", 2.5, 0.42, "#8db8e3");
flatFixedLabel.position.set(-2.05, 1.03, SHEET.thickness / 2 + 0.035);
flatScene.add(flatFixedLabel);
const flatMovingLabel = makeTextPlane("ROTATING FACE", 2.65, 0.42, "#ffad4d");
flatMovingLabel.position.set(2.05, 1.03, SHEET.thickness / 2 + 0.035);
flatScene.add(flatMovingLabel);
flatScene.add(createFoldLine());
const flatFoldLabel = makeSprite("FOLD AXIS", "#ffd166", 1.35, 0.34);
flatFoldLabel.position.set(0, 2.03, 0.14);
flatScene.add(flatFoldLabel);
SHEET.holeXs.forEach((x, index) => {
flatScene.add(createHoleRing(x));
const label = makeSprite(`H${index + 1}`, "#46dfd0", 0.42, 0.26);
label.position.set(x, 0.48, 0.14);
flatScene.add(label);
});
// Subtle drafting grid behind the flat pattern.
const flatGridPoints = [];
for (let x = -4; x <= 4; x += 0.5) {
flatGridPoints.push(
new THREE.Vector3(x, -SHEET.height / 2, -0.1),
new THREE.Vector3(x, SHEET.height / 2, -0.1)
);
}
for (let y = -SHEET.height / 2; y <= SHEET.height / 2; y += 0.5) {
flatGridPoints.push(
new THREE.Vector3(-4, y, -0.1),
new THREE.Vector3(4, y, -0.1)
);
}
const flatGrid = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(flatGridPoints),
new THREE.LineBasicMaterial({
color: 0x29425b,
transparent: true,
opacity: 0.28
})
);
flatScene.add(flatGrid);
function resizeFlatPattern() {
const width = Math.max(1, flatCanvas.clientWidth);
const height = Math.max(1, flatCanvas.clientHeight);
const aspect = width / height;
const viewWidth = 9.45;
const viewHeight = Math.max(5.1, viewWidth / aspect);
flatCamera.left = -viewWidth / 2;
flatCamera.right = viewWidth / 2;
flatCamera.top = viewHeight / 2;
flatCamera.bottom = -viewHeight / 2;
flatCamera.updateProjectionMatrix();
flatRenderer.setSize(width, height, false);
}
const flatResizeObserver = new ResizeObserver(resizeFlatPattern);
flatResizeObserver.observe(flatCanvas);
resizeFlatPattern();
// ---------------------------------------------------------------
// Direct camera controls — no external controls module
// ---------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi -= dy * 0.005;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
// ---------------------------------------------------------------
// UI and animation
// ---------------------------------------------------------------
const flatButton = document.getElementById("flatButton");
const bendButton = document.getElementById("bendButton");
const animateButton = document.getElementById("animateButton");
const resetButton = document.getElementById("resetButton");
const bendRange = document.getElementById("bendRange");
const angleValue = document.getElementById("angleValue");
const maxBend = THREE.MathUtils.degToRad(70);
let currentBend = 0;
let desiredBend = 0;
let scrubbing = false;
function setDesiredBend(radians) {
desiredBend = THREE.MathUtils.clamp(radians, 0, maxBend);
flatButton.classList.toggle("active", desiredBend === 0);
bendButton.classList.toggle("active", Math.abs(desiredBend - maxBend) < 0.001);
flatButton.setAttribute(
"aria-pressed",
String(desiredBend === 0)
);
bendButton.setAttribute(
"aria-pressed",
String(Math.abs(desiredBend - maxBend) < 0.001)
);
}
flatButton.addEventListener("click", () => setDesiredBend(0));
bendButton.addEventListener("click", () => setDesiredBend(maxBend));
animateButton.addEventListener("click", () => {
setDesiredBend(currentBend < maxBend * 0.5 ? maxBend : 0);
});
bendRange.addEventListener("pointerdown", () => {
scrubbing = true;
});
window.addEventListener("pointerup", () => {
scrubbing = false;
});
bendRange.addEventListener("input", () => {
setDesiredBend(THREE.MathUtils.degToRad(Number(bendRange.value)));
});
resetButton.addEventListener("click", () => {
orbit.radius = defaultCamera.radius;
orbit.theta = defaultCamera.theta;
orbit.phi = defaultCamera.phi;
cameraTarget.set(0.2, 0.85, 0);
updateCamera();
});
function resizeMainScene() {
const width = Math.max(1, sceneHost.clientWidth);
const height = Math.max(1, sceneHost.clientHeight);
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const mainResizeObserver = new ResizeObserver(resizeMainScene);
mainResizeObserver.observe(sceneHost);
resizeMainScene();
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
const smoothing = 1 - Math.exp(-5.2 * delta);
currentBend += (desiredBend - currentBend) * smoothing;
if (Math.abs(desiredBend - currentBend) < 0.00008) {
currentBend = desiredBend;
}
movingPivot.rotation.y = -currentBend;
updateArc(currentBend);
const degrees = THREE.MathUtils.radToDeg(currentBend);
angleValue.textContent = `${Math.round(degrees)}°`;
if (!scrubbing) {
bendRange.value = String(Math.round(degrees));
}
renderer.render(scene, camera);
flatRenderer.render(flatScene, flatCamera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```