In this project work, we will:
- Install the Vuforia SDK for building AR applications
- Set up marker detection with an image target
- Create a simple AR app that will show a 3D robot model through your smartphone camera when you point it at a special "target" that you'll print out.
For this project, we will need an Android device running 4.4 or above, or an iOS device running 9 or above.
Let's get the Vuforia SDK working in a new Unity project. If you already downloaded the Vuforia SDK as part of Unity installation, you may be able to skip some or all of these steps.
- In Unity, create a new 3D Unity project.
- Select Edit > Project Settings > Player
- In the XR Settings, check the "Vuforia Augmented Reality Supported" box.
- In Unity, select GameObject > Vuforia > AR Camera. You will be prompted to install some additional assets, this will happen once per project.
- Delete the MainCamera object.
Next, you'll add an image of the robot to a Vuforia database. This image will be the marker that the application is looking for to make the robot appear.
- You will need to create a free Vuforia developer account on the Vuforia developer portal: https://developer.vuforia.com/vui/auth/register
- Once registered, create a new developer key on their website by going to Develop > License Manager > Get Development Key. Name it “ARLesson”.
- Download the zip file VuforiaAssets, which contains the assets you will need. After you unzip it, import it as a custom package to your Unity project.
- Back on the Vuforia website, go to Develop > Target Manager > Add Database. Name it “arRobot_ImageTargets”.
- Once the database is created, click on it and add a new target. Choose Single Image, browse for the ImageTargetRobot.jpg file, and set a width of 0.07. Name it “Robot”.
- Click on Download Database, then Download for Unity Editor. Import the resulting unitypackage file to your Unity project.
Here’s a tip! Vuforia benefits from having lots of trackable features which means zones of contrast in the target image. After the upload, each image will get a rating, like below.
-
Go back to the Vuforia website and navigate to the License Manager page. Click on "ARLesson" and copy the license key.
-
In Unity, click the button "Open Vuforia Engine Configuration" and paste the license key into the "App License Key" field.
Finally, you'll connect the image target to the Unity prefab that you want the app to show in augmented reality space, in this case a 3d robot model prefab.
- In your Unity project, create an image target object by selecting: GameObject > Vuforia > Image
- Configure the target to use the "arRobot_ImageTargets" database and then the "Robot" Image Target.
-
Add the RobotAnimated prefab as a child of the image target. Make sure its local scale is 1.
-
Add the scene to the build in Build Settings and build to your device.
-
Print out a physical copy of the ImageTargetRobot.jpg or, if you use a smartphone, point to a screen with the ImageTargetRobot.jpg opened. When you run your application, the 3D robot should appear when you point your smartphone camera at the image.