我有一个带有 3d 声音的全景播放器,我正尝试在 Three.js 中实现并尝试遵循此 http://www.html5rocks.com/en/tutorials/webaudio/positional_audio/
摄像机是固定的,3D 声音是围绕场景放置的,我希望音量会受到摄像机是否面向场景的影响。
声音是这样产生的(其中 position 是一个 vector3)
function playSound(buffer, looping, position, volume) {
var sound = {};
sound.source = context.createBufferSource();
sound.volume = context.createGain();
sound.source.connect(sound.volume);
sound.volume.connect(mainVolume);
var gainNode = context.createGain();
gainNode.gain.value = volume;
sound.source.connect(gainNode);
sound.source.buffer = buffer;
if(looping)
sound.source.loop = true;
sound.source.connect(context.destination);
sound.source.start();
sound.panner = context.createPanner();
sound.position = position;
//sound.panner.updateMatrixWorld();
sound.volume.connect(sound.panner);
sound.panner.connect(mainVolume);
sceneSounds.push( sound );
}
这很好用。
在渲染循环上
lat = Math.max(-85, Math.min(85, lat));
phi = THREE.Math.degToRad(90 - lat);
theta = THREE.Math.degToRad(lon);
target.x = 512 * Math.sin(phi) * Math.cos(theta);
target.y = 512 * Math.cos(phi);
target.z = 512 * Math.sin(phi) * Math.sin(theta);
camera.lookAt(target);
if(sceneSounds.length > 0)
updateSceneSounds( target );
我用相机目标调用它
function updateSceneSounds( target )
{
for(var s in sceneSounds){
var sound = sceneSounds[s];
distance = sound.position.distanceTo( target );
console.log( distance );
}
}
距离显示在 400-500 之间,我认为这不会真正有帮助,而且可能是错误的使用值。
任何线索或想法是解决此问题的最佳方法?
最佳答案
我今天刚刚添加了这个功能。这是我的实现:
https://github.com/mrdoob/three.js/commit/5ba54f71665ff4cd714d0db26c5a32c2b1c1cc8c
关于javascript - 带有 Three.js 位置 3D 声音的网络音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25634500/