PositionalAudio.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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">AudioListener</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"><code>listener</code></td>
  50. <td class="description last"><p>The global audio listener.</p></td>
  51. </tr>
  52. </tbody>
  53. </table>
  54. </div>
  55. </div>
  56. <h2 class="subsection-title">Properties</h2>
  57. <div class="member">
  58. <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>
  59. <div class="description">
  60. <p>The panner node represents the location, direction, and behavior of an audio
  61. source in 3D space.</p>
  62. </div>
  63. </div>
  64. <h2 class="subsection-title">Methods</h2>
  65. <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>
  66. <div class="method">
  67. <div class="description">
  68. <p>Returns the current distance model.</p>
  69. </div>
  70. <dl class="details">
  71. <dt class="tag-returns"><strong>Returns:</strong> The distance model.</dt>
  72. </dl>
  73. </div>
  74. <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>
  75. <div class="method">
  76. <div class="description">
  77. <p>Returns the current max distance.</p>
  78. </div>
  79. <dl class="details">
  80. <dt class="tag-returns"><strong>Returns:</strong> The max distance.</dt>
  81. </dl>
  82. </div>
  83. <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>
  84. <div class="method">
  85. <div class="description">
  86. <p>Returns the current reference distance.</p>
  87. </div>
  88. <dl class="details">
  89. <dt class="tag-returns"><strong>Returns:</strong> The reference distance.</dt>
  90. </dl>
  91. </div>
  92. <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>
  93. <div class="method">
  94. <div class="description">
  95. <p>Returns the current rolloff factor.</p>
  96. </div>
  97. <dl class="details">
  98. <dt class="tag-returns"><strong>Returns:</strong> The rolloff factor.</dt>
  99. </dl>
  100. </div>
  101. <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>
  102. <div class="method">
  103. <div class="description">
  104. <p>Sets the directional cone in which the audio can be listened.</p>
  105. </div>
  106. <table class="params">
  107. <tbody>
  108. <tr>
  109. <td class="name"><code>coneInnerAngle</code></td>
  110. <td class="description last"><p>An angle, in degrees, of a cone inside of which there will be no volume reduction.</p></td>
  111. </tr>
  112. <tr>
  113. <td class="name"><code>coneOuterAngle</code></td>
  114. <td class="description last"><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></td>
  115. </tr>
  116. <tr>
  117. <td class="name"><code>coneOuterGain</code></td>
  118. <td class="description last"><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></td>
  119. </tr>
  120. </tbody>
  121. </table>
  122. <dl class="details">
  123. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  124. </dl>
  125. </div>
  126. <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>
  127. <div class="method">
  128. <div class="description">
  129. <p>Defines which algorithm to use to reduce the volume of the audio source
  130. as it moves away from the listener.</p>
  131. <p>Read <a href="https://www.w3.org/TR/webaudio-1.1/#enumdef-distancemodeltype">the spec</a>
  132. for more details.</p>
  133. </div>
  134. <table class="params">
  135. <tbody>
  136. <tr>
  137. <td class="name"><code>value</code></td>
  138. <td class="description last"><p>The distance model to set.</p></td>
  139. </tr>
  140. </tbody>
  141. </table>
  142. <dl class="details">
  143. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  144. </dl>
  145. </div>
  146. <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>
  147. <div class="method">
  148. <div class="description">
  149. <p>Defines the maximum distance between the audio source and the listener,
  150. after which the volume is not reduced any further.</p>
  151. <p>This value is used only by the <code>linear</code> distance model.</p>
  152. </div>
  153. <table class="params">
  154. <tbody>
  155. <tr>
  156. <td class="name"><code>value</code></td>
  157. <td class="description last"><p>The max distance.</p></td>
  158. </tr>
  159. </tbody>
  160. </table>
  161. <dl class="details">
  162. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  163. </dl>
  164. </div>
  165. <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>
  166. <div class="method">
  167. <div class="description">
  168. <p>Defines the reference distance for reducing volume as the audio source moves
  169. further from the listener – i.e. the distance at which the volume reduction
  170. starts taking effect.</p>
  171. </div>
  172. <table class="params">
  173. <tbody>
  174. <tr>
  175. <td class="name"><code>value</code></td>
  176. <td class="description last"><p>The reference distance to set.</p></td>
  177. </tr>
  178. </tbody>
  179. </table>
  180. <dl class="details">
  181. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  182. </dl>
  183. </div>
  184. <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>
  185. <div class="method">
  186. <div class="description">
  187. <p>Defines how quickly the volume is reduced as the source moves away from the listener.</p>
  188. </div>
  189. <table class="params">
  190. <tbody>
  191. <tr>
  192. <td class="name"><code>value</code></td>
  193. <td class="description last"><p>The rolloff factor.</p></td>
  194. </tr>
  195. </tbody>
  196. </table>
  197. <dl class="details">
  198. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  199. </dl>
  200. </div>
  201. <h2 class="subsection-title">Source</h2>
  202. <p>
  203. <a href="https://github.com/mrdoob/three.js/blob/master/src/audio/PositionalAudio.js" target="_blank" rel="noopener" translate="no">src/audio/PositionalAudio.js</a>
  204. </p>
  205. </article>
  206. </section>
  207. <script src="../scripts/linenumber.js"></script>
  208. <script src="../scripts/page.js"></script>
  209. </body>
  210. </html>
粤ICP备19079148号