2017-04-13 77 views
2

我有一個SceneKit SCNSceneRendererDelegate實現下面的方法:不可預知的SceneKit行爲?

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

顯然,這只是旋轉了45度,名爲「mixamorig_Head」骨。

當我運行該程序時,我實際上可以看到頭部旋轉... 只有一次出來了2

我唯一要做的就是點擊XCode的運行按鈕。節目開始並顯示場景,頭部旋轉或不旋轉。在運行之間沒有代碼更新,只需點擊運行按鈕即可。

我試圖記錄每個變量,並且一切都看起來正確。

任何想法爲什麼SceneKit行爲可能會因一次跑到另一次而有所不同?

編輯 上傳演示項目here

+0

在頭不旋轉的情況下,做頭似乎有*已經旋轉,還是看起來沒有旋轉過? –

+0

它根本不動,仍然處於起始位置。 –

+0

我不知道這個場景是否有時候沒有完全初始化......你說你已經記錄了幾乎所有的東西---你是否證實在沒有發生旋轉的情況下man和headBone不是零? –

回答

1

我看了一下DAE文件,發現所有的骨骼都附有動畫。這在添加新動畫時似乎是個問題,並且它們並不總是有效。 (不知道爲什麼它有時而不是其他)。

您可以刪除SceneKit編輯器中所有的動畫,或要動畫節點編程刪除:

[headBone removeAllAnimations];