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

MathUtils.clamp()

介绍

MathUtils.clamp() 方法是three.js中的一个工具函数,用于将一个数值限定在某个范围内,即将数值限制在最小值和最大值之间。

语法

MathUtils.clamp(value, min, max);
  • value: 待限制的数字数值。
  • min: 允许的最小值。
  • max: 允许的最大值。

返回值

返回一个限制在最小值和最大值之间的数值。

示例

MathUtils.clamp(5, 0, 10); // 返回 5
MathUtils.clamp(15, 0, 10); // 返回 10
MathUtils.clamp(-5, 0, 10); // 返回 0

注意事项

  • 如果value小于min,那么返回值为min
  • 如果value大于max,那么返回值为max
  • 如果valueminmax之间,那么返回值为value本身。

参考链接