Importing .scn file to scene from URL with textures

南笙酒味 提交于 2019-12-04 12:53:25

问题


I am using ARKit for my application and I try to dynamically load .scn files from web-server

Here is a part of my code

    let url = URL(string: "http://192.168.0.31:1234/5a27e09cbad20a7a03ad5d80/box/box.scn")
    if let objectScene = try? SCNScene(url: url!, options: [.overrideAssetURLs: true]) {
        print("load success")
        let node = SCNNode()
        for childNode in objectScene.rootNode.childNodes {
            node.addChildNode(childNode)
        }

        sceneView.scene.rootNode.addChildNode(node)
    } else {
        print("error loading")
    }

here box.scn contains textures. And I got an error

Failed loading: C3DImage 0x1c00f6f80 src:file:///var/containers/Bundle/Application/110F7AB6-00F8-4E5B-B843-46551A23CB7F/ar.app/maps/CMU_Split_Face_Running_200x400_bump.jpg [0.000000x0.000000]

Why Scenekit tries to load this textures from local file ? How can I fix it?


回答1:


You should download the file along with its textures, and then load the scene. Note that the .scn file and the textures should be in the same directory unless you want to add some loading options.

After downloading a .scn file with a texture from the server, I used this code to display the object:

do {
        let scene = try SCNScene(url: URL(fileURLWithPath: "YourDownloadedScnFilePath") , options: nil)

        // Set the scene to the view
        sceneView.scene = scene
    } catch {
        print("ERROR loading scene")
    }


来源:https://stackoverflow.com/questions/47677954/importing-scn-file-to-scene-from-url-with-textures

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