Prompt specification
Build or customize the Three.js 3D scene "Lace tension closes shoe sides" 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: Lace tension closes shoe sides
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/lace-tension-closes-shoe-sides-x0622
Scene Description Prompt:
Pull both lace ends in a simplified rig so the two eyelet rows approach evenly; preserve the lacing order and keep the cord threaded through every hole. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (lace-tension-closes-shoe-sides-x0622):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Symmetric Lace Pull Rig</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(14, 21, 32, 0.86);
--border: rgba(148, 163, 184, 0.22);
--text: #e7edf6;
--muted: #93a4b8;
--cyan: #57d9ff;
--orange: #ff956f;
--green: #83e6b0;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #080d14;
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.title-card {
top: 24px;
left: 24px;
max-width: 360px;
padding: 18px 20px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(16px);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 7px;
font-size: clamp(25px, 4vw, 38px);
line-height: 1;
letter-spacing: -0.04em;
}
.title-card p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: fixed;
z-index: 10;
left: 50%;
bottom: 22px;
width: min(760px, calc(100vw - 28px));
transform: translateX(-50%);
padding: 15px 16px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
backdrop-filter: blur(18px);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
}
.control-row {
display: flex;
align-items: center;
gap: 14px;
}
.control-row + .control-row {
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid rgba(148, 163, 184, 0.13);
}
button,
input[type="range"] {
accent-color: var(--cyan);
}
button {
border: 1px solid rgba(148, 163, 184, 0.25);
border-radius: 10px;
padding: 9px 12px;
background: rgba(148, 163, 184, 0.09);
color: var(--text);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(87, 217, 255, 0.13);
border-color: rgba(87, 217, 255, 0.42);
}
button:active {
transform: translateY(1px);
}
button.primary {
min-width: 130px;
border-color: rgba(87, 217, 255, 0.42);
background: rgba(87, 217, 255, 0.14);
color: #bcefff;
}
input[type="range"] {
width: 100%;
min-width: 90px;
cursor: pointer;
}
.range-wrap {
display: grid;
flex: 1;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 10px;
}
.label {
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.value {
min-width: 48px;
color: var(--text);
font-variant-numeric: tabular-nums;
font-size: 12px;
font-weight: 800;
text-align: right;
}
.status {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-left: auto;
}
.badge {
padding: 6px 9px;
border: 1px solid rgba(131, 230, 176, 0.2);
border-radius: 999px;
background: rgba(131, 230, 176, 0.08);
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
white-space: nowrap;
}
.order {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 11px;
user-select: none;
cursor: pointer;
}
.order input {
margin: 0;
}
.sequence {
flex: 1;
min-width: 0;
overflow: hidden;
color: #b7c5d5;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
#gap-label {
position: fixed;
z-index: 4;
padding: 5px 8px;
border: 1px solid rgba(87, 217, 255, 0.25);
border-radius: 7px;
background: rgba(8, 13, 20, 0.84);
color: #bcefff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
}
.hint {
position: fixed;
z-index: 4;
top: 24px;
right: 24px;
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(14, 21, 32, 0.72);
color: var(--muted);
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(12px);
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
padding: 13px 15px;
}
.title-card p,
.hint,
.sequence {
display: none;
}
.controls {
bottom: 10px;
width: calc(100vw - 20px);
padding: 12px;
}
.control-row {
flex-wrap: wrap;
}
.status {
width: 100%;
margin-left: 0;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly shoelace tightening rig"></canvas>
<section class="hud title-card">
<div class="eyebrow">Symmetric Lace Pull Rig</div>
<h1>Even Pull</h1>
<p>
One continuous lace, ten threaded eyelets, and a symmetric linkage that
brings both eyelet rows inward at the same rate.
</p>
</section>
<div class="hint">
Drag a glowing end upward · Drag background to orbit · Wheel to zoom
</div>
<div id="gap-label">ROW GAP 2.65</div>
<section class="controls">
<div class="control-row">
<button id="pull-button" class="primary" type="button">Pull together</button>
<div class="range-wrap">
<label class="label" for="pull-slider">Pull</label>
<input
id="pull-slider"
type="range"
min="0"
max="100"
value="18"
aria-label="Lace pull amount"
/>
<output id="pull-value" class="value">18%</output>
</div>
<div class="status">
<span class="badge">10 / 10 HOLES THREADED</span>
<span class="badge">SYMMETRIC LINKAGE</span>
</div>
</div>
<div class="control-row">
<label class="order">
<input id="order-toggle" type="checkbox" checked />
Path order
</label>
<div class="sequence">
L5 → R4 → L3 → R2 → L1 → R1 → L2 → R3 → L4 → R5
</div>
<button id="release-button" type="button">Release</button>
<button id="reset-view" type="button">Reset view</button>
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const pullSlider = document.querySelector("#pull-slider");
const pullValue = document.querySelector("#pull-value");
const pullButton = document.querySelector("#pull-button");
const releaseButton = document.querySelector("#release-button");
const resetViewButton = document.querySelector("#reset-view");
const orderToggle = document.querySelector("#order-toggle");
const gapLabel = document.querySelector("#gap-label");
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080d14);
scene.fog = new THREE.Fog(0x080d14, 15, 30);
const camera = new THREE.OrthographicCamera(
-7,
7,
4.4,
-4.4,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 0.55, 0.1);
const cameraState = {
theta: 0.47,
phi: 0.86,
radius: 14,
zoom: 1
};
function updateCamera() {
const { theta, phi, radius } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const verticalSpan = 8.8;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.left = (-verticalSpan * aspect) / 2;
camera.right = (verticalSpan * aspect) / 2;
camera.top = verticalSpan / 2;
camera.bottom = -verticalSpan / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Lighting and floor
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0x9cc9ff, 0x1a1420, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0dc, 3.1);
keyLight.position.set(-4.5, 9, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x54c8ff, 1.4);
rimLight.position.set(5, 5, -6);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x0c121b,
roughness: 0.94,
metalness: 0.04
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.28;
floor.receiveShadow = true;
scene.add(floor);
// -------------------------------------------------------------------------
// Low-poly shoe body
// -------------------------------------------------------------------------
const soleOutline = [
[-1.48, -3.0],
[1.48, -3.0],
[1.86, -1.85],
[1.76, 1.55],
[1.53, 2.72],
[-1.53, 2.72],
[-1.76, 1.55],
[-1.86, -1.85]
];
const upperOutline = [
[-1.26, -2.72],
[1.26, -2.72],
[1.56, -1.82],
[1.48, 1.55],
[1.32, 2.45],
[-1.32, 2.45],
[-1.48, 1.55],
[-1.56, -1.82]
];
function makeShoeGeometry(outline, depth) {
const shape = new THREE.Shape();
outline.forEach(([x, z], index) => {
// The -PI/2 rotation later maps shape Y to world Z.
if (index === 0) shape.moveTo(x, -z);
else shape.lineTo(x, -z);
});
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.06,
bevelThickness: 0.04,
curveSegments: 1
});
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
return geometry;
}
const soleMaterial = new THREE.MeshStandardMaterial({
color: 0x171e28,
roughness: 0.86,
metalness: 0.05,
flatShading: true
});
const midsoleMaterial = new THREE.MeshStandardMaterial({
color: 0x637083,
roughness: 0.78,
metalness: 0.04,
flatShading: true
});
const upperMaterial = new THREE.MeshStandardMaterial({
color: 0x29394e,
roughness: 0.72,
metalness: 0.08,
flatShading: true
});
const sole = new THREE.Mesh(
makeShoeGeometry(soleOutline, 0.3),
soleMaterial
);
sole.position.y = -0.25;
sole.castShadow = true;
sole.receiveShadow = true;
scene.add(sole);
const midsole = new THREE.Mesh(
makeShoeGeometry(
soleOutline.map(([x, z]) => [x * 0.985, z * 0.99]),
0.14
),
midsoleMaterial
);
midsole.position.y = 0.01;
midsole.castShadow = true;
midsole.receiveShadow = true;
scene.add(midsole);
const upper = new THREE.Mesh(
makeShoeGeometry(upperOutline, 0.47),
upperMaterial
);
upper.position.y = 0.14;
upper.castShadow = true;
upper.receiveShadow = true;
scene.add(upper);
const tongue = new THREE.Mesh(
new THREE.BoxGeometry(1.22, 0.2, 4.45, 1, 1, 3),
new THREE.MeshStandardMaterial({
color: 0x536982,
roughness: 0.92,
metalness: 0,
flatShading: true
})
);
tongue.position.set(0, 0.71, 0.08);
tongue.castShadow = true;
tongue.receiveShadow = true;
scene.add(tongue);
const tongueBadge = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 0.035, 0.62),
new THREE.MeshStandardMaterial({
color: 0x263a50,
roughness: 0.8,
flatShading: true
})
);
tongueBadge.position.set(0, 0.825, -1.12);
tongueBadge.castShadow = true;
scene.add(tongueBadge);
const upperEdgePoints = upperOutline.map(
([x, z]) => new THREE.Vector3(x, 0.625, z)
);
const upperEdge = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(upperEdgePoints),
new THREE.LineBasicMaterial({
color: 0x7894b0,
transparent: true,
opacity: 0.65
})
);
scene.add(upperEdge);
// -------------------------------------------------------------------------
// Flexible side panels
// -------------------------------------------------------------------------
function createSidePanel(side) {
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(24);
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3).setUsage(
THREE.DynamicDrawUsage
)
);
geometry.setIndex([
0, 2, 1, 1, 2, 3,
0, 4, 1, 1, 4, 5,
2, 3, 6, 3, 7, 6,
0, 2, 4, 2, 6, 4,
1, 5, 3, 3, 5, 7,
4, 6, 5, 5, 6, 7
]);
const material = new THREE.MeshStandardMaterial({
color: side < 0 ? 0x3b526d : 0x354a63,
roughness: 0.8,
metalness: 0.04,
flatShading: true,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
function update(gap) {
const innerBottom = side * (gap / 2 - 0.46);
const innerTop = side * (gap / 2 - 0.43);
const outerBottom = side * 1.55;
const outerTop = side * 1.65;
const bottomZ = -2.38;
const topZ = 2.48;
const values = [
innerBottom, 0.82, bottomZ,
outerBottom, 0.72, bottomZ,
innerTop, 0.84, topZ,
outerTop, 0.74, topZ,
innerBottom, 0.71, bottomZ,
outerBottom, 0.61, bottomZ,
innerTop, 0.73, topZ,
outerTop, 0.63, topZ
];
positions.set(values);
geometry.attributes.position.needsUpdate = true;
geometry.computeVertexNormals();
}
return { mesh, update };
}
const panels = [
createSidePanel(-1),
createSidePanel(1)
];
// -------------------------------------------------------------------------
// Eyelet rows
// -------------------------------------------------------------------------
const holeZ = [-1.85, -0.925, 0, 0.925, 1.85];
const holeY = 0.91;
const eyeletMaterial = new THREE.MeshStandardMaterial({
color: 0xd9a54b,
emissive: 0x2b1703,
emissiveIntensity: 0.35,
roughness: 0.35,
metalness: 0.75,
flatShading: true
});
const eyelets = [];
for (const side of [-1, 1]) {
for (let index = 0; index < holeZ.length; index++) {
const geometry = new THREE.TorusGeometry(0.105, 0.027, 6, 14);
geometry.rotateX(Math.PI / 2);
const eyelet = new THREE.Mesh(geometry, eyeletMaterial);
eyelet.castShadow = true;
scene.add(eyelet);
eyelets.push({ mesh: eyelet, side, index });
}
}
// Center guide and dynamic row-gap gauge.
const centerGuide = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.835, -2.18),
new THREE.Vector3(0, 0.835, 2.28)
]),
new THREE.LineDashedMaterial({
color: 0x88b7d8,
dashSize: 0.12,
gapSize: 0.09,
transparent: true,
opacity: 0.55
})
);
centerGuide.computeLineDistances();
scene.add(centerGuide);
const gaugeGeometry = new THREE.BufferGeometry();
gaugeGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(18), 3)
);
const gauge = new THREE.LineSegments(
gaugeGeometry,
new THREE.LineBasicMaterial({
color: 0x57d9ff,
transparent: true,
opacity: 0.8
})
);
scene.add(gauge);
// -------------------------------------------------------------------------
// Pull handles
// -------------------------------------------------------------------------
const handlePickMeshes = [];
function createHandle(side, color) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.45,
roughness: 0.34,
metalness: 0.4,
flatShading: true
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.16, 0.052, 6, 12),
material
);
ring.rotation.x = Math.PI / 2;
ring.castShadow = true;
group.add(ring);
const grip = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 0.075, 0.1),
material
);
grip.position.y = 0.015;
grip.castShadow = true;
group.add(grip);
scene.add(group);
handlePickMeshes.push(ring);
return { group, ring, grip, side };
}
const leftHandle = createHandle(-1, 0x57d9ff);
const rightHandle = createHandle(1, 0xff956f);
// -------------------------------------------------------------------------
// Optional numbered path-order markers
// -------------------------------------------------------------------------
function createNumberSprite(number) {
const markerCanvas = document.createElement("canvas");
markerCanvas.width = 128;
markerCanvas.height = 128;
const context = markerCanvas.getContext("2d");
context.clearRect(0, 0, 128, 128);
context.beginPath();
context.arc(64, 64, 48, 0, Math.PI * 2);
context.fillStyle = "rgba(8, 13, 20, 0.9)";
context.fill();
context.lineWidth = 7;
context.strokeStyle = "#57d9ff";
context.stroke();
context.fillStyle = "#eaf8ff";
context.font = "bold 62px Arial";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(String(number), 64, 67);
const texture = new THREE.CanvasTexture(markerCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(0.27, 0.27, 0.27);
sprite.renderOrder = 10;
scene.add(sprite);
return sprite;
}
// A single continuous lace path. All ten holes occur exactly once.
const laceSequence = [
{ row: -1, index: 4 }, // L5
{ row: 1, index: 3 }, // R4
{ row: -1, index: 2 }, // L3
{ row: 1, index: 1 }, // R2
{ row: -1, index: 0 }, // L1
{ row: 1, index: 0 }, // R1
{ row: -1, index: 1 }, // L2
{ row: 1, index: 2 }, // R3
{ row: -1, index: 3 }, // L4
{ row: 1, index: 4 } // R5
];
const orderSprites = laceSequence.map((entry, index) =>
createNumberSprite(index + 1)
);
// -------------------------------------------------------------------------
// Continuous lace geometry
// -------------------------------------------------------------------------
const laceMaterial = new THREE.MeshStandardMaterial({
color: 0xf1dfb7,
roughness: 0.8,
metalness: 0.02,
flatShading: true
});
let laceMesh = null;
let lastBuiltPull = Number.NaN;
function rowX(row, gap) {
return row * gap * 0.5;
}
function buildLace(gap) {
const points = [];
const leftPosition = leftHandle.group.position;
const rightPosition = rightHandle.group.position;
// Left free end.
points.push(
new THREE.Vector3(
leftPosition.x,
leftPosition.y,
leftPosition.z
),
new THREE.Vector3(
leftPosition.x,
leftPosition.y + 0.035,
leftPosition.z - 0.32
)
);
function addHole(row, index, mode = "normal") {
const x = rowX(row, gap);
const z = holeZ[index];
if (mode === "top") {
points.push(
new THREE.Vector3(x, holeY + 0.14, z),
new THREE.Vector3(x, holeY, z),
new THREE.Vector3(x, holeY + 0.14, z)
);
} else if (mode === "normal") {
points.push(
new THREE.Vector3(x, holeY + 0.14, z),
new THREE.Vector3(x, holeY, z),
new THREE.Vector3(x, holeY - 0.16, z),
new THREE.Vector3(x, holeY + 0.14, z)
);
} else if (mode === "bottomA") {
points.push(
new THREE.Vector3(x, holeY + 0.14, z),
new THREE.Vector3(x, holeY, z),
new THREE.Vector3(x, holeY - 0.16, z)
);
} else if (mode === "bottomB") {
points.push(
new THREE.Vector3(x, holeY - 0.16, z),
new THREE.Vector3(x, holeY, z),
new THREE.Vector3(x, holeY + 0.14, z)
);
} else if (mode === "final") {
points.push(
new THREE.Vector3(x, holeY + 0.14, z),
new THREE.Vector3(x, holeY, z),
new THREE.Vector3(x, holeY + 0.14, z)
);
}
}
// Alternating over/under layers for the criss-cross sections.
const segmentLayers = [
1.07, 0.92, 1.07, 0.92, 0.52,
1.07, 0.92, 1.07, 0.92
];
addHole(laceSequence[0].row, laceSequence[0].index, "top");
for (let step = 1; step < laceSequence.length; step++) {
const previous = laceSequence[step - 1];
const current = laceSequence[step];
if (step === 4) {
// L1 descends through its eyelet and travels beneath the tongue.
addHole(current.row, current.index, "bottomA");
continue;
}
if (step === 5) {
// The hidden under-tongue section enters R1 from below.
const leftX = rowX(-1, gap);
const rightX = rowX(1, gap);
const z = holeZ[0];
points.push(
new THREE.Vector3(leftX, 0.52, z),
new THREE.Vector3(0, 0.5, z),
new THREE.Vector3(rightX, 0.52, z)
);
addHole(current.row, current.index, "bottomB");
continue;
}
const previousX = rowX(previous.row, gap);
const currentX = rowX(current.row, gap);
const previousZ = holeZ[previous.index];
const currentZ = holeZ[current.index];
points.push(
new THREE.Vector3(
(previousX + currentX) * 0.5,
segmentLayers[step - 1],
(previousZ + currentZ) * 0.5
)
);
addHole(
current.row,
current.index,
step === laceSequence.length - 1 ? "final" : "normal"
);
}
// Right free end.
points.push(
new THREE.Vector3(
rightPosition.x,
rightPosition.y + 0.035,
rightPosition.z + 0.32
),
new THREE.Vector3(
rightPosition.x,
rightPosition.y,
rightPosition.z
)
);
const curve = new THREE.CatmullRomCurve3(
points,
false,
"centripetal",
0.2
);
const geometry = new THREE.TubeGeometry(
curve,
360,
0.042,
6,
false
);
if (laceMesh) {
scene.remove(laceMesh);
laceMesh.geometry.dispose();
}
laceMesh = new THREE.Mesh(geometry, laceMaterial);
laceMesh.castShadow = true;
laceMesh.receiveShadow = true;
scene.add(laceMesh);
}
// -------------------------------------------------------------------------
// Rig state and updates
// -------------------------------------------------------------------------
const rig = {
targetPull: 0.18,
currentPull: 0.18,
gap: 2.65
};
function updateRig() {
const wideGap = 2.65;
const tightGap = 1.35;
const pull = rig.currentPull;
rig.gap = THREE.MathUtils.lerp(wideGap, tightGap, pull);
// Both rows use opposite signs around the same center, guaranteeing an
// equal inward displacement on the left and right.
for (const eyelet of eyelets) {
eyelet.mesh.position.set(
rowX(eyelet.side, rig.gap),
holeY,
holeZ[eyelet.index]
);
}
for (const panel of panels) {
panel.update(rig.gap);
}
const handleZ = 2.78 + pull * 0.68;
const handleY = 1.13 + pull * 0.055;
const handleX = 1.28 + pull * 0.16;
leftHandle.group.position.set(-handleX, handleY, handleZ);
rightHandle.group.position.set(handleX, handleY, handleZ);
// Dynamic gap measurement.
const gaugePositions = gaugeGeometry.attributes.position;
const halfGap = rig.gap * 0.5;
const gaugeZ = 2.47;
const gaugeY = 1.07;
gaugePositions.setXYZ(0, -halfGap, gaugeY, gaugeZ);
gaugePositions.setXYZ(1, halfGap, gaugeY, gaugeZ);
gaugePositions.setXYZ(2, -halfGap, gaugeY, gaugeZ - 0.13);
gaugePositions.setXYZ(3, -halfGap, gaugeY, gaugeZ + 0.13);
gaugePositions.setXYZ(4, halfGap, gaugeY, gaugeZ - 0.13);
gaugePositions.setXYZ(5, halfGap, gaugeY, gaugeZ + 0.13);
gaugePositions.needsUpdate = true;
// Update the numbered path-order markers.
laceSequence.forEach((entry, index) => {
const sprite = orderSprites[index];
sprite.visible = orderToggle.checked;
sprite.position.set(
rowX(entry.row, rig.gap) + entry.row * 0.22,
1.18,
holeZ[entry.index]
);
});
if (
laceMesh === null ||
Math.abs(pull - lastBuiltPull) > 0.00001
) {
buildLace(rig.gap);
lastBuiltPull = pull;
}
}
function updateGapLabel() {
const projected = new THREE.Vector3(0, 1.09, 2.48).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
gapLabel.style.left = `${x}px`;
gapLabel.style.top = `${y}px`;
gapLabel.textContent = `ROW GAP ${rig.gap.toFixed(2)}`;
}
function updateUI() {
const percent = Math.round(rig.currentPull * 100);
pullValue.textContent = `${percent}%`;
pullButton.textContent =
rig.targetPull > 0.95 ? "Release rig" : "Pull together";
}
// -------------------------------------------------------------------------
// Direct camera and handle controls
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragState = null;
function setPointerFromEvent(event) {
const rect = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(handlePickMeshes, false);
if (hits.length > 0) {
dragState = {
type: "pull",
startY: event.clientY,
startPull: rig.targetPull
};
} else {
dragState = {
type: "orbit",
lastX: event.clientX,
lastY: event.clientY
};
}
canvas.setPointerCapture(event.pointerId);
event.preventDefault();
});
canvas.addEventListener("pointermove", (event) => {
if (!dragState) return;
if (dragState.type === "pull") {
const delta =
(dragState.startY - event.clientY) / 220;
rig.targetPull = THREE.MathUtils.clamp(
dragState.startPull + delta,
0,
1
);
pullSlider.value = String(Math.round(rig.targetPull * 100));
} else {
const deltaX = event.clientX - dragState.lastX;
const deltaY = event.clientY - dragState.lastY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.28,
1.42
);
dragState.lastX = event.clientX;
dragState.lastY = event.clientY;
updateCamera();
}
event.preventDefault();
});
function endDrag(event) {
dragState = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.65
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.theta = 0.47;
cameraState.phi = 0.86;
cameraState.zoom = 1;
updateCamera();
});
pullSlider.addEventListener("input", () => {
rig.targetPull = Number(pullSlider.value) / 100;
});
pullButton.addEventListener("click", () => {
rig.targetPull = rig.targetPull > 0.95 ? 0 : 1;
pullSlider.value = String(Math.round(rig.targetPull * 100));
});
releaseButton.addEventListener("click", () => {
rig.targetPull = 0;
pullSlider.value = "0";
});
resetViewButton.addEventListener("click", () => {
cameraState.theta = 0.47;
cameraState.phi = 0.86;
cameraState.zoom = 1;
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
rig.targetPull = rig.targetPull > 0.95 ? 0 : 1;
pullSlider.value = String(Math.round(rig.targetPull * 100));
}
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-7 * delta);
rig.currentPull = THREE.MathUtils.lerp(
rig.currentPull,
rig.targetPull,
smoothing
);
updateRig();
updateUI();
updateGapLabel();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```