nape-js API
    Preparing search index...

    Class Ray

    A ray for raycasting queries.

    Fully modernized — uses ZPP_Ray directly (extracted to TypeScript).

    Index

    Constructors

    • Create a Ray from an origin point and a direction vector. Both must be non-null, non-disposed Vec2s.

      Parameters

      • origin: Vec2

        The start point of the ray in world coordinates.

      • direction: Vec2

        The direction vector (need not be unit length).

      Returns Ray

    Accessors

    • get direction(): Vec2

      The ray's direction vector (need not be unit length; the engine normalises internally).

      Returns Vec2

    • set direction(value: Vec2): void

      The ray's direction vector (need not be unit length; the engine normalises internally).

      Parameters

      Returns void

    • get maxDistance(): number

      Maximum travel distance for raycasting queries. Defaults to Infinity.

      Returns number

    • set maxDistance(value: number): void

      Maximum travel distance for raycasting queries. Defaults to Infinity.

      Parameters

      • value: number

      Returns void

    • get userData(): Record<string, unknown>

      Arbitrary user data attached to this Ray.

      Returns Record<string, unknown>

    Methods

    • Compute the axis-aligned bounding box that encloses the ray from origin to maxDistance.

      Returns AABB

      A new AABB wrapping the ray's extent.

    • Return the world-space point at distance along the ray.

      Parameters

      • distance: number

        Distance from the ray origin along the ray direction.

      • weak: boolean = false

        If true, the returned Vec2 is a weak (pooled) reference.

      Returns Vec2

      The point origin + distance * normalised_direction.

    • Return a new Ray with the same origin, direction, and maxDistance. Alias for copy().

      Returns Ray

      A new Ray with the same properties.

    • Return a new Ray with the same origin, direction, and maxDistance.

      Returns Ray

      A deep copy of this Ray.

    • Create a Ray from a line segment. The ray origin is start, direction is end − start, and maxDistance is the segment length.

      Parameters

      • start: Vec2

        The start point of the segment.

      • end: Vec2

        The end point of the segment.

      Returns Ray

      A new Ray spanning the segment.