Prompt specification
Build or customize the Three.js 3D scene "Broken Hinge and Replaceable Part Tray" 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: Broken Hinge and Replaceable Part Tray
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/broken-hinge-and-replaceable-part-tray-x3957
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: broken hinge and replaceable part tray. Model a small box with a visibly failed hinge beside a compatible replacement. Show the specific lost function and the interface needed to restore it.
Working Three.js Starter (broken-hinge-and-replaceable-part-tray-x3957):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Failed Hinge — Replacement Part Tray</title>
<style>
:root {
color-scheme: dark;
--bg: #07131b;
--panel: rgba(10, 25, 34, 0.88);
--line: rgba(166, 209, 220, 0.18);
--text: #e6f2f4;
--muted: #8da7af;
--orange: #ff8358;
--mint: #68e8bd;
--cyan: #82d9ec;
--danger: #ff6b61;
}
* { 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 { font: inherit; }
#app {
position: fixed;
inset: 0;
background:
radial-gradient(circle at 55% 38%, rgba(40, 83, 96, 0.16), transparent 38%),
var(--bg);
}
#app canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.ui {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.header {
position: absolute;
top: 25px;
left: 28px;
display: flex;
align-items: center;
gap: 13px;
pointer-events: none;
}
.brand-mark {
width: 39px;
height: 39px;
display: grid;
place-items: center;
border: 1px solid rgba(130, 217, 236, 0.45);
background: rgba(8, 24, 32, 0.75);
color: var(--cyan);
font: 700 13px ui-monospace, monospace;
transform: rotate(45deg);
box-shadow: 0 0 25px rgba(130, 217, 236, 0.08);
}
.brand-mark span {
transform: rotate(-45deg);
}
.header h1 {
margin: 0;
font-size: 18px;
line-height: 1.05;
letter-spacing: 0.12em;
font-weight: 760;
}
.header p {
margin: 6px 0 0;
color: var(--muted);
font: 600 10px/1.3 ui-monospace, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.controls {
position: absolute;
top: 25px;
right: 28px;
display: flex;
gap: 8px;
pointer-events: auto;
}
.control {
min-height: 39px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 4px;
color: #cfe0e4;
background: rgba(9, 24, 32, 0.78);
backdrop-filter: blur(14px);
cursor: pointer;
transition:
border-color 160ms ease,
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.control:hover {
color: white;
border-color: rgba(130, 217, 236, 0.48);
background: rgba(19, 44, 55, 0.9);
transform: translateY(-1px);
}
.control:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
.control.primary {
border-color: rgba(255, 131, 88, 0.45);
color: #ffd4c5;
}
.control.active {
border-color: rgba(104, 232, 189, 0.65);
color: #c8ffeb;
background: rgba(21, 70, 60, 0.82);
}
.diagnosis {
position: absolute;
left: 28px;
bottom: 27px;
width: 356px;
padding: 20px 21px 19px;
border: 1px solid var(--line);
border-radius: 8px;
background:
linear-gradient(145deg, rgba(19, 39, 48, 0.93), rgba(8, 20, 28, 0.91));
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font: 700 10px/1 ui-monospace, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 19px;
height: 2px;
background: var(--orange);
box-shadow: 0 0 12px rgba(255, 131, 88, 0.5);
}
.diagnosis h2 {
margin: 14px 0 8px;
font-size: 23px;
line-height: 1.16;
letter-spacing: -0.02em;
}
.diagnosis p {
margin: 0;
color: #a9bdc3;
font-size: 12px;
line-height: 1.55;
}
.function-strip {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 17px 0 16px;
}
.metric {
padding: 11px 12px;
border: 1px solid rgba(166, 209, 220, 0.12);
border-radius: 4px;
background: rgba(0, 0, 0, 0.12);
}
.metric label {
display: block;
margin-bottom: 7px;
color: #708a92;
font: 700 9px/1 ui-monospace, monospace;
letter-spacing: 0.13em;
}
.metric strong {
display: block;
font: 700 20px/1 ui-monospace, monospace;
}
.metric small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
}
.metric.blocked strong { color: var(--orange); }
.angle-track {
height: 4px;
margin: -7px 0 17px;
overflow: hidden;
border-radius: 4px;
background: rgba(255, 255, 255, 0.06);
}
.angle-fill {
width: 64%;
height: 100%;
background: linear-gradient(90deg, var(--orange), #ffd07a);
box-shadow: 0 0 10px rgba(255, 131, 88, 0.45);
transition: width 100ms linear;
}
.interface-title {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
color: var(--mint);
font: 700 10px/1 ui-monospace, monospace;
letter-spacing: 0.13em;
}
.interface-title span {
color: #77939b;
letter-spacing: 0.08em;
}
.specs {
display: grid;
gap: 8px;
margin: 0;
padding: 0;
list-style: none;
}
.specs li {
display: flex;
align-items: center;
gap: 9px;
color: #b9cbd0;
font-size: 11px;
}
.specs i {
width: 7px;
height: 7px;
border: 1px solid var(--mint);
border-radius: 50%;
box-shadow: 0 0 9px rgba(104, 232, 189, 0.35);
}
.status {
position: absolute;
right: 28px;
bottom: 28px;
width: 285px;
padding: 14px 16px;
border: 1px solid var(--line);
border-left: 3px solid var(--cyan);
border-radius: 5px;
background: rgba(8, 23, 31, 0.86);
backdrop-filter: blur(12px);
pointer-events: none;
}
.status strong {
display: block;
margin-bottom: 5px;
color: #dcebee;
font: 700 10px/1.3 ui-monospace, monospace;
letter-spacing: 0.11em;
}
.status span {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.status.danger {
border-left-color: var(--danger);
}
.status.danger strong { color: #ffaaa3; }
.status.match {
border-left-color: var(--mint);
}
.status.match strong { color: #a7f3d7; }
.hint {
position: absolute;
left: 50%;
bottom: 25px;
transform: translateX(-50%);
color: rgba(172, 196, 202, 0.55);
font: 600 9px/1 ui-monospace, monospace;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
}
#leaders {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
.annotation {
position: absolute;
z-index: 3;
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px 7px 7px;
border: 1px solid rgba(166, 209, 220, 0.2);
border-radius: 3px;
color: #d8e7ea;
background: rgba(7, 20, 27, 0.86);
box-shadow: 0 8px 26px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(9px);
transform: translate(-50%, -50%);
font: 700 9px/1 ui-monospace, monospace;
letter-spacing: 0.08em;
white-space: nowrap;
pointer-events: none;
transition: opacity 180ms ease;
}
.annotation b {
display: grid;
place-items: center;
width: 20px;
height: 20px;
border-radius: 2px;
background: rgba(255, 131, 88, 0.13);
color: var(--orange);
}
.annotation.mint b {
background: rgba(104, 232, 189, 0.13);
color: var(--mint);
}
.annotation.cyan b {
background: rgba(130, 217, 236, 0.13);
color: var(--cyan);
}
@media (max-width: 760px) {
.header { top: 17px; left: 17px; }
.header h1 { font-size: 14px; }
.header p { font-size: 8px; }
.brand-mark { width: 32px; height: 32px; }
.controls {
top: 69px;
left: 17px;
right: 17px;
flex-wrap: wrap;
}
.control {
min-height: 34px;
padding: 0 10px;
font-size: 10px;
}
.diagnosis {
left: 14px;
bottom: 14px;
width: calc(100% - 28px);
padding: 14px;
}
.diagnosis h2 { font-size: 18px; }
.diagnosis p { font-size: 10px; }
.function-strip { margin: 12px 0; }
.angle-track { margin-bottom: 12px; }
.specs { grid-template-columns: 1fr 1fr; gap: 6px; }
.specs li { font-size: 9px; }
.status {
right: 14px;
bottom: 245px;
width: 235px;
padding: 10px 12px;
}
.hint { display: none; }
.annotation { font-size: 7px; padding: 5px 7px 5px 5px; }
.annotation b { width: 17px; height: 17px; }
}
</style>
</head>
<body>
<div id="app"></div>
<div class="ui">
<header class="header">
<div class="brand-mark"><span>H6</span></div>
<div>
<h1>HINGE REPAIR BAY</h1>
<p>Field case 07 / failed motion study</p>
</div>
</header>
<nav class="controls" aria-label="Scene controls">
<button class="control primary" id="testButton">Run failed closure</button>
<button class="control" id="interfaceButton">Reveal mating interface</button>
<button class="control" id="resetButton">Reset scene</button>
</nav>
<section class="diagnosis">
<div class="eyebrow">Failure analysis / H-06</div>
<h2>The lid can no longer close.</h2>
<p>
The lid must rotate about the hinge pin from 105° open to 0° sealed.
A fractured barrel has released the pin, so closure stops before
the axis is fully engaged.
</p>
<div class="function-strip">
<div class="metric">
<label>REQUIRED MOTION</label>
<strong>105°</strong>
<small>open ↔ sealed</small>
</div>
<div class="metric blocked">
<label>LAST REACH</label>
<strong id="currentAngle">68°</strong>
<small id="currentState">open / failed</small>
</div>
</div>
<div class="angle-track">
<div class="angle-fill" id="angleFill"></div>
</div>
<div class="interface-title">
RESTORE INTERFACE
<span>H-06 VERIFIED MATCH</span>
</div>
<ul class="specs">
<li><i></i>Ø6 mm coaxial through-pin</li>
<li><i></i>Two matching barrel ears</li>
<li><i></i>4ר4 mm screw holes</li>
<li><i></i>32 mm mounting-hole pitch</li>
</ul>
</section>
<div class="status" id="statusBox">
<strong id="statusTitle">FAILURE ISOLATED</strong>
<span id="statusText">
The replacement uses the same pin axis, barrel bore, and mounting-hole pattern.
</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset view</div>
<svg id="leaders" aria-hidden="true"></svg>
<div class="annotation" id="failedTag">
<b>01</b><span>FAILED HINGE / PIN RELEASED</span>
</div>
<div class="annotation" id="functionTag">
<b>02</b><span>LOST FUNCTION / CLOSURE PATH</span>
</div>
<div class="annotation mint" id="replacementTag">
<b>03</b><span>H-06 / COMPATIBLE REPLACEMENT</span>
</div>
<div class="annotation cyan" id="interfaceTag">
<b>04</b><span>Ø6 PIN · 4ר4 HOLES · 32 mm PITCH</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const app = document.getElementById("app");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131b);
scene.fog = new THREE.Fog(0x07131b, 10, 22);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraState = {
theta: 0.63,
phi: 1.02,
radius: 8.7,
target: new THREE.Vector3(0.55, 0.08, 0)
};
function updateCamera() {
const s = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * s * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * s * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc5e6ef, 0x16242b, 2.0));
const keyLight = new THREE.DirectionalLight(0xe5f7ff, 3.8);
keyLight.position.set(-3.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x67d8ef, 18, 12, 2);
rimLight.position.set(4.2, 3.4, -3.2);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff8a5e, 9, 5, 2);
warmLight.position.set(-2.4, 1.6, 3.3);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const material = {
body: new THREE.MeshStandardMaterial({
color: 0x304650,
roughness: 0.58,
metalness: 0.22
}),
bodyDark: new THREE.MeshStandardMaterial({
color: 0x172a33,
roughness: 0.72,
metalness: 0.12
}),
lid: new THREE.MeshStandardMaterial({
color: 0x718992,
roughness: 0.48,
metalness: 0.24
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x09161d,
roughness: 0.9,
metalness: 0.02
}),
orange: new THREE.MeshStandardMaterial({
color: 0xff7549,
emissive: 0x411207,
emissiveIntensity: 0.55,
roughness: 0.34,
metalness: 0.68
}),
orangeDark: new THREE.MeshStandardMaterial({
color: 0x9f3d27,
emissive: 0x260702,
emissiveIntensity: 0.4,
roughness: 0.52,
metalness: 0.62
}),
mint: new THREE.MeshStandardMaterial({
color: 0x69e2b9,
emissive: 0x073d30,
emissiveIntensity: 0.45,
roughness: 0.3,
metalness: 0.65
}),
mintDark: new THREE.MeshStandardMaterial({
color: 0x329d7e,
emissive: 0x05271f,
emissiveIntensity: 0.35,
roughness: 0.4,
metalness: 0.58
}),
steel: new THREE.MeshStandardMaterial({
color: 0xc2d1d4,
roughness: 0.24,
metalness: 0.86
}),
pin: new THREE.MeshStandardMaterial({
color: 0xffcf68,
emissive: 0x50320a,
emissiveIntensity: 0.35,
roughness: 0.2,
metalness: 0.85
}),
hole: new THREE.MeshBasicMaterial({ color: 0x02070a }),
tray: new THREE.MeshStandardMaterial({
color: 0x263943,
roughness: 0.64,
metalness: 0.28
}),
trayInsert: new THREE.MeshStandardMaterial({
color: 0x0b1b23,
roughness: 0.93,
metalness: 0.02
}),
floor: new THREE.MeshStandardMaterial({
color: 0x09151c,
roughness: 0.92,
metalness: 0.08
})
};
function roundedRectShape(width, height, radius) {
const w = width / 2;
const h = height / 2;
const r = Math.min(radius, w * 0.95, h * 0.95);
const shape = new THREE.Shape();
shape.moveTo(-w + r, -h);
shape.lineTo(w - r, -h);
shape.quadraticCurveTo(w, -h, w, -h + r);
shape.lineTo(w, h - r);
shape.quadraticCurveTo(w, h, w - r, h);
shape.lineTo(-w + r, h);
shape.quadraticCurveTo(-w, h, -w, h - r);
shape.lineTo(-w, -h + r);
shape.quadraticCurveTo(-w, -h, -w + r, -h);
return shape;
}
// Rounded box with dimensions X × Y × Z.
function roundedBox(width, height, depth, radius, mat) {
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(width, height, radius),
{
depth,
bevelEnabled: false,
curveSegments: 6,
steps: 1
}
);
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// Rounded slab with dimensions X × Z and thickness Y.
function roundedSlab(width, depth, thickness, radius, mat) {
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(width, depth, radius),
{
depth: thickness,
bevelEnabled: false,
curveSegments: 6,
steps: 1
}
);
geometry.translate(0, 0, -thickness / 2);
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function cylinderX(radius, length, mat, arc = Math.PI * 2) {
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
28,
1,
false,
0,
arc
);
geometry.rotateZ(Math.PI / 2);
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function cylinderZ(radius, length, mat) {
const geometry = new THREE.CylinderGeometry(radius, radius, length, 24);
geometry.rotateX(Math.PI / 2);
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
return mesh;
}
function ringAroundX(radius, tube, mat) {
const geometry = new THREE.TorusGeometry(radius, tube, 10, 40);
geometry.rotateY(Math.PI / 2);
const mesh = new THREE.Mesh(geometry, mat);
return mesh;
}
function textPanel(text, width, height, accent = "#82d9ec") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(5, 17, 23, 0.94)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = accent;
ctx.lineWidth = 8;
ctx.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
ctx.fillStyle = accent;
ctx.fillRect(30, 35, 14, canvas.height - 70);
ctx.fillStyle = "#dcebee";
ctx.font = "700 72px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 540, 132);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
toneMapped: false,
depthWrite: false
})
);
mesh.renderOrder = 3;
return mesh;
}
// -------------------------------------------------------------------------
// Workbench, grid, and object platforms
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
material.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.835;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(28, 56, 0x28505a, 0x173039);
grid.position.y = -0.828;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
const boxPlatform = roundedSlab(3.0, 2.42, 0.10, 0.15, material.bodyDark);
boxPlatform.position.set(-1.12, -0.78, 0);
scene.add(boxPlatform);
const floorRing = new THREE.Mesh(
new THREE.RingGeometry(1.48, 1.505, 96),
new THREE.MeshBasicMaterial({
color: 0x4bb8cb,
transparent: true,
opacity: 0.22,
side: THREE.DoubleSide
})
);
floorRing.rotation.x = -Math.PI / 2;
floorRing.position.set(2.25, -0.827, 0);
scene.add(floorRing);
// -------------------------------------------------------------------------
// Small field case and failed lid
// -------------------------------------------------------------------------
const boxX = -1.12;
const pivotPosition = new THREE.Vector3(boxX, 0.755, 0.96);
const boxBody = roundedBox(2.4, 1.4, 1.8, 0.13, material.body);
boxBody.position.set(boxX, -0.02, 0);
scene.add(boxBody);
const topGasket = roundedSlab(2.16, 1.56, 0.045, 0.09, material.rubber);
topGasket.position.set(boxX, 0.691, 0);
scene.add(topGasket);
const boxInset = roundedSlab(1.94, 1.36, 0.025, 0.07, material.bodyDark);
boxInset.position.set(boxX, 0.717, -0.02);
scene.add(boxInset);
const frontLabel = textPanel("FIELD CASE 07", 0.92, 0.23, "#ff8358");
frontLabel.position.set(boxX, 0.02, 0.916);
scene.add(frontLabel);
const latch = roundedBox(0.23, 0.22, 0.13, 0.035, material.steel);
latch.position.set(boxX + 0.82, 0.36, 0.955);
scene.add(latch);
const latchInset = roundedBox(0.10, 0.08, 0.018, 0.015, material.rubber);
latchInset.position.set(boxX + 0.82, 0.36, 1.027);
scene.add(latchInset);
const lidPivot = new THREE.Group();
lidPivot.position.copy(pivotPosition);
scene.add(lidPivot);
const lid = roundedBox(2.46, 0.22, 1.86, 0.11, material.lid);
lid.position.set(0, 0.08, -0.92);
lidPivot.add(lid);
const lidInset = roundedBox(2.14, 0.026, 1.52, 0.08, material.rubber);
lidInset.position.set(0, -0.043, -0.92);
lidPivot.add(lidInset);
const lidInnerRail = roundedBox(1.46, 0.025, 0.08, 0.025, material.bodyDark);
lidInnerRail.position.set(0, -0.061, -0.38);
lidPivot.add(lidInnerRail);
let lidAngle = THREE.MathUtils.degToRad(68);
let lidTarget = lidAngle;
let motionState = "idle";
const jamAngle = THREE.MathUtils.degToRad(12);
lidPivot.rotation.x = lidAngle;
// -------------------------------------------------------------------------
// Failed hinge: base leaf, lid leaf, alternating knuckles, displaced pin
// -------------------------------------------------------------------------
const failedRoot = new THREE.Group();
failedRoot.position.copy(pivotPosition);
scene.add(failedRoot);
const baseLeaf = roundedBox(1.62, 0.34, 0.066, 0.045, material.orangeDark);
baseLeaf.position.set(0, -0.225, 0.012);
failedRoot.add(baseLeaf);
const lidLeaf = roundedBox(1.62, 0.31, 0.066, 0.045, material.orange);
lidLeaf.position.set(0, -0.205, 0.035);
lidPivot.add(lidLeaf);
// Base-side knuckles.
[-0.57, 0, 0.57].forEach((x) => {
const knuckle = cylinderX(0.108, 0.235, material.orangeDark);
knuckle.position.x = x;
failedRoot.add(knuckle);
});
// Intact lid-side knuckle.
const intactLidKnuckle = cylinderX(0.108, 0.235, material.orange);
intactLidKnuckle.position.x = -0.285;
lidPivot.add(intactLidKnuckle);
// Cracked lid-side knuckle: most of the barrel remains, but the bore is open.
const brokenLidKnuckle = cylinderX(
0.108,
0.235,
material.orange,
Math.PI * 1.56
);
brokenLidKnuckle.position.x = 0.285;
lidPivot.add(brokenLidKnuckle);
const fracture = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.11, 0),
material.orangeDark
);
fracture.position.set(0.39, -0.045, 0.075);
fracture.rotation.set(0.4, 0.2, 0.8);
fracture.castShadow = true;
lidPivot.add(fracture);
// Red ghost ring identifies the missing barrel engagement.
const missingEngagement = ringAroundX(
0.128,
0.013,
new THREE.MeshBasicMaterial({
color: 0xff5c55,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
missingEngagement.position.x = 0.285;
missingEngagement.renderOrder = 8;
lidPivot.add(missingEngagement);
// Visible screw holes in the failed base leaf.
[-0.57, 0.57].forEach((x) => {
const hole = cylinderZ(0.046, 0.014, material.hole);
hole.position.set(x, -0.225, 0.052);
failedRoot.add(hole);
});
// Visible screw holes in the failed lid leaf.
[-0.57, 0.57].forEach((x) => {
const hole = cylinderZ(0.046, 0.014, material.hole);
hole.position.set(x, -0.205, 0.075);
lidPivot.add(hole);
});
// The pin has escaped the common axis and sits visibly in front.
const failedPin = new THREE.Group();
failedPin.position.set(-0.03, 0.135, 0.12);
failedPin.rotation.x = 0.18;
failedRoot.add(failedPin);
const failedPinShaft = cylinderX(0.037, 1.48, material.pin);
failedPin.add(failedPinShaft);
const failedPinHead = cylinderX(0.071, 0.058, material.steel);
failedPinHead.position.x = -0.765;
failedPin.add(failedPinHead);
// Desired nominal motion arc, centered on the failed hinge.
const arcPoints = [];
for (let i = 0; i <= 64; i++) {
const angle = THREE.MathUtils.degToRad(105) * (i / 64);
arcPoints.push(
new THREE.Vector3(
boxX + 1.06,
pivotPosition.y + 0.62 * Math.sin(angle),
pivotPosition.z - 0.62 * Math.cos(angle)
)
);
}
const motionArc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(arcPoints),
new THREE.LineDashedMaterial({
color: 0xffc46a,
dashSize: 0.075,
gapSize: 0.055,
transparent: true,
opacity: 0.58
})
);
motionArc.computeLineDistances();
scene.add(motionArc);
const arcEnd = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 18, 12),
new THREE.MeshBasicMaterial({ color: 0xffc46a })
);
arcEnd.position.copy(arcPoints[arcPoints.length - 1]);
scene.add(arcEnd);
// -------------------------------------------------------------------------
// Replacement tray and compatible H-06 hinge
// -------------------------------------------------------------------------
const trayRoot = new THREE.Group();
trayRoot.position.set(2.25, 0, 0);
scene.add(trayRoot);
const trayOuter = roundedSlab(2.68, 2.08, 0.16, 0.16, material.tray);
trayOuter.position.y = -0.74;
trayRoot.add(trayOuter);
const trayInsert = roundedSlab(2.39, 1.79, 0.055, 0.11, material.trayInsert);
trayInsert.position.y = -0.635;
trayRoot.add(trayInsert);
const rimFront = roundedSlab(2.58, 0.11, 0.16, 0.035, material.tray);
rimFront.position.set(0, -0.60, 0.995);
trayRoot.add(rimFront);
const rimBack = rimFront.clone();
rimBack.position.z = -0.995;
trayRoot.add(rimBack);
const rimLeft = roundedSlab(0.11, 1.88, 0.16, 0.035, material.tray);
rimLeft.position.set(-1.285, -0.60, 0);
trayRoot.add(rimLeft);
const rimRight = rimLeft.clone();
rimRight.position.x = 1.285;
trayRoot.add(rimRight);
const trayLabel = textPanel("H-06 / VERIFIED FIT", 1.28, 0.24, "#68e8bd");
trayLabel.position.set(2.25, -0.60, 1.055);
scene.add(trayLabel);
const replacementRoot = new THREE.Group();
replacementRoot.position.set(2.25, -0.58, 0);
scene.add(replacementRoot);
// Two leaves, one on each side of the common hinge axis.
const replacementBaseLeaf = roundedSlab(1.55, 0.42, 0.06, 0.045, material.mintDark);
replacementBaseLeaf.position.set(0, 0, -0.22);
replacementRoot.add(replacementBaseLeaf);
const replacementLidLeaf = roundedSlab(1.55, 0.42, 0.06, 0.045, material.mint);
replacementLidLeaf.position.set(0, 0, 0.22);
replacementRoot.add(replacementLidLeaf);
const knuckleXPositions = [-0.57, -0.285, 0, 0.285, 0.57];
knuckleXPositions.forEach((x, index) => {
const knuckle = cylinderX(
0.108,
0.235,
index % 2 === 0 ? material.mintDark : material.mint
);
knuckle.position.set(x, 0.055, 0);
replacementRoot.add(knuckle);
});
// Four matching mounting holes: two per leaf.
[-0.57, 0.57].forEach((x) => {
[-0.22, 0.22].forEach((z) => {
const hole = new THREE.Mesh(
new THREE.CylinderGeometry(0.046, 0.046, 0.014, 24),
material.hole
);
hole.position.set(x, 0.036, z);
replacementRoot.add(hole);
const countersink = new THREE.Mesh(
new THREE.TorusGeometry(0.054, 0.008, 8, 28),
material.steel
);
countersink.rotation.x = Math.PI / 2;
countersink.position.set(x, 0.039, z);
replacementRoot.add(countersink);
});
});
// The replacement pin is lifted slightly so its common bore is readable.
const replacementPin = new THREE.Group();
replacementPin.position.set(0, 0.145, 0);
replacementRoot.add(replacementPin);
const replacementPinShaft = cylinderX(0.037, 1.48, material.steel);
replacementPin.add(replacementPinShaft);
const replacementPinHead = cylinderX(0.067, 0.055, material.mint);
replacementPinHead.position.x = 0.765;
replacementPin.add(replacementPinHead);
const replacementAxisRing = ringAroundX(
0.135,
0.012,
new THREE.MeshBasicMaterial({
color: 0x74f1c6,
transparent: true,
opacity: 0.92,
depthTest: false
})
);
replacementAxisRing.position.y = 0.055;
replacementAxisRing.renderOrder = 8;
replacementRoot.add(replacementAxisRing);
// Axis guides make the matching interface explicit.
function makeAxisGuide(color) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-1.02, 0, 0),
new THREE.Vector3(1.02, 0, 0)
]);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color,
dashSize: 0.055,
gapSize: 0.045,
transparent: true,
opacity: 0.12,
depthTest: false
})
);
line.computeLineDistances();
line.renderOrder = 7;
return line;
}
const failedAxisGuide = makeAxisGuide(0xff655d);
failedAxisGuide.position.z = 0.055;
failedRoot.add(failedAxisGuide);
const replacementAxisGuide = makeAxisGuide(0x71edc2);
replacementAxisGuide.position.y = 0.055;
replacementRoot.add(replacementAxisGuide);
// Subtle schematic link between the two matching interfaces.
const matchGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]);
const matchLink = new THREE.Line(
matchGeometry,
new THREE.LineBasicMaterial({
color: 0x75e6c3,
transparent: true,
opacity: 0,
depthTest: false
})
);
matchLink.renderOrder = 6;
scene.add(matchLink);
// -------------------------------------------------------------------------
// UI and annotation leaders
// -------------------------------------------------------------------------
const testButton = document.getElementById("testButton");
const interfaceButton = document.getElementById("interfaceButton");
const resetButton = document.getElementById("resetButton");
const statusBox = document.getElementById("statusBox");
const statusTitle = document.getElementById("statusTitle");
const statusText = document.getElementById("statusText");
const currentAngle = document.getElementById("currentAngle");
const currentState = document.getElementById("currentState");
const angleFill = document.getElementById("angleFill");
function setStatus(title, text, type = "") {
statusTitle.textContent = title;
statusText.textContent = text;
statusBox.className = `status ${type}`;
}
const svg = document.getElementById("leaders");
const annotationDefinitions = [
{
element: document.getElementById("failedTag"),
color: "#ff8358",
offset: new THREE.Vector2(-132, -78)
},
{
element: document.getElementById("functionTag"),
color: "#ffcf68",
offset: new THREE.Vector2(92, -100)
},
{
element: document.getElementById("replacementTag"),
color: "#68e8bd",
offset: new THREE.Vector2(118, -72)
},
{
element: document.getElementById("interfaceTag"),
color: "#82d9ec",
offset: new THREE.Vector2(126, 58)
}
];
annotationDefinitions.forEach((definition) => {
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
line.setAttribute("stroke", definition.color);
line.setAttribute("stroke-width", "1");
line.setAttribute("stroke-opacity", "0.58");
line.setAttribute("stroke-dasharray", "3 5");
const dot = document.createElementNS(
"http://www.w3.org/2000/svg",
"circle"
);
dot.setAttribute("r", "3");
dot.setAttribute("fill", definition.color);
svg.appendChild(line);
svg.appendChild(dot);
definition.line = line;
definition.dot = dot;
});
const projected = new THREE.Vector3();
function updateAnnotation(definition, worldAnchor, visible = true) {
projected.copy(worldAnchor).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.3 &&
Math.abs(projected.y) < 1.3;
const anchorX = (projected.x * 0.5 + 0.5) * window.innerWidth;
const anchorY = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const labelX = THREE.MathUtils.clamp(
anchorX + definition.offset.x,
80,
window.innerWidth - 80
);
const labelY = THREE.MathUtils.clamp(
anchorY + definition.offset.y,
75,
window.innerHeight - 95
);
definition.element.style.left = `${labelX}px`;
definition.element.style.top = `${labelY}px`;
definition.element.style.opacity = visible && onScreen ? "1" : "0";
definition.line.setAttribute("x1", anchorX);
definition.line.setAttribute("y1", anchorY);
definition.line.setAttribute("x2", labelX);
definition.line.setAttribute("y2", labelY);
definition.line.setAttribute("opacity", visible && onScreen ? "0.58" : "0");
definition.dot.setAttribute("cx", anchorX);
definition.dot.setAttribute("cy", anchorY);
definition.dot.setAttribute("opacity", visible && onScreen ? "0.95" : "0");
}
// -------------------------------------------------------------------------
// Interaction state
// -------------------------------------------------------------------------
let interfaceMode = false;
let interfaceMix = 0;
testButton.addEventListener("click", () => {
lidTarget = 0;
motionState = "closing";
testButton.classList.add("active");
setStatus(
"CLOSURE TEST RUNNING",
"The lid is driving toward 0°. Watch the released pin leave the common axis.",
"danger"
);
});
interfaceButton.addEventListener("click", () => {
interfaceMode = !interfaceMode;
interfaceButton.classList.toggle("active", interfaceMode);
if (interfaceMode) {
setStatus(
"INTERFACE MATCH CONFIRMED",
"H-06 shares the Ø6 pin bore, barrel spacing, and four-hole mounting pattern.",
"match"
);
} else {
setStatus(
"FAILURE ISOLATED",
"The replacement uses the same pin axis, barrel bore, and mounting-hole pattern."
);
}
});
resetButton.addEventListener("click", () => {
lidTarget = THREE.MathUtils.degToRad(68);
motionState = "idle";
interfaceMode = false;
interfaceMix = 0;
testButton.classList.remove("active");
interfaceButton.classList.remove("active");
resetCamera();
setStatus(
"FAILURE ISOLATED",
"The replacement uses the same pin axis, barrel bore, and mounting-hole pattern."
);
});
// -------------------------------------------------------------------------
// Direct orbit controls — no camera-control addons
// -------------------------------------------------------------------------
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.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.48,
1.36
);
});
function stopDragging(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.style.cursor = "grab";
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.007,
5.7,
13.5
);
},
{ passive: false }
);
function resetCamera() {
cameraState.theta = 0.63;
cameraState.phi = 1.02;
cameraState.radius = 8.7;
cameraState.target.set(0.55, 0.08, 0);
}
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
svg.setAttribute("viewBox", `0 0 ${window.innerWidth} ${window.innerHeight}`);
}
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const tempVector = new THREE.Vector3();
const matchStart = new THREE.Vector3();
const matchEnd = new THREE.Vector3();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
// Failed hinge motion.
if (motionState === "closing" || motionState === "jammed") {
const target = motionState === "closing" ? 0 : jamAngle;
lidAngle += (target - lidAngle) * (1 - Math.exp(-4.8 * dt));
if (motionState === "closing" && lidAngle < THREE.MathUtils.degToRad(12.5)) {
motionState = "jammed";
lidTarget = jamAngle;
setStatus(
"CLOSURE BLOCKED AT 12°",
"The fractured barrel no longer captures the pin, so the lid cannot reach 0° sealed.",
"danger"
);
}
if (motionState === "jammed") {
lidAngle =
jamAngle +
Math.sin(elapsed * 36) * 0.0045 * Math.exp(-elapsed * 0.03);
}
} else {
lidAngle += (lidTarget - lidAngle) * (1 - Math.exp(-4.2 * dt));
}
lidPivot.rotation.x = lidAngle;
const angleDegrees = THREE.MathUtils.radToDeg(lidAngle);
currentAngle.textContent = `${Math.round(angleDegrees)}°`;
currentState.textContent =
motionState === "jammed"
? "blocked / pin released"
: motionState === "closing"
? "driving to seal"
: "open / failed";
angleFill.style.width = `${Math.min(100, (angleDegrees / 105) * 100)}%`;
// Interface exploded-view reveal.
const interfaceTarget = interfaceMode ? 1 : 0;
interfaceMix +=
(interfaceTarget - interfaceMix) * (1 - Math.exp(-6 * dt));
failedPin.position.y = 0.135 + interfaceMix * 0.17;
failedPin.position.z = 0.12 + interfaceMix * 0.08;
failedPin.rotation.x = 0.18 + interfaceMix * 0.13;
replacementPin.position.y = 0.145 + interfaceMix * 0.22;
failedAxisGuide.material.opacity = 0.12 + interfaceMix * 0.66;
replacementAxisGuide.material.opacity = 0.12 + interfaceMix * 0.66;
matchLink.material.opacity = interfaceMix * 0.34;
missingEngagement.material.opacity = 0.58 + interfaceMix * 0.42;
replacementAxisRing.material.opacity = 0.54 + interfaceMix * 0.46;
// Schematic link between the two equivalent axes.
failedRoot.getWorldPosition(matchStart);
replacementRoot.localToWorld(matchEnd.set(0, 0.055, 0));
const matchPositions = matchGeometry.attributes.position;
matchPositions.setXYZ(0, matchStart.x, matchStart.y + 0.09, matchStart.z);
matchPositions.setXYZ(1, matchEnd.x, matchEnd.y + 0.09, matchEnd.z);
matchPositions.needsUpdate = true;
matchGeometry.computeBoundingSphere();
// Update projected callouts.
failedRoot.getWorldPosition(tempVector);
updateAnnotation(annotationDefinitions[0], tempVector);
lidPivot.localToWorld(tempVector.set(0, 0.05, -0.28));
updateAnnotation(annotationDefinitions[1], tempVector);
replacementRoot.localToWorld(tempVector.set(0, 0.11, 0.68));
updateAnnotation(annotationDefinitions[2], tempVector);
replacementRoot.localToWorld(tempVector.set(0, 0.055, 0));
updateAnnotation(
annotationDefinitions[3],
tempVector,
true
);
annotationDefinitions[3].element.style.opacity = `${0.45 + interfaceMix * 0.55}`;
updateCamera();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```