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 · 0 comments
Open

How to use custom loader #2385

zbx99 opened this issue Sep 23, 2024 · 0 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
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

1 participant