Skip to content

Commit

Permalink
support all types of animation interpolation from gltf (#10755)
Browse files Browse the repository at this point in the history
# Objective

- Support step and cubic spline interpolation from gltf

## Solution

- Support step and cubic spline interpolation from gltf

Tested with
https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/InterpolationTest
expected: 

![](https://github.com/raw/KhronosGroup/glTF-Sample-Models/master/2.0/InterpolationTest/screenshot/screenshot.gif)
result: 

![output](https://github.com/bevyengine/bevy/assets/8672791/e7f1afd5-20c9-4921-97d4-8d0c82203068)

---

## Migration Guide

When manually specifying an animation `VariableCurve`, the interpolation
type must be specified:

- Bevy 0.12
```rust
        VariableCurve {
            keyframe_timestamps: vec![0.0, 1.0, 2.0, 3.0, 4.0],
            keyframes: Keyframes::Rotation(vec![
                Quat::IDENTITY,
                Quat::from_axis_angle(Vec3::Y, PI / 2.),
                Quat::from_axis_angle(Vec3::Y, PI / 2. * 2.),
                Quat::from_axis_angle(Vec3::Y, PI / 2. * 3.),
                Quat::IDENTITY,
            ]),
        },
```

- Bevy 0.13
```rust
        VariableCurve {
            keyframe_timestamps: vec![0.0, 1.0, 2.0, 3.0, 4.0],
            keyframes: Keyframes::Rotation(vec![
                Quat::IDENTITY,
                Quat::from_axis_angle(Vec3::Y, PI / 2.),
                Quat::from_axis_angle(Vec3::Y, PI / 2. * 2.),
                Quat::from_axis_angle(Vec3::Y, PI / 2. * 3.),
                Quat::IDENTITY,
            ]),
            interpolation: Interpolation::Linear,
        },
```
  • Loading branch information
mockersf committed Dec 31, 2023
1 parent 09c8308 commit f88d755
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,18 @@ async fn load_gltf<'a, 'b, 'c>(

#[cfg(feature = "bevy_animation")]
let (animations, named_animations, animation_roots) = {
use bevy_animation::Keyframes;
use bevy_animation::{Interpolation, Keyframes};
use gltf::animation::util::ReadOutputs;
let mut animations = vec![];
let mut named_animations = HashMap::default();
let mut animation_roots = HashSet::default();
for animation in gltf.animations() {
let mut animation_clip = bevy_animation::AnimationClip::default();
for channel in animation.channels() {
match channel.sampler().interpolation() {
gltf::animation::Interpolation::Linear => (),
other => warn!(
"Animation interpolation {:?} is not supported, will use linear",
other
),
let interpolation = match channel.sampler().interpolation() {
gltf::animation::Interpolation::Linear => Interpolation::Linear,
gltf::animation::Interpolation::Step => Interpolation::Step,
gltf::animation::Interpolation::CubicSpline => Interpolation::CubicSpline,
};
let node = channel.target().node();
let reader = channel.reader(|buffer| Some(&buffer_data[buffer.index()]));
Expand Down Expand Up @@ -264,6 +262,7 @@ async fn load_gltf<'a, 'b, 'c>(
bevy_animation::VariableCurve {
keyframe_timestamps,
keyframes,
interpolation,
},
);
} else {
Expand Down

0 comments on commit f88d755

Please sign in to comment.