diff --git a/examples/js/loaders/DDSLoader.js b/examples/js/loaders/DDSLoader.js index dfaa604d9f1d06af2dae2e36dcbb1732bcd126e5..583ec13005bc90f84603810221136e5c97e3497b 100644 --- a/examples/js/loaders/DDSLoader.js +++ b/examples/js/loaders/DDSLoader.js @@ -16,7 +16,7 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) { var dds = { mipmaps: [], width: 0, height: 0, format: null, mipmapCount: 1 }; // Adapted from @toji's DDS utils - // https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js + // https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js // All values and structures referenced from: // http://msdn.microsoft.com/en-us/library/bb943991.aspx/ @@ -175,9 +175,9 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) { default: - if ( header[ off_RGBBitCount ] == 32 + if ( header[ off_RGBBitCount ] === 32 && header[ off_RBitMask ] & 0xff0000 - && header[ off_GBitMask ] & 0xff00 + && header[ off_GBitMask ] & 0xff00 && header[ off_BBitMask ] & 0xff && header[ off_ABitMask ] & 0xff000000 ) { @@ -201,9 +201,21 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) { } - //TODO: Verify that all faces of the cubemap are present with DDSCAPS2_CUBEMAP_POSITIVEX, etc. + var caps2 = header[ off_caps2 ]; + dds.isCubemap = caps2 & DDSCAPS2_CUBEMAP ? true : false; + if ( dds.isCubemap && ( + ! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEX ) || + ! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX ) || + ! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEY ) || + ! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY ) || + ! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ ) || + ! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ ) + ) ) { + + console.error( 'THREE.DDSLoader.parse: Incomplete cubemap faces' ); + return dds; - dds.isCubemap = header[ off_caps2 ] & DDSCAPS2_CUBEMAP ? true : false; + } dds.width = header[ off_width ]; dds.height = header[ off_height ]; @@ -212,13 +224,13 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) { // Extract mipmaps buffers - var width = dds.width; - var height = dds.height; - var faces = dds.isCubemap ? 6 : 1; for ( var face = 0; face < faces; face ++ ) { + var width = dds.width; + var height = dds.height; + for ( var i = 0; i < dds.mipmapCount; i ++ ) { if ( isRGBAUncompressed ) { @@ -232,23 +244,19 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) { var byteArray = new Uint8Array( buffer, dataOffset, dataLength ); } - + var mipmap = { "data": byteArray, "width": width, "height": height }; dds.mipmaps.push( mipmap ); dataOffset += dataLength; - width = Math.max( width * 0.5, 1 ); - height = Math.max( height * 0.5, 1 ); + width = Math.max( width >> 1, 1 ); + height = Math.max( height >> 1, 1 ); } - width = dds.width; - height = dds.height; - } return dds; }; -