PositionalAudio.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Object3D] &rarr; [page:Audio] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. Create a positional audio object.<br /><br />
  14. This uses the
  15. [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. const listener = new THREE.AudioListener();
  21. camera.add( listener );
  22. // create the PositionalAudio object (passing in the listener)
  23. const sound = new THREE.PositionalAudio( listener );
  24. // load a sound and set it as the PositionalAudio object's buffer
  25. const 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. const sphere = new THREE.SphereGeometry( 20, 32, 16 );
  33. const material = new THREE.MeshPhongMaterial( { color: 0xff2200 } );
  34. const 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>listener — (required) [page:AudioListener AudioListener] instance.</p>
  48. <h2>Properties</h2>
  49. <p>See the [page:Audio Audio] class for inherited properties.</p>
  50. <h3>[property:PannerNode panner]</h3>
  51. <p>
  52. The PositionalAudio's
  53. [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode PannerNode].
  54. </p>
  55. <h2>Methods</h2>
  56. <p>See the [page:Audio Audio] class for inherited methods.</p>
  57. <h3>[method:PannerNode getOutput]()</h3>
  58. <p>Returns the [page:PositionalAudio.panner panner].</p>
  59. <h3>[method:Float getRefDistance]()</h3>
  60. <p>
  61. Returns the value of
  62. [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/refDistance panner.refDistance].
  63. </p>
  64. <h3>[method:this setRefDistance]( [param:Float value] )</h3>
  65. <p>
  66. Sets the value of
  67. [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/refDistance panner.refDistance].
  68. </p>
  69. <h3>[method:Float getRolloffFactor]()</h3>
  70. <p>
  71. Returns the value of
  72. [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/rolloffFactor panner.rolloffFactor].
  73. </p>
  74. <h3>[method:this setRolloffFactor]( [param:Float value] )</h3>
  75. <p>
  76. Sets the value of
  77. [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/rolloffFactor panner.rolloffFactor].
  78. </p>
  79. <h3>[method:String getDistanceModel]()</h3>
  80. <p>
  81. Returns the value of
  82. [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/distanceModel panner.distanceModel].
  83. </p>
  84. <h3>[method:this setDistanceModel]( [param:String value] )</h3>
  85. <p>
  86. Sets the value of
  87. [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/distanceModel panner.distanceModel].
  88. </p>
  89. <h3>[method:Float getMaxDistance]()</h3>
  90. <p>
  91. Returns the value of
  92. [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/maxDistance panner.maxDistance].
  93. </p>
  94. <h3>[method:this setMaxDistance]( [param:Float value] )</h3>
  95. <p>
  96. Sets the value of
  97. [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/maxDistance panner.maxDistance].
  98. </p>
  99. <h3>[method:this setDirectionalCone]( [param:Float coneInnerAngle], [param:Float coneOuterAngle], [param:Float coneOuterGain] )
  100. </h3>
  101. <p>
  102. This method can be used in order to transform an omnidirectional sound
  103. into a [link:https://developer.mozilla.org/en-US/docs/Web/API/PannerNode directional sound].
  104. </p>
  105. <h2>Source</h2>
  106. <p>
  107. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  108. </p>
  109. </body>
  110. </html>