Prompt specification
Build or customize the Three.js 3D scene "Comfortable-fit design sandbox" 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: Comfortable-fit design sandbox
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/comfortable-fit-design-sandbox-x0584
Scene Description Prompt:
Adjust elastic regions on a low-poly garment around a body form, presenting expansion as a schematic demonstration. Standalone HTML with Three.js from cdnjs.
Working Three.js Starter (comfortable-fit-design-sandbox-x0584):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Elastic Expansion Study</title>
<style>
:root {
--ink: #18221f;
--muted: #66716c;
--line: #d9ded9;
--paper: #f3f5f1;
--panel: #fbfcf9;
--waist: #f06f5f;
--side: #30a99e;
--hem: #9b83cc;
}
* {
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;
}
button,
input {
font: inherit;
}
.app {
display: grid;
grid-template-columns: 350px 1fr;
width: 100%;
height: 100%;
}
.sidebar {
position: relative;
z-index: 10;
display: flex;
flex-direction: column;
min-height: 0;
padding: 28px 26px 22px;
overflow-y: auto;
background: var(--panel);
border-right: 1px solid var(--line);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 15px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
content: "";
background: var(--ink);
}
h1 {
max-width: 280px;
margin: 0;
font-size: clamp(28px, 3vw, 39px);
font-weight: 620;
letter-spacing: -0.045em;
line-height: 0.98;
}
.intro {
margin: 17px 0 25px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 12px;
color: var(--muted);
font-size: 10px;
font-weight: 760;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.section-title span:last-child {
color: #9ba39e;
font-weight: 550;
letter-spacing: 0.06em;
}
.controls {
display: grid;
gap: 9px;
}
.control {
--accent: var(--waist);
padding: 14px 15px 13px;
background: #fff;
border: 1px solid #e3e7e2;
border-radius: 12px;
box-shadow: 0 4px 16px rgba(35, 48, 42, 0.025);
}
.control-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.control-name {
display: flex;
align-items: center;
gap: 9px;
font-size: 13px;
font-weight: 680;
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--accent);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}
.control-sub {
margin-top: 4px;
color: #89928d;
font-size: 10px;
line-height: 1.3;
}
output {
min-width: 57px;
color: var(--accent);
font-size: 12px;
font-variant-numeric: tabular-nums;
font-weight: 750;
text-align: right;
}
input[type="range"] {
--fill: 0%;
display: block;
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border: 0;
border-radius: 999px;
outline: none;
background: linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--fill),
#dfe4df var(--fill),
#dfe4df 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid #fff;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 1px 5px rgba(25, 40, 32, 0.28);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #fff;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 1px 5px rgba(25, 40, 32, 0.28);
}
.settings {
display: grid;
gap: 2px;
margin-top: 23px;
padding: 15px 0;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.switch-row {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 38px;
gap: 14px;
color: #3d4944;
font-size: 12px;
cursor: pointer;
}
.switch {
position: relative;
width: 34px;
height: 19px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
}
.switch-track {
position: absolute;
inset: 0;
border-radius: 999px;
background: #d6dcd6;
transition: background 160ms ease;
}
.switch-track::after {
position: absolute;
top: 3px;
left: 3px;
width: 13px;
height: 13px;
content: "";
border-radius: 50%;
background: #fff;
box-shadow: 0 1px 4px rgba(24, 35, 30, 0.25);
transition: transform 160ms ease;
}
.switch input:checked + .switch-track {
background: #34463f;
}
.switch input:checked + .switch-track::after {
transform: translateX(15px);
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 18px;
}
.action {
min-height: 40px;
padding: 9px 10px;
border: 1px solid #d9dfd9;
border-radius: 9px;
background: #fff;
color: var(--ink);
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition:
transform 140ms ease,
background 140ms ease,
border-color 140ms ease;
}
.action:hover {
transform: translateY(-1px);
border-color: #bfc8c1;
}
.action.primary {
border-color: var(--ink);
background: var(--ink);
color: #fff;
}
.action.primary:hover {
background: #2c3934;
}
.note {
margin-top: auto;
padding-top: 22px;
color: #8b948f;
font-size: 10px;
line-height: 1.55;
}
.note strong {
color: #5c6862;
font-weight: 700;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e7ebe6;
}
.stage canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
.stage canvas:active {
cursor: grabbing;
}
.stage-top {
position: absolute;
z-index: 3;
top: 22px;
right: 22px;
left: 22px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
}
.live-badge,
.view-button {
border: 1px solid rgba(64, 78, 70, 0.15);
background: rgba(248, 250, 247, 0.78);
box-shadow: 0 6px 20px rgba(44, 58, 50, 0.05);
backdrop-filter: blur(8px);
}
.live-badge {
display: flex;
align-items: center;
gap: 8px;
min-height: 31px;
padding: 0 11px;
border-radius: 999px;
color: #53605a;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: #3db89d;
box-shadow: 0 0 0 3px rgba(61, 184, 157, 0.14);
}
.view-button {
min-height: 32px;
padding: 0 12px;
border-radius: 8px;
color: #4b5852;
font-size: 10px;
font-weight: 700;
cursor: pointer;
pointer-events: auto;
}
.view-button:hover {
background: rgba(255, 255, 255, 0.94);
}
.stage-bottom {
position: absolute;
z-index: 3;
right: 22px;
bottom: 20px;
left: 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
color: #64706a;
font-size: 10px;
pointer-events: none;
}
.gestures {
display: flex;
gap: 15px;
white-space: nowrap;
}
.gestures span {
display: flex;
align-items: center;
gap: 6px;
}
.gestures span::before {
width: 4px;
height: 4px;
content: "";
border-radius: 50%;
background: #8d9992;
}
.scale-note {
padding: 7px 10px;
border: 1px solid rgba(64, 78, 70, 0.12);
border-radius: 7px;
background: rgba(248, 250, 247, 0.68);
backdrop-filter: blur(7px);
white-space: nowrap;
}
.labels {
position: absolute;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.model-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid rgba(45, 57, 51, 0.13);
border-radius: 6px;
background: rgba(250, 252, 249, 0.88);
box-shadow: 0 5px 18px rgba(34, 48, 41, 0.08);
color: #4b5852;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
white-space: nowrap;
transform: translate(-50%, -50%);
backdrop-filter: blur(7px);
}
.model-label::before {
width: 6px;
height: 6px;
content: "";
border-radius: 2px;
background: var(--label-color);
}
.model-label strong {
color: var(--label-color);
font-variant-numeric: tabular-nums;
}
@media (max-width: 820px) {
.app {
grid-template-columns: 1fr;
grid-template-rows: minmax(330px, 43vh) 1fr;
}
.sidebar {
grid-row: 2;
padding: 20px;
border-top: 1px solid var(--line);
border-right: 0;
}
.stage {
grid-row: 1;
}
h1 {
max-width: none;
font-size: 28px;
}
.intro {
margin-bottom: 16px;
}
.controls {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.control {
padding: 12px;
}
.control-top {
display: block;
}
output {
display: block;
margin: 7px 0 0 18px;
text-align: left;
}
.stage-top {
top: 14px;
right: 14px;
left: 14px;
}
.stage-bottom {
right: 14px;
bottom: 12px;
left: 14px;
}
.scale-note {
display: none;
}
}
@media (max-width: 520px) {
.app {
grid-template-rows: minmax(300px, 38vh) 1fr;
}
.controls {
grid-template-columns: 1fr;
}
.control-top {
display: flex;
}
output {
margin: 0;
text-align: right;
}
.gestures {
gap: 9px;
font-size: 9px;
}
.live-badge {
font-size: 8px;
}
}
</style>
</head>
<body>
<main class="app">
<aside class="sidebar">
<div class="eyebrow">Garment Lab / Study 07</div>
<h1>Elastic expansion study</h1>
<p class="intro">
Expand the garment's elastic zones around a low-poly dress form.
Colored regions and vectors show the schematic deformation.
</p>
<div class="section-title">
<span>Elastic regions</span>
<span>03 adjustable zones</span>
</div>
<div class="controls">
<section class="control" style="--accent: var(--waist)">
<div class="control-top">
<div>
<div class="control-name">
<span class="swatch"></span>
Waistband
</div>
<div class="control-sub">Circumferential give</div>
</div>
<output id="waist-value">+0 mm</output>
</div>
<input
id="waist"
type="range"
min="0"
max="100"
value="0"
aria-label="Waistband expansion"
/>
</section>
<section class="control" style="--accent: var(--side)">
<div class="control-top">
<div>
<div class="control-name">
<span class="swatch"></span>
Side gussets
</div>
<div class="control-sub">Paired lateral panels</div>
</div>
<output id="side-value">+0 mm</output>
</div>
<input
id="side"
type="range"
min="0"
max="100"
value="0"
aria-label="Side gusset expansion"
/>
</section>
<section class="control" style="--accent: var(--hem)">
<div class="control-top">
<div>
<div class="control-name">
<span class="swatch"></span>
Hem band
</div>
<div class="control-sub">Lower edge recovery</div>
</div>
<output id="hem-value">+0 mm</output>
</div>
<input
id="hem"
type="range"
min="0"
max="100"
value="0"
aria-label="Hem band expansion"
/>
</section>
</div>
<div class="settings">
<label class="switch-row" for="baseline">
<span>Baseline contours</span>
<span class="switch">
<input id="baseline" type="checkbox" checked />
<span class="switch-track"></span>
</span>
</label>
<label class="switch-row" for="vectors">
<span>Expansion vectors</span>
<span class="switch">
<input id="vectors" type="checkbox" checked />
<span class="switch-track"></span>
</span>
</label>
</div>
<div class="actions">
<button class="action primary" id="active-stretch" type="button">
Active stretch
</button>
<button class="action" id="release" type="button">
Release to baseline
</button>
</div>
<div class="note">
<strong>Schematic mode.</strong> Dimensions indicate relative radial
offset and are not calibrated garment-fit measurements.
</div>
</aside>
<section class="stage" id="stage" aria-label="Interactive 3D garment study">
<div class="stage-top">
<div class="live-badge">
<span class="live-dot"></span>
<span id="active-status">Baseline garment</span>
</div>
<button class="view-button" id="reset-view" type="button">
Reset view
</button>
</div>
<div class="labels" aria-hidden="true">
<div class="model-label" id="label-waist" style="--label-color: var(--waist)">
WAIST <strong>+0 mm</strong>
</div>
<div class="model-label" id="label-side" style="--label-color: var(--side)">
GUSSET <strong>+0 mm</strong>
</div>
<div class="model-label" id="label-hem" style="--label-color: var(--hem)">
HEM <strong>+0 mm</strong>
</div>
</div>
<div class="stage-bottom">
<div class="gestures">
<span>Drag to orbit</span>
<span>Scroll to zoom</span>
<span>Shift-drag to pan</span>
</div>
<div class="scale-note">Radial offset / schematic units</div>
</div>
</section>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const baselineCheckbox = document.getElementById("baseline");
const vectorsCheckbox = document.getElementById("vectors");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
stage.insertBefore(renderer.domElement, stage.firstChild);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7ebe6);
scene.fog = new THREE.Fog(0xe7ebe6, 11, 23);
const camera = new THREE.PerspectiveCamera(
38,
stage.clientWidth / stage.clientHeight,
0.1,
50
);
const controls = {
target: new THREE.Vector3(0, 2.05, 0),
desired: {
theta: 0.55,
phi: 1.25,
radius: 7.2
},
current: {
theta: 0.55,
phi: 1.25,
radius: 7.2
}
};
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x9aa49d, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff7e9, 2.8);
keyLight.position.set(4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -4;
keyLight.shadow.camera.right = 4;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -2;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9e9ef, 1.05);
fillLight.position.set(-5, 3.5, -3);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xdfe4de,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.012;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(20, 40, 0xbfc7c0, 0xd0d6d0);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
const mannequinMaterial = new THREE.MeshStandardMaterial({
color: 0xd7cfc0,
roughness: 0.86,
metalness: 0,
flatShading: true
});
const standMaterial = new THREE.MeshStandardMaterial({
color: 0x69736e,
roughness: 0.58,
metalness: 0.34,
flatShading: true
});
const mannequin = new THREE.Group();
scene.add(mannequin);
const bodyProfile = [
new THREE.Vector2(0.46, 1.52),
new THREE.Vector2(0.51, 1.76),
new THREE.Vector2(0.43, 2.13),
new THREE.Vector2(0.49, 2.40),
new THREE.Vector2(0.61, 2.76),
new THREE.Vector2(0.65, 3.00),
new THREE.Vector2(0.58, 3.16),
new THREE.Vector2(0.33, 3.28),
new THREE.Vector2(0.16, 3.36)
];
const body = new THREE.Mesh(
new THREE.LatheGeometry(bodyProfile, 12),
mannequinMaterial
);
body.scale.z = 0.83;
body.castShadow = true;
body.receiveShadow = true;
mannequin.add(body);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.145, 0.16, 0.17, 10),
mannequinMaterial
);
neck.position.y = 3.43;
neck.castShadow = true;
mannequin.add(neck);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.052, 0.06, 1.55, 10),
standMaterial
);
pole.position.y = 0.89;
pole.castShadow = true;
mannequin.add(pole);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.77, 0.88, 0.14, 16),
standMaterial
);
base.position.y = 0.07;
base.castShadow = true;
base.receiveShadow = true;
mannequin.add(base);
const baseTop = new THREE.Mesh(
new THREE.CylinderGeometry(0.69, 0.69, 0.035, 16),
new THREE.MeshStandardMaterial({
color: 0x89928d,
roughness: 0.72,
metalness: 0.12,
flatShading: true
})
);
baseTop.position.y = 0.157;
baseTop.castShadow = true;
mannequin.add(baseTop);
const TAU = Math.PI * 2;
const SEGMENTS = 18;
const rings = [
{ y: 2.30, r: 0.49 },
{ y: 2.22, r: 0.54 },
{ y: 2.08, r: 0.60 },
{ y: 1.84, r: 0.72 },
{ y: 1.52, r: 0.88 },
{ y: 1.22, r: 1.00 },
{ y: 1.08, r: 1.04 },
{ y: 1.00, r: 1.06 }
];
const waistWeights = [1.0, 0.72, 0.28, 0.08, 0, 0, 0, 0];
const hemWeights = [0, 0, 0, 0, 0.03, 0.22, 0.72, 1.0];
const sideRowWeights = [0, 0, 1, 1, 1, 1, 0, 0];
function sideAngularWeight(theta) {
const distanceToSide = (angle) => {
const delta = Math.abs(Math.atan2(
Math.sin(angle - Math.PI / 2),
Math.cos(angle - Math.PI / 2)
));
return 1 - THREE.MathUtils.smoothstep(delta, 0.52, 0.78);
};
return Math.max(
distanceToSide(theta),
distanceToSide(theta + Math.PI)
);
}
const baseVertices = [];
const positions = [];
const indices = [];
for (let row = 0; row < rings.length; row++) {
for (let j = 0; j < SEGMENTS; j++) {
const theta = (j / SEGMENTS) * TAU;
const x = Math.sin(theta) * rings[row].r;
const z = Math.cos(theta) * rings[row].r;
baseVertices.push({
row,
theta,
x,
y: rings[row].y,
z,
r: rings[row].r
});
positions.push(x, rings[row].y, z);
}
}
const dressGeometry = new THREE.BufferGeometry();
dressGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
.setUsage(THREE.DynamicDrawUsage)
);
const groups = [];
for (let row = 0; row < rings.length - 1; row++) {
for (let j = 0; j < SEGMENTS; j++) {
const next = (j + 1) % SEGMENTS;
const a = row * SEGMENTS + j;
const b = row * SEGMENTS + next;
const c = (row + 1) * SEGMENTS + j;
const d = (row + 1) * SEGMENTS + next;
indices.push(a, c, b, b, c, d);
const centerAngle = ((j + 0.5) / SEGMENTS) * TAU;
const sideSegment =
j === 3 || j === 4 || j === 12 || j === 13;
let materialIndex = 0;
if (row <= 1) {
materialIndex = 1;
} else if (row >= 6) {
materialIndex = 3;
} else if (sideSegment) {
materialIndex = 2;
}
groups.push({
start: indices.length - 6,
count: 6,
materialIndex
});
}
}
dressGeometry.setIndex(indices);
for (const group of groups) {
dressGeometry.addGroup(
group.start,
group.count,
group.materialIndex
);
}
dressGeometry.computeVertexNormals();
const garmentMaterials = [
new THREE.MeshStandardMaterial({
color: 0x26364e,
roughness: 0.82,
metalness: 0.02,
flatShading: true,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0xf06f5f,
emissive: 0x4c1008,
emissiveIntensity: 0.12,
roughness: 0.68,
metalness: 0.01,
flatShading: true,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0x30a99e,
emissive: 0x073c37,
emissiveIntensity: 0.1,
roughness: 0.7,
metalness: 0.01,
flatShading: true,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0x9b83cc,
emissive: 0x21143d,
emissiveIntensity: 0.1,
roughness: 0.72,
metalness: 0.01,
flatShading: true,
side: THREE.DoubleSide
})
];
const dress = new THREE.Mesh(dressGeometry, garmentMaterials);
dress.castShadow = true;
dress.receiveShadow = true;
scene.add(dress);
const baselineGroup = new THREE.Group();
scene.add(baselineGroup);
const baselineMaterial = new THREE.LineDashedMaterial({
color: 0x68766e,
transparent: true,
opacity: 0.42,
dashSize: 0.055,
gapSize: 0.038,
depthTest: false
});
for (const rowIndex of [0, 3, 5, 7]) {
const ring = rings[rowIndex];
const points = [];
for (let j = 0; j <= SEGMENTS; j++) {
const theta = (j / SEGMENTS) * TAU;
points.push(
new THREE.Vector3(
Math.sin(theta) * ring.r,
ring.y,
Math.cos(theta) * ring.r
)
);
}
const contour = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
baselineMaterial
);
contour.computeLineDistances();
contour.renderOrder = 4;
baselineGroup.add(contour);
}
const state = {
target: { waist: 0, side: 0, hem: 0 },
current: { waist: 0, side: 0, hem: 0 },
maxMM: { waist: 180, side: 260, hem: 170 }
};
const sliders = {
waist: document.getElementById("waist"),
side: document.getElementById("side"),
hem: document.getElementById("hem")
};
const outputs = {
waist: document.getElementById("waist-value"),
side: document.getElementById("side-value"),
hem: document.getElementById("hem-value")
};
const labels = {
waist: document.getElementById("label-waist"),
side: document.getElementById("label-side"),
hem: document.getElementById("label-hem")
};
const activeStatus = document.getElementById("active-status");
const activeButton = document.getElementById("active-stretch");
const releaseButton = document.getElementById("release");
function setRangeFill(element) {
const percentage = Number(element.value);
element.style.setProperty("--fill", `${percentage}%`);
}
function updateOutput(key) {
outputs[key].textContent =
`+${Math.round(state.target[key] * state.maxMM[key])} mm`;
setRangeFill(sliders[key]);
}
function updateStatus() {
const activeCount = Object.values(state.target)
.filter((value) => value > 0.015).length;
activeStatus.textContent = activeCount
? `${activeCount} zone${activeCount === 1 ? "" : "s"} expanded`
: "Baseline garment";
}
function setPreset(values) {
for (const key of Object.keys(values)) {
state.target[key] = values[key];
sliders[key].value = String(Math.round(values[key] * 100));
updateOutput(key);
}
updateStatus();
}
for (const key of Object.keys(sliders)) {
sliders[key].addEventListener("input", () => {
state.target[key] = Number(sliders[key].value) / 100;
updateOutput(key);
updateStatus();
activeButton.removeAttribute("aria-pressed");
});
setRangeFill(sliders[key]);
}
activeButton.setAttribute("aria-pressed", "false");
activeButton.addEventListener("click", () => {
setPreset({ waist: 0.72, side: 0.88, hem: 0.58 });
activeButton.setAttribute("aria-pressed", "true");
});
releaseButton.addEventListener("click", () => {
setPreset({ waist: 0, side: 0, hem: 0 });
activeButton.removeAttribute("aria-pressed");
});
baselineCheckbox.addEventListener("change", () => {
baselineGroup.visible = baselineCheckbox.checked;
});
vectorsCheckbox.addEventListener("change", () => {
for (const label of Object.values(labels)) {
label.style.display = vectorsCheckbox.checked ? "flex" : "none";
}
});
function updateDress() {
const position = dressGeometry.attributes.position.array;
for (let i = 0; i < baseVertices.length; i++) {
const vertex = baseVertices[i];
const sideWeight =
sideRowWeights[vertex.row] *
sideAngularWeight(vertex.theta);
const radius =
vertex.r +
waistWeights[vertex.row] * 0.18 * state.current.waist +
sideWeight * 0.30 * state.current.side +
hemWeights[vertex.row] * 0.16 * state.current.hem;
position[i * 3] = Math.sin(vertex.theta) * radius;
position[i * 3 + 1] = vertex.y;
position[i * 3 + 2] = Math.cos(vertex.theta) * radius;
}
dressGeometry.attributes.position.needsUpdate = true;
dressGeometry.computeVertexNormals();
}
function baseRadiusAt(y) {
for (let i = 0; i < rings.length - 1; i++) {
const upper = rings[i];
const lower = rings[i + 1];
if (y <= upper.y && y >= lower.y) {
const t = (upper.y - y) / (upper.y - lower.y);
return THREE.MathUtils.lerp(upper.r, lower.r, t);
}
}
return y > rings[0].y ? rings[0].r : rings[rings.length - 1].r;
}
function makeArrow(color) {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(),
0.1,
color,
0.09,
0.055
);
arrow.line.material.depthTest = false;
arrow.cone.material.depthTest = false;
arrow.line.renderOrder = 8;
arrow.cone.renderOrder = 8;
arrow.visible = false;
scene.add(arrow);
return arrow;
}
const arrows = {
waist: makeArrow(0xf06f5f),
side: makeArrow(0x30a99e),
hem: makeArrow(0x9b83cc)
};
const arrowSpecs = {
waist: {
theta: 0.43,
y: 2.30,
amount: 0.18,
key: "waist"
},
side: {
theta: Math.PI / 2 - 0.08,
y: 1.52,
amount: 0.30,
key: "side"
},
hem: {
theta: -0.57,
y: 1.00,
amount: 0.16,
key: "hem"
}
};
function updateArrowsAndLabels() {
camera.updateMatrixWorld();
for (const [name, spec] of Object.entries(arrowSpecs)) {
const arrow = arrows[name];
const value = state.current[spec.key];
const length = spec.amount * value;
const visible = vectorsCheckbox.checked && value > 0.012;
arrow.visible = visible;
if (!visible) {
labels[name].style.display = "none";
continue;
}
const direction = new THREE.Vector3(
Math.sin(spec.theta),
0,
Math.cos(spec.theta)
).normalize();
const radius = baseRadiusAt(spec.y);
const origin = new THREE.Vector3(
direction.x * radius,
spec.y,
direction.z * radius
);
arrow.position.copy(origin);
arrow.setDirection(direction);
arrow.setLength(
Math.max(0.001, length),
Math.min(0.11, length * 0.3),
Math.min(0.07, length * 0.18)
);
const labelPoint = origin.clone().addScaledVector(direction, length + 0.13);
const projected = labelPoint.clone().project(camera);
const visibleInFrame =
projected.z > -1 && projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
labels[name].style.display = visibleInFrame ? "flex" : "none";
if (visibleInFrame) {
labels[name].style.left =
`${(projected.x * 0.5 + 0.5) * stage.clientWidth}px`;
labels[name].style.top =
`${(-projected.y * 0.5 + 0.5) * stage.clientHeight}px`;
labels[name].querySelector("strong").textContent =
`+${Math.round(value * state.maxMM[spec.key])} mm`;
}
}
}
function resetCamera() {
controls.target.set(0, 2.05, 0);
controls.desired.theta = 0.55;
controls.desired.phi = 1.25;
controls.desired.radius = 7.2;
}
document.getElementById("reset-view").addEventListener("click", resetCamera);
renderer.domElement.addEventListener("dblclick", resetCamera);
const pointer = {
active: false,
id: null,
x: 0,
y: 0,
pan: false
};
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.pan = event.button === 2 || event.shiftKey;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.pan) {
const right = new THREE.Vector3(1, 0, 0)
.applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0, 1, 0)
.applyQuaternion(camera.quaternion);
const scale = controls.current.radius * 0.0011;
controls.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
} else {
controls.desired.theta -= dx * 0.007;
controls.desired.phi = THREE.MathUtils.clamp(
controls.desired.phi + dy * 0.006,
0.48,
1.47
);
}
});
function endPointer(event) {
if (!pointer.active || event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desired.radius = THREE.MathUtils.clamp(
controls.desired.radius * Math.exp(event.deltaY * 0.001),
4.4,
11
);
},
{ passive: false }
);
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
const clock = new THREE.Clock();
const cameraOffset = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-dt * 7.5);
const cameraSmoothing = 1 - Math.exp(-dt * 9);
let garmentMoving = false;
for (const key of Object.keys(state.current)) {
const difference = state.target[key] - state.current[key];
if (Math.abs(difference) > 0.0001) {
state.current[key] += difference * smoothing;
garmentMoving = true;
} else {
state.current[key] = state.target[key];
}
}
if (garmentMoving) {
updateDress();
}
controls.current.theta +=
(controls.desired.theta - controls.current.theta) * cameraSmoothing;
controls.current.phi +=
(controls.desired.phi - controls.current.phi) * cameraSmoothing;
controls.current.radius +=
(controls.desired.radius - controls.current.radius) * cameraSmoothing;
cameraOffset.setFromSphericalCoords(
controls.current.radius,
controls.current.phi,
controls.current.theta
);
camera.position.copy(controls.target).add(cameraOffset);
camera.lookAt(controls.target);
updateArrowsAndLabels();
renderer.render(scene, camera);
}
updateDress();
animate();
</script>
</body>
</html>
```