Ver código fonte

Use cache storage by default in asset manager.

master
Palash Bansal 3 anos atrás
pai
commit
fb7440d6fc
Nenhuma conta vinculada ao e-mail do autor do commit
1 arquivos alterados com 16 adições e 7 exclusões
  1. 16
    7
      src/assetmanager/AssetManager.ts

+ 16
- 7
src/assetmanager/AssetManager.ts Ver arquivo

*/ */
simpleCache?: boolean simpleCache?: boolean
/** /**
* cache storage for downloaded files, can use with `caches.open` default = undefined
* Cache Storage for downloaded files, can use with `caches.open`
* When true and by default uses `caches.open('threepipe-assetmanager')`, set to false to disable
* @default true
*/ */
storage?: Cache | Storage
storage?: Cache | Storage | boolean
} }


export type AddAssetOptions = AddObjectOptions & { export type AddAssetOptions = AddObjectOptions & {
readonly importer: AssetImporter readonly importer: AssetImporter
readonly exporter: AssetExporter readonly exporter: AssetExporter
readonly materials: MaterialManager readonly materials: MaterialManager
// private readonly _linkDropzone: boolean
readonly storage?: Cache | Storage
private _storage?: Cache | Storage
get storage() {return this._storage}


constructor(viewer: ThreeViewer, {simpleCache = false, storage}: AssetManagerOptions = {}) { constructor(viewer: ThreeViewer, {simpleCache = false, storage}: AssetManagerOptions = {}) {
super() super()
this.viewer = viewer this.viewer = viewer
this.viewer.scene.addEventListener('addSceneObject', this._sceneUpdated) this.viewer.scene.addEventListener('addSceneObject', this._sceneUpdated)
this.viewer.scene.addEventListener('materialChanged', this._sceneUpdated) this.viewer.scene.addEventListener('materialChanged', this._sceneUpdated)
this._initCacheStorage(simpleCache, storage)
this.storage = storage
this._initCacheStorage(simpleCache, storage ?? true)


this.importer.addEventListener('processRaw', (event)=>{ this.importer.addEventListener('processRaw', (event)=>{
// console.log('preprocess mat', mat) // console.log('preprocess mat', mat)
this.exporter.addExporter(...exporters) this.exporter.addExporter(...exporters)
} }


private _initCacheStorage(simpleCache?: boolean, storage?: Cache | Storage) {
private _initCacheStorage(simpleCache?: boolean, storage?: Cache | Storage | boolean) {
if (storage === true && window?.caches) {
window.caches.open?.('threepipe-assetmanager').then(c => {
this._initCacheStorage(simpleCache, c)
this._storage = c
})
return
}
if (simpleCache || storage) { if (simpleCache || storage) {
// three.js built-in simple memory cache. used in FileLoader.js todo: use local storage somehow // three.js built-in simple memory cache. used in FileLoader.js todo: use local storage somehow
if (simpleCache) threeCache.enabled = true if (simpleCache) threeCache.enabled = true
// todo: clear cache // todo: clear cache
} }
} }
this._storage = typeof storage === 'boolean' ? undefined : storage
} }





Carregando…
Cancelar
Salvar