Skip to content

feat(animation): impl Animatable for Rot2#23618

Closed
YurikoDX wants to merge 2 commits intobevyengine:release-0.18.1from
YurikoDX:impl-animatable-rot2
Closed

feat(animation): impl Animatable for Rot2#23618
YurikoDX wants to merge 2 commits intobevyengine:release-0.18.1from
YurikoDX:impl-animatable-rot2

Conversation

@YurikoDX
Copy link
Copy Markdown

@YurikoDX YurikoDX commented Apr 1, 2026

Objective

  • Enable animation support for 2D rotations.
  • Currently, Rot2 does not implement the Animatable trait, which prevents UiTransform::rotation and other 2D components from being animated via AnimationGraph.

Solution

  • Implemented Animatable for Rot2 in bevy_animation.
  • Implementation Parity: Followed the exact pattern of the existing Quat implementation to ensure consistency across the engine's math types:
    • Used slerp for interpolate to ensure shortest-path 2D rotation.
    • Implemented blend with cumulative SLERP to support multi-track and additive blending.
    • Added documentation comments consistent with Quat.

Testing

  • Example Validation: Verified by adding a rotation curve to the official animated-ui example.
  • Environment: Tested on Linux (NVIDIA MX150 / Intel UHD 620).

Showcase

Modified the animated-ui example to include UiTransform::rotation animation:

Click to view code snippet
use std::f32::consts::TAU;

animation_clip.add_curve_to_target(
    animation_target_id,
    AnimatableCurve::new(
        animated_field!(UiTransform::rotation),
        AnimatableKeyframeCurve::new(
            [0.0, 1.0, 2.0, 3.0]
                .into_iter()
                .zip([0., TAU / 3., TAU / 1.5, TAU].map(Rot2::radians))
        )
        .expect("should be able to build rotation curve")
    ),
);

Enable animation support for 2D rotations. Since `UiTransform` and
other 2D components now use `Rot2` for rotation, implementing
`Animatable` is required to drive these fields via the `AnimationGraph`.

- Implemented `Animatable` for `Rot2` in `bevy_animation`.
- Used `slerp` for shortest-path interpolation, mirroring `Quat` behavior.
- Implemented `blend` using cumulative SLERP to support multi-track
  blending and additive layers.
- Added documentation comments consistent with existing `Quat` implementation.

- Verified `interpolate` correctly handles shortest-path rotation.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-23618

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

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.

Would not mind a test or two, especially for the shortest path behavior, but this LGTM. Thanks!

You need to format this code (see CI), and we'll need a second approval before we can merge though.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-UI Graphical user interfaces, styles, layouts, and widgets A-Animation Make things move and change over time X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 1, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in UI Apr 1, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Animation Apr 1, 2026
@alice-i-cecile
Copy link
Copy Markdown
Member

alice-i-cecile commented Apr 1, 2026

This needs to target main

Example Validation: Verified by adding a rotation curve to the official animated-ui example.

This was also not done in this PR.

- Added comprehensive unit tests verifying shortest-path interpolation and Bevy's cumulative blending behavior for `Rot2`.
- Updated the `animated_ui` example to showcase 2D rotation curves using `Rot2`.
- Fixed minor formatting issues in `animatable.rs` to satisfy CI checks.
@alice-i-cecile alice-i-cecile removed the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Apr 2, 2026
@alice-i-cecile alice-i-cecile changed the base branch from release-0.18.1 to main April 2, 2026 03:17
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Apr 2, 2026
@alice-i-cecile alice-i-cecile changed the base branch from main to release-0.18.1 April 2, 2026 03:17
@alice-i-cecile
Copy link
Copy Markdown
Member

Swapping this to target the main branch is non-trivial. You're probably better off just cherrypicking your changes into a new branch and opening a new PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-23618

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@YurikoDX
Copy link
Copy Markdown
Author

YurikoDX commented Apr 2, 2026

I've cherry-picked these changes into a clean branch targeting main as suggested! Closing this in favor of the new PR: #23621

Thanks again for the guidance, @alice-i-cecile !

@YurikoDX YurikoDX closed this Apr 2, 2026
@github-project-automation github-project-automation bot moved this from Needs SME Triage to Done in UI Apr 2, 2026
@github-project-automation github-project-automation bot moved this from Needs SME Triage to Done in Animation Apr 2, 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 A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants