Search code examples
swiftscenekitarkitswift-playground

How to add an image to an ARSCNScene in Swift?


I stumbled upon a roadblock with the development of a Swift playground I'm developing. I want to add an image to my ARSCNScene (ARKit + SceneKit). Not as a background, but as an actual node with positions and all. Does anyone know whether this is possible? I couldn't find anything online. Thanks!


Solution

  • You can easily add UIImage as diffuse material to your SCNPlane. Example:

        let image = UIImage(named: "yourImageName")
        let node = SCNNode(geometry: SCNPlane(width: 1, height: 1))
        node.geometry?.firstMaterial?.diffuse.contents = image
    

    Further, you can modify your node as you like. I hope it helped!