Class: EventListeners

Raycaster#EventListeners(camera, renderer, settingsopt)

new EventListeners(camera, renderer, settingsopt)

Create a mouse events listeners for Raycaster instance.

The following events are listening.

  • mousemove. Is fired at an element when a pointing device (usually a mouse) is moved while the cursor's hotspot is inside it. See Element: mousemove event.
  • pointerdown. Is fired when a pointer becomes active. For mouse, it is fired when the device transitions from no buttons depressed to at least one button depressed. For touch, it is fired when physical contact is made with the digitizer. For pen, it is fired when the stylus makes physical contact with the digitizer. See Document: pointerdown event.

You can customize your 3D object for following events by add raycaster property into Object3D.userData.

  • onIntersection. Callback function that take as input the intersectObject, and mouse position. Fires after intersection of the mouse pointer with a 3D object.
  • onIntersectionOut. Callback function. Fires if mouse pointer leaves of intersection with the 3D object.
  • onMouseDown. Callback function that take as input the intersectObject. User has clicked over 3D object.

Example:
cube.userData.raycaster = {

	onIntersection: function ( intersection, mouse ) {

		if ( cube.userData.currentHex === undefined )
			cube.userData.currentHex = cube.material.emissive.getHex();
		cube.material.emissive.setHex( 0xff0000 );
		Options.raycaster.onIntersection( intersection, options, group, camera, renderer );

	},
	onIntersectionOut: function () {

		if ( cube.userData.currentHex !== undefined )
			cube.material.emissive.setHex( cube.userData.currentHex );
		cube.userData.currentHex = undefined;
		Options.raycaster.onIntersectionOut( group, renderer );

	},
	onMouseDown: function ( intersection ) {

		alert( 'Clicked over cube.' );

	},

}
Parameters:
Name Type Attributes Default Description
camera THREE.Camera PerspectiveCamera instance
renderer THREE.WebGLRenderer WebGLRenderer instance
settings Object <optional>
{} the following settings are available
Properties
Name Type Attributes Default Description
options Options <optional>
{} Options instance
threshold number <optional>
0.03 Precision of the raycaster when intersecting objects, in world units. See Raycaster.params.
Source:

Methods

addParticle(particle)

Adds new particle into array of objects to check for intersection with the ray.
Parameters:
Name Type Description
particle THREE.Mesh The Mech or derived class instance for check for intersection with the ray.
Source:
See:

removeParticle(particle)

Removes particle from array of objects to check for intersection with the ray.
Parameters:
Name Type Description
particle THREE.Mesh The Mech for removing.
Source:
See: