Skip to content

Commit

Permalink
animations: don't ignore curves with one keyframe (bevyengine#4406)
Browse files Browse the repository at this point in the history
# Objective

- While playing with animated models, I noticed some were a little off

## Solution

- Some animations curves only have one keyframe, they are used to set a transform to a given value
- Those were ignored as we're never exactly at the ts 0.0 of an animation. going there explicitly (`.set_elapsed(0.0).pause()`) would crash
- Special case this as there isn't much to animate in this case
  • Loading branch information
mockersf authored and aevyrie committed Jun 7, 2022
1 parent 915b71e commit 42859ab
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ pub fn animation_player(
}
if let Ok(mut transform) = transforms.get_mut(current_entity) {
for curve in curves {
// Some curves have only one keyframe used to set a transform
if curve.keyframe_timestamps.len() == 1 {
match &curve.keyframes {
Keyframes::Rotation(keyframes) => transform.rotation = keyframes[0],
Keyframes::Translation(keyframes) => {
transform.translation = keyframes[0]
}
Keyframes::Scale(keyframes) => transform.scale = keyframes[0],
}
continue;
}

// Find the current keyframe
// PERF: finding the current keyframe can be optimised
let step_start = match curve
Expand Down

0 comments on commit 42859ab

Please sign in to comment.