From ec14e946b8c1299da1fc21beed6035c3300956e9 Mon Sep 17 00:00:00 2001 From: irate Date: Mon, 8 Jan 2024 23:58:45 +0100 Subject: [PATCH] Update `glam`, `encase` and `hexasphere` (#11082) Update to `glam` 0.25, `encase` 0.7 and `hexasphere` to 10.0 ## Changelog Added the `FloatExt` trait to the `bevy_math` prelude which adds `lerp`, `inverse_lerp` and `remap` methods to the `f32` and `f64` types. --- benches/Cargo.toml | 2 +- crates/bevy_animation/src/lib.rs | 8 ++++---- crates/bevy_math/Cargo.toml | 2 +- crates/bevy_math/src/lib.rs | 4 ++-- crates/bevy_mikktspace/Cargo.toml | 2 +- crates/bevy_reflect/Cargo.toml | 2 +- crates/bevy_render/Cargo.toml | 4 ++-- examples/3d/parallax_mapping.rs | 3 +-- examples/ui/ui_scaling.rs | 4 ++-- 9 files changed, 15 insertions(+), 16 deletions(-) diff --git a/benches/Cargo.toml b/benches/Cargo.toml index b78352a55d..7afdde7e20 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -7,7 +7,7 @@ publish = false license = "MIT OR Apache-2.0" [dev-dependencies] -glam = "0.24.1" +glam = "0.25" rand = "0.8" rand_chacha = "0.3" criterion = { version = "0.3", features = ["html_reports"] } diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index 2b25f89e09..f3fe022035 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -10,7 +10,7 @@ use bevy_asset::{Asset, AssetApp, Assets, Handle}; use bevy_core::Name; use bevy_ecs::prelude::*; use bevy_hierarchy::{Children, Parent}; -use bevy_math::{Quat, Vec3}; +use bevy_math::{FloatExt, Quat, Vec3}; use bevy_reflect::Reflect; use bevy_render::mesh::morph::MorphWeights; use bevy_time::Time; @@ -593,7 +593,7 @@ fn run_animation_player( fn lerp_morph_weights(weights: &mut [f32], keyframe: impl Iterator, key_lerp: f32) { let zipped = weights.iter_mut().zip(keyframe); for (morph_weight, keyframe) in zipped { - *morph_weight += (keyframe - *morph_weight) * key_lerp; + *morph_weight = morph_weight.lerp(keyframe, key_lerp); } } @@ -721,7 +721,7 @@ fn apply_animation( }; let ts_start = curve.keyframe_timestamps[step_start]; let ts_end = curve.keyframe_timestamps[step_start + 1]; - let lerp = (animation.seek_time - ts_start) / (ts_end - ts_start); + let lerp = f32::inverse_lerp(ts_start, ts_end, animation.seek_time); apply_keyframe( curve, @@ -844,7 +844,7 @@ fn apply_keyframe( let result = morph_start .iter() .zip(morph_end) - .map(|(a, b)| *a + lerp * (*b - *a)); + .map(|(a, b)| a.lerp(*b, lerp)); lerp_morph_weights(morphs.weights_mut(), result, weight); } } diff --git a/crates/bevy_math/Cargo.toml b/crates/bevy_math/Cargo.toml index 832a1fca69..48b7959d48 100644 --- a/crates/bevy_math/Cargo.toml +++ b/crates/bevy_math/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0" keywords = ["bevy"] [dependencies] -glam = { version = "0.24.1", features = ["bytemuck"] } +glam = { version = "0.25", features = ["bytemuck"] } serde = { version = "1", features = ["derive"], optional = true } [features] diff --git a/crates/bevy_math/src/lib.rs b/crates/bevy_math/src/lib.rs index c6fb416d7e..7444a0f346 100644 --- a/crates/bevy_math/src/lib.rs +++ b/crates/bevy_math/src/lib.rs @@ -26,8 +26,8 @@ pub mod prelude { CubicBSpline, CubicBezier, CubicCardinalSpline, CubicGenerator, CubicHermite, CubicSegment, }, - primitives, BVec2, BVec3, BVec4, EulerRot, IRect, IVec2, IVec3, IVec4, Mat2, Mat3, Mat4, - Quat, Ray2d, Ray3d, Rect, URect, UVec2, UVec3, UVec4, Vec2, Vec2Swizzles, Vec3, + primitives, BVec2, BVec3, BVec4, EulerRot, FloatExt, IRect, IVec2, IVec3, IVec4, Mat2, + Mat3, Mat4, Quat, Ray2d, Ray3d, Rect, URect, UVec2, UVec3, UVec4, Vec2, Vec2Swizzles, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles, }; } diff --git a/crates/bevy_mikktspace/Cargo.toml b/crates/bevy_mikktspace/Cargo.toml index 451e4e24a0..03ff2c30e6 100644 --- a/crates/bevy_mikktspace/Cargo.toml +++ b/crates/bevy_mikktspace/Cargo.toml @@ -15,7 +15,7 @@ license = "Zlib AND (MIT OR Apache-2.0)" keywords = ["bevy", "3D", "graphics", "algorithm", "tangent"] [dependencies] -glam = "0.24.1" +glam = "0.25" [[example]] name = "generate" diff --git a/crates/bevy_reflect/Cargo.toml b/crates/bevy_reflect/Cargo.toml index 0b3be900d2..16d2eef4c2 100644 --- a/crates/bevy_reflect/Cargo.toml +++ b/crates/bevy_reflect/Cargo.toml @@ -32,7 +32,7 @@ downcast-rs = "1.2" thiserror = "1.0" serde = "1" -glam = { version = "0.24.1", features = ["serde"], optional = true } +glam = { version = "0.25", features = ["serde"], optional = true } smol_str = { version = "0.2.0", optional = true } [dev-dependencies] diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 110aae2df0..2e95d840d5 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -77,7 +77,7 @@ downcast-rs = "1.2.0" thread_local = "1.1" thiserror = "1.0" futures-lite = "2.0.1" -hexasphere = "9.0" +hexasphere = "10.0" ddsfile = { version = "0.5.0", optional = true } ktx2 = { version = "0.3.0", optional = true } # For ktx2 supercompression @@ -85,7 +85,7 @@ flate2 = { version = "1.0.22", optional = true } ruzstd = { version = "0.4.0", optional = true } # For transcoding of UASTC/ETC1S universal formats, and for .basis file support basis-universal = { version = "0.3.0", optional = true } -encase = { version = "0.6.1", features = ["glam"] } +encase = { version = "0.7", features = ["glam"] } # For wgpu profiling using tracing. Use `RUST_LOG=info` to also capture the wgpu spans. profiling = { version = "1", features = [ "profile-with-tracing", diff --git a/examples/3d/parallax_mapping.rs b/examples/3d/parallax_mapping.rs index 0e1ab2be02..15189b19de 100644 --- a/examples/3d/parallax_mapping.rs +++ b/examples/3d/parallax_mapping.rs @@ -99,8 +99,7 @@ fn update_parallax_depth_scale( let mut text = text.single_mut(); for (_, mat) in materials.iter_mut() { let current_depth = mat.parallax_depth_scale; - let new_depth = - current_depth * (1.0 - DEPTH_CHANGE_RATE) + (target_depth.0 * DEPTH_CHANGE_RATE); + let new_depth = current_depth.lerp(target_depth.0, DEPTH_CHANGE_RATE); mat.parallax_depth_scale = new_depth; text.sections[0].value = format!("Parallax depth scale: {new_depth:.5}\n"); if (new_depth - current_depth).abs() <= 0.000000001 { diff --git a/examples/ui/ui_scaling.rs b/examples/ui/ui_scaling.rs index 3d812bed24..9c1beccbcd 100644 --- a/examples/ui/ui_scaling.rs +++ b/examples/ui/ui_scaling.rs @@ -113,8 +113,8 @@ impl TargetScale { fn current_scale(&self) -> f32 { let completion = self.target_time.fraction(); - let multiplier = ease_in_expo(completion); - self.start_scale + (self.target_scale - self.start_scale) * multiplier + let t = ease_in_expo(completion); + self.start_scale.lerp(self.target_scale, t) } fn tick(&mut self, delta: Duration) -> &Self {