Browse Source

Optimize Geometry.prototype.computeBoundingSphere
- Add parameter for vertex skimming
- Minimize square root calculations

Jay Weeks 13 years ago
parent
commit
e5943ee1c7
1 changed files with 6 additions and 6 deletions
  1. 6 6
      src/core/Geometry.js

+ 6 - 6
src/core/Geometry.js

@@ -544,20 +544,20 @@ THREE.Geometry.prototype = {
 
 	},
 
-	computeBoundingSphere: function () {
+	computeBoundingSphere: function ( skip ) {
 
 		if ( ! this.boundingSphere ) this.boundingSphere = { radius: 0 };
 
-		var radius, maxRadius = 0;
+		var radiusSq, maxRadiusSq = 0, vs = skip || 1;
 
-		for ( var v = 0, vl = this.vertices.length; v < vl; v ++ ) {
+		for ( var v = 0, vl = this.vertices.length; v < vl; v += vs ) {
 
-			radius = this.vertices[ v ].length();
-			if ( radius > maxRadius ) maxRadius = radius;
+			radiusSq = this.vertices[ v ].lengthSq();
+			if ( radiusSq > maxRadiusSq ) maxRadiusSq = radiusSq;
 
 		}
 
-		this.boundingSphere.radius = maxRadius;
+		this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
 
 	},