123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- import { Vector3 } from '../math/Vector3.js';
- import { Quaternion } from '../math/Quaternion.js';
- import { Clock } from '../core/Clock.js';
- import { Object3D } from '../core/Object3D.js';
- import { AudioContext } from './AudioContext.js';
- function AudioListener() {
- Object3D.call( this );
- this.type = 'AudioListener';
- this.context = AudioContext.getContext();
- this.gain = this.context.createGain();
- this.gain.connect( this.context.destination );
- this.filter = null;
- }
- AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
- constructor: AudioListener,
- getInput: function () {
- return this.gain;
- },
- removeFilter: function ( ) {
- if ( this.filter !== null ) {
- this.gain.disconnect( this.filter );
- this.filter.disconnect( this.context.destination );
- this.gain.connect( this.context.destination );
- this.filter = null;
- }
- return this;
- },
- getFilter: function () {
- return this.filter;
- },
- setFilter: function ( value ) {
- if ( this.filter !== null ) {
- this.gain.disconnect( this.filter );
- this.filter.disconnect( this.context.destination );
- } else {
- this.gain.disconnect( this.context.destination );
- }
- this.filter = value;
- this.gain.connect( this.filter );
- this.filter.connect( this.context.destination );
- return this;
- },
- getMasterVolume: function () {
- return this.gain.gain.value;
- },
- setMasterVolume: function ( value ) {
- this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
- return this;
- },
- updateMatrixWorld: ( function () {
- var position = new Vector3();
- var quaternion = new Quaternion();
- var scale = new Vector3();
- var orientation = new Vector3();
- var clock = new Clock();
- return function updateMatrixWorld( force ) {
- Object3D.prototype.updateMatrixWorld.call( this, force );
- var listener = this.context.listener;
- var up = this.up;
- this.matrixWorld.decompose( position, quaternion, scale );
- orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
- if ( listener.positionX ) {
- var delta = clock.getDelta();
- var endTime = this.context.currentTime + delta;
- listener.positionX.linearRampToValueAtTime( position.x, endTime );
- listener.positionY.linearRampToValueAtTime( position.y, endTime );
- listener.positionZ.linearRampToValueAtTime( position.z, endTime );
- listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
- listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
- listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
- listener.upX.linearRampToValueAtTime( up.x, endTime );
- listener.upY.linearRampToValueAtTime( up.y, endTime );
- listener.upZ.linearRampToValueAtTime( up.z, endTime );
- } else {
- listener.setPosition( position.x, position.y, position.z );
- listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
- }
- };
- } )()
- } );
- export { AudioListener };
|