gpt4 book ai didi

animation - SceneKit Swift3 编译器错误

转载 作者:行者123 更新时间:2023-12-02 11:00:26 25 4
gpt4 key购买 nike

我正在尝试在 SceneKit 中运行动画“DAE”模型:

let url = Bundle.main.url(forResource: "art.scnassets/Player(walking)", withExtension: "dae")
let sceneSource = SCNSceneSource(url: url!, options: [SCNSceneSource.LoadingOption.animationImportPolicy: SCNSceneSource.AnimationImportPolicy.playRepeatedly] )
let animationIds: NSArray = sceneSource?.identifiersOfEntries(withClass: CAAnimation)

for eachId in animationIds {
let animation: CAAnimation = (sceneSource?.entryWithIdentifier(eachId as! String, withClass: CAAnimation.self))!
animations.add(animation)
}
character?._walkAnimations = animations

但是编译器它抛出就行了:

让 animationIds: NSArray = sceneSource?.identifiersOfEntries(withClass: CAAnimation)

并写出错误:

无法转换类型“[String]?”的值到指定类型 'NSArray'

请帮我解决这个问题。

提前致谢。

最佳答案

为什么要转换 [String]?NSArray然后将每个元素转换为 String再次,不需要它,只需使用 Swift native Array并用 if let 包装可选值或 guard let .

guard let animationIds = sceneSource?.identifiersOfEntries(withClass: CAAnimation) else {
return
}
for eachId in animationIds {
if let animation = sceneSource?.entryWithIdentifier(eachId, withClass: CAAnimation.self) {
animations.add(animation)
}
}
character?._walkAnimations = animations

关于animation - SceneKit Swift3 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43275928/

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