SCNAnimationPlayer()似乎在使用SceneKit时只播放动画的一小部分

问题描述 投票:0回答:1

我在Blender中制作了动画,并将其移至Xcode,并从.dae文件转换为到Xcode的.scn。

我可以在Blender中设计的Xcode场景图中播放动画。

我正在加载几何图形和动画并为动画对象创建节点。

我使用SCNAnimationPlayer()加载动画。代码如下。

let scene = SCNScene(named: "scene.scn")!
let geometry = scene.rootNode.childNode(withName: "animatedGeo",
                                              recursively:true).geometry!

let animationNode = SCNNode(geometry: geometry)


let armature = scene.rootNode.childNode(withName: "Armature", recursively: true)!
let animationPlayer = armature.animationPlayer(forKey: "action_container-Armature")!
animationNode.addAnimationPlayer(animationPlayer, forKey: "action_container-Armature")

rootNode.addChildNode(animationNode)

我没有以编程方式为animationPlayer设置任何内容,因为所有设置看起来在Xcode的场景图形窗口中可以。

但是,当场景加载时,我在iPhone屏幕上看到动画对象上有一个小的移动。看起来只有第一个(父)骨骼动画正在播放。我找不到为什么所有动画都无法在场景图中播放的原因。

ios swift animation scenekit
1个回答
0
投票

是的,当我尝试以编程方式操纵我在Blender中设计和动画的对象而不是我在Blender中制作的动画时,我发现了如何做。

您要做的是将“ Armature”节点添加到对象的节点。这就是全部。您不必使用SCNAnimationPlayer()。

let scene = SCNScene(named: "scene.scn")!
let geometry = scene.rootNode.childNode(withName: "animatedGeo", recursively: true)!
let myObjectNode = SCNNode(geometry: geometry)  
let myObjectArmaturNode = scene.rootNode.childNode(withName: "Armature", recursively: true)!

rootNode.addChildNode(myObjectNode)
myObjectNode.addChildNode(myObjectArmaturNode)     

就是这样。动画的运行就像在Blender中设计的一样。动画由4条骨头组成。

© www.soinside.com 2019 - 2024. All rights reserved.