title: Scenekit - adding UIImage material to custom geometry
body: <p>I'm running this in ARKit and if you try it out, the triangle appears (very tall) and 2 the right of the camera, pan round a little. The problem I have is that I can't apply an image material to the object, I can change it's colour, but not apply image:</p>
  
  <p>So this works:</p>
  
  <pre><code>triangle.firstMaterial?.diffuse.contents = UIColor.red
  </code></pre>
  
  <p>But this doesn't:</p>
  
  <pre><code>triangle.firstMaterial?.diffuse.contents = UIImage(named: "wallpaper.jpg")
  </code></pre>
  
  <p>Here is the complete ViewController code from a fresh ARKit project in Xcode9:</p>
  
  <pre><code>import UIKit
  import SceneKit
  import ARKit
  
  class ViewController: UIViewController, ARSCNViewDelegate {
  
      @IBOutlet var sceneView: ARSCNView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          sceneView.delegate = self
  
          let scene = SCNScene()
  
          let triangle = SCNGeometry.triangleFrom(vector1: SCNVector3(x: 0.059511181, y: -0.181795284, z: -0.0939711183), vector2: SCNVector3(x: 0.113824688, y: -0.181780666, z: -0.0674673915), vector3: SCNVector3(x: 0.113824688, y: 1.8182193, z: -0.0674673915))
  
          triangle.firstMaterial?.diffuse.contents = UIImage(named: "wallpaper.jpg")
  
          let triangleNode = SCNNode(geometry: triangle)
  
          triangleNode.name = "Triangle"
  
          scene.rootNode.addChildNode(triangleNode)
  
          sceneView.scene = scene
  
      }
  
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
  
          // Create a session configuration
          let configuration = ARWorldTrackingSessionConfiguration()
  
          // Run the view's session
          sceneView.session.run(configuration)
      }
  
      override func viewWillDisappear(_ animated: Bool) {
          super.viewWillDisappear(animated)
          sceneView.session.pause()
      }
  
  }
  
  extension SCNGeometry {
      class func triangleFrom(vector1: SCNVector3, vector2: SCNVector3, vector3: SCNVector3) -&gt; SCNGeometry {
  
          let indices: [Int32] = [0, 1, 2]
  
          let source = SCNGeometrySource(vertices: [vector1, vector2, vector3])
  
          let element = SCNGeometryElement(indices: indices, primitiveType: .triangles)
  
          return SCNGeometry(sources: [source], elements: [element])
      }
  }
  </code></pre>
  
  <p>The only thing I've not included is the texture image but any image downloaded will do.</p>
  
  <p>Thanks</p>