【问题标题】:SceneKit: save scn file to diskSceneKit:将 scn 文件保存到磁盘
【发布时间】:2021-11-03 18:40:29
【问题描述】:

目标:将 scn 文件保存到磁盘。

我做了什么: 尝试使用此 API: https://developer.apple.com/documentation/scenekit/scnscene/1523577-write

问题: 得到这个错误: AttributeGraph:通过属性 248096 检测到循环 === 操作无法完成。 (MDLErrorDomain 错误 0。)

非常感谢任何帮助!

  let scnScene = SCNScene(named: "Art.scnassets/Ship")!

//get documents URL
func getDocumentsDirectory() -> URL {
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    return paths[0]
}
  //save scn to disk
    func saveSCNFileToDisk() {
        let url = getDocumentsDirectory()
        scnScene.write(to: url, options: nil, delegate: nil) { float, error, pointer in
            if let error = error {
                print(error.localizedDescription)
                return
            }
            self.scene = url.absoluteString
            
        }
    }

【问题讨论】:

  • 我认为您缺少应该由 url 指定的文件名 + 扩展名 (.scn)?好像只指定了一个文件夹?
  • 抱歉,我没听懂。我应该在哪里指定名称 + 扩展名 (.scn)?

标签: scenekit xcode13


【解决方案1】:

您的代码应按照文档中的说明指定文件方案

//save scn to disk
func saveSCNFileToDisk() {
    let url = getDocumentsDirectory().appendingPathComponent("someFleName.scn)
    scnScene.write(to: url, options: nil, delegate: nil) { float, error, pointer in
        if let error = error {
            print(error.localizedDescription)
            return
        }
        self.scene = url.absoluteString
        
    }
}

【讨论】:

    猜你喜欢
    • 2016-07-22
    • 2013-12-19
    • 2010-09-23
    • 2010-11-08
    • 2019-10-30
    • 2018-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多