不可预测的 SceneKit 行为?

Unpredictable SceneKit behaviour?

我有一个实现以下方法的 SceneKit SCNSceneRendererDelegate :

- (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"] ;
    }
}

显然,这只是将名为 "mixamorig_Head" 的骨骼旋转 45 度。

当我运行程序时,我实际上可以看到头部在旋转...2次中只有一次

我唯一要做的就是点击 XCode 的 运行 按钮。程序启动并显示场景,头部旋转……或不旋转。在 运行 秒之间没有代码更新,只需单击 运行 按钮。

我尝试记录每个变量,一切似乎都是正确的。

知道为什么 SceneKit 的行为可能不同于一个 运行 另一个吗?

编辑 上传一个演示项目 here.

我查看了 DAE 文件,发现所有骨骼都附有动画。这似乎是添加新动画时的一个问题,而且它们并不总是有效。 (不知道为什么它有时有效而不是其他)。

您可以删除 SceneKit 编辑器中的所有动画,或者以编程方式从您要设置动画的节点中删除它们:

[headBone removeAllAnimations];