Giter VIP home page Giter VIP logo

bevy_easings's People

Contributors

blu-dev avatar carlton-perkins avatar dependabot[bot] avatar dtaralla avatar evenius avatar jzjones avatar mockersf avatar neo97online avatar rampedindent avatar rparrett avatar sliman4 avatar vrixyz avatar yrns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bevy_easings's Issues

Some way to work with the updates to transforms in bevy 0.6.1

bevy 0.6.1 has some changes to transforms, which makes bevy_easings break.

I've found this plugin to be very helpful so far, and I'd love to see it work with the newest updates as well!

Anyway, currently this code,

commands
    .entity(camera_entity)
    .insert(camera_transform.ease_to(
        Transform::default().with_translation(Vec3::new(0., 0., 10.)),
        EaseFunction::QuadraticIn,
        EasingType::Once {
            duration: Duration::from_millis(PANEL_TRANSITION_DURATION),
        },
    ));

(which used to work) gives this error:

the method `ease_to` exists for struct `bevy::prelude::Transform`, but its trait bounds were not satisfied
Click me for full error

error[E0599]: the method `ease_to` exists for reference `&bevy::prelude::Transform`, but its trait bounds were not satisfied
  --> src\panel_interaction.rs:25:46
   |
25 |                     .insert(camera_transform.ease_to(
   |                                              ^^^^^^^ method cannot be called on `&bevy::prelude::Transform` due to unsatisfied trait bounds
   |
  ::: C:\Users\AdminUser\.cargo\git\checkouts\bevy-f7ffde730c324c74\d8974e7\crates\bevy_transform\src\components\transform.rs:30:1
   |
30 | pub struct Transform {
   | -------------------- doesn't satisfy `bevy::prelude::Transform: Ease`
   |
  ::: C:\Users\AdminUser\.cargo\git\checkouts\bevy_easings-b8e4391b61bb95dc\e29534d\src\lib.rs:27:1
   |
27 | pub struct EaseValue<T>(pub T);
   | -------------------------------
   | |
   | doesn't satisfy `<_ as Lerp>::Scalar = f32`
   | doesn't satisfy `EaseValue<&&bevy::prelude::Transform>: Lerp`
   | doesn't satisfy `EaseValue<&bevy::prelude::Transform>: Lerp`
   | doesn't satisfy `EaseValue<&mut &bevy::prelude::Transform>: Lerp`
   | doesn't satisfy `EaseValue<&mut bevy::prelude::Transform>: Lerp`
   | doesn't satisfy `EaseValue<bevy::prelude::Transform>: Lerp`
   |
   = note: the following trait bounds were not satisfied:
           `<EaseValue<&bevy::prelude::Transform> as Lerp>::Scalar = f32`
           which is required by `&bevy::prelude::Transform: Ease`
           `EaseValue<&bevy::prelude::Transform>: Lerp`
           which is required by `&bevy::prelude::Transform: Ease`
           `<EaseValue<&&bevy::prelude::Transform> as Lerp>::Scalar = f32`
           which is required by `&&bevy::prelude::Transform: Ease`
           `EaseValue<&&bevy::prelude::Transform>: Lerp`
           which is required by `&&bevy::prelude::Transform: Ease`
           `<EaseValue<&mut &bevy::prelude::Transform> as Lerp>::Scalar = f32`
           which is required by `&mut &bevy::prelude::Transform: Ease`
           `EaseValue<&mut &bevy::prelude::Transform>: Lerp`
           which is required by `&mut &bevy::prelude::Transform: Ease`
           `<EaseValue<bevy::prelude::Transform> as Lerp>::Scalar = f32`
           which is required by `bevy::prelude::Transform: Ease`
           `EaseValue<bevy::prelude::Transform>: Lerp`
           which is required by `bevy::prelude::Transform: Ease`
           `<EaseValue<&mut bevy::prelude::Transform> as Lerp>::Scalar = f32`
           which is required by `&mut bevy::prelude::Transform: Ease`
           `EaseValue<&mut bevy::prelude::Transform>: Lerp`
           which is required by `&mut bevy::prelude::Transform: Ease`

Either an example of how to work around this, or some kind of fix to make it work with the code as it is, would be very much appreciated! Thank you!

`TypeUuid` incompatibility in bevy_easings with bevy

Using the latest git commit of both bevy_extras and bevy:

error[E0405]: cannot find trait `TypeUuid` in crate `bevy::type_registry`
   --> /home/jamadazi/src/bevy_extra/bevy_easings/src/plugin.rs:194:66
    |
194 | fn handle_ease_system<T: Ease + Component + bevy::type_registry::TypeUuid>(
    |                                                                  ^^^^^^^^ not found in `bevy::type_registry`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0405`.
error: could not compile `bevy_easings`

bevy_easings fails to compile with rust 1.55

This is possibly related to #11, although that predates rust 1.55 and doesn't seem like an actual solution. But perhaps that user was using rust beta?

error[E0658]: use of unstable library feature 'float_interpolation'
   --> bevy_easings/src/implemented.rs:125:49
    |
125 |                 EaseValue(Val::Percent(self_val.lerp(&other_val, scalar)))
    |                                                 ^^^^
    |
    = note: see issue #86269 <https://github.com/rust-lang/rust/issues/86269> for more information

error[E0308]: mismatched types
   --> bevy_easings/src/implemented.rs:125:54
    |
125 |                 EaseValue(Val::Percent(self_val.lerp(&other_val, scalar)))
    |                                                      ^^^^^^^^^^
    |                                                      |
    |                                                      expected `f32`, found `&f32`
    |                                                      help: consider removing the borrow: `other_val`

I am able to reproduce this consistently by

rustup update stable
rustup install 1.54

git clone [email protected]:mockersf/bevy_extra.git
cd bevy_extra/bevy_easings
git checkout 68d53df #0.4?
cargo clean && cargo +stable test #fails
cargo clean && cargo +1.54 test   #succeeds

This seems a little wacky to me, because I can't find any information about 1.55 related to float_interpolation.

Eased UI components are not styled properly since 0.11

I feel like this issue must be with Bevy, but I have been unable to reproduce without bevy_easings so far, so maybe not.

0.11: children are arranged in a row

image

0.10: children are arranged in a column as intended

image
use bevy::prelude::*;

use bevy_easings::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    App::default()
        .add_plugins(DefaultPlugins)
        .add_plugin(bevy_easings::EasingsPlugin)
        // 0.10
        //.add_startup_system(setup)
        // 0.11
        .add_systems(Startup, setup)
        .run();
    Ok(())
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());

    let from_style = Style {
        flex_direction: FlexDirection::Column,
        margin: UiRect {
            top: Val::Px(0.),
            ..Default::default()
        },
        // 0.10
        //size: Size::all(Val::Px(100.)),
        // 0.11
        width: Val::Px(100.),
        height: Val::Px(100.),
        ..Default::default()
    };
    let mut to_style = from_style.clone();
    to_style.margin = UiRect {
        top: Val::Px(500.),
        ..Default::default()
    };

    commands
        .spawn((
            NodeBundle {
                background_color: BackgroundColor(Color::RED),
                style: from_style.clone(),
                ..Default::default()
            },
            from_style.ease_to(
                to_style,
                bevy_easings::EaseFunction::SineInOut,
                bevy_easings::EasingType::PingPong {
                    duration: std::time::Duration::from_secs(10),
                    pause: Some(std::time::Duration::from_millis(500)),
                },
            ),
        ))
        .with_children(|parent| {
            for _ in 0..2 {
                parent.spawn(NodeBundle {
                    background_color: BackgroundColor(Color::WHITE),
                    style: Style {
                        // 0.10
                        //size: Size::all(Val::Px(20.)),
                        // 0.11
                        width: Val::Px(20.),
                        height: Val::Px(20.),
                        ..default()
                    },
                    ..Default::default()
                });
            }
        });
}

Easings

Hi,

How would I know when an easing finished?

Easings inserted during the same update that the previous easing ends get removed

I've had this mysterious bug in my game for a while Trouv/willos-graveyard#7

Basically, if the beginning of one of my movement animations happens during the same update as the ending of the previous movement animation, the new animation doesn't happen. I'm starting the new animation by inserting a new easing component, rather than using a chain (a chain doesn't quite fit this situation). Looking into the source code, it makes sense why. I managed to resolve the issue on my end by moving my systems responsible for inserting easings out of CoreStage::Update. I think using easing chains may have helped resolve this as well, but I had a hard time understanding how to turn an easing into an easing chain after the easing had already been inserted.

I can think of a few changes that may help alleviate this:

  • Move the default easing systems out of CoreStage::Update
  • Give the default easing systems a system label (users could then avoid this by adding their systems .after(EasingLabel))
  • Make all easings easing chains. Instead of EasingComponent, you would just have a single-element EasingChainComponent. I think it would make querying for easings and adding to the chain later more understandable. I imagine this is controversial though.

Add Example Showing Easings on Update Schedule instead of Startup

All of the existing examples show easings running in perpetuity (unless paused), initiating on startup. My use case is easing once between states that transition in response to changing conditions at runtime, and the vibrations I'm getting suggest my current method (running commands.entity().insert on every Update) is not the correct one.

breakage due to new Asset API in bevy

With the latest master commit of Bevy, compilation errors occur, due to changes in Bevy's Asset API.

In bevy_ninepatch:

error[E0277]: the trait bound `ninepatch::NinePatchBuilder<T>: TypeUuid` is not satisfied
   --> /home/jamadazi/.cargo/git/checkouts/bevy_extra-5808b82edd9c06c1/1f3f3b3/bevy_ninepatch/src/plugin.rs:258:23
    |
258 |     mut nine_patches: ResMut<Assets<NinePatchBuilder<T>>>,
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TypeUuid` is not implemented for `ninepatch::NinePatchBuilder<T>`
    |
   ::: /home/jamadazi/.cargo/git/checkouts/bevy-f7ffde730c324c74/c32e637/crates/bevy_asset/src/assets.rs:48:22
    |
48  | pub struct Assets<T: Asset> {
    |                      ----- required by this bound in `Assets`
    |
    = note: required because of the requirements on the impl of `Asset` for `ninepatch::NinePatchBuilder<T>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `bevy_ninepatch`

In bevy_easings:

error[E0277]: the trait bound `T: TypeUuid` is not satisfied
   --> /home/jamadazi/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_easings-0.1.1/src/plugin.rs:181:17
    |
181 |     mut assets: ResMut<Assets<T>>,
    |                 ^^^^^^^^^^^^^^^^^ the trait `TypeUuid` is not implemented for `T`
    |
   ::: /home/jamadazi/.cargo/git/checkouts/bevy-f7ffde730c324c74/c32e637/crates/bevy_asset/src/assets.rs:48:22
    |
48  | pub struct Assets<T: Asset> {
    |                      ----- required by this bound in `bevy::prelude::Assets`
    |
    = note: required because of the requirements on the impl of `Asset` for `T`
help: consider further restricting this bound
    |
188 |     T: IntermediateLerp + TypeUuid,
    |                         ^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `bevy_easings`

Chain easing from vector

Hey! I would like to start with BIG THANKS for creating a library that is great of use to me as a Bevy newbie.

I have dynamically generated vector of animations to perform (interpolated movement on the grid).
It is almost impossible (more on that later) to convert that vector to chain of animations.

Normally one would use fold: vector.iter().fold(component, |component, animation| component.ease_to(animation)
but it doesn't work, because types change:

component -> Component
component.ease_to() -> EasingComponent<Component>
component.ease_to().ease_to() -> EasingChainComponent<Component>
component.ease_to().ease_to().ease_to() -> EasingChainComponent<Component>

The best workaround I found is to call .ease_to two times to stabilize type into EasingChainComponent, and then fold normally:

let animation_component = component
            .ease_to(
                component.clone(),
                EaseMethod::Linear,
                EasingType::Once {
                    duration: std::time::Duration::from_millis(0),
                },
            )
            .ease_to(
                component.clone(),
                EaseMethod::Linear,
                EasingType::Once {
                    duration: std::time::Duration::from_millis(0),
                },
            );

        let animation_component =
            interpolation
                .iter()
                .fold(animation_component, |component, interpolation_item| {
                    component.ease_to(
                        <actual easing using interpolation_item>
                    )
                });

I think it would be interesting to have some way to approach that in non-hacky way. I'm newbie, so I really cannot suggest anything unfortunately.

`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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.