Prompt specification
Build or customize the Three.js 3D scene "Modular clothing 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: Modular clothing fastener exhibit
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/modular-clothing-fastener-exhibit-x0640
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Create a garment panel with interchangeable zipper, buttons, and ties; users operate each closure and compare how opening length and local attachment points differ.
Working Three.js Starter (modular-clothing-fastener-exhibit-x0640):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Closure Lab — Garment Panel</title>
<style>
:root {
--ink: #172326;
--muted: #657376;
--paper: rgba(250, 248, 242, 0.91);
--line: rgba(23, 35, 38, 0.13);
--accent: #df5f3f;
--teal: #267c78;
--gold: #e5ad4c;
--violet: #7156a5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 52% 38%, #f8f2e7 0, #eee5d7 43%, #d8cec0 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.topbar {
position: fixed;
z-index: 5;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 45px);
font-weight: 500;
letter-spacing: -0.045em;
line-height: 0.95;
}
.subtitle {
margin: 10px 0 0;
max-width: 390px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.view-tools {
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.view-chip,
.icon-button {
border: 1px solid rgba(23, 35, 38, 0.12);
background: rgba(250, 248, 242, 0.72);
color: var(--ink);
backdrop-filter: blur(12px);
box-shadow: 0 8px 30px rgba(45, 39, 31, 0.07);
}
.view-chip {
padding: 9px 12px;
border-radius: 999px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
}
.icon-button {
width: 36px;
height: 36px;
border-radius: 50%;
cursor: pointer;
font-size: 17px;
}
.icon-button:hover {
background: white;
}
.control-card,
.compare-card {
position: fixed;
z-index: 5;
border: 1px solid rgba(23, 35, 38, 0.12);
border-radius: 18px;
background: var(--paper);
box-shadow:
0 22px 70px rgba(42, 35, 27, 0.13),
inset 0 1px 0 rgba(255, 255, 255, 0.85);
backdrop-filter: blur(18px) saturate(1.1);
}
.control-card {
left: 28px;
bottom: 26px;
width: 326px;
padding: 17px;
}
.compare-card {
right: 28px;
bottom: 26px;
width: 346px;
padding: 17px;
}
.card-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
}
.card-heading h2 {
margin: 0;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.live-status {
display: flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.live-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(38, 124, 120, 0.11);
}
.closure-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-bottom: 17px;
}
.closure-tab {
min-width: 0;
padding: 10px 5px 9px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.42);
color: var(--muted);
cursor: pointer;
transition: 160ms ease;
}
.closure-tab:hover {
background: white;
color: var(--ink);
}
.closure-tab.active {
border-color: var(--ink);
background: var(--ink);
color: white;
box-shadow: 0 7px 18px rgba(23, 35, 38, 0.17);
}
.tab-icon {
display: block;
height: 19px;
margin-bottom: 5px;
font-size: 18px;
line-height: 19px;
}
.tab-name {
display: block;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
}
.range-block {
margin-top: 14px;
}
.range-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
font-size: 10px;
font-weight: 720;
}
output {
color: var(--muted);
font-variant-numeric: tabular-nums;
font-weight: 650;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--fill, 0%),
rgba(23, 35, 38, 0.12) var(--fill, 0%),
rgba(23, 35, 38, 0.12) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 2px 8px rgba(23, 35, 38, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid white;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 8px rgba(23, 35, 38, 0.25);
}
.operation-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 9px;
align-items: stretch;
margin-top: 17px;
}
.primary-button {
min-height: 42px;
border: 0;
border-radius: 11px;
background: var(--ink);
color: white;
cursor: pointer;
font-size: 11px;
font-weight: 780;
letter-spacing: 0.06em;
text-transform: uppercase;
transition: 160ms ease;
}
.primary-button:hover {
transform: translateY(-1px);
background: #294044;
}
.primary-button:active {
transform: translateY(0);
}
.anchor-toggle {
display: grid;
place-items: center;
width: 42px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.5);
color: var(--muted);
cursor: pointer;
font-size: 17px;
}
.anchor-toggle.active {
border-color: rgba(113, 86, 165, 0.32);
background: rgba(113, 86, 165, 0.1);
color: var(--violet);
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 16px;
}
.stat {
min-width: 0;
padding: 10px 8px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.36);
}
.stat-value {
display: block;
overflow: hidden;
color: var(--ink);
font-size: 16px;
font-weight: 750;
line-height: 1.1;
text-overflow: ellipsis;
white-space: nowrap;
}
.stat-label {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.mechanism {
min-height: 50px;
margin: 13px 1px 0;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.mechanism strong {
color: var(--ink);
}
.compare-card .card-heading {
margin-bottom: 8px;
}
.compare-intro {
margin: 0 0 12px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.compare-row {
display: grid;
grid-template-columns: 77px 1fr auto;
gap: 9px;
align-items: center;
width: 100%;
padding: 11px 8px;
border: 0;
border-top: 1px solid var(--line);
background: transparent;
color: var(--ink);
text-align: left;
cursor: pointer;
}
.compare-row:last-child {
border-bottom: 1px solid var(--line);
}
.compare-row:hover {
background: rgba(255, 255, 255, 0.46);
}
.compare-row.active {
margin: 0 -5px;
padding-right: 13px;
padding-left: 13px;
border-radius: 8px;
background: rgba(23, 35, 38, 0.065);
}
.compare-name {
font-size: 11px;
font-weight: 780;
}
.compare-type {
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.compare-travel {
color: var(--muted);
font-size: 9px;
font-variant-numeric: tabular-nums;
text-align: right;
}
.compare-legend {
display: flex;
gap: 13px;
margin-top: 13px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-dot {
width: 7px;
height: 7px;
border-radius: 50%;
}
.legend-dot.a {
background: var(--violet);
}
.legend-dot.b {
background: var(--gold);
}
.anchor-label {
position: fixed;
z-index: 4;
display: none;
width: 24px;
height: 24px;
border: 2px solid white;
border-radius: 50%;
color: white;
font-size: 9px;
font-weight: 850;
line-height: 20px;
text-align: center;
pointer-events: none;
box-shadow: 0 4px 14px rgba(23, 35, 38, 0.23);
transform: translate(-50%, -50%);
}
#labelA {
background: var(--violet);
}
#labelB {
background: var(--gold);
color: var(--ink);
}
.shortcut-note {
position: fixed;
z-index: 3;
left: 50%;
bottom: 27px;
transform: translateX(-50%);
color: rgba(23, 35, 38, 0.48);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
pointer-events: none;
text-transform: uppercase;
}
@media (max-width: 1050px) {
.compare-card {
width: 310px;
}
.control-card {
width: 304px;
}
.shortcut-note {
display: none;
}
}
@media (max-width: 760px) {
.topbar {
top: 15px;
left: 16px;
right: 16px;
}
.subtitle {
max-width: 250px;
font-size: 10px;
}
.view-chip {
display: none;
}
.control-card {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 13px;
border-radius: 15px;
}
.compare-card {
display: none;
}
.closure-tabs {
margin-bottom: 11px;
}
.range-block {
margin-top: 10px;
}
.operation-row {
margin-top: 12px;
}
.stats {
margin-top: 11px;
}
.mechanism {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="topbar">
<div>
<div class="eyebrow">Closure Lab / 03</div>
<h1>Garment Panel</h1>
<p class="subtitle">
Compare continuous, discrete, and tied closures. Release each mechanism,
move its local anchors, and inspect how the opening geometry changes.
</p>
</div>
<div class="view-tools">
<div class="view-chip">Drag to orbit · Scroll to zoom</div>
<button class="icon-button" id="resetView" title="Reset camera" aria-label="Reset camera">
↺
</button>
</div>
</header>
<section class="control-card" aria-label="Closure controls">
<div class="card-heading">
<h2>Closure mechanism</h2>
<div class="live-status">
<span class="live-dot"></span>
<span id="liveStatus">Closed</span>
</div>
</div>
<div class="closure-tabs" role="tablist" aria-label="Closure type">
<button class="closure-tab active" data-type="zipper" role="tab" aria-selected="true">
<span class="tab-icon">▥</span>
<span class="tab-name">ZIPPER</span>
</button>
<button class="closure-tab" data-type="buttons" role="tab" aria-selected="false">
<span class="tab-icon">●</span>
<span class="tab-name">BUTTONS</span>
</button>
<button class="closure-tab" data-type="ties" role="tab" aria-selected="false">
<span class="tab-icon">∞</span>
<span class="tab-name">TIES</span>
</button>
</div>
<div class="range-block">
<label class="range-label" for="openingRange">
<span>Opening length</span>
<output id="openingValue">0 cm</output>
</label>
<input id="openingRange" type="range" min="0" max="92" step="1" value="0" />
</div>
<div class="range-block">
<label class="range-label" for="anchorARange">
<span>Attachment point A</span>
<output id="anchorAValue">8 cm</output>
</label>
<input id="anchorARange" type="range" min="0" max="100" step="1" value="8" />
</div>
<div class="range-block">
<label class="range-label" for="anchorBRange">
<span>Attachment point B</span>
<output id="anchorBValue">88 cm</output>
</label>
<input id="anchorBRange" type="range" min="0" max="100" step="1" value="88" />
</div>
<div class="operation-row">
<button class="primary-button" id="operateButton">Release closure</button>
<button
class="anchor-toggle active"
id="anchorToggle"
title="Show attachment points"
aria-label="Show attachment points"
aria-pressed="true"
>
◎
</button>
</div>
<div class="stats" aria-live="polite">
<div class="stat">
<span class="stat-value" id="openingMetric">0 cm</span>
<span class="stat-label">Current opening</span>
</div>
<div class="stat">
<span class="stat-value" id="gapMetric">0 cm</span>
<span class="stat-label">Edge separation</span>
</div>
<div class="stat">
<span class="stat-value" id="attachmentMetric">80 cm</span>
<span class="stat-label">Anchor span</span>
</div>
</div>
<p class="mechanism" id="mechanismCopy">
<strong>Continuous engagement.</strong> Two toothed edge tapes interlock along
one shared center seam.
</p>
</section>
<aside class="compare-card" aria-label="Closure comparison">
<div class="card-heading">
<h2>Mechanism comparison</h2>
</div>
<p class="compare-intro">
Select a row to swap the mechanism while preserving its current open percentage.
</p>
<button class="compare-row active" data-type="zipper">
<span class="compare-name">Zipper</span>
<span class="compare-type">Continuous<br />edge-to-edge</span>
<span class="compare-travel">92 cm<br />max</span>
</button>
<button class="compare-row" data-type="buttons">
<span class="compare-name">Buttons</span>
<span class="compare-type">4 discrete<br />point pairs</span>
<span class="compare-travel">72 cm<br />max</span>
</button>
<button class="compare-row" data-type="ties">
<span class="compare-name">Ties</span>
<span class="compare-type">Offset side<br />anchors</span>
<span class="compare-travel">48 cm<br />max</span>
</button>
<div class="compare-legend">
<span class="legend-item"><i class="legend-dot a"></i> Anchor A</span>
<span class="legend-item"><i class="legend-dot b"></i> Anchor B</span>
</div>
</aside>
<div class="anchor-label" id="labelA">A</div>
<div class="anchor-label" id="labelB">B</div>
<div class="shortcut-note">1 / 2 / 3 swap closure · Space release / close</div>
<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");
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe8dfd1, 8, 15);
const camera = new THREE.PerspectiveCamera(
34,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
const hemisphere = new THREE.HemisphereLight(0xfff8ea, 0x607476, 2.05);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4db, 3.3);
keyLight.position.set(-3.8, 6.5, 6.2);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xaed5d0, 1.45);
fillLight.position.set(4, 1.2, 3);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xe8aa5e, 14, 9, 2);
rimLight.position.set(-2.5, 1.2, -2.5);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xd8cdbd,
roughness: 0.94,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.28;
ground.receiveShadow = true;
scene.add(ground);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(3.1, 3.25, 0.13, 48),
new THREE.MeshStandardMaterial({
color: 0x34484a,
roughness: 0.78
})
);
pedestal.position.y = -2.34;
pedestal.receiveShadow = true;
scene.add(pedestal);
const garment = new THREE.Group();
garment.rotation.y = -0.05;
scene.add(garment);
// -------------------------------------------------------------------------
// State
// -------------------------------------------------------------------------
const closureDefs = {
zipper: {
name: "Zipper",
maxOpening: 92,
maxGap: 0.78,
anchorA: 8,
anchorB: 88,
description:
"<strong>Continuous engagement.</strong> Two toothed edge tapes interlock along one shared center seam."
},
buttons: {
name: "Buttons",
maxOpening: 72,
maxGap: 0.63,
anchorA: 20,
anchorB: 80,
description:
"<strong>Discrete attachment.</strong> Four button-to-buttonhole bridges transfer load only at separated anchor points."
},
ties: {
name: "Ties",
maxOpening: 48,
maxGap: 0.49,
anchorA: 36,
anchorB: 56,
description:
"<strong>Offset attachment.</strong> Looped textile anchors pull from the sides, creating a softer and shorter opening."
}
};
const state = {
type: "zipper",
opening: 0,
targetNormalized: 0,
anchorA: 8,
anchorB: 88,
showAnchors: true,
manual: true
};
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function normalizedOpening() {
return state.opening / closureDefs[state.type].maxOpening;
}
function anchorY(centimetersFromNeck) {
return 1.65 - (centimetersFromNeck / 100) * 3.65;
}
function closureRun() {
const a = anchorY(state.anchorA);
const b = anchorY(state.anchorB);
return {
top: Math.min(a, b),
bottom: Math.max(a, b),
a,
b
};
}
// Separation at a vertical garment coordinate.
function gapAt(y) {
const normalized = normalizedOpening();
if (normalized <= 0.0001) return 0;
const def = closureDefs[state.type];
if (state.type === "ties") {
const vertical = clamp((y + 1.85) / 3.5, 0, 1);
return def.maxGap * normalized * (0.35 + vertical * 0.65);
}
const run = closureRun();
if (y > run.top || y < run.bottom) return 0;
const sliderY = run.top - normalized * (run.top - run.bottom);
if (y < sliderY) return 0;
const denominator = Math.max(0.001, run.top - sliderY);
return def.maxGap * normalized * ((y - sliderY) / denominator);
}
// -------------------------------------------------------------------------
// Low-poly garment panels
// -------------------------------------------------------------------------
const panelBaseColor = new THREE.Color("#277d78");
function makeBoundary(side) {
const raw = [
{ x: 0.00, y: 1.65, inner: true },
{ x: 0.28, y: 1.78 },
{ x: 1.03, y: 2.08 },
{ x: 1.62, y: 1.31 },
{ x: 1.88, y: -0.48 },
{ x: 1.55, y: -2.02 },
{ x: 0.00, y: -2.02, inner: true },
{ x: 0.00, y: -1.36, inner: true },
{ x: 0.00, y: -0.72, inner: true },
{ x: 0.00, y: -0.08, inner: true },
{ x: 0.00, y: 0.56, inner: true },
{ x: 0.00, y: 1.13, inner: true }
];
return raw.map((point) => ({
...point,
x: point.x * side
}));
}
function createGarmentPanel(side) {
const boundary = makeBoundary(side);
const center = new THREE.Vector3(side * 0.76, 0.02, 0.08);
const triangleCount = boundary.length;
const positions = new Float32Array(triangleCount * 9);
const colors = new Float32Array(triangleCount * 9);
for (let i = 0; i < triangleCount; i++) {
const lightness = 0.83 + (i % 3) * 0.055;
const color = panelBaseColor.clone().multiplyScalar(lightness);
for (let v = 0; v < 3; v++) {
color.toArray(colors, i * 9 + v * 3);
}
}
const geometry = new THREE.BufferGeometry();
const positionAttribute = new THREE.BufferAttribute(positions, 3);
positionAttribute.setUsage(THREE.DynamicDrawUsage);
geometry.setAttribute("position", positionAttribute);
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
side: THREE.DoubleSide,
roughness: 0.92,
metalness: 0.02,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
garment.add(mesh);
const outlineGeometry = new THREE.BufferGeometry();
outlineGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(boundary.length * 3), 3)
);
const outline = new THREE.LineLoop(
outlineGeometry,
new THREE.LineBasicMaterial({
color: 0xd4e3d6,
transparent: true,
opacity: 0.9
})
);
garment.add(outline);
const seamIndices = [0, 11, 10, 9, 8, 7, 6];
const seamGeometry = new THREE.BufferGeometry();
seamGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(seamIndices.length * 3), 3)
);
const seam = new THREE.Line(
seamGeometry,
new THREE.LineDashedMaterial({
color: 0xe8dfc8,
dashSize: 0.07,
gapSize: 0.045,
transparent: true,
opacity: 0.8
})
);
garment.add(seam);
return {
side,
boundary,
center,
mesh,
outline,
seam,
seamIndices
};
}
const panels = [createGarmentPanel(-1), createGarmentPanel(1)];
function updatePanel(panel) {
const position = panel.mesh.geometry.attributes.position;
const array = position.array;
const actualBoundary = panel.boundary.map((point, index) => {
const x = point.inner ? panel.side * gapAt(point.y) : point.x;
const z = Math.sin(index * 1.71) * 0.035;
return new THREE.Vector3(x, point.y, z);
});
let offset = 0;
for (let i = 0; i < panel.boundary.length; i++) {
const next = (i + 1) % panel.boundary.length;
panel.center.toArray(array, offset);
actualBoundary[i].toArray(array, offset + 3);
actualBoundary[next].toArray(array, offset + 6);
offset += 9;
}
position.needsUpdate = true;
panel.mesh.geometry.computeVertexNormals();
const outlinePosition = panel.outline.geometry.attributes.position;
actualBoundary.forEach((point, i) => point.toArray(outlinePosition.array, i * 3));
outlinePosition.needsUpdate = true;
const seamPosition = panel.seam.geometry.attributes.position;
panel.seamIndices.forEach((boundaryIndex, i) => {
actualBoundary[boundaryIndex].toArray(seamPosition.array, i * 3);
});
seamPosition.needsUpdate = true;
panel.seam.computeLineDistances();
}
// Shoulder pins add scale and a subtle tailoring reference.
const pinGeometry = new THREE.IcosahedronGeometry(0.065, 1);
const pinMaterial = new THREE.MeshStandardMaterial({
color: 0xe0ae53,
roughness: 0.38,
metalness: 0.48
});
for (const x of [-1.08, 1.08]) {
const pin = new THREE.Mesh(pinGeometry, pinMaterial);
pin.position.set(x, 2.03, 0.14);
pin.castShadow = true;
garment.add(pin);
}
// Vertical measurement rule.
const rulerPoints = [];
rulerPoints.push(new THREE.Vector3(-2.36, -2.0, -0.08));
rulerPoints.push(new THREE.Vector3(-2.36, 1.65, -0.08));
for (let i = 0; i <= 10; i++) {
const y = -2 + (i / 10) * 3.65;
rulerPoints.push(new THREE.Vector3(-2.36, y, -0.08));
rulerPoints.push(
new THREE.Vector3(i % 2 === 0 ? -2.48 : -2.42, y, -0.08)
);
}
const rulerGeometry = new THREE.BufferGeometry().setFromPoints(rulerPoints);
const ruler = new THREE.LineSegments(
rulerGeometry,
new THREE.LineBasicMaterial({
color: 0x6f7774,
transparent: true,
opacity: 0.42
})
);
scene.add(ruler);
// -------------------------------------------------------------------------
// Closure mechanisms
// -------------------------------------------------------------------------
const interactiveObjects = [];
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const unitRod = new THREE.CylinderGeometry(1, 1, 1, 6);
const upVector = new THREE.Vector3(0, 1, 0);
function setRod(mesh, a, b, radius, depth = radius) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(upVector, direction.normalize());
mesh.scale.set(radius, length, depth);
}
function markInteractive(object) {
object.userData.action = "toggle";
interactiveObjects.push(object);
}
// ZIPPER ------------------------------------------------------------------
const zipperGroup = new THREE.Group();
garment.add(zipperGroup);
const zipperTapeMaterial = new THREE.MeshStandardMaterial({
color: 0x29383b,
roughness: 0.78
});
const zipperToothMaterial = new THREE.MeshStandardMaterial({
color: 0xe8b65d,
roughness: 0.35,
metalness: 0.62
});
const zipperTapes = [];
const zipperTeeth = [];
for (let side of [-1, 1]) {
for (let i = 0; i < 20; i++) {
const mesh = new THREE.Mesh(unitBox, zipperTapeMaterial);
mesh.castShadow = true;
zipperGroup.add(mesh);
zipperTapes.push({ mesh, side });
}
for (let i = 0; i < 32; i++) {
const mesh = new THREE.Mesh(unitBox, zipperToothMaterial);
mesh.castShadow = true;
zipperGroup.add(mesh);
zipperTeeth.push({ mesh, side });
}
}
const zipperSlider = new THREE.Group();
const sliderBody = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.2, 0.09),
zipperToothMaterial
);
sliderBody.castShadow = true;
zipperSlider.add(sliderBody);
markInteractive(sliderBody);
const sliderPull = new THREE.Mesh(
new THREE.TorusGeometry(0.085, 0.018, 7, 18),
zipperToothMaterial
);
sliderPull.position.set(0, -0.15, 0.02);
sliderPull.castShadow = true;
zipperSlider.add(sliderPull);
zipperGroup.add(zipperSlider);
const zipperStoppers = [0, 1].map(() => {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.09, 0.065),
zipperToothMaterial
);
mesh.castShadow = true;
zipperGroup.add(mesh);
return mesh;
});
// BUTTONS -----------------------------------------------------------------
const buttonGroup = new THREE.Group();
garment.add(buttonGroup);
const buttonMaterial = new THREE.MeshStandardMaterial({
color: 0xf0dfbd,
roughness: 0.58
});
const holeMaterial = new THREE.MeshStandardMaterial({
color: 0x233b3d,
roughness: 0.82
});
const buttonGeometry = new THREE.CylinderGeometry(0.088, 0.088, 0.038, 12);
buttonGeometry.rotateX(Math.PI / 2);
const holeGeometry = new THREE.TorusGeometry(0.052, 0.012, 6, 14);
const buttons = [];
const holes = [];
for (let i = 0; i < 4; i++) {
const button = new THREE.Mesh(buttonGeometry, buttonMaterial);
button.castShadow = true;
buttonGroup.add(button);
buttons.push(button);
markInteractive(button);
const hole = new THREE.Mesh(holeGeometry, holeMaterial);
buttonGroup.add(hole);
holes.push(hole);
}
// TIES --------------------------------------------------------------------
const tieGroup = new THREE.Group();
garment.add(tieGroup);
const tieMaterial = new THREE.MeshStandardMaterial({
color: 0xcb694a,
roughness: 0.93
});
const tieRods = [];
for (let i = 0; i < 42; i++) {
const rod = new THREE.Mesh(unitRod, tieMaterial);
rod.castShadow = true;
tieGroup.add(rod);
tieRods.push(rod);
}
const tieKnot = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.16, 1),
tieMaterial
);
tieKnot.castShadow = true;
tieGroup.add(tieKnot);
markInteractive(tieKnot);
// ANCHORS -----------------------------------------------------------------
const anchorGroup = new THREE.Group();
garment.add(anchorGroup);
const markerA = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.09, 1),
new THREE.MeshStandardMaterial({
color: 0x7156a5,
emissive: 0x28194e,
emissiveIntensity: 0.22,
roughness: 0.42
})
);
const markerB = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.09, 1),
new THREE.MeshStandardMaterial({
color: 0xe5ad4c,
emissive: 0x563807,
emissiveIntensity: 0.18,
roughness: 0.42
})
);
anchorGroup.add(markerA, markerB);
const anchorLineGeometry = new THREE.BufferGeometry();
anchorLineGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const anchorLine = new THREE.Line(
anchorLineGeometry,
new THREE.LineDashedMaterial({
color: 0x7156a5,
dashSize: 0.065,
gapSize: 0.045,
transparent: true,
opacity: 0.72
})
);
anchorGroup.add(anchorLine);
const labelA = document.querySelector("#labelA");
const labelB = document.querySelector("#labelB");
let markerPositionA = new THREE.Vector3();
let markerPositionB = new THREE.Vector3();
function quadraticPoint(a, b, c, t, target = new THREE.Vector3()) {
const inverse = 1 - t;
target.set(0, 0, 0);
target.addScaledVector(a, inverse * inverse);
target.addScaledVector(b, 2 * inverse * t);
target.addScaledVector(c, t * t);
return target;
}
function updateZipper() {
const run = closureRun();
const normalized = normalizedOpening();
const sliderY = run.top - normalized * (run.top - run.bottom);
for (let i = 0; i < zipperTapes.length; i++) {
const entry = zipperTapes[i];
const t0 = i / zipperTapes.length;
const t1 = (i + 1) / zipperTapes.length;
const y0 = lerp(run.top, run.bottom, t0);
const y1 = lerp(run.top, run.bottom, t1);
const ym = (y0 + y1) * 0.5;
const x = entry.side * (gapAt(ym) + 0.035);
const a = new THREE.Vector3(x, y0, 0.13);
const b = new THREE.Vector3(x, y1, 0.13);
setRod(entry.mesh, a, b, 0.038, 0.028);
}
for (let i = 0; i < zipperTeeth.length; i++) {
const entry = zipperTeeth[i];
const y = lerp(run.top, run.bottom, (i + 0.5) / zipperTeeth.length);
const x = entry.side * (gapAt(y) + 0.013);
entry.mesh.position.set(x, y, 0.175);
entry.mesh.scale.set(0.055, 0.047, 0.035);
entry.mesh.rotation.z = entry.side * 0.08;
}
zipperSlider.position.set(gapAt(sliderY), sliderY, 0.225);
zipperStoppers[0].position.set(
gapAt(run.top),
run.top,
0.19
);
zipperStoppers[1].position.set(
gapAt(run.bottom),
run.bottom,
0.19
);
}
function updateButtons() {
const run = closureRun();
for (let i = 0; i < buttons.length; i++) {
const y = lerp(run.top, run.bottom, i / (buttons.length - 1));
const gap = gapAt(y);
buttons[i].position.set(gap + 0.075, y, 0.19);
holes[i].position.set(-gap - 0.075, y, 0.18);
}
}
function updateTies() {
const yA = anchorY(state.anchorA);
const yB = anchorY(state.anchorB);
const left = new THREE.Vector3(
-(gapAt(yA) + 0.28),
yA,
0.22
);
const right = new THREE.Vector3(
gapAt(yB) + 0.28,
yB,
0.22
);
const centerY = (yA + yB) * 0.5;
const knot = new THREE.Vector3(0, centerY, 0.3);
tieKnot.position.copy(knot);
let rodIndex = 0;
// Two main cords running from the side anchors into the knot.
for (const anchor of [left, right]) {
for (let i = 0; i < 8; i++) {
const a = new THREE.Vector3().lerpVectors(anchor, knot, i / 8);
const b = new THREE.Vector3().lerpVectors(anchor, knot, (i + 1) / 8);
setRod(tieRods[rodIndex++], a, b, 0.026);
}
}
// Two low-poly bow loops.
for (const side of [-1, 1]) {
const control = new THREE.Vector3(side * 0.96, centerY + 0.55, 0.27);
const end = new THREE.Vector3(side * 0.52, centerY + 0.04, 0.29);
for (let i = 0; i < 7; i++) {
const a = quadraticPoint(knot, control, end, i / 7);
const b = quadraticPoint(knot, control, end, (i + 1) / 7);
setRod(tieRods[rodIndex++], a, b, 0.024);
}
}
// Two hanging tails.
for (const side of [-1, 1]) {
const start = knot.clone();
const control = new THREE.Vector3(side * 0.2, centerY - 0.26, 0.24);
const end = new THREE.Vector3(side * 0.38, centerY - 0.64, 0.2);
for (let i = 0; i < 6; i++) {
const a = quadraticPoint(start, control, end, i / 6);
const b = quadraticPoint(start, control, end, (i + 1) / 6);
setRod(tieRods[rodIndex++], a, b, 0.025);
}
}
while (rodIndex < tieRods.length) {
tieRods[rodIndex].visible = false;
rodIndex++;
}
tieRods.forEach((rod, index) => {
if (index < 42) rod.visible = true;
});
markerPositionA.copy(left);
markerPositionB.copy(right);
}
function updateAnchors() {
if (state.type === "zipper") {
const a = anchorY(state.anchorA);
const b = anchorY(state.anchorB);
markerPositionA.set(-gapAt(a) - 0.055, a, 0.26);
markerPositionB.set(gapAt(b) + 0.055, b, 0.26);
} else if (state.type === "buttons") {
const a = anchorY(state.anchorA);
const b = anchorY(state.anchorB);
markerPositionA.set(-gapAt(a) - 0.075, a, 0.24);
markerPositionB.set(gapAt(b) + 0.075, b, 0.24);
}
markerA.position.copy(markerPositionA);
markerB.position.copy(markerPositionB);
const positions = anchorLine.geometry.attributes.position;
markerPositionA.toArray(positions.array, 0);
markerPositionB.toArray(positions.array, 3);
positions.needsUpdate = true;
anchorLine.computeLineDistances();
anchorGroup.visible = state.showAnchors;
}
function updateMechanisms() {
zipperGroup.visible = state.type === "zipper";
buttonGroup.visible = state.type === "buttons";
tieGroup.visible = state.type === "ties";
if (state.type === "zipper") updateZipper();
if (state.type === "buttons") updateButtons();
if (state.type === "ties") updateTies();
updateAnchors();
}
// -------------------------------------------------------------------------
// Camera controls — implemented without Three.js addons
// -------------------------------------------------------------------------
const cameraState = {
theta: 0,
phi: Math.PI / 2,
radius: 6.55,
target: new THREE.Vector3(0, 0.04, 0)
};
function applyCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = 0;
cameraState.phi = Math.PI / 2;
cameraState.radius = 6.55;
applyCamera();
}
const pointer = {
down: false,
moved: false,
x: 0,
y: 0,
startX: 0,
startY: 0
};
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
function objectIsVisible(object) {
let current = object;
while (current) {
if (!current.visible) return false;
current = current.parent;
}
return true;
}
function pickClosure(event) {
const rect = renderer.domElement.getBoundingClientRect();
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const hits = raycaster.intersectObjects(interactiveObjects, false);
return hits.find((hit) => objectIsVisible(hit.object));
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.down = true;
pointer.moved = false;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.down) {
renderer.domElement.style.cursor = pickClosure(event) ? "pointer" : "grab";
return;
}
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (Math.hypot(
event.clientX - pointer.startX,
event.clientY - pointer.startY
) > 4) {
pointer.moved = true;
}
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi - dy * 0.005, 0.72, 2.12);
applyCamera();
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointer.down = false;
renderer.domElement.style.cursor = "grab";
if (!pointer.moved) {
const hit = pickClosure(event);
if (hit) toggleClosure();
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.down = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius + event.deltaY * 0.005,
4.5,
9
);
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
const openingRange = document.querySelector("#openingRange");
const openingValue = document.querySelector("#openingValue");
const anchorARange = document.querySelector("#anchorARange");
const anchorBRange = document.querySelector("#anchorBRange");
const anchorAValue = document.querySelector("#anchorAValue");
const anchorBValue = document.querySelector("#anchorBValue");
const operateButton = document.querySelector("#operateButton");
const anchorToggle = document.querySelector("#anchorToggle");
const liveStatus = document.querySelector("#liveStatus");
const openingMetric = document.querySelector("#openingMetric");
const gapMetric = document.querySelector("#gapMetric");
const attachmentMetric = document.querySelector("#attachmentMetric");
const mechanismCopy = document.querySelector("#mechanismCopy");
const typeButtons = [
...document.querySelectorAll(".closure-tab"),
...document.querySelectorAll(".compare-row")
];
function updateRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percentage = max === min ? 0 : ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
function setClosure(type) {
if (!closureDefs[type]) return;
const oldNormalized = normalizedOpening();
state.type = type;
state.opening = oldNormalized * closureDefs[type].maxOpening;
state.anchorA = closureDefs[type].anchorA;
state.anchorB = closureDefs[type].anchorB;
state.manual = true;
openingRange.max = String(closureDefs[type].maxOpening);
openingRange.value = String(state.opening);
anchorARange.value = String(state.anchorA);
anchorBRange.value = String(state.anchorB);
typeButtons.forEach((button) => {
const active = button.dataset.type === type;
button.classList.toggle("active", active);
if (button.classList.contains("closure-tab")) {
button.setAttribute("aria-selected", String(active));
}
});
mechanismCopy.innerHTML = closureDefs[type].description;
updateRangeFill(openingRange);
updateRangeFill(anchorARange);
updateRangeFill(anchorBRange);
updateInterface();
}
function toggleClosure() {
const normalized = normalizedOpening();
state.manual = false;
state.targetNormalized = normalized > 0.5 ? 0 : 1;
updateInterface();
}
typeButtons.forEach((button) => {
button.addEventListener("click", () => setClosure(button.dataset.type));
});
operateButton.addEventListener("click", toggleClosure);
openingRange.addEventListener("input", () => {
state.opening = Number(openingRange.value);
state.manual = true;
state.targetNormalized = state.opening >= closureDefs[state.type].maxOpening ? 1 : 0;
updateRangeFill(openingRange);
updateInterface();
});
anchorARange.addEventListener("input", () => {
state.anchorA = Number(anchorARange.value);
updateRangeFill(anchorARange);
updateInterface();
});
anchorBRange.addEventListener("input", () => {
state.anchorB = Number(anchorBRange.value);
updateRangeFill(anchorBRange);
updateInterface();
});
anchorToggle.addEventListener("click", () => {
state.showAnchors = !state.showAnchors;
anchorToggle.classList.toggle("active", state.showAnchors);
anchorToggle.setAttribute("aria-pressed", String(state.showAnchors));
});
document.querySelector("#resetView").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "1") setClosure("zipper");
if (event.key === "2") setClosure("buttons");
if (event.key === "3") setClosure("ties");
if (event.code === "Space") {
event.preventDefault();
toggleClosure();
}
if (event.key.toLowerCase() === "r") resetCamera();
});
function updateInterface() {
const def = closureDefs[state.type];
const normalized = normalizedOpening();
const opening = Math.round(state.opening);
const separation = Math.round(def.maxGap * normalized * 34);
const anchorSpan = Math.round(Math.abs(state.anchorB - state.anchorA));
openingValue.textContent = `${opening} cm`;
anchorAValue.textContent = `${state.anchorA} cm`;
anchorBValue.textContent = `${state.anchorB} cm`;
openingMetric.textContent = `${opening} cm`;
gapMetric.textContent = `${separation} cm`;
attachmentMetric.textContent =
state.type === "buttons" ? "4 pairs" : `${anchorSpan} cm`;
if (normalized < 0.01) {
liveStatus.textContent = "Closed";
} else if (normalized > 0.985) {
liveStatus.textContent = "Fully open";
} else {
liveStatus.textContent = `${Math.round(normalized * 100)}% open`;
}
operateButton.textContent =
normalized > 0.5 ? "Close closure" : "Release closure";
openingRange.value = String(state.opening);
updateRangeFill(openingRange);
}
function projectLabel(element, position) {
const projected = position.clone().project(camera);
if (
!state.showAnchors ||
projected.z < -1 ||
projected.z > 1
) {
element.style.display = "none";
return;
}
element.style.display = "block";
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!state.manual) {
const max = closureDefs[state.type].maxOpening;
const target = state.targetNormalized * max;
const speed = max * 0.62;
if (Math.abs(target - state.opening) < 0.15) {
state.opening = target;
state.manual = true;
} else {
state.opening += Math.sign(target - state.opening) *
Math.min(speed * delta, Math.abs(target - state.opening));
}
}
panels.forEach(updatePanel);
updateMechanisms();
updateInterface();
projectLabel(labelA, markerPositionA);
projectLabel(labelB, markerPositionB);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
setClosure("zipper");
resetCamera();
animate();
</script>
</body>
</html>
```