Prompt specification
Build or customize the Three.js 3D scene "Waistband expansion comparison" 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: Waistband expansion comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/waistband-expansion-comparison-x0582
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts elastic waistbands. Stretch two bands with different fictional stiffness values using equal displayed pulls; show different extensions and label the response as an illustrative material model. Voxel style.
Working Three.js Starter (waistband-expansion-comparison-x0582):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Elastic Waistbands — Illustrative Material Model</title>
<style>
:root {
color-scheme: dark;
--bg: #080d18;
--panel: rgba(13, 21, 38, 0.94);
--border: #2a3b59;
--text: #eef4ff;
--muted: #8fa3c2;
--soft: #ff5277;
--stiff: #39c6d9;
--pull: #ffb347;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
.intro {
position: fixed;
top: 24px;
left: 24px;
z-index: 5;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--pull);
font: 800 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 38px);
line-height: 1;
letter-spacing: -0.045em;
text-shadow: 3px 3px 0 #03060c;
}
.intro p {
margin: 10px 0 0;
color: var(--muted);
font-size: 14px;
text-shadow: 2px 2px 0 #03060c;
}
.model-badge {
position: fixed;
top: 24px;
right: 24px;
z-index: 5;
max-width: 310px;
padding: 12px 15px;
border: 1px solid #725a2b;
background: rgba(28, 24, 17, 0.9);
box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.35);
pointer-events: none;
}
.model-badge strong {
display: block;
color: var(--pull);
font: 800 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
}
.model-badge span {
display: block;
margin-top: 6px;
color: #c7b997;
font-size: 11px;
line-height: 1.45;
}
.tag {
position: fixed;
z-index: 3;
pointer-events: none;
transform: translate(-50%, -50%);
opacity: 0;
transition: opacity 150ms ease;
}
.tag.visible {
opacity: 1;
}
.band-tag {
min-width: 178px;
padding: 10px 12px;
border: 1px solid var(--border);
border-left-width: 5px;
background: var(--panel);
box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.38);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.band-tag.soft {
border-left-color: var(--soft);
}
.band-tag.stiff {
border-left-color: var(--stiff);
}
.band-tag .name {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 8px;
font-weight: 900;
letter-spacing: 0.08em;
}
.band-tag .name b {
color: var(--soft);
}
.band-tag.stiff .name b {
color: var(--stiff);
}
.tag-row {
display: flex;
justify-content: space-between;
gap: 18px;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
}
.tag-row strong {
color: var(--text);
font-weight: 800;
}
.pull-tag {
padding: 5px 7px;
border: 1px solid #8b612b;
background: rgba(36, 26, 13, 0.95);
color: var(--pull);
box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
white-space: nowrap;
}
.control-panel {
position: fixed;
z-index: 6;
left: 50%;
bottom: 24px;
width: min(760px, calc(100vw - 32px));
transform: translateX(-50%);
padding: 15px 17px;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 7px 7px 0 rgba(0, 0, 0, 0.4);
backdrop-filter: blur(12px);
}
.control-top {
display: grid;
grid-template-columns: 145px 1fr 54px;
align-items: center;
gap: 14px;
}
.control-top label {
font: 800 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.pull-value {
padding: 7px 8px;
border: 1px solid #8b612b;
background: rgba(255, 179, 71, 0.08);
color: var(--pull);
text-align: center;
font: 900 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
input[type="range"] {
width: 100%;
margin: 0;
accent-color: var(--pull);
cursor: pointer;
}
.comparison {
display: grid;
grid-template-columns: 1fr 1fr 1.25fr;
gap: 12px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid #22314a;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.comparison > div {
min-width: 0;
}
.comparison .label {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.comparison .value {
margin-top: 4px;
font-size: 12px;
font-weight: 800;
white-space: nowrap;
}
.soft-text {
color: var(--soft);
}
.stiff-text {
color: var(--stiff);
}
.formula {
color: #d4deed;
font-size: 11px;
line-height: 1.45;
}
.hint {
position: fixed;
right: 24px;
bottom: 150px;
z-index: 5;
color: #6f829f;
font: 700 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
text-align: right;
pointer-events: none;
}
@media (max-width: 700px) {
.intro {
top: 16px;
left: 16px;
}
.intro p {
max-width: 260px;
font-size: 12px;
}
.model-badge {
top: auto;
right: 16px;
bottom: 154px;
max-width: 230px;
}
.model-badge span {
display: none;
}
.control-panel {
bottom: 12px;
padding: 12px;
}
.control-top {
grid-template-columns: 100px 1fr 48px;
gap: 9px;
}
.comparison {
grid-template-columns: 1fr 1fr;
}
.comparison .formula {
grid-column: 1 / -1;
}
.hint {
display: none;
}
.band-tag {
min-width: 150px;
padding: 8px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D comparison of two elastic waistbands"></canvas>
<header class="intro">
<div class="eyebrow">Voxel Materials Lab / 01</div>
<h1>ELASTIC WAISTBANDS</h1>
<p>Equal displayed pull. Different fictional stiffness.</p>
</header>
<aside class="model-badge">
<strong>ILLUSTRATIVE MATERIAL MODEL</strong>
<span>
Linear response using fictional stiffness values.
This visualization is not calibrated to a real rubber or waistband.
</span>
</aside>
<div id="softTag" class="tag band-tag soft">
<div class="name"><span>SOFT</span><b>k* = 12</b></div>
<div class="tag-row"><span>Extension</span><strong id="softExtension">+1.50 u</strong></div>
<div class="tag-row"><span>Final width</span><strong id="softWidth">5.68 u</strong></div>
</div>
<div id="stiffTag" class="tag band-tag stiff">
<div class="name"><span>STIFF</span><b>k* = 36</b></div>
<div class="tag-row"><span>Extension</span><strong id="stiffExtension">+0.50 u</strong></div>
<div class="tag-row"><span>Final width</span><strong id="stiffWidth">4.68 u</strong></div>
</div>
<div id="softLeftPull" class="tag pull-tag">PULL P = 18</div>
<div id="softRightPull" class="tag pull-tag">PULL P = 18</div>
<div id="stiffLeftPull" class="tag pull-tag">PULL P = 18</div>
<div id="stiffRightPull" class="tag pull-tag">PULL P = 18</div>
<section class="control-panel" aria-label="Model controls">
<div class="control-top">
<label for="pullSlider">Applied pull P</label>
<input
id="pullSlider"
type="range"
min="6"
max="30"
step="1"
value="18"
aria-label="Applied pull applied equally to both waistbands"
/>
<output id="pullValue" class="pull-value" for="pullSlider">18</output>
</div>
<div class="comparison">
<div>
<div class="label">Soft / k* = 12</div>
<div id="softSummary" class="value soft-text">ΔL = 1.50 u</div>
</div>
<div>
<div class="label">Stiff / k* = 36</div>
<div id="stiffSummary" class="value stiff-text">ΔL = 0.50 u</div>
</div>
<div class="formula">
Illustrative relation: <strong>ΔL = P / k*</strong><br />
Both arrows always show the same pull P.
</div>
</div>
</section>
<div class="hint">
DRAG TO ORBIT · SCROLL TO ZOOM<br />
DOUBLE-CLICK TO RESET VIEW
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080d18);
scene.fog = new THREE.Fog(0x080d18, 17, 31);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
// Camera controls are implemented directly here, without Three.js addons.
const cameraState = {
radius: 13.3,
theta: 0.48,
phi: 0.88,
target: new THREE.Vector3(0, 0.2, 0.25)
};
function updateCamera() {
const { radius, theta, phi, target } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
updateCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.42,
1.28
);
});
function endDrag() {
dragging = false;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
8.5,
20
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.radius = 13.3;
cameraState.theta = 0.48;
cameraState.phi = 0.88;
});
// Lighting
scene.add(new THREE.HemisphereLight(0xb8d5ff, 0x121829, 1.7));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x39c6d9, 30, 22);
cyanLight.position.set(-7, 4, -5);
scene.add(cyanLight);
const pinkLight = new THREE.PointLight(0xff5277, 26, 22);
pinkLight.position.set(7, 3, 5);
scene.add(pinkLight);
// Floor and grid
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1222,
roughness: 0.95,
metalness: 0.02
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 32),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(28, 56, 0x30415e, 0x1a2940);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.48;
grid.material.depthWrite = false;
scene.add(grid);
const CELL = 0.22;
const NX = 19;
const NZ = 8;
const NATURAL_WIDTH = NX * CELL;
const BAND_DEPTH = NZ * CELL;
const ARROW_TIP = 0.67;
const cubeGeometry = new THREE.BoxGeometry(
CELL * 0.94,
CELL * 0.94,
CELL * 0.94
);
const voxelEdgeGeometry = new THREE.EdgesGeometry(cubeGeometry);
const voxelEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x07101d,
transparent: true,
opacity: 0.72
});
const arrowCubeGeometry = new THREE.BoxGeometry(0.11, 0.11, 0.11);
const arrowEdgeGeometry = new THREE.EdgesGeometry(arrowCubeGeometry);
const arrowEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x3b2610,
transparent: true,
opacity: 0.85
});
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xffb347,
emissive: 0x4b2100,
emissiveIntensity: 0.55,
roughness: 0.55,
metalness: 0.08,
flatShading: true
});
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0x8394ac,
emissive: 0x1b2637,
emissiveIntensity: 0.35,
transparent: true,
opacity: 0.72,
roughness: 0.8
});
function addVoxelEdges(mesh, geometry, material) {
const edges = new THREE.LineSegments(geometry, material);
edges.scale.setScalar(1.002);
mesh.add(edges);
}
function makeBandMaterials(baseColor) {
const base = new THREE.Color(baseColor);
return [
new THREE.MeshStandardMaterial({
color: base,
roughness: 0.72,
metalness: 0.04,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: base.clone().offsetHSL(0, 0.015, 0.11),
roughness: 0.76,
metalness: 0.03,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: base.clone().offsetHSL(0, 0.01, -0.09),
roughness: 0.8,
metalness: 0.03,
flatShading: true
})
];
}
function createPlatform(z) {
const platform = new THREE.Mesh(
new THREE.BoxGeometry(8.6, 0.08, 2.35),
new THREE.MeshStandardMaterial({
color: 0x111b2d,
roughness: 0.9,
metalness: 0.06
})
);
platform.position.set(0, 0.04, z);
platform.receiveShadow = true;
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(platform.geometry),
new THREE.LineBasicMaterial({
color: 0x314663,
transparent: true,
opacity: 0.8
})
);
platform.add(outline);
scene.add(platform);
}
class ElasticBand {
constructor({ centerZ, stiffness, color }) {
this.centerZ = centerZ;
this.stiffness = stiffness;
this.currentExtension = 0;
this.targetExtension = 0;
this.voxels = [];
this.group = new THREE.Group();
this.group.position.z = centerZ;
scene.add(this.group);
const materials = makeBandMaterials(color);
// Build a closed, rectangular waistband loop from individual voxels.
for (let iz = 0; iz < NZ; iz++) {
for (let ix = 0; ix < NX; ix++) {
const isBoundary =
ix === 0 ||
ix === NX - 1 ||
iz === 0 ||
iz === NZ - 1;
if (!isBoundary) continue;
const shade =
(ix + iz * 2) % 7 === 0 ? 2 : (ix + iz) % 3 === 0 ? 1 : 0;
const mesh = new THREE.Mesh(cubeGeometry, materials[shade]);
const baseX = (ix - (NX - 1) / 2) * CELL;
const baseZ = (iz - (NZ - 1) / 2) * CELL;
mesh.position.set(baseX, 0.19, baseZ);
mesh.castShadow = true;
mesh.receiveShadow = true;
addVoxelEdges(mesh, voxelEdgeGeometry, voxelEdgeMaterial);
this.group.add(mesh);
this.voxels.push({ mesh, baseX });
}
}
// Static markers show where the original ends were before pulling.
for (const sign of [-1, 1]) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 0.025, BAND_DEPTH),
markerMaterial
);
marker.position.set(sign * NATURAL_WIDTH / 2, 0.095, 0);
this.group.add(marker);
}
this.leftArrow = this.createArrow(-1);
this.rightArrow = this.createArrow(1);
this.group.add(this.leftArrow, this.rightArrow);
}
createArrow(sign) {
const arrow = new THREE.Group();
// Stepped voxel arrowhead and shaft.
const parts = [
[0.22, 0],
[0.36, 0],
[0.50, 0],
[ARROW_TIP, 0],
[0.57, 0.12],
[0.47, 0.24],
[0.57, -0.12],
[0.47, -0.24]
];
for (const [x, z] of parts) {
const cube = new THREE.Mesh(arrowCubeGeometry, arrowMaterial);
cube.position.set(sign * x, 0.43, z);
cube.castShadow = true;
addVoxelEdges(cube, arrowEdgeGeometry, arrowEdgeMaterial);
arrow.add(cube);
}
return arrow;
}
setTargetExtension(extension) {
this.targetExtension = extension;
}
applyExtension(extension) {
this.currentExtension = extension;
const width = NATURAL_WIDTH + extension;
const xScale = width / NATURAL_WIDTH;
for (const voxel of this.voxels) {
voxel.mesh.position.x = voxel.baseX * xScale;
}
this.rightArrow.position.x = width / 2 + 0.08;
this.leftArrow.position.x = -(width / 2 + 0.08);
}
getArrowTipPosition(sign, target) {
return target.set(
sign * (NATURAL_WIDTH / 2 + this.currentExtension / 2 + 0.08 + ARROW_TIP),
0.54,
this.centerZ
);
}
}
createPlatform(-1.58);
createPlatform(1.58);
const softBand = new ElasticBand({
centerZ: -1.58,
stiffness: 12,
color: 0xff5277
});
const stiffBand = new ElasticBand({
centerZ: 1.58,
stiffness: 36,
color: 0x39c6d9
});
const bands = [softBand, stiffBand];
const ui = {
slider: document.querySelector("#pullSlider"),
pullValue: document.querySelector("#pullValue"),
softExtension: document.querySelector("#softExtension"),
softWidth: document.querySelector("#softWidth"),
stiffExtension: document.querySelector("#stiffExtension"),
stiffWidth: document.querySelector("#stiffWidth"),
softSummary: document.querySelector("#softSummary"),
stiffSummary: document.querySelector("#stiffSummary"),
softTag: document.querySelector("#softTag"),
stiffTag: document.querySelector("#stiffTag"),
pullTags: [
document.querySelector("#softLeftPull"),
document.querySelector("#softRightPull"),
document.querySelector("#stiffLeftPull"),
document.querySelector("#stiffRightPull")
]
};
function formatNumber(value) {
return Number(value).toFixed(2);
}
function updateModel() {
const pull = Number(ui.slider.value);
ui.pullValue.value = String(pull);
ui.pullValue.textContent = String(pull);
const softExtension = pull / softBand.stiffness;
const stiffExtension = pull / stiffBand.stiffness;
softBand.setTargetExtension(softExtension);
stiffBand.setTargetExtension(stiffExtension);
ui.softExtension.textContent = `+${formatNumber(softExtension)} u`;
ui.stiffExtension.textContent = `+${formatNumber(stiffExtension)} u`;
ui.softWidth.textContent =
`${formatNumber(NATURAL_WIDTH + softExtension)} u`;
ui.stiffWidth.textContent =
`${formatNumber(NATURAL_WIDTH + stiffExtension)} u`;
ui.softSummary.textContent =
`ΔL = ${formatNumber(softExtension)} u`;
ui.stiffSummary.textContent =
`ΔL = ${formatNumber(stiffExtension)} u`;
for (const tag of ui.pullTags) {
tag.textContent = `PULL P = ${pull}`;
}
}
ui.slider.addEventListener("input", updateModel);
updateModel();
const projected = new THREE.Vector3();
function placeTag(element, worldPosition, offsetX = 0, offsetY = 0) {
projected.copy(worldPosition).project(camera);
if (projected.z < -1 || projected.z > 1) {
element.classList.remove("visible");
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth + offsetX;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.classList.add("visible");
}
function positionLabels() {
const bandAnchor = new THREE.Vector3();
const arrowAnchor = new THREE.Vector3();
bandAnchor.set(0, 0.42, softBand.centerZ);
placeTag(ui.softTag, bandAnchor, 0, -58);
bandAnchor.set(0, 0.42, stiffBand.centerZ);
placeTag(ui.stiffTag, bandAnchor, 0, -58);
softBand.getArrowTipPosition(-1, arrowAnchor);
placeTag(ui.pullTags[0], arrowAnchor, 0, -17);
softBand.getArrowTipPosition(1, arrowAnchor);
placeTag(ui.pullTags[1], arrowAnchor, 0, -17);
stiffBand.getArrowTipPosition(-1, arrowAnchor);
placeTag(ui.pullTags[2], arrowAnchor, 0, -17);
stiffBand.getArrowTipPosition(1, arrowAnchor);
placeTag(ui.pullTags[3], arrowAnchor, 0, -17);
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", onResize);
function animate() {
requestAnimationFrame(animate);
// Smoothly interpolate to the selected illustrative model values.
for (const band of bands) {
const next =
band.currentExtension +
(band.targetExtension - band.currentExtension) * 0.16;
band.applyExtension(next);
}
updateCamera();
positionLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```