Skip to content

Commit

Permalink
set withCredentials for other loaders (#4085)
Browse files Browse the repository at this point in the history
  • Loading branch information
elalish authored Feb 1, 2023
1 parent b6e8a11 commit 8d63780
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/model-viewer/src/features/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const DEFAULT_KTX2_TRANSCODER_LOCATION =
'https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/';

const DEFAULT_LOTTIE_LOADER_LOCATION =
'https://cdn.jsdelivr.net/npm/three@0.148.0/examples/jsm/loaders/LottieLoader.js';
'https://cdn.jsdelivr.net/npm/three@0.149.0/examples/jsm/loaders/LottieLoader.js';

const RevealStrategy: {[index: string]: RevealAttributeValue} = {
AUTO: 'auto',
Expand Down
3 changes: 2 additions & 1 deletion packages/model-viewer/src/model-viewer-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ export default class ModelViewerElementBase extends ReactiveElement {
}

if (changedProperties.has('withCredentials')) {
CachingGLTFLoader.withCredentials = this.withCredentials
CachingGLTFLoader.withCredentials = this.withCredentials;
this[$renderer].textureUtils!.withCredentials = this.withCredentials;
}

if (changedProperties.has('generateSchema')) {
Expand Down
10 changes: 7 additions & 3 deletions packages/model-viewer/src/three-components/TextureUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {BackSide, BoxGeometry, CubeCamera, CubeTexture, EquirectangularReflectionMapping, EventDispatcher, HalfFloatType, LinearEncoding, Mesh, NoBlending, NoToneMapping, RGBAFormat, Scene, ShaderMaterial, sRGBEncoding, Texture, TextureLoader, Vector3, WebGLCubeRenderTarget, WebGLRenderer} from 'three';
import {BackSide, BoxGeometry, CubeCamera, CubeTexture, EquirectangularReflectionMapping, EventDispatcher, HalfFloatType, LinearEncoding, Loader, Mesh, NoBlending, NoToneMapping, RGBAFormat, Scene, ShaderMaterial, sRGBEncoding, Texture, TextureLoader, Vector3, WebGLCubeRenderTarget, WebGLRenderer} from 'three';
import {RGBELoader} from 'three/examples/jsm/loaders/RGBELoader.js';

import {deserializeUrl, timePasses} from '../utilities.js';
Expand All @@ -35,10 +35,11 @@ const HDR_FILE_RE = /\.hdr(\.js)?$/;

export default class TextureUtils extends EventDispatcher {
public lottieLoaderUrl = '';
public withCredentials = false;

private _ldrLoader: TextureLoader|null = null;
private _hdrLoader: RGBELoader|null = null;
private _lottieLoader = null;
private _lottieLoader: Loader|null = null;

private generatedEnvironmentMap: Promise<CubeTexture>|null = null;
private generatedEnvironmentMapAlt: Promise<CubeTexture>|null = null;
Expand All @@ -56,6 +57,7 @@ export default class TextureUtils extends EventDispatcher {
if (this._ldrLoader == null) {
this._ldrLoader = new TextureLoader();
}
this._ldrLoader.withCredentials = this.withCredentials;
return this._ldrLoader;
}

Expand All @@ -64,14 +66,16 @@ export default class TextureUtils extends EventDispatcher {
this._hdrLoader = new RGBELoader();
this._hdrLoader.setDataType(HalfFloatType);
}
this._hdrLoader.withCredentials = this.withCredentials;
return this._hdrLoader;
}

async getLottieLoader(): Promise<any> {
if (this._lottieLoader == null) {
const {LottieLoader} = await import(this.lottieLoaderUrl);
this._lottieLoader = new LottieLoader();
this._lottieLoader = new LottieLoader() as Loader;
}
this._lottieLoader.withCredentials = this.withCredentials;
return this._lottieLoader;
}

Expand Down

0 comments on commit 8d63780

Please sign in to comment.