From 762ce21d7c05e5415259ad0c00fcaf9fd2d4f634 Mon Sep 17 00:00:00 2001 From: MiniaczQ Date: Sun, 14 Jan 2024 01:42:47 +0100 Subject: [PATCH 1/2] fix extract --- examples/3d/shadow_biases.rs | 120 +--------- examples/3d/skybox.rs | 138 +---------- examples/helpers/camera_controller.rs | 219 ++++++++++++++++++ .../scene_viewer/camera_controller_plugin.rs | 196 ---------------- examples/tools/scene_viewer/main.rs | 6 +- .../tools/scene_viewer/scene_viewer_plugin.rs | 2 +- 6 files changed, 234 insertions(+), 447 deletions(-) create mode 100644 examples/helpers/camera_controller.rs delete mode 100644 examples/tools/scene_viewer/camera_controller_plugin.rs diff --git a/examples/3d/shadow_biases.rs b/examples/3d/shadow_biases.rs index c3d3db32ff3a0..a9de1ff94fbde 100644 --- a/examples/3d/shadow_biases.rs +++ b/examples/3d/shadow_biases.rs @@ -1,12 +1,15 @@ //! Demonstrates how shadow biases affect shadows in a 3d scene. -use std::f32::consts::PI; +#[path = "../helpers/camera_controller.rs"] +mod camera_controller; -use bevy::{input::mouse::MouseMotion, pbr::ShadowFilteringMethod, prelude::*}; +use bevy::{pbr::ShadowFilteringMethod, prelude::*}; +use camera_controller::{CameraController, CameraControllerPlugin}; fn main() { App::new() .add_plugins(DefaultPlugins) + .add_plugins(CameraControllerPlugin) .add_systems(Startup, setup) .add_systems( Update, @@ -16,7 +19,6 @@ fn main() { adjust_point_light_biases, toggle_light, adjust_directional_light_biases, - camera_controller, ), ) .run(); @@ -342,115 +344,3 @@ fn adjust_directional_light_biases( example_text.single_mut().sections[20].value = format!("{:.1}", light.shadow_normal_bias); } } - -#[derive(Component)] -struct CameraController { - pub enabled: bool, - pub sensitivity: f32, - pub key_forward: KeyCode, - pub key_back: KeyCode, - pub key_left: KeyCode, - pub key_right: KeyCode, - pub key_up: KeyCode, - pub key_down: KeyCode, - pub key_run: KeyCode, - pub walk_speed: f32, - pub run_speed: f32, - pub friction: f32, - pub pitch: f32, - pub yaw: f32, - pub velocity: Vec3, -} - -impl Default for CameraController { - fn default() -> Self { - Self { - enabled: true, - sensitivity: 0.5, - key_forward: KeyCode::KeyW, - key_back: KeyCode::KeyS, - key_left: KeyCode::KeyA, - key_right: KeyCode::KeyD, - key_up: KeyCode::KeyE, - key_down: KeyCode::KeyQ, - key_run: KeyCode::ShiftLeft, - walk_speed: 10.0, - run_speed: 30.0, - friction: 0.5, - pitch: 0.0, - yaw: 0.0, - velocity: Vec3::ZERO, - } - } -} - -fn camera_controller( - time: Res