raycast method
Get intersections between a casted ray and this mesh.
Raycaster.intersectObject
will call this method, but the results
are not ordered.
Implementation
void raycast(Raycaster raycaster,List<Intersection> intersects ) {
final material = this.material! as LineMaterial;
final worldUnits = material.worldUnits;
final camera = raycaster.camera;
if(worldUnits == null) {
console.error( 'LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.' );
}
final threshold = ( raycaster.params['Line2'] != null ) ? raycaster.params['Line2']['threshold'] ?? 0 : 0;
_ray = raycaster.ray;
final matrixWorld = this.matrixWorld;
final geometry = this.geometry!;
_lineWidth = material.linewidth! + threshold;
// check if we intersect the sphere bounds
if ( geometry.boundingSphere == null ) {
geometry.computeBoundingSphere();
}
_sphere.setFrom(geometry.boundingSphere!).applyMatrix4( matrixWorld );
// increase the sphere bounds by the worst case line screen space width
late double sphereMargin;
if ( worldUnits == true){
sphereMargin = _lineWidth * 0.5;
}
else {
final distanceToSphere = math.max( camera.near, _sphere.distanceToPoint( _ray.origin ) );
sphereMargin = getWorldSpaceHalfWidth( camera, distanceToSphere, material.resolution );
}
_sphere.radius += sphereMargin;
if ( _ray.intersectsSphere( _sphere ) == false ) {
return;
}
// check if we intersect the box bounds
if(geometry.boundingBox == null){
geometry.computeBoundingBox();
}
_box.setFrom( geometry.boundingBox! ).applyMatrix4( matrixWorld );
// increase the box bounds by the worst case line width
late double boxMargin;
if ( worldUnits == true) {
boxMargin = _lineWidth * 0.5;
}
else {
final distanceToBox = math.max( camera.near, _box.distanceToPoint( _ray.origin ) );
boxMargin = getWorldSpaceHalfWidth( camera, distanceToBox, material.resolution );
}
_box.expandByScalar( boxMargin );
if ( _ray.intersectsBox( _box ) == false ) {
return;
}
if ( worldUnits == true) {
raycastWorldUnits( this, intersects );
}
else {
raycastScreenSpace( this, camera, intersects );
}
}