【问题标题】:SceneKit Swift3 compiler-errorSceneKit Swift3 编译器错误
【发布时间】:2017-09-02 17:00:41
【问题描述】:

我正在尝试在 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'

请帮我解决这个问题。

提前致谢。

【问题讨论】:

    标签: animation compiler-errors 3d swift3 scenekit


    【解决方案1】:

    为什么要将[String]? 转换为NSArray,然后将每个元素再次转换为String,不需要它,只需使用Swift 原生Array 并用if letguard 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
    

    【讨论】:

    • 感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-04
    • 2013-05-05
    • 2011-01-02
    • 2011-12-22
    • 2011-08-10
    相关资源
    最近更新 更多