소스 검색

GLTFLoader: Make error when loading textures with no data clear

If GLTFLoader is used to load a texture with no uri or bufferView, it
uses an empty uri which results in FileLoader loading the HTML document
from which the call originates. The resulting document is then fed into
an actual image loader such as KTX2Loader or BitmapLoader, which tends
to generate hard to understand errors.

This change detects the error early and throws a special message to make
debugging easier.
Arseny Kapoulkine 4 년 전
부모
커밋
5d6ad11735
2개의 변경된 파일9개의 추가작업 그리고 1개의 파일을 삭제
  1. 5 1
      examples/js/loaders/GLTFLoader.js
  2. 4 0
      examples/jsm/loaders/GLTFLoader.js

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

@@ -2443,6 +2443,10 @@ THREE.GLTFLoader = ( function () {
 
 			} );
 
+		} else if ( source.uri === undefined ) {
+
+			throw new Error( 'THREE.GLTFLoader: Image ' + textureIndex + ' is missing URI and bufferView' );
+
 		}
 
 		return Promise.resolve( sourceURI ).then( function ( sourceURI ) {
@@ -2626,7 +2630,7 @@ THREE.GLTFLoader = ( function () {
 				if ( useFlatShading ) cachedMaterial.flatShading = true;
 				if ( useMorphTargets ) cachedMaterial.morphTargets = true;
 				if ( useMorphNormals ) cachedMaterial.morphNormals = true;
-				
+
 				if ( useVertexTangents ) {
 
 					cachedMaterial.vertexTangents = true;

+ 4 - 0
examples/jsm/loaders/GLTFLoader.js

@@ -2508,6 +2508,10 @@ var GLTFLoader = ( function () {
 
 			} );
 
+		} else if ( source.uri === undefined ) {
+
+			throw new Error( 'THREE.GLTFLoader: Image ' + textureIndex + ' is missing URI and bufferView' );
+
 		}
 
 		return Promise.resolve( sourceURI ).then( function ( sourceURI ) {