1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#![warn(missing_docs)]
//! Plugin for the Bevy game engine which provides the ability to render to an image headlessly.
use bevy::{
prelude::*,
render::{
extract_component::ExtractComponentPlugin, graph::CameraDriverLabel,
render_asset::RenderAssetPlugin, render_graph::RenderGraph, Render, RenderApp, RenderSet,
},
};
use components::HeadlessRenderDestination;
use nodes::{HeadlessRenderCopyLabel, HeadlessRenderCopyNode};
use render_assets::{HeadlessRenderSource, GpuHeadlessRenderSource};
/// Components used by this plugin.
pub mod components;
/// Render assets used by this plugin.
pub mod render_assets;
mod nodes;
mod systems;
/// Plugin which handles headless rendering.
pub struct HeadlessRenderPlugin;
impl Plugin for HeadlessRenderPlugin {
fn build(&self, app: &mut App) {
app.register_type::<HeadlessRenderSource>()
.init_asset::<HeadlessRenderSource>()
.register_asset_reflect::<HeadlessRenderSource>()
.add_plugins((
RenderAssetPlugin::<GpuHeadlessRenderSource>::default(),
ExtractComponentPlugin::<HeadlessRenderDestination>::default(),
));
let render_app = app.sub_app_mut(RenderApp);
render_app.add_systems(
Render,
systems::copy_buffers
.after(RenderSet::Render)
.before(RenderSet::Cleanup),
);
let mut graph = render_app.world_mut().resource_mut::<RenderGraph>();
graph.add_node(HeadlessRenderCopyLabel, HeadlessRenderCopyNode);
graph.add_node_edge(CameraDriverLabel, HeadlessRenderCopyLabel);
}
}
|