ReadonlydirectionThe unit-length direction the ray runs in
ReadonlyoriginThe point the ray starts from
ReadonlytypeNames the shape without an instanceof check, like the type on pixi's 2D shapes
Transforms this ray by an affine matrix
The direction comes out unit length, so a t measured along the new ray is in the new space's
units: under scale, compare hits as points, not as t values.
matrix must be affine (bottom row [0, 0, 0, 1]), as a Container3D#worldTransform
always is and a projection matrix isn't.
The result ray for chaining
Writes the closest point on this ray to point into out
Points behind origin give origin. Requires a unit-length direction.
The point to measure from
Optionalout: Vector3
Optional vector to write into; a new Vector3 when omitted
The closest point on this ray
Returns the squared Euclidean distance from point to the closest point on this ray
Cheaper than Ray#distanceToPoint; compare it against a squared radius. Requires a
unit-length direction.
The point to measure from
The squared distance to the closest point on this ray
Returns the Euclidean distance from point to the closest point on this ray
Requires a unit-length direction.
The point to measure from
The distance to the closest point on this ray
Returns true when origin and direction match ray exactly (no epsilon tolerance)
The ray to compare with
Whether the origin and direction match
Intersects this ray with box
Works with a direction of any length.
The entry point (or the exit point from inside), or null when the ray misses
const hit = new Vector3();
if (localRay.intersectBox(mesh.geometry.bounds3D, hit)) decal.position.copyFrom(hit);
Ray#intersectBoxT For the distance to the same hit, without the point.
Intersects this ray with box and returns the distance to the hit rather than the point
Same hit as Ray#intersectBox; Ray#at turns t into the point. With a
unit-length direction, t is the distance from origin. A ray that runs along one of the
box's faces still gets the right entry or exit distance.
The box to intersect
The distance t to the entry point, or to the exit point when the origin is inside
the box, or -1 when the ray misses
Intersects this ray with plane
A ray that lies in the plane hits at its origin. Works with a direction of any length.
The hit point, or null when the ray points away from the plane or runs parallel to it
Returns true when this ray hits box
The box to test
Whether the ray hits the box
Intersects this ray with sphere
An empty sphere is never hit. Requires a unit-length direction.
The entry point (or the exit point from inside), or null when the ray misses
const hit = new Vector3();
if (ray.intersectSphere(planet.boundingSphere, hit)) flag.position.copyFrom(hit);
Ray#intersectSphereT For the distance to the same hit, without the point.
Intersects this ray with sphere and returns the distance to the hit rather than the point
Same hit as Ray#intersectSphere; Ray#at turns the distance into the point.
Compare distances to find the nearest of several hits without making a point for each.
Requires a unit-length direction.
The sphere to intersect
The distance t to the hit (>= 0), or -1 when the ray misses
Returns true when this ray hits plane, including when its origin lies on the plane
The plane to test
Whether the ray hits the plane
Returns true when this ray hits sphere
Requires a unit-length direction. An empty sphere is never hit.
The sphere to test
Whether the ray hits the sphere
Sets the origin and direction of this ray, copying their values
The origin of the ray
The unit-length direction of the ray
This ray for chaining
Advanced
Returns a string representation of this ray
A string in the form [@pixi/3d/math:Ray origin=(0, 0, 0) direction=(0, 0, -1)]
A half-line that starts at
originand runs alongdirection, for picking and line-of-sight testsView3D#screenToRay builds one through a pointer position, in world space. Test a ray against shapes in its own space; Ray#applyMatrix4 moves it into a mesh's local space. Keep
directionunit length, and calldirection.normalize()after changing it by hand; the distance, closest-point and sphere methods give wrong results otherwise.Example