Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use custom loader #2385

Open
zbx99 opened this issue Sep 23, 2024 · 2 comments
Open

How to use custom loader #2385

zbx99 opened this issue Sep 23, 2024 · 2 comments

Comments

@zbx99
Copy link

zbx99 commented Sep 23, 2024

I try to write my own custom loader like this.https://galacean.antgroup.com/engine/docs/assets/custom/ ,but I cannot use my own custom loader.Here is my loader.

export class ZipLoader extends Loader<GLTFResource>{
  load(
    item: LoadItem,
    resourceManager: ResourceManager
  ): AssetPromise<GLTFResource> {
    // 读取zip压缩文件,然后传回GLTFResource
    if (item.url) {
      fs.readFile(item.url!, (err, data) => {
        if (err) throw err;
        // 使用JSZip解压文件
        JSZip.loadAsync(data).then((zip) => {
          zip.forEach((relativePath,zipEntry)=>{
            if (/\.(gltf|glb)$/i.test(zipEntry.name)) {
              zipEntry.async("base64").then((file)=>{
                 return resourceManager.load<GLTFResource>(file);
              })
            }
          })
        });
      });
    }
    return new AssetPromise<GLTFResource>((resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) => {})
  }
}
    const baseUrl = "assets/Building/output"
    // 加载ZIP文件
    let self = this;
    this.engine.resourceManager.load<GALACEAN.GLTFResource>({
      type:"ZIP",
      url:baseUrl+index+".zip"
    }).then((asset) => {
      console.log(asset)
    })
  }
@zbx99 zbx99 changed the title How to How to use custom loader Sep 23, 2024
@cptbtptpbcptdtptp
Copy link
Collaborator

cptbtptpbcptdtptp commented Sep 29, 2024

You need to call resourceLoader before use to tell the engine that your loader is required to load this file.
image

@cptbtptpbcptdtptp
Copy link
Collaborator

You can write like this:

@resourceLoader("ZIP", ["zip"])
export class ZipLoader extends Loader<GLTFResource>{

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants