-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Make better use of cache in loaders #5650
Comments
Maybe |
The initial implementation of the I've experimented a bit with the cache/loader, although I'm not completely sure about the approach. To get the 'global' behavior, I've simply added the cache to the However, that is not sufficient to solve #3601. The problem here is uncoordinated concurrent retrieval of the same resource, and it needs more that a cache. My solution to get around this problem is to introduce a You can see it in action here: http://jsfiddle.net/dubejf/r9n8b0b4/4/ Basically, instead of
However, it adds a some complexity, and I'm not sure how big of a problem the lack of caching is in general. |
Hmmm... Stupid me... I should detail more why I do changes... I don't remember why I made it not global...
|
This would help my use case. In the chess game, the pawns are loaded 8 times, when the cached version of the .obj could be saved and reused. :) |
We can add caching to more loaders, but it also sound like for your case you could handle that on your side too... |
@dubejf - about what you say, "I'm not sure how big of a problem the lack of caching is in general." In my understand it is a big problem. We've dealt with it in own code, outside three.js, but it might be nice to have it work properly in three already if there's a simple nice clear way. |
I ended up solving this by creating an AssetManager. I could make this into an npm module if there was any interest. I also parse the .objs using a webworker, but I might look into .gltf to see if it's even faster. |
ImageLoader
andXHRLoader
both use aCache
to store loaded assets for reuse, although not very efficiently, at least for some use case.For instance,
TextureLoader.onload()
creates a newImageLoader
every time the method is called, which means that the image cache is always empty because the image loader instance is only used once.ImageUtils.loadTexture()
behaves similarly.My preferred way to solve this would be to put the cache in the
LoadingManager
(one cache perLoadingManager
instance). EachImageLoader
andXHRLoader
would share the cache of their parent manager.Users would be responsible to manually purge the manager cache as necessary, to free resources or request updated assets. That could be a problem for an application that cycles through a lot of loaded textures/images, especially if the
DefaultLoadingManager
is used - users might not be aware of cache implication. Maybe the common cache could be opted-in (loadingManager.useCache = true
), which would be equivalent to the status quo. A simpleloadingManager.cache.maxSize
could be enough, too.Another approach would be to create an
ImageLoader
instance as a property ofTextureLoader
in its constructor. The image cache would be reused as long as the sameTextureLoader
is kept around.I can work on a patch if we agree on the approach.
Related to #3601
The text was updated successfully, but these errors were encountered: