Prompt specification
Build or customize the Three.js 3D scene "Continuous versus discrete fastener exhibit" 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: Continuous versus discrete fastener exhibit
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/continuous-versus-discrete-fastener-exhibit-x0568
Scene Description Prompt:
Continuous versus discrete fastener exhibit. Create belt, sliding strap, and lace closures around identical forms; users compare adjustment increments and trace the distinct mechanisms that hold each chosen size. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (continuous-versus-discrete-fastener-exhibit-x0568):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fastener Field Lab — Continuous vs. Discrete Adjustment</title>
<style>
:root {
color-scheme: dark;
--bg: #0b1117;
--panel: #111a22;
--panel-2: #17232d;
--line: rgba(255, 255, 255, 0.12);
--text: #edf1ec;
--muted: #96a5ad;
--belt: #e6ad57;
--strap: #72d6bd;
--lace: #ef807b;
--active: #e6ad57;
}
* {
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;
}
button {
color: inherit;
}
#stage {
position: fixed;
inset: 0 380px 0 0;
overflow: hidden;
background: #101820;
}
#stage canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.stage-header {
position: absolute;
z-index: 4;
top: 27px;
left: 30px;
right: 30px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 9px;
color: #b9c3c7;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
max-width: 610px;
margin: 0;
font-size: clamp(31px, 4vw, 58px);
font-weight: 560;
letter-spacing: -0.055em;
line-height: 0.96;
}
.subtitle {
max-width: 570px;
margin: 16px 0 0;
color: #a9b6bc;
font-size: 13px;
line-height: 1.55;
}
.view-tools {
display: flex;
gap: 8px;
pointer-events: auto;
}
.view-button {
border: 1px solid var(--line);
border-radius: 999px;
padding: 9px 14px;
background: rgba(12, 19, 25, 0.68);
backdrop-filter: blur(14px);
cursor: pointer;
font-size: 11px;
letter-spacing: 0.04em;
}
.view-button:hover,
.view-button.active {
border-color: rgba(255, 255, 255, 0.35);
background: rgba(255, 255, 255, 0.1);
}
.interaction-hint {
position: absolute;
z-index: 4;
left: 30px;
bottom: 155px;
color: rgba(218, 228, 231, 0.58);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
#labels {
position: absolute;
z-index: 5;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.hotspot {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
padding: 6px 10px 6px 7px;
transform: translate(-50%, -50%);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 999px;
background: rgba(8, 14, 19, 0.84);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(12px);
color: #e6edef;
font-size: 10px;
white-space: nowrap;
pointer-events: auto;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
opacity 150ms ease;
}
.hotspot::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--hotspot-color, #e6ad57);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--hotspot-color, #e6ad57) 18%, transparent);
content: "";
}
.hotspot.active {
border-color: var(--hotspot-color, #e6ad57);
background: rgba(14, 23, 30, 0.95);
}
.hotspot.hidden {
opacity: 0;
pointer-events: none;
}
#compare {
position: absolute;
z-index: 6;
left: 24px;
right: 24px;
bottom: 22px;
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 9px;
}
.compare-card {
position: relative;
min-width: 0;
padding: 13px 14px 12px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(13, 21, 27, 0.76);
backdrop-filter: blur(16px);
text-align: left;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
.compare-card::after {
position: absolute;
top: 0;
left: 0;
width: 3px;
height: 100%;
background: var(--card-color);
opacity: 0.75;
content: "";
}
.compare-card:hover {
transform: translateY(-2px);
border-color: rgba(255, 255, 255, 0.28);
}
.compare-card.active {
border-color: color-mix(in srgb, var(--card-color) 72%, transparent);
background: rgba(24, 34, 42, 0.9);
}
.compare-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.compare-name {
font-size: 12px;
font-weight: 700;
}
.compare-value {
color: var(--card-color);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.compare-type {
margin-top: 6px;
color: #9eabb1;
font-size: 10px;
}
.compare-type strong {
color: #dce3e4;
font-weight: 600;
}
#panel {
position: fixed;
z-index: 20;
top: 0;
right: 0;
bottom: 0;
width: 380px;
overflow-y: auto;
padding: 25px 25px 30px;
border-left: 1px solid var(--line);
background:
radial-gradient(circle at 95% 0%, rgba(230, 173, 87, 0.08), transparent 30%),
var(--panel);
scrollbar-width: thin;
scrollbar-color: #35434d transparent;
}
.panel-kicker {
margin: 0 0 19px;
color: #8e9da5;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.tabs {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
margin-bottom: 27px;
}
.tab {
padding: 10px 5px;
border: 1px solid var(--line);
border-radius: 8px;
background: transparent;
color: #93a1a8;
cursor: pointer;
font-size: 10px;
transition: 150ms ease;
}
.tab:hover {
color: #fff;
border-color: rgba(255, 255, 255, 0.28);
}
.tab.active {
border-color: color-mix(in srgb, var(--tab-color) 70%, transparent);
background: color-mix(in srgb, var(--tab-color) 13%, transparent);
color: #fff;
}
.tab:first-child {
font-size: 9px;
}
.mechanism-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 15px;
}
h2 {
margin: 0;
font-size: 27px;
font-weight: 560;
letter-spacing: -0.04em;
}
.type-badge {
flex: 0 0 auto;
margin-top: 2px;
padding: 6px 8px;
border: 1px solid color-mix(in srgb, var(--active) 42%, transparent);
border-radius: 999px;
background: color-mix(in srgb, var(--active) 9%, transparent);
color: var(--active);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.description {
min-height: 74px;
margin: 13px 0 23px;
color: #a9b5bb;
font-size: 12px;
line-height: 1.62;
}
.section {
padding: 19px 0;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
color: #dce3e4;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-title span {
color: #7d8c94;
font-weight: 500;
letter-spacing: 0.03em;
text-transform: none;
}
.size-readout {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 12px;
}
.size-number {
font-size: 39px;
font-weight: 520;
letter-spacing: -0.06em;
font-variant-numeric: tabular-nums;
}
.size-unit {
margin-left: 5px;
color: #89989f;
font-size: 13px;
letter-spacing: 0;
}
.size-note {
color: #84949b;
font-size: 10px;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 4px 0 10px;
border-radius: 999px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--active) 0%,
var(--active) var(--range-progress, 50%),
#34424b var(--range-progress, 50%),
#34424b 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #172129;
border-radius: 50%;
appearance: none;
background: var(--active);
box-shadow: 0 0 0 1px var(--active);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #172129;
border-radius: 50%;
background: var(--active);
box-shadow: 0 0 0 1px var(--active);
}
.step-controls {
display: grid;
grid-template-columns: 38px 1fr 38px;
gap: 7px;
margin-top: 14px;
}
.step-button {
height: 34px;
border: 1px solid var(--line);
border-radius: 8px;
background: #17222b;
cursor: pointer;
font-size: 17px;
}
.step-button:hover {
border-color: rgba(255, 255, 255, 0.3);
}
.resolution {
min-height: 48px;
margin-top: 18px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.resolution-label {
margin-bottom: 10px;
color: #9eabb1;
font-size: 10px;
}
.resolution-label strong {
color: var(--active);
}
.tick-scale {
position: relative;
display: flex;
height: 18px;
align-items: flex-start;
justify-content: space-between;
}
.tick-scale::before {
position: absolute;
top: 5px;
left: 0;
right: 0;
height: 1px;
background: #50606a;
content: "";
}
.tick {
position: relative;
width: 1px;
height: 11px;
background: #718089;
}
.tick:first-child,
.tick:last-child {
height: 16px;
background: var(--active);
}
.continuous-scale {
position: relative;
height: 12px;
}
.continuous-scale::before {
position: absolute;
top: 5px;
left: 0;
right: 0;
height: 3px;
border-radius: 999px;
background: linear-gradient(
90deg,
color-mix(in srgb, var(--active) 30%, transparent),
var(--active),
color-mix(in srgb, var(--active) 30%, transparent)
);
content: "";
}
.continuous-scale::after {
position: absolute;
top: 1px;
right: 32%;
width: 11px;
height: 11px;
border: 3px solid #172129;
border-radius: 50%;
background: var(--active);
box-shadow: 0 0 0 1px var(--active);
content: "";
}
.trace-button {
width: 100%;
padding: 11px 14px;
border: 1px solid color-mix(in srgb, var(--active) 52%, transparent);
border-radius: 9px;
background: color-mix(in srgb, var(--active) 11%, transparent);
color: var(--active);
cursor: pointer;
font-size: 11px;
font-weight: 700;
transition: 150ms ease;
}
.trace-button:hover,
.trace-button.active {
background: color-mix(in srgb, var(--active) 20%, transparent);
}
#steps {
display: grid;
gap: 5px;
margin: 13px 0 0;
padding: 0;
list-style: none;
}
.step-item {
display: grid;
grid-template-columns: 24px 1fr;
align-items: center;
gap: 9px;
width: 100%;
padding: 8px;
border: 1px solid transparent;
border-radius: 8px;
background: transparent;
color: #9ba9af;
text-align: left;
cursor: pointer;
font-size: 10px;
}
.step-item:hover,
.step-item.active {
border-color: var(--line);
background: rgba(255, 255, 255, 0.035);
color: #edf2f1;
}
.step-index {
display: grid;
width: 22px;
height: 22px;
place-items: center;
border: 1px solid #43515a;
border-radius: 50%;
color: #83939b;
font-size: 9px;
}
.step-item.active .step-index {
border-color: var(--active);
background: color-mix(in srgb, var(--active) 14%, transparent);
color: var(--active);
}
.part-callout {
padding: 14px;
border-left: 2px solid var(--active);
border-radius: 0 9px 9px 0;
background: rgba(255, 255, 255, 0.035);
}
.part-callout strong {
display: block;
margin-bottom: 6px;
color: #f0f4f2;
font-size: 11px;
}
.part-callout p {
margin: 0;
color: #9aa9b0;
font-size: 10px;
line-height: 1.58;
}
.footer-note {
margin: 21px 0 0;
color: #6f8088;
font-size: 9px;
line-height: 1.5;
}
#loading {
position: absolute;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #101820;
color: #a9b7bd;
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 980px) {
#stage {
inset: 0 0 44vh 0;
}
#panel {
top: auto;
width: 100%;
height: 44vh;
border-top: 1px solid var(--line);
border-left: 0;
padding: 20px 24px 28px;
}
.panel-kicker {
margin-bottom: 12px;
}
.tabs {
margin-bottom: 18px;
}
.description {
min-height: 0;
margin-bottom: 14px;
}
#compare {
left: 14px;
right: 14px;
bottom: 13px;
}
.interaction-hint {
bottom: 112px;
}
.stage-header {
top: 19px;
left: 20px;
right: 20px;
}
h1 {
font-size: clamp(27px, 6vw, 46px);
}
.subtitle {
max-width: 430px;
font-size: 11px;
}
}
@media (max-width: 620px) {
.stage-header {
display: block;
}
.view-tools {
margin-top: 13px;
}
.subtitle {
display: none;
}
#compare {
grid-template-columns: 1fr;
gap: 5px;
}
.compare-card {
padding: 8px 11px;
}
.compare-type {
display: none;
}
.interaction-hint {
display: none;
}
.hotspot {
font-size: 9px;
}
#panel {
height: 46vh;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive three-dimensional fastener exhibit">
<div id="loading">Preparing the exhibit</div>
<header class="stage-header">
<div>
<p class="eyebrow">Fastener Field Lab / Exhibit 03</p>
<h1>How a fit<br />holds its size.</h1>
<p class="subtitle">
Three closures. One identical low-poly form. Compare adjustment resolution
and trace the force path from release to locked position.
</p>
</div>
<div class="view-tools">
<button class="view-button active" id="allView" type="button">All three</button>
</div>
</header>
<div id="labels"></div>
<div class="interaction-hint">Drag to orbit · Scroll to zoom · Select a part</div>
<nav id="compare" aria-label="Compare fastener adjustment"></nav>
</main>
<aside id="panel" aria-label="Mechanism controls and explanation">
<p class="panel-kicker">Choose a closure mechanism</p>
<div class="tabs" role="tablist">
<button class="tab active" data-closure="belt" style="--tab-color: var(--belt)" type="button">
Belt
</button>
<button class="tab" data-closure="strap" style="--tab-color: var(--strap)" type="button">
Sliding
</button>
<button class="tab" data-closure="lace" style="--tab-color: var(--lace)" type="button">
Lace
</button>
<button class="tab" data-closure="all" style="--tab-color: #dbe4e5" type="button">
All
</button>
</div>
<div class="mechanism-heading">
<h2 id="mechanismTitle">Buckle & hole</h2>
<div class="type-badge" id="typeBadge">Discrete</div>
</div>
<p class="description" id="description"></p>
<section class="section">
<div class="section-title">
Selected fit
<span id="rangeLabel">72–108 cm</span>
</div>
<div class="size-readout">
<div>
<span class="size-number" id="sizeNumber">86</span>
<span class="size-unit">cm</span>
</div>
<div class="size-note" id="sizeNote">Even-centimeter hole</div>
</div>
<input
id="sizeRange"
type="range"
min="72"
max="108"
step="2"
value="86"
aria-label="Selected circumference in centimeters"
/>
<div class="step-controls">
<button class="step-button" id="decrease" type="button" aria-label="Decrease size">−</button>
<button class="step-button" id="increase" type="button" aria-label="Increase size">+</button>
</div>
<div class="resolution" id="resolution"></div>
</section>
<section class="section">
<div class="section-title">
Mechanism trace
<span id="traceStatus">Select a numbered step</span>
</div>
<button class="trace-button" id="traceButton" type="button">
Trace the load path
</button>
<ol id="steps"></ol>
</section>
<section class="section">
<div class="section-title">Selected part</div>
<div class="part-callout">
<strong id="partTitle"></strong>
<p id="partDescription"></p>
</div>
</section>
<p class="footer-note">
The forms remain geometrically identical. The different closure geometries,
adjustment resolutions, and highlighted load paths show how each system
establishes and retains a chosen circumference.
</p>
</aside>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const labelsElement = document.querySelector("#labels");
const loading = document.querySelector("#loading");
const mechanisms = {
belt: {
name: "Buckle & hole",
shortName: "Belt",
type: "Discrete",
color: "#e6ad57",
min: 72,
max: 108,
step: 2,
value: 86,
description:
"A tongue pins the belt into one indexed hole. Its position can only change when the hole spacing permits, so the fit is quantized.",
note: "Even-centimeter hole",
parts: [
{
id: "wrap",
label: "Belt body",
text: "The wrapped body carries most of the tensile load. Its bend around the form introduces friction and a small inward pulling force.",
anchor: "wrap"
},
{
id: "buckle",
label: "Buckle frame",
text: "The rigid frame turns the loose end into a pin. It redirects the tail and prevents the two layers from sliding sideways.",
anchor: "buckle"
},
{
id: "hole",
label: "Indexed hole",
text: "The tongue bears against the edge of a fixed hole. This is the final mechanical stop that determines the selected circumference.",
anchor: "hole"
},
{
id: "tail",
label: "Belt tail",
text: "The free tail adds friction through the buckle and stabilizes the connection, but it does not set the final hole position.",
anchor: "tail"
}
]
},
strap: {
name: "Sliding strap",
shortName: "Sliding strap",
type: "Continuous",
color: "#72d6bd",
min: 72,
max: 108,
step: 0.1,
value: 92.4,
description:
"A webbing tail passes through a capture slider. Pulling changes the overlap continuously, while the slider's friction holds the selected position.",
note: "Continuously adjustable",
parts: [
{
id: "webbing",
label: "Webbing body",
text: "The flexible band wraps the form and carries tension around the body. Its flexibility allows the closure to conform without a rigid frame.",
anchor: "webbing"
},
{
id: "slider",
label: "Capture slider",
text: "The slider changes direction and increases bearing pressure between the strap layers. Friction at this contact is what resists further movement.",
anchor: "slider"
},
{
id: "overlap",
label: "Overlap zone",
text: "Two layers of webbing overlap inside the slider. More overlap means more surface friction and a broader distribution of contact pressure.",
anchor: "overlap"
},
{
id: "loop",
label: "Return loop",
text: "The return loop keeps the loose end aligned and prevents it from peeling away from the primary band.",
anchor: "loop"
}
]
},
lace: {
name: "Cross-lacing",
shortName: "Lace",
type: "Discrete",
color: "#ef807b",
min: 72,
max: 108,
step: 1,
value: 91,
description:
"Opposing cords cross between fixed eyelets. Pulling the laces shortens the path between opposite sides, and each eyelet level creates a discrete setting.",
note: "One-centimeter eyelet level",
parts: [
{
id: "eyelet",
label: "Eyelet row",
text: "Each reinforced eyelet provides a fixed routing point. The lace cannot move between these points, so the available settings form discrete levels.",
anchor: "eyelet"
},
{
id: "cross",
label: "Crossover",
text: "Crossing the cord makes tension act diagonally. Opposing pulls draw the two sides toward one another and distribute load through the panel.",
anchor: "cross"
},
{
id: "bow",
label: "Bow & stay",
text: "The bow contains the adjustment after the laces are tensioned. It preserves the cord path and keeps the selected size from loosening.",
anchor: "bow"
}
]
}
};
const positions = {
belt: -2.25,
strap: 0,
lace: 2.25
};
const state = {
active: "belt",
selectedPart: "hole",
tracing: false,
traceIndex: 0,
lastTraceTime: 0,
values: {
belt: 86,
strap: 92.4,
lace: 91
},
displayValues: {
belt: 86,
strap: 92.4,
lace: 91
}
};
const scene = new THREE.Scene();
scene.background = new THREE.Color("#101820");
scene.fog = new THREE.Fog("#101820", 10, 20);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Interactive low-poly mannequin fastener comparison");
stage.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
stage.clientWidth / stage.clientHeight,
0.1,
50
);
const cameraTarget = new THREE.Vector3(0, 1.55, 0);
const desiredTarget = cameraTarget.clone();
const cameraState = {
theta: 0.08,
phi: 1.13,
radius: 9.1,
desiredTheta: 0.08,
desiredPhi: 1.13,
desiredRadius: 9.1
};
camera.position.set(0, 3.4, 8.8);
camera.lookAt(cameraTarget);
const hemisphere = new THREE.HemisphereLight(0xfff4de, 0x172630, 2.4);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d8, 3.7);
keyLight.position.set(-4.5, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x8dc7d0, 2.2);
rimLight.position.set(5, 4, -5);
scene.add(rimLight);
Object.keys(mechanisms).forEach((id, index) => {
const light = new THREE.PointLight(mechanisms[id].color, 6, 5, 2);
light.position.set(positions[id], 2.7, 2.6);
scene.add(light);
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({ color: 0x152129, roughness: 0.95 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.02;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 48, 0x31404a, 0x223039);
grid.position.y = 0.001;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
const formMaterial = new THREE.MeshStandardMaterial({
color: 0xd9d2c2,
roughness: 0.78,
metalness: 0.02,
flatShading: true
});
const metalMaterial = new THREE.MeshStandardMaterial({
color: 0xc7c9c3,
roughness: 0.24,
metalness: 0.82,
flatShading: true
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x20262a,
roughness: 0.62,
metalness: 0.08,
flatShading: true
});
const refs = {
belt: {},
strap: {},
lace: {}
};
const formGroups = {};
function createBandGeometry(rx, rz, height, segments = 48, thickness = 0.028) {
const positionsArray = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const sine = Math.sin(angle);
const cosine = Math.cos(angle);
positionsArray.push(
(rx - thickness) * sine, -height / 2, (rz - thickness) * cosine,
rx * sine, -height / 2, rz * cosine,
(rx - thickness) * sine, height / 2, (rz - thickness) * cosine,
rx * sine, height / 2, rz * cosine
);
}
for (let i = 0; i < segments; i++) {
const a = i * 4;
const b = (i + 1) * 4;
indices.push(
a + 1, b + 1, a + 3,
a + 3, b + 1, b + 3,
a, a + 2, b,
b, a + 2, b + 2,
a + 2, a + 3, b + 2,
a + 3, b + 3, b + 2,
a, b, a + 1,
b, b + 1, a + 1
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positionsArray, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeRod(radius = 0.015, material = metalMaterial, segments = 6) {
return new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 1, segments),
material
);
}
const upAxis = new THREE.Vector3(0, 1, 0);
function alignRod(mesh, a, b, radius = 0.015) {
const direction = b.clone().sub(a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(upAxis, direction.normalize());
mesh.scale.set(radius, length, radius);
}
function createForm(x, id) {
const group = new THREE.Group();
group.position.x = x;
formGroups[id] = group;
scene.add(group);
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(0.83, 0.9, 0.13, 16),
new THREE.MeshStandardMaterial({
color: 0x26343d,
roughness: 0.82,
metalness: 0.12,
flatShading: true
})
);
plinth.position.y = 0.065;
plinth.castShadow = true;
plinth.receiveShadow = true;
group.add(plinth);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.065, 0.55, 10),
metalMaterial
);
stem.position.y = 0.39;
stem.castShadow = true;
group.add(stem);
const profile = [
[0.61, 0.62],
[0.68, 0.85],
[0.62, 1.19],
[0.53, 1.52],
[0.57, 1.84],
[0.67, 2.13],
[0.55, 2.43],
[0.31, 2.61],
[0.24, 2.69]
].map(([radius, y]) => new THREE.Vector2(radius, y));
const torso = new THREE.Mesh(
new THREE.LatheGeometry(profile, 12),
formMaterial
);
torso.castShadow = true;
torso.receiveShadow = true;
group.add(torso);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.23, 0.25, 10),
formMaterial
);
neck.position.y = 2.77;
neck.castShadow = true;
group.add(neck);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.255, 1),
formMaterial
);
head.position.y = 3.06;
head.scale.set(0.85, 1.13, 0.85);
head.castShadow = true;
group.add(head);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.225, 0.025, 5, 14),
darkMaterial
);
collar.rotation.x = Math.PI / 2;
collar.position.y = 2.7;
group.add(collar);
}
createForm(positions.belt, "belt");
createForm(positions.strap, "strap");
createForm(positions.lace, "lace");
function createBelt() {
const group = new THREE.Group();
group.userData.closure = "belt";
formGroups.belt.add(group);
refs.belt.group = group;
const leather = new THREE.MeshStandardMaterial({
color: 0x514238,
roughness: 0.73,
metalness: 0.05,
side: THREE.DoubleSide,
flatShading: true
});
const belt = new THREE.Mesh(
createBandGeometry(0.58, 0.49, 0.18, 48),
leather
);
belt.position.y = 1.54;
belt.userData.part = "wrap";
belt.castShadow = true;
group.add(belt);
refs.belt.wrap = belt;
const holes = [];
const holeGeometry = new THREE.CircleGeometry(0.025, 8);
const holeMaterial = new THREE.MeshBasicMaterial({
color: 0x111111,
side: THREE.DoubleSide
});
for (let i = 0; i < 6; i++) {
const angle = 1.03 + i * 0.125;
const hole = new THREE.Mesh(holeGeometry, holeMaterial);
hole.position.set(
Math.sin(angle) * 0.583,
1.54,
Math.cos(angle) * 0.494
);
const normal = new THREE.Vector3(Math.sin(angle), 0, Math.cos(angle));
hole.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
normal.normalize()
);
hole.userData.part = "hole";
group.add(hole);
holes.push(hole);
}
refs.belt.holes = holes;
const buckle = new THREE.Group();
buckle.position.set(0, 1.54, 0.535);
buckle.userData.part = "buckle";
group.add(buckle);
refs.belt.buckle = buckle;
const top = new THREE.Mesh(
new THREE.BoxGeometry(0.29, 0.048, 0.045),
metalMaterial
);
top.position.y = 0.075;
const bottom = top.clone();
bottom.position.y = -0.075;
const left = new THREE.Mesh(
new THREE.BoxGeometry(0.048, 0.15, 0.045),
metalMaterial
);
left.position.x = -0.121;
const right = left.clone();
right.position.x = 0.121;
buckle.add(top, bottom, left, right);
const tongue = makeRod(0.018, metalMaterial, 8);
tongue.userData.part = "hole";
group.add(tongue);
refs.belt.tongue = tongue;
const tail = new THREE.Group();
tail.position.set(0.09, 1.46, 0.557);
tail.rotation.z = -0.42;
tail.userData.part = "tail";
group.add(tail);
refs.belt.tail = tail;
const tailMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.105, 0.43, 0.035),
leather
);
tailMesh.position.y = -0.18;
tail.add(tailMesh);
const tailTip = new THREE.Mesh(
new THREE.BoxGeometry(0.108, 0.09, 0.038),
metalMaterial
);
tailTip.position.y = -0.395;
tail.add(tailTip);
const wrapAnchor = new THREE.Object3D();
wrapAnchor.position.set(0, 1.54, 0.5);
group.add(wrapAnchor);
refs.belt.wrapAnchor = wrapAnchor;
}
function createStrap() {
const group = new THREE.Group();
group.userData.closure = "strap";
formGroups.strap.add(group);
refs.strap.group = group;
const webbingMaterial = new THREE.MeshStandardMaterial({
color: 0x315d58,
roughness: 0.84,
metalness: 0.02,
side: THREE.DoubleSide,
flatShading: true
});
const webbing = new THREE.Mesh(
createBandGeometry(0.58, 0.49, 0.11, 48, 0.022),
webbingMaterial
);
webbing.position.y = 1.54;
webbing.userData.part = "webbing";
webbing.castShadow = true;
group.add(webbing);
refs.strap.webbing = webbing;
const overlap = new THREE.Mesh(
new THREE.BoxGeometry(0.66, 0.105, 0.034),
webbingMaterial
);
overlap.position.set(-0.07, 1.54, 0.54);
overlap.userData.part = "overlap";
group.add(overlap);
refs.strap.overlap = overlap;
const slider = new THREE.Group();
slider.position.set(0.02, 1.54, 0.565);
slider.userData.part = "slider";
group.add(slider);
refs.strap.slider = slider;
const sliderMaterial = new THREE.MeshStandardMaterial({
color: 0xb7beb8,
roughness: 0.26,
metalness: 0.76,
flatShading: true
});
const sliderTop = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.035, 0.045),
sliderMaterial
);
sliderTop.position.y = 0.057;
const sliderBottom = sliderTop.clone();
sliderBottom.position.y = -0.057;
const sliderLeft = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.115, 0.045),
sliderMaterial
);
sliderLeft.position.x = -0.093;
const sliderRight = sliderLeft.clone();
sliderRight.position.x = 0.093;
slider.add(sliderTop, sliderBottom, sliderLeft, sliderRight);
const bar = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.105, 0.038),
sliderMaterial
);
slider.add(bar);
const tail = new THREE.Mesh(
new THREE.BoxGeometry(0.115, 0.43, 0.035),
webbingMaterial
);
tail.position.set(0.13, 1.29, 0.57);
tail.rotation.z = -0.24;
tail.userData.part = "overlap";
group.add(tail);
refs.strap.tail = tail;
const loop = new THREE.Mesh(
new THREE.TorusGeometry(0.09, 0.023, 5, 12),
sliderMaterial
);
loop.position.set(0.38, 1.54, 0.03);
loop.rotation.y = Math.PI / 2;
loop.userData.part = "loop";
group.add(loop);
refs.strap.loop = loop;
for (let i = 0; i < 5; i++) {
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.012, 0.012),
new THREE.MeshBasicMaterial({ color: 0xb4d9ce })
);
tick.position.set(0.25 + i * 0.075, 1.595, 0.565);
tick.userData.part = "overlap";
group.add(tick);
}
}
function createLace() {
const group = new THREE.Group();
group.userData.closure = "lace";
formGroups.lace.add(group);
refs.lace.group = group;
const panelShape = new THREE.Shape();
panelShape.moveTo(-0.15, 1.89);
panelShape.lineTo(0.15, 1.89);
panelShape.lineTo(0.095, 2.48);
panelShape.lineTo(-0.095, 2.48);
panelShape.closePath();
const panel = new THREE.Mesh(
new THREE.ShapeGeometry(panelShape),
new THREE.MeshStandardMaterial({
color: 0x563d3c,
roughness: 0.83,
side: THREE.DoubleSide
})
);
panel.position.z = 0.485;
panel.userData.part = "eyelet";
group.add(panel);
refs.lace.panel = panel;
const eyelets = [];
const eyeletGeometry = new THREE.TorusGeometry(0.031, 0.009, 5, 10);
const eyeletMaterial = new THREE.MeshStandardMaterial({
color: 0xc8a05c,
roughness: 0.28,
metalness: 0.73,
flatShading: true
});
for (let side = 0; side < 2; side++) {
for (let row = 0; row < 7; row++) {
const eyelet = new THREE.Mesh(eyeletGeometry, eyeletMaterial);
eyelet.userData.part = "eyelet";
group.add(eyelet);
eyelets.push({ mesh: eyelet, side, row });
}
}
refs.lace.eyelets = eyelets;
const cords = [];
const cordMaterial = new THREE.MeshStandardMaterial({
color: 0xd9b890,
roughness: 0.75,
metalness: 0.02,
flatShading: true
});
for (let i = 0; i < 12; i++) {
const cord = makeRod(0.012, cordMaterial, 6);
cord.userData.part = "cross";
cord.castShadow = true;
group.add(cord);
cords.push(cord);
}
refs.lace.cords = cords;
const bow = new THREE.Group();
bow.userData.part = "bow";
group.add(bow);
refs.lace.bow = bow;
const bowMaterial = new THREE.MeshStandardMaterial({
color: 0xd9b890,
roughness: 0.77,
flatShading: true
});
const leftLoop = new THREE.Mesh(
new THREE.TorusGeometry(0.105, 0.014, 5, 12),
bowMaterial
);
leftLoop.position.x = -0.083;
leftLoop.rotation.z = -0.35;
leftLoop.scale.x = 0.68;
const rightLoop = leftLoop.clone();
rightLoop.position.x = 0.083;
rightLoop.rotation.z = 0.35;
bow.add(leftLoop, rightLoop);
const bowTailLeft = makeRod(0.012, bowMaterial, 6);
const bowTailRight = makeRod(0.012, bowMaterial, 6);
bow.add(bowTailLeft, bowTailRight);
refs.lace.bowTailLeft = bowTailLeft;
refs.lace.bowTailRight = bowTailRight;
}
createBelt();
createStrap();
createLace();
function cloneMechanismMaterials(group) {
group.traverse((object) => {
if (!object.isMesh) return;
if (Array.isArray(object.material)) {
object.material = object.material.map((material) => material.clone());
} else {
object.material = object.material.clone();
}
});
}
Object.values(refs).forEach((entry) => cloneMechanismMaterials(entry.group));
function updateBelt(value) {
const normalized = (value - 72) / 36;
const radius = 0.53 + normalized * 0.11;
const ratio = radius / 0.58;
refs.belt.group.scale.set(ratio, 1, ratio);
const selectedIndex = THREE.MathUtils.clamp(
Math.round(normalized * (refs.belt.holes.length - 1)),
0,
refs.belt.holes.length - 1
);
refs.belt.selectedIndex = selectedIndex;
const hole = refs.belt.holes[selectedIndex];
const holePosition = hole.position
.clone()
.multiply(new THREE.Vector3(ratio, 1, ratio));
const tongueStart = new THREE.Vector3(0.04, 1.54, 0.535 * ratio);
alignRod(refs.belt.tongue, tongueStart, holePosition, 0.016);
refs.belt.tail.scale.y = 0.92 + normalized * 0.18;
}
function updateStrap(value) {
const normalized = (value - 72) / 36;
const radius = 0.53 + normalized * 0.11;
const ratio = radius / 0.58;
refs.strap.group.scale.set(ratio, 1, ratio);
const sliderX = -0.015 + normalized * 0.16;
refs.strap.slider.position.x = sliderX;
refs.strap.slider.position.z = 0.565 * ratio;
refs.strap.overlap.scale.x = 0.86 + normalized * 0.28;
refs.strap.overlap.position.x = -0.15 + normalized * 0.16;
refs.strap.overlap.position.z = 0.54 * ratio;
refs.strap.tail.position.x = sliderX + 0.12;
refs.strap.tail.position.z = 0.57 * ratio;
refs.strap.tail.scale.y = 0.8 + normalized * 0.55;
}
function updateLace(value) {
const normalized = (value - 72) / 36;
const tension = 1 - normalized * 0.52;
const x = 0.34 - tension * 0.055;
const positionsByEyelet = [];
refs.lace.eyelets.forEach((entry) => {
const y = 1.94 + entry.row * 0.078;
const bodyRadius = THREE.MathUtils.lerp(0.63, 0.55, entry.row / 6);
const z = Math.sqrt(Math.max(0.05, bodyRadius * bodyRadius - x * x)) - 0.012;
const position = new THREE.Vector3(
entry.side === 0 ? -x : x,
y,
z
);
entry.mesh.position.copy(position);
entry.mesh.userData.row = entry.row;
entry.mesh.userData.side = entry.side;
positionsByEyelet.push(position);
});
let cordIndex = 0;
for (let row = 0; row < 6; row++) {
const left = row;
const right = 7 + row;
alignRod(
refs.lace.cords[cordIndex++],
positionsByEyelet[left],
positionsByEyelet[right + 1],
0.012
);
alignRod(
refs.lace.cords[cordIndex++],
positionsByEyelet[right],
positionsByEyelet[left + 1],
0.012
);
}
refs.lace.bow.position.set(0, 1.91, 0.555);
refs.lace.bow.scale.setScalar(0.9 + normalized * 0.35);
const leftTailEnd = new THREE.Vector3(
-0.11 - normalized * 0.04,
1.69 - normalized * 0.08,
0.56
);
const rightTailEnd = new THREE.Vector3(
0.11 + normalized * 0.04,
1.68 - normalized * 0.08,
0.56
);
alignRod(
refs.lace.bowTailLeft,
new THREE.Vector3(-0.045, 1.91, 0.56),
leftTailEnd,
0.012
);
alignRod(
refs.lace.bowTailRight,
new THREE.Vector3(0.045, 1.91, 0.56),
rightTailEnd,
0.012
);
refs.lace.selectedIndex = THREE.MathUtils.clamp(
Math.round(normalized * 6),
0,
6
);
}
function updateMechanism(id, value) {
if (id === "belt") updateBelt(value);
if (id === "strap") updateStrap(value);
if (id === "lace") updateLace(value);
}
function getPart(object) {
let current = object;
while (current) {
if (current.userData.part) return current.userData.part;
current = current.parent;
}
return null;
}
function highlightPart(partId) {
const mechanism = mechanisms[state.active];
const accent = new THREE.Color(mechanism.color);
refs[state.active].group.traverse((object) => {
if (!object.isMesh || !object.material?.emissive) return;
const isMatch = getPart(object) === partId;
object.material.emissive.copy(isMatch ? accent : new THREE.Color(0x000000));
object.material.emissiveIntensity = isMatch ? 0.48 : 0;
});
}
function focusClosure(id) {
if (id === "all") {
desiredTarget.set(0, 1.55, 0);
cameraState.desiredRadius = stage.clientWidth < 620 ? 11.4 : 9.1;
return;
}
desiredTarget.set(positions[id], 1.55, 0);
cameraState.desiredRadius = stage.clientWidth < 620 ? 7.2 : 6.4;
}
function formatValue(id, value) {
return id === "strap" ? value.toFixed(1) : value.toFixed(0);
}
function updateCards() {
const cards = document.querySelectorAll(".compare-card");
cards.forEach((card) => {
const id = card.dataset.closure;
card.classList.toggle("active", id === state.active);
card.querySelector(".compare-value").textContent =
`${formatValue(id, state.values[id])} cm`;
});
}
function renderComparison() {
const compare = document.querySelector("#compare");
compare.innerHTML = "";
Object.entries(mechanisms).forEach(([id, mechanism]) => {
const card = document.createElement("button");
card.type = "button";
card.className = "compare-card";
card.dataset.closure = id;
card.style.setProperty("--card-color", mechanism.color);
const increment =
id === "belt"
? "2 cm hole spacing"
: id === "strap"
? "continuous movement"
: "1 cm eyelet levels";
card.innerHTML = `
<div class="compare-top">
<span class="compare-name">${mechanism.shortName}</span>
<span class="compare-value">${formatValue(id, state.values[id])} cm</span>
</div>
<div class="compare-type"><strong>${mechanism.type}</strong> · ${increment}</div>
`;
card.addEventListener("click", () => setActive(id, true));
compare.appendChild(card);
});
}
function renderResolution(id) {
const resolution = document.querySelector("#resolution");
if (id === "strap") {
resolution.innerHTML = `
<div class="resolution-label">
Adjustment resolution: <strong>continuous</strong>
</div>
<div class="continuous-scale"></div>
`;
return;
}
const tickCount = id === "belt" ? 7 : 9;
const ticks = Array.from({ length: tickCount }, () => '<span class="tick"></span>').join("");
resolution.innerHTML = `
<div class="resolution-label">
Adjustment resolution:
<strong>${id === "belt" ? "2 cm" : "1 cm"}</strong>
per indexed position
</div>
<div class="tick-scale">${ticks}</div>
`;
}
function renderSteps() {
const list = document.querySelector("#steps");
list.innerHTML = "";
mechanisms[state.active].parts.forEach((part, index) => {
const item = document.createElement("li");
const button = document.createElement("button");
button.type = "button";
button.className = "step-item";
button.dataset.part = part.id;
button.innerHTML = `
<span class="step-index">${index + 1}</span>
<span>${part.label}</span>
`;
button.addEventListener("click", () => {
state.tracing = false;
setPart(part.id);
updateTraceButton();
});
item.appendChild(button);
list.appendChild(item);
});
}
let hotspotElements = [];
function renderHotspots() {
labelsElement.innerHTML = "";
hotspotElements = [];
mechanisms[state.active].parts.forEach((part) => {
const button = document.createElement("button");
button.type = "button";
button.className = "hotspot";
button.textContent = part.label;
button.style.setProperty("--hotspot-color", mechanisms[state.active].color);
button.addEventListener("click", (event) => {
event.stopPropagation();
state.tracing = false;
setPart(part.id);
updateTraceButton();
});
labelsElement.appendChild(button);
hotspotElements.push({ button, part });
});
}
function updateHotspotPositions() {
const width = stage.clientWidth;
const height = stage.clientHeight;
const selectedHole = refs.belt.holes?.[refs.belt.selectedIndex ?? 0];
const selectedEyelet = refs.lace.eyelets?.find(
(entry) => entry.row === refs.lace.selectedIndex && entry.side === 0
);
hotspotElements.forEach(({ button, part }) => {
let anchor = null;
if (state.active === "belt") {
anchor =
part.anchor === "hole"
? selectedHole
: part.anchor === "buckle"
? refs.belt.buckle
: part.anchor === "tail"
? refs.belt.tail
: refs.belt.wrapAnchor;
}
if (state.active === "strap") {
anchor =
part.anchor === "slider"
? refs.strap.slider
: part.anchor === "overlap"
? refs.strap.overlap
: part.anchor === "loop"
? refs.strap.loop
: refs.strap.webbing;
}
if (state.active === "lace") {
anchor =
part.anchor === "eyelet"
? selectedEyelet?.mesh
: part.anchor === "cross"
? refs.lace.cords[0]
: refs.lace.bow;
}
if (!anchor) {
button.classList.add("hidden");
return;
}
const world = new THREE.Vector3();
anchor.getWorldPosition(world);
world.project(camera);
const visible = world.z > -1 && world.z < 1;
button.classList.toggle("hidden", !visible);
if (visible) {
const x = (world.x * 0.5 + 0.5) * width;
const y = (-world.y * 0.5 + 0.5) * height;
button.style.left = `${x}px`;
button.style.top = `${y}px`;
}
});
}
function updatePartCallout() {
const part = mechanisms[state.active].parts.find(
(entry) => entry.id === state.selectedPart
);
document.querySelector("#partTitle").textContent = part.label;
document.querySelector("#partDescription").textContent = part.text;
document.querySelectorAll(".step-item").forEach((button) => {
button.classList.toggle("active", button.dataset.part === state.selectedPart);
});
hotspotElements.forEach(({ button, part: hotspotPart }) => {
button.classList.toggle("active", hotspotPart.id === state.selectedPart);
});
}
function setPart(partId) {
state.selectedPart = partId;
highlightPart(partId);
updatePartCallout();
}
function updateTraceButton() {
const button = document.querySelector("#traceButton");
button.classList.toggle("active", state.tracing);
button.textContent = state.tracing ? "Tracing load path…" : "Trace the load path";
document.querySelector("#traceStatus").textContent = state.tracing
? `Step ${state.traceIndex + 1} of ${mechanisms[state.active].parts.length}`
: "Select a numbered step";
}
function updatePanel() {
const mechanism = mechanisms[state.active];
const value = state.values[state.active];
document.documentElement.style.setProperty("--active", mechanism.color);
document.querySelector("#mechanismTitle").textContent = mechanism.name;
document.querySelector("#typeBadge").textContent = mechanism.type;
document.querySelector("#description").textContent = mechanism.description;
document.querySelector("#sizeNumber").textContent = formatValue(state.active, value);
document.querySelector("#sizeNote").textContent = mechanism.note;
document.querySelector("#rangeLabel").textContent = `${mechanism.min}–${mechanism.max} cm`;
const range = document.querySelector("#sizeRange");
range.min = mechanism.min;
range.max = mechanism.max;
range.step = mechanism.step;
range.value = value;
const progress =
((value - mechanism.min) / (mechanism.max - mechanism.min)) * 100;
range.style.setProperty("--range-progress", `${progress}%`);
document.querySelectorAll(".tab").forEach((tab) => {
tab.classList.toggle(
"active",
tab.dataset.closure === state.active ||
(tab.dataset.closure === "all" && false)
);
});
renderResolution(state.active);
renderSteps();
updateCards();
updateTraceButton();
updatePartCallout();
}
function setActive(id, focus = true) {
if (id !== "all" && !mechanisms[id]) return;
state.tracing = false;
if (id === "all") {
document.querySelectorAll(".tab").forEach((tab) => {
tab.classList.toggle("active", tab.dataset.closure === "all");
});
document.querySelector("#allView").classList.add("active");
focusClosure("all");
return;
}
state.active = id;
state.selectedPart = mechanisms[id].parts[0].id;
document.querySelector("#allView").classList.remove("active");
renderHotspots();
updatePanel();
highlightPart(state.selectedPart);
if (focus) focusClosure(id);
}
function setValue(value) {
const mechanism = mechanisms[state.active];
const clamped = THREE.MathUtils.clamp(value, mechanism.min, mechanism.max);
const snapped = Math.round(clamped / mechanism.step) * mechanism.step;
state.values[state.active] = Number(snapped.toFixed(2));
updateMechanism(state.active, state.values[state.active]);
updatePanel();
}
document.querySelector("#sizeRange").addEventListener("input", (event) => {
setValue(Number(event.target.value));
});
document.querySelector("#decrease").addEventListener("click", () => {
setValue(state.values[state.active] - mechanisms[state.active].step);
});
document.querySelector("#increase").addEventListener("click", () => {
setValue(state.values[state.active] + mechanisms[state.active].step);
});
document.querySelectorAll(".tab").forEach((tab) => {
tab.addEventListener("click", () => setActive(tab.dataset.closure, true));
});
document.querySelector("#allView").addEventListener("click", () => {
setActive("all", true);
});
document.querySelector("#traceButton").addEventListener("click", () => {
if (state.tracing) {
state.tracing = false;
updateTraceButton();
return;
}
state.tracing = true;
state.traceIndex = 0;
state.lastTraceTime = performance.now();
setPart(mechanisms[state.active].parts[0].id);
updateTraceButton();
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const mechanismRoots = Object.values(refs).map((entry) => entry.group);
let pointerDown = false;
let pointerMoved = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(mechanismRoots, true);
renderer.domElement.style.cursor = hits.length ? "pointer" : "grab";
return;
}
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
if (
Math.abs(event.clientX - pointerStartX) +
Math.abs(event.clientY - pointerStartY) >
5
) {
pointerMoved = true;
}
cameraState.desiredTheta -= deltaX * 0.006;
cameraState.desiredPhi = THREE.MathUtils.clamp(
cameraState.desiredPhi + deltaY * 0.0045,
0.72,
1.42
);
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointerDown = false;
renderer.domElement.style.cursor = "grab";
if (pointerMoved) return;
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(mechanismRoots, true);
if (!hits.length) return;
const object = hits[0].object;
const partId = getPart(object);
if (!partId) return;
let root = object;
while (root && !root.userData.closure) root = root.parent;
if (!root) return;
state.tracing = false;
setActive(root.userData.closure, false);
setPart(partId);
updateTraceButton();
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius + event.deltaY * 0.008,
4.8,
14
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.desiredTheta = 0.08;
cameraState.desiredPhi = 1.13;
focusClosure("all");
});
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
renderComparison();
renderHotspots();
Object.keys(mechanisms).forEach((id) => {
updateMechanism(id, state.values[id]);
});
setActive("belt", false);
updatePanel();
const clock = new THREE.Clock();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
Object.keys(mechanisms).forEach((id) => {
const target = state.values[id];
const current = state.displayValues[id];
const next = THREE.MathUtils.lerp(current, target, 1 - Math.pow(0.001, delta));
if (Math.abs(next - target) < 0.001) {
state.displayValues[id] = target;
} else {
state.displayValues[id] = next;
}
updateMechanism(id, state.displayValues[id]);
});
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.desiredTheta,
1 - Math.pow(0.0005, delta)
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.desiredPhi,
1 - Math.pow(0.0005, delta)
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.desiredRadius,
1 - Math.pow(0.0005, delta)
);
cameraTarget.lerp(desiredTarget, 1 - Math.pow(0.0005, delta));
const horizontalRadius =
cameraState.radius * Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x + horizontalRadius * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.phi),
cameraTarget.z + horizontalRadius * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
if (state.tracing && now - state.lastTraceTime > 1250) {
state.traceIndex += 1;
if (state.traceIndex >= mechanisms[state.active].parts.length) {
state.tracing = false;
updateTraceButton();
} else {
state.lastTraceTime = now;
setPart(mechanisms[state.active].parts[state.traceIndex].id);
updateTraceButton();
}
}
if (state.tracing) {
const mechanism = mechanisms[state.active];
const accent = new THREE.Color(mechanism.color);
const pulse = 0.34 + Math.sin(now * 0.007) * 0.14;
refs[state.active].group.traverse((object) => {
if (!object.isMesh || !object.material?.emissive) return;
if (getPart(object) === state.selectedPart) {
object.material.emissive.copy(accent);
object.material.emissiveIntensity = pulse;
}
});
}
updateHotspotPositions();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```