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

Box3.clampPoint()

Box3.clampPoint() 方法将一个给定的 3D 点限制在 Box3 包围盒之内。

语法

box3.clampPoint(point, target)

参数

  • point:vector3类型,要被限制的点
  • target:vector3类型,可选参数,用来保存限制后的点坐标

返回值

返回一个 vector3 类型的点,代表限制后的点坐标。

异常

描述

给定一个 Box3 包围盒和一个 vector3 类型的点,Box3.clampPoint() 方法将该点限制在包围盒之内,如果该点不在包围盒内,它将会被移动到离它最近的点坐标。最终返回修改后的向量。

示例

const box = new THREE.Box3(
  new THREE.Vector3(-1, -1, -1),
  new THREE.Vector3(1, 1, 1)
);

const pointInside = new THREE.Vector3(0, 0, 0);
const pointOutside = new THREE.Vector3(2, 2, 2);

const resultInside = box.clampPoint(pointInside);
const resultOutside = box.clampPoint(pointOutside);

console.log(resultInside); // 输出:Vector3 { x: 0, y: 0, z: 0 }
console.log(resultOutside); // 输出:Vector3 { x: 1, y: 1, z: 1 }

上述代码中,我们创建了一个 3D Box 包围盒、一个在该包围盒内的点、以及一个在包围盒外部的点。我们分别使用 Box3.clampPoint() 方法将这两个点限制在此包围盒内,然后输出它们的限制后的坐标。

相关链接