SpatialGltfModelAnimation

@RequiresApi(value = 26)
class SpatialGltfModelAnimation : AutoCloseable


An animation that is attached to a glTF model.

This may be used to inspect or control the state of this animation.

Summary

Nested types

The current animation state of the SpatialGltfModelAnimation.

Public functions

open Unit
Unit

Starts playing this animation.

Unit

Pauses this animation.

Unit

Resumes this animation.

Unit

Seeks the animation to a specific time offset from the start of the animation.

Unit

Starts playing this animation.

Unit

Stops this animation.

Public properties

SpatialGltfModelAnimation.AnimationState

The current playing state of this animation.

Duration

The duration of this animation.

String?

The name of this animation or null if the animation does not have a name.

Float

Sets the playback speed for this animation.

Public functions

close

Added in 1.0.0-alpha15
open fun close(): Unit

loop

Added in 1.0.0-alpha15
fun loop(): Unit

Starts playing this animation. The animation will play and repeat from the beginning when it reaches its duration.

This transitions the animation state to AnimationState.Playing.

If the animation is already playing, calling this will start the animation again but it will now loop instead of ending when the animation is over.

pause

Added in 1.0.0-alpha15
fun pause(): Unit

Pauses this animation.

This freezes the animation at the current frame and transitions the animation state to AnimationState.Paused. Use start to continue playback.

Note: Calling start or loop while in the AnimationState.Paused state will resume the animation from the current frame. To reset the animation, call stop() or seekTo(0.seconds).

resume

Added in 1.0.0-alpha15
fun resume(): Unit

Resumes this animation.

This continues the animation from the point where it was paused and transitions the animation state to AnimationState.Playing.

Note: Calling resume while in the AnimationState.Playing and AnimationState.Stopped state will have no effect.

seekTo

Added in 1.0.0-alpha15
fun seekTo(time: Duration): Unit

Seeks the animation to a specific time offset from the start of the animation.

If the animationState of the animation is AnimationState.Stopped, this will set the start time of the animation that will take effect when the animation is played next. The state of glTF will not update until the next time start or loop is called.

Parameters
time: Duration

The offset from the beginning of the animation. It must be greater than or equal to zero. If time is larger than the duration of the animation, the duration of the animation will be used instead.

Throws
IllegalArgumentException

if time is negative.

start

Added in 1.0.0-alpha15
fun start(): Unit

Starts playing this animation. The animation will play once and stop once it reaches its duration.

This transitions the animation state to AnimationState.Playing.

If the animation is already looping, calling this will start the animation again but it won't loop when the animation is over.

stop

Added in 1.0.0-alpha15
fun stop(): Unit

Stops this animation.

This resets the playback time to 0 and transitions the animation state to AnimationState.Stopped. If this animation is not currently playing or pausing, this method has no effect.

Public properties

animationState

val animationStateSpatialGltfModelAnimation.AnimationState

The current playing state of this animation.

This is backed by a snapshot State object that is updated whenever the animation state changes and may trigger recomposition.

duration

val durationDuration

The duration of this animation.

name

Added in 1.0.0-alpha15
val nameString?

The name of this animation or null if the animation does not have a name.

The name is not guaranteed to be unique across all animations.

playbackSpeed

Added in 1.0.0-alpha15
var playbackSpeedFloat

Sets the playback speed for this animation.

The speed multiplier determines the playback rate:

  • 1.0: Normal speed.

  • > 1.0: Faster playback.

  • > 0.0 and < 1.0: Slower playback (e.g., 0.5 is half speed).

  • 0.0: Freezes the animation at the current frame while keeping it active (unlike pausing).

  • < 0.0: Plays the animation in reverse.

Note: This call is only valid during the AnimationState.Playing and AnimationState.Paused states. Calling this method while in the AnimationState.Stopped state will have no effect.