threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ZipLoader.ts 750B

123456789101112131415161718
  1. import {FileLoader} from 'three'
  2. import {unzipSync} from 'three/examples/jsm/libs/fflate.module.js'
  3. export class ZipLoader extends FileLoader {
  4. load(url: string, onLoad?: (t: any) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): void {
  5. this.setResponseType('arraybuffer')
  6. return super.load(url, (buffer: any)=>{
  7. // const files = blob.arrayBuffer().then(buff => )
  8. const files = unzipSync(new Uint8Array(buffer))
  9. const map = new Map<string, File>(Object.entries(files).map(([path, fileBuffer]) => {
  10. return [path, new File([fileBuffer as any], path)]
  11. }))
  12. onLoad?.(map)
  13. }, onProgress, onError)
  14. }
  15. }