ARKit Examples

 

Blend Reality.

 

This powerful ARKit library is updated the very second a new ARKit example arrives on the web.

 

Saint is highly selective of what it chooses and only the highest of quality ARKit examples will be published here.

 

 

Learn more about how you can get your ARKit code, recognition and viewership with Saint (Coming Soon)

 

For now you can submit your ARKit project or code on your GitHub profile and I will personally email you if I find it great to be here on this page.

 

 

 

 

Getting Started with ARKit.

 

Xcode 9 and iOS 11

 

Download iOS 11 Beta and the latest beta of Xcode 9, which includes the iOS 11 SDK to build AR features in your app today.

 

 

 

 

 

Library of ARKit Examples

 

 

FloorIsLava  🔥

 

By Arielle (Ari) Vaniderstine

 

Basic ARKit example that detects planes and makes them lava.

 

 

ARKit Examples

 

 

 

 

 

Requirements

 

  • Xcode 9 (you can view the code in Xcode 8 but will not be able to build the project)

 

  • Device running iOS 11, with an A9 chip or higher (iPhone 6S or newer, iPad Pro)

 

 

 

 

Project Walkthrough

 

Welcome to ARKit!

 

This basic project setup shows how to start an AR session and watch for planes that are detected. We are using an ARSCNView, a specially designed SceneKit view that contains an ARSession.

 

 

 

1. Configuring and starting the session

 

The ARSession gathers data from the world and processes it. Because we want to place objects on horizontal planes, we need to configure the session to detect them:

 

let configuration = ARWorldTrackingSessionConfiguration()
configuration.planeDetection = .horizontal

 

We can then start the session with this configuration by running:

 

sceneView.session.run(configuration)

 

 

 

 

2. Add a SceneKit node to detected planes

 

Next, we override the ARSCNViewDelegate renderer methods. The SceneView will call these methods when AR “anchors” are detected in the world. Since we’ve configured the session to detect horizontal planes, these methods will be called for those as well.

 

In the didAdd method, we check that the discovered node is a plane, then use a helper function to create a simple SceneKit plane. Finally, we add the SceneKit plane as a child of the automatically-generated node for the anchor.

 

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

  guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
  
  let planeNode = createPlaneNode(anchor: planeAnchor)
  
  // ARKit owns the node corresponding to the anchor, so make the plane a child node.
  node.addChildNode(planeNode) 
}

 

 

 

 

3.  Update the SceneKit plane when the AR plane is updated

 

As the user moves the device camera around the world, the session gets more information about anchors. We implement the didUpdate method, which is called when the session updates an existing anchor, so we can update our SceneKit node to match the AR plane.

 

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

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

    // Remove existing plane nodes
    node.enumerateChildNodes {
        (childNode, _) in
        childNode.removeFromParentNode()
    }

    let planeNode = createPlaneNode(anchor: planeAnchor)

    node.addChildNode(planeNode)
}

 

 

 

 

4. Remove the SceneKit plane when the AR plane is removed

 

Finally, we implement the didRemove delegate method to remove any SceneKit planes we’ve created if a plane is removed from the world.

 

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

    guard anchor is ARPlaneAnchor else { return }

    // Remove existing plane nodes
    node.enumerateChildNodes {
        (childNode, _) in
        childNode.removeFromParentNode()
    }
}