I am not able to add an image to the cube in ARKit using the "Material" object.
Here is the code:
import UIKit
import SceneKit
import ARKit
class SimpleBoxViewController: UIViewController, ARSCNViewDelegate {
var sceneView: ARSCNView!
override func viewDidLoad() {
super.viewDidLoad()
self.sceneView = ARSCNView(frame: self.view.frame)
self.view.addSubview(self.sceneView)
sceneView.delegate = self
sceneView.showsStatistics = true
let scene = SCNScene()
let box = SCNBox(width: 0.2, height: 0.2, length: 0.2, chamferRadius: 0)
let material = SCNMaterial()
//This is not working
material.diffuse.contents = UIImage(named: "<someImage>.png")
let node = SCNNode()
node.geometry = box
node.geometry?.materials = [material]
node.position = SCNVector3(0, -0.1, -0.5)
scene.rootNode.addChildNode(node)
sceneView.scene = scene
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let configuration = ARWorldTrackingConfiguration()
sceneView.session.run(configuration)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Pause the view's session
sceneView.session.pause()
}
I tried to add various different images but nothing works. The only image that works is the image named "textures.png" which is preloaded into an ARKit project.
Is there a specific requirement for an image to be to loaded?