bevy
bevy copied to clipboard
Animation Blending
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
transitionfield
- added the
animation_playersystemanimated_fox.rs: Adapted example to be able to crossfade or normale play animations
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.
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.
This increase the system animation_player duration by 1.4ms in many_foxes examples, without any transitions between animations
red is main, yellow is this PR
Would it be possible to reduce the impact when there are no transitions ongoing?
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.
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
This increase the system
animation_playerduration by 1.4ms in many_foxes examples, without any transitions between animationsred 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 ?
@mockersf Just to check, is this PR still in consideration or should I just close it?
Animation changed since this PR, and this feature should be covered by #6922