-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
The current loader API is (subjectively) a little heavy.
For example, to load a GLTF file:
let loader = world.read_resource();
let progress = ();
let format = GltfSceneFormat;
let options = Default::default();
let storage = &world.read_resource();
let asset = loader.load("path/to/gltf.gltf", GltfSceneFormat, options, progress, storage);And to load a GLTF file from a custom source:
let loader = world.read_resource();
let progress = ();
let format = GltfSceneFormat;
let options = Default::default();
let source = /*...*/;
let storage = &world.read_resource();
let asset = loader.load_from("path/to/gltf.gltf", GltfSceneFormat, options, source, progress, storage);I think this API could be made slightly cleaner by doing (any subset of) a few things:
- Dynamically dispatch on the resource URL to determine the source and format (maybe integrating with the
vnodessystem) - Put the storages within the Loader / give the Loader some way to get handles to the storages, so that the user doesn't have to
- Use the builder pattern
Then, a simple asset load can look like just:
let asset = loader.asset("/io/assets/path/to/texture.png").load();And a complex load can look like:
let asset = loader
.asset("/io/assets/special_source/path_to_scene.gltf")
.progress(progress_counter)
.options(GltfSceneOptions { /* ... */ })
.custom_storage(custom_storage) // not sure if this would be needed
.load();Since loading assets is something that you do a lot, I think it's worth it to make the API nice to use.
Downsides:
- Makes things slightly more prone to runtime errors (can have file-type mismatches)
- Gives Loader more responsibilities
Metadata
Metadata
Assignees
Labels
No labels