SIGN IN SIGN UP
bevyengine / bevy UNCLAIMED

A refreshingly simple data-driven game engine built in Rust

0 0 59 Rust

Add a curve sampling method to the AnimationClip API (#24152)

# Objective

Add a method to `AnimationClip` to sample a property at a specific time.
This is the first point proposed in #23355. The original goal was to
allow the development of root motion, but it turns out that this API
improvement can be useful for third party crates or games that need to
sample animation curves directly. This PR is also inspired by the
previous work in #16395.

## Solution

Add a method `sample_clamped` to `AnimationClip` :
```Rust
pub fn sample_clamped<P: AnimatableProperty>(
    &self,
    animatable_property: P,
    target: AnimationTargetId,
    time: f32,
) -> Option<P::Property> {}
```

This method requires to add another `sample_clamped` method to the
`AnimationCurve` trait:
```Rust
fn sample_clamped(&self, t: f32) -> Box<dyn Any>;
```

## Testing

There is 2 new tests. One at the `AnimationCurve` level and one at the
`AnimationClip` level. There is also an example in the method's
documentation.
H
Hilpogar committed
1dce2550909e8ab3ed167e0462b469a073eda909
Parent: 4bd3708
Committed by GitHub <noreply@github.com> on 5/7/2026, 3:28:40 AM