【发布时间】:2018-07-16 03:05:59
【问题描述】:
我尝试在 ARKit 应用程序中从服务器 URL 动态加载 .scn 和纹理文件。我已经实现了从 web url this 方式加载 .scn 文件。但运行后我在设备上看不到任何纹理。我收到以下错误消息。
ARKitExample[3016:995067] [SceneKit] Error: Failed loading : <C3DImage 0x1d42e1980 src:file:///var/containers/Bundle/Application/622ACF79-2318-4953-A9AE-9A7F2B453AFB/ARKitExample.app/textures/lamp_DIFFUSE.png [0.000000x0.000000]>
ARKitExample[3016:995067] [SceneKit] Error: Failed loading : <C3DImage 0x1d00fe800 src:file:///var/containers/Bundle/Application/622ACF79-2318-4953-A9AE-9A7F2B453AFB/ARKitExample.app/textures/lamp_NORMAL.png [0.000000x0.000000]>
ARKitExample[3016:995067] [SceneKit] Error: Failed loading : <C3DImage 0x1d40ff800 src:file:///var/containers/Bundle/Application/622ACF79-2318-4953-A9AE-9A7F2B453AFB/ARKitExample.app/textures/lamp_METALLIC.png [0.000000x0.000000]>
ARKitExample[3016:995067] [SceneKit] Error: Failed loading : <C3DImage 0x1d42e0d80 src:file:///var/containers/Bundle/Application/622ACF79-2318-4953-A9AE-9A7F2B453AFB/ARKitExample.app/textures/lamp_ROUGHNESS.png [0.000000x0.000000]>
ARKitExample[3016:995067] [SceneKit] Error: Failed loading : <C3DImage 0x1d02e2e00 src:file:///var/containers/Bundle/Application/622ACF79-2318-4953-A9AE-9A7F2B453AFB/ARKitExample.app/textures/lamp_SHADOW.png [0.000000x0.000000]>
如何解决这个问题。谢谢
@Xartec 我试过你提到的方法,但我没有得到任何回应。我该如何解决?
let urlString = "\("https://d533c2fd.ngrok.io/")\("mode")"
let url = URL.init(string: urlString)
let request = URLRequest(url: url!)
let session = URLSession.shared
let downloadTask = session.downloadTask(with: request,
completionHandler: { (location:URL?, response:URLResponse?, error:Error?)
-> Void in
print("location:\(String(describing: location))")
let locationPath = location!.path
// let documents:String = NSHomeDirectory() + "/Documents/"+"\(self.modelName).\(self.fileExtension)"
// let documents:String = NSHomeDirectory() + "/Documents/"+"\("model5").\("scn")"
let documents:String = NSHomeDirectory() + "/Documents/"+"\("mode")"
ls = NSHomeDirectory() + "/Documents"
let fileManager = FileManager.default
if (fileManager.fileExists(atPath: documents)){
try! fileManager.removeItem(atPath: documents)
}
try! fileManager.moveItem(atPath: locationPath, toPath: documents)
print("new location:\(documents)")
let node = SCNNode()
do {
let documentss = documents + "\("model5").\("scn")"
let scene = try SCNScene(url: URL(fileURLWithPath: documentss), options: [.overrideAssetURLs: true])
let nodess = scene.rootNode.childNode(withName: "SketchUp", recursively: true)
node.addChildNode(nodess!)
self.addChildNode(node)
self.modelLoaded = true
} catch {}
})
downloadTask.resume()
【问题讨论】:
-
@Xartec 这是重复的......但是,早期的提问者没有找到解决纹理无法从远程 URL 动态加载的 scn 文件的问题的解决方案。有什么想法吗?
-
解决方案在该问题的第一个也是唯一的答案中描述,在 OP 说他没有找到解决方案一周后发布:“你应该下载文件及其纹理,然后加载场景。请注意,.scn 文件和纹理应该在同一个目录中,除非您想添加一些加载选项。”
-
@Xartec 我已经更新了我的问题,请检查。
-
我负责下载一个包含 3D 模型(在我的例子中是 mtl/obj)和所有需要的纹理的 zip。回家后我会发布相关代码
标签: ios swift arkit scnnode scnscene