Prompt specification
Build or customize the Three.js 3D scene "Watch strap hole-spacing model" 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: Watch strap hole-spacing model
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/watch-strap-hole-spacing-model-x0633
Scene Description Prompt:
Please use Three.js from cdnjs for a stylized scene based on this idea: watch strap hole-spacing model. Show a watch strap laid flat with evenly spaced holes, buckle, and keeper; wrap a second copy around a cylinder to expose the adjustment relationship. Return one self-contained HTML file.
Working Three.js Starter (watch-strap-hole-spacing-model-x0633):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Watch Strap Hole-Spacing Study</title>
<style>
:root {
--ink: #183536;
--paper: #efede6;
--accent: #b88a46;
--muted: #677674;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
header {
position: absolute;
top: 28px;
left: 32px;
max-width: 390px;
}
.eyebrow {
margin-bottom: 9px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(26px, 3.4vw, 48px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.055em;
}
.subtitle {
max-width: 340px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.model-tag {
position: absolute;
min-width: 154px;
padding: 10px 13px 10px 15px;
border: 1px solid rgba(24, 53, 54, 0.13);
border-radius: 12px;
background: rgba(250, 249, 244, 0.88);
box-shadow: 0 12px 30px rgba(30, 49, 47, 0.10);
backdrop-filter: blur(12px);
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
}
.model-tag::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 24px;
background: linear-gradient(var(--accent), transparent);
}
.model-tag strong {
display: block;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.model-tag span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
}
#flatTag strong { color: var(--accent); }
#wrapTag strong { color: var(--ink); }
.controls {
position: absolute;
right: 28px;
top: 28px;
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
button {
border: 1px solid rgba(24, 53, 54, 0.16);
border-radius: 999px;
padding: 10px 15px;
background: rgba(250, 249, 244, 0.84);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(10px);
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fffdf8;
}
.hint {
position: absolute;
left: 32px;
bottom: 25px;
color: rgba(24, 53, 54, 0.57);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.legend {
position: absolute;
right: 30px;
bottom: 25px;
display: flex;
align-items: center;
gap: 9px;
color: rgba(24, 53, 54, 0.62);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend i {
width: 18px;
height: 3px;
border-radius: 2px;
background: var(--accent);
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: var(--paper);
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 450ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
header { top: 20px; left: 20px; max-width: 260px; }
.subtitle { display: none; }
.controls { top: 20px; right: 18px; }
.controls span { display: none; }
.model-tag { min-width: 132px; padding: 8px 10px; }
.model-tag span { font-size: 10px; }
.hint { left: 20px; bottom: 18px; }
.legend { display: none; }
}
</style>
</head>
<body>
<div id="loading">Preparing the strap study…</div>
<div class="ui">
<header>
<div class="eyebrow">Industrial design / 01</div>
<h1>Watch strap<br />hole-spacing model</h1>
<p class="subtitle">
A flat reference and a wrapped copy share the same hole pitch.
Bending the strap preserves every interval while revealing its relationship to circumference.
</p>
</header>
<div class="controls">
<span>Orbit / zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
<div id="flatTag" class="model-tag">
<strong>01 / Flat reference</strong>
<span>True cutouts · buckle · keeper</span>
</div>
<div id="wrapTag" class="model-tag">
<strong>02 / Wrapped copy</strong>
<span>Identical pitch across the arc</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div class="legend"><i></i> Measured hole interval</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xefede6);
scene.fog = new THREE.Fog(0xefede6, 17, 31);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const target = new THREE.Vector3(-0.65, 0.75, 0.02);
let azimuth = 0.24;
let polar = 1.075;
let radius = innerWidth < 720 ? 15.6 : 12.4;
const palette = {
strap: 0x173d3e,
strapDark: 0x0b2729,
brass: 0xc29958,
silver: 0xcbd4d4,
cylinder: 0xd8c2a0,
platform: 0xf8f6ef,
ground: 0xefede6,
stitch: 0xb69b76
};
const strapMaterial = new THREE.MeshPhysicalMaterial({
color: palette.strap,
roughness: 0.43,
metalness: 0.03,
clearcoat: 0.18,
clearcoatRoughness: 0.42
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: palette.strapDark,
roughness: 0.58,
metalness: 0.02,
side: THREE.DoubleSide
});
const brassMaterial = new THREE.MeshStandardMaterial({
color: palette.brass,
roughness: 0.3,
metalness: 0.72
});
const silverMaterial = new THREE.MeshStandardMaterial({
color: palette.silver,
roughness: 0.22,
metalness: 0.88
});
const cylinderMaterial = new THREE.MeshStandardMaterial({
color: palette.cylinder,
roughness: 0.72,
metalness: 0.01
});
const platformMaterial = new THREE.MeshStandardMaterial({
color: palette.platform,
roughness: 0.84,
metalness: 0
});
const groundMaterial = new THREE.MeshStandardMaterial({
color: palette.ground,
roughness: 0.94,
metalness: 0
});
const stitchMaterial = new THREE.LineDashedMaterial({
color: palette.stitch,
dashSize: 0.075,
gapSize: 0.055,
transparent: true,
opacity: 0.58
});
const measureMaterial = new THREE.MeshStandardMaterial({
color: palette.brass,
roughness: 0.32,
metalness: 0.55
});
function roundedRectShape(width, height, radius) {
const s = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
const r = Math.min(radius, width / 2, height / 2);
s.moveTo(x + r, y);
s.lineTo(x + width - r, y);
s.quadraticCurveTo(x + width, y, x + width, y + r);
s.lineTo(x + width, y + height - r);
s.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
s.lineTo(x + r, y + height);
s.quadraticCurveTo(x, y + height, x, y + height - r);
s.lineTo(x, y + r);
s.quadraticCurveTo(x, y, x + r, y);
return s;
}
const strapLength = 6.0;
const strapWidth = 0.90;
const strapDepth = 0.13;
const holeRadius = 0.12;
const holePitch = 0.75;
const holeXs = [-2.0, -1.25, -0.5, 0.25, 1.0, 1.75];
function createFlatStrapGeometry() {
const shape = roundedRectShape(strapLength, strapWidth, strapWidth * 0.48);
for (const x of holeXs) {
const hole = new THREE.Path();
hole.moveTo(x + holeRadius, 0);
hole.absarc(x, 0, holeRadius, 0, Math.PI * 2, true);
shape.holes.push(hole);
}
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: strapDepth,
steps: 1,
curveSegments: 40,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.014,
bevelThickness: 0.014
});
geometry.translate(0, 0, -strapDepth / 2);
geometry.computeVertexNormals();
return geometry;
}
function createBuckleModel() {
const group = new THREE.Group();
const outer = roundedRectShape(0.86, 1.08, 0.18);
const inner = roundedRectShape(0.58, 0.80, 0.12);
outer.holes.push(inner);
const frame = new THREE.Mesh(
new THREE.ExtrudeGeometry(outer, {
depth: 0.14,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: 0.025,
bevelThickness: 0.02,
curveSegments: 30
}),
silverMaterial
);
frame.geometry.translate(0, 0, -0.07);
frame.castShadow = true;
group.add(frame);
const prong = new THREE.Mesh(
new THREE.CylinderGeometry(0.033, 0.033, 0.86, 14),
silverMaterial
);
prong.position.set(-0.24, 0, 0.095);
prong.castShadow = true;
group.add(prong);
const hinge = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.065, 0.16, 18),
silverMaterial
);
hinge.rotation.x = Math.PI / 2;
hinge.position.set(-0.34, 0, 0.07);
hinge.castShadow = true;
group.add(hinge);
return group;
}
function createKeeperModel() {
const group = new THREE.Group();
const outer = roundedRectShape(1.12, 0.42, 0.11);
const inner = roundedRectShape(0.92, 0.24, 0.07);
outer.holes.push(inner);
const loop = new THREE.Mesh(
new THREE.ExtrudeGeometry(outer, {
depth: 0.20,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.015,
bevelThickness: 0.012,
curveSegments: 24
}),
strapMaterial
);
loop.geometry.translate(0, 0, -0.10);
loop.castShadow = true;
group.add(loop);
return group;
}
function createRod(a, b, radius, material, radialSegments = 12) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
return mesh;
}
function createTextSprite(text, dark = true) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 160;
const ctx = canvas.getContext("2d");
const r = 28;
const x = 8;
const y = 8;
const w = 624;
const h = 144;
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
ctx.fillStyle = dark ? "rgba(20, 48, 49, 0.94)" : "rgba(249, 246, 237, 0.95)";
ctx.fill();
ctx.strokeStyle = dark ? "rgba(211, 172, 103, 0.72)" : "rgba(24, 53, 54, 0.18)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = dark ? "#f8f4e9" : "#183536";
ctx.font = "700 38px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, w / 2, h / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.62, 0.405, 1);
sprite.renderOrder = 20;
return sprite;
}
function addFlatStitching(group, z) {
const points = [];
for (let x = -2.72; x <= 2.67; x += 0.08) {
points.push(new THREE.Vector3(x, 0.282, z));
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
stitchMaterial
);
line.computeLineDistances();
group.add(line);
}
// Flat reference assembly.
const flat = new THREE.Group();
flat.position.set(-2.78, 0, 0.38);
flat.rotation.y = -0.105;
scene.add(flat);
const flatPlatform = new THREE.Mesh(
new THREE.BoxGeometry(7.15, 0.12, 1.85),
platformMaterial
);
flatPlatform.position.set(0.15, 0.06, 0);
flatPlatform.receiveShadow = true;
flat.add(flatPlatform);
const flatStrap = new THREE.Mesh(createFlatStrapGeometry(), strapMaterial);
flatStrap.rotation.x = -Math.PI / 2;
flatStrap.position.y = 0.205;
flatStrap.castShadow = true;
flatStrap.receiveShadow = true;
flat.add(flatStrap);
const flatBuckle = createBuckleModel();
flatBuckle.rotation.x = -Math.PI / 2;
flatBuckle.position.set(3.02, 0.245, 0);
flat.add(flatBuckle);
const flatKeeper = createKeeperModel();
flatKeeper.rotation.x = -Math.PI / 2;
flatKeeper.position.set(-2.56, 0.265, 0);
flat.add(flatKeeper);
addFlatStitching(flat, -0.365);
addFlatStitching(flat, 0.365);
for (const x of holeXs.slice(0, 2)) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.137, 0.012, 8, 40),
measureMaterial
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(x, 0.278, 0);
flat.add(ring);
}
const flatMeasureY = 0.29;
const flatMeasureZ = 0.66;
flat.add(createRod(
new THREE.Vector3(-2.0, flatMeasureY, flatMeasureZ),
new THREE.Vector3(-1.25, flatMeasureY, flatMeasureZ),
0.012,
measureMaterial
));
for (const x of [-2.0, -1.25]) {
flat.add(createRod(
new THREE.Vector3(x, flatMeasureY, flatMeasureZ - 0.09),
new THREE.Vector3(x, flatMeasureY, flatMeasureZ + 0.09),
0.011,
measureMaterial
));
}
const flatLabel = createTextSprite("0.75 / HOLE PITCH");
flatLabel.position.set(-1.625, 0.52, 0.94);
flat.add(flatLabel);
// Curved, perforated strap geometry.
const wrapLength = 6.05;
const wrapWidth = 0.90;
const wrapDepth = 0.13;
const wrapRadius = 1.0;
const wrapStart = 0.12;
function isInsideHole(localX, v) {
for (const hx of holeXs) {
const dx = localX - hx;
if (dx * dx + v * v < holeRadius * holeRadius * 1.12) {
return true;
}
}
return false;
}
function createCurvedStrapGeometry() {
const positions = [];
const indices = [];
const longitudinalSegments = 240;
const widthSegments = 24;
const outerRadius = wrapRadius + wrapDepth / 2;
const innerRadius = wrapRadius - wrapDepth / 2;
function addLayer(radius, reverse) {
const base = positions.length / 3;
for (let i = 0; i <= longitudinalSegments; i++) {
const s = wrapLength * i / longitudinalSegments;
const theta = wrapStart + s / wrapRadius;
for (let j = 0; j <= widthSegments; j++) {
const v = -wrapWidth / 2 + wrapWidth * j / widthSegments;
positions.push(
v,
radius * Math.cos(theta),
radius * Math.sin(theta)
);
}
}
for (let i = 0; i < longitudinalSegments; i++) {
const s = (i + 0.5) * wrapLength / longitudinalSegments;
for (let j = 0; j < widthSegments; j++) {
const v = -wrapWidth / 2 +
wrapWidth * (j + 0.5) / widthSegments;
if (isInsideHole(s - wrapLength / 2, v)) continue;
const a = base + i * (widthSegments + 1) + j;
const b = base + (i + 1) * (widthSegments + 1) + j;
const c = b + 1;
const d = a + 1;
if (reverse) {
indices.push(a, d, b, b, d, c);
} else {
indices.push(a, b, d, b, c, d);
}
}
}
}
addLayer(outerRadius, false);
addLayer(innerRadius, true);
function addSide(v, reverse = false) {
const base = positions.length / 3;
for (let i = 0; i <= longitudinalSegments; i++) {
const s = wrapLength * i / longitudinalSegments;
const theta = wrapStart + s / wrapRadius;
positions.push(
v, outerRadius * Math.cos(theta), outerRadius * Math.sin(theta),
v, innerRadius * Math.cos(theta), innerRadius * Math.sin(theta)
);
}
for (let i = 0; i < longitudinalSegments; i++) {
const a = base + i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
if (reverse) indices.push(a, b, c, b, d, c);
else indices.push(a, c, b, b, c, d);
}
}
addSide(-wrapWidth / 2);
addSide(wrapWidth / 2, true);
function addEnd(s, reverse = false) {
const base = positions.length / 3;
const theta = wrapStart + s / wrapRadius;
for (let j = 0; j <= widthSegments; j++) {
const v = -wrapWidth / 2 + wrapWidth * j / widthSegments;
positions.push(
v, outerRadius * Math.cos(theta), outerRadius * Math.sin(theta),
v, innerRadius * Math.cos(theta), innerRadius * Math.sin(theta)
);
}
for (let j = 0; j < widthSegments; j++) {
const a = base + j * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
if (reverse) indices.push(a, b, c, b, d, c);
else indices.push(a, c, b, b, c, d);
}
}
addEnd(0);
addEnd(wrapLength, true);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
function createHoleTunnels() {
const positions = [];
const indices = [];
const segments = 48;
const outerRadius = wrapRadius + wrapDepth / 2;
const innerRadius = wrapRadius - wrapDepth / 2;
for (const holeX of holeXs) {
const base = positions.length / 3;
const centerS = holeX + wrapLength / 2;
for (let i = 0; i <= segments; i++) {
const phi = i / segments * Math.PI * 2;
const s = centerS + holeRadius * Math.cos(phi);
const v = holeRadius * Math.sin(phi);
const theta = wrapStart + s / wrapRadius;
positions.push(
v, outerRadius * Math.cos(theta), outerRadius * Math.sin(theta),
v, innerRadius * Math.cos(theta), innerRadius * Math.sin(theta)
);
}
for (let i = 0; i < segments; i++) {
const a = base + i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const wrapped = new THREE.Group();
wrapped.position.set(3.22, 1.02, -0.18);
scene.add(wrapped);
const wrappedBase = new THREE.Mesh(
new THREE.CylinderGeometry(1.28, 1.30, 0.14, 64),
platformMaterial
);
wrappedBase.position.y = -0.95;
wrappedBase.castShadow = true;
wrappedBase.receiveShadow = true;
wrapped.add(wrappedBase);
const wristForm = new THREE.Mesh(
new THREE.CylinderGeometry(0.89, 0.89, 1.58, 64, 1, false),
cylinderMaterial
);
wristForm.rotation.z = Math.PI / 2;
wristForm.castShadow = true;
wristForm.receiveShadow = true;
wrapped.add(wristForm);
const curvedStrap = new THREE.Mesh(
createCurvedStrapGeometry(),
strapMaterial
);
curvedStrap.castShadow = true;
curvedStrap.receiveShadow = true;
wrapped.add(curvedStrap);
const tunnels = new THREE.Mesh(
createHoleTunnels(),
darkMaterial
);
tunnels.castShadow = true;
wrapped.add(tunnels);
function basisQuaternion(xAxis, yAxis, zAxis) {
const matrix = new THREE.Matrix4();
matrix.makeBasis(xAxis, yAxis, zAxis);
return new THREE.Quaternion().setFromRotationMatrix(matrix);
}
function surfaceFrame(theta) {
const tangent = new THREE.Vector3(0, -Math.sin(theta), Math.cos(theta));
const widthAxis = new THREE.Vector3(1, 0, 0);
const normal = new THREE.Vector3(0, Math.cos(theta), Math.sin(theta));
return { tangent, widthAxis, normal };
}
function thetaForHole(holeX) {
return wrapStart + (holeX + wrapLength / 2) / wrapRadius;
}
for (const holeX of holeXs.slice(0, 2)) {
const theta = thetaForHole(holeX);
const { tangent, widthAxis, normal } = surfaceFrame(theta);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.137, 0.012, 8, 40),
measureMaterial
);
ring.quaternion.copy(
basisQuaternion(tangent, widthAxis, normal)
);
ring.position.copy(normal.multiplyScalar(wrapRadius + wrapDepth / 2 + 0.008));
wrapped.add(ring);
}
const thetaA = thetaForHole(holeXs[0]);
const thetaB = thetaForHole(holeXs[1]);
const arcPoints = [];
const arcStart = thetaA + holeRadius / wrapRadius;
const arcEnd = thetaB - holeRadius / wrapRadius;
for (let i = 0; i <= 30; i++) {
const theta = THREE.MathUtils.lerp(arcStart, arcEnd, i / 30);
const radius = wrapRadius + wrapDepth / 2 + 0.018;
arcPoints.push(new THREE.Vector3(
0,
radius * Math.cos(theta),
radius * Math.sin(theta)
));
}
const arc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(arcPoints),
new THREE.LineBasicMaterial({ color: palette.brass })
);
wrapped.add(arc);
const curvedLabel = createTextSprite("0.75 / ON ARC");
const labelTheta = (thetaA + thetaB) / 2;
const labelNormal = new THREE.Vector3(
0, Math.cos(labelTheta), Math.sin(labelTheta)
);
curvedLabel.position.copy(
labelNormal.multiplyScalar(wrapRadius + 0.53)
);
wrapped.add(curvedLabel);
function addCurvedStitching(v) {
const points = [];
const radius = wrapRadius + wrapDepth / 2 + 0.008;
for (let s = 0.05; s <= wrapLength - 0.05; s += 0.055) {
const theta = wrapStart + s / wrapRadius;
points.push(new THREE.Vector3(
v,
radius * Math.cos(theta),
radius * Math.sin(theta)
));
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
stitchMaterial
);
line.computeLineDistances();
wrapped.add(line);
}
addCurvedStitching(-0.365);
addCurvedStitching(0.365);
const endTheta = wrapStart + wrapLength / wrapRadius;
const endFrame = surfaceFrame(endTheta);
const wrappedBuckle = createBuckleModel();
wrappedBuckle.quaternion.copy(
basisQuaternion(endFrame.tangent, endFrame.widthAxis, endFrame.normal)
);
wrappedBuckle.position.copy(
endFrame.normal.multiplyScalar(wrapRadius + 0.01)
.add(endFrame.tangent.multiplyScalar(0.28))
);
wrapped.add(wrappedBuckle);
const keeperTheta = thetaForHole(-2.56);
const keeperFrame = surfaceFrame(keeperTheta);
const wrappedKeeper = createKeeperModel();
wrappedKeeper.quaternion.copy(
basisQuaternion(
keeperFrame.widthAxis,
keeperFrame.normal,
keeperFrame.tangent
)
);
wrappedKeeper.position.copy(
keeperFrame.normal.multiplyScalar(wrapRadius)
);
wrapped.add(wrappedKeeper);
// A restrained circular guide on the exposed cylinder end.
const capGuidePoints = [];
for (let i = 0; i < 100; i++) {
const a = i / 100 * Math.PI * 2;
capGuidePoints.push(new THREE.Vector3(
0.798,
0.70 * Math.cos(a),
0.70 * Math.sin(a)
));
}
const capGuide = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(capGuidePoints),
new THREE.LineBasicMaterial({
color: palette.brass,
transparent: true,
opacity: 0.43
})
);
wrapped.add(capGuide);
for (const x of [-0.795, 0.795]) {
const edgeRing = new THREE.Mesh(
new THREE.TorusGeometry(0.89, 0.012, 8, 64),
new THREE.MeshStandardMaterial({
color: 0xbba786,
roughness: 0.45,
metalness: 0.15
})
);
edgeRing.rotation.y = Math.PI / 2;
edgeRing.position.x = x;
wrapped.add(edgeRing);
}
// Environment and lighting.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.015;
ground.receiveShadow = true;
scene.add(ground);
const hemisphere = new THREE.HemisphereLight(0xfffbf1, 0x7c8b8b, 2.25);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xfff5df, 3.2);
key.position.set(-4.5, 10, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -10;
key.shadow.camera.right = 10;
key.shadow.camera.top = 9;
key.shadow.camera.bottom = -7;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 30;
key.shadow.bias = -0.00035;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0xb9d9dd, 1.2);
fill.position.set(7, 5, -6);
scene.add(fill);
const rim = new THREE.PointLight(0xffdfae, 25, 18, 2);
rim.position.set(-1, 4, -6);
scene.add(rim);
// Camera controls implemented directly, without addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function resetView() {
azimuth = 0.24;
polar = 1.075;
radius = innerWidth < 720 ? 15.6 : 12.4;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(polar - dy * 0.005, 0.52, 1.43);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius + event.deltaY * 0.008,
8.2,
20
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("reset").addEventListener("click", resetView);
addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") azimuth += 0.08;
if (event.key === "ArrowRight") azimuth -= 0.08;
if (event.key === "ArrowUp") polar = Math.max(0.52, polar - 0.06);
if (event.key === "ArrowDown") polar = Math.min(1.43, polar + 0.06);
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
const flatTag = document.getElementById("flatTag");
const wrapTag = document.getElementById("wrapTag");
function positionTag(element, worldPosition) {
const p = worldPosition.clone().project(camera);
const visible = p.z > -1 && p.z < 1;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(p.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-p.y * 0.5 + 0.5) * innerHeight}px`;
}
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function animate() {
requestAnimationFrame(animate);
updateCamera();
scene.updateMatrixWorld(true);
const flatAnchor = flat.localToWorld(
new THREE.Vector3(-0.8, 0.72, 1.02)
);
const wrappedAnchor = wrapped.localToWorld(
new THREE.Vector3(0, 1.66, 0.15)
);
positionTag(flatTag, flatAnchor);
positionTag(wrapTag, wrappedAnchor);
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
const loading = document.getElementById("loading");
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 500);
});
</script>
</body>
</html>
```