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.getMaxDistance()

PositionalAudio.getMaxDistance()方法返回音频源的最大距离,超过该距离,音频的音量将被自动减小。

语法

audio.getMaxDistance()

返回值

  • Number - 音频源的最大距离,单位为场景中的距离单位(默认为米)。

示例

const listener = new THREE.AudioListener();
const audio = new THREE.PositionalAudio( listener );
const audioLoader = new THREE.AudioLoader();
audioLoader.load( 'audio.ogg', function( buffer ) {
    audio.setBuffer( buffer );
    audio.setRefDistance( 100 );
    audio.setMaxDistance( 2000 );
    audio.play();
} );
scene.add( audio );

console.log(audio.getMaxDistance());
// expected output: 2000

说明

设置最大距离后,音频源在该距离内的音量将根据实际距离逐步减小。距离超过最大距离后,音量将保持不变。默认值为10000,表示不会自动减小音量。

注意:如果 PositionalAudio 对象没有绑定到一个 AudioListener,则 getMaxDistance() 方法将返回 0

引用

https://threejs.org/docs/index.html#api/en/audio/PositionalAudio.getMaxDistance