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

Properties

ray: Ray

The Ray used for the raycasting.

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: 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: number

The precision factor of the raycaster when intersecting Line objects.

pointThreshold: number

The distance threshold to check a point's intersection.

layers: Layers
enableScreenSpaceTolerance: boolean

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

_camera: Nullable<Camera3D>
_viewHeight: number

Methods

  • 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

  • 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

  • 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[]

  • 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[]