Ray

A ray that emits from an origin in a certain direction. This is used by the Raycaster| Raycaster to assist with ray casting. Raycaster is used for mouse picking (working out what objects in the 3D space the mouse is over) amongst other things.

Core Class

A ray that emits from an origin in a certain direction. This is used by the Raycaster| Raycaster to assist with ray casting. Raycaster is used for mouse picking (working out what objects in the 3D space the mouse is over) amongst other things.

Constructors

Properties

origin: Vector3

The origin of the Ray.

direction: Vector3

The direction of the Ray. This must be normalized (with Vector3.normalize) for the methods to operate properly.

Methods

  • This must be normalized (with Vector3.normalize) for the methods to operate properly. Sets this ray's .origin| origin and .direction| direction properties by copying the values from the given objects.

    Parameters

    Returns Ray

  • Creates a new Ray with identical origin| origin and direction to this one.

    Returns Ray

  • Copies the origin| origin and direction properties of ray into this ray.

    Parameters

    Returns Ray

  • Get a Vector3 that is a given distance along this Ray.

    Parameters

    • t: number

      the distance along the Ray to retrieve a position for.

    • target: Vector3

      the result will be copied into this Vector3.

    Returns Vector3

  • Adjusts the direction of the ray to point at the vector in world coordinates.

    Parameters

    Returns Ray

  • Shift the origin of this Ray along its direction by the distance given.

    Parameters

    • t: number

      The distance along the Ray to interpolate.

    Returns Ray

  • Get the point along this Ray that is closest to the Vector3 provided.

    Parameters

    • point: Vector3

      the point to get the closest approach to.

    • target: Vector3

      the result will be copied into this Vector3.

    Returns Vector3

  • Get the distance of the closest approach between the Ray and the point.

    Parameters

    Returns number

  • Get the squared distance of the closest approach between the Ray and the Vector3.

    Parameters

    Returns number

  • Get the squared distance between this Ray and a line segment.

    Parameters

    • v0: Vector3

      the start of the line segment.

    • v1: Vector3

      the end of the line segment.

    • optionalPointOnRay: Vector3

      (optional) if this is provided, it receives the point on this Ray that is closest to the segment.

    • optionalPointOnSegment: Vector3

      (optional) if this is provided, it receives the point on the line segment that is closest to this Ray.

    Returns number

  • Intersect this Ray with a Sphere, returning the intersection point or null if there is no intersection.

    Parameters

    • sphere: Sphere

      the Sphere to intersect with.

    • target: Vector3

      the result will be copied into this Vector3.

    Returns Nullable<Vector3>

  • Calculate the maximum distance between origin and one or two intersections if this ray through the sphere.

    Parameters

    Returns number

  • Calculate the length, which is the distance projected on the ray from given point to origin.

    Parameters

    Returns number

  • Return true if this Ray intersects with the Sphere.

    Parameters

    Returns boolean

  • Get the distance from origin| origin to the Plane, or null if the Ray doesn't intersect the Plane.

    Parameters

    Returns Nullable<number>

  • Intersect this Ray with a Plane, returning the intersection point or null if there is no intersection.

    Parameters

    • plane: Plane

      the Plane to intersect with.

    • target: Vector3

      the result will be copied into this Vector3.

    Returns Nullable<Vector3>

  • Return true if this Ray intersects with the Plane.

    Parameters

    Returns boolean

  • Intersect this Ray with a Box3, returning the intersection point or null if there is no intersection.

    Parameters

    • box: Box3

      the Box3 to intersect with.

    • target: Vector3

      the result will be copied into this Vector3.

    Returns Nullable<Vector3>

  • Return true if this Ray intersects with the Box3.

    Parameters

    Returns boolean

  • Returns true if this and the other ray have equal origin| origin and direction.

    Parameters

    • ray: Ray

      the Ray to compare to.

    Returns boolean

  • Intersect this Ray with a triangle, returning the intersection point or null if there is no intersection.

    Parameters

    • a: Vector3
    • b: Vector3
    • c: Vector3
    • backfaceCulling: boolean

      whether to use backface culling

    • target: Vector3

      the result will be copied into this Vector3.

    Returns Nullable<Vector3>