【发布时间】:2017-09-09 10:57:32
【问题描述】:
我有一个实现以下方法的 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。
【问题讨论】:
-
在头部不旋转的情况下,头部看起来是已经旋转了,还是看起来根本没有旋转?
-
它完全不动,保持在起始位置。
-
我想知道场景是否有时没有完全初始化......你说你已经记录了几乎所有东西---你确认 man 和 headBone 在旋转的情况下不是 nil不会发生?
-
是的,我确实证实了这一点(而且 animation1 不是零)。如果您有兴趣,我会将项目上传到airxygene.fr/transfer/3DTests.zip。这是一个简单的“构建场景,添加动画”测试。如果您多次构建并运行它,您应该在不更改任何代码的情况下看到这两种行为。我正在使用 XCode 8.3 (8E162) 和 macOS Sierra。
-
我认为您的 headBone 已经附加了动画。在
awakeFromNib中调用[headBone removeAllAnimations];似乎让动画每次都能为我工作。