Prompt specification
Build or customize the Three.js 3D scene "Clothespin grip demonstration" 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: Clothespin grip demonstration
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/clothespin-grip-demonstration-x0002
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: clothespin grip demonstration. Create a short clothesline and fabric square; squeezing rear handles opens the jaws, releasing them closes around the fabric with a clearly visible pivot.
Working Three.js Starter (clothespin-grip-demonstration-x0002):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Clothespin Grip Demonstration</title>
<style>
:root {
color-scheme: light;
--ink: #26333d;
--paper: rgba(250, 248, 239, 0.9);
--orange: #f36f3d;
--yellow: #ffc857;
--teal: #4c9a91;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8efe8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
padding: 16px 18px;
border: 1px solid rgba(38, 51, 61, 0.12);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(45, 64, 61, 0.12);
backdrop-filter: blur(10px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 5px;
color: var(--orange);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 4vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.panel p {
margin: 10px 0 0;
color: #526069;
font-size: 13px;
line-height: 1.55;
}
kbd {
display: inline-block;
min-width: 21px;
padding: 1px 5px;
border: 1px solid #bac4bf;
border-bottom-width: 2px;
border-radius: 5px;
background: #fffdf5;
color: #35434a;
font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
.controls {
position: fixed;
z-index: 20;
left: 50%;
bottom: max(20px, env(safe-area-inset-bottom));
display: flex;
align-items: center;
gap: 12px;
width: max-content;
max-width: calc(100vw - 32px);
transform: translateX(-50%);
}
.squeeze-button {
min-width: 218px;
min-height: 54px;
padding: 0 22px;
border: 0;
border-radius: 14px;
background: var(--ink);
color: #fffdf5;
box-shadow: 0 10px 24px rgba(38, 51, 61, 0.22);
font: 800 13px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
touch-action: none;
user-select: none;
-webkit-user-select: none;
transition:
transform 100ms ease,
background 100ms ease,
box-shadow 100ms ease;
}
.squeeze-button:hover {
background: #354750;
}
.squeeze-button.active {
background: var(--orange);
box-shadow:
0 7px 18px rgba(243, 111, 61, 0.3),
inset 0 3px 0 rgba(255, 255, 255, 0.2);
transform: translateY(3px) scale(0.985);
}
.status {
min-width: 175px;
padding: 11px 14px;
border: 1px solid rgba(38, 51, 61, 0.12);
border-radius: 12px;
background: var(--paper);
box-shadow: 0 8px 22px rgba(45, 64, 61, 0.1);
color: #536169;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
text-align: center;
text-transform: uppercase;
pointer-events: none;
}
.status.open {
color: #a44223;
}
.status.closed {
color: #27756d;
}
.pin-label {
position: fixed;
z-index: 8;
padding: 5px 8px;
border: 1px solid rgba(38, 51, 61, 0.15);
border-radius: 7px;
background: rgba(255, 253, 245, 0.92);
box-shadow: 0 5px 14px rgba(38, 51, 61, 0.12);
color: #48575e;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
line-height: 1;
text-transform: uppercase;
pointer-events: none;
transform: translate(-50%, -150%);
white-space: nowrap;
}
.pin-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--orange);
content: "";
transform: translate(-50%, 7px);
}
#handleLabel::after {
background: var(--teal);
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #e8efe8;
color: #59686e;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 650px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.panel p {
font-size: 12px;
}
.controls {
bottom: 12px;
flex-direction: column;
gap: 8px;
}
.squeeze-button {
width: min(310px, calc(100vw - 32px));
}
.status {
min-width: 250px;
padding: 9px 12px;
}
.pin-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="loading">Building the workshop…</div>
<header class="panel">
<p class="eyebrow">Voxel mechanism</p>
<h1>Clothespin grip</h1>
<p>
Press and hold either wooden rear handle to squeeze the mechanism and
open the jaws. Release to let the spring close around the fabric.
You can also hold <kbd>Space</kbd>. Drag the background to orbit and
scroll to zoom.
</p>
</header>
<div class="pin-label" id="handleLabel">Rear handles</div>
<div class="pin-label" id="pivotLabel">Pivot axle</div>
<div class="controls">
<button
id="squeezeButton"
class="squeeze-button"
type="button"
aria-label="Press and hold to squeeze the clothespin handles"
aria-pressed="false"
>
Hold to squeeze
</button>
<div id="status" class="status closed">Released · gripping fabric</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.querySelector("#loading");
const squeezeButton = document.querySelector("#squeezeButton");
const status = document.querySelector("#status");
const handleLabel = document.querySelector("#handleLabel");
const pivotLabel = document.querySelector("#pivotLabel");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8efe8);
scene.fog = new THREE.Fog(0xe8efe8, 12, 23);
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.08;
renderer.domElement.setAttribute("aria-label", "Interactive voxel clothespin scene");
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-4, 4, 3, -3, 0.1, 50);
const cameraTarget = new THREE.Vector3(0, 2.02, 0);
let cameraAzimuth = 0.27;
let cameraPolar = 1.31;
let cameraRadius = 9.2;
let cameraZoom = 1;
function updateCamera() {
const sinPolar = Math.sin(cameraPolar);
camera.position.set(
cameraTarget.x + cameraRadius * sinPolar * Math.sin(cameraAzimuth),
cameraTarget.y + cameraRadius * Math.cos(cameraPolar),
cameraTarget.z + cameraRadius * sinPolar * Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(4.9, 6.55 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const hemiLight = new THREE.HemisphereLight(0xfff8df, 0x7e9a96, 2.35);
scene.add(hemiLight);
const keyLight = new THREE.DirectionalLight(0xfff0d2, 3.25);
keyLight.position.set(-4.5, 7.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -2;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xa9d9d1, 1.2);
rimLight.position.set(5, 4, -4);
scene.add(rimLight);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
});
const materials = {
ground: material(0xdde8df),
platform: material(0xc7d5c8),
platformEdge: material(0x9eb5aa),
post: material(0xb47b49),
postDark: material(0x7c5138),
ropeA: material(0x75533c),
ropeB: material(0x8a6243),
woodLeft: material(0xd59650),
woodRight: material(0xc78545),
woodLight: material(0xe4ad62),
handleLeft: material(0xa9663b, {
emissive: 0xff844d,
emissiveIntensity: 0.04
}),
handleRight: material(0xb87543, {
emissive: 0xff844d,
emissiveIntensity: 0.04
}),
grip: material(0x774a31),
pad: material(0xf0cf99),
spring: material(0x3e7774, { metalness: 0.15 }),
pivot: material(0xf36f3d, { metalness: 0.18, roughness: 0.48 }),
pivotCap: material(0xffc857, { metalness: 0.12, roughness: 0.5 }),
pivotCenter: material(0x26333d, { metalness: 0.45, roughness: 0.36 }),
fabric: material(0xffffff, { roughness: 1 }),
fold: material(0xd95850),
accent: material(0xef7555)
};
function box(parent, size, position, mat, castShadow = true, receiveShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function beam(parent, a, b, width, depth, mat, z = 0) {
const dx = b.x - a.x;
const dy = b.y - a.y;
const length = Math.hypot(dx, dy);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, length, depth),
mat
);
mesh.position.set((a.x + b.x) / 2, (a.y + b.y) / 2, z);
mesh.rotation.z = Math.atan2(dy, dx) - Math.PI / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ground and low voxel platform.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
box(
scene,
[6.25, 0.18, 2.45],
[0, 0.09, -0.2],
materials.platform
);
box(
scene,
[6.3, 0.055, 2.5],
[0, 0.205, -0.2],
materials.platformEdge
);
// Two short voxel stands supporting the clothesline.
for (const x of [-2.58, 2.58]) {
box(scene, [0.52, 0.16, 0.58], [x, 0.25, -0.32], materials.postDark);
box(scene, [0.13, 3.17, 0.13], [x, 1.88, -0.32], materials.post);
box(scene, [0.26, 0.16, 0.25], [x, 3.52, -0.32], materials.postDark);
box(scene, [0.22, 0.09, 0.22], [x, 3.62, -0.32], materials.ropeB);
}
// Taut, segmented clothesline.
const lineSegments = 20;
const lineLength = 5.05;
const segmentLength = lineLength / lineSegments;
for (let i = 0; i < lineSegments; i++) {
const x = -lineLength / 2 + segmentLength * (i + 0.5);
box(
scene,
[segmentLength * 1.04, 0.065, 0.07],
[x, 3.48, -0.3],
i % 2 ? materials.ropeA : materials.ropeB
);
}
box(scene, [0.18, 0.2, 0.14], [-2.53, 3.48, -0.3], materials.ropeA);
box(scene, [0.18, 0.2, 0.14], [2.53, 3.48, -0.3], materials.ropeA);
// Square fabric made from individually colored voxel tiles.
const fabricGroup = new THREE.Group();
fabricGroup.position.set(0, 2.23, -0.1);
scene.add(fabricGroup);
const tileCount = 11;
const tileStep = 0.11;
const tileGeometry = new THREE.BoxGeometry(0.102, 0.102, 0.066);
const fabricInstances = new THREE.InstancedMesh(
tileGeometry,
materials.fabric,
tileCount * tileCount
);
const dummy = new THREE.Object3D();
const fabricColors = [
new THREE.Color(0xef765f),
new THREE.Color(0xf39a70),
new THREE.Color(0xf7c18c),
new THREE.Color(0xe96b61),
new THREE.Color(0xf4aa83)
];
const hemColor = new THREE.Color(0xc94f4c);
let instanceIndex = 0;
for (let row = 0; row < tileCount; row++) {
for (let col = 0; col < tileCount; col++) {
const x = (col - (tileCount - 1) / 2) * tileStep;
const y = -row * tileStep;
const z = (row + col) % 2 === 0 ? 0.003 : 0;
dummy.position.set(x, y, z);
dummy.updateMatrix();
fabricInstances.setMatrixAt(instanceIndex, dummy.matrix);
const color =
row === 0 || col === 0 || row === tileCount - 1 || col === tileCount - 1
? hemColor
: fabricColors[(row * 3 + col * 5) % fabricColors.length];
fabricInstances.setColorAt(instanceIndex, color);
instanceIndex++;
}
}
fabricInstances.instanceMatrix.needsUpdate = true;
fabricInstances.instanceColor.needsUpdate = true;
fabricInstances.castShadow = true;
fabricInstances.receiveShadow = true;
fabricGroup.add(fabricInstances);
// A small bunched fold directly beneath the jaws.
for (let i = 0; i < 3; i++) {
box(
fabricGroup,
[0.105, 0.09, 0.085],
[(i - 1) * 0.095, -0.032, 0.02 + (i === 1 ? 0.012 : 0)],
materials.fold
);
}
const pivotY = 3.02;
const leftJaw = new THREE.Group();
const rightJaw = new THREE.Group();
leftJaw.position.set(0, pivotY, 0);
rightJaw.position.set(0, pivotY, 0);
scene.add(leftJaw, rightJaw);
const handleMeshes = [];
const handleMaterials = [
materials.handleLeft,
materials.handleRight
];
function addHandleRidges(group, a, b, mat) {
const dx = b.x - a.x;
const dy = b.y - a.y;
const angle = Math.atan2(dy, dx);
for (const t of [0.42, 0.59, 0.76]) {
const ridge = box(
group,
[0.225, 0.055, 0.205],
[a.x + dx * t, a.y + dy * t, -0.025],
materials.grip
);
ridge.rotation.z = angle + Math.PI / 2;
handleMeshes.push(ridge);
}
}
function buildSide(group, side, handleMat, jawMat) {
const s = side;
// Upper rear handle.
const handleA = { x: s * 0.09, y: 0.08 };
const handleB = { x: s * 0.73, y: 0.7 };
const handle = beam(
group,
handleA,
handleB,
0.18,
0.18,
handleMat,
-0.035
);
handleMeshes.push(handle);
addHandleRidges(group, handleA, handleB, handleMat);
const endCap = box(
group,
[0.23, 0.22, 0.2],
[handleB.x, handleB.y, -0.035],
handleMat
);
handleMeshes.push(endCap);
// Two-part lower wooden jaw.
const jawA = { x: s * 0.055, y: -0.045 };
const jawB = { x: s * 0.14, y: -0.42 };
const jawC = { x: s * 0.17, y: -0.79 };
const upperJaw = beam(
group,
jawA,
jawB,
0.17,
0.21,
jawMat,
0.04
);
const lowerJaw = beam(
group,
jawB,
jawC,
0.19,
0.22,
materials.woodLight,
0.04
);
// Broad padded contact at the bottom of each jaw.
box(
group,
[0.205, 0.235, 0.245],
[jawC.x, jawC.y, 0.045],
materials.pad
);
// Darker inner contact pad.
box(
group,
[0.052, 0.18, 0.252],
[s * 0.112, -0.775, 0.048],
materials.grip
);
// Small square shoulder around the pivot.
box(
group,
[0.25, 0.25, 0.23],
[s * 0.075, 0.015, 0.025],
jawMat
);
}
buildSide(leftJaw, -1, materials.handleLeft, materials.woodLeft);
buildSide(rightJaw, 1, materials.handleRight, materials.woodRight);
// Visible spring behind the pivot.
beam(
scene,
{ x: -0.21, y: 3.13 },
{ x: 0, y: 3.0 },
0.048,
0.048,
materials.spring,
-0.19
);
beam(
scene,
{ x: 0, y: 3.0 },
{ x: 0.21, y: 3.13 },
0.048,
0.048,
materials.spring,
-0.19
);
// Bright, octagonal pivot axle and front screw cap.
const axle = new THREE.Mesh(
new THREE.CylinderGeometry(0.073, 0.073, 0.66, 8),
materials.pivot
);
axle.rotation.x = Math.PI / 2;
axle.position.set(0, pivotY, 0.015);
axle.castShadow = true;
scene.add(axle);
const rearCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.125, 0.125, 0.065, 8),
materials.pivot
);
rearCap.rotation.x = Math.PI / 2;
rearCap.position.set(0, pivotY, -0.335);
rearCap.castShadow = true;
scene.add(rearCap);
const frontCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.15, 0.085, 8),
materials.pivotCap
);
frontCap.rotation.x = Math.PI / 2;
frontCap.position.set(0, pivotY, 0.355);
frontCap.castShadow = true;
scene.add(frontCap);
box(
scene,
[0.065, 0.065, 0.055],
[0, pivotY, 0.408],
materials.pivotCenter
);
// Four orange corner pixels emphasize the mechanical pivot.
for (const [x, y] of [
[0, 0.175],
[0, -0.175],
[0.175, 0],
[-0.175, 0]
]) {
box(
scene,
[0.055, 0.055, 0.055],
[x, pivotY + y, 0.409],
materials.pivot
);
}
// Small decorative blocks on the platform.
for (const x of [-2.95, 2.95]) {
box(scene, [0.28, 0.12, 0.28], [x, 0.3, 0.45], materials.accent);
}
let squeezing = false;
let openness = 0;
let hoveringHandle = false;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function setSqueezed(value) {
squeezing = value;
squeezeButton.classList.toggle("active", value);
squeezeButton.setAttribute("aria-pressed", String(value));
}
function pickHandle(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
scene.updateMatrixWorld(true);
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(handleMeshes, false);
}
let orbiting = false;
let orbitPointerId = null;
let lastPointerX = 0;
let lastPointerY = 0;
let handlePointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
const hits = pickHandle(event);
if (hits.length) {
handlePointerId = event.pointerId;
renderer.domElement.setPointerCapture(event.pointerId);
setSqueezed(true);
event.preventDefault();
return;
}
orbiting = true;
orbitPointerId = event.pointerId;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (orbiting && event.pointerId === orbitPointerId) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
cameraAzimuth -= dx * 0.006;
cameraPolar = THREE.MathUtils.clamp(
cameraPolar + dy * 0.0045,
1.04,
1.48
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
return;
}
if (!squeezing) {
hoveringHandle = pickHandle(event).length > 0;
renderer.domElement.style.cursor = hoveringHandle ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (event.pointerId === handlePointerId) {
handlePointerId = null;
setSqueezed(false);
}
if (event.pointerId === orbitPointerId) {
orbiting = false;
orbitPointerId = null;
renderer.domElement.style.cursor = hoveringHandle ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointercancel", () => {
orbiting = false;
orbitPointerId = null;
handlePointerId = null;
setSqueezed(false);
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.76,
1.38
);
updateCamera();
},
{ passive: false }
);
squeezeButton.addEventListener("pointerdown", (event) => {
event.preventDefault();
squeezeButton.setPointerCapture(event.pointerId);
setSqueezed(true);
});
squeezeButton.addEventListener("pointerup", () => setSqueezed(false));
squeezeButton.addEventListener("pointercancel", () => setSqueezed(false));
squeezeButton.addEventListener("blur", () => setSqueezed(false));
window.addEventListener("pointerup", () => {
if (!squeezeButton.matches(":active")) {
setSqueezed(false);
}
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
setSqueezed(true);
}
});
window.addEventListener("keyup", (event) => {
if (event.code === "Space") {
event.preventDefault();
setSqueezed(false);
}
});
window.addEventListener("blur", () => setSqueezed(false));
const pivotWorld = new THREE.Vector3(0, pivotY, 0.43);
const leftHandleWorld = new THREE.Vector3();
const rightHandleWorld = new THREE.Vector3();
const handleWorld = new THREE.Vector3();
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
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`;
}
const clock = new THREE.Clock();
let elapsed = 0;
let lastStatus = "";
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
const targetOpenness = squeezing ? 1 : 0;
const response = squeezing ? 13 : 10;
openness = THREE.MathUtils.damp(
openness,
targetOpenness,
response,
dt
);
const openingAngle = openness * 0.36;
// Opposite lever rotations squeeze the handles together and open the jaws.
leftJaw.rotation.z = -openingAngle;
rightJaw.rotation.z = openingAngle;
// The cloth relaxes slightly while the jaws are open.
fabricGroup.position.y = 2.23 - openness * 0.045;
fabricGroup.position.x =
Math.sin(elapsed * 0.75) * 0.012 * (1 - openness);
fabricGroup.rotation.z =
Math.sin(elapsed * 0.9) * 0.008 * (1 - openness) +
openness * 0.012;
const glow = squeezing ? 0.48 : hoveringHandle ? 0.3 : 0.04;
handleMaterials.forEach((mat) => {
mat.emissiveIntensity = glow;
});
let statusText;
let statusClass;
if (squeezing) {
statusText = "Squeezing · jaws open";
statusClass = "open";
} else if (openness > 0.025) {
statusText = "Spring returning · closing";
statusClass = "open";
} else {
statusText = "Released · gripping fabric";
statusClass = "closed";
}
if (statusText !== lastStatus) {
status.textContent = statusText;
status.className = `status ${statusClass}`;
lastStatus = statusText;
}
scene.updateMatrixWorld(true);
leftHandleWorld.set(-0.73, 0.7, -0.035).applyMatrix4(leftJaw.matrixWorld);
rightHandleWorld.set(0.73, 0.7, -0.035).applyMatrix4(rightJaw.matrixWorld);
handleWorld
.copy(leftHandleWorld)
.add(rightHandleWorld)
.multiplyScalar(0.5);
handleWorld.y += 0.22;
positionLabel(handleLabel, handleWorld);
positionLabel(pivotLabel, pivotWorld);
renderer.render(scene, camera);
}
loading.remove();
animate();
</script>
</body>
</html>
```