Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation Blending #5415

Closed
wants to merge 17 commits into from
Closed

Conversation

Bendzae
Copy link

@Bendzae Bendzae commented Jul 21, 2022

Objective

  • Extend the bevy animation system to allow blending between animations
    • Should be able to specify the duration of the transition
    • Both the current and the target animations should run while blending between them
    • Provide a working example

Solution

Extended the AnimationPlayer with a function:
pub fn cross_fade(&mut self, handle: Handle<AnimationClip>, transition_time: f32) -> &mut AnimationTransition
This initiates a fade from the current to the provided animation.

The information about this "Transition" is stored in a the struct AnimationTransition and is added to the AnimationPlayer.

The animation_player system was adapted to handle this new data by interpolating the transforms of the targeted entities between the transforms of the keyframes of the current and target clip.


Changelog

Added

  • AnimationTransition: Representation of the data needed to transition from one to another animation

Changed

  • AnimationPlayer
    • added the cross_fade() function
    • added the transition field
  • animation_player system
  • animated_fox.rs: Adapted example to be able to crossfade or normale play animations

@alice-i-cecile alice-i-cecile added C-Enhancement A new feature A-Animation Make things move and change over time labels Jul 21, 2022
crates/bevy_animation/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_animation/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_animation/src/lib.rs Outdated Show resolved Hide resolved
@alice-i-cecile
Copy link
Member

Surprisingly straightforward. I'm not entirely sure how this fits into the broader plans in this area, but given the amount of added functionality relative to the complexity and the importance of Transform animation (which is likely going to end up special-cased) I'm inclined to merge this before the RFCs are in.

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now :) You can resolve all of my comments.

Copy link
Member

@james7132 james7132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While useful in its own right, this implementation is a bit shortsighted. This only supports a single linear transition between two clips, whereas the animation RFCs aim to support an arbitrary N-wise linear blend of multiple clips. This not only supports a transition between single clips, but also more complex blending structures like state machines, layered blends, or N-D blend trees.

Overall, I think we should prioritize reviewing and implementing the RFCs over extending the current animation player, which we've acknowledged was meant as a short term stopgap to ship with 0.7.

@Bendzae
Copy link
Author

Bendzae commented Jul 21, 2022

While useful in its own right, this implementation is a bit shortsighted. This only supports a single linear transition between two clips, whereas the animation RFCs aim to support an arbitrary N-wise linear blend of multiple clips. This not only supports a transition between single clips, but also more complex blending structures like state machines, layered blends, or N-D blend trees.

Overall, I think we should prioritize reviewing and implementing the RFCs over extending the current animation player, which we've acknowledged was meant as a short term stopgap to ship with 0.7.

I totally agree. My line of thought was just to put it out there to provide an intermediary solution until the RFCs are implemented. So people like myself, that need at least some basic form of animation blending for their project, have something to work with.

If you think it will somehow hinder the progress or is too much effort to review I would have no Problem with closing this PR for now.

Since I am very new to bevy I trust your opinion on if this PR is worth it.

@mockersf
Copy link
Member

mockersf commented Jul 23, 2022

This increase the system animation_player duration by 1.4ms in many_foxes examples, without any transitions between animations
crossfade
red is main, yellow is this PR

Would it be possible to reduce the impact when there are no transitions ongoing?

@Bendzae
Copy link
Author

Bendzae commented Jul 29, 2022

Hi Mockersf,
Sorry for the late reply, what profiling tool are you using to generate that graph?
I will try to optimize frametimes for non-transition animations asap.

@mockersf
Copy link
Member

I am using Tracy: https://github.com/wolfpld/tracy.
There are some docs in how to use with Bevy here: https://github.com/bevyengine/bevy/blob/main/docs/profiling.md#backend-trace_tracy

You'll need to enable Bevy feature trace_tracy: cargo run --release --example many_foxes --features trace_tracy

@Bendzae
Copy link
Author

Bendzae commented Jul 31, 2022

This increase the system animation_player duration by 1.4ms in many_foxes examples, without any transitions between animations crossfade red is main, yellow is this PR

Would it be possible to reduce the impact when there are no transitions ongoing?

I managed to get it down to a difference of about .1 ms on my machine. Would that be fine with you @mockersf ?

image

Bendzae and others added 3 commits July 31, 2022 18:00
This reverts commit 2a1218fefd0d3fbf142897d2c6aaf8abf0c68084.
@Bendzae
Copy link
Author

Bendzae commented Aug 11, 2022

@mockersf Just to check, is this PR still in consideration or should I just close it?

@mockersf
Copy link
Member

Animation changed since this PR, and this feature should be covered by #6922

@mockersf mockersf closed this Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Animation Make things move and change over time C-Enhancement A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants