Darko Dujmović
Aug 9, 2017 · 1 min read

For people working with Swift

func createPlaneNode(anchor: ARPlaneAnchor) -> SCNNode {

// Create a SceneKit plane to visualize the node using its position and extent.

// Create the geometry and its materials

let plane = SCNPlane(width: CGFloat(anchor.extent.x), height: CGFloat(anchor.extent.z))

let lavaImage = UIImage(named: “greenGrid”)

let lavaMaterial = SCNMaterial()

lavaMaterial.diffuse.contents = lavaImage

lavaMaterial.isDoubleSided = true

plane.materials = [lavaMaterial]

// Create a node with the plane geometry we created

let planeNode = SCNNode(geometry: plane)

planeNode.position = SCNVector3Make(anchor.center.x, 0, anchor.center.z)

// SCNPlanes are vertically oriented in their local coordinate space.

// Rotate it to match the horizontal orientation of the ARPlaneAnchor.

planeNode.transform = SCNMatrix4MakeRotation(-Float.pi / 2, 1, 0, 0)

let width = plane.width

let height = plane.height

let material = plane.materials.first

material!.diffuse.contentsTransform = SCNMatrix4MakeScale(Float(width), Float(height), 1)

material!.diffuse.wrapS = SCNWrapMode.repeat

material!.diffuse.wrapT = SCNWrapMode.repeat

return planeNode

}

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {

guard let planeAnchor = anchor as? ARPlaneAnchor else { return }

let planeNode = createPlaneNode(anchor: planeAnchor)

node.addChildNode(planeNode)

}

    Darko Dujmović

    Written by

    iOS developer