Prompt specification
Build or customize the Three.js 3D scene "Lock gate hinge and chamber wall" 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: Lock gate hinge and chamber wall
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/lock-gate-hinge-and-chamber-wall-x2457
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows the opening of the Panama Canal in 1914. Build a simplified Panama-style lock gate segment beside its chamber wall. Show the hinge axis and closing angle, keeping the gate visibly separate from the concrete structure. Stylized solid forms.
Working Three.js Starter (lock-gate-hinge-and-chamber-wall-x2457):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Opening of the Panama Canal — 1914</title>
<style>
:root {
--ink: #172b30;
--muted: #62777a;
--paper: rgba(248, 246, 238, 0.94);
--line: rgba(23, 43, 48, 0.16);
--rust: #8f4337;
--concrete: #b9b5a9;
--amber: #f0b83d;
}
* {
box-sizing: border-box;
}
html,
body,
#app {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
background: #d8e3df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.title-block {
position: absolute;
top: 28px;
left: 30px;
max-width: 430px;
text-shadow: 0 1px 14px rgba(255, 255, 255, 0.65);
}
.kicker {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 7px;
color: #4f686b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
}
.kicker::before {
width: 30px;
height: 2px;
content: "";
background: var(--rust);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4.4vw, 58px);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.045em;
}
h1 span {
display: block;
margin-top: 8px;
color: var(--rust);
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.28em;
}
.subtitle {
max-width: 360px;
margin: 13px 0 0;
color: #526a6d;
font-size: 13px;
line-height: 1.5;
}
.legend {
position: absolute;
top: 28px;
right: 28px;
width: 225px;
padding: 16px 17px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 4px;
background: rgba(248, 246, 238, 0.82);
box-shadow: 0 10px 35px rgba(39, 57, 57, 0.1);
backdrop-filter: blur(10px);
}
.legend-title {
margin-bottom: 10px;
color: #6b7d7e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin: 8px 0;
font-size: 12px;
font-weight: 650;
}
.swatch {
width: 18px;
height: 8px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.gate {
background: var(--rust);
}
.swatch.concrete {
background: var(--concrete);
}
.swatch.axis {
height: 3px;
background: var(--amber);
}
.legend-note {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.controls {
position: absolute;
right: 28px;
bottom: 27px;
width: 390px;
padding: 18px 19px 16px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 5px;
background: var(--paper);
box-shadow: 0 14px 40px rgba(33, 49, 49, 0.15);
pointer-events: auto;
backdrop-filter: blur(12px);
}
.readout {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 20px;
}
.readout-label {
color: #627477;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
}
.angle-number {
margin-top: 2px;
font-family: Georgia, "Times New Roman", serif;
font-size: 38px;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.angle-state {
margin-top: 5px;
color: var(--rust);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 24px;
margin: 12px 0 4px;
accent-color: var(--rust);
cursor: pointer;
}
.range-labels {
display: flex;
justify-content: space-between;
color: #758587;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.button-row {
display: flex;
gap: 8px;
margin-top: 14px;
}
button {
min-height: 36px;
padding: 0 14px;
border: 1px solid rgba(23, 43, 48, 0.18);
border-radius: 3px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
cursor: pointer;
transition:
background 150ms ease,
color 150ms ease,
transform 150ms ease;
}
button:hover {
background: var(--ink);
color: #f7f4eb;
}
button:active {
transform: translateY(1px);
}
button.primary {
flex: 1;
border-color: var(--rust);
background: var(--rust);
color: white;
}
button.primary:hover {
background: #71362e;
}
.caption {
position: absolute;
left: 30px;
bottom: 28px;
max-width: 310px;
color: #4f686b;
font-size: 11px;
line-height: 1.55;
text-shadow: 0 1px 10px rgba(255, 255, 255, 0.8);
}
.caption strong {
display: block;
margin-bottom: 3px;
color: var(--ink);
font-size: 10px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.help {
position: absolute;
right: 30px;
bottom: 225px;
color: rgba(31, 55, 59, 0.65);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.annotation {
position: absolute;
z-index: 8;
display: none;
transform: translate(-50%, -50%);
white-space: nowrap;
pointer-events: none;
transition: opacity 120ms linear;
}
.annotation.axis-label {
padding: 7px 10px;
border-left: 3px solid var(--amber);
border-radius: 2px;
background: rgba(248, 246, 238, 0.92);
color: #4e5d5e;
box-shadow: 0 5px 16px rgba(28, 42, 42, 0.13);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
}
.annotation.angle-label {
padding: 8px 11px;
border: 1px solid rgba(240, 184, 61, 0.8);
border-radius: 3px;
background: rgba(25, 39, 40, 0.9);
color: #ffd66b;
box-shadow: 0 6px 18px rgba(28, 42, 42, 0.17);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
}
.vignette {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 50%, rgba(45, 64, 62, 0.1) 100%);
}
@media (max-width: 760px) {
.title-block {
top: 19px;
left: 19px;
}
.subtitle,
.legend,
.caption,
.help {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
left: 14px;
width: auto;
padding: 15px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="vignette"></div>
<div class="ui">
<header class="title-block">
<div class="kicker">Opening of the Panama Canal</div>
<h1>
Gatún Locks
<span>1914</span>
</h1>
<p class="subtitle">
A simplified study of a Panama-style steel miter gate beside the
chamber wall, with its vertical hinge axis and closing angle exposed.
</p>
</header>
<aside class="legend">
<div class="legend-title">Scene key</div>
<div class="legend-row">
<span class="swatch gate"></span>
Steel gate leaf
</div>
<div class="legend-row">
<span class="swatch concrete"></span>
Concrete chamber
</div>
<div class="legend-row">
<span class="swatch axis"></span>
Hinge and angle guides
</div>
<div class="legend-note">
The gate is held visually clear of the concrete so the rotating
assembly remains legible.
</div>
</aside>
<section class="controls">
<div class="readout">
<div>
<div class="readout-label">Closing angle</div>
<div class="angle-number" id="angleNumber">46°</div>
</div>
<div class="angle-state" id="angleState">Swinging</div>
</div>
<input
id="angleSlider"
type="range"
min="0"
max="75"
step="1"
value="46"
aria-label="Gate closing angle"
/>
<div class="range-labels">
<span>0° · Open datum</span>
<span>75° · Miter closed</span>
</div>
<div class="button-row">
<button class="primary" id="motionButton" type="button">
▶ Animate closing
</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</section>
<div class="caption">
<strong>Engineering diagram · not to scale</strong>
Closing angle is measured from the wall-parallel open datum. The closed
75° gate position produces the characteristic 15° miter offset.
</div>
<div class="help">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</div>
<div class="annotation axis-label" id="axisLabel">
VERTICAL HINGE AXIS
</div>
<div class="annotation angle-label" id="angleLabel">
CLOSING ANGLE · 46°
</div>
<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 app = document.getElementById("app");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(app.clientWidth, app.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9e5e1);
scene.fog = new THREE.Fog(0xd9e5e1, 27, 68);
const camera = new THREE.PerspectiveCamera(
42,
app.clientWidth / app.clientHeight,
0.1,
100
);
const state = {
angle: 46,
cameraTheta: 0.58,
cameraPhi: 1.03,
cameraRadius: 19.5,
target: new THREE.Vector3(-0.2, 1.15, 0),
animating: false
};
const HINGE = new THREE.Vector3(-0.8, 0, -3.78);
const ARC_RADIUS = 1.62;
const ARC_SEGMENTS = 44;
const hemisphere = new THREE.HemisphereLight(
0xf4fbfa,
0x746451,
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d8, 3.1);
sun.position.set(-8, 15, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9df, 1.05);
fill.position.set(10, 7, -12);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and helpers
// -------------------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.04,
...options
});
}
const materials = {
ground: standardMaterial(0xb3a17e, { roughness: 1 }),
floor: standardMaterial(0x8c8980),
concrete: standardMaterial(0xb9b5a9),
concreteDark: standardMaterial(0xa39f94),
concreteLight: standardMaterial(0xcac5b8),
joint: standardMaterial(0x8c8a83),
recess: standardMaterial(0x5e625e),
water: standardMaterial(0x68999b, {
transparent: true,
opacity: 0.83,
roughness: 0.3,
metalness: 0.08
}),
waterLight: standardMaterial(0xa6c9c5, {
transparent: true,
opacity: 0.23,
roughness: 0.5
}),
gate: standardMaterial(0x91473c, {
roughness: 0.64,
metalness: 0.25
}),
gateDark: standardMaterial(0x5a2927, {
roughness: 0.62,
metalness: 0.3
}),
gateFrame: standardMaterial(0x462321, {
roughness: 0.6,
metalness: 0.32
}),
hinge: standardMaterial(0x3c4241, {
roughness: 0.42,
metalness: 0.7
}),
house: standardMaterial(0xe4d9bd),
roof: standardMaterial(0x8b4136),
window: standardMaterial(0x40585a, {
roughness: 0.35,
metalness: 0.12
}),
hill: standardMaterial(0x718b71),
hillLight: standardMaterial(0x82977a),
hull: standardMaterial(0x304b4b),
cabin: standardMaterial(0xe1d6b7),
stack: standardMaterial(0x934a37),
mast: standardMaterial(0x544b3d)
};
function addBox(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Stylized surroundings
// -------------------------------------------------------------------------
addBox(72, 0.3, 72, materials.ground, 0, -0.82, 0);
const hillData = [
[-15, 6.8, -18, 7.2],
[-7, 4.8, -21, 5.6],
[2, 7.6, -23, 8.2],
[11, 5.4, -20, 6.3],
[19, 8.5, -25, 9.1]
];
hillData.forEach(([x, radius, z, height], index) => {
const hill = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, 5),
index % 2 ? materials.hill : materials.hillLight
);
hill.position.set(x, height / 2 - 0.65, z);
hill.rotation.y = index * 0.71;
hill.castShadow = true;
hill.receiveShadow = true;
scene.add(hill);
});
// Lock chamber floor and water.
addBox(22.3, 0.32, 9.35, materials.floor, 0, -0.49, 0);
addBox(21.65, 0.1, 8.45, materials.water, 0, -0.27, 0);
// Subtle solid ripple shapes.
[
[-7.4, 2.7, 4.8],
[-2.2, -2.4, 3.4],
[3.8, 2.1, 4.1],
[7.1, -1.9, 3.1],
[-4.2, 1.4, 2.3]
].forEach(([x, z, length], index) => {
const ripple = addBox(
length,
0.012,
0.07,
materials.waterLight,
x,
-0.213,
z
);
ripple.rotation.y = index % 2 ? 0.12 : -0.09;
ripple.castShadow = false;
});
// Full far wall.
addBox(
22.3,
4.4,
0.9,
materials.concrete,
0,
1.55,
-4.7
);
// Low cutaway wall on the camera side.
addBox(
22.3,
1.6,
0.9,
materials.concreteDark,
0,
0.15,
4.7
);
// Capstones.
for (let i = 0; i < 10; i++) {
const x = -9.9 + i * 2.2;
addBox(
2.12,
0.24,
1.04,
i % 2 ? materials.concreteLight : materials.concrete,
x,
3.86,
-4.7
);
addBox(
2.12,
0.18,
1.02,
i % 2 ? materials.concrete : materials.concreteLight,
x,
1.04,
4.7
);
}
// Vertical construction joints on the far wall.
for (let i = -4; i <= 4; i++) {
addBox(
0.026,
3.78,
0.026,
materials.joint,
i * 2.25,
1.5,
-4.235
);
}
// Dark hinge recess behind, with the steel assembly clearly offset in front.
addBox(
0.58,
3.35,
0.035,
materials.recess,
HINGE.x,
1.46,
-4.215
);
// Small period lock-house/control pavilion.
const lockHouse = new THREE.Group();
lockHouse.position.set(6.15, 3.82, -4.78);
scene.add(lockHouse);
addBox(
1.85,
1.15,
1.25,
materials.house,
0,
0.575,
0,
lockHouse
);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(1.42, 0.58, 4),
materials.roof
);
roof.position.y = 1.43;
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.83;
roof.castShadow = true;
lockHouse.add(roof);
addBox(
0.38,
0.4,
0.025,
materials.window,
-0.42,
0.64,
0.638,
lockHouse
);
addBox(
0.38,
0.4,
0.025,
materials.window,
0.42,
0.64,
0.638,
lockHouse
);
// -------------------------------------------------------------------------
// Small stylized 1914 steamer
// -------------------------------------------------------------------------
const ship = new THREE.Group();
ship.position.set(-5.35, 0, 0.72);
scene.add(ship);
const hullShape = new THREE.Shape();
hullShape.moveTo(-1.5, -0.43);
hullShape.lineTo(1.12, -0.43);
hullShape.lineTo(1.65, 0);
hullShape.lineTo(1.12, 0.43);
hullShape.lineTo(-1.5, 0.43);
hullShape.closePath();
const hullGeometry = new THREE.ExtrudeGeometry(hullShape, {
depth: 0.42,
bevelEnabled: true,
bevelThickness: 0.07,
bevelSize: 0.06,
bevelSegments: 1,
steps: 1
});
hullGeometry.rotateX(-Math.PI / 2);
const hull = new THREE.Mesh(hullGeometry, materials.hull);
hull.position.y = -0.23;
hull.castShadow = true;
hull.receiveShadow = true;
ship.add(hull);
addBox(2.45, 0.11, 0.84, materials.cabin, 0.03, 0.27, 0, ship);
addBox(1.02, 0.48, 0.61, materials.cabin, 0.13, 0.55, 0, ship);
addBox(0.52, 0.32, 0.64, materials.cabin, 0.57, 0.47, 0, ship);
const stack = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.18, 0.58, 12),
materials.stack
);
stack.position.set(-0.67, 0.69, 0);
stack.castShadow = true;
ship.add(stack);
const mast = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.045, 1.35, 8),
materials.mast
);
mast.position.set(0.73, 0.93, 0);
mast.castShadow = true;
ship.add(mast);
addBox(
0.65,
0.055,
0.055,
materials.mast,
0.54,
1.16,
0,
ship
);
// -------------------------------------------------------------------------
// Panama-style miter gate leaf
// -------------------------------------------------------------------------
const gatePivot = new THREE.Group();
gatePivot.position.copy(HINGE);
scene.add(gatePivot);
const GATE_LENGTH = 4.1;
const GATE_HEIGHT = 3.35;
const GATE_BOTTOM = -0.18;
const GATE_TOP = GATE_BOTTOM + GATE_HEIGHT;
const GATE_THICKNESS = 0.38;
// Main steel plate.
addBox(
GATE_LENGTH - 0.12,
GATE_HEIGHT,
GATE_THICKNESS,
materials.gate,
(GATE_LENGTH + 0.12) / 2,
GATE_BOTTOM + GATE_HEIGHT / 2,
0,
gatePivot
);
// Top and bottom horizontal girders.
addBox(
GATE_LENGTH,
0.22,
0.48,
materials.gateFrame,
GATE_LENGTH / 2,
GATE_TOP - 0.11,
0,
gatePivot
);
addBox(
GATE_LENGTH,
0.22,
0.48,
materials.gateFrame,
GATE_LENGTH / 2,
GATE_BOTTOM + 0.11,
0,
gatePivot
);
// Vertical stiffeners.
for (let i = 0; i < 5; i++) {
const x = 0.52 + i * 0.82;
addBox(
0.16,
GATE_HEIGHT - 0.28,
0.18,
materials.gateDark,
x,
GATE_BOTTOM + GATE_HEIGHT / 2,
0.28,
gatePivot
);
}
// Stylized diagonal bracing.
function addDiagonal(x1, y1, x2, y2, z) {
const length = Math.hypot(x2 - x1, y2 - y1);
const brace = addBox(
length,
0.125,
0.15,
materials.gateFrame,
(x1 + x2) / 2,
(y1 + y2) / 2,
z,
gatePivot
);
brace.rotation.z = Math.atan2(y2 - y1, x2 - x1);
}
addDiagonal(0.38, GATE_BOTTOM + 0.34, 3.76, GATE_TOP - 0.34, 0.39);
addDiagonal(0.38, GATE_TOP - 0.34, 3.76, GATE_BOTTOM + 0.34, 0.40);
// Hinge rings, leaving the highlighted axis visible through them.
[-0.02, 0.94, 1.94, 2.94].forEach((y) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.22, 0.055, 8, 24),
materials.hinge
);
ring.position.set(0, y, 0);
ring.rotation.x = Math.PI / 2;
ring.castShadow = true;
gatePivot.add(ring);
});
// Highlighted vertical hinge axis.
const axisMaterial = new THREE.MeshBasicMaterial({
color: 0xf0b83d,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const hingeAxis = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.065, 4.28, 16),
axisMaterial
);
hingeAxis.position.set(HINGE.x, 1.62, HINGE.z);
hingeAxis.renderOrder = 30;
scene.add(hingeAxis);
const axisArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.16, 0.38, 16),
axisMaterial
);
axisArrow.position.set(HINGE.x, 3.95, HINGE.z);
axisArrow.renderOrder = 30;
scene.add(axisArrow);
// -------------------------------------------------------------------------
// Angle guide: open datum, arc, translucent wedge, endpoint
// -------------------------------------------------------------------------
const guideMaterial = new THREE.LineBasicMaterial({
color: 0xf0b83d,
depthTest: false,
depthWrite: false,
transparent: true,
opacity: 0.95,
toneMapped: false
});
const datumMaterial = new THREE.LineDashedMaterial({
color: 0xffd46b,
dashSize: 0.16,
gapSize: 0.11,
depthTest: false,
depthWrite: false,
transparent: true,
opacity: 0.85,
toneMapped: false
});
const datumGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(HINGE.x, 0.36, HINGE.z),
new THREE.Vector3(HINGE.x + 2.05, 0.36, HINGE.z)
]);
const datumLine = new THREE.Line(datumGeometry, datumMaterial);
datumLine.computeLineDistances();
datumLine.renderOrder = 27;
scene.add(datumLine);
const arcPositions = new Float32Array((ARC_SEGMENTS + 1) * 3);
const arcGeometry = new THREE.BufferGeometry();
arcGeometry.setAttribute(
"position",
new THREE.BufferAttribute(arcPositions, 3)
);
const arcLine = new THREE.Line(arcGeometry, guideMaterial);
arcLine.renderOrder = 28;
scene.add(arcLine);
// A broad, translucent sector makes the angle readable at a glance.
const wedgePositions = new Float32Array((ARC_SEGMENTS + 2) * 3);
const wedgeIndices = [];
for (let i = 0; i < ARC_SEGMENTS; i++) {
wedgeIndices.push(0, i + 1, i + 2);
}
const wedgeGeometry = new THREE.BufferGeometry();
wedgeGeometry.setAttribute(
"position",
new THREE.BufferAttribute(wedgePositions, 3)
);
wedgeGeometry.setIndex(wedgeIndices);
const wedgeMaterial = new THREE.MeshBasicMaterial({
color: 0xf0b83d,
transparent: true,
opacity: 0.15,
side: THREE.DoubleSide,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const angleWedge = new THREE.Mesh(wedgeGeometry, wedgeMaterial);
angleWedge.renderOrder = 26;
scene.add(angleWedge);
const endpoint = new THREE.Mesh(
new THREE.SphereGeometry(0.085, 12, 8),
axisMaterial
);
endpoint.renderOrder = 29;
scene.add(endpoint);
// -------------------------------------------------------------------------
// UI and angle updates
// -------------------------------------------------------------------------
const angleSlider = document.getElementById("angleSlider");
const angleNumber = document.getElementById("angleNumber");
const angleState = document.getElementById("angleState");
const angleLabel = document.getElementById("angleLabel");
const motionButton = document.getElementById("motionButton");
const resetButton = document.getElementById("resetButton");
const axisLabel = document.getElementById("axisLabel");
const axisAnchor = new THREE.Vector3(
HINGE.x,
4.28,
HINGE.z
);
const angleAnchor = new THREE.Vector3();
function updateAngleGeometry() {
const radians = THREE.MathUtils.degToRad(state.angle);
// Arc line.
for (let i = 0; i <= ARC_SEGMENTS; i++) {
const a = radians * (i / ARC_SEGMENTS);
const offset = i * 3;
arcPositions[offset] = HINGE.x + Math.cos(a) * ARC_RADIUS;
arcPositions[offset + 1] = 0.365;
arcPositions[offset + 2] = HINGE.z + Math.sin(a) * ARC_RADIUS;
}
arcGeometry.attributes.position.needsUpdate = true;
arcGeometry.computeBoundingSphere();
// Translucent wedge.
wedgePositions[0] = HINGE.x;
wedgePositions[1] = 0.355;
wedgePositions[2] = HINGE.z;
for (let i = 0; i <= ARC_SEGMENTS; i++) {
const a = radians * (i / ARC_SEGMENTS);
const offset = (i + 1) * 3;
wedgePositions[offset] = HINGE.x + Math.cos(a) * ARC_RADIUS;
wedgePositions[offset + 1] = 0.355;
wedgePositions[offset + 2] = HINGE.z + Math.sin(a) * ARC_RADIUS;
}
wedgeGeometry.attributes.position.needsUpdate = true;
wedgeGeometry.computeBoundingSphere();
endpoint.position.set(
HINGE.x + Math.cos(radians) * ARC_RADIUS,
0.39,
HINGE.z + Math.sin(radians) * ARC_RADIUS
);
const midpoint = radians * 0.5;
angleAnchor.set(
HINGE.x + Math.cos(midpoint) * (ARC_RADIUS + 0.16),
0.96,
HINGE.z + Math.sin(midpoint) * (ARC_RADIUS + 0.16)
);
}
function setGateAngle(degrees) {
state.angle = THREE.MathUtils.clamp(degrees, 0, 75);
const rounded = Math.round(state.angle);
gatePivot.rotation.y = -THREE.MathUtils.degToRad(state.angle);
angleSlider.value = String(rounded);
angleNumber.textContent = `${rounded}°`;
angleLabel.textContent = `CLOSING ANGLE · ${rounded}°`;
if (state.angle < 4) {
angleState.textContent = "Open datum";
} else if (state.angle > 72) {
angleState.textContent = "Miter closed";
} else {
angleState.textContent = "Swinging";
}
updateAngleGeometry();
}
angleSlider.addEventListener("input", () => {
state.animating = false;
motionButton.textContent = "▶ Animate closing";
setGateAngle(Number(angleSlider.value));
});
motionButton.addEventListener("click", () => {
state.animating = !state.animating;
if (state.animating) {
if (state.angle >= 74.5) {
setGateAngle(0);
}
motionButton.textContent = "■ Pause motion";
} else {
motionButton.textContent = "▶ Animate closing";
}
});
// -------------------------------------------------------------------------
// Custom camera controls — no addons or OrbitControls
// -------------------------------------------------------------------------
function updateCamera() {
const sinPhi = Math.sin(state.cameraPhi);
const cosPhi = Math.cos(state.cameraPhi);
camera.position.set(
state.target.x +
state.cameraRadius * sinPhi * Math.sin(state.cameraTheta),
state.target.y + state.cameraRadius * cosPhi,
state.target.z +
state.cameraRadius * sinPhi * Math.cos(state.cameraTheta)
);
camera.lookAt(state.target);
camera.updateMatrixWorld();
}
function resetCamera() {
state.cameraTheta = 0.58;
state.cameraPhi = 1.03;
state.cameraRadius = 19.5;
state.target.set(-0.2, 1.15, 0);
updateCamera();
}
resetButton.addEventListener("click", resetCamera);
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
state.cameraTheta -= deltaX * 0.005;
state.cameraPhi = THREE.MathUtils.clamp(
state.cameraPhi - deltaY * 0.0045,
0.35,
1.42
);
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
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("dblclick", resetCamera);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
state.cameraRadius = THREE.MathUtils.clamp(
state.cameraRadius + event.deltaY * 0.012,
10,
32
);
},
{ passive: false }
);
renderer.domElement.style.cursor = "grab";
// -------------------------------------------------------------------------
// Project 3D annotation anchors into HTML positions
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function positionAnnotation(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * app.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * app.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function resize() {
const width = app.clientWidth;
const height = app.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function render() {
requestAnimationFrame(render);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.animating) {
setGateAngle(state.angle + delta * 10.5);
if (state.angle >= 75) {
state.animating = false;
motionButton.textContent = "↻ Close again";
}
}
updateCamera();
positionAnnotation(axisLabel, axisAnchor);
positionAnnotation(angleLabel, angleAnchor);
renderer.render(scene, camera);
}
setGateAngle(state.angle);
updateCamera();
render();
</script>
</body>
</html>
```