PositionalAudio.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. [page:Object3D] &rarr; [page:Audio] &rarr;
  12. <h1>[name]</h1>
  13. <p class="desc">
  14. Create a positional audio object.<br /><br />
  15. This uses the [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API Web Audio API].
  16. </p>
  17. <h2>Code Example</h2>
  18. <code>
  19. // create an AudioListener and add it to the camera
  20. var listener = new THREE.AudioListener();
  21. camera.add( listener );
  22. // create the PositionalAudio object (passing in the listener)
  23. var sound = new THREE.PositionalAudio( listener );
  24. // load a sound and set it as the PositionalAudio object's buffer
  25. var audioLoader = new THREE.AudioLoader();
  26. audioLoader.load( 'sounds/song.ogg', function( buffer ) {
  27. sound.setBuffer( buffer );
  28. sound.setRefDistance( 20 );
  29. sound.play();
  30. });
  31. // create an object for the sound to play from
  32. var sphere = new THREE.SphereBufferGeometry( 20, 32, 16 );
  33. var material = new THREE.MeshPhongMaterial( { color: 0xff2200 } );
  34. var mesh = new THREE.Mesh( sphere, material );
  35. scene.add( mesh );
  36. // finally add the sound to the mesh
  37. mesh.add( sound );
  38. </code>
  39. <h2>Examples</h2>
  40. <p>
  41. [example:webaudio_orientation webaudio / orientation ]<br />
  42. [example:webaudio_sandbox webaudio / sandbox ]<br />
  43. [example:webaudio_timing webaudio / timing ]
  44. </p>
  45. <h2>Constructor</h2>
  46. <h3>[name]( [param:AudioListener listener] )</h3>
  47. <p>
  48. listener — (required) [page:AudioListener AudioListener] instance.
  49. </p>
  50. <h2>Properties</h2>
  51. <p>
  52. See the [page:Audio Audio] class for inherited properties.
  53. </p>
  54. <h3>[property:PannerNode panner]</h3>
  55. <p>The PositionalAudio's [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode PannerNode].</p>
  56. <h2>Methods</h2>
  57. <p>
  58. See the [page:Audio Audio] class for inherited methods.
  59. </p>
  60. <h3>[method:PannerNode getOutput]()</h3>
  61. <p>
  62. Returns the [page:PositionalAudio.panner panner].
  63. </p>
  64. <h3>[method:Float getRefDistance]()</h3>
  65. <p>
  66. Returns the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/refDistance panner.refDistance].
  67. </p>
  68. <h3>[method:PositionalAudio setRefDistance]( [param:Float value] )</h3>
  69. <p>
  70. Sets the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/refDistance panner.refDistance].
  71. </p>
  72. <h3>[method:Float getRolloffFactor]()</h3>
  73. <p>
  74. Returns the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/rolloffFactor panner.rolloffFactor].
  75. </p>
  76. <h3>[method:PositionalAudio setRolloffFactor]( [param:Float value] )</h3>
  77. <p>
  78. Sets the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/rolloffFactor panner.rolloffFactor].
  79. </p>
  80. <h3>[method:String getDistanceModel]()</h3>
  81. <p>
  82. Returns the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/distanceModel panner.distanceModel].
  83. </p>
  84. <h3>[method:PositionalAudio setDistanceModel]( [param:String value] )</h3>
  85. <p>
  86. Sets the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/distanceModel panner.distanceModel].
  87. </p>
  88. <h3>[method:Float getMaxDistance]()</h3>
  89. <p>
  90. Returns the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/maxDistance panner.maxDistance].
  91. </p>
  92. <h3>[method:PositionalAudio setMaxDistance]( [param:Float value] )</h3>
  93. <p>
  94. Sets the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/maxDistance panner.maxDistance].
  95. </p>
  96. <h3>[method:PositionalAudio setDirectionalCone]( [param:Float coneInnerAngle], [param:Float coneOuterAngle], [param:Float coneOuterGain] )</h3>
  97. <p>
  98. This method can be used in order to transform an omnidirectional sound into a [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode directional sound].
  99. </p>
  100. <h2>Source</h2>
  101. <p>
  102. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  103. </p>
  104. </body>
  105. </html>