射线([name])

射线由一个原点向一个确定的方向发射。它被[page:Raycaster](光线投射)所使用, 以用于辅助[link:https://en.wikipedia.org/wiki/Ray_casting raycasting]。 光线投射用于在各个物体之间进行拾取(当鼠标经过三维空间中的物体/对象时进行拾取)。

构造函数

[name]( [param:Vector3 origin], [param:Vector3 direction] )

[page:Vector3 origin] - (可选)[page:Ray](射线)的原点,默认值是一个位于(0, 0, 0)的[page:Vector3]。
[page:Vector3 direction] - [page:Vector3] [page:Ray](射线)的方向。该向量必须被标准化(使用[page:Vector3.normalize]函数),这样才能使方法正常运行。 默认值是一个位于(0, 0, 0)的[page:Vector3]。

创建一个新的[name]。

属性

[property:Vector3 origin]

[page:Ray](射线)的原点,默认值是一个位于(0, 0, 0)的[page:Vector3]。

[property:Vector3 direction]

[page:Ray](射线)的方向。该向量必须被标准化(使用[page:Vector3.normalize]函数),这样才能使方法正常运行。 默认值是一个位于(0, 0, 0)的[page:Vector3]。

方法

[method:Ray applyMatrix4]( [param:Matrix4 matrix4] )

[page:Matrix4 matrix4] - 将被用于这个[page:Ray]的[page:Matrix4]。

使用传入的[page:Matrix4]来变换这个[page:Ray]。

[method:Vector3 at]( [param:Float t], [param:Vector3 target] )

[page:Float t] - 使用这一传入的距离,在[page:Ray]上确定一个位置。
[page:Vector3 target] — 结果将复制到这一Vector3中。

获得这一[page:Ray]上给定距离处的[page:Vector3]。

[method:Ray clone]()

创建一个新的和这个Ray具有相同[page:.origin origin]和[page:.direction direction]的Ray。

[method:Vector3 closestPointToPoint]( [param:Vector3 point], [param:Vector3 target] )

[page:Vector3 point] - the point to get the closest approach to.
[page:Vector3 target] — the result will be copied into this Vector3.

沿着[page:Ray],获得与所传入[page:Vector3]最接近的点。

[method:Ray copy]( [param:Ray ray] )

复制所传入Ray的[page:.origin origin]和[page:.direction direction]属性到这个Ray上。

[method:Float distanceSqToPoint]( [param:Vector3 point] )

[page:Vector3 point] - the [page:Vector3] to compute a distance to.

获得[page:Ray]与传入的[page:Vector3]之间最近的平方距离。

[method:Float distanceSqToSegment]( [param:Vector3 v0], [param:Vector3 v1], [param:Vector3 optionalPointOnRay], [param:Vector3 optionalPointOnSegment] )

[page:Vector3 v0] - the start of the line segment.
[page:Vector3 v1] - the end of the line segment.
optionalPointOnRay - (optional) if this is provided, it receives the point on this [page:Ray] that is closest to the segment.
optionalPointOnSegment - (optional) if this is provided, it receives the point on the line segment that is closest to this [page:Ray].

Get the squared distance between this [page:Ray] and a line segment.

[method:Float distanceToPlane]( [param:Plane plane] )

[page:Plane plane] - the [page:Plane] to get the distance to.

Get the distance from [page:.origin origin] to the [page:Plane], or *null* if the [page:Ray] doesn't intersect the [page:Plane].

[method:Float distanceToPoint]( [param:Vector3 point] )

[page:Vector3 point] - [page:Vector3] The [page:Vector3] to compute a distance to.

Get the distance of the closest approach between the [page:Ray] and the [page:Vector3 point].

[method:Boolean equals]( [param:Ray ray] )

[page:Ray ray] - 用于比较的[page:Ray]。

如果所传入的[page:Ray ray]具有和当前Ray相同的[page:.offset offset]和[page:.direction direction]则返回true。

[method:Vector3 intersectBox]( [param:Box3 box], [param:Vector3 target] )

[page:Box3 box] - the [page:Box3] to intersect with.
[page:Vector3 target] — the result will be copied into this Vector3.

相交 Intersect this [page:Ray] with a [page:Box3], returning the intersection point or *null* if there is no intersection.

[method:Vector3 intersectPlane]( [param:Plane plane], [param:Vector3 target] )

[page:Plane plane] - the [page:Plane] to intersect with.
[page:Vector3 target] — the result will be copied into this Vector3.

Intersect this [page:Ray] with a [page:Plane], returning the intersection point or *null* if there is no intersection.

[method:Vector3 intersectSphere]( [param:Sphere sphere], [param:Vector3 target] )

[page:Sphere sphere] - the [page:Sphere] to intersect with.
[page:Vector3 target] — the result will be copied into this Vector3.

Intersect this [page:Ray] with a [page:Sphere], returning the intersection point or *null* if there is no intersection.

[method:Vector3 intersectTriangle]( [param:Vector3 a], [param:Vector3 b], [param:Vector3 c], [param:Boolean backfaceCulling], [param:Vector3 target] )

[page:Vector3 a], [page:Vector3 b], [page:Vector3 c] - The [page:Vector3] points making up the triangle.
[page:Boolean backfaceCulling] - whether to use backface culling.
[page:Vector3 target] — the result will be copied into this Vector3.

Intersect this [page:Ray] with a triangle, returning the intersection point or *null* if there is no intersection.

[method:Boolean intersectsBox]( [param:Box3 box] )

[page:Box3 box] - the [page:Box3] to intersect with.

Return true if this [page:Ray] intersects with the [page:Box3].

[method:Boolean intersectsPlane]( [param:Plane plane] )

[page:Plane plane] - the [page:Plane] to intersect with.

Return true if this [page:Ray] intersects with the [page:Plane].

[method:Boolean intersectsSphere]( [param:Sphere sphere] )

[page:Sphere sphere] - the [page:Sphere] to intersect with.

Return true if this [page:Ray] intersects with the [page:Sphere].

[method:Ray lookAt]( [param:Vector3 v] )

[page:Vector3 v] - 将要“直视”的[page:Vector3]

调整光线的方向到世界坐标中该向量所指代的点。

[method:Ray recast]( [param:Float t] )

[page:Float t] - The distance along the [page:Ray] to interpolate.

Shift the origin of this [page:Ray] along its direction by the distance given.

[method:Ray set]( [param:Vector3 origin], [param:Vector3 direction] )

[page:Vector3 origin] - the [page:.origin origin] of the [page:Ray].
[page:Vector3 origin] - the [page:.direction direction] of the [page:Ray]. This must be normalized (with [page:Vector3.normalize]) for the methods to operate properly.

Copy the parameters to the [page:.origin origin] and [page:.direction direction] properties of this ray.

源代码

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]