【发布时间】:2014-09-04 08:19:04
【问题描述】:
我有一个带有 3d 声音的全景播放器,我正试图在 Three.js 中实现并尝试遵循这个 http://www.html5rocks.com/en/tutorials/webaudio/positional_audio/
摄像机是固定的,3D 声音放置在场景周围,我希望摄像机是否面向场景会影响音量。
这样就创建了声音(其中位置是一个向量3)
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 之间的数字,我认为这不会真正有帮助,并且可能是使用错误的值。
有任何线索或想法是解决此问题的最佳方法吗?
【问题讨论】:
标签: javascript three.js html5-audio