ARKitAnimation
ARKitAnimation copied to clipboard
Load Animations?
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
}
}
It seems as though it's not returning True here:
if let animationObject = sceneSource?.entryWithIdentifier(animationIdentifier, withClass: CAAnimation.self) {
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
:
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.
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
hi when multi animation includes dae , how can play animation?
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