bevy/examples/asset
CowSociety 8866c61161
Fix AssetTransformer breaking LabeledAssets (#11626)
# Objective

- `AssetTransformer` provides an input asset, and output an asset, but
provides no access to the `LabeledAsset`'s created by the `AssetLoader`.
Labeled sub assets are an extremely important piece of many assets, Gltf
in particular, and without them the amount of transformation on an asset
is limited. In order for `AssetTransformer`'s to be useful, they need to
have access to these sub assets.
- LabeledAsset's loaded by `AssetLoader`s are provided to `AssetSaver`s
in the `LoadAndSave` process, but the `LoadTransformAndSave` process
drops these values in the transform stage, and so `AssetSaver` is given
none.
- Fixes #11606

Ideally the AssetTransformer should not ignore labeled sub assets, and
they should be kept at least for the AssetSaver

## Solution

- I created a new struct similar to `SavedAsset` named
`TransformedAsset` which holds the input asset, and the HashMap of
`LabeledAsset`s. The transform function now takes as input a
`TransformedAsset`, and returns a `TransformedAsset::<AssetOutput>`.
This gives the transform function access to the labeled sub assets
created by the `AssetLoader`.
- I also created `TransformedSubAsset` which holds mutable references to
a sub asset and that sub assets HashMap of `LabeledAsset`s. This allows
you to travers the Tree of `LabeledAsset`s by reference relatively
easily.
- The `LoadTransformAndSave` processor was then reworked to use the new
structs, stopping the `LabeledAsset`s from being dropped.

---

## Changelog

- Created TransformedAsset struct and TransformedSubAsset struct.
- Changed `get_untyped_handle` to return a `UntypedHandle` directly
rather than a reference and added `get_handle` as a typed variant in
SavedAsset and TransformedAsset
- Added `SavedAsset::from_transformed` as a constructor from a
`TransformedAsset`
- Switched LoadTransformAndSave process code to work with new
`TransformedAsset` type
- Added a `ProcessError` for `AssetTransformer` in process.rs
- Switched `AssetTransformer::transform` to use `TransformedAsset` as
input and output.
- Switched `AssetTransformer` to use a `BoxedFuture` like `AssetLoader`
and `AssetSaver` to allow for async transformation code.
- Updated AssetTransformer example to use new structure.
2024-02-02 14:57:31 +00:00
..
processing Fix AssetTransformer breaking LabeledAssets (#11626) 2024-02-02 14:57:31 +00:00
asset_decompression.rs Added Method to Allow Pipelined Asset Loading (#10565) 2023-11-16 17:47:31 +00:00
asset_loading.rs Restore brightness in the remaining three examples after exposure PR (#11389) 2024-01-17 17:10:21 +00:00
bevy_pixel_light.png Fix embedded asset path manipulation (#10383) 2024-02-02 14:49:05 +00:00
custom_asset_reader.rs fix example custom_asset_reader on wasm (#10574) 2023-11-16 01:50:13 +00:00
custom_asset.rs Added Support for Extension-less Assets (#10153) 2024-01-31 14:58:08 +00:00
embedded_asset.rs Fix embedded asset path manipulation (#10383) 2024-02-02 14:49:05 +00:00
hot_asset_reloading.rs Restore brightness in the remaining three examples after exposure PR (#11389) 2024-01-17 17:10:21 +00:00