Reputation: 2908
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?
Upvotes: 5
Views: 2780
Reputation: 19
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")
}
Upvotes: 1