Repeat calls to third.load.<x> crash. (Cache is trying to use cache payload as url)
Describe the bug
When loading a GLTF or other files through the three graphics package.
The function that queries the cache, supplies the cached binary array to this.gltfLoader.load instead of the url.
e.g.
public gltf(url: string): Promise<GLTF> {
// if the cache has a value this resolves to the payload and key becomes a big byte array
const key = this.cache.get(url)
url = key ? key : url
return new Promise(resolve => {
this.gltfLoader.load(url, (gltf: GLTF) => {
resolve(gltf)
})
})
}
This means a second call to load the same file, hits an exception when it gets a byte array instead of a url string.
Can you please share a code snippet where you get a error? I can't reproduce the error.
What three.js version are you using?
I am using a slightly dated "three": "0.171.0" ...that could be the issue
... though, looking at the code - I assume cache.get(url) returns the cache payload rather than the url and gltfLoader.load(<some_array>) would fail.
If you care to check out my gamejam game. Hit backslash to open the debug overlay and click "preload scene" https://github.com/zvodd/phaser_3dnoodles/tree/7c5cb6e27d78d2076c6c27a3812c88a9a6457c9f
Try to use the preloader:
await this.load.preload('flower', '/assets/flower.glb')
const gltf1 = await this.load.gltf('flower')
const gltf2 = await this.load.gltf('flower')
Once preloaded, it will use the browser cache. Unfortunately (and I believe is still the case) it is not possible to cache a gltf model. Every time you reuse the gltf model, it should go through the loader which will do some parsing (or something like this) and will create a unique object each time.
OK I'll try that, sorry about the pull request. I got abit discombobulated navigating javascript build systems and setting up a private npr (Verdaccio). I never even tried running the test suite before pushing.
Don't worry. My enable3d documentation is bad and I should use preload in all examples.