bevy/crates/bevy_asset/src
Zachary Harrold afa7b5cba5
Added Support for Extension-less Assets (#10153)
# Objective

- Addresses **Support processing and loading files without extensions**
from #9714
- Addresses **More runtime loading configuration** from #9714
- Fixes #367
- Fixes #10703

## Solution

`AssetServer::load::<A>` and `AssetServer::load_with_settings::<A>` can
now use the `Asset` type parameter `A` to select a registered
`AssetLoader` without inspecting the provided `AssetPath`. This change
cascades onto `LoadContext::load` and `LoadContext::load_with_settings`.
This allows the loading of assets which have incorrect or ambiguous file
extensions.

```rust
// Allow the type to be inferred by context
let handle = asset_server.load("data/asset_no_extension");

// Hint the type through the handle
let handle: Handle<CustomAsset> = asset_server.load("data/asset_no_extension");

// Explicit through turbofish
let handle = asset_server.load::<CustomAsset>("data/asset_no_extension");
```

Since a single `AssetPath` no longer maps 1:1 with an `Asset`, I've also
modified how assets are loaded to permit multiple asset types to be
loaded from a single path. This allows for two different `AssetLoaders`
(which return different types of assets) to both load a single path (if
requested).

```rust
// Uses GltfLoader
let model = asset_server.load::<Gltf>("cube.gltf");

// Hypothetical Blob loader for data transmission (for example)
let blob = asset_server.load::<Blob>("cube.gltf");
```

As these changes are reflected in the `LoadContext` as well as the
`AssetServer`, custom `AssetLoaders` can also take advantage of this
behaviour to create more complex assets.

---

## Change Log

- Updated `custom_asset` example to demonstrate extension-less assets.
- Added `AssetServer::get_handles_untyped` and Added
`AssetServer::get_path_ids`

## Notes

As a part of that refactor, I chose to store `AssetLoader`s (within
`AssetLoaders`) using a `HashMap<TypeId, ...>` instead of a `Vec<...>`.
My reasoning for this was I needed to add a relationship between `Asset`
`TypeId`s and the `AssetLoader`, so instead of having a `Vec` and a
`HashMap`, I combined the two, removing the `usize` index from the
adjacent maps.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2024-01-31 14:58:08 +00:00
..
io Added Support for Extension-less Assets (#10153) 2024-01-31 14:58:08 +00:00
processor AssetSaver and AssetTransformer split (#11260) 2024-01-26 20:20:58 +00:00
server Added Support for Extension-less Assets (#10153) 2024-01-31 14:58:08 +00:00
assets.rs Remove TypeUuid (#11497) 2024-01-25 16:16:58 +00:00
event.rs Added AssetLoadFailedEvent, UntypedAssetLoadFailedEvent (#11369) 2024-01-17 21:12:00 +00:00
folder.rs Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
handle.rs bevy_reflect: Split #[reflect(where)] (#11597) 2024-01-29 17:54:17 +00:00
id.rs bevy_reflect: Split #[reflect(where)] (#11597) 2024-01-29 17:54:17 +00:00
lib.rs AssetSaver and AssetTransformer split (#11260) 2024-01-26 20:20:58 +00:00
loader.rs Added Support for Extension-less Assets (#10153) 2024-01-31 14:58:08 +00:00
meta.rs Reorder impl to be the same as the trait (#11076) 2023-12-24 17:43:55 +00:00
path.rs AssetPath source parse fix (#11543) 2024-01-26 21:23:06 +00:00
reflect.rs Enable the unsafe_op_in_unsafe_fn lint (#11591) 2024-01-28 23:18:11 +00:00
saver.rs Make SavedAsset::get_labeled accept &str as label (#11612) 2024-01-30 22:18:41 +00:00
transformer.rs AssetSaver and AssetTransformer split (#11260) 2024-01-26 20:20:58 +00:00