Ray

Class representing a ray with position and direction

• Ray

Constructors

constructor

Find examples in Playground
• Creates a new ray

Parameters

• origin: Vector3

origin point

direction

• Optional length: number

length of the ray

Properties

direction

Find examples in Playground
direction: Vector3

direction

length

Find examples in Playground
length: number

length of the ray

origin

Find examples in Playground
origin: Vector3

origin point

Methods

intersectionSegment

Find examples in Playground
• Intersection test between the ray and a given segment whithin 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

intersectsAxis

Find examples in Playground
• Calculate the intercept of a ray on a given axis

Parameters

• axis: string

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

• Optional offset: number

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.

intersectsBox

Find examples in Playground
• Checks if the ray intersects a box

Parameters

• box: DeepImmutable<BoundingBox>

the bounding box to check

• Optional intersectionTreshold: number

extra extend to be added to the BoundingBox in all direction

Returns boolean

if the box was hit

intersectsBoxMinMax

Find examples in Playground
• Checks if the ray intersects a box

Parameters

• minimum: DeepImmutable<Vector3>

bound of the box

• maximum: DeepImmutable<Vector3>

bound of the box

• Optional intersectionTreshold: number

extra extend to be added to the box in all direction

Returns boolean

if the box was hit

intersectsMesh

Find examples in Playground
• Checks if ray intersects a mesh

Parameters

• mesh: DeepImmutable<AbstractMesh>

the mesh to check

• Optional fastCheck: boolean

if only the bounding box should checked

Returns PickingInfo

picking info of the intersecton

intersectsMeshes

Find examples in Playground
• Checks if ray intersects a mesh

Parameters

• meshes: Array<DeepImmutable<AbstractMesh>>

the meshes to check

• Optional fastCheck: boolean

if only the bounding box should checked

• Optional results: Array<PickingInfo>

array to store result in

Returns Array<PickingInfo>

Array of picking infos

intersectsPlane

Find examples in Playground
• Checks if ray intersects a plane

Parameters

• plane: DeepImmutable<Plane>

the plane to check

Returns Nullable<number>

the distance away it was hit

intersectsSphere

Find examples in Playground
• If the ray hits a sphere

Parameters

• sphere: DeepImmutable<BoundingSphere>

the bounding sphere to check

• Optional intersectionTreshold: number

extra extend to be added to the BoundingSphere in all direction

Returns boolean

true if it hits the sphere

intersectsTriangle

Find examples in Playground
• 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

unprojectRayToRef

Find examples in Playground
• 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

update

Find examples in Playground
• Update the ray from viewport position

Parameters

position

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

this ray updated

Static CreateNew

Find examples in Playground
• Creates a new ray from screen space and viewport

Parameters

position

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

new ray

Static CreateNewFromTo

Find examples in Playground
• 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: DeepImmutable<Vector3>

The origin point

• end: DeepImmutable<Vector3>

The end point

• Optional world: DeepImmutable<Matrix>

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

the new ray

Static Transform

Find examples in Playground
• 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

Static TransformToRef

Find examples in Playground
• 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

Static Zero

Find examples in Playground
• Creates a ray with origin and direction of 0,0,0

Returns Ray

the new ray

Generated using TypeDoc