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

AssetListLoader should load dependencies for all asset types #7345

Open
lucaheft opened this issue Feb 12, 2025 · 4 comments
Open

AssetListLoader should load dependencies for all asset types #7345

lucaheft opened this issue Feb 12, 2025 · 4 comments

Comments

@lucaheft
Copy link

Currently AssetListLoader is only loading dependencies of asset type model.

// json based models should be loaded with the loadFromUrl function so that their dependencies can be loaded too.
if (this._assetHasDependencies(asset)) {
this._registry.loadFromUrl(asset.file.url, asset.type, (err, loadedAsset) => {
if (err) {
this._onError(err, asset);
return;
}
this._onLoad(asset);
});
}

_assetHasDependencies(asset) {
return (asset.type === 'model' && asset.file?.url && asset.file.url && asset.file.url.match(/.json$/g));
}

My use case:
When switching between scenes I want to use the AssetListLoader to preload all assets and show a progress bar.

I parse the scene and create a list of all assets which need to be loaded.

Let's say the scene contains a render component. When loading the render component the glb won't be loaded with it.
This results in pop in, when changing the scene.

There are multiple asset types, where this problem occurs:

Asset Type Missing dependencies
cubemap textures
material textures
render glb
... ...

There are 2 solutions to this problem:

  1. Handle loading of dependencies in AssetListLoader (similar to model asset type)
  2. Handle loading in AssetRegistry.load. (When a asset is loaded, always load it's dependencies)
@Maksims
Copy link
Collaborator

Maksims commented Feb 13, 2025

Perhaps a third option a more simple way of getting actual dependencies, something like:

const related = asset.getRelated();

That way you can provide a full list to AssetListLoader.
Changing AssetRegistry.load - would not be within its semantic, as it suppose to load a single asset.

The reason why model was loading straight away but render isn't, is because model asset contained actual geometry data, while render asset is only a "reference" to a container asset.

@lucaheft
Copy link
Author

That would definetly make loading of dependencies easier!

However I do advocate for some API where I can pass in an asset and it loads all dependencies as well. I don't really want to do that manually as this can be generalized.

Could be a new method like AssetRegistry.loadWithDependencies?

@Maksims
Copy link
Collaborator

Maksims commented Feb 13, 2025

AssetRegistry.loadWithDependencies - might be way too simplified, as there are cases when we would want to load only a diff, and unload what is not required anymore. This is common when you load game level after different one. To avoid unloading resources that used in both levels, you get a list of assets required, and remove them from list of previously used assets, and just unload the remaining. And then load the new list, which of course will ignore loading for already loaded resources.
So asset.getRelated - is very useful in this case, and solves all cases, just requires a bit more code from developer.
Currently to do that, we tag assets manually, and use tags to find lists and manipulate them what described above.

AssetRegistry.loadWithDependencies - could be simplified useful method indeed. But if it is based on asset.getRelated - even better.

@lucaheft
Copy link
Author

I didn't think about unloading! But that's a valid use case as well. I mostly never unload as my scenes are pretty small.

I've seen the examples where tagging is used to define which assets are loaded. However I'm not a big fan of this, as this involves manual setup, which introduces human errors.
Currently I'm parsing the scene data, to get all relevant assets which are needed by a scene. scene.getRelatedAssets would be helpful here as well.

I do like your idea of AssetRegistry.loadWithDependencies using asset.getRelated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants