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

Raycaster.set()

描述

Raycaster.set() 方法用于设置射线投射的起始点和方向。

语法

raycaster.set( origin, direction, near, far );

参数

  • originVector3 类型,表示射线起点的坐标。
  • directionVector3 类型,表示射线方向的向量。
  • near:可选参数,表示射线的起始距离。默认值为 0。
  • far:可选参数,表示射线的最大距离。默认值为 Infinity。

示例

设置射线起点和方向

const raycaster = new THREE.Raycaster();
const origin = new THREE.Vector3(0, 0, 0);
const direction = new THREE.Vector3(1, 0, 0);
raycaster.set(origin, direction);

设置射线起点、方向和最大距离

const raycaster = new THREE.Raycaster();
const origin = new THREE.Vector3(0, 0, 0);
const direction = new THREE.Vector3(1, 0, 0);
const far = 10;
raycaster.set(origin, direction, null, far);

注意事项

  • origin 参数和 direction 参数不能为空。如果这两个参数都为空,则 raycaster 对象的属性不会被修改。
  • near 参数和 far 参数是可选的。如果不指定这两个参数,则会使用默认值。
  • 这个方法会修改 raycaster 对象的属性。如果你需要使用多个射线投射,请创建多个 Raycaster 对象。