threejs-audio
$
npx mdskill add partme-ai/full-stack-skills/threejs-audioEnables 3D audio spatialization in three.js for sound placement, panner configuration, and visualization.
- Helps developers implement spatial audio effects and manage browser autoplay policies.
- Integrates with three.js AudioListener, Audio, PositionalAudio, AudioAnalyser, and Web Audio API.
- Triggers on mentions of audio components, distance models, or visualization needs.
- Provides guidance on setup steps and references external loaders for file decoding.
SKILL.md
.github/skills/threejs-audioView on GitHub ↗
---
name: threejs-audio
description: "three.js audio spatialization: AudioListener attached to camera rig, Audio and PositionalAudio sources, AudioAnalyser for FFT/time-domain data, and integration with Web Audio API contexts; AudioLoader is referenced from threejs-loaders for file decoding. Use when placing 3D sound, configuring panner parameters, or building audio visualization; not a replacement for full game audio middleware."
---
## When to use this skill
**ALWAYS use this skill when the user mentions:**
- `AudioListener` on `Camera`, `Audio` vs `PositionalAudio`, distance models, refDistance/maxDistance/rolloff
- `AudioAnalyser` for visualization bars/spectrum
- Browser autoplay policies blocking audio start
**IMPORTANT: audio vs loaders**
| Step | Skill |
|------|--------|
| Decode mp3/ogg buffer | **threejs-loaders** (`AudioLoader`) |
| Spatial playback API | **threejs-audio** |
**Trigger phrases include:**
- "PositionalAudio", "AudioListener", "AudioAnalyser", "panner"
- "空间音频", "音量衰减", "频谱"
## How to use this skill
1. **Attach listener** to camera object so head-related audio follows view.
2. **Validate AudioContext state** — check `listener.context.state` before playback; resume if suspended.
3. **Create context** compatible with user gesture unlock patterns in browsers.
4. **PositionalAudio** — set `refDistance`, `maxDistance`, `rolloffFactor`, `distanceModel` per docs.
5. **Load buffer** via `AudioLoader` (**threejs-loaders**), then `positionalAudio.setBuffer`.
6. **Analyser** — connect graph `listener.context.createAnalyser()` pathways per examples; watch performance.
7. **Update** — audio nodes usually need no per-frame update unless following moving sources manually.
### Example: PositionalAudio with context validation
```javascript
import * as THREE from 'three';
const listener = new THREE.AudioListener();
camera.add(listener);
// Validate AudioContext state before attempting playback
function ensureAudioContext() {
if (listener.context.state === 'suspended') {
listener.context.resume();
}
}
// Resume on user gesture (required by browser autoplay policy)
document.addEventListener('click', ensureAudioContext, { once: true });
const sound = new THREE.PositionalAudio(listener);
const loader = new THREE.AudioLoader();
loader.load('sound.mp3', (buffer) => {
sound.setBuffer(buffer);
sound.setRefDistance(20);
sound.setRolloffFactor(1);
});
mesh.add(sound); // Attach to a scene object for spatial positioning
```
See [examples/workflow-positional-audio.md](examples/workflow-positional-audio.md).
## Doc map (official)
| Docs section | Representative links |
|--------------|----------------------|
| Audio | https://threejs.org/docs/AudioListener.html |
| Audio | https://threejs.org/docs/Audio.html |
| Audio | https://threejs.org/docs/PositionalAudio.html |
| Audio | https://threejs.org/docs/AudioAnalyser.html |
Extended list: [references/official-sections.md](references/official-sections.md).
## Scope
- **In scope:** Core Audio classes, spatialization parameters, analyser usage overview.
- **Out of scope:** FMOD/Wwise-style authoring tools.
## Common pitfalls and best practices
- Autoplay restrictions require user interaction to resume AudioContext.
- Too many positional sources hurt CPU—pool or LOD audio.
- Ensure world units match distance model expectations.
## Documentation and version
Audio classes are under [Audio](https://threejs.org/docs/#Audio) in [three.js docs](https://threejs.org/docs/). Decoding buffers uses `AudioLoader`—see **threejs-loaders**. Browser Web Audio policies are external but must be mentioned when `AudioContext` is suspended.
## Agent response checklist
When answering under this skill, prefer responses that:
1. Link `AudioListener`, `PositionalAudio`, or `AudioAnalyser` as relevant.
2. Delegate file loading of sound buffers to **threejs-loaders** (`AudioLoader`).
3. Note autoplay / user-gesture requirements for resuming context.
4. Relate distance attenuation to world units and **threejs-objects** placement.
5. Avoid promising DAW-level mixing—stay within three.js audio scope.
## References
- https://threejs.org/docs/#Audio
- https://threejs.org/docs/AudioListener.html
- https://threejs.org/docs/PositionalAudio.html
## Keywords
**English:** audio, positional audio, listener, analyser, spatial sound, web audio, three.js
**中文:** 音频、空间音频、AudioListener、PositionalAudio、Web Audio、three.js
More from partme-ai/full-stack-skills
- adobe-xd"Guides creation of UI/UX designs, interactive prototypes, reusable components, and design specs in Adobe XD. Use when the user asks about Adobe XD artboards, prototype links, repeat grids, component states, design tokens export, or developer handoff."
- angular"Provides comprehensive guidance for Angular framework including components, modules, services, dependency injection, routing, forms, and TypeScript integration. Use when the user asks about Angular, needs to create Angular applications, implement Angular components, or work with Angular features."
- ansible"Provides comprehensive guidance for Ansible automation including playbooks, roles, inventory, and module usage. Use when the user asks about Ansible, needs to automate IT tasks, create Ansible playbooks, or manage infrastructure with Ansible."
- ant-design-mini"Builds mini-program UIs with Ant Design Mini components for Alipay and WeChat mini-programs. Covers Button, Form, List, Modal, Tabs, NavBar, and 60+ components with theme customization and CSS variable theming. Use when the user needs to create mini-program interfaces with Ant Design Mini, configure themes, or implement mini-program-specific UI patterns."
- ant-design-mobile"Builds React mobile UIs with Ant Design Mobile (antd-mobile) components including Button, Form, List, Modal, Picker, Tabs, PullToRefresh, InfiniteScroll, and 50+ mobile-optimized components. Use when the user needs to create mobile-first React interfaces, implement mobile navigation, forms, or data display with Ant Design Mobile."
- ant-design-react"Builds enterprise React UIs with Ant Design (antd) including 60+ components (Button, Form, Table, Select, Modal, Message), design tokens, TypeScript support, and ConfigProvider theming. Use when the user needs to create React applications with Ant Design, build forms with validation, display data tables, or customize the Ant Design theme."
- ant-design-vueProvides comprehensive guidance for Ant Design Vue (AntDV) component library for Vue 3. Covers installation, usage, API reference, templates, and all component categories. Use when building enterprise-class UI with Vue 3 and Ant Design.
- api-doc-generator"Generate API documentation by scanning Controller classes, extracting endpoint URLs, HTTP methods, parameters, and response structures, then producing standardized docs from templates. Use when the user explicitly mentions generating API documentation, creating API docs, scanning interfaces, or documenting REST APIs. Do not trigger for generic documentation requests without explicit API mention."
- appium"Provides comprehensive guidance for Appium mobile testing including mobile app automation, element location, gestures, and cross-platform testing. Use when the user asks about Appium, needs to test mobile applications, automate mobile apps, or write Appium test scripts."
- ascii-ansi-colorizer"Add an ANSI color layer to existing ASCII/plain-text output (gradient/rainbow/highlights) with alignment-safe rules and a required no-color fallback. Use when the user wants to colorize terminal output, add rainbow effects to CLI text, or style ASCII art with ANSI colors."