PositionalAudio.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>PositionalAudio - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → <a href="Object3D.html">Object3D</a> → <a href="Audio.html">Audio</a> → </p>
  13. <h1 translate="no">PositionalAudio</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>Represents a positional audio object.</p></div>
  17. <h2>Code Example</h2>
  18. <div translate="no"><pre><code class="language-js">// create an AudioListener and add it to the camera
  19. const listener = new THREE.AudioListener();
  20. camera.add( listener );
  21. // create the PositionalAudio object (passing in the listener)
  22. const sound = new THREE.PositionalAudio( listener );
  23. // load a sound and set it as the PositionalAudio object's buffer
  24. const audioLoader = new THREE.AudioLoader();
  25. audioLoader.load( 'sounds/song.ogg', function( buffer ) {
  26. sound.setBuffer( buffer );
  27. sound.setRefDistance( 20 );
  28. sound.play();
  29. });
  30. // create an object for the sound to play from
  31. const sphere = new THREE.SphereGeometry( 20, 32, 16 );
  32. const material = new THREE.MeshPhongMaterial( { color: 0xff2200 } );
  33. const mesh = new THREE.Mesh( sphere, material );
  34. scene.add( mesh );
  35. // finally add the sound to the mesh
  36. mesh.add( sound );</code></pre></div>
  37. </header>
  38. <article>
  39. <div class="container-overview">
  40. <h2>Constructor</h2>
  41. <h3 class="name name-method" id="PositionalAudio" translate="no">new <a href="#PositionalAudio">PositionalAudio</a><span class="signature">( listener : <span class="param-type"><a href="AudioListener.html">AudioListener</a></span> )</span> </h3>
  42. <div class="method">
  43. <div class="description">
  44. <p>Constructs a positional audio.</p>
  45. </div>
  46. <table class="params">
  47. <tbody>
  48. <tr>
  49. <td class="name">
  50. <strong>listener</strong>
  51. </td>
  52. <td class="description last">
  53. <p>The global audio listener.</p>
  54. </td>
  55. </tr>
  56. </tbody>
  57. </table>
  58. </div>
  59. </div>
  60. <h2 class="subsection-title">Properties</h2>
  61. <div class="member">
  62. <h3 class="name" id="panner" translate="no">.<a href="#panner">panner</a><span class="type-signature"> : PannerNode</span> <span class="type-signature">(readonly) </span></h3>
  63. <div class="description">
  64. <p>The panner node represents the location, direction, and behavior of an audio
  65. source in 3D space.</p>
  66. </div>
  67. </div>
  68. <h2 class="subsection-title">Methods</h2>
  69. <h3 class="name name-method" id="getDistanceModel" translate="no">.<a href="#getDistanceModel">getDistanceModel</a><span class="signature">()</span><span class="type-signature"> : 'linear' | 'inverse' | 'exponential'</span> </h3>
  70. <div class="method">
  71. <div class="description">
  72. <p>Returns the current distance model.</p>
  73. </div>
  74. <dl class="details">
  75. <dt class="tag-returns"><strong>Returns:</strong> The distance model.</dt>
  76. </dl>
  77. </div>
  78. <h3 class="name name-method" id="getMaxDistance" translate="no">.<a href="#getMaxDistance">getMaxDistance</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  79. <div class="method">
  80. <div class="description">
  81. <p>Returns the current max distance.</p>
  82. </div>
  83. <dl class="details">
  84. <dt class="tag-returns"><strong>Returns:</strong> The max distance.</dt>
  85. </dl>
  86. </div>
  87. <h3 class="name name-method" id="getRefDistance" translate="no">.<a href="#getRefDistance">getRefDistance</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  88. <div class="method">
  89. <div class="description">
  90. <p>Returns the current reference distance.</p>
  91. </div>
  92. <dl class="details">
  93. <dt class="tag-returns"><strong>Returns:</strong> The reference distance.</dt>
  94. </dl>
  95. </div>
  96. <h3 class="name name-method" id="getRolloffFactor" translate="no">.<a href="#getRolloffFactor">getRolloffFactor</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  97. <div class="method">
  98. <div class="description">
  99. <p>Returns the current rolloff factor.</p>
  100. </div>
  101. <dl class="details">
  102. <dt class="tag-returns"><strong>Returns:</strong> The rolloff factor.</dt>
  103. </dl>
  104. </div>
  105. <h3 class="name name-method" id="setDirectionalCone" translate="no">.<a href="#setDirectionalCone">setDirectionalCone</a><span class="signature">( coneInnerAngle : <span class="param-type">number</span>, coneOuterAngle : <span class="param-type">number</span>, coneOuterGain : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="PositionalAudio.html">PositionalAudio</a></span> </h3>
  106. <div class="method">
  107. <div class="description">
  108. <p>Sets the directional cone in which the audio can be listened.</p>
  109. </div>
  110. <table class="params">
  111. <tbody>
  112. <tr>
  113. <td class="name">
  114. <strong>coneInnerAngle</strong>
  115. </td>
  116. <td class="description last">
  117. <p>An angle, in degrees, of a cone inside of which there will be no volume reduction.</p>
  118. </td>
  119. </tr>
  120. <tr>
  121. <td class="name">
  122. <strong>coneOuterAngle</strong>
  123. </td>
  124. <td class="description last">
  125. <p>An angle, in degrees, of a cone outside of which the volume will be reduced by a constant value, defined by the <code>coneOuterGain</code> parameter.</p>
  126. </td>
  127. </tr>
  128. <tr>
  129. <td class="name">
  130. <strong>coneOuterGain</strong>
  131. </td>
  132. <td class="description last">
  133. <p>The amount of volume reduction outside the cone defined by the <code>coneOuterAngle</code>. When set to <code>0</code>, no sound can be heard.</p>
  134. </td>
  135. </tr>
  136. </tbody>
  137. </table>
  138. <dl class="details">
  139. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  140. </dl>
  141. </div>
  142. <h3 class="name name-method" id="setDistanceModel" translate="no">.<a href="#setDistanceModel">setDistanceModel</a><span class="signature">( value : <span class="param-type">'linear' | 'inverse' | 'exponential'</span> )</span><span class="type-signature"> : <a href="PositionalAudio.html">PositionalAudio</a></span> </h3>
  143. <div class="method">
  144. <div class="description">
  145. <p>Defines which algorithm to use to reduce the volume of the audio source
  146. as it moves away from the listener.</p>
  147. <p>Read <a href="https://www.w3.org/TR/webaudio-1.1/#enumdef-distancemodeltype" target="_blank" rel="noopener">the spec</a>
  148. for more details.</p>
  149. </div>
  150. <table class="params">
  151. <tbody>
  152. <tr>
  153. <td class="name">
  154. <strong>value</strong>
  155. </td>
  156. <td class="description last">
  157. <p>The distance model to set.</p>
  158. </td>
  159. </tr>
  160. </tbody>
  161. </table>
  162. <dl class="details">
  163. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  164. </dl>
  165. </div>
  166. <h3 class="name name-method" id="setMaxDistance" translate="no">.<a href="#setMaxDistance">setMaxDistance</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="PositionalAudio.html">PositionalAudio</a></span> </h3>
  167. <div class="method">
  168. <div class="description">
  169. <p>Defines the maximum distance between the audio source and the listener,
  170. after which the volume is not reduced any further.</p>
  171. <p>This value is used only by the <code>linear</code> distance model.</p>
  172. </div>
  173. <table class="params">
  174. <tbody>
  175. <tr>
  176. <td class="name">
  177. <strong>value</strong>
  178. </td>
  179. <td class="description last">
  180. <p>The max distance.</p>
  181. </td>
  182. </tr>
  183. </tbody>
  184. </table>
  185. <dl class="details">
  186. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  187. </dl>
  188. </div>
  189. <h3 class="name name-method" id="setRefDistance" translate="no">.<a href="#setRefDistance">setRefDistance</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="PositionalAudio.html">PositionalAudio</a></span> </h3>
  190. <div class="method">
  191. <div class="description">
  192. <p>Defines the reference distance for reducing volume as the audio source moves
  193. further from the listener – i.e. the distance at which the volume reduction
  194. starts taking effect.</p>
  195. </div>
  196. <table class="params">
  197. <tbody>
  198. <tr>
  199. <td class="name">
  200. <strong>value</strong>
  201. </td>
  202. <td class="description last">
  203. <p>The reference distance to set.</p>
  204. </td>
  205. </tr>
  206. </tbody>
  207. </table>
  208. <dl class="details">
  209. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  210. </dl>
  211. </div>
  212. <h3 class="name name-method" id="setRolloffFactor" translate="no">.<a href="#setRolloffFactor">setRolloffFactor</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="PositionalAudio.html">PositionalAudio</a></span> </h3>
  213. <div class="method">
  214. <div class="description">
  215. <p>Defines how quickly the volume is reduced as the source moves away from the listener.</p>
  216. </div>
  217. <table class="params">
  218. <tbody>
  219. <tr>
  220. <td class="name">
  221. <strong>value</strong>
  222. </td>
  223. <td class="description last">
  224. <p>The rolloff factor.</p>
  225. </td>
  226. </tr>
  227. </tbody>
  228. </table>
  229. <dl class="details">
  230. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  231. </dl>
  232. </div>
  233. <h2 class="subsection-title">Source</h2>
  234. <p>
  235. <a href="https://github.com/mrdoob/three.js/blob/master/src/audio/PositionalAudio.js" translate="no" target="_blank" rel="noopener">src/audio/PositionalAudio.js</a>
  236. </p>
  237. </article>
  238. </section>
  239. <script src="../scripts/linenumber.js"></script>
  240. <script src="../scripts/page.js"></script>
  241. </body>
  242. </html>
粤ICP备19079148号