Getting started with ARKit

With WWDC’s announcement of ARKit I knew I had to try out some of the new stuff they announced. I decided to play around with the new ARKit. I wanted to link it somehow with music so I decided to build a disco ball in augmented reality to enhance your boogie experience. The result can be seen here:

The most important thing in ARKit is the plane detection. It enables you to build augmented reality apps without anything other than your phone.

To get started you need to add a ARSCNView to a view controller view. To use the plane detection you set your view controller as a delegate of the ARSCNView. Every time a new plane is detected you will be alerted of a new SCNNode being added.

We check for every node added if its anchor is a plane. If so we assume that ARKit has found a plane for us to add our content to. Using this new node and its anchor we can create a SceneKit plane which we can then add objects to. In our case we want to add a disco ball a set distance above that plane.

Now that we have a plane to add stuff we can build nodes for the disco ball and the light beams coming out of it:

We apply a simple texture to the disco ball and give the light beam cones colors. We can then put it all together:

We call this function with the anchor plane and node we got in the delegate function. We start by creating a plane, disco ball and 30 light beam nodes. We then add the light beams to random places on the disco ball, then we add the disco ball to the plane and finally we add the plane to the node that ARKit found for us.

Code for this little project can be found here. (You will need Xcode 9 and iOS 11 to run, both of which are currently in beta)