ARKitAnimation icon indicating copy to clipboard operation
ARKitAnimation copied to clipboard

Load Animations?

Open arkwl opened this issue 7 years ago • 6 comments

Hello!

So ive tried to follow your tutorial here: https://blog.pusher.com/animating-3d-model-ar-arkit-mixamo/ and my code is identical to yours but im getting an error thrown at playAnimation(...) because the animations array is empty even though loadAnimations(...) is called. Any explanation? Im fairly new to Swift.

     loadAnimation(withKey: "dancing", sceneName: "IdleFixed", animationIdentifier: "samba_danceFixed-1")
    }
    
    func loadAnimation(withKey: String, sceneName:String, animationIdentifier:String) {
        let sceneURL = Bundle.main.url(forResource: sceneName, withExtension: "dae")
        let sceneSource = SCNSceneSource(url: sceneURL!, options: nil)
        
        if let animationObject = sceneSource?.entryWithIdentifier(animationIdentifier, withClass: CAAnimation.self) {
            // The animation will only play once
            animationObject.repeatCount = 1
            // To create smooth transitions between animations
            animationObject.fadeInDuration = CGFloat(1)
            animationObject.fadeOutDuration = CGFloat(0.5)
            
            // Store the animation for later use
            animations[withKey] = animationObject
        }
    }

arkwl avatar Jan 30 '18 04:01 arkwl

It seems as though it's not returning True here:

if let animationObject = sceneSource?.entryWithIdentifier(animationIdentifier, withClass: CAAnimation.self) {

arkwl avatar Jan 30 '18 04:01 arkwl

Hi!

According to the line:

loadAnimation(withKey: "dancing", sceneName: "IdleFixed", animationIdentifier: "samba_danceFixed-1")

You're trying to load the animation samba_danceFixed-1 from the file IdleFixed.dae. Shouldn't be something like samba_danceFixed.dae?

You should have one DAE file for the idle position and another one for the dancing animation and you should load the dancing animation calling loadAnimation with the latter.

Otherwise, probably there's something wrong with the DAE file.

Check if your dancing animation file has only one animation node and that its identifier is samba_danceFixed-1: screen shot 2018-01-29 at 23 35 48

eh3rrera avatar Jan 30 '18 05:01 eh3rrera

converting the .dae to .scn the animation is still there. But the method sceneSource?.entryWithIdentifier return nothing. even tho the node has the animation keys.

omarojo avatar Aug 08 '18 22:08 omarojo

Hi @omarojo.

Sorry, I never tried with a SCN file, and right now I cannot help you, my mac broke a few months ago and I have been disconnected from the iOS world since then.

But are you using the latest version of XCode? If so, maybe entryWithIdentifier is now deprecated or there's a new API for this.

Maybe someone else can see this issue and help.

eh3rrera avatar Aug 09 '18 19:08 eh3rrera

@eh3rrera

hi when multi animation includes dae , how can play animation?

J-Arji avatar Mar 28 '20 22:03 J-Arji

Hi @J-Arji

I haven't programmed in ARKit for a while, but if I remember correctly, each animation has an identifier, so I guess you just have to get the animation you want by its identifier and then play it.

The code shown in these links might help you: https://riptutorial.com/scenekit/example/23522/load-an-animation-from-a-collada-or-scn-file https://stackoverflow.com/questions/29692388/scenekit-stop-continuously-looping-collada-animation

eh3rrera avatar Mar 29 '20 18:03 eh3rrera