Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 468
HeySaiK Avatar asked Mar 18 '18 21:03

HeySaiK


2 Answers

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!

like image 84
Eugene Avatar answered Oct 06 '22 02:10

Eugene


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)

like image 22
Nico Prasetyo Avatar answered Oct 06 '22 04:10

Nico Prasetyo