Skip to content
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

docs: update docs #2

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bevy_headless

Derived from `bevy_image_export` with
Derived from `bevy_image_export` with access to the current generated image frame.

## Examples
- [minimal](./examples/minimal.rs)
5 changes: 2 additions & 3 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ impl Node for ImageExportNode {
world: &World,
) -> Result<(), NodeRunError> {
for (_, source) in world.resource::<RenderAssets<ImageExportSource>>().iter() {
if let Some(gpu_image) = world
.resource::<RenderAssets<Image>>()
.get(&source.source_handle)
if let Some(gpu_image) =
world.resource::<RenderAssets<Image>>().get(&source.source_handle)
{
render_context.command_encoder().copy_texture_to_buffer(
gpu_image.texture.as_image_copy(),
Expand Down
48 changes: 13 additions & 35 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ pub struct GpuImageExportSource {

impl GpuImageExportSource {
fn get_bps(&self) -> (usize, usize, Extent3d) {
(
self.bytes_per_row as usize,
self.padded_bytes_per_row as usize,
self.source_size,
)
(self.bytes_per_row as usize, self.padded_bytes_per_row as usize, self.source_size)
}
}

Expand Down Expand Up @@ -122,29 +118,20 @@ pub struct ImageExportStartFrame(u64);

impl Default for ImageExportSettings {
fn default() -> Self {
Self {
extension: "png".into(),
}
Self { extension: "png".into() }
}
}

impl ExtractComponent for ImageExportSettings {
type Filter = ();
type Out = (Self, Handle<ImageExportSource>, ImageExportStartFrame);
type Query = (
&'static Self,
&'static Handle<ImageExportSource>,
&'static ImageExportStartFrame,
);
type Query =
(&'static Self, &'static Handle<ImageExportSource>, &'static ImageExportStartFrame);

fn extract_component(
(settings, source_handle, start_frame): QueryItem<'_, Self::Query>,
) -> Option<Self::Out> {
Some((
settings.clone(),
source_handle.clone_weak(),
start_frame.clone(),
))
Some((settings.clone(), source_handle.clone_weak(), start_frame.clone()))
}
}

Expand All @@ -155,9 +142,7 @@ fn setup_exporters(
) {
*frame_id = frame_id.wrapping_add(1);
for entity in &exporters {
commands
.entity(entity)
.insert(ImageExportStartFrame(*frame_id));
commands.entity(entity).insert(ImageExportStartFrame(*frame_id));
}
}

Expand Down Expand Up @@ -228,7 +213,7 @@ fn save_buffer_as_resource(
frame_id,
extension,
);
}
},
_ => {
capture_img_bytes::<Rgba<u8>>(
&image_bytes,
Expand All @@ -237,7 +222,7 @@ fn save_buffer_as_resource(
frame_id,
extension,
);
}
},
}
}
}
Expand All @@ -255,14 +240,11 @@ fn capture_img_bytes<P: Pixel + PixelWithColorType>(
{
match ImageBuffer::<P, _>::from_raw(source_size.width, source_size.height, image_bytes) {
Some(image_bytes) => {
curr_img
.0
.lock()
.update_data(frame_id, &image_bytes, extension.to_owned());
}
curr_img.0.lock().update_data(frame_id, &image_bytes, extension.to_owned());
},
None => {
log::error!("Failed creating image buffer for frame - '{frame_id}'");
}
},
}
}

Expand Down Expand Up @@ -295,9 +277,7 @@ impl Plugin for HeadlessPlugin {

app.configure_sets(
PostUpdate,
(SetupImageExport, SetupImageExportFlush)
.chain()
.before(CameraUpdateSystem),
(SetupImageExport, SetupImageExportFlush).chain().before(CameraUpdateSystem),
)
.register_type::<ImageExportSource>()
.init_asset::<ImageExportSource>()
Expand All @@ -320,9 +300,7 @@ impl Plugin for HeadlessPlugin {

render_app.add_systems(
Render,
save_buffer_as_resource
.after(RenderSet::Render)
.before(RenderSet::Cleanup),
save_buffer_as_resource.after(RenderSet::Render).before(RenderSet::Cleanup),
);

let mut graph = render_app.world.get_resource_mut::<RenderGraph>().unwrap();
Expand Down
Loading