Class Ray
Constructors
constructor
-
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
- origin: Vector3
Properties
direction
direction
epsilon
[Epsilon] The epsilon value to use when calculating the ray/triangle intersection (default: Epsilon from math constants)
length
[Number.MAX_VALUE] length of the ray
origin
origin point
Methods
clone
intersection Segment
-
intersectionSegment(
sega: DeepImmutable<Vector3>,
segb: DeepImmutable<Vector3>,
threshold: number,
): numberIntersection 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
- sega: DeepImmutable<Vector3>
intersects Axis
-
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.
- axis: string
intersects Box
-
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
- box: DeepImmutable<BoundingBox>
intersects Box Min Max
-
intersectsBoxMinMax(
minimum: DeepImmutable<Vector3>,
maximum: DeepImmutable<Vector3>,
intersectionTreshold?: number,
): booleanChecks 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
- minimum: DeepImmutable<Vector3>
intersects Mesh
-
intersectsMesh(
mesh: DeepImmutable<AbstractMesh>,
fastCheck?: boolean,
trianglePredicate?: TrianglePickingPredicate,
onlyBoundingInfo?: boolean,
worldToUse?: any,
skipBoundingInfo?: boolean,
): PickingInfoChecks 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: booleandefines if the first intersection will be used (and not the closest)
OptionaltrianglePredicate: TrianglePickingPredicatedefines 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: anydefines 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
- mesh: DeepImmutable<AbstractMesh>
intersects Meshes
-
intersectsMeshes(
meshes: DeepImmutable<AbstractMesh>[],
fastCheck?: boolean,
results?: PickingInfo[],
): PickingInfo[]Checks if ray intersects a mesh
Parameters
- meshes: DeepImmutable<AbstractMesh>[]
the meshes to check
OptionalfastCheck: booleandefines if the first intersection will be used (and not the closest)
Optionalresults: PickingInfo[]array to store result in
Returns PickingInfo[]
Array of picking infos
- meshes: DeepImmutable<AbstractMesh>[]
intersects Plane
-
Checks if ray intersects a plane
Parameters
- plane: DeepImmutable<Plane>
the plane to check
Returns Nullable<number>
the distance away it was hit
- plane: DeepImmutable<Plane>
intersects Sphere
-
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
- sphere: DeepImmutable<BoundingSphere>
intersects Triangle
-
intersectsTriangle(
vertex0: DeepImmutable<Vector3>,
vertex1: DeepImmutable<Vector3>,
vertex2: DeepImmutable<Vector3>,
): Nullable<IntersectionInfo>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
- vertex0: DeepImmutable<Vector3>
unproject Ray To Ref
-
unprojectRayToRef(
sourceX: float,
sourceY: float,
viewportWidth: number,
viewportHeight: number,
world: DeepImmutable<Matrix>,
view: DeepImmutable<Matrix>,
projection: DeepImmutable<Matrix>,
): voidUnproject 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
- sourceX: float
update
-
update(
x: number,
y: number,
viewportWidth: number,
viewportHeight: number,
world: DeepImmutable<Matrix>,
view: DeepImmutable<Matrix>,
projection: DeepImmutable<Matrix>,
enableDistantPicking?: boolean,
): RayUpdate 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
- x: number
StaticCreate From To To Ref
-
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
- origin: Vector3
StaticCreate New
-
CreateNew(
x: number,
y: number,
viewportWidth: number,
viewportHeight: number,
world: DeepImmutable<Matrix>,
view: DeepImmutable<Matrix>,
projection: DeepImmutable<Matrix>,
): RayCreates 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
- x: number
StaticCreate New From To
-
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
- origin: Vector3
Class representing a ray with position and direction