API

Class Ray

Class representing a ray with position and direction

Index
  • Creates a new ray

    Parameters

    • origin: Vector3

      origin point

    • direction: Vector3

      direction

    • length: number = Number.MAX_VALUE

      length of the ray

    • epsilon: number = Epsilon

      The epsilon value to use when calculating the ray/triangle intersection (default: Epsilon from math constants)

    Returns Ray

direction: Vector3

direction

epsilon: number = Epsilon

[Epsilon] The epsilon value to use when calculating the ray/triangle intersection (default: Epsilon from math constants)

length: number = Number.MAX_VALUE

[Number.MAX_VALUE] length of the ray

origin: Vector3

origin point

  • Intersection test between the ray and a given segment within a given tolerance (threshold)

    Parameters

    • sega: DeepImmutable<Vector3>

      the first point of the segment to test the intersection against

    • segb: DeepImmutable<Vector3>

      the second point of the segment to test the intersection against

    • threshold: number

      the tolerance margin, if the ray doesn't intersect the segment but is close to the given threshold, the intersection is successful

    Returns number

    the distance from the ray origin to the intersection point if there's intersection, or -1 if there's no intersection

  • Calculate the intercept of a ray on a given axis

    Parameters

    • axis: string

      to check 'x' | 'y' | 'z'

    • offset: number = 0

      from axis interception (i.e. an offset of 1y is intercepted above ground)

    Returns Nullable<Vector3>

    a vector containing the coordinates where 'axis' is equal to zero (else offset), or null if there is no intercept.

  • Checks if the ray intersects a box This does not account for the ray length by design to improve perfs.

    Parameters

    • box: DeepImmutable<BoundingBox>

      the bounding box to check

    • intersectionTreshold: number = 0

      extra extend to be added to the BoundingBox in all direction

    Returns boolean

    if the box was hit

  • Checks if the ray intersects a box This does not account for the ray length by design to improve perfs.

    Parameters

    • minimum: DeepImmutable<Vector3>

      bound of the box

    • maximum: DeepImmutable<Vector3>

      bound of the box

    • intersectionTreshold: number = 0

      extra extend to be added to the box in all direction

    Returns boolean

    if the box was hit

  • Checks if ray intersects a mesh. The ray is defined in WORLD space. A mesh triangle can be picked both from its front and back sides, irrespective of orientation.

    Parameters

    • mesh: DeepImmutable<AbstractMesh>

      the mesh to check

    • OptionalfastCheck: boolean

      defines if the first intersection will be used (and not the closest)

    • OptionaltrianglePredicate: TrianglePickingPredicate

      defines an optional predicate used to select faces when a mesh intersection is detected

    • onlyBoundingInfo: boolean = false

      defines a boolean indicating if picking should only happen using bounding info (false by default)

    • OptionalworldToUse: any

      defines the world matrix to use to get the world coordinate of the intersection point

    • skipBoundingInfo: boolean = false

      a boolean indicating if we should skip the bounding info check

    Returns PickingInfo

    picking info of the intersection

  • Checks if ray intersects a mesh

    Parameters

    • meshes: DeepImmutable<AbstractMesh>[]

      the meshes to check

    • OptionalfastCheck: boolean

      defines if the first intersection will be used (and not the closest)

    • Optionalresults: PickingInfo[]

      array to store result in

    Returns PickingInfo[]

    Array of picking infos

  • Checks if ray intersects a plane

    Parameters

    • plane: DeepImmutable<Plane>

      the plane to check

    Returns Nullable<number>

    the distance away it was hit

  • If the ray hits a sphere

    Parameters

    • sphere: DeepImmutable<BoundingSphere>

      the bounding sphere to check

    • intersectionTreshold: number = 0

      extra extend to be added to the BoundingSphere in all direction

    Returns boolean

    true if it hits the sphere

  • If the ray hits a triange

    Parameters

    • vertex0: DeepImmutable<Vector3>

      triangle vertex

    • vertex1: DeepImmutable<Vector3>

      triangle vertex

    • vertex2: DeepImmutable<Vector3>

      triangle vertex

    Returns Nullable<IntersectionInfo>

    intersection information if hit

  • Unproject a ray from screen space to object space

    Parameters

    • sourceX: float

      defines the screen space x coordinate to use

    • sourceY: float

      defines the screen space y coordinate to use

    • viewportWidth: number

      defines the current width of the viewport

    • viewportHeight: number

      defines the current height of the viewport

    • world: DeepImmutable<Matrix>

      defines the world matrix to use (can be set to Identity to go to world space)

    • view: DeepImmutable<Matrix>

      defines the view matrix to use

    • projection: DeepImmutable<Matrix>

      defines the projection matrix to use

    Returns void

  • Update the ray from viewport position

    Parameters

    • x: number

      position

    • y: number

      y position

    • viewportWidth: number

      viewport width

    • viewportHeight: number

      viewport height

    • world: DeepImmutable<Matrix>

      world matrix

    • view: DeepImmutable<Matrix>

      view matrix

    • projection: DeepImmutable<Matrix>

      projection matrix

    • enableDistantPicking: boolean = false

      defines if picking should handle large values for mesh position/scaling (false by default)

    Returns Ray

    this ray updated

  • Function will update a transformed ray starting from origin and ending at the end point. Ray's length will be set, and ray will be transformed to the given world matrix.

    Parameters

    • origin: Vector3

      The origin point

    • end: Vector3

      The end point

    • result: Ray

      the object to store the result

    • world: DeepImmutable<Matrix> = Matrix.IdentityReadOnly

      a matrix to transform the ray to. Default is the identity matrix.

    Returns Ray

    the ref ray

  • Creates a new ray from screen space and viewport

    Parameters

    • x: number

      position

    • y: number

      y position

    • viewportWidth: number

      viewport width

    • viewportHeight: number

      viewport height

    • world: DeepImmutable<Matrix>

      world matrix

    • view: DeepImmutable<Matrix>

      view matrix

    • projection: DeepImmutable<Matrix>

      projection matrix

    Returns Ray

    new ray

  • Function will create a new transformed ray starting from origin and ending at the end point. Ray's length will be set, and ray will be transformed to the given world matrix.

    Parameters

    • origin: Vector3

      The origin point

    • end: Vector3

      The end point

    • world: DeepImmutable<Matrix> = Matrix.IdentityReadOnly

      a matrix to transform the ray to. Default is the identity matrix.

    Returns Ray

    the new ray

  • Transforms a ray by a matrix

    Parameters

    • ray: DeepImmutable<Ray>

      ray to transform

    • matrix: DeepImmutable<Matrix>

      matrix to apply

    Returns Ray

    the resulting new ray

  • Transforms a ray by a matrix

    Parameters

    • ray: DeepImmutable<Ray>

      ray to transform

    • matrix: DeepImmutable<Matrix>

      matrix to apply

    • result: Ray

      ray to store result in

    Returns Ray

    the updated result ray