Skip to content
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

Add ability to set speed of animations #464

Merged
merged 1 commit into from
May 29, 2024
Merged

Conversation

johnwhh
Copy link
Contributor

@johnwhh johnwhh commented Apr 15, 2024

Proposition

In the current version, there is no way to pause, reverse, or change the speed of animations on a ModelNode. This enhancement would bring each of those capabilities.

Changes

  • A speed variable has been added to the PlayingAnimation data class to give each animation its own speed. The speed can be changed while the animation is playing to dynamic change the rate at which the animation is played.

  • Two functions have been added to assist in changing the speed of animations, both of which keep the precedent set by the playAnimation functions.

fun setAnimationSpeed(animationName: String, speed: Float)
fun setAnimationSpeed(animationIndex: Int, speed: Float)
  • Each playAnimation function can now be passed a speed. Each one uses a speed of 1f by default.

  • The logic for applying animations has been moved into its own private function called applyAnimations to make the onFrame call site cleaner.

  • Added some missing documentation to the playAnimation functions.

Enhancements

To reverse an animation, use a negative speed:

playAnimation(0, speed = -1f) 

To pause an animation, use a speed of zero:

setAnimationSpeed(0, speed = 0f) 

Copy link
Contributor

@ThomasGorisse ThomasGorisse left a comment

Choose a reason for hiding this comment

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

Thanks! That's clean code!

@ThomasGorisse ThomasGorisse merged commit af9063b into SceneView:main May 29, 2024
1 check passed
@MicahMeadows
Copy link

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants