Creating a Simple AR App

Introduction to Vuforia and Unity for Creating Augmented Reality Applications

Vuforia Engine is the most widely used platform for AR development. It can easily be integrated with Unity.

Developers can easily add advanced computer vision functionality to any application, allowing it to recognize images and objects, and interact with spaces in the real world.

The Vuforia Engine platform supports AR app development for Android, iOS, and UWP devices. See: Vuforia Supported Versions

Workflow

This tutorial will cover the creation of a basic application which recognises ImageTargets and displays information based on the recognition of those targets. The basic process of app development is to:

  • Create a Unity Project

  • Create a Vuforia License and Image Database

  • Add an Augmented Reality Camera

  • Add Image Targets

  • Add GameObjects as Child Assets

  • Build Application

Ensure you have downloaded and installed Unity and created a Vuforia Developer Account

Create a Unity Project

Follow the steps outlined in the Unity Primer to create an example project.

We have named our project AugmentedRealityDemo

Vuforia Database and License Management

Follow the steps outlined in the Vuforia Primer to obtain a Development License Key and to create a Target Database. Our Target Database is titled AugmentedRealityDemo.unitypackage

Import the .unitypackage in to the newly created Unity Project.

The AR Camera

The first GameObject required to create an Augmented Reality app is the Vuforia AR Camera.

The AR Camera is located under the GameObject menu: GameObject > Vuforia Engine > AR Camera

During first-run, Vuforia Assets may take several minutes to unpack and install

The ARCamera will now appear in the Hierarchy Window.

When the ARCamera GameObject is selected, a Camera Preview window should appear. By default, Unity will use the computer's webcam as the ARCamera.

Ensure Vuforia is enabled in Player Settings:

File > Build Settings > Player Settings > XR Settings > Vuforia Augmented Reality

Adding the Unity Development Key

With the ARCamera selected, click Open Vuforia Engine Configuration from the Inspector window. Inspector > Vuforia Behaviour (Script) > Open Vuforia Engine Configuration

Copy and paste the License Key created on the Vuforia License Manager

Click Debug (The play symbol in the centre of the toolbar) to verify that the Unity is able to access the camera.

Delete all unnecessary GameObjects such as the MainCamera and Directional Light

Hierarchy Window > Select > Right-click > Delete

ImageTargets

Image Targets can be added as children of the ARCamera by selecting the AR Camera in the Hierarchy Window and adding Images from the GameObject Menu

GameObject > Vuforia Engine > Image

The Image Target can be changed within the Inspector Window drop-down menu.

You can duplicate the ImageTarget GameObject by right-clicking the object in the Hierarchy Window and selecting Duplicate.

For this tutorial, we have created three ImageTarget GameObjects, each with a different Image Target. (Bark, Stones and Tarmac).

Adding Content to ImageTargets

ImageTargets are objects which, when detected by the ARCamera, can display some type of content. This content can either be in the form of:

  • Assets downloaded from the Unity Store,

  • .obj files

  • Assets built in to Unity such as

    • 3D Geometries

    • Text

This tutorial will focus on adding simple 3D geometries and Text built in to Unity.

To add a cube, head to GameObject > 3D Object > Cube.

Ensure to scale the object correctly using the controls in the Inspector Window, and that the GameObject is a child of a particular ImageTarget in the Hierarchy Window.

Adding Annotations

Simple 3d Text can be added by heading to GameObject > 3D Object > 3D Text

Rotate and Resize the text using the Transform functions in the Inspector Window.

This text should be made a child of either the ImageTarget or the Cube we have just created.

As we want the text to show as an annotation of the Cube, we have made it a child of the Cube, by dragging and dropping the GameObject in the Heirarchy Window.

Debugging

Use the Play button in the toolbar to test the application.

Importing Other Model Types in to Unity

Models can be imported in to your Unity Application in a variety of ways.

Importing assets from the Asset store.

The asset store provides access to a library of pre-made content (both paid and free). This content is particularly useful to easily create animated figures.

To access the asset store, click Asset Store on the Scene Window Toolbar.

You can search for free assets by using the cost slider. Download your asset and drag and drop it from the Project Window

Importing .obj Files

The easiest way to import .obj models in to Unity is by dragging and dropping the model files in to the Project Window. It is best practice to keep these assets their own dedicated folder. .stl and .3dm filetypes are not supported in Unity.

See also: Creating and texturing .obj files in Rhino3d.

Final Output

This scene consists of assets built in to Unity,

Packaging Applications

Applications can be packaged for different platforms. Head to File > Build Settings and select the desired platform. Be sure to click Add Open Scenes to Build.

See the Unity Primer for information on Building Applications

Unity Primer

Vuforia only supports a variety of handheld and headset devices. Therefore, AR apps built with the Vuforia Engine cannot easily be deployed on Windows or OSX.

See: Supported Devices

Note that for iOS applications, OSX and XCode are required.

Going Further

Unity Next Steps: Interaction

Other Resources

Last updated