ARkit - Loading .scn file from Web-Server URL in SCNScene

两盒软妹~` 提交于 2019-12-02 21:04:38

About init?(named: String), the documentation says:

Loads a scene from a file with the specified name in the app’s main bundle

since you don't have such file inside the main bundle (is coming from a download), you may try with the following constructor:

init(url: URL, options: [SCNSceneSource.LoadingOption : Any]? = nil)

so your code might be:

do {
   let documents = "yourValidPath"
   let scene = try SCNScene(url: URL(fileURLWithPath: documents), options: nil)
} catch {}
    let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
    let pathToObject = documentDirectory + "ship.scn"
    let fileUrl = URL(fileURLWithPath: pathToObject)

    guard let cshipScene = try? SCNScene(url: fileUrl, options: nil) else { return }
    let shipNode = SCNNode()
    let shipSceneChildNodes = shipScene.rootNode.childNodes
    for childNode in shipSceneChildNodes {
        shipNode.addChildNode(childNode)
    }

    node.addChildNode(shipNode)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!