提交 df6c2f95 编写于 作者: M Mr.doob

Merge pull request #7091 from nopjia/dev

DDSLoader: Verify all faces of cubemap
...@@ -16,7 +16,7 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) { ...@@ -16,7 +16,7 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {
var dds = { mipmaps: [], width: 0, height: 0, format: null, mipmapCount: 1 }; var dds = { mipmaps: [], width: 0, height: 0, format: null, mipmapCount: 1 };
// Adapted from @toji's DDS utils // 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: // All values and structures referenced from:
// http://msdn.microsoft.com/en-us/library/bb943991.aspx/ // http://msdn.microsoft.com/en-us/library/bb943991.aspx/
...@@ -175,9 +175,9 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) { ...@@ -175,9 +175,9 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {
default: default:
if ( header[ off_RGBBitCount ] == 32 if ( header[ off_RGBBitCount ] === 32
&& header[ off_RBitMask ] & 0xff0000 && header[ off_RBitMask ] & 0xff0000
&& header[ off_GBitMask ] & 0xff00 && header[ off_GBitMask ] & 0xff00
&& header[ off_BBitMask ] & 0xff && header[ off_BBitMask ] & 0xff
&& header[ off_ABitMask ] & 0xff000000 ) { && header[ off_ABitMask ] & 0xff000000 ) {
...@@ -201,9 +201,21 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) { ...@@ -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.width = header[ off_width ];
dds.height = header[ off_height ]; dds.height = header[ off_height ];
...@@ -212,13 +224,13 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) { ...@@ -212,13 +224,13 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {
// Extract mipmaps buffers // Extract mipmaps buffers
var width = dds.width;
var height = dds.height;
var faces = dds.isCubemap ? 6 : 1; var faces = dds.isCubemap ? 6 : 1;
for ( var face = 0; face < faces; face ++ ) { for ( var face = 0; face < faces; face ++ ) {
var width = dds.width;
var height = dds.height;
for ( var i = 0; i < dds.mipmapCount; i ++ ) { for ( var i = 0; i < dds.mipmapCount; i ++ ) {
if ( isRGBAUncompressed ) { if ( isRGBAUncompressed ) {
...@@ -232,23 +244,19 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) { ...@@ -232,23 +244,19 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {
var byteArray = new Uint8Array( buffer, dataOffset, dataLength ); var byteArray = new Uint8Array( buffer, dataOffset, dataLength );
} }
var mipmap = { "data": byteArray, "width": width, "height": height }; var mipmap = { "data": byteArray, "width": width, "height": height };
dds.mipmaps.push( mipmap ); dds.mipmaps.push( mipmap );
dataOffset += dataLength; dataOffset += dataLength;
width = Math.max( width * 0.5, 1 ); width = Math.max( width >> 1, 1 );
height = Math.max( height * 0.5, 1 ); height = Math.max( height >> 1, 1 );
} }
width = dds.width;
height = dds.height;
} }
return dds; return dds;
}; };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册