bevy_easings
bevy_easings copied to clipboard
`StandardMaterial` easings?
Any plan on adding StandardMaterial as an available easing target? I'm fumbling around with trying it myself, but I'm running into problems due to lack of skills.
Current attempt:
#[derive(Debug, Default)]
struct MyEaseValue<T>(pub T);
impl Lerp for MyEaseValue<StandardMaterial> {
type Scalar = f32;
fn lerp(&self, other: &Self, scalar: &Self::Scalar) -> Self {
MyEaseValue(StandardMaterial {
albedo: self.0.albedo
+ (other.0.albedo + (self.0.albedo * -1.)) * *scalar,
albedo_texture: None,
..Default::default()
})
}
}
Which is more or less copied from your implementation for ColorMaterial. Getting problems with how to add easings for my materials with this.
OK, figured out how to use custom easings finally. Just thought it would be a good idea to summarize what I did, if anyone else stumbles upon this:
#[derive(Debug, Default)]
struct MyEaseValue<T>(pub T);
impl Lerp for MyEaseValue<Color> {
type Scalar = f32;
fn lerp(&self, other: &Self, scalar: &Self::Scalar) -> Self {
MyEaseValue(self.0 + (other.0 + (self.0 * -1.)) * *scalar)
}
}
And then created a helper function to add an EasingComponent to a specified entity:
#[derive(Debug)]
struct Fade;
fn fade_to(
commands: &mut Commands,
entity: Entity,
from: Color,
to: Color,
millis: u64,
) {
commands.set_current_entity(entity);
commands.with(Fade).with(MyEaseValue(from)).with(
MyEaseValue(from).ease_to(
MyEaseValue(to),
EaseFunction::QuadraticOut,
EasingType::Once {
duration: Duration::from_millis(millis),
},
),
);
}
Fade in the above is just a component for my fading system to recognize that it should handle this entity:
fn fade(
mut materials: ResMut<Assets<StandardMaterial>>,
mut query: Query<
(&MyEaseValue<Color>, &Handle<StandardMaterial>),
With<Fade>,
>,
) {
for (color, mat_handle) in query.iter_mut() {
materials.set(mat_handle, color.0.into());
}
}
Finally, the systems should be added:
app
.add_system(fade.system())
.add_system(custom_ease_system::<MyEaseValue<Color>>.system())
Feel free to close this issue. I don't know if it's a good idea to have StandardMaterial easings? Maybe that would not work so well with textures etc...
great! thank you for digging into this!
doing easing on something that is behind a Handle is not something simple, it depends on which part you want to change... your solution for that is nice!