Prompt specification
Build or customize the Three.js 3D scene "Strap length symmetry test" 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: Strap length symmetry test
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/strap-length-symmetry-test-x0626
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: strap length symmetry test. Adjust one suspender strap while the other stays fixed; show the waistband tilting, then restore equal lengths to return the garment to a level position.
Working Three.js Starter (strap-length-symmetry-test-x0626):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Strap Symmetry Test</title>
<style>
:root {
--ink: #18202a;
--muted: #707783;
--paper: #eeeae1;
--panel: rgba(23, 29, 37, 0.94);
--orange: #ff8a3d;
--teal: #51c5b8;
--line: rgba(255, 255, 255, 0.12);
}
* {
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 {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.brand {
position: fixed;
z-index: 5;
top: 25px;
left: 27px;
display: flex;
align-items: center;
gap: 13px;
pointer-events: none;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
place-items: center;
background: var(--ink);
border-radius: 9px;
box-shadow: 0 7px 22px rgba(30, 35, 40, 0.18);
}
.brand-mark::before {
content: "";
width: 15px;
height: 15px;
background:
linear-gradient(90deg, var(--orange) 0 48%, transparent 48% 100%),
linear-gradient(0deg, var(--teal) 0 48%, transparent 48% 100%);
transform: rotate(45deg);
}
.eyebrow {
margin-bottom: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: clamp(20px, 2vw, 28px);
line-height: 1;
letter-spacing: -0.04em;
}
.view-reset {
position: fixed;
z-index: 6;
top: 27px;
right: 27px;
padding: 9px 12px;
border: 1px solid rgba(24, 32, 42, 0.17);
border-radius: 8px;
background: rgba(255, 255, 255, 0.63);
color: #4f5864;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
cursor: pointer;
backdrop-filter: blur(8px);
}
.view-reset:hover {
background: rgba(255, 255, 255, 0.9);
color: var(--ink);
}
.scene-note {
position: fixed;
z-index: 4;
left: 29px;
bottom: 25px;
display: flex;
align-items: center;
gap: 9px;
color: #6f747c;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.04em;
pointer-events: none;
}
.scene-note::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(81, 197, 184, 0.13);
}
.panel {
position: fixed;
z-index: 10;
right: 24px;
bottom: 24px;
width: 362px;
padding: 20px;
color: #f7f7f4;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 16px;
box-shadow: 0 22px 65px rgba(21, 26, 33, 0.24);
backdrop-filter: blur(16px);
}
.panel-kicker {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
color: #8f99a5;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: #bfc7cf;
}
.live::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #63d2a1;
box-shadow: 0 0 0 4px rgba(99, 210, 161, 0.12);
}
.panel h2 {
margin: 0 0 7px;
font-size: 22px;
letter-spacing: -0.035em;
}
.description {
margin: 0 0 17px;
color: #9ca5af;
font-size: 12px;
line-height: 1.55;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 7px;
margin-bottom: 18px;
}
.metric {
min-width: 0;
padding: 11px 10px;
background: rgba(255, 255, 255, 0.055);
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 9px;
}
.metric-label {
display: block;
margin-bottom: 6px;
color: #87919c;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.metric-value {
display: block;
overflow: hidden;
color: #f6f7f8;
font-size: 16px;
font-weight: 760;
letter-spacing: -0.035em;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric-value.teal {
color: var(--teal);
}
.metric-value.orange {
color: var(--orange);
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: #c5ccd3;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.control-label strong {
color: var(--orange);
font-size: 11px;
letter-spacing: 0;
}
.range-wrap {
position: relative;
padding: 2px 0 0;
}
input[type="range"] {
--pct: 44.444%;
width: 100%;
height: 5px;
margin: 0;
border: 0;
border-radius: 10px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--orange) 0%,
var(--orange) var(--pct),
#46505b var(--pct),
#46505b 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #202832;
border-radius: 50%;
appearance: none;
background: var(--orange);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #202832;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3);
}
.range-scale {
position: relative;
height: 29px;
margin-top: 9px;
color: #747f8b;
font-size: 9px;
font-weight: 700;
}
.range-scale span {
position: absolute;
top: 0;
}
.range-scale .min {
left: 0;
}
.range-scale .max {
right: 0;
}
.equal-mark {
position: absolute;
top: -8px;
left: 44.444%;
transform: translateX(-50%);
color: #aeb7c1;
white-space: nowrap;
}
.equal-mark::before {
content: "";
position: absolute;
top: -8px;
left: 50%;
width: 1px;
height: 7px;
background: #707b87;
}
.status {
display: flex;
align-items: flex-start;
gap: 10px;
min-height: 44px;
margin: 0 0 16px;
padding: 10px 11px;
border: 1px solid rgba(99, 210, 161, 0.18);
border-radius: 9px;
background: rgba(99, 210, 161, 0.065);
}
.status-dot {
flex: 0 0 auto;
width: 8px;
height: 8px;
margin-top: 3px;
border-radius: 50%;
background: #63d2a1;
box-shadow: 0 0 0 4px rgba(99, 210, 161, 0.1);
}
.status-title {
margin-bottom: 3px;
color: #b9e8d6;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-detail {
color: #87948f;
font-size: 10px;
line-height: 1.4;
}
.status.asymmetric {
border-color: rgba(255, 138, 61, 0.22);
background: rgba(255, 138, 61, 0.07);
}
.status.asymmetric .status-dot {
background: var(--orange);
box-shadow: 0 0 0 4px rgba(255, 138, 61, 0.11);
}
.status.asymmetric .status-title {
color: #ffc29b;
}
.buttons {
display: grid;
grid-template-columns: 1.15fr 1fr;
gap: 8px;
}
button {
min-height: 39px;
padding: 0 11px;
border: 0;
border-radius: 8px;
font: inherit;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:disabled {
cursor: default;
opacity: 0.38;
}
.primary {
background: var(--orange);
color: #241a14;
box-shadow: 0 7px 20px rgba(255, 138, 61, 0.18);
}
.primary.running {
background: #ff9b59;
}
.secondary {
border: 1px solid rgba(255, 255, 255, 0.13);
background: rgba(255, 255, 255, 0.06);
color: #c7cdd4;
}
.tag {
position: fixed;
z-index: 3;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid rgba(24, 32, 42, 0.12);
border-radius: 7px;
background: rgba(255, 255, 255, 0.88);
color: #3d4650;
box-shadow: 0 6px 20px rgba(37, 43, 49, 0.1);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
backdrop-filter: blur(7px);
}
.tag i {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--teal);
}
.tag.adjustable i {
background: var(--orange);
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 16px;
}
.brand-mark {
width: 33px;
height: 33px;
}
.brand h1 {
font-size: 20px;
}
.view-reset,
.scene-note,
.tag {
display: none;
}
.panel {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 16px;
}
.description {
margin-bottom: 13px;
}
.metrics {
margin-bottom: 13px;
}
}
@media (max-height: 680px) and (min-width: 761px) {
.panel {
padding: 15px;
}
.description {
display: none;
}
.metrics {
margin-bottom: 12px;
}
.status {
margin-bottom: 11px;
}
}
</style>
</head>
<body>
<header class="brand">
<div class="brand-mark"></div>
<div>
<div class="eyebrow">Garment mechanics / rig 02</div>
<h1>Strap symmetry test</h1>
</div>
</header>
<button class="view-reset" id="resetView">RESET VIEW</button>
<div class="scene-note">Drag to orbit · Scroll to zoom</div>
<div class="tag" id="fixedTag"><i></i> FIXED · 295 MM</div>
<div class="tag adjustable" id="adjustableTag"><i></i> ADJUSTABLE</div>
<section class="panel" aria-label="Strap symmetry controls">
<div class="panel-kicker">
<span>Suspender balance</span>
<span class="live">Live rig</span>
</div>
<h2>Length asymmetry</h2>
<p class="description">
Lengthen one suspender while the opposite strap remains fixed. The garment
tilts until both lengths are restored.
</p>
<div class="metrics">
<div class="metric">
<span class="metric-label">Left strap</span>
<span class="metric-value teal">295 mm</span>
</div>
<div class="metric">
<span class="metric-label">Right strap</span>
<span class="metric-value orange" id="rightValue">295 mm</span>
</div>
<div class="metric">
<span class="metric-label">Waist tilt</span>
<span class="metric-value" id="tiltValue">0.0°</span>
</div>
</div>
<div class="control-label">
<span>Adjust right strap</span>
<strong id="rangeValue">295 mm</strong>
</div>
<div class="range-wrap">
<input
id="strapRange"
type="range"
min="235"
max="370"
step="1"
value="295"
aria-label="Adjustable right suspender length"
/>
<div class="range-scale">
<span class="min">235</span>
<span class="equal-mark">EQUAL · 295</span>
<span class="max">370</span>
</div>
</div>
<div class="status" id="statusBox" role="status" aria-live="polite">
<div class="status-dot"></div>
<div>
<div class="status-title" id="statusTitle">Symmetric — level</div>
<div class="status-detail" id="statusDetail">
Both straps are 295 mm. The waistband is level.
</div>
</div>
</div>
<div class="buttons">
<button class="primary" id="runTest">Run tilt test</button>
<button class="secondary" id="restoreSymmetry">Restore equal lengths</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";
const $ = (id) => document.getElementById(id);
const LEFT_LENGTH = 295;
const EQUAL_LENGTH = 295;
const MIN_LENGTH = 235;
const MAX_LENGTH = 370;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeeeae1);
scene.fog = new THREE.Fog(0xeeeae1, 11, 24);
const camera = new THREE.PerspectiveCamera(
36,
innerWidth / innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel garment with adjustable suspender straps"
);
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff8e9, 0x8c9aaa, 1.9);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3dc, 3.5);
keyLight.position.set(5.5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d9ff, 1.15);
fillLight.position.set(-6, 4, 5);
scene.add(fillLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = {
rail: new THREE.MeshStandardMaterial({
color: 0x222a31,
roughness: 0.7,
metalness: 0.28
}),
railEdge: new THREE.MeshStandardMaterial({
color: 0x39434c,
roughness: 0.65,
metalness: 0.25
}),
navy: new THREE.MeshStandardMaterial({
color: 0x354154,
roughness: 0.9
}),
navyLight: new THREE.MeshStandardMaterial({
color: 0x45536a,
roughness: 0.88
}),
navyDark: new THREE.MeshStandardMaterial({
color: 0x242e3d,
roughness: 0.94
}),
waist: new THREE.MeshStandardMaterial({
color: 0x202a38,
roughness: 0.85
}),
waistAlt: new THREE.MeshStandardMaterial({
color: 0x293545,
roughness: 0.86
}),
teal: new THREE.MeshStandardMaterial({
color: 0x51c5b8,
roughness: 0.72
}),
orange: new THREE.MeshStandardMaterial({
color: 0xff8a3d,
roughness: 0.72
}),
gold: new THREE.MeshStandardMaterial({
color: 0xf2c56b,
roughness: 0.58,
metalness: 0.2
}),
metal: new THREE.MeshStandardMaterial({
color: 0x98a2ab,
roughness: 0.52,
metalness: 0.55
}),
platform: new THREE.MeshStandardMaterial({
color: 0xddd7cb,
roughness: 0.95
})
};
function addBlock(parent, x, y, z, sx, sy, sz, material) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Floor and test platform.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0xeeeae1,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -3.06;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 48, 0xb8b1a4, 0xd1cbc0);
grid.position.y = -3.045;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
addBlock(
scene,
0,
-2.99,
0,
5.9,
0.12,
2.65,
materials.platform
);
// Voxel overhead test frame.
for (const side of [-1, 1]) {
addBlock(
scene,
side * 3.04,
0.72,
-0.58,
0.24,
7.58,
0.42,
materials.rail
);
addBlock(
scene,
side * 3.04,
-2.91,
-0.58,
0.9,
0.18,
1.12,
materials.railEdge
);
}
for (let i = -6; i <= 6; i++) {
addBlock(
scene,
i * 0.52,
4.53,
-0.48,
0.5,
0.28,
0.45,
i % 2 === 0 ? materials.rail : materials.railEdge
);
}
// Small measurement ticks on the right post.
for (let i = 0; i < 11; i++) {
addBlock(
scene,
3.19,
-2.4 + i * 0.58,
-0.35,
i % 2 === 0 ? 0.18 : 0.12,
0.035,
0.08,
materials.railEdge
);
}
const anchorLeft = new THREE.Vector3(-1.15, 4.15, 0.42);
const anchorRight = new THREE.Vector3(1.15, 4.15, 0.42);
for (const anchor of [anchorLeft, anchorRight]) {
addBlock(
scene,
anchor.x,
4.29,
-0.08,
0.28,
0.32,
0.28,
materials.railEdge
);
addBlock(
scene,
anchor.x,
anchor.y,
anchor.z,
0.22,
0.18,
0.22,
materials.gold
);
}
// Garment origin is the midpoint between the two waist attachments.
const garment = new THREE.Group();
scene.add(garment);
const attachmentHalfWidth = 1.55;
// Waistband.
for (let i = -7; i <= 7; i++) {
addBlock(
garment,
i * 0.27,
-0.14,
0,
0.255,
0.36,
0.72,
i % 2 === 0 ? materials.waist : materials.waistAlt
);
}
// Upper hip row.
for (let i = -6; i <= 6; i++) {
addBlock(
garment,
i * 0.29,
-0.46,
0,
0.275,
0.3,
0.69,
Math.abs(i) === 6 ? materials.navyDark : materials.navy
);
}
// Two block-built trouser legs.
for (let row = 0; row < 10; row++) {
const y = -0.72 - row * 0.29;
const leftColumns =
row >= 7
? [-1.38, -1.07, -0.76]
: [-1.5, -1.19, -0.88, -0.57];
const rightColumns = leftColumns.map((x) => -x);
leftColumns.forEach((x, column) => {
const panel =
row === 4 && column === 1
? materials.navyLight
: row > 7
? materials.navyDark
: materials.navy;
addBlock(
garment,
x,
y,
0,
0.285,
0.278,
0.66,
panel
);
});
rightColumns.forEach((x, column) => {
const panel =
row === 4 && column === 1
? materials.navyLight
: row > 7
? materials.navyDark
: materials.navy;
addBlock(
garment,
x,
y,
0,
0.285,
0.278,
0.66,
panel
);
});
}
// Voxel front pockets.
for (const side of [-1, 1]) {
addBlock(
garment,
side * 1.16,
-0.61,
0.355,
0.36,
0.22,
0.08,
materials.navyLight
);
addBlock(
garment,
side * 1.32,
-0.48,
0.355,
0.2,
0.2,
0.08,
materials.navyLight
);
}
// Center fly.
for (let i = 0; i < 4; i++) {
addBlock(
garment,
0,
-0.39 - i * 0.17,
0.355,
0.09,
0.13,
0.08,
materials.metal
);
}
// Belt loops.
for (const x of [-1.55, -0.55, 0.55, 1.55]) {
addBlock(
garment,
x,
-0.065,
0.385,
0.13,
0.32,
0.1,
x === -1.55
? materials.teal
: x === 1.55
? materials.orange
: materials.waistAlt
);
}
addBlock(
garment,
0,
-0.14,
0.415,
0.3,
0.24,
0.12,
materials.gold
);
// Waist attachment blocks.
addBlock(
garment,
-attachmentHalfWidth,
-0.015,
0.43,
0.27,
0.3,
0.16,
materials.teal
);
addBlock(
garment,
attachmentHalfWidth,
-0.015,
0.43,
0.27,
0.3,
0.16,
materials.orange
);
// Pooled rectangular voxels used for the two suspenders.
function createStrapPool(material) {
const pool = [];
for (let i = 0; i < 34; i++) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.visible = false;
scene.add(mesh);
pool.push(mesh);
}
return pool;
}
const leftStrap = createStrapPool(materials.teal);
const rightStrap = createStrapPool(materials.orange);
const rightAdjuster = new THREE.Mesh(unitBox, materials.gold);
rightAdjuster.castShadow = true;
scene.add(rightAdjuster);
function updateStrap(pool, start, end) {
const dx = end.x - start.x;
const dy = end.y - start.y;
const dz = end.z - start.z;
const length = Math.sqrt(dx * dx + dy * dy + dz * dz);
const count = Math.min(pool.length, Math.ceil(length / 0.125));
const segmentLength = length / count;
const angle = Math.atan2(dy, dx) - Math.PI / 2;
for (let i = 0; i < pool.length; i++) {
const mesh = pool[i];
mesh.visible = i < count;
if (!mesh.visible) continue;
const t = (i + 0.5) / count;
mesh.position.set(
THREE.MathUtils.lerp(start.x, end.x, t),
THREE.MathUtils.lerp(start.y, end.y, t),
THREE.MathUtils.lerp(start.z, end.z, t)
);
mesh.rotation.set(0, 0, angle);
mesh.scale.set(0.145, segmentLength * 1.08, 0.16);
}
return { length, angle };
}
/*
Solve the rigid-strap geometry.
The left strap is always 295 mm. The waist attachment points rotate
around their midpoint while preserving the fixed left strap length.
The right strap is then constrained to the requested length.
*/
function solveRig(rightMillimeters) {
const anchorX = 1.15;
const halfWidth = attachmentHalfWidth;
const anchorY = 4.15;
const fixedWorldLength = LEFT_LENGTH / 100;
const rightWorldLength = rightMillimeters / 100;
const targetDifference =
rightWorldLength * rightWorldLength -
fixedWorldLength * fixedWorldLength;
function lengthDifference(theta) {
const c = Math.cos(theta);
const s = Math.sin(theta);
const horizontal = anchorX - halfWidth * c;
const remaining = Math.max(
0.0001,
fixedWorldLength * fixedWorldLength - horizontal * horizontal
);
const q = halfWidth * s - Math.sqrt(remaining);
return 4 * halfWidth * q * s;
}
let low = -0.42;
let high = 0.42;
for (let i = 0; i < 48; i++) {
const mid = (low + high) * 0.5;
if (lengthDifference(mid) < targetDifference) {
high = mid;
} else {
low = mid;
}
}
const theta = (low + high) * 0.5;
const c = Math.cos(theta);
const s = Math.sin(theta);
const horizontal = anchorX - halfWidth * c;
const remaining = Math.max(
0.0001,
fixedWorldLength * fixedWorldLength - horizontal * horizontal
);
const q = halfWidth * s - Math.sqrt(remaining);
const midpointY = anchorY + q;
return {
theta,
midpointY,
leftEnd: new THREE.Vector3(
-halfWidth * c,
midpointY - halfWidth * s,
0.43
),
rightEnd: new THREE.Vector3(
halfWidth * c,
midpointY + halfWidth * s,
0.43
)
};
}
// A static reference line marks the equal-length waist datum.
const levelY = solveRig(EQUAL_LENGTH).midpointY;
const datumGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-2.5, levelY, -0.26),
new THREE.Vector3(2.5, levelY, -0.26)
]);
const datum = new THREE.Line(
datumGeometry,
new THREE.LineDashedMaterial({
color: 0x9b9488,
dashSize: 0.12,
gapSize: 0.1,
transparent: true,
opacity: 0.5
})
);
datum.computeLineDistances();
scene.add(datum);
// Direct camera controls; no external controls module is used.
const cameraTarget = new THREE.Vector3(0, 0.65, 0);
let cameraTheta = 0.57;
let cameraPhi = 1.22;
let cameraRadius = 11.4;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraTheta = 0.57;
cameraPhi = 1.22;
cameraRadius = 11.4;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.005,
0.68,
1.48
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
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();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
7.6,
16
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
$("resetView").addEventListener("click", resetCamera);
// Interaction state.
const range = $("strapRange");
let rightLength = EQUAL_LENGTH;
let rightTarget = EQUAL_LENGTH;
let demo = null;
let restoreTween = null;
const easeInOutCubic = (t) =>
t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
range.addEventListener("input", () => {
demo = null;
restoreTween = null;
rightTarget = Number(range.value);
});
function startDemo() {
restoreTween = null;
demo = {
phase: "extend",
elapsed: 0,
from: rightLength
};
rightTarget = 355;
}
$("runTest").addEventListener("click", startDemo);
$("restoreSymmetry").addEventListener("click", () => {
demo = null;
restoreTween = {
elapsed: 0,
from: rightLength,
duration: 0.85
};
rightTarget = EQUAL_LENGTH;
});
function updateDemo(dt) {
demo.elapsed += dt;
if (demo.phase === "extend") {
const p = Math.min(demo.elapsed / 1.1, 1);
rightLength = THREE.MathUtils.lerp(
demo.from,
355,
easeInOutCubic(p)
);
range.value = Math.round(rightLength);
if (p >= 1) {
demo.phase = "hold";
demo.elapsed = 0;
}
} else if (demo.phase === "hold") {
if (demo.elapsed >= 0.85) {
demo.phase = "restore";
demo.elapsed = 0;
demo.from = rightLength;
rightTarget = EQUAL_LENGTH;
}
} else if (demo.phase === "restore") {
const p = Math.min(demo.elapsed / 1.05, 1);
rightLength = THREE.MathUtils.lerp(
demo.from,
EQUAL_LENGTH,
easeInOutCubic(p)
);
range.value = Math.round(rightLength);
if (p >= 1) {
rightLength = EQUAL_LENGTH;
rightTarget = EQUAL_LENGTH;
range.value = EQUAL_LENGTH;
demo = null;
}
}
}
function updateRestore(dt) {
restoreTween.elapsed += dt;
const p = Math.min(
restoreTween.elapsed / restoreTween.duration,
1
);
rightLength = THREE.MathUtils.lerp(
restoreTween.from,
EQUAL_LENGTH,
easeInOutCubic(p)
);
range.value = Math.round(rightLength);
if (p >= 1) {
rightLength = EQUAL_LENGTH;
rightTarget = EQUAL_LENGTH;
range.value = EQUAL_LENGTH;
restoreTween = null;
}
}
function placeTag(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.left =
`${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top =
`${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
element.style.opacity = visible ? "1" : "0";
}
function updateInterface(rig) {
const difference = rightLength - EQUAL_LENGTH;
const tilt = (rig.theta * 180) / Math.PI;
$("rightValue").textContent = `${Math.round(rightLength)} mm`;
$("rangeValue").textContent = `${Math.round(rightTarget)} mm`;
$("tiltValue").textContent =
Math.abs(tilt) < 0.05
? "0.0°"
: `${Math.abs(tilt).toFixed(1)}° ${tilt < 0 ? "CW" : "CCW"}`;
const pct =
((rightTarget - MIN_LENGTH) / (MAX_LENGTH - MIN_LENGTH)) * 100;
range.style.setProperty("--pct", `${pct}%`);
const statusBox = $("statusBox");
const statusTitle = $("statusTitle");
const statusDetail = $("statusDetail");
if (Math.abs(difference) < 0.5) {
statusBox.classList.remove("asymmetric");
statusTitle.textContent = "Symmetric — level";
statusDetail.textContent =
"Both straps are 295 mm. The waistband is level.";
} else if (difference > 0) {
statusBox.classList.add("asymmetric");
statusTitle.textContent = "Asymmetric — right strap long";
statusDetail.textContent =
`+${Math.round(difference)} mm mismatch. The right waist drops and the band tilts.`;
} else {
statusBox.classList.add("asymmetric");
statusTitle.textContent = "Asymmetric — right strap short";
statusDetail.textContent =
`${Math.round(difference)} mm mismatch. The right waist rises and the band tilts.`;
}
$("runTest").textContent = demo
? "Test in progress"
: "Run tilt test";
$("runTest").classList.toggle("running", Boolean(demo));
$("restoreSymmetry").textContent = restoreTween
? "Restoring…"
: "Restore equal lengths";
$("restoreSymmetry").disabled =
Math.abs(difference) < 0.5 && !demo && !restoreTween;
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
let previousTime = performance.now();
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (demo) {
updateDemo(dt);
} else if (restoreTween) {
updateRestore(dt);
} else {
const smoothing = 1 - Math.exp(-14 * dt);
rightLength += (rightTarget - rightLength) * smoothing;
if (Math.abs(rightTarget - rightLength) < 0.01) {
rightLength = rightTarget;
}
}
const rig = solveRig(rightLength);
garment.position.set(0, rig.midpointY, 0);
garment.rotation.z = rig.theta;
updateStrap(leftStrap, anchorLeft, rig.leftEnd);
const rightStrapInfo = updateStrap(rightStrap, anchorRight, rig.rightEnd);
// Visible adjustment slider on the right suspender.
const adjusterT = 0.26;
rightAdjuster.position.set(
THREE.MathUtils.lerp(anchorRight.x, rig.rightEnd.x, adjusterT),
THREE.MathUtils.lerp(anchorRight.y, rig.rightEnd.y, adjusterT),
THREE.MathUtils.lerp(anchorRight.z, rig.rightEnd.z, adjusterT)
);
rightAdjuster.rotation.z = rightStrapInfo.angle;
rightAdjuster.scale.set(0.35, 0.14, 0.245);
updateCamera();
const leftTagPosition = anchorLeft.clone().lerp(rig.leftEnd, 0.53);
const rightTagPosition = anchorRight
.clone()
.lerp(rig.rightEnd, 0.53);
leftTagPosition.z += 0.32;
rightTagPosition.z += 0.32;
placeTag($("fixedTag"), leftTagPosition);
placeTag($("adjustableTag"), rightTagPosition);
updateInterface(rig);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```