Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LegacyGLTFLoader: Fix parsing textures in GLB files. #13589

Merged
merged 1 commit into from
Mar 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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