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

[Merged by Bors] - animation player #4375

Closed
wants to merge 15 commits into from

Conversation

mockersf
Copy link
Member

Objective

Solution

  • Can play animations
    • looping or not
  • Can pause animations
  • Can seek in animation
  • Can alter speed of animation
  • I also removed the previous gltf animation example
animated_fox.mp4

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Mar 31, 2022
@mockersf mockersf added C-Feature A new feature, making something new possible A-Animation Make things move and change over time and removed S-Needs-Triage This issue needs to be labelled labels Mar 31, 2022
crates/bevy_animation/src/lib.rs Outdated Show resolved Hide resolved
examples/animation/animated_fox.rs Outdated Show resolved Hide resolved
Co-authored-by: Jakob Hellermann <[email protected]>
@kirusfg
Copy link
Contributor

kirusfg commented Apr 1, 2022

Regarding the keyframes, I thought of remembering the step_start and step_end keyframes and updating them if elapsed time is greater than that of step_end instead of traversing through all of them each frame. Do you think that is a good approach?

Choosing an arbitrary position on the track would still require some kind of traversal, I think.

@CptPotato
Copy link
Contributor

CptPotato commented Apr 1, 2022

Regarding the keyframes, I thought of remembering the step_start and step_end keyframes and updating them if elapsed time is greater than that of step_end instead of traversing through all of them each frame. Do you think that is a good approach?

Choosing an arbitrary position on the track would still require some kind of traversal, I think.

That's generally a good idea in my opinion 👍

To elaborate a bit more: From my experience, when working with animations finding the keyframe works very well with these two strategies:

  • for continuous playback start at the index of the last iteration (in this case step_start) and perform a linear search (forward or backward depending on playback direction) *
  • for seeking to arbitrary positions, binary search is a sensible default (though it could be optimized more when necessary)

* The cached value of step_start is tied to the "playback instance" so it would be stored as a part of the animation player

This assumes that the framerate of the keyframes isn't significantly higher than the playback speed.
There are also different approaches for cases where the keyframes occur at a fixed rate.

@james7132
Copy link
Member

A keyframe cursor is generally useful for linear playback which this player is mostly intended for. For a more realistic modern use case where we have multiple blended clips in any given state, random seeks become more common (think transitioned blending and arbitrary gameplay driven blend states), which is actually negatively impacted when using a cursor.

For this PR, I think it's fine to use as is but we may want to revisit if it's worth the complexity as we scale this.

@cart
Copy link
Member

cart commented Apr 1, 2022

Awesome! Love the new user-facing api.

@mockersf
Copy link
Member Author

mockersf commented Apr 1, 2022

Switched they keyframe lookup to a binary search.
I would prefer to avoid adding cursors for now, they are quite more complex, and we would need a way to address each curve independently as the cursors need to be by curve

@cart
Copy link
Member

cart commented Apr 1, 2022

I'm down to optimize for implementation simplicity, given the timelines we're dealing with here.

Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

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

I think this is in a good spot for 0.7 and provides a reasonable starting point for future improvements. Well done!

crates/bevy_animation/src/lib.rs Outdated Show resolved Hide resolved
@cart
Copy link
Member

cart commented Apr 1, 2022

I'll hold off on other approvals for a day or so, then I'll merge.

Copy link
Contributor

@tim-blackbird tim-blackbird left a comment

Choose a reason for hiding this comment

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

Does this handle playing animations in reverse?

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 Show resolved Hide resolved
examples/animation/animated_fox.rs Show resolved Hide resolved
@mockersf
Copy link
Member Author

mockersf commented Apr 1, 2022

Does this handle playing animations in reverse?

now it does 👍

) {
if !*done {
if let Ok(mut player) = player.get_single_mut() {
player.play_animation(animations.0[0].clone_weak()).repeat();

Choose a reason for hiding this comment

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

Hm... Looking from a use perspective AnimationPlayer would look prettier if it was just Animation.
system param
animations: Query<&mut Animation>,
then later
if let Ok(mut animation) = animations.get_single_mut() {
animation.play(fox_animations.0[0].clone_weak()).repeat();

Copy link
Member

Choose a reason for hiding this comment

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

I do like the bias toward "nicer names", but in this particular case, I think AnimationPlayer is the better name. It represents a thing that plays animation, not a thing that is Animation. I'm more open to renaming AnimationClip to Animation, but I'm also happy with the current name, for now.

Additionally, we have plans for a more general "bevy animation system". It probably makes sense to reserve the Animation name until we sort out how that fits in to this.

@alice-i-cecile alice-i-cecile added this to the Bevy 0.7 milestone Apr 2, 2022
@cart
Copy link
Member

cart commented Apr 2, 2022

bors r+

bors bot pushed a commit that referenced this pull request Apr 2, 2022
# Objective

- Add a basic animation player
  - Single track
  - Not generic, can only animate `Transform`s
  - With plenty of possible optimisations available
  - Close-ish to bevyengine/rfcs#49
- https://discord.com/channels/691052431525675048/774027865020039209/958820063148929064

## Solution

- Can play animations
  - looping or not
- Can pause animations
- Can seek in animation
- Can alter speed of animation
- I also removed the previous gltf animation example

https://user-images.githubusercontent.com/8672791/161051887-e79283f0-9803-448a-93d0-5f7a62acb02d.mp4
@bors bors bot changed the title animation player [Merged by Bors] - animation player Apr 2, 2022
@bors bors bot closed this Apr 2, 2022
aevyrie pushed a commit to aevyrie/bevy that referenced this pull request Jun 7, 2022
# Objective

- Add a basic animation player
  - Single track
  - Not generic, can only animate `Transform`s
  - With plenty of possible optimisations available
  - Close-ish to bevyengine/rfcs#49
- https://discord.com/channels/691052431525675048/774027865020039209/958820063148929064

## Solution

- Can play animations
  - looping or not
- Can pause animations
- Can seek in animation
- Can alter speed of animation
- I also removed the previous gltf animation example

https://user-images.githubusercontent.com/8672791/161051887-e79283f0-9803-448a-93d0-5f7a62acb02d.mp4
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

- Add a basic animation player
  - Single track
  - Not generic, can only animate `Transform`s
  - With plenty of possible optimisations available
  - Close-ish to bevyengine/rfcs#49
- https://discord.com/channels/691052431525675048/774027865020039209/958820063148929064

## Solution

- Can play animations
  - looping or not
- Can pause animations
- Can seek in animation
- Can alter speed of animation
- I also removed the previous gltf animation example

https://user-images.githubusercontent.com/8672791/161051887-e79283f0-9803-448a-93d0-5f7a62acb02d.mp4
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-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants