SpatialAudioListener3DThe point from which a SpatialAudioRenderer3D renders the scene. Every renderer has exactly one listener.
Uses a right-handed coordinate system with y up and -z forward by default, the same as Web Audio and three.js. A camera can be followed by copying its world position and direction every frame.
For 2D scenes, use SpatialAudioListener.
const renderer = new SpatialAudioRenderer3D(audioDevice);
// First-person controls with yaw and pitch:
renderer.listener
.setPosition(player.x, player.y + 1.7, player.z)
.setYawPitch(player.yaw, player.pitch);
// Or follow a three.js camera:
camera.getWorldDirection(forward);
renderer.listener
.setPosition(camera.position.x, camera.position.y, camera.position.z)
.setOrientation(forward, camera.up);
new SpatialAudioListener3D(options?: Partial<SpatialAudioListener3DOptions>): SpatialAudioListener3D;
You normally do not construct a listener yourself: the renderer creates one. Use renderer.setSpatialAudioListener() to replace it.
options?: Partial<SpatialAudioListener3DOptions> - Initial position, forward and up direction.id: stringA unique id, automatically generated when constructing the listener. Should NOT be changed.
position: Vector3World position of the listener. Defaults to { x: 0, y: 0, z: 0 }.
forward: Vector3Normalized facing direction. Defaults to { x: 0, y: 0, z: -1 }. Set it with setOrientation(), setYawPitch() or lookAt() rather than directly, so the internal basis stays up to date.
up: Vector3Normalized up direction, kept perpendicular to forward. Defaults to { x: 0, y: 1, z: 0 }.
setPosition(x: number, y: number, z: number): SpatialAudioListener3DSets the world position.
x: numbery: numberz: numberSpatialAudioListener3D - The same listener. Can be used to stack methods.translate(dx: number, dy: number, dz: number): SpatialAudioListener3DMoves the listener by the given amount.
dx: numberdy: numberdz: numberSpatialAudioListener3D - The same listener.setOrientation(forward: Vector3, up?: Vector3): SpatialAudioListener3DSets the facing direction and the up direction. Neither has to be normalized. The up direction is made perpendicular to forward. If both are parallel, a perpendicular direction is picked automatically.
SpatialAudioListener3D - The same listener.setYawPitch(yaw: number, pitch?: number): SpatialAudioListener3DSets the orientation from yaw (around the y-axis) and pitch (up/down), in radians. Yaw 0 and pitch 0 face -z. Positive yaw turns right, positive pitch looks up.
yaw: numberpitch?: number - Defaults to 0.SpatialAudioListener3D - The same listener.lookAt(x: number, y: number, z: number): SpatialAudioListener3DRotates the listener so it faces the given point, with world up (0, 1, 0). Does nothing when the point equals the listener position.
x: numbery: numberz: numberSpatialAudioListener3D - The same listener.toLocal(position: Vector3): Vector3Converts a world position into listener space: x = right, y = up, z = forward.
position: Vector3get right(): Vector3Unit vector pointing to the right of the listener, in world space (forward x up).
This class does not emit any events.