computeBoundingSphere method
void
computeBoundingSphere()
override
Computes the bounding sphere of the geometry, and updates the boundingSphere attribute.
The engine automatically computes the bounding sphere when it is needed, e.g., for ray casting or view frustum culling. You may need to recompute the bounding sphere if the geometry vertices are modified.
Implementation
void computeBoundingSphere() {
if ( this.boundingSphere == null ) {
this.boundingSphere = new BoundingSphere();
}
if ( this.boundingBox == null ) {
this.computeBoundingBox();
}
final start = this.attributes['instanceStart'];
final end = this.attributes['instanceEnd'];
if ( start != null && end != null ) {
final center = this.boundingSphere!.center;
this.boundingBox?.getCenter( center );
double maxRadiusSq = 0;
for (int i = 0, il = start.count; i < il; i ++ ) {
_vector.fromBuffer( start, i );
maxRadiusSq = math.max( maxRadiusSq, center.distanceToSquared( _vector ) );
_vector.fromBuffer( end, i );
maxRadiusSq = math.max( maxRadiusSq, center.distanceToSquared( _vector ) );
}
this.boundingSphere?.radius = math.sqrt( maxRadiusSq );
if (this.boundingSphere!.radius.isNaN) {
console.error( 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.');
}
}
}