Reputation: 154
I'm downloading a collada file from a web server and would like to map textures programmatically, but there's SCNGeometry is nil. Can anyone give a suggestion? Below is sample code.
let url = URL(string: "https://s3.amazonaws.com/path/to/dae.dae")!
let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
Alamofire.download(
url,
method: .get,
parameters: nil,
encoding: JSONEncoding.default,
headers: nil,
to: destination).downloadProgress(closure: { (progress) in
print(progress)
}).response(completionHandler: { (DefaultDownloadResponse) in
let path = DefaultDownloadResponse.destinationURL
let node = SCNReferenceNode(url: path!)
node?.load()
print(node)
print(node?.geometry)
self.sceneView.scene.rootNode.addChildNode(node!)
})
Upvotes: 0
Views: 789
Reputation: 154
I found the answer. SCNReferenceNode contains an array of nodes, so in order to assign a texture, you need to index into it.
node?.childNodes.first?.geometry?.firstMaterial?.diffuse.contents = UIImage(named: "example.png")
Upvotes: 1