Getting Started With Vuforia: 1. Create A License Key For Our Application
Getting Started With Vuforia: 1. Create A License Key For Our Application
To get started, we will need to go to Vuforia’s Developer Portal and create an account.
Once logged in, we can proceed to the “Develop” page. To use Vuforia with Unity, we will need to
do two things:
Once we fill in the details, we can select “Next” and then “Confirm”. This will direct us back to
the “License Manager” page where the application’s name will appear.
Once we select “ARDemo”, we will get the license key. This key will be used later in Unity.
The next step is to set up an image as a target. We head over to “Develop >> Target Manager”
and select “Add Database” and fill in the details:
Next, we will need to add images to the newly made database. So, we select the database and
click on “Add Target”. Vuforia supports various kinds of targets like single image, cylindrical,
cuboidal, 3D image etc. For this tutorial, we will be using a single image target and the
Image_name image. Any arbitrary value can be selected for width, say 0.5.
After a short upload time, the target will be added and we will have a “Download Dataset”
option.
An important thing to note here is the “Rating”. A good rating means that it can be used for
tracking, whereas a bad rating means that the image does not have enough feature points
(interesting points in the image like edges, corners etc which are used for tracking in image
processing).
Let’s download the dataset by selecting “Download Dataset >> Unity editor”
This will generate a Unity package containing trackable information about this trackable
database.
Integrating with Unity
Unity is a powerful and widely used game engine. Recently, it has also been emerging as the game
engine for HMDs. The tutorial assumes very basic knowledge of Unity. You can find some more
interesting tutorials on Unity here.
Let’s start by creating a new Unity3D project by the name of “ARDemo”.
Next, we will have to import the Vuforia Unity packages. This can be done by going to “Assets >>
Import Package >> Custom Package”. We will have two packages, one corresponding to our
dataset (Image_Targets.unitypackage) and the other corresponding to Vuforia 5 SDK for Unity
(vuforia-unity-5-0-5.unitypackage) which can be found here.
Time to add some 3D models to our project. Let’s proceed to “Window >> Asset Store”. Here we
can find a Samurai model by the name of “Red Samurai”, for free. We will have to log in with our
Unity Account to download and import this model.
Once imported, our Assets folder will look like this:
Next, we will have to add an ARCamera to our scene. “ARCamera” is an Augmented Reality
camera prefab from Vuforia and is very similar to a regular camera. We can find this under “Assets
>> Vuforia >> Prefabs” and drag it into our scene at X=0, Y=0, Z=0. Let’s also delete the Main
Camera from the scene (it can be found under the Hierarchy Panel, “Right Click >> Delete”) as we
already have an ARCamera.
For our ARCamera to run, we will have to add the App License Key. In the Inspector panel, we
will have to paste the unique key we had previously received from Vuforia’s License Manager.
At this point in time if we press the Play button in the Unity Editor we should be able to see
our WebCam feed in the Game View.
Next, let’s add the ImageTarget to our scene. It can be found under “Assets >> Vuforia >>
Prefabs”. Let’s add it to our scene at X=0, Y=-50, Z=0. Now, in the Inspector panel for the
Image Target we will have to make some changes. Under the “Image Target Behaviour
(script)” we will have to change “Data Set” to “Image_Targets” and “Image Target” to
“stones_hires”. Once done, the stone_hires image will appear in our Scene View.
Next, let’s drag our Samurai onto the Scene. It can be found under “Assets >> prefab >>
samuzai”. For the samurai to appear over ImageTarget, it needs to be made a child of
ImageTarget (can be done by just dragging the samuzai prefab in the Hierarchy panel). Then,
whenever the ImageTarget is detected by a mobile device’s camera, all the children of the
target will also appear together. The scale of the samuzai needs to be changed to X=0.5, Y=0.5,
Z=0.5.
At this point, if we select “Run” and point a print out of the image towards our webcam, we
should see the samurai on it and doing “Attack animation” which is its default animation.
We are almost done. Let’s save the scene with the name “ARDemo”.
The last step is to build the project for Android. We need to go to “File >> Build Settings”. We
need to add the current scene by selecting “Add Current”. Then, we need to select a platform
(Android). Here, we will have multiple options:
Google Android Project: This will allow us to export the current Unity project to Android
Studio so it can be edited and used to add more elements.
Development Build: Enabling this will enable Profiler functionality and also make the
Autoconnect Profiler and Script Debugging options available.
Once the app builds and runs on Android we can point the mobile device’s camera to the
marker and watch the animation.