#creative #coding #sketching

bevy_image_export

Bevy plugin for rendering image sequences

10 releases (4 breaking)

0.5.2 Mar 16, 2023
0.5.1 Mar 14, 2023
0.4.1 Mar 7, 2023
0.3.0 Nov 18, 2022
0.1.0 Sep 7, 2022

#42 in Rendering

Download history 2/week @ 2022-11-28 3/week @ 2022-12-05 7/week @ 2022-12-12 2/week @ 2022-12-19 2/week @ 2022-12-26 1/week @ 2023-01-02 6/week @ 2023-01-09 1/week @ 2023-01-16 7/week @ 2023-01-23 10/week @ 2023-01-30 9/week @ 2023-02-06 12/week @ 2023-02-13 12/week @ 2023-02-20 2/week @ 2023-02-27 43/week @ 2023-03-06 74/week @ 2023-03-13

131 downloads per month

MIT license

24KB
300 lines

Bevy Image Export

Crates.io MIT/Apache 2.0

A Bevy plugin for rendering image sequences.

Usage

use bevy::{prelude::*, winit::WinitSettings};
use bevy_image_export::{ImageExportCamera, ImageExportPlugin};

fn main() {
    let export_plugin = ImageExportPlugin::default();
    let export_threads = export_plugin.threads.clone();

    App::new()
        .insert_resource(WinitSettings {
            return_from_run: true,
            ..default()
        })
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            primary_window: Some(Window {
                resolution: (1024., 1024.).into(),
                ..default()
            }),
            ..default()
        }))
        .add_plugin(export_plugin)
        // ...
        .run();

    // This line is optional but recommended.
    // It blocks the main thread until all image files have been saved successfully.
    export_threads.finish();
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    commands
        .spawn(Camera3dBundle {
            transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
            ..default()
        })

        // Add a child camera to your main camera and insert the ImageExportCamera component.
        .with_children(|parent| {
            parent
                .spawn(Camera3dBundle::default())
                .insert(ImageExportCamera {
                    // Frames will be saved to "./out/[#####].png".
                    output_dir: "out",
                    extension: "png",
                    ..default()
                });
        });

    // ...
}

Video file export

With FFmpeg installed, you can run the following command to convert your exported image sequence to an MP4 video file:

ffmpeg -r 60 -i out/%05d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p out.mp4

Dependencies

~32–67MB
~1M SLoC