|
@@ -36,19 +36,65 @@ THREE.ImageUtils = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- loadTextureCube: function ( array, mapping, onLoad ) {
|
|
|
+ loadCompressedTexture: function ( url, mapping, onLoad, onError ) {
|
|
|
|
|
|
- var i, l, images = [];
|
|
|
- var texture = new THREE.Texture( images, mapping );
|
|
|
+ var texture = new THREE.CompressedTexture();
|
|
|
+ texture.mapping = mapping;
|
|
|
|
|
|
- texture.flipY = false;
|
|
|
+ var request = new XMLHttpRequest();
|
|
|
+
|
|
|
+ request.onload = function () {
|
|
|
+
|
|
|
+ var buffer = request.response;
|
|
|
+ var dds = THREE.ImageUtils.parseDDS( buffer, true );
|
|
|
+
|
|
|
+ texture.format = dds.format;
|
|
|
+
|
|
|
+ texture.mipmaps = dds.mipmaps;
|
|
|
+ texture.image.width = dds.width;
|
|
|
+ texture.image.height = dds.height;
|
|
|
+
|
|
|
+ // gl.generateMipmap fails for compressed textures
|
|
|
+ // mipmaps must be embedded in the DDS file
|
|
|
+ // or texture filters must not use mipmapping
|
|
|
+
|
|
|
+ texture.generateMipmaps = false;
|
|
|
+
|
|
|
+ texture.needsUpdate = true;
|
|
|
+
|
|
|
+ if ( onLoad ) onLoad( texture );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ request.onerror = onError;
|
|
|
+
|
|
|
+ request.open( 'GET', url, true );
|
|
|
+ request.responseType = "arraybuffer";
|
|
|
+ request.send( null );
|
|
|
|
|
|
+ return texture;
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ loadTextureCube: function ( array, mapping, onLoad, onError ) {
|
|
|
+
|
|
|
+ var images = [];
|
|
|
images.loadCount = 0;
|
|
|
|
|
|
- for ( i = 0, l = array.length; i < l; ++ i ) {
|
|
|
+ var texture = new THREE.Texture();
|
|
|
+ texture.image = images;
|
|
|
+ if ( mapping !== undefined ) texture.mapping = mapping;
|
|
|
+
|
|
|
+ // no flipping needed for cube textures
|
|
|
+
|
|
|
+ texture.flipY = false;
|
|
|
+
|
|
|
+ for ( var i = 0, il = array.length; i < il; ++ i ) {
|
|
|
|
|
|
- images[ i ] = new Image();
|
|
|
- images[ i ].onload = function () {
|
|
|
+ var cubeImage = new Image();
|
|
|
+ images[ i ] = cubeImage;
|
|
|
+
|
|
|
+ cubeImage.onload = function () {
|
|
|
|
|
|
images.loadCount += 1;
|
|
|
|
|
@@ -61,8 +107,10 @@ THREE.ImageUtils = {
|
|
|
|
|
|
};
|
|
|
|
|
|
- images[ i ].crossOrigin = this.crossOrigin;
|
|
|
- images[ i ].src = array[ i ];
|
|
|
+ cubeImage.onerror = onError;
|
|
|
+
|
|
|
+ cubeImage.crossOrigin = this.crossOrigin;
|
|
|
+ cubeImage.src = array[ i ];
|
|
|
|
|
|
}
|
|
|
|
|
@@ -70,41 +118,69 @@ THREE.ImageUtils = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- loadCompressedTexture: function ( url, mapping, onLoad, onError ) {
|
|
|
+ loadCompressedTextureCube: function ( array, mapping, onLoad, onError ) {
|
|
|
+
|
|
|
+ var images = [];
|
|
|
+ images.loadCount = 0;
|
|
|
|
|
|
var texture = new THREE.CompressedTexture();
|
|
|
- texture.mapping = mapping;
|
|
|
+ texture.image = images;
|
|
|
+ if ( mapping !== undefined ) texture.mapping = mapping;
|
|
|
|
|
|
- var xhr = new XMLHttpRequest();
|
|
|
+ // no flipping for cube textures
|
|
|
+ // (also flipping doesn't work for compressed textures )
|
|
|
|
|
|
- xhr.onload = function () {
|
|
|
+ texture.flipY = false;
|
|
|
|
|
|
- var buffer = xhr.response;
|
|
|
- var dds = THREE.ImageUtils.parseDDS( buffer, true );
|
|
|
+ // can't generate mipmaps for compressed textures
|
|
|
+ // mips must be embedded in DDS files
|
|
|
|
|
|
- texture.format = dds.format;
|
|
|
+ texture.generateMipmaps = false;
|
|
|
|
|
|
- texture.mipmaps = dds.mipmaps;
|
|
|
- texture.image.width = dds.width;
|
|
|
- texture.image.height = dds.height;
|
|
|
+ var generateCubeFaceCallback = function ( rq, img ) {
|
|
|
|
|
|
- // gl.generateMipmap fails for compressed textures
|
|
|
- // mipmaps must be embedded in the DDS file
|
|
|
- // or texture filters must not use mipmapping
|
|
|
+ return function () {
|
|
|
|
|
|
- texture.generateMipmaps = false;
|
|
|
+ var buffer = rq.response;
|
|
|
+ var dds = THREE.ImageUtils.parseDDS( buffer, true );
|
|
|
|
|
|
- texture.needsUpdate = true;
|
|
|
+ img.format = dds.format;
|
|
|
|
|
|
- if ( onLoad ) onLoad( texture );
|
|
|
+ img.mipmaps = dds.mipmaps;
|
|
|
+ img.width = dds.width;
|
|
|
+ img.height = dds.height;
|
|
|
+
|
|
|
+ images.loadCount += 1;
|
|
|
+
|
|
|
+ if ( images.loadCount === 6 ) {
|
|
|
+
|
|
|
+ texture.format = dds.format;
|
|
|
+ texture.needsUpdate = true;
|
|
|
+ if ( onLoad ) onLoad();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- xhr.onerror = onError;
|
|
|
+ for ( var i = 0, il = array.length; i < il; ++ i ) {
|
|
|
+
|
|
|
+ var cubeImage = {};
|
|
|
+ images[ i ] = cubeImage;
|
|
|
+
|
|
|
+ var request = new XMLHttpRequest();
|
|
|
|
|
|
- xhr.open( 'GET', url, true );
|
|
|
- xhr.responseType = "arraybuffer";
|
|
|
- xhr.send( null );
|
|
|
+ request.onload = generateCubeFaceCallback( request, cubeImage );
|
|
|
+ request.onerror = onError;
|
|
|
+
|
|
|
+ var url = array[ i ];
|
|
|
+
|
|
|
+ request.open( 'GET', url, true );
|
|
|
+ request.responseType = "arraybuffer";
|
|
|
+ request.send( null );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
return texture;
|
|
|
|