How to know if a usdz model contains animations & animate it in iOS swift using SceneKit?

65 views Asked by At

I need help in understand how to know if a usdz model contains animation & if yes animate it from one state to another state. Below is my code

class ViewController: UIViewController {
    
    
    @IBOutlet weak var sceneKitView: SCNView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        load3dModelFromAsset()
    }
    
    func load3dModelFromAsset(){
        
        let scene = SCNScene(named: "fox.usdz")
      
        let lightNode = SCNNode()
        lightNode.light = SCNLight()
        lightNode.light?.type = .omni
        lightNode.position = SCNVector3(x: 0, y: 10, z: 35)
        scene?.rootNode.addChildNode(lightNode)
        
        let ambientLightNode = SCNNode()
        ambientLightNode.light = SCNLight()
        ambientLightNode.light?.type = .ambient
        ambientLightNode.light?.color = UIColor.darkGray
        scene?.rootNode.addChildNode(ambientLightNode)
        
        sceneKitView.allowsCameraControl = true
        
        sceneKitView.backgroundColor = UIColor.white
        
        sceneKitView.cameraControlConfiguration.allowsTranslation = false
        
        
        sceneKitView.scene = scene
        

        debugPrint("length \(String(describing: scene?.rootNode.animationKeys.count))")
        if let animationKeys = scene?.rootNode.animationKeys {
            for key in animationKeys {
                print("Animation Key: \(key)")
            }
        }
    }
}

When I try to print the animation keys count in my above code I always get zero. I have used usdz model from over here

I am not sure if the models present in above url has multiple animations or not as I want to animate from one state to the other

Another way I tried was using gltf model of this fox which contains 3 states of animations so i opened it in blender and click on the export button as usd and then I opened the usd file in Xcode and again exported it in usdz. While exporting from blender I did check the animations checkbox as well but still when I run the code I get the animation keys as zero.

I am not a 3d artist so don't know how to create a usdz model of my own with animations

0

There are 0 answers