Debugging frame_scene_in_view system

This commit is contained in:
Danny McGee
2024-02-21 22:24:23 -05:00
parent a82dbf842c
commit bd85f595a9
5 changed files with 31 additions and 5 deletions
-2
View File
@@ -111,8 +111,6 @@ export class AppElement extends LitElement {
}
onSceneStateChange({ detail: state }: SceneStateEvent): void {
console.log("scene state change:", SceneState[state]);
this.loading = match (state, {
[SceneState.Active]: () => false,
_: () => true,
+1 -1
View File
@@ -20,7 +20,7 @@ use crate::{
};
#[derive(Resource, Deref, DerefMut)]
pub struct DebugMode(bool);
pub struct DebugMode(pub bool);
#[derive(Component, Clone, Copy, Debug)]
pub struct DebugPoint {
+1 -1
View File
@@ -39,7 +39,7 @@ pub use crate::{
anim::AnimPlugin,
bvh::BvhPlugin,
camera_controller::CameraControllerPlugin,
debug::DebugPlugin,
debug::{DebugMode, DebugPlugin},
input::StudioInputPlugin,
inspector::InspectorPlugin,
interaction::InteractionPlugin,
+9 -1
View File
@@ -1,6 +1,6 @@
use bevy::render::render_resource::Extent3d;
use clap::{Args, Parser, Subcommand};
use studio::{start_headless, HeadlessMode};
use studio::{start_headless, DebugMode, HeadlessMode};
#[derive(Parser)]
#[command(name = "StorytellerStudioHeadless")]
@@ -13,6 +13,9 @@ use studio::{start_headless, HeadlessMode};
struct StudioArgs {
#[command(subcommand)]
subcommand: Subcommands,
/// Render with debug visualizations enabled
#[arg(long, short)]
debug: bool,
}
#[derive(Subcommand)]
@@ -104,6 +107,11 @@ fn main() {
}
};
if args.debug {
println!("Starting in debug mode");
app.insert_resource(DebugMode(true));
}
app.run();
}
+20
View File
@@ -52,6 +52,10 @@ impl Plugin for ScenePlugin {
);
app.add_systems(Update, tag_scene_elements);
app.add_systems(
Update,
log_scene_state.run_if(resource_changed::<State<SceneState>>()),
);
//Auto loading screen
//Register handles on which we will look to show loading screen
@@ -82,6 +86,10 @@ impl Plugin for ScenePlugin {
}
}
fn log_scene_state(st_scene: Res<State<SceneState>>) {
info!("SceneState::{:?}", **st_scene);
}
fn minimal_scene_setup(mut cmd: Commands) {
cmd.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
@@ -331,6 +339,10 @@ fn frame_scene_in_view(
q_aabbs: Query<(&Aabb, &GlobalTransform), With<SceneAutoChild>>,
mut q_camera: Query<(&mut CameraController, &mut Transform, &Projection)>,
) {
info!("frame_scene_in_view");
info!(" q_aabbs length: {}", q_aabbs.iter().count());
info!(" q_camera length: {}", q_camera.iter().count());
let Ok((mut cam, mut cam_xform, cam_proj)) = q_camera.get_single_mut() else {
error!("Failed to get camera controller");
return;
@@ -400,12 +412,15 @@ fn frame_scene_in_view(
y: height,
} = bounding_rect.size();
info!(" bounding rect: {width:.2} x {height:.2}");
let s = f32::max(width, height);
let a = if s == height {
pproj.fov
} else {
f32::atan(pproj.aspect_ratio * f32::tan(pproj.fov / 2.))
};
info!(" FOV angle: {}°", a.to_degrees());
// TODO:
// According to "I eat babies" at the Ars Technica forums
@@ -427,6 +442,11 @@ fn frame_scene_in_view(
cam.focus = aabb.center.into();
cam.radius = radius;
cam_xform.translation = cam.focus + cam_xform.back() * radius;
info!(
"Centering camera at ({:.3}, {:.3}, {:.3}) with a radius of {radius:.3}",
cam.focus.x, cam.focus.y, cam.focus.z,
);
}
#[cfg(feature = "wasm")]