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.
Figure 0.2 - Create a New Unity 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.
Figure 0.3 - Import the Vuforia Target Database
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
Figure 1.0.1 - Importing the AR Camera GameObject
During first-run, Vuforia Assets may take several minutes to unpack and install
The ARCamera will now appear in the Hierarchy Window.
Figure 1.0.2 - 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.
Figure 1.0.4 - Enabling Vuforia in Player Settings
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
Figure 1.1 - Copy and Paste the Unity Development Key in to the App License Key Field
ClickDebug (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
Figure 2.0.1 - Adding ImageTargets
The Image Target can be changed within the Inspector Window drop-down menu.
Figure 2.0.2 - Changing Image Targets
You can duplicate the ImageTargetGameObject 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).
Figure 2.0.3 - Duplicating Image Targets
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.
Figure 3.0.1 - Inserting premade GameObjects
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.
Figure 3.0.2 - Using the Hierarchy Window
Adding Annotations
Simple 3d Text can be added by heading to GameObject > 3D Object > 3D Text
Figure 3.1.1 - Adding 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.
Figure 3.1.2 - Using the Hierarchy Window
Debugging
Use the Play button in the toolbar to test the application.
Figure 4.0 - Debugging an 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, clickAsset Store on the Scene Window Toolbar.
Figure 5.1.1 - Importing Assets from the App Store
You can search for free assets by using the cost slider. Download your asset and drag and drop it from the Project Window
Figure 5.1.2 - Inserting Assets in to a Scene
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.
Figure 5.2 - Importing .obj Files
See also: Creating and texturing .obj files in Rhino3d.
Final Output
This scene consists of assets built in to Unity,
Figure 5.3 - Final Output
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.
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.