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

Frustum.intersectsObject()

函数 Frustum.intersectsObject(object) 用于检查摄像机的视锥体是否与给定的物体对象 object 相交。如果相交,返回 true,否则返回 false

参数

  • object:要检查的物体对象。

返回值

  • true:视锥体与物体相交。
  • false:视锥体与物体不相交。

示例

// 创建一个带有视锥体的透视相机
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
// 创建一个视锥体对象
var frustum = new THREE.Frustum();
// 设置视锥体属性(同透视相机的属性)
frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse));
// 创建一个立方体对象
var cube = new THREE.Mesh(new THREE.BoxGeometry(10, 10, 10), new THREE.MeshBasicMaterial({ color: 0xff0000 }));
// 检查立方体是否在视锥体中
if (frustum.intersectsObject(cube)) {
  console.log('Cube is inside frustum.');
} else {
  console.log('Cube is outside frustum.');
}

注意事项

  • Frustum.intersectsObject() 函数的参数必须是一个 THREE.Object3D 类型的对象或其子类对象。如果参数类型错误会引发异常。
  • 要使用 Frustum.intersectsObject() 函数前,请确保已创建一个视锥体对象并设置好其相关属性。
  • 相交检测只能检测当前帧内的相交情况。如果物体对象在多帧内移动,则需要在每一帧内重新调用此函数,以检查相交情况。