RayHit

Ray hit.

Result of a rayCast or rayCast.

Note: this class wraps internal engine data and should only be created internally.

.constructor(scene: Scene, ptr: number) ⇒ RayHit 

ParamTypeDescription
sceneScene
ptrnumberPointer to the ray hits memory.

.distances: Float32Array 

Equivalent to getDistances.

Note: Prefer to use getDistances for performance.

.engine: WonderlandEngine 

Hosting engine instance.

.hitCount: number 

Number of hits (max 4)

.locations: Float32Array[] 

Equivalent to getLocations.

Note: Prefer to use getLocations for performance.

.normals: Float32Array[] 

Equivalent to getNormals.

Note: Prefer to use getNormals for performance.

.objects: null | Object3D[] 

Equivalent to getObjects.

Note: Prefer to use getObjects for performance.

.getDistances<T>(out: T) ⇒ T 

.getDistances() ⇒ Float32Array

Prefer these to recalculating the distance from locations.

Distances of array hits to ray origin.

Returns: The out parameter.

ParamTypeDescription
outTDestination array/vector, expected to have at least this.hitCount elements.
Template ParamType Definition
Textends NumberArray

.getLocations<T>(out: T) ⇒ T 

.getLocations() ⇒ Float32Array[]

Array of ray hit locations.

Usage 

1const hit = engine.physics.rayCast();
2if (hit.hitCount > 0) {
3    const locations = hit.getLocations();
4    console.log(`Object hit at: ${locations[0][0]}, ${locations[0][1]}, ${locations[0][2]}`);
5}

Returns: The out parameter.

ParamTypeDescription
outTDestination array of arrays/vectors, expected to have at least this.hitCount elements. Each array is expected to have at least 3 elements.
Template ParamType Definition
Textends NumberArray[]

.getNormals<T>(out: T) ⇒ T 

.getNormals() ⇒ Float32Array[]

Array of ray hit normals (only when using rayCast.

Returns: The out parameter.

ParamTypeDescription
outTDestination array of arrays/vectors, expected to have at least this.hitCount elements. Each array is expected to have at least 3 elements.
Template ParamType Definition
Textends NumberArray[]

.getObjects(out: Object3D[]) ⇒ Object3D[] 

Array of hit objects.

Returns: The out parameter.

ParamTypeDescription
outObject3D[]Destination array/vector, expected to have at least this.hitCount elements.