将 .scn 文件从带有纹理的 URL 导入场景 [英] Importing .scn file to scene from URL with textures

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

问题描述

我正在为我的应用程序使用 ARKit,并尝试从网络服务器动态加载 .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_000x0mp.0000x000000000000000000007>

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

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

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