Переглянути джерело

Merge pull request #13589 from donmccurdy/bug-legacygltfloader-binary-textures

LegacyGLTFLoader: Fix parsing textures in GLB files.
Mr.doob 7 роки тому
батько
коміт
b04b2d5f4c
1 змінених файлів з 10 додано та 11 видалено
  1. 10 11
      examples/js/loaders/deprecated/LegacyGLTFLoader.js

+ 10 - 11
examples/js/loaders/deprecated/LegacyGLTFLoader.js

@@ -394,16 +394,6 @@ THREE.LegacyGLTFLoader = ( function () {
 
 	};
 
-	GLTFBinaryExtension.prototype.loadTextureSourceUri = function ( source, bufferViews ) {
-
-		var metadata = source.extensions[ EXTENSIONS.KHR_BINARY_GLTF ];
-		var bufferView = bufferViews[ metadata.bufferView ];
-		var stringData = THREE.LoaderUtils.decodeText( new Uint8Array( bufferView ) );
-
-		return 'data:' + metadata.mimeType + ';base64,' + btoa( stringData );
-
-	};
-
 	/*********************************/
 	/********** INTERNALS ************/
 	/*********************************/
@@ -1071,10 +1061,15 @@ THREE.LegacyGLTFLoader = ( function () {
 
 						var source = json.images[ texture.source ];
 						var sourceUri = source.uri;
+						var isObjectURL = false;
 
 						if ( source.extensions && source.extensions[ EXTENSIONS.KHR_BINARY_GLTF ] ) {
 
-							sourceUri = extensions[ EXTENSIONS.KHR_BINARY_GLTF ].loadTextureSourceUri( source, dependencies.bufferViews );
+							var metadata = source.extensions[ EXTENSIONS.KHR_BINARY_GLTF ];
+							var bufferView = dependencies.bufferViews[ metadata.bufferView ];
+							var blob = new Blob( [ bufferView ], { type: metadata.mimeType } );
+							sourceUri = URL.createObjectURL( blob );
+							isObjectURL = true;
 
 						}
 
@@ -1090,6 +1085,8 @@ THREE.LegacyGLTFLoader = ( function () {
 
 						textureLoader.load( resolveURL( sourceUri, options.path ), function ( _texture ) {
 
+							if ( isObjectURL ) URL.revokeObjectURL( sourceUri );
+
 							_texture.flipY = false;
 
 							if ( texture.name !== undefined ) _texture.name = texture.name;
@@ -1120,6 +1117,8 @@ THREE.LegacyGLTFLoader = ( function () {
 
 						}, undefined, function () {
 
+							if ( isObjectURL ) URL.revokeObjectURL( sourceUri );
+
 							resolve();
 
 						} );