فهرست منبع

#4289 Move isPowerOfTwo to THREE.Math and update all references

Christopher Probst 11 سال پیش
والد
کامیت
9410acc9a9
5فایلهای تغییر یافته به همراه11 افزوده شده و 27 حذف شده
  1. 1 5
      examples/js/Mirror.js
  2. 1 4
      examples/js/WaterShader.js
  3. 1 7
      examples/js/loaders/MTLLoader.js
  4. 5 1
      src/math/Math.js
  5. 3 10
      src/renderers/WebGLRenderer.js

+ 1 - 5
examples/js/Mirror.js

@@ -57,10 +57,6 @@ THREE.Mirror = function ( renderer, camera, options ) {
 
 	this.name = 'mirror_' + this.id;
 
-	function isPowerOfTwo ( value ) {
-		return ( value & ( value - 1 ) ) === 0;
-	};
-
 	options = options || {};
 
 	this.matrixNeedsUpdate = true;
@@ -133,7 +129,7 @@ THREE.Mirror = function ( renderer, camera, options ) {
 	this.material.uniforms.mirrorColor.value = mirrorColor;
 	this.material.uniforms.textureMatrix.value = this.textureMatrix;
 
-	if ( !isPowerOfTwo(width) || !isPowerOfTwo( height ) ) {
+	if ( !THREE.Math.isPowerOfTwo(width) || !THREE.Math.isPowerOfTwo( height ) ) {
 
 		this.texture.generateMipmaps = false;
 		this.tempTexture.generateMipmaps = false;

+ 1 - 4
examples/js/WaterShader.js

@@ -107,9 +107,6 @@ THREE.Water = function ( renderer, camera, scene, options ) {
 	THREE.Object3D.call( this );
 	this.name = 'water_' + this.id;
 
-	function isPowerOfTwo ( value ) {
-		return ( value & ( value - 1 ) ) === 0;
-	};
 	function optionalParameter ( value, defaultValue ) {
 		return value !== undefined ? value : defaultValue;
 	};
@@ -177,7 +174,7 @@ THREE.Water = function ( renderer, camera, scene, options ) {
 	
 	this.material.uniforms.eye.value = this.eye;
 	
-	if ( !isPowerOfTwo(width) || !isPowerOfTwo(height) ) 
+	if ( !THREE.Math.isPowerOfTwo(width) || !THREE.Math.isPowerOfTwo(height) )
 	{
 		this.texture.generateMipmaps = false;
 		this.tempTexture.generateMipmaps = false;

+ 1 - 7
examples/js/loaders/MTLLoader.js

@@ -395,7 +395,7 @@ THREE.MTLLoader.MaterialCreator.prototype = {
 
 THREE.MTLLoader.ensurePowerOfTwo_ = function ( image ) {
 
-	if ( ! THREE.MTLLoader.isPowerOfTwo_( image.width ) || ! THREE.MTLLoader.isPowerOfTwo_( image.height ) ) {
+	if ( ! THREE.Math.isPowerOfTwo_( image.width ) || ! THREE.Math.isPowerOfTwo_( image.height ) ) {
 
 		var canvas = document.createElement( "canvas" );
 		canvas.width = THREE.MTLLoader.nextHighestPowerOfTwo_( image.width );
@@ -411,12 +411,6 @@ THREE.MTLLoader.ensurePowerOfTwo_ = function ( image ) {
 
 };
 
-THREE.MTLLoader.isPowerOfTwo_ = function ( x ) {
-
-	return ( x & ( x - 1 ) ) === 0;
-
-};
-
 THREE.MTLLoader.nextHighestPowerOfTwo_ = function( x ) {
 
 	--x;

+ 5 - 1
src/math/Math.js

@@ -152,6 +152,10 @@ THREE.Math = {
 
 		};
 
-	}()
+	}(),
+
+	isPowerOfTwo: function ( value ) {
+		return ( value & ( value - 1 ) ) === 0 && value !== 0;
+	}
 
 };

+ 3 - 10
src/renderers/WebGLRenderer.js

@@ -5822,13 +5822,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	// Textures
 
-
-	function isPowerOfTwo ( value ) {
-
-		return ( value & ( value - 1 ) ) === 0;
-
-	};
-
 	function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
 
 		if ( isImagePowerOfTwo ) {
@@ -5886,7 +5879,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 			_gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
 
 			var image = texture.image,
-			isImagePowerOfTwo = isPowerOfTwo( image.width ) && isPowerOfTwo( image.height ),
+			isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
 			glFormat = paramThreeToGL( texture.format ),
 			glType = paramThreeToGL( texture.type );
 
@@ -6036,7 +6029,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 				}
 
 				var image = cubeImage[ 0 ],
-				isImagePowerOfTwo = isPowerOfTwo( image.width ) && isPowerOfTwo( image.height ),
+				isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
 				glFormat = paramThreeToGL( texture.format ),
 				glType = paramThreeToGL( texture.type );
 
@@ -6149,7 +6142,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			// Setup texture, create render and frame buffers
 
-			var isTargetPowerOfTwo = isPowerOfTwo( renderTarget.width ) && isPowerOfTwo( renderTarget.height ),
+			var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
 				glFormat = paramThreeToGL( renderTarget.format ),
 				glType = paramThreeToGL( renderTarget.type );