raycast method
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 visibility = _visibility;
final active = _active;
final drawRanges = _drawRanges;
final geometryCount = _geometryCount;
final matrixWorld = this.matrixWorld;
final batchGeometry = geometry;
// iterate over each geometry
_mesh.material = material;
_mesh.geometry?.index = batchGeometry!.index;
_mesh.geometry?.attributes = batchGeometry!.attributes;
_mesh.geometry?.boundingBox ??= BoundingBox();
_mesh.geometry?.boundingSphere ??= BoundingSphere();
for ( int i = 0; i < geometryCount; i ++ ) {
if ( ! visibility[ i ] || ! active[ i ] ) {
continue;
}
final drawRange = drawRanges[ i ];
_mesh.geometry?.setDrawRange( drawRange.start, drawRange.count );
// ge the intersects
getMatrixAt( i, _mesh.matrixWorld )?.premultiply( matrixWorld );
getBoundingBoxAt( i, _mesh.geometry?.boundingBox );
getBoundingSphereAt( i, _mesh.geometry?.boundingSphere );
_mesh.raycast( raycaster, _batchIntersects );
// add batch id to the intersects
for (int j = 0, l = _batchIntersects.length; j < l; j ++ ) {
final intersect = _batchIntersects[ j ];
intersect.object = this;
intersect.batchId = i;
intersects.add( intersect );
}
_batchIntersects.length = 0;
}
_mesh.material = null;
_mesh.geometry?.index = null;
_mesh.geometry?.attributes = {};
_mesh.geometry?.setDrawRange( 0, double.maxFinite.toInt() );
}