|
| 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 | +
|
1 | 40 | mod log;
|
2 | 41 | mod process;
|
3 | 42 |
|
@@ -61,6 +100,7 @@ pub struct AssetProcessor {
|
61 | 100 | pub(crate) data: Arc<AssetProcessorData>,
|
62 | 101 | }
|
63 | 102 |
|
| 103 | +/// Internal data stored inside an [`AssetProcessor`]. |
64 | 104 | pub struct AssetProcessorData {
|
65 | 105 | pub(crate) asset_infos: async_lock::RwLock<ProcessorAssetInfos>,
|
66 | 106 | log: async_lock::RwLock<Option<ProcessorTransactionLog>>,
|
@@ -91,6 +131,7 @@ impl AssetProcessor {
|
91 | 131 | Self { server, data }
|
92 | 132 | }
|
93 | 133 |
|
| 134 | + /// Gets a reference to the [`Arc`] containing the [`AssetProcessorData`]. |
94 | 135 | pub fn data(&self) -> &Arc<AssetProcessorData> {
|
95 | 136 | &self.data
|
96 | 137 | }
|
@@ -965,6 +1006,7 @@ impl AssetProcessor {
|
965 | 1006 | }
|
966 | 1007 |
|
967 | 1008 | impl AssetProcessorData {
|
| 1009 | + /// Initializes a new [`AssetProcessorData`] using the given [`AssetSources`]. |
968 | 1010 | pub fn new(source: AssetSources) -> Self {
|
969 | 1011 | let (mut finished_sender, finished_receiver) = async_broadcast::broadcast(1);
|
970 | 1012 | let (mut initialized_sender, initialized_receiver) = async_broadcast::broadcast(1);
|
|
0 commit comments