From db6f9338525e6972a16305ea48baf5f590aaea10 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Wed, 14 Mar 2018 08:53:19 -0700 Subject: [PATCH] LegacyGLTFLoader: Fix parsing textures in GLB files. --- .../js/loaders/deprecated/LegacyGLTFLoader.js | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/js/loaders/deprecated/LegacyGLTFLoader.js b/examples/js/loaders/deprecated/LegacyGLTFLoader.js index f24f6eb879015c..94826cfb625069 100644 --- a/examples/js/loaders/deprecated/LegacyGLTFLoader.js +++ b/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(); } );