I have a SceneKit SCNSceneRendererDelegate that implement the following method :
- (void) renderer:(id<SCNSceneRenderer>)renderer
didRenderScene:(SCNScene*)scene
atTime:(NSTimeInterval)time
{
static NSUInteger counter = 0 ;
counter++ ;
// Rotate via animation
if (counter==1)
{
SCNNode *man = [scene.rootNode childNodeWithName:@"Man" recursively:YES] ;
SCNNode *headBone = [man childNodeWithName:@"mixamorig_Head" recursively:YES] ;
CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"rotation"] ;
animation1.fromValue = [NSValue valueWithSCNVector4:headBone.rotation] ;
animation1.toValue = [NSValue valueWithSCNVector4:SCNVector4Make(0,1,0,M_PI_4)] ;
animation1.duration = 1.2 ;
animation1.fillMode = kCAFillModeForwards ;
animation1.removedOnCompletion = NO ;
[headBone addAnimation:animation1 forKey:@"rotationAnimation"] ;
}
}
Obviously, this is just rotating a bone named "mixamorig_Head" by 45 degrees.
When I run the program, I can actually see the head rotating... only one time out of 2.
The only thing I do is click on the run button of XCode. The program starts and show the scene, with the head rotating... or not. There is no code update in between runs, just click on the run button.
I have tried to log every variable, and everything seems correct.
Any idea why SceneKit behaviour could be different from one run to another ?
Edit Upload a demo project here.
[headBone removeAllAnimations];
inawakeFromNib
seems to make the animation work every time for me. – James P