Prompt specification
Build or customize the Three.js 3D scene "Coat dressing practice board" 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: Coat dressing practice board
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/coat-dressing-practice-board-x0571
Scene Description Prompt:
Please create one HTML file with Three.js from cdnjs showing stylized hands practicing different button sizes on a fabric board.
Working Three.js Starter (coat-dressing-practice-board-x0571):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Button Practice — Stylized Hands</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e1d7;
}
canvas {
display: block;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
top: 22px;
left: 22px;
z-index: 10;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 18px;
background: rgba(255, 255, 255, 0.76);
box-shadow: 0 16px 50px rgba(39, 45, 52, 0.13);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 5px;
color: #58706f;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #26383e;
font-size: clamp(25px, 4vw, 36px);
line-height: 1.05;
letter-spacing: -0.045em;
}
.subtitle {
margin: 9px 0 15px;
color: #647277;
font-size: 13px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid rgba(44, 62, 67, 0.09);
border-radius: 999px;
background: rgba(255, 255, 255, 0.58);
color: #536268;
font-size: 11px;
font-weight: 700;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.45);
}
.dot.small {
width: 6px;
height: 6px;
background: #ee805d;
}
.dot.medium {
background: #42a7a0;
}
.dot.large {
width: 12px;
height: 12px;
background: #e2b64c;
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 10;
display: flex;
align-items: center;
gap: 9px;
padding: 8px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 14px;
background: rgba(255, 255, 255, 0.76);
box-shadow: 0 12px 34px rgba(39, 45, 52, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.controls span {
padding-left: 5px;
color: #67757a;
font-size: 11px;
font-weight: 650;
}
button {
border: 0;
border-radius: 9px;
padding: 9px 12px;
background: #304a50;
color: white;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
background: #3f6268;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e8e1d7;
color: #52686b;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 640px) {
.hud {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
margin-bottom: 10px;
}
.controls {
right: 12px;
bottom: 12px;
}
.controls span {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Preparing practice board…</div>
<section class="hud" aria-label="Scene information">
<p class="eyebrow">Fine motor study</p>
<h1>Button Practice</h1>
<p class="subtitle">
Three stylized hands repeatedly press calibrated buttons of different sizes.
</p>
<div class="legend">
<div class="legend-item">
<span class="dot small"></span>
Small · 1 target
</div>
<div class="legend-item">
<span class="dot medium"></span>
Medium · 3 targets
</div>
<div class="legend-item">
<span class="dot large"></span>
Large · 6 targets
</div>
</div>
</section>
<div class="controls">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset-view" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
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",
"Three stylized hands pressing buttons of different sizes on a fabric board"
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e1d7);
scene.fog = new THREE.Fog(0xe8e1d7, 18, 38);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
theta: 0.67,
phi: 0.94,
radius: 12.8,
target: new THREE.Vector3(0, 0.7, 0)
};
const defaultCamera = { ...cameraState, target: cameraState.target.clone() };
function updateCamera() {
const { theta, phi, radius, 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);
}
updateCamera();
// ------------------------------------------------------------
// Lights and ground
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xe8fbff, 0x5a5149, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2dc, 3.15);
keyLight.position.set(4.5, 9.5, 5.5);
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 = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x8acbd0, 1.05);
fillLight.position.set(-6, 5, -7);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xffb66f, 1.1, 20);
rimLight.position.set(5, 4, -5);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0xd7d0c5,
roughness: 0.94,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
// ------------------------------------------------------------
// Utility functions
// ------------------------------------------------------------
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function smoothstep(edge0, edge1, value) {
const x = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return x * x * (3 - 2 * x);
}
function roundedRectShape(width, height, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
function addBone(parent, start, end, radius, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const cylinderLength = Math.max(0.015, length - radius * 2);
const mesh = new THREE.Mesh(
new THREE.CapsuleGeometry(radius, cylinderLength, 5, 10),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeFabricTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 640;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#36535d";
ctx.fillRect(0, 0, canvas.width, canvas.height);
let seed = 7391;
const random = () => {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
};
// Broad woven bands.
for (let x = 0; x < canvas.width; x += 9) {
ctx.fillStyle = `rgba(255,255,255,${0.018 + random() * 0.025})`;
ctx.fillRect(x, 0, 2, canvas.height);
}
for (let y = 0; y < canvas.height; y += 9) {
ctx.fillStyle = `rgba(8,24,31,${0.025 + random() * 0.035})`;
ctx.fillRect(0, y, canvas.width, 2);
}
// Fine thread crossings.
for (let i = 0; i < 9000; i++) {
const x = random() * canvas.width;
const y = random() * canvas.height;
const alpha = 0.025 + random() * 0.055;
ctx.fillStyle = random() > 0.5
? `rgba(255,255,255,${alpha})`
: `rgba(0,12,18,${alpha})`;
ctx.fillRect(x, y, 1 + random() * 2, 1);
}
// A few subtle slubs in the fabric.
for (let i = 0; i < 90; i++) {
ctx.fillStyle = "rgba(255,255,255,0.035)";
ctx.fillRect(
random() * canvas.width,
random() * canvas.height,
8 + random() * 30,
1
);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(1.55, 1.15);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeBumpTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 320;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#888";
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let x = 0; x < canvas.width; x += 5) {
ctx.fillStyle = "rgba(255,255,255,0.15)";
ctx.fillRect(x, 0, 1, canvas.height);
}
for (let y = 0; y < canvas.height; y += 5) {
ctx.fillStyle = "rgba(0,0,0,0.13)";
ctx.fillRect(0, y, canvas.width, 1);
}
const texture = new THREE.CanvasTexture(canvas);
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(3, 2.2);
return texture;
}
// ------------------------------------------------------------
// Fabric board
// ------------------------------------------------------------
const fabricTexture = makeFabricTexture();
const bumpTexture = makeBumpTexture();
const fabricMaterial = new THREE.MeshStandardMaterial({
map: fabricTexture,
bumpMap: bumpTexture,
bumpScale: 0.065,
roughness: 0.92,
metalness: 0
});
const boardEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x243d46,
roughness: 0.9
});
const boardGeometry = new THREE.ExtrudeGeometry(
roundedRectShape(10.4, 6.4, 0.42),
{
depth: 0.4,
steps: 1,
bevelEnabled: true,
bevelThickness: 0.065,
bevelSize: 0.07,
bevelSegments: 4,
curveSegments: 16
}
);
boardGeometry.translate(0, 0, -0.2);
boardGeometry.rotateX(-Math.PI / 2);
const board = new THREE.Mesh(
boardGeometry,
[fabricMaterial, boardEdgeMaterial]
);
board.position.y = 0.2;
board.castShadow = true;
board.receiveShadow = true;
scene.add(board);
// Dashed stitched border.
const stitchShape = roundedRectShape(9.98, 5.98, 0.28);
const stitchPoints = stitchShape.getPoints(160).map(
(point) => new THREE.Vector3(point.x, 0.408, -point.y)
);
const stitchGeometry = new THREE.BufferGeometry().setFromPoints(
stitchPoints
);
const stitches = new THREE.LineLoop(
stitchGeometry,
new THREE.LineDashedMaterial({
color: 0xb6c9c9,
dashSize: 0.15,
gapSize: 0.105,
transparent: true,
opacity: 0.48
})
);
stitches.computeLineDistances();
scene.add(stitches);
// Small padded feet under the board.
const footMaterial = new THREE.MeshStandardMaterial({
color: 0x344b50,
roughness: 0.72
});
for (const x of [-4.35, 4.35]) {
for (const z of [-2.5, 2.5]) {
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.2, 0.2, 20),
footMaterial
);
foot.position.set(x, -0.08, z);
foot.castShadow = true;
scene.add(foot);
}
}
// ------------------------------------------------------------
// Buttons
// ------------------------------------------------------------
const boardSurface = 0.4;
function makeTargetTexture(count) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 512;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 512, 512);
ctx.fillStyle = "rgba(255,255,255,0.94)";
ctx.strokeStyle = "rgba(255,255,255,0.92)";
ctx.lineWidth = 8;
const dots = [];
if (count === 1) {
dots.push([256, 256, 48]);
} else if (count === 3) {
dots.push([256, 150, 39], [174, 326, 39], [338, 326, 39]);
} else {
dots.push(
[170, 154, 34],
[342, 154, 34],
[256, 256, 34],
[170, 358, 34],
[342, 358, 34],
[256, 256, 34]
);
// Replace the center duplicate with a sixth distinct dot.
dots[5] = [256, 430, 30];
}
for (const [x, y, radius] of dots) {
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
ctx.fill();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function createButton({ x, z, radius, height, color, count, label }) {
const group = new THREE.Group();
group.position.set(x, boardSurface, z);
const bodyMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.3,
metalness: 0.04
});
const body = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 1.025, height, 64),
bodyMaterial
);
body.position.y = height / 2;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const top = new THREE.Mesh(
new THREE.CylinderGeometry(radius * 0.9, radius * 0.92, 0.035, 64),
new THREE.MeshStandardMaterial({
color: new THREE.Color(color).offsetHSL(0, -0.02, 0.055),
roughness: 0.23,
metalness: 0.03
})
);
top.position.y = height + 0.005;
top.castShadow = true;
group.add(top);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(radius * 0.91, 0.045, 12, 72),
new THREE.MeshStandardMaterial({
color: new THREE.Color(color).offsetHSL(0, 0.03, -0.08),
roughness: 0.35,
metalness: 0.08
})
);
rim.rotation.x = Math.PI / 2;
rim.position.y = height - 0.015;
rim.castShadow = true;
group.add(rim);
const targetMaterial = new THREE.MeshBasicMaterial({
map: makeTargetTexture(count),
transparent: true,
depthWrite: false,
toneMapped: false
});
const target = new THREE.Mesh(
new THREE.CircleGeometry(radius * 0.68, 64),
targetMaterial
);
target.rotation.x = -Math.PI / 2;
target.position.y = height + 0.027;
group.add(target);
const pulseMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0,
depthWrite: false,
toneMapped: false
});
const pulse = new THREE.Mesh(
new THREE.TorusGeometry(radius * 1.03, 0.025, 10, 72),
pulseMaterial
);
pulse.rotation.x = Math.PI / 2;
pulse.position.y = height + 0.035;
group.add(pulse);
scene.add(group);
return {
group,
pulse,
pulseMaterial,
label,
x,
z,
radius,
height,
top: boardSurface + height
};
}
const buttons = [
createButton({
x: -2.85,
z: -0.85,
radius: 0.34,
height: 0.16,
color: 0xee805d,
count: 1,
label: "Small"
}),
createButton({
x: 0,
z: 0.05,
radius: 0.59,
height: 0.28,
color: 0x42a7a0,
count: 3,
label: "Medium"
}),
createButton({
x: 2.85,
z: 1.02,
radius: 0.89,
height: 0.42,
color: 0xe2b64c,
count: 6,
label: "Large"
})
];
// ------------------------------------------------------------
// Procedural stylized hands
// ------------------------------------------------------------
function createHand(button, color, accentColor) {
const hand = new THREE.Group();
const skin = new THREE.MeshStandardMaterial({
color,
roughness: 0.5,
metalness: 0.01
});
const skinLight = new THREE.MeshStandardMaterial({
color: new THREE.Color(color).offsetHSL(0, -0.02, 0.07),
roughness: 0.48
});
const accent = new THREE.MeshStandardMaterial({
color: accentColor,
roughness: 0.42,
metalness: 0.03
});
// Palm.
const palm = new THREE.Mesh(
new THREE.SphereGeometry(1, 36, 26),
skin
);
palm.position.set(0, 1.42, 0.04);
palm.scale.set(0.68, 0.35, 0.78);
palm.rotation.x = -0.12;
palm.castShadow = true;
palm.receiveShadow = true;
hand.add(palm);
// Forearm.
addBone(
hand,
new THREE.Vector3(0, 1.42, 0.56),
new THREE.Vector3(0.08, 1.53, 2.18),
0.245,
skin
);
// Wrist cuff.
const cuff = new THREE.Mesh(
new THREE.CylinderGeometry(0.285, 0.305, 0.27, 32),
accent
);
cuff.rotation.x = Math.PI / 2;
cuff.position.set(0.03, 1.48, 1.42);
cuff.castShadow = true;
hand.add(cuff);
const cuffTrim = new THREE.Mesh(
new THREE.TorusGeometry(0.285, 0.025, 10, 40),
skinLight
);
cuffTrim.position.set(0.03, 1.48, 1.29);
hand.add(cuffTrim);
// Helper for the three relaxed fingers.
const addRelaxedFinger = (base, middle, tip, radius) => {
addBone(hand, base, middle, radius, skin);
addBone(hand, middle, tip, radius * 0.9, skin);
const joint = new THREE.Mesh(
new THREE.SphereGeometry(radius * 0.96, 16, 12),
skinLight
);
joint.position.copy(middle);
joint.castShadow = true;
hand.add(joint);
const fingertip = new THREE.Mesh(
new THREE.SphereGeometry(radius * 0.92, 16, 12),
skin
);
fingertip.position.copy(tip);
fingertip.castShadow = true;
hand.add(fingertip);
};
addRelaxedFinger(
new THREE.Vector3(-0.16, 1.38, -0.25),
new THREE.Vector3(-0.17, 1.07, -0.53),
new THREE.Vector3(-0.17, 0.77, -0.63),
0.115
);
addRelaxedFinger(
new THREE.Vector3(0.14, 1.38, -0.22),
new THREE.Vector3(0.16, 1.1, -0.44),
new THREE.Vector3(0.18, 0.84, -0.52),
0.11
);
addRelaxedFinger(
new THREE.Vector3(0.4, 1.35, -0.09),
new THREE.Vector3(0.48, 1.13, -0.27),
new THREE.Vector3(0.52, 0.91, -0.33),
0.095
);
// Thumb.
addBone(
hand,
new THREE.Vector3(0.56, 1.34, 0.15),
new THREE.Vector3(0.9, 1.18, -0.03),
0.135,
skin
);
addBone(
hand,
new THREE.Vector3(0.9, 1.18, -0.03),
new THREE.Vector3(1.03, 0.96, -0.13),
0.115,
skin
);
const thumbTip = new THREE.Mesh(
new THREE.SphereGeometry(0.115, 16, 12),
skinLight
);
thumbTip.position.set(1.03, 0.96, -0.13);
thumbTip.castShadow = true;
hand.add(thumbTip);
// Animated index finger.
const indexPivot = new THREE.Group();
indexPivot.position.set(-0.49, 1.38, -0.32);
hand.add(indexPivot);
addBone(
indexPivot,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, -0.52, -0.03),
0.12,
skin
);
const indexJoint = new THREE.Mesh(
new THREE.SphereGeometry(0.115, 18, 14),
skinLight
);
indexJoint.position.set(0, -0.52, -0.03);
indexJoint.castShadow = true;
indexPivot.add(indexJoint);
const lowerIndex = new THREE.Group();
lowerIndex.position.set(0, -0.52, -0.03);
lowerIndex.rotation.x = 0.28;
indexPivot.add(lowerIndex);
addBone(
lowerIndex,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, -0.44, 0),
0.105,
skin
);
const indexTip = new THREE.Mesh(
new THREE.SphereGeometry(0.115, 18, 14),
skinLight
);
indexTip.position.set(0, -0.46, 0);
indexTip.castShadow = true;
lowerIndex.add(indexTip);
// Small palm accent.
const palmPatch = new THREE.Mesh(
new THREE.CircleGeometry(0.16, 32),
accent
);
palmPatch.position.set(0.08, 1.55, -0.69);
palmPatch.rotation.x = -0.35;
hand.add(palmPatch);
// Align the pressing fingertip over the button.
const tipLocalY = 1.38 - 0.52 - 0.46;
const pressedY = button.top + 0.115 - tipLocalY;
hand.position.set(
button.x + 0.49,
pressedY + 0.65,
button.z + 0.47
);
scene.add(hand);
return {
group: hand,
lowerIndex,
pressedY,
button,
phase: buttons.indexOf(button) * 0.31
};
}
const hands = [
createHand(buttons[0], 0xe8a27e, 0x775a70),
createHand(buttons[1], 0x70b8ad, 0x375c68),
createHand(buttons[2], 0xaa91c8, 0x574d75)
];
// ------------------------------------------------------------
// Custom orbit and zoom controls
// ------------------------------------------------------------
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 deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = clamp(
cameraState.phi + deltaY * 0.005,
0.42,
1.38
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (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();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
7.2,
19
);
updateCamera();
},
{ passive: false }
);
function resetView() {
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
cameraState.radius = defaultCamera.radius;
cameraState.target.copy(defaultCamera.target);
updateCamera();
}
document.getElementById("reset-view").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
const cycleDuration = 2.65;
let firstFrame = true;
function animate() {
const elapsed = clock.getElapsedTime();
for (const hand of hands) {
const cycle =
((elapsed + hand.phase) % cycleDuration) / cycleDuration;
// A compact press-and-release envelope.
const press =
smoothstep(0.075, 0.17, cycle) *
(1 - smoothstep(0.235, 0.345, cycle));
const button = hand.button;
// The hand descends as the fingertip contacts the button.
hand.group.position.y =
hand.pressedY +
0.65 * (1 - press) -
0.035 * press;
// Small forward movement compensates for finger curl.
hand.group.position.z = button.z + 0.47 - 0.09 * press;
// Gentle idle motion.
hand.group.position.x =
button.x +
0.49 +
Math.sin(elapsed * 1.35 + hand.phase * 9) * 0.012 *
(1 - press);
hand.group.rotation.z =
Math.sin(elapsed * 0.8 + hand.phase * 6) * 0.008 *
(1 - press);
// The index finger straightens slightly under pressure.
hand.lowerIndex.rotation.x = 0.28 * (1 - press) + 0.07 * press;
// The button depresses and emits a subtle ring pulse.
button.group.position.y = boardSurface - 0.042 * press;
button.pulse.scale.setScalar(1 + press * 0.22);
button.pulseMaterial.opacity = press * 0.58;
}
updateCamera();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.getElementById("loading").classList.add("hidden");
}
}
renderer.setAnimationLoop(animate);
// ------------------------------------------------------------
// Resize
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```