From 99facf623b4c014c7003fa92a63a707a616c3c41 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 14 Oct 2024 11:41:45 +0200 Subject: [PATCH 1/3] update --- Cargo.toml | 2 +- build/salva2d-f64/Cargo.toml | 57 ++++++++++++++++++++++ build/salva2d/Cargo.toml | 23 ++++----- build/salva3d-f64/Cargo.toml | 53 ++++++++++++++++++++ build/salva3d/Cargo.toml | 23 ++++----- examples2d/Cargo.toml | 2 +- src/integrations/rapier/fluids_pipeline.rs | 26 +++++----- src/integrations/rapier/testbed_plugin.rs | 36 +++++++------- src/lib.rs | 34 ++++++++++--- 9 files changed, 193 insertions(+), 63 deletions(-) create mode 100644 build/salva2d-f64/Cargo.toml create mode 100644 build/salva3d-f64/Cargo.toml diff --git a/Cargo.toml b/Cargo.toml index dc9065a..f9587f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["build/salva2d", "build/salva3d", "examples2d", "examples3d"] +members = ["build/salva2d", "build/salva2d-f64", "build/salva3d", "build/salva3d-f64", "examples2d", "examples3d"] resolver = "2" [profile.release] diff --git a/build/salva2d-f64/Cargo.toml b/build/salva2d-f64/Cargo.toml new file mode 100644 index 0000000..851cef2 --- /dev/null +++ b/build/salva2d-f64/Cargo.toml @@ -0,0 +1,57 @@ +[package] +name = "salva2d-f64" +version = "0.9.0" +authors = [ "Sébastien Crozet " ] +description = "2-dimensional particle-based fluid dynamics in Rust." +documentation = "https://salva.rs/docs" +homepage = "https://salva.rs" +repository = "https://github.com/dimforge/salva" +readme = "README.md" +categories = [ "science", "game-development", "mathematics", "simulation", "wasm"] +keywords = [ "physics", "dynamics", "particles", "fluids", "SPH" ] +license = "Apache-2.0" +edition = "2021" + +[badges] +maintenance = { status = "actively-developed" } + +[features] +default = [ "dim2", "f64" ] +dim2 = [ ] +f64 = [ ] +parallel = [ "rayon" ] +sampling = [ "rapier" ] +rapier = [ "parry", "rapier2d" ] +rapier-testbed = [ "rapier", "rapier_testbed2d", "graphics" ] +rapier-harness = [ "rapier-testbed" ] +parry = [ "parry2d" ] +wasm-bindgen = [ "rapier2d/wasm-bindgen" ] +graphics = [ "bevy", "bevy_egui" ] + +[lib] +name = "salva2d_f64" +path = "../../src/lib.rs" +required-features = [ "dim2", "f64" ] + +[dependencies] +approx = "0.5" +num-traits = "0.2" +fnv = "1.0" +itertools = "0.13" +generational-arena = "0.2" +instant = { version = "0.1", features = [ "now" ] } +rayon = { version = "1.8", optional = true } + +nalgebra = "0.33" +parry2d = { version = "0.16", optional = true } +rapier2d = { version = "0.21", optional = true } +rapier_testbed2d = { version = "0.21", optional = true } + +bevy_egui = { version = "0.26", features = ["immutable_ctx"], optional = true } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +bevy = { version = "0.13.2", default-features = false, features = ["bevy_winit", "bevy_render", "x11"], optional = true } + +# Dependencies for WASM only. +[target.'cfg(target_arch = "wasm32")'.dependencies] +bevy = { version = "0.13", default-features = false, features = ["bevy_winit", "bevy_render"], optional = true } diff --git a/build/salva2d/Cargo.toml b/build/salva2d/Cargo.toml index 7abc7ed..c708454 100644 --- a/build/salva2d/Cargo.toml +++ b/build/salva2d/Cargo.toml @@ -22,16 +22,17 @@ edition = "2021" maintenance = { status = "actively-developed" } [features] -default = ["dim2"] -dim2 = [] -parallel = ["rayon"] -sampling = ["rapier"] -rapier = ["parry", "rapier2d"] -rapier-testbed = ["rapier", "rapier_testbed2d", "graphics"] -rapier-harness = ["rapier-testbed"] -parry = ["parry2d"] -wasm-bindgen = ["rapier2d/wasm-bindgen"] -graphics = ["bevy", "bevy_egui"] +default = [ "dim2", "f32" ] +dim2 = [ ] +f32 = [ ] +parallel = [ "rayon" ] +sampling = [ "rapier" ] +rapier = [ "parry", "rapier2d" ] +rapier-testbed = [ "rapier", "rapier_testbed2d", "graphics" ] +rapier-harness = [ "rapier-testbed" ] +parry = [ "parry2d" ] +wasm-bindgen = [ "rapier2d/wasm-bindgen" ] +graphics = [ "bevy", "bevy_egui" ] [lints] rust.unexpected_cfgs = { level = "warn", check-cfg = [ @@ -41,7 +42,7 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [ [lib] name = "salva2d" path = "../../src/lib.rs" -required-features = ["dim2"] +required-features = [ "dim2", "f32" ] [dependencies] approx = "0.5" diff --git a/build/salva3d-f64/Cargo.toml b/build/salva3d-f64/Cargo.toml new file mode 100644 index 0000000..a46b070 --- /dev/null +++ b/build/salva3d-f64/Cargo.toml @@ -0,0 +1,53 @@ +[package] +name = "salva3d-f64" +version = "0.9.0" +authors = [ "Sébastien Crozet " ] +description = "3-dimensional particle-based fluid dynamics in Rust." +documentation = "https://salva.rs/rustdoc/salva3d/index.html" +homepage = "https://salva.rs" +repository = "https://github.com/dimforge/salva" +readme = "README.md" +keywords = [ "physics", "dynamics", "particles", "fluids", "SPH" ] +license = "Apache-2.0" +edition = "2021" + +[features] +default = [ "dim3", "f64" ] +dim3 = [ ] +f64 = [ ] +parallel = [ "rayon" ] +rapier = [ "parry", "rapier3d" ] +sampling = [ "rapier" ] +rapier-testbed = [ "rapier", "rapier_testbed3d", "graphics" ] +rapier-harness = [ "rapier-testbed" ] +parry = [ "parry3d" ] +wasm-bindgen = [ "rapier3d/wasm-bindgen" ] +graphics = [ "bevy", "bevy_egui" ] + +[lib] +name = "salva3d_f64" +path = "../../src/lib.rs" +required-features = [ "dim3", "f64" ] + +[dependencies] +approx = "0.5" +num-traits = "0.2" +fnv = "1.0" +itertools = "0.13" +generational-arena = "0.2" +instant = { version = "0.1", features = [ "now" ] } +rayon = { version = "1.8", optional = true } + +nalgebra = "0.33" +parry3d = { version = "0.16", optional = true } +rapier3d = { version = "0.21", optional = true } +rapier_testbed3d = { version = "0.21", optional = true } + +bevy_egui = { version = "0.26", features = ["immutable_ctx"], optional = true } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +bevy = { version = "0.13", default-features = false, features = ["bevy_winit", "bevy_render", "x11"], optional = true } + +# Dependencies for WASM only. +[target.'cfg(target_arch = "wasm32")'.dependencies] +bevy = { version = "0.13", default-features = false, features = ["bevy_winit", "bevy_render"], optional = true } diff --git a/build/salva3d/Cargo.toml b/build/salva3d/Cargo.toml index 1cef4b1..a8a473b 100644 --- a/build/salva3d/Cargo.toml +++ b/build/salva3d/Cargo.toml @@ -17,21 +17,22 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [ ] } [features] -default = ["dim3"] -dim3 = [] -parallel = ["rayon"] -rapier = ["parry", "rapier3d"] -sampling = ["rapier"] -rapier-testbed = ["rapier", "rapier_testbed3d", "graphics"] -rapier-harness = ["rapier-testbed"] -parry = ["parry3d"] -wasm-bindgen = ["rapier3d/wasm-bindgen"] -graphics = ["bevy", "bevy_egui"] +default = [ "dim3", "f32" ] +dim3 = [ ] +f32 = [ ] +parallel = [ "rayon" ] +rapier = [ "parry", "rapier3d" ] +sampling = [ "rapier" ] +rapier-testbed = [ "rapier", "rapier_testbed3d", "graphics" ] +rapier-harness = [ "rapier-testbed" ] +parry = [ "parry3d" ] +wasm-bindgen = [ "rapier3d/wasm-bindgen" ] +graphics = [ "bevy", "bevy_egui" ] [lib] name = "salva3d" path = "../../src/lib.rs" -required-features = ["dim3"] +required-features = [ "dim3", "f32" ] [dependencies] approx = "0.5" diff --git a/examples2d/Cargo.toml b/examples2d/Cargo.toml index ec07788..4b6450c 100644 --- a/examples2d/Cargo.toml +++ b/examples2d/Cargo.toml @@ -5,7 +5,7 @@ authors = [ "Sébastien Crozet " ] edition = "2018" [features] -default = [] +default = ["parallel"] parallel = [ "rapier_testbed2d/parallel"] [dependencies] diff --git a/src/integrations/rapier/fluids_pipeline.rs b/src/integrations/rapier/fluids_pipeline.rs index 0881c86..4965cb5 100644 --- a/src/integrations/rapier/fluids_pipeline.rs +++ b/src/integrations/rapier/fluids_pipeline.rs @@ -2,7 +2,7 @@ use crate::coupling::CouplingManager; use crate::geometry::{HGrid, HGridEntry}; use crate::object::{BoundaryHandle, BoundarySet, Fluid}; use crate::solver::DFSPHSolver; -use crate::LiquidWorld; +use crate::{math, LiquidWorld}; use crate::TimestepManager; use approx::AbsDiffEq; use na::Unit; @@ -31,7 +31,7 @@ impl FluidsPipeline { /// - `particle_radius`: the radius of every particle for the fluid simulation. /// - `smoothing_factor`: the smoothing factor used to compute the SPH kernel radius. /// The kernel radius will be computed as `particle_radius * smoothing_factor * 2.0. - pub fn new(particle_radius: f32, smoothing_factor: f32) -> Self { + pub fn new(particle_radius: math::Real, smoothing_factor: math::Real) -> Self { let dfsph: DFSPHSolver = DFSPHSolver::new(); Self { @@ -47,8 +47,8 @@ impl FluidsPipeline { /// However, it will not integrate these forces. Use the `PhysicsPipeline` for this integration. pub fn step( &mut self, - gravity: &Vector, - dt: f32, + gravity: &Vector, + dt: math::Real, colliders: &ColliderSet, bodies: &mut RigidBodySet, ) { @@ -66,7 +66,7 @@ pub enum ColliderSampling { /// /// It is recommended that those points are separated by a distance smaller or equal to twice /// the particle radius used to initialize the LiquidWorld. - StaticSampling(Vec>), + StaticSampling(Vec>), /// The collider shape is approximated by a dynamic set of points automatically computed based on contacts with fluid particles. DynamicContactSampling, } @@ -147,8 +147,8 @@ impl<'a> CouplingManager for ColliderCouplingManager<'a> { fn update_boundaries( &mut self, timestep: &TimestepManager, - h: f32, - particle_radius: f32, + h: math::Real, + particle_radius: math::Real, hgrid: &HGrid, fluids: &mut [Fluid], boundaries: &mut BoundarySet, @@ -187,11 +187,11 @@ impl<'a> CouplingManager for ColliderCouplingManager<'a> { .push(velocity.unwrap_or(Vector::zeros())); } - boundary.volumes.resize(points.len(), na::zero::()); + boundary.volumes.resize(points.len(), na::zero::()); } ColliderSampling::DynamicContactSampling => { - let prediction = h * na::convert::<_, f32>(0.5); - let margin = particle_radius * na::convert::<_, f32>(0.1); + let prediction = h * na::convert::<_, math::Real>(0.5); + let margin = particle_radius * na::convert::<_, math::Real>(0.1); let collider_pos = collider.position(); let aabb = collider .shape() @@ -218,7 +218,7 @@ impl<'a> CouplingManager for ColliderCouplingManager<'a> { let dpt = particle_pos - proj.point; if let Some((normal, depth)) = - Unit::try_new_and_get(dpt, f32::default_epsilon()) + Unit::try_new_and_get(dpt, math::Real::default_epsilon()) { if proj.is_inside { fluid.positions[*particle_id] -= @@ -227,7 +227,7 @@ impl<'a> CouplingManager for ColliderCouplingManager<'a> { let vel_err = normal.dot(&fluid.velocities[*particle_id]); - if vel_err > na::zero::() { + if vel_err > na::zero::() { fluid.velocities[*particle_id] -= *normal * vel_err; } @@ -243,7 +243,7 @@ impl<'a> CouplingManager for ColliderCouplingManager<'a> { .velocities .push(velocity.unwrap_or(Vector::zeros())); boundary.positions.push(proj.point); - boundary.volumes.push(na::zero::()); + boundary.volumes.push(na::zero::()); coupling.features.push(feature); } } diff --git a/src/integrations/rapier/testbed_plugin.rs b/src/integrations/rapier/testbed_plugin.rs index 8699dd1..4bee517 100644 --- a/src/integrations/rapier/testbed_plugin.rs +++ b/src/integrations/rapier/testbed_plugin.rs @@ -50,23 +50,23 @@ pub enum FluidsRenderingMode { /// Use a red taint the closer to `max` the velocity is. VelocityColor { /// Fluids with a velocity smaller than this will not have any red taint. - min: f32, + min: math::Real, /// Fluids with a velocity greater than this will be completely red. - max: f32, + max: math::Real, }, // /// Use a red taint the closer to `max` the velocity is, with opacity, low velocity is more transparent // VelocityColorOpacity { // /// Fluids with a velocity smaller than this will not have any red taint. - // min: f32, + // min: math::Real, // /// Fluids with a velocity greater than this will be completely red. - // max: f32, + // max: math::Real, // }, /// Show particles as arrows indicating the velocity VelocityArrows { /// Fluids with a velocity smaller than this will not have any red taint. - min: f32, + min: math::Real, /// Fluids with a velocity greater than this will be completely red. - max: f32, + max: math::Real, }, } @@ -84,9 +84,9 @@ pub struct FluidsTestbedPlugin { fluids_pipeline: FluidsPipeline, f2sn: HashMap>, boundary2sn: HashMap>, - f2color: HashMap>, - ground_color: Point3, - default_fluid_color: Point3, + f2color: HashMap>, + ground_color: Point3, + default_fluid_color: Point3, queue_graphics_reset: bool, } @@ -120,7 +120,7 @@ impl FluidsTestbedPlugin { } /// Sets the color used to render the specified fluid. - pub fn set_fluid_color(&mut self, fluid: FluidHandle, color: Point3) { + pub fn set_fluid_color(&mut self, fluid: FluidHandle, color: Point3) { let _ = self.f2color.insert(fluid, color); } @@ -138,14 +138,14 @@ impl FluidsTestbedPlugin { fn add_particle_graphics( &self, particle: &Point, - particle_radius: f32, + particle_radius: math::Real, graphics: &mut GraphicsManager, commands: &mut Commands, meshes: &mut Assets, materials: &mut Assets, _components: &mut Query<&mut Transform>, _harness: &mut Harness, - color: &Point3, + color: &Point3, force_shape: Option, ) -> Vec { let shape = if let Some(shape) = force_shape { @@ -186,11 +186,11 @@ impl FluidsTestbedPlugin { } fn lerp_velocity( - velocity: Vector, - start: Vector3, - min: f32, - max: f32, - ) -> Vector3 { + velocity: Vector, + start: Vector3, + min: math::Real, + max: math::Real, + ) -> Vector3 { let end = Vector3::new(1.0, 0.0, 0.0); let vel: Vector = na::convert_unchecked(velocity); let vel: Vector = na::convert(vel); @@ -357,7 +357,7 @@ impl TestbedPlugin for FluidsTestbedPlugin { self.queue_graphics_reset = false; } - let (mut min, mut max) = (f32::MAX, f32::MIN); + let (mut min, mut max) = (math::Real::MAX, math::Real::MIN); for (handle, fluid) in self.fluids_pipeline.liquid_world.fluids().iter() { if let Some(entities) = self.f2sn.get_mut(&handle) { for (idx, particle) in fluid.positions.iter().enumerate() { diff --git a/src/lib.rs b/src/lib.rs index 650ee92..bf24254 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,18 +37,30 @@ The name of this library is inspired from the famous surrealist artist `Salvador extern crate nalgebra as na; extern crate num_traits as num; -#[cfg(all(feature = "dim2", feature = "parry"))] +#[cfg(all(feature = "dim2", feature = "f32"))] pub extern crate parry2d as parry; -#[cfg(all(feature = "dim3", feature = "parry"))] +#[cfg(all(feature = "dim2", feature = "f64"))] +pub extern crate parry2d_f64 as parry; +#[cfg(all(feature = "dim3", feature = "f32"))] pub extern crate parry3d as parry; -#[cfg(all(feature = "dim2", feature = "rapier"))] +#[cfg(all(feature = "dim3", feature = "f64"))] +pub extern crate parry3d_f64 as parry; +#[cfg(all(feature = "dim2", feature = "f32"))] pub extern crate rapier2d as rapier; -#[cfg(all(feature = "dim3", feature = "rapier"))] +#[cfg(all(feature = "dim2", feature = "f64"))] +pub extern crate rapier2d_f64 as rapier; +#[cfg(all(feature = "dim3", feature = "f32"))] pub extern crate rapier3d as rapier; -#[cfg(all(feature = "dim2", feature = "rapier-testbed"))] -extern crate rapier_testbed2d as rapier_testbed; -#[cfg(all(feature = "dim3", feature = "rapier-testbed"))] -extern crate rapier_testbed3d as rapier_testbed; +#[cfg(all(feature = "dim3", feature = "f64"))] +pub extern crate rapier3d_f64 as rapier; +#[cfg(all(feature = "dim2", feature = "f32", feature = "rapier-testbed"))] +pub extern crate rapier_testbed2d as rapier_testbed; +#[cfg(all(feature = "dim2", feature = "f64", feature = "rapier-testbed"))] +pub extern crate rapier_testbed2d_f64 as rapier_testbed; +#[cfg(all(feature = "dim3", feature = "f32", feature = "rapier-testbed"))] +pub extern crate rapier_testbed3d as rapier_testbed; +#[cfg(all(feature = "dim3", feature = "f64", feature = "rapier-testbed"))] +pub extern crate rapier_testbed3d_f64 as rapier_testbed; macro_rules! par_iter { ($t: expr) => {{ @@ -115,7 +127,10 @@ pub mod math { pub const DIM: usize = 3; /// The scalar type. + #[cfg(all(feature = "f32"))] pub type Real = f32; + #[cfg(all(feature = "f64"))] + pub type Real = f64; /// The dimension of the ambient space. pub type Dim = U3; @@ -196,7 +211,10 @@ pub mod math { pub const DIM: usize = 2; /// The scalar type. + #[cfg(all(feature = "f32"))] pub type Real = f32; + #[cfg(all(feature = "f64"))] + pub type Real = f64; /// The dimension of the ambient space. pub type Dim = U2; From 564578b57c988c6b27ba946e476368fb230946f0 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 14 Oct 2024 12:19:48 +0200 Subject: [PATCH 2/3] typo --- build/salva2d-f64/Cargo.toml | 4 ++-- build/salva3d-f64/Cargo.toml | 4 ++-- build/salva3d/Cargo.toml | 2 +- examples3d/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build/salva2d-f64/Cargo.toml b/build/salva2d-f64/Cargo.toml index 851cef2..1fee1fd 100644 --- a/build/salva2d-f64/Cargo.toml +++ b/build/salva2d-f64/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "salva2d-f64" +name = "salva2d-f64" version = "0.9.0" authors = [ "Sébastien Crozet " ] description = "2-dimensional particle-based fluid dynamics in Rust." @@ -17,7 +17,7 @@ maintenance = { status = "actively-developed" } [features] default = [ "dim2", "f64" ] -dim2 = [ ] +dim2 = [ ] f64 = [ ] parallel = [ "rayon" ] sampling = [ "rapier" ] diff --git a/build/salva3d-f64/Cargo.toml b/build/salva3d-f64/Cargo.toml index a46b070..eb8f73c 100644 --- a/build/salva3d-f64/Cargo.toml +++ b/build/salva3d-f64/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "salva3d-f64" +name = "salva3d-f64" version = "0.9.0" authors = [ "Sébastien Crozet " ] description = "3-dimensional particle-based fluid dynamics in Rust." @@ -13,7 +13,7 @@ edition = "2021" [features] default = [ "dim3", "f64" ] -dim3 = [ ] +dim3 = [ ] f64 = [ ] parallel = [ "rayon" ] rapier = [ "parry", "rapier3d" ] diff --git a/build/salva3d/Cargo.toml b/build/salva3d/Cargo.toml index a8a473b..572a995 100644 --- a/build/salva3d/Cargo.toml +++ b/build/salva3d/Cargo.toml @@ -18,7 +18,7 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [ [features] default = [ "dim3", "f32" ] -dim3 = [ ] +dim3 = [ ] f32 = [ ] parallel = [ "rayon" ] rapier = [ "parry", "rapier3d" ] diff --git a/examples3d/Cargo.toml b/examples3d/Cargo.toml index cd71aeb..239e995 100644 --- a/examples3d/Cargo.toml +++ b/examples3d/Cargo.toml @@ -11,7 +11,7 @@ parallel = [ "rapier_testbed3d/parallel", "salva3d/parallel"] [dependencies] num-traits = "0.2" Inflector = "0.11" -nalgebra = "0.33" +nalgebra = "0.33" rapier3d = "0.21" rapier_testbed3d = "0.21" parry3d = "0.16" From 99fde0e9df3507eded76cd8626c3e9adec1f7d46 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 14 Oct 2024 15:15:39 +0200 Subject: [PATCH 3/3] fix typo --- .gitignore | 1 + Cargo.toml | 2 ++ build/salva2d-f64/Cargo.toml | 16 ++++++---- build/salva2d/Cargo.toml | 2 +- build/salva3d-f64/Cargo.toml | 16 ++++++---- build/salva3d/Cargo.toml | 2 +- src/integrations/rapier/testbed_plugin.rs | 36 +++++++++++------------ src/lib.rs | 22 +++++++------- 8 files changed, 57 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 35e928c..25a5911 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ STYLE.md Cargo.lock .idea .vscode +.DS_Store \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index f9587f8..7cbc036 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,9 @@ opt-level = 1 [patch.crates-io] salva2d = { path = "./build/salva2d" } +salva2d-f64 = { path = "./build/salva2d-f64" } salva3d = { path = "./build/salva3d" } +salva3d-f64 = { path = "./build/salva3d-f64" } #parry2d = { git = "https://github.com/sebcrozet/parry" } #parry3d = { git = "https://github.com/sebcrozet/parry" } diff --git a/build/salva2d-f64/Cargo.toml b/build/salva2d-f64/Cargo.toml index 1fee1fd..537751d 100644 --- a/build/salva2d-f64/Cargo.toml +++ b/build/salva2d-f64/Cargo.toml @@ -21,13 +21,18 @@ dim2 = [ ] f64 = [ ] parallel = [ "rayon" ] sampling = [ "rapier" ] -rapier = [ "parry", "rapier2d" ] +rapier = [ "parry", "rapier2d-f64" ] rapier-testbed = [ "rapier", "rapier_testbed2d", "graphics" ] rapier-harness = [ "rapier-testbed" ] -parry = [ "parry2d" ] -wasm-bindgen = [ "rapier2d/wasm-bindgen" ] +parry = [ "parry2d-f64" ] +wasm-bindgen = [ "rapier2d-f64/wasm-bindgen" ] graphics = [ "bevy", "bevy_egui" ] +[lints] +rust.unexpected_cfgs = { level = "warn", check-cfg = [ + 'cfg(feature, values("dim3", "f32"))', +] } + [lib] name = "salva2d_f64" path = "../../src/lib.rs" @@ -43,8 +48,9 @@ instant = { version = "0.1", features = [ "now" ] } rayon = { version = "1.8", optional = true } nalgebra = "0.33" -parry2d = { version = "0.16", optional = true } -rapier2d = { version = "0.21", optional = true } +parry2d-f64 = { version = "0.16", optional = true } +rapier2d-f64 = { version = "0.21", optional = true } +# TODO update it to f64 rapier_testbed2d = { version = "0.21", optional = true } bevy_egui = { version = "0.26", features = ["immutable_ctx"], optional = true } diff --git a/build/salva2d/Cargo.toml b/build/salva2d/Cargo.toml index c708454..3db9dae 100644 --- a/build/salva2d/Cargo.toml +++ b/build/salva2d/Cargo.toml @@ -36,7 +36,7 @@ graphics = [ "bevy", "bevy_egui" ] [lints] rust.unexpected_cfgs = { level = "warn", check-cfg = [ - 'cfg(feature, values("dim3"))', + 'cfg(feature, values("dim3", "f64"))', ] } [lib] diff --git a/build/salva3d-f64/Cargo.toml b/build/salva3d-f64/Cargo.toml index eb8f73c..910a6e5 100644 --- a/build/salva3d-f64/Cargo.toml +++ b/build/salva3d-f64/Cargo.toml @@ -16,14 +16,19 @@ default = [ "dim3", "f64" ] dim3 = [ ] f64 = [ ] parallel = [ "rayon" ] -rapier = [ "parry", "rapier3d" ] +rapier = [ "parry", "rapier3d-f64" ] sampling = [ "rapier" ] rapier-testbed = [ "rapier", "rapier_testbed3d", "graphics" ] rapier-harness = [ "rapier-testbed" ] -parry = [ "parry3d" ] -wasm-bindgen = [ "rapier3d/wasm-bindgen" ] +parry = [ "parry3d-f64" ] +wasm-bindgen = [ "rapier3d-f64/wasm-bindgen" ] graphics = [ "bevy", "bevy_egui" ] +[lints] +rust.unexpected_cfgs = { level = "warn", check-cfg = [ + 'cfg(feature, values("dim2", "f32"))', +] } + [lib] name = "salva3d_f64" path = "../../src/lib.rs" @@ -39,8 +44,9 @@ instant = { version = "0.1", features = [ "now" ] } rayon = { version = "1.8", optional = true } nalgebra = "0.33" -parry3d = { version = "0.16", optional = true } -rapier3d = { version = "0.21", optional = true } +parry3d-f64 = { version = "0.16", optional = true } +rapier3d-f64 = { version = "0.21", optional = true } +# TODO update it to f64 rapier_testbed3d = { version = "0.21", optional = true } bevy_egui = { version = "0.26", features = ["immutable_ctx"], optional = true } diff --git a/build/salva3d/Cargo.toml b/build/salva3d/Cargo.toml index 572a995..089c106 100644 --- a/build/salva3d/Cargo.toml +++ b/build/salva3d/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" [lints] rust.unexpected_cfgs = { level = "warn", check-cfg = [ - 'cfg(feature, values("dim2"))', + 'cfg(feature, values("dim2", "f64"))', ] } [features] diff --git a/src/integrations/rapier/testbed_plugin.rs b/src/integrations/rapier/testbed_plugin.rs index 4bee517..0e7be72 100644 --- a/src/integrations/rapier/testbed_plugin.rs +++ b/src/integrations/rapier/testbed_plugin.rs @@ -50,23 +50,23 @@ pub enum FluidsRenderingMode { /// Use a red taint the closer to `max` the velocity is. VelocityColor { /// Fluids with a velocity smaller than this will not have any red taint. - min: math::Real, + min: Real, /// Fluids with a velocity greater than this will be completely red. - max: math::Real, + max: Real, }, // /// Use a red taint the closer to `max` the velocity is, with opacity, low velocity is more transparent // VelocityColorOpacity { // /// Fluids with a velocity smaller than this will not have any red taint. - // min: math::Real, + // min: Real, // /// Fluids with a velocity greater than this will be completely red. - // max: math::Real, + // max: Real, // }, /// Show particles as arrows indicating the velocity VelocityArrows { /// Fluids with a velocity smaller than this will not have any red taint. - min: math::Real, + min: Real, /// Fluids with a velocity greater than this will be completely red. - max: math::Real, + max: Real, }, } @@ -84,9 +84,9 @@ pub struct FluidsTestbedPlugin { fluids_pipeline: FluidsPipeline, f2sn: HashMap>, boundary2sn: HashMap>, - f2color: HashMap>, - ground_color: Point3, - default_fluid_color: Point3, + f2color: HashMap>, + ground_color: Point3, + default_fluid_color: Point3, queue_graphics_reset: bool, } @@ -120,7 +120,7 @@ impl FluidsTestbedPlugin { } /// Sets the color used to render the specified fluid. - pub fn set_fluid_color(&mut self, fluid: FluidHandle, color: Point3) { + pub fn set_fluid_color(&mut self, fluid: FluidHandle, color: Point3) { let _ = self.f2color.insert(fluid, color); } @@ -138,14 +138,14 @@ impl FluidsTestbedPlugin { fn add_particle_graphics( &self, particle: &Point, - particle_radius: math::Real, + particle_radius: Real, graphics: &mut GraphicsManager, commands: &mut Commands, meshes: &mut Assets, materials: &mut Assets, _components: &mut Query<&mut Transform>, _harness: &mut Harness, - color: &Point3, + color: &Point3, force_shape: Option, ) -> Vec { let shape = if let Some(shape) = force_shape { @@ -186,11 +186,11 @@ impl FluidsTestbedPlugin { } fn lerp_velocity( - velocity: Vector, - start: Vector3, - min: math::Real, - max: math::Real, - ) -> Vector3 { + velocity: Vector, + start: Vector3, + min: Real, + max: Real, + ) -> Vector3 { let end = Vector3::new(1.0, 0.0, 0.0); let vel: Vector = na::convert_unchecked(velocity); let vel: Vector = na::convert(vel); @@ -357,7 +357,7 @@ impl TestbedPlugin for FluidsTestbedPlugin { self.queue_graphics_reset = false; } - let (mut min, mut max) = (math::Real::MAX, math::Real::MIN); + let (mut min, mut max) = (Real::MAX, Real::MIN); for (handle, fluid) in self.fluids_pipeline.liquid_world.fluids().iter() { if let Some(entities) = self.f2sn.get_mut(&handle) { for (idx, particle) in fluid.positions.iter().enumerate() { diff --git a/src/lib.rs b/src/lib.rs index bf24254..e04306c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,21 +37,21 @@ The name of this library is inspired from the famous surrealist artist `Salvador extern crate nalgebra as na; extern crate num_traits as num; -#[cfg(all(feature = "dim2", feature = "f32"))] +#[cfg(all(feature = "dim2", feature = "f32", feature = "parry"))] pub extern crate parry2d as parry; -#[cfg(all(feature = "dim2", feature = "f64"))] +#[cfg(all(feature = "dim2", feature = "f64", feature = "parry"))] pub extern crate parry2d_f64 as parry; -#[cfg(all(feature = "dim3", feature = "f32"))] +#[cfg(all(feature = "dim3", feature = "f32", feature = "parry"))] pub extern crate parry3d as parry; -#[cfg(all(feature = "dim3", feature = "f64"))] +#[cfg(all(feature = "dim3", feature = "f64", feature = "parry"))] pub extern crate parry3d_f64 as parry; -#[cfg(all(feature = "dim2", feature = "f32"))] +#[cfg(all(feature = "dim2", feature = "f32", feature = "rapier"))] pub extern crate rapier2d as rapier; -#[cfg(all(feature = "dim2", feature = "f64"))] +#[cfg(all(feature = "dim2", feature = "f64", feature = "rapier"))] pub extern crate rapier2d_f64 as rapier; -#[cfg(all(feature = "dim3", feature = "f32"))] +#[cfg(all(feature = "dim3", feature = "f32", feature = "rapier"))] pub extern crate rapier3d as rapier; -#[cfg(all(feature = "dim3", feature = "f64"))] +#[cfg(all(feature = "dim3", feature = "f64", feature = "rapier"))] pub extern crate rapier3d_f64 as rapier; #[cfg(all(feature = "dim2", feature = "f32", feature = "rapier-testbed"))] pub extern crate rapier_testbed2d as rapier_testbed; @@ -126,10 +126,11 @@ pub mod math { /// The maximum number of possible translations of a rigid body. pub const DIM: usize = 3; - /// The scalar type. #[cfg(all(feature = "f32"))] + /// The scalar type. pub type Real = f32; #[cfg(all(feature = "f64"))] + /// The scalar type. pub type Real = f64; /// The dimension of the ambient space. @@ -210,10 +211,11 @@ pub mod math { /// The maximum number of possible translations of a rigid body. pub const DIM: usize = 2; - /// The scalar type. #[cfg(all(feature = "f32"))] + /// The scalar type. pub type Real = f32; #[cfg(all(feature = "f64"))] + /// The scalar type. pub type Real = f64; /// The dimension of the ambient space.