Target Based Augmented Reality With Unity
by Digijeunes in Circuits > Software
932 Views, 9 Favorites, 0 Comments
Target Based Augmented Reality With Unity
With Unity and Vuforia, we'll build an Augmented Reality application for Android phones. The application will show the user camera and add virtual 3D model to a target printed beforehand.
Supplies
A computer with Unity installed.
Create a Vuforia account on their website.
https://developer.vuforia.com/
Once created, download their UnityPackage
https://developer.vuforia.com/downloads/sdk
Create also a license key for it
https://developer.vuforia.com/vui/develop/licenses
If all of this is ready, you also are ready to start!
Start a New Project
Create a new 3D project in Unity.
Add Vuforia to your project.
Asset -> Import Package -> Custom
import the .unitypackage downloaded before.
Delete the Main Camera.
Setup the Hierarchy
To add Vuforia AR Camera to the scene, do a right click in hierarchy and choose Vuforia -> AR Camera
Do the same to add Image Target.
Setup Vuforia
Select AR Camera in hierarchy and look in the inspector to change World Center Mode to FIRST_TARGET
Then, just under this setting, click Open Vuforia Configuration
Change App License Key by the key you created on Vuforia.
You're now set'up and ready to add your target.
Add a Target
You'll now have to choose a picture as target. Vuforia will use it to recognise in the user's camera where it should show the 3D model.
Because of this, Vuforia need a picture sufficiently recognizable.
Select Image Target in hierarchy and change its Type in the inspector by From Database and click import.
You can now zoom a lot to see the picture on the scene.
Print the picture.
You can change this picture by whatever you want, add the picture in your assets to use it. and select From Image instead.
Add a 3D Model
We need to add a 3D model to our scene. If you have any, add it to your asset and put it in your hierarchy inside Image Target.
If you don't have any, you can choose a free one directly on Unity Store https://assetstore.unity.com/?category=3d&price=0-0
Once you added one to your account, you can go back to Unity and open the Package Manager in the Window Menu. Select My Assets, download and import it.
Finally find the model in your assets and drag it in your hierarchy inside Image Target.
If your model is too big compared to the size of your target, you should size it down in the inspector to a reasonable size.
Your application is ready! No code needed, Vuforia will do all the calculation by itself. Let's export our app now.
Building the App
Menu -> Files -> Build Settings.
Select Android and click on Switch Platform.
Click on player settings and set the Mininum API Level to Android 7.1.
You can now click on Build.
You'll now have an apk file that you can install on your Android and try it out!