使用纹理从URL导入.scn文件到场景 [英] Importing .scn file to scene from URL with textures

查看:238
本文介绍了使用纹理从URL导入.scn文件到场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序使用ARKit,我尝试从web-server动态加载.scn文件

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

这是我的代码的一部分

    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")
    }

此处 box.scn 包含纹理。我收到错误

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


加载失败: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]

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]

为什么Scenekit会尝试加载这个纹理来自本地文件?
如何解决?

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

推荐答案

您应该下载文件及其纹理,然后加载场景。请注意,除非要添加一些加载选项,否则.scn文件和纹理应位于同一目录中。

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.

下载带有纹理的.scn文件后服务器,我使用此代码显示对象:

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")
    }

这篇关于使用纹理从URL导入.scn文件到场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆