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

Object3D.lookAt()

该方法定义了一个对象朝向某一个点的方向。

语法

object.lookAt(vector);

参数

  • vector:THREE.Vector3类型的向量,表示要朝向的目标点。

返回值

无返回值。

详细说明

该方法会使对象的Z轴朝向目标点,从而使对象面向目标点。该方法的具体实现方式是通过计算当前对象位置和目标点位置之间的向量,然后再将该向量作为参数传递给该对象的quaternion属性。

示例

var target = new THREE.Vector3(0, 0, 0);
var object = new THREE.Mesh(geometry, material);

object.lookAt(target);

以上示例中,我们定义了一个目标点target和一个对象object,然后将对象object朝向了target点。此时,该对象的Z轴将会指向目标点。

注意事项

  • 如果该对象的parent属性为null,则该方法将使该对象的Z轴指向目标点所在的世界坐标系。
  • 如果该对象存在parent属性,则该方法将使该对象的Z轴指向目标点所在的父级坐标系(也就是相对于父级的坐标系中的方向)。

参考链接