Raycaster

This class is designed to assist with raycasting. Raycasting is used for mouse picking (working out what objects in the 3d space the mouse is over) amongst other things.

Core Class

This class is designed to assist with raycasting. Raycasting is used for mouse picking (working out what objects in the 3d space the mouse is over) amongst other things.

Constructors

Constructor

new Raycaster(origin?, direction?, near?, far?): Raycaster

Parameters

origin?

Vector3

direction?

Vector3

near?

number

far?

number

Returns

Raycaster

Properties

ray

ray: Ray

The Ray used for the raycasting.


near

near: number

The near factor of the raycaster. This value indicates which objects can be discarded based on the distance. This value shouldn’t be negative and should be smaller than the far property.


far

far: number

The far factor of the raycaster. This value indicates which objects can be discarded based on the distance. This value shouldn’t be negative and should be larger than the near property.


linePrecision

linePrecision: number

The precision factor of the raycaster when intersecting Line objects.


pointThreshold

pointThreshold: number

The distance threshold to check a point’s intersection.


layers

layers: Layers


enableScreenSpaceTolerance

enableScreenSpaceTolerance: boolean

Accept some difference when picked point do not locate on the line or points


_camera

_camera: Nullable<Camera3D>


_viewHeight

_viewHeight: number

Methods

set()

set(origin, direction): void

Set ray, near and far by given origin and direction.

Parameters

origin

Vector3

The origin vector where the ray casts from.

direction

Vector3

The normalized direction vector that gives direction to the ray.

Returns

void


setFromCamera()

setFromCamera(coords, camera, viewHeight?): void

Set ray by given camera’s castRay.

Parameters

coords

Vector2

the position of window where the ray through out.

camera

Camera3D

used to decide a way of casting the ray.

viewHeight?

number

the hight of view window.

Returns

void


intersectObject()

intersectObject(object, recursive, intersects?): Intersection[]

Calculating intersection for given object, return this object if the ray intersect with it.

Parameters

object

Object3D

recursive

boolean

put children of given object into calculation together.

intersects?

Intersection[]

if given, the result will be store here.

Returns

Intersection[]


intersectObjects()

intersectObjects(objects, recursive, intersects?): Intersection[]

Calculating intersection for array of objects, return the objects which the ray intersect with.

Parameters

objects

Object3D[]

recursive

boolean

put children of objects into calculation together.

intersects?

Intersection[]

if given, the result will be store here.

Returns

Intersection[]


raycastScene()

raycastScene(scene, intersects): Intersection[]

Parameters

scene

Scene3D

intersects

Intersection[]

Returns

Intersection[]