use std::f32::consts::PI; use std::time::Duration; use bevy::app::ScheduleRunnerPlugin; use bevy::camera::RenderTarget; use bevy::color::Color; use bevy::prelude::*; use wgpu::{TextureFormat, TextureUsages}; mod post_process; use crate::post_process::PostProcessSettings; use crate::renderer::{G13Resource, ImageExport, ImageExportPlugin, ImageExportSource}; use crate::shared::Spinner; mod renderer; mod shared; fn main() { App::new() .add_plugins(( DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { resolution: bevy::window::WindowResolution::new(160 * 4, 43 * 4) .with_scale_factor_override(4.0), ..default() }), ..default() }), ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64(1. / 30.)), post_process::PostProcessPlugin, ImageExportPlugin, )) .insert_resource(ClearColor(Color::linear_rgba(0.0, 0.0, 0.0, 0.0))) .add_systems(Startup, setup_scene_system) .add_systems(PostStartup, spawn_in_ui) .add_systems(Update, rotate_cube) .run(); } fn setup_scene_system( mut commands: Commands, meshes: ResMut>, materials: ResMut>, mut images: ResMut>, mut export_sources: ResMut>, ) { shared::spawn_3d_scene(commands.reborrow(), meshes, materials); let mut image = Image::new_target_texture( 160, 43, TextureFormat::Rgba8Unorm, Some(TextureFormat::Rgba8UnormSrgb), ); image.texture_descriptor.usage = TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::RENDER_ATTACHMENT; let image_handle = images.add(image); commands.spawn(( Camera3d::default(), Camera::default(), RenderTarget::Image(image_handle.clone().into()), Transform::from_xyz(0.0, 1.0, 2.5).looking_at(Vec3::ZERO, Vec3::Y), UiAntiAlias::Off, PostProcessSettings { scale: 1.0 }, )); commands.spawn((ImageExport(export_sources.add(image_handle)),)); } fn spawn_in_ui(mut commands: Commands, assets: Res, camera: Query<(Entity, &Camera)>) { let font: Handle = assets.load("fonts/Roboto-Bold.ttf"); let text_font = TextFont::from(font.clone()) .with_font_size(12.) .with_font_smoothing(bevy::text::FontSmoothing::None); let Ok(main_camera) = camera.single() else { return; // no camera... yet? }; commands.spawn(( Node { position_type: PositionType::Absolute, top: Val::Px(5.0), left: Val::Px(5.0), ..default() }, Text::new("Hello World!"), text_font.clone(), TextColor(Color::WHITE), UiTargetCamera(main_camera.0), )); } fn rotate_cube( mut cubes: Query<(&mut Transform, &Spinner)>, timer: Res