From b9abf1d82f625d95a54c5c86f0c2b1f690b7ca01 Mon Sep 17 00:00:00 2001 From: Brooks Palin Date: Thu, 14 Mar 2024 19:57:20 -0600 Subject: [PATCH 01/21] Composite Mode Camera Motions (#86) This PR adds the camera motions to the composite mode. There are currently 4 camera motion modes: `Orbit`, `Static`, `Pan`, `Zoom`. They are accessed by using the `--camera-motion [motion]` argument. For example, if I want to render a scene with an orbiting motion, I would do the following: `studio-headless scene --camera-motion orbit scene.ron ` Some things to note: - The argument `--orbit` no longer is there. It has been deprecated! - Currently the speed is hard coded. This can be set as a command arg later. - This only works with scenes, as this is intended for the `sample-room` scene. May not work great for other scenes Let me know if there is anything that I can fix! --- editor.ron | 4 +- studio/src/lib.rs | 2 +- studio/src/main-headless.rs | 114 +++++++++++++++++++++++++++--------- studio/src/main.rs | 6 +- 4 files changed, 91 insertions(+), 35 deletions(-) diff --git a/editor.ron b/editor.ron index 5ec76bc..61f692c 100644 --- a/editor.ron +++ b/editor.ron @@ -1,6 +1,6 @@ { - "space_editor_core::hotkeys::HotkeySet": "{\"space_editor_core::hotkeys::HotkeySet\":(bindings:{Rotate:[R],Translate:[G],Scale:[S],Multiple:[ShiftLeft],Clone:[AltLeft],Delete:[X]},name:\"GizmoHotkey\")}", - "space_undo::ChangeChainSettings": "{\"space_undo::ChangeChainSettings\":(max_change_chain_size:200)}", "space_persistence::PersistenceSettings": "{\"space_persistence::PersistenceSettings\":(load_on_startup:true,save_on_close:true)}", "space_editor_ui::settings::NewWindowSettings": "{\"space_editor_ui::settings::NewWindowSettings\":(new_tab:SameNode)}", + "space_undo::ChangeChainSettings": "{\"space_undo::ChangeChainSettings\":(max_change_chain_size:200)}", + "space_editor_core::hotkeys::HotkeySet": "{\"space_editor_core::hotkeys::HotkeySet\":(bindings:{Rotate:[R],Translate:[G],Scale:[S],Multiple:[ShiftLeft],Clone:[AltLeft],Delete:[X]},name:\"GizmoHotkey\")}", } \ No newline at end of file diff --git a/studio/src/lib.rs b/studio/src/lib.rs index ddc51fb..6eff445 100644 --- a/studio/src/lib.rs +++ b/studio/src/lib.rs @@ -26,7 +26,7 @@ mod mixamo; mod path; mod persistance; mod remote; -mod scene; +pub mod scene; pub mod screenshot; mod skybox; mod ui; diff --git a/studio/src/main-headless.rs b/studio/src/main-headless.rs index 46cb0bd..2a302bc 100644 --- a/studio/src/main-headless.rs +++ b/studio/src/main-headless.rs @@ -1,6 +1,9 @@ use bevy::{prelude::*, render::render_resource::Extent3d, transform::components::Transform}; use clap::{Args, Parser, Subcommand}; -use studio::headless::{start_headless, HeadlessMode}; +use studio::{ + headless::{start_headless, HeadlessMode}, + scene::SceneState, +}; #[derive(Parser)] #[command(name = "StorytellerStudioHeadless")] @@ -20,11 +23,7 @@ enum Subcommands { Scene { scene_dir: String, #[arg(long)] - orbit: bool, - #[arg(long, value_parser = clap::value_parser!(f32))] - orbit_radius: Option, - #[arg(long, value_parser = clap::value_parser!(f32))] - orbit_speed: Option, + camera_motion: Option, #[arg(long, short)] output_dir: Option, #[arg(long)] @@ -73,9 +72,7 @@ fn main() { let mut app = match args.subcommand { Subcommands::Scene { scene_dir, - orbit, - orbit_speed, - orbit_radius, + camera_motion, skybox, output_dir, output_resolution, @@ -98,15 +95,28 @@ fn main() { frames, output_res, ); - let orbit_speed = orbit_speed.unwrap_or(1.0); - let orbit_radius = orbit_radius.unwrap_or(8.0); - if orbit { - app.insert_resource(OrbitSettings { - radius: orbit_radius, - speed: orbit_speed, - }) - .add_systems(Update, orbit_scene); + if let Some(camera_motion) = camera_motion { + match camera_motion.as_str() { + "orbit" => { + app.insert_resource(CameraMotion::Orbit); + } + "pan" => { + app.insert_resource(CameraMotion::Pan); + } + "zoom" => { + app.insert_resource(CameraMotion::Zoom); + } + "static" => { + app.insert_resource(CameraMotion::Static); + } + _ => panic!("Unsupported camera motion type."), + } + + app.add_systems( + Update, + update_camera_motion.run_if(in_state(SceneState::Active)), + ); } app @@ -166,27 +176,73 @@ fn main() { app.run(); } +pub const SPEED: f32 = 0.1; + #[derive(Resource)] -struct OrbitSettings { - radius: f32, - speed: f32, +enum CameraMotion { + Orbit, + Pan, + Zoom, + Static, } -fn orbit_scene( - mut camera: Query<&mut Transform, With>, - orbit_settings: Res, +pub(crate) fn update_camera_motion( + mut camera: Query<&mut Transform, (With, Without)>, + camera_motion: Res, time: Res