BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

PositionalAudio.setRefDistance()

描述

PositionalAudio.setRefDistance() 方法设置音频的参考距离,这是音频被听者控制的距离。 如果听者距离音频的参考点超过参考距离,则音频的音量将根据距离减小。

参考距离默认值为 1

请注意,位置声音的减少量不会导致完全的消失,而是以渐进的方式减小。

语法

audio.setRefDistance( refDistance )

参数

  • refDistance : Number 表示音频的参考距离。

示例

// 创建 audioListener 和 audioLoader 对象
var audioLoader = new THREE.AudioLoader();
var audioListener = new THREE.AudioListener();

// 创建一个 PositionalAudio 对象
var sound = new THREE.PositionalAudio( audioListener );

// 加载音频文件并将其分配给 PositionalAudio 对象
audioLoader.load( 'sounds/sound.ogg', function( buffer ) {
    sound.setBuffer( buffer );
    sound.setLoop( true );
    sound.setRefDistance( 10 );
    sound.play();
});

// 在场景中添加带有 PositionalAudio 对象的对象
var sphere = new THREE.Mesh(
    new THREE.SphereGeometry( 20, 32, 16 ),
    new THREE.MeshPhongMaterial( { color: 0xff2200, flatShading: true } )
);
scene.add( sphere );
sphere.add( sound );

// 监听鼠标移动事件以更改监听器的位置
document.addEventListener( 'mousemove', function( event ) {
    var mouseX = ( event.clientX / window.innerWidth ) * 2 - 1;
    var mouseY = - ( event.clientY / window.innerHeight ) * 2 + 1;
    audioListener.position.x = mouseX * 50;
    audioListener.position.y = mouseY * 50;
    audioListener.position.z = 100;
});

其他

  • 该方法应该与 PositionalAudio.setDistanceModel()PositionalAudio.setMaxDistance() 一起使用,以获得更好的音频效果。