Skip to content

Commit

Permalink
fix(loaderFunctions): onUrl on loadGltf
Browse files Browse the repository at this point in the history
  • Loading branch information
lslzl3000 committed Mar 12, 2024
1 parent b4d1460 commit 65bda50
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/assets/Res.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,15 @@ export class Res {
if (this._prefabPool.has(url)) {
return this._prefabPool.get(url) as Object3D;
}
if (loaderFunctions?.onUrl) {
url = await loaderFunctions.onUrl(url);
}

let parser;
let ext = url.substring(url.lastIndexOf('.')).toLowerCase();
let loader = new FileLoader();
if (ext == '.gltf') {
parser = await loader.load(url, GLTFParser, loaderFunctions);

} else {
parser = await loader.load(url, GLBParser, loaderFunctions);
}
Expand All @@ -206,6 +208,9 @@ export class Res {
if (this._prefabPool.has(url)) {
return this._prefabPool.get(url) as Object3D;
}
if (loaderFunctions?.onUrl) {
url = await loaderFunctions.onUrl(url);
}

let parser;
let ext = url.substring(url.lastIndexOf('.')).toLowerCase();
Expand All @@ -229,6 +234,9 @@ export class Res {
if (this._prefabPool.has(url)) {
return this._prefabPool.get(url) as Object3D;
}
if (loaderFunctions?.onUrl) {
url = await loaderFunctions.onUrl(url);
}
let loader = new FileLoader();
let parser = await loader.load(url, B3DMParser, loaderFunctions, userData);
let obj = parser.data;
Expand All @@ -246,6 +254,9 @@ export class Res {
if (this._prefabPool.has(url)) {
return this._prefabPool.get(url) as Object3D;
}
if (loaderFunctions?.onUrl) {
url = await loaderFunctions.onUrl(url);
}
let loader = new FileLoader();
let parser = await loader.load(url, I3DMParser, loaderFunctions, userData);
let obj = parser.data;
Expand All @@ -264,6 +275,9 @@ export class Res {
if (this._texturePool.has(url)) {
return this._texturePool.get(url);
}
if (loaderFunctions?.onUrl) {
url = await loaderFunctions.onUrl(url);
}
let texture = new BitmapTexture2D();
texture.flipY = flipY;
await texture.load(url, loaderFunctions);
Expand Down Expand Up @@ -314,7 +328,9 @@ export class Res {
if (this._texturePool.has(url)) {
return this._texturePool.get(url);
}

if (loaderFunctions?.onUrl) {
url = await loaderFunctions.onUrl(url);
}
let hdrTexture = new HDRTexture();
hdrTexture = await hdrTexture.load(url, loaderFunctions);
this._texturePool.set(url, hdrTexture);
Expand All @@ -332,6 +348,9 @@ export class Res {
if (this._texturePool.has(url)) {
return this._texturePool.get(url);
}
if (loaderFunctions?.onUrl) {
url = await loaderFunctions.onUrl(url);
}
let hdrTexture = new HDRTextureCube();
hdrTexture = await hdrTexture.load(url, loaderFunctions);
this._texturePool.set(url, hdrTexture);
Expand All @@ -348,6 +367,9 @@ export class Res {
if (this._texturePool.has(url)) {
return this._texturePool.get(url);
}
if (loaderFunctions?.onUrl) {
url = await loaderFunctions.onUrl(url);
}
let ldrTextureCube = new LDRTextureCube();
ldrTextureCube = await ldrTextureCube.load(url, loaderFunctions);
this._texturePool.set(url, ldrTextureCube);
Expand Down Expand Up @@ -381,6 +403,9 @@ export class Res {
if (this._texturePool.has(url)) {
return this._texturePool.get(url);
}
if (loaderFunctions?.onUrl) {
url = await loaderFunctions.onUrl(url);
}

let cubeMap = new BitmapTextureCube();
await cubeMap.loadStd(url);
Expand All @@ -392,6 +417,9 @@ export class Res {
* @param url the path of image
*/
public async loadJSON(url: string, loaderFunctions?: LoaderFunctions) {
if (loaderFunctions?.onUrl) {
url = await loaderFunctions.onUrl(url);
}
return await new FileLoader()
.loadJson(url, loaderFunctions)
.then(async (ret) => {
Expand Down

0 comments on commit 65bda50

Please sign in to comment.