Prompt specification
Build or customize the Three.js 3D scene "Adjustable wearable design puzzle" 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: Adjustable wearable design puzzle
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/adjustable-wearable-design-puzzle-x0636
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts watch straps. Create generic wrist and arm forms with different circumferences; users configure strap lengths and buckle positions so each loop closes without overlap or unexplained stretching. Low-poly.
Working Three.js Starter (adjustable-wearable-design-puzzle-x0636):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Strap Fit Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(12, 23, 32, 0.9);
--panel-border: rgba(164, 199, 213, 0.16);
--text: #edf6f8;
--muted: #91a8b1;
--accent: #75e2c3;
--warn: #ff806f;
--blue: #8ab9ff;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.brand {
position: fixed;
z-index: 5;
top: 25px;
left: 28px;
pointer-events: none;
}
.brand-row {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 38px;
height: 38px;
border: 1px solid rgba(117, 226, 195, 0.5);
border-radius: 50%;
display: grid;
place-items: center;
color: var(--accent);
font-size: 15px;
font-weight: 800;
box-shadow: inset 0 0 20px rgba(117, 226, 195, 0.08);
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.brand p {
margin: 8px 0 0 50px;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.04em;
}
.hint {
position: fixed;
z-index: 4;
left: 28px;
bottom: 138px;
display: flex;
align-items: center;
gap: 9px;
color: rgba(219, 234, 239, 0.62);
font-size: 11px;
letter-spacing: 0.05em;
pointer-events: none;
}
.hint::before {
content: "";
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 9px var(--accent);
}
.panel {
position: fixed;
z-index: 10;
top: 22px;
right: 22px;
width: 348px;
max-height: calc(100vh - 44px);
overflow: auto;
padding: 20px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(25, 43, 54, 0.54), rgba(8, 18, 26, 0.82)),
var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.38),
inset 0 1px rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: rgba(117, 226, 195, 0.3) transparent;
}
.eyebrow {
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.panel h2 {
margin: 7px 0 4px;
font-size: 23px;
font-weight: 650;
letter-spacing: -0.025em;
}
.intro {
margin: 0 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.presets {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 18px;
}
.preset {
min-height: 58px;
padding: 9px 7px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: 160ms ease;
}
.preset:hover {
background: rgba(255, 255, 255, 0.055);
}
.preset.active {
border-color: rgba(117, 226, 195, 0.54);
background: rgba(117, 226, 195, 0.09);
box-shadow: inset 0 0 16px rgba(117, 226, 195, 0.04);
}
.preset span {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.11em;
}
.preset strong {
display: block;
margin-top: 5px;
font-size: 12px;
}
.control {
margin-top: 18px;
}
.control-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.control label {
color: #c9d9de;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.value {
color: var(--accent);
font-variant-numeric: tabular-nums;
font-size: 13px;
font-weight: 750;
}
.subvalue {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 4px;
border-radius: 99px;
background:
linear-gradient(90deg, rgba(117, 226, 195, 0.75), rgba(117, 226, 195, 0.1));
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
margin-top: -6px;
appearance: none;
border: 3px solid #10232c;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(117, 226, 195, 0.7);
}
input[type="range"]::-moz-range-track {
height: 4px;
border-radius: 99px;
background: rgba(117, 226, 195, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #10232c;
border-radius: 50%;
background: var(--accent);
}
.swatches {
display: flex;
align-items: center;
gap: 9px;
margin-top: 9px;
}
.swatch {
width: 25px;
height: 25px;
padding: 0;
border: 2px solid transparent;
border-radius: 50%;
cursor: pointer;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.swatch.active {
border-color: #effbff;
box-shadow:
0 0 0 2px #162832,
0 0 0 3px #effbff;
}
.fit-status {
margin-top: 19px;
padding: 14px;
border: 1px solid rgba(117, 226, 195, 0.2);
border-radius: 12px;
background: rgba(117, 226, 195, 0.055);
}
.fit-status.warning {
border-color: rgba(255, 128, 111, 0.34);
background: rgba(255, 128, 111, 0.065);
}
.status-line {
display: flex;
align-items: center;
gap: 9px;
}
.status-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 10px rgba(117, 226, 195, 0.65);
}
.warning .status-dot {
background: var(--warn);
box-shadow: 0 0 10px rgba(255, 128, 111, 0.65);
}
#status-title {
font-size: 13px;
font-weight: 800;
}
#status-detail {
margin: 7px 0 0 17px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.metric {
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 9px;
background: rgba(0, 0, 0, 0.12);
}
.metric span {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 5px;
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 12px;
}
.primary,
.secondary {
min-height: 40px;
padding: 0 14px;
border-radius: 10px;
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.055em;
text-transform: uppercase;
transition: 150ms ease;
}
.primary {
border: 1px solid rgba(117, 226, 195, 0.55);
background: var(--accent);
color: #092019;
}
.primary:hover {
background: #96efd5;
transform: translateY(-1px);
}
.secondary {
border: 1px solid rgba(255, 255, 255, 0.1);
background: rgba(255, 255, 255, 0.035);
color: var(--muted);
}
.secondary:hover {
color: var(--text);
background: rgba(255, 255, 255, 0.065);
}
.physical-note {
margin: 15px 0 0;
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
color: #7f969e;
font-size: 10px;
line-height: 1.55;
}
.physical-note strong {
color: #b4c7cd;
}
.cards {
position: fixed;
z-index: 6;
left: 28px;
bottom: 25px;
display: flex;
gap: 9px;
}
.summary-card {
width: 185px;
padding: 12px 13px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 12px;
background: rgba(9, 19, 27, 0.74);
backdrop-filter: blur(12px);
cursor: pointer;
transition: 160ms ease;
}
.summary-card:hover,
.summary-card.active {
border-color: rgba(117, 226, 195, 0.38);
background: rgba(16, 34, 42, 0.86);
transform: translateY(-2px);
}
.summary-top {
display: flex;
align-items: center;
gap: 8px;
}
.summary-id {
width: 22px;
height: 22px;
display: grid;
place-items: center;
border-radius: 6px;
color: #071018;
font-size: 10px;
font-weight: 900;
}
.summary-name {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.summary-data {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 10px;
color: var(--muted);
font-size: 10px;
}
.summary-data b {
color: #dce8eb;
font-variant-numeric: tabular-nums;
}
.summary-state {
margin-top: 8px;
color: var(--accent);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.summary-state.bad {
color: var(--warn);
}
#labels {
position: fixed;
z-index: 3;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.watch-label {
position: absolute;
min-width: 98px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
background: rgba(7, 16, 24, 0.76);
text-align: center;
transform: translate(-50%, -100%);
backdrop-filter: blur(8px);
pointer-events: auto;
cursor: pointer;
transition: border-color 150ms ease;
}
.watch-label:hover,
.watch-label.active {
border-color: rgba(117, 226, 195, 0.48);
}
.watch-label span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
}
.watch-label strong {
display: block;
margin-top: 2px;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.camera-reset {
position: fixed;
z-index: 8;
right: 390px;
top: 25px;
width: 38px;
height: 38px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 10px;
background: rgba(8, 19, 27, 0.68);
color: var(--muted);
cursor: pointer;
backdrop-filter: blur(10px);
}
.camera-reset:hover {
color: var(--text);
border-color: rgba(117, 226, 195, 0.35);
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: var(--bg);
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 45vh;
padding: 16px;
}
.brand {
top: 17px;
left: 17px;
}
.brand p,
.cards,
.hint {
display: none;
}
.camera-reset {
top: 17px;
right: 17px;
}
.panel h2 {
font-size: 19px;
}
.intro {
margin-bottom: 12px;
}
}
@media (max-width: 520px) {
.brand h1 {
font-size: 13px;
}
.brand-mark {
width: 32px;
height: 32px;
}
.presets {
margin-bottom: 10px;
}
.control {
margin-top: 13px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly wrist and watch strap fitting scene"></canvas>
<header class="brand">
<div class="brand-row">
<div class="brand-mark">SF</div>
<h1>Strap Fit Lab</h1>
</div>
<p>Three wrist sizes. One honest closure model.</p>
</header>
<button class="camera-reset" id="camera-reset" title="Reset camera" aria-label="Reset camera">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path
d="M4 8V4h4M20 8V4h-4M4 16v4h4M20 16v4h-4"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"
/>
<circle cx="12" cy="12" r="3.2" stroke="currentColor" stroke-width="1.7" />
</svg>
</button>
<div id="labels"></div>
<aside class="panel" aria-label="Watch strap controls">
<div class="eyebrow">Selected assembly</div>
<h2 id="selected-title">Standard wrist</h2>
<p class="intro">
Change the wrist, strap material length, and buckle position.
Length errors become a visible gap or overlap—never hidden mesh stretching.
</p>
<div class="presets" role="group" aria-label="Select a watch">
<button class="preset" data-select="0">
<span>A / Narrow</span>
<strong>150 mm</strong>
</button>
<button class="preset active" data-select="1">
<span>B / Regular</span>
<strong>175 mm</strong>
</button>
<button class="preset" data-select="2">
<span>C / Broad</span>
<strong>205 mm</strong>
</button>
</div>
<div class="control">
<div class="control-head">
<label for="circumference">Wrist circumference</label>
<output class="value" id="circumference-value">175 mm</output>
</div>
<input id="circumference" type="range" min="140" max="220" step="1" value="175" />
<span class="subvalue">Changing the wrist automatically refits the strap.</span>
</div>
<div class="control">
<div class="control-head">
<label for="strap-length">Strap material length</label>
<output class="value" id="strap-length-value">0.0 mm</output>
</div>
<input id="strap-length" type="range" min="120" max="210" step="0.5" value="170" />
<span class="subvalue" id="required-length">Exact fit requires 0.0 mm.</span>
</div>
<div class="control">
<div class="control-head">
<label for="buckle-position">Buckle position</label>
<output class="value" id="buckle-value">48%</output>
</div>
<input id="buckle-position" type="range" min="20" max="80" step="1" value="48" />
<span class="subvalue" id="buckle-detail">Position along the fixed wrist path.</span>
</div>
<div class="control">
<div class="control-head">
<label>Strap material</label>
<span class="value">Color</span>
</div>
<div class="swatches" id="swatches">
<button class="swatch" data-color="#b87346" style="background:#b87346" aria-label="Tan leather"></button>
<button class="swatch" data-color="#263b50" style="background:#263b50" aria-label="Navy leather"></button>
<button class="swatch" data-color="#672f38" style="background:#672f38" aria-label="Oxblood leather"></button>
<button class="swatch" data-color="#252a2e" style="background:#252a2e" aria-label="Black leather"></button>
</div>
</div>
<div class="fit-status" id="fit-status">
<div class="status-line">
<span class="status-dot"></span>
<span id="status-title">Loop closed</span>
</div>
<p id="status-detail">The buckle is seated with zero modeled stretch.</p>
<div class="metrics">
<div class="metric">
<span>Buckle-side reach</span>
<strong id="side-a">0.0 mm</strong>
</div>
<div class="metric">
<span>Tang-side reach</span>
<strong id="side-b">0.0 mm</strong>
</div>
</div>
</div>
<div class="actions">
<button class="primary" id="fit-button">Fit exactly</button>
<button class="secondary" id="reset-button">Reset</button>
</div>
<p class="physical-note">
<strong>Physical model:</strong> each band follows a fixed elliptical wrist path.
A short strap produces an open buckle gap; an extra-long strap produces visible overlap.
No strap mesh is scaled to conceal either condition.
</p>
</aside>
<div class="cards" id="cards"></div>
<div class="hint">Drag to orbit · Scroll to zoom · Click a watch to configure</div>
<div id="loading">Loading fit lab</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// One world unit represents 50 mm.
const MM = 0.02;
const GAP_MM = 8;
const GAP_WORLD = GAP_MM * MM;
const POSITIONS = [-2.75, 0, 2.75];
const DEFAULTS = [
{
name: "Narrow wrist",
shortName: "Narrow",
letter: "A",
circumference: 150,
buckle: 0.56,
color: "#b87346",
armColor: "#405966"
},
{
name: "Standard wrist",
shortName: "Regular",
letter: "B",
circumference: 175,
buckle: 0.48,
color: "#263b50",
armColor: "#56636b"
},
{
name: "Broad wrist",
shortName: "Broad",
letter: "C",
circumference: 205,
buckle: 0.52,
color: "#672f38",
armColor: "#665a5e"
}
];
const configs = DEFAULTS.map((d) => ({ ...d, strapLength: null }));
const watchRefs = [];
const canvas = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.Fog(0x071018, 12, 28);
const renderer = new THREE.WebGLRenderer({
canvas,
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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraState = {
yaw: 0.52,
pitch: 0.55,
radius: 11.7,
target: new THREE.Vector3(0, -0.05, -1.15)
};
function updateCamera() {
const { yaw, pitch, radius, target } = cameraState;
const horizontal = Math.sin(pitch) * radius;
camera.position.set(
target.x + horizontal * Math.sin(yaw),
target.y + Math.cos(pitch) * radius,
target.z + horizontal * Math.cos(yaw)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.yaw = 0.52;
cameraState.pitch = 0.55;
cameraState.radius = 11.7;
cameraState.target.set(0, -0.05, -1.15);
updateCamera();
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xc8e7ff, 0x1a2025, 1.75);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff1d7, 3.3);
key.position.set(5, 10, 8);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -9;
key.shadow.camera.right = 9;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -8;
key.shadow.camera.near = 1;
key.shadow.camera.far = 30;
scene.add(key);
const rim = new THREE.DirectionalLight(0x6dd9ff, 1.8);
rim.position.set(-8, 5, -7);
scene.add(rim);
const warm = new THREE.PointLight(0xffb46e, 18, 12, 2);
warm.position.set(0, 3, 4);
scene.add(warm);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x09151c,
roughness: 0.98,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.02;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(32, 32, 0x24414c, 0x142a34);
grid.position.y = -1.005;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
function ellipseCircumference(a, b) {
const h = ((a - b) ** 2) / ((a + b) ** 2);
return Math.PI * (a + b) * (1 + (3 * h) / (10 + Math.sqrt(4 - 3 * h)));
}
function makeArmGeometry(a, b) {
const radialSegments = 12;
const rings = [
{ z: -7.0, f: 1.34 },
{ z: -5.8, f: 1.29 },
{ z: -4.5, f: 1.20 },
{ z: -3.2, f: 1.12 },
{ z: -1.8, f: 1.055 },
{ z: -0.55, f: 1.0 },
{ z: 0.0, f: 1.0 },
{ z: 0.85, f: 0.97 }
];
const positions = [];
const indices = [];
for (const ring of rings) {
for (let j = 0; j < radialSegments; j++) {
const angle = (j / radialSegments) * Math.PI * 2;
positions.push(
Math.cos(angle) * a * ring.f,
Math.sin(angle) * b * ring.f,
ring.z
);
}
}
for (let i = 0; i < rings.length - 1; i++) {
for (let j = 0; j < radialSegments; j++) {
const next = (j + 1) % radialSegments;
const a0 = i * radialSegments + j;
const b0 = i * radialSegments + next;
const c0 = (i + 1) * radialSegments + next;
const d0 = (i + 1) * radialSegments + j;
indices.push(a0, b0, d0, b0, c0, d0);
}
}
const startCenter = positions.length / 3;
positions.push(0, 0, rings[0].z);
const endCenter = positions.length / 3;
positions.push(0, 0, rings[rings.length - 1].z);
const endOffset = (rings.length - 1) * radialSegments;
for (let j = 0; j < radialSegments; j++) {
const next = (j + 1) % radialSegments;
indices.push(startCenter, next, j);
indices.push(endCenter, endOffset + j, endOffset + next);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeHand(length, width, angle, material, y) {
const geometry = new THREE.BoxGeometry(length, 0.018, width);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(
Math.sin(angle) * length * 0.5,
y,
-Math.cos(angle) * length * 0.5
);
mesh.rotation.y = Math.PI / 2 - angle;
mesh.castShadow = true;
return mesh;
}
function makeWatchCase(a, b) {
const group = new THREE.Group();
const metal = new THREE.MeshStandardMaterial({
color: 0xaab7bd,
roughness: 0.3,
metalness: 0.82,
flatShading: true
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x263139,
roughness: 0.38,
metalness: 0.7,
flatShading: true
});
const dialMaterial = new THREE.MeshStandardMaterial({
color: 0x0a1822,
roughness: 0.48,
metalness: 0.2,
flatShading: true
});
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xdde8e8,
roughness: 0.48,
metalness: 0.1,
flatShading: true
});
const handMaterial = new THREE.MeshStandardMaterial({
color: 0xf1f6f4,
roughness: 0.35,
metalness: 0.15
});
const secondMaterial = new THREE.MeshStandardMaterial({
color: 0xff805f,
roughness: 0.4,
metalness: 0.1
});
const y = b + 0.15;
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.46, 0.16, 12, 1, false),
metal
);
body.position.y = y;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const bezel = new THREE.Mesh(
new THREE.TorusGeometry(0.35, 0.035, 6, 16),
darkMetal
);
bezel.rotation.x = Math.PI / 2;
bezel.position.y = y + 0.09;
bezel.castShadow = true;
group.add(bezel);
const dial = new THREE.Mesh(
new THREE.CylinderGeometry(0.332, 0.332, 0.026, 16),
dialMaterial
);
dial.position.y = y + 0.092;
group.add(dial);
const markerGeometry = new THREE.BoxGeometry(0.035, 0.012, 0.082);
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
marker.position.set(
Math.sin(angle) * 0.265,
y + 0.113,
-Math.cos(angle) * 0.265
);
marker.rotation.y = Math.PI / 2 - angle;
group.add(marker);
}
const hour = makeHand(0.17, 0.034, 0.8, handMaterial, y + 0.135);
const minute = makeHand(0.25, 0.024, -0.45, handMaterial, y + 0.148);
const second = makeHand(0.29, 0.012, 2.05, secondMaterial, y + 0.16);
group.add(hour, minute, second);
const pin = new THREE.Mesh(
new THREE.CylinderGeometry(0.026, 0.026, 0.025, 8),
secondMaterial
);
pin.position.y = y + 0.174;
group.add(pin);
const lugGeometry = new THREE.BoxGeometry(0.12, 0.12, 0.20);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const lug = new THREE.Mesh(lugGeometry, metal);
lug.position.set(sx * 0.28, b + 0.095, sz * 0.43);
lug.castShadow = true;
group.add(lug);
}
}
const crown = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.065, 0.12, 8),
metal
);
crown.rotation.z = Math.PI / 2;
crown.position.set(0.47, y, 0);
crown.castShadow = true;
group.add(crown);
return group;
}
function makeStrapPath(a, b, lugHalfSpacing) {
const count = 260;
const base = [];
const centers = [];
const normals = [];
const cumulative = [0];
const zAxis = new THREE.Vector3(0, 0, 1);
for (let i = 0; i <= count; i++) {
const t = i / count;
const theta = Math.PI / 2 - Math.PI * 2 * t;
base.push(
new THREE.Vector3(
(a + 0.022) * Math.cos(theta),
(b + 0.022) * Math.sin(theta),
lugHalfSpacing * (1 - 2 * t)
)
);
}
for (let i = 0; i <= count; i++) {
const prev = base[Math.max(0, i - 1)];
const next = base[Math.min(count, i + 1)];
const tangent = next.clone().sub(prev).normalize();
const normal = zAxis.clone().cross(tangent).normalize();
const center = base[i].clone().addScaledVector(normal, 0.018);
centers.push(center);
normals.push(normal);
if (i > 0) {
cumulative.push(
cumulative[i - 1] + center.distanceTo(centers[i - 1])
);
}
}
const total = cumulative[cumulative.length - 1];
function pointAt(distance) {
const s = THREE.MathUtils.clamp(distance, 0, total);
let low = 0;
let high = cumulative.length - 1;
while (low < high - 1) {
const mid = (low + high) >> 1;
if (cumulative[mid] <= s) low = mid;
else high = mid;
}
const span = cumulative[high] - cumulative[low] || 1;
const alpha = (s - cumulative[low]) / span;
const point = centers[low].clone().lerp(centers[high], alpha);
const tangent = centers[high].clone().sub(centers[low]).normalize();
const normal = zAxis.clone().cross(tangent).normalize();
return { point, tangent, normal };
}
return { centers, normals, cumulative, total, pointAt };
}
function makeRibbon(path, start, end, material, width = 0.34) {
const delta = Math.abs(end - start);
const segments = Math.max(10, Math.min(110, Math.ceil(delta / 0.045)));
const positions = [];
const indices = [];
const edgeA = [];
const edgeB = [];
const zAxis = new THREE.Vector3(0, 0, 1);
for (let i = 0; i <= segments; i++) {
const s = THREE.MathUtils.lerp(start, end, i / segments);
const { point, normal } = path.pointAt(s);
const left = point.clone().addScaledVector(zAxis, -width * 0.5);
const right = point.clone().addScaledVector(zAxis, width * 0.5);
positions.push(left.x, left.y, left.z);
positions.push(right.x, right.y, right.z);
edgeA.push(
point.clone()
.addScaledVector(zAxis, -width * 0.37)
.addScaledVector(normal, 0.008)
);
edgeB.push(
point.clone()
.addScaledVector(zAxis, width * 0.37)
.addScaledVector(normal, 0.008)
);
}
for (let i = 0; i < segments; i++) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, b, c, b, d, c);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
const edgeGeometryA = new THREE.BufferGeometry().setFromPoints(edgeA);
const edgeGeometryB = new THREE.BufferGeometry().setFromPoints(edgeB);
return { mesh, edgeGeometryA, edgeGeometryB };
}
function makeBuckle(path, closureDistance, warning) {
const group = new THREE.Group();
const { point, tangent } = path.pointAt(closureDistance);
const zAxis = new THREE.Vector3(0, 0, 1);
const widthAxis = zAxis.clone().projectOnPlane(tangent).normalize();
const outward = zAxis.clone().cross(tangent).normalize();
const matrix = new THREE.Matrix4().makeBasis(
tangent,
widthAxis.clone().negate(),
outward
);
const quaternion = new THREE.Quaternion().setFromRotationMatrix(matrix);
group.position.copy(point).addScaledVector(outward, 0.035);
group.quaternion.copy(quaternion);
const metal = new THREE.MeshStandardMaterial({
color: warning ? 0xd96f60 : 0xb9c5c9,
roughness: 0.25,
metalness: 0.88,
flatShading: true
});
const horizontalGeometry = new THREE.BoxGeometry(0.48, 0.055, 0.065);
const verticalGeometry = new THREE.BoxGeometry(0.055, 0.42, 0.065);
for (const y of [-0.21, 0.21]) {
const bar = new THREE.Mesh(horizontalGeometry, metal);
bar.position.y = y;
bar.castShadow = true;
group.add(bar);
}
for (const x of [-0.24, 0.24]) {
const bar = new THREE.Mesh(verticalGeometry, metal);
bar.position.x = x;
bar.castShadow = true;
group.add(bar);
}
const tang = new THREE.Mesh(
new THREE.BoxGeometry(0.37, 0.025, 0.025),
metal
);
tang.position.x = 0.17;
group.add(tang);
if (warning) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.31, 0.012, 6, 24),
new THREE.MeshBasicMaterial({
color: 0xff806f,
transparent: true,
opacity: 0.88,
depthWrite: false
})
);
ring.position.copy(point).addScaledVector(outward, 0.09);
ring.quaternion.copy(quaternion);
group.add(ring);
}
return group;
}
function makeHoles(path, start, end) {
const group = new THREE.Group();
const holeMaterial = new THREE.MeshBasicMaterial({
color: 0x080b0d,
side: THREE.DoubleSide
});
const zAxis = new THREE.Vector3(0, 0, 1);
const span = Math.min(0.95, Math.max(0.22, end - start));
for (let i = 0; i < 6; i++) {
const s = start + span * (0.2 + i * 0.13);
const { point, normal } = path.pointAt(s);
const hole = new THREE.Mesh(
new THREE.CircleGeometry(0.032, 8),
holeMaterial
);
hole.position.copy(point).addScaledVector(normal, 0.014);
hole.quaternion.setFromUnitVectors(zAxis, normal);
group.add(hole);
}
return group;
}
function disposeObject(object) {
const geometries = new Set();
const materials = new Set();
object.traverse((child) => {
if (child.geometry) geometries.add(child.geometry);
if (child.material) {
const list = Array.isArray(child.material)
? child.material
: [child.material];
list.forEach((material) => materials.add(material));
}
});
geometries.forEach((geometry) => geometry.dispose());
materials.forEach((material) => material.dispose());
}
function buildStrapAssembly(watch, index) {
const config = configs[index];
const path = watch.path;
const requiredWorld = path.total - GAP_WORLD;
const requiredMm = requiredWorld / MM;
const mismatchMm = config.strapLength - requiredMm;
const mismatchWorld = mismatchMm * MM;
const closure = path.total * config.buckle;
// Exact closure leaves only the physical buckle gap.
// Short material increases the gap. Extra material overlaps the other side.
const endA = closure - GAP_WORLD * 0.5 + mismatchWorld * 0.5;
const endB = closure + GAP_WORLD * 0.5 - mismatchWorld * 0.5;
watch.requiredMm = requiredMm;
watch.mismatchMm = mismatchMm;
watch.sideAMm = endA / MM;
watch.sideBMm = (path.total - endB) / MM;
const group = new THREE.Group();
const strapMaterial = new THREE.MeshStandardMaterial({
color: config.color,
roughness: 0.76,
metalness: 0.02,
side: THREE.DoubleSide,
flatShading: true
});
const stitchMaterial = new THREE.LineBasicMaterial({
color: 0xc8b59b,
transparent: true,
opacity: 0.52
});
const ribbonA = makeRibbon(path, 0, endA, strapMaterial);
const ribbonB = makeRibbon(path, endB, path.total, strapMaterial);
group.add(ribbonA.mesh, ribbonB.mesh);
const stitchA = new THREE.Line(
ribbonA.edgeGeometryA,
stitchMaterial
);
const stitchB = new THREE.Line(
ribbonB.edgeGeometryA,
stitchMaterial
);
const stitchC = new THREE.Line(
ribbonA.edgeGeometryB,
stitchMaterial
);
const stitchD = new THREE.Line(
ribbonB.edgeGeometryB,
stitchMaterial
);
group.add(stitchA, stitchB, stitchC, stitchD);
group.add(makeHoles(path, endB, path.total));
const warning = Math.abs(mismatchMm) > 0.15;
group.add(makeBuckle(path, closure, warning));
if (mismatchWorld > 0) {
const overlapMaterial = new THREE.MeshBasicMaterial({
color: 0xff6659,
transparent: true,
opacity: 0.38,
side: THREE.DoubleSide,
depthWrite: false
});
const overlap = makeRibbon(
path,
endB,
endA,
overlapMaterial,
0.35
);
overlap.mesh.renderOrder = 5;
group.add(overlap.mesh);
} else if (mismatchWorld < 0) {
const a = path.pointAt(endA).point;
const b = path.pointAt(endB).point;
const geometry = new THREE.BufferGeometry().setFromPoints([a, b]);
const material = new THREE.LineDashedMaterial({
color: 0xff806f,
dashSize: 0.06,
gapSize: 0.035,
transparent: true,
opacity: 0.95
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
group.add(line);
}
return group;
}
function updateStrap(index) {
const watch = watchRefs[index];
if (!watch) return;
if (watch.strapGroup) {
watch.root.remove(watch.strapGroup);
disposeObject(watch.strapGroup);
}
watch.strapGroup = buildStrapAssembly(watch, index);
watch.root.add(watch.strapGroup);
updateUI();
}
function rebuildWatch(index) {
const config = configs[index];
const old = watchRefs[index];
if (old) {
scene.remove(old.root);
disposeObject(old.root);
}
const root = new THREE.Group();
root.position.x = POSITIONS[index];
// A 30 × 23 mm base ellipse is scaled to the requested circumference.
const baseA = 30;
const baseB = 23;
const baseCircumference = ellipseCircumference(baseA, baseB);
const scale = config.circumference / baseCircumference;
const a = baseA * scale * MM;
const b = baseB * scale * MM;
const armGeometry = makeArmGeometry(a, b);
const armMaterial = new THREE.MeshStandardMaterial({
color: config.armColor,
roughness: 0.9,
metalness: 0,
flatShading: true
});
const arm = new THREE.Mesh(armGeometry, armMaterial);
arm.castShadow = true;
arm.receiveShadow = true;
root.add(arm);
const wire = new THREE.Mesh(
armGeometry,
new THREE.MeshBasicMaterial({
color: 0xb5d4df,
wireframe: true,
transparent: true,
opacity: 0.065,
depthWrite: false
})
);
root.add(wire);
root.add(makeWatchCase(a, b));
const path = makeStrapPath(a, b, 0.40);
const requiredMm = (path.total - GAP_WORLD) / MM;
if (config.strapLength === null) {
config.strapLength = requiredMm;
}
const labelAnchor = new THREE.Object3D();
labelAnchor.position.set(0, b + 1.05, 0.15);
root.add(labelAnchor);
const watch = {
root,
armMaterial,
path,
labelAnchor,
requiredMm,
mismatchMm: 0,
sideAMm: 0,
sideBMm: 0,
strapGroup: null
};
watchRefs[index] = watch;
watch.strapGroup = buildStrapAssembly(watch, index);
root.add(watch.strapGroup);
root.traverse((child) => {
if (child.isMesh) child.userData.pickIndex = index;
});
scene.add(root);
updateSelectionVisuals();
}
function updateSelectionVisuals() {
watchRefs.forEach((watch, index) => {
if (!watch) return;
const selected = index === selectedIndex;
watch.armMaterial.emissive.setHex(selected ? 0x153743 : 0x000000);
watch.armMaterial.emissiveIntensity = selected ? 0.42 : 0;
});
document.querySelectorAll(".watch-label").forEach((label, index) => {
label.classList.toggle("active", index === selectedIndex);
});
}
let selectedIndex = 1;
function selectWatch(index) {
selectedIndex = index;
updateSelectionVisuals();
updateUI();
}
const labelsRoot = document.querySelector("#labels");
const labelElements = configs.map((config, index) => {
const label = document.createElement("div");
label.className = "watch-label";
label.innerHTML = `
<span>${config.letter} / ${config.shortName}</span>
<strong>${config.circumference} mm wrist</strong>
`;
label.addEventListener("click", () => selectWatch(index));
labelsRoot.appendChild(label);
return label;
});
const cardsRoot = document.querySelector("#cards");
const cardElements = configs.map((config, index) => {
const card = document.createElement("button");
card.className = "summary-card";
card.type = "button";
card.addEventListener("click", () => selectWatch(index));
cardsRoot.appendChild(card);
return card;
});
function colorToCss(hex) {
return `#${hex.replace("#", "")}`;
}
function fitState(index) {
const watch = watchRefs[index];
if (!watch) return { exact: true, mismatch: 0 };
return {
exact: Math.abs(watch.mismatchMm) <= 0.15,
mismatch: watch.mismatchMm
};
}
function updateUI() {
const config = configs[selectedIndex];
const watch = watchRefs[selectedIndex];
if (!watch) return;
const state = fitState(selectedIndex);
const exact = state.exact;
document.querySelector("#selected-title").textContent = config.name;
document.querySelector("#circumference").value = config.circumference;
document.querySelector("#circumference-value").textContent =
`${config.circumference.toFixed(0)} mm`;
const strapInput = document.querySelector("#strap-length");
strapInput.min = Math.max(70, watch.requiredMm - 30).toFixed(1);
strapInput.max = (watch.requiredMm + 30).toFixed(1);
strapInput.value = config.strapLength;
document.querySelector("#strap-length-value").textContent =
`${config.strapLength.toFixed(1)} mm`;
document.querySelector("#required-length").textContent =
`Exact fit requires ${watch.requiredMm.toFixed(1)} mm.`;
document.querySelector("#buckle-position").value =
Math.round(config.buckle * 100);
document.querySelector("#buckle-value").textContent =
`${Math.round(config.buckle * 100)}%`;
const closureDistance = watch.path.total * config.buckle;
document.querySelector("#buckle-detail").textContent =
`${(closureDistance / MM).toFixed(1)} mm from the upper lug along the fixed wrist path.`;
document.querySelector("#side-a").textContent =
`${watch.sideAMm.toFixed(1)} mm`;
document.querySelector("#side-b").textContent =
`${watch.sideBMm.toFixed(1)} mm`;
const fitStatus = document.querySelector("#fit-status");
fitStatus.classList.toggle("warning", !exact);
if (exact) {
document.querySelector("#status-title").textContent = "Loop closed";
document.querySelector("#status-detail").textContent =
"The buckle is seated correctly. Modeled material stretch: 0.0 mm.";
} else if (state.mismatch < 0) {
document.querySelector("#status-title").textContent =
`Open by ${Math.abs(state.mismatch).toFixed(1)} mm`;
document.querySelector("#status-detail").textContent =
"Shortage is shown as a physical gap at the buckle. No material is stretched.";
} else {
document.querySelector("#status-title").textContent =
`Overlap by ${state.mismatch.toFixed(1)} mm`;
document.querySelector("#status-detail").textContent =
"Excess material is visibly layered at the buckle. No material is stretched.";
}
document.querySelectorAll(".preset").forEach((button) => {
button.classList.toggle(
"active",
Number(button.dataset.select) === selectedIndex
);
});
document.querySelectorAll(".swatch").forEach((button) => {
button.classList.toggle(
"active",
button.dataset.color.toLowerCase() === config.color.toLowerCase()
);
});
watchRefs.forEach((item, index) => {
const itemConfig = configs[index];
const itemState = fitState(index);
const card = cardElements[index];
card.classList.toggle("active", index === selectedIndex);
card.innerHTML = `
<div class="summary-top">
<span class="summary-id" style="background:${colorToCss(itemConfig.color)}">
${itemConfig.letter}
</span>
<span class="summary-name">${itemConfig.shortName}</span>
</div>
<div class="summary-data">
<span>Wrist <b>${itemConfig.circumference} mm</b></span>
<span>Strap <b>${itemConfig.strapLength.toFixed(0)} mm</b></span>
</div>
<div class="summary-state ${itemState.exact ? "" : "bad"}">
${itemState.exact
? "● Closed · 0 mm stretch"
: `● ${itemState.mismatch < 0 ? "Open" : "Overlap"} ${Math.abs(itemState.mismatch).toFixed(1)} mm`}
</div>
`;
labelElements[index].querySelector("strong").textContent =
`${itemConfig.circumference} mm wrist · ${itemState.exact ? "Closed" : "Check fit"}`;
});
}
document.querySelectorAll(".preset").forEach((button) => {
button.addEventListener("click", () => {
selectWatch(Number(button.dataset.select));
});
});
document.querySelector("#circumference").addEventListener("input", (event) => {
configs[selectedIndex].circumference = Number(event.target.value);
configs[selectedIndex].strapLength = null;
rebuildWatch(selectedIndex);
updateUI();
});
document.querySelector("#strap-length").addEventListener("input", (event) => {
configs[selectedIndex].strapLength = Number(event.target.value);
updateStrap(selectedIndex);
});
document.querySelector("#buckle-position").addEventListener("input", (event) => {
configs[selectedIndex].buckle = Number(event.target.value) / 100;
updateStrap(selectedIndex);
});
document.querySelector("#swatches").addEventListener("click", (event) => {
const button = event.target.closest("[data-color]");
if (!button) return;
configs[selectedIndex].color = button.dataset.color;
updateStrap(selectedIndex);
});
document.querySelector("#fit-button").addEventListener("click", () => {
const watch = watchRefs[selectedIndex];
configs[selectedIndex].strapLength = watch.requiredMm;
updateStrap(selectedIndex);
});
document.querySelector("#reset-button").addEventListener("click", () => {
configs[selectedIndex] = {
...DEFAULTS[selectedIndex],
strapLength: null
};
rebuildWatch(selectedIndex);
updateUI();
});
document.querySelector("#camera-reset").addEventListener("click", resetCamera);
// Direct camera controls; no examples/addons are imported.
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let dragging = false;
let pointerStart = { x: 0, y: 0 };
let previousPointer = { x: 0, y: 0 };
let draggedDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
draggedDistance = 0;
pointerStart = { x: event.clientX, y: event.clientY };
previousPointer = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
draggedDistance += Math.abs(dx) + Math.abs(dy);
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.22,
1.25
);
previousPointer = { x: event.clientX, y: event.clientY };
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (draggedDistance < 5) {
const rect = canvas.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(
watchRefs.map((watch) => watch.root),
true
);
if (hits.length) {
const index = hits[0].object.userData.pickIndex;
if (Number.isInteger(index)) selectWatch(index);
}
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
7.2,
18
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const projected = new THREE.Vector3();
function updateLabels() {
watchRefs.forEach((watch, index) => {
watch.labelAnchor.getWorldPosition(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
labelElements[index].style.display = visible ? "block" : "none";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
labelElements[index].style.left = `${x}px`;
labelElements[index].style.top = `${y}px`;
});
}
configs.forEach((_, index) => rebuildWatch(index));
selectWatch(1);
renderer.setAnimationLoop(() => {
updateLabels();
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```