From 53e9371150945ba6fa4913cc3482cf7bef635175 Mon Sep 17 00:00:00 2001 From: Manuel Brea Date: Tue, 9 Jul 2024 17:51:46 +0100 Subject: [PATCH] Migrate from bevy_xpbd to avian physics --- Cargo.lock | 66 ++++++++++++++++--------------- Cargo.toml | 12 +++--- examples/collision.rs | 2 +- examples/pbr.rs | 10 ++--- examples/sparks.rs | 4 +- examples/stress_test.rs | 3 +- examples/stress_test_collision.rs | 4 +- src/core.rs | 24 +++++------ src/plugin.rs | 4 +- 9 files changed, 66 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e5535c2..b53a7b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -283,6 +283,37 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +[[package]] +name = "avian3d" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a8da53296a1bc166b84f99aa7c6b9d8c10c71f0c022bc4fc72dd1fc49323b29" +dependencies = [ + "avian_derive", + "bevy", + "bevy_math", + "bitflags 2.5.0", + "derive_more", + "fxhash", + "indexmap", + "itertools 0.13.0", + "nalgebra", + "parry3d", + "parry3d-f64", + "serde", +] + +[[package]] +name = "avian_derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4adeeecb6d4628d3ca11836ce9af8309f9552d4bd3e3f6e4368440d8163260c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.55", +] + [[package]] name = "base64" version = "0.21.7" @@ -554,11 +585,11 @@ dependencies = [ [[package]] name = "bevy_firework" -version = "0.3.0" +version = "0.4.0" dependencies = [ + "avian3d", "bevy", "bevy_utilitarian", - "bevy_xpbd_3d", "bytemuck", "rand", "serde", @@ -1064,6 +1095,8 @@ dependencies = [ [[package]] name = "bevy_utilitarian" version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "292cf28c0b4dc1de6cf1406359987be1c8ce6eabd5193044e7d2383f18276e2a" dependencies = [ "bevy", "rand", @@ -1142,35 +1175,6 @@ dependencies = [ "winit", ] -[[package]] -name = "bevy_xpbd_3d" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9983ceba069c9fe1bc8600ef5664e628b16d0db9aaf947bf864ca19bc32c63f1" -dependencies = [ - "bevy", - "bevy_math", - "bevy_xpbd_derive", - "derive_more", - "fxhash", - "indexmap", - "itertools 0.13.0", - "nalgebra", - "parry3d", - "parry3d-f64", - "serde", -] - -[[package]] -name = "bevy_xpbd_derive" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e1ef1d5e328abe1b76df974245f78e17fd17867583883d5e77444c6a8223a64" -dependencies = [ - "quote", - "syn 2.0.55", -] - [[package]] name = "bindgen" version = "0.69.4" diff --git a/Cargo.toml b/Cargo.toml index aadb2e8..eb0dcd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,21 +14,21 @@ bevy = "0.14" bytemuck = "1.14.3" rand = "0.8.5" bevy_utilitarian = { version = "0.5" } -bevy_xpbd_3d = { version = "0.5", features = ["serialize"], optional = true } +avian3d = { version = "0.1", features = ["serialize"], optional = true } serde = { version = "1.0", features = ["derive"] } [features] -default = ["physics_xpbd"] -physics_xpbd = ["dep:bevy_xpbd_3d"] +default = ["physics_avian"] +physics_avian = ["dep:avian3d"] [[example]] name = "collision" -required-features = ["physics_xpbd"] +required-features = ["physics_avian"] [[example]] name = "stress_test" -required-features = ["physics_xpbd"] +required-features = ["physics_avian"] [[example]] name = "stress_test_collision" -required-features = ["physics_xpbd"] +required-features = ["physics_avian"] diff --git a/examples/collision.rs b/examples/collision.rs index b015b53..0ce4ee4 100644 --- a/examples/collision.rs +++ b/examples/collision.rs @@ -1,3 +1,4 @@ +use avian3d::prelude::*; use bevy::{core_pipeline::bloom::BloomSettings, prelude::*}; use bevy_firework::{ core::{BlendMode, ParticleCollisionSettings, ParticleSpawnerBundle, ParticleSpawnerSettings}, @@ -5,7 +6,6 @@ use bevy_firework::{ plugin::ParticleSystemPlugin, }; use bevy_utilitarian::prelude::*; -use bevy_xpbd_3d::prelude::*; use std::f32::consts::PI; fn main() { diff --git a/examples/pbr.rs b/examples/pbr.rs index e59d5f1..95f55c9 100644 --- a/examples/pbr.rs +++ b/examples/pbr.rs @@ -23,8 +23,8 @@ fn main() { app.add_plugins(ParticleSystemPlugin) .add_systems(Startup, setup) .add_systems(Update, (adjust_time_scale, rotate_point_light)); - #[cfg(feature = "physics_xpbd")] - app.add_plugins(bevy_xpbd_3d::prelude::PhysicsPlugins::default()); + #[cfg(feature = "physics_avian")] + app.add_plugins(avian3d::prelude::PhysicsPlugins::default()); app.run(); } @@ -63,10 +63,10 @@ fn setup( .spawn(ParticleSpawnerBundle::from_settings( ParticleSpawnerSettings { one_shot: false, - rate: 80.0, + rate: 150.0, emission_shape: EmissionShape::Circle { normal: Vec3::Y, - radius: 2.0, + radius: 3.5, }, lifetime: RandF32::constant(5.), inherit_parent_velocity: true, @@ -75,7 +75,7 @@ fn setup( scale_curve: ParamCurve::linear_uniform(vec![1., 2.]), color: Gradient::linear(vec![ (0., LinearRgba::new(0.6, 0.3, 0., 0.)), - (0.1, LinearRgba::new(0.6, 0.3, 0., 0.5)), + (0.1, LinearRgba::new(0.6, 0.3, 0., 0.35)), (1., LinearRgba::new(0.6, 0.3, 0., 0.0)), ]), blend_mode: BlendMode::Blend, diff --git a/examples/sparks.rs b/examples/sparks.rs index 2c4a42a..c3745a5 100644 --- a/examples/sparks.rs +++ b/examples/sparks.rs @@ -22,8 +22,8 @@ fn main() { .add_systems(Startup, setup) .add_systems(Update, adjust_time_scale); - #[cfg(feature = "physics_xpbd")] - app.add_plugins(bevy_xpbd_3d::prelude::PhysicsPlugins::default()); + #[cfg(feature = "physics_avian")] + app.add_plugins(avian3d::prelude::PhysicsPlugins::default()); app.run(); } diff --git a/examples/stress_test.rs b/examples/stress_test.rs index 3c189c9..f9d8134 100644 --- a/examples/stress_test.rs +++ b/examples/stress_test.rs @@ -1,3 +1,5 @@ +use avian3d::PhysicsPlugins; +// use avian3d::plugins::PhysicsPlugins; use bevy::{ core_pipeline::bloom::BloomSettings, diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, @@ -9,7 +11,6 @@ use bevy_firework::{ plugin::ParticleSystemPlugin, }; use bevy_utilitarian::prelude::*; -use bevy_xpbd_3d::plugins::PhysicsPlugins; use std::f32::consts::PI; fn main() { diff --git a/examples/stress_test_collision.rs b/examples/stress_test_collision.rs index 8ed7656..64cd08b 100644 --- a/examples/stress_test_collision.rs +++ b/examples/stress_test_collision.rs @@ -1,3 +1,4 @@ +use avian3d::{collision::Collider, spatial_query::SpatialQueryFilter, PhysicsPlugins}; use bevy::{ core_pipeline::bloom::BloomSettings, diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, @@ -12,9 +13,6 @@ use bevy_firework::{ plugin::ParticleSystemPlugin, }; use bevy_utilitarian::prelude::*; -use bevy_xpbd_3d::plugins::{ - collision::Collider, spatial_query::SpatialQueryFilter, PhysicsPlugins, -}; use std::f32::consts::PI; fn main() { diff --git a/src/core.rs b/src/core.rs index d049cb7..0520bc7 100644 --- a/src/core.rs +++ b/src/core.rs @@ -4,8 +4,8 @@ use bevy_utilitarian::prelude::*; use serde::{Deserialize, Serialize}; use std::time::Duration; -#[cfg(feature = "physics_xpbd")] -use bevy_xpbd_3d::prelude::*; +#[cfg(feature = "physics_avian")] +use avian3d::prelude::*; pub const DEFAULT_MESH: Handle = Handle::weak_from_u128(164408926256276437310893021157813788765); @@ -81,7 +81,7 @@ pub struct ParticleSpawnerSettings { pub blend_mode: BlendMode, /// Whether to use the PBR pipeline for the particle pub pbr: bool, - #[cfg(feature = "physics_xpbd")] + #[cfg(feature = "physics_avian")] /// If Some, particles will collide with the scene according to the provided parameters /// If None, no particle collision will occur. pub collision_settings: Option, @@ -106,7 +106,7 @@ impl Default for ParticleSpawnerSettings { blend_mode: BlendMode::Blend, linear_drag: 0., pbr: false, - #[cfg(feature = "physics_xpbd")] + #[cfg(feature = "physics_avian")] collision_settings: None, fade_edge: 0.7, fade_scene: 1., @@ -115,7 +115,7 @@ impl Default for ParticleSpawnerSettings { } } -#[cfg(feature = "physics_xpbd")] +#[cfg(feature = "physics_avian")] #[derive(Reflect, Clone, Serialize, Deserialize)] pub struct ParticleCollisionSettings { pub restitution: f32, @@ -124,7 +124,7 @@ pub struct ParticleCollisionSettings { pub filter: SpatialQueryFilter, } -#[cfg(feature = "physics_xpbd")] +#[cfg(feature = "physics_avian")] impl std::fmt::Debug for ParticleCollisionSettings { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!( @@ -294,7 +294,7 @@ pub fn spawn_particles( pub fn update_particles( mut particle_systems_query: Query<(&ParticleSpawnerSettings, &mut ParticleSpawnerData)>, time: Res