/* * @author mrdoob / http://mrdoob.com/ * * Abstract Base class to block based textures loader (dds, pvr, ...) */ THREE.CompressedTextureLoader = function () { // override in sub classes this._parser = null; }; THREE.CompressedTextureLoader.prototype = { constructor: THREE.CompressedTextureLoader, load: function ( url, onLoad, onError ) { var scope = this; var images = []; var texture = new THREE.CompressedTexture(); texture.image = images; // no flipping for cube textures // (also flipping doesn't work for compressed textures ) texture.flipY = false; // can't generate mipmaps for compressed textures // mips must be embedded in DDS files texture.generateMipmaps = false; if ( url instanceof Array ) { var loaded = 0; var loader = new THREE.XHRLoader(); loader.setResponseType( 'arraybuffer' ); var loadTexture = function ( i ) { loader.load( url[ i ], function ( buffer ) { var texDatas = scope._parser( buffer, true ); images[ i ] = { width: texDatas.width, height: texDatas.height, format: texDatas.format, mipmaps: texDatas.mipmaps } loaded += 1; if ( loaded === 6 ) { texture.format = texDatas.format; texture.needsUpdate = true; if ( onLoad ) onLoad( texture ); } } ); } for ( var i = 0, il = url.length; i < il; ++ i ) { loadTexture( i ); } } else { // compressed cubemap texture stored in a single DDS file var loader = new THREE.XHRLoader(); loader.setResponseType( 'arraybuffer' ); loader.load( url, function ( buffer ) { var texDatas = scope._parser( buffer, true ); if ( texDatas.isCubemap ) { var faces = texDatas.mipmaps.length / texDatas.mipmapCount; for ( var f = 0; f < faces; f ++ ) { images[ f ] = { mipmaps : [] }; for ( var i = 0; i < texDatas.mipmapCount; i ++ ) { images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] ); images[ f ].format = texDatas.format; images[ f ].width = texDatas.width; images[ f ].height = texDatas.height; } } } else { texture.image.width = texDatas.width; texture.image.height = texDatas.height; texture.mipmaps = texDatas.mipmaps; } texture.format = texDatas.format; texture.needsUpdate = true; if ( onLoad ) onLoad( texture ); } ); } return texture; } };