Skip to content

Add a curve sampling method to the AnimationClip API#24152

Merged
alice-i-cecile merged 1 commit intobevyengine:mainfrom
Hilpogar:root-motion-part-1
May 7, 2026
Merged

Add a curve sampling method to the AnimationClip API#24152
alice-i-cecile merged 1 commit intobevyengine:mainfrom
Hilpogar:root-motion-part-1

Conversation

@Hilpogar
Copy link
Copy Markdown
Contributor

@Hilpogar Hilpogar commented May 6, 2026

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 :

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:

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.

@Hilpogar Hilpogar force-pushed the root-motion-part-1 branch from 3964341 to 7410554 Compare May 6, 2026 08:55
@mnmaita mnmaita added C-Feature A new feature, making something new possible A-Animation Make things move and change over time D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 6, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Animation May 6, 2026
@alice-i-cecile
Copy link
Copy Markdown
Member

@emberlightstudios I'd love your review here :)

Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Surprisingly simple and well-motivated.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 7, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 7, 2026
Merged via the queue into bevyengine:main with commit 1dce255 May 7, 2026
48 checks passed
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in Animation May 7, 2026
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 D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants