feat(animation): impl Animatable for Rot2#23618
feat(animation): impl Animatable for Rot2#23618YurikoDX wants to merge 2 commits intobevyengine:release-0.18.1from
Animatable for Rot2#23618Conversation
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.
|
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! 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. |
alice-i-cecile
left a comment
There was a problem hiding this comment.
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.
|
This needs to target
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.
|
Swapping this to target the |
|
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! 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. |
|
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 ! |
## Objective This PR adds animation support for 2D rotations by implementing the `Animatable` trait for `Rot2`. This enables developers to smoothly animate 2D entities and UI elements. *(Note: This is a clean, cherry-picked recreation of bevyengine#23618 targeting the `main` branch, as suggested by @alice-i-cecile .)* ## Solution To ensure mathematical correctness and consistency with existing Bevy math types (like `Quat`), this implementation includes: - **Shortest-path interpolation:** Uses spherical linear interpolation (`slerp`) so that rotations naturally take the shortest route (e.g., passing through 0° rather than 180° when moving from 89° to -89°). - **Standardized blending:** Implements precise cumulative and additive blending logic that perfectly mirrors the behavior of `Quat`. - **Comprehensive Unit Tests:** Added tests specifically to verify: - Shortest path interpolation. - Absolute blending with equal weights. - Cumulative multi-way blending. - Additive blending. - **Example Update:** Updated the `animated_ui` example to showcase the new `Rot2` animation capabilities. ## Testing - [x] All new unit tests pass (`cargo test -p bevy_animation --lib animatable`). - [x] Ran `cargo fmt` and `cargo clippy`. - [x] Tested the `animated_ui` example locally to ensure the 2D rotation curve behaves as expected. --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Objective
Rot2does not implement theAnimatabletrait, which preventsUiTransform::rotationand other 2D components from being animated viaAnimationGraph.Solution
AnimatableforRot2inbevy_animation.Quatimplementation to ensure consistency across the engine's math types:slerpforinterpolateto ensure shortest-path 2D rotation.blendwith cumulative SLERP to support multi-track and additive blending.Quat.Testing
animated-uiexample.Showcase
Modified the
animated-uiexample to includeUiTransform::rotationanimation:Click to view code snippet