markhorgan / realitykit-animation-definition

4 stars 0 forks source link

Pause/Resume an animation #1

Open Treata11 opened 7 months ago

Treata11 commented 7 months ago

Greetings.

Thanks for the great article.

Just had a question ... Is there any way to pause an already started animation & being able to resume it from exactly where it was stopped?

The only solution I found for it is to create an argument isPlaying, in the method responsible for triggering the animation:

    private func animateTraversal(of entity: Entity, isPaused: Bool) {
        var animationDefinition = FromToByAnimation(to: Transform(translation: [0, 0, 276]), duration: 276, bindTarget: .transform, speed: 1)
        animationDefinition.name = "traversalAnimation"
        let animationResource = try! AnimationResource.generate(with: animationDefinition)

        entity.playAnimation(animationResource, startsPaused: isPaused)
    }

& then use the method in updateUIView's body:

func updateUIView(_ uiView: ARView, context: Context) {
        animateTraversal(of: notePalette, isPaused: !playerModel.isPlaying)
}

So when ever the value of isPlaying changes, the animation should respond to it. However, I'm not sure if this is the most efficient way (since updateUIView is triggered at each frame)...

Treata11 commented 7 months ago

Just another question if you don't mind :)

Is there any way to limit the rendering distance for an ARView? For example, limiting the distance to 10 meters (similar to SceneKit'szFar` property of the camera).