浏览代码

KTX2Loader: Fix regression in mipmap chain upload (#26095)

* KTX2Loader: Fix regression in mipmap chain upload.

* clarify comment
Don McCurdy 2 年之前
父节点
当前提交
2b09a2c05e
共有 1 个文件被更改,包括 22 次插入2 次删除
  1. 22 2
      examples/jsm/loaders/KTX2Loader.js

+ 22 - 2
examples/jsm/loaders/KTX2Loader.js

@@ -526,8 +526,28 @@ KTX2Loader.BasisWorker = function () {
 				for ( let layer = 0; layer < layerCount; layer ++ ) {
 
 					const levelInfo = ktx2File.getImageLevelInfo( mip, layer, face );
-					mipWidth = levelInfo.origWidth < 4 ? levelInfo.origWidth : levelInfo.width;
-					mipHeight = levelInfo.origHeight < 4 ? levelInfo.origHeight : levelInfo.height;
+
+					if ( face === 0 && mip === 0 && layer === 0 && ( levelInfo.origWidth % 4 !== 0 || levelInfo.origHeight % 4 !== 0 ) ) {
+
+						console.warn( 'THREE.KTX2Loader: ETC1S and UASTC textures should use multiple-of-four dimensions.' );
+
+					}
+
+					if ( levelCount > 1 ) {
+
+						mipWidth = levelInfo.origWidth;
+						mipHeight = levelInfo.origHeight;
+
+					} else {
+
+						// Handles non-multiple-of-four dimensions in textures without mipmaps. Textures with
+						// mipmaps must use multiple-of-four dimensions, for some texture formats and APIs.
+						// See mrdoob/three.js#25908.
+						mipWidth = levelInfo.width;
+						mipHeight = levelInfo.height;
+
+					}
+
 					const dst = new Uint8Array( ktx2File.getImageTranscodedSizeInBytes( mip, layer, 0, transcoderFormat ) );
 					const status = ktx2File.transcodeImage( dst, mip, layer, face, transcoderFormat, 0, - 1, - 1 );