Headless Mode fixes for the Backend (#65)

This PR brings some fixes that are needed for the backend to render
scenes.
This commit is contained in:
Brooks Palin
2024-02-29 21:47:42 -07:00
committed by GitHub
parent 3413810773
commit a2b2946678
6 changed files with 141 additions and 9 deletions
File diff suppressed because one or more lines are too long
+9 -3
View File
@@ -9,6 +9,7 @@ use wgpu::Extent3d;
use crate::{ use crate::{
bvh::{BvhAnimCompleteEvent, TestBvh}, bvh::{BvhAnimCompleteEvent, TestBvh},
scene::SceneState,
screenshot::{ScreenCapture, ScreenShotPlugin}, screenshot::{ScreenCapture, ScreenShotPlugin},
BvhPlugin, CommonPlugins, LoadLibraryObjectEvent, LoadSceneEvent, MainCamera, BvhPlugin, CommonPlugins, LoadLibraryObjectEvent, LoadSceneEvent, MainCamera,
MixamoImportEvent, MixamoPlugin, SkyboxId, StudioMode, WorldGridPlugin, MixamoImportEvent, MixamoPlugin, SkyboxId, StudioMode, WorldGridPlugin,
@@ -64,7 +65,10 @@ pub fn start_headless(
}, },
); );
app.add_systems(PostUpdate, check_for_bvh_capture_complete); app.add_systems(
PostUpdate,
check_for_bvh_capture_complete.run_if(in_state(SceneState::Active)),
);
} }
HeadlessMode::Scene(scene, skybox) => { HeadlessMode::Scene(scene, skybox) => {
app.add_systems( app.add_systems(
@@ -87,7 +91,10 @@ pub fn start_headless(
commands.insert_resource(SkyboxId(skybox.clone())); commands.insert_resource(SkyboxId(skybox.clone()));
}, },
); );
app.add_systems(PostUpdate, check_for_mixamo_capture_complete); app.add_systems(
PostUpdate,
check_for_mixamo_capture_complete.run_if(in_state(SceneState::Active)),
);
app.run(); app.run();
} }
@@ -135,7 +142,6 @@ fn check_for_bvh_capture_complete(
return; return;
}; };
println!("Frames captured {}", screen_capture.frames_captured());
if !screen_capture.should_capture() || !bvh_event_reader.is_empty() { if !screen_capture.should_capture() || !bvh_event_reader.is_empty() {
screen_capture.stop_capturing(); screen_capture.stop_capturing();
close_app.send(AppExit); close_app.send(AppExit);
+1
View File
@@ -7,6 +7,7 @@ use scene::ImportSceneEvent;
#[cfg(feature = "wasm")] #[cfg(feature = "wasm")]
use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_repr::{Deserialize_repr, Serialize_repr};
use space_editor::space_prefab::plugins::PrefabPlugin;
#[cfg(feature = "wasm")] #[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
+38 -3
View File
@@ -1,4 +1,7 @@
use bevy::render::render_resource::Extent3d; use bevy::{
prelude::*, render::render_resource::Extent3d, transform::components::Transform,
window::PrimaryWindow,
};
use clap::{Args, Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
use studio::headless::{start_headless, HeadlessMode}; use studio::headless::{start_headless, HeadlessMode};
@@ -19,6 +22,8 @@ struct StudioArgs {
enum Subcommands { enum Subcommands {
Scene { Scene {
scene_dir: String, scene_dir: String,
#[arg(long)]
orbit: bool,
#[arg(long, short)] #[arg(long, short)]
output_dir: Option<String>, output_dir: Option<String>,
#[arg(long)] #[arg(long)]
@@ -67,6 +72,7 @@ fn main() {
let mut app = match args.subcommand { let mut app = match args.subcommand {
Subcommands::Scene { Subcommands::Scene {
scene_dir, scene_dir,
orbit,
skybox, skybox,
output_dir, output_dir,
output_resolution, output_resolution,
@@ -82,13 +88,20 @@ fn main() {
let fps = fps.unwrap_or(24); let fps = fps.unwrap_or(24);
let frames = frames.unwrap_or(30); let frames = frames.unwrap_or(30);
let skybox = skybox.unwrap_or("gum_trees_4k".to_string()); let skybox = skybox.unwrap_or("gum_trees_4k".to_string());
start_headless( let mut app = start_headless(
HeadlessMode::Scene(scene_dir, skybox), HeadlessMode::Scene(scene_dir, skybox),
fps, fps,
&output_dir, &output_dir,
frames, frames,
output_res, output_res,
) );
if orbit {
app.insert_resource(OrbitSettings { radius: 10.0 })
.add_systems(Update, orbit_scene);
}
app
} }
Subcommands::Bvh { Subcommands::Bvh {
bvh_dir, bvh_dir,
@@ -145,6 +158,28 @@ fn main() {
app.run(); app.run();
} }
#[derive(Resource)]
struct OrbitSettings {
radius: f32,
}
fn orbit_scene(
mut camera: Query<&mut Transform, With<PrimaryWindow>>,
orbit_settings: Res<OrbitSettings>,
time: Res<Time>,
) {
let Ok(mut main_cam_transform) = camera.get_single_mut() else {
return;
};
main_cam_transform.translation = Vec3::new(
orbit_settings.radius * time.elapsed_seconds().cos() * 10.0,
orbit_settings.radius * time.elapsed_seconds().sin(),
6.0,
);
main_cam_transform.look_at(Vec3::ZERO, Vec3::Y);
}
//============================================================================== //==============================================================================
// Parsers // Parsers
//============================================================================== //==============================================================================
+3 -2
View File
@@ -26,7 +26,7 @@ use crate::{
camera_controller::{CameraController, CameraControllerBundle}, camera_controller::{CameraController, CameraControllerBundle},
change_tracking::{ChangeTracker, ChangeTrackingPlugin}, change_tracking::{ChangeTracker, ChangeTrackingPlugin},
debug::DebugPoint, debug::DebugPoint,
headless::{is_headless, is_not_headless, HeadlessSettings}, headless::{self, is_headless, is_not_headless, HeadlessSettings},
math::{Combinable, Extrema}, math::{Combinable, Extrema},
screenshot::ScreenCapture, screenshot::ScreenCapture,
MainCamera, MainCamera,
@@ -326,7 +326,8 @@ fn initialiaze_headless(
..default() ..default()
}, },
CameraControllerBundle::new(focus, camera_xform.translation), CameraControllerBundle::new(focus, camera_xform.translation),
ScreenCapture::from_out(&headless_settings.output_dir), ScreenCapture::from_out(&headless_settings.output_dir)
.with_max_frames(headless_settings.max_frames),
)); ));
} }
+13 -1
View File
@@ -1,4 +1,5 @@
use bevy::{ use bevy::{
app::AppExit,
core_pipeline::{core_3d, prepass::ViewPrepassTextures}, core_pipeline::{core_3d, prepass::ViewPrepassTextures},
prelude::*, prelude::*,
render::{ render::{
@@ -123,9 +124,16 @@ impl ScreenCapture {
} }
} }
fn update_screen_capture_on_extract_step(mut screen_captures: Query<&mut ScreenCapture>) { fn update_screen_capture_on_extract_step(
mut screen_captures: Query<&mut ScreenCapture>,
mut exit_event: EventWriter<AppExit>,
) {
for mut screen_capture in screen_captures.iter_mut() { for mut screen_capture in screen_captures.iter_mut() {
screen_capture.frames += 1; screen_capture.frames += 1;
if !screen_capture.should_capture() {
exit_event.send(AppExit);
}
// if screen_capture.number_of_frames == 0 { // if screen_capture.number_of_frames == 0 {
// commands.entity(entity).remove::<ScreenCapture>(); // commands.entity(entity).remove::<ScreenCapture>();
// } // }
@@ -139,6 +147,10 @@ fn extract_screen_capture_components(
) { ) {
for (entity, screen_capture) in screen_capure_comps.iter() { for (entity, screen_capture) in screen_capure_comps.iter() {
if screen_capture.should_capture() { if screen_capture.should_capture() {
println!(
"Capturing Frame: {} / {}",
screen_capture.frames, screen_capture.max_frames
);
commands.get_or_spawn(entity).insert(screen_capture.clone()); commands.get_or_spawn(entity).insert(screen_capture.clone());
} }
} }