-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add basic docs explaining what asset processing is and where to look #15058
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
Merged
alice-i-cecile
merged 13 commits into
bevyengine:main
from
alice-i-cecile:asset-processing-docs
Sep 17, 2024
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
480d1e5
Preamble
alice-i-cecile d43b7e9
Basic docs for AssetProcessorData
alice-i-cecile 123533c
Document entry points for asset processing
alice-i-cecile 7f986ab
Make introductory sentence less passive
alice-i-cecile 141f06a
Caveats for determinism
alice-i-cecile 878daee
Make clear that AssetProcessorData is internal
alice-i-cecile 3774c80
Swap png example
alice-i-cecile abd67f8
Add more caveats to the "don't version control processed assets" advice
alice-i-cecile 9b51c4e
Link to asset processing example folder
alice-i-cecile 0dc951e
Tweak wording on values
alice-i-cecile dbc4be6
Add better usage docs
alice-i-cecile 546cf25
Mention hot reloading + asset processing
alice-i-cecile 675bc9c
Swap one example to baked lighting
alice-i-cecile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
//! Asset processing in Bevy is a framework for automatically transforming artist-authored assets into the format that best suits the needs of your particular game. | ||
//! | ||
//! You can think of the asset processing system as a "build system" for assets. | ||
//! When an artist adds a new asset to the project, the asset processing system will automatically perform the specified processing steps on the asset. | ||
alice-i-cecile marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//! This can include things like converting a `.png` file into a compressed GPU-friendly texture format, compressing a `.wav` file to an `.ogg`, or generating mipmaps for a texture. | ||
alice-i-cecile marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//! | ||
//! Its core values are: | ||
//! | ||
//! 1. Automatic: new and changed assets should be ready to use in-game without requiring any manual conversion or cleanup steps. | ||
//! 2. Configurable: every game has its own needs, and a high level of transparency and control is required. | ||
//! 3. Lossless: the original asset should always be preserved, ensuring artists can make changes later. | ||
//! 4. Deterministic: performing the same processing steps on the same asset should (generally) produce the exact same result. In cases where this doesn't make sense (steps that involve a degree of randomness or uncertainty), the results across runs should be "acceptably similar", as they will be generated once for a given set of inputs and cached. | ||
//! | ||
//! Taken together, this means that the original asset plus the processing steps should be enough to regenerate the final asset. | ||
//! While it may be possible to manually edit the final asset, this should be discouraged. | ||
//! Final post-processed assets should generally not be version-controlled, except to save developer time when recomputing heavy asset processing steps. | ||
//! | ||
//! # Usage | ||
//! | ||
//! Asset processing can be enabled or disabled in [`AssetPlugin`](crate::AssetPlugin) by setting the [`AssetMode`](crate::AssetMode).\ | ||
//! Enable Bevy's `file_watcher` feature to automatically watch for changes to assets and reprocess them. | ||
//! | ||
//! To register a new asset processor, use [`AssetProcessor::register_processor`]. | ||
//! To set the default asset processor for a given extension, use [`AssetProcessor::set_default_processor`]. | ||
//! In most cases, these methods will be called directly on [`App`](bevy_app::App) using the [`AssetApp`](crate::AssetApp) extension trait. | ||
//! | ||
//! If a default asset processor is set, assets with a matching extension will be processed using that processor before loading. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I couldn't figure out how to load an asset with an arbitrary processor :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From code? Not possible afaik. You have to use meta files. |
||
//! | ||
//! For an end-to-end example, check out the examples in the [`examples/asset/processing`](https://github.com/bevyengine/bevy/tree/latest/examples/asset/processing) directory of the Bevy repository. | ||
//! | ||
//! # Defining asset processors | ||
//! | ||
//! Bevy provides two different ways to define new asset processors: | ||
//! | ||
//! - [`LoadTransformAndSave`] + [`AssetTransformer`](crate::transformer::AssetTransformer): a high-level API for loading, transforming, and saving assets. | ||
//! - [`Process`]: a flexible low-level API for processing assets in arbitrary ways. | ||
//! | ||
//! In most cases, [`LoadTransformAndSave`] should be sufficient. | ||
|
||
mod log; | ||
mod process; | ||
|
||
|
@@ -61,6 +100,7 @@ pub struct AssetProcessor { | |
pub(crate) data: Arc<AssetProcessorData>, | ||
} | ||
|
||
/// Internal data stored inside an [`AssetProcessor`]. | ||
pub struct AssetProcessorData { | ||
pub(crate) asset_infos: async_lock::RwLock<ProcessorAssetInfos>, | ||
log: async_lock::RwLock<Option<ProcessorTransactionLog>>, | ||
|
@@ -91,6 +131,7 @@ impl AssetProcessor { | |
Self { server, data } | ||
} | ||
|
||
/// Gets a reference to the [`Arc`] containing the [`AssetProcessorData`]. | ||
pub fn data(&self) -> &Arc<AssetProcessorData> { | ||
&self.data | ||
} | ||
|
@@ -965,6 +1006,7 @@ impl AssetProcessor { | |
} | ||
|
||
impl AssetProcessorData { | ||
/// Initializes a new [`AssetProcessorData`] using the given [`AssetSources`]. | ||
pub fn new(source: AssetSources) -> Self { | ||
let (mut finished_sender, finished_receiver) = async_broadcast::broadcast(1); | ||
let (mut initialized_sender, initialized_receiver) = async_broadcast::broadcast(1); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.