Skip to content

CORS settings not passed down to internal Loaders #20350

@amosbyon1224

Description

@amosbyon1224
Description of the problem

I am trying to load a .glb file from a remote server. The .glb file references an external texture file that also lives on the server.

I can successfully load the .glb file from the remote server with:

const loader = new GLTFLoader(manager);
loader.setCrossOrigin('use-credentials');

but I am running into CORS issues when GLTFLoader is trying to load the texture image.

It seems like GLTFLoader is using ImageBitmapLoader but ImageBitmapLoader is using fetch but not passing any options to properly set the credentials option:

fetch( url ).then( function ( res ) {
return res.blob();
} ).then( function ( blob ) {
return createImageBitmap( blob, scope.options );
} ).then( function ( imageBitmap ) {
Cache.add( url, imageBitmap );
if ( onLoad ) onLoad( imageBitmap );
scope.manager.itemEnd( url );
} ).catch( function ( e ) {
if ( onError ) onError( e );
scope.manager.itemError( url );
scope.manager.itemEnd( url );
} );

I've also noticed this in STLLoader and I'm currently not sure how many other Loaders have a similar issue:

var loader = new FileLoader( scope.manager );
loader.setPath( scope.path );
loader.setResponseType( 'arraybuffer' );
loader.setRequestHeader( this.requestHeader );
loader.load( url, function ( text ) {

Also I'm noticing that some loaders will include an extra withCredentials member variable when Loaders already has crossOrigin which makes it a little confusing for me to know which one to set. (See FileLoader)

Three.js version
  • Dev
Browser
  • Chrome
OS
  • macOS

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions