Prompt specification
Build or customize the Three.js 3D scene "Zipper closing and reopening" 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: Zipper closing and reopening
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/zipper-closing-and-reopening-x0638
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing zipper teeth and sliders. Animate the slider moving along fixed fabric edges as teeth engage behind it; reversing direction separates the same teeth without changing their order or spacing. Low-poly.
Working Three.js Starter (zipper-closing-and-reopening-x0638):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Low-Poly Zipper — Engage & Separate</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07131d;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: #eef8ff;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#panel {
position: fixed;
top: 20px;
left: 20px;
width: min(340px, calc(100vw - 40px));
padding: 18px;
border: 1px solid rgba(174, 221, 255, 0.18);
border-radius: 16px;
background: rgba(7, 20, 30, 0.82);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
user-select: none;
}
.eyebrow {
margin-bottom: 7px;
color: #70d6ff;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
}
h1 {
margin: 0 0 8px;
font-size: 27px;
line-height: 1.05;
letter-spacing: -0.04em;
}
#panel p {
margin: 0;
color: #a9bdca;
font-size: 13px;
line-height: 1.5;
}
.readout {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-top: 17px;
font-size: 11px;
letter-spacing: 0.08em;
}
#phase {
color: #ffd27c;
font-weight: 900;
}
#count {
color: #d9e9f3;
font-size: 11px;
white-space: nowrap;
}
.track {
height: 6px;
margin: 9px 0 15px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.09);
}
#bar {
display: block;
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #58c8ff, #ffd06c);
transition: width 100ms linear;
}
.buttons {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(174, 221, 255, 0.2);
border-radius: 9px;
padding: 9px 11px;
color: #eaf7ff;
background: rgba(255, 255, 255, 0.06);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(117, 215, 255, 0.55);
background: rgba(117, 215, 255, 0.13);
transform: translateY(-1px);
}
button.active {
border-color: rgba(255, 208, 108, 0.55);
color: #ffe5b5;
background: rgba(255, 208, 108, 0.12);
}
.note {
margin-top: 13px !important;
color: #78909f !important;
font-size: 11px !important;
}
#hint {
position: fixed;
right: 18px;
bottom: 16px;
padding: 8px 11px;
border: 1px solid rgba(174, 221, 255, 0.12);
border-radius: 8px;
color: #90a7b6;
background: rgba(7, 19, 29, 0.64);
font-size: 11px;
pointer-events: none;
}
@media (max-width: 700px) {
#panel {
top: 10px;
left: 10px;
width: min(305px, calc(100vw - 20px));
padding: 13px;
}
h1 {
font-size: 22px;
}
#panel p {
font-size: 12px;
}
#hint {
right: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section id="panel">
<div class="eyebrow">LOW-POLY MECHANISM</div>
<h1>Engage & Separate</h1>
<p>
The slider passes each fixed tooth once. Reversing direction separates those
same teeth without changing their order or spacing.
</p>
<div class="readout">
<span id="phase" aria-live="polite">ENGAGING</span>
<strong id="count">0 / 31 engaged</strong>
</div>
<div class="track"><i id="bar"></i></div>
<div class="buttons">
<button id="reverse" type="button">Reverse now</button>
<button id="auto" class="active" type="button">Auto cycle: ON</button>
<button id="reset" type="button">Reset view</button>
</div>
<p class="note">
31 persistent tooth IDs · X positions are never modified
</p>
</section>
<div id="hint">Drag to orbit · Wheel to zoom · R resets view · Space reverses</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene and camera
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131d);
scene.fog = new THREE.Fog(0x07131d, 18, 34);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0, 0);
const cameraControls = {
azimuth: 0,
elevation: 0.23,
zoom: 1,
radius: 16
};
function updateCamera() {
const { azimuth, elevation, radius, zoom } = cameraControls;
camera.position.set(
cameraTarget.x + radius * Math.sin(azimuth) * Math.cos(elevation),
cameraTarget.y + radius * Math.sin(elevation),
cameraTarget.z + radius * Math.cos(azimuth) * Math.cos(elevation)
);
camera.lookAt(cameraTarget);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const viewWidth = Math.max(17.5, 6.3 * aspect);
const viewHeight = viewWidth / aspect;
camera.left = -viewWidth / 2;
camera.right = viewWidth / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// Direct camera controls: no external controls/addons are used.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
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;
cameraControls.azimuth -= dx * 0.006;
cameraControls.elevation = THREE.MathUtils.clamp(
cameraControls.elevation + dy * 0.0045,
-0.08,
0.9
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraControls.zoom = THREE.MathUtils.clamp(
cameraControls.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.4
);
updateCamera();
}, { passive: false });
function resetCamera() {
cameraControls.azimuth = 0;
cameraControls.elevation = 0.23;
cameraControls.zoom = 1;
updateCamera();
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xbdeaff, 0x17212b, 2.0));
const keyLight = new THREE.DirectionalLight(0xfff1d7, 3.1);
keyLight.position.set(-4, 8, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x67cfff, 1.8);
rimLight.position.set(7, 2, 5);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Fixed fabric and backdrop
// -------------------------------------------------------------------------
const TEETH_COUNT = 31;
const TOOTH_SPACING = 0.44;
const FIRST_TOOTH_X = -((TEETH_COUNT - 1) * TOOTH_SPACING) / 2;
const LAST_TOOTH_X = -FIRST_TOOTH_X;
const FABRIC_LENGTH = LAST_TOOTH_X - FIRST_TOOTH_X + 2.4;
const backdrop = new THREE.Mesh(
new THREE.PlaneGeometry(22, 7),
new THREE.MeshStandardMaterial({
color: 0x091923,
roughness: 1,
metalness: 0
})
);
backdrop.position.z = -0.62;
backdrop.receiveShadow = true;
scene.add(backdrop);
const fabricMaterial = new THREE.MeshStandardMaterial({
color: 0x1d5963,
roughness: 0.96,
metalness: 0,
flatShading: true
});
const upperFabric = new THREE.Mesh(
new THREE.BoxGeometry(FABRIC_LENGTH, 1.44, 0.30),
fabricMaterial
);
upperFabric.position.y = 1.16;
upperFabric.castShadow = true;
upperFabric.receiveShadow = true;
scene.add(upperFabric);
const lowerFabric = new THREE.Mesh(
new THREE.BoxGeometry(FABRIC_LENGTH, 1.44, 0.30),
fabricMaterial
);
lowerFabric.position.y = -1.16;
lowerFabric.castShadow = true;
lowerFabric.receiveShadow = true;
scene.add(lowerFabric);
const edgeMaterial = new THREE.MeshStandardMaterial({
color: 0x102d37,
roughness: 0.88,
metalness: 0.05
});
const upperEdge = new THREE.Mesh(
new THREE.BoxGeometry(FABRIC_LENGTH, 0.085, 0.12),
edgeMaterial
);
upperEdge.position.set(0, 0.405, 0.19);
upperEdge.castShadow = true;
scene.add(upperEdge);
const lowerEdge = new THREE.Mesh(
new THREE.BoxGeometry(FABRIC_LENGTH, 0.085, 0.12),
edgeMaterial
);
lowerEdge.position.set(0, -0.405, 0.19);
lowerEdge.castShadow = true;
scene.add(lowerEdge);
const seam = new THREE.Mesh(
new THREE.BoxGeometry(FABRIC_LENGTH, 0.055, 0.05),
new THREE.MeshBasicMaterial({ color: 0x02080c })
);
seam.position.z = 0.10;
scene.add(seam);
// Stitch dashes remain attached to the fixed fabric.
const stitchGeometry = new THREE.BoxGeometry(0.18, 0.035, 0.035);
const stitchMaterial = new THREE.MeshStandardMaterial({
color: 0x82a9ac,
roughness: 1
});
for (let x = -FABRIC_LENGTH / 2 + 0.22;
x < FABRIC_LENGTH / 2 - 0.1;
x += 0.39) {
const upperStitch = new THREE.Mesh(stitchGeometry, stitchMaterial);
upperStitch.position.set(x, 1.60, 0.17);
scene.add(upperStitch);
const lowerStitch = new THREE.Mesh(stitchGeometry, stitchMaterial);
lowerStitch.position.set(x, -1.60, 0.17);
scene.add(lowerStitch);
}
// -------------------------------------------------------------------------
// Tooth geometry and persistent tooth records
// -------------------------------------------------------------------------
const toothShape = new THREE.Shape();
toothShape.moveTo(-0.12, -0.13);
toothShape.lineTo(0.08, -0.13);
toothShape.lineTo(0.14, -0.07);
toothShape.lineTo(0.14, 0.06);
toothShape.lineTo(0.08, 0.13);
toothShape.lineTo(-0.09, 0.13);
toothShape.lineTo(-0.14, 0.07);
toothShape.lineTo(-0.14, -0.06);
toothShape.closePath();
const toothHeadGeometry = new THREE.ExtrudeGeometry(toothShape, {
depth: 0.30,
bevelEnabled: false,
curveSegments: 1
});
toothHeadGeometry.translate(0, 0, -0.15);
const toothStemGeometry = new THREE.BoxGeometry(0.105, 0.34, 0.18);
const toothMaterials = [
new THREE.MeshStandardMaterial({
color: 0xe1b55d,
metalness: 0.78,
roughness: 0.28,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xf2cc78,
metalness: 0.72,
roughness: 0.3,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xb98536,
metalness: 0.8,
roughness: 0.32,
flatShading: true
})
];
const slotGeometry = new THREE.BoxGeometry(0.18, 0.10, 0.055);
const slotMaterial = new THREE.MeshStandardMaterial({
color: 0x07151b,
roughness: 0.9
});
const OPEN_Y = 0.34;
const CLOSED_Y = 0.075;
// Each record represents one persistent physical tooth.
// Its x coordinate and material are never changed by the animation.
const teeth = [];
for (let i = 0; i < TEETH_COUNT; i++) {
const x = FIRST_TOOTH_X + i * TOOTH_SPACING;
const side = i % 2 === 0 ? 1 : -1;
const group = new THREE.Group();
group.position.set(x, side * OPEN_Y, 0.18);
const head = new THREE.Mesh(
toothHeadGeometry,
toothMaterials[i % toothMaterials.length]
);
head.rotation.z = side > 0 ? 0 : Math.PI;
head.castShadow = true;
head.receiveShadow = true;
group.add(head);
const stem = new THREE.Mesh(
toothStemGeometry,
toothMaterials[i % toothMaterials.length]
);
stem.position.y = side * 0.18;
stem.castShadow = true;
group.add(stem);
scene.add(group);
const slot = new THREE.Mesh(slotGeometry, slotMaterial);
slot.position.set(x, side * 0.405, 0.19);
scene.add(slot);
teeth.push({
id: i,
x,
side,
group,
engaged: false,
amount: 0
});
}
// -------------------------------------------------------------------------
// Two-part slider assembly
// -------------------------------------------------------------------------
const sliderAssembly = new THREE.Group();
scene.add(sliderAssembly);
const plateShape = new THREE.Shape();
plateShape.moveTo(-0.58, -0.56);
plateShape.lineTo(0.34, -0.56);
plateShape.lineTo(0.72, 0);
plateShape.lineTo(0.34, 0.56);
plateShape.lineTo(-0.58, 0.56);
plateShape.lineTo(-0.42, 0.30);
plateShape.lineTo(-0.42, -0.30);
plateShape.closePath();
const plateGeometry = new THREE.ExtrudeGeometry(plateShape, {
depth: 0.18,
bevelEnabled: false,
curveSegments: 1
});
plateGeometry.translate(0, 0, -0.09);
const frontPlateMaterial = new THREE.MeshStandardMaterial({
color: 0xf06f38,
metalness: 0.58,
roughness: 0.3,
flatShading: true
});
const backPlateMaterial = new THREE.MeshStandardMaterial({
color: 0x9b3e24,
metalness: 0.64,
roughness: 0.34,
flatShading: true
});
const plateRig = new THREE.Group();
sliderAssembly.add(plateRig);
const frontPlate = new THREE.Mesh(plateGeometry, frontPlateMaterial);
frontPlate.position.z = 0.42;
frontPlate.castShadow = true;
frontPlate.receiveShadow = true;
plateRig.add(frontPlate);
const backPlate = new THREE.Mesh(plateGeometry, backPlateMaterial);
backPlate.position.z = -0.29;
backPlate.scale.set(0.97, 0.97, 1);
backPlate.castShadow = true;
plateRig.add(backPlate);
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xffe4b5,
metalness: 0.35,
roughness: 0.45,
flatShading: true
});
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.14, 0.34, 3),
arrowMaterial
);
arrow.rotation.z = -Math.PI / 2;
arrow.position.set(0.20, 0, 0.57);
arrow.castShadow = true;
plateRig.add(arrow);
const pullPivot = new THREE.Group();
pullPivot.position.set(0, -0.35, 0.64);
sliderAssembly.add(pullPivot);
const pullRing = new THREE.Mesh(
new THREE.TorusGeometry(0.13, 0.045, 4, 12),
new THREE.MeshStandardMaterial({
color: 0xcbd9df,
metalness: 0.82,
roughness: 0.24,
flatShading: true
})
);
pullRing.castShadow = true;
pullPivot.add(pullRing);
const pullShape = new THREE.Shape();
pullShape.moveTo(-0.10, 0);
pullShape.lineTo(0.10, 0);
pullShape.lineTo(0.15, -0.62);
pullShape.lineTo(0.10, -0.78);
pullShape.lineTo(-0.10, -0.78);
pullShape.lineTo(-0.15, -0.62);
pullShape.closePath();
const pullGeometry = new THREE.ExtrudeGeometry(pullShape, {
depth: 0.10,
bevelEnabled: false,
curveSegments: 1
});
pullGeometry.translate(0, 0, -0.05);
const pullTab = new THREE.Mesh(
pullGeometry,
new THREE.MeshStandardMaterial({
color: 0xffb24d,
metalness: 0.45,
roughness: 0.36,
flatShading: true
})
);
pullTab.castShadow = true;
pullPivot.add(pullTab);
// -------------------------------------------------------------------------
// Animation state and controls
// -------------------------------------------------------------------------
const LEFT_LIMIT = FIRST_TOOTH_X - 0.9;
const RIGHT_LIMIT = LAST_TOOTH_X + 0.9;
const SPEED = 2.65;
let sliderX = LEFT_LIMIT;
let direction = 1;
let autoCycle = true;
let dwell = 0;
let atBoundary = null;
const phaseElement = document.getElementById("phase");
const countElement = document.getElementById("count");
const barElement = document.getElementById("bar");
const reverseButton = document.getElementById("reverse");
const autoButton = document.getElementById("auto");
const resetButton = document.getElementById("reset");
function reverseNow() {
direction *= -1;
dwell = 0;
atBoundary = null;
}
reverseButton.addEventListener("click", reverseNow);
autoButton.addEventListener("click", () => {
autoCycle = !autoCycle;
autoButton.textContent = `Auto cycle: ${autoCycle ? "ON" : "OFF"}`;
autoButton.classList.toggle("active", autoCycle);
if (!autoCycle) {
dwell = 0;
}
});
resetButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.code === "Space") {
event.preventDefault();
reverseNow();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const previousSliderX = sliderX;
if (dwell > 0) {
dwell -= dt;
if (dwell <= 0) {
dwell = 0;
if (autoCycle) {
direction *= -1;
atBoundary = null;
}
}
} else if (!atBoundary && dt > 0) {
const nextX = sliderX + direction * SPEED * dt;
if (nextX >= RIGHT_LIMIT) {
sliderX = RIGHT_LIMIT;
atBoundary = "right";
if (autoCycle) dwell = 0.9;
} else if (nextX <= LEFT_LIMIT) {
sliderX = LEFT_LIMIT;
atBoundary = "left";
if (autoCycle) dwell = 0.9;
} else {
sliderX = nextX;
}
}
const travel = sliderX - previousSliderX;
// A tooth changes state only when the SAME physical tooth is crossed.
// Its x position, ordering, spacing, geometry and material remain fixed.
if (travel > 0) {
for (const tooth of teeth) {
if (previousSliderX <= tooth.x && sliderX >= tooth.x) {
tooth.engaged = true;
}
}
} else if (travel < 0) {
for (const tooth of teeth) {
if (previousSliderX >= tooth.x && sliderX <= tooth.x) {
tooth.engaged = false;
}
}
}
// Ease only the tooth's perpendicular travel. The longitudinal X position
// is deliberately untouched.
const toothEase = 1 - Math.exp(-dt * 17);
for (const tooth of teeth) {
const target = tooth.engaged ? 1 : 0;
tooth.amount += (target - tooth.amount) * toothEase;
const smoothAmount =
tooth.amount * tooth.amount * (3 - 2 * tooth.amount);
const openY = tooth.side * OPEN_Y;
const closedY = tooth.side * CLOSED_Y;
tooth.group.position.y = THREE.MathUtils.lerp(
openY,
closedY,
smoothAmount
);
}
sliderAssembly.position.x = sliderX;
const targetPlateAngle = direction > 0 ? 0 : Math.PI;
plateRig.rotation.z +=
(targetPlateAngle - plateRig.rotation.z) *
(1 - Math.exp(-dt * 10));
const targetPullAngle = -direction * 0.15;
pullPivot.rotation.z +=
(targetPullAngle - pullPivot.rotation.z) *
(1 - Math.exp(-dt * 7));
const engagedCount = teeth.reduce(
(count, tooth) => count + (tooth.engaged ? 1 : 0),
0
);
countElement.textContent = `${engagedCount} / ${TEETH_COUNT} engaged`;
barElement.style.width = `${(engagedCount / TEETH_COUNT) * 100}%`;
if (dwell > 0) {
phaseElement.textContent =
direction > 0 ? "ZIP COMPLETE" : "UNZIP COMPLETE";
} else if (atBoundary && !autoCycle) {
phaseElement.textContent = "PAUSED";
} else {
phaseElement.textContent =
direction > 0 ? "ENGAGING →" : "SEPARATING ←";
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```