From 432e5a737ab29df30e39f30d8eca074dec317159 Mon Sep 17 00:00:00 2001 From: Leon Liu Date: Thu, 14 Aug 2025 10:00:31 +0900 Subject: [PATCH] update --- Cargo.lock | 54 +++++++++++++ Cargo.toml | 1 + examples/cam_follow.rs | 87 +++++++++++++++++++++ src/main.rs | 169 ++++++++++++++++++++++++++++++----------- 4 files changed, 268 insertions(+), 43 deletions(-) create mode 100644 examples/cam_follow.rs diff --git a/Cargo.lock b/Cargo.lock index e5c9c8e..6e6e490 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,6 +154,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + [[package]] name = "android_log-sys" version = "0.3.2" @@ -1704,6 +1710,18 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-link", +] + [[package]] name = "clang-sys" version = "1.8.1" @@ -2663,6 +2681,30 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core 0.61.2", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "image" version = "0.25.6" @@ -2756,6 +2798,17 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +[[package]] +name = "iyes_perf_ui" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e4468c51a47d2422a3a3e01b45cb47ed0fbce520495dd7de495bcfe8ce0f856" +dependencies = [ + "bevy", + "chrono", + "num-traits", +] + [[package]] name = "jni" version = "0.21.1" @@ -4204,6 +4257,7 @@ dependencies = [ "bevy", "bevy-inspector-egui", "bevy_panorbit_camera", + "iyes_perf_ui", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 691fb51..0584c5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" bevy = "0.16" bevy-inspector-egui = "0.33.1" bevy_panorbit_camera = "0.26" +iyes_perf_ui = "0.5.0" # Enable a small amount of optimization in the dev profile. [profile.dev] diff --git a/examples/cam_follow.rs b/examples/cam_follow.rs new file mode 100644 index 0000000..16f5334 --- /dev/null +++ b/examples/cam_follow.rs @@ -0,0 +1,87 @@ +//! Demonstrates how to have the camera follow a target object + +use bevy::prelude::*; +use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin}; +use std::f32::consts::TAU; + +fn main() { + App::new() + .add_plugins(DefaultPlugins) + .add_plugins(PanOrbitCameraPlugin) + .add_systems(Startup, setup) + .add_systems(Update, (animate_cube, cam_follow).chain()) + .run(); +} + +#[derive(Component)] +struct Cube; + +fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + // Ground + commands.spawn(( + Mesh3d(meshes.add(Plane3d::default().mesh().size(0.5, 0.5))), + MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))), + )); + // Cube + commands + .spawn(( + Mesh3d(meshes.add(Cuboid::new(0.1, 0.1, 0.1))), + MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))), + Transform::from_xyz(0.0, 0.5, 0.0), + )) + .insert(Cube); + // Light + commands.spawn(( + PointLight { + shadows_enabled: true, + ..default() + }, + Transform::from_xyz(4.0, 8.0, 4.0), + )); + // Camera + commands.spawn(( + Transform::from_translation(Vec3::new(0.0, 0.15, 0.5)), + PanOrbitCamera { + // Panning the camera changes the focus, and so you most likely want to disable + // panning when setting the focus manually + pan_sensitivity: 0.0, + // If you want to fully control the camera's focus, set smoothness to 0 so it + // immediately snaps to that location. If you want the 'follow' to be smoothed, + // leave this at default or set it to something between 0 and 1. + pan_smoothness: 0.0, + ..default() + }, + )); +} + +/// Move the cube in a circle around the Y axis +fn animate_cube( + time: Res