-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Fix AssetTransformer breaking LabeledAssets #11626
Conversation
@thepackett, could I get your review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely overlooked labeled assets when I initially implemented asset transformers. Thanks for spotting and fixing this!
Thank you very much for catching and unbreaking this. I'd still like more examples in the |
# 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 bevyengine#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.
Objective
AssetTransformer
provides an input asset, and output an asset, but provides no access to theLabeledAsset
's created by theAssetLoader
. 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 forAssetTransformer
's to be useful, they need to have access to these sub assets.AssetLoader
s are provided toAssetSaver
s in theLoadAndSave
process, but theLoadTransformAndSave
process drops these values in the transform stage, and soAssetSaver
is given none.Ideally the AssetTransformer should not ignore labeled sub assets, and they should be kept at least for the AssetSaver
Solution
SavedAsset
namedTransformedAsset
which holds the input asset, and the HashMap ofLabeledAsset
s. The transform function now takes as input aTransformedAsset
, and returns aTransformedAsset::<AssetOutput>
. This gives the transform function access to the labeled sub assets created by theAssetLoader
.TransformedSubAsset
which holds mutable references to a sub asset and that sub assets HashMap ofLabeledAsset
s. This allows you to travers the Tree ofLabeledAsset
s by reference relatively easily.LoadTransformAndSave
processor was then reworked to use the new structs, stopping theLabeledAsset
s from being dropped.Changelog
get_untyped_handle
to return aUntypedHandle
directly rather than a reference and addedget_handle
as a typed variant in SavedAsset and TransformedAssetSavedAsset::from_transformed
as a constructor from aTransformedAsset
TransformedAsset
typeProcessError
forAssetTransformer
in process.rsAssetTransformer::transform
to useTransformedAsset
as input and output.AssetTransformer
to use aBoxedFuture
likeAssetLoader
andAssetSaver
to allow for async transformation code.