gpt4 book ai didi

swift - 如何根据要求在 SceneKit 中添加动画

转载 作者:可可西里 更新时间:2023-11-01 02:18:43 27 4
gpt4 key购买 nike

如果您能帮我将此动画添加到场景中,或者您知道如何将动画添加到场景中,将不胜感激。

代码:

let BallScene = SCNScene(named: "art.scnassets/Ball.dae")!
let ManScene = SCNScene(named: "art.scnassets/Genric_Simplifiyed9.dae")!
let Man: SCNNode = ManScene.rootNode.childNodeWithName("Bob_001", recursively: true)!
Man.position = SCNVector3(x: 0, y: 0, z: 5)
BallScene.rootNode.addChildNode(Man)

let Animation: CAAnimation
let AnimationUrl: NSURL = NSBundle.mainBundle().URLForResource("art.scnassets/Genric_Simplifiyed9.dae", withExtension: "dae")!
let sceneSource = SCNSceneSource(URL: AnimationUrl, options: [SCNSceneSourceAnimationImportPolicyKey : SCNSceneSourceAnimationImportPolicyDoNotPlay])

sceneSource.addAnimation(attackAnimation, forKey: "attack”)

最佳答案

如果您有带动画的 DAE/COLLADA 文件,您只需单击播放按钮即可在 Storyboard中播放动画。然后你就可以

let subScene = SCNScene(named: "art.scnassets/test_ball_2011.dae")!
let childNodes = subScene.rootNode.childNodes
for child in childNodes {
//child.position = SCNVector3(0, 0, -100)
rootScene.rootNode.addChildNode(child)
}

动画将在您的 rootScene 中播放

你可以使用

for child in childNodes {
let keys = child.animationKeys
child.position = SCNVector3(0, 0, -100)
for key in keys {
let animation = child.animationForKey(key)!
animation.repeatCount = 5
child.removeAnimationForKey(key)
child.addAnimation(animation, forKey: key)
}
rootScene.rootNode.addChildNode(child)

设置位置或重复次数...

另一种方式类似于您的代码:你可以使用

let url = NSBundle.mainBundle().URLForResource(/* your DAE file */)
let sceneSource = SCNSceneSource(URL: url, options: [
SCNSceneSourceAnimationImportPolicyKey : SCNSceneSourceAnimationImportPolicyPlayRepeatedly
])!

要获取源代码并在选项中可以设置很多东西,只需检查 API并使用

let node = sceneSource.entryWithIdentifier("/* the node name */", withClass: SCNNode.self)
let animation = sceneSource.entryWithIdentifier("/* the animation name */", withClass: CAAnimation.self)

获取节点和动画。如果这两个文件在不同的文件中,只需制作 2 个源即可:)最后一件事是 node.addAnimation(animation, forKey: nil)//检查 API

关于swift - 如何根据要求在 SceneKit 中添加动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33492599/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com