threejs-audio
Skill13 starsChanged 7 months agoMITView on GitHub
Adds spatial and non-spatial audio to Three.js scenes using AudioListener, Audio, PositionalAudio, AudioAnalyser, and AudioLoader. Use when the user asks about 3D audio, spatial sound, positional audio, audio visualization, background music, or Web Audio API integration. Trigger keywords: audio, sound, PositionalAudio, AudioListener, AudioAnalyser, spatial audio, 3D sound, music visualization.
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 132
Use new THREE.Audio(listener) for one-shot effects (not reusing the same Audio object)
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Three.js Audio
Setup — AudioListener
// One AudioListener per scene, attached to camera
const listener = new THREE.AudioListener();
camera.add(listener);Global (Non-Spatial) Audio
const sound = new THREE.Audio(listener);
const loader = new THREE.AudioLoader();
// Async load
const buffer = await loader.loadAsync("/audio/music.mp3");
sound.setBuffer(buffer);
sound.setLoop(true);
sound.setVolume(0.5);
// Must start on user gesture (browser autoplay policy)
document.addEventListener("click", () => sound.play(), { once: true });
// Controls
sound.pause();
sound.stop();
sound.isPlaying; // boolean
sound.offset = 10; // start at 10 seconds
sound.playbackRate = 1.5; // 1.5x speedPositional (Spatial) Audio
// Sound whose volume/pan changes based on distance and angle to camera
const posSound = new THREE.PositionalAudio(listener);
const buffer = await new THREE.AudioLoader().loadAsync("/audio/engine.mp3");
posSound.setBuffer(buffer);
posSound.setLoop(true);
posSound.setRefDistance(2); // distance at which volume = 1 (full)
posSound.setRolloffFactor(1); // how fast volume drops with distance
posSound.setDistanceModel("inverse"); // 'linear', 'inverse', 'exponential'
posSound.setMaxDistance(50); // beyond this distance, volume = 0
posSound.setDirectionalCone(180, 360, 0.1); // innerAngle, outerAngle, outerGain
// Attach to a mesh — sound follows the object
mesh.add(posSound);
document.addEventListener("click", () => posSound.play(), { once: true });AudioAnalyser (visualization)
const analyser = new THREE.AudioAnalyser(sound, 32); // sound, fftSize
function animate() {
requestAnimationFrame(animate);
const data = analyser.getFrequencyData(); // Uint8Array, length = fftSize/2
const avg = analyser.getAverageFrequency(); // 0–255
// Drive visuals with audio data
mesh.scale.setScalar(1 + avg / 255);
// Per-frequency band control
for (let i = 0; i < data.length; i++) {
bars[i].scale.y = (data[i] / 255) * maxHeight;
}
renderer.render(scene, camera);
}Web Audio API (direct access)
// Access underlying Web Audio context and nodes
const audioContext = listener.context;
// Create filter
const filter = audioContext.createBiquadFilter();
filter.type = "lowpass";
filter.frequency.value = 1000;
// Connect: source → filter → destination
sound.setFilter(filter);
// Gain control
sound.setVolume(0.8); // wraps GainNode
// Access raw audio node
const gainNode = sound.gain; // GainNode
gainNode.gain.setValueAtTime(0, audioContext.currentTime);
gainNode.gain.linearRampToValueAtTime(1, audioContext.currentTime + 2);Multiple Sounds / Preloading
const manager = new THREE.LoadingManager();
const loader = new THREE.AudioLoader(manager);
const sounds = {};
sounds.jump = await loader.loadAsync("/audio/jump.wav");
sounds.land = await loader.loadAsync("/audio/land.wav");
sounds.music = await loader.loadAsync("/audio/bg.mp3");
function playJump() {
const s = new THREE.Audio(listener);
s.setBuffer(sounds.jump);
s.play();
// one-shot: auto-cleanup on end
s.onEnded = () => s.disconnect();
}Common Gotchas
- Browsers block autoplay — always start audio inside a user gesture handler (
click,touchstart) - One
AudioListenerper scene — multiple listeners cause unexpected behavior PositionalAudiomust be added to anObject3D(mesh, group) to be positionedAudioAnalyserfftSize must be a power of 2 between 32 and 32768 — data array length = fftSize / 2sound.stop()resets playback position —sound.pause()preserves it- Use
new THREE.Audio(listener)for one-shot effects (not reusing the same Audio object) - Audio context may be in 'suspended' state until first user interaction — check
listener.context.state
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 1
- FkennedyFox/claude-skills★ 0100% same
Wrote their own version · 1
- full-stack-skills/threejs-skills★ 9same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository15 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/llms.txtllms.txt
- threejs-animationSkill
- threejs-cameraSkill
- threejs-coreSkill
- threejs-geometrySkill
- threejs-lightingSkill
- threejs-loadersSkill
- threejs-materialsSkill
- threejs-performanceSkill
- threejs-physicsSkill
- threejs-postprocessingSkill
- threejs-reactSkill
- threejs-shadersSkill
- threejs-xrSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

