123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- /*
- * @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;
- }
-
- };
|