Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface PositionalAudio

Create a positional audio object. This uses the Web Audio API. See the ngx3js docs page for details.

Examples

webaudio / orientation | webaudio / sandbox | webaudio / timing

Code Example

//  create an AudioListener and add it to the camera
const listener = new THREE.AudioListener();
camera.add( listener );
// create the PositionalAudio object (passing in the listener)
const sound = new THREE.PositionalAudio( listener );
// load a sound and set it as the PositionalAudio object's buffer
const audioLoader = new THREE.AudioLoader();
audioLoader.load(
'sounds/song.ogg',
function( buffer ) {
sound.setBuffer( buffer );
sound.setRefDistance( 20 );
sound.play();
}
);
// create an object for the sound to play from
const sphere = new THREE.SphereGeometry( 20, 32, 16 );
const material = new THREE.MeshPhongMaterial( { color: 0xff2200 } );
const mesh = new THREE.Mesh( sphere, material );
scene.add( mesh );
// finally add the sound to the mesh
mesh.add( sound );

Ngx3Js Code Example

<ngx3js-camera>
<ngx3js-listener></ngx3js-listener>
</ngx3js-camera>
<ngx3js-mesh>
<ngx3js-geometry [type]="'SphereGeometry'" [radius]="20" [widthSegments]="32" [heightSegments]="16"></ngx3js-geometry>
<ngx3js-audio [url]="'sounds/ambient.ogg'" [volume]="0.5" [loop]="true"></ngx3js-audio>
</ngx3js-mesh>

Hierarchy

Index

Constructors

constructor

Properties

DefaultMatrixAutoUpdate

DefaultMatrixAutoUpdate: boolean

The default setting for .matrixAutoUpdate for newly created Object3Ds.

static

DefaultUp

DefaultUp: I3JS.Vector3

The default .up direction for objects, also used as the default position for DirectionalLight, HemisphereLight and Spotlight (which creates lights shining from the top down). Set to ( 0, 1, 0 ) by default.

static

animations

animations: I3JS.AnimationClip[]

Array with object's animation clips.

default

[]

autoplay

autoplay: boolean

Whether to start playback automatically. Default is false.

default

false

buffer

buffer: AudioBuffer

castShadow

castShadow: boolean

Whether the object gets rendered into shadow map. Default is false.

default

false

children

children: I3JS.Object3D<Event>[]

Array with object's children. See Group for info on manually grouping objects.

default

[]

context

The AudioContext of the listener given in the constructor.

customDepthMaterial

customDepthMaterial: I3JS.Material

Custom depth material to be used when rendering to the depth map. Can only be used in context of meshes. When shadow-casting with a DirectionalLight or SpotLight, if you are modifying vertex positions in the vertex shader you must specify a customDepthMaterial for proper shadows. Default is undefined.

customDistanceMaterial

customDistanceMaterial: I3JS.Material

Same as .customDepthMaterial, but used with PointLight. Default is undefined.

detune

detune: number

Modify pitch, measured in cents. +/- 100 is a semitone. +/- 1200 is an octave. Default is 0.

default

0

duration

duration: number

Overrides the duration of the audio. Same as the duration parameter of AudioBufferSourceNode.start(). Default is undefined to play the whole buffer.

default

undefined

filters

filters: AudioNode[]

Represents an array of AudioNodes. Can be used to apply a variety of low-order filters to create more complex sound effects. In most cases, the array contains instances of BiquadFilterNodes. Filters are set via Audio.setFilter or Audio.setFilters.

default

[]

frustumCulled

frustumCulled: boolean

When this is set, it checks every frame if the object is in the frustum of the camera before rendering the object. If set to false the object gets rendered every frame even if it is not in the frustum of the camera. Default is true.

default

true

gain

gain: GainNode

A GainNode created using AudioContext.createGain().

Optional geometry

geometry?: I3JS.BufferGeometry

The BufferGeometry

hasPlaybackControl

hasPlaybackControl: boolean

Whether playback can be controlled using the play(), pause() etc. methods. Default is true.

default

true

id

id: number

Unique number for this object instance.

readonly

Readonly isObject3D

isObject3D: true

Used to check whether this or derived classes are Object3Ds. Default is true. You should not change this, as it is used internally for optimisation.

isPlaying

isPlaying: boolean

Whether the audio is currently playing.

default

false

layers

layers: I3JS.Layers

The layer membership of the object. The object is only visible if it has at least one layer in common with the Camera in use. This property can also be used to filter out unwanted objects in ray-intersection tests when using Raycaster.

default

new THREE.Layers()

listener

A reference to the listener object of this audio.

loop

loop: boolean
default

false

loopEnd

loopEnd: number
default

0

loopStart

loopStart: number
default

0

Optional material

material?: I3JS.Material | I3JS.Material[]

The Material

matrix

matrix: I3JS.Matrix4

The local transform matrix.

default

new THREE.Matrix4()

matrixAutoUpdate

matrixAutoUpdate: boolean

When this is set, it calculates the matrix of position, (rotation or quaternion) and scale every frame and also recalculates the matrixWorld property. Default is Object3D.DefaultMatrixAutoUpdate (true).

default

THREE.Object3D.DefaultMatrixAutoUpdate

matrixWorld

matrixWorld: I3JS.Matrix4

The global transform of the object. If the Object3D has no parent, then it's identical to the local transform .matrix.

default

new THREE.Matrix4()

matrixWorldNeedsUpdate

matrixWorldNeedsUpdate: boolean

When this is set, it calculates the matrixWorld in that frame and resets this property to false. Default is false.

default

false

Readonly modelViewMatrix

modelViewMatrix: I3JS.Matrix4

This is passed to the shader and used to calculate the position of the object.

default

new THREE.Matrix4()

name

name: string

Optional name of the object (doesn't need to be unique). Default is an empty string.

default

''

Readonly normalMatrix

normalMatrix: I3JS.Matrix3

This is passed to the shader and used to calculate lighting for the object. It is the transpose of the inverse of the upper left 3x3 sub-matrix of this object's modelViewMatrix. The reason for this special matrix is that simply using the modelViewMatrix could result in a non-unit length of normals (on scaling) or in a non-perpendicular direction (on non-uniform scaling). On the other hand the translation part of the modelViewMatrix is not relevant for the calculation of normals. Thus a Matrix3 is sufficient.

default

new THREE.Matrix3()

offset

offset: number

An offset to the time within the audio buffer that playback should begin. Same as the offset parameter of AudioBufferSourceNode.start(). Default is 0.

default

0

panner

panner: PannerNode

The PositionalAudio's PannerNode.

parent

Object's parent in the scene graph. An object can have at most one parent.

default

null

playbackRate

playbackRate: number

Speed of playback. Default is 1.

default

1

Readonly position

position: I3JS.Vector3

A Vector3 representing the object's local position. Default is (0, 0, 0).

default

new THREE.Vector3()

Readonly quaternion

quaternion: I3JS.Quaternion

Object's local rotation as a Quaternion.

default

new THREE.Quaternion()

receiveShadow

receiveShadow: boolean

Whether the material receives shadows. Default is false.

default

false

renderOrder

renderOrder: number

This value allows the default rendering order of scene graph objects to be overridden although opaque and transparent objects remain sorted independently. When this property is set for an instance of Group, all descendants objects will be sorted and rendered together. Sorting is from lowest to highest renderOrder. Default value is 0.

default

0

Readonly rotation

rotation: I3JS.Euler

Object's local rotation (see Euler angles), in radians.

default

new THREE.Euler()

Readonly scale

scale: I3JS.Vector3

The object's local scale. Default is Vector3( 1, 1, 1 ).

default

new THREE.Vector3()

source

source: AudioBufferSourceNode

sourceType

sourceType: string

Type of the audio source. Default is string 'empty'.

default

'empty'

type

type: "Audio"

String denoting the type, set to 'Audio'.

up

This is used by the .lookAt method, for example, to determine the orientation of the result. Default is Object3D.DefaultUp - that is, ( 0, 1, 0 ).

default

THREE.Object3D.DefaultUp.clone()

userData

userData: {}

An object that can be used to store custom data about the Object3D. It should not hold references to functions as these will not be cloned.

default

{}

Type declaration

  • [key: string]: any

uuid

uuid: string

UUID of this object instance. This gets automatically assigned, so this shouldn't be edited.

visible

visible: boolean

Object gets rendered if true. Default is true.

default

true

Methods

add

addEventListener

applyMatrix4

applyQuaternion

attach

clear

clone

connect

copy

disconnect

dispatchEvent

  • dispatchEvent(event: Event): void

getDetune

  • getDetune(): number

getDistanceModel

  • getDistanceModel(): string

getFilter

  • getFilter(): AudioNode

getFilters

  • getFilters(): AudioNode[]

getLoop

  • getLoop(): boolean

getMaxDistance

  • getMaxDistance(): number

getObjectById

  • Note that ids are assigned in chronological order: 1, 2, 3, ..., incrementing by one for each new object.

    Parameters

    • id: number

      Unique number of the object instance Searches through an object and its children, starting with the object itself, and returns the first with a matching id.

    Returns I3JS.Object3D<Event>

getObjectByName

  • Searches through an object and its children, starting with the object itself, and returns the first with a matching name. Note that for most objects the name is an empty string by default. You will have to set it manually to make use of this method.

    Parameters

    • name: string

      String to match to the children's Object3D.name property.

    Returns I3JS.Object3D<Event>

getObjectByProperty

getOutput

  • getOutput(): PannerNode

getPlaybackRate

  • getPlaybackRate(): number

getRefDistance

  • getRefDistance(): number

getRolloffFactor

  • getRolloffFactor(): number

getVolume

  • getVolume(): number

getWorldDirection

getWorldPosition

getWorldQuaternion

getWorldScale

hasEventListener

localToWorld

lookAt

  • lookAt(vector: number | I3JS.Vector3, y?: number, z?: number): void
  • Optionally, the .x, .y and .z components of the world space position. Rotates the object to face a point in world space. This method does not support objects having non-uniformly-scaled parent(s).

    Parameters

    • vector: number | I3JS.Vector3

      A vector representing a position in world space.

    • Optional y: number
    • Optional z: number

    Returns void

onAfterRender

onBeforeRender

onEnded

  • onEnded(): void

pause

play

raycast

remove

removeEventListener

removeFromParent

rotateOnAxis

rotateOnWorldAxis

rotateX

rotateY

rotateZ

setBuffer

setDetune

setDirectionalCone

  • setDirectionalCone(coneInnerAngle: number, coneOuterAngle: number, coneOuterGain: number): I3JS.PositionalAudio

setDistanceModel

setFilter

setFilters

setLoop

setLoopEnd

setLoopStart

setMaxDistance

setMediaElementSource

setMediaStreamSource

setNodeSource

setPlaybackRate

setRefDistance

setRolloffFactor

setRotationFromAxisAngle

  • setRotationFromAxisAngle(axis: I3JS.Vector3, angle: number): void

setRotationFromEuler

  • setRotationFromEuler(euler: I3JS.Euler): void

setRotationFromMatrix

setRotationFromQuaternion

setVolume

stop

toJSON

  • toJSON(meta?: { geometries: any; images: any; materials: any; textures: any }): any

translateOnAxis

translateX

translateY

translateZ

traverse

traverseAncestors

traverseVisible

updateMatrix

  • updateMatrix(): void

updateMatrixWorld

  • updateMatrixWorld(force?: boolean): void

updateWorldMatrix

  • updateWorldMatrix(updateParents: boolean, updateChildren: boolean): void

worldToLocal

Generated using TypeDoc