@@ -35,7 +35,6 @@ const HDR_FILE_RE = /\.hdr(\.js)?$/;
3535
3636export default class TextureUtils {
3737 public lottieLoaderUrl = '' ;
38- public withCredentials = false ;
3938
4039 private _ldrLoader : TextureLoader | null = null ;
4140 private _imageLoader : HDRJPGLoader | null = null ;
@@ -53,53 +52,54 @@ export default class TextureUtils {
5352 constructor ( private threeRenderer : WebGLRenderer ) {
5453 }
5554
56- get ldrLoader ( ) : TextureLoader {
55+ private ldrLoader ( withCredentials : boolean ) : TextureLoader {
5756 if ( this . _ldrLoader == null ) {
5857 this . _ldrLoader = new TextureLoader ( ) ;
5958 }
60- this . _ldrLoader . setWithCredentials ( this . withCredentials ) ;
59+ this . _ldrLoader . setWithCredentials ( withCredentials ) ;
6160 return this . _ldrLoader ;
6261 }
6362
64- get imageLoader ( ) : HDRJPGLoader {
63+ private imageLoader ( withCredentials : boolean ) : HDRJPGLoader {
6564 if ( this . _imageLoader == null ) {
6665 this . _imageLoader = new HDRJPGLoader ( this . threeRenderer ) ;
6766 }
68- this . _imageLoader . setWithCredentials ( this . withCredentials ) ;
67+ this . _imageLoader . setWithCredentials ( withCredentials ) ;
6968 return this . _imageLoader ;
7069 }
7170
72- get hdrLoader ( ) : RGBELoader {
71+ private hdrLoader ( withCredentials : boolean ) : RGBELoader {
7372 if ( this . _hdrLoader == null ) {
7473 this . _hdrLoader = new RGBELoader ( ) ;
7574 this . _hdrLoader . setDataType ( HalfFloatType ) ;
7675 }
77- this . _hdrLoader . setWithCredentials ( this . withCredentials ) ;
76+ this . _hdrLoader . setWithCredentials ( withCredentials ) ;
7877 return this . _hdrLoader ;
7978 }
8079
81- async getLottieLoader ( ) : Promise < any > {
80+ async getLottieLoader ( withCredentials : boolean ) : Promise < any > {
8281 if ( this . _lottieLoader == null ) {
8382 const { LottieLoader} =
8483 await import ( /* webpackIgnore: true */ this . lottieLoaderUrl ) ;
8584 this . _lottieLoader = new LottieLoader ( ) as Loader ;
8685 }
87- this . _lottieLoader . setWithCredentials ( this . withCredentials ) ;
86+ this . _lottieLoader . setWithCredentials ( withCredentials ) ;
8887 return this . _lottieLoader ;
8988 }
9089
91- async loadImage ( url : string ) : Promise < Texture > {
90+ async loadImage ( url : string , withCredentials : boolean ) : Promise < Texture > {
9291 const texture : Texture = await new Promise < Texture > (
93- ( resolve , reject ) =>
94- this . ldrLoader . load ( url , resolve , ( ) => { } , reject ) ) ;
92+ ( resolve , reject ) => this . ldrLoader ( withCredentials )
93+ . load ( url , resolve , ( ) => { } , reject ) ) ;
9594 texture . name = url ;
9695 texture . flipY = false ;
9796
9897 return texture ;
9998 }
10099
101- async loadLottie ( url : string , quality : number ) : Promise < Texture > {
102- const loader = await this . getLottieLoader ( ) ;
100+ async loadLottie ( url : string , quality : number , withCredentials : boolean ) :
101+ Promise < Texture > {
102+ const loader = await this . getLottieLoader ( withCredentials ) ;
103103 loader . setQuality ( quality ) ;
104104 const texture : Texture = await new Promise < Texture > (
105105 ( resolve , reject ) => loader . load ( url , resolve , ( ) => { } , reject ) ) ;
@@ -109,11 +109,13 @@ export default class TextureUtils {
109109 }
110110
111111 async loadEquirect (
112- url : string , progressCallback : ( progress : number ) => void = ( ) => { } ) :
112+ url : string , withCredentials = false ,
113+ progressCallback : ( progress : number ) => void = ( ) => { } ) :
113114 Promise < Texture > {
114115 try {
115116 const isHDR : boolean = HDR_FILE_RE . test ( url ) ;
116- const loader = isHDR ? this . hdrLoader : this . imageLoader ;
117+ const loader = isHDR ? this . hdrLoader ( withCredentials ) :
118+ this . imageLoader ( withCredentials ) ;
117119 const texture : Texture = await new Promise < Texture > (
118120 ( resolve , reject ) => loader . load (
119121 url ,
@@ -158,8 +160,8 @@ export default class TextureUtils {
158160 */
159161 async generateEnvironmentMapAndSkybox (
160162 skyboxUrl : string | null = null , environmentMapUrl : string | null = null ,
161- progressCallback : ( progress : number ) => void = ( ) => { } ) :
162- Promise < EnvironmentMapAndSkybox > {
163+ progressCallback : ( progress : number ) => void = ( ) => { } ,
164+ withCredentials = false ) : Promise < EnvironmentMapAndSkybox > {
163165 const useAltEnvironment = environmentMapUrl !== 'legacy' ;
164166 if ( environmentMapUrl === 'legacy' || environmentMapUrl === 'neutral' ) {
165167 environmentMapUrl = null ;
@@ -171,17 +173,18 @@ export default class TextureUtils {
171173
172174 // If we have a skybox URL, attempt to load it as a cubemap
173175 if ( ! ! skyboxUrl ) {
174- skyboxLoads = this . loadEquirectFromUrl ( skyboxUrl , progressCallback ) ;
176+ skyboxLoads = this . loadEquirectFromUrl (
177+ skyboxUrl , withCredentials , progressCallback ) ;
175178 }
176179
177180 if ( ! ! environmentMapUrl ) {
178181 // We have an available environment map URL
179- environmentMapLoads =
180- this . loadEquirectFromUrl ( environmentMapUrl , progressCallback ) ;
182+ environmentMapLoads = this . loadEquirectFromUrl (
183+ environmentMapUrl , withCredentials , progressCallback ) ;
181184 } else if ( ! ! skyboxUrl ) {
182185 // Fallback to deriving the environment map from an available skybox
183- environmentMapLoads =
184- this . loadEquirectFromUrl ( skyboxUrl , progressCallback ) ;
186+ environmentMapLoads = this . loadEquirectFromUrl (
187+ skyboxUrl , withCredentials , progressCallback ) ;
185188 } else {
186189 // Fallback to generating the environment map
187190 environmentMapLoads = useAltEnvironment ?
@@ -203,10 +206,11 @@ export default class TextureUtils {
203206 * Loads an equirect Texture from a given URL, for use as a skybox.
204207 */
205208 private async loadEquirectFromUrl (
206- url : string ,
209+ url : string , withCredentials : boolean ,
207210 progressCallback : ( progress : number ) => void ) : Promise < Texture > {
208211 if ( ! this . skyboxCache . has ( url ) ) {
209- const skyboxMapLoads = this . loadEquirect ( url , progressCallback ) ;
212+ const skyboxMapLoads =
213+ this . loadEquirect ( url , withCredentials , progressCallback ) ;
210214
211215 this . skyboxCache . set ( url , skyboxMapLoads ) ;
212216 }
0 commit comments