PositionalAudio.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. import { Vector3 } from '../math/Vector3.js';
  5. import { Audio } from './Audio.js';
  6. import { Object3D } from '../core/Object3D.js';
  7. function PositionalAudio( listener ) {
  8. Audio.call( this, listener );
  9. this.panner = this.context.createPanner();
  10. this.panner.connect( this.gain );
  11. }
  12. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  13. constructor: PositionalAudio,
  14. getOutput: function () {
  15. return this.panner;
  16. },
  17. getRefDistance: function () {
  18. return this.panner.refDistance;
  19. },
  20. setRefDistance: function ( value ) {
  21. this.panner.refDistance = value;
  22. },
  23. getRolloffFactor: function () {
  24. return this.panner.rolloffFactor;
  25. },
  26. setRolloffFactor: function ( value ) {
  27. this.panner.rolloffFactor = value;
  28. },
  29. getDistanceModel: function () {
  30. return this.panner.distanceModel;
  31. },
  32. setDistanceModel: function ( value ) {
  33. this.panner.distanceModel = value;
  34. },
  35. getMaxDistance: function () {
  36. return this.panner.maxDistance;
  37. },
  38. setMaxDistance: function ( value ) {
  39. this.panner.maxDistance = value;
  40. },
  41. updateMatrixWorld: ( function () {
  42. var position = new Vector3();
  43. return function updateMatrixWorld( force ) {
  44. Object3D.prototype.updateMatrixWorld.call( this, force );
  45. position.setFromMatrixPosition( this.matrixWorld );
  46. this.panner.setPosition( position.x, position.y, position.z );
  47. };
  48. } )()
  49. } );
  50. export { PositionalAudio };
粤ICP备19079148号