public
Created

Create POT texture from a nonPOT

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13
var texture = THREE.ImageUtils.loadTexture( 'nonPOT.png', new THREE.UVMapping(), function () {
 
var nextPOT = function ( value ) { var pot = 1; while ( pot < value ) pot <<= 1; return pot; };
 
var canvas = document.createElement( 'canvas' );
canvas.width = nextPOT( texture.image.width );
canvas.height = nextPOT( texture.image.height );
 
canvas.getContext( '2d' ).drawImage( texture.image, 0, 0, texture.image.width, texture.image.height, 0, 0, canvas.width, canvas.height );
 
texture.image = canvas;
 
} );

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.