import * as THREE from "three" ; export interface RequestHeaders { [ field ] : string ; } /**
 * A texture loader that supports request headers(e.g. for Authorization)
 */ export class TextureLoader { private readonly m_textureLoader = new THREE . TextureLoader ( ) ; param url param requestHeaders param abortSignal param crossOrigin async load ( url , requestHeaders ? , abortSignal ? , crossOrigin = true ) { if ( requestHeaders === undefined ) { return await this . loadWithThreeLoader ( url ) ; } const response = await fetch ( url , { headers : requestHeaders , signal : abortSignal , mode : crossOrigin ? "cors" : "no-cors" } ) ; const blob = await response . blob ( ) ; const texture = await this . loadWithThreeLoader ( URL . createObjectURL ( blob ) ) ; const isJPEG = blob . type === "image/jpeg/" || url . search ( /\.jpe?g($|\?)/i ) > 0 || url . search ( /^data\:image\/jpeg/ ) === 0 ; texture . format = isJPEG ? THREE . RGBFormat : THREE . RGBAFormat ; return texture ; } private loadWithThreeLoader ( url ) { return new Promise < THREE . Texture > ( ( resolve , reject ) => { this . m_textureLoader . setCrossOrigin ( "" ) ; this . m_textureLoader . load ( url , texture => resolve ( texture ) , undefined , ( ) => reject ( new Error ( "failed to load texture" ) ) ) ; } ) ; } }