-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimal.rs
69 lines (62 loc) · 2.26 KB
/
minimal.rs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use bevy::{
app::{App as Engine, ScheduleRunnerPlugin, Startup, Update},
asset::Assets,
core_pipeline::{clear_color::ClearColor, core_3d::Camera3dBundle, tonemapping::Tonemapping},
ecs::system::{Commands, Res, ResMut},
math::Vec3,
render::{camera::Camera, color::Color, texture::Image},
transform::components::Transform,
utils::default,
};
use bevy_headless::{CurrImageContainer, HeadlessPlugin, ImageExportSource};
fn setup(
mut commands: Commands,
mut images: ResMut<Assets<Image>>,
mut scene_controller: ResMut<bevy_headless::SceneInfo>,
export_sources: ResMut<Assets<ImageExportSource>>,
) {
let render_target = bevy_headless::setup_render_target(
&mut commands,
&mut images,
&mut scene_controller,
export_sources,
);
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 6., 12.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y),
tonemapping: Tonemapping::None,
camera: Camera { target: render_target, ..default() },
..default()
});
}
fn save_img(curr_img: Res<CurrImageContainer>) {
let curr_img = curr_img.0.lock();
if !curr_img.extension.is_empty() {
let path = format!("out/{:06}.{}", curr_img.frame_id, curr_img.extension);
log::info!("saving image to {path}");
let img = curr_img.img_buffer.clone();
std::thread::spawn(move || {
if let Err(e) = img.save(path) {
log::error!("Couldn't save image | {e:?}");
};
});
}
}
pub fn main() {
pretty_env_logger::formatted_builder()
.filter_module("minimal", log::LevelFilter::Info)
.filter_module("bevy", log::LevelFilter::Info)
.filter_module("bevy_headless", log::LevelFilter::Info)
.init();
std::fs::create_dir_all("out").expect("Output path could not be created");
let (w, h) = (1920, 1080);
Engine::new()
.insert_resource(bevy_headless::SceneInfo::new(w, h))
.insert_resource(ClearColor(Color::rgb_u8(0, 0, 0)))
.add_plugins((
HeadlessPlugin,
ScheduleRunnerPlugin::run_loop(std::time::Duration::from_secs_f64(1.0 / 60.0)),
))
.add_systems(Startup, setup)
.add_systems(Update, save_img)
.run();
}