0

I've been following a tutorial to create an AR Ruler. Therefore, with the code below, I'm able to place 3D sphere's in my scene (which im looking to keep for the tracking functionality). However, instead of a 3d image, I'm looking to place an image. I attempted changing the dotGeometry and setting it to a UIImage and commenting out the material code but wasn't sure how to deal with with dotNode piece of code. Therefore, how would I be able to set my image as the resulting on-screen addition?

let dotGeometry = SCNSphere(radius: 0.005)
    let material = SCNMaterial()
    material.diffuse.contents = UIColor.red

    dotGeometry.materials = [material]

    let dotNode = SCNNode(geometry: dotGeometry)

    dotNode.position = SCNVector3(hitResult.worldTransform.columns.3.x, hitResult.worldTransform.columns.3.y, hitResult.worldTransform.columns.3.z)

    sceneView.scene.rootNode.addChildNode(dotNode)
jonpeter
  • 599
  • 8
  • 28
  • 1
    What shape is something 2D when you consider the third dimension? A plane. See `SCNPlane`, and use `SCNBillboardConstraint` if you want to keep it always pointed at the camera. – rickster Sep 29 '17 at 20:59

1 Answers1

2

You could create a SCNBox and set its length to a very small value to make it appear flat.

let box = SCNBox(width: 0.2, height: 0.2, length: 0.005, chamferRadius: 0)
let material = SCNMaterial()
material.diffuse.contents = UIImage(named: "image.png")
box.materials = [material]

boxNode = SCNNode(geometry: box)
boxNode.opacity = 1.0
boxNode.position = SCNVector3(0,0,-0.5)

scene.rootNode.addChildNode(boxNode)

Or you could follow another approach and add an overlay SKScene (2D) to the SCNScene(3D) as described here : How can I overlay a SKScene over a SCNScene in Swift?

nagam11
  • 133
  • 1
  • 9