diff --git a/Cargo.toml b/Cargo.toml index fb1e572..40372b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ dev_native = [ [dependencies] bevy = "0.15.0-rc.3" avian3d = { git = "https://github.com/Jondolf/avian.git", branch = "bevy-0.15", features = ["debug-plugin"] } +bevy-trait-query = { git = "https://github.com/JoJoJet/bevy-trait-query.git", branch = "bevy-0.15-rc" } thiserror = "2.0.3" # ----------------------------------------------------------------------------- diff --git a/docs/devlog.md b/docs/devlog.md index fba4b1d..d44700a 100644 --- a/docs/devlog.md +++ b/docs/devlog.md @@ -42,7 +42,7 @@ update them or remove them. - [x] `avian3d` -> branch `bevy-0.15` - [ ] ~~`bevy_heavy`~~ remove for now -- [ ] ~~`bevy-trait-query`~~ remove for now +- [x] `bevy-trait-query` -> branch `bevy-0.15-rc` - [ ] ~~`bevy_common_assets`~~ remove for now - [ ] ~~`bevy_panorbit_camera`~~ remove for now - [ ] ~~`iyes_perf_ui`~~ remove for now diff --git a/src/lib.rs b/src/lib.rs index 6bc958e..6755329 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,6 @@ use bevy::{asset::AssetMetaCheck, prelude::*}; /// Re-export for convenience pub use crate::app3d::{ {ScenePlugin, InterfacePlugins}, - controls::{KeyBindingsConfig, CameraControls, DebugControls, TimeControls} }; pub struct YahsPlugin; diff --git a/src/simulator/balloon.rs b/src/simulator/balloon.rs index a789541..6a5406f 100644 --- a/src/simulator/balloon.rs +++ b/src/simulator/balloon.rs @@ -1,6 +1,6 @@ //! Properties, attributes and functions related to the balloon. -use avian3d::{math::PI, prelude::*}; +use avian3d::math::PI; use bevy::prelude::*; use super::{ diff --git a/src/simulator/forces/aero.rs b/src/simulator/forces/aero.rs index a4b3759..4e0c5ca 100644 --- a/src/simulator/forces/aero.rs +++ b/src/simulator/forces/aero.rs @@ -2,6 +2,7 @@ use avian3d::{math::PI, prelude::*}; use bevy::prelude::*; +use bevy_trait_query::{self, RegisterExt}; use super::{Atmosphere, Density, ForceUpdateOrder, Force, SimulatedBody}; @@ -10,6 +11,8 @@ pub struct AeroForcesPlugin; impl Plugin for AeroForcesPlugin { fn build(&self, app: &mut App) { app.register_type::(); + app.register_component_as::(); + app.add_systems(Update, update_drag_parameters.in_set(ForceUpdateOrder::Prepare)); } } diff --git a/src/simulator/forces/body.rs b/src/simulator/forces/body.rs index a2c63ce..9aec62d 100644 --- a/src/simulator/forces/body.rs +++ b/src/simulator/forces/body.rs @@ -2,6 +2,7 @@ use avian3d::prelude::*; use bevy::prelude::*; +use bevy_trait_query::{self, RegisterExt}; use super::{Atmosphere, Density, Force, ForceUpdateOrder, Mass, SimulatedBody, Volume}; use crate::simulator::properties::{EARTH_RADIUS_M, STANDARD_G}; @@ -13,6 +14,9 @@ impl Plugin for BodyForcesPlugin { app.register_type::(); app.register_type::(); + app.register_component_as::(); + app.register_component_as::(); + app.add_systems( Update, (update_weight_parameters, update_buoyant_parameters).in_set(ForceUpdateOrder::Prepare), diff --git a/src/simulator/forces/mod.rs b/src/simulator/forces/mod.rs index b72c431..1343f48 100644 --- a/src/simulator/forces/mod.rs +++ b/src/simulator/forces/mod.rs @@ -4,6 +4,7 @@ pub mod body; use avian3d::prelude::*; use bevy::prelude::*; +use bevy_trait_query; // Re-expert common forces #[allow(unused_imports)] @@ -34,10 +35,10 @@ impl Plugin for ForcesPlugin { Update, on_simulated_body_added.in_set(ForceUpdateOrder::First), ); - // app.add_systems( - // Update, - // update_total_external_force.in_set(ForceUpdateOrder::Apply), - // ); + app.add_systems( + Update, + update_total_external_force.in_set(ForceUpdateOrder::Apply), + ); app.add_plugins((aero::AeroForcesPlugin, body::BodyForcesPlugin)); } @@ -69,6 +70,7 @@ fn on_simulated_body_added(mut commands: Commands, query: Query String { String::from("Force") @@ -83,26 +85,26 @@ pub trait Force { fn point_of_application(&self) -> Vec3; } -// Set the `ExternalForce` to the sum of all forces in the `Forces` collection. -// This effectively applies all the calculated force vectors to the physics -// rigid body without regard to where the forces came from. -// -// TODO: preserve the position of the total force vector and apply it at that -// point instead of the center of mass. -// fn update_total_external_force( -// mut body_forces: Query<(&mut ExternalForce, &dyn Force, &RigidBody), With>, -// ) { -// // Iterate over each entity that has force vector components. -// for (mut physics_force_component, acting_forces, rigid_body) in body_forces.iter_mut() { -// // Forces only act on dynamic bodies. Don't bother with other kinds. -// if rigid_body.is_dynamic() { -// let mut net_force = Vec3::ZERO; // reset the net force to zero +/// Set the `ExternalForce` to the sum of all forces in the `Forces` collection. +/// This effectively applies all the calculated force vectors to the physics +/// rigid body without regard to where the forces came from. +/// +/// TODO: preserve the position of the total force vector and apply it at that +/// point instead of the center of mass. +fn update_total_external_force( + mut body_forces: Query<(&mut ExternalForce, &dyn Force, &RigidBody), With>, +) { + // Iterate over each entity that has force vector components. + for (mut physics_force_component, acting_forces, rigid_body) in body_forces.iter_mut() { + // Forces only act on dynamic bodies. Don't bother with other kinds. + if rigid_body.is_dynamic() { + let mut net_force = Vec3::ZERO; // reset the net force to zero -// // Iterate over each force vector component and compute its value. -// for force in acting_forces.iter() { -// net_force += force.force(); -// } -// physics_force_component.set_force(net_force); -// } -// } -// } + // Iterate over each force vector component and compute its value. + for force in acting_forces.iter() { + net_force += force.force(); + } + physics_force_component.set_force(net_force); + } + } +}