Skip to content

Commit e0d38a4

Browse files
alice-i-cecilecart
andauthored
Add basic docs explaining what asset processing is and where to look (#15058)
# Objective Asset processing (added as part of #8624) is a powerful, high-impact feature, but has been widely underused (and underdeveloped) due to poor developer understanding. ## Solution In this PR, I've documented what asset processing is, why it's useful, and pointed users to the two primary entry points. While I would like substantially more involved practical examples for how to perform common asset-processing tasks, I've split them out from this PR for ease of review (and actually submitting this for review before the weekend). We should add bread crumbs from the module docs to these docs, but whether we add that here or in #15056 depends on which gets merged first. --------- Co-authored-by: Carter Anderson <[email protected]>
1 parent 23aca13 commit e0d38a4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

crates/bevy_asset/src/processor/mod.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
//! 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.
2+
//!
3+
//! You can think of the asset processing system as a "build system" for assets.
4+
//! When an artist adds a new asset to the project or an asset is changed (assuming asset hot reloading is enabled), the asset processing system will automatically perform the specified processing steps on the asset.
5+
//! This can include things like creating lightmaps for baked lighting, compressing a `.wav` file to an `.ogg`, or generating mipmaps for a texture.
6+
//!
7+
//! Its core values are:
8+
//!
9+
//! 1. Automatic: new and changed assets should be ready to use in-game without requiring any manual conversion or cleanup steps.
10+
//! 2. Configurable: every game has its own needs, and a high level of transparency and control is required.
11+
//! 3. Lossless: the original asset should always be preserved, ensuring artists can make changes later.
12+
//! 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.
13+
//!
14+
//! Taken together, this means that the original asset plus the processing steps should be enough to regenerate the final asset.
15+
//! While it may be possible to manually edit the final asset, this should be discouraged.
16+
//! Final post-processed assets should generally not be version-controlled, except to save developer time when recomputing heavy asset processing steps.
17+
//!
18+
//! # Usage
19+
//!
20+
//! Asset processing can be enabled or disabled in [`AssetPlugin`](crate::AssetPlugin) by setting the [`AssetMode`](crate::AssetMode).\
21+
//! Enable Bevy's `file_watcher` feature to automatically watch for changes to assets and reprocess them.
22+
//!
23+
//! To register a new asset processor, use [`AssetProcessor::register_processor`].
24+
//! To set the default asset processor for a given extension, use [`AssetProcessor::set_default_processor`].
25+
//! In most cases, these methods will be called directly on [`App`](bevy_app::App) using the [`AssetApp`](crate::AssetApp) extension trait.
26+
//!
27+
//! If a default asset processor is set, assets with a matching extension will be processed using that processor before loading.
28+
//!
29+
//! 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.
30+
//!
31+
//! # Defining asset processors
32+
//!
33+
//! Bevy provides two different ways to define new asset processors:
34+
//!
35+
//! - [`LoadTransformAndSave`] + [`AssetTransformer`](crate::transformer::AssetTransformer): a high-level API for loading, transforming, and saving assets.
36+
//! - [`Process`]: a flexible low-level API for processing assets in arbitrary ways.
37+
//!
38+
//! In most cases, [`LoadTransformAndSave`] should be sufficient.
39+
140
mod log;
241
mod process;
342

@@ -61,6 +100,7 @@ pub struct AssetProcessor {
61100
pub(crate) data: Arc<AssetProcessorData>,
62101
}
63102

103+
/// Internal data stored inside an [`AssetProcessor`].
64104
pub struct AssetProcessorData {
65105
pub(crate) asset_infos: async_lock::RwLock<ProcessorAssetInfos>,
66106
log: async_lock::RwLock<Option<ProcessorTransactionLog>>,
@@ -91,6 +131,7 @@ impl AssetProcessor {
91131
Self { server, data }
92132
}
93133

134+
/// Gets a reference to the [`Arc`] containing the [`AssetProcessorData`].
94135
pub fn data(&self) -> &Arc<AssetProcessorData> {
95136
&self.data
96137
}
@@ -965,6 +1006,7 @@ impl AssetProcessor {
9651006
}
9661007

9671008
impl AssetProcessorData {
1009+
/// Initializes a new [`AssetProcessorData`] using the given [`AssetSources`].
9681010
pub fn new(source: AssetSources) -> Self {
9691011
let (mut finished_sender, finished_receiver) = async_broadcast::broadcast(1);
9701012
let (mut initialized_sender, initialized_receiver) = async_broadcast::broadcast(1);

crates/bevy_asset/src/transformer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use std::{
1111
};
1212

1313
/// Transforms an [`Asset`] of a given [`AssetTransformer::AssetInput`] type to an [`Asset`] of [`AssetTransformer::AssetOutput`] type.
14+
///
15+
/// This trait is commonly used in association with [`LoadTransformAndSave`](crate::processor::LoadTransformAndSave) to accomplish common asset pipeline workflows.
1416
pub trait AssetTransformer: Send + Sync + 'static {
1517
/// The [`Asset`] type which this [`AssetTransformer`] takes as and input.
1618
type AssetInput: Asset;

0 commit comments

Comments
 (0)