-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Animation Crate #482
Animation Crate #482
Conversation
- add automatic Transform animation component
(based on PR suggestions and clippy)
I can't build it on archlinux :(
ends up with:
EDIT: |
I'll be taking a look a this soon. This will require a thorough review + some thought on my part and I want to give it the time it deserves. I need to sort out some asset related stuff first, as thats blocking a number of projects. |
I'm looking at extending this crate to enable animating rotations using I also looked at piston's handling of rotating animations, and the code handles regular quaternions as well as something called "dual quaternions", linking to this article. https://dcgi.felk.cvut.cz/home/zara/papers/TCD-CS-2006-46.pdf |
I think that a |
I was thinking that AnimationSplineTransform should use Quats instead of euler angles, but maybe I'm mistaken in assuming you would never want to interpolate through euler angles? I guess that's desirable sometimes, now that I think about it, such as when animating something that rotates on a double joint with equal rotational speed on both axes of the joint, instead of along the shortest path from one orientation to the other. |
A totally different approach to implementing this would be to have the actual code running be much less generic, and instead re-sample the curves more finely up front, and use simple linear interpolations between these finer keyframes. That would allow the same code to approximate all variations of these complex behaviors, with some runtime cost amortized to creation of the spline, and more memory usage. |
The only thing keeping me from implementing anything with Quats so far is a lack of understanding of them on my part 😅 Swapping out for them on rotation interpolations would be better, yes, though I think an option for developers to animate in the more intuitive "Euler Space" is necessary. If we ever want to translate this over to a curve editor in a UI, those never use the four Quat values as the rotation curves. |
Absolutely! Euler angles are almost always easier to think about when
specifying orientations. Luckily, we already have Quat::from_ypr, so it
shouldn't be too huge a problem for people to interact with a quaternion
based API.
…On Thu, 22 Oct 2020, 23:45 John, ***@***.***> wrote:
The only thing keeping me from implementing anything with Quats so far is
a lack of understanding of them on my part 😅 Swapping out for them on
rotation interpolations would be better, yes, though I think an option for
developers to animate in the more intuitive "Euler Space" is necessary. If
we ever want to translate this over to a curve editor in a UI, those never
use the four Quat values as the rotation curves.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#482 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADKMETWHUYVXU3V7ROH2C23SMCRYDANCNFSM4RJ5I7XQ>
.
|
I've opened a pull request to glam that adds support for adding and subtracting quats, which would allow the splines crate to ship with a glam feature that implements all the required traits. If it turns out they're not interested in this feature, the splines crate could also potentially be refactored to do the same anyway, but without the help of the plus and minus operators, so the code gets a bit ugly. |
Glam decided to merge my pull request, so in a few weeks they should have a new version released, which means splines can merge this, and then we can use Quats directly in spline keys. |
Haven't really looked into what the crate does since it all goes over my head, but are these components for a future animation system to build upon? 2D and 3D? |
It's a combination of components that either provide number(s) that change over time based on a spline for you to hook up to your components with a system, and one that directly changes a transform on its own. It'll work for 2D and 3D. |
"Features and dependencies cannot have the same name" - also updated version numbers
Note that the spline implementation for Quats uses a normalized linear interpolation. This is fine and actually preferable when they don't rotate too far from one key to the next, but exhibits a nonlinear speed when the distance becomes greater. If the animations are imported from some kind of editor, the editor could generate lots of keys in between the user-defined poses to cover this up, but if you simply feed it quats with like 90 degree increments it will look wrong. I've looked at trying to create an extension trait to Spline that resamples sparse keys to a finer resolution, but I've only got it working for |
Quat animation
Looks like |
I did just kind of toss the merge together, sorry about that. I'll try and correct it come tomorrow. |
Closing out. This is useful prior art, but is extremely unlikely to be merged in its current form. |
Adds the
bevy_animation
crate, components to add spline animations, and two examples.Components
AnimationSplineTransform
automatically animates any entity it is a part of that has theTranslation
,Rotation
andScale
componentsTransform
component as of Bevy 0.2.1.AnimationSplineOne
exposes an automatically-animatedf32
value that a developer can retrieve in their own systems.AnimationSplineThree
fills the same function asAnimationSplineOne
, but forVec3
values.SplineGroup
All 3 components implement the trait
SplineGroup
, which requires get / mutable get functions for the properties:loop_style
, an enum to determine if an animation plays once, loops, or 'ping-pongs' back and forth.time
, the current time of the animationspeed
the speed multiplier of the animationpaused
a boolean for pausing the animationpong
, a boolean that is true if the animation is ping-pong-ing in reverse.It also offers default implementations for useful functions:
pause
play
toggle_pause
is_empty
start_time
end_time
duration
advance
by a particular amount of timesample
at a particular timecurrent
to sample at the current timeFor the default
SplineGroup
components, I think it's about striking a balance between what values are animated frequently enough to warrant having a built-in system for animating them, and what developers should be left to hook up to generic SplineGroups themselves with custom systems, or create their ownSplineGroup
sImprovements
I am not sure if the ping-pong functionality works properly. Looping and no-looping should work, though.Ping Pong works as of 39207e4AnimationSplineThree
returns samples of a struct I made,Vec3Option
, instead of a rawVec3
, to make it easy to not mutate one of the three tracks (x / y / z) that has no keyframes on it. This might be better served by returning something like(Vec3, Vec3Mask)
instead of making a whole new struct that may see too little use.