浏览代码

GLTFLoader: Fix alpha detection for colorType=3,4

Don McCurdy 4 年之前
父节点
当前提交
cefb1f97d5
共有 2 个文件被更改,包括 14 次插入2 次删除
  1. 7 1
      examples/js/loaders/GLTFLoader.js
  2. 7 1
      examples/jsm/loaders/GLTFLoader.js

+ 7 - 1
examples/js/loaders/GLTFLoader.js

@@ -2170,8 +2170,14 @@ THREE.GLTFLoader = ( function () {
 
 				if ( source.mimeType === 'image/png' ) {
 
+					// Inspect the PNG 'IHDR' chunk to determine whether the image could have an
+					// alpha channel. This check is conservative — the image could have an alpha
+					// channel with all values == 1, and the indexed type (colorType == 3) only
+					// sometimes contains alpha.
+					//
 					// https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
-					hasAlpha = new DataView( bufferView, 25, 1 ).getUint8( 0, false ) === 6;
+					var colorType = new DataView( bufferView, 25, 1 ).getUint8( 0, false );
+					hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
 
 				}
 

+ 7 - 1
examples/jsm/loaders/GLTFLoader.js

@@ -2233,8 +2233,14 @@ var GLTFLoader = ( function () {
 
 				if ( source.mimeType === 'image/png' ) {
 
+					// Inspect the PNG 'IHDR' chunk to determine whether the image could have an
+					// alpha channel. This check is conservative — the image could have an alpha
+					// channel with all values == 1, and the indexed type (colorType == 3) only
+					// sometimes contains alpha.
+					//
 					// https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
-					hasAlpha = new DataView( bufferView, 25, 1 ).getUint8( 0, false ) === 6;
+					var colorType = new DataView( bufferView, 25, 1 ).getUint8( 0, false );
+					hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
 
 				}