Skip to content

Commit

Permalink
Merge pull request #13589 from donmccurdy/bug-legacygltfloader-binary…
Browse files Browse the repository at this point in the history
…-textures

LegacyGLTFLoader: Fix parsing textures in GLB files.
  • Loading branch information
mrdoob committed Mar 14, 2018
2 parents aad9c5c + db6f933 commit b04b2d5
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions examples/js/loaders/deprecated/LegacyGLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ************/
/*********************************/
Expand Down Expand Up @@ -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;

}

Expand All @@ -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;
Expand Down Expand Up @@ -1120,6 +1117,8 @@ THREE.LegacyGLTFLoader = ( function () {

}, undefined, function () {

if ( isObjectURL ) URL.revokeObjectURL( sourceUri );

resolve();

} );
Expand Down

0 comments on commit b04b2d5

Please sign in to comment.