Skip to main content

SimpleRaycaster

A simple raycaster that allows to easily get items from the scene using the mouse and touch events.

Implements​

Properties​

components​

components: Components

The components instance to which this Raycaster belongs.


enabled​

enabled: boolean = true

Component.enabled


mouse​

readonly mouse: Mouse

The position of the mouse in the screen.


onDisposed​

readonly onDisposed: Event<unknown>

Disposable.onDisposed

Implementation of​

Disposable . onDisposed


three​

readonly three: Raycaster

A reference to the Three.js Raycaster instance. This is used for raycasting operations.


useFastModelPicking​

useFastModelPicking: boolean = false

Whether to use fast model picking to optimize raycasting. When enabled, the raycaster will first use FastModelPicker to identify which model is under the mouse, then only raycast that specific model. This can significantly improve performance when there are many models.


world​

world: World

A reference to the world instance to which this Raycaster belongs. This is used to access the camera and meshes.

Methods​

castRay()​

castRay(data?): Promise<null | Intersection<Object3D<Object3DEventMap>>>

Throws a ray from the camera to the mouse or touch event point and returns the first item found. This also takes into account the clipping planes used by the renderer.

Parameters​

ParameterType
data?object
data.items?Object3D<Object3DEventMap>[]
data.position?Vector2
data.snappingClasses?SnappingClass[]

Returns​

Promise<null | Intersection<Object3D<Object3DEventMap>>>


castRayFromVector()​

castRayFromVector(origin, direction, items): null | Intersection<Object3D<Object3DEventMap>>

Casts a ray from a given origin in a given direction and returns the first item found. This method also takes into account the clipping planes used by the renderer.

Parameters​

ParameterTypeDescription
originVector3The origin of the ray.
directionVector3The direction of the ray.
itemsMesh<BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>, Material | Material[], Object3DEventMap>[]The meshes to query. If not provided, it will query all the meshes stored in World.meshes.

Returns​

null | Intersection<Object3D<Object3DEventMap>>

The first intersection found or null if no intersection was found.


dispose()​

dispose(): void

Disposable.dispose

Returns​

void

Implementation of​

Disposable . dispose