If a USDZ file can play multiple animations?

I have a single fbx model with several animations(idle, walk, run, eat......), but after I convert it to usdz format, I can only play 1 animation, where can I find other animations and how can I play them, or USDZ doesn't support it yet?

Thank you.
Cyan

Replies

In a previous project I needed to create separate USDZ files for each animation - one animation per USDZ file. I loaded the first USDZ model and kept both the model and animation. For additional animations I loaded the USDZ file, kept the animation, and dumped the model part. I could then apply the animations to the full model I loaded first.

I split the animation files into individuals, zip them and then apply files from the zip archive as needed.

Put the new animation in a separate USDZ file and load it to the code then apply each when needed on the desired entity, which should be identical to the entity that have the external animation.

import SwiftUI
import RealityKit

struct ImmersiveView: View {
    @State var entity = Entity()

    @State var extEntity = Entity()

    var body: some View {
        RealityView { content in

            //Loading Main USDZ With Main Animation And Link it
            let mainAnim = try! await Entity(named: "main.usdz")
            if let item = mainAnim.findEntity(named: "SOME ENTITY") 
            {
                entity = item        // The Entity of the object you want to animate
                content.add(entity)
            }

            //Loading External Animation And Link it
            let extAnim = try! await Entity(named: "external.usdz")
            if let item = extAnim.findEntity(named: "SOME ENTITY") 
            {
                externalEntity = item       // The Entity Of the Object have the external Animation
            }

Then somewhere in your code when you want to apply the external animation

             func playExtraAnimation()
             {
                    entity.playAnimation(extEntity.availableAnimations[0], transitionDuration: duration , startsPaused: true)
             }