FREELessons: 13Length: 1.2 hours

Next lesson playing in 5 seconds

  • Overview
  • Transcript

2.2 Adding Geometry

Sometimes it’s enough to just use basic geometric shapes like cubes and spheres, but usually you’ll want to use 3D models. In this lesson, we’ll download a free model of a sculpture and add it to a standard ARKit example app from Apple.

Related Links

2.2 Adding Geometry

Hi, and welcome back to Get Started With Augmented Reality for iOS. This lesson is all about adding 3D geometry to your scenes. In an Augmented Reality application, you want digital models to insert into a scene. These can either be simple objects like boxes or spheres, or complex 3D models created in an external editor. If you are already proficient with SceneKit, you can safely skip this lesson, as there isn't any difference with the Enabled scene view. So to understand how to do this, we first need to talk about how a scene is organized. It consists of a hierarchical structure of nodes that describe the scene. These nodes can have various things attached, including geometry, which is what we are focusing on right now. You can also have nodes of lights, cameras, or physics bodies attached. Let's see an example using a sphere. First, you have to create the geometry with SCNSphere. It takes a radius in the initializer. There are also other basic geometry types like boxes, cones, or even a torus. Geometry can also have materials attached. So it renders with textures and applies appropriate lighting. Then, you need to create a node, passing in the geometry. The node is the object that contains positional information. Finally, you have to add the nodes to a parent, creating the hierarchy. This could be the scene's root node, for instance. So how about more complex models? They are treated as their own scene, because you can also add animations, custom lights, and so on. SceneKit on iOS supports either SceneKit archive with the scn extension, or either a dae, which stands for Digital Asset Exchange. Or abc file, which is an interchange format invented by Lucas Firm and Sony that is called Alembic, and widely used in the industry. If you aren't a 3D designer yourself or don't have access to one, there are a few resources you can use. One would be AutoDesk's SketchUp. This offers a marketplace where you can get models for free or buy them. Another great site is It offers models with different licenses and in different formats. Unfortunately, not all of the models are in the format that SceneKit supports. This is not too big of an issue, because we can use 3D modeling tools to convert them into a valid format. What is a bigger deal is the organization of those models by the author. Sometimes they create them in a weird way that makes it more difficult to use. Blender is a free application that allows us to convert obj or fbx files to a usable format in SceneKit. Here I have a sculpture. It is a good example, you can download it as an object file. It only has a minor flaw in the attached materials file, we need to add underscores to the texture. When I open up Blender, it automatically has a cube in the scene. We need neither the cube nor the camera or light, so let's delete them. Then I can import the sculpture. I can use the File menu to select Export and export the sculpture in a dae format, which is called here. Make sure you copy the materials as well. So let's have a look at the example code from Apple's ARKit example. Since we are focusing on models right now, it avoids a lot of boilerplate code. You can find it in the course repository. Let's load it up and have a look what it does. It allows you to place different objects in the vault, like a vase or a coffee cup, or even a chair. The way that Apple does it in this example I have, is by using the AR ReferenceNode clause. It is a placeholder for content that is loaded from an external scene. When we have a look at the VirtualObject class, you can see in the initializer it sets the URL to a model file. You have already seen the other way to add a model by using the scn scene initializer, like in the template of the last lesson. Let's see how they look. Well, they are synched archives, and Xcode is capable of displaying them and allows you to add it to files as well. It is basically a 3D model viewer and simple editor. The candle, for example, is a combination of geometry and particle effect. By using the play button on the bottom, you can start the candle animation, a burning flame. Now let's add the sculpture model we exported before to the assets, and add it to the JSON file. Right now it is a DAA file, but I can convert to a scene very easily. It also allows us to change the base, because it appears to have inverted faces, and therefore, we need to enable double sided so it looks nicer. To be able to place it with the example application, we have to add the sculpture to the list. When we run the application now, it shows up in the list of objects to place, and we can add it to the vault. All right, to recap. SceneKit supports SceneKit archives, Digital Asset Exchange and Alembic files. You can load the model using either SCNScene or SCNReferenceNode. Xcode allows you to view and edit properties of 3D model files. In the next lesson, I'm going to introduce you to the physics in Augmented Reality. See you there.

Back to the top