RealityKit – Playing multiple animations in USDZ file

Viewed 973

Has anyone found a workflow to create multiple animations for a skeletal mesh packaged in a USDZ file and playback the animations using RealityKit?

I have a skeletal mesh with two animations (idle & run). I want to package them into a single USDZ file (or even multiple USDZ files if I have to) to be used in RealityKit.

I have been able to create an FBX for export of my skeletal mesh and the animations, and ship them up to sketchfab for a valid USDZ export that RealityKit can understand. I do not know how to package the second animation into a single USDZ file and then use SWIFT to playback the specific animations based off of specific events.

There seem to be a lot of posts from about a year ago on the topic with no real answers and little activity since. Any pointers would be appreciated.

1 Answers

Although in SceneKit you can play multiple animations using .dae model, in RealityKit 2.0 you still have no possibility to play multiple animations found in any .usdz model. Look at this post and this post.

There is only one animation is accessible using the following code now:

let robot = try ModelEntity.load(named: "drummer")
let anchor = AnchorEntity()
anchor.children.append(robot)
arView.scene.anchors.append(anchor)

robot.playAnimation(robot.availableAnimations[0].repeat(duration: .infinity), 
                                              transitionDuration: 0.5, 
                                                    startsPaused: false)

When you choose second or third element in collection (if it really exists), your app crashes:

modelWithMultipleAnimations.availableAnimations[1]
modelWithMultipleAnimations.availableAnimations[2]
Related