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

简介

Box3.intersectsTriangle()是three.js中的一个方法,用于判断三维包围盒(Box3)是否与三角形(Triangle)相交。

语法

Box3.intersectsTriangle(triangle: Triangle, normal: Vector3)

参数

  • triangle:类型为Triangle的三角形对象。
  • normal:类型为Vector3的法线向量。

返回值

返回值为Boolean类型,表示三维包围盒和三角形是否相交。

用法

const box = new THREE.Box3(new THREE.Vector3(-1, -1, -1), new THREE.Vector3(1, 1, 1));  // 创建一个边长为2的立方体
const triangle = new THREE.Triangle(
  new THREE.Vector3(-2, -2, 0),
  new THREE.Vector3(0, 2, 0),
  new THREE.Vector3(2, -2, 0)
);  // 创建一个三角形
const normal = new THREE.Vector3(0, 0, 1);  // 创建一个法线向量

if (box.intersectsTriangle(triangle, normal)) {
  console.log('相交了');
} else {
  console.log('未相交');
}

版本要求

该方法需要three.js的r112版本或以上。

参考文献