From 543752a13cf81f06391942f833084e07b75477c1 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Thu, 13 Nov 2025 23:13:45 -0500 Subject: [PATCH 1/2] Allow water height to transition when modified --- Cargo.toml | 2 ++ src/water.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8ad6b2f..9b26321 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,6 +57,7 @@ webgpu = ["bevy/webgpu"] [dependencies] anyhow = "1.0" +derive_more = { version = "1.0", features = ["debug"] } bevy = { version = "0.17.0", default-features = false, features = [ "bevy_asset", @@ -64,6 +65,7 @@ bevy = { version = "0.17.0", default-features = false, features = [ "bevy_pbr", "bevy_log", ] } +bevy_easings = "0.17.1" [dev-dependencies] bevy = { version = "0.17.0", features = [ diff --git a/src/water.rs b/src/water.rs index f025c9d..76dbe00 100644 --- a/src/water.rs +++ b/src/water.rs @@ -1,6 +1,11 @@ +use std::time::Duration; + use bevy::light::{NotShadowCaster, NotShadowReceiver}; use bevy::prelude::*; use bevy::mesh::*; +use bevy_easings::{Ease, EaseMethod, EasingsPlugin}; +pub use bevy_easings::{EaseFunction, EasingType}; +use derive_more::Debug; pub mod material; use material::*; @@ -30,12 +35,20 @@ impl Into for WaterQuality { } #[derive(Resource, Clone, Debug, Reflect)] -#[reflect(Resource)] +#[reflect(Resource, Default)] pub struct WaterSettings { /// StandardMaterial setting. pub alpha_mode: AlphaMode, /// Base water height. pub height: f32, + /// Easing method for `height` changes. + #[reflect(ignore)] + #[debug(skip)] + pub height_easing_method: EaseMethod, + /// Easing type for `height` changes. + #[reflect(ignore)] + #[debug(skip)] + pub height_easing_type: EasingType, /// Wave amplitude. pub amplitude: f32, /// The `StandardMaterial` base_color field. This is the base color of the water. @@ -70,6 +83,8 @@ impl Default for WaterSettings { #[cfg(feature = "ssr")] alpha_mode: AlphaMode::Opaque, height: 1.0, + height_easing_method: EaseMethod::Linear, + height_easing_type: EasingType::Once { duration: Duration::from_secs(1) }, amplitude: 1.0, clarity: 0.25, base_color: Color::srgba(1.0, 1.0, 1.0, 1.0), @@ -188,9 +203,30 @@ pub fn setup_water( } pub fn update_materials( + mut commands: Commands, settings: Res, mut materials: ResMut>, + water_transforms: Query<(Entity, &Transform), With>, ) { + // Apply height easing to all water tiles if height has changed + for (entity, transform) in water_transforms.iter() { + if transform.translation.y != settings.height { + let target_transform = Transform::from_xyz( + transform.translation.x, + settings.height, + transform.translation.z, + ); + + commands.entity(entity).insert( + transform.ease_to( + target_transform, + settings.height_easing_method, + settings.height_easing_type, + ) + ); + } + } + if !settings.update_materials { // Don't update water materials. return; @@ -216,7 +252,7 @@ impl Plugin for WaterPlugin { app .init_resource::() .register_type::() - .add_plugins(WaterMaterialPlugin) + .add_plugins((WaterMaterialPlugin, EasingsPlugin::default())) .add_systems(Startup, setup_water) .add_systems( Update, From e09f6e94a51556007d2e392bd01b97d8d41c0dd0 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Thu, 13 Nov 2025 23:16:07 -0500 Subject: [PATCH 2/2] Add access to bevy_easings --- src/water.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/water.rs b/src/water.rs index 76dbe00..d28c1ac 100644 --- a/src/water.rs +++ b/src/water.rs @@ -10,6 +10,10 @@ use derive_more::Debug; pub mod material; use material::*; +pub mod easings { + pub use bevy_easings::*; +} + pub const WATER_SIZE: u32 = 256; pub const WATER_HALF_SIZE: f32 = WATER_SIZE as f32 / 2.0; pub const WATER_GRID_SIZE: u32 = 6;