codecamp

three.js PositionalAudio

创建一个位置相关的音频对象.

使用了Web Audio API.

代码示例

// create an AudioListener and add it to the camera
const listener = new THREE.AudioListener();
camera.add( listener );

// create the PositionalAudio object (passing in the listener)
const sound = new THREE.PositionalAudio( listener );

// load a sound and set it as the PositionalAudio object's buffer
const audioLoader = new THREE.AudioLoader();
audioLoader.load( 'sounds/song.ogg', function( buffer ) {
	sound.setBuffer( buffer );
	sound.setRefDistance( 20 );
	sound.play();
});

// create an object for the sound to play from
const sphere = new THREE.SphereGeometry( 20, 32, 16 );
const material = new THREE.MeshPhongMaterial( { color: 0xff2200 } );
const mesh = new THREE.Mesh( sphere, material );
scene.add( mesh );

// finally add the sound to the mesh
mesh.add( sound );

例子

webaudio / orientation

webaudio / sandbox

webaudio / timing

构造函数

PositionalAudio( listener : AudioListener )

listener — (必须) AudioListener 实例.

属性

Audio类的继承属性.

.panner : PannerNode

位置相关音频的PannerNode.

方法

Audio类的继承方法.

.getOutput () : PannerNode

返回panner.

.getRefDistance () : Float

返回panner.refDistance的值.

.setRefDistance ( value : Float ) : this

设置panner.refDistance的值.

.getRolloffFactor () : Float

返回panner.rolloffFactor的值.

.setRolloffFactor ( value : Float ) : this

设置panner.rolloffFactor的值.

.getDistanceModel () : String

返回panner.distanceModel的值.

.setDistanceModel ( value : String ) : this

设置panner.distanceModel的值.

.getMaxDistance () : Float

返回panner.maxDistance的值.

.setMaxDistance ( value : Float ) : this

设置panner.maxDistance的值.

.setDirectionalCone ( coneInnerAngle : Float, coneOuterAngle : Float, coneOuterGain : Float ) : this

这个方法用来把环绕声音转换为定向声音directional sound.

源码

src/audio/PositionalAudio.js


three.js AudioListener
three.js ArrayCamera
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

参考

核心 / BufferAttributes

渲染器 / WebXR

开发者参考

WebGL渲染器

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }