BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Audio.connect()

The Audio.connect() method in Three.js allows you to connect an audio object to the Web Audio API. This is useful when you want to create an audio scene, where multiple sounds can be played simultaneously and interact with each other.

Syntax

Audio.connect(destinationNode);
  • destinationNode - The node you want to connect the audio object to. This can be an AudioContext or any other node in the Web Audio API.

Example

const audioLoader = new THREE.AudioLoader();
const listener = new THREE.AudioListener();
const sound = new THREE.PositionalAudio(listener);

audioLoader.load('sound.mp3', function(buffer) {
  sound.setBuffer(buffer);
  sound.setRefDistance(20);
  sound.play();
});

// Connect the audio object to the listener
sound.connect(listener);

In this example, we have a positional audio object that we want to connect to an AudioListener. We load the audio file using Three.js' AudioLoader, set the buffer and play the sound. We then connect the sound object to the listener by calling connect.

Note that you can also connect the audio object to other nodes in the Web Audio API, such as a GainNode or a PannerNode.

Conclusion

The Audio.connect() method in Three.js allows you to connect an audio object to the Web Audio API, which is essential when creating a complex audio scene. By connecting multiple sounds to different nodes, you can create unique effects and add depth to the overall experience.