raycast method

  1. @override
void raycast(
  1. Raycaster raycaster,
  2. List<Intersection> intersects
)
inherited

Get intersections between a casted ray and this mesh. Raycaster.intersectObject will call this method, but the results are not ordered.

Implementation

@override
void raycast(Raycaster raycaster, List<Intersection> intersects) {
		final geometry = this.geometry;
		final material = this.material;
		final matrixWorld = this.matrixWorld;

		if ( material == null ) return;

		// test with bounding sphere in world space

		if ( geometry?.boundingSphere == null ) geometry?.computeBoundingSphere();

		_sphere.setFrom( geometry!.boundingSphere! );
		_sphere.applyMatrix4( matrixWorld );

		// check distance from ray origin to bounding sphere

		_ray.copyFrom( raycaster.ray ).recast( raycaster.near );

		if ( _sphere.containsPoint( _ray.origin ) == false ) {
			if ( _ray.intersectSphere( _sphere, _sphereHitAt ) == null ) return;
			if ( _ray.origin.distanceToSquared( _sphereHitAt ) > math.pow(( raycaster.far - raycaster.near ),2) ) return;
		}

		// convert ray to local space of mesh

		_inverseMatrix.setFrom( matrixWorld ).invert();
		_ray.copyFrom( raycaster.ray ).applyMatrix4( _inverseMatrix );

		// test with bounding box in local space

		if ( geometry.boundingBox != null ) {
			if ( _ray.intersectsBox( geometry.boundingBox! ) == false ) return;
		}

		// test for intersections with geometry

		this.computeIntersections( raycaster, intersects, _ray );
}