mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-17 00:13:17 +00:00
Merge branch 'main' of https://github.com/storytold/storyteller-bevy into animation-clips-setup
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"space_editor_core::hotkeys::HotkeySet<space_editor_ui::tools::gizmo::GizmoHotkey>": "{\"space_editor_core::hotkeys::HotkeySet<space_editor_ui::tools::gizmo::GizmoHotkey>\":(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_persistence::PersistenceSettings": "{\"space_persistence::PersistenceSettings\":(load_on_startup:true,save_on_close:true)}",
|
||||
"space_undo::ChangeChainSettings": "{\"space_undo::ChangeChainSettings\":(max_change_chain_size:200)}",
|
||||
}
|
||||
+1
-1
@@ -26,7 +26,7 @@ mod mixamo;
|
||||
mod path;
|
||||
mod persistance;
|
||||
mod remote;
|
||||
mod scene;
|
||||
pub mod scene;
|
||||
pub mod screenshot;
|
||||
mod skybox;
|
||||
mod ui;
|
||||
|
||||
+90
-29
@@ -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,9 @@ enum Subcommands {
|
||||
Scene {
|
||||
scene_dir: String,
|
||||
#[arg(long)]
|
||||
orbit: bool,
|
||||
#[arg(long, value_parser = clap::value_parser!(f32))]
|
||||
orbit_radius: Option<f32>,
|
||||
#[arg(long, value_parser = clap::value_parser!(f32))]
|
||||
orbit_speed: Option<f32>,
|
||||
camera_motion: Option<String>,
|
||||
#[arg(long)]
|
||||
camera_motion_speed: Option<f32>,
|
||||
#[arg(long, short)]
|
||||
output_dir: Option<String>,
|
||||
#[arg(long)]
|
||||
@@ -73,9 +74,8 @@ fn main() {
|
||||
let mut app = match args.subcommand {
|
||||
Subcommands::Scene {
|
||||
scene_dir,
|
||||
orbit,
|
||||
orbit_speed,
|
||||
orbit_radius,
|
||||
camera_motion,
|
||||
camera_motion_speed,
|
||||
skybox,
|
||||
output_dir,
|
||||
output_resolution,
|
||||
@@ -98,15 +98,29 @@ 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 {
|
||||
let camera_motion_speed = camera_motion_speed.unwrap_or(1.0);
|
||||
match camera_motion.as_str() {
|
||||
"orbit" => {
|
||||
app.insert_resource(CameraMotion::Orbit(camera_motion_speed));
|
||||
}
|
||||
"pan" => {
|
||||
app.insert_resource(CameraMotion::Pan(camera_motion_speed));
|
||||
}
|
||||
"zoom" => {
|
||||
app.insert_resource(CameraMotion::Zoom(camera_motion_speed));
|
||||
}
|
||||
"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
|
||||
@@ -167,26 +181,73 @@ fn main() {
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct OrbitSettings {
|
||||
radius: f32,
|
||||
speed: f32,
|
||||
enum CameraMotion {
|
||||
Orbit(f32),
|
||||
Pan(f32),
|
||||
Zoom(f32),
|
||||
Static,
|
||||
}
|
||||
|
||||
fn orbit_scene(
|
||||
mut camera: Query<&mut Transform, With<Camera>>,
|
||||
orbit_settings: Res<OrbitSettings>,
|
||||
pub(crate) fn update_camera_motion(
|
||||
mut camera: Query<&mut Transform, (With<Camera>, Without<Parent>)>,
|
||||
camera_motion: Res<CameraMotion>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
println!("{}", camera.iter().count());
|
||||
let Ok(mut main_cam_transform) = camera.get_single_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
main_cam_transform.translation = Vec3::new(
|
||||
orbit_settings.radius * (time.elapsed_seconds() * orbit_settings.speed).cos(),
|
||||
6.0,
|
||||
orbit_settings.radius * (time.elapsed_seconds() * orbit_settings.speed).sin(),
|
||||
);
|
||||
main_cam_transform.look_at(Vec3::ZERO, Vec3::Y);
|
||||
println!("Updating camera motion");
|
||||
|
||||
match *camera_motion {
|
||||
CameraMotion::Orbit(speed) => {
|
||||
orbit_camera(&mut main_cam_transform, &time, speed);
|
||||
}
|
||||
CameraMotion::Pan(speed) => {
|
||||
pan_camera(&mut main_cam_transform, &time, speed);
|
||||
}
|
||||
CameraMotion::Zoom(speed) => {
|
||||
zoom_camera(&mut main_cam_transform, &time, speed);
|
||||
}
|
||||
CameraMotion::Static => {
|
||||
main_cam_transform.translation = Vec3::new(0.340, 1.1, -0.5);
|
||||
main_cam_transform.rotation = Quat::from_euler(EulerRot::XYZ, 0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
// main_cam_transform.look_at(Vec3::ZERO, Vec3::Y);
|
||||
}
|
||||
|
||||
fn zoom_camera(main_cam_transform: &mut Transform, time: &Time<()>, speed : f32) {
|
||||
let scaled_time = time.elapsed().as_secs_f32() * speed;
|
||||
let normalized_cos = (-scaled_time.cos() + 1.0) / 2.0;
|
||||
let start_pos = Vec3::new(0.366, 1.1, 2.5);
|
||||
let end_pos = Vec3::new(0.366, 1.1, -0.5);
|
||||
|
||||
main_cam_transform.translation = start_pos.lerp(end_pos, normalized_cos);
|
||||
main_cam_transform.rotation = Quat::from_euler(EulerRot::XYZ, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
fn pan_camera(main_cam_transform: &mut Transform, time: &Time<()>, speed : f32) {
|
||||
let scaled_time = time.elapsed().as_secs_f32() * speed;
|
||||
let normalized_cos = (-scaled_time.cos() + 1.0) / 2.0;
|
||||
let start_pos = Vec3::new(0.676, 1.1, 0.119);
|
||||
let end_pos = Vec3::new(0.067, 1.1, 0.121);
|
||||
|
||||
main_cam_transform.translation = start_pos.lerp(end_pos, normalized_cos);
|
||||
main_cam_transform.rotation = Quat::from_euler(EulerRot::XYZ, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
fn orbit_camera(main_cam_transform: &mut Mut<'_, Transform>, time: &Res<'_, Time>, speed : f32) {
|
||||
let scaled_time = time.elapsed().as_secs_f32() * speed;
|
||||
let max_angle = std::f32::consts::PI / 2.0;
|
||||
let normalized_cos = (scaled_time.cos() + 1.0) / 2.0;
|
||||
let angle = max_angle * normalized_cos;
|
||||
|
||||
// let t = (time.elapsed().as_secs_f32() / 5.0) % 1.0;
|
||||
|
||||
main_cam_transform.translation = Vec3::new(-2.2 * angle.cos(), 1.0, 2.5 * angle.sin());
|
||||
main_cam_transform.look_at(Vec3::new(0.347, 0.556, -1.0), Vec3::Y);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@ use bevy::{
|
||||
window::{close_on_esc, Window},
|
||||
};
|
||||
use clap::Parser;
|
||||
use studio::{screenshot::ScreenShotPlugin, InitAsset, InitParams, StudioMode};
|
||||
use studio::{InitAsset, InitParams, StudioMode};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "StorytellerStudio")]
|
||||
@@ -19,7 +19,7 @@ struct StudioArgs {
|
||||
fn main() {
|
||||
let args = StudioArgs::parse();
|
||||
|
||||
let object_id = args.model.unwrap_or("Mannequin.gltf".to_string());
|
||||
let object_id = args.model.unwrap_or("sample-room.gltf".to_string());
|
||||
let skybox_id = args.skybox.unwrap_or("gum_trees_4k".to_string());
|
||||
|
||||
// Edit the arguments here to change the default startup scene or skybox
|
||||
@@ -37,7 +37,7 @@ fn main() {
|
||||
|
||||
// Add any additional systems, resources, etc. for local debugging
|
||||
app.add_systems(Update, close_on_esc);
|
||||
app.add_plugins(ScreenShotPlugin);
|
||||
// app.add_plugins(ScreenShotPlugin);
|
||||
|
||||
app.run();
|
||||
}
|
||||
|
||||
+2
-1
@@ -332,7 +332,8 @@ fn initialiaze_headless(
|
||||
},
|
||||
CameraControllerBundle::new(focus, camera_xform.translation),
|
||||
ScreenCapture::from_out(&headless_settings.output_dir)
|
||||
.with_max_frames(headless_settings.max_frames),
|
||||
//Part of quick hack, see screenshot.rs#261
|
||||
.with_max_frames(headless_settings.max_frames + 3),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,9 @@ fn update_screen_capture_on_extract_step(
|
||||
fn extract_screen_capture_components(
|
||||
mut commands: Commands,
|
||||
screen_capure_comps: Extract<Query<(Entity, &ScreenCapture), With<Camera>>>,
|
||||
scene_state : Extract<Res<State<SceneState>>>
|
||||
) {
|
||||
if scene_state.get() != &SceneState::Active { return };
|
||||
for (entity, screen_capture) in screen_capure_comps.iter() {
|
||||
if screen_capture.should_capture() {
|
||||
info!(
|
||||
@@ -250,10 +252,25 @@ impl ViewNode for ScreenCaptureNode {
|
||||
//==============================================================================
|
||||
|
||||
fn save_buffer_to_file(
|
||||
mut frames_to_skip : Local<Option<u32>>,
|
||||
buffers: Query<(&ScreenCapture, &ScreenCaptureBuffers)>,
|
||||
device: Res<RenderDevice>,
|
||||
) {
|
||||
for (screen_capture, buffers) in buffers.iter() {
|
||||
|
||||
// ALERT!! ALERT!! Filthy Hack in effect
|
||||
// Engine does not load scene in time for the first 3 frames
|
||||
// So we skip them. Oops :(
|
||||
// TODO: Fix the Race Condition and properly take screenshots.
|
||||
let frames_skipped = frames_to_skip.unwrap_or(3);
|
||||
|
||||
if frames_skipped > 0 {
|
||||
println!("Skipping Frame");
|
||||
*frames_to_skip = Some(frames_skipped - 1);
|
||||
return;
|
||||
}
|
||||
// Filthy Hack Ends
|
||||
|
||||
if buffers.main_bytes_per_row != buffers.main_padded_bytes_per_row {
|
||||
println!("These don't match!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user