How to make an animation stop at the last frame after playing with xcode+RCP

This is my animation playback method, there are two issues.

1.How to make the animation stop until the last frame after playing once when isLoop=false?

  1. When I specify the name of an animClipName animation clip, I cannot play the corresponding animation name. How do I set it up?

The animation structure is shown in the figure.

 PlayAnim(animEntityName: "Book",animClipName: "Open",isLoop: false)

 private func PlayAnim(animEntityName: String,animClipName: String? = nil,isLoop:Bool = true,transitionDuration: Double = 0.5){
    
    guard let XR = XR else { return }
    guard let entity = XR.findEntity(named: animEntityName) else {
        return
    }
    
    let availableAnims = entity.availableAnimations
    
    let targetAnimResource: AnimationResource?
   
    if let clipName = animClipName {
        targetAnimResource = availableAnims.first(where: { $0.name == clipName })
    } else {
        targetAnimResource = availableAnims.first
    }
    guard let animClip = targetAnimResource else {
        return
    }
   
    let anim = animClip.repeat(count: isLoop ? 0 : 1)
    entity.playAnimation(anim,transitionDuration: transitionDuration)
}

Something like this might help:

    guard let animClip = targetAnimResource else { return }

    let anim: AnimationResource
    if isLoop {
        anim = animClip.repeat(count: 0) 
    } else if let def = animClip.definition {
        // Play once, hold the final pose.
        let view = AnimationView(
            source: def,
            name: animClip.name ?? "",
            bindTarget: nil,
            blendLayer: 0,
            repeatMode: .none,
            fillMode: .forwards, // this is the important bit to get the animation to 'stop' at the completed values
            trimStart: nil, trimEnd: nil, trimDuration: nil,
            offset: 0, delay: 0, speed: 1.0
        )
        anim = (try? AnimationResource.generate(with: view)) ?? animClip
    } else {
        anim = animClip
    }

    entity.playAnimation(anim, transitionDuration: transitionDuration)

You can read the docs here: https://developer.apple.com/documentation/realitykit/animationfillmode/forwards

How to make an animation stop at the last frame after playing with xcode+RCP
 
 
Q