【发布时间】:2018-05-30 21:33:18
【问题描述】:
我使用 Scenekit/ARKit 编写代码,使用 Blender 编写 3D 模型。我有一个带有一些关键帧动画的 3D 模型 - 在 Blender 中创建,它已轻松导出到 XCode 中。没什么复杂的——它只是一只猫在上下移动。
我在我的 tapGestureRecognizer 中使用动画控件。加载视图后,我将动画设置为暂停状态:-
nonGeometryObjectNode?.childNode(withName: "Armature", recursively: true)?.animationPlayer(forKey: "cat_animated-1")?.paused = true
点击手势中的动画控件代码如下。
let animationPlayer = hitResults.first?.node.parent?.childNode(withName: "Armature", recursively: true)?.animationPlayer(forKey: "cat_animated-1")
animationPlayer?.animation.autoreverses = true
animationPlayer?.animation.repeatCount = 1
animationPlayer?.animation.duration = 0.8
animationPlayer?.animation.blendInDuration = 0.2
animationPlayer?.animation.blendOutDuration = 0.2
animationPlayer?.paused = true
if (animationPlayer?.paused)! {
animationPlayer?.play()
}
它工作正常,唯一的问题是它在第一次执行点击时只工作一次。我尝试在我的 tapGesture 代码中使用.paused、.stop(),但是每次我点击它时,animationPlayer 都不会像它应该的那样重播。 SCNAnimationPlayer 中没有 bool var,否则我可以使用它来检测动画是否已经播放完毕,这样我就可以使用.stop(),然后再次使用.play()。
我确实看到了两个实例变量 animationDidStart 和 animationDidStop,我认为它们可能对管理我需要的内容很有用。但我不知道如何使用这些。真正有用的是当我点击对象时应该使用什么来播放和停止/暂停我的动画。任何指针都会有所帮助。
【问题讨论】:
标签: ios swift scenekit blender