HeySaiK
HeySaiK

Reputation: 560

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!

Upvotes: 6

Views: 5396

Answers (2)

Nico Prasetyo
Nico Prasetyo

Reputation: 11

I think I found a solution too for this problem since im having the same issue

Write:

node.geometry?.firstmaterial?.diffuse.contents = #imageLiteral(resourceName: “yourimagename”)

Note that you have to add the image inside the assets first (as an image set of course)

Upvotes: 1

Yevhen
Yevhen

Reputation: 1068

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!

Upvotes: 13

Related Questions