Prompt specification
Build or customize the Three.js 3D scene "Clothing-size classroom display" 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: Clothing-size classroom display
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/clothing-size-classroom-display-x0583
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing elastic waistbands. Build a garment rack comparing fixed and elastic openings; adjustable body-form templates demonstrate which openings can expand while seams and nonelastic panels remain unchanged. Stylized solid forms.
Working Three.js Starter (clothing-size-classroom-display-x0583):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elastic Waistband Study</title>
<style>
:root {
--ink: #202525;
--muted: #68706d;
--paper: #f5f1e8;
--fixed: #d36f52;
--elastic: #258b80;
--seam: #e9b949;
--line: rgba(32, 37, 37, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7e2d8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport,
#viewport canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: 330px;
max-height: calc(100vh - 44px);
overflow: auto;
padding: 24px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 22px;
background: rgba(248, 245, 238, 0.91);
box-shadow:
0 22px 60px rgba(53, 50, 43, 0.16),
inset 0 0 0 1px rgba(32, 37, 37, 0.04);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
scrollbar-width: thin;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: #53605d;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 3px;
border-radius: 3px;
background: var(--elastic);
content: "";
}
h1 {
margin: 0;
font-size: clamp(28px, 3vw, 38px);
font-weight: 750;
letter-spacing: -0.045em;
line-height: 0.98;
}
.intro {
margin: 13px 0 21px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.control-section {
padding: 18px 0;
border-top: 1px solid var(--line);
}
.control-heading {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-bottom: 11px;
}
.control-heading label,
.control-heading strong {
font-size: 12px;
font-weight: 800;
letter-spacing: 0.035em;
text-transform: uppercase;
}
output {
color: var(--elastic);
font-size: 13px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 7px 0 12px;
appearance: none;
border-radius: 999px;
outline: none;
background: linear-gradient(
to right,
var(--elastic) 0%,
var(--elastic) var(--range-fill, 50%),
#d8d5cd var(--range-fill, 50%),
#d8d5cd 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
appearance: none;
border: 3px solid var(--paper);
border-radius: 50%;
background: var(--elastic);
box-shadow: 0 2px 7px rgba(32, 37, 37, 0.28);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid var(--paper);
border-radius: 50%;
background: var(--elastic);
box-shadow: 0 2px 7px rgba(32, 37, 37, 0.28);
}
.presets {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin-top: 5px;
}
button {
appearance: none;
border: 0;
font: inherit;
cursor: pointer;
}
.preset {
padding: 8px 4px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.55);
color: #59615f;
font-size: 11px;
font-weight: 750;
transition:
background 150ms ease,
color 150ms ease,
transform 150ms ease;
}
.preset:hover,
.preset.active {
background: var(--ink);
color: white;
transform: translateY(-1px);
}
.small-note {
margin: 9px 0 0;
color: #7b817e;
font-size: 11px;
line-height: 1.45;
}
.toggle {
display: flex;
align-items: center;
gap: 10px;
margin-top: 13px;
color: #4f5856;
font-size: 12px;
font-weight: 650;
cursor: pointer;
}
.toggle input {
width: 17px;
height: 17px;
accent-color: var(--elastic);
}
.legend {
display: grid;
gap: 10px;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
color: #535c59;
font-size: 12px;
}
.swatch {
width: 14px;
height: 14px;
flex: 0 0 auto;
border-radius: 4px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.09);
}
.swatch.fixed {
background: var(--fixed);
}
.swatch.elastic {
background: var(--elastic);
}
.swatch.form {
border-radius: 50%;
background: #dfcba7;
}
.swatch.seam {
height: 4px;
border-radius: 999px;
background: var(--seam);
}
.locked-note {
margin-top: 15px;
padding: 11px 12px;
border-radius: 12px;
background: rgba(233, 185, 73, 0.13);
color: #675429;
font-size: 11px;
line-height: 1.5;
}
.viewbar {
position: fixed;
z-index: 11;
top: 22px;
right: 22px;
display: flex;
gap: 5px;
padding: 5px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 14px;
background: rgba(248, 245, 238, 0.86);
box-shadow: 0 10px 30px rgba(53, 50, 43, 0.1);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.viewbar button {
padding: 9px 12px;
border-radius: 10px;
background: transparent;
color: #68706d;
font-size: 11px;
font-weight: 750;
}
.viewbar button:hover,
.viewbar button.active {
background: var(--ink);
color: white;
}
.world-label {
position: fixed;
z-index: 6;
width: 202px;
padding: 13px 14px 12px;
border: 1px solid rgba(255, 255, 255, 0.76);
border-left-width: 4px;
border-radius: 14px;
background: rgba(250, 248, 242, 0.9);
box-shadow: 0 12px 30px rgba(45, 43, 38, 0.14);
pointer-events: none;
transform: translate(-50%, -100%);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.world-label.fixed {
border-left-color: var(--fixed);
}
.world-label.elastic {
border-left-color: var(--elastic);
}
.world-label .label-title {
display: flex;
justify-content: space-between;
align-items: center;
gap: 8px;
margin-bottom: 9px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.world-label .label-title span:last-child {
color: #9a9c95;
font-size: 9px;
letter-spacing: 0.07em;
}
.metric {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-top: 5px;
}
.metric span {
color: #767d79;
font-size: 10px;
}
.metric strong {
color: #2b3230;
font-size: 14px;
font-variant-numeric: tabular-nums;
}
.status {
display: inline-block;
margin-top: 9px;
padding: 4px 7px;
border-radius: 999px;
background: rgba(37, 139, 128, 0.1);
color: #28796f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.025em;
}
.status.warning {
background: rgba(211, 111, 82, 0.13);
color: #ad5139;
}
.hint {
position: fixed;
z-index: 8;
bottom: 22px;
left: 50%;
padding: 10px 14px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 999px;
background: rgba(248, 245, 238, 0.78);
color: #69706d;
font-size: 11px;
font-weight: 650;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
@media (max-width: 760px) {
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 44vh;
padding: 17px;
border-radius: 18px;
}
.intro {
margin-bottom: 14px;
}
.viewbar {
top: 12px;
right: 12px;
}
.viewbar button {
padding: 8px 9px;
font-size: 10px;
}
.world-label,
.hint {
display: none !important;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<aside class="panel">
<div class="eyebrow">Garment mechanics / 01</div>
<h1>Elastic<br>waistbands</h1>
<p class="intro">
The same adjustable body form drives both samples. Watch the openings
respond while the lower seam and solid nonelastic panels stay fixed.
</p>
<section class="control-section">
<div class="control-heading">
<label for="waistSize">Body-form template</label>
<output id="waistSizeValue" for="waistSize">78 cm</output>
</div>
<input
id="waistSize"
type="range"
min="66"
max="108"
step="1"
value="78"
aria-label="Adjustable body form waist size"
>
<div class="presets" aria-label="Body form presets">
<button class="preset" data-size="66">XS</button>
<button class="preset active" data-size="78">S</button>
<button class="preset" data-size="90">M</button>
<button class="preset" data-size="102">L</button>
</div>
<p class="small-note">
One template is applied to both forms, making the opening behavior
directly comparable.
</p>
</section>
<section class="control-section">
<div class="control-heading">
<label for="elasticResponse">Elastic response</label>
<output id="elasticResponseValue" for="elasticResponse">100%</output>
</div>
<input
id="elasticResponse"
type="range"
min="0"
max="100"
step="1"
value="100"
aria-label="Elastic waistband response"
>
<p class="small-note">
Reduce the response to show how little the opening can adapt while
the construction seam remains locked.
</p>
</section>
<section class="control-section">
<label class="toggle">
<input id="constructionToggle" type="checkbox" checked>
Show construction seams and guides
</label>
<div class="legend" style="margin-top: 17px">
<div class="legend-row">
<span class="swatch fixed"></span>
<span>Fixed opening</span>
</div>
<div class="legend-row">
<span class="swatch elastic"></span>
<span>Elastic opening</span>
</div>
<div class="legend-row">
<span class="swatch form"></span>
<span>Adjustable body-form template</span>
</div>
<div class="legend-row">
<span class="swatch seam"></span>
<span>Locked seam / unchanged construction</span>
</div>
</div>
<div class="locked-note">
Gold rings mark construction seams. The vertical seams, lower panels,
and hem do not resize.
</div>
</section>
</aside>
<nav class="viewbar" aria-label="Camera views">
<button data-view="studio" class="active">Studio</button>
<button data-view="front">Front</button>
<button data-view="detail">Waist detail</button>
</nav>
<div id="fixedLabel" class="world-label fixed">
<div class="label-title">
<span>Fixed opening</span>
<span>Constrained</span>
</div>
<div class="metric">
<span>Opening</span>
<strong id="fixedOpeningValue">83 cm</strong>
</div>
<div class="metric">
<span>Lower panel</span>
<strong>Unchanged</strong>
</div>
<span id="fixedStatus" class="status">Fits · opening unchanged</span>
</div>
<div id="elasticLabel" class="world-label elastic">
<div class="label-title">
<span>Elastic opening</span>
<span>Adaptive</span>
</div>
<div class="metric">
<span>Opening</span>
<strong id="elasticOpeningValue">83 cm</strong>
</div>
<div class="metric">
<span>Lower panel</span>
<strong>Unchanged</strong>
</div>
<span id="elasticStatus" class="status">Tracks the form</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.06;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7e2d8);
scene.fog = new THREE.Fog(0xe7e2d8, 14, 28);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const controls = {
azimuth: 0.46,
targetAzimuth: 0.46,
polar: 1.12,
targetPolar: 1.12,
radius: 10.9,
targetRadius: 10.9,
target: new THREE.Vector3(0, 2.45, 0),
lookTarget: new THREE.Vector3(0, 2.45, 0)
};
const hemi = new THREE.HemisphereLight(0xfffbf1, 0x777267, 2.05);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff1dc, 3.2);
key.position.set(4.5, 9, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -8;
key.shadow.camera.right = 8;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -2;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 25;
key.shadow.bias = -0.0002;
scene.add(key);
const fill = new THREE.DirectionalLight(0xcde8e2, 1.25);
fill.position.set(-6, 5, 4);
scene.add(fill);
const rimLight = new THREE.DirectionalLight(0xffd7b9, 1.4);
rimLight.position.set(1, 5, -6);
scene.add(rimLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xd8d2c6,
roughness: 0.93,
metalness: 0
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const rug = new THREE.Mesh(
new THREE.CylinderGeometry(5.3, 5.3, 0.035, 96),
new THREE.MeshStandardMaterial({
color: 0xcac3b8,
roughness: 1
})
);
rug.position.y = 0.002;
rug.receiveShadow = true;
scene.add(rug);
const materials = {
rack: new THREE.MeshStandardMaterial({
color: 0x29302f,
roughness: 0.34,
metalness: 0.72
}),
rackFoot: new THREE.MeshStandardMaterial({
color: 0x414847,
roughness: 0.58,
metalness: 0.48
}),
body: new THREE.MeshStandardMaterial({
color: 0xe3d0ad,
roughness: 0.76,
metalness: 0
}),
bodyEdge: new THREE.MeshStandardMaterial({
color: 0xc9b58f,
roughness: 0.8
}),
hanger: new THREE.MeshStandardMaterial({
color: 0xc9c5ba,
roughness: 0.33,
metalness: 0.65
}),
fixedBand: new THREE.MeshStandardMaterial({
color: 0xd36f52,
roughness: 0.82,
side: THREE.DoubleSide
}),
fixedRim: new THREE.MeshStandardMaterial({
color: 0xe58a6d,
roughness: 0.66,
side: THREE.DoubleSide
}),
fixedPanelA: new THREE.MeshStandardMaterial({
color: 0xc76148,
roughness: 0.92,
side: THREE.DoubleSide
}),
fixedPanelB: new THREE.MeshStandardMaterial({
color: 0xb95843,
roughness: 0.94,
side: THREE.DoubleSide
}),
fixedPanelC: new THREE.MeshStandardMaterial({
color: 0xce6b50,
roughness: 0.94,
side: THREE.DoubleSide
}),
elasticBand: new THREE.MeshStandardMaterial({
color: 0x258b80,
roughness: 0.8,
side: THREE.DoubleSide
}),
elasticRim: new THREE.MeshStandardMaterial({
color: 0x43aa9d,
roughness: 0.65,
side: THREE.DoubleSide
}),
elasticRib: new THREE.MeshStandardMaterial({
color: 0x19776e,
roughness: 0.9
}),
elasticPanelA: new THREE.MeshStandardMaterial({
color: 0x2b8e83,
roughness: 0.9,
side: THREE.DoubleSide
}),
elasticPanelB: new THREE.MeshStandardMaterial({
color: 0x237c73,
roughness: 0.93,
side: THREE.DoubleSide
}),
elasticPanelC: new THREE.MeshStandardMaterial({
color: 0x31978b,
roughness: 0.92,
side: THREE.DoubleSide
}),
seam: new THREE.MeshStandardMaterial({
color: 0xe9b949,
roughness: 0.67,
side: THREE.DoubleSide
}),
guide: new THREE.MeshStandardMaterial({
color: 0xb99864,
roughness: 0.8,
side: THREE.DoubleSide
}),
tension: new THREE.MeshStandardMaterial({
color: 0xffc857,
emissive: 0x6b3100,
emissiveIntensity: 0.12,
roughness: 0.5
})
};
function cylinderBetween(a, b, radius, material, radialSegments = 16) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeTube(points, radius, material, closed = false, segments = 40) {
const curve = new THREE.CatmullRomCurve3(
points,
closed,
"catmullrom",
0.5
);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, 8, closed),
material
);
mesh.castShadow = true;
return mesh;
}
function createEllipseTubeGeometry(
rx,
rz,
tubeRadius,
majorSegments = 72,
minorSegments = 10
) {
const geometry = new THREE.BufferGeometry();
const positions = [];
for (let i = 0; i <= majorSegments; i++) {
const u = (i / majorSegments) * Math.PI * 2;
const cosU = Math.cos(u);
const sinU = Math.sin(u);
const nx = cosU / rx;
const nz = sinU / rz;
const normalLength = Math.hypot(nx, nz);
const outwardX = nx / normalLength;
const outwardZ = nz / normalLength;
for (let j = 0; j <= minorSegments; j++) {
const v = (j / minorSegments) * Math.PI * 2;
const radial = Math.cos(v) * tubeRadius;
const vertical = Math.sin(v) * tubeRadius;
positions.push(
rx * cosU + outwardX * radial,
vertical,
rz * sinU + outwardZ * radial
);
}
}
const indices = [];
const row = minorSegments + 1;
for (let i = 0; i < majorSegments; i++) {
for (let j = 0; j < minorSegments; j++) {
const a = i * row + j;
const b = (i + 1) * row + j;
const c = (i + 1) * row + j + 1;
const d = i * row + j + 1;
indices.push(a, d, b, b, d, c);
}
}
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.userData.majorSegments = majorSegments;
geometry.userData.minorSegments = minorSegments;
return geometry;
}
function updateEllipseTube(
geometry,
rx,
rz,
tubeRadius
) {
const position = geometry.attributes.position;
const majorSegments = geometry.userData.majorSegments;
const minorSegments = geometry.userData.minorSegments;
let index = 0;
for (let i = 0; i <= majorSegments; i++) {
const u = (i / majorSegments) * Math.PI * 2;
const cosU = Math.cos(u);
const sinU = Math.sin(u);
const nx = cosU / rx;
const nz = sinU / rz;
const normalLength = Math.hypot(nx, nz);
const outwardX = nx / normalLength;
const outwardZ = nz / normalLength;
for (let j = 0; j <= minorSegments; j++) {
const v = (j / minorSegments) * Math.PI * 2;
const radial = Math.cos(v) * tubeRadius;
const vertical = Math.sin(v) * tubeRadius;
position.setXYZ(
index++,
rx * cosU + outwardX * radial,
vertical,
rz * sinU + outwardZ * radial
);
}
}
position.needsUpdate = true;
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
}
function createBandGeometry(
bottomRx,
bottomRz,
topRx,
topRz,
bottomY,
topY,
segments = 72,
rows = 5
) {
const geometry = new THREE.BufferGeometry();
const positions = [];
const indices = [];
for (let row = 0; row <= rows; row++) {
const t = row / rows;
const y = THREE.MathUtils.lerp(bottomY, topY, t);
const rx = THREE.MathUtils.lerp(bottomRx, topRx, t);
const rz = THREE.MathUtils.lerp(bottomRz, topRz, t);
for (let i = 0; i <= segments; i++) {
const theta = (i / segments) * Math.PI * 2;
positions.push(
rx * Math.cos(theta),
y,
rz * Math.sin(theta)
);
}
}
const rowSize = segments + 1;
for (let row = 0; row < rows; row++) {
for (let i = 0; i < segments; i++) {
const a = row * rowSize + i;
const b = row * rowSize + i + 1;
const c = (row + 1) * rowSize + i + 1;
const d = (row + 1) * rowSize + i;
indices.push(a, d, b, b, d, c);
}
}
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.userData = {
bottomRx,
bottomRz,
topRx,
topRz,
bottomY,
topY,
segments,
rows
};
return geometry;
}
function updateBandGeometry(
geometry,
bottomRx,
bottomRz,
topRx,
topRz
) {
const data = geometry.userData;
const position = geometry.attributes.position;
let index = 0;
for (let row = 0; row <= data.rows; row++) {
const t = row / data.rows;
const y = THREE.MathUtils.lerp(data.bottomY, data.topY, t);
const rx = THREE.MathUtils.lerp(bottomRx, topRx, t);
const rz = THREE.MathUtils.lerp(bottomRz, topRz, t);
for (let i = 0; i <= data.segments; i++) {
const theta = (i / data.segments) * Math.PI * 2;
position.setXYZ(
index++,
rx * Math.cos(theta),
y,
rz * Math.sin(theta)
);
}
}
position.needsUpdate = true;
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
}
function createSegmentShell(
topRx,
topRz,
bottomRx,
bottomRz,
topY,
bottomY,
startAngle,
endAngle,
material,
segments = 32
) {
const geometry = new THREE.BufferGeometry();
const positions = [];
const indices = [];
const rows = 5;
const rowSize = segments + 1;
for (let row = 0; row <= rows; row++) {
const t = row / rows;
const y = THREE.MathUtils.lerp(topY, bottomY, t);
const rx = THREE.MathUtils.lerp(topRx, bottomRx, t);
const rz = THREE.MathUtils.lerp(topRz, bottomRz, t);
for (let i = 0; i <= segments; i++) {
const theta = THREE.MathUtils.lerp(
startAngle,
endAngle,
i / segments
);
positions.push(
rx * Math.cos(theta),
y,
rz * Math.sin(theta)
);
}
}
for (let row = 0; row < rows; row++) {
for (let i = 0; i < segments; i++) {
const a = row * rowSize + i;
const b = row * rowSize + i + 1;
const c = (row + 1) * rowSize + i + 1;
const d = (row + 1) * rowSize + i;
indices.push(a, d, b, b, d, c);
}
}
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function createVerticalSeam(angle, material, radius = 0.014) {
const points = [];
for (let i = 0; i <= 6; i++) {
const t = i / 6;
const y = THREE.MathUtils.lerp(1.82, 0.96, t);
const rx = THREE.MathUtils.lerp(0.54, 0.68, t) + 0.012;
const rz = THREE.MathUtils.lerp(0.375, 0.455, t) + 0.012;
points.push(
new THREE.Vector3(
rx * Math.cos(angle),
y,
rz * Math.sin(angle)
)
);
}
return makeTube(points, radius, material, false, 24);
}
function buildRack() {
const rack = new THREE.Group();
const leftBottom = new THREE.Vector3(-4.45, 0.18, 0);
const leftTop = new THREE.Vector3(-4.62, 4.65, 0);
const rightBottom = new THREE.Vector3(4.45, 0.18, 0);
const rightTop = new THREE.Vector3(4.62, 4.65, 0);
rack.add(
cylinderBetween(leftBottom, leftTop, 0.075, materials.rack, 20),
cylinderBetween(rightBottom, rightTop, 0.075, materials.rack, 20),
cylinderBetween(
new THREE.Vector3(-4.62, 4.65, 0),
new THREE.Vector3(4.62, 4.65, 0),
0.08,
materials.rack,
24
),
cylinderBetween(
new THREE.Vector3(-4.45, 0.48, 0),
new THREE.Vector3(4.45, 0.48, 0),
0.052,
materials.rack,
18
)
);
for (const x of [-4.45, 4.45]) {
rack.add(
cylinderBetween(
new THREE.Vector3(x, 0.13, -0.78),
new THREE.Vector3(x, 0.13, 0.78),
0.07,
materials.rackFoot,
20
)
);
const cap = new THREE.Mesh(
new THREE.SphereGeometry(0.095, 18, 12),
materials.rackFoot
);
cap.position.set(x, 0.13, 0.78);
cap.castShadow = true;
rack.add(cap);
}
for (const x of [-4.62, 4.62]) {
const cap = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 18, 12),
materials.rackFoot
);
cap.position.set(x, 4.65, 0);
cap.castShadow = true;
rack.add(cap);
}
scene.add(rack);
}
function buildHanger(x) {
const hanger = new THREE.Group();
const z = 0.38;
hanger.add(
cylinderBetween(
new THREE.Vector3(x, 4.2, z),
new THREE.Vector3(x - 0.66, 3.48, z),
0.028,
materials.hanger,
12
),
cylinderBetween(
new THREE.Vector3(x, 4.2, z),
new THREE.Vector3(x + 0.66, 3.48, z),
0.028,
materials.hanger,
12
),
cylinderBetween(
new THREE.Vector3(x - 0.66, 3.48, z),
new THREE.Vector3(x + 0.66, 3.48, z),
0.028,
materials.hanger,
12
)
);
const hook = makeTube(
[
new THREE.Vector3(x, 4.17, z),
new THREE.Vector3(x, 4.42, z),
new THREE.Vector3(x, 4.62, z),
new THREE.Vector3(x + 0.1, 4.72, z),
new THREE.Vector3(x + 0.2, 4.65, z),
new THREE.Vector3(x + 0.18, 4.49, z),
new THREE.Vector3(x + 0.06, 4.42, z)
],
0.026,
materials.hanger,
false,
42
);
hanger.add(hook);
scene.add(hanger);
}
function buildBodyForm() {
const group = new THREE.Group();
const profile = [
new THREE.Vector2(0.5, 2.08),
new THREE.Vector2(0.5, 2.18),
new THREE.Vector2(0.56, 2.42),
new THREE.Vector2(0.68, 2.83),
new THREE.Vector2(0.76, 3.12),
new THREE.Vector2(0.69, 3.36),
new THREE.Vector2(0.43, 3.47),
new THREE.Vector2(0.27, 3.58),
new THREE.Vector2(0.24, 3.79)
];
const torso = new THREE.Mesh(
new THREE.LatheGeometry(profile, 64),
materials.body
);
torso.scale.z = 0.68;
torso.castShadow = true;
torso.receiveShadow = true;
group.add(torso);
const neckCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.24, 0.27, 0.09, 32),
materials.bodyEdge
);
neckCap.position.y = 3.82;
neckCap.scale.z = 0.68;
neckCap.castShadow = true;
group.add(neckCap);
const guide = new THREE.Mesh(
createEllipseTubeGeometry(0.5, 0.5, 0.012, 64, 8),
materials.guide
);
guide.position.y = 2.13;
guide.scale.z = 0.68;
group.add(guide);
group.userData.guide = guide;
return group;
}
function buildGarment(kind, x) {
const group = new THREE.Group();
group.position.set(x, 0, 0.25);
const isFixed = kind === "fixed";
const baseRx = 0.53;
const baseRz = 0.36;
const bottomY = 1.84;
const topY = 2.08;
const body = buildBodyForm();
group.add(body);
const bandMaterial = isFixed
? materials.fixedBand
: materials.elasticBand;
const rimMaterial = isFixed
? materials.fixedRim
: materials.elasticRim;
const band = new THREE.Mesh(
createBandGeometry(
baseRx,
baseRz,
baseRx,
baseRz,
bottomY,
topY
),
bandMaterial
);
band.castShadow = true;
band.receiveShadow = true;
group.add(band);
const rim = new THREE.Mesh(
createEllipseTubeGeometry(baseRx, baseRz, 0.037, 72, 10),
rimMaterial
);
rim.position.y = topY;
rim.castShadow = true;
group.add(rim);
const panelA = isFixed
? materials.fixedPanelA
: materials.elasticPanelA;
const panelB = isFixed
? materials.fixedPanelB
: materials.elasticPanelB;
const panelC = isFixed
? materials.fixedPanelC
: materials.elasticPanelC;
const panelGroup = new THREE.Group();
panelGroup.add(
createSegmentShell(
0.54,
0.375,
0.68,
0.455,
bottomY + 0.015,
0.94,
0.04,
Math.PI / 2 - 0.025,
panelA,
32
),
createSegmentShell(
0.54,
0.375,
0.68,
0.455,
bottomY + 0.015,
0.94,
Math.PI / 2 + 0.025,
Math.PI - 0.04,
panelB,
32
),
createSegmentShell(
0.54,
0.375,
0.68,
0.455,
bottomY + 0.015,
0.94,
Math.PI + 0.04,
Math.PI * 2 - 0.04,
panelC,
40
)
);
group.add(panelGroup);
const construction = new THREE.Group();
const lowerSeam = new THREE.Mesh(
createEllipseTubeGeometry(0.54, 0.375, 0.022, 72, 9),
materials.seam
);
lowerSeam.position.y = bottomY + 0.004;
construction.add(lowerSeam);
const hem = new THREE.Mesh(
createEllipseTubeGeometry(0.68, 0.455, 0.018, 72, 9),
isFixed ? materials.fixedPanelB : materials.elasticPanelB
);
hem.position.y = 0.94;
construction.add(hem);
construction.add(
createVerticalSeam(0, materials.seam, 0.012),
createVerticalSeam(Math.PI / 2, materials.seam, 0.013),
createVerticalSeam(Math.PI, materials.seam, 0.012)
);
group.add(construction);
const ribs = new THREE.Group();
const ribMeshes = [];
if (!isFixed) {
for (let i = 0; i < 36; i++) {
const rib = new THREE.Mesh(
new THREE.BoxGeometry(0.022, 0.175, 0.032),
materials.elasticRib
);
rib.castShadow = true;
ribs.add(rib);
ribMeshes.push(rib);
}
}
group.add(ribs);
const tensionGroup = new THREE.Group();
if (isFixed) {
for (let i = 0; i < 7; i++) {
const theta = 0.35 + (i / 6) * (Math.PI - 0.7);
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.047, 14, 10),
materials.tension
);
marker.position.set(
baseRx * Math.cos(theta),
topY + 0.018,
baseRz * Math.sin(theta)
);
marker.castShadow = true;
tensionGroup.add(marker);
}
}
group.add(tensionGroup);
return {
kind,
group,
body,
band,
rim,
construction,
ribs,
ribMeshes,
tensionGroup,
baseRx,
baseRz,
bottomY,
topY
};
}
buildRack();
buildHanger(-2.15);
buildHanger(2.15);
const fixedGarment = buildGarment("fixed", -2.15);
const elasticGarment = buildGarment("elastic", 2.15);
scene.add(fixedGarment.group);
scene.add(elasticGarment.group);
const BODY_RX = 0.5;
const BODY_RZ = BODY_RX * 0.68;
const REFERENCE_WAIST = 78;
function ellipsePerimeter(a, b) {
const h = ((a - b) * (a - b)) / ((a + b) * (a + b));
return (
Math.PI *
(a + b) *
(1 + (3 * h) / (Math.sqrt(3 * h + 1) + 1))
);
}
const unitsToCm =
REFERENCE_WAIST / ellipsePerimeter(BODY_RX, BODY_RZ);
function openingCm(rx, rz) {
return ellipsePerimeter(rx, rz) * unitsToCm;
}
const waistSlider = document.getElementById("waistSize");
const waistOutput = document.getElementById("waistSizeValue");
const responseSlider = document.getElementById("elasticResponse");
const responseOutput = document.getElementById("elasticResponseValue");
const constructionToggle = document.getElementById("constructionToggle");
const fixedOpeningValue = document.getElementById("fixedOpeningValue");
const elasticOpeningValue = document.getElementById("elasticOpeningValue");
const fixedStatus = document.getElementById("fixedStatus");
const elasticStatus = document.getElementById("elasticStatus");
const presetButtons = [
...document.querySelectorAll(".preset")
];
function updateRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percent = ((value - min) / (max - min)) * 100;
input.style.setProperty("--range-fill", `${percent}%`);
}
function updateGarment(garment, topRx, topRz) {
updateBandGeometry(
garment.band.geometry,
garment.baseRx,
garment.baseRz,
topRx,
topRz
);
updateEllipseTube(
garment.rim.geometry,
topRx,
topRz,
0.037
);
garment.ribMeshes.forEach((rib, i) => {
const theta = (i / garment.ribMeshes.length) * Math.PI * 2;
const midRx = THREE.MathUtils.lerp(
garment.baseRx,
topRx,
0.5
);
const midRz = THREE.MathUtils.lerp(
garment.baseRz,
topRz,
0.5
);
rib.position.set(
midRx * Math.cos(theta),
(garment.bottomY + garment.topY) / 2,
midRz * Math.sin(theta)
);
rib.rotation.y = Math.PI / 2 - theta;
});
}
function updateScene() {
const waist = Number(waistSlider.value);
const response = Number(responseSlider.value) / 100;
const factor = waist / REFERENCE_WAIST;
const bodyRx = BODY_RX * factor;
const bodyRz = BODY_RZ * factor;
const elasticTopRx =
fixedGarment.baseRx +
(bodyRx - BODY_RX) * 1.08 * response;
const elasticTopRz =
fixedGarment.baseRz +
(bodyRz - BODY_RZ) * 1.08 * response;
fixedGarment.body.scale.set(factor, 1, factor);
elasticGarment.body.scale.set(factor, 1, factor);
updateGarment(fixedGarment, fixedGarment.baseRx, fixedGarment.baseRz);
updateGarment(elasticGarment, elasticTopRx, elasticTopRz);
const bodyMeasurement = openingCm(bodyRx, bodyRz);
const fixedMeasurement = openingCm(
fixedGarment.baseRx,
fixedGarment.baseRz
);
const elasticMeasurement = openingCm(
elasticTopRx,
elasticTopRz
);
fixedOpeningValue.textContent = `${Math.round(fixedMeasurement)} cm`;
elasticOpeningValue.textContent = `${Math.round(elasticMeasurement)} cm`;
const fixedTooTight = bodyMeasurement > fixedMeasurement + 1.5;
fixedGarment.tensionGroup.visible = fixedTooTight;
fixedStatus.classList.toggle("warning", fixedTooTight);
if (fixedTooTight) {
fixedStatus.textContent = "Too tight · constrained";
} else if (bodyMeasurement > fixedMeasurement - 8) {
fixedStatus.textContent = "Close fit · opening unchanged";
} else {
fixedStatus.textContent = "Fits · opening unchanged";
}
const elasticFits = bodyMeasurement <= elasticMeasurement + 1.5;
const elasticDelta = elasticMeasurement - fixedMeasurement;
elasticStatus.classList.toggle("warning", !elasticFits);
if (!elasticFits) {
elasticStatus.textContent = "Response limit reached";
} else if (Math.abs(elasticDelta) < 2) {
elasticStatus.textContent = "At baseline · tracking";
} else if (elasticDelta > 0) {
elasticStatus.textContent = `Expanded +${Math.round(elasticDelta)} cm`;
} else {
elasticStatus.textContent = `Contracted ${Math.round(elasticDelta)} cm`;
}
waistOutput.textContent = `${waist} cm`;
responseOutput.textContent = `${Math.round(response * 100)}%`;
updateRangeFill(waistSlider);
updateRangeFill(responseSlider);
presetButtons.forEach((button) => {
button.classList.toggle(
"active",
Number(button.dataset.size) === waist
);
});
}
waistSlider.addEventListener("input", updateScene);
responseSlider.addEventListener("input", updateScene);
presetButtons.forEach((button) => {
button.addEventListener("click", () => {
waistSlider.value = button.dataset.size;
updateScene();
});
});
constructionToggle.addEventListener("change", () => {
const visible = constructionToggle.checked;
fixedGarment.construction.visible = visible;
elasticGarment.construction.visible = visible;
fixedGarment.body.userData.guide.visible = visible;
elasticGarment.body.userData.guide.visible = visible;
});
const viewButtons = [
...document.querySelectorAll("[data-view]")
];
function setView(view) {
viewButtons.forEach((button) => {
button.classList.toggle("active", button.dataset.view === view);
});
if (view === "front") {
controls.targetAzimuth = 0;
controls.targetPolar = 1.27;
controls.targetRadius = 10.2;
controls.target.set(0, 2.35, 0);
} else if (view === "detail") {
controls.targetAzimuth = 0.26;
controls.targetPolar = 1.02;
controls.targetRadius = 6.6;
controls.target.set(0, 2.08, 0);
} else {
controls.targetAzimuth = 0.46;
controls.targetPolar = 1.12;
controls.targetRadius = 10.9;
controls.target.set(0, 2.45, 0);
}
}
viewButtons.forEach((button) => {
button.addEventListener("click", () => {
setView(button.dataset.view);
});
});
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
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;
controls.targetAzimuth -= dx * 0.006;
controls.targetPolar = THREE.MathUtils.clamp(
controls.targetPolar - dy * 0.005,
0.42,
1.48
);
});
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();
controls.targetRadius = THREE.MathUtils.clamp(
controls.targetRadius + event.deltaY * 0.008,
5.2,
15
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
setView("studio");
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
const fixedLabel = document.getElementById("fixedLabel");
const elasticLabel = document.getElementById("elasticLabel");
const fixedAnchor = new THREE.Vector3(-2.15, 4.03, 0.38);
const elasticAnchor = new THREE.Vector3(2.15, 4.03, 0.38);
function positionLabel(element, anchor) {
const projected = anchor.clone().project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
Math.abs(projected.x) > 1.2
) {
element.style.visibility = "hidden";
return;
}
element.style.visibility = "visible";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
updateScene();
function animate() {
requestAnimationFrame(animate);
const damping = 0.085;
controls.azimuth +=
(controls.targetAzimuth - controls.azimuth) * damping;
controls.polar +=
(controls.targetPolar - controls.polar) * damping;
controls.radius +=
(controls.targetRadius - controls.radius) * damping;
controls.lookTarget.lerp(controls.target, damping);
const sinPolar = Math.sin(controls.polar);
const cosPolar = Math.cos(controls.polar);
camera.position.set(
controls.lookTarget.x +
controls.radius * sinPolar * Math.sin(controls.azimuth),
controls.lookTarget.y + controls.radius * cosPolar,
controls.lookTarget.z +
controls.radius * sinPolar * Math.cos(controls.azimuth)
);
camera.lookAt(controls.lookTarget);
camera.updateMatrixWorld();
positionLabel(fixedLabel, fixedAnchor);
positionLabel(elasticLabel, elasticAnchor);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```