Prompt specification
Build or customize the Three.js 3D scene "Instrument Gesture Timing Bench" 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: Instrument Gesture Timing Bench
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/instrument-gesture-timing-bench-x3302
Scene Description Prompt:
Please use Three.js from cdnjs for a stylized scene based on this idea: instrument gesture timing bench. Animate plucking, striking, and blowing indicators on three original teaching instruments. Align optional synthetic sounds with visible actions and make silent playback equally informative. Return one self-contained HTML file.
Working Three.js Starter (instrument-gesture-timing-bench-x3302):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<meta name="theme-color" content="#09121d" />
<title>Gesture Lab — Instrument Timing Bench</title>
<style>
:root {
--bg: #09121d;
--panel: rgba(13, 25, 38, 0.78);
--line: rgba(196, 224, 240, 0.17);
--text: #edf7f7;
--muted: #8fa8b5;
--pluck: #ff8b62;
--strike: #ffd166;
--blow: #59ddd1;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body { touch-action: none; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 30%, rgba(2, 7, 12, 0.28) 100%),
linear-gradient(180deg, rgba(5, 12, 20, 0.18), transparent 26%, transparent 72%, rgba(5, 12, 20, 0.42));
z-index: 2;
}
.hud {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
header {
position: absolute;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 2px;
background: var(--blow);
box-shadow: 0 0 12px rgba(89, 221, 209, 0.7);
}
h1 {
margin: 0;
max-width: 560px;
font-size: clamp(25px, 3vw, 43px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.045em;
text-shadow: 0 4px 30px rgba(0, 0, 0, 0.34);
}
h1 span {
display: block;
color: #a6bbc4;
font-size: 0.43em;
font-weight: 650;
letter-spacing: 0.12em;
margin-top: 10px;
text-transform: uppercase;
}
.controls {
pointer-events: auto;
display: flex;
align-items: center;
gap: 9px;
padding: 8px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(16px) saturate(120%);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.2);
}
button {
appearance: none;
border: 1px solid rgba(213, 236, 244, 0.15);
border-radius: 10px;
min-height: 40px;
padding: 0 14px;
color: var(--text);
background: rgba(255, 255, 255, 0.055);
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.11);
border-color: rgba(213, 236, 244, 0.3);
}
button:active { transform: translateY(1px); }
button:focus-visible, input:focus-visible {
outline: 2px solid var(--blow);
outline-offset: 3px;
}
#play {
min-width: 88px;
color: #07151a;
background: var(--blow);
border-color: transparent;
box-shadow: 0 7px 22px rgba(89, 221, 209, 0.18);
}
#sound.active {
color: #ffe6a5;
border-color: rgba(255, 209, 102, 0.45);
background: rgba(255, 209, 102, 0.1);
}
.tempo {
display: grid;
grid-template-columns: auto 96px auto;
align-items: center;
gap: 9px;
padding: 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
input[type="range"] {
width: 96px;
accent-color: var(--blow);
cursor: pointer;
}
#tempoValue {
width: 30px;
color: var(--text);
text-align: right;
font-variant-numeric: tabular-nums;
}
.cue {
position: absolute;
top: 122px;
left: 50%;
width: min(360px, calc(100vw - 36px));
transform: translateX(-50%);
padding: 13px 16px 14px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(10, 21, 33, 0.66);
backdrop-filter: blur(14px);
text-align: center;
box-shadow: 0 14px 50px rgba(0, 0, 0, 0.17);
}
.cue-top {
display: flex;
align-items: center;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#beatNumber {
color: var(--text);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
#cueAction {
margin-top: 7px;
font-size: 22px;
font-weight: 760;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#cueDetail {
min-height: 16px;
margin-top: 3px;
color: #b2c4cb;
font-size: 11px;
}
#cueNext {
margin-top: 9px;
padding-top: 8px;
border-top: 1px solid rgba(213, 236, 244, 0.1);
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.timeline-panel {
position: absolute;
left: 50%;
bottom: 22px;
width: min(920px, calc(100vw - 40px));
transform: translateX(-50%);
padding: 13px 16px 11px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(10, 21, 33, 0.75);
backdrop-filter: blur(16px) saturate(120%);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.24);
}
.timeline-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend {
display: flex;
gap: 14px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
display: inline-block;
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.legend .p { color: var(--pluck); }
.legend .s { color: var(--strike); }
.legend .b { color: var(--blow); }
.track {
position: relative;
height: 34px;
overflow: hidden;
border-radius: 9px;
background:
repeating-linear-gradient(90deg, rgba(255,255,255,.045) 0 1px, transparent 1px 6.25%),
rgba(255, 255, 255, 0.025);
}
.marker {
position: absolute;
top: 9px;
width: 15px;
height: 15px;
transform: translateX(-50%);
border: 2px solid rgba(255,255,255,.16);
border-radius: 50%;
background: #172536;
box-shadow: 0 0 0 3px rgba(9,18,29,.8);
transition: transform 100ms ease, box-shadow 100ms ease;
}
.marker.pluck { border-color: var(--pluck); }
.marker.strike { border-color: var(--strike); }
.marker.blow { border-color: var(--blow); }
.marker.active {
transform: translateX(-50%) scale(1.35);
box-shadow: 0 0 0 3px rgba(9,18,29,.8), 0 0 17px currentColor;
}
.marker.pluck.active { color: var(--pluck); }
.marker.strike.active { color: var(--strike); }
.marker.blow.active { color: var(--blow); }
#playhead {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 2px;
transform: translateX(-1px);
background: rgba(244, 255, 255, 0.94);
box-shadow: 0 0 12px rgba(255, 255, 255, 0.7);
will-change: left;
}
#playhead::before {
content: "";
position: absolute;
top: 0;
left: -3px;
width: 8px;
height: 8px;
border-radius: 0 0 8px 8px;
background: white;
}
.hint {
position: absolute;
left: 28px;
bottom: 124px;
color: rgba(191, 211, 219, 0.68);
font-size: 10px;
line-height: 1.55;
letter-spacing: 0.035em;
}
.hint strong {
color: rgba(229, 245, 247, 0.9);
font-weight: 700;
}
@media (max-width: 850px) {
header { top: 18px; left: 18px; right: 18px; }
.controls { flex-wrap: wrap; justify-content: flex-end; max-width: 280px; }
.tempo { order: 3; width: 100%; justify-content: flex-end; }
.cue { top: 155px; }
.hint { display: none; }
.timeline-panel { bottom: 14px; width: calc(100vw - 24px); }
}
@media (max-width: 540px) {
h1 { font-size: 26px; }
h1 span { font-size: .38em; }
.controls { max-width: 205px; padding: 6px; gap: 5px; }
button { min-height: 36px; padding: 0 10px; font-size: 9px; }
#play { min-width: 68px; }
.cue { top: 144px; padding: 10px 12px; }
#cueAction { font-size: 18px; }
.timeline-head .legend { gap: 8px; }
.timeline-panel { padding-left: 10px; padding-right: 10px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional instrument timing bench"></canvas>
<div class="vignette"></div>
<main class="hud">
<header>
<div>
<div class="eyebrow">Gesture Lab · Teaching Instrument 03</div>
<h1>Instrument Gesture<br>Timing Bench <span>Pluck · Strike · Blow</span></h1>
</div>
<div class="controls">
<button id="play" type="button" aria-label="Play timing sequence">Run</button>
<button id="sound" type="button" aria-pressed="false" title="Toggle synthesized instrument sounds">SFX Off</button>
<label class="tempo" for="tempo">
Tempo
<input id="tempo" type="range" min="48" max="120" value="78" step="1" />
<span id="tempoValue">78</span>
</label>
</div>
</header>
<section class="cue" aria-live="polite">
<div class="cue-top">
<span>Gesture cue</span>
<span>Beat <b id="beatNumber">01</b> / 16</span>
</div>
<div id="cueAction">Ready</div>
<div id="cueDetail">Press Run to begin the study loop</div>
<div id="cueNext">Next: Pluck</div>
</section>
<section class="timeline-panel" aria-label="Sixteen beat timing timeline">
<div class="timeline-head">
<span>16-beat movement loop</span>
<div class="legend">
<span class="p"><i></i>Pluck</span>
<span class="s"><i></i>Strike</span>
<span class="b"><i></i>Blow</span>
</div>
</div>
<div class="track" id="track">
<div id="playhead"></div>
</div>
</section>
<div class="hint">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom · <strong>Tap an instrument</strong> to cue its gesture
</div>
</main>
<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 playButton = document.querySelector("#play");
const soundButton = document.querySelector("#sound");
const tempoInput = document.querySelector("#tempo");
const tempoValue = document.querySelector("#tempoValue");
const track = document.querySelector("#track");
const playhead = document.querySelector("#playhead");
const beatNumber = document.querySelector("#beatNumber");
const cueAction = document.querySelector("#cueAction");
const cueDetail = document.querySelector("#cueDetail");
const cueNext = document.querySelector("#cueNext");
const COLORS = {
pluck: 0xff8b62,
strike: 0xffd166,
blow: 0x59ddd1,
bench: 0x162638,
benchEdge: 0x23384a,
dark: 0x0b1622,
pale: 0xd7e6e7
};
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09121d);
scene.fog = new THREE.Fog(0x09121d, 18, 40);
const camera = new THREE.PerspectiveCamera(38, window.innerWidth / window.innerHeight, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.25, 0);
const cameraGoal = {
radius: window.innerWidth < 700 ? 20 : 14.4,
theta: 0.28,
phi: 1.16
};
const cameraNow = { ...cameraGoal };
function updateCamera(dt) {
const ease = 1 - Math.exp(-dt * 7);
cameraNow.radius += (cameraGoal.radius - cameraNow.radius) * ease;
cameraNow.theta += (cameraGoal.theta - cameraNow.theta) * ease;
cameraNow.phi += (cameraGoal.phi - cameraNow.phi) * ease;
const sinPhi = Math.sin(cameraNow.phi);
camera.position.set(
cameraTarget.x + cameraNow.radius * sinPhi * Math.sin(cameraNow.theta),
cameraTarget.y + cameraNow.radius * Math.cos(cameraNow.phi),
cameraTarget.z + cameraNow.radius * sinPhi * Math.cos(cameraNow.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera(1);
const hemi = new THREE.HemisphereLight(0xbfe9ff, 0x15202d, 1.65);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff1d7, 3.1);
key.position.set(4, 10, 8);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -12;
key.shadow.camera.right = 12;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -8;
key.shadow.camera.near = 1;
key.shadow.camera.far = 32;
key.shadow.bias = -0.0004;
scene.add(key);
const rim = new THREE.DirectionalLight(0x5edbd4, 1.5);
rim.position.set(-7, 5, -5);
scene.add(rim);
const warm = new THREE.PointLight(COLORS.pluck, 15, 10, 2);
warm.position.set(-4.5, 3, 2);
scene.add(warm);
const gold = new THREE.PointLight(COLORS.strike, 12, 9, 2);
gold.position.set(0, 2.7, 1.4);
scene.add(gold);
const cyan = new THREE.PointLight(COLORS.blow, 14, 10, 2);
cyan.position.set(4.5, 2.7, 1.5);
scene.add(cyan);
const standard = (color, roughness = 0.58, metalness = 0.18) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(r1, r2, h, material, x, y, z, parent = scene, segments = 48) {
const mesh = new THREE.Mesh(new THREE.CylinderGeometry(r1, r2, h, segments), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function torus(radius, tube, material, x, y, z, parent = scene, radial = 12, tubular = 64) {
const mesh = new THREE.Mesh(new THREE.TorusGeometry(radius, tube, radial, tubular), material);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function roundRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabel(index, title, subtitle, colorHex) {
const c = document.createElement("canvas");
c.width = 768;
c.height = 220;
const ctx = c.getContext("2d");
const color = `#${new THREE.Color(colorHex).getHexString()}`;
ctx.clearRect(0, 0, c.width, c.height);
roundRect(ctx, 8, 8, 752, 204, 34);
ctx.fillStyle = "rgba(8,18,29,.90)";
ctx.fill();
ctx.strokeStyle = "rgba(220,240,245,.22)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = color;
ctx.fillRect(35, 35, 7, 150);
ctx.font = "800 30px system-ui";
ctx.fillText(index, 66, 61);
ctx.font = "750 58px system-ui";
ctx.fillStyle = "#edf7f7";
ctx.fillText(title, 66, 126);
ctx.font = "650 24px system-ui";
ctx.fillStyle = color;
ctx.fillText(subtitle.toUpperCase(), 68, 169);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.scale.set(2.75, 0.79, 1);
sprite.renderOrder = 10;
scene.add(sprite);
return sprite;
}
// Room and bench.
const floorMat = standard(0x0c1723, 0.9, 0.05);
const floor = new THREE.Mesh(new THREE.PlaneGeometry(60, 60), floorMat);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.62;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(40, 40, 0x2b4a5b, 0x172a38);
grid.position.y = -1.605;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
const backdrop = new THREE.Mesh(
new THREE.PlaneGeometry(36, 18),
new THREE.MeshStandardMaterial({ color: 0x0b1723, roughness: 1, metalness: 0 })
);
backdrop.position.set(0, 4.2, -5.1);
backdrop.receiveShadow = true;
scene.add(backdrop);
const benchMat = standard(COLORS.bench, 0.55, 0.32);
const edgeMat = standard(COLORS.benchEdge, 0.42, 0.35);
const darkMat = standard(COLORS.dark, 0.64, 0.22);
box(14.8, 0.34, 4.2, benchMat, 0, 0, 0);
box(14.45, 0.45, 0.18, edgeMat, 0, -0.28, 1.96);
box(14.45, 0.12, 0.16, darkMat, 0, 0.11, 2.03);
for (const x of [-6.35, 6.35]) {
for (const z of [-1.48, 1.48]) {
box(0.36, 1.55, 0.36, darkMat, x, -0.95, z);
box(0.55, 0.10, 0.55, edgeMat, x, -1.70, z);
}
}
const stationXs = [-4.45, 0, 4.45];
const accents = [COLORS.pluck, COLORS.strike, COLORS.blow];
const stations = {};
function stationBase(x, color) {
const g = new THREE.Group();
g.position.set(x, 0, 0.05);
scene.add(g);
box(3.05, 0.16, 1.85, darkMat, 0, 0.26, 0, g);
box(2.85, 0.055, 1.65, edgeMat, 0, 0.36, 0, g);
const haloMat = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.16,
side: THREE.DoubleSide,
depthWrite: false
});
const halo = new THREE.Mesh(new THREE.RingGeometry(1.31, 1.39, 80), haloMat);
halo.rotation.x = -Math.PI / 2;
halo.position.set(0, 0.405, 0.12);
g.add(halo);
const backMat = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.095,
depthWrite: false
});
const arch = torus(1.48, 0.015, backMat, 0, 1.87, -1.22, g);
arch.scale.y = 1.14;
return { group: g, halo, haloMat, arch, backMat };
}
const pluckStation = stationBase(stationXs[0], COLORS.pluck);
const strikeStation = stationBase(stationXs[1], COLORS.strike);
const blowStation = stationBase(stationXs[2], COLORS.blow);
// Instrument 1: Torsion Lyre — a teaching frame with independently pluckable strings.
const pluckGroup = pluckStation.group;
const frameMat = standard(0x365264, 0.42, 0.42);
const stringFrameMat = standard(0x8aa2ab, 0.38, 0.52);
const pluckBodyMat = standard(0x7f3f38, 0.56, 0.2);
const pluckAccentMat = new THREE.MeshStandardMaterial({
color: COLORS.pluck,
emissive: COLORS.pluck,
emissiveIntensity: 0.18,
roughness: 0.35,
metalness: 0.25
});
box(2.48, 0.34, 1.18, pluckBodyMat, 0, 0.61, 0.08, pluckGroup);
box(2.62, 0.08, 1.28, edgeMat, 0, 0.80, 0.08, pluckGroup);
box(0.13, 2.35, 0.18, frameMat, -1.14, 1.90, 0.02, pluckGroup);
box(0.13, 2.35, 0.18, frameMat, 1.14, 1.90, 0.02, pluckGroup);
box(2.40, 0.15, 0.20, frameMat, 0, 3.03, 0.02, pluckGroup);
box(2.18, 0.065, 0.12, stringFrameMat, 0, 2.72, 0.29, pluckGroup);
box(2.18, 0.065, 0.12, stringFrameMat, 0, 0.91, 0.29, pluckGroup);
const pluckStrings = [];
for (let i = 0; i < 7; i++) {
const x = -0.86 + i * (1.72 / 6);
const geo = new THREE.BufferGeometry();
geo.setAttribute("position", new THREE.Float32BufferAttribute([
x, 2.70, 0.32,
x, 1.80, 0.32,
x, 0.92, 0.32
], 3));
const color = new THREE.Color(COLORS.pluck).lerp(new THREE.Color(COLORS.pale), i / 9);
const mat = new THREE.LineBasicMaterial({ color, transparent: true, opacity: 0.95 });
const line = new THREE.Line(geo, mat);
pluckGroup.add(line);
pluckStrings.push({ line, geo, x, mat, baseColor: color.clone() });
const bridge = new THREE.Mesh(
new THREE.SphereGeometry(0.035, 10, 8),
new THREE.MeshStandardMaterial({
color: COLORS.pale,
emissive: COLORS.pluck,
emissiveIntensity: 0.12,
roughness: 0.4
})
);
bridge.position.set(x, 0.92, 0.32);
pluckGroup.add(bridge);
}
const pickGroup = new THREE.Group();
pluckGroup.add(pickGroup);
const pickHead = new THREE.Mesh(new THREE.SphereGeometry(0.115, 20, 14), pluckAccentMat);
pickHead.scale.set(1, 1.25, 0.52);
pickGroup.add(pickHead);
const pickTip = new THREE.Mesh(new THREE.ConeGeometry(0.12, 0.28, 3), pluckAccentMat);
pickTip.rotation.z = -Math.PI / 2;
pickTip.position.x = 0.16;
pickGroup.add(pickTip);
const pluckLabel = makeLabel("01", "Torsion Lyre", "Pluck / release", COLORS.pluck);
pluckLabel.position.set(stationXs[0], 3.72, 0.08);
// Instrument 2: Pulse Membrane — a struck teaching drum with a hinged mallet.
const strikeGroup = strikeStation.group;
const strikeBodyMat = standard(0x6b5737, 0.58, 0.22);
const strikeTrimMat = new THREE.MeshStandardMaterial({
color: COLORS.strike,
emissive: COLORS.strike,
emissiveIntensity: 0.12,
roughness: 0.32,
metalness: 0.42
});
const skinMat = standard(0xe1c795, 0.84, 0.03);
const skinEdgeMat = standard(0x273340, 0.5, 0.3);
box(2.62, 0.19, 1.18, strikeBodyMat, 0, 0.55, 0.02, strikeGroup);
box(2.73, 0.055, 1.27, edgeMat, 0, 0.67, 0.02, strikeGroup);
const drum = cylinder(0.86, 0.91, 0.28, strikeBodyMat, 0, 1.77, 0.04, strikeGroup);
drum.rotation.x = Math.PI / 2;
const membrane = new THREE.Mesh(new THREE.CircleGeometry(0.78, 64), skinMat);
membrane.position.set(0, 1.77, 0.185);
membrane.receiveShadow = true;
strikeGroup.add(membrane);
torus(0.82, 0.075, strikeTrimMat, 0, 1.77, 0.19, strikeGroup);
torus(0.69, 0.018, skinEdgeMat, 0, 1.77, 0.194, strikeGroup);
for (const x of [-0.92, 0, 0.92]) {
box(0.17, 0.25, 0.22, edgeMat, x, 0.82, 0.02, strikeGroup);
}
const malletPivot = new THREE.Group();
malletPivot.position.set(1.45, 2.85, 0.39);
strikeGroup.add(malletPivot);
const handleMat = standard(0xb18456, 0.5, 0.24);
const handle = cylinder(0.045, 0.06, 1.78, handleMat, 0, -0.89, 0, malletPivot, 20);
const malletHead = new THREE.Mesh(new THREE.SphereGeometry(0.19, 24, 16), strikeTrimMat);
malletHead.position.set(0, -1.78, 0);
malletHead.castShadow = true;
malletPivot.add(malletHead);
const shockRings = [];
for (let i = 0; i < 3; i++) {
const mat = new THREE.MeshBasicMaterial({
color: COLORS.strike,
transparent: true,
opacity: 0,
depthWrite: false
});
const ring = torus(0.30, 0.012, mat, 0, 1.77, 0.205, strikeGroup);
shockRings.push({ ring, mat });
}
const strikeLabel = makeLabel("02", "Pulse Membrane", "Strike / rebound", COLORS.strike);
strikeLabel.position.set(stationXs[1], 3.72, 0.08);
// Instrument 3: Aeolian Reed — an original looped air column with a visible breath inlet.
const blowGroup = blowStation.group;
const tubeMat = new THREE.MeshStandardMaterial({
color: 0x2d666a,
emissive: COLORS.blow,
emissiveIntensity: 0.11,
roughness: 0.34,
metalness: 0.5
});
const tubeTrimMat = new THREE.MeshStandardMaterial({
color: COLORS.blow,
emissive: COLORS.blow,
emissiveIntensity: 0.28,
roughness: 0.3,
metalness: 0.4
});
box(2.56, 0.18, 1.18, darkMat, 0, 0.54, 0.02, blowGroup);
box(2.69, 0.06, 1.29, edgeMat, 0, 0.66, 0.02, blowGroup);
const tubeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.55, 0.86, 0.02),
new THREE.Vector3(-0.55, 2.13, 0.02),
new THREE.Vector3(-0.16, 2.82, 0.02),
new THREE.Vector3(0.55, 2.82, 0.02),
new THREE.Vector3(0.80, 2.28, 0.02),
new THREE.Vector3(0.80, 1.05, 0.02),
new THREE.Vector3(0.96, 0.77, 0.02)
]);
const airColumn = new THREE.Mesh(new THREE.TubeGeometry(tubeCurve, 96, 0.115, 12, false), tubeMat);
airColumn.castShadow = true;
blowGroup.add(airColumn);
const mouthpiece = cylinder(0.17, 0.14, 0.56, tubeTrimMat, -0.88, 2.13, 0.02, blowGroup, 32);
mouthpiece.rotation.z = Math.PI / 2;
const reed = box(0.11, 0.42, 0.15, tubeTrimMat, -0.62, 2.13, 0.08, blowGroup);
const reedPivot = new THREE.Group();
reedPivot.position.set(-0.62, 2.13, 0.10);
blowGroup.remove(reed);
const reedLeaf = box(0.085, 0.39, 0.12, tubeTrimMat, 0, 0, 0, reedPivot);
blowGroup.add(reedPivot);
const holeMat = new THREE.MeshStandardMaterial({ color: 0x061015, roughness: 0.8 });
for (const [x, y] of [[-0.55, 1.28], [0.80, 1.55], [0.80, 2.02]]) {
const hole = new THREE.Mesh(new THREE.CircleGeometry(0.065, 20), holeMat);
hole.position.set(x, y, 0.139);
blowGroup.add(hole);
torus(0.072, 0.012, tubeTrimMat, x, y, 0.145, blowGroup);
}
const breathParticles = [];
for (let i = 0; i < 16; i++) {
const mat = new THREE.MeshBasicMaterial({
color: COLORS.blow,
transparent: true,
opacity: 0,
depthWrite: false
});
const particle = new THREE.Mesh(new THREE.SphereGeometry(0.07, 10, 8), mat);
blowGroup.add(particle);
breathParticles.push({ particle, mat });
}
const breathRings = [];
for (let i = 0; i < 3; i++) {
const mat = new THREE.MeshBasicMaterial({
color: COLORS.blow,
transparent: true,
opacity: 0,
depthWrite: false
});
const ring = torus(0.16, 0.012, mat, -1.33, 2.13, 0.16, blowGroup);
ring.rotation.y = Math.PI / 2;
breathRings.push({ ring, mat });
}
const blowLabel = makeLabel("03", "Aeolian Reed", "Blow / sustain", COLORS.blow);
blowLabel.position.set(stationXs[2], 3.72, 0.08);
// Subtle ambient dust.
const dustCount = 110;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 20;
dustPositions[i * 3 + 1] = -1 + Math.random() * 8;
dustPositions[i * 3 + 2] = -4 + Math.random() * 10;
}
const dustGeo = new THREE.BufferGeometry();
dustGeo.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(dustGeo, new THREE.PointsMaterial({
color: 0xcbe8e8,
size: 0.024,
transparent: true,
opacity: 0.25,
depthWrite: false
}));
scene.add(dust);
// Physical beat rail on the front of the bench.
const beatLeds = [];
for (let i = 0; i < 16; i++) {
const color = accents[i % 3];
const mat = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.15,
roughness: 0.4
});
const led = box(0.42, 0.075, 0.055, mat, -6.6 + i * 0.88, -0.25, 2.075);
beatLeds.push({ led, mat, base: 0.15 });
}
// Interaction proxies.
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const pickTargets = [];
for (let i = 0; i < 3; i++) {
const hit = new THREE.Mesh(new THREE.BoxGeometry(3.1, 3.35, 2.1), hitMaterial);
hit.position.set(stationXs[i], 1.9, 0);
hit.userData.type = ["pluck", "strike", "blow"][i];
scene.add(hit);
pickTargets.push(hit);
}
// Timing score. Every beat contains one gesture.
const events = [
{ beat: 0, type: "pluck", label: "String 1 · E4", freq: 329.63, string: 0 },
{ beat: 1, type: "strike", label: "Membrane · low tone", freq: 146.83 },
{ beat: 2, type: "pluck", label: "String 3 · G4", freq: 392.00, string: 2 },
{ beat: 3, type: "blow", label: "Reed · airy phrase", freq: 523.25 },
{ beat: 4, type: "pluck", label: "String 4 · A4", freq: 440.00, string: 3 },
{ beat: 5, type: "strike", label: "Membrane · low tone", freq: 146.83 },
{ beat: 6, type: "pluck", label: "String 5 · B3", freq: 246.94, string: 4 },
{ beat: 7, type: "blow", label: "Reed · airy phrase", freq: 587.33 },
{ beat: 8, type: "pluck", label: "String 1 · E4", freq: 329.63, string: 0 },
{ beat: 9, type: "strike", label: "Membrane · low tone", freq: 146.83 },
{ beat: 10, type: "pluck", label: "String 6 · C4", freq: 261.63, string: 5 },
{ beat: 11, type: "blow", label: "Reed · airy phrase", freq: 523.25 },
{ beat: 12, type: "pluck", label: "String 7 · G4", freq: 392.00, string: 6 },
{ beat: 13, type: "strike", label: "Membrane · low tone", freq: 146.83 },
{ beat: 14, type: "pluck", label: "String 2 · A4", freq: 440.00, string: 1 },
{ beat: 15, type: "blow", label: "Reed · airy phrase", freq: 659.25 }
];
const markerElements = [];
events.forEach((event, index) => {
const marker = document.createElement("div");
marker.className = `marker ${event.type}`;
marker.style.left = `${((event.beat + 0.5) / 16) * 100}%`;
marker.title = `Beat ${event.beat + 1}: ${event.type}`;
track.appendChild(marker);
markerElements.push(marker);
});
stations.pluck = {
...pluckStation,
actionStart: -100,
actionSerial: 0,
selectedString: 0,
event: null
};
stations.strike = {
...strikeStation,
actionStart: -100,
actionSerial: 0,
event: null
};
stations.blow = {
...blowStation,
actionStart: -100,
actionSerial: 0,
event: null
};
let tempo = Number(tempoInput.value);
let beatDuration = 60 / tempo;
let playing = false;
let started = false;
let globalBeat = 0;
let nextEventIndex = 0;
let soundOn = false;
let audioContext = null;
let masterGain = null;
let noiseBuffer = null;
let currentCueType = "";
// Optional synthesized audio. It is deliberately generated in the browser.
function ensureAudio() {
if (!audioContext) {
const AudioCtx = window.AudioContext || window.webkitAudioContext;
if (!AudioCtx) return null;
audioContext = new AudioCtx();
const compressor = audioContext.createDynamicsCompressor();
compressor.threshold.value = -18;
compressor.knee.value = 18;
compressor.ratio.value = 4;
compressor.attack.value = 0.004;
compressor.release.value = 0.22;
masterGain = audioContext.createGain();
masterGain.gain.value = 0.52;
masterGain.connect(compressor);
compressor.connect(audioContext.destination);
noiseBuffer = audioContext.createBuffer(1, audioContext.sampleRate, audioContext.sampleRate);
const data = noiseBuffer.getChannelData(0);
for (let i = 0; i < data.length; i++) data[i] = Math.random() * 2 - 1;
}
if (audioContext.state === "suspended") audioContext.resume();
return audioContext;
}
function synthPluck(freq, when) {
const gain = audioContext.createGain();
const filter = audioContext.createBiquadFilter();
filter.type = "lowpass";
filter.frequency.setValueAtTime(2600, when);
filter.frequency.exponentialRampToValueAtTime(650, when + 0.72);
const osc = audioContext.createOscillator();
osc.type = "triangle";
osc.frequency.setValueAtTime(freq, when);
const harmonic = audioContext.createOscillator();
harmonic.type = "sine";
harmonic.frequency.setValueAtTime(freq * 2.01, when);
const harmonicGain = audioContext.createGain();
harmonicGain.gain.setValueAtTime(0.34, when);
harmonicGain.gain.exponentialRampToValueAtTime(0.001, when + 0.34);
gain.gain.setValueAtTime(0.0001, when);
gain.gain.exponentialRampToValueAtTime(0.24, when + 0.006);
gain.gain.exponentialRampToValueAtTime(0.0001, when + 0.82);
osc.connect(filter);
filter.connect(gain);
gain.connect(masterGain);
harmonic.connect(harmonicGain);
harmonicGain.connect(gain);
osc.start(when);
harmonic.start(when);
osc.stop(when + 0.9);
harmonic.stop(when + 0.4);
}
function synthStrike(freq, when) {
const osc = audioContext.createOscillator();
const gain = audioContext.createGain();
osc.type = "sine";
osc.frequency.setValueAtTime(freq * 1.85, when);
osc.frequency.exponentialRampToValueAtTime(freq * 0.66, when + 0.16);
gain.gain.setValueAtTime(0.0001, when);
gain.gain.exponentialRampToValueAtTime(0.42, when + 0.004);
gain.gain.exponentialRampToValueAtTime(0.0001, when + 0.43);
osc.connect(gain);
gain.connect(masterGain);
osc.start(when);
osc.stop(when + 0.46);
const source = audioContext.createBufferSource();
source.buffer = noiseBuffer;
const highpass = audioContext.createBiquadFilter();
highpass.type = "highpass";
highpass.frequency.value = 950;
const noiseGain = audioContext.createGain();
noiseGain.gain.setValueAtTime(0.13, when);
noiseGain.gain.exponentialRampToValueAtTime(0.0001, when + 0.07);
source.connect(highpass);
highpass.connect(noiseGain);
noiseGain.connect(masterGain);
source.start(when);
source.stop(when + 0.09);
}
function synthBlow(freq, when) {
const source = audioContext.createBufferSource();
source.buffer = noiseBuffer;
source.loop = true;
const band = audioContext.createBiquadFilter();
band.type = "bandpass";
band.frequency.setValueAtTime(freq * 1.25, when);
band.frequency.linearRampToValueAtTime(freq * 1.75, when + 0.35);
band.Q.value = 1.15;
const gain = audioContext.createGain();
gain.gain.setValueAtTime(0.0001, when);
gain.gain.exponentialRampToValueAtTime(0.12, when + 0.09);
gain.gain.setValueAtTime(0.12, when + 0.42);
gain.gain.exponentialRampToValueAtTime(0.0001, when + 0.92);
source.connect(band);
band.connect(gain);
gain.connect(masterGain);
source.start(when);
source.stop(when + 0.96);
const tone = audioContext.createOscillator();
const toneGain = audioContext.createGain();
tone.type = "sine";
tone.frequency.setValueAtTime(freq * 0.5, when);
tone.frequency.linearRampToValueAtTime(freq * 0.58, when + 0.7);
toneGain.gain.setValueAtTime(0.0001, when);
toneGain.gain.exponentialRampToValueAtTime(0.045, when + 0.16);
toneGain.gain.exponentialRampToValueAtTime(0.0001, when + 0.85);
tone.connect(toneGain);
toneGain.connect(masterGain);
tone.start(when);
tone.stop(when + 0.9);
}
function playActionSound(type, freq) {
if (!soundOn || !ensureAudio()) return;
const when = audioContext.currentTime + 0.006;
if (type === "pluck") synthPluck(freq, when);
if (type === "strike") synthStrike(freq, when);
if (type === "blow") synthBlow(freq, when);
}
function setCue(type, detail) {
currentCueType = type;
cueAction.textContent = type;
cueAction.style.color = type === "pluck"
? "#ff9a78"
: type === "strike"
? "#ffd166"
: type === "blow"
? "#59ddd1"
: "#edf7f7";
cueDetail.textContent = detail;
}
function triggerAction(type, event = {}, markerIndex = -1) {
const now = performance.now();
const station = stations[type];
station.actionStart = now;
station.actionSerial++;
station.event = event;
if (type === "pluck") {
station.selectedString = event.string ?? (station.actionSerial % 7);
const freq = event.freq ?? [329.63, 369.99, 392, 440, 493.88, 523.25, 587.33][station.selectedString];
event.freq = freq;
}
playActionSound(type, event.freq ?? 440);
setCue(type, event.label || "Manual practice cue");
if (markerIndex >= 0) {
const marker = markerElements[markerIndex];
marker.classList.add("active");
window.setTimeout(() => marker.classList.remove("active"), 150);
}
}
function startSequence() {
started = true;
playing = true;
globalBeat = 0;
nextEventIndex = 0;
triggerAction(events[0].type, events[0], 0);
nextEventIndex = 1;
playButton.textContent = "Pause";
playButton.setAttribute("aria-label", "Pause timing sequence");
}
playButton.addEventListener("click", () => {
if (!started) {
startSequence();
return;
}
playing = !playing;
playButton.textContent = playing ? "Pause" : "Run";
playButton.setAttribute("aria-label", playing ? "Pause timing sequence" : "Resume timing sequence");
});
soundButton.addEventListener("click", async () => {
soundOn = !soundOn;
soundButton.classList.toggle("active", soundOn);
soundButton.setAttribute("aria-pressed", String(soundOn));
soundButton.textContent = soundOn ? "SFX On" : "SFX Off";
if (soundOn) {
await ensureAudio();
cueNext.textContent = "Synthetic sound enabled · visuals remain primary";
}
});
tempoInput.addEventListener("input", () => {
tempo = Number(tempoInput.value);
beatDuration = 60 / tempo;
tempoValue.textContent = String(tempo);
});
// Direct camera controls: orbit, elevation, and zoom without addons.
let pointerDown = false;
let pointerMoved = 0;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", event => {
pointerDown = true;
pointerMoved = 0;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointerDown) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
pointerMoved += Math.abs(dx) + Math.abs(dy);
cameraGoal.theta -= dx * 0.005;
cameraGoal.phi = THREE.MathUtils.clamp(cameraGoal.phi + dy * 0.004, 0.72, 1.47);
});
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
canvas.addEventListener("pointerup", event => {
if (pointerDown && pointerMoved < 7) {
const rect = canvas.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hit = raycaster.intersectObjects(pickTargets, false)[0];
if (hit) {
const type = hit.object.userData.type;
const frequencies = { pluck: 392, strike: 146.83, blow: 523.25 };
triggerAction(type, {
label: "Manual practice cue",
freq: frequencies[type]
});
}
}
pointerDown = false;
});
canvas.addEventListener("pointercancel", () => { pointerDown = false; });
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraGoal.radius = THREE.MathUtils.clamp(
cameraGoal.radius + event.deltaY * 0.008,
9.5,
28
);
}, { passive: false });
const clock = new THREE.Clock();
const tempColor = new THREE.Color();
function actionAge(station) {
return (performance.now() - station.actionStart) / 1000;
}
function updatePluck(now) {
const st = stations.pluck;
const age = actionAge(st);
const env = age >= 0 && age < 0.72 ? Math.sin(Math.min(age / 0.72, 1) * Math.PI) : 0;
st.haloMat.opacity = 0.13 + env * 0.50;
st.halo.scale.setScalar(1 + env * 0.18);
pluckAccentMat.emissiveIntensity = 0.16 + env * 1.2;
pluckStrings.forEach((string, index) => {
let pull = 0;
if (index === st.selectedString && age >= 0.16 && age < 0.52) {
pull = Math.sin(((age - 0.16) / 0.36) * Math.PI);
}
const attr = string.geo.attributes.position;
attr.setXYZ(1, string.x + pull * 0.08, 1.80, 0.32 + pull * 0.34);
attr.needsUpdate = true;
string.mat.color.copy(string.baseColor).lerp(tempColor.set(0xffffff), pull * 0.55);
});
const targetX = pluckStrings[st.selectedString]?.x ?? 0;
let px = 1.3;
let pz = 1.05;
let py = 1.72;
if (age >= 0 && age < 0.16) {
const t = THREE.MathUtils.smoothstep(age, 0, 0.16);
px = THREE.MathUtils.lerp(1.3, targetX, t);
pz = THREE.MathUtils.lerp(1.05, 0.35, t);
} else if (age < 0.52) {
const pull = Math.sin(((age - 0.16) / 0.36) * Math.PI);
px = targetX;
pz = 0.35 + pull * 0.34;
} else if (age < 0.85) {
const t = THREE.MathUtils.smoothstep(age, 0.52, 0.85);
px = THREE.MathUtils.lerp(targetX, 1.3, t);
pz = THREE.MathUtils.lerp(0.35, 1.05, t);
}
pickGroup.position.set(px, py, pz);
pickGroup.rotation.z = -0.18 + env * 0.16;
pickGroup.visible = age < 0.9 || age > 4;
}
function updateStrike(now) {
const st = stations.strike;
const age = actionAge(st);
const raised = -0.12;
const contact = -0.92;
const rebound = -0.43;
let angle = raised;
let impact = 0;
if (age >= 0 && age < 0.16) {
const t = age / 0.16;
angle = THREE.MathUtils.lerp(raised, contact, t * t);
} else if (age < 0.31) {
angle = THREE.MathUtils.lerp(contact, rebound, THREE.MathUtils.smoothstep(age, 0.16, 0.31));
impact = Math.sin(((age - 0.16) / 0.15) * Math.PI);
} else if (age < 0.72) {
angle = THREE.MathUtils.lerp(rebound, raised, THREE.MathUtils.smoothstep(age, 0.31, 0.72));
}
malletPivot.rotation.z = angle;
const env = age >= 0 && age < 0.75 ? Math.sin(Math.min(age / 0.75, 1) * Math.PI) : 0;
st.haloMat.opacity = 0.13 + env * 0.5;
st.halo.scale.setScalar(1 + env * 0.17);
strikeTrimMat.emissiveIntensity = 0.12 + impact * 1.8;
const membraneScale = 1 + impact * 0.055;
membrane.scale.set(membraneScale, membraneScale, 1);
shockRings.forEach((entry, i) => {
const p = age - (0.15 + i * 0.10);
if (p >= 0 && p < 0.48) {
const t = p / 0.48;
entry.ring.scale.setScalar(1 + t * 2.35);
entry.mat.opacity = (1 - t) * 0.72;
} else {
entry.mat.opacity = 0;
}
});
}
function updateBlow(now) {
const st = stations.blow;
const age = actionAge(st);
const active = age >= 0 && age < 1.15;
const env = active ? Math.sin(Math.min(age / 1.15, 1) * Math.PI) : 0;
st.haloMat.opacity = 0.13 + env * 0.46;
st.halo.scale.setScalar(1 + env * 0.15);
tubeMat.emissiveIntensity = 0.11 + env * 0.75;
tubeTrimMat.emissiveIntensity = 0.25 + env * 1.1;
reedPivot.rotation.z = Math.sin(now * 0.052) * 0.045 * env;
breathParticles.forEach((entry, i) => {
if (!active) {
entry.mat.opacity = 0;
entry.particle.visible = false;
return;
}
const p = (age * 1.75 + i / breathParticles.length) % 1;
entry.particle.visible = true;
entry.particle.position.set(
-1.88 + p * 0.72,
2.13 + Math.sin(i * 2.1 + age * 12) * 0.035,
0.27 + Math.cos(i * 1.7) * 0.025
);
const s = 0.72 + Math.sin(p * Math.PI) * 0.45;
entry.particle.scale.setScalar(s);
entry.mat.opacity = Math.sin(p * Math.PI) * 0.68;
});
breathRings.forEach((entry, i) => {
const p = age * 1.5 - i * 0.17;
const t = ((p % 1) + 1) % 1;
if (active) {
entry.ring.position.x = -1.72 + t * 0.44;
entry.ring.scale.setScalar(0.75 + t * 1.6);
entry.mat.opacity = (1 - t) * 0.62;
} else {
entry.mat.opacity = 0;
}
});
}
function updateTimeline() {
const loopBeat = ((globalBeat % 16) + 16) % 16;
playhead.style.left = `${(loopBeat / 16) * 100}%`;
beatNumber.textContent = String(Math.floor(loopBeat) + 1).padStart(2, "0");
const current = Math.floor(loopBeat);
beatLeds.forEach((entry, i) => {
const distance = Math.min(
Math.abs(i - current),
Math.abs(i - current + 16),
Math.abs(i - current - 16)
);
entry.mat.emissiveIntensity = distance === 0 ? 1.6 : distance === 1 ? 0.42 : 0.12;
});
if (playing && nextEventIndex < events.length) {
const next = events[nextEventIndex];
const seconds = Math.max(0, (next.beat - globalBeat) * beatDuration);
cueNext.textContent = `Next: ${next.type} in ${seconds.toFixed(1)} s`;
} else if (!started) {
cueNext.textContent = "Next: pluck";
}
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
if (playing) {
globalBeat += dt / beatDuration;
while (nextEventIndex < events.length && events[nextEventIndex].beat <= globalBeat) {
const event = events[nextEventIndex];
triggerAction(event.type, event, nextEventIndex);
nextEventIndex++;
}
if (globalBeat >= 16) {
globalBeat -= 16;
nextEventIndex = 0;
triggerAction(events[0].type, events[0], 0);
nextEventIndex = 1;
}
}
updateCamera(dt);
updatePluck(now);
updateStrike(now);
updateBlow(now);
updateTimeline();
dust.rotation.y = now * 0.000018;
dust.position.y = Math.sin(now * 0.00013) * 0.08;
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
if (window.innerWidth < 700 && cameraNow.radius < 18) {
cameraGoal.radius = 20;
}
});
animate();
</script>
</body>
</html>
```