Using ARKit with SceneKit

As mentioned before, SceneKit is a rendering engine that is used to build three-dimensional games. SceneKit uses the Metal rendering engine under the hood, which means that it has great performance and it can be used to build truly sophisticated games. It makes a lot of sense that Apple chose to augment SceneKit in order to be compatible with ARKit. They both operate in all three dimensions to create an immersive experience.

When you create a three-dimensional scene, you often use a camera object that is used as the window through which the user looks at the scene. In a game, the camera is often positioned from the perspective of the player. As the player moves around, the camera moves through the scene and this updates the view.

Think about this for a second. A 3D game is a three-dimensional world in which the player controls the camera. Why wouldn't you replace this fictional camera with a real camera? And instead of pressing buttons to make the camera move, you could actually move the physical camera. When this idea clicks, the combination of ARKit and SceneKit seems to be almost obvious; AR is simply another way of controlling the virtual camera.

To make SceneKit compatible with ARKit, Apple has created a subclass of one of SceneKit's core components. This component is SCNView. The SCNView class is used to render a scene with SceneKit. When combining SceneKit with ARKit, you are expected to use ARSCNView. This subclass of SCNView is configured so it uses an ARSession to help to render the scene. It also helps with controlling the camera and it automatically estimates lighting. This means that it will make sure that your 3D models are always incorporated into the world as well as possible.

When you render content in SceneKit, you make use of SCNNode instances to represent the contents in your scene. When using an ARSCNView, all SCNNodes are automatically mapped to ARAnchor instances so you don't have to manually convert them. This makes combining SceneKit and ARKit pretty simple and straightforward so you can focus on creating a great AR experience. However, if you do want to manually convert certain nodes, you can implement the ARSCNDelegate protocol to provide some custom node mapping if needed.

If you don't have a need for 3D models, or if you're looking for a quicker and simpler way to get started with ARKit, the next rendering engine just might be what you're looking for. Let's take a look at SpriteKit.