[英]Web Audio with Three.js position 3D sounds
I've got a panorama player with 3d sounds I'm attempting to implement in Three.js and attempting to follow this http://www.html5rocks.com/en/tutorials/webaudio/positional_audio/ 我有一个3d声音全景播放器,我试图在Three.js中实现,并尝试遵循此http://www.html5rocks.com/zh_CN/tutorials/webaudio/positional_audio/
The camera is fixed, and the 3D sounds are placed around the scenes and I want the volume to be affected by if the camera is facing the scene or not. 相机是固定的,并且3D声音放置在场景周围,并且我希望无论相机是否面对场景,音量都会受到影响。
The sounds are created thus (where position is a vector3) 这样就创建了声音(位置是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 );
}
This works well. 这很好。
On the render loop 在渲染循环上
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 );
I'm calling this, with the camera target 我用相机瞄准这个
function updateSceneSounds( target )
{
for(var s in sceneSounds){
var sound = sceneSounds[s];
distance = sound.position.distanceTo( target );
console.log( distance );
}
}
The distances are coming out at numbers between 400-500, which won't really help I don't think, and are probably the wrong value to use. 距离以400-500之间的数字表示,这对我不认为没有帮助,可能使用了错误的值。
Any clues or ideas the best way to go about this? 有什么线索或想法可以解决此问题吗?
I just added this functionality today. 我今天刚刚添加了此功能。 Here's my implementation:
这是我的实现:
https://github.com/mrdoob/three.js/commit/5ba54f71665ff4cd714d0db26c5a32c2b1c1cc8c https://github.com/mrdoob/three.js/commit/5ba54f71665ff4cd714d0db26c5a32c2b1c1cc8c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.