-
When loading a scene file, it has to invoke other loaders - typically this is done by using a "Standin" component that when loaded, removes itself and is replaced. But one area I can't quite figure out is how to do this with Materials and Textures without a bit of bother. Lets say I have a file
And want to load this material. I had a look at how the GLTF importer handles this and, urgh, it reads the bytes into an image manually.As far as I understand it, this means that if two GLTF's reference the same image it'll be loaded from disk twice and into GPU memory twice. It would be nice to support sharing textures between assets, so another solution is desired. All this stems from the fact that (as far as I can tell), there isn't a way to load a different resource from inside an AssetLoader.(eg I can think of a way around it, but it would require more placeholder components, and means that deep recursion would span lots of frames (eg SceneA requires SceneB requires SceneC requires MeshD requires MaterialE requires ImageF). So, is there a general way to load assets while loading other assets? Is |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's possible, but not very obvious. here is an example. // Create an asset path to the asset you want loaded
let asset_path = AssetPath::new_ref(path, None);
// Get an handle to the asset at asset_path
let handle = load_context.get_handle(asset_path.clone());
// Use the handle how you want, load other stuff, ...
// Create your loaded asset. mark it as a dependency
let asset = LoadedAsset::new(CustomAsset { .. }).with_dependency(asset_path);
// Set your complete asset as the default one
load_context.set_default_asset(asset); |
Beta Was this translation helpful? Give feedback.
It's possible, but not very obvious. here is an example.